History

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

Linus Torvalds committed 6 years ago

Commit 6afa8732 parents 4c80ba3 4eac73419 files · +119 −40Browse files

Unified · Split

19 files
  1. Documentation/dev-tools/kselftest.rst +4 −4
  2. Documentation/dev-tools/kunit/index.rst +1 −0
  3. Documentation/dev-tools/kunit/kunit-tool.rst +57 −0
  4. Documentation/dev-tools/kunit/start.rst +8 −5
  5. Documentation/dev-tools/kunit/usage.rst +12 −12
  6. fs/ext4/inode-test.c +1 −1
  7. tools/testing/kunit/kunit_tool_test.py +1 −1
  8. tools/testing/selftests/ftrace/test.d/ftrace/func-filter-stacktrace.tc +2 −0
  9. tools/testing/selftests/ftrace/test.d/ftrace/func_cpumask.tc +5 −0
  10. tools/testing/selftests/ftrace/test.d/functions +4 −1
  11. tools/testing/selftests/ftrace/test.d/kprobe/multiple_kprobes.tc +3 −3
  12. tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-action-hist-xfail.tc +2 −2
  13. tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-onchange-action-hist.tc +1 −1
  14. tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-snapshot-action-hist.tc +2 −2
  15. tools/testing/selftests/kselftest/module.sh +1 −1
  16. tools/testing/selftests/kselftest/prefix.pl +1 −0
  17. tools/testing/selftests/kselftest/runner.sh +1 −0
  18. tools/testing/selftests/safesetid/Makefile +3 −2
  19. tools/testing/selftests/safesetid/safesetid-test.c +10 −5
