selftests: Add test plan API to kselftest.h and adjust callers

The test plan for TAP needs to be declared immediately after the header.
This adds the test plan API to kselftest.h and updates all callers to
declare their expected test counts.

Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
This commit is contained in:
Kees Cook
2019-04-24 16:12:37 -07:00
committed by Shuah Khan
parent f41c322f17
commit 5821ba9695
16 changed files with 48 additions and 8 deletions

View File

@@ -33,6 +33,7 @@ struct ksft_count {
};
static struct ksft_count ksft_cnt;
static unsigned int ksft_plan;
static inline int ksft_test_num(void)
{
@@ -61,13 +62,21 @@ static inline void ksft_print_header(void)
printf("TAP version 13\n");
}
static inline void ksft_set_plan(unsigned int plan)
{
ksft_plan = plan;
printf("1..%d\n", ksft_plan);
}
static inline void ksft_print_cnts(void)
{
if (ksft_plan != ksft_test_num())
printf("# Planned tests != run tests (%u != %u)\n",
ksft_plan, ksft_test_num());
printf("# Pass %d Fail %d Xfail %d Xpass %d Skip %d Error %d\n",
ksft_cnt.ksft_pass, ksft_cnt.ksft_fail,
ksft_cnt.ksft_xfail, ksft_cnt.ksft_xpass,
ksft_cnt.ksft_xskip, ksft_cnt.ksft_error);
printf("1..%d\n", ksft_test_num());
}
static inline void ksft_print_msg(const char *msg, ...)
@@ -172,7 +181,7 @@ static inline int ksft_exit_skip(const char *msg, ...)
va_list args;
va_start(args, msg);
printf("not ok %d # SKIP ", ksft_test_num());
printf("not ok %d # SKIP ", 1 + ksft_test_num());
vprintf(msg, args);
va_end(args);
} else {