Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | # Copyright (C) 2012-2020 Free Software Foundation, Inc. |
62e5f89c SDJ |
2 | |
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. | |
7 | # | |
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. | |
12 | # | |
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/>. | |
15 | ||
0ab77f5f | 16 | standard_testfile |
62e5f89c SDJ |
17 | |
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 ""}} { | |
0ab77f5f | 22 | global testfile hex srcfile |
62e5f89c | 23 | |
5b362f04 | 24 | if {[prepare_for_testing "failed to prepare" ${exec_name} $srcfile \ |
47e9d49d | 25 | [concat additional_flags=$arg debug]]} { |
62e5f89c SDJ |
26 | return -1 |
27 | } | |
28 | ||
29 | if ![runto_main] { | |
30 | return -1 | |
31 | } | |
32 | ||
03e98035 | 33 | gdb_test "print \$_probe_argc" "No probe at PC $hex" \ |
62e5f89c SDJ |
34 | "check argument not at probe point" |
35 | ||
47e9d49d GB |
36 | if {[string first "-DUSE_SEMAPHORES" $arg] != -1} { |
37 | gdb_test "info probes stap" \ | |
38 | "test *user *$hex *$hex .*" | |
39 | } else { | |
40 | gdb_test "info probes stap" \ | |
41 | "test *user *$hex .*" | |
42 | } | |
43 | ||
62e5f89c SDJ |
44 | if {[runto "-pstap test:user"]} { |
45 | pass "run to -pstap test:user" | |
46 | } else { | |
47 | fail "run to -pstap test:user" | |
48 | } | |
49 | ||
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" | |
58 | ||
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)" | |
63 | ||
64 | # Reinit GDB, set a breakpoint on probe m4. | |
65 | delete_breakpoints | |
62e5f89c SDJ |
66 | if {[runto "-pstap test:m4"]} { |
67 | pass "run to -pstap test:m4" | |
68 | } else { | |
69 | fail "run to -pstap test:m4" | |
70 | } | |
71 | ||
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" | |
82 | ||
83 | # Reinit GDB, set a breakpoint on probe ps. | |
84 | delete_breakpoints | |
62e5f89c SDJ |
85 | if {[runto "-pstap test:ps"]} { |
86 | pass "run to -pstap test:m4" | |
87 | } else { | |
88 | fail "run to -pstap test:m4" | |
89 | } | |
90 | ||
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" | |
96 | ||
97 | return 0 | |
98 | } | |
99 | ||
100 | proc stap_test_no_debuginfo {exec_name {arg ""}} { | |
101 | global testfile hex | |
102 | ||
5b362f04 | 103 | if {[prepare_for_testing "failed to prepare" ${exec_name} ${testfile}.c \ |
47e9d49d | 104 | [concat additional_flags=$arg nodebug optimize=-O2]]} { |
62e5f89c SDJ |
105 | return -1 |
106 | } | |
107 | ||
108 | if {[runto "-pstap test:user"]} { | |
109 | pass "run to -pstap test:user" | |
110 | } else { | |
111 | fail "run to -pstap test:user" | |
112 | } | |
113 | ||
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" | |
122 | ||
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)" | |
129 | ||
130 | # Reinit GDB, set a breakpoint on probe m4. | |
131 | delete_breakpoints | |
62e5f89c SDJ |
132 | if {[runto "-pstap test:m4"]} { |
133 | pass "run to -pstap test:m4" | |
134 | } else { | |
135 | fail "run to -pstap test:m4" | |
136 | } | |
137 | ||
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" | |
148 | ||
149 | # Reinit GDB, set a breakpoint on probe ps. | |
150 | delete_breakpoints | |
62e5f89c SDJ |
151 | if {[runto "-pstap test:ps"]} { |
152 | pass "run to -pstap test:m4" | |
153 | } else { | |
154 | fail "run to -pstap test:m4" | |
155 | } | |
156 | ||
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" | |
162 | ||
163 | return 0 | |
164 | } | |
165 | ||
166 | with_test_prefix "without semaphore, not optimized" { | |
167 | if {[stap_test "stap-probe-nosem-noopt"] == -1} { | |
5b362f04 | 168 | untested "stap probe test failed" |
62e5f89c SDJ |
169 | return -1 |
170 | } | |
171 | } | |
172 | ||
173 | with_test_prefix "with semaphore, not optimized" { | |
47e9d49d | 174 | stap_test "stap-probe-sem-noopt" "-DUSE_SEMAPHORES" |
62e5f89c SDJ |
175 | } |
176 | ||
177 | with_test_prefix "without semaphore, optimized" { | |
178 | stap_test_no_debuginfo "stap-probe-nosem-opt" | |
179 | } | |
180 | ||
181 | with_test_prefix "with semaphore, optimized" { | |
47e9d49d | 182 | stap_test_no_debuginfo "stap-probe-sem-opt" "-DUSE_SEMAPHORES" |
62e5f89c | 183 | } |