Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6d621897 authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge tag 'linux-kselftest-4.14-rc1-update' of...

Merge tag 'linux-kselftest-4.14-rc1-update' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest

Pull kselftest updates from Shuah Khan:

 - TAP13 framework API and converting tests to TAP13 continues. A few
   more tests are converted and kselftest common RUN_TESTS in lib.mk is
   enhanced to print TAP13 to cover test shell scripts that won't be
   able to use kselftest API.

 - Several fixes to existing tests to not fail in unsupported cases.
   This has been an ongoing work based on the feedback from stable
   release kselftest users.

 - A new watchdog test and much needed cleanups to the existing tests
   from Eugeniu Rosca.

 - Changes to kselftest common lib.mk framework to make RUN_TESTS a
   function to be called from individual test make files to run stress
   and destructive sub-tests.

* tag 'linux-kselftest-4.14-rc1-update' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: (41 commits)
  selftests: Enhance kselftest_harness.h to print which assert failed
  selftests: lib.mk: change RUN_TESTS to print messages in TAP13 format
  selftests: change lib.mk RUN_TESTS to take test list as an argument
  selftests: lib.mk: suppress "cd" output from run_tests target
  selftests: kselftest framework: change skip exit code to 0
  selftests/timers: make loop consistent with array size
  selftests: timers: remove rtctest_setdate from run_destructive_tests
  selftests: timers: Fix run_destructive_tests target to handle skipped tests
  kselftests: timers: leap-a-day: Change default arguments to help test runs
  selftests: timers: drop support for !KTEST case
  rtc: rtctest: Improve support detection
  selftests/cpu-hotplug: Skip test when there is only one online cpu
  selftests/cpu-hotplug: exit with failure when test occured unexpected behaviors
  selftests: futex: convert test to use ksft TAP13 framework
  selftests: capabilities: convert error output to TAP13 ksft framework
  selftests: memfd: Align STACK_SIZE for ARM AArch64 system
  selftests: warn if failure is due to lack of executable bit
  selftests: kselftest framework: add error counter
  selftests: capabilities: convert the test to use TAP13 ksft framework
  selftests: capabilities: fix to run Non-root +ia, sgidroot => i test
  ...
parents 42c8e86c 369130b6
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -367,11 +367,11 @@ static void launch_tests(void)

	/* Icebp traps */
	ptrace(PTRACE_CONT, child_pid, NULL, 0);
	check_success("Test icebp");
	check_success("Test icebp\n");

	/* Int 3 traps */
	ptrace(PTRACE_CONT, child_pid, NULL, 0);
	check_success("Test int 3 trap");
	check_success("Test int 3 trap\n");

	ptrace(PTRACE_CONT, child_pid, NULL, 0);
}
+114 −79
Original line number Diff line number Diff line
#define _GNU_SOURCE

#include <cap-ng.h>
#include <err.h>
#include <linux/capability.h>
#include <stdbool.h>
#include <string.h>
@@ -18,6 +17,8 @@
#include <sys/prctl.h>
#include <sys/stat.h>

#include "../kselftest.h"

#ifndef PR_CAP_AMBIENT
#define PR_CAP_AMBIENT			47
# define PR_CAP_AMBIENT_IS_SET		1
@@ -27,6 +28,7 @@
#endif

static int nerrs;
static pid_t mpid;	/*  main() pid is used to avoid duplicate test counts */

