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_timerhost.cpp File Reference
#include <stk_config.h>
#include <stk.h>
#include <time/stk_time_timer.h>
#include <assert.h>
#include <string.h>
#include "stktest_context.h"
Include dependency graph for test_timerhost.cpp:

Go to the source code of this file.

Classes

class  stk::test::timer::TestTimer
 Concrete timer implementation that increments g_ExpiredCount on each expiry. More...
class  stk::test::timer::OneShotTimerTask< _AccessMode >
 Tests that a one-shot timer fires exactly once at the expected time. More...
class  stk::test::timer::PeriodicTimerTask< _AccessMode >
 Tests that a periodic timer fires repeatedly at regular intervals. More...
class  stk::test::timer::MultipleTimersTask< _AccessMode >
 Tests that multiple concurrent timers with different periods fire independently. More...
class  stk::test::timer::StopTimerTask< _AccessMode >
 Tests that Stop() cancels a pending timer before it fires. More...
class  stk::test::timer::ResetPeriodicTimerTask< _AccessMode >
 Tests that Reset() reanchors a periodic timer's deadline from now. More...
class  stk::test::timer::RestartTimerTask< _AccessMode >
 Tests that Restart() atomically stops and re-starts a timer. More...
class  stk::test::timer::StartOrResetTask< _AccessMode >
 Tests StartOrReset(): starts if inactive, resets if active+periodic. More...
class  stk::test::timer::SetPeriodTask< _AccessMode >
 Tests SetPeriod(): changes reload period without affecting current deadline. More...
class  stk::test::timer::StressTestTask< _AccessMode >
 Stress test of TimerHost under full five-task contention. More...

Namespaces

namespace  stk
 Namespace of STK package.
namespace  stk::test
 Namespace of the test inventory.
namespace  stk::test::timer
 Namespace of TimerHost test.

Macros

#define _STK_TIMER_TEST_TIMEOUT   1000
#define _STK_TIMER_TEST_SHORT_SLEEP   10
#define _STK_TIMER_TEST_LONG_SLEEP   100
#define _STK_TIMER_STACK_SIZE   256
#define _STK_TIMER_TEST_TASKS_MAX   5
#define STK_TASK   static

Functions

static void stk::test::timer::ResetTestState ()
static bool NeedsExtendedTasks (const char *test_name)
template<class TaskType>
static int32_t RunTest (const char *test_name, int32_t param=0)
int main (int argc, char **argv)

Variables

 STK_TEST_DECL_ASSERT
static volatile int32_t stk::test::timer::g_TestResult = 0
static volatile int32_t stk::test::timer::g_SharedCounter = 0
static volatile int32_t stk::test::timer::g_ExpiredCount = 0
static sync::Event stk::test::timer::g_LastExpired [5]
static volatile int64_t stk::test::timer::g_ExpiredTime [5] = {0}
static Kernel< KERNEL_DYNAMIC|KERNEL_SYNC, 5+stk::time::TimerHost::TASK_COUNT, SwitchStrategyRR, PlatformDefaultstk::test::timer::g_Kernel
static time::TimerHost stk::test::timer::g_TimerHost

Macro Definition Documentation

◆ _STK_TIMER_STACK_SIZE

#define _STK_TIMER_STACK_SIZE   256

Definition at line 26 of file test_timerhost.cpp.

◆ _STK_TIMER_TEST_LONG_SLEEP

◆ _STK_TIMER_TEST_SHORT_SLEEP

◆ _STK_TIMER_TEST_TASKS_MAX

#define _STK_TIMER_TEST_TASKS_MAX   5

◆ _STK_TIMER_TEST_TIMEOUT

#define _STK_TIMER_TEST_TIMEOUT   1000

Definition at line 23 of file test_timerhost.cpp.

◆ STK_TASK

#define STK_TASK   static

Definition at line 32 of file test_timerhost.cpp.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 738 of file test_timerhost.cpp.

