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

selftests: kselftest framework: provide "finished" helper

Instead of having each time that wants to use ksft_exit() have to figure
out the internals of kselftest.h, add the helper ksft_finished() that
makes sure the passes, xfails, and skips are equal to the test plan count.

Link: https://lkml.kernel.org/r/20220201013717.2464392-1-keescook@chromium.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Kees Cook and committed by
Linus Torvalds
25fd2d41 9457056a

+11 -1
+10
tools/testing/selftests/kselftest.h
··· 28 28 * 29 29 * When all tests are finished, clean up and exit the program with one of: 30 30 * 31 + * ksft_finished(); 31 32 * ksft_exit(condition); 32 33 * ksft_exit_pass(); 33 34 * ksft_exit_fail(); ··· 235 234 else \ 236 235 ksft_exit_fail(); \ 237 236 } while (0) 237 + 238 + /** 239 + * ksft_finished() - Exit selftest with success if all tests passed 240 + */ 241 + #define ksft_finished() \ 242 + ksft_exit(ksft_plan == \ 243 + ksft_cnt.ksft_pass + \ 244 + ksft_cnt.ksft_xfail + \ 245 + ksft_cnt.ksft_xskip) 238 246 239 247 static inline int ksft_exit_fail_msg(const char *msg, ...) 240 248 {
+1 -1
tools/testing/selftests/vm/memfd_secret.c
··· 282 282 283 283 close(fd); 284 284 285 - ksft_exit(!ksft_get_fail_cnt()); 285 + ksft_finished(); 286 286 } 287 287 288 288 #else /* __NR_memfd_secret */