Skip to content

Tests: the host GameInput.dll path from mapped code - #2420

Merged
ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
Sc4ros:gameinput-host-test
Nov 23, 2026
Merged

ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
Sc4ros:gameinput-host-test

Conversation

@Sc4ros

@Sc4ros Sc4ros commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Claim: #2300 (comment) (new item: a test for the host GameInput.dll path)

AI-assisted (Claude), tested by running the code below on Windows; see "Tested".

Problem

docs/gameinput.md says that without the SDL3 shim the loader binds GameInputCreate to the host's GameInput.dll (#279), and runtime/CMakeLists.txt repeats it. No test covers that path: gameinput_test exercises the shim, and the shim is not built when SDL3 is missing, which is the default configuration.

Change

A test only, plus one paragraph of docs:

  • test/fixtures/gameinput_host.cpp: a CRT-free DLL built against the SDK's GameInput.h and gameinput.lib (so GameInputCreate is imported from GameInput.dll, by ordinal, as a title's import would be). Its export calls GameInputCreate, GetCurrentTimestamp, GetCurrentReading and, when a pad gives a reading, GetGamepadState.
  • test/gameinput_host_test.cpp (ctest gameinput_host) maps it with rt::Loader and checks that the import binds to the host's copy (the test links no shim table, so it cannot be a shim), that GameInputCreate succeeds from mapped code, that the library returns a timestamp, and that GetCurrentReading returns either success or GAMEINPUT_E_READING_NOT_FOUND. It passes with or without a pad attached.
  • The test exits 77 (skipped) when there is no GameInput.dll on the machine, and is only configured when gameinput.lib is found in the Windows SDK.
  • docs/gameinput.md says the path is now tested, and what the test checks.

Tested

