Skip to main content

implement_memory_manager_tests

Macro implement_memory_manager_tests 

Source
macro_rules! implement_memory_manager_tests {
    ([$($attribute:tt)*], $manager:expr, capabilities = $supported:expr) => { ... };
    (@impl, [$($attribute:tt)*], $manager:expr, $capabilities_test:expr) => { ... };
    ($manager:expr) => { ... };
}
Expand description

Macro to implement all memory manager tests for a given ManagerTrait implementation.

This macro generates individual test functions for each test category, making it easy to integrate comprehensive memory manager testing into your test suite.

§Usage

ⓘ
use memory::implement_memory_manager_tests;

mod tests {
    use super::*;
    use memory::{Manager, ManagerTrait};
     
    struct MyAllocator;
    impl ManagerTrait for MyAllocator {
        // ... implementation ...
    }
     
    static ALLOCATOR: MyAllocator = MyAllocator;
     
    implement_memory_manager_tests! {
        Manager::new(&ALLOCATOR)
    }
}

This will generate individual #[test] functions for each test category:

  • test_basic_allocation
  • test_zero_sized_allocation
  • test_aligned_allocation
  • test_allocation_with_capabilities
  • test_deallocation
  • test_reallocation_grow
  • test_reallocation_shrink
  • test_reallocation_same_size
  • test_multiple_allocations
  • test_memory_statistics
  • test_page_size
  • test_cache_flush_operations
  • test_large_allocation
  • test_allocation_pattern

To verify a platform-specific capability set, pass the test attribute and expected flags as ([#[test]], manager, capabilities = flags). The attribute can also select a target-specific test harness.