Instantiate this class in a unit test scope where malloc (and realloc, etc.) should be disallowed or curtailed.
Example:
Currently, when the device under test violates its allocation limits, the test terminates with an abort(). To better isolate what went wrong, re-run the test in a debugger.
This class is only intended for use in test code. To temporarily use it in non-test code, hack the BUILD.bazel file to mark this library testonly = 0
instead of testonly = 1
.
#include <drake/common/test_utilities/limit_malloc.h>
Public Member Functions | |
LimitMalloc () | |
Applies malloc limits until this object's destructor is run. More... | |
LimitMalloc (LimitMallocParams args) | |
Applies malloc limits until this object's destructor is run. More... | |
~LimitMalloc () | |
Undoes this object's malloc limits. More... | |
int | num_allocations () const |
Returns the number of allocations observed so far. More... | |
const LimitMallocParams & | params () const |
Returns the parameters structure used to construct this object. More... | |
Does not allow copy, move, or assignment | |
LimitMalloc (const LimitMalloc &)=delete | |
void | operator= (const LimitMalloc &)=delete |
LimitMalloc (LimitMalloc &&)=delete | |
void | operator= (LimitMalloc &&)=delete |
LimitMalloc | ( | ) |
Applies malloc limits until this object's destructor is run.
All allocations will fail. For now, only one instance of this class may be created at a time. (In the future, we may allow updating the limits by nesting these guards.)
|
explicit |
Applies malloc limits until this object's destructor is run.
A allocations will succeed except for any limits designated in args. For now, only one instance of this class may be created at a time. (In the future, we may allow updating the limits by nesting these guards.)
~LimitMalloc | ( | ) |
Undoes this object's malloc limits.
|
delete |
|
delete |
int num_allocations | ( | ) | const |
Returns the number of allocations observed so far.
|
delete |
|
delete |
const LimitMallocParams& params | ( | ) | const |
Returns the parameters structure used to construct this object.