Skip to content

Commit

Permalink
Add unit test infrastructure (#139)
Browse files Browse the repository at this point in the history
Add infrastructure for running unit tests
  • Loading branch information
vdahiya12 authored Oct 27, 2020
1 parent a659219 commit 012dc39
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 2 deletions.
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
*.pyc
*/__pycache__/
tests/*.pyc
tests/__pycache__/

# Distribution / packaging
build/
sonic_platform_common.egg-info/
.cache
.cache

# Unit test / coverage reports
.coverage
htmlcov/
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
addopts = --cov=sonic_platform_base --cov-report html
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[aliases]
test=pytest
7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@
'redis',
'sonic-py-common'
],
setup_requires= [
setup_requires = [
'pytest-runner',
'wheel'
],
tests_require = [
'pytest',
'pytest-cov',
],
classifiers=[
'Development Status :: 3 - Alpha',
'Environment :: Plugins',
Expand Down
Empty file added tests/__init__.py
Empty file.
54 changes: 54 additions & 0 deletions tests/sfputilhelper_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import os
import sys

import pytest
try:
import sonic_platform_base.sonic_sfp.sfputilhelper
except Exception as e:
print("Failed to load sonic_platform_base.sonic_sfp.sfputilhelper due to {}".format(repr(e)))


@pytest.fixture(scope="class")
def setup_class(request):
# Configure the setup
test_dir = os.path.dirname(os.path.realpath(__file__))
request.cls.port_config = os.path.join(
test_dir, 't0-sample-port-config.ini')

request.cls.port_config = sonic_platform_base.sonic_sfp.sfputilhelper.SfpUtilHelper()


@pytest.mark.usefixtures("setup_class")
class TestSfpUtilHelper(object):

platform_sfputil = None
port_config = None

def test_read_port_mappings(self):

try:
platform_sfputil.read_porttab_mappings(self.port_config, 0)
except Exception as e:
print("Failed to read port tab mappings to {}".format(repr(e)))

PORT_LIST = ["Ethernet0",
"Ethernet4",
"Ethernet8",
"Ethernet12",
"Ethernet16",
"Ethernet20",
"Ethernet24",
"Ethernet28",
"Ethernet32",
"Ethernet36",
"Ethernet40",
"Ethernet44",
"Ethernet48"]

if self.platform_sfputil is not None:
logical_port_list = self.platform_sfputil.logical
assert len(logical_port_name) == len(self.port_list)
for logical_port_name in logical_port_list:
assert logical_port_name in PORT_LIST
else:
print("platform_sfputil is None, cannot read Ports")
14 changes: 14 additions & 0 deletions tests/t0-sample-port-config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# name lanes alias
Ethernet0 29,30,31,32 fortyGigE0/0
Ethernet4 25,26,27,28 fortyGigE0/4
Ethernet8 37,38,39,40 fortyGigE0/8
Ethernet12 33,34,35,36 fortyGigE0/12
Ethernet16 41,42,43,44 fortyGigE0/16
Ethernet20 45,46,47,48 fortyGigE0/20
Ethernet24 5,6,7,8 fortyGigE0/24
Ethernet28 1,2,3,4 fortyGigE0/28
Ethernet32 9,10,11,12 fortyGigE0/32
Ethernet36 13,14,15,16 fortyGigE0/36
Ethernet40 21,22,23,24 fortyGigE0/40
Ethernet44 17,18,19,20 fortyGigE0/44
Ethernet48 49,50,51,52 fortyGigE0/48

0 comments on commit 012dc39

Please sign in to comment.