tests: hotplug API and virtual-device hotplug scenarios#826
Draft
Youw wants to merge 1 commit into
Draft
Conversation
Two new test tiers for the hotplug API: - test_hotplug_api.c (HotplugAPI_<backend>): argument validation, callback-handle properties, implicit init, hid_exit() teardown and register/deregister thread churn. Needs no device or privileges, so it runs against every backend in the ordinary CI matrix. - test_hotplug.c (Hotplug_<backend>): device-backed hotplug scenarios (async delivery, exactly-once ENUMERATE pass, callback-return deregistration, pass-before-live ordering, ARRIVED/LEFT payloads, filtering, dispatch order, deregistration post-condition and re-entrant registration) against a virtual device whose presence is toggled with the new test_virtual_device_unplug()/_replug() calls. Implemented for the uhid provider (UHID_DESTROY/UHID_CREATE2 on the same fd); the other providers return TEST_VDEV_UNAVAILABLE and their hotplug tests self-skip until presence toggling is implemented. Assisted-by: claude-code:claude-fable-5
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.
Adds the test suite for the hotplug API (#764 / connection-callback), in two tiers, built on the virtual-device test harness from #815.
What is in here
src/tests/test_hotplug_api.c— tier 1,HotplugAPI_<backend>: everything in the hotplug contract that is observable without a device event (argument validation, callback-handle properties, implicithid_init(),hid_exit()teardown incl. a register→immediate-hid_exitstress loop, and a 2-thread register/deregister churn). Needs no device, no privileges: registered for all four backends and runs in the ordinary per-push CI matrix. Self-skips (77) when a backend reports hotplug as unsupported at runtime (e.g. libusb withoutLIBUSB_CAP_HAS_HOTPLUG).src/tests/test_hotplug.c— tier 2,Hotplug_<backend>: device-backed scenarios: async delivery, exactly-once ENUMERATE pass, callback-return deregistration (live + mid-pass), pass-before-live ordering, ARRIVED/LEFT payloads and path correlation, LEFT-without-ENUMERATE, VID/PID filtering, registration-order dispatch, the deregistration post-condition, and register/deregister from within a callback.test_virtual_device_unplug()/test_virtual_device_replug()— new provider calls that toggle device presence without destroying the provider context. Implemented for the uhid provider (UHID_DESTROY/UHID_CREATE2on the same fd); the rawgadget/vhidmini2/IOHIDUserDevice providers returnTEST_VDEV_UNAVAILABLEfor now, so theirHotplug_*tests self-skip everywhere (they compile and are registered, ready for when toggling is implemented).The tier-2 test follows a strict synchronization discipline (see
src/tests/README.md): callbacks only deep-copy events into a lock-protected log; every expectation is a deadline-based predicate poll; absence assertions sit behind event barriers, not time windows; no retries.Where each test runs
HotplugAPI_hidraw,HotplugAPI_libusbbuilds.ymlubuntu-cmakeHotplugAPI_winapibuilds.ymlwindows-cmake (MSVC, NMake, ClangCL, MinGW)HotplugAPI_darwinbuilds.ymlmacos-cmakeHotplug_hidrawbuilds.ymlubuntu-cmake (viamodprobe uhid+sudo ctest)Hotplug_libusblibusb-vhid-testjob) until rawgadget unplug/replug existsHotplug_winapiwin-vhid-testjob) until driver-side presence toggling existsHotplug_darwinDeviceIO_darwinThe behavioral expectations encode the async-ENUMERATE contract, i.e. they require #822, #823, #824 and #825. On
connection-callbackas-is, tier 1 fails (e.g.*callback_handleis not zeroed on a failed registration yet), so this PR's CI will be red until those four PRs land — that is expected and is the reason this PR is a draft.Validation ahead of that: an integration branch (
hotplug-integration=connection-callback+ all four backend PRs + these tests) runs the same CI; there,HotplugAPI_hidraw/HotplugAPI_libusbpass in a local WSL run of both backends andHotplugAPI_winapipasses locally on Windows/MSVC.Relates to: #764
Assisted-by: claude-code:claude-fable-5