brintos

brintos / linux-shallow public Read only

0
0
Text · 2.8 KiB · 4710e09 Raw
134 lines · bash
1#!/bin/sh2# SPDX-License-Identifier: GPL-2.03#4# Test for mishandling of splice() on pseudofilesystems, which should catch5# 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 these8# tests expect to fail now. See https://lore.kernel.org/lkml/202009181443.C2179FB@keescook/9set -e10 11DIR=$(dirname "$0")12 13ret=014 15expect_success()16{17	title="$1"18	shift19 20	echo "" >&221	echo "$title ..." >&222 23	set +e24	"$@"25	rc=$?26	set -e27 28	case "$rc" in29	0)30		echo "ok: $title succeeded" >&231		;;32	1)33		echo "FAIL: $title should work" >&234		ret=$(( ret + 1 ))35		;;36	*)37		echo "FAIL: something else went wrong" >&238		ret=$(( ret + 1 ))39		;;40	esac41}42 43expect_failure()44{45	title="$1"46	shift47 48	echo "" >&249	echo "$title ..." >&250 51	set +e52	"$@"53	rc=$?54	set -e55 56	case "$rc" in57	0)58		echo "FAIL: $title unexpectedly worked" >&259		ret=$(( ret + 1 ))60		;;61	1)62		echo "ok: $title correctly failed" >&263		;;64	*)65		echo "FAIL: something else went wrong" >&266		ret=$(( ret + 1 ))67		;;68	esac69}70 71do_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" ] ; then80		echo "      matched $report" >&281		return 082	else83		echo "      no match: '$out' vs $report" >&284		return 185	fi86}87 88test_splice()89{90	filename="$1"91 92	echo "  checking $filename ..." >&293 94	full=$(cat "$filename")95	rc=$?96	if [ $rc -ne 0 ] ; then97		return 298	fi99 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 ..." >&2104	if ! do_splice "$filename" 4096 "$full" "full read" ; then105		return 1106	fi107 108	# Make sure a partial splice see the first two characters.109	echo "    splicing 2 bytes ..." >&2110	if ! do_splice "$filename" 2 "$two" "'$two'" ; then111		return 1112	fi113 114	return 0115}116 117### /proc/$pid/ has no splice interface; these should all fail.118expect_failure "proc_single_open(), seq_read() splice" test_splice /proc/$$/limits119expect_failure "special open(), seq_read() splice" test_splice /proc/$$/comm120 121### /proc/sys/ has a splice interface; these should all succeed.122expect_success "proc_handler: proc_dointvec_minmax() splice" test_splice /proc/sys/fs/nr_open123expect_success "proc_handler: proc_dostring() splice" test_splice /proc/sys/kernel/modprobe124expect_success "proc_handler: special read splice" test_splice /proc/sys/kernel/version125 126### /sys/ has no splice interface; these should all fail.127if ! [ -d /sys/module/test_module/sections ] ; then128	expect_success "test_module kernel module load" modprobe test_module129fi130expect_success "kernfs attr splice" test_splice /sys/module/test_module/coresize131expect_success "kernfs binattr splice" test_splice /sys/module/test_module/sections/.init.text132 133exit $ret134