summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2026-04-05 11:56:15 +0700
committerGitHub <[email protected]>2026-04-05 11:56:15 +0700
commit333a38d664c748d82bceedcf81a37fa580347991 (patch)
tree2565315548fd25e8ef556c348e2166997b35477a /test
parent625244854e4b4eeba01ef959ebfe1aa7d62d47e4 (diff)
parent3747355841f35cf5f1b2998c1806d8d19b167722 (diff)
Merge pull request #3584 from hathach/fix-hil
Fix CDC echo test issue for IMXRT and fast MCUs
Diffstat (limited to 'test')
-rw-r--r--test/hil/hil_ci.sh69
-rwxr-xr-xtest/hil/hil_test.py14
-rw-r--r--test/hil/tinyusb.json26
3 files changed, 99 insertions, 10 deletions
diff --git a/test/hil/hil_ci.sh b/test/hil/hil_ci.sh
new file mode 100644
index 000000000..fa8bb0245
--- /dev/null
+++ b/test/hil/hil_ci.sh
@@ -0,0 +1,69 @@
+#!/bin/bash
+# Run HIL test remotely on ci.lan
+# Usage: test/hil/hil_ci.sh [-b BOARD] [-t TEST] [extra hil_test.py args...]
+# Example:
+# test/hil/hil_ci.sh -b stm32f723disco
+# test/hil/hil_ci.sh -b stm32f723disco -t host/cdc_msc_hid -r 1
+
+set -e
+
+REMOTE=ci.lan
+REMOTE_DIR=/tmp/tinyusb-hil
+SCRIPT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
+
+# Parse -b BOARD from arguments to know which build to copy
+BOARD=""
+ARGS=()
+while [[ $# -gt 0 ]]; do
+ case "$1" in
+ -b)
+ BOARD="$2"
+ ARGS+=("$1" "$2")
+ shift 2
+ ;;
+ *)
+ ARGS+=("$1")
+ shift
+ ;;
+ esac
+done
+
+# Setup remote directory
+echo "==> Setting up remote $REMOTE:$REMOTE_DIR"
+ssh "$REMOTE" "rm -rf $REMOTE_DIR && mkdir -p $REMOTE_DIR/test/hil $REMOTE_DIR/examples"
+
+# Copy HIL test script and config
+echo "==> Copying test scripts"
+scp -q "$SCRIPT_DIR/test/hil/hil_test.py" \
+ "$SCRIPT_DIR/test/hil/pymtp.py" \
+ "$SCRIPT_DIR/test/hil/tinyusb.json" \
+ "$REMOTE:$REMOTE_DIR/test/hil/"
+
+# Copy only firmware binaries (elf/bin/hex), preserving directory structure
+copy_board_binaries() {
+ local src="$1"
+ local board_name
+ board_name=$(basename "$src")
+ rsync -a --include='*/' --include='*.elf' --include='*.bin' --include='*.hex' --exclude='*' \
+ "$src" "$REMOTE:$REMOTE_DIR/examples/"
+}
+
+if [ -n "$BOARD" ]; then
+ BUILD_DIR="$SCRIPT_DIR/examples/cmake-build-$BOARD"
+ if [ ! -d "$BUILD_DIR" ]; then
+ echo "Error: build directory not found: $BUILD_DIR"
+ echo "Build first with: cd examples && cmake -DBOARD=$BOARD -G Ninja -B cmake-build-$BOARD .. && cmake --build cmake-build-$BOARD"
+ exit 1
+ fi
+ echo "==> Copying binaries for $BOARD"
+ copy_board_binaries "$BUILD_DIR"
+else
+ echo "==> Copying all built binaries"
+ for dir in "$SCRIPT_DIR"/examples/cmake-build-*/; do
+ [ -d "$dir" ] && copy_board_binaries "$dir"
+ done
+fi
+
+# Run test
+echo "==> Running HIL test on $REMOTE"
+ssh -t "$REMOTE" "cd $REMOTE_DIR && python3 -u test/hil/hil_test.py -B examples ${ARGS[*]} tinyusb.json"
diff --git a/test/hil/hil_test.py b/test/hil/hil_test.py
index cf3cff1a3..f23e2fc22 100755
--- a/test/hil/hil_test.py
+++ b/test/hil/hil_test.py
@@ -564,7 +564,7 @@ def test_host_cdc_msc_hid(board):
ser.flush()
# wait until this chunk is echoed back
echo = b''
- t_end = time.monotonic() + 5.0
+ t_end = time.monotonic() + 1.0
while time.monotonic() < t_end and len(echo) < chunk_size:
rd = ser.read(chunk_size - len(echo))
if rd:
@@ -1189,9 +1189,8 @@ def test_example(board, f1, example):
print(f'Flashing {fw_name}.elf')
# flash firmware. It may fail randomly, retry a few times
- max_rety = 3
start_s = time.time()
- for i in range(max_rety):
+ for i in range(max_retry):
ret = globals()[f'flash_{board["flasher"]["name"].lower()}'](board, fw_name)
if ret.returncode == 0:
try:
@@ -1202,14 +1201,14 @@ def test_example(board, f1, example):
print(' OK', end='')
break
except Exception as e:
- if i == max_rety - 1:
+ if i == max_retry - 1:
err_count += 1
print(f'{STATUS_FAILED}: {e}')
else:
- print(f'\n Test failed: {e}, retry {i+2}/{max_rety}', end='')
+ print(f'\n Test failed: {e}, retry {i+2}/{max_retry}', end='')
time.sleep(0.5)
else:
- print(f'\n Flash failed, retry {i+2}/{max_rety}', end='')
+ print(f'\n Flash failed, retry {i+2}/{max_retry}', end='')
time.sleep(0.5)
if ret.returncode != 0:
@@ -1269,6 +1268,7 @@ def main():
global verbose
global test_only
global build_dir
+ global max_retry
duration = time.time()
@@ -1278,6 +1278,7 @@ def main():
parser.add_argument('-s', '--skip', action='append', default=[], help='Skip boards from test')
parser.add_argument('-t', '--test-only', action='append', default=[], help='Tests to run, all if not specified')
parser.add_argument('-B', '--build', default='cmake-build', help='Build folder name (default: cmake-build)')
+ parser.add_argument('-r', '--retry', type=int, default=3, help='Retry count for failed tests (default: 3)')
parser.add_argument('-v', '--verbose', action='store_true', help='Verbose output')
args = parser.parse_args()
@@ -1287,6 +1288,7 @@ def main():
verbose = args.verbose
test_only = args.test_only
build_dir = args.build
+ max_retry = args.retry
# if config file is not found, try to find it in the same directory as this script
if not os.path.exists(config_file):
diff --git a/test/hil/tinyusb.json b/test/hil/tinyusb.json
index 86ac902ce..92b7b21b0 100644
--- a/test/hil/tinyusb.json
+++ b/test/hil/tinyusb.json
@@ -62,11 +62,15 @@
{
"name": "metro_m4_express",
"uid": "9995AD485337433231202020FF100A34",
- "build" : {
- "args": ["MAX3421_HOST=1"]
+ "build": {
+ "args": [
+ "MAX3421_HOST=1"
+ ]
},
"tests": {
- "device": true, "host": false, "dual": true,
+ "device": true,
+ "host": false,
+ "dual": true,
"dev_attached": [{"vid_pid": "067b_2303", "serial": "0", "is_cdc": true}],
"comment": "pl23x"
},
@@ -178,7 +182,21 @@
"uid": "560AE75E1C7152C9",
"tests": {
"device": false, "host": true, "dual": false,
- "dev_attached": [{"vid_pid": "1a86_55d4", "serial": "52D2002694", "is_cdc": true}]
+ "dev_attached": [
+ {
+ "vid_pid": "1a86_55d4",
+ "serial": "52D2002694",
+ "is_cdc": true
+ },
+ {
+ "vid_pid": "0951_1603",
+ "serial": "820000000000000045B46338",
+ "is_msc": true,
+ "block_size": 512,
+ "block_count": 3987456,
+ "msc_inquiry": "Kingston DataTraveler 2.0 1.0"
+ }
+ ]
},
"flasher": {
"name": "openocd",