]> granicus.if.org Git - strace/commitdiff
tests: factor out common shell code to functions
authorDmitry V. Levin <ldv@altlinux.org>
Tue, 17 Mar 2015 17:07:57 +0000 (17:07 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 18 Mar 2015 02:29:36 +0000 (02:29 +0000)
Factor out shell code used in several tests to common functions.

* tests/fanotify_mark.expected: New file.
* tests/ioctl.expected: New file.
* tests/net-fd.expected: New file.
* tests/net.expected: New file.
* tests/statfs.expected: New file.
* tests/sun_path.expected: New file.
* tests/uio.expected: New file.
* tests/ipc.sh: New file.
* tests/Makefile.am (EXTRA_DIST): Add them.
* tests/init.sh (dump_log_and_fail_with, run_prog,
run_prog_skip_if_failed, run_strace, run_strace_merge,
match_awk, match_diff, match_grep): New functions.
* tests/*.test: Use them.

44 files changed:
tests/Makefile.am
tests/bexecve.test
tests/caps.test
tests/count.test
tests/detach-running.test
tests/detach-sleeping.test
tests/detach-stopped.test
tests/dumpio.test
tests/fanotify_mark.expected [new file with mode: 0755]
tests/fanotify_mark.test
tests/getdents.test
tests/getrandom.test
tests/init.sh
tests/ioctl.expected [new file with mode: 0755]
tests/ioctl.test
tests/ipc.sh [new file with mode: 0644]
tests/ipc_msg.test
tests/ipc_sem.test
tests/ipc_shm.test
tests/mmsg.test
tests/net-fd.expected [new file with mode: 0755]
tests/net-fd.test
tests/net-yy.test
tests/net.expected [new file with mode: 0755]
tests/net.test
tests/pc.test
tests/qual_syscall.test
tests/scm_rights-fd.test
tests/select.test
tests/sigaction.test
tests/sigreturn.test
tests/stat.test
tests/stat32-v.test
tests/stat64-v.test
tests/statfs.expected [new file with mode: 0755]
tests/statfs.test
tests/strace-f.test
tests/strace-k.test
tests/sun_path.expected [new file with mode: 0755]
tests/sun_path.test
tests/uid.test
tests/uio.expected [new file with mode: 0755]
tests/uio.test
tests/unix-yy.test

index ff5e1366cf629b5c4c6133a02dc004a30b5cff81..7f9a11ea4d9fa38cae030499851fe2439f67685f 100644 (file)
@@ -87,15 +87,23 @@ TEST_LOG_COMPILER = $(srcdir)/run.sh
 EXTRA_DIST = init.sh run.sh \
             caps.awk \
             dumpio.expected \
+            fanotify_mark.expected \
             getdents.awk \
             getdents.out \
             getrandom.awk \
+            ioctl.expected \
+            ipc.sh \
             mmsg.expected \
+            net.expected \
+            net-fd.expected \
             net-yy-accept.awk \
             net-yy-connect.awk \
             select.awk \
             sigaction.awk \
+            statfs.expected \
+            sun_path.expected \
             uid.awk \
+            uio.expected \
             unix-yy-accept.awk \
             unix-yy-connect.awk \
             $(TESTS)
index 9064399e44fb155003b8fc965708c62a99a19e32..c49f08b08da820a89409a02969fd5c03d12bc79e 100755 (executable)
@@ -4,35 +4,26 @@
 
 . "${srcdir=.}/init.sh"
 
-check_prog grep
-
-args='-enone'
-what="$STRACE $args sh -c 'exec false'"
-
-$STRACE $args sh -c 'exec false' 2> "$LOG"
-if [ $? -ne 1 ]; then
-       cat "$LOG"
-       fail_ "$what: unexpected exit status"
-fi
+run_strace_redir()
+{
+       args="$*"
+       $STRACE "$@" 2> "$LOG"
+}
 
-args='-bexecve -enone'
-what="$STRACE $args sh -c 'exec false'"
+run_strace_redir -enone sh -c 'exec false'
+[ $? -eq 1 ] ||
+       dump_log_and_fail_with "$STRACE $args: unexpected exit status"
 
-$STRACE $args sh -c 'exec false' 2> "$LOG" || {
-       cat "$LOG"
-       fail_ "$what: unexpected exit status"
-}
+run_strace_redir -bexecve -enone sh -c 'exec false' ||
+       dump_log_and_fail_with "$STRACE $args: unexpected exit status"
 
 pattern='Process [1-9][0-9]* detached'
 
-LC_ALL=C grep -x "$pattern" "$LOG" > /dev/null || {
-       cat "$LOG"
-       fail_ "$what: unexpected output"
-}
+LC_ALL=C grep -x "$pattern" "$LOG" > /dev/null ||
+       dump_log_and_fail_with "$STRACE $args: output mismatch"
 
 if LC_ALL=C grep -v -x "$pattern" "$LOG" > /dev/null; then
-       cat "$LOG"
-       fail_ "$what: unexpected output"
+       dump_log_and_fail_with "$STRACE $args: unexpected output"
 fi
 
 exit 0
index ac0a85daf64f7b3f495d1073064787c44b418376..9437a4ba3197569646b3a16ff1850d035a11d49e 100755 (executable)
@@ -4,23 +4,8 @@
 
 . "${srcdir=.}/init.sh"
 
-check_prog awk
-
-./caps || {
-       if [ $? -eq 77 ]; then
-               framework_skip_ 'capget/capset syscalls do not behave as expected'
-       else
-               fail_ 'caps failed'
-       fi
-}
-
-args="-e trace=capget,capset ./caps"
-$STRACE -o "$LOG" $args || {
-       cat "$LOG"
-       fail_ "$STRACE $args failed"
-}
-
-awk -f "$srcdir"/caps.awk "$LOG" ||
-       { cat "$LOG"; fail_ 'unexpected output'; }
+run_prog
+run_strace -e trace=capget,capset $args
+match_awk
 
 exit 0
index b94eebae1274f517e3458f4b17b708931bea7c26..9c53fe24bcc5db03839c56deb553371868d757df 100755 (executable)
@@ -7,38 +7,25 @@
 check_prog grep
 check_prog sleep
 
-make_log()
-{
-       $STRACE $args > $LOG 2>&1 || {
-               cat $LOG
-               fail_ "$STRACE $args failed"
-       }
-}
-
 grep_log()
 {
-       LC_ALL=C grep -E -x -e "$*" $LOG > /dev/null || {
-               cat $LOG
-               fail_ "unexpected output from $STRACE $args"
-       }
-}
+       local pattern="$1"; shift
 
-args='-c sleep 1'
-make_log
-grep nanosleep $LOG > /dev/null ||
-       skip_ 'sleep does not use nanosleep'
-grep_log ' *[^ ]+ +0\.0[^n]*nanosleep'
+       run_strace "$@"
 
-args='-c -enanosleep sleep 1'
-make_log
-grep_log ' *[^ ]+ +0\.0[^n]*nanosleep'
+       grep nanosleep "$LOG" > /dev/null ||
+               framework_skip_ 'sleep does not use nanosleep'
 
-args='-cw sleep 1'
-make_log
-grep_log ' *[^ ]+ +(1\.0|0\.99)[^n]*nanosleep'
+       LC_ALL=C grep -E -x -e "$pattern" "$LOG" > /dev/null || {
+               echo "Pattern of expected output: $pattern"
+               echo 'Actual output:'
+               dump_log_and_fail_with "$STRACE $args output mismatch"
+       }
+}
 
-args='-cw -enanosleep sleep 1'
-make_log
-grep_log '100\.00 +(1\.0|0\.99)[^n]*nanosleep'
+grep_log ' *[^ ]+ +0\.0[^n]*nanosleep'         -c sleep 1
+grep_log ' *[^ ]+ +0\.0[^n]*nanosleep'         -c -enanosleep sleep 1
+grep_log ' *[^ ]+ +(1\.0|0\.99)[^n]*nanosleep' -cw sleep 1
+grep_log '100\.00 +(1\.0|0\.99)[^n]*nanosleep' -cw -enanosleep sleep 1
 
 exit 0
index 70e52080c9a55b6f9ede82d089225ea89fddbfe4..595a505be9e7cc13fbfb76bdc6b3f8d5ce7c723a 100755 (executable)
@@ -4,17 +4,16 @@
 
 . "${srcdir=.}/init.sh"
 
-kill -0 $$ ||
-       framework_skip_ 'kill -0 does not work'
+run_prog_skip_if_failed \
+       kill -0 $$
 
-check_prog grep
 check_prog sleep
 
 set -e
 
 ./set_ptracer_any sh -c "echo > $LOG; while :; do :; done" > /dev/null &
 
-while ! [ -s $LOG ]; do
+while ! [ -s "$LOG" ]; do
        kill -0 $! 2> /dev/null ||
                fail_ 'set_ptracer_any sh failed'
        $SLEEP_A_BIT
@@ -30,30 +29,35 @@ cleanup()
        return 0
 }
 
-rm -f $LOG
-$STRACE -p $tracee_pid 2> $LOG &
+rm -f "$LOG"
+$STRACE -p $tracee_pid 2> "$LOG" &
 
-while ! grep -F "Process $tracee_pid attached" $LOG > /dev/null; do
-       kill -0 $! 2> /dev/null ||
-               { cat $LOG; cleanup; fail_ 'strace -p does not work'; }
+while ! grep -F "Process $tracee_pid attached" "$LOG" > /dev/null; do
+       kill -0 $! 2> /dev/null || {
+               cleanup
+               dump_log_and_fail_with "$STRACE -p failed to attach"
+       }
        $SLEEP_A_BIT
 done
 
 kill -INT $!
 wait $!
 
-grep -F "Process $tracee_pid detached" $LOG > /dev/null ||
-       { cat $LOG; cleanup; fail_ 'strace -p failed to detach'; }
+grep -F "Process $tracee_pid detached" "$LOG" > /dev/null || {
+               cleanup
+               dump_log_and_fail_with "$STRACE -p failed to detach"
+       }
 
 if [ -f /proc/self/status ]; then
        $SLEEP_A_BIT
-       test -d /proc/$tracee_pid ||
-               { cat $LOG; cleanup; fail_ 'tracee died after detach'; }
+       test -d /proc/$tracee_pid || {
+               cleanup
+               dump_log_and_fail_with 'tracee died after detach'
+       }
        grep '^State:.*R (running)' < /proc/$tracee_pid/status > /dev/null || {
-               cat $LOG
                grep '^State:' < /proc/$tracee_pid/status
                cleanup
-               fail_ 'tracee is not running after detach'
+               dump_log_and_fail_with 'tracee is not running after detach'
        }
 fi
 
index 6588d4f938e3a852b9f720f8dbbc9c0e50753df8..345d7d0aa4c085437ecb35bf4d8d2c2e21c14775 100755 (executable)
@@ -4,18 +4,17 @@
 
 . "${srcdir=.}/init.sh"
 
-kill -0 $$ ||
-       framework_skip_ 'kill -0 does not work'
+run_prog_skip_if_failed \
+       kill -0 $$
 
-check_prog grep
 check_prog sleep
 
 set -e
 
-rm -f $LOG
-./set_ptracer_any sleep $((2*$TIMEOUT_DURATION)) > $LOG &
+rm -f "$LOG"
+./set_ptracer_any sleep $((2*$TIMEOUT_DURATION)) > "$LOG" &
 
-while ! [ -s $LOG ]; do
+while ! [ -s "$LOG" ]; do
        kill -0 $! 2> /dev/null ||
                fail_ 'set_ptracer_any sleep failed'
        $SLEEP_A_BIT
@@ -31,30 +30,35 @@ cleanup()
        return 0
 }
 
-rm -f $LOG
-$STRACE -p $tracee_pid 2> $LOG &
+rm -f "$LOG"
+$STRACE -p $tracee_pid 2> "$LOG" &
 
-while ! grep -F "Process $tracee_pid attached" $LOG > /dev/null; do
-       kill -0 $! 2> /dev/null ||
-               { cat $LOG; cleanup; fail_ 'strace -p does not work'; }
+while ! grep -F "Process $tracee_pid attached" "$LOG" > /dev/null; do
+       kill -0 $! 2> /dev/null || {
+               cleanup
+               dump_log_and_fail_with "$STRACE -p failed to attach"
+       }
        $SLEEP_A_BIT
 done
 
 kill -INT $!
 wait $!
 
-grep -F "Process $tracee_pid detached" $LOG > /dev/null ||
-       { cat $LOG; cleanup; fail_ 'strace -p failed to detach'; }
+grep -F "Process $tracee_pid detached" "$LOG" > /dev/null || {
+       cleanup
+       dump_log_and_fail_with "$STRACE -p failed to detach"
+}
 
 if [ -f /proc/self/status ]; then
        $SLEEP_A_BIT
-       test -d /proc/$tracee_pid ||
-               { cat $LOG; cleanup; fail_ 'tracee died after detach'; }
+       test -d /proc/$tracee_pid || {
+               cleanup
+               dump_log_and_fail_with 'tracee died after detach'
+       }
        grep '^State:.*S (sleeping)' < /proc/$tracee_pid/status > /dev/null || {
-               cat $LOG
                grep '^State:' < /proc/$tracee_pid/status
                cleanup
-               fail_ 'tracee is not sleeping after detach'
+               dump_log_and_fail_with 'tracee is not sleeping after detach'
        }
 fi
 
index 871a157e23aaae2d2cf1a6dfc5a9f4a62f2ab551..3d1c67e0592fc3b8d1622efa12c148ed8076bc70 100755 (executable)
@@ -4,23 +4,22 @@
 
 . "${srcdir=.}/init.sh"
 
-kill -0 $$ ||
-       framework_skip_ 'kill -0 does not work'
+run_prog_skip_if_failed \
+       kill -0 $$
 
-check_prog grep
 check_prog sleep
 
-$STRACE -d -enone / > /dev/null 2> $LOG
-if grep -F -x "PTRACE_SEIZE doesn't work" $LOG > /dev/null; then
+$STRACE -d -enone / > /dev/null 2> "$LOG"
+if grep -F -x "PTRACE_SEIZE doesn't work" "$LOG" > /dev/null; then
        skip_ "PTRACE_SEIZE doesn't work"
 fi
 
 set -e
 
-rm -f $LOG
-./set_ptracer_any sleep $((2*$TIMEOUT_DURATION)) > $LOG &
+rm -f "$LOG"
+./set_ptracer_any sleep $((2*$TIMEOUT_DURATION)) > "$LOG" &
 
-while ! [ -s $LOG ]; do
+while ! [ -s "$LOG" ]; do
        kill -0 $! 2> /dev/null ||
                fail_ 'set_ptracer_any sleep failed'
        $SLEEP_A_BIT
@@ -38,36 +37,43 @@ cleanup()
        return 0
 }
 
-rm -f $LOG
-$STRACE -p $tracee_pid 2> $LOG &
+rm -f "$LOG"
+$STRACE -p $tracee_pid 2> "$LOG" &
 
-while ! grep -F "Process $tracee_pid attached" $LOG > /dev/null; do
-       kill -0 $! 2> /dev/null ||
-               { cat $LOG; cleanup; fail_ 'strace -p does not work'; }
+while ! grep -F "Process $tracee_pid attached" "$LOG" > /dev/null; do
+       kill -0 $! 2> /dev/null || {
+               cleanup
+               dump_log_and_fail_with "$STRACE -p failed to attach"
+       }
        $SLEEP_A_BIT
 done
 
-while ! grep -F -e '--- stopped by ' $LOG > /dev/null; do
-       kill -0 $! 2> /dev/null ||
-               { cat $LOG; cleanup; fail_ 'strace -p does not work'; }
+while ! grep -F -e '--- stopped by ' "$LOG" > /dev/null; do
+       kill -0 $! 2> /dev/null || {
+               cleanup
+               dump_log_and_fail_with "$STRACE -p missed stop notifications"
+       }
        $SLEEP_A_BIT
 done
 
 kill -INT $!
 wait $!
 
-grep -F "Process $tracee_pid detached" $LOG > /dev/null ||
-       { cat $LOG; cleanup; fail_ 'strace -p failed to detach'; }
+grep -F "Process $tracee_pid detached" "$LOG" > /dev/null || {
+       cleanup
+       dump_log_and_fail_with "$STRACE -p failed to detach"
+}
 
 if [ -f /proc/self/status ]; then
        $SLEEP_A_BIT
-       test -d /proc/$tracee_pid ||
-               { cat $LOG; cleanup; fail_ 'tracee died after detach'; }
+       test -d /proc/$tracee_pid || {
+               cleanup
+               dump_log_and_fail_with 'tracee died after detach'
+       }
        grep '^State:.*T (stopped)' < /proc/$tracee_pid/status > /dev/null || {
-               cat $LOG
                grep '^State:' < /proc/$tracee_pid/status
                cleanup
-               fail_ 'tracee is not group-stopped after detach'
+               dump_log_and_fail_with 'tracee is not group-stopped after detach'
        }
 fi
 
index ef3792d27d410b031c349e11926d2f5890e69d5f..8d272fce6bca35c29ee58ec20d1d8c25c8d93439 100755 (executable)
@@ -4,23 +4,8 @@
 
 . "${srcdir=.}/init.sh"
 
-dumpio_expected="${srcdir=.}/dumpio.expected"
-cat "$dumpio_expected" > /dev/null ||
-       fail_ "$dumpio_expected is not available"
-
-check_prog diff
-
-args='./unix-pair-send-recv abcdefghijklmnopqrstuvwxyz'
-$args ||
-       fail_ "$args failed"
-
-args="-esignal=none -esendto,recvfrom -eread=0 -ewrite=0 $args"
-$STRACE -o "$LOG" $args || {
-       cat "$LOG"
-       fail_ "$STRACE $args failed"
-}
-
-diff "$dumpio_expected" "$LOG" ||
-       fail_ "$STRACE $args failed to dump i/o properly"
+run_prog ./unix-pair-send-recv abcdefghijklmnopqrstuvwxyz
+run_strace -esignal=none -esendto,recvfrom -eread=0 -ewrite=0 $args
+match_diff
 
 exit 0
diff --git a/tests/fanotify_mark.expected b/tests/fanotify_mark.expected
new file mode 100755 (executable)
index 0000000..d2bb336
--- /dev/null
@@ -0,0 +1 @@
+fanotify_mark\(-1, FAN_MARK_ADD, FAN_MODIFY\|FAN_ONDIR, AT_FDCWD, "\."\) += -1.*
index c5eb4eb76e98392b3948260b41a7f7ea8005a8fb..4b7749afa31fa193325b72e1637307c5a2d033b9 100755 (executable)
@@ -4,32 +4,8 @@
 
 . "${srcdir=.}/init.sh"
 
-check_prog grep
-
-./fanotify_mark || {
-       if [ $? -eq 77 ]; then
-               framework_skip_ 'fanotify_mark is not available'
-       else
-               fail_ 'fanotify_mark failed'
-       fi
-}
-
-args="-efanotify_mark ./fanotify_mark"
-$STRACE -o "$LOG" $args || {
-       cat "$LOG"
-       fail_ "$STRACE $args failed"
-}
-
-grep_log()
-{
-       local syscall="$1"; shift
-
-       LC_ALL=C grep -E -x "$syscall$*" $LOG > /dev/null || {
-               cat $LOG
-               fail_ "$STRACE $args failed to trace \"$syscall\" properly"
-       }
-}
-
-grep_log fanotify_mark '\(-1, FAN_MARK_ADD, FAN_MODIFY\|FAN_ONDIR, AT_FDCWD, "\."\) += -1.*'
+run_prog
+run_strace -efanotify_mark $args
+match_grep
 
 exit 0
index 5200c0bece6baafa420cb2c80da70c9a0522330a..5be3e8372924890eccedbd59f8ab8e1f81bd8446 100755 (executable)
@@ -15,29 +15,19 @@ check_prog seq
 check_prog touch
 
 dir="$LOG.dir"
+rm -rf -- "$dir"
 mkdir -- "$dir" ||
        framework_skip_ 'failed to create a directory'
 
 touch -- "$dir/$(for i in $(seq 1 127); do echo A; done; echo Z)" ||
        framework_skip_ 'failed to create a file'
 
-ls -- "$dir" > /dev/null || {
-       rm -rf -- "$dir"
+ls -- "$dir" > /dev/null ||
        framework_skip_ 'failed to list a directory'
-}
 
-args='-vegetdents,getdents64'
-$STRACE -o "$LOG" $args ls -- "$dir" > /dev/null
-rc=$?
+run_strace -vegetdents,getdents64 ls -- "$dir" > /dev/null
+match_awk
+
 rm -rf -- "$dir"
-[ $rc -eq 0 ] || {
-       cat "$LOG"
-       fail_ "strace $args failed"
-}
-
-awk -f "$srcdir"/getdents.awk "$LOG" || {
-       cat "$LOG"
-       fail_ "strace $args failed to trace getdents/getdents64 properly"
-}
 
 exit 0
index 9117038b35a30df28f0d16b143e7e4cd94c1041d..3dd76f29a3d4e7fc4b554b232697fdd4d5b90d68 100755 (executable)
@@ -4,20 +4,8 @@
 
 . "${srcdir=.}/init.sh"
 
-check_prog awk
-
-./getrandom ||
-       framework_skip_ 'getrandom is not available'
-
-args="-e getrandom -xx -s3 ./getrandom"
-$STRACE -o "$LOG" $args || {
-       cat "$LOG"
-       fail_ "$STRACE $args failed"
-}
-
-awk -f "$srcdir"/getrandom.awk "$LOG" || {
-       cat "$LOG"
-       fail_ 'unexpected output'
-}
+run_prog
+run_strace -e getrandom -xx -s3 $args
+match_awk
 
 exit 0
index 418272b86bff9952cee525869976c8ced10888eb..a3ccd1fa2b5d8e2dd87f6aaf6c80aa8c677e8205 100644 (file)
@@ -14,6 +14,150 @@ check_prog()
                framework_skip_ "$* is not available"
 }
 
+dump_log_and_fail_with()
+{
+       cat < "$LOG"
+       fail_ "$*"
+}
+
+run_prog()
+{
+       if [ $# -eq 0 ]; then
+               set -- "./${ME_%.test}"
+       fi
+       args="$*"
+       "$@" || {
+               if [ $? -eq 77 ]; then
+                       skip_ "$args exited with code 77"
+               else
+                       fail_ "$args failed"
+               fi
+       }
+}
+
+
+run_prog_skip_if_failed()
+{
+       args="$*"
+       "$@" || framework_skip_ "$args failed"
+}
+
+run_strace()
+{
+       > "$LOG" || fail_ "failed to write $LOG"
+       args="$*"
+       $STRACE -o "$LOG" "$@" ||
+               dump_log_and_fail_with "$STRACE $args failed"
+}
+
+run_strace_merge()
+{
+       rm -f -- "$LOG".[0-9]*
+       run_strace -ff -tt "$@"
+       "$srcdir"/../strace-log-merge "$LOG" > "$LOG" ||
+               dump_log_and_fail_with 'strace-log-merge failed'
+       rm -f -- "$LOG".[0-9]*
+}
+
+# Usage: [FILE_TO_CHECK [AWK_PROGRAM [ERROR_MESSAGE [EXTRA_AWK_OPTIONS...]]]]
+# Check whether all patterns listed in AWK_PROGRAM
+# match FILE_TO_CHECK using egrep.
+# If at least one of these patterns does not match,
+# dump both files and fail with ERROR_MESSAGE.
+match_awk()
+{
+       local output program error awk
+       if [ $# -eq 0 ]; then
+               output="$LOG"
+       else
+               output="$1"; shift
+       fi
+       if [ $# -eq 0 ]; then
+               program="$srcdir/${ME_%.test}.awk"
+       else
+               program="$1"; shift
+       fi
+       if [ $# -eq 0 ]; then
+               error="$STRACE $args output mismatch"
+       else
+               error="$1"; shift
+       fi
+       awk=${AWK:-awk}
+
+       check_prog "$awk"
+
+       "$awk" -f "$program" "$@" < "$output" || {
+               cat < "$output"
+               fail_ "$error"
+       }
+}
+
+# Usage: [FILE_TO_CHECK [FILE_TO_COMPATE_WITH [ERROR_MESSAGE]]]
+# Check whether FILE_TO_CHECK differs from FILE_TO_COMPATE_WITH.
+# If it does, dump the difference and fail with ERROR_MESSAGE.
+match_diff()
+{
+       local output expected error
+       if [ $# -eq 0 ]; then
+               output="$LOG"
+       else
+               output="$1"; shift
+       fi
+       if [ $# -eq 0 ]; then
+               expected="$srcdir/${ME_%.test}.expected"
+       else
+               expected="$1"; shift
+       fi
+       if [ $# -eq 0 ]; then
+               error="$STRACE $args output mismatch"
+       else
+               error="$1"; shift
+       fi
+
+       check_prog diff
+
+       diff -- "$expected" "$output" ||
+               fail_ "$error"
+}
+
+# Usage: [FILE_TO_CHECK [FILE_WITH_PATTERNS [ERROR_MESSAGE]]]
+# Check whether all patterns listed in FILE_WITH_PATTERNS
+# match FILE_TO_CHECK using egrep.
+# If at least one of these patterns does not match,
+# dump both files and fail with ERROR_MESSAGE.
+match_grep()
+{
+       local output patterns error expected matched
+       if [ $# -eq 0 ]; then
+               output="$LOG"
+       else
+               output="$1"; shift
+       fi
+       if [ $# -eq 0 ]; then
+               patterns="$srcdir/${ME_%.test}.expected"
+       else
+               patterns="$1"; shift
+       fi
+       if [ $# -eq 0 ]; then
+               error="$STRACE $args output mismatch"
+       else
+               error="$1"; shift
+       fi
+
+       check_prog wc
+       check_prog grep
+
+       expected=$(wc -l < "$patterns") &&
+       matched=$(LC_ALL=C grep -c -E -x -f "$patterns" < "$output") &&
+       test "$expected" -eq "$matched" || {
+               echo 'Patterns of expected output:'
+               cat < "$patterns"
+               echo 'Actual output:'
+               cat < "$output"
+               fail_ "$error"
+       }
+}
+
 check_prog cat
 check_prog rm
 
diff --git a/tests/ioctl.expected b/tests/ioctl.expected
new file mode 100755 (executable)
index 0000000..b8e4a29
--- /dev/null
@@ -0,0 +1,6 @@
+ioctl\(-1, TCGETS, 0x[0-9a-f]+\) += -1 EBADF .*
+ioctl\(-1, MMTIMER_GETRES, 0x[0-9a-f]+\) += -1 EBADF .*
+ioctl\(-1, HIDIOCGRDESCSIZE or HIDIOCGVERSION, 0x[0-9a-f]+\) += -1 EBADF .*
+ioctl\(-1, HIDIOCGPHYS\(8\), 0x[0-9a-f]+\) += -1 EBADF .*
+ioctl\(-1, EVIOCGBIT\(EV_KEY, 8\), 0x[0-9a-f]+\) += -1 EBADF .*
+ioctl\(-1, _IOC\(_IOC_READ, 0xde, 0xad, 0x08\), 0x[0-9a-f]+\) += -1 EBADF .*
index bdcaa500ef1bd3f971cd98a7f6277e24d7af1c9a..8c2a9baae5c014dd1654d713391f1f8717b2107f 100755 (executable)
@@ -4,37 +4,8 @@
 
 . "${srcdir=.}/init.sh"
 
-check_prog grep
-
-./ioctl || {
-       if [ $? -eq 77 ]; then
-               framework_skip_ 'ioctl does not behave as expected'
-       else
-               fail_ 'ioctl failed'
-       fi
-}
-
-args="-e ioctl ./ioctl"
-$STRACE -o "$LOG" $args || {
-       cat "$LOG"
-       fail_ "$STRACE $args failed"
-}
-
-grep_log()
-{
-       local syscall="$1"; shift
-
-       LC_ALL=C grep -E -x "$syscall$*" "$LOG" > /dev/null || {
-               cat "$LOG"
-               fail_ "$STRACE $args failed to trace \"$syscall\" properly"
-       }
-}
-
-grep_log ioctl '\(-1, TCGETS, 0x[0-9a-f]+\) += -1 EBADF .*'
-grep_log ioctl '\(-1, MMTIMER_GETRES, 0x[0-9a-f]+\) += -1 EBADF .*'
-grep_log ioctl '\(-1, HIDIOCGRDESCSIZE or HIDIOCGVERSION, 0x[0-9a-f]+\) += -1 EBADF .*'
-grep_log ioctl '\(-1, HIDIOCGPHYS\(8\), 0x[0-9a-f]+\) += -1 EBADF .*'
-grep_log ioctl '\(-1, EVIOCGBIT\(EV_KEY, 8\), 0x[0-9a-f]+\) += -1 EBADF .*'
-grep_log ioctl '\(-1, _IOC\(_IOC_READ, 0xde, 0xad, 0x08\), 0x[0-9a-f]+\) += -1 EBADF .*'
+run_prog
+run_strace -e ioctl $args
+match_grep
 
 exit 0
diff --git a/tests/ipc.sh b/tests/ipc.sh
new file mode 100644 (file)
index 0000000..32ef423
--- /dev/null
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+# Check decoding of ipc syscalls
+
+. "${srcdir=.}/init.sh"
+
+OUT="$LOG.out"
+
+run_prog > /dev/null
+run_strace -eipc $args > "$OUT"
+match_grep "$LOG" "$OUT"
+
+rm -f "$OUT"
+
+exit 0
index e0d27edcbc5418b7820ed19cfe066c4843df0e3b..177495b0d3f455d2c70b1dfeddfb819a549fdab4 100755 (executable)
@@ -2,29 +2,4 @@
 
 # Check decoding of ipc msgget/msgctl syscalls
 
-. "${srcdir=.}/init.sh"
-
-check_prog grep
-
-OUT="$LOG.out"
-
-./ipc_msg > /dev/null || {
-       if [ $? -eq 77 ]; then
-               framework_skip_ 'ipc msgget/msgctl syscalls do not behave as expected'
-       else
-               fail_ 'ipc_msg failed'
-       fi
-}
-
-args="-eipc ./ipc_msg"
-$STRACE -o "$LOG" $args > "$OUT" &&
-exp_lines=$(wc -l < "$OUT") &&
-matched_lines=$(LC_ALL=C grep -c -E -x -f "$OUT" "$LOG") &&
-test $exp_lines -eq $matched_lines || {
-       cat "$OUT" "$LOG"
-       fail_ "$STRACE $args output mismatch"
-}
-
-rm -f "$OUT"
-
-exit 0
+. "${srcdir=.}/ipc.sh"
index ef957c3e0eb5cbbb01f75d59e61e8928efae69eb..cc93d07bde5abe13ceff73b421dd4712a933306c 100755 (executable)
@@ -2,29 +2,4 @@
 
 # Check decoding of ipc semget/semctl syscalls
 
-. "${srcdir=.}/init.sh"
-
-check_prog grep
-
-OUT="$LOG.out"
-
-./ipc_sem > /dev/null || {
-       if [ $? -eq 77 ]; then
-               framework_skip_ 'ipc semget/semctl syscalls do not behave as expected'
-       else
-               fail_ 'ipc_sem failed'
-       fi
-}
-
-args='-eipc ./ipc_sem'
-$STRACE -o "$LOG" $args > "$OUT" &&
-exp_lines=$(wc -l < "$OUT") &&
-matched_lines=$(LC_ALL=C grep -c -E -x -f "$OUT" "$LOG") &&
-test $exp_lines -eq $matched_lines || {
-       cat "$OUT" "$LOG"
-       fail_ "$STRACE $args output mismatch"
-}
-
-rm -f "$OUT"
-
-exit 0
+. "${srcdir=.}/ipc.sh"
index de8b47c1870b35c5e502f380600735f693c84947..a67ea291fdd7f026d8ffc8f36a2753d94eeb2839 100755 (executable)
@@ -2,29 +2,4 @@
 
 # Check decoding of ipc shmget/shmctl syscalls
 
-. "${srcdir=.}/init.sh"
-
-check_prog grep
-
-OUT="$LOG.out"
-
-./ipc_shm > /dev/null || {
-       if [ $? -eq 77 ]; then
-               framework_skip_ 'ipc shmget/shmctl syscalls do not behave as expected'
-       else
-               fail_ 'ipc_shm failed'
-       fi
-}
-
-args="-eipc ./ipc_shm"
-$STRACE -o "$LOG" $args > "$OUT" &&
-exp_lines=$(wc -l < "$OUT") &&
-matched_lines=$(LC_ALL=C grep -c -E -x -f "$OUT" "$LOG") &&
-test $exp_lines -eq $matched_lines || {
-       cat "$OUT" "$LOG"
-       fail_ "$STRACE $args output mismatch"
-}
-
-rm -f "$OUT"
-
-exit 0
+. "${srcdir=.}/ipc.sh"
index ad5c659c4876db1f745d9f6fd823ce370f9cca74..0237df80567ab9fef0efaf515f5bb0fd8e583fc7 100755 (executable)
@@ -4,28 +4,8 @@
 
 . "${srcdir=.}/init.sh"
 
-mmsg_expected="${srcdir=.}/mmsg.expected"
-
-check_prog diff
-
-cat "$mmsg_expected" > /dev/null ||
-       fail_ "$mmsg_expected is not available"
-
-./mmsg || {
-       if [ $? -eq 77 ]; then
-               framework_skip_ 'sendmmsg/recvmmsg syscalls are not available'
-       else
-               fail_ 'mmsg failed'
-       fi
-}
-
-args="-e trace=recvmmsg,sendmmsg -e read=0 -e write=1 -o $LOG ./mmsg"
-$STRACE $args || {
-       cat $LOG
-       fail_ "$STRACE $args failed"
-}
-
-diff "$mmsg_expected" $LOG ||
-       fail_ "$STRACE $args failed to decode mmsghdr properly"
+run_prog
+run_strace -e trace=recvmmsg,sendmmsg -e read=0 -e write=1 $args
+match_diff
 
 exit 0
diff --git a/tests/net-fd.expected b/tests/net-fd.expected
new file mode 100755 (executable)
index 0000000..49b6992
--- /dev/null
@@ -0,0 +1,5 @@
+[1-9][0-9]* +[0-9]+:[0-9]+:[0-9]+\.[0-9]+ +bind\(0<socket:\[[0-9]+\]>, \{sa_family=AF_(LOCAL|UNIX|FILE), sun_path="net-fd-local-stream"\}, 22\) += 0
+[1-9][0-9]* +[0-9]+:[0-9]+:[0-9]+\.[0-9]+ +listen\(0<socket:\[[0-9]+\]>, 5\) += 0
+[1-9][0-9]* +[0-9]+:[0-9]+:[0-9]+\.[0-9]+ +getsockname\(0<socket:\[[0-9]+\]>, \{sa_family=AF_(LOCAL|UNIX|FILE), sun_path="net-fd-local-stream"\}, \[22\]\) += 0
+[1-9][0-9]* +[0-9]+:[0-9]+:[0-9]+\.[0-9]+ +accept\(0<socket:\[[0-9]+\]>, \{sa_family=AF_(LOCAL|UNIX|FILE), NULL\}, \[2\]\) += 1<socket:\[[0-9]+\]>
+[1-9][0-9]* +[0-9]+:[0-9]+:[0-9]+\.[0-9]+ +connect\(1<socket:\[[0-9]+\]>, \{sa_family=AF_(LOCAL|UNIX|FILE), sun_path="net-fd-local-stream"\}, 22\) += 0
index 4c24efdaad46eabf541a81bc268739061bdf6bfe..ddef8fc77f35ce14b8431f75ce72be4566a0a63a 100755 (executable)
@@ -8,40 +8,9 @@
 [ -d /proc/self/fd/ ] ||
        framework_skip_ '/proc/self/fd/ is not available'
 
-check_prog grep
-
-rm -f $LOG.*
-
-addr=net-fd-local-stream
-./net-accept-connect $addr ||
-       fail_ 'net-accept-connect failed'
-
+run_prog ./net-accept-connect net-fd-local-stream
 # using -y to test socket descriptors 'paths' decoding
-args="-tt -ff -y -enetwork ./net-accept-connect $addr"
-$STRACE -o "$LOG" $args ||
-       fail_ "$STRACE $args failed"
-
-"$srcdir"/../strace-log-merge $LOG > $LOG || {
-       cat $LOG
-       fail_ 'strace-log-merge failed'
-}
-
-rm -f $LOG.*
-
-grep_log()
-{
-       local syscall="$1"; shift
-       local prefix='[1-9][0-9]* +[0-9]+:[0-9]+:[0-9]+\.[0-9]+ +'
-
-       LC_ALL=C grep -E -x "$prefix$syscall$*" $LOG > /dev/null || {
-               cat $LOG
-               fail_ "strace -enetwork failed to trace \"$syscall\" properly"
-       }
-}
-grep_log bind '\(0<socket:\[[0-9]+\]>, \{sa_family=AF_(LOCAL|UNIX|FILE), sun_path="'$addr'"\}, 22\) += 0'
-grep_log listen '\(0<socket:\[[0-9]+\]>, 5\) += 0'
-grep_log getsockname '\(0<socket:\[[0-9]+\]>, \{sa_family=AF_(LOCAL|UNIX|FILE), sun_path="'$addr'"\}, \[22\]\) += 0'
-grep_log accept '\(0<socket:\[[0-9]+\]>, \{sa_family=AF_(LOCAL|UNIX|FILE), NULL\}, \[2\]\) += 1<socket:\[[0-9]+\]>'
-grep_log connect '\(1<socket:\[[0-9]+\]>, \{sa_family=AF_(LOCAL|UNIX|FILE), sun_path="'$addr'"\}, 22\) += 0'
+run_strace_merge -y -enetwork $args
+match_grep
 
 exit 0
index 47e3767ac473d238d5ae4a7472809a59dc6ff82c..2a2c0f73ad6b320769b811579fdd2e0e5d4cb5cb 100755 (executable)
@@ -8,57 +8,22 @@
 [ -d /proc/self/fd/ ] ||
        framework_skip_ '/proc/self/fd/ is not available'
 
-check_prog awk
 check_prog sed
 
-rm -f $LOG.* $LOG-*
+run_prog ./netlink_inet_diag
+run_prog ./inet-accept-connect-send-recv
+run_strace_merge -yy -eclose,network $args
 
-./inet-accept-connect-send-recv || {
-       if [ $? -eq 77 ]; then
-               framework_skip_ 'PF_INET SOCK_STREAM (CONFIG_INET_TCP_DIAG) is not available'
-       else
-               fail_ 'inet-accept-connect-send-recv failed'
-       fi
-}
+child="$(sed -rn '/SIGCHLD/ s/^.*, si_pid=([1-9][0-9]*), .*/\1/p' "$LOG")"
+[ -n "$child" ] ||
+       dump_log_and_fail_with 'failed to find pid of child process'
 
-./netlink_inet_diag || {
-       if [ $? -eq 77 ]; then
-               framework_skip_ 'NETLINK_INET_DIAG is not available'
-       else
-               fail_ 'netlink_inet_diag failed'
-       fi
-}
+rm -f "$LOG"-*
+sed -rn "/^$child"' /!d; / socket\(/,$ s/^[0-9]+ +[^ ]+ (.+)/\1/p' "$LOG" > "$LOG"-connect &&
+sed -rn "/^$child"' /d; /SIGCHLD/d; / socket\(/,$ s/^[0-9]+ +[^ ]+ (.+)/\1/p' "$LOG" > "$LOG"-accept ||
+       dump_log_and_fail_with 'failed to separate logs'
 
-args="-tt -ff -yy -o $LOG -eclose,network ./inet-accept-connect-send-recv"
-$STRACE $args ||
-       fail_ "strace $args failed"
-
-"$srcdir"/../strace-log-merge $LOG > $LOG || {
-       cat $LOG
-       fail_ 'strace-log-merge failed'
-}
-rm -f $LOG.*
-
-child="$(sed -rn '/SIGCHLD/ s/^.*, si_pid=([1-9][0-9]*), .*/\1/p' $LOG)"
-[ -n "$child" ] || {
-       cat $LOG
-       fail_ 'failed to find pid of child process'
-}
-
-sed -rn "/^$child"' /!d; / socket\(/,$ s/^[0-9]+ +[^ ]+ (.+)/\1/p' $LOG > $LOG-connect &&
-sed -rn "/^$child"' /d; /SIGCHLD/d; / socket\(/,$ s/^[0-9]+ +[^ ]+ (.+)/\1/p' $LOG > $LOG-accept || {
-       cat $LOG
-       fail_ 'failed to separate logs'
-}
-
-awk -f "$srcdir"/net-yy-connect.awk $LOG-connect || {
-       cat $LOG-connect
-       fail_ "strace $args failed to decode socket descriptors properly"
-}
-
-awk -f "$srcdir"/net-yy-accept.awk $LOG-accept || {
-       cat $LOG-accept
-       fail_ "strace $args failed to decode socket descriptors properly"
-}
+match_awk "$LOG-connect" "$srcdir"/net-yy-connect.awk "$STRACE $args connect output mismatch"
+match_awk "$LOG-accept" "$srcdir"/net-yy-accept.awk "$STRACE $args accept output mismatch"
 
 exit 0
diff --git a/tests/net.expected b/tests/net.expected
new file mode 100755 (executable)
index 0000000..af92922
--- /dev/null
@@ -0,0 +1,7 @@
+[1-9][0-9]* +[0-9]+:[0-9]+:[0-9]+\.[0-9]+ +socket\(PF_(LOCAL|UNIX|FILE), SOCK_STREAM, 0\) += 0
+[1-9][0-9]* +[0-9]+:[0-9]+:[0-9]+\.[0-9]+ +socket\(PF_(LOCAL|UNIX|FILE), SOCK_STREAM, 0\) += 1
+[1-9][0-9]* +[0-9]+:[0-9]+:[0-9]+\.[0-9]+ +bind\(0, \{sa_family=AF_(LOCAL|UNIX|FILE), sun_path="net-local-stream"\}, 19\) += 0
+[1-9][0-9]* +[0-9]+:[0-9]+:[0-9]+\.[0-9]+ +listen\(0, 5\) += 0
+[1-9][0-9]* +[0-9]+:[0-9]+:[0-9]+\.[0-9]+ +getsockname\(0, \{sa_family=AF_(LOCAL|UNIX|FILE), sun_path="net-local-stream"\}, \[19\]\) += 0
+[1-9][0-9]* +[0-9]+:[0-9]+:[0-9]+\.[0-9]+ +accept\(0, \{sa_family=AF_(LOCAL|UNIX|FILE), NULL\}, \[2\]\) += 1
+[1-9][0-9]* +[0-9]+:[0-9]+:[0-9]+\.[0-9]+ +connect\(1, \{sa_family=AF_(LOCAL|UNIX|FILE), sun_path="net-local-stream"\}, 19\) += 0
index c0072713b3fabcb88788815e37bf45fc2b7ed9e7..cf943ffaafc84961aa72566c2f3410d31214ffca 100755 (executable)
@@ -4,42 +4,8 @@
 
 . "${srcdir=.}/init.sh"
 
-check_prog grep
-
-rm -f $LOG.*
-
-addr=net-local-stream
-./net-accept-connect $addr ||
-       fail_ 'net-accept-connect failed'
-
-args="-tt -ff -enetwork ./net-accept-connect $addr"
-$STRACE -o "$LOG" $args ||
-       fail_ "$STRACE $args failed"
-
-"$srcdir"/../strace-log-merge $LOG > $LOG || {
-       cat $LOG
-       fail_ 'strace-log-merge failed'
-}
-
-rm -f $LOG.*
-
-grep_log()
-{
-       local syscall="$1"; shift
-       local prefix='[1-9][0-9]* +[0-9]+:[0-9]+:[0-9]+\.[0-9]+ +'
-
-       LC_ALL=C grep -E -x "$prefix$syscall$*" $LOG > /dev/null || {
-               cat $LOG
-               fail_ "strace -enetwork failed to trace \"$syscall\" properly"
-       }
-}
-
-grep_log socket '\(PF_(LOCAL|UNIX|FILE), SOCK_STREAM, 0\) += 0'
-grep_log socket '\(PF_(LOCAL|UNIX|FILE), SOCK_STREAM, 0\) += 1'
-grep_log bind '\(0, \{sa_family=AF_(LOCAL|UNIX|FILE), sun_path="'$addr'"\}, 19\) += 0'
-grep_log listen '\(0, 5\) += 0'
-grep_log getsockname '\(0, \{sa_family=AF_(LOCAL|UNIX|FILE), sun_path="'$addr'"\}, \[19\]\) += 0'
-grep_log accept '\(0, \{sa_family=AF_(LOCAL|UNIX|FILE), NULL\}, \[2\]\) += 1'
-grep_log connect '\(1, \{sa_family=AF_(LOCAL|UNIX|FILE), sun_path="'$addr'"\}, 19\) += 0'
+run_prog ./net-accept-connect net-local-stream
+run_strace_merge -enetwork $args
+match_grep
 
 exit 0
index a8537a2507be168f12b1e6c4811c3994feee141d..022daccf72cda2958e5f7a4af7b822ccce9d6819 100755 (executable)
@@ -4,18 +4,13 @@
 
 . "${srcdir=.}/init.sh"
 
-check_prog grep
+check_prog sed
 
-OUT="$LOG.out"
+run_prog > /dev/null
 
-./pc > /dev/null ||
-       framework_skip_ 'munmap/fork/wait do not behave as expected'
-
-args="-if ./pc"
-$STRACE $args > "$OUT" 2> "$LOG" || {
-       cat "$LOG"
-       fail_ "$STRACE $args does not work"
-}
+args="-if $args"
+$STRACE $args 2> "$LOG" ||
+       dump_log_and_fail_with "$STRACE $args failed"
 
 len="$(sed -n 's/^\[[[:xdigit:]]\+\] write(-1, NULL, \([[:digit:]]\{1,2\}\))[[:space:]]\+= -1 .*/\1/p' "$LOG")" &&
 [ -n "$len" ] &&
@@ -24,24 +19,18 @@ pid="$(sed -n 's/^\[[[:xdigit:]]\{'"$len"'\}\] --- SIGCHLD {si_signo=SIGCHLD, si
 ip="$(sed -n 's/^\[pid \+'"$pid"'\] \[\([[:xdigit:]]\{'"$len"'\}\)] --- SIGSEGV {.*} ---$/\1/p' "$LOG")" &&
 [ -n "$ip" ] &&
 addr="$(echo "$ip" |sed 's/^0\+//')" &&
-[ -n "$addr" ] || {
-       cat "$OUT" "$LOG"
-       fail_ "$STRACE $args output mismatch"
-}
-
-grep_log()
-{
-       LC_ALL=C grep -x -e "$*" < "$LOG" > /dev/null || {
-               cat "$OUT" "$LOG"
-               fail_ "$STRACE $args output mismatch"
-       }
-}
-
-grep_log '\[[[:xdigit:]]\{'"$len"'\}\] munmap(0x[[:xdigit:]]\+, 0)[[:space:]]\+= -1 .*'
-grep_log '\[pid \+'"$pid"'\] \['"$ip"'\] --- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0x'"$addr"'} ---'
-grep_log '\[pid \+'"$pid"'\] \[?\{'"$len"'\}\] +++ killed by SIGSEGV\( (core dumped)\)\? +++'
-grep_log '\[?\{'"$len"'\}\] +++ exited with 0 +++'
-
-rm -f "$OUT"
+[ -n "$addr" ] ||
+       dump_log_and_fail_with
+
+EXPECTED="$LOG.expected"
+cat > "$EXPECTED" << __EOF__
+\\[[[:xdigit:]]{$len}\\] munmap\\(0x[[:xdigit:]]+, 0\\) += -1 .*
+\\[pid +$pid\\] \\[$ip\\] --- SIGSEGV \\{si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0x$addr\\} ---
+\\[pid +$pid\\] \\[\\?{$len}\\] \\+\\+\\+ killed by SIGSEGV( \\(core dumped\\))? \\+\\+\\+
+\\[\\?{$len}\\] \\+\\+\\+ exited with 0 \\+\\+\\+
+__EOF__
+
+match_grep "$LOG" "$EXPECTED"
+rm -f "$EXPECTED"
 
 exit 0
index 652fcdb30deadb17067ffa96319e2b5fec252e97..1aff1cc0f7f98135d3789ff52c3d8b0eb17553d3 100755 (executable)
@@ -5,21 +5,21 @@
 . "${srcdir=.}/init.sh"
 
 check_prog ls
-check_prog grep
+run_strace -e execve ls
 
-$STRACE -e execve ls > /dev/null 2> $LOG &&
-grep '^execve(' $LOG > /dev/null ||
-       { cat $LOG; fail_ 'strace -e execve does not work'; }
+grep '^execve(' "$LOG" > /dev/null ||
+       dump_log_and_fail_with "$STRACE $args output mismatch"
 
-grep -v '^execve(' $LOG |
+grep -v '^execve(' "$LOG" |
 LC_ALL=C grep '^[[:alnum:]_]*(' > /dev/null &&
-       { cat $LOG; fail_ 'strace -e execve does not work properly'; }
+       dump_log_and_fail_with "$STRACE $args unexpected output"
 
-$STRACE -e trace=process ls > /dev/null 2> $LOG &&
-grep '^execve(' $LOG > /dev/null ||
-       { cat $LOG; fail_ 'strace -e trace=process does not work'; }
+run_strace -e trace=process ls
 
-grep '^open' $LOG > /dev/null &&
-       { cat $LOG; fail_ 'strace -e trace=process does not work properly'; }
+grep '^execve(' "$LOG" > /dev/null ||
+       dump_log_and_fail_with "$STRACE $args output mismatch"
+
+grep '^open' "$LOG" > /dev/null &&
+       dump_log_and_fail_with "$STRACE $args unexpected output"
 
 exit 0
index 1974e0d58b8ef04def531c845d6daafeb86d9927..62e7c0dedfddb7231bc716252975c8f9aefc2e90 100755 (executable)
@@ -8,15 +8,13 @@
 [ -d /proc/self/fd/ ] ||
        framework_skip_ '/proc/self/fd/ is not available'
 
-check_prog grep
 check_prog mkdir
 check_prog rm
 check_prog seq
 check_prog touch
 
-rm -rf -- "$LOG".*
-
 dir="$LOG.dir"
+rm -rf -- "$dir"
 mkdir -- "$dir" ||
        framework_skip_ 'failed to create a directory'
 
@@ -25,36 +23,23 @@ file="$dir/$(for i in $(seq 1 127); do echo A; done; echo Z)"
 touch -- "$file" ||
        framework_skip_ 'failed to create a file'
 
-./scm_rights /dev/zero ||
-       fail_ 'scm_rights failed'
-
-args="-tt -ff -y -x -enetwork ./scm_rights /dev/zero"
-$STRACE -o "$LOG" $args "$file" ||
-       fail_ "$STRACE $args failed"
-
-"$srcdir"/../strace-log-merge "$LOG" > "$LOG" || {
-       cat $LOG
-       fail_ 'strace-log-merge failed'
-}
-
-rm -rf -- "$LOG".*
-
-grep_log()
-{
-       local syscall="$1"; shift
-       local prefix='[1-9][0-9]* +[0-9]+:[0-9]+:[0-9]+\.[0-9]+ +'
-
-       LC_ALL=C grep -E -x "$prefix$syscall$*" $LOG > /dev/null || {
-               cat $LOG
-               fail_ "$STRACE $args failed to trace \"$syscall\" properly"
-       }
-}
+run_prog ./scm_rights /dev/zero
+run_strace_merge -y -x -enetwork $args "$file"
 
 n='[1-9][0-9]*'
 msg='\{msg_name\(0\)=NULL, msg_iov\(1\)=\[\{"\\x00\\x00\\x00\\x00[^"]*", '"$n"'\}\], msg_controllen='"$n"
 rights='\{cmsg_len='"$n"', cmsg_level=SOL_SOCKET, cmsg_type=SCM_RIGHTS, \[3</dev/null>, 4</dev/zero>, 5</[^}>]*/(A\\n){127}Z>\]\}'
 creds='\{cmsg_len='"$n"', cmsg_level=SOL_SOCKET, cmsg_type=SCM_CREDENTIALS, \{pid='"$n"', uid=[0-9]+, gid=[0-9]+\}\}'
-grep_log sendmsg '\(1<socket:\[[0-9]+\]>, '"$msg"', \['"$rights"'\], msg_flags=0\}, 0\) += '"$n"
-grep_log recvmsg '\(0<socket:\[[0-9]+\]>, '"$msg"', \['"$creds"', '"$rights"'\], msg_flags=0\}, 0\) += '"$n"
+prefix='[1-9][0-9]* +[0-9]+:[0-9]+:[0-9]+\.[0-9]+ +'
+EXPECTED="$LOG.expected"
+
+cat > "$EXPECTED" << __EOF__
+${prefix}sendmsg\\(1<socket:\\[[0-9]+\\]>, $msg, \\[$rights\\], msg_flags=0\\}, 0\\) += $n
+${prefix}recvmsg\\(0<socket:\\[[0-9]+\\]>, $msg, \\[$creds, $rights\\], msg_flags=0\\}, 0\\) += $n
+__EOF__
+
+match_grep "$LOG" "$EXPECTED"
+rm -f "$EXPECTED"
+rm -rf -- "$dir"
 
 exit 0
