runtime: add opt-in input trace for the virtual gamepad #3179

Manually merged
github merged 2 commits from github-bot/gh-3177 into gh-pr/3177/base 2026-11-27 22:30:59 +00:00 AGit
Owner

@⁠lambirou on GitHub · 2026-11-27 20:26 UTC · original
lambirou:codex/input-movement-trace → main · +534 −0 · 5 files · 2 commits · merged 2026-11-27 22:29 UTC

Changes

Adds an opt-in X2W_INPUT_TRACE=1 mode to the GameInput stand-in. It logs the resolved virtual gamepad state after keyboard, XInput pad 0, the shared pad block, X2W_INPUT_PRESS and X2W_INPUT_SCRIPT have been merged:

x2w-input-trace state buttons=0x00000004 lt=0.000 rt=0.000 lx=1.000 ly=0.500 rx=0.000 ry=0.000 script=2.500 present=11

It also logs one line per script wait, mark or skipped group. The default path is unchanged and writes no trace line.

Validation

ctest --preset dev --no-tests=error -R '^startup_gameinput_(trace|script)' -V
# 4/4 passed: startup_gameinput_script_long, _entries, _syntax, startup_gameinput_trace

The fixture plays one script with the switch on and off. The control observes the same states and writes no trace line; the trace must show the A press at script time 2.000 and present 11, the stick at 2.500, and the wait/mark events.

Limits

The trace shows the input the stand-in exposes to the title; it does not prove that a game state or a rendered character changed. That still needs a scene-color comparison on a fixed profile and scripted sequence. The fixture is source-built and uses the existing picture-signature block.

Refs #870.

Review update (2026-11-27, 779c8863)

pigalot's fixture gap is fixed. The script now ends with a 0.1 s B press at 3.6-3.7 s, off the 250 ms heartbeat grid. The child expects B at 3.6 s and the trace must contain the exact buttons=0x00000008 ... script=3.600 present=11 line; dropping the state-change test now loses that line and fails.

The documentation example now uses the real 2.500 s state (buttons=0x00000000, lx=1.000, ly=0.500). startup_gameinput_trace passes in Debug and Release on the local host, with the trace and control children both passing. CI is running on 779c8863.

**@⁠lambirou** on GitHub · 2026-11-27 20:26 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3177) `lambirou:codex/input-movement-trace` → `main` · +534 −0 · 5 files · 2 commits · merged 2026-11-27 22:29 UTC ## Changes Adds an opt-in `X2W_INPUT_TRACE=1` mode to the GameInput stand-in. It logs the resolved virtual gamepad state after keyboard, XInput pad 0, the shared pad block, `X2W_INPUT_PRESS` and `X2W_INPUT_SCRIPT` have been merged: ```text x2w-input-trace state buttons=0x00000004 lt=0.000 rt=0.000 lx=1.000 ly=0.500 rx=0.000 ry=0.000 script=2.500 present=11 ``` It also logs one line per script wait, mark or skipped group. The default path is unchanged and writes no trace line. ## Validation ```powershell ctest --preset dev --no-tests=error -R '^startup_gameinput_(trace|script)' -V # 4/4 passed: startup_gameinput_script_long, _entries, _syntax, startup_gameinput_trace ``` The fixture plays one script with the switch on and off. The control observes the same states and writes no trace line; the trace must show the A press at script time 2.000 and present 11, the stick at 2.500, and the wait/mark events. ## Limits The trace shows the input the stand-in exposes to the title; it does not prove that a game state or a rendered character changed. That still needs a scene-color comparison on a fixed profile and scripted sequence. The fixture is source-built and uses the existing picture-signature block. Refs #870. ## Review update (2026-11-27, `779c8863`) pigalot's fixture gap is fixed. The script now ends with a 0.1 s B press at 3.6-3.7 s, off the 250 ms heartbeat grid. The child expects B at 3.6 s and the trace must contain the exact `buttons=0x00000008 ... script=3.600 present=11` line; dropping the state-change test now loses that line and fails. The documentation example now uses the real 2.500 s state (`buttons=0x00000000`, `lx=1.000`, `ly=0.500`). `startup_gameinput_trace` passes in Debug and Release on the local host, with the trace and control children both passing. CI is running on `779c8863`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 20:28:50 +00:00
Author
Owner

@⁠pigalot on GitHub · 2026-11-27 21:48 UTC · original · requested changes

