14#define mos_test_log(level, symbol, format, ...) \
17 lprintk(MOS_LOG_UNSET, "\r\n"); \
19 lprintk(MOS_LOG_EMPH, "[%c] ", symbol); \
21 lprintk(MOS_LOG_UNSET, " "); \
22 lprintk(level, format, ##__VA_ARGS__); \
25#define mos_test_log_cont(level, format, ...) lprintk(level, format, ##__VA_ARGS__)
34#define MOS_TEST_DEFINE_CONDITION(condition, message) \
35 const char *const _mt_test_cond_##condition##_message = message; \
38#define MOS_TEST_CONDITIONAL(cond) \
39 for (MOS_TEST_CURRENT_TEST_SKIPPED = !(cond), (*_mt_loop_leave) = false, __extension__({ \
40 if (MOS_TEST_CURRENT_TEST_SKIPPED) \
41 mos_test_log(MOS_LOG_WARN, '\0', "Skipped '%s': condition '%s' not met.", _mt_test_cond_##cond##_message, #cond); \
43 !(*_mt_loop_leave); (*_mt_loop_leave) = true, MOS_TEST_CURRENT_TEST_SKIPPED = false)
45#define MOS_TEST_SKIP() \
48 ++_MT_result->n_total; \
49 ++_MT_result->n_skipped; \
52#define MOS_TEST_CASE(_TestName) \
53 static void _TestName(mos_test_result_t *, bool *, bool *); \
54 static void _MT_WRAP_TEST_NAME(_TestName)(mos_test_result_t * result) \
56 mos_test_log(MOS_LOG_INFO, 'T', "Testing '" #_TestName "'... "); \
57 _MT_RUN_TEST_AND_PRINT_RESULT(result, _TestName); \
59 _MT_REGISTER_TEST_CASE(_TestName, _MT_WRAP_TEST_NAME(_TestName)); \
60 static void _TestName(mos_test_result_t *_MT_result, __maybe_unused bool *_mt_test_skipped, __maybe_unused bool *_mt_loop_leave)
62#define MOS_TEST_DECL_PTEST(_PTestName, ptest_args_printf_format, ...) \
63 static const char *_MT_PTEST_ARG_FORMAT(_PTestName) = "" ptest_args_printf_format ""; \
64 static void _PTestName(mos_test_result_t *_MT_result, __maybe_unused bool *_mt_test_skipped, __maybe_unused bool *_mt_loop_leave, __VA_ARGS__)
66#define MOS_TEST_PTEST_INSTANCE(_PTestName, ...) \
67 static void _MT_PTEST_CALLER(_PTestName)(mos_test_result_t * result, bool *_mt_test_skipped, bool *_mt_loop_leave) \
69 _PTestName(result, _mt_test_skipped, _mt_loop_leave, __VA_ARGS__); \
71 static void _MT_WRAP_PTEST_CALLER(_PTestName)(mos_test_result_t * result) \
73 char __buf[MOS_PRINTK_BUFFER_SIZE] = { 0 }; \
74 snprintf(__buf, MOS_PRINTK_BUFFER_SIZE, _MT_PTEST_ARG_FORMAT(_PTestName), __VA_ARGS__); \
75 mos_test_log(MOS_LOG_INFO, 'P', "Test %s with parameters: ", #_PTestName); \
76 mos_test_log_cont(MOS_LOG_UNSET, "(%s)... ", __buf); \
77 _MT_RUN_TEST_AND_PRINT_RESULT(result, _MT_PTEST_CALLER(_PTestName)); \
79 _MT_REGISTER_TEST_CASE(_TestName, _MT_WRAP_PTEST_CALLER(_PTestName))
81#define MOS_TEST_EXPECT_WARNING_N(N, body, msg) \
84 if (MOS_TEST_CURRENT_TEST_SKIPPED) \
89 test_engine_n_warning_expected = N; \
91 if (test_engine_n_warning_expected != 0) \
92 MOS_TEST_FAIL("%d more expected warning(s) not seen: %s, line %d", test_engine_n_warning_expected, msg, __LINE__); \
95#define MOS_TEST_EXPECT_WARNING(body, msg) MOS_TEST_EXPECT_WARNING_N(1, body, msg)
103#define MOS_TEST_FAIL(format, ...) \
106 ++_MT_result->n_failed; \
107 mos_test_log(MOS_LOG_EMERG, 'X', "line %d: " format, __LINE__, ##__VA_ARGS__); \
118#define MOS_TEST_ASSERT(condition, format, ...) \
121 if (MOS_TEST_CURRENT_TEST_SKIPPED) \
126 ++_MT_result->n_total; \
128 MOS_TEST_FAIL("ASSERTION FAILED: %s, " format, #condition, ##__VA_ARGS__); \
138#define MOS_TEST_CHECK(actual, expected) \
141 if (MOS_TEST_CURRENT_TEST_SKIPPED) \
146 ++_MT_result->n_total; \
147 if ((expected) != (actual)) \
148 MOS_TEST_FAIL("'%s' is %lld, expected %lld", #actual, (s64) (actual), (s64) (expected)); \
158#define MOS_TEST_CHECK_STRING(actual, expected) \
161 if (MOS_TEST_CURRENT_TEST_SKIPPED) \
166 ++_MT_result->n_total; \
167 if (strcmp(expected, actual) != 0) \
168 MOS_TEST_FAIL("values are different (expected = '%s', actual = '%s'), at line %u", (expected), (actual), (__LINE__)); \
179#define MOS_TEST_CHECK_STRING_N(actual, expected, n) \
182 if (MOS_TEST_CURRENT_TEST_SKIPPED) \
187 ++_MT_result->n_total; \
188 if (strncmp(expected, actual, n) != 0) \
189 MOS_TEST_FAIL("values are different (expected = '%.*s', actual = '%.*s'), at line %u", (n), (expected), (n), (actual), (__LINE__)); \
200#define MOS_TEST_CHECK_EPS(actual, expected, epsilon) \
203 if (MOS_TEST_CURRENT_TEST_SKIPPED) \
208 ++_MT_result->n_total; \
209 if (_MT_FLOATABS((expected) - (actual)) > (epsilon)) \
210 MOS_TEST_FAIL("values differ by more then %f (expected = %f, actual = %f)", (epsilon), (expected), (actual)); \
222#define MOS_TEST_CHECK_ARRAY(actual, expected, elements) \
225 if (MOS_TEST_CURRENT_TEST_SKIPPED) \
230 ++_MT_result->n_total; \
231 for (unsigned i = 0; i < (unsigned) (elements); ++i) \
233 if ((expected)[i] != (actual)[i]) \
235 MOS_TEST_FAIL("memories differ at %u-th position (expected = %d, actual = %d)", i, (expected)[i], (actual)[i]); \
251#define MOS_TEST_CHECK_ARRAY_EPS(actual, expected, elements, epsilon) \
254 if (MOS_TEST_CURRENT_TEST_SKIPPED) \
259 ++_MT_result->n_total; \
260 for (unsigned i = 0; i < (unsigned) (elements); ++i) \
262 if (_MT_FLOATABS((expected)[i] - (actual)[i]) > (epsilon)) \
264 MOS_TEST_FAIL("memories differ at %u by more then %f (expected = %f, actual = %f)", i, (epsilon), (expected)[i], (actual)[i]); \
270#define _MT_RUN_TEST_AND_PRINT_RESULT(_ResultVar, _TestFunc) \
273 bool _mt_test_skipped = false; \
274 bool _mt_loop_leave = false; \
275 _TestFunc(_ResultVar, &_mt_test_skipped, &_mt_loop_leave); \
276 u32 total = _ResultVar->n_total; \
277 u32 failed = _ResultVar->n_failed; \
278 u32 skipped = _ResultVar->n_skipped; \
279 u32 passed = total - failed - skipped; \
282 mos_test_log_cont(MOS_LOG_INFO2, "passed (%u tests)", total); \
284 mos_test_log_cont(MOS_LOG_INFO2, "passed (%u tests, %u skipped)", total, skipped); \
286 mos_test_log(MOS_LOG_EMERG, 'X', "%u failed, (%u tests, %u skipped, %u passed)", failed, total, skipped, passed); \
289#define _MT_FLOATABS(a) ((a) < 0 ? -(a) : (a))
291#define MOS_TEST_CURRENT_TEST_SKIPPED (*_mt_test_skipped)
294#define _MT_WRAP_TEST_NAME(test_name) __mos_test_wrapped_test_##test_name
297#define _MT_PTEST_ARG_FORMAT(ptest_name) __mos_test_ptest_args_format_##ptest_name
298#define _MT_PTEST_CALLER(ptest_name) MOS_CONCAT(__mos_test_ptest_caller_##ptest_name, __LINE__)
299#define _MT_WRAP_PTEST_CALLER(ptest_name) MOS_CONCAT(__mos_test_wrapped_ptest_caller_##ptest_name, __LINE__)
308#define _MT_REGISTER_TEST_CASE(_TName, _TFunc) MOS_PUT_IN_SECTION(".mos.test_cases", mos_test_func_t, MOS_CONCAT(test_cases_##_TName##_L, __LINE__), { _TFunc, #_TName })
309#define MOS_TEST_FOREACH_TEST_CASE(_FPtr) for (const mos_test_func_t *_FPtr = __MOS_TEST_CASES_START; _FPtr != __MOS_TEST_CASES_END; _FPtr++)
MOSAPI void(1, 2) fatal_abort(const char *fmt
const mos_test_func_t __MOS_TEST_CASES_START[]
const mos_test_func_t __MOS_TEST_CASES_END[]
s32 test_engine_n_warning_expected