static void vmaybe_write_file(bool enoent_ok, char *filename, char *fmt, va_list ap)
{
@@ -36,29 +38,32 @@ static void vmaybe_write_file(bool enoent_ok, char *filename, char *fmt, va_list
	int buf_len;

	buf_len = vsnprintf(buf, sizeof(buf), fmt, ap);
	if (buf_len < 0) {
		err(1, "vsnprintf failed");
	}
	if (buf_len >= sizeof(buf)) {
		errx(1, "vsnprintf output truncated");
	}
	if (buf_len < 0)
		ksft_exit_fail_msg("vsnprintf failed - %s\n", strerror(errno));

	if (buf_len >= sizeof(buf))
		ksft_exit_fail_msg("vsnprintf output truncated\n");


	fd = open(filename, O_WRONLY);
	if (fd < 0) {
		if ((errno == ENOENT) && enoent_ok)
			return;
		err(1, "open of %s failed", filename);
		ksft_exit_fail_msg("open of %s failed - %s\n",
					filename, strerror(errno));
	}
	written = write(fd, buf, buf_len);
	if (written != buf_len) {
		if (written >= 0) {
			errx(1, "short write to %s", filename);
			ksft_exit_fail_msg("short write to %s\n", filename);
		} else {
			err(1, "write to %s failed", filename);
			ksft_exit_fail_msg("write to %s failed - %s\n",
						filename, strerror(errno));
		}
	}
	if (close(fd) != 0) {
		err(1, "close of %s failed", filename);
		ksft_exit_fail_msg("close of %s failed - %s\n",
					filename, strerror(errno));
	}
}

@@ -95,11 +100,12 @@ static bool create_and_enter_ns(uid_t inner_uid)
	 */

	if (unshare(CLONE_NEWNS) == 0) {
		printf("[NOTE]\tUsing global UIDs for tests\n");
		ksft_print_msg("[NOTE]\tUsing global UIDs for tests\n");
		if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) != 0)
			err(1, "PR_SET_KEEPCAPS");
			ksft_exit_fail_msg("PR_SET_KEEPCAPS - %s\n",
						strerror(errno));
		if (setresuid(inner_uid, inner_uid, -1) != 0)
			err(1, "setresuid");
			ksft_exit_fail_msg("setresuid - %s\n", strerror(errno));

		// Re-enable effective caps
		capng_get_caps_process();
@@ -107,22 +113,24 @@ static bool create_and_enter_ns(uid_t inner_uid)
			if (capng_have_capability(CAPNG_PERMITTED, i))
				capng_update(CAPNG_ADD, CAPNG_EFFECTIVE, i);
		if (capng_apply(CAPNG_SELECT_CAPS) != 0)
			err(1, "capng_apply");
			ksft_exit_fail_msg(
					"capng_apply - %s\n", strerror(errno));

		have_outer_privilege = true;
	} else if (unshare(CLONE_NEWUSER | CLONE_NEWNS) == 0) {
		printf("[NOTE]\tUsing a user namespace for tests\n");
		ksft_print_msg("[NOTE]\tUsing a user namespace for tests\n");
		maybe_write_file("/proc/self/setgroups", "deny");
		write_file("/proc/self/uid_map", "%d %d 1", inner_uid, outer_uid);
		write_file("/proc/self/gid_map", "0 %d 1", outer_gid);

		have_outer_privilege = false;
	} else {
		errx(1, "must be root or be able to create a userns");
		ksft_exit_skip("must be root or be able to create a userns\n");
	}

	if (mount("none", "/", NULL, MS_REC | MS_PRIVATE, NULL) != 0)
		err(1, "remount everything private");
		ksft_exit_fail_msg("remount everything private - %s\n",
					strerror(errno));

	return have_outer_privilege;
}
@@ -131,20 +139,22 @@ static void chdir_to_tmpfs(void)
{
	char cwd[PATH_MAX];
	if (getcwd(cwd, sizeof(cwd)) != cwd)
		err(1, "getcwd");
		ksft_exit_fail_msg("getcwd - %s\n", strerror(errno));

	if (mount("private_tmp", ".", "tmpfs", 0, "mode=0777") != 0)
		err(1, "mount private tmpfs");
		ksft_exit_fail_msg("mount private tmpfs - %s\n",
					strerror(errno));

	if (chdir(cwd) != 0)
		err(1, "chdir to private tmpfs");
		ksft_exit_fail_msg("chdir to private tmpfs - %s\n",
					strerror(errno));
}

static void copy_fromat_to(int fromfd, const char *fromname, const char *toname)
{
	int from = openat(fromfd, fromname, O_RDONLY);
	if (from == -1)
		err(1, "open copy source");
		ksft_exit_fail_msg("open copy source - %s\n", strerror(errno));

	int to = open(toname, O_CREAT | O_WRONLY | O_EXCL, 0700);

@@ -154,10 +164,11 @@ static void copy_fromat_to(int fromfd, const char *fromname, const char *toname)
		if (sz == 0)
			break;
		if (sz < 0)
			err(1, "read");
			ksft_exit_fail_msg("read - %s\n", strerror(errno));

		if (write(to, buf, sz) != sz)
			err(1, "write");	/* no short writes on tmpfs */
			/* no short writes on tmpfs */
			ksft_exit_fail_msg("write - %s\n", strerror(errno));
	}

	close(from);
