diff options
Diffstat (limited to 'testsuite')
-rw-r--r-- | testsuite/lib/stap_run.exp | 1 | ||||
-rw-r--r-- | testsuite/systemtap.context/usymbols.c | 39 | ||||
-rw-r--r-- | testsuite/systemtap.context/usymbols.exp | 82 | ||||
-rw-r--r-- | testsuite/systemtap.context/usymbols_lib.c | 29 |
4 files changed, 151 insertions, 0 deletions
diff --git a/testsuite/lib/stap_run.exp b/testsuite/lib/stap_run.exp index a4beaa12..3043eeed 100644 --- a/testsuite/lib/stap_run.exp +++ b/testsuite/lib/stap_run.exp @@ -30,6 +30,7 @@ proc stap_run { TEST_NAME {LOAD_GEN_FUNCTION ""} {OUTPUT_CHECK_STRING ""} args } if [file readable $test_file_name] { lappend cmd $test_file_name } + send_log "executing: $cmd\n" eval spawn $cmd expect { -timeout 180 diff --git a/testsuite/systemtap.context/usymbols.c b/testsuite/systemtap.context/usymbols.c new file mode 100644 index 00000000..7c590724 --- /dev/null +++ b/testsuite/systemtap.context/usymbols.c @@ -0,0 +1,39 @@ +/* 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 from the main executable, + * and then the library through calling signal. + * + * FIXME. We call into the library to get the right symbol. If we + * register the handler from the main executable. We 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); + +// function from our library +int lib_main (void); + +void +main_handler (int signum) +{ + /* dummy handler, just used for the address... */ +} + +int +main (int argc, char *argv[], char *envp[]) +{ + // Use SIGFPE since we never expect that to be triggered. + signal(SIGFPE, main_handler); + lib_main(); +} diff --git a/testsuite/systemtap.context/usymbols.exp b/testsuite/systemtap.context/usymbols.exp new file mode 100644 index 00000000..f95fd896 --- /dev/null +++ b/testsuite/systemtap.context/usymbols.exp @@ -0,0 +1,82 @@ +set test "./usymbols" +set testpath "$srcdir/$subdir" +set testsrc "$testpath/usymbols.c" +set testsrclib "$testpath/usymbols_lib.c" +set testexe "[pwd]/usymbols" +set testlibname "usymbols" +set testlibdir "[pwd]" +set testso "$testlibdir/lib${testlibname}.so" +set testflags "additional_flags=-g additional_flags=-O" +set testlibflags "testflags additional_flags=-fPIC additional_flags=-shared" +set maintestflags "$testflags additional_flags=-L$testlibdir additional_flags=-l$testlibname additional_flags=-Wl,-rpath,$testlibdir" + +# Only run on make installcheck +if {! [installtest_p]} { untested "$test -p5"; return } + +# Compile our test program and library. +set res [target_compile $testsrclib $testso executable $testlibflags] +if { $res != "" } { + verbose "target_compile for $testso failed: $res" 2 + fail "unable to compile $testsrclib" + return +} +set res [target_compile $testsrc $testexe executable $maintestflags] +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 or the library). +set testscript { + probe syscall.rt_sigaction { + if (pid() == target() && execname() == "%s") { + handler = $act->sa_handler; + printf("handler: %%s\n", symbolname(handler)); + } + } + /* track through uprobes, so as to make sure we have the symbols */ + probe process("%s").function("*") { printf(""); } +} + +set output {handler: main_handler +handler: lib_handler} + +# 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 $testlibname]} libpath +set libpath [lindex [split $libpath " "] 2] +send_log "libpath: $libpath\n" +if {[string equal "link" [file type $libpath]]} { + set libpath [file join [file dirname $libpath] [file readlink $libpath]] +} +send_log "libpath: $libpath\n" + +# XXX Cheat, explicitly add STP_NEED_VMA_TRACKER +set cmd [concat stap -DSTP_NEED_VMA_TRACKER -d $libpath -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 $testso diff --git a/testsuite/systemtap.context/usymbols_lib.c b/testsuite/systemtap.context/usymbols_lib.c new file mode 100644 index 00000000..faccb39b --- /dev/null +++ b/testsuite/systemtap.context/usymbols_lib.c @@ -0,0 +1,29 @@ +/* usymbol test case - library helper + * 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 set through signal + * from this library. + */ + +#include <signal.h> +typedef void (*sighandler_t)(int); + +void +lib_handler (int signum) +{ + /* dummy handler, just used for the address... */ +} + +void +lib_main () +{ + // Use SIGFPE since we never expect that to be triggered. + signal(SIGFPE, lib_handler); +} |