index 5d5fe54acee73cba8f20a4b41c5c8c587bfba558..52b9f170fab750a2eebb6b75d55050f6cc1c253e 100755 (executable)
@@ -4,26 +4,14 @@
 
 . "${srcdir=.}/init.sh"
 
-check_prog awk
-
 syscall=
 $STRACE -epselect6 -h > /dev/null && syscall=$syscall,pselect6
 $STRACE -eselect -h > /dev/null && syscall=$syscall,select
 test -n "$syscall" ||
-       skip_ 'select syscall is not supported on this architecture'
-
-./select ||
-       framework_skip_ 'select syscall does not behave as expected'
-
-args="-e$syscall ./select"
-$STRACE -o "$LOG" $args || {
-       cat "$LOG"
-       fail_ "$STRACE $args failed"
-}
+       fail_ 'neither select not pselect6 syscall is supported on this architecture'
 
-awk -f "$srcdir"/select.awk "$LOG" || {
-       cat "$LOG"
-       fail_ 'unexpected output'
-}
+run_prog
+run_strace -e$syscall $args
+match_awk
 
 exit 0
index 33732e02e150b0ce081aad98f1361bf44977f8c9..fcde3bafab1451092067295e663260ba64172e95 100755 (executable)
@@ -4,16 +4,8 @@
 
 . "${srcdir=.}/init.sh"
 
