-
Notifications
You must be signed in to change notification settings - Fork 1
/
flash_tools.py
4282 lines (3487 loc) · 176 KB
/
flash_tools.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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import io
import shutil
import ntpath
import os
import re
import sys
import tempfile
import time
import urlparse
import zipfile
import random
import pytest
from infra.test_base import idparametrize
from infra.test_base import TestBase
from tools import firmware
from tools.atltoolper import AtlTool
from tools.command import Command
from tools.constants import (
NFS_SERVER, BUILDS_SERVER, FELICITY_CARDS, BERMUDA_CARDS, LINK_STATE_UP, LINK_STATE_DOWN, CARD_FIJI, CARD_NIKKI,
CARD_ANTIGUA, LINK_SPEED_AUTO, LINK_SPEED_10G, MDI_NORMAL, MDI_SWAP, LINK_STATE_UP, LINK_STATE_DOWN)
from tools.diagper import DiagWrapper, download_diag
from tools.driver import Driver, DRV_TYPE_DIAG, DRV_TYPE_DIAG_WIN_USB, DRV_TYPE_T6, DRV_TYPE_SRC_DIAG_LIN
from tools.firmware import Firmware, get_actual_fw_version, get_mac
from tools.killer import Killer
from tools.ops import OpSystem
from tools.utils import get_atf_logger, get_domain_bus_dev_func, get_url_response, remove_directory, str_to_bool
log = get_atf_logger()
datapath_seeds = os.environ.get("SEED").split(";") if os.environ.get("SEED", None) is not None else [123]
datapath_time = os.environ.get("TRAFFIC_TIME", 5)
def setup_module(module):
# import tools._test_setup # uncomment for manual test setup
os.environ["TEST"] = "flash_tools_test"
def download_from_url(suburl, directory, unzip=False):
url = urlparse.urljoin(BUILDS_SERVER, suburl)
fname = ntpath.basename(suburl)
log.debug("Downloading {} from {}".format(fname, url))
_file = os.path.join(directory, fname)
content = get_url_response(url)
if unzip:
with zipfile.ZipFile(io.BytesIO(content)) as archive:
archive.extractall(directory)
else:
with open(_file, "wb") as f:
f.write(content)
def download_fwtools(host, fwtools_local, a2_tools_version=False, fwtools_ver=None):
target_ops = OpSystem(host=host)
if target_ops.is_linux():
res = Command(cmd="uname -i", host=host).run()
if res["output"][0] == "aarch64":
platform = "linuxarm64"
else:
platform = "linux64"
elif target_ops.is_windows():
if target_ops.is_32_bit():
platform = "win32"
else:
platform = "win64"
elif target_ops.is_freebsd():
platform = "freebsd"
else:
raise Exception("Unsupported platform")
if fwtools_ver is None:
fwtools_ver = os.environ.get("FW_TOOLS", "latest")
tools_version = "atlantic2" if a2_tools_version else "atlantic"
fwtools_storage = "/storage/export/builds/tools/{}/{}/{}".format(tools_version, fwtools_ver, platform)
update_fwtools_cmd = "scp -r aqtest@{}:{}/* {}".format(NFS_SERVER, fwtools_storage, fwtools_local)
Command(cmd=update_fwtools_cmd, host=host).run()
if target_ops.is_linux():
Command(cmd='sync', host=host).run()
res = Command(cmd='{}/listDevices --help'.format(fwtools_local), host=host).run()
assert res['returncode'] == 0
def get_lspci_port(port):
domain, bus, dev, func = get_domain_bus_dev_func(port)
return "{:04x}-{:02x}:{:02x}.{:x}".format(domain, bus, dev, func)
def readstat(port, host=None, attempts=1):
lspci_port = get_lspci_port(port)
stats = {
"fw_version": {"value": None, "regexp": re.compile("Firmware Version = ([0-9.]+)")},
"mac": {"value": None, "regexp": re.compile("MAC address = ([0-9a-z:]+)")},
"vendor_id": {"value": None, "regexp": re.compile("Vendor ID = ([xA-Z0-9]+)")},
"device_id": {"value": None, "regexp": re.compile("Device ID = ([xA-Z0-9]+)")},
"subvid": {"value": None, "regexp": re.compile("Subsystem Vendor ID = ([a-zA-Z0-9]+)")},
"subdid": {"value": None, "regexp": re.compile("Subsystem Device ID = ([a-zA-Z0-9]+)")},
"lanes": {"value": None, "regexp": re.compile("PCIe Link Width = x(\d)")},
"pcirom": {"value": None, "regexp": re.compile("Oprom\sVersion\s=\s(\d+.\d+.\d+)")},
}
cmd = "sudo readstat -d {}".format(lspci_port)
for at in range(1, attempts + 1):
log.info("readstat #{}".format(at))
res = Command(cmd=cmd, host=host).wait(180)
if res["returncode"] != 0 or res["reason"] != Command.REASON_OK:
if at == attempts:
raise Exception("Failed to run readstat")
else:
log.info('Wait 10 sec...')
time.sleep(10)
else:
break
for line in res["output"]:
for key in stats:
s = stats[key]
if s["value"] is None:
m = s["regexp"].match(line)
if m is not None:
s["value"] = m.group(1)
continue
log.info('Readstat result:')
for key in stats:
log.info("{}: {}".format(key, stats[key]["value"]))
return stats
if os.environ.get("XAVIER_DUT_HOSTNAME", None) is not None:
from xavier_test import XavierTestBase
base_class = XavierTestBase
else:
base_class = TestBase
class TestFlashTools(base_class):
@classmethod
def setup_class(cls):
super(TestFlashTools, cls).setup_class()
try:
cls.log_server_dir = cls.create_logs_dir_on_log_server()
# Self protection, the test can't be run on FIJI
assert cls.dut_fw_card != CARD_FIJI
if base_class == TestBase:
if cls.state.skip_class_setup:
cls.skip_fw_install = True
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)
if not cls.state.skip_class_setup:
cls.dut_driver.install()
cls.lkp_driver.install()
if cls.dut_ops.is_windows():
cls.dut_diag_driver = Driver(port=cls.dut_port, drv_type=DRV_TYPE_DIAG, version=cls.dut_drv_version)
assert os.environ.get("OLD_DUT_FW_VERSION", None) is not None
cls.old_dut_fw_version = os.environ.get("OLD_DUT_FW_VERSION", None)
cls.old_dut_firmware = Firmware(
host=cls.dut_hostname, port=cls.dut_port, card=cls.dut_fw_card, speed=cls.dut_fw_speed,
version=cls.old_dut_fw_version, mdi=cls.dut_fw_mdi, mii=cls.dut_fw_mii,
pause=cls.dut_fw_pause, pcirom=cls.dut_fw_pcirom, dirtywake=cls.dut_fw_dirtywake,
bdp=cls.dut_bdp, sign=cls.dut_sign, se_enable=cls.dut_se, hsd=cls.dut_hsd)
cls.old_dut_fw_actual_version = get_actual_fw_version(cls.old_dut_fw_version)
cls.new_dut_fw_actual_version = get_actual_fw_version(cls.dut_fw_version)
cls.old_dut_clx_file = cls.old_dut_firmware.download()
cls.new_dut_clx_file = cls.dut_firmware.download()
cls.bb_name = os.environ.get("BB_NAME", None)
cls.t6_name = os.environ.get("T6_NAME", None)
cls.t6_port = os.environ.get("T6_PORT", None)
if cls.bb_name is not None:
cls.dut_iface_name = cls.bb_name
elif cls.t6_name is not None:
if cls.dut_ops.is_windows():
cls.t6_driver = Driver(port=cls.t6_port, drv_type=DRV_TYPE_T6, version="latest")
cls.t6_driver.install()
elif cls.dut_ops.is_linux():
Command(cmd="sudo rmmod ftdi_sio", host=cls.dut_hostname).run()
Command(cmd="sudo rmmod usbserial", host=cls.dut_hostname).run()
cls.dut_iface_name = cls.t6_name
else:
cls.dut_iface_name = get_lspci_port(cls.dut_port)
cls.dut_atltool_wrapper = AtlTool(port=cls.dut_port, host=cls.dut_hostname)
cls.fwtools_local = "/home/aqtest/fwtools"
for target in [cls.dut_hostname, cls.lkp_hostname]:
download_fwtools(host=target, fwtools_local=cls.fwtools_local)
if not cls.state.skip_class_setup:
cls.state.skip_class_setup = True
cls.state.update()
except Exception:
log.exception("Failed while setting up class")
raise
@classmethod
def teardown_class(cls):
super(TestFlashTools, cls).teardown_class()
Command(cmd="sudo rm -f *.clx", host=cls.dut_hostname).run()
def check_and_install_diag_drv(self):
if self.dut_ops.is_windows():
if self.dut_driver.is_installed():
log.info("<----- Remove NDIS driver ----->")
self.dut_driver.uninstall()
if not self.dut_diag_driver.is_installed():
log.info("<----- Install DIAG driver ----->")
self.dut_diag_driver.install()
def run_readstat(self):
stats = {
"fw_version": {"value": None, "regexp": re.compile("Firmware Version = ([0-9.]+)")},
"phy_fw_version": {"value": None,
"regexp": re.compile("PHY Firmware Version = ([0-9A-F.]+ VerStr: [0-9A-Za-z-.]+).*")},
"mac": {"value": None, "regexp": re.compile("MAC address = ([0-9a-z:]+)")},
"vendor_id": {"value": None, "regexp": re.compile("Vendor ID = ([xA-Z0-9]+)")},
"device_id": {"value": None, "regexp": re.compile("Device ID = ([xA-Z0-9]+)")},
"subvid": {"value": None, "regexp": re.compile("Subsystem Vendor ID = ([a-zA-Z0-9]+)")},
"subdid": {"value": None, "regexp": re.compile("Subsystem Device ID = ([a-zA-Z0-9]+)")},
"lanes": {"value": None, "regexp": re.compile("PCIe Link Width = x(\d)")},
}
cmd = "sudo {}/readstat -d {}".format(self.fwtools_local, self.dut_iface_name)
res = Command(cmd=cmd, host=self.dut_hostname).wait(180)
if res["returncode"] != 0 or res["reason"] != Command.REASON_OK:
raise Exception("Failed to run readstat")
for line in res["output"]:
for key in stats:
s = stats[key]
if s["value"] is None:
m = s["regexp"].match(line)
if m is not None:
s["value"] = m.group(1)
continue
log.info('Readstat result:')
for key in stats:
log.info("{}: {}".format(key, stats[key]["value"]))
return stats
def run_flash_erase(self):
cmd = "sudo {}/flashErase -d {}".format(self.fwtools_local, get_lspci_port(self.dut_port))
res = Command(cmd=cmd, host=self.dut_hostname).wait(180)
if res["returncode"] != 0 or res["reason"] != Command.REASON_OK:
raise Exception("Failed to run flashErase")
def run_flash_dump(self, out_file=None):
cmd = "sudo {}/flashDump -d {}".format(self.fwtools_local, self.dut_iface_name)
if out_file is not None:
cmd += " -o {}".format(out_file)
res = Command(cmd=cmd, host=self.dut_hostname).wait(180)
if res["returncode"] != 0 or res["reason"] != Command.REASON_OK:
raise Exception("Failed to run flashDump")
def run_flash_burn(self, clx_file, nocrc=False, exp_success=True):
cmd = "AQ_API_STOP_ON_FIRST_IMAGE_MISMATCH=1 {}/flashBurn -d {} {}".format(
self.fwtools_local, get_lspci_port(self.dut_port), clx_file)
if nocrc:
cmd += " -n"
cmd = "sudo bash -c \"{}\"".format(cmd)
res = Command(cmd=cmd, host=self.dut_hostname).wait(180)
if exp_success:
assert res["returncode"] == 0
assert any("Device burned and verified" in line for line in res["output"])
else:
assert res["returncode"] != 0
assert any("Error:" in line for line in res["output"])
def run_flash_override(self, ids=None, mac=None, check=True):
cmd = "sudo {}/flashOverride -d {}".format(self.fwtools_local, self.dut_iface_name)
if ids:
cmd += " -i {}".format(ids)
if mac:
cmd += " -m {}".format(mac)
res = Command(cmd=cmd, host=self.dut_hostname).wait(180)
if check:
if res["returncode"] != 0 or res["reason"] != Command.REASON_OK:
raise Exception("Failed to run flashOverride")
if "Override finished" not in res["output"][-1]:
raise Exception("Failed to run flashOverride")
return res
def run_flash_update(self, clx_file, bdp=False):
cmd = "sudo {}/flashUpdate -d {} {}".format(self.fwtools_local, self.dut_iface_name, clx_file)
if bdp:
cmd += " --bdp"
return Command(cmd=cmd, host=self.dut_hostname).wait(180)
def run_kickstart(self, phy=False):
cmd = "sudo {}/kickstart -d {}".format(self.fwtools_local, self.dut_iface_name)
if phy:
cmd += " --phy"
return Command(cmd=cmd, host=self.dut_hostname).wait(180)
# listDevices
def test_list_devices(self):
if self.bb_name is not None:
res = Command(cmd="sudo {}/listDevices -d BB".format(self.fwtools_local), host=self.dut_hostname).run()
assert res["returncode"] == 0, "Couldn't run listDevices"
assert any(self.bb_name in line for line in res['output'])
elif self.t6_name is not None:
res = Command(cmd="sudo {}/listDevices -d T6".format(self.fwtools_local), host=self.dut_hostname).run()
assert res["returncode"] == 0, "Couldn't run listDevices"
assert any(self.t6_name in line for line in res['output'])
else:
res = Command(cmd="lspci -D -d 1d6a:", host=self.dut_hostname).run()
assert res["returncode"] == 0, "Couldn't run lspci"
common_format = [line.split(' ')[0] for line in res["output"]]
new_format = [re.sub("^(\d+)(:)", "\g<1>-", d) for d in common_format]
res = Command(cmd="sudo {}/listDevices".format(self.fwtools_local), host=self.dut_hostname).run()
assert res["returncode"] == 0, "Couldn't run listDevices"
for d in new_format:
assert any(d in line for line in res["output"])
# readlog
def run_readlog(self, mode, log_file=None, phy=False):
if mode == "normal":
exec_bin = "readlog"
elif mode == "crypt":
exec_bin = "readlog_crypt"
elif mode == "phy":
exec_bin = "readphylog"
else:
raise Exception("Incorrect mode: {}. Possible values: normal, crypt, phy".format(mode))
cmd = "sudo {}/{} -d {}".format(self.fwtools_local, exec_bin, self.dut_iface_name)
if log_file is None:
log_file = "phy_dbg_buffer.bin" if mode == "phy" else "mac_dbg_buf.bin"
else:
cmd += " -f {}".format(log_file)
if phy:
cmd += " --phy"
readlog_cmd = Command(cmd=cmd, host=self.dut_hostname)
readlog_cmd.run_async()
self.dut_ifconfig.set_link_state(LINK_STATE_DOWN)
if self.dut_ops.is_linux():
self.dut_atltool_wrapper.kickstart(reload_phy_fw=self.dut_fw_card not in FELICITY_CARDS)
self.lkp_ifconfig.set_link_state(LINK_STATE_UP)
self.dut_ifconfig.set_link_state(LINK_STATE_UP)
self.dut_ifconfig.wait_link_up(retry_interval=2)
readlog_cmd.join(timeout=10)
Killer(host=self.dut_hostname).kill(exec_bin, excludes=['python'])
if mode == "normal":
cmd = "python qa-tests/tools/mcplog/mdbgtrace.py -f ./{}".format(log_file)
elif mode == "crypt":
cmd = "python qa-tests/tools/mcplog/mdbgtrace.py -e -f ./{}".format(log_file)
elif mode == "phy":
dbg_trace = "dbgtrace.py"
remote_file = "/storage/export/builds/firmware/{}/input/Nikki/default/{}".format(
self.dut_fw_version, dbg_trace)
Command(cmd='rm -f {}'.format(dbg_trace), host=self.dut_hostname).run()
res = Command(cmd="scp aqtest@{}:{} {}".format(NFS_SERVER, remote_file, dbg_trace),
host=self.dut_hostname).run()
assert res['returncode'] == 0, "Can't download dbgtrace file"
cmd = "python {} -m ble -f ./{}".format(dbg_trace, log_file)
res = Command(cmd=cmd, host=self.dut_hostname).run()
if not mode == 'phy':
# Can't read phy logs from the beginning
assert any(re.match(".*?Aquantia\s[A-Za-z]+\sF/W\sversion:\s[0-9.]+", line) for line in res["output"])
def test_readlog_no_options(self):
self.run_readlog(mode="normal")
def test_readlog_log_file(self):
self.run_readlog(mode="normal", log_file="mac_dbg_buf_log.bin")
def test_readlog_with_phy(self):
self.run_readlog(mode="normal", phy=True)
# readlog_crypt
def test_readlog_crypt_no_options(self):
self.run_readlog(mode="crypt")
def test_readlog_crypt_log_file(self):
self.run_readlog(mode="crypt", log_file='mac_dbg_buf_crypt.bin')
def test_readlog_crypt_with_phy(self):
self.run_readlog(mode="crypt", phy=True)
# readphylog
def test_readphylog_no_options(self):
self.run_readlog(mode="phy")
def test_readphylog_log_file(self):
self.run_readlog(mode="phy", log_file='phy_dbg_buf_log.bin')
# readefuse
def run_readefuse(self, options):
cmd = "sudo {}/readefuse -d {} {}".format(self.fwtools_local, self.dut_iface_name, options)
res = Command(cmd=cmd, host=self.dut_hostname, silent=True).run()
tool_res = []
for line in res["output"]:
m = re.match("eFuse\sdata\s+\d+\s=\s([xa-f0-9]+)", line)
if m is not None:
tool_res.append(int(m.group(1), 16))
return tool_res
def test_readefuse_no_options(self):
tool_res = self.run_readefuse(options="")
lib_res = self.dut_atltool_wrapper.load_efuse(0, 128)
assert tool_res == lib_res
def test_readefuse_start(self):
tool_res = self.run_readefuse(options="-s 60")
lib_res = self.dut_atltool_wrapper.load_efuse(60, 68)
assert tool_res == lib_res
def test_readefuse_number(self):
tool_res = self.run_readefuse(options="-n 100")
lib_res = self.dut_atltool_wrapper.load_efuse(0, 100)
assert tool_res == lib_res
def test_readefuse_start_number(self):
tool_res = self.run_readefuse(options="-s 60 -n 5")
lib_res = self.dut_atltool_wrapper.load_efuse(60, 5)
assert tool_res == lib_res
# tcpServer
def run_tcp_server(self):
if self.dut_ops.is_linux():
Command(cmd="sudo iptables -F && sudo iptables -X", host=self.dut_hostname).run()
if self.lkp_ops.is_linux():
Command(cmd="sudo iptables -F && sudo iptables -X", host=self.lkp_hostname).run()
Killer(host=self.dut_hostname).kill("tcpServer")
tcp_server_thread = Command(cmd="sudo {}/tcpServer -v".format(self.fwtools_local), host=self.dut_hostname)
tcp_server_thread.run_async()
time.sleep(5)
try:
# workaround for Xavier
res = Command(cmd="hostname", host=self.dut_hostname).run()
hostname = res["output"][0].strip()
res = Command(cmd="listDevices -d TCP", host=self.lkp_hostname).run()
if res["returncode"] != 0 or res["reason"] != Command.REASON_OK:
raise Exception("Failed to run listDevices")
server_found = False
for line in res["output"]:
if hostname in line:
server_found = True
if server_found and self.dut_iface_name in line:
tcp_port = line.strip()
break
else:
raise Exception("Can't find tcp server")
except Exception:
tcp_server_thread.join(1)
raise
return tcp_server_thread, tcp_port
def test_tcp_server_rr(self):
tcp_server_thread, tcp_port = self.run_tcp_server()
reg = 0x18
cmd = "sudo {}/atltool -d {} -rr {}".format(self.fwtools_local, tcp_port, reg)
tool_res = Command(cmd=cmd, host=self.lkp_hostname).run()
tcp_server_thread.join(1)
Killer(host=self.dut_hostname).kill("tcpServer")
assert tool_res["returncode"] == 0, "Couldn't run atltool"
re_mac_readreg = re.compile(r".*Register 0x[a-z0-9]+: (0x[a-z0-9]+) : [01\s]+")
for line in tool_res["output"]:
m = re_mac_readreg.match(line)
if m is not None:
tool_reg = int(m.group(1), 16)
break
else:
raise Exception("Can not parse the value of the register.")
lib_reg = self.dut_atltool_wrapper.readreg(reg)
assert tool_reg == lib_reg
def test_tcp_server_wr(self):
tcp_server_thread, tcp_port = self.run_tcp_server()
reg = 0x10C
reg_val = 0x10
cmd = "sudo {}/atltool -d {} -wr {} {}".format(self.fwtools_local, tcp_port, reg, reg_val)
tool_res = Command(cmd=cmd, host=self.lkp_hostname).run()
tcp_server_thread.join(1)
Killer(host=self.dut_hostname).kill("tcpServer")
assert tool_res["returncode"] == 0, "Couldn't run atltool"
lib_res = self.dut_atltool_wrapper.readreg(reg)
assert lib_res == reg_val
def test_tcp_server_rpr(self):
tcp_server_thread, tcp_port = self.run_tcp_server()
mmd, reg = 0x1e, 0x300
cmd = "sudo {}/atltool -d {} -rpr {}".format(self.fwtools_local, tcp_port, "0x{:X}.0x{:X}".format(mmd, reg))
tool_res = Command(cmd=cmd, host=self.lkp_hostname).run()
tcp_server_thread.join(1)
Killer(host=self.dut_hostname).kill("tcpServer")
assert tool_res["returncode"] == 0, "Couldn't run atltool"
re_phy_readreg = re.compile(r".*Register PHY \d 0x[0-9a-z.]+: (0x[0-9a-z.]+) : [01]+ [01]+")
for line in tool_res["output"]:
m = re_phy_readreg.match(line)
if m is not None:
tool_reg = int(m.group(1), 16)
break
else:
raise Exception("Can not parse the value of the register.")
lib_reg = self.dut_atltool_wrapper.readphyreg(mmd, reg)
assert tool_reg == lib_reg
def test_tcp_server_wpr(self):
tcp_server_thread, tcp_port = self.run_tcp_server()
mmd, reg = 0x1e, 0x300
val = 0x42
cmd = "sudo {}/atltool -d {} -wpr {} 0x{:X}".format(self.fwtools_local, tcp_port,
"0x{:X}.0x{:X}".format(mmd, reg), val)
tool_res = Command(cmd=cmd, host=self.lkp_hostname).run()
tcp_server_thread.join(1)
Killer(host=self.dut_hostname).kill("tcpServer")
assert tool_res["returncode"] == 0, "Couldn't run atltool"
lib_reg = self.dut_atltool_wrapper.readphyreg(mmd, reg)
assert lib_reg == val
# flashOverride
# # Flash erased
def test_flash_override_erased_mac_did_subvid_subdid(self):
"""
Tests FlashOverride
Initial state: Flash erased
Run with options: -m -i (Device id, SubVendor id, SubDevice id)
Expected result: "Error: No valid NCB detected in FLASH!"
"""
self.run_flash_erase()
new_mac = self.suggest_test_mac_address(self.dut_port, host=self.dut_hostname)
new_ids = "0x87B1:0xAAEE:0x0042"
res = self.run_flash_override(mac=new_mac, ids=new_ids, check=False)
assert any("Error: No valid NCB detected in FLASH!" in line for line in res["output"])
def test_flash_override_erased_mac_subvid_subdid(self):
"""
Tests FlashOverride
Initial state: Flash erased
Run with options: -m -i (SubVendor id, SubDevice id)
Expected result: "Error: No valid NCB detected in FLASH!"
"""
self.run_flash_erase()
new_mac = self.suggest_test_mac_address(self.dut_port, host=self.dut_hostname)
new_ids = "0xAAEE:0x0042"
res = self.run_flash_override(mac=new_mac, ids=new_ids, check=False)
assert any("Error: No valid NCB detected in FLASH!" in line for line in res["output"])
def test_flash_override_erased_mac(self):
"""
Tests FlashOverride
Initial state: Flash erased
Run with options: -m
Expected result: "Error: No valid NCB detected in FLASH!"
"""
self.run_flash_erase()
new_mac = self.suggest_test_mac_address(self.dut_port, host=self.dut_hostname)
res = self.run_flash_override(mac=new_mac, check=False)
assert any("Error: No valid NCB detected in FLASH!" in line for line in res["output"])
def test_flash_override_erased_did_subvid_subdid(self):
"""
Tests FlashOverride
Initial state: Flash erased
Run with options: -i (Device id, SubVendor id, SubDevice id)
Expected result: "Error: No valid NCB detected in FLASH!"
"""
self.run_flash_erase()
new_ids = "0x87B1:0xAAEE:0x0042"
res = self.run_flash_override(ids=new_ids, check=False)
assert any("Error: No valid NCB detected in FLASH!" in line for line in res["output"])
def test_flash_override_erased_subvid_subdid(self):
"""
Tests FlashOverride
Initial state: Flash erased
Run with options: -i (SubVendor id, SubDevice id)
Expected result: "Error: No valid NCB detected in FLASH!"
"""
self.run_flash_erase()
new_ids = "0xAAEE:0x0042"
res = self.run_flash_override(ids=new_ids, check=False)
assert any("Error: No valid NCB detected in FLASH!" in line for line in res["output"])
def test_flash_override_erased_no_options(self):
"""
Tests FlashOverride
Initial state: Flash erased
Run without options
Expected result: "Error: No valid NCB detected in FLASH!"
"""
self.run_flash_erase()
res = self.run_flash_override(check=False)
assert any("Error: No valid NCB detected in FLASH!" in line for line in res["output"])
# # Flash contains FW
def run_flash_override_with_fw(self, args):
if not self.state.skip_reboot:
self.state.skip_reboot = True
self.state.update()
try:
self.run_flash_burn(clx_file=self.old_dut_clx_file)
self.run_flash_override(**args)
except Exception:
self.state.skip_reboot = False
self.state.update()
raise
self.cold_restart(host=self.dut_hostname)
else:
self.state.skip_reboot = False
self.state.update()
return self.run_readstat()
def test_flash_override_with_fw_mac_subvid_subdid(self):
"""
Tests FlashOverride
Initial state: Flash contains FW
Run with options: -m -i (SubVendor id, SubDevice id)
Expected result: : Device id, SubVendor id, SubDevice id and mac address will be updated
"""
new_mac = self.suggest_test_mac_address(self.dut_port, host=self.dut_hostname)
new_ids = "0xAAEE:0x0042"
stats = self.run_flash_override_with_fw({"mac": new_mac, "ids": new_ids})
assert stats['subvid']['value'] == new_ids.split(':')[0]
assert stats['subdid']['value'] == new_ids.split(':')[1]
assert stats['mac']['value'] == new_mac
def test_flash_override_with_fw_mac_did_subvid_subdid(self):
"""
Tests FlashOverride
Initial state: Flash contains FW
Run with options: -m -i (Device id, SubVendor id, SubDevice id)
Expected result: : Device id, SubVendor id, SubDevice id and mac address will be updated
"""
new_mac = self.suggest_test_mac_address(self.dut_port, host=self.dut_hostname)
new_ids = "0x87B1:0xAAEE:0x0042"
stats = self.run_flash_override_with_fw({"mac": new_mac, "ids": new_ids})
assert stats['device_id']['value'] == new_ids.split(':')[0]
assert stats['subvid']['value'] == new_ids.split(':')[1]
assert stats['subdid']['value'] == new_ids.split(':')[2]
assert stats['mac']['value'] == new_mac
def test_flash_override_with_fw_mac(self):
"""
Tests FlashOverride
Initial state: Flash contains FW
Run with options: -m
Expected result: : mac address will be updated
"""
new_mac = self.suggest_test_mac_address(self.dut_port, host=self.dut_hostname)
stats = self.run_flash_override_with_fw({"mac": new_mac})
assert stats['mac']['value'] == new_mac
def test_flash_override_with_fw_did_subvid_subdid(self):
"""
Tests FlashOverride
Initial state: Flash contains FW
Run with options: -i (Device id, SubVendor id, SubDevice id)
Expected result: : Device id, SubVendor id, SubDevice id will be updated
"""
new_ids = "0x87B1:0xAAEE:0x0042"
stats = self.run_flash_override_with_fw({"ids": new_ids})
assert stats['device_id']['value'] == new_ids.split(':')[0]
assert stats['subvid']['value'] == new_ids.split(':')[1]
assert stats['subdid']['value'] == new_ids.split(':')[2]
def test_flash_override_with_fw_subvid_subdid(self):
"""
Tests FlashOverride
Initial state: Flash contains FW
Run with options: -i (SubVendor id, SubDevice id)
Expected result: : Device id, SubVendor id, SubDevice id and mac address will be updated
"""
new_ids = "0xAAEE:0x0042"
stats = self.run_flash_override_with_fw({"ids": new_ids})
assert stats['subvid']['value'] == new_ids.split(':')[0]
assert stats['subdid']['value'] == new_ids.split(':')[1]
def test_flash_override_with_fw_no_options(self):
"""
Tests FlashOverride
Initial state: Flash contains FW
Run with no options
Expected result: : nothing changes
"""
vendor_id_default = 0x1D6A
device_id_default = 0x07B1
mac_default = "00:17:b6:00:00:00"
stats = self.run_flash_override_with_fw({})
assert int(stats['vendor_id']['value'], 16) == vendor_id_default
assert int(stats['device_id']['value'], 16) == device_id_default
assert stats['mac']['value'] == mac_default
# flashBurn
def run_flash_burn_test(self, erased, corrupted, clx_size, exp_success, no_crc=False):
clx_size = int(clx_size)
if erased:
self.run_flash_erase()
else:
self.run_flash_burn(clx_file=self.old_dut_clx_file)
crptd_clx = 'ncb0_corrupted.clx'
cmd = "cp {} {}".format(self.new_dut_clx_file, crptd_clx)
Command(cmd=cmd, host=self.dut_hostname).run()
if corrupted:
cmd = "dd if=/dev/zero of={} bs=1 count=20 seek=10 conv=notrunc".format(crptd_clx)
Command(cmd=cmd, host=self.dut_hostname).run()
crptd_resize_clx = 'trnc_{}_{}'.format(clx_size, crptd_clx)
cmd = "dd if={} of={} bs=1K count={}".format(crptd_clx, crptd_resize_clx, clx_size)
Command(cmd=cmd, host=self.dut_hostname).run()
cmd = "dd if=/dev/zero of={} bs=1K count=0 seek={}".format(crptd_resize_clx, clx_size)
Command(cmd=cmd, host=self.dut_hostname).run()
self.run_flash_burn(clx_file=crptd_resize_clx, nocrc=no_crc, exp_success=exp_success)
# # Flash erased
# NCB0 corrupted
def test_flash_burn_erased_corrupted_low_2mb(self):
self.run_flash_burn_test(erased=True, corrupted=True, clx_size=1500, exp_success=False)
def test_flash_burn_erased_corrupted_eq_2mb(self):
self.run_flash_burn_test(erased=True, corrupted=True, clx_size=1024 * 2, exp_success=False)
def test_flash_burn_erased_corrupted_more_2mb(self):
self.run_flash_burn_test(erased=True, corrupted=True, clx_size=1024 * 2.5, exp_success=False)
# NCB0 not corrupted
def test_flash_burn_erased_not_corrupted_low_2mb(self):
self.run_flash_burn_test(erased=True, corrupted=False, clx_size=1500, exp_success=True)
def test_flash_burn_erased_not_corrupted_eq_2mb(self):
self.run_flash_burn_test(erased=True, corrupted=False, clx_size=1024 * 2, exp_success=True)
def test_flash_burn_erased_not_corrupted_more_2mb(self):
self.run_flash_burn_test(erased=True, corrupted=False, clx_size=1024 * 2.5, exp_success=True)
# # Flash contains FW
# NCB0 corrupted
def test_flash_burn_not_erased_corrupted_low_2mb(self):
self.run_flash_burn_test(erased=False, corrupted=True, clx_size=1500, exp_success=False)
def test_flash_burn_not_erased_corrupted_eq_2mb(self):
self.run_flash_burn_test(erased=False, corrupted=True, clx_size=1024 * 2, exp_success=False)
def test_flash_burn_not_erased_corrupted_more_2mb(self):
self.run_flash_burn_test(erased=False, corrupted=True, clx_size=1024 * 2.5, exp_success=False)
# NCB0 not corrupted
def test_flash_burn_not_erased_not_corrupted_low_2mb(self):
self.run_flash_burn_test(erased=False, corrupted=False, clx_size=1500, exp_success=True)
def test_flash_burn_not_erased_not_corrupted_eq_2mb(self):
self.run_flash_burn_test(erased=False, corrupted=False, clx_size=1024 * 2, exp_success=True)
def test_flash_burn_not_erased_not_corrupted_more_2mb(self):
self.run_flash_burn_test(erased=False, corrupted=False, clx_size=1024 * 2.5, exp_success=True)
# # # No CRC
# # Flash erased
# NCB0 corrupted
def test_flash_burn_erased_corrupted_nocrc_low_2mb(self):
self.run_flash_burn_test(erased=True, corrupted=True, clx_size=1500, exp_success=True, no_crc=True)
def test_flash_burn_erased_corrupted_nocrc_eq_2mb(self):
self.run_flash_burn_test(erased=True, corrupted=True, clx_size=1024 * 2, exp_success=True, no_crc=True)
def test_flash_burn_erased_corrupted_nocrc_more_2mb(self):
self.run_flash_burn_test(erased=True, corrupted=True, clx_size=1024 * 2.5, exp_success=True, no_crc=True)
# NCB0 not corrupted
def test_flash_burn_erased_not_corrupted_nocrc_low_2mb(self):
self.run_flash_burn_test(erased=True, corrupted=False, clx_size=1500, exp_success=True, no_crc=True)
def test_flash_burn_erased_not_corrupted_nocrc_eq_2mb(self):
self.run_flash_burn_test(erased=True, corrupted=False, clx_size=1024 * 2, exp_success=True, no_crc=True)
def test_flash_burn_erased_not_corrupted_nocrc_more_2mb(self):
self.run_flash_burn_test(erased=True, corrupted=False, clx_size=1024 * 2.5, exp_success=True, no_crc=True)
# # Flash contains FW
# NCB0 corrupted
def test_flash_burn_not_erased_corrupted_nocrc_low_2mb(self):
self.run_flash_burn_test(erased=False, corrupted=True, clx_size=1500, exp_success=True, no_crc=True)
def test_flash_burn_not_erased_corrupted_nocrc_eq_2mb(self):
self.run_flash_burn_test(erased=False, corrupted=True, clx_size=1024 * 2, exp_success=True, no_crc=True)
def test_flash_burn_not_erased_corrupted_nocrc_more_2mb(self):
self.run_flash_burn_test(erased=False, corrupted=True, clx_size=1024 * 2.5, exp_success=True, no_crc=True)
# NCB0 not corrupted
def test_flash_burn_not_erased_not_corrupted_nocrc_low_2mb(self):
self.run_flash_burn_test(erased=False, corrupted=False, clx_size=1500, exp_success=True, no_crc=True)
def test_flash_burn_not_erased_not_corrupted_nocrc_eq_2mb(self):
self.run_flash_burn_test(erased=False, corrupted=False, clx_size=1024 * 2, exp_success=True, no_crc=True)
def test_flash_burn_not_erased_not_corrupted_nocrc_more_2mb(self):
self.run_flash_burn_test(erased=False, corrupted=False, clx_size=1024 * 2.5, exp_success=True, no_crc=True)
# flashUpdadte
MAC_IRAM_POINTER = 0x2c, 3
PHY_IRAM_POINTER = 0x40, 3
PCI_ROM_POINTER = 0x54, 3
PCI_CFG_POINTER = 0x24, 2
def corrupt_clx(self, clx_file, ncb_num, ptr, shift_offset=0):
ptr_addr = ptr[0]
ptr_size = ptr[1]
if ncb_num == 1:
ptr_addr += 0x4000
# Read Pointer
cmd = "xxd -s {} -l {} -e {} | awk '{{print $2}}'".format(ptr_addr, ptr_size, clx_file)
res = Command(cmd=cmd, host=self.dut_hostname).run()
offset = int(res["output"][0], 16)
offset += shift_offset
# Corrupt block
crptd_clx = 'ncb{}_block_0x{:02x}_corrupted.clx'.format(ncb_num, ptr_addr)
cmd = "cp {} {}".format(clx_file, crptd_clx)
Command(cmd=cmd, host=self.dut_hostname).run()
# cmd = "dd if=/dev/urandom of={} bs=1 count=20 seek={} conv=notrunc".format(crptd_clx, offset)
cmd = "tr '\\0' '\\377' < /dev/zero | dd of={} bs=1 count=20 seek={} conv=notrunc".format(crptd_clx, offset)
Command(cmd=cmd, host=self.dut_hostname).run()
return crptd_clx
# Corrupted NCB0
def test_flash_update_corrupted_mac_fw_ncb0_bdp_on(self):
self.run_flash_burn(clx_file=self.old_dut_clx_file)
crptd_clx = self.corrupt_clx(self.new_dut_clx_file, ncb_num=0, ptr=self.MAC_IRAM_POINTER)
res = self.run_flash_update(clx_file=crptd_clx, bdp=True)
assert all([
any("Error: MAC FW 0 is corrupted" in line for line in res["output"]),
any("Using NCB1 from CLX image" in line for line in res["output"]),
any("Updating BDP in FLASH from CLX image" in line for line in res["output"]),
])
def test_flash_update_corrupted_mac_fw_ncb0_bdp_off(self):
self.run_flash_burn(clx_file=self.old_dut_clx_file)
crptd_clx = self.corrupt_clx(self.new_dut_clx_file, ncb_num=0, ptr=self.MAC_IRAM_POINTER)
res = self.run_flash_update(clx_file=crptd_clx, bdp=False)
assert all([
any("Error: MAC FW 0 is corrupted" in line for line in res["output"]),
any("Using NCB1 from CLX image" in line for line in res["output"]),
all("Updating BDP in FLASH from CLX image" not in line for line in res["output"]),
])
def test_flash_update_corrupted_phy_fw_ncb0_bdp_on(self):
self.run_flash_burn(clx_file=self.old_dut_clx_file)
crptd_clx = self.corrupt_clx(self.new_dut_clx_file, ncb_num=0, ptr=self.PHY_IRAM_POINTER)
res = self.run_flash_update(clx_file=crptd_clx, bdp=True)
assert all([
any("Error: PHY FW 0 is corrupted" in line for line in res["output"]),
any("Using NCB1 from CLX image" in line for line in res["output"]),
any("Updating BDP in FLASH from CLX image" in line for line in res["output"]),
])
def test_flash_update_corrupted_phy_fw_ncb0_bdp_off(self):
self.run_flash_burn(clx_file=self.old_dut_clx_file)
crptd_clx = self.corrupt_clx(self.new_dut_clx_file, ncb_num=0, ptr=self.PHY_IRAM_POINTER)
res = self.run_flash_update(clx_file=crptd_clx, bdp=False)
assert all([
any("Error: PHY FW 0 is corrupted" in line for line in res["output"]),
any("Using NCB1 from CLX image" in line for line in res["output"]),
all("Updating BDP in FLASH from CLX image" not in line for line in res["output"]),
])
def test_flash_update_corrupted_pci_rom_ncb0_bdp_on(self):
self.run_flash_burn(clx_file=self.old_dut_clx_file)
crptd_clx = self.corrupt_clx(self.new_dut_clx_file, ncb_num=0, ptr=self.PCI_ROM_POINTER)
res = self.run_flash_update(clx_file=crptd_clx, bdp=True)
assert all([
any("Error: PCI Option ROM 0 is corrupted" in line for line in res["output"]),
any("Using NCB1 from CLX image" in line for line in res["output"]),
any("Updating BDP in FLASH from CLX image" in line for line in res["output"]),
])
def test_flash_update_corrupted_pci_rom_ncb0_bdp_off(self):
self.run_flash_burn(clx_file=self.old_dut_clx_file)
crptd_clx = self.corrupt_clx(self.new_dut_clx_file, ncb_num=0, ptr=self.PCI_ROM_POINTER)
res = self.run_flash_update(clx_file=crptd_clx, bdp=False)
assert all([
any("Error: PCI Option ROM 0 is corrupted" in line for line in res["output"]),
any("Using NCB1 from CLX image" in line for line in res["output"]),
all("Updating BDP in FLASH from CLX image" not in line for line in res["output"]),
])
# Corrupted NCB1
@pytest.mark.xfail(reason="There are no messages about NCB1")
def test_flash_update_corrupted_mac_fw_ncb1_bdp_on(self):
self.run_flash_burn(clx_file=self.old_dut_clx_file)
crptd_clx = self.corrupt_clx(self.new_dut_clx_file, ncb_num=1, ptr=self.MAC_IRAM_POINTER)
res = self.run_flash_update(clx_file=crptd_clx, bdp=True)
assert all([
any("Error: MAC FW 1 is corrupted" in line for line in res["output"]),
any("Using NCB0 from CLX image" in line for line in res["output"]),
any("Updating BDP in FLASH from CLX image" in line for line in res["output"]),
])
@pytest.mark.xfail(reason="There are no messages about NCB1")
def test_flash_update_corrupted_mac_fw_ncb1_bdp_off(self):
self.run_flash_burn(clx_file=self.old_dut_clx_file)
crptd_clx = self.corrupt_clx(self.new_dut_clx_file, ncb_num=1, ptr=self.MAC_IRAM_POINTER)
res = self.run_flash_update(clx_file=crptd_clx, bdp=False)
assert all([
any("Error: MAC FW 1 is corrupted" in line for line in res["output"]),
any("Using NCB0 from CLX image" in line for line in res["output"]),
all("Updating BDP in FLASH from CLX image" not in line for line in res["output"]),
])