Skip to main content

codegen_tests

Macro codegen_tests 

Source
macro_rules! codegen_tests {
    () => { ... };
    ($(#[$meta:meta])* fn $name:ident($config:ident) $body:block $($rest:tt)*) => { ... };
    (#[proptest_config($($pc:tt)*)] $(#[$meta:meta])* fn $name:ident($config:ident, $($param:ident in $strategy:expr),+ $(,)?) $body:block $($rest:tt)*) => { ... };
    ($(#[$meta:meta])* fn $name:ident($config:ident, $($param:ident in $strategy:expr),+ $(,)?) $body:block $($rest:tt)*) => { ... };
    (@proptest $name:ident, $config:ident, [$($param:ident in $strategy:expr),+], $body:block, $runner:expr, [$(#[$meta:meta])*]) => { ... };
    ($(#[$meta:meta])* fn $name:ident($config:ident, $($param:ident: $ty:ty),+ $(,)?) $body:block $($rest:tt)*) => { ... };
}
Expand description

Generate one test per codegen backend (Clang, LLVM) from a single test body.

Supports three forms:

Simple test (config only, no extra params):

codegen_tests! {
    fn test_add(config) {
        let mut a = Tensor::from_slice([1.0f32, 2.0, 3.0]);
        a.realize_with(&config).unwrap();
        let result: Vec<f32> = a.as_vec().unwrap();
    }
}
// Generates: test_add::clang, test_add::llvm

Parameterized test (extra typed params, use with #[test_case]):

codegen_tests! {
    #[test_case(128, 0.5; "128x128")]
    fn test_matmul(config, size: usize, tol: f32) {
        let mut result = run_matmul(size);
        result.realize_with(&config).unwrap();
        assert_close(&result, tol);
    }
}
// Generates: test_matmul::clang::test_matmul, test_matmul::llvm::test_matmul

Proptest (property-based, params use in syntax):

codegen_tests! {
    #[proptest_config(ProptestConfig::with_cases(50))]
    fn test_sort_random(config, data in proptest::collection::vec(-100.0f32..100.0, 1..=16)) {
        let mut t = Tensor::from_slice(&data);
        let (sorted, _) = t.sort(-1, false).unwrap();
        // ...
    }
}
// Generates: test_sort_random::clang, test_sort_random::llvm