-check_prog awk
-
-./sigaction ||
-       fail_ 'sigaction failed'
-
-args="-o $LOG -ert_sigaction ./sigaction"
-$STRACE $args ||
-       fail_ "strace $args failed"
-
-awk -f "$srcdir"/sigaction.awk $LOG ||
-       { cat $LOG; fail_ 'unexpected output'; }
+run_prog
+run_strace -ert_sigaction $args
+match_awk
 
 exit 0
index 1e96eded981b66a17a46bd9185c1b3ba168115a3..8cf636a88fa82d8429d760f85187add4e484c684 100755 (executable)
@@ -4,28 +4,20 @@
 
 . "${srcdir=.}/init.sh"
 
-check_prog grep
-
-./sigreturn ||
-       fail_ 'sigreturn failed'
-
-args='-esignal ./sigreturn'
-$STRACE -o "$LOG" $args ||
-       fail_ "$STRACE $args does not work"
-
-grep_log()
-{
-       LC_ALL=C grep -E -x -e "$*" < "$LOG" > /dev/null || {
-               cat "$LOG"
-               fail_ "$STRACE $args output mismatch"
-       }
-}
+run_prog
+run_strace -esignal $args
 
 mask='\[(USR2 CHLD|CHLD USR2) RT_2 RT_3 RT_4 RT_26 RT_27\]'
 rt_sigprocmask='rt_sigprocmask\(SIG_SETMASK, '"$mask"', NULL, [[:digit:]]+\) += 0'
 osf_sigprocmask='osf_sigprocmask\(SIG_SETMASK, '"$mask"'\) += 0 +\(old mask \[[^]]*\]\)'
