10#include <stk_config.h>
23#define _STK_EVT_TEST_TASKS_MAX 5
24#define _STK_EVT_TEST_TIMEOUT 300
25#define _STK_EVT_TEST_SHORT_SLEEP 10
26#define _STK_EVT_TEST_LONG_SLEEP 100
28#define _STK_EVT_STACK_SIZE 128
31#define _STK_EVT_STACK_SIZE 256
32#define STK_TASK static
36inline void *
operator new(std::size_t,
void *ptr)
noexcept {
return ptr; }
37inline void operator delete(
void *,
void *)
noexcept { }
67template <EAccessMode _AccessMode>
93 printf(
"auto-reset basic: counter=%d (expected %d)\n",
117template <EAccessMode _AccessMode>
142 printf(
"manual-reset basic: counter=%d (expected %d), still_signaled=%d (expected 1)\n",
163template <EAccessMode _AccessMode>
192 printf(
"initial state: counter=%d (expected 2)\n", (
int)
g_SharedCounter);
205template <EAccessMode _AccessMode>
233 if (!acquired && elapsed >= 45 && elapsed <= 60)
253 printf(
"timeout wait: counter=%d (expected 2)\n", (
int)
g_SharedCounter);
266template <EAccessMode _AccessMode>
324template <EAccessMode _AccessMode>
346 printf(
"reset manual: set_changed=%d (expected 1), reset_changed=%d (expected 1), "
347 "reset_again=%d (expected 0), counter=%d (expected 0)\n",
348 (
int)set_changed, (
int)reset_changed, (
int)reset_again, (
int)
g_SharedCounter);
350 if (set_changed && reset_changed && !reset_again && (
g_SharedCounter == 0))
385template <EAccessMode _AccessMode>
415 printf(
"pulse auto-reset: counter=%d (expected %d), still_signaled=%d (expected 0)\n",
426 for (int32_t i = 0; i < share; ++i)
440template <EAccessMode _AccessMode>
468 printf(
"pulse manual-reset: counter=%d (expected %d), "
469 "still_signaled=%d (expected 0), after_empty_pulse=%d (expected 0)\n",
471 (
int)still_signaled, (
int)after_empty_pulse);
474 !still_signaled && !after_empty_pulse)
508 return (strcmp(test_name,
"InitialState") != 0) &&
509 (strcmp(test_name,
"TimeoutWait") != 0) &&
510 (strcmp(test_name,
"TryWait") != 0) &&
511 (strcmp(test_name,
"ResetManual") != 0);
517template <
class TaskType>
518static int32_t
RunTest(
const char *test_name, int32_t param = 0,
519 bool manual_reset =
false,
bool initial_state =
false)
525 printf(
"Test: %s\n", test_name);
533 TaskType task3(3, param);
534 TaskType task4(4, param);
551 printf(
"--------------\n");
568 int total_failures = 0, total_success = 0;
570 printf(
"--------------\n");
580#ifndef __ARM_ARCH_6M__
628 printf(
"##############\n");
629 printf(
"Total tests: %d\n", total_failures + total_success);
630 printf(
"Failures: %d\n", total_failures);
Top-level STK include. Provides the Kernel class template and all built-in task-switching strategies.
Implementation of synchronization primitive: stk::sync::Event.
static int32_t RunTest(const char *test_name, int32_t param=0)
#define _STK_EVT_TEST_LONG_SLEEP
int main(int argc, char **argv)
#define _STK_EVT_TEST_SHORT_SLEEP
#define _STK_EVT_TEST_TIMEOUT
static int32_t RunTest(const char *test_name, int32_t param=0, bool manual_reset=false, bool initial_state=false)
#define _STK_EVT_TEST_TASKS_MAX
static bool NeedsExtendedTasks(const char *test_name)
#define STK_TEST_DECL_ASSERT
Declare assertion redirector in the source file.
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 Delay(uint32_t ticks)
Delay calling process by busy-waiting until the deadline expires.
Namespace of the test inventory.
static volatile int32_t g_OrderIndex
static volatile int32_t g_SharedCounter
static sync::Event g_TestEvent
static volatile bool g_TestComplete
static volatile int32_t g_AcquisitionOrder[5]
static Kernel< KERNEL_DYNAMIC|KERNEL_SYNC, 5, SwitchStrategyRR, PlatformDefault > g_Kernel
static void ResetTestState(bool manual_reset=false, bool initial_state=false)
static volatile int32_t g_TestResult
Concrete implementation of IKernel.
Task(const Task &)=delete
Binary synchronization event (signaled / non-signaled) primitive.
Tests auto-reset event: Set() wakes exactly one waiting task then resets.
void Run()
Entry point of the user task.
AutoResetBasicTask(uint8_t task_id, int32_t iterations)
Tests manual-reset event: Set() wakes all waiting tasks and state stays signaled.
void Run()
Entry point of the user task.
ManualResetBasicTask(uint8_t task_id, int32_t)
Tests event constructed with initial_state=true.
InitialStateTask(uint8_t task_id, int32_t)
void Run()
Entry point of the user task.
Tests Wait() timeout behavior.
void Run()
Entry point of the user task.
TimeoutWaitTask(uint8_t task_id, int32_t)
Tests TryWait() non-blocking poll behavior.
void Run()
Entry point of the user task.
TryWaitTask(uint8_t task_id, int32_t)
Tests Reset() on a manual-reset event.
ResetManualTask(uint8_t task_id, int32_t)
void Run()
Entry point of the user task.
Tests Pulse() on an auto-reset event.
PulseAutoResetTask(uint8_t task_id, int32_t iterations)
void Run()
Entry point of the user task.
Tests Pulse() on a manual-reset event.
PulseManualResetTask(uint8_t task_id, int32_t)
void Run()
Entry point of the user task.
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.