-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdiag_select_dev.py
792 lines (734 loc) · 41.5 KB
/
diag_select_dev.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
import os
import re
from time import sleep
import pytest
from tools.command import Command
from tools.diagper import DiagWrapper, download_diag, get_actual_diag_version, uninstall_diag
from tools import driver
from infra.test_base import TestBase, idparametrize
from tools.ops import get_arch, OpSystem
from tools.utils import remove_directory, get_atf_logger
log = get_atf_logger()
diag_timeout = 30
pause = 5
def setup_module(module):
# import tools._test_setup # uncomment for manual test setup
os.environ["TEST"] = "diag_select_dev"
class TestDiag(TestBase):
@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_first_dev.install_trusted_certificate(cert)
cls.diag_drv_second_dev.install_trusted_certificate(cert)
@classmethod
def setup_class(cls):
# init from base class
super(TestDiag, cls).setup_class()
try:
cls.log_server_dir = cls.create_logs_dir_on_log_server()
cls.os = OpSystem()
cls.install_firmwares()
# uninstall previously installed diag on linux to be able to install rpm or deb
if cls.os.is_linux():
uninstall_diag()
cls.diag_dir = download_diag(cls.diag_version)
cls.diag_ver = get_actual_diag_version(cls.diag_version)
if len(cls.dut_card_dict) == 0:
raise Exception("There isn't a dictionary of cards and ports")
elif len(cls.dut_card_dict) == 1:
raise Exception("This is multiple device test, more than one card required")
else:
cls.first_port = cls.dut_card_dict.keys()[0]
cls.second_port = cls.dut_card_dict.keys()[1]
cls.first_dev_id = cls.dut_card_dict[cls.first_port]
cls.second_dev_id = cls.dut_card_dict[cls.second_port]
cls.diag_drv_first_dev = driver.Driver(port=cls.first_port, drv_type=driver.DRV_TYPE_DIAG,
version=cls.dut_drv_version)
cls.prod_drv_first_dev = driver.Driver(port=cls.first_port, version=cls.dut_drv_version)
cls.diag_drv_second_dev = driver.Driver(port=cls.second_port, drv_type=driver.DRV_TYPE_DIAG,
version=cls.dut_drv_version)
cls.prod_drv_second_dev = driver.Driver(port=cls.second_port, version=cls.dut_drv_version)
cls.diag_drv_first_dev.install()
cls.diag_drv_second_dev.install()
cls.first_port = cls.first_port.replace("00", "0")
cls.second_port = cls.second_port.replace("00", "0")
DiagWrapper.exec_single("--flash_fields dev_id={} -p -d {} --password !h:ahT8uW6"
"".format(cls.first_dev_id, cls.first_port),
cls.diag_dir)
DiagWrapper.exec_single("--flash_fields dev_id={} -p -d {} --password !h:ahT8uW6"
"".format(cls.second_dev_id, cls.second_port),
cls.diag_dir)
if cls.os.is_windows():
cls.add_diag_drv_cert(cls.diag_dir)
except Exception as e:
log.exception("Failed while setting up class")
raise e
@classmethod
def teardown_class(cls):
super(TestDiag, cls).teardown_class()
if cls.os.is_linux():
uninstall_diag()
else:
remove_directory(cls.diag_dir)
def setup_method(self, method):
super(TestDiag, self).setup_method(method)
log.info("Uninstalling drivers of first device")
while self.prod_drv_first_dev.is_installed() or self.diag_drv_first_dev.is_installed():
self.diag_drv_first_dev.uninstall()
self.prod_drv_first_dev.uninstall()
log.info("Uninstalling drivers of second device")
while self.prod_drv_second_dev.is_installed() or self.diag_drv_second_dev.is_installed():
self.diag_drv_second_dev.uninstall()
self.prod_drv_second_dev.uninstall()
def is_in_output(self, output, exp_res):
output = ' '.join(output)
result = re.findall(exp_res, output)
return len(result) != 0
def check_two_devices_in_output(self, output):
exp_res = r"".join([self.first_port, ".{1,30}", self.second_port])
assert self.is_in_output(output, exp_res), "Two cards must be represented"
def check_return_code(self, com):
assert com.result["returncode"] == 0, "Error, Diag exits with return code {}".format(com.result["returncode"])
def test_no_drv_on_both_dev(self):
log.info("Running Diag...")
d = DiagWrapper(self.diag_dir, "--raise")
com = Command(cmd=d.cmd)
com.run_async()
com.join(timeout=diag_timeout)
assert self.is_in_output(com.result["output"], 'No devices found! Diag driver is probably not installed '
'[(use "-k" or "-s" option to install)]'), "Diag tool cannot run without any driver"
def test_diag_drv_on_dev1_and_prod_drv_on_dev2(self):
self.diag_drv_first_dev.install()
self.prod_drv_second_dev.install()
log.info("Running Diag...")
d = DiagWrapper(self.diag_dir, "--raise")
com = Command(cmd=d.cmd)
com.run_async()
sleep(pause)
com.send_stdin([DiagWrapper.CMD_DICT["Select device"],
DiagWrapper.CMD_DICT["Go back to main menu"],
DiagWrapper.CMD_DICT["Exit"]])
com.join(timeout=diag_timeout)
self.check_return_code(com)
self.check_two_devices_in_output(com.result["output"])
# TODO: check that if you select second device, diag tool ask you to run with option -s/-k
def test_prod_drv_on_dev1_and_diag_drv_on_dev2(self):
self.prod_drv_first_dev.install()
self.diag_drv_second_dev.install()
log.info("Running Diag...")
d = DiagWrapper(self.diag_dir, "--raise")
com = Command(cmd=d.cmd)
com.run_async()
com.join(timeout=diag_timeout)
assert ('Device {} is found, but diag driver is not installed '
'(use "-k" or "-s" option to install). Diag driver is installed on {} (use "-d").' \
.format(self.first_port, self.second_port) in " ".join(com.result["output"]))
def test_diag_drv_on_both_dev(self):
self.diag_drv_first_dev.install()
self.diag_drv_second_dev.install()
log.info("Running Diag...")
d = DiagWrapper(self.diag_dir, "--raise")
com = Command(cmd=d.cmd)
com.run_async()
sleep(pause)
com.send_stdin([DiagWrapper.CMD_DICT["Select device"],
DiagWrapper.CMD_DICT["Go back to main menu"],
DiagWrapper.CMD_DICT["Exit"]])
com.join(timeout=diag_timeout)
self.check_return_code(com)
self.check_two_devices_in_output(com.result["output"])
def test_prod_drv_on_both_dev(self):
self.prod_drv_first_dev.install()
self.prod_drv_second_dev.install()
log.info("Running Diag...")
d = DiagWrapper(self.diag_dir, "--raise")
com = Command(cmd=d.cmd)
com.run_async()
com.join(timeout=diag_timeout)
assert self.is_in_output(com.result["output"], 'No devices found! Diag driver is probably not installed '
'[(use "-k" or "-s" option to install)]'), "Diag tool cannot run without any diag driver"
def test_diag_drv_on_dev1(self):
self.diag_drv_first_dev.install()
log.info("Running Diag...")
d = DiagWrapper(self.diag_dir, "--raise")
com = Command(cmd=d.cmd)
com.run_async()
sleep(pause)
com.send_stdin([DiagWrapper.CMD_DICT["Select device"],
DiagWrapper.CMD_DICT["Go back to main menu"],
DiagWrapper.CMD_DICT["Exit"]])
com.join(timeout=diag_timeout)
self.check_return_code(com)
self.check_two_devices_in_output(com.result["output"])
# TODO: check that if you select second device, diag tool ask you to run with option -s/-k
def test_diag_drv_on_dev2(self):
self.diag_drv_second_dev.install()
log.info("Running Diag...")
d = DiagWrapper(self.diag_dir, "--raise")
com = Command(cmd=d.cmd)
com.run_async()
com.join(timeout=diag_timeout)
assert ('Device {} is found, but diag driver is not installed '
'(use "-k" or "-s" option to install). Diag driver is installed on {} (use "-d").' \
.format(self.first_port, self.second_port) in " ".join(com.result["output"]))
def test_prod_drv_on_dev1(self):
self.prod_drv_first_dev.install()
log.info("Running Diag...")
d = DiagWrapper(self.diag_dir, "--raise")
com = Command(cmd=d.cmd)
com.run_async()
sleep(pause)
com.join(timeout=diag_timeout)
assert self.is_in_output(com.result["output"], 'No devices found! Diag driver is probably not installed '
'[(use "-k" or "-s" option to install)]'), "Diag tool cannot run without any diag driver"
def test_prod_drv_on_dev2(self):
self.prod_drv_second_dev.install()
log.info("Running Diag...")
d = DiagWrapper(self.diag_dir, "--raise")
com = Command(cmd=d.cmd)
com.run_async()
com.join(timeout=diag_timeout)
assert self.is_in_output(com.result["output"], 'No devices found! Diag driver is probably not installed '
'[(use "-k" or "-s" option to install)]'), "Diag tool cannot run without any diag driver"
def test_show_dev1(self):
self.diag_drv_first_dev.install()
self.diag_drv_second_dev.install()
log.info("Running Diag...")
d = DiagWrapper(self.diag_dir, "--raise")
com = Command(cmd=d.cmd)
com.run_async()
sleep(pause)
com.send_stdin([DiagWrapper.CMD_DICT["Select device"],
DiagWrapper.CMD_DICT["Select 1 device"],
DiagWrapper.CMD_DICT["Select device"],
DiagWrapper.CMD_DICT["Go back to main menu"],
DiagWrapper.CMD_DICT["Device Info"],
DiagWrapper.CMD_DICT["Enter"],
DiagWrapper.CMD_DICT["Exit"]])
com.join(timeout=diag_timeout)
before_select_dev = r"".join([self.first_port, ".{1,30}",
self.second_port])
after_select_dev = r"".join([self.first_port, ".*[(Selected)].*",
self.second_port])
exp_res = r"".join([before_select_dev, ".*", after_select_dev])
exp_dev_id = r"".join(["Device ID = ", self.first_dev_id])
self.check_return_code(com)
self.check_two_devices_in_output(com.result["output"])
assert self.is_in_output(com.result["output"], exp_res), "First device must be selected"
assert self.is_in_output(com.result["output"], exp_dev_id), "First device ID must be in Device Info"
def test_show_dev2(self):
self.diag_drv_first_dev.install()
self.diag_drv_second_dev.install()
log.info("Running Diag...")
d = DiagWrapper(self.diag_dir, "--raise")
com = Command(cmd=d.cmd)
com.run_async()
sleep(pause)
com.send_stdin([DiagWrapper.CMD_DICT["Select device"],
DiagWrapper.CMD_DICT["Select 2 device"],
DiagWrapper.CMD_DICT["Select device"],
DiagWrapper.CMD_DICT["Go back to main menu"],
DiagWrapper.CMD_DICT["Device Info"],
DiagWrapper.CMD_DICT["Enter"],
DiagWrapper.CMD_DICT["Exit"]])
com.join(timeout=diag_timeout)
before_select_dev = r"".join([self.first_port, ".{1,30}",
self.second_port])
after_select_dev = r"".join([self.first_port, ".*",
self.second_port, ".*[(Selected)]"])
exp_res = r"".join([before_select_dev, ".*", after_select_dev])
exp_dev_id = r"".join(["Device ID = ", self.second_dev_id])
self.check_return_code(com)
self.check_two_devices_in_output(com.result["output"])
assert self.is_in_output(com.result["output"], exp_res), "Second device must be selected"
assert self.is_in_output(com.result["output"], exp_dev_id), "Second device ID must be in Device Info"
def test_show_dev1_after_dev2(self):
self.diag_drv_first_dev.install()
self.diag_drv_second_dev.install()
log.info("Running Diag...")
d = DiagWrapper(self.diag_dir, "--raise")
com = Command(cmd=d.cmd)
com.run_async()
sleep(pause)
com.send_stdin([DiagWrapper.CMD_DICT["Select device"],
DiagWrapper.CMD_DICT["Select 2 device"],
DiagWrapper.CMD_DICT["Device Info"],
DiagWrapper.CMD_DICT["Enter"],
DiagWrapper.CMD_DICT["Select device"],
DiagWrapper.CMD_DICT["Select 1 device"],
DiagWrapper.CMD_DICT["Device Info"],
DiagWrapper.CMD_DICT["Enter"],
DiagWrapper.CMD_DICT["Select device"],
DiagWrapper.CMD_DICT["Go back to main menu"],
DiagWrapper.CMD_DICT["Exit"]])
com.join(timeout=diag_timeout)
before_select_dev = r"".join([self.first_port, ".{1,30}",
self.second_port])
after_select_second_dev = r"".join([self.first_port, ".*",
self.second_port, ".*[(Selected)]"])
after_select_first_dev = r"".join([self.first_port, ".*[(Selected)].*",
self.second_port])
exp_res = r"".join([before_select_dev, ".*", after_select_second_dev, ".*", after_select_first_dev])
exp_dev_ids = r"".join(["Device ID = ", self.second_dev_id, ".*", "Device ID = ", self.first_dev_id])
self.check_return_code(com)
self.check_two_devices_in_output(com.result["output"])
assert self.is_in_output(com.result["output"], exp_res), "Second device must be selected after the firsts" \
" one was selected"
assert self.is_in_output(com.result["output"], exp_dev_ids), "First device ID must be in Device Info " \
"after the firsts one was selected"
def test_show_dev2_after_dev1(self):
self.diag_drv_first_dev.install()
self.diag_drv_second_dev.install()
log.info("Running Diag...")
d = DiagWrapper(self.diag_dir, "--raise")
com = Command(cmd=d.cmd)
com.run_async()
sleep(pause)
com.send_stdin([DiagWrapper.CMD_DICT["Select device"],
DiagWrapper.CMD_DICT["Select 1 device"],
DiagWrapper.CMD_DICT["Device Info"],
DiagWrapper.CMD_DICT["Enter"],
DiagWrapper.CMD_DICT["Select device"],
DiagWrapper.CMD_DICT["Select 2 device"],
DiagWrapper.CMD_DICT["Device Info"],
DiagWrapper.CMD_DICT["Enter"],
DiagWrapper.CMD_DICT["Select device"],
DiagWrapper.CMD_DICT["Go back to main menu"],
DiagWrapper.CMD_DICT["Exit"]])
com.join(timeout=diag_timeout)
before_select_dev = r"".join([self.first_port, ".{1,30}",
self.second_port])
after_select_first_dev = r"".join([self.first_port, ".*[(Selected)].*",
self.second_port])
after_select_second_dev= r"".join([self.first_port, ".*",
self.second_port, ".*[(Selected)]"])
exp_res = r"".join([before_select_dev, ".*", after_select_first_dev, ".*", after_select_second_dev])
exp_dev_ids = r"".join(["Device ID = ", self.first_dev_id, ".*", "Device ID = ", self.second_dev_id])
self.check_return_code(com)
self.check_two_devices_in_output(com.result["output"])
assert self.is_in_output(com.result["output"], exp_res), "Second device must be selected after the firsts" \
" one was selected"
assert self.is_in_output(com.result["output"], exp_dev_ids), "First device ID must be in Device Info " \
"after the firsts one was selected"
def test_show_dev1_with_opt_d_pciport(self):
self.diag_drv_first_dev.install()
self.diag_drv_second_dev.install()
log.info("Running Diag...")
d = DiagWrapper(self.diag_dir, "-d {} --raise".format(self.first_port))
com = Command(cmd=d.cmd)
com.run_async()
sleep(pause)
com.send_stdin([DiagWrapper.CMD_DICT["Select device"],
DiagWrapper.CMD_DICT["Go back to main menu"],
DiagWrapper.CMD_DICT["Device Info"],
DiagWrapper.CMD_DICT["Enter"],
DiagWrapper.CMD_DICT["Exit"]])
com.join(timeout=diag_timeout)
exp_res = r"".join([self.first_port, ".*[(Selected)].*",
self.second_port])
exp_dev_id = r"".join(["Device ID = ", self.first_dev_id])
self.check_return_code(com)
assert self.is_in_output(com.result["output"], exp_res), "First device must be selected"
assert self.is_in_output(com.result["output"], exp_dev_id), "First device ID must be in Device Info"
def test_show_dev2_with_opt_d_index(self):
self.diag_drv_first_dev.install()
self.diag_drv_second_dev.install()
log.info("Running Diag...")
d = DiagWrapper(self.diag_dir, "-d 1 --raise")
com = Command(cmd=d.cmd)
com.run_async()
sleep(pause)
com.send_stdin([DiagWrapper.CMD_DICT["Select device"],
DiagWrapper.CMD_DICT["Go back to main menu"],
DiagWrapper.CMD_DICT["Device Info"],
DiagWrapper.CMD_DICT["Enter"],
DiagWrapper.CMD_DICT["Exit"]])
com.join(timeout=diag_timeout)
exp_res = r"".join([self.first_port, ".{1,30}",
self.second_port, ".*[(Selected)]"])
exp_dev_id = r"".join(["Device ID = ", self.second_dev_id])
self.check_return_code(com)
assert self.is_in_output(com.result["output"], exp_res), "Second device must be selected"
assert self.is_in_output(com.result["output"], exp_dev_id), "Second device ID must be in Device Info"
def test_show_dev1_with_opt_d_port_and_s(self):
log.info("Running Diag...")
d = DiagWrapper(self.diag_dir, "-d {} -s --raise".format(self.first_port.replace("pci", "")))
com = Command(cmd=d.cmd)
com.run_async()
sleep(10)
assert self.diag_drv_first_dev.is_installed(), "Diag driver must be installed on first device during diag"
assert not self.diag_drv_second_dev.is_installed(), "Diag driver must not be installed on second device " \
"during diag"
sleep(pause)
com.send_stdin([DiagWrapper.CMD_DICT["Select device"],
DiagWrapper.CMD_DICT["Go back to main menu"],
DiagWrapper.CMD_DICT["Device Info"],
DiagWrapper.CMD_DICT["Enter"],
DiagWrapper.CMD_DICT["Exit"]])
com.join(timeout=diag_timeout)
exp_res = r"".join([self.first_port, " [(Selected)]"])
exp_dev_id = r"".join(["Device ID = ", self.first_dev_id])
self.check_return_code(com)
sleep(pause)
assert self.is_in_output(com.result["output"], exp_res), "First device must be selected"
assert self.is_in_output(com.result["output"], exp_dev_id), "First device ID must be in Device Info"
def test_show_dev2_with_opt_d_pciport_and_s(self):
log.info("Running Diag...")
d = DiagWrapper(self.diag_dir, "-d {} -s --raise".format(self.second_port))
com = Command(cmd=d.cmd)
com.run_async()
assert self.diag_drv_second_dev.is_installed(), "Diag driver must be installed on second device during diag"
assert not self.diag_drv_first_dev.is_installed(), "Diag driver must not be installed on first device " \
"during diag"
sleep(pause)
com.send_stdin([DiagWrapper.CMD_DICT["Select device"],
DiagWrapper.CMD_DICT["Go back to main menu"],
DiagWrapper.CMD_DICT["Device Info"],
DiagWrapper.CMD_DICT["Enter"],
DiagWrapper.CMD_DICT["Exit"]])
com.join(timeout=diag_timeout)
exp_res = r"".join([self.second_port, " [(Selected)]"])
exp_dev_id = r"".join(["Device ID = ", self.second_dev_id])
self.check_return_code(com)
assert self.is_in_output(com.result["output"], exp_res), "Second device must be selected"
assert self.is_in_output(com.result["output"], exp_dev_id), "Second device ID must be in Device Info"
def test_show_dev1_with_opt_d_index_and_s_when_dev2_has_prod_drv(self):
self.prod_drv_second_dev.install()
log.info("Running Diag...")
d = DiagWrapper(self.diag_dir, "-d 0 -s --raise")
com = Command(cmd=d.cmd)
com.run_async()
assert self.diag_drv_first_dev.is_installed(), "Diag driver must be installed on first device during diag"
assert not self.diag_drv_second_dev.is_installed(), "Diag driver must not be installed on second device " \
"during diag"
sleep(pause)
com.send_stdin([DiagWrapper.CMD_DICT["Select device"],
DiagWrapper.CMD_DICT["Go back to main menu"],
DiagWrapper.CMD_DICT["Device Info"],
DiagWrapper.CMD_DICT["Enter"],
DiagWrapper.CMD_DICT["Exit"]])
com.join(timeout=diag_timeout)
exp_res = r"".join([self.first_port, " [(Selected)]"])
exp_dev_id = r"".join(["Device ID = ", self.first_dev_id])
self.check_return_code(com)
assert self.is_in_output(com.result["output"], exp_res), "First device must be selected"
assert self.is_in_output(com.result["output"], exp_dev_id), "First device ID must be in Device Info"
def test_show_dev2_with_opt_d_port_and_s_when_dev1_has_prod_drv(self):
self.prod_drv_first_dev.install()
log.info("Running Diag...")
d = DiagWrapper(self.diag_dir, "-d {} -s --raise".format(self.second_port.replace("pci", "")))
com = Command(cmd=d.cmd)
com.run_async()
assert self.diag_drv_second_dev.is_installed(), "Diag driver must be installed on second device during diag"
assert not self.diag_drv_first_dev.is_installed(), "Diag driver must not be installed on first device " \
"during diag"
sleep(pause)
com.send_stdin([DiagWrapper.CMD_DICT["Select device"],
DiagWrapper.CMD_DICT["Go back to main menu"],
DiagWrapper.CMD_DICT["Device Info"],
DiagWrapper.CMD_DICT["Enter"],
DiagWrapper.CMD_DICT["Exit"]])
com.join(timeout=diag_timeout)
exp_res = r"".join([self.second_port, " [(Selected)]"])
exp_dev_id = r"".join(["Device ID = ", self.second_dev_id])
self.check_return_code(com)
assert self.is_in_output(com.result["output"], exp_res), "Second device must be selected"
assert self.is_in_output(com.result["output"], exp_dev_id), "Second device ID must be in Device Info"
def test_show_dev1_with_opt_d_pciport_and_k(self):
log.info("Running Diag...")
d = DiagWrapper(self.diag_dir, "-d {} -k --raise".format(self.first_port))
com = Command(cmd=d.cmd)
com.run_async()
assert self.diag_drv_first_dev.is_installed(), "Diag driver must be installed on first device during diag"
assert not self.diag_drv_second_dev.is_installed(), "Diag driver must not be installed on second device " \
"during diag"
sleep(pause)
com.send_stdin([DiagWrapper.CMD_DICT["Select device"],
DiagWrapper.CMD_DICT["Go back to main menu"],
DiagWrapper.CMD_DICT["Device Info"],
DiagWrapper.CMD_DICT["Enter"],
DiagWrapper.CMD_DICT["Exit"]])
com.join(timeout=diag_timeout)
exp_res = r"".join([self.first_port, " [(Selected)]"])
exp_dev_id = r"".join(["Device ID = ", self.first_dev_id])
self.check_return_code(com)
assert self.is_in_output(com.result["output"], exp_res), "First device must be selected"
assert self.is_in_output(com.result["output"], exp_dev_id), "First device ID must be in Device Info"
def test_show_dev2_with_opt_d_index_and_k(self):
log.info("Running Diag...")
d = DiagWrapper(self.diag_dir, "-d 1 -k --raise")
com = Command(cmd=d.cmd)
com.run_async()
assert self.diag_drv_second_dev.is_installed(), "Diag driver must be installed on second device during diag"
assert not self.diag_drv_first_dev.is_installed(), "Diag driver must not be installed on first device" \
" during diag"
sleep(pause)
com.send_stdin([DiagWrapper.CMD_DICT["Select device"],
DiagWrapper.CMD_DICT["Go back to main menu"],
DiagWrapper.CMD_DICT["Device Info"],
DiagWrapper.CMD_DICT["Enter"],
DiagWrapper.CMD_DICT["Exit"]])
com.join(timeout=diag_timeout)
exp_res = r"".join([self.second_port, " [(Selected)]"])
exp_dev_id = r"".join(["Device ID = ", self.second_dev_id])
self.check_return_code(com)
assert self.is_in_output(com.result["output"], exp_res), "Second device must be selected"
assert self.is_in_output(com.result["output"], exp_dev_id), "Second device ID must be in Device Info"
def test_show_dev1_with_opt_d_port_and_k_when_dev2_has_prod_drv(self):
self.prod_drv_second_dev.install()
log.info("Running Diag...")
d = DiagWrapper(self.diag_dir, "-d {} -k --raise".format(self.first_port.replace("pci", "")))
com = Command(cmd=d.cmd)
com.run_async()
assert self.diag_drv_first_dev.is_installed(), "Diag driver must be installed on first device during diag"
assert not self.diag_drv_second_dev.is_installed(), "Diag driver must not be installed on second device " \
"during diag"
sleep(pause)
com.send_stdin([DiagWrapper.CMD_DICT["Select device"],
DiagWrapper.CMD_DICT["Go back to main menu"],
DiagWrapper.CMD_DICT["Device Info"],
DiagWrapper.CMD_DICT["Enter"],
DiagWrapper.CMD_DICT["Exit"]])
com.join(timeout=diag_timeout)
exp_res = r"".join([self.first_port, " [(Selected)]"])
exp_dev_id = r"".join(["Device ID = ", self.first_dev_id])
self.check_return_code(com)
assert self.is_in_output(com.result["output"], exp_res), "First device must be selected"
assert self.is_in_output(com.result["output"], exp_dev_id), "First device ID must be in Device Info"
def test_show_dev2_with_opt_d_pciport_and_k_when_dev1_has_prod_drv(self):
self.prod_drv_first_dev.install()
log.info("Running Diag...")
d = DiagWrapper(self.diag_dir, "-d {} -k --raise".format(self.second_port))
com = Command(cmd=d.cmd)
com.run_async()
assert self.diag_drv_second_dev.is_installed(), "Diag driver must be installed on second device during diag"
assert not self.diag_drv_first_dev.is_installed(), "Diag driver must not be installed on first device" \
" during diag"
sleep(pause)
com.send_stdin([DiagWrapper.CMD_DICT["Select device"],
DiagWrapper.CMD_DICT["Go back to main menu"],
DiagWrapper.CMD_DICT["Device Info"],
DiagWrapper.CMD_DICT["Enter"],
DiagWrapper.CMD_DICT["Exit"]])
com.join(timeout=diag_timeout)
exp_res = r"".join([self.second_port, " [(Selected)]"])
exp_dev_id = r"".join(["Device ID = ", self.second_dev_id])
self.check_return_code(com)
assert self.is_in_output(com.result["output"], exp_res), "Second device must be selected"
assert self.is_in_output(com.result["output"], exp_dev_id), "Second device ID must be in Device Info"
def test_dev1_prod_s_d_pciport_select_dev2_diag(self):
self.diag_drv_second_dev.install()
self.prod_drv_first_dev.install()
log.info("Running Diag...")
d = DiagWrapper(self.diag_dir, "-d {} -s --raise".format(self.first_port))
com = Command(cmd=d.cmd)
com.run_async()
assert self.diag_drv_first_dev.is_installed(), "Diag driver must be installed on first device" \
" during diag"
sleep(pause)
com.send_stdin([DiagWrapper.CMD_DICT["Select device"],
DiagWrapper.CMD_DICT["Choose device to test:2"],
DiagWrapper.CMD_DICT["Device Info"],
DiagWrapper.CMD_DICT["Enter"],
DiagWrapper.CMD_DICT["Exit"]])
com.join(timeout=diag_timeout)
exp_dev_id = r"".join(["Device ID = ", self.second_dev_id])
self.check_return_code(com)
assert not self.diag_drv_first_dev.is_installed(), "Error, diag driver has to be uninstalled"
assert self.prod_drv_first_dev.is_installed(), "Error, prod driver has to be installed"
assert self.is_in_output(com.result["output"], exp_dev_id), "Second device ID must be in Device Info"
def test_dev2_prod_s_d_pciport_select_dev1_diag(self):
self.diag_drv_first_dev.install()
self.prod_drv_second_dev.install()
log.info("Running Diag...")
d = DiagWrapper(self.diag_dir, "-d {} -s --raise".format(self.second_port))
com = Command(cmd=d.cmd)
com.run_async()
assert self.diag_drv_second_dev.is_installed(), "Diag driver must be installed on second device" \
" during diag"
sleep(pause)
com.send_stdin([DiagWrapper.CMD_DICT["Select device"],
DiagWrapper.CMD_DICT["Choose device to test:1"],
DiagWrapper.CMD_DICT["Device Info"],
DiagWrapper.CMD_DICT["Enter"],
DiagWrapper.CMD_DICT["Exit"]])
com.join(timeout=diag_timeout)
exp_dev_id = r"".join(["Device ID = ", self.first_dev_id])
self.check_return_code(com)
assert not self.diag_drv_second_dev.is_installed(), "Error, diag driver has to be uninstalled"
assert self.prod_drv_second_dev.is_installed(), "Error, prod driver has to be installed"
assert self.is_in_output(com.result["output"], exp_dev_id), "Second device ID must be in Device Info"
def test_dev2_diag_s_d_index_select_dev1_diag(self):
self.diag_drv_first_dev.install()
self.diag_drv_second_dev.install()
log.info("Running Diag...")
d = DiagWrapper(self.diag_dir, "-d 1 -s --raise")
com = Command(cmd=d.cmd)
com.run_async()
assert self.diag_drv_second_dev.is_installed(), "Diag driver must be installed on second device" \
" during diag"
sleep(pause)
com.send_stdin([DiagWrapper.CMD_DICT["Select device"],
DiagWrapper.CMD_DICT["Choose device to test:1"],
DiagWrapper.CMD_DICT["Device Info"],
DiagWrapper.CMD_DICT["Enter"],
DiagWrapper.CMD_DICT["Exit"]])
com.join(timeout=diag_timeout)
exp_dev_id = r"".join(["Device ID = ", self.first_dev_id])
self.check_return_code(com)
assert self.diag_drv_first_dev.is_installed(), "Error, diag driver has to be installed"
assert self.diag_drv_second_dev.is_installed(), "Error, diag driver has to be installed"
assert self.is_in_output(com.result["output"], exp_dev_id), "Second device ID must be in Device Info"
def test_dev1_diag_s_d_port_select_dev2_diag(self):
self.diag_drv_second_dev.install()
self.diag_drv_first_dev.install()
log.info("Running Diag...")
d = DiagWrapper(self.diag_dir, "-d {} -s --raise".format(self.first_port.replace("pci", "")))
com = Command(cmd=d.cmd)
com.run_async()
assert self.diag_drv_first_dev.is_installed(), "Diag driver must be installed on first device" \
" during diag"
sleep(pause)
com.send_stdin([DiagWrapper.CMD_DICT["Select device"],
DiagWrapper.CMD_DICT["Choose device to test:2"],
DiagWrapper.CMD_DICT["Device Info"],
DiagWrapper.CMD_DICT["Enter"],
DiagWrapper.CMD_DICT["Exit"]])
com.join(timeout=diag_timeout)
exp_dev_id = r"".join(["Device ID = ", self.second_dev_id])
self.check_return_code(com)
assert self.diag_drv_first_dev.is_installed(), "Error, diag driver has to be installed"
assert self.diag_drv_second_dev.is_installed(), "Error, diag driver has to be installed"
assert self.is_in_output(com.result["output"], exp_dev_id), "Second device ID must be in Device Info"
def test_dev1_s_d_pciport_select_dev2_diag(self):
self.diag_drv_second_dev.install()
log.info("Running Diag...")
d = DiagWrapper(self.diag_dir, "-d {} -s --raise".format(self.first_port))
com = Command(cmd=d.cmd)
com.run_async()
assert self.diag_drv_first_dev.is_installed(), "Diag driver must be installed on first device" \
" during diag"
sleep(pause)
com.send_stdin([DiagWrapper.CMD_DICT["Select device"],
DiagWrapper.CMD_DICT["Choose device to test:2"],
DiagWrapper.CMD_DICT["Device Info"],
DiagWrapper.CMD_DICT["Enter"],
DiagWrapper.CMD_DICT["Exit"]])
com.join(timeout=diag_timeout)
exp_dev_id = r"".join(["Device ID = ", self.second_dev_id])
self.check_return_code(com)
assert self.diag_drv_first_dev.is_installed(), "Error, diag driver has to be installed"
assert self.is_in_output(com.result["output"], exp_dev_id), "Second device ID must be in Device Info"
assert self.diag_drv_second_dev.is_installed(), "Error, diag driver has to be installed"
def test_dev2_s_d_index_select_dev1_diag(self):
self.diag_drv_first_dev.install()
log.info("Running Diag...")
d = DiagWrapper(self.diag_dir, "-d 1 -s --raise")
com = Command(cmd=d.cmd)
com.run_async()
assert self.diag_drv_second_dev.is_installed(), "Diag driver must be installed on second device" \
" during diag"
sleep(pause)
com.send_stdin([DiagWrapper.CMD_DICT["Select device"],
DiagWrapper.CMD_DICT["Choose device to test:1"],
DiagWrapper.CMD_DICT["Device Info"],
DiagWrapper.CMD_DICT["Enter"],
DiagWrapper.CMD_DICT["Exit"]])
com.join(timeout=diag_timeout)
exp_dev_id = r"".join(["Device ID = ", self.first_dev_id])
self.check_return_code(com)
assert self.diag_drv_second_dev.is_installed(), "Error, diag driver has to be installed"
assert self.diag_drv_first_dev.is_installed(), "Error, diag driver has to be installed"
assert self.is_in_output(com.result["output"], exp_dev_id), "Second device ID must be in Device Info"
def install_drv(self, drv1, drv2):
if drv1 in ['prod', 'diag']:
getattr(self, drv1 + '_drv_first_dev').install()
if drv2 in ['prod', 'diag']:
getattr(self, drv2 + '_drv_second_dev').install()
def check_install_driver_before(self, port):
if port == self.first_port:
assert self.diag_drv_first_dev.is_installed(), "Diag driver must be installed on first device during diag"
else:
assert self.diag_drv_second_dev.is_installed(), "Diag driver must be installed on second device" \
" during diag"
def check_drv_on_device_after_exit(self, dev, drv, other_drv):
if drv == 'diag':
assert getattr(self, "diag_drv_" + dev + "_dev").is_installed(), "Error, diag driver has to be installed"
elif drv == 'prod':
assert not getattr(self, "diag_drv_" + dev + "_dev").is_installed(), "Error, diag driver has to be uninstalled"
assert getattr(self, "prod_drv_" + dev + "_dev").is_installed(), "Error, prod driver has to be installed"
else:
if other_drv == 'diag':
# expected behavior on Windows as we can't rollback to NULL driver without touching other devices
assert getattr(self, "diag_drv_" + dev + "_dev").is_installed(), "Error, diag driver has to be installed"
else:
assert not getattr(self, "diag_drv_" + dev + "_dev").is_installed(), "Error, diag driver has to be uninstalled"
def check_install_driver_after(self, drv1, drv2, port, install_key):
if install_key == "-s":
self.check_drv_on_device_after_exit("first", drv1, drv2)
self.check_drv_on_device_after_exit("second", drv2, drv1)
else:
if port == self.first_port:
assert self.diag_drv_first_dev.is_installed(), "Error, diag driver has to be installed"
if install_key == "-k" and drv1 != "prod":
# Diag removes diag driver from the first device and OS Windows installs prod driver automatically
drv1 = "diag"
self.check_drv_on_device_after_exit("second", drv2, drv1)
else:
assert self.diag_drv_second_dev.is_installed(), "Error, diag driver has to be installed"
if install_key == "-k" and drv2 != "prod":
# Diag removes diag driver from the second device and OS Windows installs prod driver automatically
drv2 = "diag"
self.check_drv_on_device_after_exit("first", drv1, drv2)
def choose_device_to_test(self, port):
if port == self.first_port:
return DiagWrapper.CMD_DICT["Choose device to test:2"]
else:
return DiagWrapper.CMD_DICT["Choose device to test:1"]
def other_port(self, port):
if port == self.first_port:
return self.second_port
else:
return self.first_port
def dev_id_by_port(self, port):
if port == self.first_port:
return self.first_dev_id
else:
return self.second_dev_id
def select_device(self, drv1, drv2, port, key):
if port == 'first':
port = self.first_port
else:
port = self.second_port
self.install_drv(drv1, drv2)
log.info("Running Diag...")
d = DiagWrapper(self.diag_dir, "-d {} {} --raise".format(port, key))
com = Command(cmd=d.cmd)
com.run_async()
if key in ["-s", "-k"]:
self.check_install_driver_before(port)
sleep(pause)
com.send_stdin([DiagWrapper.CMD_DICT["Select device"],
self.choose_device_to_test(port),
DiagWrapper.CMD_DICT["y"],
DiagWrapper.CMD_DICT["Device Info"],
DiagWrapper.CMD_DICT["Enter"],
DiagWrapper.CMD_DICT["Exit"]])
com.join(timeout=diag_timeout)
exp_dev_id = r"".join(["Device ID = ", self.dev_id_by_port(self.other_port(port))])
self.check_return_code(com)
self.check_install_driver_after(drv1, drv2, port, key)
assert self.is_in_output(com.result["output"], exp_dev_id), "{} must be in Device Info".format(exp_dev_id)
@idparametrize("key", ["-s", "-k"])
@idparametrize("port_to_select", ["first", "second"])
@idparametrize("drv1, drv2", [("no", "no"), ("prod", "prod"), ("no", "prod"), ("prod", "no")])
def test_select(self, drv1, drv2, port_to_select, key):
self.select_device(drv1, drv2, port_to_select, key)
@idparametrize("drv1, drv2, port_to_select", [("diag", "prod", "first"), ("diag", "no", "first"), \
("no", "diag", "second"), ("prod", "diag", "second")])
def test_select_without_key(self, drv1, drv2, port_to_select):
self.select_device(drv1, drv2, port_to_select, "")
if __name__ == "__main__":
pytest.main([__file__, "-s", "-v"])