16#include "pw_allocator/allocator.h"
17#include "pw_allocator/first_fit.h"
19namespace pw::allocator::test {
32 allocator_(allocator),
33 allow_allocate_(
true),
35 allow_reallocate_(
true) {}
39 allow_allocate_ = allow_resize_ = allow_reallocate_ =
true;
45 allow_allocate_ = allow_resize_ = allow_reallocate_ =
false;
71 return allow_allocate_ ? allocator_.
Allocate(layout) :
nullptr;
73 void DoDeallocate(
void* ptr)
override { allocator_.
Deallocate(ptr); }
75 bool DoResize(
void* ptr,
size_t new_size)
override {
76 return allow_resize_ && allocator_.
Resize(ptr, new_size);
80 return allow_reallocate_ ? allocator_.
Reallocate(ptr, new_layout) :
nullptr;
88 bool allow_reallocate_;
Definition: allocator.h:36
constexpr Allocator()=default
TODO(b/326509341): Remove when downstream consumers migrate.
bool Resize(void *ptr, size_t new_size)
Definition: allocator.h:287
void * Reallocate(void *ptr, Layout new_layout)
Definition: allocator.h:321
void * Allocate(Layout layout)
Definition: allocator.h:44
Definition: fault_injecting_allocator.h:28
void DisableReallocate()
Return nullptr for Reallocate calls.
Definition: fault_injecting_allocator.h:64
void EnableAllocate()
Forward Allocate calls to the allocator.
Definition: fault_injecting_allocator.h:49
void EnableResize()
Forward Resize calls to the allocator.
Definition: fault_injecting_allocator.h:55
void * DoAllocate(Layout layout) override
Definition: fault_injecting_allocator.h:70
void DisableResize()
Return false for Resize calls.
Definition: fault_injecting_allocator.h:58
Allocator & real_allocator()
Returns a reference to the wrapped allocator.
Definition: fault_injecting_allocator.h:67
void DisableAll()
Definition: fault_injecting_allocator.h:44
bool DoResize(void *ptr, size_t new_size) override
Definition: fault_injecting_allocator.h:75
void EnableReallocate()
Forward Reallocate calls to the allocator.
Definition: fault_injecting_allocator.h:61
void * DoReallocate(void *ptr, Layout new_layout) override
Definition: fault_injecting_allocator.h:79
void DisableAllocate()
Return nullptr for Allocate calls.
Definition: fault_injecting_allocator.h:52
void EnableAll()
Forward Allocate, Resize, and Reallocate calls to the allocator.
Definition: fault_injecting_allocator.h:38
void Deallocate(void *ptr)
Definition: deallocator.h:60