@@ -174,18 +185,20 @@ static bool fork_wait(void)
		int status;
		if (waitpid(child, &status, 0) != child ||
		    !WIFEXITED(status)) {
			printf("[FAIL]\tChild died\n");
			ksft_print_msg("Child died\n");
			nerrs++;
		} else if (WEXITSTATUS(status) != 0) {
			printf("[FAIL]\tChild failed\n");
			ksft_print_msg("Child failed\n");
			nerrs++;
		} else {
			printf("[OK]\tChild succeeded\n");
			/* don't print this message for mpid */
			if (getpid() != mpid)
				ksft_test_result_pass("Passed\n");
		}

		return false;
	} else {
		err(1, "fork");
		ksft_exit_fail_msg("fork - %s\n", strerror(errno));
		return false;
	}
}

@@ -195,7 +208,7 @@ static void exec_other_validate_cap(const char *name,
	execl(name, name, (eff ? "1" : "0"),
	      (perm ? "1" : "0"), (inh ? "1" : "0"), (ambient ? "1" : "0"),
	      NULL);
	err(1, "execl");
	ksft_exit_fail_msg("execl - %s\n", strerror(errno));
}

static void exec_validate_cap(bool eff, bool perm, bool inh, bool ambient)
@@ -209,7 +222,8 @@ static int do_tests(int uid, const char *our_path)

	int ourpath_fd = open(our_path, O_RDONLY | O_DIRECTORY);
	if (ourpath_fd == -1)
		err(1, "open '%s'", our_path);
		ksft_exit_fail_msg("open '%s' - %s\n",
					our_path, strerror(errno));

	chdir_to_tmpfs();

@@ -221,30 +235,30 @@ static int do_tests(int uid, const char *our_path)
		copy_fromat_to(ourpath_fd, "validate_cap",
			       "validate_cap_suidroot");
		if (chown("validate_cap_suidroot", 0, -1) != 0)
			err(1, "chown");
			ksft_exit_fail_msg("chown - %s\n", strerror(errno));
		if (chmod("validate_cap_suidroot", S_ISUID | 0700) != 0)
			err(1, "chmod");
			ksft_exit_fail_msg("chmod - %s\n", strerror(errno));

		copy_fromat_to(ourpath_fd, "validate_cap",
			       "validate_cap_suidnonroot");
		if (chown("validate_cap_suidnonroot", uid + 1, -1) != 0)
			err(1, "chown");
			ksft_exit_fail_msg("chown - %s\n", strerror(errno));
		if (chmod("validate_cap_suidnonroot", S_ISUID | 0700) != 0)
			err(1, "chmod");
			ksft_exit_fail_msg("chmod - %s\n", strerror(errno));

		copy_fromat_to(ourpath_fd, "validate_cap",
			       "validate_cap_sgidroot");
		if (chown("validate_cap_sgidroot", -1, 0) != 0)
			err(1, "chown");
			ksft_exit_fail_msg("chown - %s\n", strerror(errno));
		if (chmod("validate_cap_sgidroot", S_ISGID | 0710) != 0)
			err(1, "chmod");
			ksft_exit_fail_msg("chmod - %s\n", strerror(errno));

		copy_fromat_to(ourpath_fd, "validate_cap",
			       "validate_cap_sgidnonroot");
		if (chown("validate_cap_sgidnonroot", -1, gid + 1) != 0)
			err(1, "chown");
			ksft_exit_fail_msg("chown - %s\n", strerror(errno));
		if (chmod("validate_cap_sgidnonroot", S_ISGID | 0710) != 0)
			err(1, "chmod");
			ksft_exit_fail_msg("chmod - %s\n", strerror(errno));
	}

	capng_get_caps_process();
