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
commit bb63d87b4b
2 changed files with 68 additions and 7 deletions

View file

@ -121,14 +121,46 @@ static inline void test_time_ms(void)
} while (0)
#endif
static inline void print_nothing(const char *fmt, ...)
{
ARG_UNUSED(fmt);
}
#ifndef TC_PRINT
/* Need to check for CONFIG_ZTEST_NEW_API since the TC_PRINT
* is also used by the old ztest.
*/
#ifdef CONFIG_ZTEST_NEW_API
#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 /* CONFIG_ZTEST_VERBOSE_OUTPUT */
#else
#define TC_PRINT(fmt, ...) PRINT_DATA(fmt, ##__VA_ARGS__)
#endif /* CONFIG_ZTEST_NEW_API */
#endif /* TC_PRINT */
#ifndef TC_SUMMARY_PRINT
#define TC_SUMMARY_PRINT(fmt, ...) PRINT_DATA(fmt, ##__VA_ARGS__)
#endif
#ifndef TC_START_PRINT
#ifdef CONFIG_ZTEST_NEW_API
#if defined(CONFIG_ZTEST_VERBOSE_OUTPUT)
#define TC_START_PRINT(name) PRINT_DATA("START - %s\n", name);
#else
#define TC_START_PRINT(name) print_nothing(name)
#endif /* CONFIG_ZTEST_VERBOSE_OUTPUT */
#else
#define TC_START_PRINT(name) PRINT_DATA("START - %s\n", name);
#endif /* CONFIG_ZTEST_NEW_API */
#endif /* TC_START_PRINT */
#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 +169,26 @@ 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
#ifdef CONFIG_ZTEST_NEW_API
#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, ...) print_nothing(fmt)
#endif /* CONFIG_ZTEST_VERBOSE_OUTPUT */
#else
#define TC_END_PRINT(result, fmt, ...) PRINT_DATA(fmt, ##__VA_ARGS__); PRINT_LINE
#endif /* CONFIG_ZTEST_NEW_API */
#endif /* TC_END_PRINT */
/* 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 +197,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 +213,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

@ -128,6 +128,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 shown verbosely or
just in one line.
endif # ZTEST_NEW_API
config TEST_LOGGING_FLUSH_AFTER_TEST