tests: add device-free tests for resident_pages.h #3654

Manually merged
github merged 2 commits from github-bot/gh-3652 into gh-pr/3652/base 2026-12-01 00:12:46 +00:00 AGit
Owner

@⁠Ammmae0x on GitHub · 2026-11-30 21:26 UTC · original
Ammmae0x:tests/startup-resident-pages → main · +788 −0 · 5 files · 2 commits · merged 2026-12-01 00:11 UTC

Refs #1149

Adds a device-free C++ unit and configure-time header-mutation test suite for x2w_local::resident_read_write (src/startup_stubs/resident_pages.h), which was untested directly in tests/. No existing file is modified; only 5 new files, and the header and device code are untouched.

What changed

  • tests/startup_resident_pages_check.cpp: Win32 C++17 check (windows.h, psapi.h only) with 15 cases: valid PAGE_READWRITE / PAGE_EXECUTE_READWRITE pages, an unaligned [page0 + 0xFFE, page1 + 4) span with a corrupt page on either side, a 520-page range crossing the 512-page QueryWorkingSetEx batch loop with a corrupt last page (519), and refusals for reserved, untouched, read-only, no-access, guarded and mixed-boundary pages, plus the empty and inverted range edges. Every mismatch prints FAIL: <case>: ... to stderr and exits non-zero. --case selects one case; no argument runs all.
  • tests/cmake/startup_resident_pages.cmake: registers one CTest test per case plus startup_resident_pages_all, and 5 WILL_FAIL TRUE mutation controls mirroring era_physical_owns_last_page_control. Each control builds the same check against a configure-time copy of resident_pages.h with one targeted edit: dropping the PAGE_EXECUTE_READWRITE arm (valid_exec_rw), stepping 0x2000 instead of 0x1000 (mixed_boundary_refused), accepting PAGE_READONLY (readonly_refused), single-batch while -> if (large_last_corrupt), dropping the & ~0xFFF start alignment (unaligned_span_second_corrupt).
  • tests/startup_resident_pages_meta_check.py + tests/checks/python-linux/startup_resident_pages.txt: Linux contract audit plus a mutation audit on a Python transliteration of resident_read_write.
  • docs/experiments/startup-resident-pages.md: note, zero personal paths.

Linux results

  • Meta check: PASS: startup resident pages: 15 cases, 5/5 mutations killed
  • tools/run_checks_parallel.py --from-dir tests/checks/python-linux: all 73 checks passed
  • tests/form_coverage_check.py, tests/docs_links_check.py (193 files, 749 links), tests/bidi_controls_check.py (2765 files): pass
  • No mingw cross-compiler on this host, so MSVC/Win32 execution awaits Windows verification.

Windows verification fix round (bc3af024 -> de6001a4)

Windows 11 dev + release CTest ran 21 tests: 16/16 functional cases passed and readonly_mut + batch_mut passed, but 3 WILL_FAIL TRUE controls failed because of real Win32 QueryWorkingSetEx behaviour, plus 1 privacy string lint finding. Fixed in this commit:

  • align_mut now runs unaligned_span_second_corrupt: QueryWorkingSetEx page-aligns the queried address internally, so the valid unaligned_span range still passes with the alignment dropped; the walk then steps 0x1000 from 0x...FFE and skips page 1, so the read-only second page is never looked at and the range is accepted.
  • guard_mut and valid_mut are replaced by exec_rw_mut (drop the PAGE_EXECUTE_READWRITE arm, caught by valid_exec_rw) and step_mut (step 0x2000 instead of 0x1000, caught by mixed_boundary_refused): probing confirmed both an untouched committed page and a PAGE_READWRITE | PAGE_GUARD page report Valid=0, Bad=0, Win32Protection=0x0, so the protection check already refuses both whenever Valid=0. guard_refused and untouched_refused stay as functional tests.
  • The hardcoded personal-name tuple is gone from the meta check; the doc is now checked with a generic path regex.
  • The meta check models the kernel page-alignment; 8/8 targeted self-mutations on scratch copies are killed with exact errors, and a real-cmake audit confirms all 5 fragment edits apply (including the empty-replacement exec_rw edit).

Notes

QueryWorkingSetEx on Windows 11 page-aligns a queried address internally, and reports both an untouched committed page and a PAGE_READWRITE | PAGE_GUARD page as Valid=0, Bad=0, Win32Protection=0x0. The note and the meta check document both behaviours.

Windows Verification (de6001a4)

