Skip to content

Commit 25fd2d4

Browse files
keestorvalds
authored andcommitted
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/[email protected] Signed-off-by: Kees Cook <[email protected]> Cc: Shuah Khan <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 9457056 commit 25fd2d4

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

tools/testing/selftests/kselftest.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
*
2929
* When all tests are finished, clean up and exit the program with one of:
3030
*
31+
* ksft_finished();
3132
* ksft_exit(condition);
3233
* ksft_exit_pass();
3334
* ksft_exit_fail();
@@ -235,6 +236,15 @@ static inline int ksft_exit_fail(void)
235236
ksft_exit_fail(); \
236237
} while (0)
237238

239+
/**
240+
* ksft_finished() - Exit selftest with success if all tests passed
241+
*/
242+
#define ksft_finished() \
243+
ksft_exit(ksft_plan == \
244+
ksft_cnt.ksft_pass + \
245+
ksft_cnt.ksft_xfail + \
246+
ksft_cnt.ksft_xskip)
247+
238248
static inline int ksft_exit_fail_msg(const char *msg, ...)
239249
{
240250
int saved_errno = errno;

tools/testing/selftests/vm/memfd_secret.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ int main(int argc, char *argv[])
282282

283283
close(fd);
284284

285-
ksft_exit(!ksft_get_fail_cnt());
285+
ksft_finished();
286286
}
287287

288288
#else /* __NR_memfd_secret */

0 commit comments

Comments
 (0)