Files
leleka/crates/cpu-sys/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

45 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_matches_a_hand_computed_value() {
assert_eq!(dot_i8i8_scalar(&[1, -2, 3], &[4, 5, -6]), Ok(4 - 10 - 18));
// nibbles 0x0..0xF in byte pairs: values (n - 8): byte 0x10 -> low 0 => -8, high 1 => -7
assert_eq!(dot_i4i8_scalar(&[0x10], &[1, 1]), Ok(-8 - 7));
// odd length reads only the low nibble of the last byte
assert_eq!(dot_i4i8_scalar(&[0xF8], &[2]), Ok(0));
}
#[test]
fn length_and_size_errors_are_refused_before_any_read() {
assert_eq!(dot_i8i8_scalar(&[1], &[1, 2]), Err(KernelError::LengthMismatch));
assert_eq!(
dot_i4i8_scalar(&[0, 0], &[1, 2, 3, 4, 5]),
Err(KernelError::LengthMismatch)
);
let big = vec![0i8; MAX_DOT_LEN + 1];
assert_eq!(dot_i8i8_scalar(&big, &big), Err(KernelError::TooLong));
}
#[cfg(target_arch = "x86_64")]
#[test]
fn simd_wrappers_refuse_bad_lengths_before_touching_memory() {
if !avx2_available() {
return;
}
assert_eq!(dot_i8i8_avx2(&[1], &[1, 2]), Err(KernelError::LengthMismatch));
assert_eq!(
dot_mxfp4_q8_0_avx2(&[0; 16], &[0; 34]),
Err(KernelError::LengthMismatch)
);
assert_eq!(
dot_mxfp4_q8r4_avx2(&[0; 17], &[1.0], &[0; 31]),
Err(KernelError::LengthMismatch)
);
assert_eq!(
quantize_q8_0_avx2(&[0.0; 31], &mut [0; 34]),
Err(KernelError::LengthMismatch)
);
}