Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'linux-kselftest-5.5-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest

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

+119 -40
+4 -4
Documentation/dev-tools/kselftest.rst
··· 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 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 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
+1
Documentation/dev-tools/kunit/index.rst
··· 9 9 10 10 start 11 11 usage 12 + kunit-tool 12 13 api/index 13 14 faq 14 15
+57
Documentation/dev-tools/kunit/kunit-tool.rst
··· 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
+8 -5
Documentation/dev-tools/kunit/start.rst
··· 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 ··· 62 59 followed by a list of tests that are run. All of them should be passing. 63 60 64 61 .. note:: 65 - Because it is building a lot of sources for the first time, the ``Building 66 - kunit kernel`` step may take a while. 62 + Because it is building a lot of sources for the first time, the 63 + ``Building KUnit kernel`` step may take a while. 67 64 68 65 Writing your first test 69 66 ======================= ··· 162 159 163 160 .. code-block:: bash 164 161 165 - ./tools/testing/kunit/kunit.py 162 + ./tools/testing/kunit/kunit.py run 166 163 167 164 You should see the following failure: 168 165
+12 -12
Documentation/dev-tools/kunit/usage.rst
··· 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 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 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 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 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 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
+1 -1
fs/ext4/inode-test.c
··· 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
+1 -1
tools/testing/kunit/kunit_tool_test.py
··· 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__':
+2
tools/testing/selftests/ftrace/test.d/ftrace/func-filter-stacktrace.tc
··· 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
+5
tools/testing/selftests/ftrace/test.d/ftrace/func_cpumask.tc
··· 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() {
+4 -1
tools/testing/selftests/ftrace/test.d/functions
··· 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` ··· 96 93 disable_events 97 94 [ -f set_event_pid ] && echo > set_event_pid 98 95 [ -f set_ftrace_pid ] && echo > set_ftrace_pid 99 - [ -f set_ftrace_filter ] && echo | tee set_ftrace_* 96 + [ -f set_ftrace_notrace ] && echo > set_ftrace_notrace 100 97 [ -f set_graph_function ] && echo | tee set_graph_* 101 98 [ -f stack_trace_filter ] && echo > stack_trace_filter 102 99 [ -f kprobe_events ] && echo > kprobe_events
+3 -3
tools/testing/selftests/ftrace/test.d/kprobe/multiple_kprobes.tc
··· 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
+2 -2
tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-action-hist-xfail.tc
··· 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
+1 -1
tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-onchange-action-hist.tc
··· 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
+2 -2
tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-snapshot-action-hist.tc
··· 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
+1 -1
tools/testing/selftests/kselftest/module.sh
··· 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
+1
tools/testing/selftests/kselftest/prefix.pl
··· 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;
+1
tools/testing/selftests/kselftest/runner.sh
··· 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"
+3 -2
tools/testing/selftests/safesetid/Makefile
··· 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
+10 -5
tools/testing/selftests/safesetid/safesetid-test.c
··· 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 ··· 292 291 293 292 // First test to make sure we can write userns mappings from a user 294 293 // that doesn't have any restrictions (as long as it has CAP_SETUID); 295 - setuid(NO_POLICY_USER); 296 - setgid(NO_POLICY_USER); 294 + if (setuid(NO_POLICY_USER) < 0) 295 + die("Error with set uid(%d)\n", NO_POLICY_USER); 296 + if (setgid(NO_POLICY_USER) < 0) 297 + die("Error with set gid(%d)\n", NO_POLICY_USER); 297 298 298 299 // Take away all but setid caps 299 300 drop_caps(true); ··· 309 306 die("test_userns failed when it should work\n"); 310 307 } 311 308 312 - setuid(RESTRICTED_PARENT); 313 - setgid(RESTRICTED_PARENT); 309 + if (setuid(RESTRICTED_PARENT) < 0) 310 + die("Error with set uid(%d)\n", RESTRICTED_PARENT); 311 + if (setgid(RESTRICTED_PARENT) < 0) 312 + die("Error with set gid(%d)\n", RESTRICTED_PARENT); 314 313 315 314 test_setuid(ROOT_USER, false); 316 315 test_setuid(ALLOWED_CHILD1, true);