tests: cover x2w_xmem::SlabSlots allocation, unwind, tombstones, and reclaim #3779

Manually merged
github merged 4 commits from github-bot/gh-3777 into gh-pr/3777/base 2026-12-02 15:59:31 +00:00 AGit
Owner

@⁠Ammmae0x on GitHub · 2026-12-01 19:25 UTC · original
Ammmae0x:tests/xmem-slab-slots-unit → main · +1519 −0 · 5 files · 4 commits · merged 2026-12-02 15:57 UTC

Refs #1149.

Standalone portable C++17 unit, exception-safety, and 1:1 header-mutation tests for x2w_xmem::SlabSlots in src/xmem_slab_slots.h, with zero edits to existing files (5 new files only, tests/xmem_slab_slots_check.cpp and CMakeLists.txt untouched, disjoint prefix xmem_slab_slots_unit).

What landed — commit d55a43ac, 5 new files only:

  • tests/xmem_slab_slots_unit_check.cpp — 9 cases: fresh_rollover (slots_per_slab == 4096, slab_bytes, 4096 -> new slab rollover), make_false (make returns false rollback, empty and second slab), throw_discard (throwing Handle copy triggers discard(slab) leaving slab_count/slots_in_use/slabs intact, first and second slab), unwind_fresh (last-slot undo vs mismatched index/offset/zero/older-slab no-op), release_validation (bad slab index, tombstone, misaligned offset, offset >= slab_bytes, unallocated fresh slot, duplicate release), lowest_free/take_lowest_free (multi-slab ordering and counters, empty case), reclaim_tombstone (non-trailing slab becomes Handle{} tombstone preserving later indices), reclaim_trailing (trailing pop, consecutive tombstones, fresh_used_ reset to 0 or 4096), reclaim_free_entries (reclaim frees free_ entries, slots_free invariant throughout).
  • tests/cmake/xmem_slab_slots_unit.cmake — per-case CTests plus xmem_slab_slots_unit_all, and 6 WILL_FAIL TRUE BEFORE PRIVATE header mutations: throw_discard, unwind_match, dup_release, tombstone_index, trailing_pop_reset, reclaim_free_erase.
  • tests/xmem_slab_slots_unit_meta_check.py — audits the contract and mirrors the 6 mutations 1:1 against real C++ copies (g++ if present else cl, finally-cleaned temp dir).
  • tests/checks/python-linux/xmem_slab_slots_unit.txt
  • docs/experiments/xmem-slab-slots-unit.md

Caught in development: the first throw_discard mutant replaced discard(slab); with (void)slab;, which left the discard parameter unused and failed to compile under -Werror=unused-parameter; the mutant now uses (void)discard;.

Fix on 73e070b3 — MSVC Debug xmem_slab_slots_unit_reclaim_free_erase_mut timed out (59s): with the free_ erase dropped, stale slab-0 entries survive reclaim, and continuing into take_lowest_free plus a full reclaim lets lowest_free() index the emptied slabs_ vector. reclaim_free_entries now stops (return false, after the expect_* failures) when the lowest free slot after reclaim is still slab 0 instead of slab 1 (handle 101), guards closed[1] on closed.size() >= 2, and runs the second reclaim (the one that pops the tombstone) on a fresh Slots. The mutant now fails fast on Linux instead of hanging.

Verification (Linux, this host)

  • Meta check: PASS: xmem_slab_slots_unit: 9 cases, 6/6 mutations killed (g++)
  • Scratch CMake + CTest: 100% tests passed, 0 tests failed out of 16 (9 per-case + all + 6 mutation controls); xmem_slab_slots_unit_reclaim_free_erase_mut passes in 0.00s, and the mutant run directly fails fast (rc=1, 2 FAIL: lines) instead of timing out
  • form_coverage_check.py passes, docs_links_check.py passes (226 files, 878 links), bidi_controls_check.py passes (2880 files), git diff --check clean
  • Full python-linux suite (tools/run_checks_parallel.py, from the CI workflow): all 316 checks passed

Windows Verification (73e070b380899ffc8ca55087a8b7f3b06a16b4d2)

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

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

xmem_slab_slots_unit_check.exe (dev + release): 9/9 cases passed
tests/xmem_slab_slots_unit_meta_check.py (cl): 9 cases, 6/6 mutations killed (cl)

AI-assisted.

