10#include <stk_config.h>
23#define _STK_RWMUTEX_TEST_TASKS_MAX 5
24#define _STK_RWMUTEX_TEST_TIMEOUT 1000
25#define _STK_RWMUTEX_TEST_SHORT_SLEEP 10
26#define _STK_RWMUTEX_TEST_LONG_SLEEP 100
28#define _STK_RWMUTEX_STACK_SIZE 128
31#define _STK_RWMUTEX_STACK_SIZE 256
32#define STK_TASK static
64template <EAccessMode _AccessMode>
84 printf(
"concurrent readers: max=%d (expected %d)\n",
117template <EAccessMode _AccessMode>
130 int32_t workload = 0;
138 if (++workload % 4 == 0)
156 printf(
"writer exclusivity: counter=%d (expected %d)\n",
171template <EAccessMode _AccessMode>
189 printf(
"writer starvation: writer_acquired=%d (expected 1)\n",
233template <EAccessMode _AccessMode>
267 if (!acquired && elapsed >= 45 && elapsed <= 65)
287 printf(
"timed read-lock: counter=%d (expected 3)\n", (
int)
g_SharedCounter);
301template <EAccessMode _AccessMode>
335 if (!acquired && elapsed >= 45 && elapsed <= 65)
355 printf(
"timed write-lock: counter=%d (expected 3)\n", (
int)
g_SharedCounter);
368template <EAccessMode _AccessMode>
421 printf(
"try-read while writer: counter=%d (expected 3)\n", (
int)
g_SharedCounter);
435template <EAccessMode _AccessMode>
487 printf(
"read-unlock wakes writer: counter=%d (expected 2)\n", (
int)
g_SharedCounter);
501template <EAccessMode _AccessMode>
558 printf(
"writer priority: counter=%d (expected 2)\n", (
int)
g_SharedCounter);
572template <EAccessMode _AccessMode>
631 printf(
"reader/writer alternation: max_concurrent=%d (expected >= 2)\n",
647template <EAccessMode _AccessMode>
692 printf(
"stress test: counter=%d (expected %d)\n",
722 return (strcmp(test_name,
"TimedReadLock") != 0) &&
723 (strcmp(test_name,
"TimedWriteLock") != 0) &&
724 (strcmp(test_name,
"TryReadWhileWriter") != 0);
730template <
class TaskType>
731static int32_t
RunTest(
const char *test_name, int32_t param = 0)
737 printf(
"Test: %s\n", test_name);
745 TaskType task3(3, param);
746 TaskType task4(4, param);
763 printf(
"--------------\n");
780 int total_failures = 0, total_success = 0;
782 printf(
"--------------\n");
786#ifndef __ARM_ARCH_6M__
852 printf(
"##############\n");
853 printf(
"Total tests: %d\n", total_failures + total_success);
854 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::RWMutex.
static int32_t RunTest(const char *test_name, int32_t param=0)
int main(int argc, char **argv)
#define _STK_RWMUTEX_TEST_LONG_SLEEP
static int32_t RunTest(const char *test_name, int32_t param=0)
#define _STK_RWMUTEX_TEST_TASKS_MAX
#define _STK_RWMUTEX_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 RWMutex test.
static volatile int32_t g_SharedCounter
static volatile int32_t g_InstancesDone
static volatile bool g_TestComplete
static sync::RWMutex g_TestRWMutex
static volatile int32_t g_WriterCount
static volatile int32_t g_ReaderCount
static Kernel< KERNEL_DYNAMIC|KERNEL_SYNC, 5, SwitchStrategyRR, PlatformDefault > g_Kernel
static volatile int32_t g_TestResult
static void ResetTestState()
static volatile int32_t g_MaxConcurrent
Concrete implementation of IKernel.
Task(const Task &)=delete
Reader-Writer Lock synchronization primitive for non-recursive shared and exclusive access.
Tests that multiple readers can acquire ReadLock() simultaneously.
ConcurrentReadersTask(uint8_t task_id, int32_t)
void Run()
Entry point of the user task.
Tests that writer Lock()/Unlock() provides mutual exclusion.
void Run()
Entry point of the user task.
WriterExclusivityTask(uint8_t task_id, int32_t iterations)
Tests writer preference policy: writers don't starve under reader flood.
void Run()
Entry point of the user task.
WriterStarvationTask(uint8_t task_id, int32_t)
Tests TimedReadLock() timeout behavior.
TimedReadLockTask(uint8_t task_id, int32_t)
void Run()
Entry point of the user task.
Tests TimedLock() timeout behavior for writers.
void Run()
Entry point of the user task.
TimedWriteLockTask(uint8_t task_id, int32_t)
Tests TryReadLock() returns false when writer is active; true after release.
void Run()
Entry point of the user task.
TryReadLockWhileWriterTask(uint8_t task_id, int32_t)
Tests that the last reader releasing wakes a waiting writer immediately.
void Run()
Entry point of the user task.
ReadUnlockWakesWriterTask(uint8_t task_id, int32_t)
Tests writer preference policy: new readers are blocked when writers are waiting.
WriterPriorityTask(uint8_t task_id, int32_t)
void Run()
Entry point of the user task.
Tests alternating read and write phases with multiple concurrent readers.
void Run()
Entry point of the user task.
ReaderWriterAlternationTask(uint8_t task_id, int32_t)
Stress test mixing readers and writers 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.