Skip to content

WIP: backend-agnostic virtual HID device test harness (all platforms) #1

WIP: backend-agnostic virtual HID device test harness (all platforms)

WIP: backend-agnostic virtual HID device test harness (all platforms) #1

name: Linux libusb Virtual HID Device Test (manual)
# Brings up a virtual USB HID device with USB Raw Gadget (/dev/raw-gadget) on
# top of dummy_hcd, then runs the backend-agnostic device-I/O test against it
# through the HIDAPI libusb backend. dummy_hcd is not packaged by Ubuntu, so it
# is built out-of-tree against the runner kernel headers; everything is
# best-effort and the test self-skips (CTest code 77) if the modules can't be
# provided. Run on demand (the push trigger is for developing this branch).
on:
workflow_dispatch:
push:
branches:
- virtual-device-tests
jobs:
libusb-rawgadget:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
path: hidapisrc
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libudev-dev libusb-1.0-0-dev build-essential cmake
sudo apt-get install -y "linux-modules-extra-$(uname -r)" "linux-headers-$(uname -r)" || true
- name: Load raw_gadget and dummy_hcd
run: |
set -x
sudo modprobe raw_gadget || true
sudo modprobe dummy_hcd || true
if ! lsmod | grep -q dummy_hcd; then
echo "dummy_hcd not packaged; building out-of-tree..."
git clone --depth 1 https://github.com/xairy/raw-gadget.git rawgadget || true
if [ -d rawgadget/dummy_hcd ]; then
make -C rawgadget/dummy_hcd || true
sudo insmod rawgadget/dummy_hcd/dummy_hcd.ko || true
fi
fi
sudo modprobe raw_gadget || true
echo "--- modules ---"; lsmod | grep -E 'raw_gadget|dummy_hcd' || echo "(modules not fully loaded)"
ls -l /dev/raw-gadget || echo "/dev/raw-gadget not present -> test will self-skip"
- name: Configure + build (libusb backend + tests)
run: |
cmake -B build -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DHIDAPI_WITH_LIBUSB=ON -DHIDAPI_WITH_HIDRAW=OFF -DHIDAPI_WITH_TESTS=ON
cmake --build build
- name: Run device-I/O test against the raw-gadget virtual device
working-directory: build
run: |
# Root is needed to open /dev/raw-gadget and for the libusb backend to
# detach the kernel driver and claim the interface.
sudo ctest -R DeviceIO_libusb --output-on-failure