-grep_log "$rt_sigprocmask|$osf_sigprocmask"
-grep_log '(rt_)?sigreturn\((\{mask='"$mask"'\})?\) += 0'
+EXPECTED="$LOG.expected"
+
+cat > "$EXPECTED" << __EOF__
+$rt_sigprocmask|$osf_sigprocmask
+(rt_)?sigreturn\\((\\{mask=$mask\\})?\\) += 0
+__EOF__
 
+match_grep "$LOG" "$EXPECTED"
+rm -f "$EXPECTED"
 
 exit 0
index ef57396e4328feebb6fe9b202286f8b9aa91cd0d..3e1790a4f60f55f6230ad295b1504e1328f7feac 100755 (executable)
@@ -6,74 +6,56 @@
 
 check_prog dd
 check_prog find
-check_prog grep
 
-OUT="$LOG.out"
+EXPECTED="$LOG.expected"
 size=46118400000
 sample=stat_sample
 
 rm -f $sample
 umask 022
 
-truncate_cmd="dd seek=$size bs=1 count=0 if=/dev/null of=$sample"
-$truncate_cmd > "$OUT" 2>&1 || {
-       cat "$OUT"
-       framework_skip_ 'failed to create a large sparse file'
-}
-
-find_cmd="find $sample -quit"
-$find_cmd || framework_skip_ "$find_cmd failed"
-
-find_L_cmd="find -L $sample -quit"
-$find_L_cmd || framework_skip_ "$find_L_cmd failed"
-
-rm -f $sample
-
-$STRACE -o "$LOG" -edesc $truncate_cmd 2>&1 > "$OUT" 2>&1 || {
-       cat "$LOG" "$OUT"
-       fail_ "$STRACE -edesc $truncate_cmd failed"
-}
-
-rm -f "$OUT"
+run_prog_skip_if_failed \
+       dd seek=$size bs=1 count=0 if=/dev/null of=$sample
+run_strace -edesc $args
 
 r_ftruncate="ftruncate(64)?\\(1, $size\\) += 0"
