Pull kselftest fixes from Shuah Khan: - ftrace and safesetid test fixes from Masami Hiramatsu - Kunit fixes from Brendan Higgins, Iurii Zaikin, and Heidi Fahim - Kselftest framework fixes from SeongJae Park and Michael Ellerman * tag 'linux-kselftest-5.5-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: kselftest: Support old perl versions kselftest/runner: Print new line in print of timeout log selftests: Fix dangling documentation references to kselftest_module.sh Documentation: kunit: add documentation for kunit_tool Documentation: kunit: fix typos and gramatical errors kunit: testing kunit: Bug fix in test_run_timeout function fs/ext4/inode-test: Fix inode test on 32 bit platforms. selftests: safesetid: Fix Makefile to set correct test program selftests: safesetid: Check the return value of setuid/setgid selftests: safesetid: Move link library to LDLIBS selftests/ftrace: Fix multiple kprobe testcase selftests/ftrace: Do not to use absolute debugfs path selftests/ftrace: Fix ftrace test cases to check unsupported selftests/ftrace: Fix to check the existence of set_ftrace_filter
Unified · Split
| @@ -203,12 +203,12 @@ Test Module · 202 unmodified lines | ||
| 203 | 203 | Kselftest tests the kernel from userspace. Sometimes things need |
| 204 | 204 | testing from within the kernel, one method of doing this is to create a |
| 205 | 205 | test module. We can tie the module into the kselftest framework by |
| 206 | −using a shell script test runner. ``kselftest_module.sh`` is designed | |
| 206 | +using a shell script test runner. ``kselftest/module.sh`` is designed | |
| 207 | 207 | to facilitate this process. There is also a header file provided to |
| 208 | 208 | assist writing kernel modules that are for use with kselftest: |
| 209 | 209 | |
| 210 | 210 | - ``tools/testing/kselftest/kselftest_module.h`` |
| 211 | −- ``tools/testing/kselftest/kselftest_module.sh`` | |
| 211 | +- ``tools/testing/kselftest/kselftest/module.sh`` | |
| 212 | 212 | |
| 213 | 213 | How to use |
| 214 | 214 | ---------- |
| @@ -247,7 +247,7 @@ A bare bones test module might look like this: · 32 unmodified lines | ||
| 247 | 247 | |
| 248 | 248 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 249 | 249 | |
| 250 | − #include "../tools/testing/selftests/kselftest_module.h" | |
| 250 | + #include "../tools/testing/selftests/kselftest/module.h" | |
| 251 | 251 | |
| 252 | 252 | KSTM_MODULE_GLOBALS(); |
| 253 | 253 | |
| @@ -276,7 +276,7 @@ Example test script · 22 unmodified lines | ||
| 276 | 276 | |
| 277 | 277 | #!/bin/bash |
| 278 | 278 | # SPDX-License-Identifier: GPL-2.0+ |
| 279 | − $(dirname $0)/../kselftest_module.sh "foo" test_foo | |
| 279 | + $(dirname $0)/../kselftest/module.sh "foo" test_foo | |
| 280 | 280 | |
| 281 | 281 | |
| 282 | 282 | Test Harness |
| @@ -9,6 +9,7 @@ KUnit - Unit Testing for the Linux Kernel · 8 unmodified lines | ||
| 9 | 9 | |
| 10 | 10 | start |
| 11 | 11 | usage |
| 12 | + kunit-tool | |
| 12 | 13 | api/index |
| 13 | 14 | faq |
| 14 | 15 | |
| @@ -0,0 +1,57 @@ | ||
| 1 | +.. SPDX-License-Identifier: GPL-2.0 | |
| 2 | + | |
| 3 | +================= | |
| 4 | +kunit_tool How-To | |
| 5 | +================= | |
| 6 | + | |
| 7 | +What is kunit_tool? | |
| 8 | +=================== | |
| 9 | + | |
| 10 | +kunit_tool is a script (``tools/testing/kunit/kunit.py``) that aids in building | |
| 11 | +the Linux kernel as UML (`User Mode Linux | |
| 12 | +<http://user-mode-linux.sourceforge.net/>`_), running KUnit tests, parsing | |
| 13 | +the test results and displaying them in a user friendly manner. | |
| 14 | + | |
| 15 | +What is a kunitconfig? | |
| 16 | +====================== | |
| 17 | + | |
| 18 | +It's just a defconfig that kunit_tool looks for in the base directory. | |
| 19 | +kunit_tool uses it to generate a .config as you might expect. In addition, it | |
| 20 | +verifies that the generated .config contains the CONFIG options in the | |
| 21 | +kunitconfig; the reason it does this is so that it is easy to be sure that a | |
| 22 | +CONFIG that enables a test actually ends up in the .config. | |
| 23 | + | |
| 24 | +How do I use kunit_tool? | |
| 25 | +======================== | |
| 26 | + | |
| 27 | +If a kunitconfig is present at the root directory, all you have to do is: | |
| 28 | + | |
| 29 | +.. code-block:: bash | |
| 30 | + | |
| 31 | + ./tools/testing/kunit/kunit.py run | |
| 32 | + | |
| 33 | +However, you most likely want to use it with the following options: | |
| 34 | + | |
| 35 | +.. code-block:: bash | |
| 36 | + | |
| 37 | + ./tools/testing/kunit/kunit.py run --timeout=30 --jobs=`nproc --all` | |
| 38 | + | |
| 39 | +- ``--timeout`` sets a maximum amount of time to allow tests to run. | |
| 40 | +- ``--jobs`` sets the number of threads to use to build the kernel. | |
| 41 | + | |
| 42 | +If you just want to use the defconfig that ships with the kernel, you can | |
| 43 | +append the ``--defconfig`` flag as well: | |
| 44 | + | |
| 45 | +.. code-block:: bash | |
| 46 | + | |
| 47 | + ./tools/testing/kunit/kunit.py run --timeout=30 --jobs=`nproc --all` --defconfig | |
| 48 | + | |
| 49 | +.. note:: | |
| 50 | + This command is particularly helpful for getting started because it | |
| 51 | + just works. No kunitconfig needs to be present. | |
| 52 | + | |
| 53 | +For a list of all the flags supported by kunit_tool, you can run: | |
| 54 | + | |
| 55 | +.. code-block:: bash | |
| 56 | + | |
| 57 | + ./tools/testing/kunit/kunit.py run --help | |
| @@ -19,11 +19,14 @@ The wrapper can be run with: · 18 unmodified lines | ||
| 19 | 19 | |
| 20 | 20 | .. code-block:: bash |
| 21 | 21 | |
| 22 | − ./tools/testing/kunit/kunit.py run | |
| 22 | + ./tools/testing/kunit/kunit.py run --defconfig | |
| 23 | + | |
| 24 | +For more information on this wrapper (also called kunit_tool) checkout the | |
| 25 | +:doc:`kunit-tool` page. | |
| 23 | 26 | |
| 24 | 27 | Creating a kunitconfig |
| 25 | 28 | ====================== |
| 26 | −The Python script is a thin wrapper around Kbuild as such, it needs to be | |
| 29 | +The Python script is a thin wrapper around Kbuild. As such, it needs to be | |
| 27 | 30 | configured with a ``kunitconfig`` file. This file essentially contains the |
| 28 | 31 | regular Kernel config, with the specific test targets as well. |
| 29 | 32 | |
| @@ -59,8 +62,8 @@ If everything worked correctly, you should see the following: · 29 unmodified lines | ||
| 59 | 62 | followed by a list of tests that are run. All of them should be passing. |
| 60 | 63 | |
| 61 | 64 | .. note:: |
| 62 | − Because it is building a lot of sources for the first time, the ``Building | |
| 63 | − kunit kernel`` step may take a while. | |
| 65 | + Because it is building a lot of sources for the first time, the | |
| 66 | + ``Building KUnit kernel`` step may take a while. | |
| 64 | 67 | |
| 65 | 68 | Writing your first test |
| 66 | 69 | ======================= |
| @@ -159,7 +162,7 @@ Now you can run the test: · 92 unmodified lines | ||
| 159 | 162 | |
| 160 | 163 | .. code-block:: bash |
| 161 | 164 | |
| 162 | − ./tools/testing/kunit/kunit.py | |
| 165 | + ./tools/testing/kunit/kunit.py run | |
| 163 | 166 | |
| 164 | 167 | You should see the following failure: |
| 165 | 168 | |
| @@ -16,7 +16,7 @@ Organization of this document · 15 unmodified lines | ||
| 16 | 16 | ============================= |
| 17 | 17 | |
| 18 | 18 | This document is organized into two main sections: Testing and Isolating |
| 19 | −Behavior. The first covers what a unit test is and how to use KUnit to write | |
| 19 | +Behavior. The first covers what unit tests are and how to use KUnit to write | |
| 20 | 20 | them. The second covers how to use KUnit to isolate code and make it possible |
| 21 | 21 | to unit test code that was otherwise un-unit-testable. |
| 22 | 22 | |
| @@ -174,13 +174,13 @@ Test Suites · 151 unmodified lines | ||
| 174 | 174 | ~~~~~~~~~~~ |
| 175 | 175 | |
| 176 | 176 | Now obviously one unit test isn't very helpful; the power comes from having |
| 177 | −many test cases covering all of your behaviors. Consequently it is common to | |
| 178 | −have many *similar* tests; in order to reduce duplication in these closely | |
| 179 | −related tests most unit testing frameworks provide the concept of a *test | |
| 180 | −suite*, in KUnit we call it a *test suite*; all it is is just a collection of | |
| 181 | −test cases for a unit of code with a set up function that gets invoked before | |
| 182 | −every test cases and then a tear down function that gets invoked after every | |
| 183 | −test case completes. | |
| 177 | +many test cases covering all of a unit's behaviors. Consequently it is common | |
| 178 | +to have many *similar* tests; in order to reduce duplication in these closely | |
| 179 | +related tests most unit testing frameworks - including KUnit - provide the | |
| 180 | +concept of a *test suite*. A *test suite* is just a collection of test cases | |
| 181 | +for a unit of code with a set up function that gets invoked before every test | |
| 182 | +case and then a tear down function that gets invoked after every test case | |
| 183 | +completes. | |
| 184 | 184 | |
| 185 | 185 | Example: |
| 186 | 186 | |
| @@ -211,7 +211,7 @@ KUnit test framework. · 24 unmodified lines | ||
| 211 | 211 | .. note:: |
| 212 | 212 | A test case will only be run if it is associated with a test suite. |
| 213 | 213 | |
| 214 | −For a more information on these types of things see the :doc:`api/test`. | |
| 214 | +For more information on these types of things see the :doc:`api/test`. | |
| 215 | 215 | |
| 216 | 216 | Isolating Behavior |
| 217 | 217 | ================== |
| @@ -338,7 +338,7 @@ We can easily test this code by *faking out* the underlying EEPROM: · 120 unmodified lines | ||
| 338 | 338 | return count; |
| 339 | 339 | } |
| 340 | 340 | |
| 341 | − ssize_t fake_eeprom_write(struct eeprom *this, size_t offset, const char *buffer, size_t count) | |
| 341 | + ssize_t fake_eeprom_write(struct eeprom *parent, size_t offset, const char *buffer, size_t count) | |
| 342 | 342 | { |
| 343 | 343 | struct fake_eeprom *this = container_of(parent, struct fake_eeprom, parent); |
| 344 | 344 | |
| @@ -454,7 +454,7 @@ KUnit on non-UML architectures · 109 unmodified lines | ||
| 454 | 454 | By default KUnit uses UML as a way to provide dependencies for code under test. |
| 455 | 455 | Under most circumstances KUnit's usage of UML should be treated as an |
| 456 | 456 | implementation detail of how KUnit works under the hood. Nevertheless, there |
| 457 | −are instances where being able to run architecture specific code, or test | |
| 457 | +are instances where being able to run architecture specific code or test | |
| 458 | 458 | against real hardware is desirable. For these reasons KUnit supports running on |
| 459 | 459 | other architectures. |
| 460 | 460 | |
| @@ -557,7 +557,7 @@ run your tests on your hardware setup just by compiling for your architecture. · 96 unmodified lines | ||
| 557 | 557 | .. important:: |
| 558 | 558 | Always prefer tests that run on UML to tests that only run under a particular |
| 559 | 559 | architecture, and always prefer tests that run under QEMU or another easy |
| 560 | − (and monitarily free) to obtain software environment to a specific piece of | |
| 560 | + (and monetarily free) to obtain software environment to a specific piece of | |
| 561 | 561 | hardware. |
| 562 | 562 | |
| 563 | 563 | Nevertheless, there are still valid reasons to write an architecture or hardware |
| @@ -25,7 +25,7 @@ · 24 unmodified lines | ||
| 25 | 25 | * For constructing the negative timestamp lower bound value. |
| 26 | 26 | * binary: 10000000 00000000 00000000 00000000 |
| 27 | 27 | */ |
| 28 | −#define LOWER_MSB_1 (-0x80000000L) | |
| 28 | +#define LOWER_MSB_1 (-(UPPER_MSB_0) - 1L) /* avoid overflow */ | |
| 29 | 29 | /* |
| 30 | 30 | * For constructing the negative timestamp upper bound value. |
| 31 | 31 | * binary: 11111111 11111111 11111111 11111111 |
| @@ -199,7 +199,7 @@ class KUnitMainTest(unittest.TestCase): · 198 unmodified lines | ||
| 199 | 199 | timeout = 3453 |
| 200 | 200 | kunit.main(['run', '--timeout', str(timeout)], self.linux_source_mock) |
| 201 | 201 | assert self.linux_source_mock.build_reconfig.call_count == 1 |
| 202 | − self.linux_source_mock.run_kernel.assert_called_once_with(timeout=timeout) | |
| 202 | + self.linux_source_mock.run_kernel.assert_called_once_with(build_dir=None, timeout=timeout) | |
| 203 | 203 | self.print_mock.assert_any_call(StrContains('Testing complete.')) |
| 204 | 204 | |
| 205 | 205 | if __name__ == '__main__': |
| @@ -3,6 +3,8 @@ · 2 unmodified lines | ||
| 3 | 3 | # description: ftrace - stacktrace filter command |
| 4 | 4 | # flags: instance |
| 5 | 5 | |
| 6 | +[ ! -f set_ftrace_filter ] && exit_unsupported | |
| 7 | + | |
| 6 | 8 | echo _do_fork:stacktrace >> set_ftrace_filter |
| 7 | 9 | |
| 8 | 10 | grep -q "_do_fork:stacktrace:unlimited" set_ftrace_filter |
| @@ -15,6 +15,11 @@ if [ $NP -eq 1 ] ;then · 14 unmodified lines | ||
| 15 | 15 | exit_unresolved |
| 16 | 16 | fi |
| 17 | 17 | |
| 18 | +if ! grep -q "function" available_tracers ; then | |
| 19 | + echo "Function trace is not enabled" | |
| 20 | + exit_unsupported | |
| 21 | +fi | |
| 22 | + | |
| 18 | 23 | ORIG_CPUMASK=`cat tracing_cpumask` |
| 19 | 24 | |
| 20 | 25 | do_reset() { |
| @@ -46,6 +46,9 @@ reset_events_filter() { # reset all current setting filters · 45 unmodified lines | ||
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | reset_ftrace_filter() { # reset all triggers in set_ftrace_filter |
| 49 | + if [ ! -f set_ftrace_filter ]; then | |
| 50 | + return 0 | |
| 51 | + fi | |
| 49 | 52 | echo > set_ftrace_filter |
| 50 | 53 | grep -v '^#' set_ftrace_filter | while read t; do |
| 51 | 54 | tr=`echo $t | cut -d: -f2` |
| @@ -93,7 +96,7 @@ initialize_ftrace() { # Reset ftrace to initial-state · 41 unmodified lines | ||
| 93 | 96 | disable_events |
| 94 | 97 | [ -f set_event_pid ] && echo > set_event_pid |
| 95 | 98 | [ -f set_ftrace_pid ] && echo > set_ftrace_pid |
| 96 | − [ -f set_ftrace_filter ] && echo | tee set_ftrace_* | |
| 99 | + [ -f set_ftrace_notrace ] && echo > set_ftrace_notrace | |
| 97 | 100 | [ -f set_graph_function ] && echo | tee set_graph_* |
| 98 | 101 | [ -f stack_trace_filter ] && echo > stack_trace_filter |
| 99 | 102 | [ -f kprobe_events ] && echo > kprobe_events |
| @@ -20,9 +20,9 @@ while read i; do · 19 unmodified lines | ||
| 20 | 20 | test $N -eq 256 && break |
| 21 | 21 | done |
| 22 | 22 | |
| 23 | −L=`wc -l kprobe_events` | |
| 24 | −if [ $L -ne $N ]; then | |
| 25 | − echo "The number of kprobes events ($L) is not $N" | |
| 23 | +L=`cat kprobe_events | wc -l` | |
| 24 | +if [ $L -ne 256 ]; then | |
| 25 | + echo "The number of kprobes events ($L) is not 256" | |
| 26 | 26 | exit_fail |
| 27 | 27 | fi |
| 28 | 28 | |
| @@ -21,10 +21,10 @@ grep -q "snapshot()" README || exit_unsupported # version issue · 20 unmodified lines | ||
| 21 | 21 | |
| 22 | 22 | echo "Test expected snapshot action failure" |
| 23 | 23 | |
| 24 | −echo 'hist:keys=comm:onmatch(sched.sched_wakeup).snapshot()' >> /sys/kernel/debug/tracing/events/sched/sched_waking/trigger && exit_fail | |
| 24 | +echo 'hist:keys=comm:onmatch(sched.sched_wakeup).snapshot()' >> events/sched/sched_waking/trigger && exit_fail | |
| 25 | 25 | |
| 26 | 26 | echo "Test expected save action failure" |
| 27 | 27 | |
| 28 | −echo 'hist:keys=comm:onmatch(sched.sched_wakeup).save(comm,prio)' >> /sys/kernel/debug/tracing/events/sched/sched_waking/trigger && exit_fail | |
| 28 | +echo 'hist:keys=comm:onmatch(sched.sched_wakeup).save(comm,prio)' >> events/sched/sched_waking/trigger && exit_fail | |
| 29 | 29 | |
| 30 | 30 | exit_xfail |
| @@ -16,7 +16,7 @@ grep -q "onchange(var)" README || exit_unsupported # version issue · 15 unmodified lines | ||
| 16 | 16 | |
| 17 | 17 | echo "Test onchange action" |
| 18 | 18 | |
| 19 | −echo 'hist:keys=comm:newprio=prio:onchange($newprio).save(comm,prio) if comm=="ping"' >> /sys/kernel/debug/tracing/events/sched/sched_waking/trigger | |
| 19 | +echo 'hist:keys=comm:newprio=prio:onchange($newprio).save(comm,prio) if comm=="ping"' >> events/sched/sched_waking/trigger | |
| 20 | 20 | |
| 21 | 21 | ping $LOCALHOST -c 3 |
| 22 | 22 | nice -n 1 ping $LOCALHOST -c 3 |
| @@ -23,9 +23,9 @@ grep -q "snapshot()" README || exit_unsupported # version issue · 22 unmodified lines | ||
| 23 | 23 | |
| 24 | 24 | echo "Test snapshot action" |
| 25 | 25 | |
| 26 | −echo 1 > /sys/kernel/debug/tracing/events/sched/enable | |
| 26 | +echo 1 > events/sched/enable | |
| 27 | 27 | |
| 28 | −echo 'hist:keys=comm:newprio=prio:onchange($newprio).save(comm,prio):onchange($newprio).snapshot() if comm=="ping"' >> /sys/kernel/debug/tracing/events/sched/sched_waking/trigger | |
| 28 | +echo 'hist:keys=comm:newprio=prio:onchange($newprio).save(comm,prio):onchange($newprio).snapshot() if comm=="ping"' >> events/sched/sched_waking/trigger | |
| 29 | 29 | |
| 30 | 30 | ping $LOCALHOST -c 3 |
| 31 | 31 | nice -n 1 ping $LOCALHOST -c 3 |
| @@ -9,7 +9,7 @@ · 8 unmodified lines | ||
| 9 | 9 | # |
| 10 | 10 | # #!/bin/sh |
| 11 | 11 | # SPDX-License-Identifier: GPL-2.0+ |
| 12 | −# $(dirname $0)/../kselftest_module.sh "description" module_name | |
| 12 | +# $(dirname $0)/../kselftest/module.sh "description" module_name | |
| 13 | 13 | # |
| 14 | 14 | # Example: tools/testing/selftests/lib/printf.sh |
| 15 | 15 | |
| @@ -3,6 +3,7 @@ · 2 unmodified lines | ||
| 3 | 3 | # Prefix all lines with "# ", unbuffered. Command being piped in may need |
| 4 | 4 | # to have unbuffering forced with "stdbuf -i0 -o0 -e0 $cmd". |
| 5 | 5 | use strict; |
| 6 | +use IO::Handle; | |
| 6 | 7 | |
| 7 | 8 | binmode STDIN; |
| 8 | 9 | binmode STDOUT; |
| @@ -79,6 +79,7 @@ run_one() · 78 unmodified lines | ||
| 79 | 79 | if [ $rc -eq $skip_rc ]; then \ |
| 80 | 80 | echo "not ok $test_num $TEST_HDR_MSG # SKIP" |
| 81 | 81 | elif [ $rc -eq $timeout_rc ]; then \ |
| 82 | + echo "#" | |
| 82 | 83 | echo "not ok $test_num $TEST_HDR_MSG # TIMEOUT" |
| 83 | 84 | else |
| 84 | 85 | echo "not ok $test_num $TEST_HDR_MSG # exit=$rc" |
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | # SPDX-License-Identifier: GPL-2.0 |
| 2 | 2 | # Makefile for mount selftests. |
| 3 | −CFLAGS = -Wall -lcap -O2 | |
| 3 | +CFLAGS = -Wall -O2 | |
| 4 | +LDLIBS = -lcap | |
| 4 | 5 | |
| 5 | −TEST_PROGS := run_tests.sh | |
| 6 | +TEST_PROGS := safesetid-test.sh | |
| 6 | 7 | TEST_GEN_FILES := safesetid-test |
| 7 | 8 | |
| 8 | 9 | include ../lib.mk |
| @@ -213,7 +213,8 @@ static void test_setuid(uid_t child_uid, bool expect_success) · 212 unmodified lines | ||
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | if (cpid == 0) { /* Code executed by child */ |
| 216 | − setuid(child_uid); | |
| 216 | + if (setuid(child_uid) < 0) | |
| 217 | + exit(EXIT_FAILURE); | |
| 217 | 218 | if (getuid() == child_uid) |
| 218 | 219 | exit(EXIT_SUCCESS); |
| 219 | 220 | else |
| @@ -291,8 +292,10 @@ int main(int argc, char **argv) · 71 unmodified lines | ||
| 291 | 292 | |
| 292 | 293 | // First test to make sure we can write userns mappings from a user |
| 293 | 294 | // that doesn't have any restrictions (as long as it has CAP_SETUID); |
| 294 | − setuid(NO_POLICY_USER); | |
| 295 | − setgid(NO_POLICY_USER); | |
| 295 | + if (setuid(NO_POLICY_USER) < 0) | |
| 296 | + die("Error with set uid(%d)\n", NO_POLICY_USER); | |
| 297 | + if (setgid(NO_POLICY_USER) < 0) | |
| 298 | + die("Error with set gid(%d)\n", NO_POLICY_USER); | |
| 296 | 299 | |
| 297 | 300 | // Take away all but setid caps |
| 298 | 301 | drop_caps(true); |
| @@ -306,8 +309,10 @@ int main(int argc, char **argv) · 7 unmodified lines | ||
| 306 | 309 | die("test_userns failed when it should work\n"); |
| 307 | 310 | } |
| 308 | 311 | |
| 309 | − setuid(RESTRICTED_PARENT); | |
| 310 | − setgid(RESTRICTED_PARENT); | |
| 312 | + if (setuid(RESTRICTED_PARENT) < 0) | |
| 313 | + die("Error with set uid(%d)\n", RESTRICTED_PARENT); | |
| 314 | + if (setgid(RESTRICTED_PARENT) < 0) | |
| 315 | + die("Error with set gid(%d)\n", RESTRICTED_PARENT); | |
| 311 | 316 | |
| 312 | 317 | test_setuid(ROOT_USER, false); |
| 313 | 318 | test_setuid(ALLOWED_CHILD1, true); |