MOS Source Code
Loading...
Searching...
No Matches
test_engine.c
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2
4#include "test_engine_impl.h"
5
7#include <mos/misc/cmdline.h>
8#include <mos/misc/panic.h>
9#include <mos/misc/setup.h>
10#include <mos/syslog/printk.h>
11#include <mos_stdio.h>
12#include <mos_stdlib.h>
13#include <mos_string.h>
14
16
17static void test_engine_warning_handler(const char *func, u32 line, const char *fmt, va_list args)
18{
19 char message[MOS_PRINTK_BUFFER_SIZE];
21
23 {
24 lprintk(MOS_LOG_WARN, "\r\n");
25 lprintk(MOS_LOG_WARN, "warning: %s", message);
26 lprintk(MOS_LOG_WARN, " in function: %s (line %u)", func, line);
27 mos_panic("unexpected warning, test failed.");
28 }
29
31}
32
33static const char **test_engine_skip_prefix_list = NULL;
34static bool mos_tests_halt_on_success = false;
35
36static bool mos_test_engine_setup_skip_prefix_list(const char *arg)
37{
38 // split the argument into a list of strings
39 int argc = 1;
40 for (int i = 0; arg[i]; i++)
41 if (arg[i] == ',')
42 argc++;
43
44 test_engine_skip_prefix_list = kmalloc(sizeof(char *) * argc);
45
46 int i = 0;
47 char *token = strtok((char *) arg, ",");
48 while (token)
49 {
51 token = strtok(NULL, ",");
52 i++;
53 }
54
55 return true;
56}
57
59
60static bool mos_tests_setup_halt_on_success(const char *arg)
61{
63 return true;
64}
65
66MOS_SETUP("mos_tests_halt_on_success", mos_tests_setup_halt_on_success);
67
68static bool mos_test_engine_should_skip(const char *test_name)
69{
71 return false;
72
73 for (int i = 0; test_engine_skip_prefix_list[i]; i++)
74 {
76 return true;
77 }
78
79 return false;
80}
81
82static bool mos_test_engine_run_tests(const char *arg)
83{
84 MOS_UNUSED(arg);
86
87 mos_test_result_t result = { 0 };
88
90 {
91 bool should_skip = mos_test_engine_should_skip(test_case->test_name);
92
93 if (should_skip)
94 continue;
95
96 mos_test_result_t r = { 0 };
97 test_case->test_func(&r);
98
99 result.n_total += r.n_total;
100 result.n_failed += r.n_failed;
101 result.n_skipped += r.n_skipped;
102
103 if (result.n_failed > 0)
104 mos_panic("TEST FAILED.");
105 }
106
108
109 u32 passed = result.n_total - result.n_failed - result.n_skipped;
110 pr_emph("ALL %u TESTS PASSED: (%u succeed, %u failed, %u skipped)", result.n_total, passed, result.n_failed, result.n_skipped);
111
114
115 return true;
116}
117
void platform_halt_cpu(void)
Definition mm.c:65
u32 line
Definition assert.h:36
u32 const char * fmt
Definition assert.h:36
#define MOS_PRINTK_BUFFER_SIZE
Definition autoconf.h:19
char args[3][16]
Definition avr_io.c:16
MOSAPI char * strtok(char *str, const char *delim)
Definition mos_string.c:281
MOSAPI s32 strncmp(const char *str1, const char *str2, size_t n)
Definition mos_string.c:32
MOSAPI int vsnprintf(char *__restrict buf, size_t size, const char *__restrict format, va_list args)
size_t argc
Definition kmain.c:43
bool cmdline_string_truthiness(const char *arg, bool default_value)
Definition cmdline.c:83
#define MOS_UNUSED(x)
Definition mos_global.h:64
void kwarn_handler_set(kmsg_handler_t *handler)
Definition panic.c:36
#define mos_panic(fmt,...)
Definition panic.h:55
void kwarn_handler_remove(void)
Definition panic.c:42
#define NULL
Definition pb_syshdr.h:46
static size_t strlen(const char *s)
Definition pb_syshdr.h:80
#define pr_emph(fmt,...)
Definition printk.h:37
void lprintk(loglevel_t loglevel, const char *format,...)
Definition printk.c:111
#define MOS_SETUP(_param, _fn)
Definition setup.h:35
@ MOS_LOG_WARN
Definition syslog.h:12
static const char ** test_engine_skip_prefix_list
Definition test_engine.c:33
static bool mos_tests_setup_halt_on_success(const char *arg)
Definition test_engine.c:60
static bool mos_test_engine_run_tests(const char *arg)
Definition test_engine.c:82
static bool mos_tests_halt_on_success
Definition test_engine.c:34
static bool mos_test_engine_setup_skip_prefix_list(const char *arg)
Definition test_engine.c:36
static void test_engine_warning_handler(const char *func, u32 line, const char *fmt, va_list args)
Definition test_engine.c:17
s32 test_engine_n_warning_expected
Definition test_engine.c:15
static bool mos_test_engine_should_skip(const char *test_name)
Definition test_engine.c:68
#define MOS_TEST_FOREACH_TEST_CASE(_FPtr)
signed int s32
Definition types.h:15
unsigned int u32
Definition types.h:21