diff options
-rw-r--r-- | testsuite/systemtap.base/externalvar.c | 52 | ||||
-rw-r--r-- | testsuite/systemtap.base/externalvar.exp | 70 | ||||
-rw-r--r-- | testsuite/systemtap.base/externalvar.stp | 39 | ||||
-rw-r--r-- | testsuite/systemtap.base/externalvar_lib.c | 43 |
4 files changed, 204 insertions, 0 deletions
diff --git a/testsuite/systemtap.base/externalvar.c b/testsuite/systemtap.base/externalvar.c new file mode 100644 index 00000000..a7716029 --- /dev/null +++ b/testsuite/systemtap.base/externalvar.c @@ -0,0 +1,52 @@ +/* externalvar test case + * Copyright (C) 2009, 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. + * + * Tests that an external exported variable can be accessed. + */ + +#include <stdlib.h> + +// function from our library +int lib_main (void); + +struct exestruct +{ + char c; + int i; + long l; + struct exestruct *s1; + struct exestruct *s2; +}; + +char exevar_c; +int exevar_i; +long exevar_l; +struct exestruct *exe_s; + +static void +main_call () +{ + asm (""); // dummy method, just to probe and extract and jump into lib. + lib_main (); +} + +int +main () +{ + exevar_c = 42; + exevar_i = 2; + exevar_l = 21; + exe_s = (struct exestruct *) malloc(sizeof(struct exestruct)); + exe_s->i =1; + exe_s->l =2; + exe_s->c =3; + exe_s->s1 = NULL; + exe_s->s2 = exe_s; + main_call (); + return 0; +} diff --git a/testsuite/systemtap.base/externalvar.exp b/testsuite/systemtap.base/externalvar.exp new file mode 100644 index 00000000..668dec55 --- /dev/null +++ b/testsuite/systemtap.base/externalvar.exp @@ -0,0 +1,70 @@ +set test "externalvar" +set testpath "$srcdir/$subdir" +set testsrc "$testpath/$test.c" +set testsrclib "$testpath/${test}_lib.c" +set testexe "[pwd]/$test" +set testlibname "$test" +set testlibdir "[pwd]" +set testso "$testlibdir/lib${testlibname}.so" +set testflags "additional_flags=-g additional_flags=-O0" +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 and utrace present. +if {! [installtest_p]} { untested "$test"; return } +if {! [utrace_p]} { untested "$test"; 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 +} + +set output {exevar_c = 42 +exevar_i = 2 +exevar_l = 21 +exe_s->i = 1 +exe_s->l = 2 +exe_s->c = 3 +exe_s->s1 = 0x0 +exe_s == exe_s->s2 +libvar = 42 +lib_s->i = 1 +lib_s->l = 2 +lib_s->c = 3 +lib_s == lib_s->s1 +lib_s->s2 = 0x0} + +# Got to run stap with both the exe and the libraries used as -d args. +set cmd [concat stap -d $testso -d $testexe -c $testexe $testpath/$test.stp] +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 $test + send_log "line [expr $n + 1]: expected \"[lindex $expected $n]\", " + send_log "Got \"$line\"\n" + return + } + incr n +} +if { $n != $m } { + fail $test + send_log "Got \"$n\" lines, expected \"$m\" lines\n" +} else { + pass $test +} +# exec rm -f $testexe $testso diff --git a/testsuite/systemtap.base/externalvar.stp b/testsuite/systemtap.base/externalvar.stp new file mode 100644 index 00000000..7d4b69bb --- /dev/null +++ b/testsuite/systemtap.base/externalvar.stp @@ -0,0 +1,39 @@ +probe process("externalvar").function("main_call") +{ + printf("exevar_c = %d\n", $exevar_c); + printf("exevar_i = %d\n", $exevar_i); + printf("exevar_l = %d\n", $exevar_l); + + printf("exe_s->i = %d\n", $exe_s->i); + printf("exe_s->l = %d\n", $exe_s->l); + printf("exe_s->c = %d\n", $exe_s->c); + + printf("exe_s->s1 = 0x%x\n", $exe_s->s1); + if ($exe_s == $exe_s->s2) + { + printf("exe_s == exe_s->s2\n"); + } + else + { + printf("exe_s != exe_s->s2\n"); + } +} + +probe process("libexternalvar.so").function("lib_call") +{ + printf("libvar = %d\n", $libvar); + + printf("lib_s->i = %d\n", $lib_s->i); + printf("lib_s->l = %d\n", $lib_s->l); + printf("lib_s->c = %d\n", $lib_s->c); + + if ($lib_s == $lib_s->s1) + { + printf("lib_s == lib_s->s1\n"); + } + else + { + printf("lib_s != lib_s->s2\n"); + } + printf("lib_s->s2 = 0x%x\n", $lib_s->s2); +} diff --git a/testsuite/systemtap.base/externalvar_lib.c b/testsuite/systemtap.base/externalvar_lib.c new file mode 100644 index 00000000..9017e798 --- /dev/null +++ b/testsuite/systemtap.base/externalvar_lib.c @@ -0,0 +1,43 @@ +/* external var test case - library helper + * Copyright (C) 2009, 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. + * + * Tests that an external exported variable can be accessed. + */ + +#include <stdlib.h> + +struct libstruct +{ + int i; + long l; + char c; + struct libstruct *s1; + struct libstruct *s2; +}; + +int libvar; +struct libstruct *lib_s; + +static void +lib_call () +{ + asm(""); // dummy method, just to probe and extract. +} + +void +lib_main () +{ + libvar = 42; + lib_s = (struct libstruct *) malloc(sizeof(struct libstruct)); + lib_s->i = 1; + lib_s->l = 2; + lib_s->c = 3; + lib_s->s1 = lib_s; + lib_s->s2 = NULL; + lib_call (); +} |