gdb/testsuite/
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.gdb / observer.exp
CommitLineData
4c38e0a4 1# Copyright 2003, 2004, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
5b2a3989
JB
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
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
5b2a3989 6# (at your option) any later version.
e22f8b7c 7#
5b2a3989
JB
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.
e22f8b7c 12#
5b2a3989 13# You should have received a copy of the GNU General Public License
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
5b2a3989 15
5b2a3989
JB
16# This file was written by Joel Brobecker (brobecker@gnat.com), derived
17# from xfullpath.exp.
18
19if $tracelevel then {
20 strace $tracelevel
21}
22
5b2a3989
JB
23
24# are we on a target board
c1d88655 25if { [is_remote target] || ![isnative] } then {
5b2a3989
JB
26 return
27}
28
5b2a3989
JB
29proc setup_test { executable } {
30 global gdb_prompt
31 global timeout
32
33 # load yourself into the debugger
34 # This can take a relatively long time, particularly for testing where
35 # the executable is being accessed over a network, or where gdb does not
36 # support partial symbols for a particular target and has to load the
37 # entire symbol table. Set the timeout to 10 minutes, which should be
38 # adequate for most environments (it *has* timed out with 5 min on a
39 # SPARCstation SLC under moderate load, so this isn't unreasonable).
40 # After gdb is started, set the timeout to 30 seconds for the duration
41 # of this test, and then back to the original value.
42
43 set oldtimeout $timeout
44 set timeout 600
45 verbose "Timeout is now $timeout seconds" 2
3e3ffd2b 46
2db8e78e
MC
47 global gdb_file_cmd_debug_info
48 set gdb_file_cmd_debug_info "unset"
49
3e3ffd2b 50 set result [gdb_load $executable]
5b2a3989
JB
51 set timeout $oldtimeout
52 verbose "Timeout is now $timeout seconds" 2
53
2db8e78e
MC
54 if { $result != 0 } then {
55 return -1
56 }
57
58 if { $gdb_file_cmd_debug_info != "debug" } then {
59 untested "No debug information, skipping testcase."
3e3ffd2b
MC
60 return -1
61 }
62
5b2a3989
JB
63 # Set a breakpoint at main
64 gdb_test "break captured_main" \
65 "Breakpoint.*at.* file.*, line.*" \
66 "breakpoint in captured_main"
67
68 # run yourself
69 # It may take a very long time for the inferior gdb to start (lynx),
70 # so we bump it back up for the duration of this command.
71 set timeout 600
72
73 set description "run until breakpoint at captured_main"
ab89363a 74 gdb_test_multiple "run -nw" "$description" {
5b2a3989
JB
75 -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.* at .*main.c:.*$gdb_prompt $" {
76 pass "$description"
77 }
78 -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.*$gdb_prompt $" {
79 xfail "$description (line numbers scrambled?)"
80 }
81 -re "vfork: No more processes.*$gdb_prompt $" {
82 fail "$description (out of virtual memory)"
83 set timeout $oldtimeout
84 verbose "Timeout is now $timeout seconds" 2
85 return -1
86 }
87 -re ".*$gdb_prompt $" {
88 fail "$description"
89 set timeout $oldtimeout
90 verbose "Timeout is now $timeout seconds" 2
91 return -1
92 }
5b2a3989
JB
93 }
94
95 set timeout $oldtimeout
96 verbose "Timeout is now $timeout seconds" 2
97
98 return 0
99}
100
ab89363a 101proc attach_first_observer { message } {
019ebafc
MS
102 gdb_test_no_output "set \$first_obs = observer_attach_test_notification (&observer_test_first_notification_function)" \
103 "$message; attach first observer"
5b2a3989
JB
104}
105
ab89363a 106proc attach_second_observer { message } {
019ebafc
MS
107 gdb_test_no_output "set \$second_obs = observer_attach_test_notification (&observer_test_second_notification_function)" \
108 "$message; attach second observer"
5b2a3989
JB
109}
110
ab89363a 111proc attach_third_observer { message } {
019ebafc
MS
112 gdb_test_no_output "set \$third_obs = observer_attach_test_notification (&observer_test_third_notification_function)" \
113 "$message; attach third observer"
5b2a3989
JB
114}
115
ab89363a 116proc detach_first_observer { message } {
019ebafc
MS
117 gdb_test_no_output "call observer_detach_test_notification (\$first_obs)" \
118 "$message; detach first observer"
5b2a3989
JB
119}
120
ab89363a 121proc detach_second_observer { message } {
019ebafc
MS
122 gdb_test_no_output "call observer_detach_test_notification (\$second_obs)" \
123 "$message; detach second observer"
5b2a3989
JB
124}
125
ab89363a 126proc detach_third_observer { message } {
019ebafc
MS
127 gdb_test_no_output "call observer_detach_test_notification (\$third_obs)" \
128 "$message; detach third observer"
5b2a3989
JB
129}
130
131proc check_counters { first second third message } {
132 gdb_test "print observer_test_first_observer" \
ab89363a
AC
133 ".\[0-9\]+ =.*$first" \
134 "$message; check first observer counter value"
5b2a3989 135 gdb_test "print observer_test_second_observer" \
ab89363a
AC
136 ".\[0-9\]+ =.*$second" \
137 "$message; check second observer counter value"
5b2a3989 138 gdb_test "print observer_test_third_observer" \
ab89363a
AC
139 ".\[0-9\]+ =.*$third" \
140 "$message; check third observer counter value"
5b2a3989
JB
141}
142
ab89363a 143proc reset_counters { message } {
019ebafc 144 gdb_test_no_output "set variable observer_test_first_observer = 0" \
ab89363a 145 "$message; reset first observer counter"
019ebafc 146 gdb_test_no_output "set variable observer_test_second_observer = 0" \
ab89363a 147 "$message; reset second observer counter"
019ebafc 148 gdb_test_no_output "set variable observer_test_third_observer = 0" \
ab89363a 149 "$message; reset third observer counter"
5b2a3989
JB
150}
151
3ea85240 152proc test_notifications { first second third message args } {
ab89363a
AC
153 # Do any initialization
154 for {set i 0} {$i < [llength $args]} {incr i} {
155 [lindex $args $i] $message
156 }
157 reset_counters $message
3ea85240 158 # Call observer_notify_test_notification. Note that this procedure
90990674
JB
159 # takes one argument, but this argument is ignored by the observer
160 # callbacks we have installed. So we just pass an arbitrary value.
019ebafc 161 gdb_test_no_output "call observer_notify_test_notification (0)" \
ab89363a 162 "$message; sending notification"
5b2a3989
JB
163 check_counters $first $second $third $message
164}
165
3ea85240 166proc test_observer { executable } {
5b2a3989
JB
167
168 set setup_result [setup_test $executable]
169 if {$setup_result <0} then {
170 return -1
171 }
172
173 # First, try sending a notification without any observer attached.
3ea85240 174 test_notifications 0 0 0 "no observer attached"
5b2a3989
JB
175
176 # Now, attach one observer, and send a notification.
3ea85240 177 test_notifications 0 1 0 "second observer attached" \
ab89363a 178 attach_second_observer
5b2a3989
JB
179
180 # Remove the observer, and send a notification.
3ea85240 181 test_notifications 0 0 0 "second observer detached" \
ab89363a 182 detach_second_observer
5b2a3989
JB
183
184 # With a new observer.
3ea85240 185 test_notifications 1 0 0 "1st observer added" \
ab89363a 186 attach_first_observer
5b2a3989
JB
187
188 # With 2 observers.
3ea85240 189 test_notifications 1 1 0 "2nd observer added" \
ab89363a 190 attach_second_observer
5b2a3989
JB
191
192 # With 3 observers.
3ea85240 193 test_notifications 1 1 1 "3rd observer added" \
ab89363a 194 attach_third_observer
5b2a3989
JB
195
196 # Remove middle observer.
3ea85240 197 test_notifications 1 0 1 "2nd observer removed" \
ab89363a 198 detach_second_observer
5b2a3989
JB
199
200 # Remove first observer.
3ea85240 201 test_notifications 0 0 1 "1st observer removed" \
ab89363a 202 detach_first_observer
5b2a3989
JB
203
204 # Remove last observer.
3ea85240 205 test_notifications 0 0 0 "3rd observer removed" \
ab89363a 206 detach_third_observer
5b2a3989
JB
207
208 # Go back to 3 observers, and remove them in a different order...
3ea85240 209 test_notifications 1 1 1 "three observers added" \
ab89363a
AC
210 attach_first_observer \
211 attach_second_observer \
212 attach_third_observer
5b2a3989
JB
213
214 # Remove the third observer.
3ea85240 215 test_notifications 1 1 0 "third observer removed" \
ab89363a 216 detach_third_observer
5b2a3989
JB
217
218 # Remove the second observer.
3ea85240 219 test_notifications 1 0 0 "second observer removed" \
ab89363a 220 detach_second_observer
5b2a3989
JB
221
222 # Remove the first observer, no more observers.
3ea85240 223 test_notifications 0 0 0 "first observer removed" \
ab89363a 224 detach_first_observer
5b2a3989
JB
225
226 return 0
227}
228
229# Find a pathname to a file that we would execute if the shell was asked
230# to run $arg using the current PATH.
231
232proc find_gdb { arg } {
233
234 # If the arg directly specifies an existing executable file, then
235 # simply use it.
236
237 if [file executable $arg] then {
238 return $arg
239 }
240
241 set result [which $arg]
242 if [string match "/" [ string range $result 0 0 ]] then {
243 return $result
244 }
245
246 # If everything fails, just return the unqualified pathname as default
247 # and hope for best.
248
249 return $arg
250}
251
252# Run the test with self.
253# Copy the file executable file in case this OS doesn't like to edit its own
254# text space.
255
256set GDB_FULLPATH [find_gdb $GDB]
257
258# Remove any old copy lying around.
259remote_file host delete x$tool
260
261gdb_start
262set file [remote_download host $GDB_FULLPATH x$tool]
3ea85240 263set result [test_observer $file];
5b2a3989
JB
264gdb_exit;
265catch "remote_file host delete $file";
266
267if {$result <0} then {
268 warning "Couldn't test self"
269 return -1
270}
This page took 0.756286 seconds and 4 git commands to generate.