-LC_ALL=C grep -E -x "$r_ftruncate" "$LOG" > /dev/null || {
-       cat "$LOG"
-       fail_ 'strace -edesc failed to trace ftruncate/ftruncate64 properly'
-}
-
 r_lseek="lseek\\(1, $size, SEEK_CUR\\) += $size"
 r_llseek="_llseek\\(1, $size, \\[$size\\], SEEK_CUR\\) += 0"
-LC_ALL=C grep -E -x "$r_lseek|$r_llseek" "$LOG" > /dev/null || {
-       cat "$LOG"
-       fail_ 'strace -edesc failed to trace lseek/_llseek properly'
-}
 
-$STRACE -o "$LOG" -efile $find_L_cmd || {
-       cat "$LOG"
-       fail_ "$STRACE -efile $find_L_cmd failed"
-}
+cat > "$EXPECTED" << __EOF__
+$r_ftruncate
+$r_lseek|$r_llseek
+__EOF__
+
+match_grep "$LOG" "$EXPECTED"
+
+run_prog_skip_if_failed \
+       find -L $sample -quit
+run_strace -efile $args
 
 stat="\\{st_mode=S_IFREG\\|0644, st_size=$size, \\.\\.\\.\\}"
 r_stat="stat(64)?\\(\"$sample\", $stat\\) += 0"
 r_fstatat="(new)?fstatat(64)?\\(AT_FDCWD, \"$sample\", $stat, 0\\) += 0"
