Pigweed
Loading...
Searching...
No Matches
pw::allocator::test::TestHarnessGeneric Class Referenceabstract

#include <test_harness.h>

Classes

struct  Allocation
 Associates a pointer to memory with the Layout used to allocate it. More...
 

Public Member Functions

virtual ~TestHarnessGeneric ()=default
 
void GenerateRequests (random::RandomGenerator &prng, size_t max_size, size_t num_requests)
 
void GenerateRequest (random::RandomGenerator &prng, size_t max_size)
 
void HandleRequests (const Vector< Request > &requests)
 
void HandleRequest (const Request &request)
 
void Reset ()
 Deallocates any pointers stored in the vector of allocated pointers.
 

Protected Member Functions

constexpr TestHarnessGeneric (Vector< Allocation > &allocations)
 

Detailed Description

Associates an Allocator with a vector to store allocated pointers.

This class facilitates performing allocations from generated Requests, enabling the creation of performance, stress, and fuzz tests for various allocators.

This class lacks a public constructor, and so cannot be used directly. Instead callers should use WithAllocations, which is templated on the size of the vector used to store allocated pointers.

Constructor & Destructor Documentation

◆ ~TestHarnessGeneric()

virtual pw::allocator::test::TestHarnessGeneric::~TestHarnessGeneric ( )
virtualdefault

Since this object has references passed to it that are typically owned by an object of a derived type, the destructor MUST NOT touch those references. Instead, it is the callers and/or the derived classes responsibility to call Reset before the object is destroyed, if desired.

Member Function Documentation

◆ GenerateRequest()

void pw::allocator::test::TestHarnessGeneric::GenerateRequest ( random::RandomGenerator prng,
size_t  max_size 
)

Generate and handle an allocation requests.

This method will use the given PRNG to generate an allocation request and pass it to HandleRequest. Callers MUST call Reset when no more requests remain to be generated.

◆ GenerateRequests()

void pw::allocator::test::TestHarnessGeneric::GenerateRequests ( random::RandomGenerator prng,
size_t  max_size,
size_t  num_requests 
)

Generates and handles a sequence of allocation requests.

This method will use the given PRNG to generate num_requests allocation requests and pass each in turn to HandleRequest. It will call Reset before returning.

◆ HandleRequest()

void pw::allocator::test::TestHarnessGeneric::HandleRequest ( const Request &  request)

Handles an allocator request.

This method is stateful, and modifies the vector of allocated pointers. It will call Init if it has not yet been called.

If the request is an allocation request:

  • If the vector of previous allocations is full, ignores the request.
  • Otherwise, allocates memory and stores the pointer in the vector.

If the request is a deallocation request:

  • If the vector of previous allocations is empty, ignores the request.
  • Otherwise, removes a pointer from the vector and deallocates it.

If the request is a reallocation request:

  • If the vector of previous allocations is empty, reallocates a nullptr.
  • Otherwise, removes a pointer from the vector and reallocates it.

◆ HandleRequests()

void pw::allocator::test::TestHarnessGeneric::HandleRequests ( const Vector< Request > &  requests)

Handles a sequence of allocation requests.

This method is useful for processing externally generated requests, e.g. from FuzzTest. It will call Reset before returning.


The documentation for this class was generated from the following file: