Commit 5821ba96 authored by Kees Cook's avatar Kees Cook Committed by Shuah Khan
Browse files

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: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
parent f41c322f
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@

#include "../kselftest.h"

#define COUNT_ISN_BPS	4
#define COUNT_WPS	4

/* Breakpoint access modes */
enum {
@@ -220,7 +222,7 @@ static void trigger_tests(void)
			if (!local && !global)
				continue;

			for (i = 0; i < 4; i++) {
			for (i = 0; i < COUNT_ISN_BPS; i++) {
				dummy_funcs[i]();
				check_trapped();
			}
@@ -292,7 +294,7 @@ static void launch_instruction_breakpoints(char *buf, int local, int global)
{
	int i;

	for (i = 0; i < 4; i++) {
	for (i = 0; i < COUNT_ISN_BPS; i++) {
		set_breakpoint_addr(dummy_funcs[i], i);
		toggle_breakpoint(i, BP_X, 1, local, global, 1);
		ptrace(PTRACE_CONT, child_pid, NULL, 0);
@@ -314,7 +316,7 @@ static void launch_watchpoints(char *buf, int mode, int len,
	else
		mode_str = "read";

	for (i = 0; i < 4; i++) {
	for (i = 0; i < COUNT_WPS; i++) {
		set_breakpoint_addr(&dummy_var[i], i);
		toggle_breakpoint(i, mode, len, local, global, 1);
		ptrace(PTRACE_CONT, child_pid, NULL, 0);
@@ -330,8 +332,15 @@ static void launch_watchpoints(char *buf, int mode, int len,
static void launch_tests(void)
{
	char buf[1024];
	unsigned int tests = 0;
	int len, local, global, i;

	tests += 3 * COUNT_ISN_BPS;
	tests += sizeof(long) / 2 * 3 * COUNT_WPS;
	tests += sizeof(long) / 2 * 3 * COUNT_WPS;
	tests += 2;
	ksft_set_plan(tests);

	/* Instruction breakpoints */
	for (local = 0; local < 2; local++) {
		for (global = 0; global < 2; global++) {
+2 −1
Original line number Diff line number Diff line
@@ -118,7 +118,7 @@ static bool set_watchpoint(pid_t pid, int size, int wp)
	return false;
}

static bool run_test(int wr_size, int wp_size, int wr, int wp)
static bool arun_test(int wr_size, int wp_size, int wr, int wp)
{
	int status;
	siginfo_t siginfo;
@@ -214,6 +214,7 @@ int main(int argc, char **argv)
	bool result;

	ksft_print_header();
	ksft_set_plan(213);

	act.sa_handler = sigalrm;
	sigemptyset(&act.sa_mask);
+8 −0
Original line number Diff line number Diff line
@@ -173,6 +173,7 @@ int main(int argc, char **argv)
	int opt;
	bool do_suspend = true;
	bool succeeded = true;
	unsigned int tests = 0;
	cpu_set_t available_cpus;
	int err;
	int cpu;
@@ -191,6 +192,13 @@ int main(int argc, char **argv)
		}
	}

	for (cpu = 0; cpu < CPU_SETSIZE; cpu++) {
		if (!CPU_ISSET(cpu, &available_cpus))
			continue;
		tests++;
	}
	ksft_set_plan(tests);

	if (do_suspend)
		suspend();

+4 −2
Original line number Diff line number Diff line
@@ -430,8 +430,6 @@ int main(int argc, char **argv)
{
	char *tmp1, *tmp2, *our_path;

	ksft_print_header();

	/* Find our path */
	tmp1 = strdup(argv[0]);
	if (!tmp1)
@@ -445,6 +443,8 @@ int main(int argc, char **argv)
	mpid = getpid();

	if (fork_wait()) {
		ksft_print_header();
		ksft_set_plan(12);
		ksft_print_msg("[RUN]\t+++ Tests with uid == 0 +++\n");
		return do_tests(0, our_path);
	}
@@ -452,6 +452,8 @@ int main(int argc, char **argv)
	ksft_print_msg("==================================================\n");

	if (fork_wait()) {
		ksft_print_header();
		ksft_set_plan(9);
		ksft_print_msg("[RUN]\t+++ Tests with uid != 0 +++\n");
		return do_tests(1, our_path);
	}
+1 −0
Original line number Diff line number Diff line
@@ -395,6 +395,7 @@ int main(int argc, char *argv[])
	}

	ksft_print_header();
	ksft_set_plan(1);
	ksft_print_msg("%s: Test requeue functionality\n", basename(argv[0]));
	ksft_print_msg(
		"\tArguments: broadcast=%d locked=%d owner=%d timeout=%ldns\n",
Loading