OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gdb-7.1/] [gdb/] [testsuite/] [gdb.gdb/] [observer.exp] - Blame information for rev 387

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.