-
Notifications
You must be signed in to change notification settings - Fork 1
/
drv_wake_on_link.py
426 lines (349 loc) · 16 KB
/
drv_wake_on_link.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
"""
THIS SCRIPT MUST BE EXECUTED ON LKP.
"""
import os
import time
import pytest
import re
from infra.test_base import TestBase
from tools.ifconfig import LINK_SPEED_100M
from tools.driver import Driver
from tools.utils import get_atf_logger
from tools import ifconfig
import tools.power
from tools import command
from tools import constants
from tools.lom import LightsOutManagement
log = get_atf_logger()
def setup_module(module):
# import tools._test_setup # uncomment for manual test setup
os.environ["TEST"] = "mac_ptp_avb_streams"
class TestDrvWakeOnLink(TestBase):
"""
@description: The SleepProxyDriver test is dedicated to perform check firmware is in sleep.
It performs several link drops, wake on link and other actions first time after sleeping.
@setup: Two Aquantia devices connected back to back.
"""
SLEEP_LOM_TTL = 32
NO_SLEEP_LOM_TTL = 64
MAC_NO_SLEEP = 180
REGEXP_TTL_FROM_PING = ".*\d+\s+bytes\s+from\s+[0-9\.]+:\s+icmp_seq=\d+\s+ttl=(\d+)\s+time=\d+.\d+\s+ms.*"
DUT_IP = "192.168.0.3"
LKP_IP = "192.168.0.2"
NETMASK = "255.255.255.0"
@classmethod
def setup_class(cls):
super(TestDrvWakeOnLink, cls).setup_class()
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, host=cls.dut_hostname)
cls.lkp_driver = Driver(port=cls.lkp_port, version=cls.lkp_drv_version)
cls.dut_driver.install()
cls.lkp_driver.install()
cls.host = cls.dut_hostname
cls.dut_ifconfig.set_ip_address(cls.DUT_IP, cls.NETMASK, None)
cls.lkp_ifconfig.set_ip_address(cls.LKP_IP, cls.NETMASK, None)
cls.dut_ifconfig.set_link_speed(constants.LINK_SPEED_1G)
cls.lkp_ifconfig.set_link_speed(constants.LINK_SPEED_1G)
except Exception as e:
log.exception("Failed while setting up class")
raise e
def setup_method(self, method):
super(TestDrvWakeOnLink, self).setup_method(method)
self.dut_ifconfig.set_link_state(ifconfig.LINK_STATE_UP)
self.lkp_ifconfig.set_link_state(ifconfig.LINK_STATE_UP)
if os.environ.get("LOM_TEST", None):
self.LOM_ctrl = LightsOutManagement(host=self.dut_hostname, port=self.dut_port)
self.LOM_ctrl.set_lom_mac_address(self.LOM_ctrl.LOM_MAC_ADDRESS)
self.LOM_ctrl.LoM_enable()
self.LOM_ctrl.set_lom_ip_address(self.LOM_ctrl.LOM_IP_ADDRESS)
def teardown_method(self, method):
super(TestDrvWakeOnLink, self).setup_method(method)
if os.environ.get("LOM_TEST", None):
self.LOM_ctrl.LoM_disable()
@classmethod
def teardown_class(cls):
super(TestDrvWakeOnLink, cls).teardown_class()
tools.power.Power(host=cls.dut_hostname).reboot()
def poll_host_sleeping(self, host, time_sleep):
reg = re.compile(self.REGEXP_TTL_FROM_PING)
count_wait_for_sleep = 0
match = 64
while (match != self.SLEEP_LOM_TTL):
time.sleep(1)
count_wait_for_sleep += 1
ping_dut = command.Command(cmd="ping {} -c 1".format(host))
output = ping_dut.wait(1)["output"]
for line in output:
ttl = reg.match(line)
if ttl:
match = int(ttl.group(1))
assert count_wait_for_sleep != self.MAC_NO_SLEEP, "Mac didn't fall asleep after 3 minutes"
self.verify_host_is_sleeping(host, time_sleep)
def verify_host_is_sleeping(self, host, time_sleep):
# verify that host is sleeping by checking TTL of ping the host
reg = re.compile(self.REGEXP_TTL_FROM_PING)
ping_dut = command.Command(cmd="ping {} -c {} -i 1".format(host, time_sleep))
output = ping_dut.wait(time_sleep + 5)["output"]
ttls = []
for line in output:
match = reg.match(line)
if match:
ttls.append(int(match.group(1)))
assert all(i == self.SLEEP_LOM_TTL for i in ttls), \
"Mac is not asleep. Expected that it shoult be asleep {} seconds".format(time_sleep)
log.debug("TTLS = {}\n".format(ttls))
def poll_host_awake(self, host, time_wake):
reg = re.compile(self.REGEXP_TTL_FROM_PING)
count_wait_for_wake = 0
match = 32
while (match == self.SLEEP_LOM_TTL):
time.sleep(1)
count_wait_for_wake += 1
ping_dut = command.Command(cmd="ping {} -c 1".format(host, time_wake))
output = ping_dut.wait(1)["output"]
for line in output:
ttl = reg.match(line)
if ttl:
match = int(ttl.group(1))
assert count_wait_for_wake < time_wake, "Mac didn't wake up after {} seconds".format(time_wake)
log.debug("Mac wake up after {} seconds".format(count_wait_for_wake))
def test_can_sleep_without_link_120s(self):
"""
@description: This subtest performs check firmware when it goes to sleep with link down.
@steps:
1. Put link to DOWN state.
2. Put machine to sleep.
@result: Machine didn't wake up during 2 minutes.
@duration: 2 minutes.
"""
self.lkp_ifconfig.set_link_state(ifconfig.LINK_STATE_DOWN)
tools.power.Power(host=self.dut_hostname).hibernate()
self.poll_host_sleeping(self.dut_hostname, 120)
def test_sleep_without_link_after_20s_connect_link(self):
"""
@description: This subtest performs check that firmware wake up by link up when it goes to sleep \
with link down.
@steps:
1. Put link to DOWN state.
2. Put machine to sleep.
3. Put link to UP state.
@result: Machine wake up after less than 15 seconds.
@duration: 1 minutes.
"""
self.lkp_ifconfig.set_link_state(ifconfig.LINK_STATE_DOWN)
tools.power.Power(host=self.dut_hostname).hibernate()
self.poll_host_sleeping(self.dut_hostname, 20)
self.lkp_ifconfig.set_link_state(ifconfig.LINK_STATE_UP)
self.poll_host_awake(self.dut_hostname, 15)
def test_sleep_with_link_120s(self):
"""
@description: This subtest performs check that 100M link is up in sleep when firmware \
goes to sleep with link down.
@steps:
1. Put machine to sleep.
@result: After 20 seconds 100M link is up and machine didn't wake up during 100 seconds.
@duration: 2 minutes.
"""
tools.power.Power(host=self.dut_hostname).hibernate()
self.poll_host_sleeping(self.dut_hostname, 20)
if self.lkp_ifconfig.get_link_speed() != LINK_SPEED_100M:
raise Exception("DUD didn't setup 100M link after goes asleep")
self.verify_host_is_sleeping(self.dut_hostname, 100)
def test_sleep_with_link_after_5_disconnect_link(self):
"""
@description: This subtest performs check firmware when link drops in sleep.
@steps:
1. Put machine to sleep.
2. Put link to DOWN state.
@result: Machine didn't wake up during 2 minutes.
@duration: 2 minutes.
"""
tools.power.Power(host=self.dut_hostname).hibernate()
self.poll_host_sleeping(self.dut_hostname, 5)
self.lkp_ifconfig.set_link_state(ifconfig.LINK_STATE_DOWN)
self.verify_host_is_sleeping(self.dut_hostname, 120)
def test_sleep_with_link_20_disc_and_5_con(self):
"""
@description: This subtest performs check that firmware wake up by link reconnecting.
@steps:
1. Put machine to sleep.
2. After 20 seconds put link to DOWN state.
3. After 5 seconds put link to UP state.
@result: Machine wake up after less than 15 seconds.
@duration: 1 minutes.
"""
tools.power.Power(host=self.dut_hostname).hibernate()
self.poll_host_sleeping(self.dut_hostname, 20)
self.lkp_ifconfig.set_link_state(ifconfig.LINK_STATE_DOWN)
self.verify_host_is_sleeping(self.dut_hostname, 5)
self.lkp_ifconfig.set_link_state(ifconfig.LINK_STATE_UP)
self.poll_host_awake(self.dut_hostname, 15)
def test_sleep_with_link_5_disc_5_con(self):
"""
@description: This subtest performs check that firmware cannot wake up by quickly link reconnecting.
@steps:
1. Put machine to sleep.
2. Put link to DOWN state.
3. Put link to UP state immediately.
@result: After 20 seconds 100M link is up and machine didn't wake up during 100 seconds.
@duration: 2 minutes.
"""
tools.power.Power(host=self.dut_hostname).hibernate()
self.poll_host_sleeping(self.dut_hostname, 1)
self.lkp_ifconfig.set_link_state(ifconfig.LINK_STATE_DOWN)
self.lkp_ifconfig.set_link_state(ifconfig.LINK_STATE_UP)
self.verify_host_is_sleeping(self.dut_hostname, 20)
if self.lkp_ifconfig.get_link_speed() != LINK_SPEED_100M:
raise Exception("DUD didn't setup 100M link after goes asleep")
self.verify_host_is_sleeping(self.dut_hostname, 100)
def test_sleep_with_link_5_disc_and_20_con(self):
"""
@description: This subtest performs check that firmware wake up by link reconnecting \
immediately after sleeping.
@steps:
1. Put machine to sleep.
2. Afetr 5 seconds put link to DOWN state.
3. After 20 seconds put link to UP state.
@result: Machine wake up after less than 15 seconds.
@duration: 1 minutes.
"""
tools.power.Power(host=self.dut_hostname).hibernate()
self.poll_host_sleeping(self.dut_hostname, 5)
self.lkp_ifconfig.set_link_state(ifconfig.LINK_STATE_DOWN)
self.verify_host_is_sleeping(self.dut_hostname, 20)
self.lkp_ifconfig.set_link_state(ifconfig.LINK_STATE_UP)
self.poll_host_awake(self.dut_hostname, 15)
# TC8
def test_sleep_with_link_5_disc_and_5_con_several(self):
"""
@description: This subtest performs check that firmware cannot wake up by quickly several link reconnectings.
@steps:
1. Put machine to sleep.
2. Put link to DOWN state.
3. Put link to UP state immediately.
4. Repeat steps 2 and 3 several times.
@result: After 20 seconds 100M link is up and machine didn't wake up during 1 minute.
@duration: 1 minutes.
"""
tools.power.Power(host=self.dut_hostname).hibernate()
self.poll_host_sleeping(self.dut_hostname, 1)
for i in range(5):
self.lkp_ifconfig.set_link_state(ifconfig.LINK_STATE_DOWN)
self.lkp_ifconfig.set_link_state(ifconfig.LINK_STATE_UP)
self.verify_host_is_sleeping(self.dut_hostname, 3)
self.verify_host_is_sleeping(self.dut_hostname, 20)
if self.lkp_ifconfig.get_link_speed() != LINK_SPEED_100M:
raise Exception("DUD didn't setup 100M link after goes asleep")
self.verify_host_is_sleeping(self.dut_hostname, 60)
# TC9
def test_sleep_with_link_several_disc_and_5_con(self):
"""
@description: This subtest performs check that firmware cannot wake up by link down in sleep.
@steps:
1. Put machine to sleep.
2. After 2 minute put link to DOWN state.
@result: Machine didn't wake up during 2 minutes.
@duration: 4 minutes.
"""
tools.power.Power(host=self.dut_hostname).hibernate()
self.poll_host_sleeping(self.dut_hostname, 120)
self.lkp_ifconfig.set_link_state(ifconfig.LINK_STATE_DOWN)
self.verify_host_is_sleeping(self.dut_hostname, 120)
# TC10
def test_sleep_with_link_120_disc_and_5_con(self):
"""
@description: This subtest performs check that firmware can wake up by quickly link reconnecting \
after 2 minutes.
@steps:
1. Put machine to sleep.
2. Put link to DOWN state.
3. Put link to UP state immediately.
@result: Machine wake up after less than 15 seconds.
@duration: 2 minutes.
"""
tools.power.Power(host=self.dut_hostname).hibernate()
self.poll_host_sleeping(self.dut_hostname, 120)
self.lkp_ifconfig.set_link_state(ifconfig.LINK_STATE_DOWN)
self.verify_host_is_sleeping(self.dut_hostname, 5)
self.lkp_ifconfig.set_link_state(ifconfig.LINK_STATE_UP)
self.poll_host_awake(self.dut_hostname, 15)
# TC11
def test_small_ping_in_sleep(self):
"""
@description: This subtest performs check small ping in sleep mode.
@steps:
1. Setup autoneg speed on DUT and LKP.
2. Put machine to sleep.
3. Run ping with payload size equal to 500.
@result: Machine didn't wake up and should answer to ping.
@duration: 2 minutes.
"""
self.dut_ifconfig.set_link_speed(constants.LINK_SPEED_AUTO)
self.lkp_ifconfig.set_link_speed(constants.LINK_SPEED_AUTO)
self.lkp_ifconfig.wait_link_up()
tools.power.Power(host=self.dut_hostname).hibernate()
self.poll_host_sleeping(self.dut_hostname, 20)
assert self.ping(
None, self.DUT_IP, 16, ipv6=False, src_addr=self.LKP_IP, payload_size=500, margin=20) \
is True, "Ping {} from {} failed unexpectedly".format(self.DUT_IP, self.LKP_IP)
# TC12
def test_large_ping_in_sleep(self):
"""
@description: This subtest performs check large ping in sleep mode.
@steps:
1. Setup autoneg speed on DUT and LKP.
2. Put machine to sleep.
3. Run ping with payload size equal to 4000.
@result: Machine didn't wake up and should answer to ping.
@duration: 2 minutes.
"""
self.dut_ifconfig.set_link_speed(constants.LINK_SPEED_AUTO)
self.lkp_ifconfig.set_link_speed(constants.LINK_SPEED_AUTO)
self.lkp_ifconfig.wait_link_up()
tools.power.Power(host=self.dut_hostname).hibernate()
self.poll_host_sleeping(self.dut_hostname, 20)
assert self.ping(
None, self.DUT_IP, 16, ipv6=False, src_addr=self.LKP_IP, payload_size=4000, margin=10) \
is True, "Ping {} from {} failed unexpectedly".format(self.DUT_IP, self.LKP_IP)
# TC13
def test_diff_ping_in_sleep(self):
"""
@description: This subtest performs check two ping simultaneously in sleep mode.
@steps:
1. Setup autoneg speed on DUT and LKP.
2. Put machine to sleep.
3. Run ping with payload size equal to 500.
4. Run short-term ping with payload size equal to 4000.
@result: Machine didn't wake up and should answer to ping.
@duration: 2 minutes.
"""
reg = re.compile(self.REGEXP_TTL_FROM_PING)
self.dut_ifconfig.set_link_speed(constants.LINK_SPEED_AUTO)
self.lkp_ifconfig.set_link_speed(constants.LINK_SPEED_AUTO)
self.lkp_ifconfig.wait_link_up()
tools.power.Power(host=self.dut_hostname).hibernate()
self.poll_host_sleeping(self.dut_hostname, 20)
cmd_small_ping = command.Command(cmd="ping {} -c 320 -i 1".format(self.DUT_IP))
cmd_large_ping = command.Command(cmd="ping {} -c 5 -s 4000 -i 1".format(self.DUT_IP))
cmd_small_ping.run_async()
for i in range(20):
time.sleep(10)
large_ping_output = cmd_large_ping.wait(10)
ttls = []
for line in large_ping_output["output"]:
match = reg.match(line)
if match:
ttls.append(int(match.group(1)))
assert len(ttls) != 5, "First large ping should be lost"
assert len(ttls) == 4, "Large pings are lost more than expected"
small_ping_output = cmd_small_ping.join(60)
ttls = []
for line in small_ping_output["output"]:
match = reg.match(line)
if match:
ttls.append(int(match.group(1)))
assert len(ttls) >= 300, "Small pings are lost more than expected"
if __name__ == "__main__":
pytest.main([__file__, "-s", "-v"])