Commit: de6001a47353e5211e2738a95abbefdd539a522e (merge-tree upstream/main HEAD -> ccab2b39, exit 0; git diff --check clean)
dev: cmake --build --preset dev --target startup_resident_pages_check startup_resident_pages_align_mut startup_resident_pages_readonly_mut startup_resident_pages_exec_rw_mut startup_resident_pages_batch_mut startup_resident_pages_step_mut && ctest --preset dev --no-tests=error -R "^startup_resident_pages" --output-on-failure -> 21/21 passed (0.63s; 16 functional + 5/5 WILL_FAIL header mutants)
release: cmake --build --preset release --target startup_resident_pages_check startup_resident_pages_align_mut startup_resident_pages_readonly_mut startup_resident_pages_exec_rw_mut startup_resident_pages_batch_mut startup_resident_pages_step_mut && ctest --preset release --no-tests=error -R "^startup_resident_pages" -E "cpu_native_archive_" --output-on-failure -> 21/21 passed (0.52s; 16 functional + 5/5 WILL_FAIL header mutants)
Checks: startup_resident_pages_meta_check.py (15 cases, 5/5 mutations killed), form_coverage_check.py, docs_links_check.py (193 files, 749 links), bidi_controls_check.py (2765 files) -> passed

AI-assisted.

**@⁠Ammmae0x** on GitHub · 2026-11-30 21:26 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3652) `Ammmae0x:tests/startup-resident-pages` → `main` · +788 −0 · 5 files · 2 commits · merged 2026-12-01 00:11 UTC Refs #1149 Adds a device-free C++ unit and configure-time header-mutation test suite for `x2w_local::resident_read_write` (`src/startup_stubs/resident_pages.h`), which was untested directly in `tests/`. No existing file is modified; only 5 new files, and the header and device code are untouched. What changed - `tests/startup_resident_pages_check.cpp`: Win32 C++17 check (`windows.h`, `psapi.h` only) with 15 cases: valid `PAGE_READWRITE` / `PAGE_EXECUTE_READWRITE` pages, an unaligned `[page0 + 0xFFE, page1 + 4)` span with a corrupt page on either side, a 520-page range crossing the 512-page `QueryWorkingSetEx` batch loop with a corrupt last page (519), and refusals for reserved, untouched, read-only, no-access, guarded and mixed-boundary pages, plus the empty and inverted range edges. Every mismatch prints `FAIL: <case>: ...` to stderr and exits non-zero. `--case` selects one case; no argument runs all. - `tests/cmake/startup_resident_pages.cmake`: registers one CTest test per case plus `startup_resident_pages_all`, and 5 `WILL_FAIL TRUE` mutation controls mirroring `era_physical_owns_last_page_control`. Each control builds the same check against a configure-time copy of `resident_pages.h` with one targeted edit: dropping the `PAGE_EXECUTE_READWRITE` arm (`valid_exec_rw`), stepping `0x2000` instead of `0x1000` (`mixed_boundary_refused`), accepting `PAGE_READONLY` (`readonly_refused`), single-batch `while` -> `if` (`large_last_corrupt`), dropping the `& ~0xFFF` start alignment (`unaligned_span_second_corrupt`). - `tests/startup_resident_pages_meta_check.py` + `tests/checks/python-linux/startup_resident_pages.txt`: Linux contract audit plus a mutation audit on a Python transliteration of `resident_read_write`. - `docs/experiments/startup-resident-pages.md`: note, zero personal paths. Linux results - Meta check: `PASS: startup resident pages: 15 cases, 5/5 mutations killed` - `tools/run_checks_parallel.py --from-dir tests/checks/python-linux`: all 73 checks passed - `tests/form_coverage_check.py`, `tests/docs_links_check.py` (193 files, 749 links), `tests/bidi_controls_check.py` (2765 files): pass - No mingw cross-compiler on this host, so MSVC/Win32 execution awaits Windows verification. Windows verification fix round (`bc3af024` -> `de6001a4`) Windows 11 `dev` + `release` CTest ran 21 tests: 16/16 functional cases passed and `readonly_mut` + `batch_mut` passed, but 3 `WILL_FAIL TRUE` controls failed because of real Win32 `QueryWorkingSetEx` behaviour, plus 1 privacy string lint finding. Fixed in this commit: - `align_mut` now runs `unaligned_span_second_corrupt`: `QueryWorkingSetEx` page-aligns the queried address internally, so the valid `unaligned_span` range still passes with the alignment dropped; the walk then steps `0x1000` from `0x...FFE` and skips page 1, so the read-only second page is never looked at and the range is accepted. - `guard_mut` and `valid_mut` are replaced by `exec_rw_mut` (drop the `PAGE_EXECUTE_READWRITE` arm, caught by `valid_exec_rw`) and `step_mut` (step `0x2000` instead of `0x1000`, caught by `mixed_boundary_refused`): probing confirmed both an untouched committed page and a `PAGE_READWRITE | PAGE_GUARD` page report `Valid=0, Bad=0, Win32Protection=0x0`, so the protection check already refuses both whenever `Valid=0`. `guard_refused` and `untouched_refused` stay as functional tests. - The hardcoded personal-name tuple is gone from the meta check; the doc is now checked with a generic path regex. - The meta check models the kernel page-alignment; 8/8 targeted self-mutations on scratch copies are killed with exact errors, and a real-`cmake` audit confirms all 5 fragment edits apply (including the empty-replacement `exec_rw` edit). Notes `QueryWorkingSetEx` on Windows 11 page-aligns a queried address internally, and reports both an untouched committed page and a `PAGE_READWRITE | PAGE_GUARD` page as `Valid=0, Bad=0, Win32Protection=0x0`. The note and the meta check document both behaviours. ### Windows Verification (`de6001a4`) ```text Commit: de6001a47353e5211e2738a95abbefdd539a522e (merge-tree upstream/main HEAD -> ccab2b39, exit 0; git diff --check clean) dev: cmake --build --preset dev --target startup_resident_pages_check startup_resident_pages_align_mut startup_resident_pages_readonly_mut startup_resident_pages_exec_rw_mut startup_resident_pages_batch_mut startup_resident_pages_step_mut && ctest --preset dev --no-tests=error -R "^startup_resident_pages" --output-on-failure -> 21/21 passed (0.63s; 16 functional + 5/5 WILL_FAIL header mutants) release: cmake --build --preset release --target startup_resident_pages_check startup_resident_pages_align_mut startup_resident_pages_readonly_mut startup_resident_pages_exec_rw_mut startup_resident_pages_batch_mut startup_resident_pages_step_mut && ctest --preset release --no-tests=error -R "^startup_resident_pages" -E "cpu_native_archive_" --output-on-failure -> 21/21 passed (0.52s; 16 functional + 5/5 WILL_FAIL header mutants) Checks: startup_resident_pages_meta_check.py (15 cases, 5/5 mutations killed), form_coverage_check.py, docs_links_check.py (193 files, 749 links), bidi_controls_check.py (2765 files) -> passed ``` AI-assisted. <!-- WIN-VERIFY: passed | sha=de6001a47353e5211e2738a95abbefdd539a522e | targets=startup_resident_pages_check startup_resident_pages_align_mut startup_resident_pages_readonly_mut startup_resident_pages_exec_rw_mut startup_resident_pages_batch_mut startup_resident_pages_step_mut | ctest=^startup_resident_pages | release=true -->
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 21:29:55 +00:00
Windows 11 dev + release ran 21 tests: 16/16 functional cases passed
and readonly_mut + batch_mut passed, but guard_mut, valid_mut and
align_mut failed. QueryWorkingSetEx page-aligns the queried address
internally instead of failing for an unaligned address, and reports
both an untouched committed page and a PAGE_READWRITE | PAGE_GUARD
page as Valid=0, Bad=0, Win32Protection=0x0, so the protection check
already refuses both whenever Valid=0.

