Add stack usage analysis. Used for all automated test modules (if enabled) such that the automated tests can now trap some classes of thread stack overflow. ATmega port now tested on both ATMega16 and ATmega32. STM8 port not yet modified to support the new stack-checking API.

This commit is contained in:
Kelvin Lawson
2010-03-01 20:01:10 +00:00
parent 53147d9e49
commit 2d909ba279
51 changed files with 1533 additions and 662 deletions
+45 -18
View File
@@ -36,12 +36,13 @@
/* Test period (in seconds) */
#define TEST_PERIOD_SECS 10
/* Number of test threads */
#define NUM_TEST_THREADS 3
/* Test OS objects */
static ATOM_TCB tcb1, tcb2, tcb3;
static uint8_t test1_thread_stack[TEST_THREAD_STACK_SIZE];
static uint8_t test2_thread_stack[TEST_THREAD_STACK_SIZE];
static uint8_t test3_thread_stack[TEST_THREAD_STACK_SIZE];
static ATOM_TCB tcb[NUM_TEST_THREADS];
static uint8_t test_thread_stack[NUM_TEST_THREADS][TEST_THREAD_STACK_SIZE];
/* Per-thread failure counts */
@@ -71,8 +72,9 @@ uint32_t test_start (void)
g_failure_cnt[0] = g_failure_cnt[1] = g_failure_cnt[2] = 0;
/* Create Thread 1 */
if (atomThreadCreate(&tcb1, TEST_THREAD_PRIO, test_thread_func, 1,
&test1_thread_stack[TEST_THREAD_STACK_SIZE - 1]) != ATOM_OK)
if (atomThreadCreate(&tcb[0], TEST_THREAD_PRIO, test_thread_func, 1,
&test_thread_stack[0][TEST_THREAD_STACK_SIZE - 1],
TEST_THREAD_STACK_SIZE) != ATOM_OK)
{
/* Fail */
ATOMLOG (_STR("Thread1\n"));
@@ -80,8 +82,9 @@ uint32_t test_start (void)
}
/* Create Thread 2 */
if (atomThreadCreate(&tcb2, TEST_THREAD_PRIO, test_thread_func, 2,
&test2_thread_stack[TEST_THREAD_STACK_SIZE - 1]) != ATOM_OK)
if (atomThreadCreate(&tcb[1], TEST_THREAD_PRIO, test_thread_func, 2,
&test_thread_stack[1][TEST_THREAD_STACK_SIZE - 1],
TEST_THREAD_STACK_SIZE) != ATOM_OK)
{
/* Fail */
ATOMLOG (_STR("Thread2\n"));
@@ -89,8 +92,9 @@ uint32_t test_start (void)
}
/* Create Thread 3 */
if (atomThreadCreate(&tcb3, TEST_THREAD_PRIO, test_thread_func, 3,
&test3_thread_stack[TEST_THREAD_STACK_SIZE - 1]) != ATOM_OK)
if (atomThreadCreate(&tcb[2], TEST_THREAD_PRIO, test_thread_func, 3,
&test_thread_stack[2][TEST_THREAD_STACK_SIZE - 1],
TEST_THREAD_STACK_SIZE) != ATOM_OK)
{
/* Fail */
ATOMLOG (_STR("Thread3\n"));
@@ -107,15 +111,38 @@ uint32_t test_start (void)
/* Add the per-thread failure count to the main count */
failures += g_failure_cnt[0] + g_failure_cnt[1] + g_failure_cnt[2];
/* Log final status */
if (failures == 0)
/* Check thread stack usage (if enabled) */
#ifdef ATOM_STACK_CHECKING
{
ATOMLOG (_STR("Pass\n"));
}
else
{
ATOMLOG (_STR("Fail(%d)\n"), failures);
uint32_t used_bytes, free_bytes;
int thread;
/* Check all threads */
for (thread = 0; thread < NUM_TEST_THREADS; thread++)
{
/* Check thread stack usage */
if (atomThreadStackCheck (&tcb[thread], &used_bytes, &free_bytes) != ATOM_OK)
{
ATOMLOG (_STR("StackCheck\n"));
failures++;
}
else
{
/* Check the thread did not use up to the end of stack */
if (free_bytes == 0)
{
ATOMLOG (_STR("StackOverflow %d\n"), thread);
failures++;
}
/* Log the stack usage */
#ifdef TESTS_LOG_STACK_USAGE
ATOMLOG (_STR("StackUse:%d\n"), used_bytes);
#endif
}
}
}
#endif
/* Quit */
return failures;
@@ -173,4 +200,4 @@ static void test_thread_func (uint32_t data)
}
}
}
}
}