SuperTinyKernel™ RTOS 1.05.3
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
test_eventflags.cpp File Reference
#include <stk_config.h>
#include <stk.h>
#include <sync/stk_sync_eventflags.h>
#include <assert.h>
#include <string.h>
#include "stktest_context.h"
Include dependency graph for test_eventflags.cpp:

Go to the source code of this file.

Classes

class  stk::test::eventflags::SetWaitAnyTask< _AccessMode >
 Tests WAIT_ANY (OR) semantics: a single flag unblocks a waiting task. More...
class  stk::test::eventflags::SetWaitAllTask< _AccessMode >
 Tests WAIT_ALL (AND) semantics: all requested flags must be set before unblocking. More...
class  stk::test::eventflags::ClearTask< _AccessMode >
 Tests Clear() return value and effect on subsequent Wait() calls. More...
class  stk::test::eventflags::NoClearTask< _AccessMode >
 Tests NO_CLEAR option: matched flags are not consumed after a successful Wait(). More...
class  stk::test::eventflags::TimeoutTask< _AccessMode >
 Tests Wait() timeout when the required flags are never set. More...
class  stk::test::eventflags::TryWaitTask< _AccessMode >
 Tests TryWait() non-blocking poll. More...
class  stk::test::eventflags::GetTask< _AccessMode >
 Tests Get() returns a non-destructive snapshot of the flags word. More...
class  stk::test::eventflags::MultiWaiterAnyTask< _AccessMode >
 Tests WAIT_ANY with multiple concurrent waiters watching different flag subsets. More...
class  stk::test::eventflags::MultiWaiterAllTask< _AccessMode >
 Tests WAIT_ALL with multiple concurrent waiters, each requiring the full flag set. More...
class  stk::test::eventflags::InitialFlagsTask< _AccessMode >
 Tests EventFlags constructed with a non-zero initial flags word. More...

Namespaces

namespace  stk
 Namespace of STK package.
namespace  stk::test
 Namespace of the test inventory.
namespace  stk::test::eventflags
 Namespace of EventFlags test.

Macros

#define _STK_EF_TEST_TASKS_MAX   5
#define _STK_EF_TEST_TIMEOUT   300
#define _STK_EF_TEST_SHORT_SLEEP   10
#define _STK_EF_TEST_LONG_SLEEP   100
#define _STK_EF_STACK_SIZE   256
#define STK_TASK   static

Functions

void * operator new (std::size_t, void *ptr) noexcept
void operator delete (void *, void *) noexcept
static void stk::test::eventflags::ResetTestState (uint32_t initial_flags=0U)
static bool NeedsExtendedTasks (const char *test_name)
template<class TaskType>
static int32_t RunTest (const char *test_name, int32_t param=0, uint32_t initial_flags=0U)
int main (int argc, char **argv)

Variables

 STK_TEST_DECL_ASSERT
static const uint32_t FLAG_A = (1U << 0)
static const uint32_t FLAG_B = (1U << 1)
static const uint32_t FLAG_C = (1U << 2)
static const uint32_t FLAG_D = (1U << 3)
static volatile int32_t stk::test::eventflags::g_TestResult = 0
static volatile int32_t stk::test::eventflags::g_SharedCounter = 0
static volatile bool stk::test::eventflags::g_TestComplete = false
static Kernel< KERNEL_DYNAMIC|KERNEL_SYNC, 5, SwitchStrategyRR, PlatformDefaultstk::test::eventflags::g_Kernel
static sync::EventFlags stk::test::eventflags::g_Flags

Macro Definition Documentation

◆ _STK_EF_STACK_SIZE

#define _STK_EF_STACK_SIZE   256

Definition at line 31 of file test_eventflags.cpp.

◆ _STK_EF_TEST_LONG_SLEEP

◆ _STK_EF_TEST_SHORT_SLEEP

◆ _STK_EF_TEST_TASKS_MAX

#define _STK_EF_TEST_TASKS_MAX   5

◆ _STK_EF_TEST_TIMEOUT

◆ STK_TASK

#define STK_TASK   static

Definition at line 32 of file test_eventflags.cpp.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 711 of file test_eventflags.cpp.

