1 # Copyright (C) 2012 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 set testfile stap-probe
18 # Run the tests. We run the tests two different ways: once with a
19 # plain probe, and once with a probe that has an associated semaphore.
20 # This returns -1 on failure to compile or start, 0 otherwise.
21 proc stap_test {exec_name {arg ""}} {
24 if {[prepare_for_testing ${testfile}.exp ${exec_name} ${testfile}.c \
25 [concat $arg debug]]} {
33 gdb_test "print \$_probe_argc" "No SystemTap probe at PC $hex" \
34 "check argument not at probe point"
36 gdb_test "info probes stap" \
37 "test *user *$hex .*" \
40 if {[runto "-pstap test:user"]} {
41 pass "run to -pstap test:user"
43 fail "run to -pstap test:user"
46 # Test probe arguments.
47 gdb_test "print \$_probe_argc" " = 1" \
48 "print \$_probe_argc for probe user"
49 gdb_test "print \$_probe_arg0 == x" " = 1" \
50 "check \$_probe_arg0 for probe user"
51 gdb_test "print \$_probe_arg1" \
52 "Invalid probe argument 1 -- probe has 1 arguments available" \
53 "check \$_probe_arg1 for probe user"
55 # Set a breakpoint with multiple probe locations.
56 gdb_test "break -pstap test:two" \
57 "Breakpoint \[0-9\]+ at $hex.*2 locations.*" \
58 "set multi-location probe breakpoint (probe two)"
60 # Reinit GDB, set a breakpoint on probe m4.
63 if {[runto "-pstap test:m4"]} {
64 pass "run to -pstap test:m4"
66 fail "run to -pstap test:m4"
69 # Testing probe arguments.
70 gdb_test "print \$_probe_argc" " = 3" \
71 "print \$_probe_argc for probe m4"
72 gdb_test "print \$_probe_arg0" " = 42" \
73 "check \$_probe_arg0 for probe m4"
74 gdb_test "print (const char *) \$_probe_arg1" \
75 " = $hex .This is a test message.*" \
76 "check \$_probe_arg1 for probe m4"
77 gdb_test "print \$_probe_arg2 == v" " = 1" \
78 "check \$_probe_arg2 for probe m4"
80 # Reinit GDB, set a breakpoint on probe ps.
83 if {[runto "-pstap test:ps"]} {
84 pass "run to -pstap test:m4"
86 fail "run to -pstap test:m4"
89 gdb_test "print \$_probe_argc" " = 3" \
90 "print \$_probe_argc for probe ps"
91 gdb_test "print (const char *) \$_probe_arg1" \
92 " = $hex .This is another test message.*" \
93 "print \$_probe_arg1 for probe ps"
98 proc stap_test_no_debuginfo {exec_name {arg ""}} {
101 if {[prepare_for_testing ${testfile}.exp ${exec_name} ${testfile}.c \
102 {$arg nodebug optimize=-O2}]} {
106 if {[runto "-pstap test:user"]} {
107 pass "run to -pstap test:user"
109 fail "run to -pstap test:user"
112 # Test probe arguments.
113 gdb_test "print \$_probe_argc" " = 1" \
114 "print \$_probe_argc for probe user"
115 gdb_test "print \$_probe_arg0 == 23" " = 1" \
116 "check \$_probe_arg0 for probe user"
117 gdb_test "print \$_probe_arg1" \
118 "Invalid probe argument 1 -- probe has 1 arguments available" \
119 "check \$_probe_arg1 for probe user"
121 # Set a breakpoint with multiple probe locations.
122 # In this scenario, we may expect more than 2 locations because of
123 # the optimizations (inlining, loop unrolling, etc).
124 gdb_test "break -pstap test:two" \
125 "Breakpoint .* at $hex.*\[0-9\]+ locations.*" \
126 "set multi-location probe breakpoint (probe two)"
128 # Reinit GDB, set a breakpoint on probe m4.
131 if {[runto "-pstap test:m4"]} {
132 pass "run to -pstap test:m4"
134 fail "run to -pstap test:m4"
137 # Testing probe arguments.
138 gdb_test "print \$_probe_argc" " = 3" \
139 "print \$_probe_argc for probe m4"
140 gdb_test "print \$_probe_arg0" " = 42" \
141 "check \$_probe_arg0 for probe m4"
142 gdb_test "print (const char *) \$_probe_arg1" \
143 " = $hex .This is a test message.*" \
144 "check \$_probe_arg1 for probe m4"
145 gdb_test "print \$_probe_arg2 == 0" " = 1" \
146 "check \$_probe_arg2 for probe m4"
148 # Reinit GDB, set a breakpoint on probe ps.
151 if {[runto "-pstap test:ps"]} {
152 pass "run to -pstap test:m4"
154 fail "run to -pstap test:m4"
157 gdb_test "print \$_probe_argc" " = 3" \
158 "print \$_probe_argc for probe ps"
159 gdb_test "print (const char *) \$_probe_arg1" \
160 " = $hex .This is another test message.*" \
161 "print \$_probe_arg1 for probe ps"
166 with_test_prefix "without semaphore, not optimized" {
167 if {[stap_test "stap-probe-nosem-noopt"] == -1} {
168 untested stap-probe.exp
173 with_test_prefix "with semaphore, not optimized" {
174 stap_test "stap-probe-sem-noopt" "-DUSE_PROBES"
177 with_test_prefix "without semaphore, optimized" {
178 stap_test_no_debuginfo "stap-probe-nosem-opt"
181 with_test_prefix "with semaphore, optimized" {
182 stap_test_no_debuginfo "stap-probe-sem-opt" "-DUSE_PROBES"