Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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:
f7d5bcd35d42 ("selftests: kselftest: Mark functions that unconditionally call exit() as __noreturn")

5d3a9274f0d1 ("kselftest: Add mechanism for reporting a KSFT_ result code")

Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Shuah Khan <skhan@linuxfoundation.org>

Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Mark Brown and committed by
Shuah Khan
6d75d75d dd5a440a

+22
+22
tools/testing/selftests/kselftest.h
··· 20 20 * and finally report the pass/fail/skip/xfail state of the test with one of: 21 21 * 22 22 * ksft_test_result(condition, fmt, ...); 23 + * ksft_test_result_report(result, fmt, ...); 23 24 * ksft_test_result_pass(fmt, ...); 24 25 * ksft_test_result_fail(fmt, ...); 25 26 * ksft_test_result_skip(fmt, ...); ··· 305 304 } 306 305 printf("\n"); 307 306 } 307 + 308 + /** 309 + * ksft_test_result() - Report test success based on truth of condition 310 + * 311 + * @condition: if true, report test success, otherwise failure. 312 + */ 313 + #define ksft_test_result_report(result, fmt, ...) do { \ 314 + switch (result) { \ 315 + case KSFT_PASS: \ 316 + ksft_test_result_pass(fmt, ##__VA_ARGS__); \ 317 + break; \ 318 + case KSFT_FAIL: \ 319 + ksft_test_result_fail(fmt, ##__VA_ARGS__); \ 320 + break; \ 321 + case KSFT_XFAIL: \ 322 + ksft_test_result_xfail(fmt, ##__VA_ARGS__); \ 323 + break; \ 324 + case KSFT_SKIP: \ 325 + ksft_test_result_skip(fmt, ##__VA_ARGS__); \ 326 + break; \ 327 + } } while (0) 308 328 309 329 static inline __noreturn int ksft_exit_pass(void) 310 330 {