PatchworkOS  69292a3
A non-POSIX operating system.
Loading...
Searching...
No Matches

Kernel Test Framework. More...

Collaboration diagram for Test:

Detailed Description

Kernel Test Framework.

Data Structures

struct  test_t
 Structure representing a test case. More...
 

Macros

#define TEST_ALL()
 Run all registered tests in the ._tests section.
 
#define TEST_DEFINE(_name)
 Define a test function to be run by TEST_ALL().
 
#define TEST_ASSERT(cond)
 Assert a condition in a test.
 

Typedefs

typedef uint64_t(* test_func_t) (void)
 Type of a test function.
 

Macro Definition Documentation

◆ TEST_ALL

#define TEST_ALL ( )
Value:
do \
{ \
extern test_t _tests_start; \
extern test_t _tests_end; \
const test_t* test = &_tests_start; \
while (test < &_tests_end) \
{ \
LOG_INFO("running test '%s'\n", test->name); \
uint64_t result = test->func(); \
clock_t end = clock_uptime(); \
if (result == ERR) \
{ \
LOG_ERR("test '%s' FAILED in %llu ms\n", test->name, (end - start) / (CLOCKS_PER_MS)); \
panic(NULL, "test failure"); \
} \
else \
{ \
LOG_INFO("test '%s' passed in %llu ms\n", test->name, (end - start) / (CLOCKS_PER_MS)); \
} \
test++; \
} \
} while (0)
static void start()
Definition main.c:542
#define CLOCKS_PER_MS
Definition clock_t.h:16
clock_t clock_uptime(void)
Retrieve the time in nanoseconds since boot.
Definition clock.c:99
#define NULL
Pointer error value.
Definition NULL.h:25
#define ERR
Integer error value.
Definition ERR.h:17
__UINT64_TYPE__ clock_t
A nanosecond time.
Definition clock_t.h:13
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
Structure representing a test case.
Definition test.h:29
const char * name
Definition test.h:30
test_func_t func
Definition test.h:31

Run all registered tests in the ._tests section.

Definition at line 37 of file test.h.

◆ TEST_DEFINE

#define TEST_DEFINE (   _name)
Value:
uint64_t _test_func_##_name(void); \
const test_t __test_##_name __attribute__((used, section("._tests"))) = { \
.name = #_name, \
.func = _test_func_##_name, \
}; \
uint64_t _test_func_##_name(void)

Define a test function to be run by TEST_ALL().

This will register the test within the current module or if used in the kernel, the kernel itself.

Any module that wants to use the testing framework must call TEST_ALL() on its own.

Parameters
nameThe name of the test function.

Definition at line 71 of file test.h.

◆ TEST_ASSERT

#define TEST_ASSERT (   cond)
Value:
do \
{ \
if (!(cond)) \
{ \
LOG_ERR("TEST_ASSERT failed '%s' at %s:%d\n", #cond, __FILE__, __LINE__); \
return ERR; \
} \
} while (0)

Assert a condition in a test.

Definition at line 82 of file test.h.

Typedef Documentation

◆ test_func_t

typedef uint64_t(* test_func_t) (void)

Type of a test function.

Definition at line 22 of file test.h.