History

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

Pull Kselftest fixes from Shuah Khan: - rseq build failures fixes related to glibc 2.30 compatibility from Mathieu Desnoyers - Kunit fixes and cleanups from SeongJae Park - Fixes to filesystems/epoll, firmware, and livepatch build failures and skip handling. * tag 'linux-kselftest-5.5-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: rseq/selftests: Clarify rseq_prepare_unload() helper requirements rseq/selftests: Fix: Namespace gettid() for compatibility with glibc 2.30 rseq/selftests: Turn off timeout setting kunit/kunit_tool_test: Test '--build_dir' option run kunit: Rename 'kunitconfig' to '.kunitconfig' kunit: Place 'test.log' under the 'build_dir' kunit: Create default config in '--build_dir' kunit: Remove duplicated defconfig creation docs/kunit/start: Use in-tree 'kunit_defconfig' selftests: livepatch: Fix it to do root uid check and skip selftests: firmware: Fix it to do root uid check and skip selftests: filesystems/epoll: fix build error

Linus Torvalds committed 6 years ago

Commit f4b39742 parents 1413c36 2a1f40a11 files · +70 −38Browse files

Unified · Split

11 files
  1. Documentation/dev-tools/kunit/start.rst +5 −8
  2. tools/testing/kunit/kunit.py +11 −7
  3. tools/testing/kunit/kunit_kernel.py +5 −5
  4. tools/testing/kunit/kunit_tool_test.py +9 −1
  5. tools/testing/selftests/filesystems/epoll/Makefile +1 −1
  6. tools/testing/selftests/firmware/fw_lib.sh +6 −0
  7. tools/testing/selftests/livepatch/functions.sh +14 −1
  8. tools/testing/selftests/livepatch/test-state.sh +1 −2
  9. tools/testing/selftests/rseq/param_test.c +10 −8
  10. tools/testing/selftests/rseq/rseq.h +7 −5
  11. tools/testing/selftests/rseq/settings +1 −0