-LC_ALL=C grep -E -x "$r_stat|$r_fstatat" "$LOG" > /dev/null || {
-       cat "$LOG"
-       fail_ 'strace -efile failed to trace stat/stat64 properly'
-}
 
-$STRACE -o "$LOG" -efile $find_cmd || {
-       cat "$LOG"
-       fail_ "$STRACE -efile $find_cmd failed"
-}
+cat > "$EXPECTED" << __EOF__
+$r_stat|$r_fstatat
+__EOF__
+
+match_grep "$LOG" "$EXPECTED"
+
+run_prog_skip_if_failed \
+       find $sample -quit
+run_strace -efile $args
 
 r_lstat="lstat(64)?\\(\"$sample\", $stat\\) += 0"
 r_lfstatat="(new)?fstatat(64)?\\(AT_FDCWD, \"$sample\", $stat, AT_SYMLINK_NOFOLLOW\\) += 0"
-LC_ALL=C grep -E -x "$r_lstat|$r_lfstatat" "$LOG" > /dev/null || {
-       cat "$LOG"
-       fail_ 'strace -efile failed to trace fstatat/fstatat64 properly'
-}
 
-rm -f $sample
+cat > "$EXPECTED" << __EOF__
+$r_lstat|$r_lfstatat
+__EOF__
+
+match_grep "$LOG" "$EXPECTED"
+
+rm -f "$EXPECTED" $sample
 
 exit 0
