Skip to content

Commit

Permalink
Merge tag 'linux-kselftest-4.13-rc1-update' of git://git.kernel.org/p…
Browse files Browse the repository at this point in the history
…ub/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
  ...
  • Loading branch information
torvalds committed Jul 7, 2017
2 parents 3794907 + e67f85f commit ef3ad08
Show file tree
Hide file tree
Showing 42 changed files with 1,011 additions and 509 deletions.
2 changes: 0 additions & 2 deletions Documentation/00-INDEX
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,6 @@ kprobes.txt
- documents the kernel probes debugging feature.
kref.txt
- docs on adding reference counters (krefs) to kernel objects.
kselftest.txt
- small unittests for (some) individual codepaths in the kernel.
laptops/
- directory with laptop related info and laptop driver documentation.
ldm.txt
Expand Down
1 change: 1 addition & 0 deletions Documentation/dev-tools/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ whole; patches welcome!
kmemcheck
gdb-kernel-debugging
kgdb
kselftest


.. only:: subproject and html
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
======================
Linux Kernel 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
Expand All @@ -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)
=============================================================

To build the tests:
To build the tests::

$ make -C tools/testing/selftests

To run the tests::

To run the 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

- note that some tests will require root privileges.
Note that some tests will require root privileges.


Running a subset of selftests
========================================
=============================

You can use the "TARGETS" variable on the make command line to specify
single test to run, or a list of tests to run.

To run only tests targeted for a single subsystem:
$ make -C tools/testing/selftests TARGETS=ptrace run_tests
To run only tests targeted for a single subsystem::

$ 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

See the top-level tools/testing/selftests/Makefile for the list of all
Expand All @@ -46,13 +53,15 @@ possible targets.
Running the full range hotplug selftests
========================================

To build the hotplug tests:
To build the hotplug tests::

$ make -C tools/testing/selftests hotplug

To run the hotplug tests:
To run the hotplug tests::

$ 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
Expand All @@ -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.

To install selftests in default location:
To install selftests in default location::

$ cd tools/testing/selftests
$ ./kselftest_install.sh

To install selftests in a user specified location:
To install selftests in a user specified location::

$ cd tools/testing/selftests
$ ./kselftest_install.sh install_dir

Expand All @@ -77,10 +88,10 @@ Kselftest install as well as the Kselftest tarball provide a script
named "run_kselftest.sh" to run the tests.

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
./run_kselftest.sh
$ cd kselftest
$ ./run_kselftest.sh

Contributing new tests
======================
Expand All @@ -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
unconfigured.

Contributing new tests(details)
===============================
Contributing new tests (details)
================================

* Use TEST_GEN_XXX if such binaries or files are generated during
compiling.

TEST_PROGS, TEST_GEN_PROGS mean it is the excutable tested by
default.

TEST_PROGS_EXTENDED, TEST_GEN_PROGS_EXTENDED mean it is the
executable which is not tested by default.
TEST_FILES, TEST_GEN_FILES mean it is the file which is used by
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
6 changes: 4 additions & 2 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -7337,9 +7337,10 @@ KERNEL SELFTEST FRAMEWORK
M: Shuah Khan <[email protected]>
M: Shuah Khan <[email protected]>
L: [email protected]
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
F: tools/testing/selftests
F: tools/testing/selftests/
F: Documentation/dev-tools/kselftest*

