[PATCH v9 10/15] tests: check new syntax of inject/fault actions

Nikolay Marchuk marchuk.nikolay.a at gmail.com
Thu Aug 24 11:19:48 UTC 2017


* tests/qual_fault-exit_group.test: Add checks with new syntax.
* tests/qual_fault.test: Likewise.
* tests/qual_inject-error-signal.test: Likewise.
* tests/qual_inject-retval.test: Likewise.
* tests/qual_inject-signal.test: Likewise.
* tests/tampering-syntax.sh: New file.
* tests/qual_fault-syntax.test: Move common syntax checks to tampering-syntax.sh.
Add checks with new syntax.
* tests/qual_inject-syntax.test: Likewise.
* tests/Makefile.am (EXTRA_DIST): Add tampering-syntax.sh.
---
 tests/Makefile.am                   |   1 +
 tests/qual_fault-exit_group.test    |  11 ++++
 tests/qual_fault-syntax.test        |  92 ++++++++++++------------------
 tests/qual_fault.test               |  49 +++++++++++++---
 tests/qual_inject-error-signal.test |   5 ++
 tests/qual_inject-retval.test       |   5 ++
 tests/qual_inject-signal.test       |   5 ++
 tests/qual_inject-syntax.test       | 109 ++++++++++++++----------------------
 tests/tampering-syntax.sh           |  64 +++++++++++++++++++++
 9 files changed, 210 insertions(+), 131 deletions(-)
 create mode 100644 tests/tampering-syntax.sh

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3d822541..aa1a4b8f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -364,6 +364,7 @@ EXTRA_DIST = \
 	struct_flock.c \
 	sun_path.expected \
 	syntax.sh \
+	tampering-syntax.sh \
 	trace_fstat.in \
 	trace_fstatfs.in \
 	trace_lstat.in \
diff --git a/tests/qual_fault-exit_group.test b/tests/qual_fault-exit_group.test
index 34a2da58..974109e8 100755
--- a/tests/qual_fault-exit_group.test
+++ b/tests/qual_fault-exit_group.test
@@ -43,12 +43,23 @@ test_with()
 }
 
 test_with -eexit,exit_group -efault=exit_group:error=ENOSYS ../answer
+test_with -e "trace(syscall exit,exit_group)" \
+	  -e "fault(syscall exit_group;error=ENOSYS)" ../answer
 
 test_with -eexit,exit_group -efault=exit_group:error=ENOSYS \
 	  -efault=\!process:error=1 ../answer
+test_with -e "trace(syscall exit,exit_group)" \
+	  -e "fault(syscall exit_group;error=ENOSYS)" \
+	  -e "fault(!syscall %process;error=1)" ../answer
 
 test_with -eexit,exit_group -efault=all:error=ENOSYS \
 	  -efault=exit:error=1:when=2+ ../answer
+test_with -e "trace(syscall exit,exit_group)" \
+	  -e "fault(syscall all;error=ENOSYS)" \
+	  -e "fault(syscall exit;error=1;when=2+)" ../answer
 
 test_with -eexit,exit_group -efault=exit_group:error=ENOSYS \
 	  -efault=\!%desc,%file,%memory,%process,%signal,%network,%ipc:error=1 ../answer
+test_with -e "trace(syscall exit,exit_group)" \
+	  -e "fault(syscall exit_group;error=ENOSYS)" \
+	  -e "fault(!syscall %desc,%file,%memory,%process,%signal,%network,%ipc;error=1)" ../answer
diff --git a/tests/qual_fault-syntax.test b/tests/qual_fault-syntax.test
index 7198afff..a40a22f0 100755
--- a/tests/qual_fault-syntax.test
+++ b/tests/qual_fault-syntax.test
@@ -3,6 +3,7 @@
 # Check -e fault= syntax.
 #
 # Copyright (c) 2016-2017 Dmitry V. Levin <ldv at altlinux.org>
+# Copyright (c) 2017 The strace developers.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -27,70 +28,49 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-. "${srcdir=.}/syntax.sh"
+. "${srcdir=.}/tampering-syntax.sh"
 
 #
 # F
 # F+
 # F+S
 
-fail_with()
-{
-	dump_log_and_fail_with \
-		"strace -e fault=$* failed to handle an argument error properly"
-}
+counter=7
+for arg in 42 \
+	   invalid \
+	   error= \
+	   error=invalid_error_name \
+	   error=-1 \
+	   error=-2 \
+	   error=3+ \
+	   error=4096 \
+	   ; do
+	check_tampering_syntax fault chdir "$arg"
+	check_tampering_syntax fault chdir "$arg" "when=$counter"
+	counter=$((counter + 1))
+done
 
