Commit ef3ad089 authored by Linus Torvalds's avatar Linus Torvalds

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

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

Pull Kselftest updates from Shuah Khan:
 "This update consists of:

   - TAP13 framework and changes to some tests to convert to TAP13.
     Converting kselftest output to standard format will help identify
     run to run differences and pin point failures easily. TAP13 format
     has been in use for several years and the output is human friendly.

     Please find the specification:
       https://testanything.org/tap-version-13-specification.html

     Credit goes to Tim Bird for recommending TAP13 as a suitable
     format, and to Grag KH for kick starting the work with help from
     Paul Elder and Alice Ferrazzi

     The first phase of the TAp13 conversion is included in this update.
     Future updates will include updates to rest of the tests.

   - Masami Hiramatsu fixed ftrace to run on 4.9 stable kernels.

   - Kselftest documnetation has been converted to ReST format. Document
     now has a new home under Documentation/dev-tools.

   - kselftest_harness.h is now available for general use as a result of
     Mickaël Salaün's work.

   - Several fixes to skip and/or fail tests gracefully on older
     releases"

* tag 'linux-kselftest-4.13-rc1-update' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: (48 commits)
  selftests: membarrier: use ksft_* var arg msg api
  selftests: breakpoints: breakpoint_test_arm64: convert test to use TAP13
  selftests: breakpoints: step_after_suspend_test use ksft_* var arg msg api
  selftests: breakpoint_test: use ksft_* var arg msg api
  kselftest: add ksft_print_msg() function to output general information
  kselftest: make ksft_* output functions variadic
  selftests/capabilities: Fix the test_execve test
  selftests: intel_pstate: add .gitignore
  selftests: fix memory-hotplug test
  selftests: add missing test name in memory-hotplug test
  selftests: check percentage range for memory-hotplug test
  selftests: check hot-pluggagble memory for memory-hotplug test
  selftests: typo correction for memory-hotplug test
  selftests: ftrace: Use md5sum to take less time of checking logs
  tools/testing/selftests/sysctl: Add pre-check to the value of writes_strict
  kselftest.rst: do some adjustments after ReST conversion
  selftest/net/Makefile: Specify output with $(OUTPUT)
  selftest/intel_pstate/aperf: Use LDLIBS instead of LDFLAGS
  selftest/memfd/Makefile: Fix build error
  selftests: lib: Skip tests on missing test modules
  ...
