Expand description
Test template for ManagerTrait implementations.
This module provides a comprehensive test suite that can be used to validate
any implementation of the ManagerTrait. The tests cover all the core functionality
including allocation, deallocation, reallocation, and cache management.
§Usage
§Using the Macro (Recommended)
The easiest way to test your memory manager implementation is to use the
implement_memory_manager_tests! macro, which generates individual test
functions for each test category:
ⓘ
use memory::implement_memory_manager_tests;
#[cfg(test)]
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 14 individual #[test] functions, each testing a specific
aspect of your memory manager implementation.
§Using Individual Test Functions
You can also call individual test functions directly:
ⓘ
use memory::{Manager, test_template};
#[cfg(test)]
mod tests {
use super::*;
fn get_test_manager() -> Manager<'static> {
static ALLOCATOR: YourAllocatorType = YourAllocatorType::new();
Manager::new(&ALLOCATOR)
}
#[test]
fn test_basic_allocation() {
let manager = get_test_manager();
test_template::test_basic_allocation($manager);
}
#[test]
fn test_all() {
let manager = get_test_manager();
test_template::run_all_tests($manager);
}
}§Test Categories
§Basic Allocation Tests
test_basic_allocation- Basic allocation and deallocationtest_zero_sized_allocation- Zero-size allocation handlingtest_aligned_allocation- Various alignment requirementstest_allocation_with_capabilities- Capability-based allocation
§Deallocation & Reallocation Tests
test_deallocation- Memory deallocation and usage trackingtest_reallocation_grow- Growing allocationstest_reallocation_shrink- Shrinking allocationstest_reallocation_same_size- Same-size reallocation
§Complex Operations Tests
test_multiple_allocations- Multiple simultaneous allocationstest_allocation_pattern- Complex allocation/deallocation patternstest_large_allocation- Large memory allocations
§Manager Features Tests
test_memory_statistics- Memory usage statisticstest_page_size- Page size reportingtest_cache_flush_operations- Cache management operations
Functions§
- test_
aligned_ allocation - Tests allocation with specific alignment requirements.
- test_
allocation_ pattern - Tests allocation and deallocation pattern.
- test_
allocation_ with_ capabilities - Tests allocation with different capability flags.
- test_
basic_ allocation - Tests basic memory allocation.
- test_
cache_ flush_ operations - Tests cache flush operations.
- test_
deallocation - Tests memory deallocation.
- test_
large_ allocation - Tests large memory allocation.
- test_
memory_ statistics - Tests memory usage statistics.
- test_
multiple_ allocations - Tests multiple simultaneous allocations.
- test_
page_ size - Tests the page size reporting.
- test_
reallocation_ grow - Tests memory reallocation to a larger size.
- test_
reallocation_ same_ size - Tests reallocation with the same size.
- test_
reallocation_ shrink - Tests memory reallocation to a smaller size.
- test_
zero_ sized_ allocation - Tests zero-sized allocation behavior.