Files
leleka/crates/cpu-kernels/src/tests.rs
T
Pavlo Ratushnyi c1e7c02d1e STRA-338 size-rest: cpu-kernels, cpu-sys, gguf, gptoss and quant-core within 400 lines per file
Oversize files before/after: gptoss 2 -> 0 (lib.rs 1788 into 14 modules, synthetic_model.rs 922 into topic modules),
cpu-sys 2 -> 0 (lib.rs 1007, simd.rs 1503 with its inline x86 module split by kernel family), gguf 2 -> 0,
cpu-kernels 1 -> 0, quant-core 1 -> 0 (iq2s_grid.rs reflowed four entries per line, entries unchanged).
Modules are named after what they hold; public paths are re-exported unchanged; unsafe blocks and SAFETY comments moved
verbatim (cpu-sys 70 -> 70).

Census prod/test (fn>30 / cx>10 / nesting>4 / wide lines): cpu-sys 19/16, 3/0, 2/0, 5/2 -> 11/16, 3/0, 2/0, 3/2;
gptoss 13/16, 6/4, 1/0, 1/7 -> 12/14, 6/4, 1/0, 1/8; gguf 6/5, 6/0, 0/0, 3/1 -> 6/3, 6/0, 0/0, 3/1;
cpu-kernels and quant-core unchanged. Test ids and outcomes unchanged (recorded in docs/architecture/size-split-rest.md).
2026-11-06 16:28:24 +01:00

40 lines
1.4 KiB
Rust

//! Unit tests of this crate (moved out of `lib.rs` by STRA-338; the test ids are unchanged).
use super::*;
#[test]
fn scalar_is_always_available_and_best_is_supported() {
assert!(Isa::Scalar.supported());
let best = Dispatch::best();
assert!(best.isa().supported());
assert!(Isa::ALL.iter().all(|isa| *isa <= best.isa() || !isa.supported()));
}
#[test]
fn requests_force_exactly_the_named_level_or_fail() {
assert_eq!(Dispatch::from_request(Some("scalar")).unwrap().isa(), Isa::Scalar);
assert_eq!(Dispatch::from_request(Some(" SCALAR ")).unwrap().isa(), Isa::Scalar);
assert_eq!(Dispatch::from_request(None).unwrap().isa(), Isa::detect_best());
assert_eq!(Dispatch::from_request(Some("")).unwrap().isa(), Isa::detect_best());
assert_eq!(
Dispatch::from_request(Some("avx9000")).unwrap_err(),
DispatchError::UnknownLevel("avx9000".into())
);
for isa in [Isa::Avx2, Isa::AvxVnni] {
let result = Dispatch::from_request(Some(isa.name()));
if isa.supported() {
assert_eq!(result.unwrap().isa(), isa);
} else {
assert_eq!(result.unwrap_err(), DispatchError::Unsupported(isa));
}
}
}
#[test]
fn names_round_trip() {
for isa in Isa::ALL {
assert_eq!(Isa::parse(isa.name()), Some(isa));
}
assert_eq!(Isa::parse("avxvnni"), Some(Isa::AvxVnni));
}