Pigweed
Loading...
Searching...
No Matches
pw::allocator::test::TestHarness< kMaxConcurrentAllocations > Class Template Reference

#include <test_harness.h>

Additional Inherited Members

- Public Member Functions inherited from pw::allocator::test::TestHarnessGeneric
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 inherited from pw::allocator::test::TestHarnessGeneric
constexpr TestHarnessGeneric (Vector< Allocation > &allocations)
 

Detailed Description

template<size_t kMaxConcurrentAllocations>
class pw::allocator::test::TestHarness< kMaxConcurrentAllocations >

Associates an Allocator with a vector to store allocated pointers.

This class differes from its base class only in that it uses its template parameter to explicitly size the vector used to store allocated pointers.

This class does NOT implement WithAllocationsGeneric::Init. It must be extended further with a method that provides an initialized allocator.

For example, one create a fuzzer for MyAllocator that verifies it never crashes by adding the following class, function, and macro:

constexpr size_t kMaxRequests = 256;
constexpr size_t kMaxAllocations = 128;
constexpr size_t kMaxSize = 2048;
class MyAllocatorFuzzer : public TestHarness<kMaxAllocations> {
private:
Allocator* Init() override { return &allocator_; }
MyAllocator allocator_;
};
void MyAllocatorNeverCrashes(const Vector<Request>& requests) {
static MyAllocatorFuzzer fuzzer;
fuzzer.HandleRequests(requests);
}
FUZZ_TEST(MyAllocator, MyAllocatorNeverCrashes)
.WithDomains(ArbitraryRequests<kMaxRequests, kMaxSize>());
Definition: allocator.h:32
Definition: test_harness.h:178

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