forked from dgubanovv/qa-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiag_selftest_verbose.py
166 lines (135 loc) · 6.42 KB
/
diag_selftest_verbose.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import copy
import os
import sys
import re
import pytest
import yaml
from tools.diagper import DiagWrapper, download_diag, get_actual_diag_version, uninstall_diag
from tools import driver
from tools.atltoolper import AtlTool
from tools.utils import get_atf_logger
from infra.test_base import TestBase, idparametrize
from tools.ops import get_arch, OpSystem
from tools.constants import FELICITY_CARDS, BERMUDA_CARDS
from tools.command import Command
log = get_atf_logger()
def setup_module(module):
#import tools._test_setup # uncomment for manual test setup
os.environ["TEST"] = "diag_selftest_verbose"
class TestDiag(TestBase):
DIAG_TEST_ITERATIONS = int(os.environ.get("DIAG_TEST_ITERATIONS", 5))
DEFAULT_SELFTEST_CONFIG = {
"version": 1,
"tests": {
"datapath_tests": [],
"memory_tests": [],
"offload_tests": [],
"flash_tests": [],
"misc_tests": []
},
"Ethernet_Speed": [],
"Phy_Speed": []
}
@classmethod
def add_diag_drv_cert(cls, path):
arch = get_arch()
cert_dir = "win32" if arch == "32" else "x64"
cert = os.path.join(path, "mbu/Os/{}/aquantiaDiagPack.cer".format(cert_dir))
cls.diag_drv.install_trusted_certificate(cert)
@classmethod
def setup_class(cls):
dut_felicity = os.environ.get('DUT_FELICITY', None)
if dut_felicity is not None:
os.environ['DUT_PORT'] = dut_felicity
os.environ['DUT_FW_CARD'] = 'Felicity'
super(TestDiag, cls).setup_class()
try:
cls.log_server_dir = cls.create_logs_dir_on_log_server()
cls.os = OpSystem()
cls.install_firmwares()
if cls.os.is_centos() or cls.os.is_ubuntu():
uninstall_diag()
cls.diag_dir = download_diag(cls.diag_version)
cls.diag_ver = get_actual_diag_version(cls.diag_version)
cls.diag_drv = driver.Driver(port=cls.dut_port, drv_type="diag", version=cls.dut_drv_version)
if cls.os.is_windows():
cls.add_diag_drv_cert(cls.diag_dir)
if cls.os.is_linux():
if cls.os.is_rhel():
cls.diag_drv_path = '{}/mbu/Os/linux/driver/src'.format(cls.diag_dir)
Command(cmd='cd {}; make'.format(cls.diag_drv_path)).run_join(15)
Command(cmd='insmod {}/aqdiag.ko'.format(cls.diag_drv_path)).run_join(15)
else:
Command(cmd='insmod /opt/aquantia/diag/mbu/Os/linux/driver/src/aqdiag.ko').run_join(15)
else:
cls.diag_drv.install()
cls.atltool = AtlTool(port=cls.dut_port)
except Exception as e:
log.exception("Failed while setting up class")
raise e
def run_test_selftest_verbose(self, config, speed = None):
config_path = "tmp.cfg"
tmp_content = ["tmp.cfg file content:"]
with open(config_path, "w") as f:
yaml.dump(config, f)
tmp_content.append(yaml.dump(config))
log.info('\n'.join(tmp_content))
params = "-v 2 -c -a {} {} -r --raise".format(config_path, self.DIAG_TEST_ITERATIONS)
res = DiagWrapper.exec_single(params, self.diag_dir)
assert res["reason"] == Command.REASON_OK
assert res["returncode"] == 0
log.info('Exit code: {}, reason: {}'.format(res["returncode"], res["reason"]))
re_pass = re.compile(r"^(\w+\s*\w*\s*)=\s*\d*[a-z ]*\d* passed \(100.00%\)?")
assert any(re_pass.match(line) for line in res["output"] \
if not line.startswith('=====') and 'Diagnostic Utility Version' not in line and 'Using it...' not in line)
log.info('tests are 100% passed')
re_pass_subtest = re.compile(r"^Ending (\w+\s*\w*\s*)\(*\d*\.*\d*\w*\)*(\s*\.*)* RESULT = PASS?")
itr_re_pass_subtest = 0
for line in res["output"]:
if not line.startswith('=====') and 'Diagnostic Utility Version' not in line and 'Using it...' not in line:
ms = re_pass_subtest.match(line)
if ms is not None:
log.info('subtest iteration #{} have been passed'.format(itr_re_pass_subtest))
itr_re_pass_subtest += 1
assert itr_re_pass_subtest == self.DIAG_TEST_ITERATIONS
if speed is not None:
itr = 0
re_pass_speed = re.compile(r"^Ending (\w+\s*\w*\s*)\(*(\d*\.*\d*\w*)\)*(\s*\.*)* RESULT = PASS?")
for line in res["output"]:
if not line.startswith('=====') and 'Diagnostic Utility Version' not in line and 'Using it...' not in line:
m = re_pass_speed.match(line)
if m is not None:
assert m.group(2) == speed
log.info('subtest iteration #{} have been passed with speed "{}"'.format(itr, speed))
itr += 1
assert itr == self.DIAG_TEST_ITERATIONS
def test_selftest_mac_verbose(self):
config = copy.deepcopy(self.DEFAULT_SELFTEST_CONFIG)
config["tests"]["datapath_tests"] = ["Mac"]
self.run_test_selftest_verbose(config)
@idparametrize("speed", ['100M', '1G', '2.5G', '5G', '10G'])
def test_selftest_phy_loopback_verbose(self, speed):
if self.dut_fw_card in FELICITY_CARDS:
pytest.skip("Felicity has no PHY")
if self.dut_fw_card in BERMUDA_CARDS and speed == '10G':
pytest.skip("Bermuda max 5G")
else:
config = copy.deepcopy(self.DEFAULT_SELFTEST_CONFIG)
config["tests"]["datapath_tests"] = ["Phy Loopback"]
config["Phy_Speed"] = [speed]
self.run_test_selftest_verbose(config, speed)
@idparametrize("speed", ['100M', '2.5G', '5G', '10G'])
def test_selftest_extloopback_verbose(self, speed):
if self.dut_fw_card in BERMUDA_CARDS and speed == '10G':
pytest.skip("Bermuda max 5G")
else:
config = copy.deepcopy(self.DEFAULT_SELFTEST_CONFIG)
config["tests"]["datapath_tests"] = ["External Loopback"]
config["Ethernet_Speed"] = [speed]
self.run_test_selftest_verbose(config, speed)
def test_selftest_lso_verbose(self):
config = copy.deepcopy(self.DEFAULT_SELFTEST_CONFIG)
config["tests"]["offload_tests"] = ["LSO"]
self.run_test_selftest_verbose(config)
if __name__ == "__main__":
pytest.main([__file__, "-s", "-v"])