Skip to content

Commit f998905

Browse files
Add Linux consumer tests; remove discovery probe
Replace external discovery-based tests with in-process consumer integration tests that validate virtual devices via SDL2 and libinput. Added tests/unit/test_linux_consumers.cpp and updated tests/CMakeLists.txt to use pkg-config and link PkgConfig::LIBINPUT and PkgConfig::SDL2. Removed the linux_discovery_probe example and the legacy tests/unit/test_linux_discovery.cpp, and cleaned up examples/CMakeLists.txt. Updated README to document the new Linux test requirements (SDL2, libinput, device nodes, X11/XTest where applicable) and adjusted CI (.github/workflows/ci.yml) to install libinput-dev, libsdl2-dev and pkg-config instead of the old joystick package.
1 parent 21c983a commit f998905

10 files changed

Lines changed: 567 additions & 410 deletions

File tree

.github/workflows/ci.yml

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,38 @@ jobs:
7878
build-essential \
7979
clang \
8080
cmake \
81-
joystick \
81+
libinput-dev \
82+
libsdl2-dev \
8283
libx11-dev \
8384
libxtst-dev \
8485
llvm \
85-
ninja-build
86+
ninja-build \
87+
pkg-config
88+
kernel_modules_package="linux-modules-extra-$(uname -r)"
89+
if apt-cache show "${kernel_modules_package}" >/dev/null 2>&1; then
90+
sudo apt-get install -y "${kernel_modules_package}"
91+
else
92+
echo "::warning::${kernel_modules_package} is unavailable; relying on the runner image kernel modules."
93+
fi
8694
sudo tee /etc/udev/rules.d/99-libvirtualhid-ci.rules >/dev/null <<'EOF'
8795
KERNEL=="hidraw*", ATTRS{name}=="libvirtualhid*", MODE="0666", TAG+="uaccess"
8896
SUBSYSTEMS=="input", ATTRS{name}=="libvirtualhid*", MODE="0666", TAG+="uaccess"
8997
EOF
9098
sudo udevadm control --reload-rules
91-
sudo modprobe uhid
92-
sudo modprobe uinput
93-
sudo chmod a+rw /dev/uhid /dev/uinput
99+
for module in uhid uinput; do
100+
if ! sudo modprobe "${module}"; then
101+
message="Unable to load ${module}; tests requiring /dev/${module} will fail unless the device already exists."
102+
echo "::warning::${message}"
103+
fi
104+
done
105+
for node in /dev/uhid /dev/uinput; do
106+
if [[ -e "${node}" ]]; then
107+
sudo chmod a+rw "${node}"
108+
else
109+
echo "::error::${node} does not exist after module setup."
110+
exit 1
111+
fi
112+
done
94113
95114
- name: Setup Dependencies macOS
96115
if: runner.os == 'macOS'

README.md

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,11 @@ current user cannot open `/dev/uhid`.
153153
The Linux uinput smoke test creates real keyboard and mouse devices and fails
154154
when the current user cannot open `/dev/uinput`.
155155

156-
The Linux discovery integration test creates a real UHID gamepad and probes
157-
external input discovery tools. It fails when `/dev/uhid` is unavailable, or
158-
when neither `evdev-joystick` from the `joystick` package nor `hidapitester` is
159-
installed.
160-
161-
When `BUILD_EXAMPLES` is enabled on Linux, the `linux_discovery_probe` example
162-
creates a generic UHID gamepad and performs the same external discovery probe
163-
outside the test runner.
156+
The Linux consumer integration tests create real virtual devices and validate
157+
them through in-process consumer libraries. SDL2 must see the UHID gamepad and
158+
observe button/axis input. libinput must see the uinput keyboard and mouse and
159+
observe key, pointer motion, and button events. These tests fail when the Linux
160+
device nodes or consumer development libraries are unavailable.
164161