712{
713 (void)argc;
714 (void)argv;
715
716 using namespace stk::test::eventflags;
717
719
720 int total_failures = 0, total_success = 0;
721
722 printf("--------------\n");
723
724 g_Kernel.Initialize();
725
726 // Test 1: WAIT_ANY — one Set() unblocks exactly one consumer per call
728 total_failures++;
729 else
730 total_success++;
731
732#ifndef __ARM_ARCH_6M__
733
734 // Test 2: WAIT_ALL — Wait() blocks until all requested bits are simultaneously set
736 total_failures++;
737 else
738 total_success++;
739
740 // Test 3: Clear() returns pre-clear value; cleared bits block subsequent waiters
742 total_failures++;
743 else
744 total_success++;
745
746 // Test 4: NO_CLEAR option — matched flags are not consumed; next Wait() still succeeds
748 total_failures++;
749 else
750 total_success++;
751
752 // Test 5: Wait() returns ERROR_TIMEOUT within the expected window when flags are never set
754 total_failures++;
755 else
756 total_success++;
757
758 // Test 6: TryWait() returns immediately; auto-clears on success; fails when flags absent
760 total_failures++;
761 else
762 total_success++;
763
764 // Test 7: Get() is non-destructive; reflects Set() and Clear() without consuming flags
766 total_failures++;
767 else
768 total_success++;
769
770 // Test 8: Multiple concurrent WAIT_ANY waiters, each with a unique flag bit
772 total_failures++;
773 else
774 total_success++;
775
776 // Test 9: Multiple concurrent WAIT_ALL waiters — all must eventually receive the full mask
778 total_failures++;
779 else
780 total_success++;
781
782 // Test 10: Constructor initial_flags — fast-path Wait() succeeds; cleared flag then times out
784 total_failures++;
785 else
786 total_success++;
787
788#endif // __ARM_ARCH_6M__
789
790 int32_t final_result = (total_failures == 0 ? TestContext::SUCCESS_EXIT_CODE : TestContext::DEFAULT_FAILURE_EXIT_CODE);
791
792 printf("##############\n");
793 printf("Total tests: %d\n", total_failures + total_success);
794 printf("Failures: %d\n", total_failures);
795
797 return final_result;
798}
static int32_t RunTest(const char *test_name, int32_t param=0)
#define _STK_EF_TEST_TASKS_MAX
static const uint32_t FLAG_A
Namespace of EventFlags test.
static Kernel< KERNEL_DYNAMIC|KERNEL_SYNC, 5, SwitchStrategyRR, PlatformDefault > g_Kernel
Tests WAIT_ANY (OR) semantics: a single flag unblocks a waiting task.
Tests WAIT_ALL (AND) semantics: all requested flags must be set before unblocking.
Tests Clear() return value and effect on subsequent Wait() calls.
Tests NO_CLEAR option: matched flags are not consumed after a successful Wait().
Tests Wait() timeout when the required flags are never set.
Tests TryWait() non-blocking poll.
Tests Get() returns a non-destructive snapshot of the flags word.
Tests WAIT_ANY with multiple concurrent waiters watching different flag subsets.
Tests WAIT_ALL with multiple concurrent waiters, each requiring the full flag set.
Tests EventFlags constructed with a non-zero initial flags word.
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.

References _STK_EF_TEST_TASKS_MAX, stk::test::TestContext::DEFAULT_FAILURE_EXIT_CODE, FLAG_A, stk::test::eventflags::g_Kernel, RunTest(), stk::test::TestContext::ShowTestSuiteEpilogue(), stk::test::TestContext::ShowTestSuitePrologue(), and stk::test::TestContext::SUCCESS_EXIT_CODE.

Here is the call graph for this function:

◆ NeedsExtendedTasks()

bool NeedsExtendedTasks ( const char * test_name)
static

Definition at line 653 of file test_eventflags.cpp.

654{
655 return (strcmp(test_name, "SetWaitAll") != 0) &&
656 (strcmp(test_name, "Clear") != 0) &&
657 (strcmp(test_name, "NoClear") != 0) &&
658 (strcmp(test_name, "Timeout") != 0) &&
659 (strcmp(test_name, "TryWait") != 0) &&
660 (strcmp(test_name, "Get") != 0) &&
661 (strcmp(test_name, "InitialFlags") != 0);
662}

Referenced by RunTest().

Here is the caller graph for this function:

◆ operator delete()

void operator delete ( void * ,
void *  )
inlinenoexcept

Definition at line 37 of file test_eventflags.cpp.

37{ /* nothing for placement delete */ }

◆ operator new()

void * operator new ( std::size_t ,
void * ptr )
inlinenoexcept

Definition at line 36 of file test_eventflags.cpp.

36{ return ptr; }

◆ RunTest()

template<class TaskType>
int32_t RunTest ( const char * test_name,
int32_t param = 0,
uint32_t initial_flags = 0U )
static

Definition at line 668 of file test_eventflags.cpp.

669{
670 using namespace stk;
671 using namespace stk::test;
672 using namespace stk::test::eventflags;
673
674 printf("Test: %s\n", test_name);
675
676 ResetTestState(initial_flags);
677
678 STK_TASK TaskType task0(0, param);
679 STK_TASK TaskType task1(1, param);
680 STK_TASK TaskType task2(2, param);
681 TaskType task3(3, param);
682 TaskType task4(4, param);
683
684 g_Kernel.AddTask(&task0);
685 g_Kernel.AddTask(&task1);
686 g_Kernel.AddTask(&task2);
687
688 if (NeedsExtendedTasks(test_name))
689 {
690 g_Kernel.AddTask(&task3);
691 g_Kernel.AddTask(&task4);
692 }
693
694 g_Kernel.Start();
695
697
698 printf("Result: %s\n", result == TestContext::SUCCESS_EXIT_CODE ? "PASS" : "FAIL");
699 printf("--------------\n");
700
701 return result;
702}
#define STK_TASK
static bool NeedsExtendedTasks(const char *test_name)
Namespace of STK package.
Namespace of the test inventory.
static TestTask< ACCESS_PRIVILEGED > task3(2)
static TestTask< ACCESS_PRIVILEGED > task2(1)
static volatile int32_t g_TestResult
static void ResetTestState(uint32_t initial_flags=0U)

References stk::test::TestContext::DEFAULT_FAILURE_EXIT_CODE, stk::test::eventflags::g_Kernel, stk::test::eventflags::g_TestResult, NeedsExtendedTasks(), stk::test::eventflags::ResetTestState(), STK_TASK, and stk::test::TestContext::SUCCESS_EXIT_CODE.

Here is the call graph for this function:

Variable Documentation

◆ FLAG_A

◆ FLAG_B

◆ FLAG_C

◆ FLAG_D

◆ STK_TEST_DECL_ASSERT

STK_TEST_DECL_ASSERT

Definition at line 21 of file test_eventflags.cpp.