10#include <stk_config.h>
23#define _STK_TIMER_TEST_TIMEOUT 1000
24#define _STK_TIMER_TEST_SHORT_SLEEP 10
25#define _STK_TIMER_TEST_LONG_SLEEP 100
26#define _STK_TIMER_STACK_SIZE 256
28#define _STK_TIMER_TEST_TASKS_MAX 2
31#define _STK_TIMER_TEST_TASKS_MAX 5
32#define STK_TASK static
80template <EAccessMode _AccessMode>
119 printf(
"one-shot timer: count=%d (expected 1), result=%d (expected 2)\n",
136template <EAccessMode _AccessMode>
160 while (
timer.IsActive() && wait)
175 printf(
"periodic timer: count=%d (expected 4-6)\n", (
int)
g_ExpiredCount);
190template <EAccessMode _AccessMode>
220 if ((total >= 7) && (total <= 11) && !timer3.
IsActive())
228 printf(
"multiple timers: total=%d (expected 7-11)\n", (
int)
g_ExpiredCount);
243template <EAccessMode _AccessMode>
273 printf(
"stop timer: count=%d (expected 0)\n", (
int)
g_ExpiredCount);
289template <EAccessMode _AccessMode>
332 printf(
"reset periodic: count=%d (expected 2)\n", (
int)
g_ExpiredCount);
348template <EAccessMode _AccessMode>
389 if ((
g_ExpiredCount == (count_before_restart + 1)) && (elapsed >= 45) && (elapsed <= 65) && !
timer.IsActive())
397 printf(
"restart timer: count=%d (expected 2)\n", (
int)
g_ExpiredCount);
412template <EAccessMode _AccessMode>
433 while (!
timer.IsActive() && wait)
439 if (!
timer.IsActive())
474 printf(
"start-or-reset: count=%d, result=%d (expected 2, 1)\n",
491template <EAccessMode _AccessMode>
555 printf(
"set-period: count=%d (expected 4)\n", (
int)
g_ExpiredCount);
572template <EAccessMode _AccessMode>
587 #if (_STK_TIMER_TEST_TASKS_MAX > 2)
592 static volatile int32_t g_PerTaskCount[5] = {0};
597 case 0: my_timer = &timer0;
break;
598 case 1: my_timer = &timer1;
break;
599 #if (_STK_TIMER_TEST_TASKS_MAX > 2)
600 case 2: my_timer = &timer2;
break;
601 case 3: my_timer = &timer3;
break;
602 case 4: my_timer = &timer4;
break;
641 bool all_passed =
true;
651 printf(
"stress test: total=%d, per-task counts=[%d,%d,%d,%d,%d] (expected %d each)\n",
653 (
int)g_PerTaskCount[0], (
int)g_PerTaskCount[1], (
int)g_PerTaskCount[2],
654 (
int)g_PerTaskCount[3], (
int)g_PerTaskCount[4],
685 return (strcmp(test_name,
"StressTest") == 0);
691template <
class TaskType>
692static int32_t
RunTest(
const char *test_name, int32_t param = 0)
698 printf(
"Test: %s\n", test_name);
707#if (_STK_TIMER_TEST_TASKS_MAX > 2)
708 TaskType task2(2, param);
709 TaskType task3(3, param);
710 TaskType task4(4, param);
716#if (_STK_TIMER_TEST_TASKS_MAX > 2)
730 printf(
"--------------\n");
747 int total_failures = 0, total_success = 0;
749 printf(
"--------------\n");
753#ifndef __ARM_ARCH_6M__
815 printf(
"##############\n");
816 printf(
"Total tests: %d\n", total_failures + total_success);
817 printf(
"Failures: %d\n", total_failures);
Top-level STK include. Provides the Kernel class template and all built-in task-switching strategies.
Implementation of stk::time::TimerHost, a software timer multiplexer that manages multiple stk::time:...
static int32_t RunTest(const char *test_name, int32_t param=0)
#define STK_TEST_DECL_ASSERT
Declare assertion redirector in the source file.
#define _STK_TIMER_TEST_LONG_SLEEP
int main(int argc, char **argv)
static int32_t RunTest(const char *test_name, int32_t param=0)
#define _STK_TIMER_TEST_SHORT_SLEEP
#define _STK_TIMER_TEST_TASKS_MAX
static bool NeedsExtendedTasks(const char *test_name)
Namespace of STK package.
static int64_t GetTimeNowMs()
Get current time in milliseconds since kernel start.
void Sleep(uint32_t ticks)
Put calling process into a sleep state.
void Yield()
Notify scheduler to switch to the next runnable task.
@ ACCESS_PRIVILEGED
Privileged access mode (access to hardware is fully unrestricted).
Namespace of the test inventory.
Namespace of TimerHost test.
static sync::Event g_LastExpired[5]
static volatile int32_t g_TestResult
static volatile int32_t g_SharedCounter
static time::TimerHost g_TimerHost
static volatile int64_t g_ExpiredTime[5]
static void ResetTestState()
static volatile int32_t g_ExpiredCount
static Kernel< KERNEL_DYNAMIC|KERNEL_SYNC, 5+stk::time::TimerHost::TASK_COUNT, SwitchStrategyRR, PlatformDefault > g_Kernel
Concrete implementation of IKernel.
Task(const Task &)=delete
Binary synchronization event (signaled / non-signaled) primitive.
Software timer multiplexer that manages multiple Timer instances on top of a small fixed set of kerne...
Abstract base class for a timer managed by TimerHost.
static void ShowTestSuitePrologue()
Show text string as prologue before tests start.
@ DEFAULT_FAILURE_EXIT_CODE
default exit code for exit() to denote failure of the test
@ SUCCESS_EXIT_CODE
exit code for exit() to denote the success of the test
static void ShowTestSuiteEpilogue(int32_t result)
Show text string as epilogue after tests end.
Concrete timer implementation that increments g_ExpiredCount on each expiry.
TestTimer(uint8_t timer_id)
void OnExpired(time::TimerHost *)
Tests that a one-shot timer fires exactly once at the expected time.
OneShotTimerTask(uint8_t task_id, int32_t)
void Run()
Entry point of the user task.
Tests that a periodic timer fires repeatedly at regular intervals.
PeriodicTimerTask(uint8_t task_id, int32_t)
void Run()
Entry point of the user task.
Tests that multiple concurrent timers with different periods fire independently.
void Run()
Entry point of the user task.
MultipleTimersTask(uint8_t task_id, int32_t)
Tests that Stop() cancels a pending timer before it fires.
StopTimerTask(uint8_t task_id, int32_t)
void Run()
Entry point of the user task.
Tests that Reset() reanchors a periodic timer's deadline from now.
void Run()
Entry point of the user task.
ResetPeriodicTimerTask(uint8_t task_id, int32_t)
Tests that Restart() atomically stops and re-starts a timer.
RestartTimerTask(uint8_t task_id, int32_t)
void Run()
Entry point of the user task.
Tests StartOrReset(): starts if inactive, resets if active+periodic.
void Run()
Entry point of the user task.
StartOrResetTask(uint8_t task_id, int32_t)
Tests SetPeriod(): changes reload period without affecting current deadline.
void Run()
Entry point of the user task.
SetPeriodTask(uint8_t task_id, int32_t)
Stress test of TimerHost under full five-task contention.
StressTestTask(uint8_t task_id, int32_t iterations)
void Run()
Entry point of the user task.