Independently reviewed 1600accb integrated over main 2dde49a8 (tree 9b456ee0). The merge is clean and git diff --cached --check origin/main is clean.

What I traced.

  • trace_state runs at the end of sample(), after keyboard, XInput pad 0, the shared block, X2W_INPUT_PRESS and the script have been merged, so it logs the state that capture_current() records.
  • It writes a line when the 28-byte GamepadState differs by memcmp (the struct has no padding), and otherwise at most once every 250 ms on process_milliseconds(), which follows X2W_INPUT_CLOCK_MS in the fixture.
  • present comes from read_signal, so it is none until the presenter has published a sample. For a script with no wait that means always: sampling is only requested for waits.
  • trace_event is called from log_event, so each existing wait, mark and group log gets one trace line next to it.
  • With the switch off, the only cost is the cached trace_enabled() check.

What I ran. I built startup_stub_gameinput and startup_gameinput_trace in dev and release, then ran:

ctest --test-dir out/build/dev --no-tests=error -j 1 -R '^startup_gameinput_'
ctest --test-dir out/build/release --no-tests=error -j 1 -V -R '^startup_gameinput_trace$'
  • CTest. In dev, 5 of 7 pass. startup_gameinput_trace and startup_gameinput_script_syntax are capability skips (77): this machine has an XInput pad on slot 0 (SKIP: XInput pad 0 is connected). Release is the same skip.
  • Child process run directly. To exercise the fixture anyway, I ran its child process directly with the parent's environment (X2W_TRAP_LOG, X2W_INPUT_TRACE=1|0, the same X2W_INPUT_SCRIPT, X2W_INPUT_PRESS/X2W_INPUT_KEYS unset): startup_gameinput_trace.exe GameInput.dll child trace|control. The pad was idle, so it adds nothing to the readings. Results:
    • trace and control both exit 0 in Debug and Release /O2;
    • trace mode writes 22 x2w-input-trace lines, 17 of them state lines;
    • control mode writes none.
  • Before. On main 2dde49a8, the test is not registered.

Mutants (each applied alone to src/startup_stubs/gameinput.cpp, startup_stub_gameinput rebuilt in dev, both children run, file restored from its raw bytes, git diff --quiet clean afterwards):

Mutant Result
interval 250 → 500 ms killed: bounded state lines (12..20 in four seconds)
present taken from signal.sequence killed: A-press and stick lines
trace_event not called killed: wait begun/changed lines
script time reported as 0 killed: A-press and stick lines
trace always on killed by the control: no x2w-input-trace line without the switch
state-change test dropped (memcmp term removed, interval only) survives

Finding: the fixture does not pin "one line per state change". Every state change in the script lands on a multiple of 250 ms: 2.000, 2.500, 3.000 and 3.500 s. The fixture also starts the trace at 0 and steps the clock by 50 ms. So the 250 ms heartbeat alone produces exactly the lines the check expects. All 17 state lines in the passing run are at script=0.000, 0.250, …, 4.000.

The gap is visible with a change off that grid. I appended a 0.1 s B press, 8@+1.1+0.1, to the same script, so B is held from 3.6 to 3.7 s. Then I ran the trace child. Its own state expectations then stop it at 3.6 s, but the trace line is written first.

  • PR as is: one x2w-input-trace state buttons=0x00000008 … script=3.600 present=11 line.
  • Change test dropped: no B line at all.

A press shorter than 250 ms (an X2W_INPUT_PRESS press is 0.2 s) can therefore vanish from the trace without the test noticing. That is the case the trace exists for. Suggested direction: move one script entry off the 250 ms grid (for example a 0.1 s press at 3.6 s, as above), add it to expected_at, and assert its line. That pins the change test.

Non-blocking. The example state line in the PR body and in docs/experiments/startup-input-trace.md (buttons=0x00000004 … lx=1.000 ly=0.500 … script=2.500) is not a state the fixture produces: A is released at 2.5 s, and the fixture's own line at 2.500 has buttons=0x00000000. Using the real line would avoid confusion.

Verdict: request changes on 1600accb for the fixture gap above. The runtime change behaves as described in my runs.

Environment: Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Python 3.12.10; no GPU involved. XInput pad present on slot 0, so CTest reports the trace test as a capability skip (77) here.
CI: Build and test on Windows, Assemble and translate gfx1013 fixtures and Run platform-independent Python checks on Linux pass on 1600accb.

