10#include <stk_config.h>
23#define _STK_SL_TEST_TASKS_MAX 5
24#define _STK_SL_TEST_SHORT_SLEEP 10
25#define _STK_SL_TEST_LONG_SLEEP 100
27#define _STK_SL_STACK_SIZE 128
30#define _STK_SL_STACK_SIZE 256
31#define STK_TASK static
61template <EAccessMode _AccessMode>
82 if (++workload % 4 == 0)
100 printf(
"mutual exclusion: counter=%d (expected %d)\n",
115template <EAccessMode _AccessMode>
172 printf(
"try-lock free: counter=%d (expected 4)\n", (
int)
g_SharedCounter);
185template <EAccessMode _AccessMode>
228 printf(
"try-lock contended: counter=%d (expected 2)\n", (
int)
g_SharedCounter);
245template <EAccessMode _AccessMode>
280 printf(
"recursive lock: counter=%d (expected %d)\n",
296template <EAccessMode _AccessMode>
350 printf(
"recursive try-lock: counter=%d (expected 3)\n", (
int)
g_SharedCounter);
365template <EAccessMode _AccessMode>
395 printf(
"yield under contention: counter=%d (expected %d)\n",
410template <EAccessMode _AccessMode>
441 printf(
"unlock transfer: counter=%d (expected %d)\n",
458template <EAccessMode _AccessMode>
501 printf(
"stress test: counter=%d (min expected %d)\n",
526 return (strcmp(test_name,
"TryLockFree") != 0) &&
527 (strcmp(test_name,
"TryLockContended") != 0) &&
528 (strcmp(test_name,
"RecursiveTryLock") != 0);
534template <
class TaskType>
535static int32_t
RunTest(
const char *test_name, int32_t param = 0)
541 printf(
"Test: %s\n", test_name);
549 TaskType task3(3, param);
550 TaskType task4(4, param);
567 printf(
"--------------\n");
584 int total_failures = 0, total_success = 0;
586 printf(
"--------------\n");
590#ifndef __ARM_ARCH_6M__
644 printf(
"##############\n");
645 printf(
"Total tests: %d\n", total_failures + total_success);
646 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::SpinLock.
static int32_t RunTest(const char *test_name, int32_t param=0)
#define _STK_SL_TEST_TASKS_MAX
int main(int argc, char **argv)
static int32_t RunTest(const char *test_name, int32_t param=0)
#define _STK_SL_TEST_LONG_SLEEP
#define _STK_SL_TEST_SHORT_SLEEP
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 Yield()
Notify scheduler to switch to the next runnable task.
void Delay(uint32_t ticks)
Delay calling process by busy-waiting until the deadline expires.
Namespace of the test inventory.
Namespace of SpinLock test.
static volatile int32_t g_SharedCounter
static void ResetTestState()
static volatile bool g_TestComplete
static volatile int32_t g_TestResult
static volatile int32_t g_InstancesDone
static Kernel< KERNEL_DYNAMIC, 5, SwitchStrategyRR, PlatformDefault > g_Kernel
static volatile int32_t g_OrderIndex
static sync::SpinLock g_TestSpinLock
Concrete implementation of IKernel.
Task(const Task &)=delete
Tests that Lock()/Unlock() provides mutual exclusion under concurrent access.
MutualExclusionTask(uint8_t task_id, int32_t iterations)
void Run()
Entry point of the user task.
Tests TryLock() succeeds immediately when the lock is free.
TryLockFreeTask(uint8_t task_id, int32_t)
void Run()
Entry point of the user task.
Tests TryLock() returns false immediately when the lock is held by another task.
TryLockContendedTask(uint8_t task_id, int32_t)
void Run()
Entry point of the user task.
Tests recursive Lock()/Unlock() by the same task.
RecursiveLockTask(uint8_t task_id, int32_t)
void AcquireRecursive(int32_t depth)
void Run()
Entry point of the user task.
Tests TryLock() recursive acquisition by the owning task.
RecursiveTryLockTask(uint8_t task_id, int32_t)
void Run()
Entry point of the user task.
Tests that Lock() yields cooperatively when spin count is exhausted.
void Run()
Entry point of the user task.
YieldUnderContentionTask(uint8_t task_id, int32_t iterations)
Tests that Unlock() correctly transfers the lock to a waiting contender.
void Run()
Entry point of the user task.
UnlockTransferTask(uint8_t task_id, int32_t iterations)
Stress test mixing Lock() and TryLock() 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.