Windows 11 (build 26300, GameInput.dll 0.2309.26100.9818), MSVC 19.44 (VS 2022 Build Tools, Visual Studio generator, Release), AMD Radeon RX 9060 XT, driver 32.0.32029.2010. Base: 49475796 (main).

  • ctest --test-dir runtime/build -C Release on this branch: 117 run, 111 passed, 6 skipped (five need the package, vk_sync_validation skips itself), 0 failed. gameinput (the SDL3 shim's test) is disabled because SDL3 is not installed here.
  • gameinput_host_test here, no pad attached: all checks pass (GameInputCreate returns S_OK, a non-zero timestamp, reading 0x838A0003). An earlier C build of the same fixture, run with a gamepad attached, also passed: a reading came back and GetGamepadState succeeded.
  • No game data and no input values are read or logged beyond the HRESULTs.

@Kam471

Kam471 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Verified on Windows: built with MSVC 19.44.35228.0 + SDK 10.0.26100.0 and ran the focused CTest.

cmake -S runtime -B <temp> -G "Visual Studio 17 2022" -A x64 -DBUILD_TESTING=ON
cmake --build <temp> --config Release --target gameinput_host_test
ctest --test-dir <temp> -C Release -R "^gameinput_host$" --output-on-failure

1/1 passed, 0 skipped; test output 4 PASS. It ran against the real host GameInput.dll 0.2309.26100.9278 (GameInputCreate hr 0x0), not the shim. The fixture imports GameInput.dll by ordinal 1, the test EXE has no GameInput.dll dependency or gameinput symbols, and binding was asserted rt::Binding::Host with the probe going through m.exports. Skip logic is sound by inspection (exit 77 before initialise(), SKIP_RETURN_CODE 77); I could not exercise it because the DLL is present. Docs match the observed behaviour; no game data, absolute paths or writes.

Two nits and one real defect:

  1. Debug link failure (blocker for -Debug). Debug fails to link the fixture: /NODEFAULTLIB plus MSVC's default Debug /RTC1 gives LNK2019 _RTC_CheckStackVars/_RTC_InitBase/_RTC_Shutdown and LNK1120. scripts/build_runtime.ps1 -Debug therefore breaks. Fix with /RTC1- (or a Debug-only option), or waive it explicitly.
  2. The test also disappears at configure time when the SDK has no gameinput.lib; the docs only mention skipping when the DLL is absent.
  3. The Tests list is not updated, though the intro paragraph covers it.

Mergeable once the Debug link failure is fixed or explicitly waived. Release/CI is clean.

@JRamos1993

Copy link
Copy Markdown
Contributor

Ran this on main 4947579 (Windows 11, GameInput.dll 0.2309.26100.9818, MSVC 19.44, RelWithDebInfo, no pad attached): gameinput_host passes 10 of 10 runs, 4 checks. The import is gameinput.dll!#1.

  1. The skip hides the failure this test exists to catch. The test returns 77 ("SKIP: no GameInput.dll on this machine") whenever the import's binding is Unimplemented (gameinput_host_test.cpp:52–55), whatever the cause. When I broke host ordinal binding in Loader::resolve (pe_loader.cpp:890, if (p) → if (p && !by_ordinal)), the test skipped and ctest reported 100% passed, although GameInput.dll is present.

    Deciding the skip with LoadLibraryExW(L"GameInput.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32) before mapping, and counting Unimplemented as a failure, makes that same change fail (4 failures). The unchanged test still passes.

  2. The fixture doesn't link in Debug, the Visual Studio generator's default config. /NODEFAULTLIB (CMakeLists.txt:498) plus the default /RTC1 leaves _RTC_InitBase, _RTC_Shutdown and _RTC_CheckStackVars unresolved (LNK1120). CI builds RelWithDebInfo, so only local Debug builds hit it.

Minor: the fixture sets *reading_hr = 0 before returning when GameInputCreate fails. In that case the test reports "a gamepad is attached" and passes the GetCurrentReading check.

AI-assisted (Claude Code).

@Koro4e

Koro4e commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested d43bb93 on RTX 3060, driver 617.14, Windows 11, MSVC 14.44 RelWithDebInfo: pass

  • Built gameinput_host_test (pulls the gameinput_host fixture DLL) and the neighbouring gameinput_test (SDL3 shim); ctest -R gameinput: gameinput_host passed (0.05-0.12 s), gameinput passed (1.35 s), 0 failed.
  • gameinput_host bound the import to the host's copy, GameInputCreate returned S_OK, GetCurrentTimestamp returned a time, GetCurrentReading correctly reported GAMEINPUT_E_READING_NOT_FOUND (0x838A0003, no gamepad attached); the skip branch did not trigger because the host GameInput.dll is present.

AI-assisted.

docs/gameinput.md says that without the SDL3 shim the loader binds
GameInputCreate to the host's GameInput.dll, but nothing tested it.
gameinput_host_test maps a CRT-free fixture DLL built against the SDK's
gameinput.lib and checks that the import binds to the host copy (the test links
no shim table), that GameInputCreate and GetCurrentTimestamp work from mapped
code, that GetCurrentReading answers, and, with a pad attached, that
GetGamepadState succeeds. It skips (77) where there is no GameInput.dll, and is
only built when gameinput.lib is found.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@lunisahdidouch

Copy link
Copy Markdown

Tested d43bb93 on Windows 11 (26300), built with VS 2022 Build Tools and the pinned SDL3 (-FetchSdl3): pass

ctest -R gameinput gives 2/2 passed: the new gameinput_host and gameinput. gameinput passes on main 1628210 with the same build setup too.

AI-assisted

@Sc4ros

Sc4ros commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Pushed 37e6d48: rebased onto main f847748. The conflict was in runtime/CMakeLists.txt, where this PR's gameinput_host block sits next to the dll_thread_calls block that #2383 added; I kept both, no other change. ctest -R "gameinput_host|dll_thread_calls" passes 2/2 (Windows 11 build 26300, MSVC 19.44, RX 9060 XT, driver 32.0.32029.2010). JRamos1993's three review points are not in this commit; they follow in a separate push.

AI-assisted (Claude Code). No game files.

… present (review)

- gameinput_host_test decides the skip before mapping: LoadLibraryExW of GameInput.dll from System32. Only "not found"
  skips (77); an import that then binds to nothing is a failure. Breaking host ordinal binding in Loader::resolve now
  fails the test (4 failures) instead of skipping.
- The gameinput_host fixture links in Debug: /RTC1 with /NODEFAULTLIB left _RTC_InitBase, _RTC_Shutdown and
  _RTC_CheckStackVars unresolved, so the fixture defines them as no-ops when runtime checks are on.
- The fixture reports E_FAIL, not S_OK, when GameInputCreate fails, and the test counts a gamepad as attached only when
  the library was created.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@Sc4ros

Sc4ros commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @JRamos1993, all three are in; pushed a41173a (on top of the rebase 37e6d48, one extra commit).

  1. Skip hides the failure. gameinput_host_test now calls LoadLibraryExW(L"GameInput.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32) before mapping anything and skips (77) only when that fails with module/file/path not found. Any other load error fails; with the DLL present, an import that binds to Unimplemented is now just a failed check. Your mutation (if (p) → if (p && !by_ordinal) in Loader::resolve) now gives gameinput_host_test: FAILED (4 failures) (the binding, GameInputCreate, timestamp and reading checks), and the unchanged loader gives OK (0 failures). The doc sentence about the skip and the CMake comments were updated to match.
  2. Debug link. Reproduced the LNK1120 (_RTC_InitBase, _RTC_Shutdown, _RTC_CheckStackVars). /RTC- is not a valid cl option (D9002, still LNK2019), so the fixture defines those three as no-ops when __MSVC_RUNTIME_CHECKS is set. gameinput_host and gameinput_host_test now build in Debug and ctest -C Debug -R gameinput_host passes.
  3. "Gamepad attached" on failure. The fixture reports E_FAIL instead of S_OK for reading_hr when GameInputCreate fails, and the test counts a gamepad as attached only when created == 1 && reading_hr == 0.

Tested on Windows 11 build 26300, MSVC 19.44, AMD Radeon RX 9060 XT (driver 32.0.32029.2010), no gamepad attached: Release and Debug builds, ctest -R gameinput_host passes in both; tests/test_docs_links.py, test_docs_list_items.py, test_docs_repo_paths.py OK.

AI-assisted (Claude Code). No game files.

@ItsNotRexed
ItsNotRexed merged commit 5fd0db9 into ItsNotRexed:main Nov 23, 2026
2 of 4 checks passed
@Sc4ros
Sc4ros deleted the gameinput-host-test branch November 23, 2026 06:00
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.

6 participants