This reply was AI-assisted.

**@⁠pigalot** on GitHub · 2026-11-27 21:48 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3177#pullrequestreview-6093636497) · **requested changes** Independently reviewed `1600accb` integrated over `main` `2dde49a8` (tree `9b456ee0`). The merge is clean and `git diff --cached --check origin/main` is clean. **What I traced.** - `trace_state` runs at the end of `sample()`, after keyboard, XInput pad 0, the shared block, `X2W_INPUT_PRESS` and the script have been merged, so it logs the state that `capture_current()` records. - It writes a line when the 28-byte `GamepadState` differs by `memcmp` (the struct has no padding), and otherwise at most once every 250 ms on `process_milliseconds()`, which follows `X2W_INPUT_CLOCK_MS` in the fixture. - `present` comes from `read_signal`, so it is `none` until the presenter has published a sample. For a script with no wait that means always: sampling is only requested for waits. - `trace_event` is called from `log_event`, so each existing wait, mark and group log gets one trace line next to it. - With the switch off, the only cost is the cached `trace_enabled()` check. **What I ran.** I built `startup_stub_gameinput` and `startup_gameinput_trace` in `dev` and `release`, then ran: ```powershell ctest --test-dir out/build/dev --no-tests=error -j 1 -R '^startup_gameinput_' ctest --test-dir out/build/release --no-tests=error -j 1 -V -R '^startup_gameinput_trace$' ``` - **CTest.** In `dev`, 5 of 7 pass. `startup_gameinput_trace` and `startup_gameinput_script_syntax` are capability skips (77): this machine has an XInput pad on slot 0 (`SKIP: XInput pad 0 is connected`). Release is the same skip. - **Child process run directly.** To exercise the fixture anyway, I ran its child process directly with the parent's environment (`X2W_TRAP_LOG`, `X2W_INPUT_TRACE=1|0`, the same `X2W_INPUT_SCRIPT`, `X2W_INPUT_PRESS`/`X2W_INPUT_KEYS` unset): `startup_gameinput_trace.exe GameInput.dll child trace|control`. The pad was idle, so it adds nothing to the readings. Results: - trace and control both exit 0 in Debug and Release `/O2`; - trace mode writes 22 `x2w-input-trace` lines, 17 of them state lines; - control mode writes none. - **Before.** On `main` `2dde49a8`, the test is not registered. **Mutants** (each applied alone to `src/startup_stubs/gameinput.cpp`, `startup_stub_gameinput` rebuilt in `dev`, both children run, file restored from its raw bytes, `git diff --quiet` clean afterwards): | Mutant | Result | |---|---| | interval 250 → 500 ms | killed: `bounded state lines (12..20 in four seconds)` | | `present` taken from `signal.sequence` | killed: A-press and stick lines | | `trace_event` not called | killed: wait begun/changed lines | | script time reported as 0 | killed: A-press and stick lines | | trace always on | killed by the control: `no x2w-input-trace line without the switch` | | **state-change test dropped** (`memcmp` term removed, interval only) | **survives** | **Finding: the fixture does not pin "one line per state change".** Every state change in the script lands on a multiple of 250 ms: 2.000, 2.500, 3.000 and 3.500 s. The fixture also starts the trace at 0 and steps the clock by 50 ms. So the 250 ms heartbeat alone produces exactly the lines the check expects. All 17 state lines in the passing run are at `script=0.000, 0.250, …, 4.000`. The gap is visible with a change off that grid. I appended a 0.1 s B press, `8@+1.1+0.1`, to the same script, so B is held from 3.6 to 3.7 s. Then I ran the trace child. Its own state expectations then stop it at 3.6 s, but the trace line is written first. - PR as is: one `x2w-input-trace state buttons=0x00000008 … script=3.600 present=11` line. - Change test dropped: no B line at all. A press shorter than 250 ms (an `X2W_INPUT_PRESS` press is 0.2 s) can therefore vanish from the trace without the test noticing. That is the case the trace exists for. Suggested direction: move one script entry off the 250 ms grid (for example a 0.1 s press at 3.6 s, as above), add it to `expected_at`, and assert its line. That pins the change test. **Non-blocking.** The example state line in the PR body and in `docs/experiments/startup-input-trace.md` (`buttons=0x00000004 … lx=1.000 ly=0.500 … script=2.500`) is not a state the fixture produces: A is released at 2.5 s, and the fixture's own line at 2.500 has `buttons=0x00000000`. Using the real line would avoid confusion. **Verdict:** request changes on `1600accb` for the fixture gap above. The runtime change behaves as described in my runs. Environment: Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Python 3.12.10; no GPU involved. XInput pad present on slot 0, so CTest reports the trace test as a capability skip (77) here. CI: `Build and test on Windows`, `Assemble and translate gfx1013 fixtures` and `Run platform-independent Python checks on Linux` pass on `1600accb`. This reply was AI-assisted.
The trace fixture's state changes all landed on the 250 ms heartbeat, so a
mutant that dropped the state-change test survived. Add a 0.1 s B press at
3.6 s and require its exact trace line; also use a real state line in the
documentation.
Author
Owner