**@⁠Ammmae0x** on GitHub · 2026-12-01 19:25 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3777) `Ammmae0x:tests/xmem-slab-slots-unit` → `main` · +1519 −0 · 5 files · 4 commits · merged 2026-12-02 15:57 UTC Refs #1149. Standalone portable C++17 unit, exception-safety, and 1:1 header-mutation tests for `x2w_xmem::SlabSlots` in `src/xmem_slab_slots.h`, with zero edits to existing files (5 new files only, `tests/xmem_slab_slots_check.cpp` and `CMakeLists.txt` untouched, disjoint prefix `xmem_slab_slots_unit`). **What landed** — commit `d55a43ac`, 5 new files only: - `tests/xmem_slab_slots_unit_check.cpp` — 9 cases: `fresh_rollover` (`slots_per_slab == 4096`, `slab_bytes`, 4096 -> new slab rollover), `make_false` (make returns false rollback, empty and second slab), `throw_discard` (throwing `Handle` copy triggers `discard(slab)` leaving `slab_count`/`slots_in_use`/`slabs` intact, first and second slab), `unwind_fresh` (last-slot undo vs mismatched index/offset/zero/older-slab no-op), `release_validation` (bad slab index, tombstone, misaligned offset, `offset >= slab_bytes`, unallocated fresh slot, duplicate release), `lowest_free`/`take_lowest_free` (multi-slab ordering and counters, empty case), `reclaim_tombstone` (non-trailing slab becomes `Handle{}` tombstone preserving later indices), `reclaim_trailing` (trailing pop, consecutive tombstones, `fresh_used_` reset to 0 or 4096), `reclaim_free_entries` (reclaim frees `free_` entries, `slots_free` invariant throughout). - `tests/cmake/xmem_slab_slots_unit.cmake` — per-case CTests plus `xmem_slab_slots_unit_all`, and 6 `WILL_FAIL TRUE` `BEFORE PRIVATE` header mutations: `throw_discard`, `unwind_match`, `dup_release`, `tombstone_index`, `trailing_pop_reset`, `reclaim_free_erase`. - `tests/xmem_slab_slots_unit_meta_check.py` — audits the contract and mirrors the 6 mutations 1:1 against real C++ copies (g++ if present else cl, `finally`-cleaned temp dir). - `tests/checks/python-linux/xmem_slab_slots_unit.txt` - `docs/experiments/xmem-slab-slots-unit.md` Caught in development: the first `throw_discard` mutant replaced `discard(slab);` with `(void)slab;`, which left the `discard` parameter unused and failed to compile under `-Werror=unused-parameter`; the mutant now uses `(void)discard;`. **Fix on `73e070b3`** — MSVC Debug `xmem_slab_slots_unit_reclaim_free_erase_mut` timed out (59s): with the `free_` erase dropped, stale slab-0 entries survive reclaim, and continuing into `take_lowest_free` plus a full reclaim lets `lowest_free()` index the emptied `slabs_` vector. `reclaim_free_entries` now stops (`return false`, after the `expect_*` failures) when the lowest free slot after reclaim is still slab 0 instead of slab 1 (handle 101), guards `closed[1]` on `closed.size() >= 2`, and runs the second reclaim (the one that pops the tombstone) on a fresh `Slots`. The mutant now fails fast on Linux instead of hanging. **Verification (Linux, this host)** - Meta check: `PASS: xmem_slab_slots_unit: 9 cases, 6/6 mutations killed (g++)` - Scratch CMake + CTest: `100% tests passed, 0 tests failed out of 16` (9 per-case + all + 6 mutation controls); `xmem_slab_slots_unit_reclaim_free_erase_mut` passes in 0.00s, and the mutant run directly fails fast (rc=1, 2 `FAIL:` lines) instead of timing out - `form_coverage_check.py` passes, `docs_links_check.py` passes (226 files, 878 links), `bidi_controls_check.py` passes (2880 files), `git diff --check` clean - Full `python-linux` suite (`tools/run_checks_parallel.py`, from the CI workflow): `all 316 checks passed` ### Windows Verification (`73e070b380899ffc8ca55087a8b7f3b06a16b4d2`) ```text ctest --preset dev --no-tests=error -j16 -R '^xmem_slab_slots_unit' --output-on-failure -> 100% tests passed, 0 tests failed out of 16 (0.68s) ctest --preset release --no-tests=error -j16 -R '^xmem_slab_slots_unit' --output-on-failure -> 100% tests passed, 0 tests failed out of 16 (0.64s) xmem_slab_slots_unit_check.exe (dev + release): 9/9 cases passed tests/xmem_slab_slots_unit_meta_check.py (cl): 9 cases, 6/6 mutations killed (cl) ``` AI-assisted. <!-- WIN-VERIFY: passed | sha=73e070b380899ffc8ca55087a8b7f3b06a16b4d2 -->
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 19:26:09 +00:00
MSVC Debug xmem_slab_slots_unit_reclaim_free_erase_mut timed out
(59s): with the free_ erase dropped, stale slab-0 entries survive
reclaim, and continuing into take_lowest_free plus a full reclaim
lets lowest_free() index the emptied slabs_ vector. Stop the case
(return false, after the expect_* failures) when the lowest free
slot after reclaim is still slab 0 instead of slab 1 (handle 101),
guard closed[1] on closed.size() >= 2, and run the second reclaim
(the one that pops the tombstone) on a fresh Slots.
Author
Owner

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

I checked the five-file test-only diff and a clean trial merge. On the exact head, python3 -B tests/xmem_slab_slots_unit_meta_check.py passed with GCC, exercising all nine cases and catching all six mutations. I also built the unmodified CMake fragment in a standalone harness with MSVC 19.51. ctest --test-dir build --output-on-failure passed 16/16 including the six expected failures. The unwind, duplicate release, tombstone and trailing reset controls exercise distinct allocator invariants.

**@⁠R0Y00** on GitHub · 2026-12-02 14:15 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3777#pullrequestreview-6152532005) · **approved these changes** I checked the five-file test-only diff and a clean trial merge. On the exact head, `python3 -B tests/xmem_slab_slots_unit_meta_check.py` passed with GCC, exercising all nine cases and catching all six mutations. I also built the unmodified CMake fragment in a standalone harness with MSVC 19.51. `ctest --test-dir build --output-on-failure` passed 16/16 including the six expected failures. The unwind, duplicate release, tombstone and trailing reset controls exercise distinct allocator invariants.
github-bot changed target branch from main to gh-pr/3777/base 2026-12-02 15:59:28 +00:00
github manually merged commit e2486a6af0 into gh-pr/3777/base 2026-12-02 15:59:31 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.