26 #include <blackboard/bbconfig.h>
27 #include <blackboard/exceptions.h>
28 #include <blackboard/internal/memory_manager.h>
29 #include <core/exceptions/system.h>
43 signal_handler(
int signum)
49 #define BLACKBOARD_MEMORY_SIZE 2 * 1024 * 1024
52 main(
int argc,
char **argv)
54 signal(SIGINT, signal_handler);
63 cout <<
"Running basic tests" << endl;
64 cout <<
"=========================================================================" << endl;
70 for (
unsigned int i = 0; i < NUM_CHUNKS; ++i) {
71 cout <<
"Allocating m[" << i <<
"] with " << (i + 1) * 1000 <<
" bytes.." << flush;
72 m[i] = mm->
alloc((i + 1) * 1000);
73 cout <<
"done" << endl;
77 cout <<
"Largest chunk is not " << NUM_CHUNKS * 1000 <<
" bytes, error, aborting" << endl;
82 cout <<
"Free chunks:" << endl;
84 cout <<
"Allocated chunks:" << endl;
88 for (
unsigned int i = 0; i < NUM_CHUNKS; ++i) {
89 cout <<
"Freeing m[" << i <<
"].." << flush;
91 cout <<
"done" << endl;
95 cout <<
"Largest chunk is not 0 bytes, error, aborting" << endl;
101 cout <<
"Max free size after tests differe from before test, error, aborting" << endl;
106 cout <<
"Free chunks:" << endl;
108 cout <<
"Allocated chunks:" << endl;
112 cout <<
"Basic tests finished" << endl;
113 cout <<
"=========================================================================" << endl;
115 cout << endl <<
"Running gremlin tests, press Ctrl-C to stop" << endl;
116 cout <<
"=========================================================================" << endl;
118 std::vector<void *> ptrs;
121 unsigned int modcount = 0;
123 if (rand() < RAND_MAX / 2) {
124 cout <<
"a" << flush;
126 unsigned int s = (rand() % BLACKBOARD_MEMORY_SIZE) / 1000;
136 cout <<
"Memory Manager ran out of memory, tried to allocate " << s
137 <<
" bytes, detailed info:" << endl;
138 cout <<
"Free chunks:" << endl;
140 cout <<
"Allocated chunks:" << endl;
145 cout <<
"f" << flush;
147 if (ptrs.size() > 0) {
149 unsigned int erase = rand() % ptrs.size();
151 mm->
free(ptrs[erase]);
152 ptrs.erase(ptrs.begin() + erase);
154 cout <<
"Ouch, tried to free invalid pointer" << endl;
155 cout <<
"Allocated chunks:" << endl;
157 printf(
"Pointer tried to free: 0x%lx\n", (
long unsigned int)ptrs[erase]);
165 cout <<
"Inconsistent memory found, printing exception trace" << endl;
167 cout <<
"Free chunks:" << endl;
169 cout <<
"Allocated chunks:" << endl;
175 if (modcount % 10 == 0) {
179 cout <<
"Overhang detected, allocated chunks:" << endl;
Thrown when BlackBoard memory has been corupted This exception is thrown by the memory manager if the...
A NULL pointer was supplied where not allowed.
BlackBoard memory manager.
unsigned int overhang_size() const
Get number of overhanging bytes.
void * alloc(unsigned int num_bytes)
Allocate memory.
void print_free_chunks_info() const
Print out info about free chunks.
void print_allocated_chunks_info() const
Print out info about allocated chunks.
void free(void *chunk_ptr)
Free a memory chunk.
unsigned int max_free_size() const
Get maximum allocatable memory size.
void check()
Check memory consistency.
void print_performance_info() const
Prints out performance info.
unsigned int max_allocated_size() const
Get maximum alloced memory size.
void print_trace()
Prints trace to stderr.
System ran out of memory and desired operation could not be fulfilled.
Fawkes library namespace.