From bb63d87b4b8da882ffbc5764446218e9221946c3 Mon Sep 17 00:00:00 2001 From: Ming Shao Date: Thu, 21 Jul 2022 17:04:57 +0800 Subject: [PATCH] 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 --- subsys/testsuite/include/zephyr/tc_util.h | 61 ++++++++++++++++++++--- subsys/testsuite/ztest/Kconfig | 14 ++++++ 2 files changed, 68 insertions(+), 7 deletions(-) diff --git a/subsys/testsuite/include/zephyr/tc_util.h b/subsys/testsuite/include/zephyr/tc_util.h index dd87aac2095..95bec0becc5 100644 --- a/subsys/testsuite/include/zephyr/tc_util.h +++ b/subsys/testsuite/include/zephyr/tc_util.h @@ -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 diff --git a/subsys/testsuite/ztest/Kconfig b/subsys/testsuite/ztest/Kconfig index 2fba41170ad..91dc1f0dfa5 100644 --- a/subsys/testsuite/ztest/Kconfig +++ b/subsys/testsuite/ztest/Kconfig @@ -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