Skip to content

Commit

Permalink
selftests: kselftest framework: provide "finished" helper
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
kees authored and torvalds committed Mar 25, 2022
1 parent 9457056 commit 25fd2d4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions tools/testing/selftests/kselftest.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*
* When all tests are finished, clean up and exit the program with one of:
*
* ksft_finished();
* ksft_exit(condition);
* ksft_exit_pass();
* ksft_exit_fail();
Expand Down Expand Up @@ -235,6 +236,15 @@ static inline int ksft_exit_fail(void)
ksft_exit_fail(); \
} while (0)

/**
* ksft_finished() - Exit selftest with success if all tests passed
*/
#define ksft_finished() \
ksft_exit(ksft_plan == \
ksft_cnt.ksft_pass + \
ksft_cnt.ksft_xfail + \
ksft_cnt.ksft_xskip)

static inline int ksft_exit_fail_msg(const char *msg, ...)
{
int saved_errno = errno;
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/vm/memfd_secret.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ int main(int argc, char *argv[])

close(fd);

ksft_exit(!ksft_get_fail_cnt());
ksft_finished();
}

#else /* __NR_memfd_secret */
Expand Down

0 comments on commit 25fd2d4

Please sign in to comment.