Skip to main content
Pigweed's logo Pigweed
code_xml
  1. Home
  2. Reference
  3. C/C++
  4. pw_allocator
  5. Implementation interfaces
  6. Testing and debugging
Loading...
Searching...
No Matches
Testing and debugging

Overview

Test utilities for allocator implementers.

These facilitate writing unit tests and fuzz tests for both concrete and forwarding allocator implementations. They are not intended to be used by module consumers.

Submodules

 FuzzTest support
 

Classes

class  pw::allocator::test::FaultInjectingAllocator
 
struct  pw::allocator::test::AllocationRequest
 Represents a request to allocate some memory. More...
 
struct  pw::allocator::test::DeallocationRequest
 Represents a request to free some allocated memory. More...
 
struct  pw::allocator::test::ReallocationRequest
 Represents a request to reallocate allocated memory with a new size. More...
 
class  pw::allocator::test::TestHarness
 
class  pw::allocator::test::AllocatorForTest< kBufferSize, BlockType_, MetricsType_ >
 A configurable allocator that can be used in unit tests. More...
 

Macros

#define PW_ALLOCATOR_FIA_FOREACH(fn)
 Applies the given macro to each pair of names.
 
#define PW_ALLOCATOR_ABSORB_SEMICOLON()   static_assert(true)
 
#define PW_ALLOCATOR_FIA_ACCESSOR(snake, Camel)
 
#define PW_ALLOCATOR_FIA_SET_TRUE(snake, Camel)   can_##snake##_ = true
 
#define PW_ALLOCATOR_FIA_SET_FALSE(snake, Camel)   can_##snake##_ = false
 
#define PW_ALLOCATOR_FIA_ENABLE(snake, Camel)
 
#define PW_ALLOCATOR_FIA_DISABLE(snake, Camel)
 
#define PW_ALLOCATOR_FIA_FIELD(snake, Camel)    bool PW_ALLOCATOR_FIA_SET_TRUE(snake, Camel)
 

Typedefs

using pw::allocator::test::Request = std::variant< AllocationRequest, DeallocationRequest, ReallocationRequest >
 

Functions

size_t pw::allocator::test::AlignmentFromLShift (size_t lshift, size_t size)
 
template<typename BlockType >
void pw::allocator::test::FreeAll (typename BlockType::Range range)
 Free all the blocks reachable by the given block. Useful for test cleanup.
 

Variables

constexpr pw::tokenizer::Token pw::allocator::test::kToken = PW_TOKENIZE_STRING("test")
 

Macro Definition Documentation

◆ PW_ALLOCATOR_FIA_ACCESSOR

#define PW_ALLOCATOR_FIA_ACCESSOR (   snake,
  Camel 
)
Value:
[[nodiscard]] constexpr bool can_##snake() const { return can_##snake##_; } \
PW_ALLOCATOR_ABSORB_SEMICOLON()

For a name pair like (foo_bar, FooBar), creates an accessor like: [[nodiscard]] constexpr bool can_foo_bar() const { return can_foo_bar_; }

◆ PW_ALLOCATOR_FIA_DISABLE

#define PW_ALLOCATOR_FIA_DISABLE (   snake,
  Camel 
)
Value:
void Disable##Camel() { PW_ALLOCATOR_FIA_SET_FALSE(snake, Camel); } \
PW_ALLOCATOR_ABSORB_SEMICOLON()
#define PW_ALLOCATOR_FIA_SET_FALSE(snake, Camel)
Definition: fault_injecting_allocator.h:49

For a name pair like (foo_bar, FooBar), creates a method like void DisableFooBar() { can_foo_bar_ = false; }

◆ PW_ALLOCATOR_FIA_ENABLE

#define PW_ALLOCATOR_FIA_ENABLE (   snake,
  Camel 
)
Value:
void Enable##Camel() { PW_ALLOCATOR_FIA_SET_TRUE(snake, Camel); } \
PW_ALLOCATOR_ABSORB_SEMICOLON()
#define PW_ALLOCATOR_FIA_SET_TRUE(snake, Camel)
Definition: fault_injecting_allocator.h:45

For a name pair like (foo_bar, FooBar), creates a method like void EnableFooBar() { can_foo_bar_ = true; }

◆ PW_ALLOCATOR_FIA_FIELD

#define PW_ALLOCATOR_FIA_FIELD (   snake,
  Camel 
)     bool PW_ALLOCATOR_FIA_SET_TRUE(snake, Camel)

For a name pair like (foo_bar, FooBar), creates a field like bool can_foo_bar_ = true

◆ PW_ALLOCATOR_FIA_FOREACH

#define PW_ALLOCATOR_FIA_FOREACH (   fn)
Value:
fn(allocate, Allocate); \
fn(resize, Resize); \
fn(reallocate, Reallocate); \
fn(get_capacity, GetCapacity); \
fn(get_allocated, GetAllocated); \
fn(measure_fragmentation, MeasureFragmentation); \
fn(get_requested_layout, GetRequestedLayout); \
fn(get_usable_layout, GetUsableLayout); \
fn(get_allocated_layout, GetAllocatedLayout); \
fn(recognize, Recognizes)

Applies the given macro to each pair of names.

◆ PW_ALLOCATOR_FIA_SET_FALSE

#define PW_ALLOCATOR_FIA_SET_FALSE (   snake,
  Camel 
)    can_##snake##_ = false

For a name pair like (foo_bar, FooBar) and a boolean value, creates statement like can_foo_bar_ = false

◆ PW_ALLOCATOR_FIA_SET_TRUE

#define PW_ALLOCATOR_FIA_SET_TRUE (   snake,
  Camel 
)    can_##snake##_ = true

For a name pair like (foo_bar, FooBar) and a boolean value, creates statement like can_foo_bar_ = true;

Function Documentation

◆ AlignmentFromLShift()

size_t pw::allocator::test::AlignmentFromLShift ( size_t  lshift,
size_t  size 
)

Helper function to produce a valid alignment for a given size from an arbitrary left shift amount.