10#include <stk_config.h>
24#define _STK_CV_TEST_TASKS_MAX 5
25#define _STK_CV_TEST_TIMEOUT 300
26#define _STK_CV_TEST_SHORT_SLEEP 10
27#define _STK_CV_TEST_LONG_SLEEP 100
29#define _STK_CV_STACK_SIZE 128
32#define _STK_CV_STACK_SIZE 256
33#define STK_TASK static
37inline void *
operator new(std::size_t,
void *ptr)
noexcept {
return ptr; }
38inline void operator delete(
void *,
void *)
noexcept { }
72template <EAccessMode _AccessMode>
101 printf(
"notify-one wakes: counter=%d (expected %d)\n",
127template <EAccessMode _AccessMode>
152 printf(
"notify-all wakes: counter=%d (expected %d)\n",
175template <EAccessMode _AccessMode>
199 if (!woken && elapsed >= 45 && elapsed <= 65)
227 printf(
"timeout expires: counter=%d (expected 2)\n", (
int)
g_SharedCounter);
243template <EAccessMode _AccessMode>
293 printf(
"mutex reacquired: counter=%d (expected 3)\n", (
int)
g_SharedCounter);
309template <EAccessMode _AccessMode>
329 for (int32_t i = 0; i < consumers; ++i)
341 printf(
"predicate loop: counter=%d (expected %d)\n",
370template <EAccessMode _AccessMode>
389 for (int32_t i = 0; i < consumers; ++i)
402 for (int32_t i = 1; i < consumers; ++i)
411 printf(
"notify-one order: order=[%d,%d,%d,%d], ordered=%d (expected 1)\n",
443template <EAccessMode _AccessMode>
492 printf(
"no-wait timeout: counter=%d (expected 2)\n", (
int)
g_SharedCounter);
508template <EAccessMode _AccessMode>
551 printf(
"stress test: counter=%d (min expected %d)\n",
586 return (strcmp(test_name,
"TimeoutExpires") != 0) &&
587 (strcmp(test_name,
"MutexReacquired") != 0) &&
588 (strcmp(test_name,
"NoWaitTimeout") != 0);
594template <
class TaskType>
595static int32_t
RunTest(
const char *test_name, int32_t param = 0)
601 printf(
"Test: %s\n", test_name);
609 TaskType task3(3, param);
610 TaskType task4(4, param);
627 printf(
"--------------\n");
644 int total_failures = 0, total_success = 0;
646 printf(
"--------------\n");
650#ifndef __ARM_ARCH_6M__
704 printf(
"##############\n");
705 printf(
"Total tests: %d\n", total_failures + total_success);
706 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::ConditionVariable.
Implementation of synchronization primitive: stk::sync::Mutex.
#define _STK_CV_TEST_SHORT_SLEEP
#define _STK_CV_TEST_LONG_SLEEP
int main(int argc, char **argv)
static int32_t RunTest(const char *test_name, int32_t param=0)
#define _STK_CV_TEST_TIMEOUT
static bool NeedsExtendedTasks(const char *test_name)
#define _STK_CV_TEST_TASKS_MAX
#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.
const Timeout NO_WAIT
Timeout value: return immediately if the synchronization object is not yet signaled (non-blocking pol...
Namespace of the test inventory.
Namespace of ConditionVariable test.
static Kernel< KERNEL_DYNAMIC|KERNEL_SYNC, 5, SwitchStrategyRR, PlatformDefault > g_Kernel
static volatile int32_t g_InstancesDone
static volatile bool g_TestComplete
static sync::Mutex g_TestMutex
static volatile int32_t g_OrderIndex
static sync::ConditionVariable g_TestCond
static volatile int32_t g_SharedCounter
static volatile int32_t g_TestResult
static volatile int32_t g_AcquisitionOrder[5]
static void ResetTestState()
Concrete implementation of IKernel.
Task(const Task &)=delete
Condition Variable primitive for signaling between tasks based on specific predicates.
Recursive mutex primitive that allows the same thread to acquire the lock multiple times.
Tests that NotifyOne() wakes exactly one waiting task per call.
void Run()
Entry point of the user task.
NotifyOneWakesTask(uint8_t task_id, int32_t iterations)
Tests that NotifyAll() wakes every waiting task in one call.
void Run()
Entry point of the user task.
NotifyAllWakesTask(uint8_t task_id, int32_t)
Tests that Wait() returns false within the expected time when no notification arrives.
TimeoutExpiresTask(uint8_t task_id, int32_t)
void Run()
Entry point of the user task.
Tests that Wait() atomically releases the mutex and re-acquires it before returning.
MutexReacquiredTask(uint8_t task_id, int32_t)
void Run()
Entry point of the user task.
Tests the canonical spurious-wakeup-safe predicate loop pattern.
void Run()
Entry point of the user task.
PredicateLoopTask(uint8_t task_id, int32_t)
Tests that NotifyOne() releases waiters in FIFO arrival order.
NotifyOneOrderTask(uint8_t task_id, int32_t)
void Run()
Entry point of the user task.
Tests that Wait(NO_WAIT) returns false immediately without blocking.
NoWaitTimeoutTask(uint8_t task_id, int32_t)
void Run()
Entry point of the user task.
Stress test of ConditionVariable under full five-task contention.
void Run()
Entry point of the user task.
StressTestTask(uint8_t task_id, int32_t iterations)
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.