Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756222AbdIHQcA (ORCPT ); Fri, 8 Sep 2017 12:32:00 -0400 Received: from ec2-52-27-115-49.us-west-2.compute.amazonaws.com ([52.27.115.49]:57392 "EHLO osg.samsung.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753577AbdIHQb4 (ORCPT ); Fri, 8 Sep 2017 12:31:56 -0400 To: torvalds@linux-foundation.org Cc: Shuah Khan , "linux-kselftest@vger.kernel.org" , LKML , Shuah Khan From: Shuah Khan Subject: [GIT PULL] Kselftest update for 4.14-rc1 Message-ID: <3ed48863-7474-30fc-929d-c408ea4e0cc6@osg.samsung.com> Date: Fri, 8 Sep 2017 10:31:51 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------4FB839D6DD6AB6F7230BC0FA" Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 79683 Lines: 2592 This is a multi-part message in MIME format. --------------4FB839D6DD6AB6F7230BC0FA Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Hi Linus, Please pull the following Kselftest update for 4.14-rc1. This update consists of: -- 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. Diff for the update attached. thanks, -- Shuah ----------------------------------------------------------------------------------- The following changes since commit 5771a8c08880cdca3bfb4a3fc6d309d6bba20877: Linux v4.13-rc1 (2017-07-15 15:22:10 -0700) are available in the git repository at: git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest tags/linux-kselftest-4.14-rc1-update for you to fetch changes up to 369130b63178e0e2f863a2da2a5ad0238ded6d9d: selftests: Enhance kselftest_harness.h to print which assert failed (2017-09-05 19:21:33 -0600) ---------------------------------------------------------------- linux-kselftest-4.14-rc1-update This update consists of: -- 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. ---------------------------------------------------------------- Benjamin Gaignard (1): selftests/timers: make loop consistent with array size Daniel Díaz (1): selftests: Fix installation for splice test Eugeniu Rosca (6): selftests: watchdog: fix mixed whitespace selftests: watchdog: use getopt_long() selftests: watchdog: prefer strtoul() over atoi() selftests: watchdog: point out ioctl() failures selftests: watchdog: avoid keepalive flood selftests: watchdog: get boot reason via WDIOC_GETBOOTSTATUS Grygorii Strashko (1): selftests: ptp: include default header install path John Stultz (1): kselftests: timers: leap-a-day: Change default arguments to help test runs Li Zhijian (2): selftests/cpu-hotplug: exit with failure when test occured unexpected behaviors selftests/cpu-hotplug: Skip test when there is only one online cpu Luis R. Rodriguez (1): selftests: warn if failure is due to lack of executable bit Lukáš Doktor (1): rtc: rtctest: Improve support detection Masami Hiramatsu (5): selftests: ftrace: Do not failure if there is unsupported tests selftests: ftrace: Add --fail-unsupported option selftests: ftrace: Add more verbosity for immediate log selftests: ftrace: Output only to console with "--logdir -" selftests: ftrace: Check given string is not zero-length Mickaël Salaün (1): selftests: Enhance kselftest_harness.h to print which assert failed Naresh Kamboju (1): selftests/nsfs: create kconfig fragments Orson Zhai (1): selftests: memfd: Align STACK_SIZE for ARM AArch64 system Shuah Khan (19): selftests: breakpoint_test: Add missing line breaks selftests: sync: differentiate between sync unsupported and access errors selftests: kselftest framework: add API to return pass/fail/* counts selftests: sync: convert to use TAP13 ksft framework selftests: pstore: add .gitignore for generated files selftests: splice: add .gitignore for generated files selftests: sigaltstack: convert to use TAP13 ksft framework selftests: capabilities: fix to run Non-root +ia, sgidroot => i test selftests: capabilities: convert the test to use TAP13 ksft framework selftests: kselftest framework: add error counter selftests: capabilities: convert error output to TAP13 ksft framework selftests: futex: convert test to use ksft TAP13 framework selftests: timers: drop support for !KTEST case selftests: timers: Fix run_destructive_tests target to handle skipped tests selftests: timers: remove rtctest_setdate from run_destructive_tests selftests: kselftest framework: change skip exit code to 0 selftests: lib.mk: suppress "cd" output from run_tests target selftests: change lib.mk RUN_TESTS to take test list as an argument selftests: lib.mk: change RUN_TESTS to print messages in TAP13 format .../selftests/breakpoints/breakpoint_test.c | 4 +- tools/testing/selftests/capabilities/test_execve.c | 193 ++++++++++++--------- .../testing/selftests/capabilities/validate_cap.c | 24 ++- .../selftests/cpu-hotplug/cpu-on-off-test.sh | 14 ++ tools/testing/selftests/ftrace/ftracetest | 51 ++++-- .../selftests/futex/functional/futex_requeue_pi.c | 8 +- .../functional/futex_requeue_pi_mismatched_ops.c | 3 +- .../functional/futex_requeue_pi_signal_restart.c | 5 +- .../functional/futex_wait_private_mapped_file.c | 6 +- .../futex/functional/futex_wait_timeout.c | 5 +- .../functional/futex_wait_uninitialized_heap.c | 3 +- .../futex/functional/futex_wait_wouldblock.c | 3 +- tools/testing/selftests/futex/include/logging.h | 20 +-- tools/testing/selftests/kselftest.h | 30 +++- tools/testing/selftests/kselftest_harness.h | 39 ++++- tools/testing/selftests/lib.mk | 17 +- tools/testing/selftests/memfd/fuse_test.c | 2 +- tools/testing/selftests/nsfs/config | 3 + tools/testing/selftests/pstore/.gitignore | 2 + tools/testing/selftests/ptp/Makefile | 1 + tools/testing/selftests/seccomp/seccomp_bpf.c | 2 +- tools/testing/selftests/sigaltstack/sas.c | 53 +++--- tools/testing/selftests/splice/.gitignore | 1 + tools/testing/selftests/splice/Makefile | 5 +- tools/testing/selftests/sync/sync_test.c | 71 +++++--- tools/testing/selftests/sync/synctest.h | 3 +- tools/testing/selftests/timers/Makefile | 23 +-- tools/testing/selftests/timers/adjtick.c | 11 -- .../testing/selftests/timers/alarmtimer-suspend.c | 11 -- tools/testing/selftests/timers/change_skew.c | 11 -- .../testing/selftests/timers/clocksource-switch.c | 13 +- .../testing/selftests/timers/inconsistency-check.c | 11 -- tools/testing/selftests/timers/leap-a-day.c | 28 +-- tools/testing/selftests/timers/leapcrash.c | 13 -- tools/testing/selftests/timers/mqueue-lat.c | 11 -- tools/testing/selftests/timers/nanosleep.c | 11 -- tools/testing/selftests/timers/nsleep-lat.c | 11 -- tools/testing/selftests/timers/raw_skew.c | 12 -- tools/testing/selftests/timers/rtctest.c | 7 +- tools/testing/selftests/timers/set-2038.c | 11 -- tools/testing/selftests/timers/set-tai.c | 11 -- tools/testing/selftests/timers/set-timer-lat.c | 11 -- tools/testing/selftests/timers/set-tz.c | 11 -- tools/testing/selftests/timers/skew_consistency.c | 11 -- tools/testing/selftests/timers/threadtest.c | 12 -- tools/testing/selftests/timers/valid-adjtimex.c | 11 -- tools/testing/selftests/watchdog/watchdog-test.c | 190 ++++++++++++-------- 47 files changed, 518 insertions(+), 491 deletions(-) create mode 100644 tools/testing/selftests/nsfs/config create mode 100644 tools/testing/selftests/pstore/.gitignore create mode 100644 tools/testing/selftests/splice/.gitignore ----------------------------------------------------------------------------------- -- Shuah Khan Sr. Linux Kernel Developer Open Source Innovation Group Samsung Research America (Silicon Valley) shuahkh@osg.samsung.com --------------4FB839D6DD6AB6F7230BC0FA Content-Type: text/x-patch; name="linux-kselftest-4.14-rc1-update.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="linux-kselftest-4.14-rc1-update.diff" diff --git a/tools/testing/selftests/breakpoints/breakpoint_test.c b/tool= s/testing/selftests/breakpoints/breakpoint_test.c index f63356151ad4..901b85ea6a59 100644 --- a/tools/testing/selftests/breakpoints/breakpoint_test.c +++ b/tools/testing/selftests/breakpoints/breakpoint_test.c @@ -367,11 +367,11 @@ static void launch_tests(void) =20 /* Icebp traps */ ptrace(PTRACE_CONT, child_pid, NULL, 0); - check_success("Test icebp"); + check_success("Test icebp\n"); =20 /* Int 3 traps */ ptrace(PTRACE_CONT, child_pid, NULL, 0); - check_success("Test int 3 trap"); + check_success("Test int 3 trap\n"); =20 ptrace(PTRACE_CONT, child_pid, NULL, 0); } diff --git a/tools/testing/selftests/capabilities/test_execve.c b/tools/t= esting/selftests/capabilities/test_execve.c index 763f37fecfb8..cf6778441381 100644 --- a/tools/testing/selftests/capabilities/test_execve.c +++ b/tools/testing/selftests/capabilities/test_execve.c @@ -1,7 +1,6 @@ #define _GNU_SOURCE =20 #include -#include #include #include #include @@ -18,6 +17,8 @@ #include #include =20 +#include "../kselftest.h" + #ifndef PR_CAP_AMBIENT #define PR_CAP_AMBIENT 47 # define PR_CAP_AMBIENT_IS_SET 1 @@ -27,6 +28,7 @@ #endif =20 static int nerrs; +static pid_t mpid; /* main() pid is used to avoid duplicate test counts= */ =20 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 *f= ilename, char *fmt, va_list int buf_len; =20 buf_len =3D vsnprintf(buf, sizeof(buf), fmt, ap); - if (buf_len < 0) { - err(1, "vsnprintf failed"); - } - if (buf_len >=3D sizeof(buf)) { - errx(1, "vsnprintf output truncated"); - } + if (buf_len < 0) + ksft_exit_fail_msg("vsnprintf failed - %s\n", strerror(errno)); + + if (buf_len >=3D sizeof(buf)) + ksft_exit_fail_msg("vsnprintf output truncated\n"); + =20 fd =3D open(filename, O_WRONLY); if (fd < 0) { if ((errno =3D=3D 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 =3D write(fd, buf, buf_len); if (written !=3D buf_len) { if (written >=3D 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) !=3D 0) { - err(1, "close of %s failed", filename); + ksft_exit_fail_msg("close of %s failed - %s\n", + filename, strerror(errno)); } } =20 @@ -95,11 +100,12 @@ static bool create_and_enter_ns(uid_t inner_uid) */ =20 if (unshare(CLONE_NEWNS) =3D=3D 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) !=3D 0) - err(1, "PR_SET_KEEPCAPS"); + ksft_exit_fail_msg("PR_SET_KEEPCAPS - %s\n", + strerror(errno)); if (setresuid(inner_uid, inner_uid, -1) !=3D 0) - err(1, "setresuid"); + ksft_exit_fail_msg("setresuid - %s\n", strerror(errno)); =20 // 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) !=3D 0) - err(1, "capng_apply"); + ksft_exit_fail_msg( + "capng_apply - %s\n", strerror(errno)); =20 have_outer_privilege =3D true; } else if (unshare(CLONE_NEWUSER | CLONE_NEWNS) =3D=3D 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); =20 have_outer_privilege =3D 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"); } =20 if (mount("none", "/", NULL, MS_REC | MS_PRIVATE, NULL) !=3D 0) - err(1, "remount everything private"); + ksft_exit_fail_msg("remount everything private - %s\n", + strerror(errno)); =20 return have_outer_privilege; } @@ -131,20 +139,22 @@ static void chdir_to_tmpfs(void) { char cwd[PATH_MAX]; if (getcwd(cwd, sizeof(cwd)) !=3D cwd) - err(1, "getcwd"); + ksft_exit_fail_msg("getcwd - %s\n", strerror(errno)); =20 if (mount("private_tmp", ".", "tmpfs", 0, "mode=3D0777") !=3D 0) - err(1, "mount private tmpfs"); + ksft_exit_fail_msg("mount private tmpfs - %s\n", + strerror(errno)); =20 if (chdir(cwd) !=3D 0) - err(1, "chdir to private tmpfs"); + ksft_exit_fail_msg("chdir to private tmpfs - %s\n", + strerror(errno)); } =20 static void copy_fromat_to(int fromfd, const char *fromname, const char = *toname) { int from =3D openat(fromfd, fromname, O_RDONLY); if (from =3D=3D -1) - err(1, "open copy source"); + ksft_exit_fail_msg("open copy source - %s\n", strerror(errno)); =20 int to =3D open(toname, O_CREAT | O_WRONLY | O_EXCL, 0700); =20 @@ -154,10 +164,11 @@ static void copy_fromat_to(int fromfd, const char *= fromname, const char *toname) if (sz =3D=3D 0) break; if (sz < 0) - err(1, "read"); + ksft_exit_fail_msg("read - %s\n", strerror(errno)); =20 if (write(to, buf, sz) !=3D sz) - err(1, "write"); /* no short writes on tmpfs */ + /* no short writes on tmpfs */ + ksft_exit_fail_msg("write - %s\n", strerror(errno)); } =20 close(from); @@ -174,18 +185,20 @@ static bool fork_wait(void) int status; if (waitpid(child, &status, 0) !=3D child || !WIFEXITED(status)) { - printf("[FAIL]\tChild died\n"); + ksft_print_msg("Child died\n"); nerrs++; } else if (WEXITSTATUS(status) !=3D 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() !=3D mpid) + ksft_test_result_pass("Passed\n"); } - return false; } else { - err(1, "fork"); + ksft_exit_fail_msg("fork - %s\n", strerror(errno)); + return false; } } =20 @@ -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)); } =20 static void exec_validate_cap(bool eff, bool perm, bool inh, bool ambien= t) @@ -209,7 +222,8 @@ static int do_tests(int uid, const char *our_path) =20 int ourpath_fd =3D open(our_path, O_RDONLY | O_DIRECTORY); if (ourpath_fd =3D=3D -1) - err(1, "open '%s'", our_path); + ksft_exit_fail_msg("open '%s' - %s\n", + our_path, strerror(errno)); =20 chdir_to_tmpfs(); =20 @@ -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) !=3D 0) - err(1, "chown"); + ksft_exit_fail_msg("chown - %s\n", strerror(errno)); if (chmod("validate_cap_suidroot", S_ISUID | 0700) !=3D 0) - err(1, "chmod"); + ksft_exit_fail_msg("chmod - %s\n", strerror(errno)); =20 copy_fromat_to(ourpath_fd, "validate_cap", "validate_cap_suidnonroot"); if (chown("validate_cap_suidnonroot", uid + 1, -1) !=3D 0) - err(1, "chown"); + ksft_exit_fail_msg("chown - %s\n", strerror(errno)); if (chmod("validate_cap_suidnonroot", S_ISUID | 0700) !=3D 0) - err(1, "chmod"); + ksft_exit_fail_msg("chmod - %s\n", strerror(errno)); =20 copy_fromat_to(ourpath_fd, "validate_cap", "validate_cap_sgidroot"); if (chown("validate_cap_sgidroot", -1, 0) !=3D 0) - err(1, "chown"); + ksft_exit_fail_msg("chown - %s\n", strerror(errno)); if (chmod("validate_cap_sgidroot", S_ISGID | 0710) !=3D 0) - err(1, "chmod"); + ksft_exit_fail_msg("chmod - %s\n", strerror(errno)); =20 copy_fromat_to(ourpath_fd, "validate_cap", "validate_cap_sgidnonroot"); if (chown("validate_cap_sgidnonroot", -1, gid + 1) !=3D 0) - err(1, "chown"); + ksft_exit_fail_msg("chown - %s\n", strerror(errno)); if (chmod("validate_cap_sgidnonroot", S_ISGID | 0710) !=3D 0) - err(1, "chmod"); + ksft_exit_fail_msg("chmod - %s\n", strerror(errno)); } =20 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) !=3D 0) - err(1, "capng_apply"); + ksft_exit_fail_msg("capng_apply - %s\n", strerror(errno)); =20 if (uid =3D=3D 0) { - printf("[RUN]\tRoot =3D> ep\n"); + ksft_print_msg("[RUN]\tRoot =3D> ep\n"); if (fork_wait()) exec_validate_cap(true, true, false, false); } else { - printf("[RUN]\tNon-root =3D> no caps\n"); + ksft_print_msg("[RUN]\tNon-root =3D> no caps\n"); if (fork_wait()) exec_validate_cap(false, false, false, false); } =20 - printf("[OK]\tCheck cap_ambient manipulation rules\n"); + ksft_print_msg("Check cap_ambient manipulation rules\n"); =20 /* 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) !=3D -1 || errno !=3D EPERM) { if (errno =3D=3D 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-inherit= able 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"); =20 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) !=3D 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) != =3D -1 || errno !=3D EPERM) { - printf("[FAIL]\tPR_CAP_AMBIENT_RAISE should have failed on a non-permi= tted 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"); =20 capng_update(CAPNG_ADD, CAPNG_INHERITABLE, CAP_NET_BIND_SERVICE); if (capng_apply(CAPNG_SELECT_CAPS) !=3D 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) !=3D 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"); =20 if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET, CAP_NET_BIND_SERVICE, = 0, 0, 0) !=3D 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; } =20 if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_CLEAR_ALL, 0, 0, 0, 0) !=3D 0)= - err(1, "PR_CAP_AMBIENT_CLEAR_ALL"); + ksft_exit_fail_msg("PR_CAP_AMBIENT_CLEAR_ALL - %s\n", + strerror(errno)); =20 if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET, CAP_NET_BIND_SERVICE, = 0, 0, 0) !=3D 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; } =20 if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, CAP_NET_BIND_SERVICE, 0= , 0, 0) !=3D 0) - err(1, "PR_CAP_AMBIENT_RAISE"); + ksft_exit_fail_msg("PR_CAP_AMBIENT_RAISE - %s\n", + strerror(errno)); =20 capng_update(CAPNG_DROP, CAPNG_INHERITABLE, CAP_NET_BIND_SERVICE); if (capng_apply(CAPNG_SELECT_CAPS) !=3D 0) - err(1, "capng_apply"); + ksft_exit_fail_msg("capng_apply - %s\n", strerror(errno)); =20 if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET, CAP_NET_BIND_SERVICE, = 0, 0, 0) !=3D 0) { - printf("[FAIL]\tDropping I should have dropped A\n"); + ksft_test_result_fail("Dropping I should have dropped A\n"); return 1; } =20 - printf("[OK]\tBasic manipulation appears to work\n"); + ksft_test_result_pass("Basic manipulation appears to work\n"); =20 capng_update(CAPNG_ADD, CAPNG_INHERITABLE, CAP_NET_BIND_SERVICE); if (capng_apply(CAPNG_SELECT_CAPS) !=3D 0) - err(1, "capng_apply"); + ksft_exit_fail_msg("capng_apply - %s\n", strerror(errno)); if (uid =3D=3D 0) { - printf("[RUN]\tRoot +i =3D> eip\n"); + ksft_print_msg("[RUN]\tRoot +i =3D> eip\n"); if (fork_wait()) exec_validate_cap(true, true, true, false); } else { - printf("[RUN]\tNon-root +i =3D> i\n"); + ksft_print_msg("[RUN]\tNon-root +i =3D> i\n"); if (fork_wait()) exec_validate_cap(false, false, true, false); } =20 if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, CAP_NET_BIND_SERVICE, 0= , 0, 0) !=3D 0) - err(1, "PR_CAP_AMBIENT_RAISE"); + ksft_exit_fail_msg("PR_CAP_AMBIENT_RAISE - %s\n", + strerror(errno)); =20 - printf("[RUN]\tUID %d +ia =3D> eipa\n", uid); + ksft_print_msg("[RUN]\tUID %d +ia =3D> eipa\n", uid); if (fork_wait()) exec_validate_cap(true, true, true, true); =20 /* The remaining tests need real privilege */ =20 if (!have_outer_privilege) { - printf("[SKIP]\tSUID/SGID tests (needs privilege)\n"); + ksft_test_result_skip("SUID/SGID tests (needs privilege)\n"); goto done; } =20 if (uid =3D=3D 0) { - printf("[RUN]\tRoot +ia, suidroot =3D> eipa\n"); + ksft_print_msg("[RUN]\tRoot +ia, suidroot =3D> eipa\n"); if (fork_wait()) exec_other_validate_cap("./validate_cap_suidroot", true, true, true, true); =20 - printf("[RUN]\tRoot +ia, suidnonroot =3D> ip\n"); + ksft_print_msg("[RUN]\tRoot +ia, suidnonroot =3D> ip\n"); if (fork_wait()) exec_other_validate_cap("./validate_cap_suidnonroot", false, true, true, false); =20 - printf("[RUN]\tRoot +ia, sgidroot =3D> eipa\n"); + ksft_print_msg("[RUN]\tRoot +ia, sgidroot =3D> eipa\n"); if (fork_wait()) exec_other_validate_cap("./validate_cap_sgidroot", true, true, true, true); =20 if (fork_wait()) { - printf("[RUN]\tRoot, gid !=3D 0, +ia, sgidroot =3D> eip\n"); + ksft_print_msg( + "[RUN]\tRoot, gid !=3D 0, +ia, sgidroot =3D> eip\n"); if (setresgid(1, 1, 1) !=3D 0) - err(1, "setresgid"); + ksft_exit_fail_msg("setresgid - %s\n", + strerror(errno)); exec_other_validate_cap("./validate_cap_sgidroot", true, true, true, false); } =20 - printf("[RUN]\tRoot +ia, sgidnonroot =3D> eip\n"); + ksft_print_msg("[RUN]\tRoot +ia, sgidnonroot =3D> eip\n"); if (fork_wait()) exec_other_validate_cap("./validate_cap_sgidnonroot", true, true, true, false); } else { - printf("[RUN]\tNon-root +ia, sgidnonroot =3D> i\n"); - exec_other_validate_cap("./validate_cap_sgidnonroot", + ksft_print_msg("[RUN]\tNon-root +ia, sgidnonroot =3D> i\n"); + if (fork_wait()) + exec_other_validate_cap("./validate_cap_sgidnonroot", false, false, true, false); =20 if (fork_wait()) { - printf("[RUN]\tNon-root +ia, sgidroot =3D> i\n"); + ksft_print_msg("[RUN]\tNon-root +ia, sgidroot =3D> i\n"); if (setresgid(1, 1, 1) !=3D 0) - err(1, "setresgid"); + ksft_exit_fail_msg("setresgid - %s\n", + strerror(errno)); exec_other_validate_cap("./validate_cap_sgidroot", false, false, true, false); } } =20 done: + ksft_print_cnts(); return nerrs ? 1 : 0; } =20 @@ -400,23 +429,29 @@ int main(int argc, char **argv) { char *tmp1, *tmp2, *our_path; =20 + ksft_print_header(); + /* Find our path */ tmp1 =3D strdup(argv[0]); if (!tmp1) - err(1, "strdup"); + ksft_exit_fail_msg("strdup - %s\n", strerror(errno)); tmp2 =3D dirname(tmp1); our_path =3D strdup(tmp2); if (!our_path) - err(1, "strdup"); + ksft_exit_fail_msg("strdup - %s\n", strerror(errno)); free(tmp1); =20 + mpid =3D getpid(); + if (fork_wait()) { - printf("[RUN]\t+++ Tests with uid =3D=3D 0 +++\n"); + ksft_print_msg("[RUN]\t+++ Tests with uid =3D=3D 0 +++\n"); return do_tests(0, our_path); } =20 + ksft_print_msg("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D\n"); + if (fork_wait()) { - printf("[RUN]\t+++ Tests with uid !=3D 0 +++\n"); + ksft_print_msg("[RUN]\t+++ Tests with uid !=3D 0 +++\n"); return do_tests(1, our_path); } =20 diff --git a/tools/testing/selftests/capabilities/validate_cap.c b/tools/= testing/selftests/capabilities/validate_cap.c index dd3c45f7b23c..694cd73d4493 100644 --- a/tools/testing/selftests/capabilities/validate_cap.c +++ b/tools/testing/selftests/capabilities/validate_cap.c @@ -1,5 +1,4 @@ #include -#include #include #include #include @@ -7,6 +6,8 @@ #include #include =20 +#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; + } } =20 int main(int argc, char **argv) @@ -39,7 +42,7 @@ int main(int argc, char **argv) */ =20 if (argc !=3D 5) - errx(1, "wrong argc"); + ksft_exit_fail_msg("wrong argc\n"); =20 #ifdef HAVE_GETAUXVAL if (getauxval(AT_SECURE)) @@ -51,23 +54,26 @@ int main(int argc, char **argv) capng_get_caps_process(); =20 if (capng_have_capability(CAPNG_EFFECTIVE, CAP_NET_BIND_SERVICE) !=3D b= ool_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) !=3D b= ool_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) !=3D= bool_arg(argv, 3)) { - printf("[FAIL]\tWrong inheritable state%s\n", atsec); + ksft_print_msg("Wrong inheritable state%s\n", atsec); return 1; } =20 if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET, CAP_NET_BIND_SERVICE, = 0, 0, 0) !=3D bool_arg(argv, 4)) { - printf("[FAIL]\tWrong ambient state%s\n", atsec); + ksft_print_msg("Wrong ambient state%s\n", atsec); return 1; } =20 - printf("[OK]\tCapabilities after execve were correct\n"); + ksft_print_msg("%s: Capabilities after execve were correct\n", + "validate_cap:"); return 0; } diff --git a/tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh b/too= ls/testing/selftests/cpu-hotplug/cpu-on-off-test.sh index 98b1d6565f2c..b18b253d7bfb 100755 --- a/tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh +++ b/tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh @@ -28,6 +28,12 @@ prerequisite() echo "CPU online/offline summary:" online_cpus=3D`cat $SYSFS/devices/system/cpu/online` online_max=3D${online_cpus##*-} + + if [[ "$online_cpus" =3D "$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" =20 offline_cpus=3D`cat $SYSFS/devices/system/cpu/offline` @@ -89,8 +95,10 @@ online_cpu_expect_success() =20 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 } =20 @@ -100,8 +108,10 @@ online_cpu_expect_fail() =20 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 } =20 @@ -111,8 +121,10 @@ offline_cpu_expect_success() =20 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 } =20 @@ -122,8 +134,10 @@ offline_cpu_expect_fail() =20 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 } =20 diff --git a/tools/testing/selftests/ftrace/ftracetest b/tools/testing/se= lftests/ftrace/ftracetest index 14a03ea1e21d..abc706cf7702 100755 --- a/tools/testing/selftests/ftrace/ftracetest +++ b/tools/testing/selftests/ftrace/ftracetest @@ -8,15 +8,18 @@ # Released under the terms of the GPL v2. =20 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 Save logs on the " +echo " If is -, all logs output in console only" exit $1 } =20 @@ -47,7 +50,7 @@ parse_opts() { # opts local OPT_TEST_CASES=3D local OPT_TEST_DIR=3D =20 - while [ "$1" ]; do + while [ ! -z "$1" ]; do case "$1" in --help|-h) usage 0 @@ -56,15 +59,20 @@ parse_opts() { # opts KEEP_LOG=3D1 shift 1 ;; - --verbose|-v|-vv) + --verbose|-v|-vv|-vvv) VERBOSE=3D$((VERBOSE + 1)) [ $1 =3D '-vv' ] && VERBOSE=3D$((VERBOSE + 1)) + [ $1 =3D '-vvv' ] && VERBOSE=3D$((VERBOSE + 2)) shift 1 ;; --debug|-d) DEBUG=3D1 shift 1 ;; + --fail-unsupported) + UNSUPPORTED_RESULT=3D1 + shift 1 + ;; --logdir|-l) LOG_DIR=3D$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=3D$OPT_TEST_CASES fi } @@ -108,6 +116,7 @@ LOG_DIR=3D$TOP_DIR/logs/`date +%Y%m%d-%H%M%S`/ KEEP_LOG=3D0 DEBUG=3D0 VERBOSE=3D0 +UNSUPPORTED_RESULT=3D0 # Parse command-line options parse_opts $* =20 @@ -119,14 +128,20 @@ if [ -z "$TRACING_DIR" -o ! -d "$TRACING_DIR" ]; th= en fi =20 # Preparing logs -LOG_FILE=3D$LOG_DIR/ftracetest.log -mkdir -p $LOG_DIR || errexit "Failed to make a log directory: $LOG_DIR" -date > $LOG_FILE +if [ "x$LOG_DIR" =3D "x-" ]; then + LOG_FILE=3D + date +else + LOG_FILE=3D$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 "=3D=3D=3D Ftrace unit tests =3D=3D=3D" =20 @@ -187,7 +202,7 @@ eval_result() { # sigval $UNSUPPORTED) prlog " [UNSUPPORTED]" UNSUPPORTED_CASES=3D"$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=3D`basename $1` - local testlog=3D`mktemp $LOG_DIR/${testname}-log.XXXXXX` + if [ ! -z "$LOG_FILE" ] ; then + local testlog=3D`mktemp $LOG_DIR/${testname}-log.XXXXXX` + else + local testlog=3D/proc/self/fd/1 + fi export TMPDIR=3D`mktemp -d /tmp/ftracetest-dir.XXXXXX` testcase $1 echo "execute$INSTANCE: "$1 > $testlog SIG_RESULT=3D0 - 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=3D1 fi rm -rf $TMPDIR diff --git a/tools/testing/selftests/futex/functional/futex_requeue_pi.c = b/tools/testing/selftests/futex/functional/futex_requeue_pi.c index d24ab7421e73..54cd5c414e82 100644 --- a/tools/testing/selftests/futex/functional/futex_requeue_pi.c +++ b/tools/testing/selftests/futex/functional/futex_requeue_pi.c @@ -394,9 +394,11 @@ int main(int argc, char *argv[]) } } =20 - printf("%s: Test requeue functionality\n", basename(argv[0])); - printf("\tArguments: broadcast=3D%d locked=3D%d owner=3D%d timeout=3D%l= dns\n", - broadcast, locked, owner, timeout_ns); + ksft_print_header(); + ksft_print_msg("%s: Test requeue functionality\n", basename(argv[0])); + ksft_print_msg( + "\tArguments: broadcast=3D%d locked=3D%d owner=3D%d timeout=3D%ldns\n"= , + broadcast, locked, owner, timeout_ns); =20 /* * FIXME: unit_test is obsolete now that we parse options and the diff --git a/tools/testing/selftests/futex/functional/futex_requeue_pi_mi= smatched_ops.c b/tools/testing/selftests/futex/functional/futex_requeue_p= i_mismatched_ops.c index e0a798ad0d21..08187a16507f 100644 --- a/tools/testing/selftests/futex/functional/futex_requeue_pi_mismatche= d_ops.c +++ b/tools/testing/selftests/futex/functional/futex_requeue_pi_mismatche= d_ops.c @@ -78,7 +78,8 @@ int main(int argc, char *argv[]) } } =20 - printf("%s: Detect mismatched requeue_pi operations\n", + ksft_print_header(); + ksft_print_msg("%s: Detect mismatched requeue_pi operations\n", basename(argv[0])); =20 if (pthread_create(&child, NULL, blocking_child, NULL)) { diff --git a/tools/testing/selftests/futex/functional/futex_requeue_pi_si= gnal_restart.c b/tools/testing/selftests/futex/functional/futex_requeue_p= i_signal_restart.c index 982f83577501..f0542a344d95 100644 --- a/tools/testing/selftests/futex/functional/futex_requeue_pi_signal_re= start.c +++ b/tools/testing/selftests/futex/functional/futex_requeue_pi_signal_re= start.c @@ -143,9 +143,10 @@ int main(int argc, char *argv[]) } } =20 - printf("%s: Test signal handling during requeue_pi\n", + ksft_print_header(); + ksft_print_msg("%s: Test signal handling during requeue_pi\n", basename(argv[0])); - printf("\tArguments: \n"); + ksft_print_msg("\tArguments: \n"); =20 sa.sa_handler =3D handle_signal; sigemptyset(&sa.sa_mask); diff --git a/tools/testing/selftests/futex/functional/futex_wait_private_= mapped_file.c b/tools/testing/selftests/futex/functional/futex_wait_priva= te_mapped_file.c index bdc48dc047e5..6216de828093 100644 --- a/tools/testing/selftests/futex/functional/futex_wait_private_mapped_= file.c +++ b/tools/testing/selftests/futex/functional/futex_wait_private_mapped_= file.c @@ -97,8 +97,10 @@ int main(int argc, char **argv) } } =20 - printf("%s: Test the futex value of private file mappings in FUTEX_WAIT= \n", - basename(argv[0])); + ksft_print_header(); + ksft_print_msg( + "%s: Test the futex value of private file mappings in FUTEX_WAIT\n", + basename(argv[0])); =20 ret =3D pthread_create(&thr, NULL, thr_futex_wait, NULL); if (ret < 0) { diff --git a/tools/testing/selftests/futex/functional/futex_wait_timeout.= c b/tools/testing/selftests/futex/functional/futex_wait_timeout.c index 6aadd560366e..bab3dfe1787f 100644 --- a/tools/testing/selftests/futex/functional/futex_wait_timeout.c +++ b/tools/testing/selftests/futex/functional/futex_wait_timeout.c @@ -68,9 +68,10 @@ int main(int argc, char *argv[]) } } =20 - printf("%s: Block on a futex and wait for timeout\n", + ksft_print_header(); + ksft_print_msg("%s: Block on a futex and wait for timeout\n", basename(argv[0])); - printf("\tArguments: timeout=3D%ldns\n", timeout_ns); + ksft_print_msg("\tArguments: timeout=3D%ldns\n", timeout_ns); =20 /* initialize timeout */ to.tv_sec =3D 0; diff --git a/tools/testing/selftests/futex/functional/futex_wait_uninitia= lized_heap.c b/tools/testing/selftests/futex/functional/futex_wait_uninit= ialized_heap.c index d237a8b702f0..26975322545b 100644 --- a/tools/testing/selftests/futex/functional/futex_wait_uninitialized_h= eap.c +++ b/tools/testing/selftests/futex/functional/futex_wait_uninitialized_h= eap.c @@ -99,7 +99,8 @@ int main(int argc, char **argv) exit(1); } =20 - printf("%s: Test the uninitialized futex value in FUTEX_WAIT\n", + ksft_print_header(); + ksft_print_msg("%s: Test the uninitialized futex value in FUTEX_WAIT\n"= , basename(argv[0])); =20 =20 diff --git a/tools/testing/selftests/futex/functional/futex_wait_wouldblo= ck.c b/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c index 9a2c56fa7305..da15a63269b4 100644 --- a/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c +++ b/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c @@ -64,7 +64,8 @@ int main(int argc, char *argv[]) } } =20 - printf("%s: Test the unexpected futex value in FUTEX_WAIT\n", + ksft_print_header(); + ksft_print_msg("%s: Test the unexpected futex value in FUTEX_WAIT\n", basename(argv[0])); =20 info("Calling futex_wait on f1: %u @ %p with val=3D%u\n", f1, &f1, f1+1= ); diff --git a/tools/testing/selftests/futex/include/logging.h b/tools/test= ing/selftests/futex/include/logging.h index 4e7944984fbb..01989644e50a 100644 --- a/tools/testing/selftests/futex/include/logging.h +++ b/tools/testing/selftests/futex/include/logging.h @@ -109,22 +109,20 @@ void log_verbosity(int level) */ void print_result(const char *test_name, int ret) { - const char *result =3D "Unknown return code"; - switch (ret) { case RET_PASS: - ksft_inc_pass_cnt(); - result =3D PASS; - break; + ksft_test_result_pass("%s\n", test_name); + ksft_print_cnts(); + return; case RET_ERROR: - result =3D ERROR; - break; + ksft_test_result_error("%s\n", test_name); + ksft_print_cnts(); + return; case RET_FAIL: - ksft_inc_fail_cnt(); - result =3D FAIL; - break; + ksft_test_result_fail("%s\n", test_name); + ksft_print_cnts(); + return; } - printf("selftests: %s [%s]\n", test_name, result); } =20 /* log level macros */ diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftest= s/kselftest.h index 08e90c2cc5cb..1ae565ed9bf0 100644 --- a/tools/testing/selftests/kselftest.h +++ b/tools/testing/selftests/kselftest.h @@ -19,7 +19,8 @@ #define KSFT_FAIL 1 #define KSFT_XFAIL 2 #define KSFT_XPASS 3 -#define KSFT_SKIP 4 +/* Treat skip as pass */ +#define KSFT_SKIP KSFT_PASS =20 /* counters */ struct ksft_count { @@ -28,6 +29,7 @@ struct ksft_count { unsigned int ksft_xfail; unsigned int ksft_xpass; unsigned int ksft_xskip; + unsigned int ksft_error; }; =20 static struct ksft_count ksft_cnt; @@ -36,7 +38,7 @@ static inline int ksft_test_num(void) { return ksft_cnt.ksft_pass + ksft_cnt.ksft_fail + ksft_cnt.ksft_xfail + ksft_cnt.ksft_xpass + - ksft_cnt.ksft_xskip; + ksft_cnt.ksft_xskip + ksft_cnt.ksft_error; } =20 static inline void ksft_inc_pass_cnt(void) { ksft_cnt.ksft_pass++; } @@ -44,6 +46,14 @@ static inline void ksft_inc_fail_cnt(void) { ksft_cnt.= ksft_fail++; } static inline void ksft_inc_xfail_cnt(void) { ksft_cnt.ksft_xfail++; } static inline void ksft_inc_xpass_cnt(void) { ksft_cnt.ksft_xpass++; } static inline void ksft_inc_xskip_cnt(void) { ksft_cnt.ksft_xskip++; } +static inline void ksft_inc_error_cnt(void) { ksft_cnt.ksft_error++; } + +static inline int ksft_get_pass_cnt(void) { return ksft_cnt.ksft_pass; }= +static inline int ksft_get_fail_cnt(void) { return ksft_cnt.ksft_fail; }= +static inline int ksft_get_xfail_cnt(void) { return ksft_cnt.ksft_xfail;= } +static inline int ksft_get_xpass_cnt(void) { return ksft_cnt.ksft_xpass;= } +static inline int ksft_get_xskip_cnt(void) { return ksft_cnt.ksft_xskip;= } +static inline int ksft_get_error_cnt(void) { return ksft_cnt.ksft_error;= } =20 static inline void ksft_print_header(void) { @@ -52,6 +62,10 @@ static inline void ksft_print_header(void) =20 static inline void ksft_print_cnts(void) { + 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()); } =20 @@ -101,6 +115,18 @@ static inline void ksft_test_result_skip(const char = *msg, ...) va_end(args); } =20 +static inline void ksft_test_result_error(const char *msg, ...) +{ + va_list args; + + ksft_cnt.ksft_error++; + + va_start(args, msg); + printf("not ok %d # error ", ksft_test_num()); + vprintf(msg, args); + va_end(args); +} + static inline int ksft_exit_pass(void) { ksft_print_cnts(); diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/= selftests/kselftest_harness.h index c56f72e07cd7..e81bd28bdd89 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -51,6 +51,9 @@ #define __KSELFTEST_HARNESS_H =20 #define _GNU_SOURCE +#include +#include +#include #include #include #include @@ -84,6 +87,14 @@ * E.g., #define TH_LOG_ENABLED 1 * * If no definition is provided, logging is enabled by default. + * + * If there is no way to print an error message for the process running = the + * test (e.g. not allowed to write to stderr), it is still possible to g= et the + * ASSERT_* number for which the test failed. This behavior can be enab= led by + * writing `_metadata->no_print =3D true;` before the check sequence tha= t is + * unable to print. When an error occur, instead of printing an error m= essage + * and calling `abort(3)`, the test process call `_exit(2)` with the ass= ert + * number as argument, which is then printed by the parent process. */ #define TH_LOG(fmt, ...) do { \ if (TH_LOG_ENABLED) \ @@ -555,12 +566,18 @@ * return while still providing an optional block to the API consumer. */ #define OPTIONAL_HANDLER(_assert) \ - for (; _metadata->trigger; _metadata->trigger =3D __bail(_assert)) + for (; _metadata->trigger; _metadata->trigger =3D \ + __bail(_assert, _metadata->no_print, _metadata->step)) + +#define __INC_STEP(_metadata) \ + if (_metadata->passed && _metadata->step < 255) \ + _metadata->step++; =20 #define __EXPECT(_expected, _seen, _t, _assert) do { \ /* Avoid multiple evaluation of the cases */ \ __typeof__(_expected) __exp =3D (_expected); \ __typeof__(_seen) __seen =3D (_seen); \ + if (_assert) __INC_STEP(_metadata); \ if (!(__exp _t __seen)) { \ unsigned long long __exp_print =3D (uintptr_t)__exp; \ unsigned long long __seen_print =3D (uintptr_t)__seen; \ @@ -576,6 +593,7 @@ #define __EXPECT_STR(_expected, _seen, _t, _assert) do { \ const char *__exp =3D (_expected); \ const char *__seen =3D (_seen); \ + if (_assert) __INC_STEP(_metadata); \ if (!(strcmp(__exp, __seen) _t 0)) { \ __TH_LOG("Expected '%s' %s '%s'.", __exp, #_t, __seen); \ _metadata->passed =3D 0; \ @@ -590,6 +608,8 @@ struct __test_metadata { int termsig; int passed; int trigger; /* extra handler after the evaluation */ + __u8 step; + bool no_print; /* manual trigger when TH_LOG_STREAM is not available */= struct __test_metadata *prev, *next; }; =20 @@ -634,10 +654,13 @@ static inline void __register_test(struct __test_me= tadata *t) } } =20 -static inline int __bail(int for_realz) +static inline int __bail(int for_realz, bool no_print, __u8 step) { - if (for_realz) + if (for_realz) { + if (no_print) + _exit(step); abort(); + } return 0; } =20 @@ -655,18 +678,24 @@ void __run_test(struct __test_metadata *t) t->passed =3D 0; } else if (child_pid =3D=3D 0) { t->fn(t); - _exit(t->passed); + /* return the step that failed or 0 */ + _exit(t->passed ? 0 : t->step); } else { /* TODO(wad) add timeout support. */ waitpid(child_pid, &status, 0); if (WIFEXITED(status)) { - t->passed =3D t->termsig =3D=3D -1 ? WEXITSTATUS(status) : 0; + t->passed =3D t->termsig =3D=3D -1 ? !WEXITSTATUS(status) : 0; if (t->termsig !=3D -1) { fprintf(TH_LOG_STREAM, "%s: Test exited normally " "instead of by signal (code: %d)\n", t->name, WEXITSTATUS(status)); + } else if (!t->passed) { + fprintf(TH_LOG_STREAM, + "%s: Test failed at step #%d\n", + t->name, + WEXITSTATUS(status)); } } else if (WIFSIGNALED(status)) { t->passed =3D 0; diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib= =2Emk index 959273c3a52e..693616651da5 100644 --- a/tools/testing/selftests/lib.mk +++ b/tools/testing/selftests/lib.mk @@ -11,15 +11,26 @@ TEST_GEN_FILES :=3D $(patsubst %,$(OUTPUT)/%,$(TEST_G= EN_FILES)) =20 all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) =20 +.ONESHELL: define RUN_TESTS - @for TEST in $(TEST_GEN_PROGS) $(TEST_PROGS); do \ + @test_num=3D`echo 0`; + @echo "TAP version 13"; + @for TEST in $(1); do \ BASENAME_TEST=3D`basename $$TEST`; \ - cd `dirname $$TEST`; (./$$BASENAME_TEST && echo "selftests: $$BASENAME= _TEST [PASS]") || echo "selftests: $$BASENAME_TEST [FAIL]"; cd -;\ + test_num=3D`echo $$test_num+1 | bc`; \ + echo "selftests: $$BASENAME_TEST"; \ + echo "=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D"; \ + if [ ! -x $$BASENAME_TEST ]; then \ + echo "selftests: Warning: file $$BASENAME_TEST is not executable, cor= rect this.";\ + echo "not ok 1..$$test_num selftests: $$BASENAME_TEST [FAIL]"; \ + else \ + cd `dirname $$TEST` > /dev/null; (./$$BASENAME_TEST && echo "ok 1..$$= test_num selftests: $$BASENAME_TEST [PASS]") || echo "not ok 1..$$test_nu= m selftests: $$BASENAME_TEST [FAIL]"; cd - > /dev/null;\ + fi; \ done; endef =20 run_tests: all - $(RUN_TESTS) + $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_PROGS)) =20 define INSTALL_RULE @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" !=3D "X" ]; t= hen \ diff --git a/tools/testing/selftests/memfd/fuse_test.c b/tools/testing/se= lftests/memfd/fuse_test.c index 67908b18f035..7f3617274bf5 100644 --- a/tools/testing/selftests/memfd/fuse_test.c +++ b/tools/testing/selftests/memfd/fuse_test.c @@ -33,7 +33,7 @@ #include =20 #define MFD_DEF_SIZE 8192 -#define STACK_SIZE 65535 +#define STACK_SIZE 65536 =20 static int sys_memfd_create(const char *name, unsigned int flags) diff --git a/tools/testing/selftests/nsfs/config b/tools/testing/selftest= s/nsfs/config new file mode 100644 index 000000000000..598d0a225fc9 --- /dev/null +++ b/tools/testing/selftests/nsfs/config @@ -0,0 +1,3 @@ +CONFIG_USER_NS=3Dy +CONFIG_UTS_NS=3Dy +CONFIG_PID_NS=3Dy diff --git a/tools/testing/selftests/pstore/.gitignore b/tools/testing/se= lftests/pstore/.gitignore new file mode 100644 index 000000000000..5a4a26e5464b --- /dev/null +++ b/tools/testing/selftests/pstore/.gitignore @@ -0,0 +1,2 @@ +logs +*uuid diff --git a/tools/testing/selftests/ptp/Makefile b/tools/testing/selftes= ts/ptp/Makefile index 83dd42b2129e..d4064c742c26 100644 --- a/tools/testing/selftests/ptp/Makefile +++ b/tools/testing/selftests/ptp/Makefile @@ -1,3 +1,4 @@ +CFLAGS +=3D -I../../../../usr/include/ TEST_PROGS :=3D testptp LDLIBS +=3D -lrt all: $(TEST_PROGS) diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testin= g/selftests/seccomp/seccomp_bpf.c index 73f5ea6778ce..4d6f92a9df6b 100644 --- a/tools/testing/selftests/seccomp/seccomp_bpf.c +++ b/tools/testing/selftests/seccomp/seccomp_bpf.c @@ -107,7 +107,7 @@ TEST(mode_strict_support) ASSERT_EQ(0, ret) { TH_LOG("Kernel does not support CONFIG_SECCOMP"); } - syscall(__NR_exit, 1); + syscall(__NR_exit, 0); } =20 TEST_SIGNAL(mode_strict_cannot_call_prctl, SIGKILL) diff --git a/tools/testing/selftests/sigaltstack/sas.c b/tools/testing/se= lftests/sigaltstack/sas.c index ccd07343d418..7d406c3973ba 100644 --- a/tools/testing/selftests/sigaltstack/sas.c +++ b/tools/testing/selftests/sigaltstack/sas.c @@ -17,6 +17,8 @@ #include #include =20 +#include "../kselftest.h" + #ifndef SS_AUTODISARM #define SS_AUTODISARM (1U << 31) #endif @@ -41,8 +43,7 @@ void my_usr1(int sig, siginfo_t *si, void *u) =20 if (sp < (unsigned long)sstack || sp >=3D (unsigned long)sstack + SIGSTKSZ) { - printf("[FAIL]\tSP is not on sigaltstack\n"); - exit(EXIT_FAILURE); + ksft_exit_fail_msg("SP is not on sigaltstack\n"); } /* put some data on stack. other sighandler will try to overwrite it */= aa =3D alloca(1024); @@ -50,21 +51,22 @@ void my_usr1(int sig, siginfo_t *si, void *u) p =3D (struct stk_data *)(aa + 512); strcpy(p->msg, msg); p->flag =3D 1; - printf("[RUN]\tsignal USR1\n"); + ksft_print_msg("[RUN]\tsignal USR1\n"); err =3D sigaltstack(NULL, &stk); if (err) { - perror("[FAIL]\tsigaltstack()"); + ksft_exit_fail_msg("sigaltstack() - %s\n", strerror(errno)); exit(EXIT_FAILURE); } if (stk.ss_flags !=3D SS_DISABLE) - printf("[FAIL]\tss_flags=3D%x, should be SS_DISABLE\n", + ksft_test_result_fail("tss_flags=3D%x, should be SS_DISABLE\n", stk.ss_flags); else - printf("[OK]\tsigaltstack is disabled in sighandler\n"); + ksft_test_result_pass( + "sigaltstack is disabled in sighandler\n"); swapcontext(&sc, &uc); - printf("%s\n", p->msg); + ksft_print_msg("%s\n", p->msg); if (!p->flag) { - printf("[RUN]\tAborting\n"); + ksft_exit_skip("[RUN]\tAborting\n"); exit(EXIT_FAILURE); } } @@ -74,13 +76,13 @@ void my_usr2(int sig, siginfo_t *si, void *u) char *aa; struct stk_data *p; =20 - printf("[RUN]\tsignal USR2\n"); + ksft_print_msg("[RUN]\tsignal USR2\n"); aa =3D alloca(1024); /* dont run valgrind on this */ /* try to find the data stored by previous sighandler */ p =3D memmem(aa, 1024, msg, strlen(msg)); if (p) { - printf("[FAIL]\tsigaltstack re-used\n"); + ksft_test_result_fail("sigaltstack re-used\n"); /* corrupt the data */ strcpy(p->msg, msg2); /* tell other sighandler that his data is corrupted */ @@ -90,7 +92,7 @@ void my_usr2(int sig, siginfo_t *si, void *u) =20 static void switch_fn(void) { - printf("[RUN]\tswitched to user ctx\n"); + ksft_print_msg("[RUN]\tswitched to user ctx\n"); raise(SIGUSR2); setcontext(&sc); } @@ -101,6 +103,8 @@ int main(void) stack_t stk; int err; =20 + ksft_print_header(); + sigemptyset(&act.sa_mask); act.sa_flags =3D SA_ONSTACK | SA_SIGINFO; act.sa_sigaction =3D my_usr1; @@ -110,19 +114,20 @@ int main(void) sstack =3D mmap(NULL, SIGSTKSZ, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0); if (sstack =3D=3D MAP_FAILED) { - perror("mmap()"); + ksft_exit_fail_msg("mmap() - %s\n", strerror(errno)); return EXIT_FAILURE; } =20 err =3D sigaltstack(NULL, &stk); if (err) { - perror("[FAIL]\tsigaltstack()"); + ksft_exit_fail_msg("sigaltstack() - %s\n", strerror(errno)); exit(EXIT_FAILURE); } if (stk.ss_flags =3D=3D SS_DISABLE) { - printf("[OK]\tInitial sigaltstack state was SS_DISABLE\n"); + ksft_test_result_pass( + "Initial sigaltstack state was SS_DISABLE\n"); } else { - printf("[FAIL]\tInitial sigaltstack state was %x; " + ksft_exit_fail_msg("Initial sigaltstack state was %x; " "should have been SS_DISABLE\n", stk.ss_flags); return EXIT_FAILURE; } @@ -133,7 +138,8 @@ int main(void) err =3D sigaltstack(&stk, NULL); if (err) { if (errno =3D=3D EINVAL) { - printf("[NOTE]\tThe running kernel doesn't support SS_AUTODISARM\n");= + ksft_exit_skip( + "[NOTE]\tThe running kernel doesn't support SS_AUTODISARM\n"); /* * If test cases for the !SS_AUTODISARM variant were * added, we could still run them. We don't have any @@ -142,7 +148,9 @@ int main(void) */ return 0; } else { - perror("[FAIL]\tsigaltstack(SS_ONSTACK | SS_AUTODISARM)"); + ksft_exit_fail_msg( + "sigaltstack(SS_ONSTACK | SS_AUTODISARM) %s\n", + strerror(errno)); return EXIT_FAILURE; } } @@ -150,7 +158,7 @@ int main(void) ustack =3D mmap(NULL, SIGSTKSZ, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0); if (ustack =3D=3D MAP_FAILED) { - perror("mmap()"); + ksft_exit_fail_msg("mmap() - %s\n", strerror(errno)); return EXIT_FAILURE; } getcontext(&uc); @@ -162,16 +170,17 @@ int main(void) =20 err =3D sigaltstack(NULL, &stk); if (err) { - perror("[FAIL]\tsigaltstack()"); + ksft_exit_fail_msg("sigaltstack() - %s\n", strerror(errno)); exit(EXIT_FAILURE); } if (stk.ss_flags !=3D SS_AUTODISARM) { - printf("[FAIL]\tss_flags=3D%x, should be SS_AUTODISARM\n", + ksft_exit_fail_msg("ss_flags=3D%x, should be SS_AUTODISARM\n", stk.ss_flags); exit(EXIT_FAILURE); } - printf("[OK]\tsigaltstack is still SS_AUTODISARM after signal\n"); + ksft_test_result_pass( + "sigaltstack is still SS_AUTODISARM after signal\n"); =20 - printf("[OK]\tTest passed\n"); + ksft_exit_pass(); return 0; } diff --git a/tools/testing/selftests/splice/.gitignore b/tools/testing/se= lftests/splice/.gitignore new file mode 100644 index 000000000000..1e23fefd68e8 --- /dev/null +++ b/tools/testing/selftests/splice/.gitignore @@ -0,0 +1 @@ +default_file_splice_read diff --git a/tools/testing/selftests/splice/Makefile b/tools/testing/self= tests/splice/Makefile index 9fc78e5e5451..7e1187e007fa 100644 --- a/tools/testing/selftests/splice/Makefile +++ b/tools/testing/selftests/splice/Makefile @@ -1,7 +1,4 @@ TEST_PROGS :=3D default_file_splice_read.sh -EXTRA :=3D default_file_splice_read -all: $(TEST_PROGS) $(EXTRA) +TEST_GEN_PROGS_EXTENDED :=3D default_file_splice_read =20 include ../lib.mk - -EXTRA_CLEAN :=3D $(EXTRA) diff --git a/tools/testing/selftests/sync/sync_test.c b/tools/testing/sel= ftests/sync/sync_test.c index 62fa666e501a..7f7938263c5c 100644 --- a/tools/testing/selftests/sync/sync_test.c +++ b/tools/testing/selftests/sync/sync_test.c @@ -31,62 +31,83 @@ #include #include #include +#include +#include =20 +#include "../kselftest.h" #include "synctest.h" =20 static int run_test(int (*test)(void), char *name) { int result; pid_t childpid; + int ret; =20 fflush(stdout); childpid =3D fork(); =20 if (childpid) { waitpid(childpid, &result, 0); - if (WIFEXITED(result)) - return WEXITSTATUS(result); + if (WIFEXITED(result)) { + ret =3D WEXITSTATUS(result); + if (!ret) + ksft_test_result_pass("[RUN]\t%s\n", name); + else + ksft_test_result_fail("[RUN]\t%s\n", name); + return ret; + } return 1; } =20 - printf("[RUN]\tExecuting %s\n", name); exit(test()); } =20 -static int sync_api_supported(void) +static void sync_api_supported(void) { struct stat sbuf; + int ret; =20 - return 0 =3D=3D stat("/sys/kernel/debug/sync/sw_sync", &sbuf); + ret =3D stat("/sys/kernel/debug/sync/sw_sync", &sbuf); + if (!ret) + return; + + if (errno =3D=3D ENOENT) + ksft_exit_skip("Sync framework not supported by kernel\n"); + + if (errno =3D=3D EACCES) + ksft_exit_skip("Run Sync test as root.\n"); + + ksft_exit_fail_msg("stat failed on /sys/kernel/debug/sync/sw_sync: %s",= + strerror(errno)); } =20 int main(void) { - int err =3D 0; + int err; =20 - if (!sync_api_supported()) { - printf("SKIP: Sync framework not supported by kernel\n"); - return 0; - } + ksft_print_header(); + + sync_api_supported(); =20 - printf("[RUN]\tTesting sync framework\n"); + ksft_print_msg("[RUN]\tTesting sync framework\n"); =20 - err +=3D RUN_TEST(test_alloc_timeline); - err +=3D RUN_TEST(test_alloc_fence); - err +=3D RUN_TEST(test_alloc_fence_negative); + RUN_TEST(test_alloc_timeline); + RUN_TEST(test_alloc_fence); + RUN_TEST(test_alloc_fence_negative); =20 - err +=3D RUN_TEST(test_fence_one_timeline_wait); - err +=3D RUN_TEST(test_fence_one_timeline_merge); - err +=3D RUN_TEST(test_fence_merge_same_fence); - err +=3D RUN_TEST(test_fence_multi_timeline_wait); - err +=3D RUN_TEST(test_stress_two_threads_shared_timeline); - err +=3D RUN_TEST(test_consumer_stress_multi_producer_single_consumer);= - err +=3D RUN_TEST(test_merge_stress_random_merge); + RUN_TEST(test_fence_one_timeline_wait); + RUN_TEST(test_fence_one_timeline_merge); + RUN_TEST(test_fence_merge_same_fence); + RUN_TEST(test_fence_multi_timeline_wait); + RUN_TEST(test_stress_two_threads_shared_timeline); + RUN_TEST(test_consumer_stress_multi_producer_single_consumer); + RUN_TEST(test_merge_stress_random_merge); =20 + err =3D ksft_get_fail_cnt(); if (err) - printf("[FAIL]\tsync errors: %d\n", err); - else - printf("[OK]\tsync\n"); + ksft_exit_fail_msg("%d out of %d sync tests failed\n", + err, ksft_test_num()); =20 - return !!err; + /* need this return to keep gcc happy */ + return ksft_exit_pass(); } diff --git a/tools/testing/selftests/sync/synctest.h b/tools/testing/self= tests/sync/synctest.h index e7d1d57dba7a..90a8e5369914 100644 --- a/tools/testing/selftests/sync/synctest.h +++ b/tools/testing/selftests/sync/synctest.h @@ -29,10 +29,11 @@ #define SELFTESTS_SYNCTEST_H =20 #include +#include "../kselftest.h" =20 #define ASSERT(cond, msg) do { \ if (!(cond)) { \ - printf("[ERROR]\t%s", (msg)); \ + ksft_print_msg("[ERROR]\t%s", (msg)); \ return 1; \ } \ } while (0) diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/self= tests/timers/Makefile index a9b86133b9b3..ae4593115408 100644 --- a/tools/testing/selftests/timers/Makefile +++ b/tools/testing/selftests/timers/Makefile @@ -1,5 +1,4 @@ -BUILD_FLAGS =3D -DKTEST -CFLAGS +=3D -O3 -Wl,-no-as-needed -Wall $(BUILD_FLAGS) +CFLAGS +=3D -O3 -Wl,-no-as-needed -Wall LDFLAGS +=3D -lrt -lpthread -lm =20 # these are all "safe" tests that don't modify @@ -7,9 +6,11 @@ LDFLAGS +=3D -lrt -lpthread -lm TEST_GEN_PROGS =3D posix_timers nanosleep nsleep-lat set-timer-lat mqueu= e-lat \ inconsistency-check raw_skew threadtest rtctest =20 -TEST_GEN_PROGS_EXTENDED =3D alarmtimer-suspend valid-adjtimex adjtick ch= ange_skew \ +DESTRUCTIVE_TESTS =3D alarmtimer-suspend valid-adjtimex adjtick change_s= kew \ skew_consistency clocksource-switch freq-step leap-a-day \ - leapcrash set-tai set-2038 set-tz rtctest_setdate + leapcrash set-tai set-2038 set-tz + +TEST_GEN_PROGS_EXTENDED =3D $(DESTRUCTIVE_TESTS) rtctest_setdate =20 =20 include ../lib.mk @@ -18,16 +19,4 @@ include ../lib.mk # and may modify the system time or trigger # other behavior like suspend run_destructive_tests: run_tests - ./alarmtimer-suspend - ./valid-adjtimex - ./adjtick - ./change_skew - ./skew_consistency - ./clocksource-switch - ./freq-step - ./leap-a-day -s -i 10 - ./leapcrash - ./set-tz - ./set-tai - ./set-2038 - + $(call RUN_TESTS, $(DESTRUCTIVE_TESTS)) diff --git a/tools/testing/selftests/timers/adjtick.c b/tools/testing/sel= ftests/timers/adjtick.c index 9887fd538fec..0caca3a06bd2 100644 --- a/tools/testing/selftests/timers/adjtick.c +++ b/tools/testing/selftests/timers/adjtick.c @@ -23,18 +23,7 @@ #include #include =20 -#ifdef KTEST #include "../kselftest.h" -#else -static inline int ksft_exit_pass(void) -{ - exit(0); -} -static inline int ksft_exit_fail(void) -{ - exit(1); -} -#endif =20 #define CLOCK_MONOTONIC_RAW 4 =20 diff --git a/tools/testing/selftests/timers/alarmtimer-suspend.c b/tools/= testing/selftests/timers/alarmtimer-suspend.c index 2b361b830395..4da09dbf83ba 100644 --- a/tools/testing/selftests/timers/alarmtimer-suspend.c +++ b/tools/testing/selftests/timers/alarmtimer-suspend.c @@ -28,18 +28,7 @@ #include #include #include -#ifdef KTEST #include "../kselftest.h" -#else -static inline int ksft_exit_pass(void) -{ - exit(0); -} -static inline int ksft_exit_fail(void) -{ - exit(1); -} -#endif =20 #define CLOCK_REALTIME 0 #define CLOCK_MONOTONIC 1 diff --git a/tools/testing/selftests/timers/change_skew.c b/tools/testing= /selftests/timers/change_skew.c index cb1968977c04..c4eab7124990 100644 --- a/tools/testing/selftests/timers/change_skew.c +++ b/tools/testing/selftests/timers/change_skew.c @@ -28,18 +28,7 @@ #include #include #include -#ifdef KTEST #include "../kselftest.h" -#else -static inline int ksft_exit_pass(void) -{ - exit(0); -} -static inline int ksft_exit_fail(void) -{ - exit(1); -} -#endif =20 #define NSEC_PER_SEC 1000000000LL =20 diff --git a/tools/testing/selftests/timers/clocksource-switch.c b/tools/= testing/selftests/timers/clocksource-switch.c index 5ff165373f8b..bfc974b4572d 100644 --- a/tools/testing/selftests/timers/clocksource-switch.c +++ b/tools/testing/selftests/timers/clocksource-switch.c @@ -34,18 +34,7 @@ #include #include #include -#ifdef KTEST #include "../kselftest.h" -#else -static inline int ksft_exit_pass(void) -{ - exit(0); -} -static inline int ksft_exit_fail(void) -{ - exit(1); -} -#endif =20 =20 int get_clocksources(char list[][30]) @@ -61,7 +50,7 @@ int get_clocksources(char list[][30]) =20 close(fd); =20 - for (i =3D 0; i < 30; i++) + for (i =3D 0; i < 10; i++) list[i][0] =3D '\0'; =20 head =3D buf; diff --git a/tools/testing/selftests/timers/inconsistency-check.c b/tools= /testing/selftests/timers/inconsistency-check.c index 74c60e8759a0..022d3ffe3fbf 100644 --- a/tools/testing/selftests/timers/inconsistency-check.c +++ b/tools/testing/selftests/timers/inconsistency-check.c @@ -28,18 +28,7 @@ #include #include #include -#ifdef KTEST #include "../kselftest.h" -#else -static inline int ksft_exit_pass(void) -{ - exit(0); -} -static inline int ksft_exit_fail(void) -{ - exit(1); -} -#endif =20 #define CALLS_PER_LOOP 64 #define NSEC_PER_SEC 1000000000ULL diff --git a/tools/testing/selftests/timers/leap-a-day.c b/tools/testing/= selftests/timers/leap-a-day.c index fb46ad6ac92c..19e46ed5dfb5 100644 --- a/tools/testing/selftests/timers/leap-a-day.c +++ b/tools/testing/selftests/timers/leap-a-day.c @@ -48,18 +48,7 @@ #include #include #include -#ifdef KTEST #include "../kselftest.h" -#else -static inline int ksft_exit_pass(void) -{ - exit(0); -} -static inline int ksft_exit_fail(void) -{ - exit(1); -} -#endif =20 #define NSEC_PER_SEC 1000000000ULL #define CLOCK_TAI 11 @@ -190,18 +179,18 @@ int main(int argc, char **argv) struct sigevent se; struct sigaction act; int signum =3D SIGRTMAX; - int settime =3D 0; + int settime =3D 1; int tai_time =3D 0; int insert =3D 1; - int iterations =3D -1; + int iterations =3D 10; int opt; =20 /* Process arguments */ while ((opt =3D getopt(argc, argv, "sti:")) !=3D -1) { switch (opt) { - case 's': - printf("Setting time to speed up testing\n"); - settime =3D 1; + case 'w': + printf("Only setting leap-flag, not changing time. It could take up t= o a day for leap to trigger.\n"); + settime =3D 0; break; case 'i': iterations =3D atoi(optarg); @@ -210,9 +199,10 @@ int main(int argc, char **argv) tai_time =3D 1; break; default: - printf("Usage: %s [-s] [-i ]\n", argv[0]); - printf(" -s: Set time to right before leap second each iteration\n");= - printf(" -i: Number of iterations\n"); + printf("Usage: %s [-w] [-i ]\n", argv[0]); + printf(" -w: Set flag and wait for leap second each iteration"); + printf(" (default sets time to right before leapsecond)\n"); + printf(" -i: Number of iterations (-1 =3D infinite, default is 10)\n"= ); printf(" -t: Print TAI time\n"); exit(-1); } diff --git a/tools/testing/selftests/timers/leapcrash.c b/tools/testing/s= elftests/timers/leapcrash.c index a1071bdbdeb7..830c462f605d 100644 --- a/tools/testing/selftests/timers/leapcrash.c +++ b/tools/testing/selftests/timers/leapcrash.c @@ -22,20 +22,7 @@ #include #include #include -#ifdef KTEST #include "../kselftest.h" -#else -static inline int ksft_exit_pass(void) -{ - exit(0); -} -static inline int ksft_exit_fail(void) -{ - exit(1); -} -#endif - - =20 /* clear NTP time_status & time_state */ int clear_time_state(void) diff --git a/tools/testing/selftests/timers/mqueue-lat.c b/tools/testing/= selftests/timers/mqueue-lat.c index a2a3924d0b41..1867db5d6f5e 100644 --- a/tools/testing/selftests/timers/mqueue-lat.c +++ b/tools/testing/selftests/timers/mqueue-lat.c @@ -29,18 +29,7 @@ #include #include #include -#ifdef KTEST #include "../kselftest.h" -#else -static inline int ksft_exit_pass(void) -{ - exit(0); -} -static inline int ksft_exit_fail(void) -{ - exit(1); -} -#endif =20 #define NSEC_PER_SEC 1000000000ULL =20 diff --git a/tools/testing/selftests/timers/nanosleep.c b/tools/testing/s= elftests/timers/nanosleep.c index ff942ff7c9b3..8adb0bb51d4d 100644 --- a/tools/testing/selftests/timers/nanosleep.c +++ b/tools/testing/selftests/timers/nanosleep.c @@ -27,18 +27,7 @@ #include #include #include -#ifdef KTEST #include "../kselftest.h" -#else -static inline int ksft_exit_pass(void) -{ - exit(0); -} -static inline int ksft_exit_fail(void) -{ - exit(1); -} -#endif =20 #define NSEC_PER_SEC 1000000000ULL =20 diff --git a/tools/testing/selftests/timers/nsleep-lat.c b/tools/testing/= selftests/timers/nsleep-lat.c index 2d7898fda0f1..c3c3dc10db17 100644 --- a/tools/testing/selftests/timers/nsleep-lat.c +++ b/tools/testing/selftests/timers/nsleep-lat.c @@ -24,18 +24,7 @@ #include #include #include -#ifdef KTEST #include "../kselftest.h" -#else -static inline int ksft_exit_pass(void) -{ - exit(0); -} -static inline int ksft_exit_fail(void) -{ - exit(1); -} -#endif =20 #define NSEC_PER_SEC 1000000000ULL =20 diff --git a/tools/testing/selftests/timers/raw_skew.c b/tools/testing/se= lftests/timers/raw_skew.c index 30906bfd9c1b..ca6cd146aafe 100644 --- a/tools/testing/selftests/timers/raw_skew.c +++ b/tools/testing/selftests/timers/raw_skew.c @@ -25,19 +25,7 @@ #include #include #include -#ifdef KTEST #include "../kselftest.h" -#else -static inline int ksft_exit_pass(void) -{ - exit(0); -} -static inline int ksft_exit_fail(void) -{ - exit(1); -} -#endif - =20 #define CLOCK_MONOTONIC_RAW 4 #define NSEC_PER_SEC 1000000000LL diff --git a/tools/testing/selftests/timers/rtctest.c b/tools/testing/sel= ftests/timers/rtctest.c index f61170f7b024..411eff625e66 100644 --- a/tools/testing/selftests/timers/rtctest.c +++ b/tools/testing/selftests/timers/rtctest.c @@ -221,6 +221,11 @@ int main(int argc, char **argv) /* Read the current alarm settings */ retval =3D ioctl(fd, RTC_ALM_READ, &rtc_tm); if (retval =3D=3D -1) { + if (errno =3D=3D EINVAL) { + fprintf(stderr, + "\n...EINVAL reading current alarm setting.\n"); + goto test_PIE; + } perror("RTC_ALM_READ ioctl"); exit(errno); } @@ -231,7 +236,7 @@ int main(int argc, char **argv) /* Enable alarm interrupts */ retval =3D ioctl(fd, RTC_AIE_ON, 0); if (retval =3D=3D -1) { - if (errno =3D=3D EINVAL) { + if (errno =3D=3D EINVAL || errno =3D=3D EIO) { fprintf(stderr, "\n...Alarm IRQs not supported.\n"); goto test_PIE; diff --git a/tools/testing/selftests/timers/set-2038.c b/tools/testing/se= lftests/timers/set-2038.c index c8a7e14446b1..688cfd81b531 100644 --- a/tools/testing/selftests/timers/set-2038.c +++ b/tools/testing/selftests/timers/set-2038.c @@ -27,18 +27,7 @@ #include #include #include -#ifdef KTEST #include "../kselftest.h" -#else -static inline int ksft_exit_pass(void) -{ - exit(0); -} -static inline int ksft_exit_fail(void) -{ - exit(1); -} -#endif =20 #define NSEC_PER_SEC 1000000000LL =20 diff --git a/tools/testing/selftests/timers/set-tai.c b/tools/testing/sel= ftests/timers/set-tai.c index dc88dbc8831f..70fed27d8fd3 100644 --- a/tools/testing/selftests/timers/set-tai.c +++ b/tools/testing/selftests/timers/set-tai.c @@ -23,18 +23,7 @@ #include #include #include -#ifdef KTEST #include "../kselftest.h" -#else -static inline int ksft_exit_pass(void) -{ - exit(0); -} -static inline int ksft_exit_fail(void) -{ - exit(1); -} -#endif =20 int set_tai(int offset) { diff --git a/tools/testing/selftests/timers/set-timer-lat.c b/tools/testi= ng/selftests/timers/set-timer-lat.c index 4fc98c5b0899..b343ac90b598 100644 --- a/tools/testing/selftests/timers/set-timer-lat.c +++ b/tools/testing/selftests/timers/set-timer-lat.c @@ -27,18 +27,7 @@ #include #include #include -#ifdef KTEST #include "../kselftest.h" -#else -static inline int ksft_exit_pass(void) -{ - exit(0); -} -static inline int ksft_exit_fail(void) -{ - exit(1); -} -#endif =20 #define CLOCK_REALTIME 0 #define CLOCK_MONOTONIC 1 diff --git a/tools/testing/selftests/timers/set-tz.c b/tools/testing/self= tests/timers/set-tz.c index f4184928b16b..877fd5532fee 100644 --- a/tools/testing/selftests/timers/set-tz.c +++ b/tools/testing/selftests/timers/set-tz.c @@ -23,18 +23,7 @@ #include #include #include -#ifdef KTEST #include "../kselftest.h" -#else -static inline int ksft_exit_pass(void) -{ - exit(0); -} -static inline int ksft_exit_fail(void) -{ - exit(1); -} -#endif =20 int set_tz(int min, int dst) { diff --git a/tools/testing/selftests/timers/skew_consistency.c b/tools/te= sting/selftests/timers/skew_consistency.c index 2a996e072259..022b711c78ee 100644 --- a/tools/testing/selftests/timers/skew_consistency.c +++ b/tools/testing/selftests/timers/skew_consistency.c @@ -35,18 +35,7 @@ #include #include #include -#ifdef KTEST #include "../kselftest.h" -#else -static inline int ksft_exit_pass(void) -{ - exit(0); -} -static inline int ksft_exit_fail(void) -{ - exit(1); -} -#endif =20 #define NSEC_PER_SEC 1000000000LL =20 diff --git a/tools/testing/selftests/timers/threadtest.c b/tools/testing/= selftests/timers/threadtest.c index e632e116f05e..759c9c06f1a0 100644 --- a/tools/testing/selftests/timers/threadtest.c +++ b/tools/testing/selftests/timers/threadtest.c @@ -21,19 +21,7 @@ #include #include #include -#ifdef KTEST #include "../kselftest.h" -#else -static inline int ksft_exit_pass(void) -{ - exit(0); -} -static inline int ksft_exit_fail(void) -{ - exit(1); -} -#endif - =20 /* serializes shared list access */ pthread_mutex_t list_lock =3D PTHREAD_MUTEX_INITIALIZER; diff --git a/tools/testing/selftests/timers/valid-adjtimex.c b/tools/test= ing/selftests/timers/valid-adjtimex.c index 60fe3c569bd9..d9d3ab93b31a 100644 --- a/tools/testing/selftests/timers/valid-adjtimex.c +++ b/tools/testing/selftests/timers/valid-adjtimex.c @@ -32,18 +32,7 @@ #include #include #include -#ifdef KTEST #include "../kselftest.h" -#else -static inline int ksft_exit_pass(void) -{ - exit(0); -} -static inline int ksft_exit_fail(void) -{ - exit(1); -} -#endif =20 #define NSEC_PER_SEC 1000000000LL #define USEC_PER_SEC 1000000LL diff --git a/tools/testing/selftests/watchdog/watchdog-test.c b/tools/tes= ting/selftests/watchdog/watchdog-test.c index a74c9d739d07..a1391be2dc1e 100644 --- a/tools/testing/selftests/watchdog/watchdog-test.c +++ b/tools/testing/selftests/watchdog/watchdog-test.c @@ -9,12 +9,25 @@ #include #include #include +#include #include #include #include =20 +#define DEFAULT_PING_RATE 1 + int fd; const char v =3D 'V'; +static const char sopts[] =3D "bdehp:t:"; +static const struct option lopts[] =3D { + {"bootstatus", no_argument, NULL, 'b'}, + {"disable", no_argument, NULL, 'd'}, + {"enable", no_argument, NULL, 'e'}, + {"help", no_argument, NULL, 'h'}, + {"pingrate", required_argument, NULL, 'p'}, + {"timeout", required_argument, NULL, 't'}, + {NULL, no_argument, NULL, 0x0} +}; =20 /* * This function simply sends an IOCTL to the driver, which in turn tick= s @@ -23,12 +36,12 @@ const char v =3D 'V'; */ static void keep_alive(void) { - int dummy; - int ret; + int dummy; + int ret; =20 - ret =3D ioctl(fd, WDIOC_KEEPALIVE, &dummy); - if (!ret) - printf("."); + ret =3D ioctl(fd, WDIOC_KEEPALIVE, &dummy); + if (!ret) + printf("."); } =20 /* @@ -38,75 +51,110 @@ static void keep_alive(void) =20 static void term(int sig) { - int ret =3D write(fd, &v, 1); - - close(fd); - if (ret < 0) - printf("\nStopping watchdog ticks failed (%d)...\n", errno); - else - printf("\nStopping watchdog ticks...\n"); - exit(0); + int ret =3D write(fd, &v, 1); + + close(fd); + if (ret < 0) + printf("\nStopping watchdog ticks failed (%d)...\n", errno); + else + printf("\nStopping watchdog ticks...\n"); + exit(0); +} + +static void usage(char *progname) +{ + printf("Usage: %s [options]\n", progname); + printf(" -b, --bootstatus Get last boot status (Watchdog/POR)\n"); + printf(" -d, --disable Turn off the watchdog timer\n"); + printf(" -e, --enable Turn on the watchdog timer\n"); + printf(" -h, --help Print the help message\n"); + printf(" -p, --pingrate=3DP Set ping rate to P seconds (default %d)\= n", DEFAULT_PING_RATE); + printf(" -t, --timeout=3DT Set timeout to T seconds\n"); + printf("\n"); + printf("Parameters are parsed left-to-right in real-time.\n"); + printf("Example: %s -d -t 10 -p 5 -e\n", progname); } =20 int main(int argc, char *argv[]) { - int flags; - unsigned int ping_rate =3D 1; - int ret; - int i; - - setbuf(stdout, NULL); - - fd =3D open("/dev/watchdog", O_WRONLY); - - if (fd =3D=3D -1) { - printf("Watchdog device not enabled.\n"); - exit(-1); - } - - for (i =3D 1; i < argc; i++) { - if (!strncasecmp(argv[i], "-d", 2)) { - flags =3D WDIOS_DISABLECARD; - ret =3D ioctl(fd, WDIOC_SETOPTIONS, &flags); - if (!ret) - printf("Watchdog card disabled.\n"); - } else if (!strncasecmp(argv[i], "-e", 2)) { - flags =3D WDIOS_ENABLECARD; - ret =3D ioctl(fd, WDIOC_SETOPTIONS, &flags); - if (!ret) - printf("Watchdog card enabled.\n"); - } else if (!strncasecmp(argv[i], "-t", 2) && argv[2]) { - flags =3D atoi(argv[i + 1]); - ret =3D ioctl(fd, WDIOC_SETTIMEOUT, &flags); - if (!ret) - printf("Watchdog timeout set to %u seconds.\n", flags); - i++; - } else if (!strncasecmp(argv[i], "-p", 2) && argv[2]) { - ping_rate =3D strtoul(argv[i + 1], NULL, 0); - printf("Watchdog ping rate set to %u seconds.\n", ping_rate)= ; - i++; - } else { - printf("-d to disable, -e to enable, -t to set " - "the timeout,\n-p to set the ping rate, and "); - printf("run by itself to tick the card.\n"); - printf("Parameters are parsed left-to-right in real-time.\n"= ); - printf("Example: %s -d -t 10 -p 5 -e\n", argv[0]); - goto end; - } - } - - printf("Watchdog Ticking Away!\n"); - - signal(SIGINT, term); - - while(1) { - keep_alive(); - sleep(ping_rate); - } + int flags; + unsigned int ping_rate =3D DEFAULT_PING_RATE; + int ret; + int c; + int oneshot =3D 0; + + setbuf(stdout, NULL); + + fd =3D open("/dev/watchdog", O_WRONLY); + + if (fd =3D=3D -1) { + printf("Watchdog device not enabled.\n"); + exit(-1); + } + + while ((c =3D getopt_long(argc, argv, sopts, lopts, NULL)) !=3D -1) { + switch (c) { + case 'b': + flags =3D 0; + oneshot =3D 1; + ret =3D ioctl(fd, WDIOC_GETBOOTSTATUS, &flags); + if (!ret) + printf("Last boot is caused by: %s.\n", (flags !=3D 0) ? + "Watchdog" : "Power-On-Reset"); + else + printf("WDIOC_GETBOOTSTATUS errno '%s'\n", strerror(errno)); + break; + case 'd': + flags =3D WDIOS_DISABLECARD; + ret =3D ioctl(fd, WDIOC_SETOPTIONS, &flags); + if (!ret) + printf("Watchdog card disabled.\n"); + else + printf("WDIOS_DISABLECARD errno '%s'\n", strerror(errno)); + break; + case 'e': + flags =3D WDIOS_ENABLECARD; + ret =3D ioctl(fd, WDIOC_SETOPTIONS, &flags); + if (!ret) + printf("Watchdog card enabled.\n"); + else + printf("WDIOS_ENABLECARD errno '%s'\n", strerror(errno)); + break; + case 'p': + ping_rate =3D strtoul(optarg, NULL, 0); + if (!ping_rate) + ping_rate =3D DEFAULT_PING_RATE; + printf("Watchdog ping rate set to %u seconds.\n", ping_rate); + break; + case 't': + flags =3D strtoul(optarg, NULL, 0); + ret =3D ioctl(fd, WDIOC_SETTIMEOUT, &flags); + if (!ret) + printf("Watchdog timeout set to %u seconds.\n", flags); + else + printf("WDIOC_SETTIMEOUT errno '%s'\n", strerror(errno)); + break; + default: + usage(argv[0]); + goto end; + } + } + + if (oneshot) + goto end; + + printf("Watchdog Ticking Away!\n"); + + signal(SIGINT, term); + + while (1) { + keep_alive(); + sleep(ping_rate); + } end: - ret =3D write(fd, &v, 1); - if (ret < 0) - printf("Stopping watchdog ticks failed (%d)...\n", errno); - close(fd); - return 0; + ret =3D write(fd, &v, 1); + if (ret < 0) + printf("Stopping watchdog ticks failed (%d)...\n", errno); + close(fd); + return 0; } --------------4FB839D6DD6AB6F7230BC0FA--