index 67eb5edcad7e4605894ae215b03b57f4267acf20..46e49f44e26e17e18dc53ebfc52d8f5b2eec8fd9 100755 (executable)
@@ -4,8 +4,9 @@
 
 . "${srcdir=.}/init.sh"
 
+run_prog ./stat32 . > /dev/null
+
 check_prog dd
-check_prog grep
 check_prog touch
 
 OUT="$LOG.out"
@@ -13,32 +14,15 @@ size=233811181
 sample=stat32_sample
 
 umask 022
-truncate_cmd="dd seek=$size bs=1 count=0 if=/dev/null of=$sample"
-$truncate_cmd > "$OUT" 2>&1 || {
-       cat "$OUT"
-       framework_skip_ 'failed to create a large sparse file'
-}
-
-./stat32 $sample > /dev/null || {
-       if [ $? -eq 77 ]; then
-               rm -f $sample "$OUT"
-               framework_skip_ '32-bit stat syscall is not available'
-       else
-               fail_ 'stat32 failed'
-       fi
-}
-
-touch -t 0102030405 $sample
+run_prog_skip_if_failed \
+       dd seek=$size bs=1 count=0 if=/dev/null of=$sample
+
+run_prog_skip_if_failed \
+       touch -t 0102030405 $sample
 
 for f in $sample . /dev/null; do
-       args="-v -efile ./stat32 $f"
-       $STRACE -o "$LOG" $args > "$OUT" &&
-       exp_lines=$(wc -l < "$OUT") &&
-       matched_lines=$(LC_ALL=C grep -c -E -x -f "$OUT" "$LOG") &&
-       test $exp_lines -eq $matched_lines || {
-               cat "$OUT" "$LOG"
-               fail_ "$STRACE $args output mismatch"
-       }
+       run_strace -v -efile ./stat32 $f > "$OUT"
+       match_grep "$LOG" "$OUT"
 done
 
 rm -f $sample "$OUT"
index 785403dc1b468c24b6e831ef3fa18bd52b193352..a8122f01219806e3d11a5b5127752b660910eeba 100755 (executable)
@@ -4,8 +4,9 @@
 
 . "${srcdir=.}/init.sh"
 
+run_prog ./stat . > /dev/null
+
 check_prog dd
-check_prog grep
 check_prog touch
 
 OUT="$LOG.out"
@@ -13,26 +14,15 @@ size=46118400000
 sample=stat64_sample
 
 umask 022
-truncate_cmd="dd seek=$size bs=1 count=0 if=/dev/null of=$sample"
-$truncate_cmd > "$OUT" 2>&1 || {
-       cat "$OUT"
-       framework_skip_ 'failed to create a large sparse file'
-}
-
-./stat $sample > /dev/null ||
-       fail_ 'stat failed'
+run_prog_skip_if_failed \
+       dd seek=$size bs=1 count=0 if=/dev/null of=$sample
 
-touch -d '1970-01-01 -42 seconds' $sample
+run_prog_skip_if_failed \
+       touch -d '1970-01-01 -42 seconds' $sample
 
 for f in $sample . /dev/null; do
-       args="-v -efile ./stat $f"
-       $STRACE -o "$LOG" $args > "$OUT" &&
-       exp_lines=$(wc -l < "$OUT") &&
-       matched_lines=$(LC_ALL=C grep -c -E -x -f "$OUT" "$LOG") &&
-       test $exp_lines -eq $matched_lines || {
-               cat "$OUT" "$LOG"
-               fail_ "$STRACE $args output mismatch"
-       }
+       run_strace -v -efile ./stat $f > "$OUT"
+       match_grep "$LOG" "$OUT"
 done
 
 rm -f $sample "$OUT"
diff --git a/tests/statfs.expected b/tests/statfs.expected
new file mode 100755 (executable)
index 0000000..93e2b51
--- /dev/null
@@ -0,0 +1 @@
+statfs(64)?\("/proc/self/status"(, [1-9][0-9]*)?, \{f_type="PROC_SUPER_MAGIC", f_bsize=[1-9][0-9]*, f_blocks=[0-9]+, f_bfree=[0-9]+, f_bavail=[0-9]+, f_files=[0-9]+, f_ffree=[0-9]+, f_fsid=\{[0-9]+, [0-9]+\}, f_namelen=[1-9][0-9]*(, f_frsize=[0-9]+)?(, f_flags=[0-9]+)?\}\) += 0
index 5b8cc972a7d410142c45a872656c9b15b83b37ac..214d52108a9f8aa2d1a8a47adbe907999555b03e 100755 (executable)
@@ -4,31 +4,12 @@
 
 . "${srcdir=.}/init.sh"
 
-check_prog grep
-
 # this test probes /proc/self/status
 [ -f /proc/self/status ] ||
         framework_skip_ '/proc/self/status is not available'
 
-./statfs ||
-       fail_ 'statfs failed'
-
-args="-efile ./statfs"
-$STRACE $args > $LOG 2>&1 || {
-       cat $LOG
-       fail_ "$STRACE $args failed"
-}
-
-grep_log()
-{
-       local syscall="$1"; shift
-
-       LC_ALL=C grep -E -x "$syscall$*" $LOG > /dev/null || {
-               cat $LOG
-               fail_ "$STRACE $args failed to trace \"$syscall\" properly"
-       }
-}
-
-grep_log 'statfs(64)?' '\("/proc/self/status"(, [1-9][0-9]*)?, \{f_type="PROC_SUPER_MAGIC", f_bsize=[1-9][0-9]*, f_blocks=[0-9]+, f_bfree=[0-9]+, f_bavail=[0-9]+, f_files=[0-9]+, f_ffree=[0-9]+, f_fsid=\{[0-9]+, [0-9]+\}, f_namelen=[1-9][0-9]*(, f_frsize=[0-9]+)?(, f_flags=[0-9]+)?\}\) += 0'
+run_prog
+run_strace -efile $args
+match_grep
 
 exit 0
index 0c4622c5e0a851a04ea4ff2ab0c7607a34a40c13..7b5a6c2f0682101363362cdf936c56580c27818d 100755 (executable)
@@ -6,6 +6,5 @@
 
 time=/usr/bin/time
 check_prog $time
-
-$STRACE -f $time /bin/ls > $LOG 2>&1 ||
-       { cat $LOG; fail_ 'strace -f does not work'; }
+check_prog ls
+run_strace -f $time ls > /dev/null
index f757fb91be573818c444f47c61e25eb57aed41ba..90d56dc2a6e4b2b64ddc6772e739a1fbe0c54e83 100755 (executable)
@@ -4,6 +4,9 @@
 
 . "${srcdir=.}/init.sh"
 
+$STRACE -h | grep '^-k' > /dev/null ||
+       skip_ 'strace -k is not available'
+
 # strace -k is implemented using /proc/$pid/maps
 [ -f /proc/self/maps ] ||
        framework_skip_ '/proc/self/maps is not available'
 check_prog sed
 check_prog tr
 
-./stack-fcall ||
-       fail_ 'stack-fcall failed'
-
-$STRACE -h | grep '^-k' > /dev/null ||
-       skip_ 'strace -k is not available'
-
-args="-e getpid -k ./stack-fcall"
-$STRACE $args > $LOG 2>&1 || {
-       cat $LOG
-       fail_ "$STRACE $args failed"
-}
+run_prog ./stack-fcall
+run_strace -e getpid -k $args
 
 expected='getpid f3 f2 f1 f0 main '
