]> granicus.if.org Git - strace/commitdiff
unwind: tests: add a test for -k option
authorMasatake YAMATO <yamato@redhat.com>
Wed, 14 May 2014 04:16:29 +0000 (13:16 +0900)
committerDmitry V. Levin <ldv@altlinux.org>
Fri, 30 May 2014 22:59:27 +0000 (22:59 +0000)
* tests/stack-fcall.c: New test target.
* tests/strace-k.test: New test driver.
* tests/Makefile.am (check_PROGRAMS): Add stack-fcall.
(TESTS): Add strace-k.test.
* tests/.gitignore: Add stack-fcall.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
tests/.gitignore
tests/Makefile.am
tests/stack-fcall.c [new file with mode: 0644]
tests/strace-k.test [new file with mode: 0755]

index 7a87842d73f25e43839ff38f5541b4bdb12cdd2c..e22e556dab4f6fa92913213c8f9139137fb35f66 100644 (file)
@@ -2,6 +2,7 @@ net-accept-connect
 scm_rights
 set_ptracer_any
 sigaction
+stack-fcall
 uio
 *.log
 *.log.*
index b561ce3e4add14821bf3b5b68aae52c632478528..efe646db8847afdc11ea1346360296bae20770b9 100644 (file)
@@ -7,6 +7,7 @@ check_PROGRAMS = \
        scm_rights \
        set_ptracer_any \
        sigaction \
+       stack-fcall \
        uio
 
 uio_CFLAGS = $(AM_CFLAGS) -D_FILE_OFFSET_BITS=64
@@ -24,7 +25,8 @@ TESTS = \
        count.test \
        detach-sleeping.test \
        detach-stopped.test \
-       detach-running.test
+       detach-running.test \
+       strace-k.test
 
 net-fd.log: net.log
 
diff --git a/tests/stack-fcall.c b/tests/stack-fcall.c
new file mode 100644 (file)
index 0000000..04339b1
--- /dev/null
@@ -0,0 +1,23 @@
+#include <unistd.h>
+#include <sys/types.h>
+
+/* Use "volatile" to avoid compiler optimization. */
+
+int f1(int i)
+{
+       static uid_t (* volatile g)(void) = getuid;
+       return g() + i;
+}
+
+int f0(volatile int i)
+{
+       static int (* volatile g)(int) = f1;
+       return g(i) - i;
+}
+
+int main(int argc, char** argv)
+{
+       static int (* volatile g)(int) = f0;
+       g(argc);
+       return 0;
+}
diff --git a/tests/strace-k.test b/tests/strace-k.test
new file mode 100755 (executable)
index 0000000..329f302
--- /dev/null
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+# Ensure that strace -k works.
+
+. "${srcdir=.}/init.sh"
+
+# 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 getuid -k ./stack-fcall"
+$STRACE $args > $LOG 2>&1 || {
+       cat $LOG
+       fail_ "$STRACE $args failed"
+}
+
+expected='getuid f1 f0 main '
+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"
+}
+
+exit 0