1 # Copyright
(C
) 2012-2019 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" \
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.
62 if {[runto
"-pstap test:m4"]} {
63 pass
"run to -pstap test:m4"
65 fail
"run to -pstap test:m4"
68 # Testing probe arguments.
69 gdb_test
"print \$_probe_argc" " = 3" \
70 "print \$_probe_argc for probe m4"
71 gdb_test
"print \$_probe_arg0" " = 42" \
72 "check \$_probe_arg0 for probe m4"
73 gdb_test
"print (const char *) \$_probe_arg1" \
74 " = $hex .This is a test message.*" \
75 "check \$_probe_arg1 for probe m4"
76 gdb_test
"print \$_probe_arg2 == v" " = 1" \
77 "check \$_probe_arg2 for probe m4"
79 # Reinit GDB
, set a breakpoint
on probe ps.
81 if {[runto
"-pstap test:ps"]} {
82 pass
"run to -pstap test:m4"
84 fail
"run to -pstap test:m4"
87 gdb_test
"print \$_probe_argc" " = 3" \
88 "print \$_probe_argc for probe ps"
89 gdb_test
"print (const char *) \$_probe_arg1" \
90 " = $hex .This is another test message.*" \
91 "print \$_probe_arg1 for probe ps"
96 proc stap_test_no_debuginfo
{exec_name
{arg ""}} {
99 if {[prepare_for_testing
"failed to prepare" ${exec_name} ${testfile}.c \
100 {$
arg nodebug optimize
=-O2
}]} {
104 if {[runto
"-pstap test:user"]} {
105 pass
"run to -pstap test:user"
107 fail
"run to -pstap test:user"
110 # Test probe arguments.
111 gdb_test
"print \$_probe_argc" " = 1" \
112 "print \$_probe_argc for probe user"
113 gdb_test
"print \$_probe_arg0 == 23" " = 1" \
114 "check \$_probe_arg0 for probe user"
115 gdb_test
"print \$_probe_arg1" \
116 "Invalid probe argument 1 -- probe has 1 arguments available" \
117 "check \$_probe_arg1 for probe user"
119 #
Set a breakpoint with multiple probe locations.
120 # In this scenario
, we may expect more than
2 locations because of
121 # the optimizations
(inlining
, loop unrolling
, etc
).
122 gdb_test
"break -pstap test:two" \
123 "Breakpoint .* at $hex.*\[0-9\]+ locations.*" \
124 "set multi-location probe breakpoint (probe two)"
126 # Reinit GDB
, set a breakpoint
on probe m4.
128 if {[runto
"-pstap test:m4"]} {
129 pass
"run to -pstap test:m4"
131 fail
"run to -pstap test:m4"
134 # Testing probe arguments.
135 gdb_test
"print \$_probe_argc" " = 3" \
136 "print \$_probe_argc for probe m4"
137 gdb_test
"print \$_probe_arg0" " = 42" \
138 "check \$_probe_arg0 for probe m4"
139 gdb_test
"print (const char *) \$_probe_arg1" \
140 " = $hex .This is a test message.*" \
141 "check \$_probe_arg1 for probe m4"
142 gdb_test
"print \$_probe_arg2 == 0" " = 1" \
143 "check \$_probe_arg2 for probe m4"
145 # Reinit GDB
, set a breakpoint
on probe ps.
147 if {[runto
"-pstap test:ps"]} {
148 pass
"run to -pstap test:m4"
150 fail
"run to -pstap test:m4"
153 gdb_test
"print \$_probe_argc" " = 3" \
154 "print \$_probe_argc for probe ps"
155 gdb_test
"print (const char *) \$_probe_arg1" \
156 " = $hex .This is another test message.*" \
157 "print \$_probe_arg1 for probe ps"
162 with_test_prefix
"without semaphore, not optimized" {
163 if {[stap_test
"stap-probe-nosem-noopt"] == -1} {
164 untested
"stap probe test failed"
169 with_test_prefix
"with semaphore, not optimized" {
170 stap_test
"stap-probe-sem-noopt" "-DUSE_PROBES"
173 with_test_prefix
"without semaphore, optimized" {
174 stap_test_no_debuginfo
"stap-probe-nosem-opt"
177 with_test_prefix
"with semaphore, optimized" {
178 stap_test_no_debuginfo
"stap-probe-sem-opt" "-DUSE_PROBES"