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
stktest.cpp
Go to the documentation of this file.
1/*
2 * SuperTinyKernel(TM) RTOS: Lightweight High-Performance Deterministic C++ RTOS for Embedded Systems.
3 *
4 * Source: https://github.com/SuperTinyKernel-RTOS
5 *
6 * Copyright (c) 2022-2026 Neutron Code Limited <stk@neutroncode.com>. All Rights Reserved.
7 * License: MIT License, see LICENSE for a full text.
8 */
9
10#include "stktest.h"
11#include <CppUTest/CommandLineTestRunner.h>
12
13using namespace stk;
14using namespace stk::test;
15
17void (* g_RelaxCpuHandler)() = NULL;
21bool test::g_InsideISR = false;
22uintptr_t g_Tls = 0;
23
27void STK_ASSERT_HANDLER(const char *message, const char *file, int32_t line)
28{
29 if (g_TestContext.IsExpectingAssert())
30 {
31 #if CPPUTEST_HAVE_EXCEPTIONS
32 if (g_TestContext.IsRethrowingAssertException())
33 throw TestAssertPassed();
34 else
35 return;
36 #else
37 return;
38 #endif
39 }
40
41 SimpleString what = "Assertion failed!\n";
42 what += "\twhat: ";
43 what += message;
44 what += "\n\tfile: ";
45 what += file;
46 what += "\n\tline: ";
47 what += StringFrom(line);
48
49 CHECK_TEXT(false, what.asCharString());
50}
51
56{
57 g_PanicValue = id;
58
59 if (g_TestContext.IsExpectingPanic())
60 return;
61
62 SimpleString what = "Kernel panic!\n";
63 what += "\n\tid: ";
64 what += StringFrom(id);
65
66 CHECK_TEXT(false, what.asCharString());
67}
68
73
84
86{
87 m_lock = true;
88}
90{
91 m_lock = false;
92}
93
94uintptr_t stk::hw::GetTls()
95{
96 return g_Tls;
97}
98void stk::hw::SetTls(uintptr_t tp)
99{
100 g_Tls = tp;
101}
102
104{
105 return g_InsideISR;
106}
107
108int main(int argc, char **argv)
109{
110 (void)argc;
111 (void)argv;
112
114
115 int32_t result = RUN_ALL_TESTS(argc, argv);
116
118
119 return result;
120}
int main(int argc, char **argv)
void STK_ASSERT_HANDLER(const char *message, const char *file, int32_t line)
Definition stktest.cpp:27
void(* g_RelaxCpuHandler)()
__stk_relax_cpu handler.
Definition stktest.cpp:17
uintptr_t g_Tls
Definition stktest.cpp:22
void STK_PANIC_HANDLER_DEFAULT(EKernelPanicId id)
Default panic handler: disable interrupts, record the id, and spin in a tight loop — a defined,...
Definition stktest.cpp:55
Namespace of STK package.
EKernelPanicId
Identifies the source of a kernel panic.
Definition stk_common.h:52
@ KERNEL_PANIC_NONE
Panic is absent (no fault).
Definition stk_common.h:53
void SetTls(Word tp)
Write raw thread-pointer (TP) register used as per-task TLS storage.
Word GetTls()
Read raw thread-pointer (TP) register used as per-task TLS storage.
bool IsInsideISR()
Check whether the CPU is currently executing inside a hardware interrupt service routine (ISR).
Definition stktest.cpp:103
Namespace of the test inventory.
TestContext g_TestContext
Global instance of the TestContext.
Definition stktest.cpp:16
IKernelService * g_KernelService
Definition stktest.cpp:18
int32_t g_CriticalSectionState
Critical section state.
Definition stktest.cpp:19
EKernelPanicId g_PanicValue
Panic value.
Definition stktest.cpp:20
bool g_InsideISR
ISR state.
Definition stktest.cpp:21
static void Exit()
Exit a critical section.
Definition stktest.cpp:78
static void Enter()
Enter a critical section.
Definition stktest.cpp:74
void Lock()
Acquire SpinLock, blocking until it is available.
Definition stktest.cpp:85
void Unlock()
Release SpinLock, allowing another thread or core to acquire it.
Definition stktest.cpp:89
Interface for the kernel services exposed to the user processes during run-time when Kernel started s...
Definition stk_common.h:929
static IKernelService * GetInstance()
Get CPU-local instance of the kernel service.
Definition stktest.cpp:69
Throwable class for catching assertions from STK_ASSERT_HANDLER().
Definition stktest.h:67
Common context for a test suite.
static void ShowTestSuitePrologue()
Show text string as prologue before tests start.
static void ShowTestSuiteEpilogue(int32_t result)
Show text string as epilogue after tests end.