- align_mut now runs unaligned_span_second_corrupt: the walk steps
  0x1000 from 0x...FFE and skips page 1, so the read-only second page
  is never looked at and the range is accepted.
- guard_mut and valid_mut are replaced by exec_rw_mut (drop the
  PAGE_EXECUTE_READWRITE arm, caught by valid_exec_rw) and step_mut
  (step 0x2000 instead of 0x1000, caught by mixed_boundary_refused).
  guard_refused and untouched_refused stay as functional tests.
- The meta check models the kernel page-alignment, drops the
  hardcoded personal-name tuple for a generic path regex, and pins
  the five corrected controls; the note documents the Win32Protection
  0x0 behaviour.

Refs #1149
github-bot changed target branch from main to gh-pr/3652/base 2026-12-01 00:12:42 +00:00
github manually merged commit de6001a473 into gh-pr/3652/base 2026-12-01 00:12:46 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-01 00:10 UTC · original · approved these changes

Reviewed the resident-pages fixtures and CTest controls. ctest --test-dir <build> --no-tests=error -j1 -R '^startup_resident_pages_' --output-on-failure passed in the Windows Release integration. All five mutations were caught, including the unaligned second-page and last-page checks. python -B tests/startup_resident_pages_meta_check.py also passed.

**@⁠R0Y00** on GitHub · 2026-12-01 00:10 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3652#pullrequestreview-6122839343) · **approved these changes** Reviewed the resident-pages fixtures and CTest controls. `ctest --test-dir <build> --no-tests=error -j1 -R '^startup_resident_pages_' --output-on-failure` passed in the Windows Release integration. All five mutations were caught, including the unaligned second-page and last-page checks. `python -B tests/startup_resident_pages_meta_check.py` also passed.
This discussion has been locked. Commenting is limited to contributors.
No description provided.