@⁠lambirou on GitHub · 2026-11-27 22:13 UTC · original

Review update (2026-11-27, 779c8863)

pigalot's fixture gap is fixed. The script now ends with a 0.1 s B press at 3.6-3.7 s, off the 250 ms heartbeat grid. The child expects B at 3.6 s and the trace must contain the exact buttons=0x00000008 ... script=3.600 present=11 line; dropping the state-change test now loses that line and fails.

The documentation example now uses the real 2.500 s state (buttons=0x00000000, lx=1.000, ly=0.500). startup_gameinput_trace passes in Debug and Release on the local host, with the trace and control children both passing. CI is running on 779c8863.

**@⁠lambirou** on GitHub · 2026-11-27 22:13 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3177#issuecomment-7229133479) ## Review update (2026-11-27, `779c8863`) pigalot's fixture gap is fixed. The script now ends with a 0.1 s B press at 3.6-3.7 s, off the 250 ms heartbeat grid. The child expects B at 3.6 s and the trace must contain the exact `buttons=0x00000008 ... script=3.600 present=11` line; dropping the state-change test now loses that line and fails. The documentation example now uses the real 2.500 s state (`buttons=0x00000000`, `lx=1.000`, `ly=0.500`). `startup_gameinput_trace` passes in Debug and Release on the local host, with the trace and control children both passing. CI is running on `779c8863`.
Author
Owner

@⁠lambirou on GitHub · 2026-11-27 22:19 UTC · original

@⁠pigalot the off-grid 0.1 s B press is added on 779c8863; the trace requires the 3.600 s line. Could you re-review?

**@⁠lambirou** on GitHub · 2026-11-27 22:19 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3177#issuecomment-7229229320) @⁠pigalot the off-grid 0.1 s B press is added on `779c8863`; the trace requires the 3.600 s line. Could you re-review?
github-bot changed target branch from main to gh-pr/3177/base 2026-11-27 22:30:57 +00:00
github manually merged commit 779c8863f3 into gh-pr/3177/base 2026-11-27 22:30:59 +00:00
Author
Owner

@⁠pigalot on GitHub · 2026-11-27 22:29 UTC · original · approved these changes

Retested 779c8863 integrated over main 06de199e (tree ce2c88ef). The merge is clean (docs/startup-runtime.md auto-merged) and git diff --cached --check origin/main is clean.

My earlier finding (the fixture does not pin one line per state change): addressed. The script now ends with 8@+1.1+0.1, so B is held from 3.6 to 3.7 s, off the 250 ms heartbeat grid. expected_at expects it, and the trace child requires exactly one buttons=0x00000008 … script=3.600 present=11 line. The state-line bound moves from 12..20 to 12..21 for the extra change line. In my run there are 18 state lines.

What I ran. I built startup_stub_gameinput, startup_gameinput_trace and the other startup_gameinput_* executables in dev and release, then ran:

ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^startup_gameinput_'
  • CTest. In both presets, 5 of 7 pass. startup_gameinput_trace and startup_gameinput_script_syntax are capability skips (77): this machine has an XInput pad on slot 0.
  • Child process run directly, as in my last review, with the PR's script: startup_gameinput_trace.exe GameInput.dll child trace|control.
    • Trace and control both exit 0 in Debug and Release /O2.
    • Trace mode writes 23 x2w-input-trace lines, 18 of them state lines, including the single script=3.600 B line.
    • Control mode writes none.

