summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorhathach <[email protected]>2025-04-16 22:04:19 +0700
committerhathach <[email protected]>2025-04-16 23:47:17 +0700
commit7ef17a85cb5c6655e778e3385dfef20be00de199 (patch)
treef783632d671d84803a3395541cacab241acafc91 /test
parent4d601545eba2793280752fb04ab6a7628a1a14ea (diff)
de-duplicate flash board_test for board with multiple flags_on
Diffstat (limited to 'test')
-rwxr-xr-xtest/hil/hil_test.py103
1 files changed, 60 insertions, 43 deletions
diff --git a/test/hil/hil_test.py b/test/hil/hil_test.py
index 8b89de66c..14ab4e63a 100755
--- a/test/hil/hil_test.py
+++ b/test/hil/hil_test.py
@@ -514,6 +514,63 @@ host_test = [
]
+def test_example(board, f1, example):
+ """
+ Test example firmware
+ :param board: board dict
+ :param f1: flags on
+ :param example: example name
+ :return: 0 if success/skip, 1 if failed
+ """
+ name = board['name']
+ err_count = 0
+
+ f1_str = ""
+ if f1 != "":
+ f1_str = '-f1_' + f1.replace(' ', '_')
+
+ fw_dir = f'{TINYUSB_ROOT}/cmake-build/cmake-build-{name}{f1_str}/{example}'
+ if not os.path.exists(fw_dir):
+ fw_dir = f'{TINYUSB_ROOT}/examples/cmake-build-{name}{f1_str}/{example}'
+ fw_name = f'{fw_dir}/{os.path.basename(example)}'
+ print(f'{name+f1_str:40} {example:30} ... ', end='')
+
+ if not os.path.exists(fw_dir) or not (os.path.exists(f'{fw_name}.elf') or os.path.exists(f'{fw_name}.bin')):
+ print('Skip (no binary)')
+ return 0
+
+ if verbose:
+ print(f'Flashing {fw_name}.elf')
+
+ # flash firmware. It may fail randomly, retry a few times
+ max_rety = 2
+ for i in range(max_rety):
+ ret = globals()[f'flash_{board["flasher"]["name"].lower()}'](board, fw_name)
+ if ret.returncode == 0:
+ try:
+ globals()[f'test_{example.replace("/", "_")}'](board)
+ print('OK')
+ break
+ except Exception as e:
+ if i == max_rety - 1:
+ err_count += 1
+ print(STATUS_FAILED)
+ print(f' {e}')
+ else:
+ print()
+ print(f' Test failed: {e}, retry {i+2}/{max_rety}')
+ time.sleep(1)
+ else:
+ print(f'Flashing failed, retry {i+2}/{max_rety}')
+ time.sleep(1)
+
+ if ret.returncode != 0:
+ err_count += 1
+ print(f'Flash {STATUS_FAILED}')
+
+ return err_count
+
+
def test_board(board):
name = board['name']
flasher = board['flasher']
@@ -537,57 +594,17 @@ def test_board(board):
test_list.remove(skip)
print(f'{name:25} {skip:30} ... Skip')
- # board_test is added last to disable board's usb
- test_list.append('device/board_test')
-
err_count = 0
flags_on_list = [""]
if 'build' in board and 'flags_on' in board['build']:
flags_on_list = board['build']['flags_on']
for f1 in flags_on_list:
- f1_str = ""
- if f1 != "":
- f1_str = '-f1_' + f1.replace(' ', '_')
for test in test_list:
- fw_dir = f'{TINYUSB_ROOT}/cmake-build/cmake-build-{name}{f1_str}/{test}'
- if not os.path.exists(fw_dir):
- fw_dir = f'{TINYUSB_ROOT}/examples/cmake-build-{name}{f1_str}/{test}'
- fw_name = f'{fw_dir}/{os.path.basename(test)}'
- print(f'{name+f1_str:40} {test:30} ... ', end='')
-
- if not os.path.exists(fw_dir) or not (os.path.exists(f'{fw_name}.elf') or os.path.exists(f'{fw_name}.bin')):
- print('Skip (no binary)')
- continue
-
- if verbose:
- print(f'Flashing {fw_name}.elf')
-
- # flash firmware. It may fail randomly, retry a few times
- max_rety = 2
- for i in range(max_rety):
- ret = globals()[f'flash_{flasher["name"].lower()}'](board, fw_name)
- if ret.returncode == 0:
- try:
- globals()[f'test_{test.replace("/", "_")}'](board)
- print('OK')
- break
- except Exception as e:
- if i == max_rety - 1:
- err_count += 1
- print(STATUS_FAILED)
- print(f' {e}')
- else:
- print()
- print(f' Test failed: {e}, retry {i+2}/{max_rety}')
- time.sleep(1)
- else:
- print(f'Flashing failed, retry {i+2}/{max_rety}')
- time.sleep(1)
+ err_count += test_example(board, f1, test)
- if ret.returncode != 0:
- err_count += 1
- print(f'Flash {STATUS_FAILED}')
+ # flash board_test last to disable board's usb
+ test_example(board, flags_on_list[0], 'device/board_test')
return err_count