summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorhathach <[email protected]>2024-10-02 18:22:06 +0700
committerhathach <[email protected]>2024-10-02 18:22:06 +0700
commitdb15f63736e44592e042a09b526c982e0bd80d4f (patch)
tree77d65e74899cf3481d2c37d52eb8331e9558e700 /test
parent3fa7da95bd2a7189020ba6fe2d6aa17577f83abd (diff)
parenteda3cceab207bce390b995462e313ed124fa7732 (diff)
Merge branch 'master' into fork/Maerdl/master
Diffstat (limited to 'test')
-rw-r--r--test/hil/hil_test.py66
-rw-r--r--test/hil/requirements.txt2
-rw-r--r--test/hil/tinyusb.json (renamed from test/hil/rpi.json)20
3 files changed, 52 insertions, 36 deletions
diff --git a/test/hil/hil_test.py b/test/hil/hil_test.py
index a569e7666..cb885aeb5 100644
--- a/test/hil/hil_test.py
+++ b/test/hil/hil_test.py
@@ -45,6 +45,11 @@ STATUS_SKIPPED = "\033[33mSkipped\033[0m"
verbose = False
+# -------------------------------------------------------------
+# Path
+# -------------------------------------------------------------
+OPENCOD_ADI_PATH = f'{os.getenv("HOME")}/app/openocd_adi'
+
# get usb serial by id
def get_serial_dev(id, vendor_str, product_str, ifnum):
if vendor_str and product_str:
@@ -112,8 +117,8 @@ def read_disk_file(uid, lun, fname):
# -------------------------------------------------------------
# Flashing firmware
# -------------------------------------------------------------
-def run_cmd(cmd):
- r = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+def run_cmd(cmd, cwd=None):
+ r = subprocess.run(cmd, cwd=cwd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
if r.returncode != 0:
title = f'COMMAND FAILED: {cmd}'
print()
@@ -187,11 +192,7 @@ echo "Ready for Remote Connections"
def flash_openocd_adi(board, firmware):
- openocd_adi_script_path = f'{os.getenv("HOME")}/app/openocd_adi/tcl'
- if not os.path.exists(openocd_adi_script_path):
- openocd_adi_script_path = '/home/pi/openocd_adi/tcl'
-
- ret = run_cmd(f'openocd_adi -c "adapter serial {board["flasher_sn"]}" -s {openocd_adi_script_path} '
+ ret = run_cmd(f'{OPENCOD_ADI_PATH}/src/openocd -c "adapter serial {board["flasher_sn"]}" -s {OPENCOD_ADI_PATH}/tcl '
f'{board["flasher_args"]} -c "program {firmware}.elf reset exit"')
return ret
@@ -203,14 +204,14 @@ def flash_wlink_rs(board, firmware):
def flash_esptool(board, firmware):
port = get_serial_dev(board["flasher_sn"], None, None, 0)
- dir = os.path.dirname(f'{firmware}.bin')
- with open(f'{dir}/config.env') as f:
- IDF_TARGET = json.load(f)['IDF_TARGET']
- with open(f'{dir}/flash_args') as f:
+ fw_dir = os.path.dirname(f'{firmware}.bin')
+ with open(f'{fw_dir}/config.env') as f:
+ idf_target = json.load(f)['IDF_TARGET']
+ with open(f'{fw_dir}/flash_args') as f:
flash_args = f.read().strip().replace('\n', ' ')
- command = (f'esptool.py --chip {IDF_TARGET} -p {port} {board["flasher_args"]} '
+ command = (f'esptool.py --chip {idf_target} -p {port} {board["flasher_args"]} '
f'--before=default_reset --after=hard_reset write_flash {flash_args}')
- ret = subprocess.run(command, shell=True, cwd=dir, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ ret = run_cmd(command, cwd=fw_dir)
return ret
@@ -239,8 +240,13 @@ def test_dual_host_info_to_device_cdc(board):
print(f'\r\n {l} ', end='')
enum_dev_sn.append(f'{vid_pid_sn.group(1)}_{vid_pid_sn.group(2)}_{vid_pid_sn.group(3)}')
- assert(set(declared_devs) == set(enum_dev_sn)), \
- f'Enumerated devices {enum_dev_sn} not match with declared {declared_devs}'
+ if set(declared_devs) != set(enum_dev_sn):
+ # for pico/pico2 make this test optional
+ failed_msg = f'Enumerated devices {enum_dev_sn} not match with declared {declared_devs}'
+ if 'raspberry_pi_pico' in board['name']:
+ print(f'\r\n {failed_msg} ', end='')
+ else:
+ assert False, failed_msg
return 0
@@ -305,8 +311,7 @@ def test_device_dfu(board):
# Wait device enum
timeout = ENUM_TIMEOUT
while timeout:
- ret = subprocess.run(f'dfu-util -l',
- shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ ret = run_cmd(f'dfu-util -l')
stdout = ret.stdout.decode()
if f'serial="{uid}"' in stdout and 'Found DFU: [cafe:4000]' in stdout:
break
@@ -347,8 +352,7 @@ def test_device_dfu_runtime(board):
# Wait device enum
timeout = ENUM_TIMEOUT
while timeout:
- ret = subprocess.run(f'dfu-util -l',
- shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ ret = run_cmd(f'dfu-util -l')
stdout = ret.stdout.decode()
if f'serial="{uid}"' in stdout and 'Found Runtime: [cafe:4000]' in stdout:
break
@@ -382,17 +386,18 @@ def test_device_hid_composite_freertos(id):
# -------------------------------------------------------------
# Main
# -------------------------------------------------------------
-# all possible tests: board_test is added last to disable board's usb
-all_tests = [
+# device tests
+device_tests = [
'device/cdc_dual_ports',
'device/cdc_msc',
'device/dfu',
'device/cdc_msc_freertos', # don't test 2 cdc_msc next to each other
'device/dfu_runtime',
'device/hid_boot_interface',
+]
+dual_tests = [
'dual/host_info_to_device_cdc',
- 'device/board_test'
]
@@ -401,16 +406,22 @@ def test_board(board):
flasher = board['flasher'].lower()
# default to all tests
- test_list = list(all_tests)
+ test_list = list(device_tests)
if 'tests' in board:
board_tests = board['tests']
+ if 'dual_attached' in board_tests:
+ test_list += dual_tests
if 'only' in board_tests:
- test_list = board_tests['only'] + ['device/board_test']
+ test_list = board_tests['only']
if 'skip' in board_tests:
for skip in board_tests['skip']:
if skip in test_list:
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
for test in test_list:
@@ -421,7 +432,7 @@ def test_board(board):
print(f'{name:25} {test:30} ... ', end='')
if not os.path.exists(fw_dir):
- print('Skip')
+ print('Skip (no binary)')
continue
# flash firmware. It may fail randomly, retry a few times
@@ -453,6 +464,8 @@ def main():
"""
global verbose
+ duration = time.time()
+
parser = argparse.ArgumentParser()
parser.add_argument('config_file', help='Configuration JSON file')
parser.add_argument('-b', '--board', action='append', default=[], help='Boards to test, all if not specified')
@@ -477,9 +490,10 @@ def main():
with Pool(processes=os.cpu_count()) as pool:
err_count = sum(pool.map(test_board, config_boards))
+ duration = time.time() - duration
print()
print("-" * 30)
- print(f'Total failed: {err_count}')
+ print(f'Total failed: {err_count} in {duration:.1f}s')
print("-" * 30)
sys.exit(err_count)
diff --git a/test/hil/requirements.txt b/test/hil/requirements.txt
new file mode 100644
index 000000000..c33980c9d
--- /dev/null
+++ b/test/hil/requirements.txt
@@ -0,0 +1,2 @@
+fs
+pyfatfs
diff --git a/test/hil/rpi.json b/test/hil/tinyusb.json
index 77919f346..066dc5876 100644
--- a/test/hil/rpi.json
+++ b/test/hil/tinyusb.json
@@ -75,6 +75,16 @@
"flasher": "openocd",
"flasher_sn": "066FFF495087534867063844",
"flasher_args": "-f interface/stlink.cfg -f target/stm32g0x.cfg"
+ },
+ {
+ "name": "espressif_s3_devkitm",
+ "uid": "84F703C084E4",
+ "tests": {
+ "only": ["device/cdc_msc_freertos", "device/hid_composite_freertos"]
+ },
+ "flasher": "esptool",
+ "flasher_sn": "3ea619acd1cdeb11a0a0b806e93fd3f1",
+ "flasher_args": "-b 921600"
}
],
"boards-skip": [
@@ -91,16 +101,6 @@
"flasher": "openocd_wch",
"flasher_sn": "EBCA8F0670AF",
"flasher_args": ""
- },
- {
- "name": "espressif_s3_devkitm",
- "uid": "84F703C084E4",
- "tests": {
- "only": ["device/cdc_msc_freertos", "device/hid_composite_freertos"]
- },
- "flasher": "esptool",
- "flasher_sn": "3ea619acd1cdeb11a0a0b806e93fd3f1",
- "flasher_args": "-b 921600"
}
]
}