-result=$(sed -n '1,/(main+0x[a-f0-9]\+) .*/ s/^.*(\([^+]\+\)+0x[a-f0-9]\+) .*/\1/p' $LOG |
+result=$(sed -n '1,/(main+0x[a-f0-9]\+) .*/ s/^.*(\([^+]\+\)+0x[a-f0-9]\+) .*/\1/p' "$LOG" |
        tr '\n' ' ')
 
 test "$result" = "$expected" || {
-       cat $LOG
        echo "expected: \"$expected\""
        echo "result: \"$result\""
-       fail_ "unexpected output from $STRACE $args"
+       dump_log_and_fail_with "$STRACE $args output mismatch"
 }
 
 exit 0
diff --git a/tests/sun_path.expected b/tests/sun_path.expected
new file mode 100755 (executable)
index 0000000..4407686
--- /dev/null
@@ -0,0 +1,3 @@
+[1-9][0-9]* +[0-9]+:[0-9]+:[0-9]+\.[0-9]+ +bind\(0, \{sa_family=AF_(LOCAL|UNIX|FILE), sun_path="123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678"\}, 110\) += 0
+[1-9][0-9]* +[0-9]+:[0-9]+:[0-9]+\.[0-9]+ +getsockname\(0, \{sa_family=AF_(LOCAL|UNIX|FILE), sun_path="123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678"\}, \[111\]\) += 0
+[1-9][0-9]* +[0-9]+:[0-9]+:[0-9]+\.[0-9]+ +connect\(1, \{sa_family=AF_(LOCAL|UNIX|FILE), sun_path="123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678"\}, 110\) += 0
index 6ae67f453de95052022bde159f44c41e7ef5f49e..728328a84fc9288efb234c75fcfd1955e0241ac2 100755 (executable)
@@ -4,38 +4,8 @@
 
 . "${srcdir=.}/init.sh"
 
-check_prog grep
-
-rm -f $LOG.*
-
-addr=123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
-./net-accept-connect $addr ||
-       fail_ 'net-accept-connect failed'
-
-args="-tt -ff -ebind,connect,getsockname ./net-accept-connect $addr"
-$STRACE -o "$LOG" $args ||
-       fail_ "$STRACE $args failed"
-
-"$srcdir"/../strace-log-merge $LOG > $LOG || {
-       cat $LOG
-       fail_ 'strace-log-merge failed'
-}
-
-rm -f $LOG.*
-
-grep_log()
-{
-       local syscall="$1"; shift
-       local prefix='[1-9][0-9]* +[0-9]+:[0-9]+:[0-9]+\.[0-9]+ +'
-
-       LC_ALL=C grep -E -x "$prefix$syscall$*" $LOG > /dev/null || {
-               cat $LOG
-               fail_ "strace -enetwork failed to trace \"$syscall\" properly"
-       }
-}
-
-grep_log bind '\(0, \{sa_family=AF_(LOCAL|UNIX|FILE), sun_path="'$addr'"\}, 110\) += 0'
-grep_log getsockname '\(0, \{sa_family=AF_(LOCAL|UNIX|FILE), sun_path="'$addr'"\}, \[111\]\) += 0'
-grep_log connect '\(1, \{sa_family=AF_(LOCAL|UNIX|FILE), sun_path="'$addr'"\}, 110\) += 0'
+run_prog ./net-accept-connect 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+run_strace_merge -ebind,connect,getsockname $args
+match_grep
 
 exit 0
index d8b026127dce663b5c9d8ee894c57ffcc7b6a31f..7bbcca7b80574979df60bdbed9116bd2627777bb 100755 (executable)
@@ -4,29 +4,15 @@
 
 . "${srcdir=.}/init.sh"
 
-check_prog gawk
-
 s="${uid_syscall_suffix-}"
 w="${uid_t_size-}"
-uid="uid$s$w"
-./"$uid" || {
-       if [ $? -eq 77 ]; then
-               framework_skip_ "some uid$s or uid${w}_t syscalls are not available"
-       else
-               fail_ "$uid failed"
-       fi
-}
+
+run_prog ./uid$s$w
 
 syscalls="getuid$s,setuid$s,getresuid$s,setreuid$s,setresuid$s,fchown$s,getgroups$s"
-args="-e trace=$syscalls"
-$STRACE -o "$LOG" $args ./"$uid"|| {
-       cat "$LOG"
-       fail_ "$STRACE $args ./$uid failed"
-}
+run_strace -e trace="$syscalls" $args
 
-gawk -f "$srcdir"/uid.awk -v suffix="$s" "$LOG" || {
-       cat "$LOG"
-       fail_ 'unexpected output'
-}
+AWK=gawk
+match_awk "$LOG" "$srcdir"/uid.awk "$STRACE $args output mismatch" -v suffix="$s"
 
 exit 0
diff --git a/tests/uio.expected b/tests/uio.expected
new file mode 100755 (executable)
index 0000000..999b88c
--- /dev/null
@@ -0,0 +1,4 @@
+pread(64)?\(3, "\\0\\0\\0\\0", 4, 1004211379570065135\) += 4
+preadv\(3, \[{"\\0\\0\\0\\0", 4}\], 1, 1004211379570065135\) += 4
+pwrite(64)?\(3, "\\0\\0\\0\\0", 4, 1004211379570065135\) += 4
+pwritev\(3, \[{"\\0\\0\\0\\0", 4}\], 1, 1004211379570065135\) += 4
index 0e8b31550cccc966588937ed44f81ff5800d039b..020b97e95424ef3cc2e9c958699e1489a46537ff 100755 (executable)
@@ -4,35 +4,8 @@
 
 . "${srcdir=.}/init.sh"
 
-check_prog grep
-
-./uio || {
-       if [ $? -eq 77 ]; then
-               framework_skip_ 'preadv/pwritev syscalls are not available'
-       else
-               fail_ 'uio failed'
-       fi
-}
-
-args="-edesc ./uio"
-$STRACE $args > $LOG 2>&1 || {
-       cat $LOG
-       fail_ "$STRACE $args failed"
-}
-
-grep_log()
-{
-       local syscall="$1"; shift
-
-       LC_ALL=C grep -E -x "$syscall$*" $LOG > /dev/null || {
-               cat $LOG
-               fail_ "$STRACE $args failed to trace \"$syscall\" properly"
-       }
-}
-
-grep_log 'pread(64)?' '\(3, "\\0\\0\\0\\0", 4, 1004211379570065135\) += 4'
-grep_log 'preadv' '\(3, \[{"\\0\\0\\0\\0", 4}\], 1, 1004211379570065135\) += 4'
-grep_log 'pwrite(64)?' '\(3, "\\0\\0\\0\\0", 4, 1004211379570065135\) += 4'
-grep_log 'pwritev' '\(3, \[{"\\0\\0\\0\\0", 4}\], 1, 1004211379570065135\) += 4'
+run_prog
+run_strace -edesc $args
+match_grep
 
 exit 0
index 1845f557ab5d163799499c9d5953e084d6c3c984..640b47752839052e388026b1a64cee1d467df1e1 100755 (executable)
@@ -9,53 +9,23 @@
 [ -d /proc/self/fd/ ] ||
        framework_skip_ '/proc/self/fd/ is not available'
 
-check_prog awk
 check_prog sed
 
-rm -f $LOG.* $LOG-*
-
+run_prog ./netlink_unix_diag
 addr=unix-yy-local-stream
-./net-accept-connect $addr ||
-       fail_ 'net-accept-connect failed'
-
-./netlink_unix_diag || {
-       if [ $? -eq 77 ]; then
-               framework_skip_ 'NETLINK_SOCK_DIAG for unix domain sockets (CONFIG_UNIX_DIAG) is not available'
-       else
-               fail_ 'netlink_unix_diag failed'
-       fi
-}
-
-args="-tt -ff -yy -eclose,network ./net-accept-connect $addr"
-$STRACE -o "$LOG" $args ||
-       fail_ "$STRACE $args failed"
-
-"$srcdir"/../strace-log-merge $LOG > $LOG || {
-       cat $LOG
-       fail_ 'strace-log-merge failed'
-}
-rm -f $LOG.*
-
-child="$(sed -rn '/SIGCHLD/ s/^.*, si_pid=([1-9][0-9]*), .*/\1/p' $LOG)"
-[ -n "$child" ] || {
-       cat $LOG
-       fail_ 'failed to find pid of child process'
-}
-
-sed -rn "/^$child"' /!d; / socket\(/,$ s/^[0-9]+ +[^ ]+ (.+)/\1/p' $LOG > $LOG-connect &&
-sed -rn "/^$child"' /d; /SIGCHLD/d; / socket\(/,$ s/^[0-9]+ +[^ ]+ (.+)/\1/p' $LOG > $LOG-accept || {
-       cat $LOG
-       fail_ 'failed to separate logs'
-}
-
-awk -f "$srcdir"/unix-yy-connect.awk -v addr=$addr $LOG-connect || {
-       cat $LOG-connect
-       fail_ "strace $args failed to decode socket descriptors properly"
-}
-
-awk -f "$srcdir"/unix-yy-accept.awk -v addr=$addr $LOG-accept || {
-       cat $LOG-accept
-       fail_ "strace $args failed to decode socket descriptors properly"
-}
+run_prog ./net-accept-connect $addr
+run_strace_merge -yy -eclose,network $args
+
+child="$(sed -rn '/SIGCHLD/ s/^.*, si_pid=([1-9][0-9]*), .*/\1/p' "$LOG")"
+[ -n "$child" ] ||
+       dump_log_and_fail_with 'failed to find pid of child process'
+
+rm -f "$LOG"-*
+sed -rn "/^$child"' /!d; / socket\(/,$ s/^[0-9]+ +[^ ]+ (.+)/\1/p' "$LOG" > "$LOG"-connect &&
+sed -rn "/^$child"' /d; /SIGCHLD/d; / socket\(/,$ s/^[0-9]+ +[^ ]+ (.+)/\1/p' "$LOG" > "$LOG"-accept ||
+       dump_log_and_fail_with 'failed to separate logs'
+
+match_awk "$LOG-connect" "$srcdir"/unix-yy-connect.awk "$STRACE $args connect output mismatch" -v addr=$addr
+match_awk "$LOG-accept" "$srcdir"/unix-yy-accept.awk "$STRACE $args accept output mismatch" -v addr=$addr
 
 exit 0