0001
0002
0003
0004
0005
0006
0007
0008
0009 set -e
0010
0011 DIR=$(dirname "$0")
0012
0013 ret=0
0014
0015 expect_success()
0016 {
0017 title="$1"
0018 shift
0019
0020 echo "" >&2
0021 echo "$title ..." >&2
0022
0023 set +e
0024 "$@"
0025 rc=$?
0026 set -e
0027
0028 case "$rc" in
0029 0)
0030 echo "ok: $title succeeded" >&2
0031 ;;
0032 1)
0033 echo "FAIL: $title should work" >&2
0034 ret=$(( ret + 1 ))
0035 ;;
0036 *)
0037 echo "FAIL: something else went wrong" >&2
0038 ret=$(( ret + 1 ))
0039 ;;
0040 esac
0041 }
0042
0043 expect_failure()
0044 {
0045 title="$1"
0046 shift
0047
0048 echo "" >&2
0049 echo "$title ..." >&2
0050
0051 set +e
0052 "$@"
0053 rc=$?
0054 set -e
0055
0056 case "$rc" in
0057 0)
0058 echo "FAIL: $title unexpectedly worked" >&2
0059 ret=$(( ret + 1 ))
0060 ;;
0061 1)
0062 echo "ok: $title correctly failed" >&2
0063 ;;
0064 *)
0065 echo "FAIL: something else went wrong" >&2
0066 ret=$(( ret + 1 ))
0067 ;;
0068 esac
0069 }
0070
0071 do_splice()
0072 {
0073 filename="$1"
0074 bytes="$2"
0075 expected="$3"
0076 report="$4"
0077
0078 out=$("$DIR"/splice_read "$filename" "$bytes" | cat)
0079 if [ "$out" = "$expected" ] ; then
0080 echo " matched $report" >&2
0081 return 0
0082 else
0083 echo " no match: '$out' vs $report" >&2
0084 return 1
0085 fi
0086 }
0087
0088 test_splice()
0089 {
0090 filename="$1"
0091
0092 echo " checking $filename ..." >&2
0093
0094 full=$(cat "$filename")
0095 rc=$?
0096 if [ $rc -ne 0 ] ; then
0097 return 2
0098 fi
0099
0100 two=$(echo "$full" | grep -m1 . | cut -c-2)
0101
0102
0103 echo " splicing 4096 bytes ..." >&2
0104 if ! do_splice "$filename" 4096 "$full" "full read" ; then
0105 return 1
0106 fi
0107
0108
0109 echo " splicing 2 bytes ..." >&2
0110 if ! do_splice "$filename" 2 "$two" "'$two'" ; then
0111 return 1
0112 fi
0113
0114 return 0
0115 }
0116
0117
0118 expect_failure "proc_single_open(), seq_read() splice" test_splice /proc/$$/limits
0119 expect_failure "special open(), seq_read() splice" test_splice /proc/$$/comm
0120
0121
0122 expect_success "proc_handler: proc_dointvec_minmax() splice" test_splice /proc/sys/fs/nr_open
0123 expect_success "proc_handler: proc_dostring() splice" test_splice /proc/sys/kernel/modprobe
0124 expect_success "proc_handler: special read splice" test_splice /proc/sys/kernel/version
0125
0126
0127 if ! [ -d /sys/module/test_module/sections ] ; then
0128 expect_success "test_module kernel module load" modprobe test_module
0129 fi
0130 expect_failure "kernfs attr splice" test_splice /sys/module/test_module/coresize
0131 expect_failure "kernfs binattr splice" test_splice /sys/module/test_module/sections/.init.text
0132
0133 exit $ret