diff options
author | Paul Elder <paul.elder@pitt.edu> | 2017-06-28 10:40:20 -0400 |
---|---|---|
committer | Shuah Khan <shuahkh@osg.samsung.com> | 2017-06-30 18:14:55 -0400 |
commit | 151b2732111f0743e764a7bc62d4f580341a62f3 (patch) | |
tree | 8040c7e514545b2e04512f4499f88286151ec2ae /tools | |
parent | 796a3bae2fba6810427efdb314a1c126c9490fb3 (diff) |
kselftest: make ksft_* output functions variadic
Make the ksft_* output functions variadic to allow string formatting
directly in these functions.
Signed-off-by: Paul Elder <paul.elder@pitt.edu>
Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/testing/selftests/kselftest.h | 55 |
1 files 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 @@ | |||
12 | 12 | ||
13 | #include <stdlib.h> | 13 | #include <stdlib.h> |
14 | #include <unistd.h> | 14 | #include <unistd.h> |
15 | #include <stdarg.h> | ||
15 | 16 | ||
16 | /* define kselftest exit codes */ | 17 | /* define kselftest exit codes */ |
17 | #define KSFT_PASS 0 | 18 | #define KSFT_PASS 0 |
@@ -54,22 +55,40 @@ static inline void ksft_print_cnts(void) | |||
54 | printf("1..%d\n", ksft_test_num()); | 55 | printf("1..%d\n", ksft_test_num()); |
55 | } | 56 | } |
56 | 57 | ||
57 | static inline void ksft_test_result_pass(const char *msg) | 58 | static inline void ksft_test_result_pass(const char *msg, ...) |
58 | { | 59 | { |
60 | va_list args; | ||
61 | |||
59 | ksft_cnt.ksft_pass++; | 62 | ksft_cnt.ksft_pass++; |
60 | printf("ok %d %s\n", ksft_test_num(), msg); | 63 | |
64 | va_start(args, msg); | ||
65 | printf("ok %d ", ksft_test_num()); | ||
66 | vprintf(msg, args); | ||
67 | va_end(args); | ||
61 | } | 68 | } |
62 | 69 | ||
63 | static inline void ksft_test_result_fail(const char *msg) | 70 | static inline void ksft_test_result_fail(const char *msg, ...) |
64 | { | 71 | { |
72 | va_list args; | ||
73 | |||
65 | ksft_cnt.ksft_fail++; | 74 | ksft_cnt.ksft_fail++; |
66 | printf("not ok %d %s\n", ksft_test_num(), msg); | 75 | |
76 | va_start(args, msg); | ||
77 | printf("not ok %d ", ksft_test_num()); | ||
78 | vprintf(msg, args); | ||
79 | va_end(args); | ||
67 | } | 80 | } |
68 | 81 | ||
69 | static inline void ksft_test_result_skip(const char *msg) | 82 | static inline void ksft_test_result_skip(const char *msg, ...) |
70 | { | 83 | { |
84 | va_list args; | ||
85 | |||
71 | ksft_cnt.ksft_xskip++; | 86 | ksft_cnt.ksft_xskip++; |
72 | printf("ok %d # skip %s\n", ksft_test_num(), msg); | 87 | |
88 | va_start(args, msg); | ||
89 | printf("ok %d # skip ", ksft_test_num()); | ||
90 | vprintf(msg, args); | ||
91 | va_end(args); | ||
73 | } | 92 | } |
74 | 93 | ||
75 | static inline int ksft_exit_pass(void) | 94 | static inline int ksft_exit_pass(void) |
@@ -85,9 +104,15 @@ static inline int ksft_exit_fail(void) | |||
85 | exit(KSFT_FAIL); | 104 | exit(KSFT_FAIL); |
86 | } | 105 | } |
87 | 106 | ||
88 | static inline int ksft_exit_fail_msg(const char *msg) | 107 | static inline int ksft_exit_fail_msg(const char *msg, ...) |
89 | { | 108 | { |
90 | printf("Bail out! %s\n", msg); | 109 | va_list args; |
110 | |||
111 | va_start(args, msg); | ||
112 | printf("Bail out! "); | ||
113 | vprintf(msg, args); | ||
114 | va_end(args); | ||
115 | |||
91 | ksft_print_cnts(); | 116 | ksft_print_cnts(); |
92 | exit(KSFT_FAIL); | 117 | exit(KSFT_FAIL); |
93 | } | 118 | } |
@@ -104,12 +129,18 @@ static inline int ksft_exit_xpass(void) | |||
104 | exit(KSFT_XPASS); | 129 | exit(KSFT_XPASS); |
105 | } | 130 | } |
106 | 131 | ||
107 | static inline int ksft_exit_skip(const char *msg) | 132 | static inline int ksft_exit_skip(const char *msg, ...) |
108 | { | 133 | { |
109 | if (msg) | 134 | if (msg) { |
110 | printf("1..%d # Skipped: %s\n", ksft_test_num(), msg); | 135 | va_list args; |
111 | else | 136 | |
137 | va_start(args, msg); | ||
138 | printf("1..%d # Skipped: ", ksft_test_num()); | ||
139 | vprintf(msg, args); | ||
140 | va_end(args); | ||
141 | } else { | ||
112 | ksft_print_cnts(); | 142 | ksft_print_cnts(); |
143 | } | ||
113 | exit(KSFT_SKIP); | 144 | exit(KSFT_SKIP); |
114 | } | 145 | } |
115 | 146 | ||