Documentation/dev-tools/kunit/start.rst+5−8
@@ -24,19 +24,16 @@ The wrapper can be run with: · 23 unmodified lines
24For more information on this wrapper (also called kunit_tool) checkout the24For more information on this wrapper (also called kunit_tool) checkout the
25:doc:`kunit-tool` page.25:doc:`kunit-tool` page.
26 26
27Creating a kunitconfig27Creating a .kunitconfig
28======================28=======================
29The Python script is a thin wrapper around Kbuild. As such, it needs to be29The Python script is a thin wrapper around Kbuild. As such, it needs to be
30configured with a ``kunitconfig`` file. This file essentially contains the30configured with a ``.kunitconfig`` file. This file essentially contains the
31regular Kernel config, with the specific test targets as well.31regular Kernel config, with the specific test targets as well.
32 32
33.. code-block:: bash33.. code-block:: bash
34 34
35 git clone -b master https://kunit.googlesource.com/kunitconfig $PATH_TO_KUNITCONFIG_REPO
36 cd $PATH_TO_LINUX_REPO35 cd $PATH_TO_LINUX_REPO
37 ln -s $PATH_TO_KUNIT_CONFIG_REPO/kunitconfig kunitconfig36 cp arch/um/configs/kunit_defconfig .kunitconfig
38
39You may want to add kunitconfig to your local gitignore.
40 37
41Verifying KUnit Works38Verifying KUnit Works
42---------------------39---------------------
@@ -151,7 +148,7 @@ and the following to ``drivers/misc/Makefile``: · 108 unmodified lines
151 148
152 obj-$(CONFIG_MISC_EXAMPLE_TEST) += example-test.o149 obj-$(CONFIG_MISC_EXAMPLE_TEST) += example-test.o
153 150
154Now add it to your ``kunitconfig``:151Now add it to your ``.kunitconfig``:
155 152
156.. code-block:: none153.. code-block:: none
157 154
tools/testing/kunit/kunit.py+11−7
@@ -31,15 +31,12 @@ class KunitStatus(Enum): · 30 unmodified lines
31 TEST_FAILURE = auto()31 TEST_FAILURE = auto()
32 32
33def create_default_kunitconfig():33def create_default_kunitconfig():
34 if not os.path.exists(kunit_kernel.KUNITCONFIG_PATH):34 if not os.path.exists(kunit_kernel.kunitconfig_path):
35 shutil.copyfile('arch/um/configs/kunit_defconfig',35 shutil.copyfile('arch/um/configs/kunit_defconfig',
36 kunit_kernel.KUNITCONFIG_PATH)36 kunit_kernel.kunitconfig_path)
37 37
38def run_tests(linux: kunit_kernel.LinuxSourceTree,38def run_tests(linux: kunit_kernel.LinuxSourceTree,
39 request: KunitRequest) -> KunitResult:39 request: KunitRequest) -> KunitResult:
40 if request.defconfig:
41 create_default_kunitconfig()
42
43 config_start = time.time()40 config_start = time.time()
44 success = linux.build_reconfig(request.build_dir)41 success = linux.build_reconfig(request.build_dir)
45 config_end = time.time()42 config_end = time.time()
@@ -108,15 +105,22 @@ def main(argv, linux=None): · 62 unmodified lines
108 run_parser.add_argument('--build_dir',105 run_parser.add_argument('--build_dir',
109 help='As in the make command, it specifies the build '106 help='As in the make command, it specifies the build '
110 'directory.',107 'directory.',
111 type=str, default=None, metavar='build_dir')108 type=str, default='', metavar='build_dir')
112 109
113 run_parser.add_argument('--defconfig',110 run_parser.add_argument('--defconfig',
114 help='Uses a default kunitconfig.',111 help='Uses a default .kunitconfig.',
115 action='store_true')112 action='store_true')
116 113
117 cli_args = parser.parse_args(argv)114 cli_args = parser.parse_args(argv)
118 115
119 if cli_args.subcommand == 'run':116 if cli_args.subcommand == 'run':
117 if cli_args.build_dir:
118 if not os.path.exists(cli_args.build_dir):
119 os.mkdir(cli_args.build_dir)
120 kunit_kernel.kunitconfig_path = os.path.join(
121 cli_args.build_dir,
122 kunit_kernel.kunitconfig_path)
123
120 if cli_args.defconfig:124 if cli_args.defconfig:
121 create_default_kunitconfig()125 create_default_kunitconfig()
122 126
tools/testing/kunit/kunit_kernel.py+5−5
@@ -14,7 +14,7 @@ import os · 13 unmodified lines
14import kunit_config14import kunit_config
15 15
16KCONFIG_PATH = '.config'16KCONFIG_PATH = '.config'
17KUNITCONFIG_PATH = 'kunitconfig'17kunitconfig_path = '.kunitconfig'
18 18
19class ConfigError(Exception):19class ConfigError(Exception):
20 """Represents an error trying to configure the Linux kernel."""20 """Represents an error trying to configure the Linux kernel."""
@@ -82,7 +82,7 @@ class LinuxSourceTree(object): · 61 unmodified lines
82 82
83 def __init__(self):83 def __init__(self):
84 self._kconfig = kunit_config.Kconfig()84 self._kconfig = kunit_config.Kconfig()
85 self._kconfig.read_from_file(KUNITCONFIG_PATH)85 self._kconfig.read_from_file(kunitconfig_path)
86 self._ops = LinuxSourceTreeOperations()86 self._ops = LinuxSourceTreeOperations()
87 87
88 def clean(self):88 def clean(self):
@@ -111,7 +111,7 @@ class LinuxSourceTree(object): · 22 unmodified lines
111 return True111 return True
112 112
113 def build_reconfig(self, build_dir):113 def build_reconfig(self, build_dir):
114 """Creates a new .config if it is not a subset of the kunitconfig."""114 """Creates a new .config if it is not a subset of the .kunitconfig."""
115 kconfig_path = get_kconfig_path(build_dir)115 kconfig_path = get_kconfig_path(build_dir)
116 if os.path.exists(kconfig_path):116 if os.path.exists(kconfig_path):
117 existing_kconfig = kunit_config.Kconfig()117 existing_kconfig = kunit_config.Kconfig()
@@ -140,10 +140,10 @@ class LinuxSourceTree(object): · 22 unmodified lines
140 return False140 return False
141 return True141 return True
142 142
143 def run_kernel(self, args=[], timeout=None, build_dir=None):143 def run_kernel(self, args=[], timeout=None, build_dir=''):
144 args.extend(['mem=256M'])144 args.extend(['mem=256M'])
145 process = self._ops.linux_bin(args, timeout, build_dir)145 process = self._ops.linux_bin(args, timeout, build_dir)
146 with open('test.log', 'w') as f:146 with open(os.path.join(build_dir, 'test.log'), 'w') as f:
147 for line in process.stdout:147 for line in process.stdout:
148 f.write(line.rstrip().decode('ascii') + '\n')148 f.write(line.rstrip().decode('ascii') + '\n')
149 yield line.rstrip().decode('ascii')149 yield line.rstrip().decode('ascii')
tools/testing/kunit/kunit_tool_test.py+9−1
@@ -174,6 +174,7 @@ class KUnitMainTest(unittest.TestCase): · 173 unmodified lines
174 kunit.main(['run'], self.linux_source_mock)174 kunit.main(['run'], self.linux_source_mock)
175 assert self.linux_source_mock.build_reconfig.call_count == 1175 assert self.linux_source_mock.build_reconfig.call_count == 1
176 assert self.linux_source_mock.run_kernel.call_count == 1176 assert self.linux_source_mock.run_kernel.call_count == 1
177 self.linux_source_mock.run_kernel.assert_called_once_with(build_dir='', timeout=300)
177 self.print_mock.assert_any_call(StrContains('Testing complete.'))178 self.print_mock.assert_any_call(StrContains('Testing complete.'))
178 179
179 def test_run_passes_args_fail(self):180 def test_run_passes_args_fail(self):
@@ -199,7 +200,14 @@ class KUnitMainTest(unittest.TestCase): · 19 unmodified lines
199 timeout = 3453200 timeout = 3453
200 kunit.main(['run', '--timeout', str(timeout)], self.linux_source_mock)201 kunit.main(['run', '--timeout', str(timeout)], self.linux_source_mock)
201 assert self.linux_source_mock.build_reconfig.call_count == 1202 assert self.linux_source_mock.build_reconfig.call_count == 1
202 self.linux_source_mock.run_kernel.assert_called_once_with(build_dir=None, timeout=timeout)203 self.linux_source_mock.run_kernel.assert_called_once_with(build_dir='', timeout=timeout)
204 self.print_mock.assert_any_call(StrContains('Testing complete.'))
205
206 def test_run_builddir(self):
207 build_dir = '.kunit'
208 kunit.main(['run', '--build_dir', build_dir], self.linux_source_mock)
209 assert self.linux_source_mock.build_reconfig.call_count == 1
210 self.linux_source_mock.run_kernel.assert_called_once_with(build_dir=build_dir, timeout=300)
203 self.print_mock.assert_any_call(StrContains('Testing complete.'))211 self.print_mock.assert_any_call(StrContains('Testing complete.'))
204 212
205if __name__ == '__main__':213if __name__ == '__main__':
tools/testing/selftests/filesystems/epoll/Makefile+1−1
@@ -1,7 +1,7 @@
1# SPDX-License-Identifier: GPL-2.01# SPDX-License-Identifier: GPL-2.0
2 2
3CFLAGS += -I../../../../../usr/include/3CFLAGS += -I../../../../../usr/include/
4LDFLAGS += -lpthread4LDLIBS += -lpthread
5TEST_GEN_PROGS := epoll_wakeup_test5TEST_GEN_PROGS := epoll_wakeup_test
6 6
7include ../../lib.mk7include ../../lib.mk
tools/testing/selftests/firmware/fw_lib.sh+6−0
@@ -34,6 +34,12 @@ test_modprobe() · 33 unmodified lines
34 34
35check_mods()35check_mods()
36{36{
37 local uid=$(id -u)
38 if [ $uid -ne 0 ]; then
39 echo "skip all tests: must be run as root" >&2
40 exit $ksft_skip
41 fi
42
37 trap "test_modprobe" EXIT43 trap "test_modprobe" EXIT
38 if [ ! -d $DIR ]; then44 if [ ! -d $DIR ]; then
39 modprobe test_firmware45 modprobe test_firmware
tools/testing/selftests/livepatch/functions.sh+14−1
@@ -7,6 +7,9 @@ · 6 unmodified lines
7MAX_RETRIES=6007MAX_RETRIES=600
8RETRY_INTERVAL=".1" # seconds8RETRY_INTERVAL=".1" # seconds
9 9
10# Kselftest framework requirement - SKIP code is 4
11ksft_skip=4
12
10# log(msg) - write message to kernel log13# log(msg) - write message to kernel log
11# msg - insightful words14# msg - insightful words
12function log() {15function log() {
@@ -18,7 +21,16 @@ function log() { · 5 unmodified lines
18function skip() {21function skip() {
19 log "SKIP: $1"22 log "SKIP: $1"
20 echo "SKIP: $1" >&223 echo "SKIP: $1" >&2
21 exit 424 exit $ksft_skip
25}
26
27# root test
28function is_root() {
29 uid=$(id -u)
30 if [ $uid -ne 0 ]; then
31 echo "skip all tests: must be run as root" >&2
32 exit $ksft_skip
33 fi
22}34}
23 35
24# die(msg) - game over, man36# die(msg) - game over, man
@@ -62,6 +74,7 @@ function set_ftrace_enabled() { · 37 unmodified lines
62# for verbose livepatching output and turn on74# for verbose livepatching output and turn on
63# the ftrace_enabled sysctl.75# the ftrace_enabled sysctl.
64function setup_config() {76function setup_config() {
77 is_root
65 push_config78 push_config
66 set_dynamic_debug79 set_dynamic_debug
67 set_ftrace_enabled 180 set_ftrace_enabled 1
tools/testing/selftests/livepatch/test-state.sh+1−2
@@ -8,8 +8,7 @@ MOD_LIVEPATCH=test_klp_state · 7 unmodified lines
8MOD_LIVEPATCH2=test_klp_state28MOD_LIVEPATCH2=test_klp_state2
9MOD_LIVEPATCH3=test_klp_state39MOD_LIVEPATCH3=test_klp_state3
10 10
11set_dynamic_debug11setup_config
12
13 12
14# TEST: Loading and removing a module that modifies the system state13# TEST: Loading and removing a module that modifies the system state
15 14
tools/testing/selftests/rseq/param_test.c+10−8
@@ -15,7 +15,7 @@ · 14 unmodified lines
15#include <errno.h>15#include <errno.h>
16#include <stddef.h>16#include <stddef.h>
17 17
18static inline pid_t gettid(void)18static inline pid_t rseq_gettid(void)
19{19{
20 return syscall(__NR_gettid);20 return syscall(__NR_gettid);
21}21}
@@ -373,11 +373,12 @@ void *test_percpu_spinlock_thread(void *arg) · 351 unmodified lines
373 rseq_percpu_unlock(&data->lock, cpu);373 rseq_percpu_unlock(&data->lock, cpu);
374#ifndef BENCHMARK374#ifndef BENCHMARK
375 if (i != 0 && !(i % (reps / 10)))375 if (i != 0 && !(i % (reps / 10)))
376 printf_verbose("tid %d: count %lld\n", (int) gettid(), i);376 printf_verbose("tid %d: count %lld\n",
377 (int) rseq_gettid(), i);
377#endif378#endif
378 }379 }
379 printf_verbose("tid %d: number of rseq abort: %d, signals delivered: %u\n",380 printf_verbose("tid %d: number of rseq abort: %d, signals delivered: %u\n",
380 (int) gettid(), nr_abort, signals_delivered);381 (int) rseq_gettid(), nr_abort, signals_delivered);
381 if (!opt_disable_rseq && thread_data->reg &&382 if (!opt_disable_rseq && thread_data->reg &&
382 rseq_unregister_current_thread())383 rseq_unregister_current_thread())
383 abort();384 abort();
@@ -454,11 +455,12 @@ void *test_percpu_inc_thread(void *arg) · 70 unmodified lines
454 } while (rseq_unlikely(ret));455 } while (rseq_unlikely(ret));
455#ifndef BENCHMARK456#ifndef BENCHMARK
456 if (i != 0 && !(i % (reps / 10)))457 if (i != 0 && !(i % (reps / 10)))
457 printf_verbose("tid %d: count %lld\n", (int) gettid(), i);458 printf_verbose("tid %d: count %lld\n",
459 (int) rseq_gettid(), i);
458#endif460#endif
459 }461 }
460 printf_verbose("tid %d: number of rseq abort: %d, signals delivered: %u\n",462 printf_verbose("tid %d: number of rseq abort: %d, signals delivered: %u\n",
461 (int) gettid(), nr_abort, signals_delivered);463 (int) rseq_gettid(), nr_abort, signals_delivered);
462 if (!opt_disable_rseq && thread_data->reg &&464 if (!opt_disable_rseq && thread_data->reg &&
463 rseq_unregister_current_thread())465 rseq_unregister_current_thread())
464 abort();466 abort();
@@ -605,7 +607,7 @@ void *test_percpu_list_thread(void *arg) · 140 unmodified lines
605 }607 }
606 608
607 printf_verbose("tid %d: number of rseq abort: %d, signals delivered: %u\n",609 printf_verbose("tid %d: number of rseq abort: %d, signals delivered: %u\n",
608 (int) gettid(), nr_abort, signals_delivered);610 (int) rseq_gettid(), nr_abort, signals_delivered);
609 if (!opt_disable_rseq && rseq_unregister_current_thread())611 if (!opt_disable_rseq && rseq_unregister_current_thread())
610 abort();612 abort();
611 613
@@ -796,7 +798,7 @@ void *test_percpu_buffer_thread(void *arg) · 184 unmodified lines
796 }798 }
797 799
798 printf_verbose("tid %d: number of rseq abort: %d, signals delivered: %u\n",800 printf_verbose("tid %d: number of rseq abort: %d, signals delivered: %u\n",
799 (int) gettid(), nr_abort, signals_delivered);801 (int) rseq_gettid(), nr_abort, signals_delivered);
800 if (!opt_disable_rseq && rseq_unregister_current_thread())802 if (!opt_disable_rseq && rseq_unregister_current_thread())
801 abort();803 abort();
802 804
@@ -1011,7 +1013,7 @@ void *test_percpu_memcpy_buffer_thread(void *arg) · 208 unmodified lines
1011 }1013 }
1012 1014
1013 printf_verbose("tid %d: number of rseq abort: %d, signals delivered: %u\n",1015 printf_verbose("tid %d: number of rseq abort: %d, signals delivered: %u\n",
1014 (int) gettid(), nr_abort, signals_delivered);1016 (int) rseq_gettid(), nr_abort, signals_delivered);
1015 if (!opt_disable_rseq && rseq_unregister_current_thread())1017 if (!opt_disable_rseq && rseq_unregister_current_thread())
1016 abort();1018 abort();
1017 1019
tools/testing/selftests/rseq/rseq.h+7−5
@@ -149,11 +149,13 @@ static inline void rseq_clear_rseq_cs(void) · 148 unmodified lines
149/*149/*
150 * rseq_prepare_unload() should be invoked by each thread executing a rseq150 * rseq_prepare_unload() should be invoked by each thread executing a rseq
151 * critical section at least once between their last critical section and151 * critical section at least once between their last critical section and
152 * library unload of the library defining the rseq critical section152 * library unload of the library defining the rseq critical section (struct
153 * (struct rseq_cs). This also applies to use of rseq in code generated by153 * rseq_cs) or the code referred to by the struct rseq_cs start_ip and
154 * JIT: rseq_prepare_unload() should be invoked at least once by each154 * post_commit_offset fields. This also applies to use of rseq in code
155 * thread executing a rseq critical section before reclaim of the memory155 * generated by JIT: rseq_prepare_unload() should be invoked at least once by
156 * holding the struct rseq_cs.156 * each thread executing a rseq critical section before reclaim of the memory
157 * holding the struct rseq_cs or reclaim of the code pointed to by struct
158 * rseq_cs start_ip and post_commit_offset fields.
157 */159 */
158static inline void rseq_prepare_unload(void)160static inline void rseq_prepare_unload(void)
159{161{
tools/testing/selftests/rseq/settings+1−0
@@ -0,0 +1 @@
1timeout=0