parents 37949075 e67f85fb
...@@ -242,8 +242,6 @@ kprobes.txt ...@@ -242,8 +242,6 @@ kprobes.txt
- documents the kernel probes debugging feature. - documents the kernel probes debugging feature.
kref.txt kref.txt
- docs on adding reference counters (krefs) to kernel objects. - docs on adding reference counters (krefs) to kernel objects.
kselftest.txt
- small unittests for (some) individual codepaths in the kernel.
laptops/ laptops/
- directory with laptop related info and laptop driver documentation. - directory with laptop related info and laptop driver documentation.
ldm.txt ldm.txt
......
...@@ -24,6 +24,7 @@ whole; patches welcome! ...@@ -24,6 +24,7 @@ whole; patches welcome!
kmemcheck kmemcheck
gdb-kernel-debugging gdb-kernel-debugging
kgdb kgdb
kselftest
.. only:: subproject and html .. only:: subproject and html
......
======================
Linux Kernel Selftests Linux Kernel Selftests
======================
The kernel contains a set of "self tests" under the tools/testing/selftests/ The kernel contains a set of "self tests" under the tools/testing/selftests/
directory. These are intended to be small tests to exercise individual code directory. These are intended to be small tests to exercise individual code
...@@ -15,28 +17,33 @@ hotplug test is run on 2% of hotplug capable memory instead of 10%. ...@@ -15,28 +17,33 @@ hotplug test is run on 2% of hotplug capable memory instead of 10%.
Running the selftests (hotplug tests are run in limited mode) Running the selftests (hotplug tests are run in limited mode)
============================================================= =============================================================
To build the tests: To build the tests::
$ make -C tools/testing/selftests $ make -C tools/testing/selftests
To run the tests::
To run the tests:
$ make -C tools/testing/selftests run_tests $ make -C tools/testing/selftests run_tests
To build and run the tests with a single command, use: To build and run the tests with a single command, use::
$ make kselftest $ make kselftest
- note that some tests will require root privileges. Note that some tests will require root privileges.
Running a subset of selftests Running a subset of selftests
======================================== =============================
You can use the "TARGETS" variable on the make command line to specify You can use the "TARGETS" variable on the make command line to specify
single test to run, or a list of tests to run. single test to run, or a list of tests to run.
To run only tests targeted for a single subsystem: To run only tests targeted for a single subsystem::
$ make -C tools/testing/selftests TARGETS=ptrace run_tests
$ make -C tools/testing/selftests TARGETS=ptrace run_tests
You can specify multiple tests to build and run::
You can specify multiple tests to build and run:
$ make TARGETS="size timers" kselftest $ make TARGETS="size timers" kselftest
See the top-level tools/testing/selftests/Makefile for the list of all See the top-level tools/testing/selftests/Makefile for the list of all
...@@ -46,13 +53,15 @@ possible targets. ...@@ -46,13 +53,15 @@ possible targets.
Running the full range hotplug selftests Running the full range hotplug selftests
======================================== ========================================
To build the hotplug tests: To build the hotplug tests::
$ make -C tools/testing/selftests hotplug $ make -C tools/testing/selftests hotplug
To run the hotplug tests: To run the hotplug tests::
$ make -C tools/testing/selftests run_hotplug $ make -C tools/testing/selftests run_hotplug
- note that some tests will require root privileges. Note that some tests will require root privileges.
Install selftests Install selftests
...@@ -62,11 +71,13 @@ You can use kselftest_install.sh tool installs selftests in default ...@@ -62,11 +71,13 @@ You can use kselftest_install.sh tool installs selftests in default
location which is tools/testing/selftests/kselftest or a user specified location which is tools/testing/selftests/kselftest or a user specified
location. location.
To install selftests in default location: To install selftests in default location::
$ cd tools/testing/selftests $ cd tools/testing/selftests
$ ./kselftest_install.sh $ ./kselftest_install.sh
To install selftests in a user specified location: To install selftests in a user specified location::
$ cd tools/testing/selftests $ cd tools/testing/selftests
$ ./kselftest_install.sh install_dir $ ./kselftest_install.sh install_dir
...@@ -77,10 +88,10 @@ Kselftest install as well as the Kselftest tarball provide a script ...@@ -77,10 +88,10 @@ Kselftest install as well as the Kselftest tarball provide a script
named "run_kselftest.sh" to run the tests. named "run_kselftest.sh" to run the tests.
You can simply do the following to run the installed Kselftests. Please You can simply do the following to run the installed Kselftests. Please
note some tests will require root privileges. note some tests will require root privileges::
cd kselftest $ cd kselftest
./run_kselftest.sh $ ./run_kselftest.sh
Contributing new tests Contributing new tests
====================== ======================
...@@ -96,14 +107,49 @@ In general, the rules for selftests are ...@@ -96,14 +107,49 @@ In general, the rules for selftests are
* Don't cause the top-level "make run_tests" to fail if your feature is * Don't cause the top-level "make run_tests" to fail if your feature is
unconfigured. unconfigured.
Contributing new tests(details) Contributing new tests (details)
=============================== ================================
* Use TEST_GEN_XXX if such binaries or files are generated during * Use TEST_GEN_XXX if such binaries or files are generated during
compiling. compiling.
TEST_PROGS, TEST_GEN_PROGS mean it is the excutable tested by TEST_PROGS, TEST_GEN_PROGS mean it is the excutable tested by
default. default.
TEST_PROGS_EXTENDED, TEST_GEN_PROGS_EXTENDED mean it is the TEST_PROGS_EXTENDED, TEST_GEN_PROGS_EXTENDED mean it is the
executable which is not tested by default. executable which is not tested by default.
TEST_FILES, TEST_GEN_FILES mean it is the file which is used by TEST_FILES, TEST_GEN_FILES mean it is the file which is used by
test. test.
Test Harness
============
The kselftest_harness.h file contains useful helpers to build tests. The tests
from tools/testing/selftests/seccomp/seccomp_bpf.c can be used as example.
Example
-------
.. kernel-doc:: tools/testing/selftests/kselftest_harness.h
:doc: example
Helpers
-------
.. kernel-doc:: tools/testing/selftests/kselftest_harness.h
:functions: TH_LOG TEST TEST_SIGNAL FIXTURE FIXTURE_DATA FIXTURE_SETUP
FIXTURE_TEARDOWN TEST_F TEST_HARNESS_MAIN
Operators
---------
.. kernel-doc:: tools/testing/selftests/kselftest_harness.h
:doc: operators
.. kernel-doc:: tools/testing/selftests/kselftest_harness.h
:functions: ASSERT_EQ ASSERT_NE ASSERT_LT ASSERT_LE ASSERT_GT ASSERT_GE
ASSERT_NULL ASSERT_TRUE ASSERT_NULL ASSERT_TRUE ASSERT_FALSE
ASSERT_STREQ ASSERT_STRNE EXPECT_EQ EXPECT_NE EXPECT_LT
EXPECT_LE EXPECT_GT EXPECT_GE EXPECT_NULL EXPECT_TRUE
EXPECT_FALSE EXPECT_STREQ EXPECT_STRNE
...@@ -7337,9 +7337,10 @@ KERNEL SELFTEST FRAMEWORK ...@@ -7337,9 +7337,10 @@ KERNEL SELFTEST FRAMEWORK
M: Shuah Khan <shuahkh@osg.samsung.com> M: Shuah Khan <shuahkh@osg.samsung.com>
M: Shuah Khan <shuah@kernel.org> M: Shuah Khan <shuah@kernel.org>
L: linux-kselftest@vger.kernel.org L: linux-kselftest@vger.kernel.org
T: git git://git.kernel.org/pub/scm/shuah/linux-kselftest T: git git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git
S: Maintained S: Maintained
F: tools/testing/selftests F: tools/testing/selftests/
F: Documentation/dev-tools/kselftest*
KERNEL VIRTUAL MACHINE (KVM) KERNEL VIRTUAL MACHINE (KVM)
M: Paolo Bonzini <pbonzini@redhat.com> M: Paolo Bonzini <pbonzini@redhat.com>
...@@ -11740,6 +11741,7 @@ F: kernel/seccomp.c ...@@ -11740,6 +11741,7 @@ F: kernel/seccomp.c
F: include/uapi/linux/seccomp.h F: include/uapi/linux/seccomp.h
F: include/linux/seccomp.h F: include/linux/seccomp.h
F: tools/testing/selftests/seccomp/* F: tools/testing/selftests/seccomp/*
F: tools/testing/selftests/kselftest_harness.h
F: Documentation/userspace-api/seccomp_filter.rst F: Documentation/userspace-api/seccomp_filter.rst
K: \bsecure_computing K: \bsecure_computing
K: \bTIF_SECCOMP\b K: \bTIF_SECCOMP\b
......
...@@ -4564,7 +4564,8 @@ static const char readme_msg[] = ...@@ -4564,7 +4564,8 @@ static const char readme_msg[] =
#endif #endif
#if defined(CONFIG_KPROBE_EVENTS) || defined(CONFIG_UPROBE_EVENTS) #if defined(CONFIG_KPROBE_EVENTS) || defined(CONFIG_UPROBE_EVENTS)
"\t accepts: event-definitions (one definition per line)\n" "\t accepts: event-definitions (one definition per line)\n"
"\t Format: p|r[:[<group>/]<event>] <place> [<args>]\n" "\t Format: p[:[<group>/]<event>] <place> [<args>]\n"
"\t r[maxactive][:[<group>/]<event>] <place> [<args>]\n"
"\t -:[<group>/]<event>\n" "\t -:[<group>/]<event>\n"
#ifdef CONFIG_KPROBE_EVENTS #ifdef CONFIG_KPROBE_EVENTS
"\t place: [<module>:]<symbol>[+<offset>]|<memaddr>\n" "\t place: [<module>:]<symbol>[+<offset>]|<memaddr>\n"
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
#include <signal.h> #include <signal.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <errno.h>
#include <string.h>
#include "../kselftest.h" #include "../kselftest.h"
...@@ -42,10 +44,9 @@ static void set_breakpoint_addr(void *addr, int n) ...@@ -42,10 +44,9 @@ static void set_breakpoint_addr(void *addr, int n)
ret = ptrace(PTRACE_POKEUSER, child_pid, ret = ptrace(PTRACE_POKEUSER, child_pid,
offsetof(struct user, u_debugreg[n]), addr); offsetof(struct user, u_debugreg[n]), addr);
if (ret) { if (ret)
perror("Can't set breakpoint addr\n"); ksft_exit_fail_msg("Can't set breakpoint addr: %s\n",
ksft_exit_fail(); strerror(errno));
}
} }
static void toggle_breakpoint(int n, int type, int len, static void toggle_breakpoint(int n, int type, int len,
...@@ -106,8 +107,8 @@ static void toggle_breakpoint(int n, int type, int len, ...@@ -106,8 +107,8 @@ static void toggle_breakpoint(int n, int type, int len,
ret = ptrace(PTRACE_POKEUSER, child_pid, ret = ptrace(PTRACE_POKEUSER, child_pid,
offsetof(struct user, u_debugreg[7]), dr7); offsetof(struct user, u_debugreg[7]), dr7);
if (ret) { if (ret) {
perror("Can't set dr7"); ksft_print_msg("Can't set dr7: %s\n", strerror(errno));
ksft_exit_fail(); exit(-1);
} }
} }
...@@ -206,7 +207,7 @@ static void trigger_tests(void) ...@@ -206,7 +207,7 @@ static void trigger_tests(void)
ret = ptrace(PTRACE_TRACEME, 0, NULL, 0); ret = ptrace(PTRACE_TRACEME, 0, NULL, 0);
if (ret) { if (ret) {
perror("Can't be traced?\n"); ksft_print_msg("Can't be traced? %s\n", strerror(errno));
return; return;
} }
...@@ -261,29 +262,30 @@ static void trigger_tests(void) ...@@ -261,29 +262,30 @@ static void trigger_tests(void)
static void check_success(const char *msg) static void check_success(const char *msg)
{ {
const char *msg2;
int child_nr_tests; int child_nr_tests;
int status; int status;
int ret;
/* Wait for the child to SIGTRAP */ /* Wait for the child to SIGTRAP */
wait(&status); wait(&status);
msg2 = "Failed"; ret = 0;
if (WSTOPSIG(status) == SIGTRAP) { if (WSTOPSIG(status) == SIGTRAP) {
child_nr_tests = ptrace(PTRACE_PEEKDATA, child_pid, child_nr_tests = ptrace(PTRACE_PEEKDATA, child_pid,
&nr_tests, 0); &nr_tests, 0);
if (child_nr_tests == nr_tests) if (child_nr_tests == nr_tests)
msg2 = "Ok"; ret = 1;
if (ptrace(PTRACE_POKEDATA, child_pid, &trapped, 1)) { if (ptrace(PTRACE_POKEDATA, child_pid, &trapped, 1))
perror("Can't poke\n"); ksft_exit_fail_msg("Can't poke: %s\n", strerror(errno));
ksft_exit_fail();
}
} }
nr_tests++; nr_tests++;
printf("%s [%s]\n", msg, msg2); if (ret)
ksft_test_result_pass(msg);
else
ksft_test_result_fail(msg);
} }
static void launch_instruction_breakpoints(char *buf, int local, int global) static void launch_instruction_breakpoints(char *buf, int local, int global)
...@@ -294,7 +296,7 @@ static void launch_instruction_breakpoints(char *buf, int local, int global) ...@@ -294,7 +296,7 @@ static void launch_instruction_breakpoints(char *buf, int local, int global)
set_breakpoint_addr(dummy_funcs[i], i); set_breakpoint_addr(dummy_funcs[i], i);
toggle_breakpoint(i, BP_X, 1, local, global, 1); toggle_breakpoint(i, BP_X, 1, local, global, 1);
ptrace(PTRACE_CONT, child_pid, NULL, 0); ptrace(PTRACE_CONT, child_pid, NULL, 0);
sprintf(buf, "Test breakpoint %d with local: %d global: %d", sprintf(buf, "Test breakpoint %d with local: %d global: %d\n",
i, local, global); i, local, global);
check_success(buf); check_success(buf);
toggle_breakpoint(i, BP_X, 1, local, global, 0); toggle_breakpoint(i, BP_X, 1, local, global, 0);
...@@ -316,8 +318,9 @@ static void launch_watchpoints(char *buf, int mode, int len, ...@@ -316,8 +318,9 @@ static void launch_watchpoints(char *buf, int mode, int len,
set_breakpoint_addr(&dummy_var[i], i); set_breakpoint_addr(&dummy_var[i], i);
toggle_breakpoint(i, mode, len, local, global, 1); toggle_breakpoint(i, mode, len, local, global, 1);
ptrace(PTRACE_CONT, child_pid, NULL, 0); ptrace(PTRACE_CONT, child_pid, NULL, 0);
sprintf(buf, "Test %s watchpoint %d with len: %d local: " sprintf(buf,
"%d global: %d", mode_str, i, len, local, global); "Test %s watchpoint %d with len: %d local: %d global: %d\n",
mode_str, i, len, local, global);
check_success(buf); check_success(buf);
toggle_breakpoint(i, mode, len, local, global, 0); toggle_breakpoint(i, mode, len, local, global, 0);
} }
...@@ -378,10 +381,12 @@ int main(int argc, char **argv) ...@@ -378,10 +381,12 @@ int main(int argc, char **argv)
pid_t pid; pid_t pid;
int ret; int ret;
ksft_print_header();
pid = fork(); pid = fork();
if (!pid) { if (!pid) {
trigger_tests(); trigger_tests();
return 0; exit(0);
} }
child_pid = pid; child_pid = pid;
...@@ -392,5 +397,5 @@ int main(int argc, char **argv) ...@@ -392,5 +397,5 @@ int main(int argc, char **argv)
wait(NULL); wait(NULL);
return ksft_exit_pass(); ksft_exit_pass();
} }
...@@ -43,19 +43,25 @@ static void child(int size, int wr) ...@@ -43,19 +43,25 @@ static void child(int size, int wr)
volatile uint8_t *addr = &var[32 + wr]; volatile uint8_t *addr = &var[32 + wr];
if (ptrace(PTRACE_TRACEME, 0, NULL, NULL) != 0) { if (ptrace(PTRACE_TRACEME, 0, NULL, NULL) != 0) {
perror("ptrace(PTRACE_TRACEME) failed"); ksft_print_msg(
"ptrace(PTRACE_TRACEME) failed: %s\n",
strerror(errno));
_exit(1); _exit(1);
} }
if (raise(SIGSTOP) != 0) { if (raise(SIGSTOP) != 0) {
perror("raise(SIGSTOP) failed"); ksft_print_msg(
"raise(SIGSTOP) failed: %s\n", strerror(errno));
_exit(1); _exit(1);
} }
if ((uintptr_t) addr % size) { if ((uintptr_t) addr % size) {
perror("Wrong address write for the given size\n"); ksft_print_msg(
"Wrong address write for the given size: %s\n",
strerror(errno));
_exit(1); _exit(1);
} }
switch (size) { switch (size) {
case 1: case 1:
*addr = 47; *addr = 47;
...@@ -100,12 +106,14 @@ static bool set_watchpoint(pid_t pid, int size, int wp) ...@@ -100,12 +106,14 @@ static bool set_watchpoint(pid_t pid, int size, int wp)
if (ptrace(PTRACE_SETREGSET, pid, NT_ARM_HW_WATCH, &iov) == 0) if (ptrace(PTRACE_SETREGSET, pid, NT_ARM_HW_WATCH, &iov) == 0)
return true; return true;
if (errno == EIO) { if (errno == EIO)
printf("ptrace(PTRACE_SETREGSET, NT_ARM_HW_WATCH) " ksft_print_msg(
"not supported on this hardware\n"); "ptrace(PTRACE_SETREGSET, NT_ARM_HW_WATCH) not supported on this hardware: %s\n",
ksft_exit_skip(); strerror(errno));
}
perror("ptrace(PTRACE_SETREGSET, NT_ARM_HW_WATCH) failed"); ksft_print_msg(
"ptrace(PTRACE_SETREGSET, NT_ARM_HW_WATCH) failed: %s\n",
strerror(errno));
return false; return false;
} }
...@@ -117,7 +125,8 @@ static bool run_test(int wr_size, int wp_size, int wr, int wp) ...@@ -117,7 +125,8 @@ static bool run_test(int wr_size, int wp_size, int wr, int wp)
pid_t wpid; pid_t wpid;
if (pid < 0) { if (pid < 0) {
perror("fork() failed"); ksft_test_result_fail(
"fork() failed: %s\n", strerror(errno));
return false; return false;
} }
if (pid == 0) if (pid == 0)
...@@ -125,15 +134,17 @@ static bool run_test(int wr_size, int wp_size, int wr, int wp) ...@@ -125,15 +134,17 @@ static bool run_test(int wr_size, int wp_size, int wr, int wp)
wpid = waitpid(pid, &status, __WALL); wpid = waitpid(pid, &status, __WALL);
if (wpid != pid) { if (wpid != pid) {
perror("waitpid() failed"); ksft_print_msg(
"waitpid() failed: %s\n", strerror(errno));
return false; return false;
} }
if (!WIFSTOPPED(status)) { if (!WIFSTOPPED(status)) {
printf("child did not stop\n"); ksft_print_msg(
"child did not stop: %s\n", strerror(errno));
return false; return false;
} }
if (WSTOPSIG(status) != SIGSTOP) { if (WSTOPSIG(status) != SIGSTOP) {
printf("child did not stop with SIGSTOP\n"); ksft_print_msg("child did not stop with SIGSTOP\n");
return false; return false;
} }
...@@ -141,42 +152,49 @@ static bool run_test(int wr_size, int wp_size, int wr, int wp) ...@@ -141,42 +152,49 @@ static bool run_test(int wr_size, int wp_size, int wr, int wp)
return false; return false;
if (ptrace(PTRACE_CONT, pid, NULL, NULL) < 0) { if (ptrace(PTRACE_CONT, pid, NULL, NULL) < 0) {
perror("ptrace(PTRACE_SINGLESTEP) failed"); ksft_print_msg(
"ptrace(PTRACE_SINGLESTEP) failed: %s\n",
strerror(errno));
return false; return false;
} }
alarm(3); alarm(3);
wpid = waitpid(pid, &status, __WALL); wpid = waitpid(pid, &status, __WALL);
if (wpid != pid) { if (wpid != pid) {
perror("waitpid() failed"); ksft_print_msg(
"waitpid() failed: %s\n", strerror(errno));
return false; return false;
} }
alarm(0); alarm(0);
if (WIFEXITED(status)) { if (WIFEXITED(status)) {
printf("child did not single-step\t"); ksft_print_msg("child did not single-step\n");
return false; return false;
} }
if (!WIFSTOPPED(status)) { if (!WIFSTOPPED(status)) {
printf("child did not stop\n"); ksft_print_msg("child did not stop\n");
return false; return false;
} }
if (WSTOPSIG(status) != SIGTRAP) { if (WSTOPSIG(status) != SIGTRAP) {
printf("child did not stop with SIGTRAP\n"); ksft_print_msg("child did not stop with SIGTRAP\n");
return false; return false;
} }
if (ptrace(PTRACE_GETSIGINFO, pid, NULL, &siginfo) != 0) { if (ptrace(PTRACE_GETSIGINFO, pid, NULL, &siginfo) != 0) {
perror("ptrace(PTRACE_GETSIGINFO)"); ksft_print_msg(
"ptrace(PTRACE_GETSIGINFO): %s\n",
strerror(errno));
return false; return false;
} }
if (siginfo.si_code != TRAP_HWBKPT) { if (siginfo.si_code != TRAP_HWBKPT) {
printf("Unexpected si_code %d\n", siginfo.si_code); ksft_print_msg(
"Unexpected si_code %d\n", siginfo.si_code);
return false; return false;
} }
kill(pid, SIGKILL); kill(pid, SIGKILL);
wpid = waitpid(pid, &status, 0); wpid = waitpid(pid, &status, 0);
if (wpid != pid) { if (wpid != pid) {
perror("waitpid() failed"); ksft_print_msg(
"waitpid() failed: %s\n", strerror(errno));
return false; return false;
} }
return true; return true;
...@@ -194,6 +212,8 @@ int main(int argc, char **argv) ...@@ -194,6 +212,8 @@ int main(int argc, char **argv)
int wr, wp, size; int wr, wp, size;
bool result; bool result;
ksft_print_header();
act.sa_handler = sigalrm; act.sa_handler = sigalrm;
sigemptyset(&act.sa_mask); sigemptyset(&act.sa_mask);
act.sa_flags = 0; act.sa_flags = 0;
...@@ -201,14 +221,16 @@ int main(int argc, char **argv) ...@@ -201,14 +221,16 @@ int main(int argc, char **argv)
for (size = 1; size <= 32; size = size*2) { for (size = 1; size <= 32; size = size*2) {
for (wr = 0; wr <= 32; wr = wr + size) { for (wr = 0; wr <= 32; wr = wr + size) {
for (wp = wr - size; wp <= wr + size; wp = wp + size) { for (wp = wr - size; wp <= wr + size; wp = wp + size) {
printf("Test size = %d write offset = %d watchpoint offset = %d\t", size, wr, wp);
result = run_test(size, MIN(size, 8), wr, wp); result = run_test(size, MIN(size, 8), wr, wp);
if ((result && wr == wp) || (!result && wr != wp)) { if ((result && wr == wp) ||
printf("[OK]\n"); (!result && wr != wp))
ksft_inc_pass_cnt(); ksft_test_result_pass(
} else { "Test size = %d write offset = %d watchpoint offset = %d\n",
printf("[FAILED]\n"); size, wr, wp);
ksft_inc_fail_cnt(); else {
ksft_test_result_fail(
"Test size = %d write offset = %d watchpoint offset = %d\n",
size, wr, wp);
succeeded = false; succeeded = false;
} }
} }
...@@ -216,19 +238,18 @@ int main(int argc, char **argv) ...@@ -216,19 +238,18 @@ int main(int argc, char **argv)
} }
for (size = 1; size <= 32; size = size*2) { for (size = 1; size <= 32; size = size*2) {
printf("Test size = %d write offset = %d watchpoint offset = -8\t", size, -size); if (run_test(size, 8, -size, -8))
ksft_test_result_pass(
if (run_test(size, 8, -size, -8)) { "Test size = %d write offset = %d watchpoint offset = -8\n",
printf("[OK]\n"); size, -size);
ksft_inc_pass_cnt(); else {
} else { ksft_test_result_fail(
printf("[FAILED]\n"); "Test size = %d write offset = %d watchpoint offset = -8\n",
ksft_inc_fail_cnt(); size, -size);
succeeded = false; succeeded = false;
} }
} }
ksft_print_cnts();
if (succeeded) if (succeeded)
ksft_exit_pass(); ksft_exit_pass();
else else
......
...@@ -37,17 +37,19 @@ void child(int cpu) ...@@ -37,17 +37,19 @@ void child(int cpu)
CPU_ZERO(&set); CPU_ZERO(&set);
CPU_SET(cpu, &set); CPU_SET(cpu, &set);
if (sched_setaffinity(0, sizeof(set), &set) != 0) { if (sched_setaffinity(0, sizeof(set), &set) != 0) {
perror("sched_setaffinity() failed"); ksft_print_msg("sched_setaffinity() failed: %s\n",
strerror(errno));
_exit(1); _exit(1);
} }
if (ptrace(PTRACE_TRACEME, 0, NULL, NULL) != 0) { if (ptrace(PTRACE_TRACEME, 0, NULL, NULL) != 0) {
perror("ptrace(PTRACE_TRACEME) failed"); ksft_print_msg("ptrace(PTRACE_TRACEME) failed: %s\n",
strerror(errno));
_exit(1); _exit(1);
} }
if (raise(SIGSTOP) != 0) { if (raise(SIGSTOP) != 0) {
perror("raise(SIGSTOP) failed"); ksft_print_msg("raise(SIGSTOP) failed: %s\n", strerror(errno));
_exit(1); _exit(1);
} }
...@@ -61,7 +63,7 @@ bool run_test(int cpu) ...@@ -61,7 +63,7 @@ bool run_test(int cpu)
pid_t wpid; pid_t wpid;
if (pid < 0) { if (pid < 0) {
perror("fork() failed"); ksft_print_msg("fork() failed: %s\n", strerror(errno));
return false; return false;
} }
if (pid == 0) if (pid == 0)
...@@ -69,57 +71,64 @@ bool run_test(int cpu) ...@@ -69,57 +71,64 @@ bool run_test(int cpu)
wpid = waitpid(pid, &status, __WALL); wpid = waitpid(pid, &status, __WALL);
if (wpid != pid) { if (wpid != pid) {
perror("waitpid() failed"); ksft_print_msg("waitpid() failed: %s\n", strerror(errno));
return false; return false;
} }
if (!WIFSTOPPED(status)) { if (!WIFSTOPPED(status)) {
printf("child did not stop\n"); ksft_print_msg("child did not stop: %s\n", strerror(errno));
return false; return false;
} }
if (WSTOPSIG(status) != SIGSTOP) { if (WSTOPSIG(status) != SIGSTOP) {
printf("child did not stop with SIGSTOP\n"); ksft_print_msg("child did not stop with SIGSTOP: %s\n",
strerror(errno));
return false; return false;
} }
if (ptrace(PTRACE_SINGLESTEP, pid, NULL, NULL) < 0) { if (ptrace(PTRACE_SINGLESTEP, pid, NULL, NULL) < 0) {
if (errno == EIO) { if (errno == EIO) {
printf("ptrace(PTRACE_SINGLESTEP) not supported on this architecture\n"); ksft_exit_skip(
ksft_exit_skip(); "ptrace(PTRACE_SINGLESTEP) not supported on this architecture: %s\n",
strerror(errno));
} }
perror("ptrace(PTRACE_SINGLESTEP) failed"); ksft_print_msg("ptrace(PTRACE_SINGLESTEP) failed: %s\n",
strerror(errno));
return false; return false;
} }
wpid = waitpid(pid, &status, __WALL); wpid = waitpid(pid, &status, __WALL);
if (wpid != pid) { if (wpid != pid) {
perror("waitpid() failed"); ksft_print_msg("waitpid() failed: $s\n", strerror(errno));
return false; return false;
} }
if (WIFEXITED(status)) { if (WIFEXITED(status)) {
printf("child did not single-step\n"); ksft_print_msg("child did not single-step: %s\n",
strerror(errno));
return false; return false;
} }
if (!WIFSTOPPED(status)) { if (!WIFSTOPPED(status)) {
printf("child did not stop\n"); ksft_print_msg("child did not stop: %s\n", strerror(errno));
return false; return false;
} }
if (WSTOPSIG(status) != SIGTRAP) { if (WSTOPSIG(status) != SIGTRAP) {
printf("child did not stop with SIGTRAP\n"); ksft_print_msg("child did not stop with SIGTRAP: %s\n",
strerror(errno));
return false; return false;
} }
if (ptrace(PTRACE_CONT, pid, NULL, NULL) < 0) { if (ptrace(PTRACE_CONT, pid, NULL, NULL) < 0) {
perror("ptrace(PTRACE_CONT) failed"); ksft_print_msg("ptrace(PTRACE_CONT) failed: %s\n",
strerror(errno));
return false; return false;
} }
wpid = waitpid(pid, &status, __WALL); wpid = waitpid(pid, &status, __WALL);
if (wpid != pid) { if (wpid != pid) {
perror("waitpid() failed"); ksft_print_msg("waitpid() failed: %s\n", strerror(errno));
return false; return false;
} }
if (!WIFEXITED(status)) { if (!WIFEXITED(status)) {
printf("child did not exit after PTRACE_CONT\n"); ksft_print_msg("child did not exit after PTRACE_CONT: %s\n",
strerror(errno));
return false; return false;
} }
...@@ -135,28 +144,21 @@ void suspend(void) ...@@ -135,28 +144,21 @@ void suspend(void)
struct itimerspec spec = {}; struct itimerspec spec = {};
power_state_fd = open("/sys/power/state", O_RDWR); power_state_fd = open("/sys/power/state", O_RDWR);
if (power_state_fd < 0) { if (power_state_fd < 0)
perror("open(\"/sys/power/state\") failed (is this test running as root?)"); ksft_exit_fail_msg(
ksft_exit_fail(); "open(\"/sys/power/state\") failed (is this test running as root?)\n");
}
timerfd = timerfd_create(CLOCK_BOOTTIME_ALARM, 0); timerfd = timerfd_create(CLOCK_BOOTTIME_ALARM, 0);
if (timerfd < 0) { if (timerfd < 0)
perror("timerfd_create() failed"); ksft_exit_fail_msg("timerfd_create() failed\n");
ksft_exit_fail();
}
spec.it_value.tv_sec = 5; spec.it_value.tv_sec = 5;
err = timerfd_settime(timerfd, 0, &spec, NULL); err = timerfd_settime(timerfd, 0, &spec, NULL);
if (err < 0) { if (err < 0)
perror("timerfd_settime() failed"); ksft_exit_fail_msg("timerfd_settime() failed\n");
ksft_exit_fail();
}
if (write(power_state_fd, "mem", strlen("mem")) != strlen("mem")) { if (write(power_state_fd, "mem", strlen("mem")) != strlen("mem"))
perror("entering suspend failed"); ksft_exit_fail_msg("Failed to enter Suspend state\n");
ksft_exit_fail();
}
close(timerfd); close(timerfd);
close(power_state_fd); close(power_state_fd);
...@@ -171,6 +173,8 @@ int main(int argc, char **argv) ...@@ -171,6 +173,8 @@ int main(int argc, char **argv)
int err; int err;
int cpu; int cpu;
ksft_print_header();
while ((opt = getopt(argc, argv, "n")) != -1) { while ((opt = getopt(argc, argv, "n")) != -1) {
switch (opt) { switch (opt) {
case 'n': case 'n':
...@@ -187,10 +191,8 @@ int main(int argc, char **argv) ...@@ -187,10 +191,8 @@ int main(int argc, char **argv)
suspend(); suspend();
err = sched_getaffinity(0, sizeof(available_cpus), &available_cpus); err = sched_getaffinity(0, sizeof(available_cpus), &available_cpus);
if (err < 0) { if (err < 0)
perror("sched_getaffinity() failed"); ksft_exit_fail_msg("sched_getaffinity() failed\n");
ksft_exit_fail();
}
for (cpu = 0; cpu < CPU_SETSIZE; cpu++) { for (cpu = 0; cpu < CPU_SETSIZE; cpu++) {
bool test_success; bool test_success;
...@@ -199,18 +201,14 @@ int main(int argc, char **argv) ...@@ -199,18 +201,14 @@ int main(int argc, char **argv)
continue; continue;
test_success = run_test(cpu); test_success = run_test(cpu);
printf("CPU %d: ", cpu);
if (test_success) { if (test_success) {
printf("[OK]\n"); ksft_test_result_pass("CPU %d\n", cpu);
ksft_inc_pass_cnt();
} else { } else {
printf("[FAILED]\n"); ksft_test_result_fail("CPU %d\n", cpu);
ksft_inc_fail_cnt();
succeeded = false; succeeded = false;
} }
} }
ksft_print_cnts();
if (succeeded) if (succeeded)
ksft_exit_pass(); ksft_exit_pass();
else else
......
...@@ -138,9 +138,6 @@ static void chdir_to_tmpfs(void) ...@@ -138,9 +138,6 @@ static void chdir_to_tmpfs(void)
if (chdir(cwd) != 0) if (chdir(cwd) != 0)
err(1, "chdir to private tmpfs"); err(1, "chdir to private tmpfs");
if (umount2(".", MNT_DETACH) != 0)
err(1, "detach private tmpfs");
} }
static void copy_fromat_to(int fromfd, const char *fromname, const char *toname) static void copy_fromat_to(int fromfd, const char *fromname, const char *toname)
...@@ -248,7 +245,7 @@ static int do_tests(int uid, const char *our_path) ...@@ -248,7 +245,7 @@ static int do_tests(int uid, const char *our_path)
err(1, "chown"); err(1, "chown");
if (chmod("validate_cap_sgidnonroot", S_ISGID | 0710) != 0) if (chmod("validate_cap_sgidnonroot", S_ISGID | 0710) != 0)
err(1, "chmod"); err(1, "chmod");
} }
capng_get_caps_process(); capng_get_caps_process();
...@@ -384,7 +381,7 @@ static int do_tests(int uid, const char *our_path) ...@@ -384,7 +381,7 @@ static int do_tests(int uid, const char *our_path)
} else { } else {
printf("[RUN]\tNon-root +ia, sgidnonroot => i\n"); printf("[RUN]\tNon-root +ia, sgidnonroot => i\n");
exec_other_validate_cap("./validate_cap_sgidnonroot", exec_other_validate_cap("./validate_cap_sgidnonroot",
false, false, true, false); false, false, true, false);
if (fork_wait()) { if (fork_wait()) {
printf("[RUN]\tNon-root +ia, sgidroot => i\n"); printf("[RUN]\tNon-root +ia, sgidroot => i\n");
......
...@@ -250,7 +250,7 @@ run_test() { # testfile ...@@ -250,7 +250,7 @@ run_test() { # testfile
local testlog=`mktemp $LOG_DIR/${testname}-log.XXXXXX` local testlog=`mktemp $LOG_DIR/${testname}-log.XXXXXX`
export TMPDIR=`mktemp -d /tmp/ftracetest-dir.XXXXXX` export TMPDIR=`mktemp -d /tmp/ftracetest-dir.XXXXXX`
testcase $1 testcase $1
echo "execute: "$1 > $testlog echo "execute$INSTANCE: "$1 > $testlog
SIG_RESULT=0 SIG_RESULT=0
if [ $VERBOSE -ge 2 ]; then if [ $VERBOSE -ge 2 ]; then
__run_test $1 2>> $testlog | tee -a $testlog __run_test $1 2>> $testlog | tee -a $testlog
......
...@@ -28,7 +28,9 @@ echo '*:*' > set_event ...@@ -28,7 +28,9 @@ echo '*:*' > set_event
yield yield
count=`cat trace | grep -v ^# | wc -l` echo 0 > tracing_on
count=`head -n 128 trace | grep -v ^# | wc -l`
if [ $count -eq 0 ]; then if [ $count -eq 0 ]; then
fail "none of events are recorded" fail "none of events are recorded"
fi fi
...@@ -36,10 +38,12 @@ fi ...@@ -36,10 +38,12 @@ fi
do_reset do_reset
echo 1 > events/enable echo 1 > events/enable
echo 1 > tracing_on
yield yield
count=`cat trace | grep -v ^# | wc -l` echo 0 > tracing_on
count=`head -n 128 trace | grep -v ^# | wc -l`
if [ $count -eq 0 ]; then if [ $count -eq 0 ]; then
fail "none of events are recorded" fail "none of events are recorded"
fi fi
......
...@@ -11,17 +11,6 @@ fi ...@@ -11,17 +11,6 @@ fi
disable_tracing disable_tracing
clear_trace clear_trace
# filter by ?, schedule is always good
if ! echo "sch?dule" > set_ftrace_filter; then
# test for powerpc 64
if ! echo ".sch?dule" > set_ftrace_filter; then
fail "can not enable schedule filter"
fi
cat set_ftrace_filter | grep '^.schedule$'
else
cat set_ftrace_filter | grep '^schedule$'
fi
ftrace_filter_check() { # glob grep ftrace_filter_check() { # glob grep
echo "$1" > set_ftrace_filter echo "$1" > set_ftrace_filter
cut -f1 -d" " set_ftrace_filter > $TMPDIR/actual cut -f1 -d" " set_ftrace_filter > $TMPDIR/actual
...@@ -39,11 +28,28 @@ ftrace_filter_check '*schedule*' '^.*schedule.*$' ...@@ -39,11 +28,28 @@ ftrace_filter_check '*schedule*' '^.*schedule.*$'
# filter by *, end match # filter by *, end match
ftrace_filter_check 'schedule*' '^schedule.*$' ftrace_filter_check 'schedule*' '^schedule.*$'
# Advanced full-glob matching feature is recently supported.
# Skip the tests if we are sure the kernel does not support it.
if grep -q 'accepts: .* glob-matching-pattern' README ; then
# filter by *, both side match # filter by *, both side match
ftrace_filter_check 'sch*ule' '^sch.*ule$' ftrace_filter_check 'sch*ule' '^sch.*ule$'
# filter by char class. # filter by char class.
ftrace_filter_check '[Ss]y[Ss]_*' '^[Ss]y[Ss]_.*$' ftrace_filter_check '[Ss]y[Ss]_*' '^[Ss]y[Ss]_.*$'
# filter by ?, schedule is always good
if ! echo "sch?dule" > set_ftrace_filter; then
# test for powerpc 64
if ! echo ".sch?dule" > set_ftrace_filter; then
fail "can not enable schedule filter"
fi
cat set_ftrace_filter | grep '^.schedule$'
else
cat set_ftrace_filter | grep '^schedule$'
fi
fi
echo > set_ftrace_filter echo > set_ftrace_filter
enable_tracing enable_tracing
...@@ -72,6 +72,15 @@ run_enable_disable() { ...@@ -72,6 +72,15 @@ run_enable_disable() {
test_event_enabled $check_disable test_event_enabled $check_disable
echo "schedule:${enable}_event:$EVENT" > set_ftrace_filter echo "schedule:${enable}_event:$EVENT" > set_ftrace_filter
if [ -d ../../instances ]; then # Check instances
cur=`cat set_ftrace_filter`
top=`cat ../../set_ftrace_filter`
if [ "$cur" = "$top" ]; then
echo "This kernel is too old to support per instance filter"
reset_ftrace_filter
exit_unsupported
fi
fi
echo " make sure it works 5 times" echo " make sure it works 5 times"
......
...@@ -63,6 +63,10 @@ fi ...@@ -63,6 +63,10 @@ fi
# powerpc uses .schedule # powerpc uses .schedule
func="schedule" func="schedule"
available_file=available_filter_functions
if [ -d ../../instances -a -f ../../available_filter_functions ]; then
available_file=../../available_filter_functions
fi
x=`grep '^\.schedule$' available_filter_functions | wc -l` x=`grep '^\.schedule$' available_filter_functions | wc -l`
if [ "$x" -eq 1 ]; then if [ "$x" -eq 1 ]; then
func=".schedule" func=".schedule"
...@@ -71,6 +75,15 @@ fi ...@@ -71,6 +75,15 @@ fi
echo '** SET TRACEOFF' echo '** SET TRACEOFF'
echo "$func:traceoff" > set_ftrace_filter echo "$func:traceoff" > set_ftrace_filter
if [ -d ../../instances ]; then # Check instances
cur=`cat set_ftrace_filter`
top=`cat ../../set_ftrace_filter`
if [ "$cur" = "$top" ]; then
echo "This kernel is too old to support per instance filter"
reset_ftrace_filter
exit_unsupported
fi
fi
cnt=`grep schedule set_ftrace_filter | wc -l` cnt=`grep schedule set_ftrace_filter | wc -l`
if [ $cnt -ne 1 ]; then if [ $cnt -ne 1 ]; then
...@@ -90,11 +103,11 @@ if [ $on != "0" ]; then ...@@ -90,11 +103,11 @@ if [ $on != "0" ]; then
fail "Tracing is not off" fail "Tracing is not off"
fi fi
line1=`cat trace | tail -1` csum1=`md5sum trace`
sleep $SLEEP_TIME sleep $SLEEP_TIME
line2=`cat trace | tail -1` csum2=`md5sum trace`
if [ "$line1" != "$line2" ]; then if [ "$csum1" != "$csum2" ]; then
fail "Tracing file is still changing" fail "Tracing file is still changing"
fi fi
......
...@@ -82,7 +82,10 @@ rmdir foo ...@@ -82,7 +82,10 @@ rmdir foo
if [ -d foo ]; then if [ -d foo ]; then
fail "foo still exists" fail "foo still exists"
fi fi
if grep -q "schedule:enable_event:sched:sched_switch" ../set_ftrace_filter; then
echo "Older kernel detected. Cleanup filter"
echo '!schedule:enable_event:sched:sched_switch' > ../set_ftrace_filter
fi
instance_slam() { instance_slam() {
while :; do while :; do
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
# description: Kretprobe dynamic event with maxactive # description: Kretprobe dynamic event with maxactive
[ -f kprobe_events ] || exit_unsupported # this is configurable [ -f kprobe_events ] || exit_unsupported # this is configurable
grep -q 'r\[maxactive\]' README || exit_unsupported # this is older version
echo > kprobe_events echo > kprobe_events
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "futextest.h" #include "futextest.h"
#include "logging.h" #include "logging.h"
#define TEST_NAME "futex-requeue-pi"
#define MAX_WAKE_ITERS 1000 #define MAX_WAKE_ITERS 1000
#define THREAD_MAX 10 #define THREAD_MAX 10
#define SIGNAL_PERIOD_US 100 #define SIGNAL_PERIOD_US 100
...@@ -404,6 +405,6 @@ int main(int argc, char *argv[]) ...@@ -404,6 +405,6 @@ int main(int argc, char *argv[])
*/ */
ret = unit_test(broadcast, locked, owner, timeout_ns); ret = unit_test(broadcast, locked, owner, timeout_ns);
print_result(ret); print_result(TEST_NAME, ret);
return ret; return ret;
} }
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
#include "futextest.h" #include "futextest.h"
#include "logging.h" #include "logging.h"
#define TEST_NAME "futex-requeue-pi-mismatched-ops"
futex_t f1 = FUTEX_INITIALIZER; futex_t f1 = FUTEX_INITIALIZER;
futex_t f2 = FUTEX_INITIALIZER; futex_t f2 = FUTEX_INITIALIZER;
int child_ret = 0; int child_ret = 0;
...@@ -130,6 +132,6 @@ int main(int argc, char *argv[]) ...@@ -130,6 +132,6 @@ int main(int argc, char *argv[])
out: out:
/* If the kernel crashes, we shouldn't return at all. */ /* If the kernel crashes, we shouldn't return at all. */
print_result(ret); print_result(TEST_NAME, ret);
return ret; return ret;
} }
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "futextest.h" #include "futextest.h"
#include "logging.h" #include "logging.h"
#define TEST_NAME "futex-requeue-pi-signal-restart"
#define DELAY_US 100 #define DELAY_US 100
futex_t f1 = FUTEX_INITIALIZER; futex_t f1 = FUTEX_INITIALIZER;
...@@ -218,6 +219,6 @@ int main(int argc, char *argv[]) ...@@ -218,6 +219,6 @@ int main(int argc, char *argv[])
if (ret == RET_PASS && waiter_ret) if (ret == RET_PASS && waiter_ret)
ret = waiter_ret; ret = waiter_ret;
print_result(ret); print_result(TEST_NAME, ret);
return ret; return ret;
} }
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "logging.h" #include "logging.h"
#include "futextest.h" #include "futextest.h"
#define TEST_NAME "futex-wait-private-mapped-file"
#define PAGE_SZ 4096 #define PAGE_SZ 4096
char pad[PAGE_SZ] = {1}; char pad[PAGE_SZ] = {1};
...@@ -60,7 +61,7 @@ void *thr_futex_wait(void *arg) ...@@ -60,7 +61,7 @@ void *thr_futex_wait(void *arg)
ret = futex_wait(&val, 1, &wait_timeout, 0); ret = futex_wait(&val, 1, &wait_timeout, 0);
if (ret && errno != EWOULDBLOCK && errno != ETIMEDOUT) { if (ret && errno != EWOULDBLOCK && errno != ETIMEDOUT) {
error("futex error.\n", errno); error("futex error.\n", errno);
print_result(RET_ERROR); print_result(TEST_NAME, RET_ERROR);
exit(RET_ERROR); exit(RET_ERROR);
} }
...@@ -120,6 +121,6 @@ int main(int argc, char **argv) ...@@ -120,6 +121,6 @@ int main(int argc, char **argv)
pthread_join(thr, NULL); pthread_join(thr, NULL);
out: out:
print_result(ret); print_result(TEST_NAME, ret);
return ret; return ret;
} }
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
#include "futextest.h" #include "futextest.h"
#include "logging.h" #include "logging.h"
#define TEST_NAME "futex-wait-timeout"
static long timeout_ns = 100000; /* 100us default timeout */ static long timeout_ns = 100000; /* 100us default timeout */
void usage(char *prog) void usage(char *prog)
...@@ -81,6 +83,6 @@ int main(int argc, char *argv[]) ...@@ -81,6 +83,6 @@ int main(int argc, char *argv[])
ret = RET_FAIL; ret = RET_FAIL;
} }
print_result(ret); print_result(TEST_NAME, ret);
return ret; return ret;
} }
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "logging.h" #include "logging.h"
#include "futextest.h" #include "futextest.h"
#define TEST_NAME "futex-wait-uninitialized-heap"
#define WAIT_US 5000000 #define WAIT_US 5000000
static int child_blocked = 1; static int child_blocked = 1;
...@@ -119,6 +120,6 @@ int main(int argc, char **argv) ...@@ -119,6 +120,6 @@ int main(int argc, char **argv)
} }
out: out:
print_result(ret); print_result(TEST_NAME, ret);
return ret; return ret;
} }
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "futextest.h" #include "futextest.h"
#include "logging.h" #include "logging.h"
#define TEST_NAME "futex-wait-wouldblock"
#define timeout_ns 100000 #define timeout_ns 100000
void usage(char *prog) void usage(char *prog)
...@@ -74,6 +75,6 @@ int main(int argc, char *argv[]) ...@@ -74,6 +75,6 @@ int main(int argc, char *argv[])
ret = RET_FAIL; ret = RET_FAIL;
} }
print_result(ret); print_result(TEST_NAME, ret);
return ret; return ret;
} }
...@@ -107,7 +107,7 @@ void log_verbosity(int level) ...@@ -107,7 +107,7 @@ void log_verbosity(int level)
* *
* print_result() is primarily intended for functional tests. * print_result() is primarily intended for functional tests.
*/ */
void print_result(int ret) void print_result(const char *test_name, int ret)
{ {
const char *result = "Unknown return code"; const char *result = "Unknown return code";
...@@ -124,7 +124,7 @@ void print_result(int ret) ...@@ -124,7 +124,7 @@ void print_result(int ret)
result = FAIL; result = FAIL;
break; break;
} }
printf("Result: %s\n", result); printf("selftests: %s [%s]\n", test_name, result);
} }
/* log level macros */ /* log level macros */
......
CFLAGS := $(CFLAGS) -Wall -D_GNU_SOURCE CFLAGS := $(CFLAGS) -Wall -D_GNU_SOURCE
LDFLAGS := $(LDFLAGS) -lm LDLIBS := $(LDLIBS) -lm
TEST_GEN_FILES := msr aperf TEST_GEN_FILES := msr aperf
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <stdarg.h>
/* define kselftest exit codes */ /* define kselftest exit codes */
#define KSFT_PASS 0 #define KSFT_PASS 0
...@@ -31,38 +32,125 @@ struct ksft_count { ...@@ -31,38 +32,125 @@ struct ksft_count {
static struct ksft_count ksft_cnt; static struct ksft_count ksft_cnt;
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;
}
static inline void ksft_inc_pass_cnt(void) { ksft_cnt.ksft_pass++; } static inline void ksft_inc_pass_cnt(void) { ksft_cnt.ksft_pass++; }
static inline void ksft_inc_fail_cnt(void) { ksft_cnt.ksft_fail++; } 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_xfail_cnt(void) { ksft_cnt.ksft_xfail++; }
static inline void ksft_inc_xpass_cnt(void) { ksft_cnt.ksft_xpass++; } 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_xskip_cnt(void) { ksft_cnt.ksft_xskip++; }
static inline void ksft_print_header(void)
{
printf("TAP version 13\n");
}
static inline void ksft_print_cnts(void) static inline void ksft_print_cnts(void)
{ {
printf("Pass: %d Fail: %d Xfail: %d Xpass: %d, Xskip: %d\n", printf("1..%d\n", ksft_test_num());
ksft_cnt.ksft_pass, ksft_cnt.ksft_fail, }
ksft_cnt.ksft_xfail, ksft_cnt.ksft_xpass,
ksft_cnt.ksft_xskip); static inline void ksft_print_msg(const char *msg, ...)
{
va_list args;
va_start(args, msg);
printf("# ");
vprintf(msg, args);
va_end(args);
}
static inline void ksft_test_result_pass(const char *msg, ...)
{
va_list args;
ksft_cnt.ksft_pass++;
va_start(args, msg);
printf("ok %d ", ksft_test_num());
vprintf(msg, args);
va_end(args);
}
static inline void ksft_test_result_fail(const char *msg, ...)
{
va_list args;
ksft_cnt.ksft_fail++;
va_start(args, msg);
printf("not ok %d ", ksft_test_num());
vprintf(msg, args);
va_end(args);
}
static inline void ksft_test_result_skip(const char *msg, ...)
{
va_list args;
ksft_cnt.ksft_xskip++;
va_start(args, msg);
printf("ok %d # skip ", ksft_test_num());
vprintf(msg, args);
va_end(args);
} }
static inline int ksft_exit_pass(void) static inline int ksft_exit_pass(void)
{ {
ksft_print_cnts();
exit(KSFT_PASS); exit(KSFT_PASS);
} }
static inline int ksft_exit_fail(void) static inline int ksft_exit_fail(void)
{ {
printf("Bail out!\n");
ksft_print_cnts();
exit(KSFT_FAIL);
}
static inline int ksft_exit_fail_msg(const char *msg, ...)
{
va_list args;
va_start(args, msg);
printf("Bail out! ");
vprintf(msg, args);
va_end(args);
ksft_print_cnts();
exit(KSFT_FAIL); exit(KSFT_FAIL);
} }
static inline int ksft_exit_xfail(void) static inline int ksft_exit_xfail(void)
{ {
ksft_print_cnts();
exit(KSFT_XFAIL); exit(KSFT_XFAIL);
} }
static inline int ksft_exit_xpass(void) static inline int ksft_exit_xpass(void)
{ {
ksft_print_cnts();
exit(KSFT_XPASS); exit(KSFT_XPASS);
} }
static inline int ksft_exit_skip(void)
static inline int ksft_exit_skip(const char *msg, ...)
{ {
if (msg) {
va_list args;
va_start(args, msg);
printf("1..%d # Skipped: ", ksft_test_num());
vprintf(msg, args);
va_end(args);
} else {
ksft_print_cnts();
}
exit(KSFT_SKIP); exit(KSFT_SKIP);
} }
......
#!/bin/sh #!/bin/sh
# Runs bitmap infrastructure tests using test_bitmap kernel module # Runs bitmap infrastructure tests using test_bitmap kernel module
if ! /sbin/modprobe -q -n test_bitmap; then
echo "bitmap: [SKIP]"
exit 77
fi
if /sbin/modprobe -q test_bitmap; then if /sbin/modprobe -q test_bitmap; then
/sbin/modprobe -q -r test_bitmap /sbin/modprobe -q -r test_bitmap
......
#!/bin/sh #!/bin/sh
# Runs printf infrastructure using test_printf kernel module # Runs printf infrastructure using test_printf kernel module
if ! /sbin/modprobe -q -n test_printf; then
echo "printf: [SKIP]"
exit 77
fi
if /sbin/modprobe -q test_printf; then if /sbin/modprobe -q test_printf; then
/sbin/modprobe -q -r test_printf /sbin/modprobe -q -r test_printf
......
...@@ -7,56 +7,63 @@ ...@@ -7,56 +7,63 @@
#include "../kselftest.h" #include "../kselftest.h"
enum test_membarrier_status {
TEST_MEMBARRIER_PASS = 0,
TEST_MEMBARRIER_FAIL,
TEST_MEMBARRIER_SKIP,
};
static int sys_membarrier(int cmd, int flags) static int sys_membarrier(int cmd, int flags)
{ {
return syscall(__NR_membarrier, cmd, flags); return syscall(__NR_membarrier, cmd, flags);
} }
static enum test_membarrier_status test_membarrier_cmd_fail(void) static int test_membarrier_cmd_fail(void)
{ {
int cmd = -1, flags = 0; int cmd = -1, flags = 0;
if (sys_membarrier(cmd, flags) != -1) { if (sys_membarrier(cmd, flags) != -1) {
printf("membarrier: Wrong command should fail but passed.\n"); ksft_exit_fail_msg(
return TEST_MEMBARRIER_FAIL; "sys membarrier invalid command test: command = %d, flags = %d. Should fail, but passed\n",
cmd, flags);
} }
return TEST_MEMBARRIER_PASS;
ksft_test_result_pass(
"sys membarrier invalid command test: command = %d, flags = %d. Failed as expected\n",
cmd, flags);
return 0;
} }
static enum test_membarrier_status test_membarrier_flags_fail(void) static int test_membarrier_flags_fail(void)
{ {
int cmd = MEMBARRIER_CMD_QUERY, flags = 1; int cmd = MEMBARRIER_CMD_QUERY, flags = 1;
if (sys_membarrier(cmd, flags) != -1) { if (sys_membarrier(cmd, flags) != -1) {
printf("membarrier: Wrong flags should fail but passed.\n"); ksft_exit_fail_msg(
return TEST_MEMBARRIER_FAIL; "sys membarrier MEMBARRIER_CMD_QUERY invalid flags test: flags = %d. Should fail, but passed\n",
flags);
} }
return TEST_MEMBARRIER_PASS;
ksft_test_result_pass(
"sys membarrier MEMBARRIER_CMD_QUERY invalid flags test: flags = %d. Failed as expected\n",
flags);
return 0;
} }
static enum test_membarrier_status test_membarrier_success(void) static int test_membarrier_success(void)
{ {
int cmd = MEMBARRIER_CMD_SHARED, flags = 0; int cmd = MEMBARRIER_CMD_SHARED, flags = 0;
const char *test_name = "sys membarrier MEMBARRIER_CMD_SHARED\n";
if (sys_membarrier(cmd, flags) != 0) { if (sys_membarrier(cmd, flags) != 0) {
printf("membarrier: Executing MEMBARRIER_CMD_SHARED failed. %s.\n", ksft_exit_fail_msg(
strerror(errno)); "sys membarrier MEMBARRIER_CMD_SHARED test: flags = %d\n",
return TEST_MEMBARRIER_FAIL; flags);
} }
printf("membarrier: MEMBARRIER_CMD_SHARED success.\n"); ksft_test_result_pass(
return TEST_MEMBARRIER_PASS; "sys membarrier MEMBARRIER_CMD_SHARED test: flags = %d\n",
flags);
return 0;
} }
static enum test_membarrier_status test_membarrier(void) static int test_membarrier(void)
{ {
enum test_membarrier_status status; int status;
status = test_membarrier_cmd_fail(); status = test_membarrier_cmd_fail();
if (status) if (status)
...@@ -67,52 +74,38 @@ static enum test_membarrier_status test_membarrier(void) ...@@ -67,52 +74,38 @@ static enum test_membarrier_status test_membarrier(void)
status = test_membarrier_success(); status = test_membarrier_success();
if (status) if (status)
return status; return status;
return TEST_MEMBARRIER_PASS; return 0;
} }
static enum test_membarrier_status test_membarrier_query(void) static int test_membarrier_query(void)
{ {
int flags = 0, ret; int flags = 0, ret;
printf("membarrier MEMBARRIER_CMD_QUERY ");
ret = sys_membarrier(MEMBARRIER_CMD_QUERY, flags); ret = sys_membarrier(MEMBARRIER_CMD_QUERY, flags);
if (ret < 0) { if (ret < 0) {
printf("failed. %s.\n", strerror(errno)); if (errno == ENOSYS) {
switch (errno) {
case ENOSYS:
/* /*
* It is valid to build a kernel with * It is valid to build a kernel with
* CONFIG_MEMBARRIER=n. However, this skips the tests. * CONFIG_MEMBARRIER=n. However, this skips the tests.
*/ */
return TEST_MEMBARRIER_SKIP; ksft_exit_skip(
case EINVAL: "sys membarrier (CONFIG_MEMBARRIER) is disabled.\n");
default:
return TEST_MEMBARRIER_FAIL;
} }
ksft_exit_fail_msg("sys_membarrier() failed\n");
} }
if (!(ret & MEMBARRIER_CMD_SHARED)) { if (!(ret & MEMBARRIER_CMD_SHARED))
printf("command MEMBARRIER_CMD_SHARED is not supported.\n"); ksft_exit_fail_msg("sys_membarrier is not supported.\n");
return TEST_MEMBARRIER_FAIL;
} ksft_test_result_pass("sys_membarrier available\n");
printf("syscall available.\n"); return 0;
return TEST_MEMBARRIER_PASS;
} }
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
switch (test_membarrier_query()) { ksft_print_header();
case TEST_MEMBARRIER_FAIL:
return ksft_exit_fail(); test_membarrier_query();
case TEST_MEMBARRIER_SKIP: test_membarrier();
return ksft_exit_skip();
}
switch (test_membarrier()) {
case TEST_MEMBARRIER_FAIL:
return ksft_exit_fail();
case TEST_MEMBARRIER_SKIP:
return ksft_exit_skip();
}
printf("membarrier: tests done!\n"); ksft_exit_pass();
return ksft_exit_pass();
} }
...@@ -7,7 +7,7 @@ TEST_PROGS := run_fuse_test.sh ...@@ -7,7 +7,7 @@ TEST_PROGS := run_fuse_test.sh
TEST_GEN_FILES := memfd_test fuse_mnt fuse_test TEST_GEN_FILES := memfd_test fuse_mnt fuse_test
fuse_mnt.o: CFLAGS += $(shell pkg-config fuse --cflags) fuse_mnt.o: CFLAGS += $(shell pkg-config fuse --cflags)
fuse_mnt: LDFLAGS += $(shell pkg-config fuse --libs)
include ../lib.mk include ../lib.mk
$(OUTPUT)/fuse_mnt: LDLIBS += $(shell pkg-config fuse --libs)
...@@ -22,6 +22,11 @@ prerequisite() ...@@ -22,6 +22,11 @@ prerequisite()
echo $msg memory hotplug is not supported >&2 echo $msg memory hotplug is not supported >&2
exit 0 exit 0
fi fi
if ! grep -q 1 $SYSFS/devices/system/memory/memory*/removable; then
echo $msg no hot-pluggable memory >&2
exit 0
fi
} }
# #
...@@ -39,7 +44,7 @@ hotpluggable_memory() ...@@ -39,7 +44,7 @@ hotpluggable_memory()
done done
} }
hotplaggable_offline_memory() hotpluggable_offline_memory()
{ {
hotpluggable_memory offline hotpluggable_memory offline
} }
...@@ -75,9 +80,12 @@ online_memory_expect_success() ...@@ -75,9 +80,12 @@ online_memory_expect_success()
if ! online_memory $memory; then if ! online_memory $memory; then
echo $FUNCNAME $memory: unexpected fail >&2 echo $FUNCNAME $memory: unexpected fail >&2
return 1
elif ! memory_is_online $memory; then elif ! memory_is_online $memory; then
echo $FUNCNAME $memory: unexpected offline >&2 echo $FUNCNAME $memory: unexpected offline >&2
return 1
fi fi
return 0
} }
online_memory_expect_fail() online_memory_expect_fail()
...@@ -86,9 +94,12 @@ online_memory_expect_fail() ...@@ -86,9 +94,12 @@ online_memory_expect_fail()
if online_memory $memory 2> /dev/null; then if online_memory $memory 2> /dev/null; then
echo $FUNCNAME $memory: unexpected success >&2 echo $FUNCNAME $memory: unexpected success >&2
return 1
elif ! memory_is_offline $memory; then elif ! memory_is_offline $memory; then
echo $FUNCNAME $memory: unexpected online >&2 echo $FUNCNAME $memory: unexpected online >&2
return 1
fi fi
return 0
} }
offline_memory_expect_success() offline_memory_expect_success()
...@@ -97,9 +108,12 @@ offline_memory_expect_success() ...@@ -97,9 +108,12 @@ offline_memory_expect_success()
if ! offline_memory $memory; then if ! offline_memory $memory; then
echo $FUNCNAME $memory: unexpected fail >&2 echo $FUNCNAME $memory: unexpected fail >&2
return 1
elif ! memory_is_offline $memory; then elif ! memory_is_offline $memory; then
echo $FUNCNAME $memory: unexpected offline >&2 echo $FUNCNAME $memory: unexpected offline >&2
return 1
fi fi
return 0
} }
offline_memory_expect_fail() offline_memory_expect_fail()
...@@ -108,14 +122,18 @@ offline_memory_expect_fail() ...@@ -108,14 +122,18 @@ offline_memory_expect_fail()
if offline_memory $memory 2> /dev/null; then if offline_memory $memory 2> /dev/null; then
echo $FUNCNAME $memory: unexpected success >&2 echo $FUNCNAME $memory: unexpected success >&2
return 1
elif ! memory_is_online $memory; then elif ! memory_is_online $memory; then
echo $FUNCNAME $memory: unexpected offline >&2 echo $FUNCNAME $memory: unexpected offline >&2
return 1
fi fi
return 0
} }
error=-12 error=-12
priority=0 priority=0
ratio=10 ratio=10
retval=0
while getopts e:hp:r: opt; do while getopts e:hp:r: opt; do
case $opt in case $opt in
...@@ -131,6 +149,10 @@ while getopts e:hp:r: opt; do ...@@ -131,6 +149,10 @@ while getopts e:hp:r: opt; do
;; ;;
r) r)
ratio=$OPTARG ratio=$OPTARG
if [ "$ratio" -gt 100 ] || [ "$ratio" -lt 0 ]; then
echo "The percentage should be an integer within 0~100 range"
exit 1
fi
;; ;;
esac esac
done done
...@@ -143,35 +165,58 @@ fi ...@@ -143,35 +165,58 @@ fi
prerequisite prerequisite
echo "Test scope: $ratio% hotplug memory" echo "Test scope: $ratio% hotplug memory"
echo -e "\t online all hotplug memory in offline state"
echo -e "\t offline $ratio% hotplug memory in online state"
echo -e "\t online all hotplug memory in offline state"
# #
# Online all hot-pluggable memory # Online all hot-pluggable memory
# #
for memory in `hotplaggable_offline_memory`; do hotpluggable_num=`hotpluggable_offline_memory | wc -l`
echo offline-online $memory echo -e "\t online all hot-pluggable memory in offline state:"
online_memory_expect_success $memory if [ "$hotpluggable_num" -gt 0 ]; then
done for memory in `hotpluggable_offline_memory`; do
echo "offline->online memory$memory"
if ! online_memory_expect_success $memory; then
retval=1
fi
done
else
echo -e "\t\t SKIPPED - no hot-pluggable memory in offline state"
fi
# #
# Offline $ratio percent of hot-pluggable memory # Offline $ratio percent of hot-pluggable memory
# #
hotpluggable_num=`hotpluggable_online_memory | wc -l`
target=`echo "a=$hotpluggable_num*$ratio; if ( a%100 ) a/100+1 else a/100" | bc`
echo -e "\t offline $ratio% hot-pluggable memory in online state"
echo -e "\t trying to offline $target out of $hotpluggable_num memory block(s):"
for memory in `hotpluggable_online_memory`; do for memory in `hotpluggable_online_memory`; do
if [ $((RANDOM % 100)) -lt $ratio ]; then if [ "$target" -gt 0 ]; then
echo online-offline $memory echo "online->offline memory$memory"
offline_memory_expect_success $memory if offline_memory_expect_success $memory; then
target=$(($target - 1))
fi
fi fi
done done
if [ "$target" -gt 0 ]; then
retval=1
echo -e "\t\t FAILED - unable to offline some memory blocks, device busy?"
fi
# #
# Online all hot-pluggable memory again # Online all hot-pluggable memory again
# #
for memory in `hotplaggable_offline_memory`; do hotpluggable_num=`hotpluggable_offline_memory | wc -l`
echo offline-online $memory echo -e "\t online all hot-pluggable memory in offline state:"
online_memory_expect_success $memory if [ "$hotpluggable_num" -gt 0 ]; then
done for memory in `hotpluggable_offline_memory`; do
echo "offline->online memory$memory"
if ! online_memory_expect_success $memory; then
retval=1
fi
done
else
echo -e "\t\t SKIPPED - no hot-pluggable memory in offline state"
fi
# #
# Test with memory notifier error injection # Test with memory notifier error injection
...@@ -189,15 +234,16 @@ prerequisite_extra() ...@@ -189,15 +234,16 @@ prerequisite_extra()
if [ ! -d "$DEBUGFS" ]; then if [ ! -d "$DEBUGFS" ]; then
echo $msg debugfs is not mounted >&2 echo $msg debugfs is not mounted >&2
exit 0 exit $retval
fi fi
if [ ! -d $NOTIFIER_ERR_INJECT_DIR ]; then if [ ! -d $NOTIFIER_ERR_INJECT_DIR ]; then
echo $msg memory-notifier-error-inject module is not available >&2 echo $msg memory-notifier-error-inject module is not available >&2
exit 0 exit $retval
fi fi
} }
echo -e "\t Test with memory notifier error injection"
prerequisite_extra prerequisite_extra
# #
...@@ -214,7 +260,7 @@ done ...@@ -214,7 +260,7 @@ done
# Test memory hot-add error handling (offline => online) # Test memory hot-add error handling (offline => online)
# #
echo $error > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_ONLINE/error echo $error > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_ONLINE/error
for memory in `hotplaggable_offline_memory`; do for memory in `hotpluggable_offline_memory`; do
online_memory_expect_fail $memory online_memory_expect_fail $memory
done done
...@@ -222,7 +268,7 @@ done ...@@ -222,7 +268,7 @@ done
# Online all hot-pluggable memory # Online all hot-pluggable memory
# #
echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_ONLINE/error echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_ONLINE/error
for memory in `hotplaggable_offline_memory`; do for memory in `hotpluggable_offline_memory`; do
online_memory_expect_success $memory online_memory_expect_success $memory
done done
...@@ -236,3 +282,5 @@ done ...@@ -236,3 +282,5 @@ done
echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_OFFLINE/error echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_OFFLINE/error
/sbin/modprobe -q -r memory-notifier-error-inject /sbin/modprobe -q -r memory-notifier-error-inject
exit $retval
...@@ -3,8 +3,6 @@ ...@@ -3,8 +3,6 @@
CFLAGS = -Wall -Wl,--no-as-needed -O2 -g CFLAGS = -Wall -Wl,--no-as-needed -O2 -g
CFLAGS += -I../../../../usr/include/ CFLAGS += -I../../../../usr/include/
reuseport_bpf_numa: LDFLAGS += -lnuma
TEST_PROGS := run_netsocktests run_afpackettests test_bpf.sh netdevice.sh TEST_PROGS := run_netsocktests run_afpackettests test_bpf.sh netdevice.sh
TEST_GEN_FILES = socket TEST_GEN_FILES = socket
TEST_GEN_FILES += psock_fanout psock_tpacket TEST_GEN_FILES += psock_fanout psock_tpacket
...@@ -13,3 +11,4 @@ TEST_GEN_FILES += reuseport_dualstack ...@@ -13,3 +11,4 @@ TEST_GEN_FILES += reuseport_dualstack
include ../lib.mk include ../lib.mk
$(OUTPUT)/reuseport_bpf_numa: LDFLAGS += -lnuma
...@@ -4,3 +4,5 @@ LDFLAGS += -lpthread ...@@ -4,3 +4,5 @@ LDFLAGS += -lpthread
include ../lib.mk include ../lib.mk
$(TEST_GEN_PROGS): seccomp_bpf.c ../kselftest_harness.h
$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
#include <unistd.h> #include <unistd.h>
#include <sys/syscall.h> #include <sys/syscall.h>
#include "test_harness.h" #include "../kselftest_harness.h"
#ifndef PR_SET_PTRACER #ifndef PR_SET_PTRACER
# define PR_SET_PTRACER 0x59616d61 # define PR_SET_PTRACER 0x59616d61
...@@ -1310,7 +1310,7 @@ void change_syscall(struct __test_metadata *_metadata, ...@@ -1310,7 +1310,7 @@ void change_syscall(struct __test_metadata *_metadata,
iov.iov_len = sizeof(regs); iov.iov_len = sizeof(regs);
ret = ptrace(PTRACE_GETREGSET, tracee, NT_PRSTATUS, &iov); ret = ptrace(PTRACE_GETREGSET, tracee, NT_PRSTATUS, &iov);
#endif #endif
EXPECT_EQ(0, ret); EXPECT_EQ(0, ret) {}
#if defined(__x86_64__) || defined(__i386__) || defined(__powerpc__) || \ #if defined(__x86_64__) || defined(__i386__) || defined(__powerpc__) || \
defined(__s390__) || defined(__hppa__) defined(__s390__) || defined(__hppa__)
......
...@@ -75,26 +75,31 @@ void _start(void) ...@@ -75,26 +75,31 @@ void _start(void)
int ccode; int ccode;
struct sysinfo info; struct sysinfo info;
unsigned long used; unsigned long used;
static const char *test_name = " get runtime memory use\n";
print("Testing system size.\n"); print("TAP version 13\n");
print("1..1\n"); print("# Testing system size.\n");
ccode = sysinfo(&info); ccode = sysinfo(&info);
if (ccode < 0) { if (ccode < 0) {
print("not ok 1 get runtime memory use\n"); print("not ok 1");
print("# could not get sysinfo\n"); print(test_name);
print(" ---\n reason: \"could not get sysinfo\"\n ...\n");
_exit(ccode); _exit(ccode);
} }
print("ok 1");
print(test_name);
/* ignore cache complexities for now */ /* ignore cache complexities for now */
used = info.totalram - info.freeram - info.bufferram; used = info.totalram - info.freeram - info.bufferram;
print_k_value("ok 1 get runtime memory use # size = ", used,
info.mem_unit);
print("# System runtime memory report (units in Kilobytes):\n"); print("# System runtime memory report (units in Kilobytes):\n");
print_k_value("# Total: ", info.totalram, info.mem_unit); print(" ---\n");
print_k_value("# Free: ", info.freeram, info.mem_unit); print_k_value(" Total: ", info.totalram, info.mem_unit);
print_k_value("# Buffer: ", info.bufferram, info.mem_unit); print_k_value(" Free: ", info.freeram, info.mem_unit);
print_k_value("# In use: ", used, info.mem_unit); print_k_value(" Buffer: ", info.bufferram, info.mem_unit);
print_k_value(" In use: ", used, info.mem_unit);
print(" ...\n");
print("1..1\n");
_exit(0); _exit(0);
} }
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h> #include <sys/wait.h>
#include "synctest.h" #include "synctest.h"
...@@ -52,10 +53,22 @@ static int run_test(int (*test)(void), char *name) ...@@ -52,10 +53,22 @@ static int run_test(int (*test)(void), char *name)
exit(test()); exit(test());
} }
static int sync_api_supported(void)
{
struct stat sbuf;
return 0 == stat("/sys/kernel/debug/sync/sw_sync", &sbuf);
}
int main(void) int main(void)
{ {
int err = 0; int err = 0;
if (!sync_api_supported()) {
printf("SKIP: Sync framework not supported by kernel\n");
return 0;
}
printf("[RUN]\tTesting sync framework\n"); printf("[RUN]\tTesting sync framework\n");
err += RUN_TEST(test_alloc_timeline); err += RUN_TEST(test_alloc_timeline);
......
...@@ -24,6 +24,14 @@ verify() ...@@ -24,6 +24,14 @@ verify()
return 0 return 0
} }
exit_test()
{
if [ ! -z ${old_strict} ]; then
echo ${old_strict} > ${WRITES_STRICT}
fi
exit $rc
}
trap 'set_orig; rm -f "${TEST_FILE}"' EXIT trap 'set_orig; rm -f "${TEST_FILE}"' EXIT
rc=0 rc=0
...@@ -63,6 +71,20 @@ else ...@@ -63,6 +71,20 @@ else
echo "ok" echo "ok"
fi fi
echo -n "Checking write strict setting ... "
WRITES_STRICT="${SYSCTL}/kernel/sysctl_writes_strict"
if [ ! -e ${WRITES_STRICT} ]; then
echo "FAIL, but skip in case of old kernel" >&2
else
old_strict=$(cat ${WRITES_STRICT})
if [ "$old_strict" = "1" ]; then
echo "ok"
else
echo "FAIL, strict value is 0 but force to 1 to continue" >&2
echo "1" > ${WRITES_STRICT}
fi
fi
# Now that we've validated the sanity of "set_test" and "set_orig", # Now that we've validated the sanity of "set_test" and "set_orig",
# we can use those functions to set starting states before running # we can use those functions to set starting states before running
# specific behavioral tests. # specific behavioral tests.
......
...@@ -7,4 +7,4 @@ TEST_STR=$(( $ORIG + 1 )) ...@@ -7,4 +7,4 @@ TEST_STR=$(( $ORIG + 1 ))
. ./common_tests . ./common_tests
exit $rc exit_test
...@@ -74,4 +74,4 @@ else ...@@ -74,4 +74,4 @@ else
echo "ok" echo "ok"
fi fi
exit $rc exit_test
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#include <numaif.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/time.h> #include <sys/time.h>
...@@ -32,15 +31,33 @@ ...@@ -32,15 +31,33 @@
* different areas one below 128TB and one above 128TB * different areas one below 128TB and one above 128TB
* till it reaches 512TB. One with size 128TB and the * till it reaches 512TB. One with size 128TB and the
* other being 384TB. * other being 384TB.
*
* On Arm64 the address space is 256TB and no high mappings
* are supported so far.
*/ */
#define NR_CHUNKS_128TB 8192UL /* Number of 16GB chunks for 128TB */ #define NR_CHUNKS_128TB 8192UL /* Number of 16GB chunks for 128TB */
#define NR_CHUNKS_384TB 24576UL /* Number of 16GB chunks for 384TB */ #define NR_CHUNKS_256TB (NR_CHUNKS_128TB * 2UL)
#define NR_CHUNKS_384TB (NR_CHUNKS_128TB * 3UL)
#define ADDR_MARK_128TB (1UL << 47) /* First address beyond 128TB */ #define ADDR_MARK_128TB (1UL << 47) /* First address beyond 128TB */
#define ADDR_MARK_256TB (1UL << 48) /* First address beyond 256TB */
#ifdef __aarch64__
#define HIGH_ADDR_MARK ADDR_MARK_256TB
#define HIGH_ADDR_SHIFT 49
#define NR_CHUNKS_LOW NR_CHUNKS_256TB
#define NR_CHUNKS_HIGH 0
#else
#define HIGH_ADDR_MARK ADDR_MARK_128TB
#define HIGH_ADDR_SHIFT 48
#define NR_CHUNKS_LOW NR_CHUNKS_128TB
#define NR_CHUNKS_HIGH NR_CHUNKS_384TB
#endif
static char *hind_addr(void) static char *hind_addr(void)
{ {
int bits = 48 + rand() % 15; int bits = HIGH_ADDR_SHIFT + rand() % (63 - HIGH_ADDR_SHIFT);
return (char *) (1UL << bits); return (char *) (1UL << bits);
} }
...@@ -50,14 +67,14 @@ static int validate_addr(char *ptr, int high_addr) ...@@ -50,14 +67,14 @@ static int validate_addr(char *ptr, int high_addr)
unsigned long addr = (unsigned long) ptr; unsigned long addr = (unsigned long) ptr;
if (high_addr) { if (high_addr) {
if (addr < ADDR_MARK_128TB) { if (addr < HIGH_ADDR_MARK) {
printf("Bad address %lx\n", addr); printf("Bad address %lx\n", addr);
return 1; return 1;
} }
return 0; return 0;
} }
if (addr > ADDR_MARK_128TB) { if (addr > HIGH_ADDR_MARK) {
printf("Bad address %lx\n", addr); printf("Bad address %lx\n", addr);
return 1; return 1;
} }
...@@ -79,12 +96,12 @@ static int validate_lower_address_hint(void) ...@@ -79,12 +96,12 @@ static int validate_lower_address_hint(void)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
char *ptr[NR_CHUNKS_128TB]; char *ptr[NR_CHUNKS_LOW];
char *hptr[NR_CHUNKS_384TB]; char *hptr[NR_CHUNKS_HIGH];
char *hint; char *hint;
unsigned long i, lchunks, hchunks; unsigned long i, lchunks, hchunks;
for (i = 0; i < NR_CHUNKS_128TB; i++) { for (i = 0; i < NR_CHUNKS_LOW; i++) {
ptr[i] = mmap(NULL, MAP_CHUNK_SIZE, PROT_READ | PROT_WRITE, ptr[i] = mmap(NULL, MAP_CHUNK_SIZE, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
...@@ -99,7 +116,7 @@ int main(int argc, char *argv[]) ...@@ -99,7 +116,7 @@ int main(int argc, char *argv[])
} }
lchunks = i; lchunks = i;
for (i = 0; i < NR_CHUNKS_384TB; i++) { for (i = 0; i < NR_CHUNKS_HIGH; i++) {
hint = hind_addr(); hint = hind_addr();
hptr[i] = mmap(hint, MAP_CHUNK_SIZE, PROT_READ | PROT_WRITE, hptr[i] = mmap(hint, MAP_CHUNK_SIZE, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment