tests: cover x2w_root_constants bounds, storage, and truncation #3861

Manually merged
github merged 2 commits from github-bot/gh-3859 into gh-pr/3859/base 2026-12-02 15:37:04 +00:00 AGit
Owner

@⁠Ammmae0x on GitHub · 2026-12-02 14:31 UTC · original
Ammmae0x:tests/root-constant-store-unit → main · +1103 −0 · 5 files · 2 commits · merged 2026-12-02 15:32 UTC

Refs #1149

Portable C++17 unit and header-mutation tests for x2w_root_constants::Store (src/startup_stubs/root_constant_store.h), matching tests/cmake/logical_view_table_unit.cmake. The source is unchanged; only 5 new files are added (+1103/-0), and the existing tests/startup_root_constant_store.cpp coverage is untouched. The new check uses the disjoint root_constant_store_unit prefix so test names do not collide.

What landed

  • tests/root_constant_store_unit_check.cpp — 10 cases, header-only against src, no device, no loader, no title data. Every shared constant is static constexpr.
  • tests/cmake/root_constant_store_unit.cmake — one CTest test per case plus root_constant_store_unit_all, and 6 WILL_FAIL TRUE controls (BEFORE PRIVATE mutated header copies, 1:1 with the meta check).
  • tests/root_constant_store_unit_meta_check.py — audits the contract, compiles and runs the real C++ check and every mutation natively with g++ -std=c++17 -Wall -Wextra -Wpedantic -Werror (or cl with /W4).
  • tests/checks/python-linux/root_constant_store_unit.txt — lists exactly the meta check.
  • docs/experiments/root-constant-store-unit.md — cases, controls, and verification.

Cases

  • constants: parameter_count == 16 and words_per_parameter == 8; stored, truncated and dropped are distinct; a default store holds no words and no bound bits.
  • clear: clearing a fresh store is a no-op; after filling parameters 0, 7 and 15, clear() zeroes every word and forgets every bound bit; a second clear() is still a no-op, and the store accepts a write afterwards.
  • set_stored: a write that fits is stored whole, reads back at its offsets, and marks exactly the words it wrote; a full row at offset 0 and a write ending exactly at the last word are stored, not truncated; parameter 15 is the last one kept; an overwriting set_one changes one word without disturbing its neighbours.
  • set_one: a single word at the last offset is stored and bound; writing 0 is still a write (word() reads 0 either way, but is_bound() is true); a single word in parameter 15 and an overwrite read back.
  • bad_param: parameters 16, 17 and the largest unsigned value (the unsigned -1) are dropped for both set and set_one, leaving sentinel words in parameters 0 and 15 unchanged; word(-1, 0), word(16, 0) and word(INT_MAX, 0) read 0.
  • bad_offset: offsets 8, 9 and the largest unsigned value (the unsigned -1) are dropped for both set and set_one, leaving a sentinel full row unchanged; word(0, 8), word(0, 9) and word(0, -1) read 0; offset 7 is the last valid offset.
  • zero_count: a zero-count write is dropped with valid data, a null source, or at offset 3, and writes nothing; a zero-count range is never bound even after the whole row is written; a range running past the end of the row is never bound.
  • truncation: a write running past the end of the parameter is cut off (offset 6 count 4, offset 0 count 9, offset 7 count 2): the words that fit are kept and bound, nothing spills into the next parameter; a write ending exactly at the last word is stored, not truncated.
  • null_data: a null source is dropped at any count, parameter and offset, writes nothing, and leaves the store intact for a later write.
  • word_oob: every out-of-range read gives 0 on a fresh store and after in-range words are set (-1, 16, 17, INT_MAX as the parameter; -1, 8, 9, INT_MAX as the offset; INT_MIN for both); a never-written word also reads 0, and only is_bound() tells it from a word written as 0.

