initial commit

This commit is contained in:
2022-10-23 23:45:43 -07:00
commit e190fa5193
6450 changed files with 8626944 additions and 0 deletions
@@ -0,0 +1,23 @@
#include "test_heap.h"
//
// test_heap
void test_heap( test_info_t** info ){
static test_info_t test_heap_info;
static char* test_heap_name = "Heap Allocation";
test_heap_info.name = test_heap_name;
*(info) = &test_heap_info;
void* mem = NULL;
size_t len = 0;
// boost_mode_enable(true);
do {
len++;
mem = (void*)malloc( len * sizeof(uint8_t));
free(mem);
} while (mem != NULL);
// boost_mode_enable(false);
test_heap_info.metric = "largest allocated space";
test_heap_info.value = len;
}
@@ -0,0 +1,8 @@
#ifndef _TEST_HEAP_H_
#define _TEST_HEAP_H_
#include "tests.h"
void test_heap( test_info_t** info );
#endif // _TEST_HEAP_H_
@@ -0,0 +1,58 @@
#include "test_stack.h"
#define MEMORY_HEADSPACE 4096
// Globals
uint32_t stack_pointer;
uint32_t min_stack_pointer = 0xFFFFFFFF;
uint32_t free_mem;
uint32_t min_free_mem = 0xFFFFFFFF;
bool go_deeper = true;
uint32_t max_depth = 0;
extern unsigned char _sheap;
uint32_t free_memory( void ){
// Without an implementation of _sbrk (heap management) we are assuming
// that the heap has zero size. If there was heap management then you
// would compute the distance to the program break (the end of the heap)
void* local;
return (((uint32_t)&local) - ((uint32_t)&_sheap));
}
void update_stack_info( void ){
void* local;
stack_pointer = (uint32_t)(&local);
free_mem = free_memory();
min_free_mem = (free_mem < min_free_mem) ? free_mem : min_free_mem;
min_stack_pointer = (stack_pointer < min_stack_pointer) ? stack_pointer : min_stack_pointer;
}
void deep_horizon( void ){
update_stack_info();
if(free_memory() < MEMORY_HEADSPACE){
go_deeper = false;
return;
}
if( go_deeper ){
deep_horizon();
}
max_depth++;
}
//
// test_stack
void test_stack( test_info_t** info ){
static test_info_t test_stack_info;
static char* test_stack_name = "Stack Allocation";
test_stack_info.name = test_stack_name;
*(info) = &test_stack_info;
go_deeper = true;
min_free_mem = 0xFFFFFFFF;
max_depth = 0;
deep_horizon();
test_stack_info.metric = "recursion depth";
test_stack_info.value = max_depth;
}
@@ -0,0 +1,8 @@
#ifndef _TEST_STACK_H_
#define _TEST_STACK_H_
#include "tests.h"
void test_stack( test_info_t** info );
#endif // _TEST_STACK_H_
@@ -0,0 +1,30 @@
#include "tests.h"
test_fn tests[] = {
test_stack,
test_heap,
// test_fail,
// test_pass,
NULL, // NULL terminates the list
};
// test definitions
void test_fail( test_info_t** info ){
static test_info_t test_fail_info;
static char* test_fail_name = "Fail Test";
test_fail_info.name = test_fail_name;
test_fail_info.metric = "success";
test_fail_info.value = 0;
*(info) = &test_fail_info;
}
void test_pass( test_info_t** info ){
static test_info_t test_pass_info;
static char* test_pass_name = "Pass Test";
test_pass_info.name = test_pass_name;
test_pass_info.metric = "success";
test_pass_info.value = 1;
*(info) = &test_pass_info;
}
@@ -0,0 +1,18 @@
// test definitions
#ifndef _TESTS_H_
#define _TESTS_H_
#include "test_framework.h"
// included tests
#include "test_stack.h"
#include "test_heap.h"
// simple tests
void test_fail( test_info_t** info );
void test_pass( test_info_t** info );
// list of tests to run
extern test_fn tests[];
#endif // _TESTS_H_