-
Notifications
You must be signed in to change notification settings - Fork 1
/
link_reset.py
133 lines (99 loc) · 4.46 KB
/
link_reset.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
import os
import re
import tempfile
import time
import timeit
from shutil import copyfile
import pytest
import shutil
from infra.test_base import TestBase
from tools.atltoolper import AtlTool
from tools.constants import LINK_SPEED_AUTO, LINK_SPEED_100M, LINK_SPEED_1G, \
LINK_SPEED_2_5G, LINK_SPEED_5G, LINK_SPEED_10G
from tools import ops
from tools import test_configure
from tools.atltoolper import AtlTool
from tools.driver import Driver
from tools.utils import get_atf_logger
log = get_atf_logger()
def setup_module(module):
# import tools._test_setup # uncomment for manual test setup
os.environ["TEST"] = "link_up_time"
class TestLinkUpTime(TestBase):
LOCAL_LINK_CAP_REG = 0x368
LINK_CAP_RESOLUTION_REG = 0x370
@classmethod
def setup_class(cls):
super(TestLinkUpTime, cls).setup_class()
cls.DUT_IPV4_ADDR = cls.suggest_test_ip_address(cls.dut_port)
cls.LKP_IPV4_ADDR = cls.suggest_test_ip_address(cls.lkp_port, cls.lkp_hostname)
cls.NETMASK_IPV4 = "255.255.0.0"
try:
cls.log_server_dir = cls.create_logs_dir_on_log_server()
cls.install_firmwares()
cls.dut_driver = Driver(port=cls.dut_port, version=cls.dut_drv_version)
cls.lkp_driver = Driver(port=cls.lkp_port, version=cls.lkp_drv_version, host=cls.lkp_hostname)
cls.dut_driver.install()
cls.lkp_driver.install()
cls.network_interface = cls.dut_ifconfig.get_conn_name()
cls.dut_atltool_wrapper = AtlTool(port=cls.dut_port)
cls.lkp_atltool_wrapper = AtlTool(port=cls.lkp_port, host=cls.lkp_hostname)
except Exception as e:
log.exception("Failed while setting up class")
raise e
@classmethod
def teardown_class(cls):
super(TestLinkUpTime, cls).teardown_class()
# cls.state.test_cleanup_cold_restart = True
def setup_method(self, method):
pass
def teardown_method(self, method):
super(TestLinkUpTime, self).teardown_method(method)
if self.MCP_LOG:
self.dut_atltool_wrapper.debug_buffer_enable(False)
shutil.copy(self.bin_log_file, self.test_log_dir)
shutil.copy(self.txt_log_file, self.test_log_dir)
self.lkp_bin_log_file, self.lkp_txt_log_file = self.lkp_atltool_wrapper.debug_buffer_enable(False)
shutil.copy(self.lkp_bin_log_file, self.test_log_dir)
shutil.copy(self.lkp_txt_log_file, self.test_log_dir)
@test_configure.auto_configure_link_speed
def link_state_reset(self, speed):
timeout = 0.1
cycles = 150
self.dut_ifconfig.set_link_speed(speed)
self.lkp_ifconfig.set_link_speed(speed)
time.sleep(timeout * cycles)
start_value = self.dut_atltool_wrapper.readreg(self.LOCAL_LINK_CAP_REG)
ival = self.dut_atltool_wrapper.readreg(self.LINK_CAP_RESOLUTION_REG)
new_value = start_value - pow(2, 30)
self.dut_atltool_wrapper.writereg(self.LOCAL_LINK_CAP_REG, new_value)
pval = ival
change_counter = 0
for _ in range(cycles):
tval = self.dut_atltool_wrapper.readreg(self.LINK_CAP_RESOLUTION_REG)
if tval != pval:
change_counter += 1
pval = tval
time.sleep(timeout)
log.info('Link state changes detected: %i' % change_counter)
assert (change_counter == 2 and ival != 0) or (change_counter == 1 and ival == 0)
def test_link_reset_AUTO(self):
"""Test that auto negotiated link becomes up with single try."""
self.link_state_reset(speed=LINK_SPEED_AUTO)
def test_link_reset_100M(self):
"""Test that 100M link becomes up with single try."""
self.link_state_reset(speed=LINK_SPEED_100M)
def test_link_reset_1G(self):
"""Test that 1G link becomes up with single try."""
self.link_state_reset(speed=LINK_SPEED_1G)
def test_link_reset_2_5G(self):
"""Test that 2.5G link becomes up with single try."""
self.link_state_reset(speed=LINK_SPEED_2_5G)
def test_link_reset_5G(self):
"""Test that 5G link becomes up with single try."""
self.link_state_reset(speed=LINK_SPEED_5G)
def test_link_reset_10G(self):
"""Test that 10G link becomes up with single try."""
self.link_state_reset(speed=LINK_SPEED_10G)
if __name__ == "__main__":
pytest.main([__file__, "-s", "-v"])