Compare commits

..
Author SHA1 Message Date
Swastickc b9372408c8 qa: measure CPU test runtime and add deterministic test-target shards (#159)
Add scripts/cpu-tests.sh, which lists the default-feature workspace test
targets, runs shard K of N of them in a fixed round-robin order, and checks
that N shards cover every target exactly once. It fails when Cargo cannot
build the workspace instead of running a partial list. The full gate
(cargo test --locked --workspace) and scripts/test-gpu.sh are unchanged.

Record the measured gate cost and the selected-versus-full comparison in
docs/testing/cpu-coverage.md, index it in docs/README.md, and add a
changelog entry.

Signed-off-by: Swastickc <28708247+Swastickc@users.noreply.github.com>
2026-11-24 23:11:18 +05:30
6 changed files with 223 additions and 35 deletions

No files matched your search

+6 -1
View File
@@ -18,6 +18,12 @@ remains unsupported.
### Added
- Added the VOP3A (`_e64`) encodings of eleven gfx1030 VOP2 integer forms (`v_mul_{i32_i24,hi_i32_i24,u32_u24,hi_u32_u24}`, `v_{min,max}_{i32,u32}`, `v_xnor_b32`, `v_sub_nc_u32`, `v_subrev_nc_u32`) and of the sixteen Wave32 integer compares (explicit SGPR mask destination, `s_cbranch_vccz` through `vcc_lo`, a translation error for reads of runtime-only SGPR results) as semantic-registry encoding variants, with VGPR sources only. New fixtures `vop3-integer` and `vop3-compare` with IR and MSL goldens, and an independent guide-derived oracle (`tests/validation/tests/vop3_{integer,compare}.rs`) that agrees on both reference interpreters and on native Metal. Part of #215.
- Added `scripts/cpu-tests.sh`, which lists the default-feature workspace test targets and runs
deterministic shards of them (`--shard K/N`), with `--check N` showing every target lands in
exactly one shard. It does not replace `cargo test --locked --workspace` or
`scripts/test-gpu.sh`. `docs/testing/cpu-coverage.md` records local CPU gate timings on one
Apple M4 host (about 40 s wall time; one loader target takes about 19 s) and shows that the 2- and
3-shard unions match the full gate's 681 passed and 34 ignored tests (#159).
- Added guest texture binding through D3D12-style descriptor tables (#303): shader-visible CBV_SRV_UAV and sampler heaps, `CreateShaderResourceView` for one-level RGBA8 and BC1 2D textures, a point/clamp `CreateSampler`, a root signature with one pixel-stage SRV table and one sampler table, and `SetDescriptorHeaps`/`SetGraphicsRootDescriptorTable` in `crates/loader/src/graphics.rs`, plus `NativeCompute::render_rgba8_sampled_bc1`. Verified locally on an Apple M5 Pro under Metal validation: a guest draw with the translated `image_sample_lz` pixel stage matches the software reference and hand-derived images on 16 of 16 pixels for two RGBA8 textures and 64 of 64 for an 8×8 BC1 texture. A wrong descriptor slot changes the image, off-centre and out-of-range coordinates point-sample with clamping, and a rejected binding, draw shape or resource state never reaches the backend. The software reference samples BC1 with the spec-exact decoder, while Apple's hardware rounds BC1's interpolated palette entries differently (171/84 against 170/85), so the BC1 fixtures use only endpoint colours. Not yet reachable from guest imports. Not yet independently accepted.
- Added four Wave32 gfx1030 VOP2 select and carry forms through the semantic registry. Conditional select, add with carry and both subtract orders with borrow use a per-lane VCC bit and have a guide-derived oracle that passes on both CPU interpreters and on native Metal (local Apple M5, API and shader validation); independent acceptance is pending. Part of #215.
- Added decoding and Metal shader translation for twelve Wave32 VOPC 16-bit integer compares (#215). The signed and unsigned forms compare the low 16 bits of each source and write the Wave32 VCC mask. CPU verification covers 1,572 compiler acceptance cases and 408 rejections from the guide-derived oracle, which also passes on native Metal (1,572 cases in 1,420 programs on a local Apple M5 under API and shader validation); acceptance is pending.
@@ -188,7 +194,6 @@ remains unsupported.
### Fixed
- Made the static probe and the binder share one bounded import parser, after the truncated-name fix for #270. Truncated, unterminated, empty or non-ASCII names, reserved bits and endless tables are reported by the probe and refused by the binder.
- Fixed the decoder refusing an instruction whose REX prefix is followed by a legacy prefix (#69). Such a REX is ignored, as the Intel SDM (Vol. 2A, 2.2.1) specifies, so `48 66 01 D8` now runs as `add ax, bx`; it used to stop the guest with an illegal-instruction exit. The ignored byte still counts toward the instruction's length, and a REX that directly precedes the opcode behaves as before. The interpreter, the DBT and the static probe share the decoder. One SDM-derived case in `cpu_known_answers.rs` moved from refused to verified and three were added, for an ignored REX.B, an ignored REX.W before a segment prefix, and a later REX that does apply. Two REX bytes in a row and the address-size prefix stay rejected. Not compared with x86 hardware; awaiting independent review.
- Fixed import binding writing some slots before finding an unresolved import, and service calls taking effect before an unreadable return address was noticed. A service that changes a nonvolatile register, including XMM6 to XMM15, now stops the guest (part of #201).
- Fixed older import-generator templates that reported success for unimplemented wrappers, used a nonexistent exit reason, and read floating-point arguments from integer registers.
- Fixed guest flags in the native DBT (#64, #70). They lived only in host NZCV, so they were lost across helper calls and block boundaries and register ADD, SUB and XOR set none. JB, JAE, JBE and JA used ARM carry polarity, which is inverted for subtraction. Flags are now stored in the guest state.
+4 -22
View File
@@ -237,15 +237,6 @@ impl<E, F: FnMut(u64) -> Result<u8, E>> Cursor<F> {
}
}
/// Whether `byte` is a legacy prefix: an operand-size, address-size, segment,
/// LOCK or repeat prefix (Intel SDM Vol. 2A, 2.1.1).
fn is_legacy_prefix(byte: u8) -> bool {
matches!(
byte,
0x26 | 0x2E | 0x36 | 0x3E | 0x64 | 0x65 | 0x66 | 0x67 | 0xF0 | 0xF2 | 0xF3
)
}
/// Decode one instruction at `rip`. `fetch` supplies the byte at an address and
/// is called only for bytes that belong to the instruction, in order.
///
@@ -267,22 +258,9 @@ pub fn decode<E>(
let mut repne = false;
let mut lock = false;
let mut segment = None;
let mut rex = 0;
let mut byte = cursor.u8()?;
loop {
let selected = match byte {
// REX applies only immediately before the opcode. One that is
// followed by a legacy prefix is ignored (Intel SDM Vol. 2A, 2.2.1).
0x40..=0x4F => {
let next = cursor.u8()?;
if !is_legacy_prefix(next) {
rex = byte;
byte = next;
break;
}
byte = next;
continue;
}
0x64 => Segment::Fs,
0x65 => Segment::Gs,
0x66 => {
@@ -321,6 +299,10 @@ pub fn decode<E>(
byte = cursor.u8()?;
}
let rex = if byte & 0xF0 == 0x40 { byte } else { 0 };
if rex != 0 {
byte = cursor.u8()?;
}
let (rex_w, rex_r, rex_x, rex_b) =
(rex & 8 != 0, (rex & 4) << 1, (rex & 2) << 2, (rex & 1) << 3);
+1 -12
View File
@@ -1307,18 +1307,6 @@ addr32_sum_wraps_at_32_bits: rbx=ffff0000 rcx=10000+D rax=0 m0=44332211 => rax=1
486601d8
SDM 2A 2.2.1
rex_not_adjacent_to_opcode_is_ignored: rax=112233445566ffff rbx=1 => rax=1122334455660000 f=CPAZso
@ .byte 0x41,0x66,0x01,0xd8
416601d8
SDM 2A 2.2.1
ignored_rex_b_does_not_select_r8: rax=112233445566ffff rbx=1 r8=5 => rax=1122334455660000 f=CPAZso
@ .byte 0x48,0x64,0x8b,0x03
48648b03
SDM 2A 2.2.1; 1 3.4.1.1
ignored_rex_w_before_segment_prefix_loads_32_bits: rax=ffffffffffffffff rbx=8 fs8=1122334455667788 => rax=44332211 f=*
@ .byte 0x41,0x66,0x41,0x01,0xd8
41664101d8
SDM 2A 2.2.1
rex_after_ignored_rex_applies: rax=7 rbx=1 r8=112233445566ffff => r8=1122334455660000 f=CPAZso
@ .byte 0x66,0x48,0x01,0xd8
664801d8
SDM 2A 2.2.1.2
@@ -2758,6 +2746,7 @@ const UNSUPPORTED: &[(&str, usize)] = &[
("repne_scasb_finds_byte", 1),
("repne_scasb_finds_byte_df_clear", 0),
("repne_scasd_exhausts_count", 1),
("rex_not_adjacent_to_opcode_is_ignored", 0),
("roundps_uses_mxcsr_rc", 0),
("roundsd_suppress_precision", 0),
("roundss_imm_modes", 0),
+1
View File
@@ -41,6 +41,7 @@ either path. The [changelog](../CHANGELOG.md) records notable changes.
## Testing, validation, and benchmarks
- [Engineering progress](progress.md) — Verification commands, metric definitions, and open release gates.
- [CPU test runtime and shard selection](testing/cpu-coverage.md) — Measured CPU gate cost and deterministic test-target shards.
- [Test inventory comparison](testing/test-inventory.md) — Detect missing or newly ignored Cargo tests across commits.
- [Persistent resource and translated rendering acceptance](testing/x9-acceptance.md) — Pinned upstream tests, native ARM64 results and unsupported cases.
- [Baseline acceptance](testing/phase-02-baseline.md), [Phase 01 assurance](testing/phase01-assurance.md), and [independent reviews](testing/review-log.md) — Candidate-specific results and release findings.
+98
View File
@@ -0,0 +1,98 @@
# CPU test runtime and shard selection
This page records what the CPU test gate costs and describes
`scripts/cpu-tests.sh`, which splits that gate into deterministic shards. The
shards are a convenience for local iteration and parallel runners. They do not
replace any gate: `cargo test --locked --workspace` stays the full CPU gate, and
`scripts/test-gpu.sh` stays the GPU gate.
## What counts as a CPU test
A CPU test is any test target that `cargo test --locked --workspace` builds with
default features. Targets that need a Metal device are either behind the
`gpu-tests` feature (`xenora-metal`, `xenora-loader`, `xenora-ffi`) or marked
`#[ignore = "requires a native Metal device ..."]` (for example
`tests/validation/known_answers.rs`), so the default run does not execute them.
`scripts/test-gpu.sh` runs them. The selection uses Cargo's own target list, so
it never decides by file name which tests are CPU tests.
One exception: two `xenora-ffi` library tests
(`test_resource_management_lifecycle_and_validation` and
`test_deferred_resource_retirement_waits_for_in_flight`) call
`xenora_session_create_texture`. When a Metal device is available, that
function creates one and uploads a texture; when none is available, it
continues without one. So on a Mac these default tests do touch Metal, and they
are not GPU verification. The selection keeps them because the full gate runs
them.
## Usage
```sh
scripts/cpu-tests.sh --list # every default-feature test target, sorted
scripts/cpu-tests.sh --shard 2/3 # run shard 2 of 3
scripts/cpu-tests.sh --check 3 # show that 3 shards cover every target once
```
Targets are sorted by package, kind and name. Shard K of N takes each target
whose zero-based index i satisfies i mod N = K - 1. Shard 1 also runs the
workspace doctests. A new target joins a shard without any edit to the script.
The script exits 1 when any selected target fails or when Cargo cannot build the
workspace. Partial target lists never run. It exits 2 on bad arguments.
It uses at most four Cargo build jobs unless `CARGO_BUILD_JOBS` says otherwise.
## Measurements
Host: Apple M4 (10 cores), macOS on ARM64, `cargo 1.100.0`, target
`aarch64-apple-darwin`, debug test profile, main at `d7f7d58`. All runs used a
warm build unless noted. These are single-host samples, not benchmarks.
Full gate, `cargo test --locked --workspace`, three runs: 40.47 s, 39.99 s and
40.12 s wall time. It ran 82 test targets plus doctests (92 `test result` lines):
681 passed, 0 failed, 34 ignored.
Running each target alone through `cargo test -p <package> <selector>` adds up
to 79.5 s, because every invocation pays Cargo start-up. The five most expensive
targets, one sample each:
| Target | Wall time | Passed / ignored |
| --- | --- | --- |
| `xenora-loader --test runtime_services` | 19.13 s | 23 / 0 |
| `xenora-loader --test cpu_known_answers` | 8.18 s | 42 / 5 |
| `xenora-loader --test probe_delay_imports` | 3.53 s | 8 / 0 |
| `xenora-loader --test probe_truncation` | 3.32 s | 1 / 0 |
| `xenora-ffi --lib` | 2.16 s | 18 / 0 |
`runtime_services` alone is about a quarter of the summed cost. Any shard that
contains it takes at least about 19 s. The next step for a faster gate is
profiling that target, not finer sharding.
Shard runs, one sample each, sequential on the same host:
| Selection | Wall time per shard | Passed | Failed | Ignored | Result lines |
| --- | --- | --- | --- | --- | --- |
| 2 shards | 37.98 s, 4.55 s | 360 + 321 = 681 | 0 | 21 + 13 = 34 | 51 + 41 = 92 |
| 3 shards | 6.54 s, 29.55 s, 6.27 s | 160 + 282 + 239 = 681 | 0 | 9 + 12 + 13 = 34 | 38 + 27 + 27 = 92 |
For both shard counts, the union of the shards matches the full gate exactly
in passed, failed, ignored and result-line counts. Round-robin by name does
not balance cost: with one dominant target, parallel shards finish no sooner
than the shard that holds it. Running the shards one after another costs more
than the full gate, because each target pays Cargo start-up.
## Verification of the script
- `--check N` for N = 1 to 4 reports that all 82 targets are covered once.
- `--check 3` fails when the selection expression is changed to skip a
residue or to repeat a target.
- `--list` exits 1 with an error when a crate fails to compile, instead of
printing a shortened list.
- Bad arguments (`--shard 0/2`, `--shard 3/2`, `--check x`) exit 2.
## Limitations
- Timings come from one machine and few samples. Re-measure before using them
for decisions.
- Shard membership changes when targets are added or renamed. Shards from two
different commits are not comparable.
- The experiment workspace `experiments/x1` is outside the selection. CI runs
it separately.
+113
View File
@@ -0,0 +1,113 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-3.0-or-later
#
# Deterministic CPU-only selection of the workspace test targets (#159).
#
# scripts/cpu-tests.sh --list print every default-feature test target
# scripts/cpu-tests.sh --shard K/N run shard K of N (1 <= K <= N)
# scripts/cpu-tests.sh --check N prove N shards cover every target once
#
# Targets are the ones `cargo test --locked --workspace` builds with default
# features, sorted by package, kind and name. Shard K takes every target whose
# index i in that order has i mod N == K - 1; shard 1 also runs the doctests.
# New targets join a shard automatically. The selection never replaces the full
# gate, `cargo test --locked --workspace`; `gpu-tests` targets stay in
# scripts/test-gpu.sh.
set -eu
cd "$(dirname "$0")/.."
export CARGO_BUILD_JOBS=${CARGO_BUILD_JOBS:-4}
usage() {
echo "usage: $0 --list | --shard K/N | --check N" >&2
exit 2
}
# Prints "package selector..." for each test target, one per line, sorted.
# Fails when Cargo cannot build every target, so a partial list never runs.
targets() {
json=$(cargo test --locked --workspace --no-run --message-format=json) || {
echo "cpu-tests: cargo could not build the workspace test targets" >&2
exit 1
}
printf '%s\n' "$json" | python3 -c '
import json, sys
rows = set()
for line in sys.stdin:
m = json.loads(line)
if m.get("reason") != "compiler-artifact" or not m.get("executable"):
continue
if not m["profile"]["test"]:
continue
pkg = m["package_id"].split("#")[-1].split("@")[0]
kind, name = m["target"]["kind"][0], m["target"]["name"]
sel = {"test": "--test " + name, "bin": "--bin " + name}.get(kind, "--lib")
rows.add(f"{pkg} {sel}")
if not rows:
sys.exit("cpu-tests: no test targets found; does the workspace build?")
print("\n".join(sorted(rows)))
'
}
# Keeps the lines of stdin that belong to shard $1 of $2.
select_shard() {
awk -v k="$1" -v n="$2" '(NR - 1) % n == k - 1'
}
parse_count() {
case $1 in '' | *[!0-9]*) usage ;; esac
[ "$1" -ge 1 ] || usage
}
[ $# -ge 1 ] || usage
case $1 in
--list)
[ $# -eq 1 ] || usage
targets
;;
--check)
[ $# -eq 2 ] || usage
parse_count "$2"
all=$(targets)
total=$(printf '%s\n' "$all" | wc -l | tr -d ' ')
union=$(k=1; while [ "$k" -le "$2" ]; do
printf '%s\n' "$all" | select_shard "$k" "$2"
k=$((k + 1))
done)
if [ "$(printf '%s\n' "$union" | sort)" != "$(printf '%s\n' "$all" | sort)" ]; then
echo "cpu-tests: $2 shards do not cover the $total targets exactly once" >&2
exit 1
fi
echo "cpu-tests: $2 shards cover all $total targets exactly once"
;;
--shard)
[ $# -eq 2 ] || usage
k=${2%/*}
n=${2#*/}
[ "$k/$n" = "$2" ] || usage
parse_count "$k"
parse_count "$n"
[ "$k" -le "$n" ] || usage
all=$(targets)
selected=$(printf '%s\n' "$all" | select_shard "$k" "$n")
failed=0
# Word splitting of $line is intended: it holds "package --test name".
while IFS= read -r line; do
[ -n "$line" ] || continue
echo "cpu-tests[$k/$n]: cargo test --locked -p $line"
# shellcheck disable=SC2086
cargo test --locked -p $line || failed=$((failed + 1))
done <<EOF
$selected
EOF
if [ "$k" -eq 1 ]; then
echo "cpu-tests[$k/$n]: cargo test --locked --workspace --doc"
cargo test --locked --workspace --doc || failed=$((failed + 1))
fi
if [ "$failed" -ne 0 ]; then
echo "cpu-tests[$k/$n]: $failed target(s) failed" >&2
exit 1
fi
echo "cpu-tests[$k/$n]: all selected targets passed"
;;
*) usage ;;
esac