-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add infrastructure for running unit tests
- Loading branch information
Showing
7 changed files
with
87 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[pytest] | ||
addopts = --cov=sonic_platform_base --cov-report html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[aliases] | ||
test=pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |