20#include "pw_allocator/allocator.h"
21#include "pw_containers/intrusive_list.h"
22#include "pw_containers/vector.h"
23#include "pw_random/xor_shift.h"
25namespace pw::allocator::test {
47 std::variant<AllocationRequest, DeallocationRequest, ReallocationRequest>;
87 size_t num_allocations()
const {
return num_allocations_; }
88 size_t allocated()
const {
return allocated_; }
90 void set_allocator(
Allocator* allocator) { allocator_ = allocator; }
91 void set_prng_seed(uint64_t seed) { prng_ = random::XorShiftStarRng64(seed); }
92 void set_available(
size_t available) { available_ = available; }
146 size_t GenerateSize(
size_t max_size);
151 virtual void AfterAllocate(
const void*) {}
152 virtual void BeforeReallocate(
const Layout&) {}
153 virtual void AfterReallocate(
const void*) {}
154 virtual void BeforeDeallocate(
const void*) {}
155 virtual void AfterDeallocate() {}
166 void AddAllocation(
void* ptr, Layout layout);
171 Allocation* RemoveAllocation(
size_t index);
174 Allocator* allocator_ =
nullptr;
177 IntrusiveList<Allocation> allocations_;
180 size_t num_allocations_ = 0;
183 size_t allocated_ = 0;
188 std::optional<size_t> available_;
191 std::optional<random::XorShiftStarRng64> prng_;
195 std::optional<size_t> max_size_;
Definition: allocator.h:36
Definition: test_harness.h:74
bool HandleRequest(const Request &request)
void GenerateRequests(size_t max_size, size_t num_requests)
void Reset()
Deallocates any pointers stored in the vector of allocated pointers.
void HandleRequests(const Vector< Request > &requests)
virtual void BeforeAllocate(const Layout &)
Definition: test_harness.h:150
void GenerateRequest(size_t max_size)
Definition: intrusive_list.h:88
size_t AlignmentFromLShift(size_t lshift, size_t size)
Represents a request to allocate some memory.
Definition: test_harness.h:30
Represents a request to free some allocated memory.
Definition: test_harness.h:36
Represents a request to reallocate allocated memory with a new size.
Definition: test_harness.h:41
Associates a pointer to memory with the Layout used to allocate it.
Definition: test_harness.h:77