Skip to content

Commit 6afa873

Browse files
committed
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
2 parents 4c80ba3 + 4eac734 commit 6afa873

File tree

19 files changed

+119
-40
lines changed

19 files changed

+119
-40
lines changed

Documentation/dev-tools/kselftest.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,12 @@ Test Module
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:
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
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ KUnit - Unit Testing for the Linux Kernel
99

1010
start
1111
usage
12+
kunit-tool
1213
api/index
1314
faq
1415

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ The wrapper can be run with:
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:
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:
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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Organization of this document
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
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.
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:
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
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.
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def test_run_timeout(self):
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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ if [ $NP -eq 1 ] ;then
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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ reset_events_filter() { # reset all current setting filters
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
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

0 commit comments

Comments
 (0)