Expand description
Conformance helpers for downstream impls of FixedRange and
Allocator.
Drop these into a #[test] to validate that a custom
implementation meets the trait contracts that wrappers in the
forge-alloc family rely on. Helpers panic on failure with a
human-readable diagnostic, so they compose with the standard
#[test] harness without ceremony.
§Example
ⓘ
use forge_alloc_core::testing::{
assert_allocator_basic_round_trip,
assert_fixed_range_invariants,
};
#[test]
fn my_allocator_meets_contract() {
let a = MyAllocator::new(4096);
assert_fixed_range_invariants(&a);
assert_allocator_basic_round_trip(&a);
}These helpers cover the structural and basic behavioral
parts of the contract — pointer non-null-ness, alignment,
non-overlap, address-range stability, single-threaded
write-then-read round-trip, contains membership for issued
pointers. They do NOT cover:
- Concurrent-access invariants (Inv 3 — “allocator doesn’t concurrently write user-visible bytes”). Verifying that requires a multi-threaded probe with a happens-before discipline, which is allocator-specific.
grow/shrinksemantics (Inv 5). Add helpers for these as they’re needed.- Statistical / performance properties (no benchmarking) or hardening-specific behavior (no MAC verification, no canary checks). Use crate-specific tests for those.
On failure, helpers panic at the call site (each is
#[track_caller]) so the test report points at your test, not
at this file.
Functions§
- assert_
allocator_ basic_ round_ trip - Verify the basic round-trip invariants of
Allocator: - assert_
allocator_ respects_ alignment - Verify that
allocatereturns pointers aligned to the requested alignment, across every power-of-two alignment from1to512. (Covers up throughCACHE_LINE= 128on every supported target plus a 4-KiB-page-aligned slot.) - assert_
combined_ invariants - Verify that an allocator implements both
FixedRangeandAllocatorconsistently: - assert_
fixed_ range_ invariants - Verify the structural invariants of
FixedRange: