testsuite: Factor out suite header/footer to tc_util.h

We have a few remaining tests where ztest module is not used directly,
and instead lower-level tc_util.h is used (where ztest also uses that
header). Supposedly, there're good reasons for that. However, tc_util.h
tests have output which is somewhat inconsistent with ztest output,
which may be a problem with automated parsing of test results, e.g. in
CI systems.

So, factor out code to mark testsuite start/end from ztest.c to
tc_util.h as TC_SUITE_START() and TC_SUITE_END() macros, to allow
tc_util.h based tests to produce output fully consistent with
ztest, while avoiding duplicate of code. TC_SUITE_END() accepts
result code (TC_PASS/TC_FAIL), similar to existing TC_END_REPORT().

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
This commit is contained in:
Paul Sokolovsky 2021-04-27 19:07:52 +03:00 committed by Anas Nashif
commit 92ba428626
2 changed files with 21 additions and 7 deletions

View file

@ -154,6 +154,25 @@ static inline void test_time_ms(void)
Z_TC_END_RESULT((result), __func__)
#endif
#ifndef TC_SUITE_START
#define TC_SUITE_START(name) \
do { \
TC_PRINT("Running test suite %s\n", name); \
PRINT_LINE; \
} while (0)
#endif
#ifndef TC_SUITE_END
#define TC_SUITE_END(name, result) \
do { \
if (result == TC_PASS) { \
TC_PRINT("Test suite %s succeeded\n", name); \
} else { \
TC_PRINT("Test suite %s failed.\n", name); \
} \
} while (0)
#endif
#if defined(CONFIG_ARCH_POSIX)
#define TC_END_POST(result) posix_exit(result)
#else

View file

@ -372,8 +372,7 @@ void z_ztest_run_test_suite(const char *name, struct unit_test *suite)
init_testing();
PRINT("Running test suite %s\n", name);
PRINT_LINE;
TC_SUITE_START(name);
while (suite->test) {
fail += run_test(suite);
suite++;
@ -382,11 +381,7 @@ void z_ztest_run_test_suite(const char *name, struct unit_test *suite)
break;
}
}
if (fail) {
TC_PRINT("Test suite %s failed.\n", name);
} else {
TC_PRINT("Test suite %s succeeded\n", name);
}
TC_SUITE_END(name, (fail > 0 ? TC_FAIL : TC_PASS));
test_status = (test_status || fail) ? 1 : 0;
}