Make the ksft_* output functions variadic to allow string formatting directly in these functions. Signed-off-by: Paul Elder <paul.elder@xxxxxxxx> --- Changes from v1: Removed auto-inserted newline character from functions where the caller specifies a message string. tools/testing/selftests/kselftest.h | 55 +++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h index be01f2d15472..a00844e4c915 100644 --- a/tools/testing/selftests/kselftest.h +++ b/tools/testing/selftests/kselftest.h @@ -12,6 +12,7 @@ #include <stdlib.h> #include <unistd.h> +#include <stdarg.h> /* define kselftest exit codes */ #define KSFT_PASS 0 @@ -54,22 +55,40 @@ static inline void ksft_print_cnts(void) printf("1..%d\n", ksft_test_num()); } -static inline void ksft_test_result_pass(const char *msg) +static inline void ksft_test_result_pass(const char *msg, ...) { + va_list args; + ksft_cnt.ksft_pass++; - printf("ok %d %s\n", ksft_test_num(), msg); + + va_start(args, msg); + printf("ok %d ", ksft_test_num()); + vprintf(msg, args); + va_end(args); } -static inline void ksft_test_result_fail(const char *msg) +static inline void ksft_test_result_fail(const char *msg, ...) { + va_list args; + ksft_cnt.ksft_fail++; - printf("not ok %d %s\n", ksft_test_num(), msg); + + va_start(args, msg); + printf("not ok %d ", ksft_test_num()); + vprintf(msg, args); + va_end(args); } -static inline void ksft_test_result_skip(const char *msg) +static inline void ksft_test_result_skip(const char *msg, ...) { + va_list args; + ksft_cnt.ksft_xskip++; - printf("ok %d # skip %s\n", ksft_test_num(), msg); + + va_start(args, msg); + printf("ok %d # skip ", ksft_test_num()); + vprintf(msg, args); + va_end(args); } static inline int ksft_exit_pass(void) @@ -85,9 +104,15 @@ static inline int ksft_exit_fail(void) exit(KSFT_FAIL); } -static inline int ksft_exit_fail_msg(const char *msg) +static inline int ksft_exit_fail_msg(const char *msg, ...) { - printf("Bail out! %s\n", msg); + va_list args; + + va_start(args, msg); + printf("Bail out! "); + vprintf(msg, args); + va_end(args); + ksft_print_cnts(); exit(KSFT_FAIL); } @@ -104,12 +129,18 @@ static inline int ksft_exit_xpass(void) exit(KSFT_XPASS); } -static inline int ksft_exit_skip(const char *msg) +static inline int ksft_exit_skip(const char *msg, ...) { - if (msg) - printf("1..%d # Skipped: %s\n", ksft_test_num(), msg); - else + if (msg) { + va_list args; + + va_start(args, msg); + printf("1..%d # Skipped: ", ksft_test_num()); + vprintf(msg, args); + va_end(args); + } else { ksft_print_cnts(); + } exit(KSFT_SKIP); } -- 2.11.0 -- To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html