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_context.h
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#ifndef STKTEST_CONTEX_H_
11#define STKTEST_CONTEX_H_
12
13#include <stdio.h>
14#include <stdlib.h>
15#include <stdint.h>
16#include <exception>
17
18namespace stk {
19namespace test {
20
25{
26public:
32
34 {}
35
39 void ExpectAssert(bool expect) { m_expect_assert = expect; }
40
43 bool IsExpectingAssert() const { return m_expect_assert; }
44
48 void ExpectPanic(bool expect) { m_expect_panic = expect; }
49
52 bool IsExpectingPanic() const { return m_expect_panic; }
53
57 void RethrowAssertException(bool rethrow) { m_rethrow_assert = rethrow; }
58
62
65 static inline void ShowTestSuitePrologue()
66 {
67 // required to show log in Eclipse IDE Console for 64-bit binary
68 #if defined(_WIN32) || defined(WIN32)
69 setbuf(stdout, NULL);
70 #endif
71
72 printf("STKTEST-START\n");
73 }
74
78 static inline void ShowTestSuiteEpilogue(int32_t result)
79 {
80 printf("STKTEST-RESULT: %d\n", (int)result);
81 }
82
86 static inline void ForceExitTestSuite(int32_t result)
87 {
89 exit(result);
90 }
91
92private:
97};
98
103
107#define STK_TEST_CHECK_EQUAL(expected, actual)\
108 if ((expected) != (actual)) {\
109 printf("STK_TEST_CHECK_EQUAL failed!\n file: %s\n line: %d\n expected: %d\n actual: %d\n", __FILE__, __LINE__, (int)expected, (int)actual);\
110 __stk_debug_break();\
111 exit(1);\
112 }
113
117#define STK_TEST_DECL_ASSERT\
118 extern void STK_ASSERT_HANDLER(const char *message, const char *file, int32_t line)\
119 {\
120 printf("_STK_ASSERT failed!\n file: %s\n line: %d\n message: %s\n", file, (int)line, message);\
121 __stk_debug_break();\
122 abort();\
123 }
124
125} // namespace test
126} // namespace stk
127
128#endif /* STKTEST_CONTEX_H_ */
Namespace of STK package.
Namespace of the test inventory.
TestContext g_TestContext
Global instance of the TestContext.
Definition stktest.cpp:16
Common context for a test suite.
bool IsExpectingPanic() const
Check if test case is expecting kernel panic.
void ExpectPanic(bool expect)
Start expecting kernel panic for the test case.
bool m_rethrow_assert
rethrow assert's exception
static void ShowTestSuitePrologue()
Show text string as prologue before tests start.
static TestContext m_instance
global instance of the TestContext
void ExpectAssert(bool expect)
Start expecting assertion for the test case.
void RethrowAssertException(bool rethrow)
Re-throw assert's exception for the test case.
bool IsRethrowingAssertException() const
Check if exception must be thrown if assertion is hit.
static void ForceExitTestSuite(int32_t result)
Exit test suite process forcibly.
@ 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.
bool IsExpectingAssert() const
Check if test case is expecting assertion.
bool m_expect_assert
assert expectation flag
bool m_expect_panic
panic expectation flag