10#include <stk_config.h>
23#define _STK_PIPE_TEST_TASKS_MAX 5
24#define _STK_PIPE_TEST_TIMEOUT 300
25#define _STK_PIPE_TEST_SHORT_SLEEP 10
26#define _STK_PIPE_TEST_LONG_SLEEP 100
27#define _STK_PIPE_CAPACITY 8
29#define _STK_PIPE_STACK_SIZE 128
32#define _STK_PIPE_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 { }
67template <EAccessMode _AccessMode>
88 printf(
"basic write/read: counter=%d (expected %d)\n",
115template <EAccessMode _AccessMode>
142 printf(
"write blocks when full: counter=%d (expected %d)\n",
166template <EAccessMode _AccessMode>
187 printf(
"read blocks when empty: counter=%d (expected 1)\n", (
int)
g_SharedCounter);
210template <EAccessMode _AccessMode>
230 if (!ok && elapsed >= 45 && elapsed <= 65)
248 if (!ok && elapsed >= 45 && elapsed <= 65)
273template <EAccessMode _AccessMode>
297 printf(
"bulk write/read: written=%d, counter=%d (expected %d)\n",
312 bool all_correct =
true;
337template <EAccessMode _AccessMode>
394 printf(
"get-size/is-empty: counter=%d (expected 1)\n", (
int)
g_SharedCounter);
409template <EAccessMode _AccessMode>
450 printf(
"multi producer/consumer: counter=%d (expected %d)\n",
467template <EAccessMode _AccessMode>
481 int32_t consumed = 0;
513 int32_t remaining = (int32_t)
g_TestPipe.GetSize();
515 printf(
"stress test: net_written=%d remaining=%d (expected: remaining >= 0)\n",
547 return (strcmp(test_name,
"BasicWriteRead") != 0) &&
548 (strcmp(test_name,
"WriteBlocksWhenFull") != 0) &&
549 (strcmp(test_name,
"ReadBlocksWhenEmpty") != 0) &&
550 (strcmp(test_name,
"Timeout") != 0) &&
551 (strcmp(test_name,
"BulkWriteRead") != 0) &&
552 (strcmp(test_name,
"GetSizeIsEmpty") != 0);
558template <
class TaskType>
559static int32_t
RunTest(
const char *test_name, int32_t param = 0)
565 printf(
"Test: %s\n", test_name);
573 TaskType task3(3, param);
574 TaskType task4(4, param);
591 printf(
"--------------\n");
608 int total_failures = 0, total_success = 0;
610 printf(
"--------------\n");
614#ifndef __ARM_ARCH_6M__
668 printf(
"##############\n");
669 printf(
"Total tests: %d\n", total_failures + total_success);
670 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::Pipe.
static int32_t RunTest(const char *test_name, int32_t param=0)
#define _STK_PIPE_TEST_TASKS_MAX
#define _STK_PIPE_TEST_LONG_SLEEP
#define _STK_PIPE_TEST_TIMEOUT
int main(int argc, char **argv)
#define _STK_PIPE_CAPACITY
static int32_t RunTest(const char *test_name, int32_t param=0)
#define _STK_PIPE_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.
Namespace of the test inventory.
static Kernel< KERNEL_DYNAMIC|KERNEL_SYNC, 5, SwitchStrategyRR, PlatformDefault > g_Kernel
static sync::Pipe< int32_t, 8 > g_TestPipe
static volatile int32_t g_InstancesDone
static volatile int32_t g_SharedCounter
static volatile bool g_TestComplete
static void ResetTestState()
static volatile int32_t g_TestResult
Concrete implementation of IKernel.
Task(const Task &)=delete
Thread-safe FIFO communication pipe for inter-task data passing.
Tests basic Write()/Read() functionality in producer-consumer arrangement.
void Run()
Entry point of the user task.
BasicWriteReadTask(uint8_t task_id, int32_t iterations)
Tests that Write() blocks when the pipe is full and unblocks when space is freed.
void Run()
Entry point of the user task.
WriteBlocksWhenFullTask(uint8_t task_id, int32_t)
Tests that Read() blocks when the pipe is empty and unblocks when data arrives.
ReadBlocksWhenEmptyTask(uint8_t task_id, int32_t)
void Run()
Entry point of the user task.
Tests that Write() and Read() return false within the expected time on timeout.
TimeoutTask(uint8_t task_id, int32_t)
void Run()
Entry point of the user task.
Tests WriteBulk()/ReadBulk() for multi-element block transfers.
BulkWriteReadTask(uint8_t task_id, int32_t iterations)
void Run()
Entry point of the user task.
Tests GetSize() and IsEmpty() reflect accurate pipe state.
GetSizeIsEmptyTask(uint8_t task_id, int32_t)
void Run()
Entry point of the user task.
Tests concurrent multi-producer / multi-consumer throughput.
MultiProducerConsumerTask(uint8_t task_id, int32_t iterations)
void Run()
Entry point of the user task.
Stress test of Pipe under full five-task contention.
StressTestTask(uint8_t task_id, int32_t iterations)
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.