Skip to content

tools: add serial test programs and a host runner - #6023

Closed
dgryski wants to merge 2 commits into
tinygo-org:devfrom
dgryski:uart-test-tools
Closed

dgryski wants to merge 2 commits into
tinygo-org:devfrom
dgryski:uart-test-tools

Conversation

@dgryski

@dgryski dgryski commented Oct 24, 2026

Copy link
Copy Markdown
Member

I wrote these tests while checking the Arduino Uno R4 UART driver in #6015. They only use the default serial port, so they seemed useful for other boards too.

tools/uart-test has a host runner and a few small TinyGo programs. The runner flashes each program with tinygo flash, then checks the output over the board's serial port. It builds with the standard Go compiler and uses go.bug.st/serial.

go run ./tools/uart-test -target <target>

Tests:

  • echo: bytes sent to the board come back unchanged
  • burst: overflowing the RX buffer keeps the first bytes and receiving still works
  • seq: 2000 numbered lines arrive in order
  • bytes: all 256 byte values arrive intact
  • conc: serial output and input work together with goroutines and allocation

I ran all of them on an Arduino Uno R4 WiFi and they pass. The programs also compile for the pico, feather-m4, arduino-nano33 and stm32f4disco, but I have only run them on the R4.

Does tools make sense for this? I'm happy to move it somewhere else in this repo, or to another repo such as tinygo-org/drivers, if that fits better. I'm also fine with dropping it if it isn't wanted.

Flashes small programs that exercise the default serial port and checks their output over the board's serial port.
@dgryski

dgryski commented Oct 25, 2026 •

Copy link
Copy Markdown
Member Author

I ran these tests on more boards.

Board Target Serial echo burst seq bytes conc
Arduino Uno R4 WiFi arduino-uno-r4-wifi UART through the ESP32-S3 bridge (with #6015) pass pass pass pass pass
Arduino Nano (clone, ATmega328P) arduino-nano UART through a USB-serial chip pass pass pass pass not supported, AVR has no goroutine scheduler
Raspberry Pi Pico 2 W pico2-w USB CDC pass pass pass pass pass
Raspberry Pi Pico 2 pico2 USB CDC pass pass pass pass pass
Raspberry Pi Pico pico USB CDC pass pass pass pass pass
Seeed XIAO M0 (SAMD21) xiao USB CDC pass pass pass pass fail

The conc failure on the XIAO is a bug in the SAMD USB driver that these tests found. The fix is in #6024.

The Nano needed the second commit in this PR, which sets the baud rate to 115200 so that boards with a different default baud rate work.

The RX buffer size differs by board, 32 bytes on the Nano, 128 on the R4 UART and 512 on the USB CDC boards. The burst test does not depend on the size.

The runner uses 115200 but the programs used the default of each board. AVR defaults to 9600.

@davecheney davecheney left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I love the idea

@dgryski

dgryski commented Oct 25, 2026

Copy link
Copy Markdown
Member Author

I'm building a larger test suite with the serial tests as one part. Currently stalled on that because of a reproducible hang on pico2 when trying to run the new tests. Let's hold off on merging this one until I'm happy with the newer tests or decide they're not worth it.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants