10#include <stk_config.h>
23#define _STK_EF_TEST_TASKS_MAX 5
24#define _STK_EF_TEST_TIMEOUT 300
25#define _STK_EF_TEST_SHORT_SLEEP 10
26#define _STK_EF_TEST_LONG_SLEEP 100
28#define _STK_EF_STACK_SIZE 128
31#define _STK_EF_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 { }
41static const uint32_t
FLAG_A = (1U << 0);
42static const uint32_t
FLAG_B = (1U << 1);
43static const uint32_t
FLAG_C = (1U << 2);
44static const uint32_t
FLAG_D = (1U << 3);
74template <EAccessMode _AccessMode>
101 printf(
"set-wait-any: counter=%d (expected %d)\n",
130template <EAccessMode _AccessMode>
155 printf(
"set-wait-all: counter=%d (expected 1)\n", (
int)
g_SharedCounter);
182template <EAccessMode _AccessMode>
207 printf(
"clear: pre_ok=%d (expected 1), post_ok=%d (expected 1), "
208 "flag_b_ok=%d (expected 1), counter=%d (expected 1)\n",
246template <EAccessMode _AccessMode>
306template <EAccessMode _AccessMode>
369template <EAccessMode _AccessMode>
428template <EAccessMode _AccessMode>
443 bool empty_ok = (
g_Flags.Get() == 0U);
457 printf(
"get: empty_ok=%d (expected 1), set_ok=%d (expected 1), "
458 "clear_ok=%d (expected 1), counter=%d (expected 1)\n",
470 uint32_t snapshot =
g_Flags.Get();
487template <EAccessMode _AccessMode>
508 printf(
"multi-waiter-any: counter=%d (expected %d)\n",
518 uint32_t my_flag = k_flags[
m_task_id - 1];
538template <EAccessMode _AccessMode>
564 printf(
"multi-waiter-all: counter=%d (expected %d)\n",
591template <EAccessMode _AccessMode>
622 printf(
"initial-flags: counter=%d (expected 2)\n", (
int)
g_SharedCounter);
655 return (strcmp(test_name,
"SetWaitAll") != 0) &&
656 (strcmp(test_name,
"Clear") != 0) &&
657 (strcmp(test_name,
"NoClear") != 0) &&
658 (strcmp(test_name,
"Timeout") != 0) &&
659 (strcmp(test_name,
"TryWait") != 0) &&
660 (strcmp(test_name,
"Get") != 0) &&
661 (strcmp(test_name,
"InitialFlags") != 0);
667template <
class TaskType>
668static int32_t
RunTest(
const char *test_name, int32_t param = 0, uint32_t initial_flags = 0U)
674 printf(
"Test: %s\n", test_name);
681 TaskType task3(3, param);
682 TaskType task4(4, param);
699 printf(
"--------------\n");
720 int total_failures = 0, total_success = 0;
722 printf(
"--------------\n");
732#ifndef __ARM_ARCH_6M__
792 printf(
"##############\n");
793 printf(
"Total tests: %d\n", total_failures + total_success);
794 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::EventFlags.
static int32_t RunTest(const char *test_name, int32_t param=0)
static const uint32_t FLAG_B
static const uint32_t FLAG_C
int main(int argc, char **argv)
#define _STK_EF_TEST_TIMEOUT
#define _STK_EF_TEST_LONG_SLEEP
#define _STK_EF_TEST_TASKS_MAX
static int32_t RunTest(const char *test_name, int32_t param=0, uint32_t initial_flags=0U)
static const uint32_t FLAG_A
#define _STK_EF_TEST_SHORT_SLEEP
static const uint32_t FLAG_D
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.
Namespace of EventFlags test.
static sync::EventFlags g_Flags
static volatile int32_t g_TestResult
static volatile bool g_TestComplete
static Kernel< KERNEL_DYNAMIC|KERNEL_SYNC, 5, SwitchStrategyRR, PlatformDefault > g_Kernel
static volatile int32_t g_SharedCounter
static void ResetTestState(uint32_t initial_flags=0U)
Concrete implementation of IKernel.
Task(const Task &)=delete
32-bit event flags group for multi-flag synchronization between tasks.
static const uint32_t ERROR_TIMEOUT
Return sentinel: wait timed out before the flags condition was met.
static bool IsError(uint32_t result)
Checks if a return value from Set(), Clear(), or Wait() is an error.
static const uint32_t OPT_NO_CLEAR
Do not clear matched flags after a successful wait.
static const uint32_t OPT_WAIT_ALL
Wait for ALL of the specified flags to be set simultaneously (AND semantics).
static const uint32_t OPT_WAIT_ANY
Wait for ANY of the specified flags to be set (OR semantics, default).
Tests WAIT_ANY (OR) semantics: a single flag unblocks a waiting task.
SetWaitAnyTask(uint8_t task_id, int32_t iterations)
void Run()
Entry point of the user task.
Tests WAIT_ALL (AND) semantics: all requested flags must be set before unblocking.
void Run()
Entry point of the user task.
SetWaitAllTask(uint8_t task_id, int32_t)
Tests Clear() return value and effect on subsequent Wait() calls.
ClearTask(uint8_t task_id, int32_t)
void Run()
Entry point of the user task.
Tests NO_CLEAR option: matched flags are not consumed after a successful Wait().
NoClearTask(uint8_t task_id, int32_t)
void Run()
Entry point of the user task.
Tests Wait() timeout when the required flags are never set.
void Run()
Entry point of the user task.
TimeoutTask(uint8_t task_id, int32_t)
Tests TryWait() non-blocking poll.
TryWaitTask(uint8_t task_id, int32_t)
void Run()
Entry point of the user task.
Tests Get() returns a non-destructive snapshot of the flags word.
GetTask(uint8_t task_id, int32_t)
void Run()
Entry point of the user task.
Tests WAIT_ANY with multiple concurrent waiters watching different flag subsets.
MultiWaiterAnyTask(uint8_t task_id, int32_t)
void Run()
Entry point of the user task.
Tests WAIT_ALL with multiple concurrent waiters, each requiring the full flag set.
void Run()
Entry point of the user task.
MultiWaiterAllTask(uint8_t task_id, int32_t consumers)
Tests EventFlags constructed with a non-zero initial flags word.
InitialFlagsTask(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.