diff options
Diffstat (limited to 'testsuite/systemtap.context')
-rw-r--r-- | testsuite/systemtap.context/fib.c | 31 | ||||
-rw-r--r-- | testsuite/systemtap.context/fib.exp | 37 | ||||
-rw-r--r-- | testsuite/systemtap.context/fib.stp | 17 | ||||
-rw-r--r-- | testsuite/systemtap.context/uprobe_backtrace.stp | 31 | ||||
-rw-r--r-- | testsuite/systemtap.context/uprobe_uaddr.exp | 58 | ||||
-rw-r--r-- | testsuite/systemtap.context/uprobe_uaddr.stp | 24 |
6 files changed, 198 insertions, 0 deletions
diff --git a/testsuite/systemtap.context/fib.c b/testsuite/systemtap.context/fib.c new file mode 100644 index 00000000..61fee0a7 --- /dev/null +++ b/testsuite/systemtap.context/fib.c @@ -0,0 +1,31 @@ +#include <stdlib.h> +#include <stdio.h> + +long fib(int x) +{ + if (x == 0 || x == 1) + return 1; + else + return fib(x - 1) + fib(x - 2); +} + +int main(int argc, char **argv) +{ + int x = 0; + long result = 0; + + if (argc != 2) + { + printf("0\n"); + return 1; + } + x = atoi(argv[1]); + if (x < 0) + { + printf("0\n"); + return 1; + } + result = fib(x); + printf("%ld\n", result); + return 0; +} diff --git a/testsuite/systemtap.context/fib.exp b/testsuite/systemtap.context/fib.exp new file mode 100644 index 00000000..cc4d75a1 --- /dev/null +++ b/testsuite/systemtap.context/fib.exp @@ -0,0 +1,37 @@ +# Tests backtrace in the classic Fibonacci program + + +set test "fib" + +# Only run on make installcheck and utrace present. +if {! [installtest_p]} { untested "$test"; return } +if {! [utrace_p]} { untested "$test"; return } + +set testpath "$srcdir/$subdir" +set testsrc "$testpath/fib.c" +set testexe "[pwd]/$test" + +# We want debug info and no optimization (is that totally necessary?) +set testflags "additional_flags=-g additional_flags=-O0" +set teststp "$testpath/$test.stp" + +set res [target_compile $testsrc $testexe executable $testflags] +if { $res != "" } { + verbose "target_compile failed: $res" 2 + fail "unable to compile $testsrc" + return +} + +spawn stap -c "$testexe 10" $teststp +set fibcalls 0 +set maincalls 0 +expect { + -timeout 120 + -re {^fib[^\r\n]*[\r\n]} { incr fibcalls; exp_continue } + -re {^main[^\r\n]*[\r\n]} { incr maincalls; exp_continue } + -re {^[^\r\n]*[\r\n]} {exp_continue} + timeout { fail "$test (timeout)" } + eof { } +} +wait +if {$fibcalls == 18 && $maincalls == 2} { pass "$test ($fibcalls $maincalls)" } { fail "$test ($fibcalls $maincalls)" } diff --git a/testsuite/systemtap.context/fib.stp b/testsuite/systemtap.context/fib.stp new file mode 100644 index 00000000..85c2fc1d --- /dev/null +++ b/testsuite/systemtap.context/fib.stp @@ -0,0 +1,17 @@ +global depth = 0 +global max_depth = 0 + +probe process("fib").function("fib").call { + depth++ + if (depth > max_depth) { + max_depth = depth + } +} + +probe process("fib").function("fib").return { + if (depth == max_depth) { + print_ubacktrace_brief() + printf("\n") + } + depth-- +} diff --git a/testsuite/systemtap.context/uprobe_backtrace.stp b/testsuite/systemtap.context/uprobe_backtrace.stp new file mode 100644 index 00000000..6d6fe3f7 --- /dev/null +++ b/testsuite/systemtap.context/uprobe_backtrace.stp @@ -0,0 +1,31 @@ +probe process("uprobe_uaddr").function("main").call { + print_ubacktrace() + printf("\n") +} + +probe process("uprobe_uaddr").function("main").return { + print_ubacktrace() + printf("\n") +} + +probe process("uprobe_uaddr").function("func").call { + print_ubacktrace() + printf("\n") +} + +probe process("uprobe_uaddr").function("func").return { + print_ubacktrace() + printf("\n") +} + + +probe process("uprobe_uaddr").function("func2").call { + print_ubacktrace() + printf("\n") +} + + +probe process("uprobe_uaddr").function("func2").return { + print_ubacktrace() + printf("\n") +} diff --git a/testsuite/systemtap.context/uprobe_uaddr.exp b/testsuite/systemtap.context/uprobe_uaddr.exp new file mode 100644 index 00000000..521dfa57 --- /dev/null +++ b/testsuite/systemtap.context/uprobe_uaddr.exp @@ -0,0 +1,58 @@ +# Tests uaddr in function call and return probes. For a call probe we +# expect the address to be in the function; for a return probe it +# should be in the function's caller. + +set test "uprobe_uaddr" + +# Only run on make installcheck and utrace present. +if {! [installtest_p]} { untested "$test"; return } +if {! [utrace_p]} { untested "$test"; return } + +set testpath "$srcdir/$subdir" +set testsrc "$testpath/uprobe_stmt_num.c" +set testexe "[pwd]/$test" + +# We want debug info and no optimization (every line counts). +set testflags "additional_flags=-g additional_flags=-O0" +set teststp "$testpath/$test.stp" + +set res [target_compile $testsrc $testexe executable $testflags] +if { $res != "" } { + verbose "target_compile failed: $res" 2 + fail "unable to compile $testsrc" + return +} + +set cmd [concat stap -c $testexe $teststp] +send_log "cmd: $cmd\n" +catch {eval exec $cmd} output +send_log "cmd output:\n $output\n" + +set output_lines [split $output "\n"] + +set lines [llength $output_lines] +if { $lines == 6 } { + pass "$test" +} else { + fail "$test ($lines)" +} + +set result_funcs [list "main *" "func *" "func2 *" "func *" "main *"] + +foreach expected $result_funcs output $output_lines { + if {$expected != ""} { + if [string match $expected $output] { + pass "$test" + } else { + fail "$test $output" + } + } else { + break; + } +} + +if [string match "main *" [lindex $output_lines 5]] { + fail "$test return from main" +} else { + pass "$test" +} diff --git a/testsuite/systemtap.context/uprobe_uaddr.stp b/testsuite/systemtap.context/uprobe_uaddr.stp new file mode 100644 index 00000000..1528e559 --- /dev/null +++ b/testsuite/systemtap.context/uprobe_uaddr.stp @@ -0,0 +1,24 @@ +probe process("uprobe_uaddr").function("main").call { + println(usymdata(uaddr())) +} + +probe process("uprobe_uaddr").function("main").return { + println(usymdata(uaddr())) +} + +probe process("uprobe_uaddr").function("func").call { + println(usymdata(uaddr())) +} + +probe process("uprobe_uaddr").function("func").return { + println(usymdata(uaddr())) +} + +probe process("uprobe_uaddr").function("func2").call { + println(usymdata(uaddr())) +} + +probe process("uprobe_uaddr").function("func2").return { + println(usymdata(uaddr())) +} + |