tests: check new syntax of inject/fault actions

* 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.
This commit is contained in:
Nikolay Marchuk
2017-08-21 17:59:36 +07:00
committed by Dmitry V. Levin
parent fe9e13c311
commit 98e1b86c8c
9 changed files with 222 additions and 143 deletions

View File

@ -423,6 +423,7 @@ EXTRA_DIST = \
strace.supp \
sun_path.expected \
syntax.sh \
tampering-syntax.sh \
trace_fstat.in \
trace_fstatfs.in \
trace_lstat.in \

View File

@ -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

View File

@ -3,6 +3,7 @@
# Check -e fault= syntax.
#
# Copyright (c) 2016-2018 Dmitry V. Levin <ldv@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=.}/init.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"
}
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 \
counter=7
for arg in 42 \
invalid \
error= \
error=invalid_error_name \
error=-1 \
error=-2 \
error=3+ \
error=4096 \
; 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" "when=$counter"
counter=$((counter + 1))
done
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
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

View File

@ -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 \

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -3,6 +3,7 @@
# Check -e inject= syntax.
#
# Copyright (c) 2016-2018 Dmitry V. Levin <ldv@altlinux.org>
# Copyright (c) 2017 The strace developers.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@ -27,86 +28,62 @@
# (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=.}/init.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"
}
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=a \
chdir:retval=0b \
chdir:retval=0x10000000000000000 \
chdir:signal=0 \
chdir:signal=129 \
chdir:signal=1:signal=2 \
chdir:signal=1:retval=0:signal=2 \
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 \
chdir:delay_enter=-1 \
chdir:delay_exit=-2 \
chdir:delay_enter=1:delay_enter=2 \
chdir:delay_exit=3:delay_exit=4 \
chdir:delay_enter=5:delay_exit=6:delay_enter=7 \
chdir:delay_exit=8:delay_enter=9:delay_exit=10 \
counter=7
for arg in 42 \
invalid \
error= \
error=invalid_error_name \
error=-1 \
error=-2 \
error=3+ \
error=4096 \
; 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" "when=$counter"
counter=$((counter + 1))
done
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
check_tampering_syntax inject chdir "$arg"
check_tampering_syntax inject chdir "$arg" "error=$counter"
counter=$((counter + 1))
done
check_tampering_syntax inject chdir retval=a
check_tampering_syntax inject chdir retval=0b
check_tampering_syntax inject chdir retval=0x10000000000000000
check_tampering_syntax inject chdir signal=0
check_tampering_syntax inject chdir signal=129
check_tampering_syntax inject chdir signal=1 signal=2
check_tampering_syntax inject chdir signal=1 retval=0 signal=2
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
check_tampering_syntax inject chdir delay_enter=-1
check_tampering_syntax inject chdir delay_exit=-2
check_tampering_syntax inject chdir delay_enter=1 delay_enter=2
check_tampering_syntax inject chdir delay_exit=3 delay_exit=4
check_tampering_syntax inject chdir delay_enter=5 delay_exit=6 delay_enter=7
check_tampering_syntax inject chdir delay_exit=8 delay_enter=9 delay_exit=10
exit 0

64
tests/tampering-syntax.sh Normal file
View File

@ -0,0 +1,64 @@
#!/bin/sh
#
# Define inject/fault syntax testing primitives.
#
# Copyright (c) 2016 Dmitry V. Levin <ldv@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
}