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