1 # Copyright (C) 2012-2020 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 {arg ""}} {
22 global testfile hex srcfile
24 if {[prepare_for_testing "failed to prepare" ${exec_name} $srcfile \
25 [concat additional_flags=$arg debug]]} {
33 gdb_test "print \$_probe_argc" "No probe at PC $hex" \
34 "check argument not at probe point"
36 if {[string first "-DUSE_SEMAPHORES" $arg] != -1} {
37 gdb_test "info probes stap" \
38 "test *user *$hex *$hex .*"
40 gdb_test "info probes stap" \
44 if {[runto "-pstap test:user"]} {
45 pass "run to -pstap test:user"
47 fail "run to -pstap test:user"
50 # Test probe arguments.
51 gdb_test "print \$_probe_argc" " = 1" \
52 "print \$_probe_argc for probe user"
53 gdb_test "print \$_probe_arg0 == x" " = 1" \
54 "check \$_probe_arg0 for probe user"
55 gdb_test "print \$_probe_arg1" \
56 "Invalid probe argument 1 -- probe has 1 arguments available" \
57 "check \$_probe_arg1 for probe user"
59 # Set a breakpoint with multiple probe locations.
60 gdb_test "break -pstap test:two" \
61 "Breakpoint \[0-9\]+ at $hex.*2 locations.*" \
62 "set multi-location probe breakpoint (probe two)"
64 # Reinit GDB, set a breakpoint on probe m4.
66 if {[runto "-pstap test:m4"]} {
67 pass "run to -pstap test:m4"
69 fail "run to -pstap test:m4"
72 # Testing probe arguments.
73 gdb_test "print \$_probe_argc" " = 3" \
74 "print \$_probe_argc for probe m4"
75 gdb_test "print \$_probe_arg0" " = 42" \
76 "check \$_probe_arg0 for probe m4"
77 gdb_test "print (const char *) \$_probe_arg1" \
78 " = $hex .This is a test message.*" \
79 "check \$_probe_arg1 for probe m4"
80 gdb_test "print \$_probe_arg2 == v" " = 1" \
81 "check \$_probe_arg2 for probe m4"
83 # Reinit GDB, set a breakpoint on probe ps.
85 if {[runto "-pstap test:ps"]} {
86 pass "run to -pstap test:m4"
88 fail "run to -pstap test:m4"
91 gdb_test "print \$_probe_argc" " = 3" \
92 "print \$_probe_argc for probe ps"
93 gdb_test "print (const char *) \$_probe_arg1" \
94 " = $hex .This is another test message.*" \
95 "print \$_probe_arg1 for probe ps"
100 proc stap_test_no_debuginfo {exec_name {arg ""}} {
103 if {[prepare_for_testing "failed to prepare" ${exec_name} ${testfile}.c \
104 [concat additional_flags=$arg nodebug optimize=-O2]]} {
108 if {[runto "-pstap test:user"]} {
109 pass "run to -pstap test:user"
111 fail "run to -pstap test:user"
114 # Test probe arguments.
115 gdb_test "print \$_probe_argc" " = 1" \
116 "print \$_probe_argc for probe user"
117 gdb_test "print \$_probe_arg0 == 23" " = 1" \
118 "check \$_probe_arg0 for probe user"
119 gdb_test "print \$_probe_arg1" \
120 "Invalid probe argument 1 -- probe has 1 arguments available" \
121 "check \$_probe_arg1 for probe user"
123 # Set a breakpoint with multiple probe locations.
124 # In this scenario, we may expect more than 2 locations because of
125 # the optimizations (inlining, loop unrolling, etc).
126 gdb_test "break -pstap test:two" \
127 "Breakpoint .* at $hex.*\[0-9\]+ locations.*" \
128 "set multi-location probe breakpoint (probe two)"
130 # Reinit GDB, set a breakpoint on probe m4.
132 if {[runto "-pstap test:m4"]} {
133 pass "run to -pstap test:m4"
135 fail "run to -pstap test:m4"
138 # Testing probe arguments.
139 gdb_test "print \$_probe_argc" " = 3" \
140 "print \$_probe_argc for probe m4"
141 gdb_test "print \$_probe_arg0" " = 42" \
142 "check \$_probe_arg0 for probe m4"
143 gdb_test "print (const char *) \$_probe_arg1" \
144 " = $hex .This is a test message.*" \
145 "check \$_probe_arg1 for probe m4"
146 gdb_test "print \$_probe_arg2 == 0" " = 1" \
147 "check \$_probe_arg2 for probe m4"
149 # 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 test failed"
173 with_test_prefix "with semaphore, not optimized" {
174 stap_test "stap-probe-sem-noopt" "-DUSE_SEMAPHORES"
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_SEMAPHORES"