Skip to content

Commit fc2fb38

Browse files
committed
Merge tag 'linux-kselftest-5.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull kselftest updates from Shuah Khan: "This consists of: - Several fixes from Masami Hiramatsu to improve coverage for lib and sysctl tests. - Clean up to vdso test and a new test for getcpu() from Mark Brown. - Add new gen_tar selftests Makefile target generate selftest package running "make gen_tar" in selftests directory from Veronika Kabatova. - Other miscellaneous fixes to timens, exec, tpm2 tests" * tag 'linux-kselftest-5.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: selftests/sysctl: Make sysctl test driver as a module selftests/sysctl: Fix to load test_sysctl module lib: Make test_sysctl initialized as module lib: Make prime number generator independently selectable selftests/ftrace: Return unsupported if no error_log file selftests/ftrace: Use printf for backslash included command selftests/timens: handle a case when alarm clocks are not supported Kernel selftests: Add check if TPM devices are supported selftests: vdso: Add a selftest for vDSO getcpu() selftests: vdso: Use a header file to prototype parse_vdso API selftests: vdso: Rename vdso_test to vdso_test_gettimeofday selftests/exec: Verify execve of non-regular files fail selftests: introduce gen_tar Makefile target
2 parents a5ad574 + 382561a commit fc2fb38

27 files changed

+196
-57
lines changed

Documentation/dev-tools/kselftest.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,29 @@ note some tests will require root privileges::
151151
$ cd kselftest
152152
$ ./run_kselftest.sh
153153

154+
Packaging selftests
155+
===================
156+
157+
In some cases packaging is desired, such as when tests need to run on a
158+
different system. To package selftests, run::
159+
160+
$ make -C tools/testing/selftests gen_tar
161+
162+
This generates a tarball in the `INSTALL_PATH/kselftest-packages` directory. By
163+
default, `.gz` format is used. The tar format can be overridden by specifying
164+
a `FORMAT` make variable. Any value recognized by `tar's auto-compress`_ option
165+
is supported, such as::
166+
167+
$ make -C tools/testing/selftests gen_tar FORMAT=.xz
168+
169+
`make gen_tar` invokes `make install` so you can use it to package a subset of
170+
tests by using variables specified in `Running a subset of selftests`_
171+
section::
172+
173+
$ make -C tools/testing/selftests gen_tar TARGETS="bpf" FORMAT=.xz
174+
175+
.. _tar's auto-compress: https://www.gnu.org/software/tar/manual/html_node/gzip.html#auto_002dcompress
176+
154177
Contributing new tests
155178
======================
156179

lib/math/Kconfig

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ config CORDIC
66
calculations are in fixed point. Module will be called cordic.
77

88
config PRIME_NUMBERS
9-
tristate
9+
tristate "Simple prime number generator for testing"
10+
help
11+
This option provides a simple prime number generator for test
12+
modules.
13+
14+
If unsure, say N.
1015

1116
config RATIONAL
1217
bool

lib/test_sysctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ static int __init test_sysctl_init(void)
162162
}
163163
return 0;
164164
}
165-
late_initcall(test_sysctl_init);
165+
module_init(test_sysctl_init);
166166

