tests: test_runner, working simple single-ESP "solo" test cases

This commit is contained in:
Angus Gratton 2016-02-09 21:03:50 +11:00
parent 97a46e8c1a
commit 80b191af08
7 changed files with 492 additions and 22 deletions

View file

@ -1,8 +0,0 @@
#include "testcase.h"
DEFINE_SOLO_TESTCASE(01_basic)
static bool a_01_basic()
{
return false;
}

View file

@ -0,0 +1,71 @@
#include "testcase.h"
#include <FreeRTOS.h>
#include <task.h>
#include <esp/uart.h>
/* Basic test cases to validate the FreeRTOS scheduler works */
DEFINE_SOLO_TESTCASE(01_scheduler_basic)
DEFINE_SOLO_TESTCASE(01_scheduler_priorities)
void set_variable(void *pvParameters)
{
bool *as_bool = (bool *)pvParameters;
*as_bool = true;
/* deliberately a busywait at the end, not vTaskSuspend, to test priorities */
while(1) { }
}
/* Really simple - do created tasks run? */
static void a_01_scheduler_basic()
{
volatile bool a = false, b = false, c = false;
printf("top of scheduler...\n");
uart_flush_txfifo(0);
xTaskCreate(set_variable, (signed char *)"set_a", 128, (void *)&a, tskIDLE_PRIORITY, NULL);
xTaskCreate(set_variable, (signed char *)"set_b", 128, (void *)&b, tskIDLE_PRIORITY, NULL);
xTaskCreate(set_variable, (signed char *)"set_c", 128, (void *)&c, tskIDLE_PRIORITY, NULL);
TEST_ASSERT_FALSE_MESSAGE(a, "task set_a shouldn't run yet");
TEST_ASSERT_FALSE_MESSAGE(b, "task set_b shouldn't run yet");
TEST_ASSERT_FALSE_MESSAGE(c, "task set_c shouldn't run yet");
vTaskDelay(5);
TEST_ASSERT_TRUE_MESSAGE(a, "task set_a should have run");
TEST_ASSERT_TRUE_MESSAGE(b, "task set_b should have run");
TEST_ASSERT_TRUE_MESSAGE(c, "task set_c should have run");
TEST_PASS;
}
/* Verify that a high-priority task will starve a lower priority task */
static void a_01_scheduler_priorities()
{
/* Increase priority of the init task to make sure it always takes priority */
vTaskPrioritySet(xTaskGetCurrentTaskHandle(), tskIDLE_PRIORITY+4);
bool lower = false, higher = false;
xTaskHandle task_lower, task_higher;
xTaskCreate(set_variable, (signed char *)"high_prio", 128, (void *)&higher, tskIDLE_PRIORITY+1, &task_higher);
xTaskCreate(set_variable, (signed char *)"low_prio", 128, (void *)&lower, tskIDLE_PRIORITY, &task_lower);
TEST_ASSERT_FALSE_MESSAGE(higher, "higher prio task should not have run yet");
TEST_ASSERT_FALSE_MESSAGE(lower, "lower prio task should not have run yet");
vTaskDelay(2);
TEST_ASSERT_TRUE_MESSAGE(higher, "higher prio task should have run");
TEST_ASSERT_FALSE_MESSAGE(lower, "lower prio task should not have run");
/* Bump lower priority task over higher priority task */
vTaskPrioritySet(task_lower, tskIDLE_PRIORITY+2);
TEST_ASSERT_FALSE_MESSAGE(lower, "lower prio task should still not have run yet");
vTaskDelay(1);
TEST_ASSERT_TRUE_MESSAGE(lower, "lower prio task should have run");
TEST_PASS;
}

37
tests/cases/02_heap.c Normal file
View file

@ -0,0 +1,37 @@
#include "testcase.h"
#include <malloc.h>
#include <string.h>
#include <FreeRTOS.h>
DEFINE_SOLO_TESTCASE(02_heap_simple)
/* 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;
}