[pr-tests][audio] darner-formats XMA: unit tests for the bit reader, large values, log2 and sample conversion #329

Open
ElGibbone wants to merge 1 commit from elgibbone/xma-bit-reader into main AGit
First-time contributor

What it changes

  • The problem on main: read from the code only. The XMA frame reader Bits (peek32, its tail path, read, signed, overread) and the helpers large_value, log2 and to_i16 had no direct tests; they were only reached through whole-frame decodes.

Adds five tests to crates/darner-formats/src/xma.rs, with no change outside the test module:

  • bit_reads_match_a_bit_by_bit_reader_up_to_and_past_the_end: every width from 0 to 32 bits, from every bit position up to a byte past a 23-byte buffer, against a one-bit-at-a-time reader (the 8-byte path, the tail path and zeros past the end), with consumed and overread checked on each read.
  • signed_reads_take_the_top_bit_as_the_sign: 6-bit reads as the step size uses them, and a 1-bit read.
  • large_values_read_8_16_24_or_31_bits_after_their_prefix: the four prefixes of ff_wma_get_large_val.
  • log2_is_the_floor_and_zero_counts_as_one.
  • samples_round_and_clamp_to_sixteen_bits: scale by 32768, round half away from zero, clamp, NaN to 0.

Checked that the tests catch real changes: with the tail path dropping its last byte, the two bit-reader tests fail (the existing XMA tests all still pass); overread as >=, a 32767 scale in to_i16 and 32 bits for the longest large value each fail their test.

How it was tested

  • Tested revision: d340f99 (on f3840d7)
  • Commands and results (macOS aarch64, toolchain 1.98.1):
    • cargo test -p darner-formats --locked: 92 passed, 0 failed, 7 ignored (88 and 7 on main)
    • cargo clippy -p darner-formats --all-targets --locked -- -D warnings, and with --all-features: clean
    • the same two with cargo xwin clippy --target x86_64-pc-windows-msvc: clean
    • cargo xtask policy: 555 files ok; git diff --check: clean
  • Changes a default: no
  • Gates run on that revision: the three on darner-formats only, on macOS, plus Windows-target clippy. Not --workspace, not on Windows.
  • Gameplay: not relevant (tests only).
  • Hardware dependence: none.
  • Coverage gaps: workspace-wide gates not run; not run on Windows.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
    Not run in the game: tests only, no behaviour change.
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: none found. #258 is the only open PR in darner-formats and changes texture.rs, not xma.rs. #248 is about the XMA worker in darner-hle, not this decoder.
  • Replaces or overlaps: none found
## What it changes - The problem on main: read from the code only. The XMA frame reader `Bits` (`peek32`, its tail path, `read`, `signed`, `overread`) and the helpers `large_value`, `log2` and `to_i16` had no direct tests; they were only reached through whole-frame decodes. Adds five tests to `crates/darner-formats/src/xma.rs`, with no change outside the test module: - `bit_reads_match_a_bit_by_bit_reader_up_to_and_past_the_end`: every width from 0 to 32 bits, from every bit position up to a byte past a 23-byte buffer, against a one-bit-at-a-time reader (the 8-byte path, the tail path and zeros past the end), with `consumed` and `overread` checked on each read. - `signed_reads_take_the_top_bit_as_the_sign`: 6-bit reads as the step size uses them, and a 1-bit read. - `large_values_read_8_16_24_or_31_bits_after_their_prefix`: the four prefixes of `ff_wma_get_large_val`. - `log2_is_the_floor_and_zero_counts_as_one`. - `samples_round_and_clamp_to_sixteen_bits`: scale by 32768, round half away from zero, clamp, NaN to 0. Checked that the tests catch real changes: with the tail path dropping its last byte, the two bit-reader tests fail (the existing XMA tests all still pass); `overread` as `>=`, a 32767 scale in `to_i16` and 32 bits for the longest large value each fail their test. ## How it was tested - Tested revision: d340f99 (on f3840d7) - Commands and results (macOS aarch64, toolchain 1.98.1): - `cargo test -p darner-formats --locked`: 92 passed, 0 failed, 7 ignored (88 and 7 on main) - `cargo clippy -p darner-formats --all-targets --locked -- -D warnings`, and with `--all-features`: clean - the same two with `cargo xwin clippy --target x86_64-pc-windows-msvc`: clean - `cargo xtask policy`: 555 files ok; `git diff --check`: clean - Changes a default: no - Gates run on that revision: the three on darner-formats only, on macOS, plus Windows-target clippy. Not `--workspace`, not on Windows. - Gameplay: not relevant (tests only). - Hardware dependence: none. - Coverage gaps: workspace-wide gates not run; not run on Windows. ## Checklist - [ ] I ran this change in the game, or say below why it can't be (docs, tests only). Not run in the game: tests only, no behaviour change. - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: none found. #258 is the only open PR in darner-formats and changes `texture.rs`, not `xma.rs`. #248 is about the XMA worker in darner-hle, not this decoder. - Replaces or overlaps: none found
The bit reader is checked against a bit-by-bit reader for every width from
0 to 32 bits at every position up to a byte past the data (the 8-byte path,
the tail path and zeros past the end), with overread set exactly when a
read passes the end. Signed reads, ff_wma_get_large_val's four prefixes,
log2 and to_i16's rounding, clamping and NaN are pinned too. Tests only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
First-time contributor

