summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/splice/short_splice_read.sh
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2020-08-06 23:01:09 -0700
committerKees Cook <keescook@chromium.org>2020-08-07 10:50:11 -0700
commit9af47666cb0f331bfcd76799ee368cdfcb00882c (patch)
tree9134feaef0f6076f5f1ebe484fb3791d60d1ff7b /tools/testing/selftests/splice/short_splice_read.sh
parent11990a5bd7e558e9203c1070fc52fb6f0488e75b (diff)
downloadlinux-9af47666cb0f331bfcd76799ee368cdfcb00882c.tar.bz2
selftests: splice: Check behavior of full and short splices
In order to help catch regressions in splice vs read behavior in certain special files, test a few with various different kinds of internal kernel helpers. Cc: Shuah Khan <shuah@kernel.org> Signed-off-by: Kees Cook <keescook@chromium.org>
Diffstat (limited to 'tools/testing/selftests/splice/short_splice_read.sh')
-rwxr-xr-xtools/testing/selftests/splice/short_splice_read.sh56
1 files changed, 56 insertions, 0 deletions
diff --git a/tools/testing/selftests/splice/short_splice_read.sh b/tools/testing/selftests/splice/short_splice_read.sh
new file mode 100755
index 000000000000..7810d3589d9a
--- /dev/null
+++ b/tools/testing/selftests/splice/short_splice_read.sh
@@ -0,0 +1,56 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+set -e
+
+ret=0
+
+do_splice()
+{
+ filename="$1"
+ bytes="$2"
+ expected="$3"
+
+ out=$(./splice_read "$filename" "$bytes" | cat)
+ if [ "$out" = "$expected" ] ; then
+ echo "ok: $filename $bytes"
+ else
+ echo "FAIL: $filename $bytes"
+ ret=1
+ fi
+}
+
+test_splice()
+{
+ filename="$1"
+
+ full=$(cat "$filename")
+ two=$(echo "$full" | grep -m1 . | cut -c-2)
+
+ # Make sure full splice has the same contents as a standard read.
+ do_splice "$filename" 4096 "$full"
+
+ # Make sure a partial splice see the first two characters.
+ do_splice "$filename" 2 "$two"
+}
+
+# proc_single_open(), seq_read()
+test_splice /proc/$$/limits
+# special open, seq_read()
+test_splice /proc/$$/comm
+
+# proc_handler, proc_dointvec_minmax
+test_splice /proc/sys/fs/nr_open
+# proc_handler, proc_dostring
+test_splice /proc/sys/kernel/modprobe
+# proc_handler, special read
+test_splice /proc/sys/kernel/version
+
+if ! [ -d /sys/module/test_module/sections ] ; then
+ modprobe test_module
+fi
+# kernfs, attr
+test_splice /sys/module/test_module/coresize
+# kernfs, binattr
+test_splice /sys/module/test_module/sections/.init.text
+
+exit $ret