10#include <stk_config.h>
23#define _STK_SEM_TEST_TASKS_MAX 5
24#define _STK_SEM_TEST_TIMEOUT 1000
25#define _STK_SEM_TEST_SHORT_SLEEP 10
26#define _STK_SEM_TEST_LONG_SLEEP 100
28#define _STK_SEM_STACK_SIZE 128
31#define _STK_SEM_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 { }
66template <EAccessMode _AccessMode>
92 printf(
"basic signal/wait: counter=%d (expected %d)\n", (
int)
g_SharedCounter, (
int)expected);
115template <EAccessMode _AccessMode>
146 printf(
"initial count: fast-path counter=%d (expected %d), blocked-wait acquired=%d (expected 0)\n",
160template <EAccessMode _AccessMode>
189 if (!acquired && elapsed >= 45 && elapsed <= 60)
209 printf(
"timeout wait: counter=%d (expected 2)\n", (
int)
g_SharedCounter);
222template <EAccessMode _AccessMode>
262 printf(
"zero-timeout wait: counter=%d (expected 2)\n", (
int)
g_SharedCounter);
275template <EAccessMode _AccessMode>
299 printf(
"signal-before-wait: count_after_signals=%d (expected %d), counter=%d (expected %d)\n",
324template <EAccessMode _AccessMode>
356 printf(
"order violation: position %d has task %d (expected %d)\n",
384template <EAccessMode _AccessMode>
413 for (int32_t i = 0; i < share; ++i)
428 printf(
"stress test: consumed=%d remaining=%d total=%d (expected %d)\n",
429 (
int)total_consumed, (
int)remaining, (
int)(total_consumed + remaining), (
int)
m_iterations);
443template <EAccessMode _AccessMode>
511 return (strcmp(test_name,
"TimeoutWait") != 0) &&
512 (strcmp(test_name,
"ZeroTimeout") != 0) &&
513 (strcmp(test_name,
"SignalBeforeWait") != 0) &&
514 (strcmp(test_name,
"BoundedBuffer") != 0);
520template <
class TaskType>
521static int32_t
RunTest(
const char *test_name, int32_t param = 0, uint32_t initial_count = 0)
527 printf(
"Test: %s\n", test_name);
535 TaskType task3(3, param);
536 TaskType task4(4, param);
553 printf(
"--------------\n");
570 int total_failures = 0, total_success = 0;
572 printf(
"--------------\n");
576#ifndef __ARM_ARCH_6M__
630 printf(
"##############\n");
631 printf(
"Total tests: %d\n", total_failures + total_success);
632 printf(
"Failures: %d\n", (
int)total_failures);
Top-level STK include. Provides the Kernel class template and all built-in task-switching strategies.
Implementation of synchronization primitive: stk::sync::Semaphore.
static int32_t RunTest(const char *test_name, int32_t param=0)
#define _STK_SEM_TEST_SHORT_SLEEP
int main(int argc, char **argv)
static int32_t RunTest(const char *test_name, int32_t param=0, uint32_t initial_count=0)
#define _STK_SEM_TEST_LONG_SLEEP
#define _STK_SEM_TEST_TIMEOUT
#define _STK_SEM_TEST_TASKS_MAX
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.
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 Semaphore test.
static volatile int32_t g_OrderIndex
static volatile int32_t g_AcquisitionOrder[5]
static volatile int32_t g_SharedCounter
static volatile int32_t g_TestResult
static Kernel< KERNEL_DYNAMIC|KERNEL_SYNC, 5, SwitchStrategyRR, PlatformDefault > g_Kernel
static volatile bool g_TestComplete
static void ResetTestState(uint32_t initial_count=0)
static sync::Semaphore g_TestSemaphore
Concrete implementation of IKernel.
Task(const Task &)=delete
Counting semaphore primitive for resource management and signaling.
Tests basic Signal/Wait functionality.
BasicSignalWaitTask(uint8_t task_id, int32_t iterations)
void Run()
Entry point of the user task.
Tests semaphore constructed with a non-zero initial count.
InitialCountTask(uint8_t task_id, int32_t)
void Run()
Entry point of the user task.
Tests Wait() timeout behavior.
TimeoutWaitTask(uint8_t task_id, int32_t)
void Run()
Entry point of the user task.
Tests Wait(0) (NO_WAIT) non-blocking behavior.
ZeroTimeoutTask(uint8_t task_id, int32_t)
void Run()
Entry point of the user task.
Tests that Signal() before Wait() is remembered by the counter.
SignalBeforeWaitTask(uint8_t task_id, int32_t iterations)
void Run()
Entry point of the user task.
Tests FIFO ordering of waiting tasks.
FIFOOrderTask(uint8_t task_id, int32_t)
void Run()
Entry point of the user task.
Stress test with many interleaved Signal/Wait cycles.
void Run()
Entry point of the user task.
StressTestTask(uint8_t task_id, int32_t iterations)
Tests classic producer/consumer synchronization pattern.
void Run()
Entry point of the user task.
BoundedBufferTask(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.