Independent Windows build, gate, and code-read review of d340f9909 (full head d340f990957bfc2f5742a7875a15b0fc931c3557, based on main f3840d73d3504c30218debfbc8795b9225447317). Not run in-game.

Environment

  • Windows 11 Pro 26H2 (build 26300.10075), Intel Core i9-14900K, NVIDIA RTX A2000 12GB (driver 621.47), Rust 1.98.1 (x86_64-pc-windows-msvc), MSVC 19.44.35230.

Measured results

  • Gate 1 (cargo clippy --workspace --all-targets --locked -- -D warnings): PASS.
  • Gate 2 (cargo clippy --workspace --all-targets --all-features --locked -- -D warnings): PASS.
  • cargo xtask policy: PASS (asset policy: 555 files ok).
  • cargo test -p darner-formats --locked: PASS (92 passed; 0 failed; 7 ignored; doc tests: 0).

Code-read audit

  • bit_reads_match_a_bit_by_bit_reader_up_to_and_past_the_end checks widths 0–32 at every position through and beyond a 23-byte buffer against an independent MSB-first reader, and separately checks consumed position and overread state. It exercises both peek32's 8-byte path and peek32_tail (crates/darner-formats/src/xma.rs:233-280, 2240-2274).
  • signed_reads_take_the_top_bit_as_the_sign pins negative, positive, minimum 6-bit, and 1-bit sign extension. large_values_read_8_16_24_or_31_bits_after_their_prefix covers all four prefix branches, including the 31-bit maximum and a high-bit payload, and checks consumed lengths (xma.rs:272-278, 417-428, 2276-2305).
  • log2_is_the_floor_and_zero_counts_as_one covers zero, powers of two, adjacent values, and the frame trim width; samples_round_and_clamp_to_sixteen_bits checks signed half-way rounding, saturation, infinities, and NaN against to_i16 (xma.rs:431-433, 1366, 2307-2337). The diff adds only tests and helpers inside the test module.

No blocking issue found; the new tests independently exercise the specified decoder helpers with synthetic data.

Verdict: PASS.

AI-assisted: yes (GitHub Copilot, Auto mode).

Independent Windows build, gate, and code-read review of `d340f9909` (full head `d340f990957bfc2f5742a7875a15b0fc931c3557`, based on `main` `f3840d73d3504c30218debfbc8795b9225447317`). Not run in-game. ### Environment - Windows 11 Pro 26H2 (build 26300.10075), Intel Core i9-14900K, NVIDIA RTX A2000 12GB (driver 621.47), Rust 1.98.1 (`x86_64-pc-windows-msvc`), MSVC 19.44.35230. ### Measured results - Gate 1 (`cargo clippy --workspace --all-targets --locked -- -D warnings`): **PASS**. - Gate 2 (`cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`): **PASS**. - `cargo xtask policy`: **PASS** (`asset policy: 555 files ok`). - `cargo test -p darner-formats --locked`: **PASS** (`92 passed; 0 failed; 7 ignored`; doc tests: 0). ### Code-read audit - `bit_reads_match_a_bit_by_bit_reader_up_to_and_past_the_end` checks widths 0–32 at every position through and beyond a 23-byte buffer against an independent MSB-first reader, and separately checks consumed position and overread state. It exercises both `peek32`'s 8-byte path and `peek32_tail` (`crates/darner-formats/src/xma.rs:233-280`, `2240-2274`). - `signed_reads_take_the_top_bit_as_the_sign` pins negative, positive, minimum 6-bit, and 1-bit sign extension. `large_values_read_8_16_24_or_31_bits_after_their_prefix` covers all four prefix branches, including the 31-bit maximum and a high-bit payload, and checks consumed lengths (`xma.rs:272-278`, `417-428`, `2276-2305`). - `log2_is_the_floor_and_zero_counts_as_one` covers zero, powers of two, adjacent values, and the frame trim width; `samples_round_and_clamp_to_sixteen_bits` checks signed half-way rounding, saturation, infinities, and NaN against `to_i16` (`xma.rs:431-433`, `1366`, `2307-2337`). The diff adds only tests and helpers inside the test module. No blocking issue found; the new tests independently exercise the specified decoder helpers with synthetic data. **Verdict: PASS.** AI-assisted: yes (GitHub Copilot, Auto mode).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/329/head:elgibbone/xma-bit-reader'
git switch 'elgibbone/xma-bit-reader'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'elgibbone/xma-bit-reader'
git switch 'elgibbone/xma-bit-reader'
git rebase 'main'
git switch 'main'
git merge --ff-only 'elgibbone/xma-bit-reader'
git switch 'elgibbone/xma-bit-reader'
git rebase 'main'
git switch 'main'
git merge --no-ff 'elgibbone/xma-bit-reader'
git switch 'main'
git merge --squash 'elgibbone/xma-bit-reader'
git switch 'main'
git merge --ff-only 'elgibbone/xma-bit-reader'
git switch 'main'
git merge 'elgibbone/xma-bit-reader'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
TrustNo1/Darner!329
No description provided.