~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/splice/short_splice_read.sh

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #!/bin/sh
  2 # SPDX-License-Identifier: GPL-2.0
  3 #
  4 # Test for mishandling of splice() on pseudofilesystems, which should catch
  5 # bugs like 11990a5bd7e5 ("module: Correctly truncate sysfs sections output")
  6 #
  7 # Since splice fallback was removed as part of the set_fs() rework, many of these
  8 # tests expect to fail now. See https://lore.kernel.org/lkml/202009181443.C2179FB@keescook/
  9 set -e
 10 
 11 DIR=$(dirname "$0")
 12 
 13 ret=0
 14 
 15 expect_success()
 16 {
 17         title="$1"
 18         shift
 19 
 20         echo "" >&2
 21         echo "$title ..." >&2
 22 
 23         set +e
 24         "$@"
 25         rc=$?
 26         set -e
 27 
 28         case "$rc" in
 29         0)
 30                 echo "ok: $title succeeded" >&2
 31                 ;;
 32         1)
 33                 echo "FAIL: $title should work" >&2
 34                 ret=$(( ret + 1 ))
 35                 ;;
 36         *)
 37                 echo "FAIL: something else went wrong" >&2
 38                 ret=$(( ret + 1 ))
 39                 ;;
 40         esac
 41 }
 42 
 43 expect_failure()
 44 {
 45         title="$1"
 46         shift
 47 
 48         echo "" >&2
 49         echo "$title ..." >&2
 50 
 51         set +e
 52         "$@"
 53         rc=$?
 54         set -e
 55 
 56         case "$rc" in
 57         0)
 58                 echo "FAIL: $title unexpectedly worked" >&2
 59                 ret=$(( ret + 1 ))
 60                 ;;
 61         1)
 62                 echo "ok: $title correctly failed" >&2
 63                 ;;
 64         *)
 65                 echo "FAIL: something else went wrong" >&2
 66                 ret=$(( ret + 1 ))
 67                 ;;
 68         esac
 69 }
 70 
 71 do_splice()
 72 {
 73         filename="$1"
 74         bytes="$2"
 75         expected="$3"
 76         report="$4"
 77 
 78         out=$("$DIR"/splice_read "$filename" "$bytes" | cat)
 79         if [ "$out" = "$expected" ] ; then
 80                 echo "      matched $report" >&2
 81                 return 0
 82         else
 83                 echo "      no match: '$out' vs $report" >&2
 84                 return 1
 85         fi
 86 }
 87 
 88 test_splice()
 89 {
 90         filename="$1"
 91 
 92         echo "  checking $filename ..." >&2
 93 
 94         full=$(cat "$filename")
 95         rc=$?
 96         if [ $rc -ne 0 ] ; then
 97                 return 2
 98         fi
 99 
100         two=$(echo "$full" | grep -m1 . | cut -c-2)
101 
102         # Make sure full splice has the same contents as a standard read.
103         echo "    splicing 4096 bytes ..." >&2
104         if ! do_splice "$filename" 4096 "$full" "full read" ; then
105                 return 1
106         fi
107 
108         # Make sure a partial splice see the first two characters.
109         echo "    splicing 2 bytes ..." >&2
110         if ! do_splice "$filename" 2 "$two" "'$two'" ; then
111                 return 1
112         fi
113 
114         return 0
115 }
116 
117 ### /proc/$pid/ has no splice interface; these should all fail.
118 expect_failure "proc_single_open(), seq_read() splice" test_splice /proc/$$/limits
119 expect_failure "special open(), seq_read() splice" test_splice /proc/$$/comm
120 
121 ### /proc/sys/ has a splice interface; these should all succeed.
122 expect_success "proc_handler: proc_dointvec_minmax() splice" test_splice /proc/sys/fs/nr_open
123 expect_success "proc_handler: proc_dostring() splice" test_splice /proc/sys/kernel/modprobe
124 expect_success "proc_handler: special read splice" test_splice /proc/sys/kernel/version
125 
126 ### /sys/ has no splice interface; these should all fail.
127 if ! [ -d /sys/module/test_module/sections ] ; then
128         expect_success "test_module kernel module load" modprobe test_module
129 fi
130 expect_success "kernfs attr splice" test_splice /sys/module/test_module/coresize
131 expect_success "kernfs binattr splice" test_splice /sys/module/test_module/sections/.init.text
132 
133 exit $ret

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php