tests: virtual HID device test harness (Linux/Windows/macOS/libusb)#815
Draft
Youw wants to merge 2 commits into
Draft
tests: virtual HID device test harness (Linux/Windows/macOS/libusb)#815Youw wants to merge 2 commits into
Youw wants to merge 2 commits into
Conversation
Member
|
Great. We need this kind of virtual test device for hidapi (and also libusb). |
1cdc8d5 to
b330600
Compare
Member
|
FYI on WDK, the Windows runners have WDK installed already. Nuget WDK -- smaller but lacking some tools, which may be okay for this purpose Reference: |
b330600 to
b4693d6
Compare
Add a reusable harness that runs HIDAPI tests against a *virtual* HID device,
needing no physical hardware. Tests use only the public HIDAPI API plus a
backend-agnostic test_virtual_device interface, so the same test runs against
every backend that ships a virtual-device provider. Devices expose pre-recorded
"scenarios": the test sends a Feature report carrying a command byte and the
device replays the matching canned input report.
- src/tests/test_device_io.c: a simple open -> write -> exchange reports ->
close smoke test (skips via CTest code 77 when no virtual device is present).
- Providers:
test_virtual_device_uhid.c Linux hidraw (kernel /dev/uhid)
test_virtual_device_rawgadget.c Linux libusb (/dev/raw-gadget + dummy_hcd)
test_virtual_device_win.c (+windows/driver/) Windows winapi (vhidmini2 UMDF2)
test_virtual_device_mac.c macOS darwin (IOHIDUserDevice)
Each self-skips when its device can't be created.
- HIDAPI_WITH_TESTS is offered on Linux/macOS too; src/tests builds the test for
whichever backend(s) are present.
- src/tests/README.md documents the providers, the scenario protocol, and why
FreeBSD/NetBSD/OpenBSD have no provider (no userspace HID/USB-create facility).
Assisted-by: Claude:claude-opus-4.8
- builds.yml: build the test on Linux/Windows/macOS and run it where possible (ubuntu-cmake loads uhid and runs DeviceIO_hidraw; Windows/macOS/libusb build and self-skip), keeping the per-push matrix green. - win-vhid-test.yml: build, self-sign and install the vhidmini2 driver on a hosted windows-latest runner and run DeviceIO_winapi against it. - libusb-vhid-test.yml (+ .github/vmrun-libusb.sh): the hosted kernel has no USB gadget subsystem, so run DeviceIO_libusb inside a virtme-ng VM that boots a generic kernel (building dummy_hcd out-of-tree and loading raw_gadget) against a real virtual USB device. Both privileged jobs run only via workflow_dispatch or a 'ci-virtual-device' pull-request label, so they stay out of the per-push matrix. Assisted-by: Claude:claude-opus-4.8
5a24890 to
6089973
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a small, reusable virtual HID device test harness so HIDAPI can be tested without physical hardware. Tests are written purely against the public HIDAPI API plus a backend-agnostic
test_virtual_deviceinterface, so the same test runs against every backend that ships a provider.Devices expose pre-recorded scenarios: the test sends a Feature report whose first payload byte is a command, and the device replays the matching canned input report — keeping the test code 100% platform-neutral.
Intended as a foundation further tests can build on (e.g. the
hid_read_interrupttest in #799 can rebase onto this harness).What's here
src/tests/test_device_io.c— a simple open → write → exchange reports (Feature trigger / input read) → close smoke test.test_virtual_device_uhid.c/dev/uhidtest_virtual_device_rawgadget.c/dev/raw-gadget+dummy_hcd, inside a VMlibusb-vhid-test)test_virtual_device_win.c+windows/driver/win-vhid-test)test_virtual_device_mac.cIOHIDUserDevice(IOKit)See
src/tests/README.mdfor details, including why FreeBSD/NetBSD/OpenBSD have no provider (no userspace HID/USB-create facility on any BSD).CI
builds.yml): the test is built on all platforms and run where possible.ubuntu-cmakeloadsuhidand runsDeviceIO_hidrawfor real; Windows/macOS build the test and self-skip — so the matrix stays green everywhere.win-vhid-test.yml(manual): builds, self-signs and installs the vhidmini2 driver on a hostedwindows-latestrunner and runsDeviceIO_winapiagainst the real device. ✅ verified passing.libusb-vhid-test.yml(manual): the hostedubuntu-latest(azure) kernel has no USB gadget subsystem, so this runsDeviceIO_libusbinside a lightweightvirtme-ng+ QEMU VM that boots a generic kernel (buildingdummy_hcdout-of-tree and loadingraw_gadget), against a real virtual USB device. ✅ verified passing. The same approach works locally and on WSL2.The two privileged jobs run only via
workflow_dispatchor when a pull request carries theci-virtual-devicelabel, so they stay out of the per-push matrix.Commits
tests: add a backend-agnostic virtual HID device test harnessci: build and run the virtual HID device testsDrafted with Claude Code.