16#include "pw_allocator/allocator.h"
17#include "pw_allocator/first_fit.h"
19namespace pw::allocator::test {
30 allocator_(allocator),
31 allow_allocate_(
true),
33 allow_reallocate_(
true) {}
37 allow_allocate_ = allow_resize_ = allow_reallocate_ =
true;
43 allow_allocate_ = allow_resize_ = allow_reallocate_ =
false;
69 return allow_allocate_ ? allocator_.
Allocate(layout) :
nullptr;
71 void DoDeallocate(
void* ptr)
override { allocator_.
Deallocate(ptr); }
73 bool DoResize(
void* ptr,
size_t new_size)
override {
74 return allow_resize_ && allocator_.
Resize(ptr, new_size);
78 return allow_reallocate_ ? allocator_.
Reallocate(ptr, new_layout) :
nullptr;
86 bool allow_reallocate_;
Definition: allocator.h:34
constexpr Allocator()=default
TODO(b/326509341): Remove when downstream consumers migrate.
bool Resize(void *ptr, size_t new_size)
Definition: allocator.h:285
void * Reallocate(void *ptr, Layout new_layout)
Definition: allocator.h:319
void * Allocate(Layout layout)
Definition: allocator.h:42
void Deallocate(void *ptr)
Definition: deallocator.h:58
Definition: fault_injecting_allocator.h:26
void DisableReallocate()
Return nullptr for Reallocate calls.
Definition: fault_injecting_allocator.h:62
void EnableAllocate()
Forward Allocate calls to the allocator.
Definition: fault_injecting_allocator.h:47
void EnableResize()
Forward Resize calls to the allocator.
Definition: fault_injecting_allocator.h:53
void * DoAllocate(Layout layout) override
Definition: fault_injecting_allocator.h:68
void DisableResize()
Return false for Resize calls.
Definition: fault_injecting_allocator.h:56
Allocator & real_allocator()
Returns a reference to the wrapped allocator.
Definition: fault_injecting_allocator.h:65
void DisableAll()
Definition: fault_injecting_allocator.h:42
bool DoResize(void *ptr, size_t new_size) override
Definition: fault_injecting_allocator.h:73
void EnableReallocate()
Forward Reallocate calls to the allocator.
Definition: fault_injecting_allocator.h:59
void * DoReallocate(void *ptr, Layout new_layout) override
Definition: fault_injecting_allocator.h:77
void DisableAllocate()
Return nullptr for Allocate calls.
Definition: fault_injecting_allocator.h:50
void EnableAll()
Forward Allocate, Resize, and Reallocate calls to the allocator.
Definition: fault_injecting_allocator.h:36