Mutation controls (6/6 killed)

  • count_guard_mut: the count == 0 guard in set() is dropped, so an empty write is stored instead of dropped; zero_count then returns stored for set(0, 0, data, 0).
  • trunc_cut_mut: the truncation cut is off by one (count > words - offset becomes >=); set_stored then returns truncated for a full row that exactly fits.
  • bound_mask_mut: the bound mask is not shifted to the write offset; set_stored then reports is_bound(3, 2, 4) false after set(3, 4, data, 2).
  • is_bound_zero_mut: the count == 0 guard in is_bound() is dropped, so an empty range reports bound (its mask is zero); zero_count then reports is_bound(0, 0, 0) true.
  • clear_bound_mut: clear() no longer forgets the bound bits; clear then reports is_bound(0, 0, 8) true after clear().
  • result_swap_mut: the stored / truncated results are swapped; set_stored then returns truncated for a write that fits.

There is no control for the data == nullptr guard: dropping it dereferences a null pointer, which CTest reports as a crash rather than an expected failure, so it has no clean WILL_FAIL control; null_data still exercises that guard directly. There is likewise no control for the parameter / offset guards in set(): weakening one lets a write index past the kept words, which is undefined behaviour rather than a wrong result; bad_param and bad_offset still exercise those guards directly.

Verification (Linux, this host, g++ -std=c++17, base origin/main 5770f14e)

./out/pe-env/bin/python -B tests/root_constant_store_unit_meta_check.py
PASS: root_constant_store_unit: 10 cases, 6/6 mutations killed (g++)
ctest --test-dir out/root-constant-store-unit-scratch/build --no-tests=error -R '^root_constant_store_unit'
100% tests passed, 0 tests failed out of 17

Full configure needs DXC, unavailable on Linux, so the fragment was configured standalone via symlinked src/tests under out/root-constant-store-unit-scratch (17 tests: 10 cases + all + 6 controls).

./out/pe-env/bin/python -B tests/form_coverage_check.py
form coverage checks passed
./out/pe-env/bin/python -B tests/docs_links_check.py
Checked 242 Markdown files and 921 links.
./out/pe-env/bin/python -B tests/bidi_controls_check.py
Checked 2960 tracked source, script and build/CI files: no bidirectional controls.

Full Linux CI list from .github/workflows/windows.yml (tools/run_checks_parallel.py --from-dir tests/checks/python-linux ...): all 329 checks passed.

git diff --check clean; git merge-tree exits 0. No mingw on this host, so no Windows compile check; WIN-VERIFY is the arbiter.

Windows Verification (6ec52266911ea1a0f23d340b15759a43fc2fe23f)

ctest --preset dev --no-tests=error -j16 -R '^root_constant_store_unit' --output-on-failure
-> 100% tests passed, 0 tests failed out of 17 (1.06s)

ctest --preset release --no-tests=error -j16 -R '^root_constant_store_unit' --output-on-failure
-> 100% tests passed, 0 tests failed out of 17 (0.66s)

root_constant_store_unit_check.exe (dev + release): 10/10 cases passed
tests/root_constant_store_unit_meta_check.py (cl): 10 cases, 6/6 mutations killed (cl)

AI-assisted.

