summaryrefslogtreecommitdiffstats
path: root/testsuite/systemtap.base/sdt_misc.exp
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/systemtap.base/sdt_misc.exp')
-rw-r--r--testsuite/systemtap.base/sdt_misc.exp240
1 files changed, 240 insertions, 0 deletions
diff --git a/testsuite/systemtap.base/sdt_misc.exp b/testsuite/systemtap.base/sdt_misc.exp
new file mode 100644
index 00000000..459b669a
--- /dev/null
+++ b/testsuite/systemtap.base/sdt_misc.exp
@@ -0,0 +1,240 @@
+set test "static_user_markers"
+
+# Test miscellaneous features of .mark probes
+
+# Compile a C program to use as the user-space probing target
+set sup_srcpath "[pwd]/static_user_markers.c"
+set sup_exepath "[pwd]/static_user_markers.x"
+set supcplus_exepath "[pwd]/static_user_markers_cplus.x"
+set fp [open $sup_srcpath "w"]
+puts $fp "
+#include <stdlib.h>
+#define USE_STAP_PROBE 1
+#include \"static_user_markers_.h\"
+
+void
+bar (int i)
+{
+ STATIC_USER_MARKERS_TEST_PROBE_2(i);
+ if (i == 0)
+ i = 1000;
+ STAP_PROBE1(static_uprobes,test_probe_2,i);
+}
+
+void
+baz (int i, char* s)
+{
+ STAP_PROBE1(static_uprobes,test_probe_0,i);
+ if (i == 0)
+ i = 1000;
+ STATIC_USER_MARKERS_TEST_PROBE_3(i,s);
+}
+
+void
+buz (int parm)
+{
+ struct astruct
+ {
+ int a;
+ int b;
+ };
+ struct astruct bstruct = {parm, parm + 1};
+ if (parm == 0)
+ parm = 1000;
+ DTRACE_PROBE1(static_user_markers,test_probe_4,&bstruct);
+}
+
+int
+main ()
+{
+ bar(2);
+ baz(3,(char*)\"abc\");
+ buz(4);
+}
+"
+close $fp
+
+set sup_stppath "[pwd]/static_user_markers.stp"
+set fp [open $sup_stppath "w"]
+puts $fp "
+probe process(\"static_user_markers.x\").mark(\"test_probe_0\")
+{
+ printf(\"In test_probe_0 probe %#x\\n\", \$arg1)
+}
+probe process(\"static_user_markers.x\").mark(\"test_probe_2\")
+{
+ printf(\"In test_probe_2 probe %#x\\n\", \$arg1)
+}
+probe process(\"static_user_markers.x\").mark(\"test_probe_3\")
+{
+ printf(\"In test_probe_3 probe %#x %#x\\n\", \$arg1, \$arg2)
+}
+probe process(\"static_user_markers.x\").mark(\"test_probe_4\")
+{
+ printf(\"In test_probe_4 dtrace probe %#x %#x\\n\", \$arg1->a, \$arg1->b)
+}
+"
+close $fp
+
+set sup_dpath "[pwd]/static_user_markers_.d"
+set sup_hpath "[pwd]/static_user_markers_.h"
+set sup_opath "[pwd]/static_user_markers_.o"
+set fp [open $sup_dpath "w"]
+puts $fp "
+provider static_user_markers {
+ probe test_probe_1 ();
+ probe test_probe_2 (int i);
+ probe test_probe_3 (int i, char* x);
+ probe test_probe_4 (struct astruct arg);
+};
+struct astruct {int a; int b;};
+"
+close $fp
+
+# Test dtrace
+
+if {[installtest_p]} {
+ set dtrace $env(SYSTEMTAP_PATH)/dtrace
+} else {
+ set dtrace $srcdir/../dtrace
+}
+if {[catch {exec $dtrace --types -G -s $sup_dpath} res]} {
+ verbose -log "unable to run $dtrace: $res"
+}
+if {[file exists $sup_hpath] && [file exists $sup_opath]} then {
+ pass "$test dtrace"
+} else {
+ fail "$test dtrace"
+ if { $verbose == 0 } {
+ catch {exec rm -f $sup_srcpath $sup_hpath $sup_stppath}
+ }
+ return
+}
+
+if {[installtest_p]} {
+ set sdtdir $env(SYSTEMTAP_INCLUDES)
+} else {
+ set sdtdir $srcdir/../includes
+}
+
+set pbtype_flags {{""} {additional_flags=-O additional_flags=-DEXPERIMENTAL_UTRACE_SDT} {additional_flags=-O additional_flags=-DEXPERIMENTAL_KPROBE_SDT}}
+set pbtype_mssgs {{uprobe} {utrace} {kprobe}}
+
+# Iterate pbtype_flags
+for {set i 0} {$i < [llength $pbtype_flags]} {incr i} {
+set pbtype_flag [lindex $pbtype_flags $i]
+set pbtype_mssg [lindex $pbtype_mssgs $i]
+set testprog "sdt.c.exe.$i"
+
+set sup_flags "additional_flags=-I$srcdir/../includes/sys"
+set sup_flags "$sup_flags additional_flags=-I$sdtdir"
+set sup_flags "$sup_flags additional_flags=-g"
+set sup_flags "$sup_flags additional_flags=$sup_opath"
+set sup_flags "$sup_flags additional_flags=-I. $pbtype_flag"
+set res [target_compile $sup_srcpath $sup_exepath executable $sup_flags]
+if { $res != "" } {
+ verbose "target_compile failed: $res" 2
+ fail "$test compiling -g $pbtype_mssg"
+ if { $verbose == 0 } {
+ catch {exec rm -f $sup_srcpath $sup_hpath $sup_stppath}
+ }
+ return
+} else {
+ pass "$test compiling -g $pbtype_mssg"
+}
+
+if {![installtest_p]} {untested $test; return}
+if {![utrace_p]} {
+ untested "$test"
+ if { $verbose == 0 } {
+ catch {exec rm -f $sup_srcpath}
+ }
+ return
+}
+
+# Run stap on executable built with dtrace generated header file
+
+set ok 0
+
+verbose -log "spawn stap -c $sup_exepath $sup_stppath"
+spawn stap -c $sup_exepath $sup_stppath
+expect {
+ -timeout 180
+ -re {In test_probe_2 probe 0x2} { incr ok; exp_continue }
+ -re {In test_probe_0 probe 0x3} { incr ok; exp_continue }
+ -re {In test_probe_3 probe 0x3 0x[0-9a-f][0-9a-f]} { incr ok; exp_continue }
+ -re {In test_probe_4 dtrace probe 0x4 0x5} { incr ok; exp_continue }
+ timeout { fail "$test (timeout)" }
+ eof { }
+}
+
+wait
+
+if {$ok == 5} {
+ pass "$test $pbtype_mssg"
+} else {
+ fail "$test ($ok) $pbtype_mssg"
+}
+
+# Test passing various C types to .mark probes
+
+set sup_flags "$sup_flags $pbtype_flag additional_flags=-O0 "
+set res [target_compile $srcdir/$subdir/sdt_types.c sdt_types.x executable $sup_flags]
+if { $res != "" } {
+ verbose "target_compile failed: $res" 2
+ fail "$test compiling types -g $pbtype_mssg"
+ return
+} else {
+ pass "$test compiling types -g $pbtype_mssg"
+}
+
+set ok 0
+set fail "types"
+verbose -log "spawn stap -c ./sdt_types.x $srcdir/$subdir/sdt_types.stp ./sdt_types.x"
+spawn stap -c ./sdt_types.x $srcdir/$subdir/sdt_types.stp ./sdt_types.x
+expect {
+ -timeout 180
+ -re {FAIL: [a-z_]+var} { regexp " .*$" $expect_out(0,string) s;
+ incr ok; set fail "$fail $s"; exp_continue }
+ timeout { fail "$test (timeout) }
+ eof { }
+}
+
+wait
+
+set pbtype_mssgs {{uprobe} {utrace} {kprobe}}
+if { $ok != 0} {
+ if { $pbtype_mssg == "uprobe" } {
+ fail "$test $fail $pbtype_mssg"
+ } else {
+ # (needs cast)
+ xfail "$test $fail $pbtype_mssg"
+ }
+} else {
+ pass "$test types $pbtype_mssg"
+}
+
+# Test .mark probe wildcard matching
+
+set ok 0
+spawn stap -l "process(\"./sdt_types.x\").mark(\"*\")"
+expect {
+ -timeout 180
+ -re {mark\(\"[a-z_]+\"\)} { incr ok; exp_continue }
+ timeout { fail "$test (timeout)" }
+ eof { }
+}
+
+if { $ok == 45 } {
+ pass "$test wildcard $pbtype_mssg"
+} else {
+ fail "$test wildcard ($ok) $pbtype_mssg"
+}
+
+# for {set i 0}
+}
+
+if { $verbose == 0 } {
+catch {exec rm -f $sup_srcpath $sup_exepath $supcplus_exepath $sup_dpath $sup_hpath $sup_stppath sdt_types.x}
+}
+