summaryrefslogtreecommitdiffstats
path: root/testsuite
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/ChangeLog5
-rw-r--r--testsuite/systemtap.context/usymbols.c41
-rw-r--r--testsuite/systemtap.context/usymbols.exp69
3 files changed, 115 insertions, 0 deletions
diff --git a/testsuite/ChangeLog b/testsuite/ChangeLog
index 8e174efc..44261176 100644
--- a/testsuite/ChangeLog
+++ b/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2008-12-10 Mark Wielaard <mjw@redhat.com>
+
+ * systemtap.context/usymbols.c: New test program.
+ * systemtap.context/usymbols.exp: New dejagnu test.
+
2008-12-09 Frank Ch. Eigler <fche@elastic.org>
PR6961.
diff --git a/testsuite/systemtap.context/usymbols.c b/testsuite/systemtap.context/usymbols.c
new file mode 100644
index 00000000..f8ee05b5
--- /dev/null
+++ b/testsuite/systemtap.context/usymbols.c
@@ -0,0 +1,41 @@
+/* usymbol test case
+ * Copyright (C) 2008, Red Hat Inc.
+ *
+ * This file is part of systemtap, and is free software. You can
+ * redistribute it and/or modify it under the terms of the GNU General
+ * Public License (GPL); either version 2, or (at your option) any
+ * later version.
+ *
+ * Uses signal to tranfer user space addresses into the kernel where a
+ * probe on sigaction will extract them and produce the symbols. To
+ * poke into the executable we get the sa_handler, to poke into glibc
+ * we get the sa_restorer fields in the stap script.
+ *
+ * XXX - Seems sa_restorer isn't set on all architectures. should use
+ * our own shared library and set signal handler from there. Also
+ * need to handle @plt symbols (setting a handler in the main
+ * executable that is in a shared library will have the @plt address,
+ * not the address inside the shared library).
+ */
+
+#include <signal.h>
+typedef void (*sighandler_t)(int);
+
+void
+handler (int signum)
+{
+ /* dummy handler, just used for the address... */
+}
+
+sighandler_t
+libc_handler (void *func)
+{
+ return (sighandler_t) func;
+}
+
+int
+main (int argc, char *argv[], char *envp[])
+{
+ // Use SIGFPE since we never expect that to be triggered.
+ signal(SIGFPE, handler);
+}
diff --git a/testsuite/systemtap.context/usymbols.exp b/testsuite/systemtap.context/usymbols.exp
new file mode 100644
index 00000000..ebaa058e
--- /dev/null
+++ b/testsuite/systemtap.context/usymbols.exp
@@ -0,0 +1,69 @@
+set test "./usymbols"
+set testpath "$srcdir/$subdir"
+set testsrc "$testpath/usymbols.c"
+set testexe "[pwd]/usymbols"
+set testflags "additional_flags=-g additional_flags=-O"
+
+# Only run on make installcheck
+if {! [installtest_p]} { untested "$test -p5"; return }
+
+# Compile out test program
+set res [target_compile $testsrc $testexe executable $testflags]
+if { $res != "" } {
+ verbose "target_compile failed: $res" 2
+ fail "unable to compile $testsrc"
+ return
+}
+
+# We need the execname() trick to work around (the workaround of) PR6964
+# otherwise we get also the rt_sigactions of stapio. Get the handler
+# (comes from the executable) and the restorer (comes from glibc).
+set testscript {
+ probe syscall.rt_sigaction {
+ if (pid() == target() && execname() == "%s") {
+ handler = $act->sa_handler;
+ printf("handler: %%s\n", symbolname(handler));
+ restorer = $act->sa_restorer;
+ printf("restorer: %%s\n", symbolname(restorer));
+ }
+ }
+ probe process("%s").syscall { printf(""); /* XXX trigger tracker */ }
+}
+
+set output {handler: handler
+restorer: __restore_rt}
+
+# Got to run stap with both the exe and the libraries used as -d args.
+# XXX Note how we need the fully resolved (absolute) path...
+set script [format $testscript usymbols $testexe]
+catch {eval exec [concat ldd $testexe | grep libc.so]} libc
+set libc [lindex [split $libc " "] 2]
+send_log "libc: $libc\n"
+if {[string equal "link" [file type $libc]]} {
+ set libc [file join [file dirname $libc] [file readlink $libc]]
+}
+send_log "libc: $libc\n"
+set cmd [concat stap -d $libc -d $testexe -c $testexe -e {$script}]
+send_log "cmd: $cmd\n"
+catch {eval exec $cmd} res
+send_log "cmd output: $res\n"
+
+set n 0
+set m [llength [split $output "\n"]]
+set expected [split $output "\n"]
+foreach line [split $res "\n"] {
+ if {![string equal $line [lindex $expected $n]]} {
+ fail usymbols
+ send_log "line [expr $n + 1]: expected \"[lindex $expected $n]\", "
+ send_log "Got \"$line\"\n"
+ return
+ }
+ incr n
+}
+if { $n != $m } {
+ fail usymbols
+ send_log "Got \"$n\" lines, expected \"$m\" lines\n"
+} else {
+ pass usymbols
+}
+exec rm -f $testexe