[PATCH] unwind: add simple test case for testing -k

Masatake YAMATO yamato at redhat.com
Wed May 14 04:16:29 UTC 2014


tests/Makefile.am (check_PROGRAMS): Added stack-fcall
as a new test case.

tests/strace-k.test: New test driver file.

tests/stack-fcall.c: New test target file.

Signed-off-by: Masatake YAMATO <yamato at redhat.com>
---
 tests/Makefile.am   |  5 +++--
 tests/stack-fcall.c | 27 ++++++++++++++++++++++++++
 tests/strace-k.test | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 86 insertions(+), 2 deletions(-)
 create mode 100644 tests/stack-fcall.c
 create mode 100755 tests/strace-k.test

diff --git a/tests/Makefile.am b/tests/Makefile.am
index c63c41f..c3291e9 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -2,7 +2,7 @@
 
 AM_CFLAGS = $(WARN_CFLAGS)
 
-check_PROGRAMS = net-accept-connect set_ptracer_any sigaction uio
+check_PROGRAMS = net-accept-connect set_ptracer_any sigaction uio stack-fcall
 
 uio_CFLAGS = $(AM_CFLAGS) -D_FILE_OFFSET_BITS=64
 
@@ -17,7 +17,8 @@ TESTS = \
 	uio.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
index 0000000..3e6ffd4
--- /dev/null
+++ b/tests/stack-fcall.c
@@ -0,0 +1,27 @@
+#include <unistd.h>
+#include <sys/types.h>
+
+/* volatile is used to protect 'call' is converted to 'jump'
+   by gcc.
+   
+   I cannot find the way not to apply -O0 to this program 
+   in info doc of automake. */
+
+int f1(int dummy)
+{ 
+  static uid_t (* volatile g)(void) = getuid;
+  return g() + dummy;
+}
+
+int f0(volatile int dummy)
+{ 
+  static int (* volatile g) (int) = f1;
+  return g(dummy) - dummy;
+}
+
+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
index 0000000..3fd056e
--- /dev/null
+++ b/tests/strace-k.test
@@ -0,0 +1,56 @@
+#!/bin/sh
+
+# Ensure that strace -k works.
+
+. "${srcdir=.}/init.sh"
+
+check_prog head
+check_prog sed
+check_prog tr
+
+extract_symbols()
+{
+    local depth=$1
+    local log=$2
+    # INPUT:
+    # getuid()                                = 1000
+    # > /usr/lib64/libc-2.18.so(getuid+0x7) [0xbd857]
+    # > ./stack-fcall(f1+0xc) [0x55c]
+    # > ./stack-fcall(f0+0x15) [0x575]
+    # > ./stack-fcall(main+0xd) [0x45d]
+    # > /usr/lib64/libc-2.18.so(__libc_start_main+0xf5) [0x21d65]
+    # > ./stack-fcall(_start+0x29) [0x48d]
+    # +++ exited with 0 +++
+    # OUTPUT 4:
+    # getuid f1 f0 main
+
+    sed -n -e 's/^.*(\([^+]\+\)+0x[a-f0-9]\+).*/\1/p' "$log" \
+	| head -"$depth" \
+	| tr '\n' ' ' \
+	| sed -e 's/ *$//'
+}
+
+./stack-fcall ||
+	        fail_ 'stack-fcall failed'
+
+$STRACE -h | grep -e '^-k' || {
+	skip_ 'stack trace function is not available'
+	exit 0
+}
+
+args="-e getuid -k ./stack-fcall"
+$STRACE $args > $LOG 2>&1 || {
+	cat $LOG
+	fail_ "$STRACE $args failed"
+}
+
+result=$(extract_symbols 4 $LOG)
+expected="getuid f1 f0 main"
+test "$result" = "$expected" || {
+    cat $LOG
+    echo "expected: \"$expected\""
+    echo "result: \"$result\""
+    fail_ "unexpected output from $STRACE $args"
+}
+
+exit 0
-- 
1.9.0





More information about the Strace-devel mailing list