@@ -252,147 +266,162 @@ static int do_tests(int uid, const char *our_path)
	/* Make sure that i starts out clear */
	capng_update(CAPNG_DROP, CAPNG_INHERITABLE, CAP_NET_BIND_SERVICE);
	if (capng_apply(CAPNG_SELECT_CAPS) != 0)
		err(1, "capng_apply");
		ksft_exit_fail_msg("capng_apply - %s\n", strerror(errno));

	if (uid == 0) {
		printf("[RUN]\tRoot => ep\n");
		ksft_print_msg("[RUN]\tRoot => ep\n");
		if (fork_wait())
			exec_validate_cap(true, true, false, false);
	} else {
		printf("[RUN]\tNon-root => no caps\n");
		ksft_print_msg("[RUN]\tNon-root => no caps\n");
		if (fork_wait())
			exec_validate_cap(false, false, false, false);
	}

	printf("[OK]\tCheck cap_ambient manipulation rules\n");
	ksft_print_msg("Check cap_ambient manipulation rules\n");

	/* We should not be able to add ambient caps yet. */
	if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, CAP_NET_BIND_SERVICE, 0, 0, 0) != -1 || errno != EPERM) {
		if (errno == EINVAL)
			printf("[FAIL]\tPR_CAP_AMBIENT_RAISE isn't supported\n");
			ksft_test_result_fail(
				"PR_CAP_AMBIENT_RAISE isn't supported\n");
		else
			printf("[FAIL]\tPR_CAP_AMBIENT_RAISE should have failed eith EPERM on a non-inheritable cap\n");
			ksft_test_result_fail(
				"PR_CAP_AMBIENT_RAISE should have failed eith EPERM on a non-inheritable cap\n");
		return 1;
	}
	printf("[OK]\tPR_CAP_AMBIENT_RAISE failed on non-inheritable cap\n");
	ksft_test_result_pass(
		"PR_CAP_AMBIENT_RAISE failed on non-inheritable cap\n");

	capng_update(CAPNG_ADD, CAPNG_INHERITABLE, CAP_NET_RAW);
	capng_update(CAPNG_DROP, CAPNG_PERMITTED, CAP_NET_RAW);
	capng_update(CAPNG_DROP, CAPNG_EFFECTIVE, CAP_NET_RAW);
	if (capng_apply(CAPNG_SELECT_CAPS) != 0)
		err(1, "capng_apply");
		ksft_exit_fail_msg("capng_apply - %s\n", strerror(errno));
	if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, CAP_NET_RAW, 0, 0, 0) != -1 || errno != EPERM) {
		printf("[FAIL]\tPR_CAP_AMBIENT_RAISE should have failed on a non-permitted cap\n");
		ksft_test_result_fail(
			"PR_CAP_AMBIENT_RAISE should have failed on a non-permitted cap\n");
		return 1;
	}
	printf("[OK]\tPR_CAP_AMBIENT_RAISE failed on non-permitted cap\n");
	ksft_test_result_pass(
		"PR_CAP_AMBIENT_RAISE failed on non-permitted cap\n");

	capng_update(CAPNG_ADD, CAPNG_INHERITABLE, CAP_NET_BIND_SERVICE);
	if (capng_apply(CAPNG_SELECT_CAPS) != 0)
		err(1, "capng_apply");
		ksft_exit_fail_msg("capng_apply - %s\n", strerror(errno));
	if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, CAP_NET_BIND_SERVICE, 0, 0, 0) != 0) {
		printf("[FAIL]\tPR_CAP_AMBIENT_RAISE should have succeeded\n");
		ksft_test_result_fail(
			"PR_CAP_AMBIENT_RAISE should have succeeded\n");
		return 1;
	}
	printf("[OK]\tPR_CAP_AMBIENT_RAISE worked\n");
	ksft_test_result_pass("PR_CAP_AMBIENT_RAISE worked\n");

	if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET, CAP_NET_BIND_SERVICE, 0, 0, 0) != 1) {
		printf("[FAIL]\tPR_CAP_AMBIENT_IS_SET is broken\n");
		ksft_test_result_fail("PR_CAP_AMBIENT_IS_SET is broken\n");
		return 1;
	}

	if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_CLEAR_ALL, 0, 0, 0, 0) != 0)
		err(1, "PR_CAP_AMBIENT_CLEAR_ALL");
		ksft_exit_fail_msg("PR_CAP_AMBIENT_CLEAR_ALL - %s\n",
					strerror(errno));

	if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET, CAP_NET_BIND_SERVICE, 0, 0, 0) != 0) {
		printf("[FAIL]\tPR_CAP_AMBIENT_CLEAR_ALL didn't work\n");
		ksft_test_result_fail(
			"PR_CAP_AMBIENT_CLEAR_ALL didn't work\n");
		return 1;
	}

	if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, CAP_NET_BIND_SERVICE, 0, 0, 0) != 0)
		err(1, "PR_CAP_AMBIENT_RAISE");
		ksft_exit_fail_msg("PR_CAP_AMBIENT_RAISE - %s\n",
					strerror(errno));

	capng_update(CAPNG_DROP, CAPNG_INHERITABLE, CAP_NET_BIND_SERVICE);
	if (capng_apply(CAPNG_SELECT_CAPS) != 0)
		err(1, "capng_apply");
		ksft_exit_fail_msg("capng_apply - %s\n", strerror(errno));

	if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET, CAP_NET_BIND_SERVICE, 0, 0, 0) != 0) {
		printf("[FAIL]\tDropping I should have dropped A\n");
		ksft_test_result_fail("Dropping I should have dropped A\n");
		return 1;
	}

	printf("[OK]\tBasic manipulation appears to work\n");
	ksft_test_result_pass("Basic manipulation appears to work\n");

	capng_update(CAPNG_ADD, CAPNG_INHERITABLE, CAP_NET_BIND_SERVICE);
	if (capng_apply(CAPNG_SELECT_CAPS) != 0)
		err(1, "capng_apply");
		ksft_exit_fail_msg("capng_apply - %s\n", strerror(errno));
	if (uid == 0) {
		printf("[RUN]\tRoot +i => eip\n");
		ksft_print_msg("[RUN]\tRoot +i => eip\n");
		if (fork_wait())
			exec_validate_cap(true, true, true, false);
	} else {
		printf("[RUN]\tNon-root +i => i\n");
		ksft_print_msg("[RUN]\tNon-root +i => i\n");
		if (fork_wait())
			exec_validate_cap(false, false, true, false);
	}

	if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, CAP_NET_BIND_SERVICE, 0, 0, 0) != 0)
		err(1, "PR_CAP_AMBIENT_RAISE");
		ksft_exit_fail_msg("PR_CAP_AMBIENT_RAISE - %s\n",
					strerror(errno));

	printf("[RUN]\tUID %d +ia => eipa\n", uid);
	ksft_print_msg("[RUN]\tUID %d +ia => eipa\n", uid);
	if (fork_wait())
		exec_validate_cap(true, true, true, true);

	/* The remaining tests need real privilege */

	if (!have_outer_privilege) {
		printf("[SKIP]\tSUID/SGID tests (needs privilege)\n");
		ksft_test_result_skip("SUID/SGID tests (needs privilege)\n");
		goto done;
	}

	if (uid == 0) {
		printf("[RUN]\tRoot +ia, suidroot => eipa\n");
		ksft_print_msg("[RUN]\tRoot +ia, suidroot => eipa\n");
		if (fork_wait())
			exec_other_validate_cap("./validate_cap_suidroot",
						true, true, true, true);

		printf("[RUN]\tRoot +ia, suidnonroot => ip\n");
		ksft_print_msg("[RUN]\tRoot +ia, suidnonroot => ip\n");
		if (fork_wait())
			exec_other_validate_cap("./validate_cap_suidnonroot",
						false, true, true, false);

		printf("[RUN]\tRoot +ia, sgidroot => eipa\n");
		ksft_print_msg("[RUN]\tRoot +ia, sgidroot => eipa\n");
		if (fork_wait())
			exec_other_validate_cap("./validate_cap_sgidroot",
						true, true, true, true);

		if (fork_wait()) {
			printf("[RUN]\tRoot, gid != 0, +ia, sgidroot => eip\n");
			ksft_print_msg(
				"[RUN]\tRoot, gid != 0, +ia, sgidroot => eip\n");
			if (setresgid(1, 1, 1) != 0)
				err(1, "setresgid");
				ksft_exit_fail_msg("setresgid - %s\n",
							strerror(errno));
			exec_other_validate_cap("./validate_cap_sgidroot",
						true, true, true, false);
		}

		printf("[RUN]\tRoot +ia, sgidnonroot => eip\n");
		ksft_print_msg("[RUN]\tRoot +ia, sgidnonroot => eip\n");
		if (fork_wait())
			exec_other_validate_cap("./validate_cap_sgidnonroot",
						true, true, true, false);
	} else {
		printf("[RUN]\tNon-root +ia, sgidnonroot => i\n");
		ksft_print_msg("[RUN]\tNon-root +ia, sgidnonroot => i\n");
		if (fork_wait())
			exec_other_validate_cap("./validate_cap_sgidnonroot",
					false, false, true, false);

		if (fork_wait()) {
			printf("[RUN]\tNon-root +ia, sgidroot => i\n");
			ksft_print_msg("[RUN]\tNon-root +ia, sgidroot => i\n");
			if (setresgid(1, 1, 1) != 0)
				err(1, "setresgid");
				ksft_exit_fail_msg("setresgid - %s\n",
							strerror(errno));
			exec_other_validate_cap("./validate_cap_sgidroot",
						false, false, true, false);
		}
	}

