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 $arg debug]]} {
33 gdb_test "print \$_probe_argc" "No probe at PC $hex" \
34 "check argument not at probe point"
36 gdb_test "info probes stap" \
39 if {[runto "-pstap test:user"]} {
40 pass "run to -pstap test:user"
42 fail "run to -pstap test:user"
45 # Test probe arguments.
46 gdb_test "print \$_probe_argc" " = 1" \
47 "print \$_probe_argc for probe user"
48 gdb_test "print \$_probe_arg0 == x" " = 1" \
49 "check \$_probe_arg0 for probe user"
50 gdb_test "print \$_probe_arg1" \
51 "Invalid probe argument 1 -- probe has 1 arguments available" \
52 "check \$_probe_arg1 for probe user"
54 # Set a breakpoint with multiple probe locations.
55 gdb_test "break -pstap test:two" \
56 "Breakpoint \[0-9\]+ at $hex.*2 locations.*" \
57 "set multi-location probe breakpoint (probe two)"
59 # Reinit GDB, set a breakpoint on probe m4.
61 if {[runto "-pstap test:m4"]} {
62 pass "run to -pstap test:m4"
64 fail "run to -pstap test:m4"
67 # Testing probe arguments.
68 gdb_test "print \$_probe_argc" " = 3" \
69 "print \$_probe_argc for probe m4"
70 gdb_test "print \$_probe_arg0" " = 42" \
71 "check \$_probe_arg0 for probe m4"
72 gdb_test "print (const char *) \$_probe_arg1" \
73 " = $hex .This is a test message.*" \
74 "check \$_probe_arg1 for probe m4"
75 gdb_test "print \$_probe_arg2 == v" " = 1" \
76 "check \$_probe_arg2 for probe m4"
78 # Reinit GDB, set a breakpoint on probe ps.
80 if {[runto "-pstap test:ps"]} {
81 pass "run to -pstap test:m4"
83 fail "run to -pstap test:m4"
86 gdb_test "print \$_probe_argc" " = 3" \
87 "print \$_probe_argc for probe ps"
88 gdb_test "print (const char *) \$_probe_arg1" \
89 " = $hex .This is another test message.*" \
90 "print \$_probe_arg1 for probe ps"
95 proc stap_test_no_debuginfo {exec_name {arg ""}} {
98 if {[prepare_for_testing "failed to prepare" ${exec_name} ${testfile}.c \
99 {$arg nodebug optimize=-O2}]} {
103 if {[runto "-pstap test:user"]} {
104 pass "run to -pstap test:user"
106 fail "run to -pstap test:user"
109 # Test probe arguments.
110 gdb_test "print \$_probe_argc" " = 1" \
111 "print \$_probe_argc for probe user"
112 gdb_test "print \$_probe_arg0 == 23" " = 1" \
113 "check \$_probe_arg0 for probe user"
114 gdb_test "print \$_probe_arg1" \
115 "Invalid probe argument 1 -- probe has 1 arguments available" \
116 "check \$_probe_arg1 for probe user"
118 # Set a breakpoint with multiple probe locations.
119 # In this scenario, we may expect more than 2 locations because of
120 # the optimizations (inlining, loop unrolling, etc).
121 gdb_test "break -pstap test:two" \
122 "Breakpoint .* at $hex.*\[0-9\]+ locations.*" \
123 "set multi-location probe breakpoint (probe two)"
125 # Reinit GDB, set a breakpoint on probe m4.
127 if {[runto "-pstap test:m4"]} {
128 pass "run to -pstap test:m4"
130 fail "run to -pstap test:m4"
133 # Testing probe arguments.
134 gdb_test "print \$_probe_argc" " = 3" \
135 "print \$_probe_argc for probe m4"
136 gdb_test "print \$_probe_arg0" " = 42" \
137 "check \$_probe_arg0 for probe m4"
138 gdb_test "print (const char *) \$_probe_arg1" \
139 " = $hex .This is a test message.*" \
140 "check \$_probe_arg1 for probe m4"
141 gdb_test "print \$_probe_arg2 == 0" " = 1" \
142 "check \$_probe_arg2 for probe m4"
144 # Reinit GDB, set a breakpoint on probe ps.
146 if {[runto "-pstap test:ps"]} {
147 pass "run to -pstap test:m4"
149 fail "run to -pstap test:m4"
152 gdb_test "print \$_probe_argc" " = 3" \
153 "print \$_probe_argc for probe ps"
154 gdb_test "print (const char *) \$_probe_arg1" \
155 " = $hex .This is another test message.*" \
156 "print \$_probe_arg1 for probe ps"
161 with_test_prefix "without semaphore, not optimized" {
162 if {[stap_test "stap-probe-nosem-noopt"] == -1} {
163 untested "stap probe test failed"
168 with_test_prefix "with semaphore, not optimized" {
169 stap_test "stap-probe-sem-noopt" "-DUSE_PROBES"
172 with_test_prefix "without semaphore, optimized" {
173 stap_test_no_debuginfo "stap-probe-nosem-opt"
176 with_test_prefix "with semaphore, optimized" {
177 stap_test_no_debuginfo "stap-probe-sem-opt" "-DUSE_PROBES"