**@⁠Ammmae0x** on GitHub · 2026-12-02 14:31 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3859) `Ammmae0x:tests/root-constant-store-unit` → `main` · +1103 −0 · 5 files · 2 commits · merged 2026-12-02 15:32 UTC Refs #1149 Portable C++17 unit and header-mutation tests for `x2w_root_constants::Store` (`src/startup_stubs/root_constant_store.h`), matching `tests/cmake/logical_view_table_unit.cmake`. The source is unchanged; only 5 new files are added (+1103/-0), and the existing `tests/startup_root_constant_store.cpp` coverage is untouched. The new check uses the disjoint `root_constant_store_unit` prefix so test names do not collide. **What landed** - `tests/root_constant_store_unit_check.cpp` — 10 cases, header-only against `src`, no device, no loader, no title data. Every shared constant is `static constexpr`. - `tests/cmake/root_constant_store_unit.cmake` — one CTest test per case plus `root_constant_store_unit_all`, and 6 `WILL_FAIL TRUE` controls (`BEFORE PRIVATE` mutated header copies, 1:1 with the meta check). - `tests/root_constant_store_unit_meta_check.py` — audits the contract, compiles and runs the real C++ check and every mutation natively with `g++ -std=c++17 -Wall -Wextra -Wpedantic -Werror` (or `cl` with `/W4`). - `tests/checks/python-linux/root_constant_store_unit.txt` — lists exactly the meta check. - `docs/experiments/root-constant-store-unit.md` — cases, controls, and verification. **Cases** - `constants`: `parameter_count == 16` and `words_per_parameter == 8`; `stored`, `truncated` and `dropped` are distinct; a default store holds no words and no bound bits. - `clear`: clearing a fresh store is a no-op; after filling parameters 0, 7 and 15, `clear()` zeroes every word and forgets every bound bit; a second `clear()` is still a no-op, and the store accepts a write afterwards. - `set_stored`: a write that fits is stored whole, reads back at its offsets, and marks exactly the words it wrote; a full row at offset 0 and a write ending exactly at the last word are stored, not truncated; parameter 15 is the last one kept; an overwriting `set_one` changes one word without disturbing its neighbours. - `set_one`: a single word at the last offset is stored and bound; writing 0 is still a write (`word()` reads 0 either way, but `is_bound()` is true); a single word in parameter 15 and an overwrite read back. - `bad_param`: parameters 16, 17 and the largest unsigned value (the unsigned `-1`) are dropped for both `set` and `set_one`, leaving sentinel words in parameters 0 and 15 unchanged; `word(-1, 0)`, `word(16, 0)` and `word(INT_MAX, 0)` read 0. - `bad_offset`: offsets 8, 9 and the largest unsigned value (the unsigned `-1`) are dropped for both `set` and `set_one`, leaving a sentinel full row unchanged; `word(0, 8)`, `word(0, 9)` and `word(0, -1)` read 0; offset 7 is the last valid offset. - `zero_count`: a zero-count write is dropped with valid data, a null source, or at offset 3, and writes nothing; a zero-count range is never bound even after the whole row is written; a range running past the end of the row is never bound. - `truncation`: a write running past the end of the parameter is cut off (offset 6 count 4, offset 0 count 9, offset 7 count 2): the words that fit are kept and bound, nothing spills into the next parameter; a write ending exactly at the last word is stored, not truncated. - `null_data`: a null source is dropped at any count, parameter and offset, writes nothing, and leaves the store intact for a later write. - `word_oob`: every out-of-range read gives 0 on a fresh store and after in-range words are set (`-1`, `16`, `17`, `INT_MAX` as the parameter; `-1`, `8`, `9`, `INT_MAX` as the offset; `INT_MIN` for both); a never-written word also reads 0, and only `is_bound()` tells it from a word written as 0. **Mutation controls (6/6 killed)** - `count_guard_mut`: the `count == 0` guard in `set()` is dropped, so an empty write is stored instead of dropped; `zero_count` then returns `stored` for `set(0, 0, data, 0)`. - `trunc_cut_mut`: the truncation cut is off by one (`count > words - offset` becomes `>=`); `set_stored` then returns `truncated` for a full row that exactly fits. - `bound_mask_mut`: the bound mask is not shifted to the write offset; `set_stored` then reports `is_bound(3, 2, 4)` false after `set(3, 4, data, 2)`. - `is_bound_zero_mut`: the `count == 0` guard in `is_bound()` is dropped, so an empty range reports bound (its mask is zero); `zero_count` then reports `is_bound(0, 0, 0)` true. - `clear_bound_mut`: `clear()` no longer forgets the bound bits; `clear` then reports `is_bound(0, 0, 8)` true after `clear()`. - `result_swap_mut`: the `stored` / `truncated` results are swapped; `set_stored` then returns `truncated` for a write that fits. There is no control for the `data == nullptr` guard: dropping it dereferences a null pointer, which CTest reports as a crash rather than an expected failure, so it has no clean `WILL_FAIL` control; `null_data` still exercises that guard directly. There is likewise no control for the parameter / offset guards in `set()`: weakening one lets a write index past the kept words, which is undefined behaviour rather than a wrong result; `bad_param` and `bad_offset` still exercise those guards directly. **Verification (Linux, this host, `g++ -std=c++17`, base `origin/main` `5770f14e`)** ```text ./out/pe-env/bin/python -B tests/root_constant_store_unit_meta_check.py PASS: root_constant_store_unit: 10 cases, 6/6 mutations killed (g++) ``` ```text ctest --test-dir out/root-constant-store-unit-scratch/build --no-tests=error -R '^root_constant_store_unit' 100% tests passed, 0 tests failed out of 17 ``` Full configure needs DXC, unavailable on Linux, so the fragment was configured standalone via symlinked `src`/`tests` under `out/root-constant-store-unit-scratch` (17 tests: 10 cases + all + 6 controls). ```text ./out/pe-env/bin/python -B tests/form_coverage_check.py form coverage checks passed ./out/pe-env/bin/python -B tests/docs_links_check.py Checked 242 Markdown files and 921 links. ./out/pe-env/bin/python -B tests/bidi_controls_check.py Checked 2960 tracked source, script and build/CI files: no bidirectional controls. ``` Full Linux CI list from `.github/workflows/windows.yml` (`tools/run_checks_parallel.py --from-dir tests/checks/python-linux ...`): `all 329 checks passed`. `git diff --check` clean; `git merge-tree` exits 0. No mingw on this host, so no Windows compile check; WIN-VERIFY is the arbiter. ### Windows Verification (`6ec52266911ea1a0f23d340b15759a43fc2fe23f`) ```text ctest --preset dev --no-tests=error -j16 -R '^root_constant_store_unit' --output-on-failure -> 100% tests passed, 0 tests failed out of 17 (1.06s) ctest --preset release --no-tests=error -j16 -R '^root_constant_store_unit' --output-on-failure -> 100% tests passed, 0 tests failed out of 17 (0.66s) root_constant_store_unit_check.exe (dev + release): 10/10 cases passed tests/root_constant_store_unit_meta_check.py (cl): 10 cases, 6/6 mutations killed (cl) ``` AI-assisted. <!-- WIN-VERIFY: passed | sha=6ec52266911ea1a0f23d340b15759a43fc2fe23f -->
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 14:34:28 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-02 14:56 UTC · original · approved these changes