done:
	ksft_print_cnts();
	return nerrs ? 1 : 0;
}

@@ -400,23 +429,29 @@ int main(int argc, char **argv)
{
	char *tmp1, *tmp2, *our_path;

	ksft_print_header();

	/* Find our path */
	tmp1 = strdup(argv[0]);
	if (!tmp1)
		err(1, "strdup");
		ksft_exit_fail_msg("strdup - %s\n", strerror(errno));
	tmp2 = dirname(tmp1);
	our_path = strdup(tmp2);
	if (!our_path)
		err(1, "strdup");
		ksft_exit_fail_msg("strdup - %s\n", strerror(errno));
	free(tmp1);

	mpid = getpid();

	if (fork_wait()) {
		printf("[RUN]\t+++ Tests with uid == 0 +++\n");
		ksft_print_msg("[RUN]\t+++ Tests with uid == 0 +++\n");
		return do_tests(0, our_path);
	}

	ksft_print_msg("==================================================\n");

	if (fork_wait()) {
		printf("[RUN]\t+++ Tests with uid != 0 +++\n");
		ksft_print_msg("[RUN]\t+++ Tests with uid != 0 +++\n");
		return do_tests(1, our_path);
	}

+15 −9
Original line number Diff line number Diff line
#include <cap-ng.h>
#include <err.h>
#include <linux/capability.h>
#include <stdbool.h>
#include <string.h>
@@ -7,6 +6,8 @@
#include <sys/prctl.h>
#include <sys/auxv.h>

#include "../kselftest.h"

#ifndef PR_CAP_AMBIENT
#define PR_CAP_AMBIENT			47
# define PR_CAP_AMBIENT_IS_SET		1
@@ -25,8 +26,10 @@ static bool bool_arg(char **argv, int i)
		return false;
	else if (!strcmp(argv[i], "1"))
		return true;
	else
		errx(1, "wrong argv[%d]", i);
	else {
		ksft_exit_fail_msg("wrong argv[%d]\n", i);
		return false;
	}
}

