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
2424 For more information on this wrapper (also called kunit_tool) checkout the
2525 :doc:`kunit-tool` page.
2626
27−Creating a kunitconfig
28−======================
27+Creating a .kunitconfig
28+=======================
2929 The Python script is a thin wrapper around Kbuild. As such, it needs to be
30−configured with a ``kunitconfig`` file. This file essentially contains the
30+configured with a ``.kunitconfig`` file. This file essentially contains the
3131 regular Kernel config, with the specific test targets as well.
3232
3333 .. code-block:: bash
3434
35− git clone -b master https://kunit.googlesource.com/kunitconfig $PATH_TO_KUNITCONFIG_REPO
3635 cd $PATH_TO_LINUX_REPO
37− ln -s $PATH_TO_KUNIT_CONFIG_REPO/kunitconfig kunitconfig
38−
39−You may want to add kunitconfig to your local gitignore.
36+ cp arch/um/configs/kunit_defconfig .kunitconfig
4037
4138 Verifying KUnit Works
4239 ---------------------
@@ -151,7 +148,7 @@ and the following to ``drivers/misc/Makefile``: · 108 unmodified lines
151148
152149 obj-$(CONFIG_MISC_EXAMPLE_TEST) += example-test.o
153150
154−Now add it to your ``kunitconfig``:
151+Now add it to your ``.kunitconfig``:
155152
156153 .. code-block:: none
157154
tools/testing/kunit/kunit.py+11−7
@@ -31,15 +31,12 @@ class KunitStatus(Enum): · 30 unmodified lines
3131 TEST_FAILURE = auto()
3232
3333 def create_default_kunitconfig():
34− if not os.path.exists(kunit_kernel.KUNITCONFIG_PATH):
34+ if not os.path.exists(kunit_kernel.kunitconfig_path):
3535 shutil.copyfile('arch/um/configs/kunit_defconfig',
36− kunit_kernel.KUNITCONFIG_PATH)
36+ kunit_kernel.kunitconfig_path)
3737
3838 def run_tests(linux: kunit_kernel.LinuxSourceTree,
3939 request: KunitRequest) -> KunitResult:
40− if request.defconfig:
41− create_default_kunitconfig()
42−
4340 config_start = time.time()
4441 success = linux.build_reconfig(request.build_dir)
4542 config_end = time.time()
@@ -108,15 +105,22 @@ def main(argv, linux=None): · 62 unmodified lines
108105 run_parser.add_argument('--build_dir',
109106 help='As in the make command, it specifies the build '
110107 'directory.',
111− type=str, default=None, metavar='build_dir')
108+ type=str, default='', metavar='build_dir')
112109
113110 run_parser.add_argument('--defconfig',
114− help='Uses a default kunitconfig.',
111+ help='Uses a default .kunitconfig.',
115112 action='store_true')
116113
117114 cli_args = parser.parse_args(argv)
118115
119116 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+
120124 if cli_args.defconfig:
121125 create_default_kunitconfig()
122126
tools/testing/kunit/kunit_kernel.py+5−5
@@ -14,7 +14,7 @@ import os · 13 unmodified lines
1414 import kunit_config
1515
1616 KCONFIG_PATH = '.config'
17−KUNITCONFIG_PATH = 'kunitconfig'
17+kunitconfig_path = '.kunitconfig'
1818
1919 class ConfigError(Exception):
2020 """Represents an error trying to configure the Linux kernel."""
@@ -82,7 +82,7 @@ class LinuxSourceTree(object): · 61 unmodified lines
8282
8383 def __init__(self):
8484 self._kconfig = kunit_config.Kconfig()
85− self._kconfig.read_from_file(KUNITCONFIG_PATH)
85+ self._kconfig.read_from_file(kunitconfig_path)
8686 self._ops = LinuxSourceTreeOperations()
8787
8888 def clean(self):
@@ -111,7 +111,7 @@ class LinuxSourceTree(object): · 22 unmodified lines
111111 return True
112112
113113 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."""
115115 kconfig_path = get_kconfig_path(build_dir)
116116 if os.path.exists(kconfig_path):
117117 existing_kconfig = kunit_config.Kconfig()
@@ -140,10 +140,10 @@ class LinuxSourceTree(object): · 22 unmodified lines
140140 return False
141141 return True
142142
143− def run_kernel(self, args=[], timeout=None, build_dir=None):
143+ def run_kernel(self, args=[], timeout=None, build_dir=''):
144144 args.extend(['mem=256M'])
145145 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:
147147 for line in process.stdout:
148148 f.write(line.rstrip().decode('ascii') + '\n')
149149 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
174174 kunit.main(['run'], self.linux_source_mock)
175175 assert self.linux_source_mock.build_reconfig.call_count == 1
176176 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)
177178 self.print_mock.assert_any_call(StrContains('Testing complete.'))
178179
179180 def test_run_passes_args_fail(self):
@@ -199,7 +200,14 @@ class KUnitMainTest(unittest.TestCase): · 19 unmodified lines
199200 timeout = 3453
200201 kunit.main(['run', '--timeout', str(timeout)], self.linux_source_mock)
201202 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)
203211 self.print_mock.assert_any_call(StrContains('Testing complete.'))
204212
205213 if __name__ == '__main__':
tools/testing/selftests/filesystems/epoll/Makefile+1−1
@@ -1,7 +1,7 @@
11 # SPDX-License-Identifier: GPL-2.0
22
33 CFLAGS += -I../../../../../usr/include/
4−LDFLAGS += -lpthread
4+LDLIBS += -lpthread
55 TEST_GEN_PROGS := epoll_wakeup_test
66
77 include ../../lib.mk
tools/testing/selftests/firmware/fw_lib.sh+6−0
@@ -34,6 +34,12 @@ test_modprobe() · 33 unmodified lines
3434
3535 check_mods()
3636 {
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+
3743 trap "test_modprobe" EXIT
3844 if [ ! -d $DIR ]; then
3945 modprobe test_firmware
tools/testing/selftests/livepatch/functions.sh+14−1
@@ -7,6 +7,9 @@ · 6 unmodified lines
77 MAX_RETRIES=600
88 RETRY_INTERVAL=".1" # seconds
99
10+# Kselftest framework requirement - SKIP code is 4
11+ksft_skip=4
12+
1013 # log(msg) - write message to kernel log
1114 # msg - insightful words
1215 function log() {
@@ -18,7 +21,16 @@ function log() { · 5 unmodified lines
1821 function skip() {
1922 log "SKIP: $1"
2023 echo "SKIP: $1" >&2
21− exit 4
24+ exit $ksft_skip
25+}
26+
27+# root test
28+function 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
2234 }
2335
2436 # die(msg) - game over, man
@@ -62,6 +74,7 @@ function set_ftrace_enabled() { · 37 unmodified lines
6274 # for verbose livepatching output and turn on
6375 # the ftrace_enabled sysctl.
6476 function setup_config() {
77+ is_root
6578 push_config
6679 set_dynamic_debug
6780 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
88 MOD_LIVEPATCH2=test_klp_state2
99 MOD_LIVEPATCH3=test_klp_state3
1010
11−set_dynamic_debug
12−
11+setup_config
1312
1413 # TEST: Loading and removing a module that modifies the system state
1514
tools/testing/selftests/rseq/param_test.c+10−8
@@ -15,7 +15,7 @@ · 14 unmodified lines
1515 #include <errno.h>
1616 #include <stddef.h>
1717
18−static inline pid_t gettid(void)
18+static inline pid_t rseq_gettid(void)
1919 {
2020 return syscall(__NR_gettid);
2121 }
@@ -373,11 +373,12 @@ void *test_percpu_spinlock_thread(void *arg) · 351 unmodified lines
373373 rseq_percpu_unlock(&data->lock, cpu);
374374 #ifndef BENCHMARK
375375 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);
377378 #endif
378379 }
379380 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);
381382 if (!opt_disable_rseq && thread_data->reg &&
382383 rseq_unregister_current_thread())
383384 abort();
@@ -454,11 +455,12 @@ void *test_percpu_inc_thread(void *arg) · 70 unmodified lines
454455 } while (rseq_unlikely(ret));
455456 #ifndef BENCHMARK
456457 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);
458460 #endif
459461 }
460462 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);
462464 if (!opt_disable_rseq && thread_data->reg &&
463465 rseq_unregister_current_thread())
464466 abort();
@@ -605,7 +607,7 @@ void *test_percpu_list_thread(void *arg) · 140 unmodified lines
605607 }
606608
607609 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);
609611 if (!opt_disable_rseq && rseq_unregister_current_thread())
610612 abort();
611613
@@ -796,7 +798,7 @@ void *test_percpu_buffer_thread(void *arg) · 184 unmodified lines
796798 }
797799
798800 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);
800802 if (!opt_disable_rseq && rseq_unregister_current_thread())
801803 abort();
802804
@@ -1011,7 +1013,7 @@ void *test_percpu_memcpy_buffer_thread(void *arg) · 208 unmodified lines
10111013 }
10121014
10131015 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);
10151017 if (!opt_disable_rseq && rseq_unregister_current_thread())
10161018 abort();
10171019
tools/testing/selftests/rseq/rseq.h+7−5
@@ -149,11 +149,13 @@ static inline void rseq_clear_rseq_cs(void) · 148 unmodified lines
149149 /*
150150 * rseq_prepare_unload() should be invoked by each thread executing a rseq
151151 * critical section at least once between their last critical section and
152− * library unload of the library defining the rseq critical section
153− * (struct rseq_cs). This also applies to use of rseq in code generated by
154− * JIT: rseq_prepare_unload() should be invoked at least once by each
155− * thread executing a rseq critical section before reclaim of the memory
156− * holding the struct rseq_cs.
152+ * library unload of the library defining the rseq critical section (struct
153+ * rseq_cs) or the code referred to by the struct rseq_cs start_ip and
154+ * post_commit_offset fields. This also applies to use of rseq in code
155+ * generated by JIT: rseq_prepare_unload() should be invoked at least once by
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.
157159 */
158160 static inline void rseq_prepare_unload(void)
159161 {
tools/testing/selftests/rseq/settings+1−0
@@ -0,0 +1 @@
1+timeout=0