739{
740 (void)argc;
741 (void)argv;
742
743 using namespace stk::test::timer;
744
746
747 int total_failures = 0, total_success = 0;
748
749 printf("--------------\n");
750
751 g_Kernel.Initialize();
752
753#ifndef __ARM_ARCH_6M__
754
755 // Test 1: One-shot timer fires exactly once at expected time
757 total_failures++;
758 else
759 total_success++;
760
761 // Test 2: Periodic timer fires repeatedly at regular intervals
763 total_failures++;
764 else
765 total_success++;
766
767 // Test 3: Multiple concurrent timers with different periods fire independently
769 total_failures++;
770 else
771 total_success++;
772
773 // Test 4: Stop() cancels pending timer before it fires
775 total_failures++;
776 else
777 total_success++;
778
779 // Test 5: Reset() reanchors periodic timer's deadline from now
781 total_failures++;
782 else
783 total_success++;
784
785 // Test 6: Restart() atomically stops and re-starts timer
787 total_failures++;
788 else
789 total_success++;
790
791 // Test 7: StartOrReset() starts if inactive, resets if active+periodic
793 total_failures++;
794 else
795 total_success++;
796
797 // Test 8: SetPeriod() changes reload period without affecting current deadline
799 total_failures++;
800 else
801 total_success++;
802
803#endif // __ARM_ARCH_6M__
804
805 // Test 9: Stress test under full five-task contention with varying timer delays
807 total_failures++;
808 else
809 total_success++;
810
811 g_TimerHost.Shutdown();
812
813 int32_t final_result = (total_failures == 0 ? TestContext::SUCCESS_EXIT_CODE : TestContext::DEFAULT_FAILURE_EXIT_CODE);
814
815 printf("##############\n");
816 printf("Total tests: %d\n", total_failures + total_success);
817 printf("Failures: %d\n", total_failures);
818
820 return final_result;
821}
static int32_t RunTest(const char *test_name, int32_t param=0)
Namespace of TimerHost test.
static time::TimerHost g_TimerHost
static Kernel< KERNEL_DYNAMIC|KERNEL_SYNC, 5+stk::time::TimerHost::TASK_COUNT, SwitchStrategyRR, PlatformDefault > g_Kernel
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.
Tests that a one-shot timer fires exactly once at the expected time.
Tests that a periodic timer fires repeatedly at regular intervals.
Tests that multiple concurrent timers with different periods fire independently.
Tests that Stop() cancels a pending timer before it fires.
Tests that Reset() reanchors a periodic timer's deadline from now.
Tests that Restart() atomically stops and re-starts a timer.
Tests StartOrReset(): starts if inactive, resets if active+periodic.
Tests SetPeriod(): changes reload period without affecting current deadline.
Stress test of TimerHost under full five-task contention.

References stk::test::TestContext::DEFAULT_FAILURE_EXIT_CODE, stk::test::timer::g_Kernel, stk::test::timer::g_TimerHost, 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 683 of file test_timerhost.cpp.

684{
685 return (strcmp(test_name, "StressTest") == 0);
686}

Referenced by RunTest().

Here is the caller graph for this function:

◆ RunTest()

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

Definition at line 692 of file test_timerhost.cpp.

693{
694 using namespace stk;
695 using namespace stk::test;
696 using namespace stk::test::timer;
697
698 printf("Test: %s\n", test_name);
699
701
703
704 // Create tasks based on test type
705 STK_TASK TaskType task0(0, param);
706 STK_TASK TaskType task1(1, param);
707#if (_STK_TIMER_TEST_TASKS_MAX > 2)
708 TaskType task2(2, param);
709 TaskType task3(3, param);
710 TaskType task4(4, param);
711#endif
712
713 g_Kernel.AddTask(&task0);
714 g_Kernel.AddTask(&task1);
715
716#if (_STK_TIMER_TEST_TASKS_MAX > 2)
717 if (NeedsExtendedTasks(test_name))
718 {
719 g_Kernel.AddTask(&task2);
720 g_Kernel.AddTask(&task3);
721 g_Kernel.AddTask(&task4);
722 }
723#endif
724
725 g_Kernel.Start();
726
728
729 printf("Result: %s\n", result == TestContext::SUCCESS_EXIT_CODE ? "PASS" : "FAIL");
730 printf("--------------\n");
731
732 return result;
733}
#define STK_TASK
static bool NeedsExtendedTasks(const char *test_name)
Namespace of STK package.
@ ACCESS_PRIVILEGED
Privileged access mode (access to hardware is fully unrestricted).
Definition stk_common.h:33
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()

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

Here is the call graph for this function:

Variable Documentation

◆ STK_TEST_DECL_ASSERT

STK_TEST_DECL_ASSERT

Definition at line 21 of file test_timerhost.cpp.