int main(int argc, char **argv)
@@ -39,7 +42,7 @@ int main(int argc, char **argv)
	 */

	if (argc != 5)
		errx(1, "wrong argc");
		ksft_exit_fail_msg("wrong argc\n");

#ifdef HAVE_GETAUXVAL
	if (getauxval(AT_SECURE))
@@ -51,23 +54,26 @@ int main(int argc, char **argv)
	capng_get_caps_process();

	if (capng_have_capability(CAPNG_EFFECTIVE, CAP_NET_BIND_SERVICE) != bool_arg(argv, 1)) {
		printf("[FAIL]\tWrong effective state%s\n", atsec);
		ksft_print_msg("Wrong effective state%s\n", atsec);
		return 1;
	}

	if (capng_have_capability(CAPNG_PERMITTED, CAP_NET_BIND_SERVICE) != bool_arg(argv, 2)) {
		printf("[FAIL]\tWrong permitted state%s\n", atsec);
		ksft_print_msg("Wrong permitted state%s\n", atsec);
		return 1;
	}

	if (capng_have_capability(CAPNG_INHERITABLE, CAP_NET_BIND_SERVICE) != bool_arg(argv, 3)) {
		printf("[FAIL]\tWrong inheritable state%s\n", atsec);
		ksft_print_msg("Wrong inheritable state%s\n", atsec);
		return 1;
	}

	if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET, CAP_NET_BIND_SERVICE, 0, 0, 0) != bool_arg(argv, 4)) {
		printf("[FAIL]\tWrong ambient state%s\n", atsec);
		ksft_print_msg("Wrong ambient state%s\n", atsec);
		return 1;
	}

	printf("[OK]\tCapabilities after execve were correct\n");
	ksft_print_msg("%s: Capabilities after execve were correct\n",
			"validate_cap:");
	return 0;
}
+14 −0
Original line number Diff line number Diff line
@@ -28,6 +28,12 @@ prerequisite()
	echo "CPU online/offline summary:"
	online_cpus=`cat $SYSFS/devices/system/cpu/online`
	online_max=${online_cpus##*-}

	if [[ "$online_cpus" = "$online_max" ]]; then
		echo "$msg: since there is only one cpu: $online_cpus"
		exit 0
	fi

	echo -e "\t Cpus in online state: $online_cpus"

	offline_cpus=`cat $SYSFS/devices/system/cpu/offline`
@@ -89,8 +95,10 @@ online_cpu_expect_success()

	if ! online_cpu $cpu; then
		echo $FUNCNAME $cpu: unexpected fail >&2
		exit 1
	elif ! cpu_is_online $cpu; then
		echo $FUNCNAME $cpu: unexpected offline >&2
		exit 1
	fi
}