167167
static void __exit test_sysctl_exit(void)
168168
{

tools/testing/selftests/Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,17 @@ else
249249
$(error Error: set INSTALL_PATH to use install)
250250
endif
251251

252+
FORMAT ?= .gz
253+
TAR_PATH = $(abspath ${INSTALL_PATH}/kselftest-packages/kselftest.tar${FORMAT})
254+
gen_tar: install
255+
@mkdir -p ${INSTALL_PATH}/kselftest-packages/
256+
@tar caf ${TAR_PATH} --exclude=kselftest-packages -C ${INSTALL_PATH} .
257+
@echo "Created ${TAR_PATH}"
258+
252259
clean:
253260
@for TARGET in $(TARGETS); do \
254261
BUILD_TARGET=$$BUILD/$$TARGET; \
255262
$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
256263
done;
257264

258-
.PHONY: khdr all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean
265+
.PHONY: khdr all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar

tools/testing/selftests/exec/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ execveat.ephemeral
99
execveat.denatured
1010
/recursion-depth
1111
xxxxxxxx*
12+
pipe

tools/testing/selftests/exec/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ CFLAGS += -D_GNU_SOURCE
55

66
TEST_PROGS := binfmt_script
77
TEST_GEN_PROGS := execveat
8-
TEST_GEN_FILES := execveat.symlink execveat.denatured script subdir
8+
TEST_GEN_FILES := execveat.symlink execveat.denatured script subdir pipe
99
# Makefile is a run-time dependency, since it's accessed by the execveat test
1010
TEST_FILES := Makefile
1111

tools/testing/selftests/exec/execveat.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
* Selftests for execveat(2).
66
*/
77

8+
#ifndef _GNU_SOURCE
89
#define _GNU_SOURCE /* to get O_PATH, AT_EMPTY_PATH */
10+
#endif
911
#include <sys/sendfile.h>
1012
#include <sys/stat.h>
1113
#include <sys/syscall.h>
@@ -311,6 +313,10 @@ static int run_tests(void)
311313
fail += check_execveat_fail(AT_FDCWD, fullname_symlink,
312314
AT_SYMLINK_NOFOLLOW, ELOOP);
313315

316+
/* Non-regular file failure */
317+
fail += check_execveat_fail(dot_dfd, "pipe", 0, EACCES);
318+
unlink("pipe");
319+
314320
/* Shell script wrapping executable file: */
315321
/* dfd + path */
316322
fail += check_execveat(subdir_dfd, "../script", 0);
@@ -384,6 +390,8 @@ static void prerequisites(void)
384390
fd = open("subdir.ephemeral/script", O_RDWR|O_CREAT|O_TRUNC, 0755);
385391
write(fd, script, strlen(script));
386392
close(fd);
393+
394+
mkfifo("pipe", 0755);
387395
}
388396

389397
int main(int argc, char **argv)

tools/testing/selftests/ftrace/test.d/ftrace/tracing-error-log.tc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ if [ ! -f set_event ]; then
1414
exit_unsupported
1515
fi
1616

17+
[ -f error_log ] || exit_unsupported
18+
1719
ftrace_errlog_check 'event filter parse error' '((sig >= 10 && sig < 15) || dsig ^== 17) && comm != bash' 'events/signal/signal_generate/filter'
1820

1921
exit 0

tools/testing/selftests/ftrace/test.d/functions

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,14 @@ yield() {
119119
ping $LOCALHOST -c 1 || sleep .001 || usleep 1 || sleep 1
120120
}
121121

122+
# Since probe event command may include backslash, explicitly use printf "%s"
123+
# to NOT interpret it.
122124
ftrace_errlog_check() { # err-prefix command-with-error-pos-by-^ command-file
123-
pos=$(echo -n "${2%^*}" | wc -c) # error position
124-
command=$(echo "$2" | tr -d ^)
125+
pos=$(printf "%s" "${2%^*}" | wc -c) # error position
126+
command=$(printf "%s" "$2" | tr -d ^)
125127
echo "Test command: $command"
126128
echo > error_log
127-
(! echo "$command" >> "$3" ) 2> /dev/null
129+
(! printf "%s" "$command" >> "$3" ) 2> /dev/null
128130
grep "$1: error:" -A 3 error_log
129131
N=$(tail -n 1 error_log | wc -c)
130132
# " Command: " and "^\n" => 13

tools/testing/selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ esac
9191
if grep -q "Create/append/" README && grep -q "imm-value" README; then
9292
echo 'p:kprobes/testevent _do_fork' > kprobe_events
9393
check_error '^r:kprobes/testevent do_exit' # DIFF_PROBE_TYPE
94-
echo 'p:kprobes/testevent _do_fork abcd=\1' > kprobe_events
94+
95+
# Explicitly use printf "%s" to not interpret \1
96+
printf "%s" 'p:kprobes/testevent _do_fork abcd=\1' > kprobe_events
9597
check_error 'p:kprobes/testevent _do_fork ^bcd=\1' # DIFF_ARG_TYPE
9698
check_error 'p:kprobes/testevent _do_fork ^abcd=\1:u8' # DIFF_ARG_TYPE
9799
check_error 'p:kprobes/testevent _do_fork ^abcd=\"foo"' # DIFF_ARG_TYPE

0 commit comments

Comments
 (0)