-for arg in chdir:42 \!chdir:42 \
-	   chdir:42:when=7 \
-	   chdir:invalid \
-	   chdir:invalid:when=8 \
-	   chdir:error= \
-	   chdir:error=:when=10 \
-	   chdir:error=invalid_error_name \
-	   chdir:error=invalid_error_name:when=11 \
-	   chdir:error=-1 \
-	   chdir:error=-1:when=12 \
-	   chdir:error=-2 \
-	   chdir:error=-2:when=13 \
-	   chdir:error=3+ \
-	   chdir:error=3+:when=14 \
-	   chdir:error=4096 \
-	   chdir:error=4096:when=15 \
-	   chdir:when=7:error=invalid_error_name \
-	   chdir:when= \
-	   chdir:when=:error=19 \
-	   chdir:when=0 \
-	   chdir:when=0:error=20 \
-	   chdir:when=-1 \
-	   chdir:when=-1:error=21 \
-	   chdir:when=-2+ \
-	   chdir:when=-2+:error=22 \
-	   chdir:when=-3+0 \
-	   chdir:when=-3+0:error=23 \
-	   chdir:when=4- \
-	   chdir:when=4-:error=24 \
-	   chdir:when=5+- \
-	   chdir:when=5+-:error=25 \
-	   chdir:when=6++ \
-	   chdir:when=6++:error=26 \
-	   chdir:when=7+0 \
-	   chdir:when=7+0:error=27 \
-	   chdir:when=8+-1 \
-	   chdir:when=8+-1:error=28 \
-	   chdir:when=9+1+ \
-	   chdir:when=9+1+:error=29 \
-	   chdir:when=65536 \
-	   chdir:when=65536:error=30 \
-	   chdir:when=1+65536 \
-	   chdir:when=1+65536:error=31 \
-	   chdir:retval=0 \
-	   chdir:signal=1 \
-	   chdir:error=1:error=2 \
+for arg in when= \
+	   when=0 \
+	   when=-1 \
+	   when=-2+ \
+	   when=-3+0 \
+	   when=4- \
+	   when=5+- \
+	   when=6++ \
+	   when=7+0 \
+	   when=8+-1 \
+	   when=9+1+ \
+	   when=65536 \
+	   when=1+65536 \
 	   ; do
-	$STRACE -e fault="$arg" true 2> "$LOG" &&
-		fail_with "$arg"
-	LC_ALL=C grep -F 'invalid fault argument' < "$LOG" > /dev/null ||
-		fail_with "$arg"
+	check_tampering_syntax fault chdir "$arg"
+	check_tampering_syntax fault chdir "$arg" "error=$counter"
+	counter=$((counter + 1))
 done
 
+check_tampering_syntax fault chdir "retval=0"
+check_tampering_syntax fault chdir "signal=1"
+check_tampering_syntax fault chdir "error=1" "error=2"
+
 exit 0
diff --git a/tests/qual_fault.test b/tests/qual_fault.test
index 12b0a850..e2fbd4df 100755
--- a/tests/qual_fault.test
+++ b/tests/qual_fault.test
@@ -48,29 +48,46 @@ check_fault_injection()
 	procs=$1; shift
 	extra="$*"
 
-	local when=
+	local when_qualify=
+	local when_new=
 	if [ -z "$first$step" ]; then
 		first=1
 		step=1
 	else
 		case "$step" in
-			'') when=":when=$first"; step=0 ;;
-			+) when=":when=$first+"; step=1 ;;
-			*) when=":when=$first+$step" ;;
+			'')
+			when_qualify=":when=$first"
+			when_new=";when=$first"
+			step=0
+			;;
+			+)
+			when_qualify=":when=$first+"
+			when_new=";when=$first+"
+			step=1
+			;;
+			*)
+			when_qualify=":when=$first+$step"
+			when_new=";when=$first+$step"
+			;;
 		esac
 	fi
 
-	local error=
+	local error_qualify=
+	local error_new=
 	local raw=reg
 	set --
 	case "$err" in
 		'') ;;
 		[123456789]*)
-			error=":error=$err"
+			error_qualify=":error=$err"
+			error_new=";error=$err"
 			raw=raw
 			set -- -e raw=all
 			;;
-		*) error=":error=$err" ;;
+		*)
+		error_qualify=":error=$err"
+		error_new=";error=$err"
+		;;
 	esac
 
 	outexp="$NAME.out.exp"
@@ -79,7 +96,21 @@ check_fault_injection()
 	outpid="$NAME.pid"
 
 	run_strace -a11 -ff -e trace=$trace \