@@ -100,8 +108,10 @@ online_cpu_expect_fail()

	if online_cpu $cpu 2> /dev/null; then
		echo $FUNCNAME $cpu: unexpected success >&2
		exit 1
	elif ! cpu_is_offline $cpu; then
		echo $FUNCNAME $cpu: unexpected online >&2
		exit 1
	fi
}

@@ -111,8 +121,10 @@ offline_cpu_expect_success()

	if ! offline_cpu $cpu; then
		echo $FUNCNAME $cpu: unexpected fail >&2
		exit 1
	elif ! cpu_is_offline $cpu; then
		echo $FUNCNAME $cpu: unexpected offline >&2
		exit 1
	fi
}

@@ -122,8 +134,10 @@ offline_cpu_expect_fail()

	if offline_cpu $cpu 2> /dev/null; then
		echo $FUNCNAME $cpu: unexpected success >&2
		exit 1
	elif ! cpu_is_online $cpu; then
		echo $FUNCNAME $cpu: unexpected offline >&2
		exit 1
	fi
}

+37 −14
Original line number Diff line number Diff line
@@ -8,15 +8,18 @@
# Released under the terms of the GPL v2.

usage() { # errno [message]
[ "$2" ] && echo $2
[ ! -z "$2" ] && echo $2
echo "Usage: ftracetest [options] [testcase(s)] [testcase-directory(s)]"
echo " Options:"
echo "		-h|--help  Show help message"
echo "		-k|--keep  Keep passed test logs"
echo "		-v|--verbose Increase verbosity of test messages"
echo "		-vv        Alias of -v -v (Show all results in stdout)"
echo "		-vvv       Alias of -v -v -v (Show all commands immediately)"
echo "		--fail-unsupported Treat UNSUPPORTED as a failure"
echo "		-d|--debug Debug mode (trace all shell commands)"
echo "		-l|--logdir <dir> Save logs on the <dir>"
echo "		            If <dir> is -, all logs output in console only"
exit $1
}

@@ -47,7 +50,7 @@ parse_opts() { # opts
  local OPT_TEST_CASES=
  local OPT_TEST_DIR=

  while [ "$1" ]; do
  while [ ! -z "$1" ]; do
    case "$1" in
    --help|-h)
      usage 0
