mirror of
https://github.com/kelvinlawson/atomthreads.git
synced 2026-03-06 20:43:14 +01:00
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:
@@ -37,12 +37,15 @@
|
||||
#define QUEUE_ENTRIES 16
|
||||
|
||||
|
||||
/* Number of test threads */
|
||||
#define NUM_TEST_THREADS 2
|
||||
|
||||
|
||||
/* Test OS objects */
|
||||
static ATOM_QUEUE queue1;
|
||||
static ATOM_TCB tcb1, tcb2;
|
||||
static uint8_t test1_thread_stack[TEST_THREAD_STACK_SIZE];
|
||||
static uint8_t test2_thread_stack[TEST_THREAD_STACK_SIZE];
|
||||
static uint8_t queue1_storage[QUEUE_ENTRIES];
|
||||
static ATOM_TCB tcb[NUM_TEST_THREADS];
|
||||
static uint8_t test_thread_stack[NUM_TEST_THREADS][TEST_THREAD_STACK_SIZE];
|
||||
|
||||
|
||||
/* Test result tracking */
|
||||
@@ -103,8 +106,9 @@ uint32_t test_start (void)
|
||||
}
|
||||
|
||||
/* Create a test thread that will block because the queue is full */
|
||||
if (atomThreadCreate(&tcb1, TEST_THREAD_PRIO, test1_thread_func, 0,
|
||||
&test1_thread_stack[TEST_THREAD_STACK_SIZE - 1]) != ATOM_OK)
|
||||
if (atomThreadCreate(&tcb[0], TEST_THREAD_PRIO, test1_thread_func, 0,
|
||||
&test_thread_stack[0][TEST_THREAD_STACK_SIZE - 1],
|
||||
TEST_THREAD_STACK_SIZE) != ATOM_OK)
|
||||
{
|
||||
/* Fail */
|
||||
ATOMLOG (_STR("Error creating test thread 1\n"));
|
||||
@@ -173,8 +177,9 @@ uint32_t test_start (void)
|
||||
}
|
||||
|
||||
/* Create a test thread that will block because the queue is full */
|
||||
if (atomThreadCreate(&tcb2, TEST_THREAD_PRIO, test2_thread_func, 0,
|
||||
&test2_thread_stack[TEST_THREAD_STACK_SIZE - 1]) != ATOM_OK)
|
||||
if (atomThreadCreate(&tcb[1], TEST_THREAD_PRIO, test2_thread_func, 0,
|
||||
&test_thread_stack[1][TEST_THREAD_STACK_SIZE - 1],
|
||||
TEST_THREAD_STACK_SIZE) != ATOM_OK)
|
||||
{
|
||||
/* Fail */
|
||||
ATOMLOG (_STR("Error creating test thread 2\n"));
|
||||
@@ -221,15 +226,38 @@ uint32_t test_start (void)
|
||||
}
|
||||
}
|
||||
|
||||
/* 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;
|
||||
|
||||
Reference in New Issue
Block a user