10#include <stk_config.h>
23#define _STK_MUTEX_TEST_TASKS_MAX 5
24#define _STK_MUTEX_TEST_TIMEOUT 1000
25#define _STK_MUTEX_TEST_SHORT_SLEEP 10
26#define _STK_MUTEX_TEST_LONG_SLEEP 100
28#define _STK_MUTEX_STACK_SIZE 128
31#define _STK_MUTEX_STACK_SIZE 256
32#define STK_TASK static
62template <EAccessMode _AccessMode>
83 if (++workload % 4 == 0)
104 printf(
"basic lock/unlock: counter=%d (expected %d)\n", (
int)
g_SharedCounter, (
int)expected);
116template <EAccessMode _AccessMode>
152 printf(
"recursive lock/unlock: counter=%d (expected %d)\n", (
int)
g_SharedCounter, (
int)expected);
164template <EAccessMode _AccessMode>
212template <EAccessMode _AccessMode>
242 if (!acquired && elapsed >= 45 && elapsed <= 60)
280template <EAccessMode _AccessMode>
328 printf(
"Order violation: position %d has task %d (expected %d)\n",
344template <EAccessMode _AccessMode>
412template <EAccessMode _AccessMode>
447 printf(
"recursive depth: counter=%d (expected %d)\n", (
int)
g_SharedCounter, (
int)expected);
459template <EAccessMode _AccessMode>
471 for (int32_t round = 0; round < 10; ++round)
500 printf(
"Coordination test: counter=%d (expected %d)\n",
529 return (strcmp(test_name,
"TryLock") != 0) &&
530 (strcmp(test_name,
"TimedLock") != 0);
539 return (strcmp(test_name,
"TryLock") != 0);
545template <
class TaskType>
546static int32_t
RunTest(
const char *test_name, int32_t param = 0)
552 printf(
"Test: %s\n", test_name);
559 TaskType task2(2, param);
560 TaskType task3(3, param);
561 TaskType task4(4, param);
580 printf(
"--------------\n");
597 int total_failures = 0, total_success = 0;
599 printf(
"--------------\n");
603#ifndef __ARM_ARCH_6M__
657 printf(
"##############\n");
658 printf(
"Total tests: %d\n", total_failures + total_success);
659 printf(
"Failures: %d\n", (
int)total_failures);
Top-level STK include. Provides the Kernel class template and all built-in task-switching strategies.
#define STK_TICKLESS_IDLE
Enables tickless (dynamic-tick) low-power operation during idle periods.
Implementation of synchronization primitive: stk::sync::Mutex.
static int32_t RunTest(const char *test_name, int32_t param=0)
#define _STK_MUTEX_TEST_LONG_SLEEP
#define _STK_MUTEX_TEST_TASKS_MAX
int main(int argc, char **argv)
static bool NeedsThreeTasks(const char *test_name)
static int32_t RunTest(const char *test_name, int32_t param=0)
#define _STK_MUTEX_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.
PlatformArmCortexM PlatformDefault
Default platform implementation.
SwitchStrategyRoundRobin SwitchStrategyRR
Shorthand alias for SwitchStrategyRoundRobin.
@ KERNEL_TICKLESS
Tickless mode. To use this mode STK_TICKLESS_IDLE must be defined to 1 in stk_config....
@ KERNEL_SYNC
Synchronization support (see Event).
@ KERNEL_DYNAMIC
Tasks can be added or removed and therefore exit when done.
Namespace of the test inventory.
static volatile int32_t g_InstancesDone
static volatile int32_t g_OrderIndex
static volatile int32_t g_TestResult
static volatile int32_t g_SharedCounter
static Kernel< KERNEL_DYNAMIC|KERNEL_SYNC|(STK_TICKLESS_IDLE ? KERNEL_TICKLESS :0), 5, SwitchStrategyRR, PlatformDefault > g_Kernel
static volatile bool g_TestComplete
static volatile int32_t g_AcquisitionOrder[5]
static void ResetTestState()
static sync::Mutex g_TestMutex
Concrete implementation of IKernel.
Task(const Task &)=delete
Recursive mutex primitive that allows the same thread to acquire the lock multiple times.
Tests basic lock/unlock functionality.
void Run()
Entry point of the user task.
BasicLockUnlockTask(uint8_t task_id, int32_t iterations)
Tests recursive locking capability.
RecursiveLockTask(uint8_t task_id, int32_t)
void Run()
Entry point of the user task.
Tests TryLock() non-blocking behavior.
void Run()
Entry point of the user task.
TryLockTask(uint8_t task_id, int32_t)
Tests TimedLock() timeout behavior.
void Run()
Entry point of the user task.
TimedLockTask(uint8_t task_id, int32_t)
Tests FIFO ordering of waiting threads.
FIFOOrderTask(uint8_t task_id, int32_t)
void Run()
Entry point of the user task.
Stress test with many lock/unlock cycles.
void Run()
Entry point of the user task.
StressTestTask(uint8_t task_id, int32_t iterations)
Tests deep recursive locking.
void Run()
Entry point of the user task.
RecursiveDepthTask(uint8_t task_id, int32_t)
void RecursiveLock(int32_t depth)
Tests mutex for coordinating work between tasks.
InterTaskCoordinationTask(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.