Skip to content

armgit / uzu

Public Imported from GitHub
0

A high-performance inference engine for AI models

Switch tests to libtest-mimic for stable testing harness (#835)

uuuvn047c52d83aba
diff --git a/Cargo.lock b/Cargo.lock
index aec20e27b..a97926fb3 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1888,6 +1888,12 @@ version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d817e038c30374a4bcb22f94d0a8a0e216958d4c3dcde369b1439fec4bdda6e6"
+[[package]]
+name = "escape8259"
+version = "0.5.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5692dd7b5a1978a5aeb0ce83b7655c58ca8efdcb79d21036ea249da95afec2c6"
+
[[package]]
name = "etcetera"
version = "0.10.0"
@@ -3312,6 +3318,18 @@ dependencies = [
"libc",
]
+[[package]]
+name = "libtest-mimic"
+version = "0.8.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "14e6ba06f0ade6e504aff834d7c34298e5155c6baca353cc6a4aaff2f9fd7f33"
+dependencies = [
+ "anstream",
+ "anstyle",
+ "clap",
+ "escape8259",
+]
+
[[package]]
name = "line-clipping"
version = "0.3.7"
@@ -6518,7 +6536,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd"
dependencies = [
"fastrand",
- "getrandom 0.3.4",
+ "getrandom 0.4.3",
"once_cell",
"rustix",
"windows-sys 0.61.2",
@@ -7608,6 +7626,7 @@ dependencies = [
"itertools 0.14.0",
"keisoku",
"libm",
+ "libtest-mimic",
"monostate",
"mtl-rs",
"ndarray",
diff --git a/Cargo.toml b/Cargo.toml
index eb7967ca4..496b38499 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -125,6 +125,7 @@ rstest = "0.26"
wiremock = "0.6"
proptest = { version = "1.10", default-features = false, features = ["std"] }
criterion = { version = "0.8.2", default-features = false }
+libtest-mimic = "0.8.2"
indexmap = { version = "2.13.0", features = ["serde"] }
tracing = "0.1.44"
tracing-subscriber = { version = "0.3.22", features = ["env-filter"] }
diff --git a/crates/uzu-engine-macros/src/uzu_test.rs b/crates/uzu-engine-macros/src/uzu_test.rs
index 10523878e..a4dcb24d0 100644
--- a/crates/uzu-engine-macros/src/uzu_test.rs
+++ b/crates/uzu-engine-macros/src/uzu_test.rs
@@ -10,13 +10,9 @@ pub fn uzu_test(
let ignore_attr =
func.attrs.iter().position(|attr| attr.path().is_ident("ignore")).map(|index| func.attrs.remove(index));
- let (ignore, ignore_message) = match ignore_attr.as_ref().map(|attr| &attr.meta) {
- None => (quote! { false }, quote! { ::core::option::Option::None }),
- Some(Meta::Path(_)) => (quote! { true }, quote! { ::core::option::Option::None }),
- Some(Meta::NameValue(name_value)) => {
- let message = &name_value.value;
- (quote! { true }, quote! { ::core::option::Option::Some(#message) })
- },
+ let ignore = match ignore_attr.as_ref().map(|attr| &attr.meta) {
+ None => quote! { false },
+ Some(Meta::Path(_)) => quote! { true },
Some(meta) => {
return syn::Error::new_spanned(meta, "unsupported #[ignore] form").to_compile_error().into();
},
@@ -31,28 +27,14 @@ pub fn uzu_test(
#[test_case]
#[allow(non_upper_case_globals)]
const #const_name: crate::tests::harness::UzuTest =
- crate::tests::harness::UzuTest::Test(&crate::tests::harness::test::TestDescAndFn {
- desc: crate::tests::harness::test::TestDesc {
- name: crate::tests::harness::test::StaticTestName(concat!(
- module_path!(),
- "::",
- stringify!(#name),
- )),
- ignore: #ignore,
- ignore_message: #ignore_message,
- source_file: file!(),
- start_line: line!() as usize,
- start_col: column!() as usize,
- end_line: line!() as usize,
- end_col: column!() as usize,
- should_panic: crate::tests::harness::test::ShouldPanic::No,
- compile_fail: false,
- no_run: false,
- test_type: crate::tests::harness::test::TestType::Unknown,
- },
- testfn: crate::tests::harness::test::StaticTestFn(|| {
- crate::tests::harness::test::assert_test_result(#name())
- }),
+ crate::tests::harness::UzuTest::Test(&crate::tests::harness::UzuTestCase {
+ name: concat!(
+ module_path!(),
+ "::",
+ stringify!(#name),
+ ),
+ ignore: #ignore,
+ run: #name,
});
}
.into()
diff --git a/crates/uzu-engine/Cargo.toml b/crates/uzu-engine/Cargo.toml
index 0871a8a3f..a9c02a1a4 100644
--- a/crates/uzu-engine/Cargo.toml
+++ b/crates/uzu-engine/Cargo.toml
@@ -87,6 +87,7 @@ schemars = { workspace = true, optional = true }
test-tag.workspace = true
proptest.workspace = true
criterion.workspace = true
+libtest-mimic.workspace = true
rand.workspace = true
rand_distr.workspace = true
is_close.workspace = true
diff --git a/crates/uzu-engine/src/lib.rs b/crates/uzu-engine/src/lib.rs
index ee527db87..f29b0b540 100644
--- a/crates/uzu-engine/src/lib.rs
+++ b/crates/uzu-engine/src/lib.rs
@@ -1,4 +1,4 @@
-#![cfg_attr(test, feature(custom_test_frameworks, test))]
+#![cfg_attr(test, feature(custom_test_frameworks))]
#![cfg_attr(test, test_runner(crate::tests::harness::uzu_harness))]
#![cfg_attr(target_family = "wasm", feature(wasi_ext))]
diff --git a/crates/uzu-engine/unit/backends/common/kernel/attention/ancestor_attention_test.rs b/crates/uzu-engine/unit/backends/common/kernel/attention/ancestor_attention_test.rs
index f247f9755..704ab57c3 100644
--- a/crates/uzu-engine/unit/backends/common/kernel/attention/ancestor_attention_test.rs
+++ b/crates/uzu-engine/unit/backends/common/kernel/attention/ancestor_attention_test.rs
@@ -158,7 +158,7 @@ fn ancestor_attention_matches_cpu() {
}
#[uzu_test]
-#[ignore = "benchmark"]
+#[ignore]
fn benchmark_ancestor_attention() {
const BATCH: u32 = 32;
const SAMPLES: usize = 50;
diff --git a/crates/uzu-engine/unit/backends/common/kernel/gated_act_mul_test.rs b/crates/uzu-engine/unit/backends/common/kernel/gated_act_mul_test.rs
index 7d37bb5de..3f67aa1bf 100644
--- a/crates/uzu-engine/unit/backends/common/kernel/gated_act_mul_test.rs
+++ b/crates/uzu-engine/unit/backends/common/kernel/gated_act_mul_test.rs
@@ -98,7 +98,7 @@ fn interleaved_test<T: ArrayElement + Float + Debug + Display>(act_type: Activat
}
#[uzu_test]
-#[ignore = "flaky"] // TODO
+#[ignore] // TODO: flaky
fn test_gated_act_mul_interleaved_hadamard_bf16() {
let input = interleaved_input::<bf16>(ActivationType::SILU);
let expected = run_interleaved::<bf16, Cpu>(&input, true);
diff --git a/crates/uzu-engine/unit/backends/common/kernel/radix_top_k_small_test.rs b/crates/uzu-engine/unit/backends/common/kernel/radix_top_k_small_test.rs
index a03713951..7fd6c7d27 100644
--- a/crates/uzu-engine/unit/backends/common/kernel/radix_top_k_small_test.rs
+++ b/crates/uzu-engine/unit/backends/common/kernel/radix_top_k_small_test.rs
@@ -112,7 +112,7 @@ fn radix_top_k_small_matches_cpu() {
#[cfg(backend = "metal")]
#[uzu_test]
-#[ignore = "benchmark"]
+#[ignore]
fn benchmark_radix_top_k_small() {
const ROWS: usize = 15;
const SAMPLES: usize = 50;
diff --git a/crates/uzu-engine/unit/common/cold_pool.rs b/crates/uzu-engine/unit/common/cold_pool.rs
index 72efbf1da..55d082c9f 100644
--- a/crates/uzu-engine/unit/common/cold_pool.rs
+++ b/crates/uzu-engine/unit/common/cold_pool.rs
@@ -31,7 +31,7 @@ impl<T, F: FnMut() -> T> ColdPool<T, F> {
}
}
-pub(crate) fn copy_count(
+pub fn copy_count(
working_set: usize,
bytes_per_copy: usize,
) -> usize {
diff --git a/crates/uzu-engine/unit/common/harness.rs b/crates/uzu-engine/unit/common/harness.rs
index 7c1cf19a4..1aa1de161 100644
--- a/crates/uzu-engine/unit/common/harness.rs
+++ b/crates/uzu-engine/unit/common/harness.rs
@@ -1,11 +1,17 @@
-pub(crate) extern crate test;
+use libtest_mimic::{Arguments, Trial};
const METAL_CAPTURE_ENABLED: &str = "METAL_CAPTURE_ENABLED";
const UZU_CAPTURE_BENCH: &str = "UZU_CAPTURE_BENCH";
-pub(crate) enum UzuTest {
+pub enum UzuTest {
Bench(&'static dyn Fn()),
- Test(&'static test::TestDescAndFn),
+ Test(&'static UzuTestCase),
+}
+
+pub struct UzuTestCase {
+ pub name: &'static str,
+ pub ignore: bool,
+ pub run: fn(),
}
#[cfg(target_os = "ios")]
@@ -18,7 +24,7 @@ fn ios_set_current_dir() {
}
}
-pub(crate) fn uzu_harness(tests: &[&UzuTest]) {
+pub fn uzu_harness(tests: &[&UzuTest]) {
let args = std::env::args().collect::<Vec<String>>();
let benchmarks = args.contains(&"--bench".to_string());
if benchmarks {
@@ -34,14 +40,20 @@ pub(crate) fn uzu_harness(tests: &[&UzuTest]) {
.collect::<Vec<_>>();
criterion::runner(bench_tests.as_slice());
} else {
- let default_tests: Vec<&test::TestDescAndFn> = tests
+ let trials: Vec<Trial> = tests
.iter()
- .filter_map(|test| match test {
+ .filter_map(|test| match **test {
UzuTest::Bench(_) => None,
- UzuTest::Test(test) => Some(*test),
+ UzuTest::Test(case) => Some(
+ Trial::test(case.name, move || {
+ (case.run)();
+ Ok(())
+ })
+ .with_ignored_flag(case.ignore),
+ ),
})
- .collect::<Vec<_>>();
- test::test_main_static(&default_tests)
+ .collect();
+ libtest_mimic::run(&Arguments::from_args(), trials).exit();
}
}
diff --git a/crates/uzu-engine/unit/common/matmul/quant.rs b/crates/uzu-engine/unit/common/matmul/quant.rs
index b0772b60e..97ee49263 100644
--- a/crates/uzu-engine/unit/common/matmul/quant.rs
+++ b/crates/uzu-engine/unit/common/matmul/quant.rs
@@ -160,7 +160,7 @@ impl<T: ArrayElement + Float> QuantInput<T> {
self
}
- pub(crate) fn weights_for_upload(&self) -> Vec<u32> {
+ pub fn weights_for_upload(&self) -> Vec<u32> {
let mut words = self.w_packed.clone();
let sign_flip_mask = self.signed_codes.then(|| self.mode.weight_codes_sign_flip_mask()).flatten();
if let Some(mask) = sign_flip_mask {
@@ -170,7 +170,7 @@ impl<T: ArrayElement + Float> QuantInput<T> {
words
}
- pub(crate) fn weight_buffer_bytes(&self) -> usize {
+ pub fn weight_buffer_bytes(&self) -> usize {
size_of_val(self.w_packed.as_slice())
+ size_of_val(self.scales.as_slice())
+ self.biases.as_ref().map_or(0, |biases| size_of_val(biases.as_slice()))
diff --git a/crates/uzu-engine/unit/common/mod.rs b/crates/uzu-engine/unit/common/mod.rs
index f694058ce..dfa417228 100644
--- a/crates/uzu-engine/unit/common/mod.rs
+++ b/crates/uzu-engine/unit/common/mod.rs
@@ -1,8 +1,6 @@
#[cfg(not(backend = "cpu"))]
compile_error!("uzu tests require cpu backend");
-pub extern crate test;
-
pub mod assert;
pub mod cold_pool;
pub mod env_vars;