Skip to content

Replace tty0tty with a USB/IP CP2102 simulator - #121

Merged
puddly merged 9 commits into
devfrom
puddly/usbip-cp2102
Sep 27, 2026
Merged

puddly merged 9 commits into
devfrom
puddly/usbip-cp2102

Conversation

@puddly

@puddly puddly commented Sep 26, 2026

Copy link
Copy Markdown
Owner

I was researching USB/IP and realized something interesting: USB/IP allows real kernel drivers to attach to fake devices exposed by userspace tools. For serialx, this allows reasonably-accurate simulation of serial hardware and lets us improve on both tty0tty and com0com.

Kernel modules like tty0tty cover the 99% use case of virtual serial ports that only need to shuttle data through a serial-ish pipe, there's no reason to be "accurate". For serialx, however, we ideally want something that behaves like a real pair of adapters connected end-to-end:

  1. Modem lines are hooked up.
  2. High baudrates are fast and low baudrates are slow.
  3. Mis-matched baudrates still "work" but yield garbage.
  4. Flow control pins work.

As it turns out, this is very straightforward to implement by allowing the real cp210x kernel driver to attach to a pair of emulated USB devices connected over loopback USB/IP. The fake USB devices show up in /dev/serial/by-id/ with proper metadata and pass the entire serialx test suite. All of the tty0tty test suite quirks for Linux have been removed: no-rts-cts,no-dtr-dsr,no-num-unwritten-bytes,no-reset-write-buffer,no-write-timeout,no-buffer-control becomes just no-reset-write-buffer.

GitHub's Azure kernels ship no USB serial drivers, so the emulated CP2102
had nothing to bind to. Build usbserial and cp210x out of tree from the
matching upstream sources, and build the emulator once per push instead
of once per Python version.
@puddly
puddly force-pushed the puddly/usbip-cp2102 branch from 70e5a6c to 705987e Compare September 27, 2026 14:34
@codecov

codecov Bot commented Sep 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.13%. Comparing base (e5d3ca3) to head (87ab635).

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #121      +/-   ##
==========================================
+ Coverage   93.11%   94.13%   +1.01%     
==========================================
  Files          24       24              
  Lines        4025     4025              
==========================================
+ Hits         3748     3789      +41     
+ Misses        277      236      -41     

☔ View full report in Codecov by Harness.
📢 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.

@puddly
puddly merged commit 779a495 into dev Sep 27, 2026
44 checks passed
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.

1 participant