summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/splice/short_splice_read.sh
blob: 7810d3589d9ab0ef5a491cca24d0f09c4177b369 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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