]> sourceware.org Git - systemtap.git/commitdiff
stmt_inlines.exp: testcase for statement probes in inlines
authorJonathan Lebon <jlebon@redhat.com>
Tue, 22 Apr 2014 16:16:49 +0000 (12:16 -0400)
committerJonathan Lebon <jlebon@redhat.com>
Tue, 22 Apr 2014 16:25:10 +0000 (12:25 -0400)
This testcase verifies our ability to place probes on statements in
functions that have been inlined multiple times.

testsuite/systemtap.base/stmt_inlines.c [new file with mode: 0644]
testsuite/systemtap.base/stmt_inlines.exp [new file with mode: 0644]

diff --git a/testsuite/systemtap.base/stmt_inlines.c b/testsuite/systemtap.base/stmt_inlines.c
new file mode 100644 (file)
index 0000000..c1ff550
--- /dev/null
@@ -0,0 +1,14 @@
+#include <stdio.h>
+
+__attribute__((always_inline))
+inline static void foo(int i)
+{
+   printf("printf %d\n", i);
+}
+
+int main(int argc, char** argv)
+{
+   foo(argc);
+   foo(argc*2);
+   return 0;
+}
diff --git a/testsuite/systemtap.base/stmt_inlines.exp b/testsuite/systemtap.base/stmt_inlines.exp
new file mode 100644 (file)
index 0000000..78e3b1c
--- /dev/null
@@ -0,0 +1,81 @@
+set test "stmt_inlines"
+if {![utrace_p]} { untested "$test"; return }
+
+# This test verifies that probing a statement in a function inlined multiple
+# times will place a probe at all instances.
+
+proc cleanup {} {
+   global test
+   if {[file exists "$test"]} {
+      file delete "$test"
+   }
+}
+
+catch {exec gcc -g -o $test $srcdir/$subdir/$test.c} err
+if {$err == "" && [file exists $test]} {
+   pass "$test (compiled)"
+} else {
+   fail "$test (compilation error)"
+   cleanup
+   return
+}
+
+# Check that the statement and var show up in -L
+
+eval spawn stap -L process("./$test").statement("foo@$test.c:6")
+set failed 1
+expect {
+   -timeout 30
+   -re {^process\("[^\"]+"\)\.statement\("foo@[^\:]+\:6"\) \$i:int\r\n$} {
+      set failed 0
+   }
+   timeout { kill -INT -[exp_pid] 2 }
+   eof {}
+}
+catch {close}; catch {wait}
+
+if {!$failed} {
+   pass "$test (listing)"
+} else {
+   fail "$test (listing error)"
+   cleanup
+   return
+}
+
+# Now check that probing actually triggers the inlined statement twice
+
+if {![installtest_p]} {
+   untested "$test (runtime)"
+   cleanup
+   return
+}
+
+set script " \
+   probe process(\"./$test\").statement(\"foo@$test.c:6\") { \
+      printf(\"before printf with i=%d\\n\", \$i) \
+   } \
+"
+
+eval spawn stap -e {$script} -c "./$test"
+set n 0
+expect {
+   -timeout 60
+   "printf 1" { incr n; exp_continue }
+   "printf 2" { incr n; exp_continue }
+   "before printf with i=1" { incr n; exp_continue }
+   "before printf with i=2" { incr n; exp_continue }
+   timeout { kill -INT -[exp_pid] 2 }
+   eof {}
+}
+catch {close}; catch {wait}
+
+if {$n == 4} {
+   pass "$test (probing)"
+} else {
+   fail "$test (probing error, expected 4, got $n)"
+   cleanup
+   return
+}
+
+cleanup
+
This page took 0.077121 seconds and 5 git commands to generate.