diff options
| author | Ha Thach <[email protected]> | 2026-05-05 15:08:41 +0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-05-05 15:08:41 +0700 |
| commit | 9b1b781c3efb778d7e631d41e44d36c8ee435906 (patch) | |
| tree | b1dda2c88b03c5f5d9bfb1f0db82793dbf9b64ce /test | |
| parent | 3170fa0bf2667c4cc8e5a22944c15686c681654e (diff) | |
| parent | 076fd79b4c16b7435060585c0337bc69133e073f (diff) | |
Merge pull request #3627 from hathach/merge-usbd-control
Refactor USB control transfer handling into `usbd.c`
Diffstat (limited to 'test')
| -rw-r--r-- | test/fuzz/rules.mk | 1 | ||||
| -rwxr-xr-x | test/hil/hil_test.py | 16 | ||||
| -rw-r--r-- | test/hil/tinyusb.json | 5 | ||||
| -rw-r--r-- | test/unit-test/CMakeLists.txt | 4 |
4 files changed, 15 insertions, 11 deletions
diff --git a/test/fuzz/rules.mk b/test/fuzz/rules.mk index 329dcce11..c14330312 100644 --- a/test/fuzz/rules.mk +++ b/test/fuzz/rules.mk @@ -23,7 +23,6 @@ SRC_C += \ src/tusb.c \ src/common/tusb_fifo.c \ src/device/usbd.c \ - src/device/usbd_control.c \ src/class/audio/audio_device.c \ src/class/cdc/cdc_device.c \ src/class/dfu/dfu_device.c \ diff --git a/test/hil/hil_test.py b/test/hil/hil_test.py index e98bd5da7..f96d0d90a 100755 --- a/test/hil/hil_test.py +++ b/test/hil/hil_test.py @@ -30,6 +30,7 @@ import argparse import os import random import re +import select import sys import time import warnings @@ -923,18 +924,27 @@ def test_device_printer_to_cdc(board): ser.reset_input_buffer() # Test 1: Printer -> CDC with multiple sizes, write in random 1-64 byte chunks + LP_WRITE_TIMEOUT = 5.0 # seconds; firmware may stall draining the printer OUT endpoint for size in sizes: test_data = rand_ascii(size) ser.reset_input_buffer() rd = b'' offset = 0 - with open(lp_dev, 'wb') as lp: + lp_fd = os.open(lp_dev, os.O_WRONLY | os.O_NONBLOCK) + try: while offset < size: chunk_size = min(random.randint(1, 64), size - offset) - lp.write(test_data[offset:offset + chunk_size]) - lp.flush() + buf = test_data[offset:offset + chunk_size] + written = 0 + while written < len(buf): + _, wr, _ = select.select([], [lp_fd], [], LP_WRITE_TIMEOUT) + assert wr, f'Printer write timeout after {LP_WRITE_TIMEOUT}s (firmware not draining OUT endpoint)' + n = os.write(lp_fd, buf[written:]) + written += n rd += ser.read(chunk_size) offset += chunk_size + finally: + os.close(lp_fd) # read any remaining bytes (fullspeed devices may need extra time) while len(rd) < size: remaining = ser.read(size - len(rd)) diff --git a/test/hil/tinyusb.json b/test/hil/tinyusb.json index a3f7ff8bf..aed711f80 100644 --- a/test/hil/tinyusb.json +++ b/test/hil/tinyusb.json @@ -156,11 +156,6 @@ "device": false, "host": true, "dual": false, "dev_attached": [ { - "vid_pid": "1a86_55d4", - "serial": "52D2023934", - "is_cdc": true - }, - { "vid_pid": "2008_2018", "serial": "O20070925A002746", "is_msc": true, diff --git a/test/unit-test/CMakeLists.txt b/test/unit-test/CMakeLists.txt index b44a91d57..a33af4563 100644 --- a/test/unit-test/CMakeLists.txt +++ b/test/unit-test/CMakeLists.txt @@ -117,14 +117,14 @@ add_ceedling_test( add_ceedling_test( test_usbd ${CEEDLING_WORKDIR}/test/device/usbd/test_usbd.c - "${CEEDLING_WORKDIR}/../../src/tusb.c;${CEEDLING_WORKDIR}/../../src/device/usbd.c;${CEEDLING_WORKDIR}/../../src/device/usbd_control.c;${CEEDLING_WORKDIR}/../../src/common/tusb_fifo.c" + "${CEEDLING_WORKDIR}/../../src/tusb.c;${CEEDLING_WORKDIR}/../../src/device/usbd.c;${CEEDLING_WORKDIR}/../../src/common/tusb_fifo.c" "${CEEDLING_BUILD_DIR}/test/mocks/test_usbd/mock_dcd.c;${CEEDLING_BUILD_DIR}/test/mocks/test_usbd/mock_msc_device.c" ) add_ceedling_test( test_msc_device ${CEEDLING_WORKDIR}/test/device/msc/test_msc_device.c - "${CEEDLING_WORKDIR}/../../src/tusb.c;${CEEDLING_WORKDIR}/../../src/device/usbd.c;${CEEDLING_WORKDIR}/../../src/device/usbd_control.c;${CEEDLING_WORKDIR}/../../src/class/msc/msc_device.c;${CEEDLING_WORKDIR}/../../src/common/tusb_fifo.c" + "${CEEDLING_WORKDIR}/../../src/tusb.c;${CEEDLING_WORKDIR}/../../src/device/usbd.c;${CEEDLING_WORKDIR}/../../src/class/msc/msc_device.c;${CEEDLING_WORKDIR}/../../src/common/tusb_fifo.c" "${CEEDLING_BUILD_DIR}/test/mocks/test_msc_device/mock_dcd.c" ) |
