-
Notifications
You must be signed in to change notification settings - Fork 1.4k
add more hil tests #3557
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add more hil tests #3557
Changes from 1 commit
a3b2b42
45e80a1
55994bc
b2a592d
3e47f1f
6c895e7
b765656
0521e66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -416,6 +416,80 @@ def test_host_device_info(board): | |
| return 0 | ||
|
|
||
|
|
||
| def test_host_cdc_msc_hid(board): | ||
| flasher = board['flasher'] | ||
| cdc_devs = [d for d in board['tests'].get('dev_attached', []) if d.get('is_cdc')] | ||
| if not cdc_devs: | ||
| return | ||
hathach marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| port = get_serial_dev(flasher["uid"], None, None, 0) | ||
| ser = open_serial_dev(port) | ||
| ser.timeout = 0.1 | ||
|
|
||
| # reset device to catch mount messages | ||
| ret = globals()[f'reset_{flasher["name"].lower()}'](board) | ||
| assert ret.returncode == 0, 'Failed to reset device' | ||
|
|
||
|
|
||
| # Wait for CDC mounted message | ||
| data = b'' | ||
| timeout = ENUM_TIMEOUT | ||
| while timeout > 0: | ||
| new_data = ser.read(ser.in_waiting or 1) | ||
| if new_data: | ||
| data += new_data | ||
| if b'CDC Interface is mounted' in data: | ||
| break | ||
| time.sleep(0.1) | ||
| timeout -= 0.1 | ||
| assert b'CDC Interface is mounted' in data, 'CDC device not mounted on host' | ||
|
|
||
| # Lookup serial chip name from vid_pid | ||
| vid_pid_name = { | ||
| '0403_6001': 'FTDI', '0403_6010': 'FTDI', '0403_6011': 'FTDI', '0403_6014': 'FTDI', | ||
| '10c4_ea60': 'CP210x', '10c4_ea70': 'CP210x', | ||
| '067b_2303': 'PL2303', '067b_23a3': 'PL2303', | ||
| '1a86_7523': 'CH340', '1a86_7522': 'CH340', | ||
| '1a86_55d3': 'CH9102', '1a86_55d4': 'CH9102', | ||
| } | ||
| dev = cdc_devs[0] | ||
| chip_name = vid_pid_name.get(dev['vid_pid'], dev['vid_pid']) | ||
| for l in data.decode('utf-8', errors='ignore').splitlines(): | ||
| if 'CDC Interface is mounted' in l: | ||
| print(f'\r\n {chip_name}: {l} ', end='') | ||
|
|
||
| # CDC echo test via flasher serial | ||
| time.sleep(2) | ||
| ser.reset_input_buffer() | ||
|
|
||
| def rand_ascii(length): | ||
| return "".join(random.choices(string.ascii_letters + string.digits, k=length)).encode("ascii") | ||
|
|
||
| sizes = [8, 32, 64, 128] | ||
| for size in sizes: | ||
| test_data = rand_ascii(size) | ||
| ser.reset_input_buffer() | ||
|
|
||
| # Write byte-by-byte with delay to avoid UART overrun | ||
| for b in test_data: | ||
| ser.write(bytes([b])) | ||
| ser.flush() | ||
| time.sleep(0.001) | ||
|
|
||
| # Read echo back with timeout | ||
| echo = b'' | ||
| t = 5.0 | ||
| while t > 0 and len(echo) < size: | ||
| rd = ser.read(max(1, ser.in_waiting)) | ||
| if rd: | ||
| echo += rd | ||
| time.sleep(0.05) | ||
| t -= 0.05 | ||
| assert echo == test_data, (f'CDC echo wrong data ({size} bytes):\n' | ||
| f' expected: {test_data}\n received: {echo}') | ||
|
|
||
| ser.close() | ||
|
|
||
|
|
||
|
Comment on lines
+482
to
+566
|
||
| # ------------------------------------------------------------- | ||
| # Tests: device | ||
| # ------------------------------------------------------------- | ||
|
|
@@ -763,6 +837,7 @@ def test_device_mtp(board): | |
| ] | ||
|
|
||
| host_test = [ | ||
| 'host/cdc_msc_hid', | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Adding Useful? React with 👍 / 👎. |
||
| 'host/device_info', | ||
| ] | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
HAL_Delay(10)in this retry loop can deadlock STM32H7 FreeRTOS startups:board_init()disables SysTick before callingboard_init2()inhw/bsp/stm32h7/family.c, so if the first I2C access fails here,HAL_Delay()has no advancing tick source and blocks indefinitely instead of retrying. This retry path needs a delay mechanism that works before the scheduler/tick is running.Useful? React with 👍 / 👎.