Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@dpgeorge
Copy link
Member

Summary

The existing serial_test.py script tests data in/out throughput and reliability. But it only tests data sizes that are a power of two. It's also important to test reliability of data in/out that is not a power of two.

This PR adds a new echo sub-test to the serial_test.py script. It sends out data to the board and gets the board to echo it back, and then compares the result (the echo'd data should be equal to the sent data). It does this for data packets between 1 and 520 (inclusive) bytes. That covers USB FS and HS packet sizes (64 and 512 respectively).

It uses random data for the test, but seeded by a constant seed so that it's deterministic. If there's an error then it prints out all the sent and echo'd data to make it easier to see where it went wrong (eg if the previous packet was repeated).

Testing

Tested on PYBV11 with the stm32 and TinyUSB stacks:

  • using Linux as the host the new tests pass
  • using macOS as the host, the stm32 USB stack passes the test, but TinyUSB fails!

Testing ESP32-S3 (uses TinyUSB), again it passes on Linux but fails on macOS.

So, this is an important test, it found a bug.

Trade-offs and Alternatives

It takes around 10 seconds to run on a board with UART REPL, but I'm not sure how to make that faster without decreasing the coverage of the test.

@dpgeorge dpgeorge added the tests Relates to tests/ directory in source label Nov 11, 2025
@codecov
Copy link

codecov bot commented Nov 11, 2025

Codecov Report

βœ… All modified and coverable lines are covered by tests.
βœ… Project coverage is 98.38%. Comparing base (2762fe6) to head (816713b).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #18402   +/-   ##
=======================================
  Coverage   98.38%   98.38%           
=======================================
  Files         171      171           
  Lines       22294    22294           
=======================================
  Hits        21933    21933           
  Misses        361      361           

β˜” View full report in Codecov by Sentry.
πŸ“’ Have feedback on the report? Share it here.

πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • πŸ“¦ JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dpgeorge
Copy link
Member Author

@andrewleech @iabdalkader this test uncovers a bug in TinyUSB's DWC2 backend (my current working theory), which is used by a lot of chips. Eg STM32 F4, F7 and N6 (but not WB!), as well as ESP32-S3. But it's only apparent when a macOS is the host PC.

Would you be able to see if you can reproduce the issue that I'm seeing? To do that, build an STM32 board using TinyUSB that uses DWC2, and then run the script from this PR on macOS (with the board connected). I'm seeing it fail the echo test at a packet size of 65 (it repeats the 64 byte packet).

You can also try with an ESP32-S3 if you like, you should see the same error.

@iabdalkader
Copy link
Contributor

I don't have any macos to test with.

I'm seeing it fail the echo test at a packet size of 65 (it repeats the 64 byte packet).

It sounds like the extra byte is buffered, maybe call tud_cdc_write_flush()?

@dpgeorge
Copy link
Member Author

It's actually a bug in TinyUSB, which was fixed very recently, see: hathach/tinyusb#3293

@andrewleech
Copy link
Contributor

andrewleech commented Nov 12, 2025

Oh nice find, I was about to test but looks like don't need to rush!
Always nice to see an old TODO comment replaced with updated impl :-D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Relates to tests/ directory in source

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants