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 {
45 std::variant<AllocationRequest, DeallocationRequest, ReallocationRequest>;
49size_t AlignmentFromLShift(
size_t lshift,
size_t size);
85 size_t num_allocations()
const {
return num_allocations_; }
86 size_t allocated()
const {
return allocated_; }
88 void set_allocator(
Allocator* allocator) { allocator_ = allocator; }
89 void set_prng_seed(uint64_t seed) { prng_ = random::XorShiftStarRng64(seed); }
90 void set_available(
size_t available) { available_ = available; }
144 size_t GenerateSize(
size_t max_size);
149 virtual void AfterAllocate(
const void*) {}
150 virtual void BeforeReallocate(
const Layout&) {}
151 virtual void AfterReallocate(
const void*) {}
152 virtual void BeforeDeallocate(
const void*) {}
153 virtual void AfterDeallocate() {}
164 void AddAllocation(
void* ptr, Layout layout);
169 Allocation* RemoveAllocation(
size_t index);
172 Allocator* allocator_ =
nullptr;
175 IntrusiveList<Allocation> allocations_;
178 size_t num_allocations_ = 0;
181 size_t allocated_ = 0;
186 std::optional<size_t> available_;
189 std::optional<random::XorShiftStarRng64> prng_;
193 std::optional<size_t> max_size_;
Definition: allocator.h:34
Definition: test_harness.h:72
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:148
void GenerateRequest(size_t max_size)
Definition: intrusive_list.h:82
Represents a request to allocate some memory.
Definition: test_harness.h:28
Represents a request to free some allocated memory.
Definition: test_harness.h:34
Represents a request to reallocate allocated memory with a new size.
Definition: test_harness.h:39
Associates a pointer to memory with the Layout used to allocate it.
Definition: test_harness.h:75