summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorHiFiPhile <[email protected]>2025-04-11 23:07:22 +0200
committerHiFiPhile <[email protected]>2025-04-11 23:07:22 +0200
commit459e2cd39ece797eb35f74ccace0db0a588b795a (patch)
tree68e0f398392eb001ab64857575a2b76934519021 /test
parent8d2310247c47160bf8de6e5f754284360ad7e937 (diff)
parent865e3488f99209c57b73953428dccf2bc666f0be (diff)
Merge remote-tracking branch 'upstream/master' into async_io
Signed-off-by: HiFiPhile <[email protected]>
Diffstat (limited to 'test')
-rwxr-xr-xtest/hil/hil_test.py52
-rw-r--r--test/hil/tinyusb.json29
2 files changed, 51 insertions, 30 deletions
diff --git a/test/hil/hil_test.py b/test/hil/hil_test.py
index a9f5dc1e1..8b89de66c 100755
--- a/test/hil/hil_test.py
+++ b/test/hil/hil_test.py
@@ -81,7 +81,7 @@ def get_serial_dev(id, vendor_str, product_str, ifnum):
return f'/dev/serial/by-id/usb-{vendor_str}_{product_str}_{id}-if{ifnum:02d}'
else:
# just use id: mostly for cp210x/ftdi flasher
- pattern = f'/dev/serial/by-id/usb-*_{id}-if{ifnum:02d}*'
+ pattern = f'/dev/serial/by-id/usb-*_{id}-if*'
port_list = glob.glob(pattern)
return port_list[0]
@@ -98,20 +98,18 @@ def get_hid_dev(id, vendor_str, product_str, event):
def open_serial_dev(port):
timeout = ENUM_TIMEOUT
ser = None
- while timeout:
+ while timeout > 0:
if os.path.exists(port):
try:
- # slight delay since kernel may occupy the port briefly
- time.sleep(0.5)
- timeout = timeout - 0.5
ser = serial.Serial(port, baudrate=115200, timeout=5)
break
except serial.SerialException:
+ print(f'serial {port} not reaady {timeout} sec')
pass
- time.sleep(0.5)
- timeout = timeout - 0.5
+ time.sleep(0.1)
+ timeout -= 0.1
- assert timeout, f'Cannot open port f{port}' if os.path.exists(port) else f'Port {port} not existed'
+ assert timeout > 0, f'Cannot open port f{port}' if os.path.exists(port) else f'Port {port} not existed'
return ser
@@ -119,7 +117,7 @@ def read_disk_file(uid, lun, fname):
# open_fs("fat://{dev}) require 'pip install pyfatfs'
dev = get_disk_dev(uid, 'TinyUSB', lun)
timeout = ENUM_TIMEOUT
- while timeout:
+ while timeout > 0:
if os.path.exists(dev):
fat = fs.open_fs(f'fat://{dev}?read_only=true')
try:
@@ -132,7 +130,7 @@ def read_disk_file(uid, lun, fname):
time.sleep(1)
timeout -= 1
- assert timeout, f'Storage {dev} not existed'
+ assert timeout > 0, f'Storage {dev} not existed'
return None
@@ -202,14 +200,14 @@ def reset_stflash(board):
def flash_openocd(board, firmware):
flasher = board['flasher']
ret = run_cmd(f'openocd -c "tcl_port disabled" -c "gdb_port disabled" -c "adapter serial {flasher["uid"]}" '
- f'{flasher["args"]} -c init -c halt -c "program {firmware}.elf verify" -c reset -c exit')
+ f'{flasher["args"]} -c "init; halt; program {firmware}.elf verify; reset; exit"')
return ret
def reset_openocd(board):
flasher = board['flasher']
ret = run_cmd(f'openocd -c "tcl_port disabled" -c "gdb_port disabled" -c "adapter serial {flasher["uid"]}" '
- f'{flasher["args"]} -c "reset exit"')
+ f'{flasher["args"]} -c "init; reset run; exit"')
return ret
@@ -304,11 +302,11 @@ def test_dual_host_info_to_device_cdc(board):
ser = open_serial_dev(port)
# read from cdc, first line should contain vid/pid and serial
- data = ser.read(1000)
+ data = ser.read(10000)
ser.close()
if len(data) == 0:
assert False, 'No data from device'
- lines = data.decode('utf-8').splitlines()
+ lines = data.decode('utf-8', errors='ignore').splitlines()
enum_dev_sn = []
for l in lines:
@@ -319,6 +317,7 @@ def test_dual_host_info_to_device_cdc(board):
if set(declared_devs) != set(enum_dev_sn):
failed_msg = f'Expected {declared_devs}, Enumerated {enum_dev_sn}'
+ print('\n'.join(lines))
assert False, failed_msg
return 0
@@ -337,12 +336,12 @@ def test_host_device_info(board):
ret = globals()[f'reset_{flasher["name"].lower()}'](board)
assert ret.returncode == 0, 'Failed to reset device'
- data = ser.read(1000)
+ data = ser.read(10000)
ser.close()
if len(data) == 0:
assert False, 'No data from device'
+ lines = data.decode('utf-8', errors='ignore').splitlines()
- lines = data.decode('utf-8').splitlines()
enum_dev_sn = []
for l in lines:
vid_pid_sn = re.search(r'ID ([0-9a-fA-F]+):([0-9a-fA-F]+) SN (\w+)', l)
@@ -352,8 +351,8 @@ def test_host_device_info(board):
if set(declared_devs) != set(enum_dev_sn):
failed_msg = f'Expected {declared_devs}, Enumerated {enum_dev_sn}'
+ print('\n'.join(lines))
assert False, failed_msg
-
return 0
@@ -419,7 +418,7 @@ def test_device_dfu(board):
# Wait device enum
timeout = ENUM_TIMEOUT
- while timeout:
+ while timeout > 0:
ret = run_cmd(f'dfu-util -l')
stdout = ret.stdout.decode()
if f'serial="{uid}"' in stdout and 'Found DFU: [cafe:4000]' in stdout:
@@ -427,7 +426,7 @@ def test_device_dfu(board):
time.sleep(1)
timeout = timeout - 1
- assert timeout, 'Device not available'
+ assert timeout > 0, 'Device not available'
f_dfu0 = f'dfu0_{uid}'
f_dfu1 = f'dfu1_{uid}'
@@ -460,7 +459,7 @@ def test_device_dfu_runtime(board):
# Wait device enum
timeout = ENUM_TIMEOUT
- while timeout:
+ while timeout > 0:
ret = run_cmd(f'dfu-util -l')
stdout = ret.stdout.decode()
if f'serial="{uid}"' in stdout and 'Found Runtime: [cafe:4000]' in stdout:
@@ -468,7 +467,7 @@ def test_device_dfu_runtime(board):
time.sleep(1)
timeout = timeout - 1
- assert timeout, 'Device not available'
+ assert timeout > 0, 'Device not available'
def test_device_hid_boot_interface(board):
@@ -478,13 +477,13 @@ def test_device_hid_boot_interface(board):
mouse2 = get_hid_dev(uid, 'TinyUSB', 'TinyUSB_Device', 'if01-mouse')
# Wait device enum
timeout = ENUM_TIMEOUT
- while timeout:
+ while timeout > 0:
if os.path.exists(kbd) and os.path.exists(mouse1) and os.path.exists(mouse2):
break
time.sleep(1)
timeout = timeout - 1
- assert timeout, 'HID device not available'
+ assert timeout > 0, 'HID device not available'
def test_device_hid_composite_freertos(id):
@@ -561,6 +560,9 @@ def test_board(board):
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):
@@ -577,10 +579,10 @@ def test_board(board):
print(f' {e}')
else:
print()
- print(f' Test failed: {e}, retry {i+1}')
+ print(f' Test failed: {e}, retry {i+2}/{max_rety}')
time.sleep(1)
else:
- print(f'Flashing failed, retry {i+1}')
+ print(f'Flashing failed, retry {i+2}/{max_rety}')
time.sleep(1)
if ret.returncode != 0:
diff --git a/test/hil/tinyusb.json b/test/hil/tinyusb.json
index 7393226eb..a9460bf9d 100644
--- a/test/hil/tinyusb.json
+++ b/test/hil/tinyusb.json
@@ -60,7 +60,7 @@
"name": "metro_m4_express",
"uid": "9995AD485337433231202020FF100A34",
"tests": {
- "device": true, "host": false, "dual": false,
+ "device": true, "host": false, "dual": true,
"dev_attached": [{"vid_pid": "1a86_55d4", "serial": "52D2002130"}]
},
"flasher": {
@@ -70,6 +70,19 @@
}
},
{
+ "name": "mimxrt1064_evk",
+ "uid": "BAE96FB95AFA6DBB8F00005002001200",
+ "tests": {
+ "device": true, "host": true, "dual": true,
+ "dev_attached": [{"vid_pid": "1a86_55d4", "serial": "52D2023299"}]
+ },
+ "flasher": {
+ "name": "jlink",
+ "uid": "000725299165",
+ "args": "-device MIMXRT1064xxx6A"
+ }
+ },
+ {
"name": "lpcxpresso11u37",
"uid": "17121919",
"tests": {
@@ -98,8 +111,11 @@
{
"name": "raspberry_pi_pico",
"uid": "E6614C311B764A37",
+ "build" : {
+ "flags_on": ["CFG_TUH_RPI_PIO_USB"]
+ },
"tests": {
- "device": true, "host": false, "dual": false,
+ "device": true, "host": true, "dual": true,
"dev_attached": [{"vid_pid": "1a86_55d4", "serial": "52D2002470"}]
},
"flasher": {
@@ -111,8 +127,11 @@
{
"name": "raspberry_pi_pico2",
"uid": "560AE75E1C7152C9",
+ "build" : {
+ "flags_on": ["CFG_TUH_RPI_PIO_USB"]
+ },
"tests": {
- "device": true, "host": false, "dual": false,
+ "device": true, "host": true, "dual": true,
"dev_attached": [{"vid_pid": "1a86_55d4", "serial": "533D004242"}]
},
"flasher": {
@@ -157,9 +176,9 @@
"device": true, "host": false, "dual": false
},
"flasher": {
- "name": "stlink",
+ "name": "openocd",
"uid": "004C00343137510F39383538",
- "args": ""
+ "args": "-f interface/stlink.cfg -f target/stm32h7x.cfg"
}
},
{