ztest: Add config switch for modes of test output

Support verbose or one-line summary at test suite level.
Support verbose or no output at test function level.

Totally 4 combinations configurable:
- function verbose + suite verbose
- function verbose + suite oneline
- no function output + suite verbose
- no function output + suite oneline

Signed-off-by: Ming Shao <ming.shao@intel.com>
This commit is contained in:
Ming Shao 2022-07-21 17:04:57 +08:00 committed by Anas Nashif
parent dc3e86e7dc
commit 5a850a5d06
2 changed files with 53 additions and 7 deletions

View file

@ -121,14 +121,35 @@ static inline void test_time_ms(void)
} while (0)
#endif
static inline void print_nothing(const char *fmt, ...)
{
ARG_UNUSED(fmt);
}
#ifndef TC_PRINT
#if defined(CONFIG_ZTEST_VERBOSE_OUTPUT)
#define TC_PRINT(fmt, ...) PRINT_DATA(fmt, ##__VA_ARGS__)
#else
#define TC_PRINT(fmt, ...) print_nothing(fmt, ##__VA_ARGS__)
#endif
#endif
#ifndef TC_SUMMARY_PRINT
#define TC_SUMMARY_PRINT(fmt, ...) PRINT_DATA(fmt, ##__VA_ARGS__)
#endif
#ifndef TC_START_PRINT
#if defined(CONFIG_ZTEST_VERBOSE_OUTPUT)
#define TC_START_PRINT(name) PRINT_DATA("START - %s\n", name);
#else
#define TC_START_PRINT(name)
#endif
#endif
#ifndef TC_START
#define TC_START(name) \
do { \
PRINT_DATA("START - %s\n", name); \
TC_START_PRINT(name); \
get_start_time_cyc(); \
} while (0)
#endif
@ -137,15 +158,22 @@ static inline void test_time_ms(void)
#define TC_END(result, fmt, ...) PRINT_DATA(fmt, ##__VA_ARGS__)
#endif
#ifndef Z_TC_END_RESULT
#ifndef TC_END_PRINT
#if defined(CONFIG_ZTEST_VERBOSE_OUTPUT)
#define TC_END_PRINT(result, fmt, ...) PRINT_DATA(fmt, ##__VA_ARGS__); PRINT_LINE
#else
#define TC_END_PRINT(result, fmt, ...)
#endif
#endif
/* prints result and the function name */
#ifndef Z_TC_END_RESULT
#define Z_TC_END_RESULT(result, func) \
do { \
test_time_ms(); \
TC_END(result, " %s - %s in %u.%u seconds\n", \
TC_END_PRINT(result, " %s - %s in %u.%u seconds\n", \
TC_RESULT_TO_STR(result), func, tc_spend_time/1000, \
tc_spend_time%1000); \
PRINT_LINE; \
} while (0)
#endif
@ -154,10 +182,14 @@ static inline void test_time_ms(void)
Z_TC_END_RESULT((result), __func__)
#endif
#ifndef TC_SUITE_PRINT
#define TC_SUITE_PRINT(fmt, ...) PRINT_DATA(fmt, ##__VA_ARGS__)
#endif
#ifndef TC_SUITE_START
#define TC_SUITE_START(name) \
do { \
TC_PRINT("Running TESTSUITE %s\n", name); \
TC_SUITE_PRINT("Running TESTSUITE %s\n", name); \
PRINT_LINE; \
} while (0)
#endif
@ -166,9 +198,9 @@ static inline void test_time_ms(void)
#define TC_SUITE_END(name, result) \
do { \
if (result != TC_FAIL) { \
TC_PRINT("TESTSUITE %s succeeded\n", name); \
TC_SUITE_PRINT("TESTSUITE %s succeeded\n", name); \
} else { \
TC_PRINT("TESTSUITE %s failed.\n", name); \
TC_SUITE_PRINT("TESTSUITE %s failed.\n", name); \
} \
} while (0)
#endif

View file

@ -122,6 +122,20 @@ config ZTEST_SHUFFLE_TEST_REPEAT_COUNT
endif #ZTEST_SHUFFLE
config ZTEST_VERBOSE_OUTPUT
bool "Verbose test output"
default y
help
This option controls whether test output is shown verbosely or
no output at all.
config ZTEST_VERBOSE_SUMMARY
bool "Verbose test summary"
default y
help
This option controls whether suite summary is shwon verbosely or
just in one line.
endif # ZTEST_NEW_API
endif # ZTEST