Skip to content

Commit 6d75d75

Browse files
broonieshuahkh
authored andcommitted
kselftest: Add mechanism for reporting a KSFT_ result code
Currently there's no helper which a test can use to report it's result as a KSFT_ result code, we can report a boolean pass/fail but not a skip. This is sometimes a useful idiom so let's add a helper ksft_test_result_report() which translates into the relevant report types. Due to the use of va_args in the result reporting functions this is done as a macro rather than an inline function as one might expect, none of the alternatives looked particularly great. Resolved merge conflict in next betwwen the following commits: f7d5bcd ("selftests: kselftest: Mark functions that unconditionally call exit() as __noreturn") 5d3a927 ("kselftest: Add mechanism for reporting a KSFT_ result code") Reported-by: Stephen Rothwell <[email protected]> Shuah Khan <[email protected]> Signed-off-by: Mark Brown <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent dd5a440 commit 6d75d75

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tools/testing/selftests/kselftest.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* and finally report the pass/fail/skip/xfail state of the test with one of:
2121
*
2222
* ksft_test_result(condition, fmt, ...);
23+
* ksft_test_result_report(result, fmt, ...);
2324
* ksft_test_result_pass(fmt, ...);
2425
* ksft_test_result_fail(fmt, ...);
2526
* ksft_test_result_skip(fmt, ...);
@@ -305,6 +306,27 @@ void ksft_test_result_code(int exit_code, const char *test_name,
305306
printf("\n");
306307
}
307308

309+
/**
310+
* ksft_test_result() - Report test success based on truth of condition
311+
*
312+
* @condition: if true, report test success, otherwise failure.
313+
*/
314+
#define ksft_test_result_report(result, fmt, ...) do { \
315+
switch (result) { \
316+
case KSFT_PASS: \
317+
ksft_test_result_pass(fmt, ##__VA_ARGS__); \
318+
break; \
319+
case KSFT_FAIL: \
320+
ksft_test_result_fail(fmt, ##__VA_ARGS__); \
321+
break; \
322+
case KSFT_XFAIL: \
323+
ksft_test_result_xfail(fmt, ##__VA_ARGS__); \
324+
break; \
325+
case KSFT_SKIP: \
326+
ksft_test_result_skip(fmt, ##__VA_ARGS__); \
327+
break; \
328+
} } while (0)
329+
308330
static inline __noreturn int ksft_exit_pass(void)
309331
{
310332
ksft_print_cnts();

0 commit comments

Comments
 (0)