-		"$@" -e fault=$fault$when$error $extra \
+		"$@" -e fault=$fault$when_qualify$error_qualify $extra \
+		../$NAME $raw "$err" "$first" "$step" $N \
+		"$procs" "$outexp" "$outgot" "$outout" "$outpid"
+
+	for i in $(seq 0 $((procs - 1)) )
+	do
+		pid=$(cat "$outpid.$i")
+
+		match_diff "$outout.$i" "$LOG.$pid"
+		match_diff "$outexp.$i" "$outgot.$i"
+	done
+
+	# New syntax
+	run_strace -a11 -ff -e "trace(syscall $trace)" \
+		"$@" -e "fault(syscall $fault$when_new$error_new)" $extra \
 		../$NAME $raw "$err" "$first" "$step" $N \
 		"$procs" "$outexp" "$outgot" "$outout" "$outpid"
 
@@ -93,7 +124,7 @@ check_fault_injection()
 }
 
 for err in '' ENOSYS 22 einval; do
-	for fault in writev desc,51; do
+	for fault in writev %desc,51; do
 		check_fault_injection \
 			writev $fault "$err" '' '' 1 -efault=chdir
 		check_fault_injection \
diff --git a/tests/qual_inject-error-signal.test b/tests/qual_inject-error-signal.test
index 1fe46126..ddbbef8b 100755
--- a/tests/qual_inject-error-signal.test
+++ b/tests/qual_inject-error-signal.test
@@ -6,3 +6,8 @@
 run_strace -a12 -echdir,exit_group -einject=chdir:error=ENOENT:signal=USR1 \
 	"../$NAME"
 match_diff
+
+run_strace -a12 -e "syscall chdir,exit_group" \
+	   -e "inject(syscall chdir;error=ENOENT;signal=USR1)" \
+	"../$NAME"
+match_diff
diff --git a/tests/qual_inject-retval.test b/tests/qual_inject-retval.test
index 5a4efd11..d71106fc 100755
--- a/tests/qual_inject-retval.test
+++ b/tests/qual_inject-retval.test
@@ -14,6 +14,11 @@ check_injection()
 	run_strace -a12 -e$syscall -einject="$syscall:retval=$rval" "$@" \
 		../qual_inject-retval "$rval" > "$EXP"
 	match_diff "$LOG" "$EXP"
+
+	run_strace -a12 -e "syscall $syscall" \
+		   -e "inject(syscall $syscall;retval=$rval)" "$@" \
+		../qual_inject-retval "$rval" > "$EXP"
+	match_diff "$LOG" "$EXP"
 }
 
 check_injection 0
diff --git a/tests/qual_inject-signal.test b/tests/qual_inject-signal.test
index f17e5a01..6cf6c7e5 100755
--- a/tests/qual_inject-signal.test
+++ b/tests/qual_inject-signal.test
@@ -6,3 +6,8 @@
 run_strace -a12 -echdir,exit_group -einject=chdir:signal=USR1 \
 	../$NAME
 match_diff
+
+run_strace -a12 -e "syscall chdir,exit_group" \
+	   -e "inject(syscall chdir;signal=USR1)" \
+	../$NAME
+match_diff
diff --git a/tests/qual_inject-syntax.test b/tests/qual_inject-syntax.test
index 17c18fde..bac8eb40 100755
--- a/tests/qual_inject-syntax.test
+++ b/tests/qual_inject-syntax.test
@@ -3,6 +3,7 @@
 # Check -e inject= syntax.
 #
 # Copyright (c) 2016-2017 Dmitry V. Levin <ldv at altlinux.org>
+# Copyright (c) 2017 The strace developers.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -27,76 +28,52 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-. "${srcdir=.}/syntax.sh"
+. "${srcdir=.}/tampering-syntax.sh"
 
-#
-# F
-# F+
-# F+S
+check_tampering_syntax inject 42
+check_tampering_syntax inject chdir
 
-fail_with()
-{
-	dump_log_and_fail_with \
-		"strace -e inject=$* failed to handle an argument error properly"
-}
+counter=7
+for arg in 42 \
+	   invalid \
+	   error= \
+	   error=invalid_error_name \
+	   error=-1 \
+	   error=-2 \
+	   error=3+ \
+	   error=4096 \
+	   ; do
+	check_tampering_syntax inject chdir "$arg"
+	check_tampering_syntax inject chdir "$arg" "when=$counter"
+	counter=$((counter + 1))
+done
 
