MOS Source Code
Loading...
Searching...
No Matches
test_engine_impl.h File Reference
#include <mos/mos_global.h>
#include <mos/types.h>
#include <mos_stdio.h>
#include <mos_string.h>
#include <stdbool.h>
+ Include dependency graph for test_engine_impl.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  mos_test_result_t
 
struct  mos_test_func_t
 

Macros

#define mos_test_log(level, symbol, format, ...)
 
#define mos_test_log_cont(level, format, ...)
 
#define MOS_TEST_DEFINE_CONDITION(condition, message)
 
#define MOS_TEST_CONDITIONAL(cond)
 
#define MOS_TEST_SKIP()
 
#define MOS_TEST_CASE(_TestName)
 
#define MOS_TEST_DECL_PTEST(_PTestName, ptest_args_printf_format, ...)
 
#define MOS_TEST_PTEST_INSTANCE(_PTestName, ...)
 
#define MOS_TEST_EXPECT_WARNING_N(N, body, msg)
 
#define MOS_TEST_EXPECT_WARNING(body, msg)
 
#define MOS_TEST_FAIL(format, ...)
 
#define MOS_TEST_ASSERT(condition, format, ...)
 
#define MOS_TEST_CHECK(actual, expected)
 
#define MOS_TEST_CHECK_STRING(actual, expected)
 
#define MOS_TEST_CHECK_STRING_N(actual, expected, n)
 
#define MOS_TEST_CHECK_EPS(actual, expected, epsilon)
 
#define MOS_TEST_CHECK_ARRAY(actual, expected, elements)
 
#define MOS_TEST_CHECK_ARRAY_EPS(actual, expected, elements, epsilon)
 
#define _MT_RUN_TEST_AND_PRINT_RESULT(_ResultVar, _TestFunc)
 
#define _MT_FLOATABS(a)
 
#define MOS_TEST_CURRENT_TEST_SKIPPED   (*_mt_test_skipped)
 
#define _MT_WRAP_TEST_NAME(test_name)
 
#define _MT_PTEST_ARG_FORMAT(ptest_name)
 
#define _MT_PTEST_CALLER(ptest_name)
 
#define _MT_WRAP_PTEST_CALLER(ptest_name)
 
#define _MT_REGISTER_TEST_CASE(_TName, _TFunc)
 
#define MOS_TEST_FOREACH_TEST_CASE(_FPtr)
 

Variables

s32 test_engine_n_warning_expected
 
const mos_test_func_t __MOS_TEST_CASES_START []
 
const mos_test_func_t __MOS_TEST_CASES_END []
 

Macro Definition Documentation

◆ mos_test_log

#define mos_test_log ( level,
symbol,
format,
... )
Value:
do \
{ \
lprintk(MOS_LOG_UNSET, "\r\n"); \
if (symbol) \
lprintk(MOS_LOG_EMPH, "[%c] ", symbol); \
else \
lprintk(MOS_LOG_UNSET, " "); \
lprintk(level, format, ##__VA_ARGS__); \
} while (0)
MOSAPI const char *__restrict format
Definition mos_stdio.h:17
@ MOS_LOG_EMPH
Definition syslog.h:13
@ MOS_LOG_UNSET
Definition syslog.h:16

Definition at line 14 of file test_engine_impl.h.

◆ mos_test_log_cont

#define mos_test_log_cont ( level,
format,
... )
Value:
lprintk(level, format, ##__VA_ARGS__)
void lprintk(loglevel_t loglevel, const char *format,...)
Definition printk.c:111

Definition at line 25 of file test_engine_impl.h.

◆ MOS_TEST_DEFINE_CONDITION

#define MOS_TEST_DEFINE_CONDITION ( condition,
message )
Value:
const char *const _mt_test_cond_##condition##_message = message; \
static bool condition

Definition at line 34 of file test_engine_impl.h.

◆ MOS_TEST_CONDITIONAL

#define MOS_TEST_CONDITIONAL ( cond)
Value:
for (MOS_TEST_CURRENT_TEST_SKIPPED = !(cond), (*_mt_loop_leave) = false, __extension__({ \
mos_test_log(MOS_LOG_WARN, '\0', "Skipped '%s': condition '%s' not met.", _mt_test_cond_##cond##_message, #cond); \
}); \
!(*_mt_loop_leave); (*_mt_loop_leave) = true, MOS_TEST_CURRENT_TEST_SKIPPED = false)
@ MOS_LOG_WARN
Definition syslog.h:12
#define MOS_TEST_CURRENT_TEST_SKIPPED

Definition at line 38 of file test_engine_impl.h.

Referenced by MOS_TEST_CASE().

◆ MOS_TEST_SKIP

#define MOS_TEST_SKIP ( )
Value:
do \
{ \
++_MT_result->n_total; \
++_MT_result->n_skipped; \
} while (0)

Definition at line 45 of file test_engine_impl.h.

◆ MOS_TEST_CASE

#define MOS_TEST_CASE ( _TestName)
Value:
static void _TestName(mos_test_result_t *, bool *, bool *); \
static void _MT_WRAP_TEST_NAME(_TestName)(mos_test_result_t * result) \
{ \
mos_test_log(MOS_LOG_INFO, 'T', "Testing '" #_TestName "'... "); \
_MT_RUN_TEST_AND_PRINT_RESULT(result, _TestName); \
} \
_MT_REGISTER_TEST_CASE(_TestName, _MT_WRAP_TEST_NAME(_TestName)); \
static void _TestName(mos_test_result_t *_MT_result, __maybe_unused bool *_mt_test_skipped, __maybe_unused bool *_mt_loop_leave)
#define __maybe_unused
Definition mos_global.h:33
@ MOS_LOG_INFO
Definition syslog.h:14
#define _MT_WRAP_TEST_NAME(test_name)

Definition at line 52 of file test_engine_impl.h.

◆ MOS_TEST_DECL_PTEST

#define MOS_TEST_DECL_PTEST ( _PTestName,
ptest_args_printf_format,
... )
Value:
static const char *_MT_PTEST_ARG_FORMAT(_PTestName) = "" ptest_args_printf_format ""; \
static void _PTestName(mos_test_result_t *_MT_result, __maybe_unused bool *_mt_test_skipped, __maybe_unused bool *_mt_loop_leave, __VA_ARGS__)
#define _MT_PTEST_ARG_FORMAT(ptest_name)

Definition at line 62 of file test_engine_impl.h.

◆ MOS_TEST_PTEST_INSTANCE

#define MOS_TEST_PTEST_INSTANCE ( _PTestName,
... )
Value:
static void _MT_PTEST_CALLER(_PTestName)(mos_test_result_t * result, bool *_mt_test_skipped, bool *_mt_loop_leave) \
{ \
_PTestName(result, _mt_test_skipped, _mt_loop_leave, __VA_ARGS__); \
} \
static void _MT_WRAP_PTEST_CALLER(_PTestName)(mos_test_result_t * result) \
{ \
char __buf[MOS_PRINTK_BUFFER_SIZE] = { 0 }; \
snprintf(__buf, MOS_PRINTK_BUFFER_SIZE, _MT_PTEST_ARG_FORMAT(_PTestName), __VA_ARGS__); \
mos_test_log(MOS_LOG_INFO, 'P', "Test %s with parameters: ", #_PTestName); \
mos_test_log_cont(MOS_LOG_UNSET, "(%s)... ", __buf); \
_MT_RUN_TEST_AND_PRINT_RESULT(result, _MT_PTEST_CALLER(_PTestName)); \
} \
_MT_REGISTER_TEST_CASE(_TestName, _MT_WRAP_PTEST_CALLER(_PTestName))
#define MOS_PRINTK_BUFFER_SIZE
Definition autoconf.h:19
#define _MT_PTEST_CALLER(ptest_name)
#define _MT_WRAP_PTEST_CALLER(ptest_name)

Definition at line 66 of file test_engine_impl.h.

◆ MOS_TEST_EXPECT_WARNING_N

#define MOS_TEST_EXPECT_WARNING_N ( N,
body,
msg )
Value:
do \
{ \
{ \
MOS_TEST_SKIP(); \
break; \
} \
body; \
MOS_TEST_FAIL("%d more expected warning(s) not seen: %s, line %d", test_engine_n_warning_expected, msg, __LINE__); \
} while (0)
s32 test_engine_n_warning_expected
Definition test_engine.c:15

