Skip to content

Commit 3be7a98

Browse files
committed
de-duplicate flash board_test for board with multiple flags_on
1 parent 4d60154 commit 3be7a98

File tree

1 file changed

+57
-40
lines changed

1 file changed

+57
-40
lines changed

test/hil/hil_test.py

+57-40
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,59 @@ def test_device_hid_composite_freertos(id):
514514
]
515515

516516

517+
def test_example(board, f1_str, example):
518+
"""
519+
Test example firmware
520+
:param board: board dict
521+
:param f1: flags on
522+
:param example: example name
523+
:return: 0 if success/skip, 1 if failed
524+
"""
525+
name = board['name']
526+
err_count = 0
527+
528+
fw_dir = f'{TINYUSB_ROOT}/cmake-build/cmake-build-{name}{f1_str}/{example}'
529+
if not os.path.exists(fw_dir):
530+
fw_dir = f'{TINYUSB_ROOT}/examples/cmake-build-{name}{f1_str}/{example}'
531+
fw_name = f'{fw_dir}/{os.path.basename(example)}'
532+
print(f'{name+f1_str:40} {example:30} ... ', end='')
533+
534+
if not os.path.exists(fw_dir) or not (os.path.exists(f'{fw_name}.elf') or os.path.exists(f'{fw_name}.bin')):
535+
print('Skip (no binary)')
536+
return 0
537+
538+
if verbose:
539+
print(f'Flashing {fw_name}.elf')
540+
541+
# flash firmware. It may fail randomly, retry a few times
542+
max_rety = 2
543+
for i in range(max_rety):
544+
ret = globals()[f'flash_{board["flasher"]["name"].lower()}'](board, fw_name)
545+
if ret.returncode == 0:
546+
try:
547+
globals()[f'test_{example.replace("/", "_")}'](board)
548+
print('OK')
549+
break
550+
except Exception as e:
551+
if i == max_rety - 1:
552+
err_count += 1
553+
print(STATUS_FAILED)
554+
print(f' {e}')
555+
else:
556+
print()
557+
print(f' Test failed: {e}, retry {i+2}/{max_rety}')
558+
time.sleep(1)
559+
else:
560+
print(f'Flashing failed, retry {i+2}/{max_rety}')
561+
time.sleep(1)
562+
563+
if ret.returncode != 0:
564+
err_count += 1
565+
print(f'Flash {STATUS_FAILED}')
566+
567+
return err_count
568+
569+
517570
def test_board(board):
518571
name = board['name']
519572
flasher = board['flasher']
@@ -537,9 +590,6 @@ def test_board(board):
537590
test_list.remove(skip)
538591
print(f'{name:25} {skip:30} ... Skip')
539592

540-
# board_test is added last to disable board's usb
541-
test_list.append('device/board_test')
542-
543593
err_count = 0
544594
flags_on_list = [""]
545595
if 'build' in board and 'flags_on' in board['build']:
@@ -550,44 +600,11 @@ def test_board(board):
550600
if f1 != "":
551601
f1_str = '-f1_' + f1.replace(' ', '_')
552602
for test in test_list:
553-
fw_dir = f'{TINYUSB_ROOT}/cmake-build/cmake-build-{name}{f1_str}/{test}'
554-
if not os.path.exists(fw_dir):
555-
fw_dir = f'{TINYUSB_ROOT}/examples/cmake-build-{name}{f1_str}/{test}'
556-
fw_name = f'{fw_dir}/{os.path.basename(test)}'
557-
print(f'{name+f1_str:40} {test:30} ... ', end='')
558-
559-
if not os.path.exists(fw_dir) or not (os.path.exists(f'{fw_name}.elf') or os.path.exists(f'{fw_name}.bin')):
560-
print('Skip (no binary)')
561-
continue
562-
563-
if verbose:
564-
print(f'Flashing {fw_name}.elf')
565-
566-
# flash firmware. It may fail randomly, retry a few times
567-
max_rety = 2
568-
for i in range(max_rety):
569-
ret = globals()[f'flash_{flasher["name"].lower()}'](board, fw_name)
570-
if ret.returncode == 0:
571-
try:
572-
globals()[f'test_{test.replace("/", "_")}'](board)
573-
print('OK')
574-
break
575-
except Exception as e:
576-
if i == max_rety - 1:
577-
err_count += 1
578-
print(STATUS_FAILED)
579-
print(f' {e}')
580-
else:
581-
print()
582-
print(f' Test failed: {e}, retry {i+2}/{max_rety}')
583-
time.sleep(1)
584-
else:
585-
print(f'Flashing failed, retry {i+2}/{max_rety}')
586-
time.sleep(1)
603+
err_count += test_example(board, f1_str, test)
604+
587605

588-
if ret.returncode != 0:
589-
err_count += 1
590-
print(f'Flash {STATUS_FAILED}')
606+
# flash board_test last to disable board's usb
607+
test_example(board, flags_on_list[0], 'device/board_test')
591608

592609
return err_count
593610

0 commit comments

Comments
 (0)