Mutants (each applied alone to src/startup_stubs/gameinput.cpp, startup_stub_gameinput rebuilt in dev, both children run, file restored from its raw bytes, git diff --quiet clean afterwards):

Mutant Result
state-change test dropped (memcmp term removed, interval only) killed (it survived on 1600accb): off-grid B press line at script time 3.600
interval 250 → 500 ms killed: bounded state lines (12..21 in four seconds)
present taken from signal.sequence killed: A-press and stick lines
trace_event not called killed: wait begun/changed lines
script time reported as 0 killed: A-press and stick lines
trace always on killed by the control: no x2w-input-trace line without the switch

Earlier non-blocking note (the example state line): half addressed. docs/experiments/startup-input-trace.md now shows the line the fixture really writes at 2.500 s (buttons=0x00000000). The PR body still shows buttons=0x00000004 at script=2.500. Since it is only the description, I'm not blocking on it.

Verdict: approve on 779c8863. This supersedes my changes-requested review on 1600accb.

Environment: Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Python 3.12.10. No GPU is involved. An XInput pad is present on slot 0, so CTest reports the trace test as a capability skip (77) here, and the child was run directly instead.
CI: Build and test on Windows, Assemble and translate gfx1013 fixtures and Run platform-independent Python checks on Linux pass on 779c8863.

This reply was AI-assisted.

**@⁠pigalot** on GitHub · 2026-11-27 22:29 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3177#pullrequestreview-6093959414) · **approved these changes** Retested `779c8863` integrated over `main` `06de199e` (tree `ce2c88ef`). The merge is clean (`docs/startup-runtime.md` auto-merged) and `git diff --cached --check origin/main` is clean. **My earlier finding (the fixture does not pin one line per state change): addressed.** The script now ends with `8@+1.1+0.1`, so B is held from 3.6 to 3.7 s, off the 250 ms heartbeat grid. `expected_at` expects it, and the trace child requires exactly one `buttons=0x00000008 … script=3.600 present=11` line. The state-line bound moves from 12..20 to 12..21 for the extra change line. In my run there are 18 state lines. **What I ran.** I built `startup_stub_gameinput`, `startup_gameinput_trace` and the other `startup_gameinput_*` executables in `dev` and `release`, then ran: ```powershell ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^startup_gameinput_' ``` - **CTest.** In both presets, 5 of 7 pass. `startup_gameinput_trace` and `startup_gameinput_script_syntax` are capability skips (77): this machine has an XInput pad on slot 0. - **Child process run directly**, as in my last review, with the PR's script: `startup_gameinput_trace.exe GameInput.dll child trace|control`. - Trace and control both exit 0 in Debug and Release `/O2`. - Trace mode writes 23 `x2w-input-trace` lines, 18 of them state lines, including the single `script=3.600` B line. - Control mode writes none. **Mutants** (each applied alone to `src/startup_stubs/gameinput.cpp`, `startup_stub_gameinput` rebuilt in `dev`, both children run, file restored from its raw bytes, `git diff --quiet` clean afterwards): | Mutant | Result | |---|---| | **state-change test dropped** (`memcmp` term removed, interval only) | **killed** (it survived on `1600accb`): `off-grid B press line at script time 3.600` | | interval 250 → 500 ms | killed: `bounded state lines (12..21 in four seconds)` | | `present` taken from `signal.sequence` | killed: A-press and stick lines | | `trace_event` not called | killed: wait begun/changed lines | | script time reported as 0 | killed: A-press and stick lines | | trace always on | killed by the control: `no x2w-input-trace line without the switch` | **Earlier non-blocking note (the example state line): half addressed.** `docs/experiments/startup-input-trace.md` now shows the line the fixture really writes at 2.500 s (`buttons=0x00000000`). The PR body still shows `buttons=0x00000004` at `script=2.500`. Since it is only the description, I'm not blocking on it. **Verdict:** approve on `779c8863`. This supersedes my changes-requested review on `1600accb`. Environment: Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Python 3.12.10. No GPU is involved. An XInput pad is present on slot 0, so CTest reports the trace test as a capability skip (77) here, and the child was run directly instead. CI: `Build and test on Windows`, `Assemble and translate gfx1013 fixtures` and `Run platform-independent Python checks on Linux` pass on `779c8863`. This reply was AI-assisted.
This discussion has been locked. Commenting is limited to contributors.
No description provided.