@@ -56,15 +59,20 @@ parse_opts() { # opts
      KEEP_LOG=1
      shift 1
    ;;
    --verbose|-v|-vv)
    --verbose|-v|-vv|-vvv)
      VERBOSE=$((VERBOSE + 1))
      [ $1 = '-vv' ] && VERBOSE=$((VERBOSE + 1))
      [ $1 = '-vvv' ] && VERBOSE=$((VERBOSE + 2))
      shift 1
    ;;
    --debug|-d)
      DEBUG=1
      shift 1
    ;;
    --fail-unsupported)
      UNSUPPORTED_RESULT=1
      shift 1
    ;;
    --logdir|-l)
      LOG_DIR=$2
      shift 2
@@ -88,7 +96,7 @@ parse_opts() { # opts
    ;;
    esac
  done
  if [ "$OPT_TEST_CASES" ]; then
  if [ ! -z "$OPT_TEST_CASES" ]; then
    TEST_CASES=$OPT_TEST_CASES
  fi
}
@@ -108,6 +116,7 @@ LOG_DIR=$TOP_DIR/logs/`date +%Y%m%d-%H%M%S`/
KEEP_LOG=0
DEBUG=0
VERBOSE=0
UNSUPPORTED_RESULT=0
# Parse command-line options
parse_opts $*

@@ -119,14 +128,20 @@ if [ -z "$TRACING_DIR" -o ! -d "$TRACING_DIR" ]; then
fi

# Preparing logs
if [ "x$LOG_DIR" = "x-" ]; then
  LOG_FILE=
  date
else
  LOG_FILE=$LOG_DIR/ftracetest.log
  mkdir -p $LOG_DIR || errexit "Failed to make a log directory: $LOG_DIR"
  date > $LOG_FILE
fi

prlog() { # messages
  echo "$@" | tee -a $LOG_FILE
  [ -z "$LOG_FILE" ] && echo "$@" || echo "$@" | tee -a $LOG_FILE
}
catlog() { #file
  cat $1 | tee -a $LOG_FILE
  [ -z "$LOG_FILE" ] && cat $1 || cat $1 | tee -a $LOG_FILE
}
prlog "=== Ftrace unit tests ==="

@@ -187,7 +202,7 @@ eval_result() { # sigval
    $UNSUPPORTED)
      prlog "	[UNSUPPORTED]"
      UNSUPPORTED_CASES="$UNSUPPORTED_CASES $CASENO"
      return 1 # this is not a bug, but the result should be reported.
      return $UNSUPPORTED_RESULT # depends on use case
    ;;
    $XFAIL)
      prlog "	[XFAIL]"
@@ -247,12 +262,20 @@ __run_test() { # testfile
# Run one test case
run_test() { # testfile
  local testname=`basename $1`
  if [ ! -z "$LOG_FILE" ] ; then
    local testlog=`mktemp $LOG_DIR/${testname}-log.XXXXXX`
  else
    local testlog=/proc/self/fd/1
  fi
  export TMPDIR=`mktemp -d /tmp/ftracetest-dir.XXXXXX`
  testcase $1
  echo "execute$INSTANCE: "$1 > $testlog
  SIG_RESULT=0
  if [ $VERBOSE -ge 2 ]; then
  if [ -z "$LOG_FILE" ]; then
    __run_test $1 2>&1
  elif [ $VERBOSE -ge 3 ]; then
    __run_test $1 | tee -a $testlog 2>&1
  elif [ $VERBOSE -eq 2 ]; then
    __run_test $1 2>> $testlog | tee -a $testlog
  else
    __run_test $1 >> $testlog 2>&1
@@ -260,9 +283,9 @@ run_test() { # testfile
  eval_result $SIG_RESULT
  if [ $? -eq 0 ]; then
    # Remove test log if the test was done as it was expected.
    [ $KEEP_LOG -eq 0 ] && rm $testlog
    [ $KEEP_LOG -eq 0 -a ! -z "$LOG_FILE" ] && rm $testlog
  else
    [ $VERBOSE -ge 1 ] && catlog $testlog
    [ $VERBOSE -eq 1 -o $VERBOSE -eq 2 ] && catlog $testlog
    TOTAL_RESULT=1
  fi
  rm -rf $TMPDIR
Loading