Unit testing for esp-open-rtos (#253)
* Get testing system by projectgus working with master HEAD * Fix running dual test. Add basic wifi test * Moved spiff test to a test case. Reset retries in test runner * Add timers test case * test_runner: List test cases and run individual test cases * Add README for tests * Update README.md * Code clean-up * Python3.4 support. README.md update
This commit is contained in:
parent
dda384f3a1
commit
7c702d7f09
19 changed files with 1562 additions and 45 deletions
56
tests/cases/02_heap.c
Normal file
56
tests/cases/02_heap.c
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
#include "testcase.h"
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include <FreeRTOS.h>
|
||||
|
||||
DEFINE_SOLO_TESTCASE(02_heap_simple)
|
||||
DEFINE_SOLO_TESTCASE(02_heap_full)
|
||||
|
||||
/* Simple heap accounting tests */
|
||||
static void a_02_heap_simple()
|
||||
{
|
||||
struct mallinfo info = mallinfo();
|
||||
printf("'arena' allocation size %d bytes\n", info.arena);
|
||||
/* This is really a sanity check, if the "arena" size shrinks then
|
||||
this is a good thing and we can update the test. If it grows
|
||||
then we can also update the test, but we need a good reason. */
|
||||
TEST_ASSERT_INT_WITHIN_MESSAGE(1000, 15000, info.arena, "Initial allocated heap should be approximately 15kB. SEE COMMENT.");
|
||||
|
||||
uint32_t freeheap = xPortGetFreeHeapSize();
|
||||
printf("xPortGetFreeHeapSize = %d bytes\n", freeheap);
|
||||
TEST_ASSERT_TRUE_MESSAGE(freeheap > 20000, "Should be at least 20kB free.");
|
||||
|
||||
uint8_t *buf = malloc(8192);
|
||||
/* <-- have to do something with buf or gcc helpfully optimises it out! */
|
||||
memset(buf, 0xEE, 8192);
|
||||
uint32_t after = xPortGetFreeHeapSize();
|
||||
struct mallinfo after_info = mallinfo();
|
||||
printf("after arena size = %d bytes\n", after_info.arena);
|
||||
printf("after xPortGetFreeHeapSize = %d bytes\n", after);
|
||||
TEST_ASSERT_UINT32_WITHIN_MESSAGE(100, info.arena+8192, after_info.arena, "Allocated heap 'after' size should be 8kB more than before");
|
||||
TEST_ASSERT_UINT32_WITHIN_MESSAGE(100, freeheap-8192, after, "Free heap size should be 8kB less than before");
|
||||
|
||||
free(buf);
|
||||
after = xPortGetFreeHeapSize();
|
||||
printf("after freeing xPortGetFreeHeapSize = %d bytes\n", after);
|
||||
TEST_ASSERT_UINT32_WITHIN_MESSAGE(100, freeheap, after, "Free heap size after freeing buffer should be close to initial");
|
||||
TEST_PASS();
|
||||
}
|
||||
|
||||
/* Ensure malloc behaves when out of memory */
|
||||
static void a_02_heap_full()
|
||||
{
|
||||
void *x = malloc(65536);
|
||||
TEST_ASSERT_NULL_MESSAGE(x, "Allocating 64kB should fail and return null");
|
||||
|
||||
void *y = malloc(32768);
|
||||
TEST_ASSERT_NOT_NULL_MESSAGE(y, "Allocating 32kB should succeed");
|
||||
|
||||
void *z = malloc(32768);
|
||||
TEST_ASSERT_NULL_MESSAGE(z, "Allocating second 32kB should fail");
|
||||
|
||||
free(y);
|
||||
z = malloc(32768);
|
||||
TEST_ASSERT_NOT_NULL_MESSAGE(z, "Allocating 32kB should succeed after first block freed");
|
||||
TEST_PASS();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue