1 # Copyright (C) 2012-2021 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/>.
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 {args ""}} {
22 global testfile hex srcfile
24 if {[prepare_for_testing "failed to prepare" ${exec_name} $srcfile \
25 [concat $args debug]]} {
29 set semaphore_addr_var ""
30 if {[string first "-DUSE_SEMAPHORES" $args] == -1} {
31 gdb_test_no_output "set breakpoint always-inserted on"
32 set semaphore_addr_var [get_hexadecimal_valueof "&relocation_marker" "0"]
39 gdb_test "print \$_probe_argc" "No probe at PC $hex" \
40 "check argument not at probe point"
42 if {[string first "-DUSE_SEMAPHORES" $args] != -1} {
43 gdb_test "info probes stap" \
44 "test *user *$hex *$hex .*"
46 gdb_test "info probes stap" \
50 if {[runto "-pstap test:user"]} {
51 pass "run to -pstap test:user"
53 fail "run to -pstap test:user"
56 if {[string first "-DUSE_SEMAPHORES" $args] == -1} {
58 [expr [get_hexadecimal_valueof "&relocation_marker" "0"] - $semaphore_addr_var]
59 if {$relocation_base != 0} {
60 # Checks that GDB doesn't mistakenly relocate and write to null
61 # semaphore addresses. If it were to relocate a zero-valued
62 # semaphore address and increment the value at that address, we
63 # would expect to see "\200ELF" here instead.
64 gdb_test "p (*(char*) $relocation_base)@4" \
66 "null semaphore relocation"
70 # Test probe arguments.
71 gdb_test "print \$_probe_argc" " = 1" \
72 "print \$_probe_argc for probe user"
73 gdb_test "print \$_probe_arg0 == x" " = 1" \
74 "check \$_probe_arg0 for probe user"
75 gdb_test "print \$_probe_arg1" \
76 "Invalid probe argument 1 -- probe has 1 arguments available" \
77 "check \$_probe_arg1 for probe user"
79 # Set a breakpoint with multiple probe locations.
80 gdb_test "break -pstap test:two" \
81 "Breakpoint \[0-9\]+ at $hex.*2 locations.*" \
82 "set multi-location probe breakpoint (probe two)"
84 # Reinit GDB, set a breakpoint on probe m4.
86 if {[runto "-pstap test:m4"]} {
87 pass "run to -pstap test:m4"
89 fail "run to -pstap test:m4"
92 # Testing probe arguments.
93 gdb_test "print \$_probe_argc" " = 3" \
94 "print \$_probe_argc for probe m4"
95 gdb_test "print \$_probe_arg0" " = 42" \
96 "check \$_probe_arg0 for probe m4"
97 gdb_test "print (const char *) \$_probe_arg1" \
98 " = $hex .This is a test message.*" \
99 "check \$_probe_arg1 for probe m4"
100 gdb_test "print \$_probe_arg2 == v" " = 1" \
101 "check \$_probe_arg2 for probe m4"
103 # Reinit GDB, set a breakpoint on probe ps.
105 if {[runto "-pstap test:ps"]} {
106 pass "run to -pstap test:m4"
108 fail "run to -pstap test:m4"
111 gdb_test "print \$_probe_argc" " = 3" \
112 "print \$_probe_argc for probe ps"
113 gdb_test "print (const char *) \$_probe_arg1" \
114 " = $hex .This is another test message.*" \
115 "print \$_probe_arg1 for probe ps"
120 proc stap_test_no_debuginfo {exec_name {args ""}} {
123 if {[prepare_for_testing "failed to prepare" ${exec_name} ${testfile}.c \
124 [concat $args nodebug optimize=-O2]]} {
128 if {[runto "-pstap test:user"]} {
129 pass "run to -pstap test:user"
131 fail "run to -pstap test:user"
134 # Test probe arguments.
135 gdb_test "print \$_probe_argc" " = 1" \
136 "print \$_probe_argc for probe user"
137 gdb_test "print \$_probe_arg0 == 23" " = 1" \
138 "check \$_probe_arg0 for probe user"
139 gdb_test "print \$_probe_arg1" \
140 "Invalid probe argument 1 -- probe has 1 arguments available" \
141 "check \$_probe_arg1 for probe user"
143 # Set a breakpoint with multiple probe locations.
144 # In this scenario, we may expect more than 2 locations because of
145 # the optimizations (inlining, loop unrolling, etc).
146 gdb_test "break -pstap test:two" \
147 "Breakpoint .* at $hex.*\[0-9\]+ locations.*" \
148 "set multi-location probe breakpoint (probe two)"
150 # Reinit GDB, set a breakpoint on probe m4.
152 if {[runto "-pstap test:m4"]} {
153 pass "run to -pstap test:m4"
155 fail "run to -pstap test:m4"
158 # Testing probe arguments.
159 gdb_test "print \$_probe_argc" " = 3" \
160 "print \$_probe_argc for probe m4"
161 gdb_test "print \$_probe_arg0" " = 42" \
162 "check \$_probe_arg0 for probe m4"
163 gdb_test "print (const char *) \$_probe_arg1" \
164 " = $hex .This is a test message.*" \
165 "check \$_probe_arg1 for probe m4"
166 gdb_test "print \$_probe_arg2 == 0" " = 1" \
167 "check \$_probe_arg2 for probe m4"
169 # Reinit GDB, set a breakpoint on probe ps.
171 if {[runto "-pstap test:ps"]} {
172 pass "run to -pstap test:m4"
174 fail "run to -pstap test:m4"
177 gdb_test "print \$_probe_argc" " = 3" \
178 "print \$_probe_argc for probe ps"
179 gdb_test "print (const char *) \$_probe_arg1" \
180 " = $hex .This is another test message.*" \
181 "print \$_probe_arg1 for probe ps"
186 with_test_prefix "without semaphore, not optimized" {
187 if {[stap_test "stap-probe-nosem-noopt"] == -1} {
188 untested "stap probe test failed"
192 foreach_with_prefix pie { "nopie" "pie" } {
193 stap_test "stap-probe-nosem-noopt-$pie" $pie
197 with_test_prefix "with semaphore, not optimized" {
198 stap_test "stap-probe-sem-noopt" additional_flags=-DUSE_SEMAPHORES
201 with_test_prefix "without semaphore, optimized" {
202 stap_test_no_debuginfo "stap-probe-nosem-opt"
205 with_test_prefix "with semaphore, optimized" {
206 stap_test_no_debuginfo "stap-probe-sem-opt" additional_flags=-DUSE_SEMAPHORES