Definition at line 81 of file test_engine_impl.h.

Referenced by MOS_TEST_CASE().

◆ MOS_TEST_EXPECT_WARNING

#define MOS_TEST_EXPECT_WARNING ( body,
msg )
Value:
#define MOS_TEST_EXPECT_WARNING_N(N, body, msg)

Definition at line 95 of file test_engine_impl.h.

Referenced by MOS_TEST_CASE(), MOS_TEST_CASE(), and MOS_TEST_CASE().

◆ MOS_TEST_FAIL

#define MOS_TEST_FAIL ( format,
... )
Value:
do \
{ \
++_MT_result->n_failed; \
mos_test_log(MOS_LOG_EMERG, 'X', "line %d: " format, __LINE__, ##__VA_ARGS__); \
} while (false)
@ MOS_LOG_EMERG
Definition syslog.h:11

Definition at line 103 of file test_engine_impl.h.

◆ MOS_TEST_ASSERT

#define MOS_TEST_ASSERT ( condition,
format,
... )
Value:
do \
{ \
{ \
MOS_TEST_SKIP(); \
break; \
} \
++_MT_result->n_total; \
if (!(condition)) \
MOS_TEST_FAIL("ASSERTION FAILED: %s, " format, #condition, ##__VA_ARGS__); \
} while (false)

Definition at line 118 of file test_engine_impl.h.

Referenced by __mos_test_wrapped_test_kmalloc_a_lot(), __mos_test_wrapped_test_kmalloc_large(), __mos_test_wrapped_test_kmalloc_single(), __mos_test_wrapped_test_kmalloc_stress(), and MOS_TEST_DECL_PTEST().

◆ MOS_TEST_CHECK

#define MOS_TEST_CHECK ( actual,
expected )
Value:
do \
{ \
{ \
MOS_TEST_SKIP(); \
break; \
} \
++_MT_result->n_total; \
if ((expected) != (actual)) \
MOS_TEST_FAIL("'%s' is %lld, expected %lld", #actual, (s64) (actual), (s64) (expected)); \
} while (false)
signed long long int s64
Definition types.h:17

Definition at line 138 of file test_engine_impl.h.

Referenced by __mos_test_wrapped_test_hashmap_foreach_function(), __mos_test_wrapped_test_hashmap_get_function(), __mos_test_wrapped_test_hashmap_init_simple_macro(), __mos_test_wrapped_test_hashmap_put_multiple(), __mos_test_wrapped_test_hashmap_put_overflow(), __mos_test_wrapped_test_hashmap_put_single(), __mos_test_wrapped_test_hashmap_remove_function(), __mos_test_wrapped_test_multi_args_with_multiple_options(), __mos_test_wrapped_test_one_arg_with_an_option(), __mos_test_wrapped_test_one_arg_with_multiple_options(), __mos_test_wrapped_test_quotation_with_escaped_quotation_marks(), __mos_test_wrapped_test_quoted_args(), __mos_test_wrapped_test_quoted_args_with_spaces(), __mos_test_wrapped_test_quoted_args_with_spaces_and_commas(), __mos_test_wrapped_test_quoted_args_with_spaces_and_commas_and_equals(), __mos_test_wrapped_test_simple_cmdline(), __mos_test_wrapped_test_stack_init_deinit(), __mos_test_wrapped_test_stack_push_pop_stack(), MOS_TEST_CASE(), MOS_TEST_CASE(), MOS_TEST_CASE(), MOS_TEST_CASE(), MOS_TEST_CASE(), MOS_TEST_CASE(), MOS_TEST_CASE(), MOS_TEST_CASE(), MOS_TEST_CASE(), MOS_TEST_CASE(), MOS_TEST_CASE(), MOS_TEST_CASE(), MOS_TEST_CASE(), MOS_TEST_CASE(), MOS_TEST_CASE(), MOS_TEST_CASE(), MOS_TEST_CASE(), MOS_TEST_CASE(), MOS_TEST_CASE(), and MOS_TEST_CASE().

◆ MOS_TEST_CHECK_STRING

◆ MOS_TEST_CHECK_STRING_N

#define MOS_TEST_CHECK_STRING_N ( actual,
expected,
n )
Value:
do \
{ \
{ \
MOS_TEST_SKIP(); \
break; \
} \
++_MT_result->n_total; \
if (strncmp(expected, actual, n) != 0) \
MOS_TEST_FAIL("values are different (expected = '%.*s', actual = '%.*s'), at line %u", (n), (expected), (n), (actual), (__LINE__)); \
} while (false);
MOSAPI s32 strncmp(const char *str1, const char *str2, size_t n)
Definition mos_string.c:32