165162
The XTest fallback should not be treated as a gamepad backend. It can cover
166163
keyboard and mouse injection on X11, but it does not create virtual HID devices,
@@ -273,8 +270,8 @@ the requirements expressed in terms that apply to other consumers:
273270
- [x] Keep the public headers under `include/libvirtualhid` and the implementation
274271
split into shared core code plus platform-specific backends.
275272
- [x] Add Windows CI coverage for the client library with MSVC and MinGW/UCRT64.
276-
- [x] Add Linux CI coverage for GCC and Clang, with integration tests gated behind
277-
explicit availability of `/dev/uinput`, `/dev/uhid`, or X11/XTest.
273+
- [x] Add Linux CI coverage for GCC and Clang, with integration tests requiring
274+
`/dev/uinput`, `/dev/uhid`, SDL2, libinput, and X11/XTest where applicable.
278275
- [ ] Add separate WDK/MSVC validation for the driver package once driver sources
279276
exist.
280277
@@ -326,8 +323,8 @@ third-party/googletest/ GoogleTest submodule
326323
- [x] Add `uinput` support for keyboard and mouse once the gamepad path is stable.
327324
- [x] Support output report callbacks for rumble and profile-specific feedback.
328325
- [x] Add X11/XTest fallback support for keyboard and mouse only.
329-
- [x] Add examples and integration tests that validate external gamepad
330-
discovery where available.
326+
- [x] Add examples and integration tests that validate virtual device visibility
327+
through SDL2 for gamepads and libinput for keyboard/mouse.
331328
- [x] Document required Linux permissions and sample udev rules.
332329

333330
### Phase 3: Windows MVP
@@ -368,7 +365,7 @@ third-party/googletest/ GoogleTest submodule
368365
- [ ] Validate multi-controller behavior and stable ordering.
369366
- [ ] Test against real consumers where practical: Sunshine, SDL, HIDAPI, browser
370367
Gamepad API, DirectInput/XInput/GameInput on Windows, and evdev/libinput
371-
tooling on Linux.
368+
libraries on Linux.
372369

373370
## License
374371

examples/CMakeLists.txt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,3 @@ target_link_libraries(keyboard_mouse_adapter
1414

1515
libvirtualhid_copy_mingw_runtime(gamepad_adapter)
1616
libvirtualhid_copy_mingw_runtime(keyboard_mouse_adapter)
17-
18-
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
19-
add_executable(linux_discovery_probe
20-
"${CMAKE_CURRENT_SOURCE_DIR}/linux_discovery_probe.cpp")
21-
22-
target_link_libraries(linux_discovery_probe
23-
PRIVATE
24-
libvirtualhid::libvirtualhid)
25-
endif()

examples/linux_discovery_probe.cpp

Lines changed: 0 additions & 168 deletions
This file was deleted.

src/platform/linux/uhid_backend.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939
#include <X11/keysym.h>
4040
#include <X11/Xlib.h>
4141
#include <X11/Xutil.h>
42+
43+
// Xlib defines Status as a macro, which collides with lvh::Status.
44+
#if defined(Status)
45+
#undef Status
46+
#endif
4247
#endif
4348

4449
// local includes

tests/CMakeLists.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@ set(LIBVIRTUALHID_TEST_SOURCES
1818
"${CMAKE_CURRENT_SOURCE_DIR}/fixtures/fixtures.cpp"
1919
"${CMAKE_CURRENT_SOURCE_DIR}/unit/test_gamepad_lifecycle.cpp"
2020
"${CMAKE_CURRENT_SOURCE_DIR}/unit/test_linux_backend.cpp"
21-
"${CMAKE_CURRENT_SOURCE_DIR}/unit/test_linux_discovery.cpp"
21+
"${CMAKE_CURRENT_SOURCE_DIR}/unit/test_linux_consumers.cpp"
2222
"${CMAKE_CURRENT_SOURCE_DIR}/unit/test_profiles.cpp"
2323
"${CMAKE_CURRENT_SOURCE_DIR}/unit/test_report.cpp"
2424
"${CMAKE_CURRENT_SOURCE_DIR}/unit/test_runtime.cpp")
2525

2626
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
27+
find_package(PkgConfig REQUIRED)
28+
pkg_check_modules(LIBINPUT REQUIRED IMPORTED_TARGET libinput)
29+
pkg_check_modules(SDL2 REQUIRED IMPORTED_TARGET sdl2)
30+
2731
list(APPEND LIBVIRTUALHID_TEST_SOURCES
2832
"${CMAKE_CURRENT_SOURCE_DIR}/fixtures/linux_backend_test_hooks.cpp")
2933

@@ -45,6 +49,13 @@ target_link_libraries(${TEST_BINARY}
4549
gmock_main
4650
libvirtualhid::libvirtualhid)
4751

52+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
53+
target_link_libraries(${TEST_BINARY}
54+
PRIVATE
55+
PkgConfig::LIBINPUT
56+
PkgConfig::SDL2)
57+
endif()
58+
4859
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND LIBVIRTUALHID_ENABLE_XTEST AND X11_FOUND AND X11_XTest_FOUND)
4960
target_compile_definitions(${TEST_BINARY}
5061
PRIVATE

0 commit comments

Comments
 (0)