Reviewed the five-file test-only diff and verified a clean trial merge. On 6ec52266, python3 -B tests/root_constant_store_unit_meta_check.py passed all 10 original cases on GCC and caught all six mutations. I also built the unmodified CMake fragment in a standalone harness with MSVC 19.51 and ran ctest --test-dir build --output-on-failure. All 17 tests passed, including the expected mutation failures. The cases exercise parameter and word bounds, truncation, clear and zero-count behavior. Hosted Windows CI still fails in the shared native_direct_mesh fixture tracked by #3853.

**@⁠R0Y00** on GitHub · 2026-12-02 14:56 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3859#pullrequestreview-6153270659) · **approved these changes** Reviewed the five-file test-only diff and verified a clean trial merge. On 6ec52266, `python3 -B tests/root_constant_store_unit_meta_check.py` passed all 10 original cases on GCC and caught all six mutations. I also built the unmodified CMake fragment in a standalone harness with MSVC 19.51 and ran `ctest --test-dir build --output-on-failure`. All 17 tests passed, including the expected mutation failures. The cases exercise parameter and word bounds, truncation, clear and zero-count behavior. Hosted Windows CI still fails in the shared `native_direct_mesh` fixture tracked by #3853.
github-bot changed target branch from main to gh-pr/3859/base 2026-12-02 15:37:01 +00:00
github manually merged commit ee9c59941c into gh-pr/3859/base 2026-12-02 15:37:03 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.