KERNEL VIRTUAL MACHINE (KVM)
M: Paolo Bonzini <[email protected]>
Expand Down Expand Up @@ -11740,6 +11741,7 @@ F: kernel/seccomp.c
F: include/uapi/linux/seccomp.h
F: include/linux/seccomp.h
F: tools/testing/selftests/seccomp/*
F: tools/testing/selftests/kselftest_harness.h
F: Documentation/userspace-api/seccomp_filter.rst
K: \bsecure_computing
K: \bTIF_SECCOMP\b
Expand Down
3 changes: 2 additions & 1 deletion kernel/trace/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -4564,7 +4564,8 @@ static const char readme_msg[] =
#endif
#if defined(CONFIG_KPROBE_EVENTS) || defined(CONFIG_UPROBE_EVENTS)
"\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"
#ifdef CONFIG_KPROBE_EVENTS
"\t place: [<module>:]<symbol>[+<offset>]|<memaddr>\n"
Expand Down
45 changes: 25 additions & 20 deletions tools/testing/selftests/breakpoints/breakpoint_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <errno.h>
#include <string.h>

#include "../kselftest.h"

Expand All @@ -42,10 +44,9 @@ static void set_breakpoint_addr(void *addr, int n)

ret = ptrace(PTRACE_POKEUSER, child_pid,
offsetof(struct user, u_debugreg[n]), addr);
if (ret) {
perror("Can't set breakpoint addr\n");
ksft_exit_fail();
}
if (ret)
ksft_exit_fail_msg("Can't set breakpoint addr: %s\n",
strerror(errno));
}

static void toggle_breakpoint(int n, int type, int len,
Expand Down Expand Up @@ -106,8 +107,8 @@ static void toggle_breakpoint(int n, int type, int len,
ret = ptrace(PTRACE_POKEUSER, child_pid,
offsetof(struct user, u_debugreg[7]), dr7);
if (ret) {
perror("Can't set dr7");
ksft_exit_fail();
ksft_print_msg("Can't set dr7: %s\n", strerror(errno));
exit(-1);
}
}

Expand Down Expand Up @@ -206,7 +207,7 @@ static void trigger_tests(void)

ret = ptrace(PTRACE_TRACEME, 0, NULL, 0);
if (ret) {
perror("Can't be traced?\n");
ksft_print_msg("Can't be traced? %s\n", strerror(errno));
return;
}

Expand Down Expand Up @@ -261,29 +262,30 @@ static void trigger_tests(void)

static void check_success(const char *msg)
{
const char *msg2;
int child_nr_tests;
int status;
int ret;

/* Wait for the child to SIGTRAP */
wait(&status);

msg2 = "Failed";
ret = 0;

if (WSTOPSIG(status) == SIGTRAP) {
child_nr_tests = ptrace(PTRACE_PEEKDATA, child_pid,
&nr_tests, 0);
if (child_nr_tests == nr_tests)
msg2 = "Ok";
if (ptrace(PTRACE_POKEDATA, child_pid, &trapped, 1)) {
perror("Can't poke\n");
ksft_exit_fail();
}
ret = 1;
if (ptrace(PTRACE_POKEDATA, child_pid, &trapped, 1))
ksft_exit_fail_msg("Can't poke: %s\n", strerror(errno));
}

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)
Expand All @@ -294,7 +296,7 @@ static void launch_instruction_breakpoints(char *buf, int local, int global)
set_breakpoint_addr(dummy_funcs[i], i);
toggle_breakpoint(i, BP_X, 1, local, global, 1);
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);
check_success(buf);
toggle_breakpoint(i, BP_X, 1, local, global, 0);
Expand All @@ -316,8 +318,9 @@ static void launch_watchpoints(char *buf, int mode, int len,
set_breakpoint_addr(&dummy_var[i], i);
toggle_breakpoint(i, mode, len, local, global, 1);
ptrace(PTRACE_CONT, child_pid, NULL, 0);
sprintf(buf, "Test %s watchpoint %d with len: %d local: "
"%d global: %d", mode_str, i, len, local, global);
sprintf(buf,
"Test %s watchpoint %d with len: %d local: %d global: %d\n",
mode_str, i, len, local, global);
check_success(buf);
toggle_breakpoint(i, mode, len, local, global, 0);
}
Expand Down Expand Up @@ -378,10 +381,12 @@ int main(int argc, char **argv)
pid_t pid;
int ret;

ksft_print_header();

pid = fork();
if (!pid) {
trigger_tests();
return 0;
exit(0);
}

child_pid = pid;
Expand All @@ -392,5 +397,5 @@ int main(int argc, char **argv)

wait(NULL);

return ksft_exit_pass();
ksft_exit_pass();
}
Loading

0 comments on commit ef3ad08

Please sign in to comment.