Definition at line 179 of file test_engine_impl.h.

Referenced by MOS_TEST_CASE().

◆ MOS_TEST_CHECK_EPS

#define MOS_TEST_CHECK_EPS ( actual,
expected,
epsilon )
Value:
do \
{ \
{ \
MOS_TEST_SKIP(); \
break; \
} \
++_MT_result->n_total; \
if (_MT_FLOATABS((expected) - (actual)) > (epsilon)) \
MOS_TEST_FAIL("values differ by more then %f (expected = %f, actual = %f)", (epsilon), (expected), (actual)); \
} while (false)
#define _MT_FLOATABS(a)

Definition at line 200 of file test_engine_impl.h.

◆ MOS_TEST_CHECK_ARRAY

#define MOS_TEST_CHECK_ARRAY ( actual,
expected,
elements )
Value:
do \
{ \
{ \
MOS_TEST_SKIP(); \
break; \
} \
++_MT_result->n_total; \
for (unsigned i = 0; i < (unsigned) (elements); ++i) \
{ \
if ((expected)[i] != (actual)[i]) \
{ \
MOS_TEST_FAIL("memories differ at %u-th position (expected = %d, actual = %d)", i, (expected)[i], (actual)[i]); \
break; \
} \
} \
} while (false)

Definition at line 222 of file test_engine_impl.h.

◆ MOS_TEST_CHECK_ARRAY_EPS

#define MOS_TEST_CHECK_ARRAY_EPS ( actual,
expected,
elements,
epsilon )
Value:
do \
{ \
{ \
MOS_TEST_SKIP(); \
break; \
} \
++_MT_result->n_total; \
for (unsigned i = 0; i < (unsigned) (elements); ++i) \
{ \
if (_MT_FLOATABS((expected)[i] - (actual)[i]) > (epsilon)) \
{ \
MOS_TEST_FAIL("memories differ at %u by more then %f (expected = %f, actual = %f)", i, (epsilon), (expected)[i], (actual)[i]); \
break; \
} \
} \
} while (false)

Definition at line 251 of file test_engine_impl.h.

◆ _MT_RUN_TEST_AND_PRINT_RESULT

#define _MT_RUN_TEST_AND_PRINT_RESULT ( _ResultVar,
_TestFunc )
Value:
do \
{ \
bool _mt_test_skipped = false; \
bool _mt_loop_leave = false; \
_TestFunc(_ResultVar, &_mt_test_skipped, &_mt_loop_leave); \
u32 total = _ResultVar->n_total; \
u32 failed = _ResultVar->n_failed; \
u32 skipped = _ResultVar->n_skipped; \
u32 passed = total - failed - skipped; \
if (failed == 0) \
if (skipped == 0) \
mos_test_log_cont(MOS_LOG_INFO2, "passed (%u tests)", total); \
else \
mos_test_log_cont(MOS_LOG_INFO2, "passed (%u tests, %u skipped)", total, skipped); \
else \
mos_test_log(MOS_LOG_EMERG, 'X', "%u failed, (%u tests, %u skipped, %u passed)", failed, total, skipped, passed); \
} while (0)
@ MOS_LOG_INFO2
Definition syslog.h:15
unsigned int u32
Definition types.h:21

Definition at line 270 of file test_engine_impl.h.

◆ _MT_FLOATABS

#define _MT_FLOATABS ( a)
Value:
((a) < 0 ? -(a) : (a))

Definition at line 289 of file test_engine_impl.h.

◆ MOS_TEST_CURRENT_TEST_SKIPPED

#define MOS_TEST_CURRENT_TEST_SKIPPED   (*_mt_test_skipped)

Definition at line 291 of file test_engine_impl.h.

◆ _MT_WRAP_TEST_NAME

#define _MT_WRAP_TEST_NAME ( test_name)
Value:
__mos_test_wrapped_test_##test_name

Definition at line 294 of file test_engine_impl.h.

◆ _MT_PTEST_ARG_FORMAT

#define _MT_PTEST_ARG_FORMAT ( ptest_name)
Value:
__mos_test_ptest_args_format_##ptest_name

Definition at line 297 of file test_engine_impl.h.

◆ _MT_PTEST_CALLER

#define _MT_PTEST_CALLER ( ptest_name)
Value:
MOS_CONCAT(__mos_test_ptest_caller_##ptest_name, __LINE__)
#define MOS_CONCAT(a, b)
Definition mos_global.h:67

Definition at line 298 of file test_engine_impl.h.

◆ _MT_WRAP_PTEST_CALLER

#define _MT_WRAP_PTEST_CALLER ( ptest_name)
Value:
MOS_CONCAT(__mos_test_wrapped_ptest_caller_##ptest_name, __LINE__)

Definition at line 299 of file test_engine_impl.h.

◆ _MT_REGISTER_TEST_CASE

#define _MT_REGISTER_TEST_CASE ( _TName,
_TFunc )
Value:
MOS_PUT_IN_SECTION(".mos.test_cases", mos_test_func_t, MOS_CONCAT(test_cases_##_TName##_L, __LINE__), { _TFunc, #_TName })
#define MOS_PUT_IN_SECTION(_section, _struct, _var,...)
Definition mos_global.h:125

Definition at line 308 of file test_engine_impl.h.

◆ MOS_TEST_FOREACH_TEST_CASE

#define MOS_TEST_FOREACH_TEST_CASE ( _FPtr)
Value:
for (const mos_test_func_t *_FPtr = __MOS_TEST_CASES_START; _FPtr != __MOS_TEST_CASES_END; _FPtr++)
const mos_test_func_t __MOS_TEST_CASES_START[]
const mos_test_func_t __MOS_TEST_CASES_END[]

Definition at line 309 of file test_engine_impl.h.

Referenced by mos_test_engine_run_tests().

Variable Documentation

◆ test_engine_n_warning_expected

s32 test_engine_n_warning_expected
extern

Definition at line 15 of file test_engine.c.

Referenced by test_engine_warning_handler().

◆ __MOS_TEST_CASES_START

const mos_test_func_t __MOS_TEST_CASES_START[]
extern

◆ __MOS_TEST_CASES_END

const mos_test_func_t __MOS_TEST_CASES_END[]
extern