27 #include <blackboard/internal/memory_manager.h> 28 #include <blackboard/exceptions.h> 29 #include <blackboard/bbconfig.h> 31 #include <core/exceptions/system.h> 47 signal_handler(
int signum)
54 #define BLACKBOARD_MEMORY_SIZE 2 * 1024 * 1024 57 main(
int argc,
char **argv)
60 signal(SIGINT, signal_handler);
69 cout <<
"Running basic tests" << endl;
70 cout <<
"=========================================================================" << endl;
76 for (
unsigned int i = 0; i < NUM_CHUNKS; ++i) {
77 cout <<
"Allocating m[" << i <<
"] with " << (i+1) * 1000 <<
" bytes.." << flush;
78 m[i] = mm->
alloc( (i+1) * 1000 );
79 cout <<
"done" << endl;
83 cout <<
"Largest chunk is not " << NUM_CHUNKS * 1000 <<
" bytes, error, aborting" << endl;
88 cout <<
"Free chunks:" << endl;
90 cout <<
"Allocated chunks:" << endl;
94 for (
unsigned int i = 0; i < NUM_CHUNKS; ++i) {
95 cout <<
"Freeing m[" << i <<
"].." << flush;
97 cout <<
"done" << endl;
101 cout <<
"Largest chunk is not 0 bytes, error, aborting" << endl;
107 cout <<
"Max free size after tests differe from before test, error, aborting" << endl;
112 cout <<
"Free chunks:" << endl;
114 cout <<
"Allocated chunks:" << endl;
118 cout <<
"Basic tests finished" << endl;
119 cout <<
"=========================================================================" << endl;
121 cout << endl <<
"Running gremlin tests, press Ctrl-C to stop" << endl;
122 cout <<
"=========================================================================" << endl;
124 std::vector< void * > ptrs;
127 unsigned int modcount = 0;
129 if (rand() < RAND_MAX / 2) {
130 cout <<
"a" << flush;
132 unsigned int s = (rand() % BLACKBOARD_MEMORY_SIZE) / 1000;
142 cout <<
"Memory Manager ran out of memory, tried to allocate " 143 << s <<
" bytes, detailed info:" << endl;
144 cout <<
"Free chunks:" << endl;
146 cout <<
"Allocated chunks:" << endl;
151 cout <<
"f" << flush;
153 if ( ptrs.size() > 0 ) {
155 unsigned int erase = rand() % ptrs.size();
157 mm->
free( ptrs[erase] );
158 ptrs.erase( ptrs.begin() + erase );
160 cout <<
"Ouch, tried to free invalid pointer" << endl;
161 cout <<
"Allocated chunks:" << endl;
163 printf(
"Pointer tried to free: 0x%lx\n", (
long unsigned int)ptrs[erase]);
171 cout <<
"Inconsistent memory found, printing exception trace" << endl;
173 cout <<
"Free chunks:" << endl;
175 cout <<
"Allocated chunks:" << endl;
181 if ( modcount % 10 == 0 ) {
185 cout <<
"Overhang detected, allocated chunks:" << endl;
void print_performance_info() const
Prints out performance info.
Thrown when BlackBoard memory has been corupted This exception is thrown by the memory manager if the...
void print_allocated_chunks_info() const
Print out info about allocated chunks.
Fawkes library namespace.
BlackBoard memory manager.
void * alloc(unsigned int num_bytes)
Allocate memory.
A NULL pointer was supplied where not allowed.
void print_free_chunks_info() const
Print out info about free chunks.
void print_trace()
Prints trace to stderr.
void check()
Check memory consistency.
unsigned int max_allocated_size() const
Get maximum alloced memory size.
void free(void *chunk_ptr)
Free a memory chunk.
unsigned int max_free_size() const
Get maximum allocatable memory size.
System ran out of memory and desired operation could not be fulfilled.
unsigned int overhang_size() const
Get number of overhanging bytes.