tests: cover x2w_bcpack diagnostics, layouts, and failure classes #3862

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

@⁠Ammmae0x on GitHub · 2026-12-02 14:41 UTC · original
Ammmae0x:tests/bcpack-inspect-unit → main · +1416 −0 · 5 files · 2 commits · merged 2026-12-02 15:32 UTC

Refs #1149

Portable C++17 unit and header-mutation tests for x2w_bcpack::inspect_layout, inspect_class, inspect_class_name and inspect_bcpack (src/startup_stubs/bcpack_inspect.h, Refs #1198), matching tests/cmake/logical_view_table_unit.cmake. The source is unchanged; only 5 new files are added (+1416/-0), and the existing tests/bcpack_inspect_check.cpp coverage is untouched. The new check uses the disjoint bcpack_inspect_unit prefix so test names do not collide.

What landed

  • tests/bcpack_inspect_unit_check.cpp — 12 cases, header-only against src plus the test-only encoder and fixtures in tests, no device, no loader, no title data. The BC1 and BC7 streams are the synthetic vectors already in the repository; the BC3/BC4/BC5 streams come from the test-only encoder and the BC2/BC6/BC7 fixtures from the fixture encoder. Every class is also checked against decode_bcpack: it decodes exactly when the class is ok.
  • tests/cmake/bcpack_inspect_unit.cmake — one CTest test per case plus bcpack_inspect_unit_all, and 6 WILL_FAIL TRUE controls (BEFORE PRIVATE mutated header copies, 1:1 with the meta check). Mutant targets also add src/startup_stubs to the include path, mirroring d3d12_teardown, so the mutated header's sibling include of bcpack_decoder.h resolves.
  • tests/bcpack_inspect_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/bcpack_inspect_unit.txt — lists exactly the meta check.
  • docs/experiments/bcpack-inspect-unit.md — cases, controls, and verification.

Cases

  • layout_formats: seven layouts, one per format BC1 through BC7, each the table entry for its format, with the fixture lane count, block size, symbols per block and alphabet index per lane; formats 0, 8, 9 and 255 have no layout.
  • class_and_names: inspect_class maps all ten LaneFailure values to their InspectClass; inspect_class_name names all fourteen classes, and an out-of-range value reads as unknown.
  • bad_arguments: null input, empty input, zero destination, and null/empty input with an unsupported format (the argument check runs first); the cap is the 16 MiB chunk window, and inspect_max_output + 1/+ 8 (BC1) and + 16/256 MiB (BC7) are refused before anything is allocated, with no lane counts reported.
  • unsupported_format: a BC1 stream read as format 0, 8 or 9, and a BC7 stream read as format 8, refused before the lanes run, with no lane counts reported.
  • destination_misaligned: BC1 at 510, 12 and 1 bytes, BC7 at 15 and 24 bytes, and the BC1 bytes as BC2 (24 bytes) and as BC6 (8 bytes); refused before the lanes run, with no lane counts reported.
  • bc1_ok_counts: the 64-block BC1 vector decodes (ok, 515 bytes read, 64 symbols per lane, target 64), including with zero padding; a shorter request reads as request_shorter_than_stream (1, 16 and 63 blocks) and a longer one as request_longer_than_stream (65 and 1000 blocks).
  • bc1_lane_failures: a cut stream reads as truncated_in_fragment (cut at 514, 300, 100 and 1); one byte after the end reads as trailing_input; first byte 0 reads as fragment_not_home; byte 2 set to 11 reads as cycle_limit; byte 382 flipped reads as end_state_invalid; the BC1 stream read with the BC7 layout reads as fragment_not_home.
  • bc7_ok_failures: the one- and two-block BC7 vectors decode (ok, 104 and 132 bytes read, 2 and 4 symbols per lane); a shorter request reads as request_shorter_than_stream, a longer one as request_longer_than_stream, a cut stream as truncated_in_fragment; first byte 1 reads as end_state_invalid, byte 8 zero as fragment_not_home; the single mode 6 block decodes to the block the vector was made from.
  • bc345_encoder_streams: encoder streams for BC3, BC4 and BC5 (40 blocks, unflushed fragments) decode exactly; half the blocks read as request_shorter_than_stream, one byte after the end as trailing_input, a misaligned size as destination_misaligned, twice the blocks as request_longer_than_stream or truncated_in_fragment, half the stream as truncated_in_fragment or request_longer_than_stream.
  • bc2_bc6_bc7_fixtures: the BC2 and BC6 fixture streams decode exactly; a BC6 fixture with mode 14 reads as bc6_mode_invalid; a BC7 fixture whose control code is 0x07f reads as control_code_unmapped.
  • lane_report: decode_lanes with a report names header_invalid for a fragment header at alphabet index 2, bad_arguments for no lanes and for an alphabet index above 8, and the report's header_invalid maps to InspectClass::header_invalid.
  • inspection_cap_boundary: a BC1 request at exactly inspect_max_output is inspected, not refused, and reads as request_longer_than_stream (515 bytes read, 64 symbols per lane, target 2,097,152).

Mutation controls (6/6 killed)

  • layout_null_mut: the layout lookup returns the BC1 layout instead of null; unsupported_format then decodes format 8 as BC1 instead of refusing it.
  • class_map_mut: the class mapping reports a bad fragment header as ok; class_and_names then maps header_invalid to ok.
  • class_name_mut: the ok class is named bad_arguments; class_and_names then reads inspect_class_name(ok) as bad_arguments.
  • cap_guard_mut: the inspection cap is eight bytes too high; bad_arguments then reads inspect_max_output + 1 as destination_misaligned (and + 8 as request_longer_than_stream).
  • misaligned_guard_mut: the misaligned-destination test is weakened to a remainder above 1; destination_misaligned then reads a 510-byte BC1 request as request_shorter_than_stream.
  • bc6_result_mut: a BC6 block with an undefined mode is reported as ok; bc2_bc6_bc7_fixtures then reads the mode-14 fixture as ok instead of bc6_mode_invalid.

There is no control for dropping the destination-misaligned guard outright, or for the BC7 control-code assignment: dropping the misaligned guard is covered by weakening its remainder test instead, and the BC7 assignment is the mirror of the BC6 one.

Linux-only notes, flagged explicitly

  • bcpack_decoder.h (included by bcpack_inspect.h) includes MSVC-only <intrin.h>, so g++ cannot compile the header as-is. The meta check writes a minimal intrin.h shim into its own temporary directory (never into the repository) for _BitScanReverse and _BitScanForward, the two scan intrinsics the non-AVX2 paths use, implemented with __builtin_clz and __builtin_ctz with MSVC semantics. On Windows, cl uses the real <intrin.h> and no shim is involved. Windows CTest remains the arbiter for the MSVC build.
  • header_invalid cannot arise through inspect_bcpack itself: the BC1 through BC7 layouts never use an alphabet index below 3, and a fragment header's top two bits are at most 3, so the derived alphabet index never wraps above 8. The check reaches it through decode_lanes directly, with a one-lane decode at alphabet index 2, and pins the inspect_class mapping from that report.

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

./out/pe-env/bin/python -B tests/bcpack_inspect_unit_meta_check.py
PASS: bcpack_inspect_unit: 12 cases, 6/6 mutations killed (g++)
ctest --no-tests=error -R '^bcpack_inspect_unit'
100% tests passed, 0 tests failed out of 19

Full configure needs DXC, unavailable on Linux, so the fragment was configured standalone via symlinked src/tests (19 tests: 12 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 --write-tree origin/main HEAD exits 0.

Windows Verification (6aa0f7a0aeef2d475f00d701d0fc8ff48472f0b9)

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

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

bcpack_inspect_unit_check.exe (dev + release): 12/12 cases passed
tests/bcpack_inspect_unit_meta_check.py (cl): 12 cases, 6/6 mutations killed (cl)

AI-assisted.

**@⁠Ammmae0x** on GitHub · 2026-12-02 14:41 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3860) `Ammmae0x:tests/bcpack-inspect-unit` → `main` · +1416 −0 · 5 files · 2 commits · merged 2026-12-02 15:32 UTC Refs #1149 Portable C++17 unit and header-mutation tests for `x2w_bcpack::inspect_layout`, `inspect_class`, `inspect_class_name` and `inspect_bcpack` (`src/startup_stubs/bcpack_inspect.h`, Refs #1198), matching `tests/cmake/logical_view_table_unit.cmake`. The source is unchanged; only 5 new files are added (+1416/-0), and the existing `tests/bcpack_inspect_check.cpp` coverage is untouched. The new check uses the disjoint `bcpack_inspect_unit` prefix so test names do not collide. **What landed** - `tests/bcpack_inspect_unit_check.cpp` — 12 cases, header-only against `src` plus the test-only encoder and fixtures in `tests`, no device, no loader, no title data. The BC1 and BC7 streams are the synthetic vectors already in the repository; the BC3/BC4/BC5 streams come from the test-only encoder and the BC2/BC6/BC7 fixtures from the fixture encoder. Every class is also checked against `decode_bcpack`: it decodes exactly when the class is `ok`. - `tests/cmake/bcpack_inspect_unit.cmake` — one CTest test per case plus `bcpack_inspect_unit_all`, and 6 `WILL_FAIL TRUE` controls (`BEFORE PRIVATE` mutated header copies, 1:1 with the meta check). Mutant targets also add `src/startup_stubs` to the include path, mirroring `d3d12_teardown`, so the mutated header's sibling include of `bcpack_decoder.h` resolves. - `tests/bcpack_inspect_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/bcpack_inspect_unit.txt` — lists exactly the meta check. - `docs/experiments/bcpack-inspect-unit.md` — cases, controls, and verification. **Cases** - `layout_formats`: seven layouts, one per format BC1 through BC7, each the table entry for its format, with the fixture lane count, block size, symbols per block and alphabet index per lane; formats 0, 8, 9 and 255 have no layout. - `class_and_names`: `inspect_class` maps all ten `LaneFailure` values to their `InspectClass`; `inspect_class_name` names all fourteen classes, and an out-of-range value reads as `unknown`. - `bad_arguments`: null input, empty input, zero destination, and null/empty input with an unsupported format (the argument check runs first); the cap is the 16 MiB chunk window, and `inspect_max_output + 1`/`+ 8` (BC1) and `+ 16`/256 MiB (BC7) are refused before anything is allocated, with no lane counts reported. - `unsupported_format`: a BC1 stream read as format 0, 8 or 9, and a BC7 stream read as format 8, refused before the lanes run, with no lane counts reported. - `destination_misaligned`: BC1 at 510, 12 and 1 bytes, BC7 at 15 and 24 bytes, and the BC1 bytes as BC2 (24 bytes) and as BC6 (8 bytes); refused before the lanes run, with no lane counts reported. - `bc1_ok_counts`: the 64-block BC1 vector decodes (`ok`, 515 bytes read, 64 symbols per lane, target 64), including with zero padding; a shorter request reads as `request_shorter_than_stream` (1, 16 and 63 blocks) and a longer one as `request_longer_than_stream` (65 and 1000 blocks). - `bc1_lane_failures`: a cut stream reads as `truncated_in_fragment` (cut at 514, 300, 100 and 1); one byte after the end reads as `trailing_input`; first byte 0 reads as `fragment_not_home`; byte 2 set to 11 reads as `cycle_limit`; byte 382 flipped reads as `end_state_invalid`; the BC1 stream read with the BC7 layout reads as `fragment_not_home`. - `bc7_ok_failures`: the one- and two-block BC7 vectors decode (`ok`, 104 and 132 bytes read, 2 and 4 symbols per lane); a shorter request reads as `request_shorter_than_stream`, a longer one as `request_longer_than_stream`, a cut stream as `truncated_in_fragment`; first byte 1 reads as `end_state_invalid`, byte 8 zero as `fragment_not_home`; the single mode 6 block decodes to the block the vector was made from. - `bc345_encoder_streams`: encoder streams for BC3, BC4 and BC5 (40 blocks, unflushed fragments) decode exactly; half the blocks read as `request_shorter_than_stream`, one byte after the end as `trailing_input`, a misaligned size as `destination_misaligned`, twice the blocks as `request_longer_than_stream` or `truncated_in_fragment`, half the stream as `truncated_in_fragment` or `request_longer_than_stream`. - `bc2_bc6_bc7_fixtures`: the BC2 and BC6 fixture streams decode exactly; a BC6 fixture with mode 14 reads as `bc6_mode_invalid`; a BC7 fixture whose control code is `0x07f` reads as `control_code_unmapped`. - `lane_report`: `decode_lanes` with a report names `header_invalid` for a fragment header at alphabet index 2, `bad_arguments` for no lanes and for an alphabet index above 8, and the report's `header_invalid` maps to `InspectClass::header_invalid`. - `inspection_cap_boundary`: a BC1 request at exactly `inspect_max_output` is inspected, not refused, and reads as `request_longer_than_stream` (515 bytes read, 64 symbols per lane, target 2,097,152). **Mutation controls (6/6 killed)** - `layout_null_mut`: the layout lookup returns the BC1 layout instead of null; `unsupported_format` then decodes format 8 as BC1 instead of refusing it. - `class_map_mut`: the class mapping reports a bad fragment header as `ok`; `class_and_names` then maps `header_invalid` to `ok`. - `class_name_mut`: the `ok` class is named `bad_arguments`; `class_and_names` then reads `inspect_class_name(ok)` as `bad_arguments`. - `cap_guard_mut`: the inspection cap is eight bytes too high; `bad_arguments` then reads `inspect_max_output + 1` as `destination_misaligned` (and `+ 8` as `request_longer_than_stream`). - `misaligned_guard_mut`: the misaligned-destination test is weakened to a remainder above 1; `destination_misaligned` then reads a 510-byte BC1 request as `request_shorter_than_stream`. - `bc6_result_mut`: a BC6 block with an undefined mode is reported as `ok`; `bc2_bc6_bc7_fixtures` then reads the mode-14 fixture as `ok` instead of `bc6_mode_invalid`. There is no control for dropping the destination-misaligned guard outright, or for the BC7 control-code assignment: dropping the misaligned guard is covered by weakening its remainder test instead, and the BC7 assignment is the mirror of the BC6 one. **Linux-only notes, flagged explicitly** - `bcpack_decoder.h` (included by `bcpack_inspect.h`) includes MSVC-only `<intrin.h>`, so `g++` cannot compile the header as-is. The meta check writes a minimal `intrin.h` shim into its own temporary directory (never into the repository) for `_BitScanReverse` and `_BitScanForward`, the two scan intrinsics the non-AVX2 paths use, implemented with `__builtin_clz` and `__builtin_ctz` with MSVC semantics. On Windows, `cl` uses the real `<intrin.h>` and no shim is involved. Windows CTest remains the arbiter for the MSVC build. - `header_invalid` cannot arise through `inspect_bcpack` itself: the BC1 through BC7 layouts never use an alphabet index below 3, and a fragment header's top two bits are at most 3, so the derived alphabet index never wraps above 8. The check reaches it through `decode_lanes` directly, with a one-lane decode at alphabet index 2, and pins the `inspect_class` mapping from that report. **Verification (Linux, this host, `g++ -std=c++17`, base `origin/main` `5770f14e`)** ```text ./out/pe-env/bin/python -B tests/bcpack_inspect_unit_meta_check.py PASS: bcpack_inspect_unit: 12 cases, 6/6 mutations killed (g++) ``` ```text ctest --no-tests=error -R '^bcpack_inspect_unit' 100% tests passed, 0 tests failed out of 19 ``` Full configure needs DXC, unavailable on Linux, so the fragment was configured standalone via symlinked `src`/`tests` (19 tests: 12 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 --write-tree origin/main HEAD` exits 0. ### Windows Verification (`6aa0f7a0aeef2d475f00d701d0fc8ff48472f0b9`) ```text ctest --preset dev --no-tests=error -j16 -R '^bcpack_inspect_unit' --output-on-failure -> 100% tests passed, 0 tests failed out of 19 (0.69s) ctest --preset release --no-tests=error -j16 -R '^bcpack_inspect_unit' --output-on-failure -> 100% tests passed, 0 tests failed out of 19 (0.95s) bcpack_inspect_unit_check.exe (dev + release): 12/12 cases passed tests/bcpack_inspect_unit_meta_check.py (cl): 12 cases, 6/6 mutations killed (cl) ``` AI-assisted. <!-- WIN-VERIFY: passed | sha=6aa0f7a0aeef2d475f00d701d0fc8ff48472f0b9 -->
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 14:46:14 +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 6aa0f7a0, python3 -B tests/bcpack_inspect_unit_meta_check.py passed all 12 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 19 tests passed, including the expected mutation failures. The cases cover synthetic BC1–BC7 data, layout and classification, output limits and malformed lane reports. 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/3860#pullrequestreview-6153272658) · **approved these changes** Reviewed the five-file test-only diff and verified a clean trial merge. On 6aa0f7a0, `python3 -B tests/bcpack_inspect_unit_meta_check.py` passed all 12 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 19 tests passed, including the expected mutation failures. The cases cover synthetic BC1–BC7 data, layout and classification, output limits and malformed lane reports. 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/3860/base 2026-12-02 15:37:31 +00:00
github manually merged commit b6ab6f2def into gh-pr/3860/base 2026-12-02 15:37:33 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.