-for arg in 42 chdir \
-	   chdir:42 \!chdir:42 \
-	   chdir:42:when=7 \
-	   chdir:invalid \
-	   chdir:invalid:when=8 \
-	   chdir:error= \
-	   chdir:error=:when=10 \
-	   chdir:error=invalid_error_name \
-	   chdir:error=invalid_error_name:when=11 \
-	   chdir:error=-1 \
-	   chdir:error=-1:when=12 \
-	   chdir:error=-2 \
-	   chdir:error=-2:when=13 \
-	   chdir:error=3+ \
-	   chdir:error=3+:when=14 \
-	   chdir:error=4096 \
-	   chdir:error=4096:when=15 \
-	   chdir:when=7:error=invalid_error_name \
-	   chdir:when= \
-	   chdir:when=:error=19 \
-	   chdir:when=0 \
-	   chdir:when=0:error=20 \
-	   chdir:when=-1 \
-	   chdir:when=-1:error=21 \
-	   chdir:when=-2+ \
-	   chdir:when=-2+:error=22 \
-	   chdir:when=-3+0 \
-	   chdir:when=-3+0:error=23 \
-	   chdir:when=4- \
-	   chdir:when=4-:error=24 \
-	   chdir:when=5+- \
-	   chdir:when=5+-:error=25 \
-	   chdir:when=6++ \
-	   chdir:when=6++:error=26 \
-	   chdir:when=7+0 \
-	   chdir:when=7+0:error=27 \
-	   chdir:when=8+-1 \
-	   chdir:when=8+-1:error=28 \
-	   chdir:when=9+1+ \
-	   chdir:when=9+1+:error=29 \
-	   chdir:when=65536 \
-	   chdir:when=65536:error=30 \
-	   chdir:when=1+65536 \
-	   chdir:when=1+65536:error=31 \
-	   chdir:retval=-1 \
-	   chdir:signal=0 \
-	   chdir:signal=129 \
-	   chdir:retval=0:retval=1 \
-	   chdir:error=1:error=2 \
-	   chdir:retval=0:error=1 \
-	   chdir:error=1:retval=0 \
-	   chdir:retval=0:signal=1:error=1 \
+for arg in when= \
+	   when=0 \
+	   when=-1 \
+	   when=-2+ \
+	   when=-3+0 \
+	   when=4- \
+	   when=5+- \
+	   when=6++ \
+	   when=7+0 \
+	   when=8+-1 \
+	   when=9+1+ \
+	   when=65536 \
+	   when=1+65536 \
 	   ; do
-	$STRACE -e inject="$arg" true 2> "$LOG" &&
-		fail_with "$arg"
-	LC_ALL=C grep -F 'invalid inject argument' < "$LOG" > /dev/null ||
-		fail_with "$arg"
+	check_tampering_syntax inject chdir "$arg"
+	check_tampering_syntax inject chdir "$arg" "error=$counter"
+	counter=$((counter + 1))
 done
 
+check_tampering_syntax inject chdir "retval=-1"
+check_tampering_syntax inject chdir "signal=0"
+check_tampering_syntax inject chdir "signal=129"
+check_tampering_syntax inject chdir "retval=0" "retval=1"
+check_tampering_syntax inject chdir "error=1" "error=2"
+check_tampering_syntax inject chdir "retval=0" "error=1"
+check_tampering_syntax inject chdir "error=1" "retval=0"
+check_tampering_syntax inject chdir "retval=0" "signal=1" "error=1"
+
 exit 0
diff --git a/tests/tampering-syntax.sh b/tests/tampering-syntax.sh
new file mode 100644
index 00000000..6b7ed261
--- /dev/null
+++ b/tests/tampering-syntax.sh
@@ -0,0 +1,64 @@
+#!/bin/sh
+#
+# Define inject/fault syntax testing primitives.
+#
+# Copyright (c) 2016 Dmitry V. Levin <ldv at altlinux.org>
+# Copyright (c) 2016-2017 The strace developers.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+# 3. The name of the author may not be used to endorse or promote products
+#    derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+. "${srcdir=.}/syntax.sh"
+
+check_tampering_syntax()
+{
+	local action syscall argument_qualify argument_new
+	action=$1; shift
+	syscall=$1; shift
+
+	if [ -n "$1" ]; then
+		argument_qualify="$1"
+		argument_new="$1"
+		shift
+	else
+		check_e "invalid $action argument ''" \
+			-e "$action=$syscall" true
+		check_e "invalid $action argument ''" \
+			-e "$action(syscall $syscall)" true
+		return
+	fi
+
+	for arg in "$@"
+	do
+		[ -z "$arg" ] && break
+		argument_qualify="$argument_qualify:$arg"
+		argument_new="$argument_new;$arg"
+		shift
+	done
+	check_e "invalid $action argument '$argument_qualify'" \
+		-e "$action=$syscall:$argument_qualify" \
+		true
+	check_e "invalid $action argument '$argument_new'" \
+		-e "$action(syscall $syscall;$argument_new)" \
+		true
+}
-- 
2.11.0





More information about the Strace-devel mailing list