Documentation/dev-tools/kselftest.rst+4−4
@@ -203,12 +203,12 @@ Test Module · 202 unmodified lines
203203 Kselftest tests the kernel from userspace. Sometimes things need
204204 testing from within the kernel, one method of doing this is to create a
205205 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
207207 to facilitate this process. There is also a header file provided to
208208 assist writing kernel modules that are for use with kselftest:
209209
210210 - ``tools/testing/kselftest/kselftest_module.h``
211−- ``tools/testing/kselftest/kselftest_module.sh``
211+- ``tools/testing/kselftest/kselftest/module.sh``
212212
213213 How to use
214214 ----------
@@ -247,7 +247,7 @@ A bare bones test module might look like this: · 32 unmodified lines
247247
248248 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
249249
250− #include "../tools/testing/selftests/kselftest_module.h"
250+ #include "../tools/testing/selftests/kselftest/module.h"
251251
252252 KSTM_MODULE_GLOBALS();
253253
@@ -276,7 +276,7 @@ Example test script · 22 unmodified lines
276276
277277 #!/bin/bash
278278 # SPDX-License-Identifier: GPL-2.0+
279− $(dirname $0)/../kselftest_module.sh "foo" test_foo
279+ $(dirname $0)/../kselftest/module.sh "foo" test_foo
280280
281281
282282 Test Harness
Documentation/dev-tools/kunit/index.rst+1−0
@@ -9,6 +9,7 @@ KUnit - Unit Testing for the Linux Kernel · 8 unmodified lines
99
1010 start
1111 usage
12+ kunit-tool
1213 api/index
1314 faq
1415
Documentation/dev-tools/kunit/kunit-tool.rst+57−0
@@ -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
Documentation/dev-tools/kunit/start.rst+8−5
@@ -19,11 +19,14 @@ The wrapper can be run with: · 18 unmodified lines
1919
2020 .. code-block:: bash
2121
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.
2326
2427 Creating a kunitconfig
2528 ======================
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
2730 configured with a ``kunitconfig`` file. This file essentially contains the
2831 regular Kernel config, with the specific test targets as well.
2932
@@ -59,8 +62,8 @@ If everything worked correctly, you should see the following: · 29 unmodified lines
5962 followed by a list of tests that are run. All of them should be passing.
6063
6164 .. 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.
6467
6568 Writing your first test
6669 =======================
@@ -159,7 +162,7 @@ Now you can run the test: · 92 unmodified lines
159162
160163 .. code-block:: bash
161164
162− ./tools/testing/kunit/kunit.py
165+ ./tools/testing/kunit/kunit.py run
163166
164167 You should see the following failure:
165168
Documentation/dev-tools/kunit/usage.rst+12−12
@@ -16,7 +16,7 @@ Organization of this document · 15 unmodified lines
1616 =============================
1717
1818 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
2020 them. The second covers how to use KUnit to isolate code and make it possible
2121 to unit test code that was otherwise un-unit-testable.
2222
@@ -174,13 +174,13 @@ Test Suites · 151 unmodified lines
174174 ~~~~~~~~~~~
175175
176176 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.
184184
185185 Example:
186186
@@ -211,7 +211,7 @@ KUnit test framework. · 24 unmodified lines
211211 .. note::
212212 A test case will only be run if it is associated with a test suite.
213213
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`.
215215
216216 Isolating Behavior
217217 ==================
@@ -338,7 +338,7 @@ We can easily test this code by *faking out* the underlying EEPROM: · 120 unmodified lines
338338 return count;
339339 }
340340
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)
342342 {
343343 struct fake_eeprom *this = container_of(parent, struct fake_eeprom, parent);
344344
@@ -454,7 +454,7 @@ KUnit on non-UML architectures · 109 unmodified lines
454454 By default KUnit uses UML as a way to provide dependencies for code under test.
455455 Under most circumstances KUnit's usage of UML should be treated as an
456456 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
458458 against real hardware is desirable. For these reasons KUnit supports running on
459459 other architectures.
460460
@@ -557,7 +557,7 @@ run your tests on your hardware setup just by compiling for your architecture. · 96 unmodified lines
557557 .. important::
558558 Always prefer tests that run on UML to tests that only run under a particular
559559 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
561561 hardware.
562562
563563 Nevertheless, there are still valid reasons to write an architecture or hardware
fs/ext4/inode-test.c+1−1
@@ -25,7 +25,7 @@ · 24 unmodified lines
2525 * For constructing the negative timestamp lower bound value.
2626 * binary: 10000000 00000000 00000000 00000000
2727 */
28−#define LOWER_MSB_1 (-0x80000000L)
28+#define LOWER_MSB_1 (-(UPPER_MSB_0) - 1L) /* avoid overflow */
2929 /*
3030 * For constructing the negative timestamp upper bound value.
3131 * binary: 11111111 11111111 11111111 11111111
tools/testing/kunit/kunit_tool_test.py+1−1
@@ -199,7 +199,7 @@ class KUnitMainTest(unittest.TestCase): · 198 unmodified lines
199199 timeout = 3453
200200 kunit.main(['run', '--timeout', str(timeout)], self.linux_source_mock)
201201 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)
203203 self.print_mock.assert_any_call(StrContains('Testing complete.'))
204204
205205 if __name__ == '__main__':
tools/testing/selftests/ftrace/test.d/ftrace/func-filter-stacktrace.tc+2−0
@@ -3,6 +3,8 @@ · 2 unmodified lines
33 # description: ftrace - stacktrace filter command
44 # flags: instance
55
6+[ ! -f set_ftrace_filter ] && exit_unsupported
7+
68 echo _do_fork:stacktrace >> set_ftrace_filter
79
810 grep -q "_do_fork:stacktrace:unlimited" set_ftrace_filter
tools/testing/selftests/ftrace/test.d/ftrace/func_cpumask.tc+5−0
@@ -15,6 +15,11 @@ if [ $NP -eq 1 ] ;then · 14 unmodified lines
1515 exit_unresolved
1616 fi
1717
18+if ! grep -q "function" available_tracers ; then
19+ echo "Function trace is not enabled"
20+ exit_unsupported
21+fi
22+
1823 ORIG_CPUMASK=`cat tracing_cpumask`
1924
2025 do_reset() {
tools/testing/selftests/ftrace/test.d/functions+4−1
@@ -46,6 +46,9 @@ reset_events_filter() { # reset all current setting filters · 45 unmodified lines
4646 }
4747
4848 reset_ftrace_filter() { # reset all triggers in set_ftrace_filter
49+ if [ ! -f set_ftrace_filter ]; then
50+ return 0
51+ fi
4952 echo > set_ftrace_filter
5053 grep -v '^#' set_ftrace_filter | while read t; do
5154 tr=`echo $t | cut -d: -f2`
@@ -93,7 +96,7 @@ initialize_ftrace() { # Reset ftrace to initial-state · 41 unmodified lines
9396 disable_events
9497 [ -f set_event_pid ] && echo > set_event_pid
9598 [ -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
97100 [ -f set_graph_function ] && echo | tee set_graph_*
98101 [ -f stack_trace_filter ] && echo > stack_trace_filter
99102 [ -f kprobe_events ] && echo > kprobe_events
tools/testing/selftests/ftrace/test.d/kprobe/multiple_kprobes.tc+3−3
@@ -20,9 +20,9 @@ while read i; do · 19 unmodified lines
2020 test $N -eq 256 && break
2121 done
2222
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"
2626 exit_fail
2727 fi
2828
tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-action-hist-xfail.tc+2−2
@@ -21,10 +21,10 @@ grep -q "snapshot()" README || exit_unsupported # version issue · 20 unmodified lines
2121
2222 echo "Test expected snapshot action failure"
2323
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
2525
2626 echo "Test expected save action failure"
2727
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
2929
3030 exit_xfail
tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-onchange-action-hist.tc+1−1
@@ -16,7 +16,7 @@ grep -q "onchange(var)" README || exit_unsupported # version issue · 15 unmodified lines
1616
1717 echo "Test onchange action"
1818
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
2020
2121 ping $LOCALHOST -c 3
2222 nice -n 1 ping $LOCALHOST -c 3
tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-snapshot-action-hist.tc+2−2
@@ -23,9 +23,9 @@ grep -q "snapshot()" README || exit_unsupported # version issue · 22 unmodified lines
2323
2424 echo "Test snapshot action"
2525
26−echo 1 > /sys/kernel/debug/tracing/events/sched/enable
26+echo 1 > events/sched/enable
2727
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
2929
3030 ping $LOCALHOST -c 3
3131 nice -n 1 ping $LOCALHOST -c 3
tools/testing/selftests/kselftest/module.sh+1−1
@@ -9,7 +9,7 @@ · 8 unmodified lines
99 #
1010 # #!/bin/sh
1111 # SPDX-License-Identifier: GPL-2.0+
12−# $(dirname $0)/../kselftest_module.sh "description" module_name
12+# $(dirname $0)/../kselftest/module.sh "description" module_name
1313 #
1414 # Example: tools/testing/selftests/lib/printf.sh
1515
tools/testing/selftests/kselftest/prefix.pl+1−0
@@ -3,6 +3,7 @@ · 2 unmodified lines
33 # Prefix all lines with "# ", unbuffered. Command being piped in may need
44 # to have unbuffering forced with "stdbuf -i0 -o0 -e0 $cmd".
55 use strict;
6+use IO::Handle;
67
78 binmode STDIN;
89 binmode STDOUT;
tools/testing/selftests/kselftest/runner.sh+1−0
@@ -79,6 +79,7 @@ run_one() · 78 unmodified lines
7979 if [ $rc -eq $skip_rc ]; then \
8080 echo "not ok $test_num $TEST_HDR_MSG # SKIP"
8181 elif [ $rc -eq $timeout_rc ]; then \
82+ echo "#"
8283 echo "not ok $test_num $TEST_HDR_MSG # TIMEOUT"
8384 else
8485 echo "not ok $test_num $TEST_HDR_MSG # exit=$rc"
tools/testing/selftests/safesetid/Makefile+3−2
@@ -1,8 +1,9 @@
11 # SPDX-License-Identifier: GPL-2.0
22 # Makefile for mount selftests.
3−CFLAGS = -Wall -lcap -O2
3+CFLAGS = -Wall -O2
4+LDLIBS = -lcap
45
5−TEST_PROGS := run_tests.sh
6+TEST_PROGS := safesetid-test.sh
67 TEST_GEN_FILES := safesetid-test
78
89 include ../lib.mk
tools/testing/selftests/safesetid/safesetid-test.c+10−5
@@ -213,7 +213,8 @@ static void test_setuid(uid_t child_uid, bool expect_success) · 212 unmodified lines
213213 }
214214
215215 if (cpid == 0) { /* Code executed by child */
216− setuid(child_uid);
216+ if (setuid(child_uid) < 0)
217+ exit(EXIT_FAILURE);
217218 if (getuid() == child_uid)
218219 exit(EXIT_SUCCESS);
219220 else
@@ -291,8 +292,10 @@ int main(int argc, char **argv) · 71 unmodified lines
291292
292293 // First test to make sure we can write userns mappings from a user
293294 // 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);
296299
297300 // Take away all but setid caps
298301 drop_caps(true);
@@ -306,8 +309,10 @@ int main(int argc, char **argv) · 7 unmodified lines
306309 die("test_userns failed when it should work\n");
307310 }
308311
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);
311316
312317 test_setuid(ROOT_USER, false);
313318 test_setuid(ALLOWED_CHILD1, true);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t