aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.chill/tests2.exp
blob: dcc29cefd1a885d4ad79264e2249184ce9af7a96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# Copyright (C) 1992, 1995 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */

# Please email any bugs, comments, and/or additions to this file to:
# bug-gdb@prep.ai.mit.edu

if $tracelevel then {
	strace $tracelevel
}

set prms_id 0
set bug_id 0

# Set the current language to chill.  This counts as a test.  If it
# fails, then we skip the other tests.

proc set_lang_chill {} {
    global prompt
    global binfile objdir subdir

    if ![file exists $objdir/$subdir/$binfile] then {
	return 0
    }
    verbose "loading file '$objdir/$subdir/$binfile'"
    gdb_load $objdir/$subdir/$binfile

    send "set language chill\n"
    expect {
	-re ".*$prompt $" {}
	timeout { fail "set language chill (timeout)" ; return 0 }
    }

    send "show language\n"
    expect {
	-re ".* source language is \"chill\".*$prompt $" {
	    pass "set language to \"chill\""
	    send "break dummyfunc\n"
	    expect {
		-re ".*$prompt $" {
		    send "run\n"
		    expect -re ".*$prompt $" {}
		    return 1
		}
		timeout {
		    fail "can't set breakpoint (timeout)"
		    return 0
		}
	    }
	}
	-re ".*$prompt $" {
	    fail "setting language to \"chill\""
	    return 0
	}
	timeout {
	    fail "can't show language (timeout)"
	    return 0
	}
    }
}

# Testing printing of a specific value.  Increment passcount for
# success or issue fail message for failure.  In both cases, return
# a 1 to indicate that more tests can proceed.  However a timeout
# is a serious error, generates a special fail message, and causes
# a 0 to be returned to indicate that more tests are likely to fail
# as well.
#
# Args are:
#
#	First one is string to send to gdb
#	Second one is string to match gdb result to
#	Third one is an optional message to be printed

proc test_print_accept { args } {
    global prompt
    global passcount
    global verbose

    if [llength $args]==3 then {
	set message [lindex $args 2]
    } else {
	set message [lindex $args 0]
    }
    set sendthis [lindex $args 0]
    set expectthis [lindex $args 1]
    if $verbose>2 then {
	send_user "Sending \"$sendthis\" to gdb\n"
	send_user "Looking to match \"$expectthis\"\n"
	send_user "Message is \"$message\"\n"
    }
    send "$sendthis\n"
    expect {
	-re ".* = $expectthis\r\n$prompt $" {
	    incr passcount
	    return 1
	}
	-re ".*$prompt $" {
	    if ![string match "" $message] then {
		fail "$sendthis ($message)"
	    } else {
		fail "$sendthis"
	    }
	    return 1
	}
	timeout {
	    fail "$sendthis (timeout)"
	    return 0
	}
    }
}

# Testing printing of a specific value.  Increment passcount for
# success or issue fail message for failure.  In both cases, return
# a 1 to indicate that more tests can proceed.  However a timeout
# is a serious error, generates a special fail message, and causes
# a 0 to be returned to indicate that more tests are likely to fail
# as well.

proc test_print_reject { args } {
    global prompt
    global passcount
    global verbose

    if [llength $args]==2 then {
	set expectthis [lindex $args 1]
    } else {
	set expectthis "should never match this bogus string"
    }
    set sendthis [lindex $args 0]
    if $verbose>2 then {
	send_user "Sending \"$sendthis\" to gdb\n"
	send_user "Looking to match \"$expectthis\"\n"
    }
    send "$sendthis\n"
    expect {
	-re ".*A .* in expression.*\\.*$prompt $" {
	    incr passcount
	    return 1
	}
	-re ".*Junk after end of expression.*$prompt $" {
	    incr passcount
	    return 1
	}
	-re ".*No symbol table is loaded.*$prompt $" {
	    incr passcount
	    return 1
	}
	-re ".*$expectthis.*$prompt $" {
	    incr passcount
	    return 1
	}
	-re ".*$prompt $" {
	    fail "$sendthis not properly rejected"
	    return 1
	}
	timeout {
	    fail "$sendthis (timeout)"
	    return 0
	}
    }
}

# checks if structure was accessed correctly
proc test_write { args } {
    global prompt
    global passcount

    if [llength $args]==5 then {
	set message [lindex $args 4]
	set extended [lindex $args 3]
	set matchval [lindex $args 2]
    } elseif [llength $args]==4 then {
	set message [lindex $args 3]
	set matchval [lindex $args 2]
	set extended ""
    } elseif [llength $args]==3 then {
	set message [lindex $args 2]
	set extended ""
    } else {
	warning "test ($args) write called with wrong number of arguments"
	return 
    }

    set location [lindex $args 0]
    set value [lindex $args 1]
    if ![info exists matchval] then {
	set matchval $value
    }
    verbose "loc: $location, val: $value, msg: $message, ext: $extended, match: $matchval"

    verbose "setting var $value..."
    send "set var $location.m$extended := $value\n"
    expect -re ".*$prompt $" {}
    test_print_accept "print $location" \
	"\[\[\]\\.p1: 2863311530, \\.m: $matchval, \\.p2: 1431655765\[\]\]" \
	"$message"
}

# test write access from gdb (setvar x:=y) from gdb
proc write_access { } {
    global passcount

    set passcount 0
    verbose "testing write access to locations"
    
    # discrete modes
    test_write b1 127 "byte write 1"
    test_write b1 -128 "byte write 2"
    test_write b1 0 "byte write 3"
    test_write ub1 255 "ubyte write 1"
    test_write ub1 0 "ubyte write 2"
    test_write ub1 42 "ubyte write 3"
    test_write i1 32767 "int write 1"
    test_write i1 -32768 "int write 2"
    test_write i1 0 "int write 3"
    test_write ui1 65535 "uint write 1"
    test_write ui1 0 "uint write 2"
    test_write ui1 123 "uint write 3"
    test_write l1 2147483647 "long write 1"
    test_write l1 -2147483648 "long write 2"
    test_write l1 0 "long write 3"
    test_write ul1 4294967295 "ulong write 1"
    test_write ul1 0 "ulong write 2"
    test_write ul1 1000000 "ulong write 3"
    test_write bo1 FALSE "bool write 1"
    test_write bo1 TRUE "bool write 2"
    test_write c1 \"1234\" "char write 1"
    test_write c2 \"1234567\" "char write 2"
    test_write c3 \"654321\" "char write 3"
    test_write c4 C'65' 'e' "char write 4"
    test_write bi1 B'10100101' "bitstring write 1"
    test_write bi2 B'0101001010' "bitstring write 2"
    test_write se1 a "set write 1"
    test_write se1 h "set write 2"
    # The following two use numbered sets with too-large values.
    setup_xfail "*-*-*"
    test_write nse1 nb "numbered set write 1"
    setup_xfail "*-*-*"
    test_write nse1 nc "numbered set write 2"
    test_write r1 127 "range write 1"
    test_write r2 32767 "range write 2"
    test_write r3 2147483647 "range write 3"

    # powerset modes
    test_write p1 {[pa:ph]} {\[pa:ph\]} "powerset write 1"
    test_write p1 {[pa, pc:pf, ph]} {\[pa, pc:pf, ph\]} "powerset write 2"
    test_write p1 {[pa, pc, pe, pg]} {\[pa, pc, pe, pg\]} "powerset write 3"
    test_write p1 {[]} {\[\]} "powerset write 4"
    test_write p2 {[1:32]} {\[1:32\]} "powerset write 5"
    test_write p2 {[1, 3:30, 32]} {\[1, 3:30, 32\]} "powerset write 6"
    test_write p2 {[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]} {\[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31\]} \
	"powerset write 7"
    test_write p2 {[]} {\[\]} "powerset write 8"

# Fixme: this should be rejected by gnuchill
#    test_write p3 {[-2147483648:2147483647]} {\[-2147483648:2147483647\]} \
#	"powerset write 9"
#    test_write p3 {[-2147483648, -1000000:1000000, 2147483647]} \
#	{\[-2147483648, -1000000:1000000, 2147483647\]} \
#	"powerset write 10"
#    test_write p3 {[-99, -97, -95, 1001, 1003, 1005]} \
#	{\[-99, -97, -95, 1001, 1003, 1005\]} "powerset write 11"
#    test_write p3 {[]} {\[\]} "powerset write 12"
    
    # reference modes
    test_write ref1 ->ref1 {H'[0-9a-fA-F]+} "reference write 1"
    test_write ref2 ->b1 {H'[0-9a-fA-F]+} "reference write 2"
    test_write ref1 NULL "reference write 3"
    test_write ref2 NULL "reference write 4"

    # procedure modes
    test_write pr1 NULL "procefure write 1"
    # FIXME: remove when NULL is understood
    test_write pr1 0 NULL "procefure write 2"
    test_write pr1 dummyfunc {H'[0-9a-fA-F]+ <dummyfunc>} "procedure write 3"

    # timing modes, FIXME when callbacks to timefunctions are implemented
    #test_write ti1 abstime(1970, 3, 12, 10, 43, 0) {} "time write 1"
    #test_write ti2 <set somehow a duration>
    xfail "timing modes not implemented yet"
    
    # real modes
    # This ones 
    test_write re1 42.03 {42.0[0-9]*} "real write 1"
    test_write re1 0 "real write 2"
    test_write re1 "1e+38" {1e\+38|1\.0[0-9]*e\+38|9\.9[0-9]*e\+37} \
	"real write 3"
    test_write re1 "1e+39" Infinity "real write 4"
    test_write re2 42.03 {42.0[0-9]*} "real write 5"
    test_write re2 0 "real write 6"
    test_write re2 "1e+308" {1e\+308} "real write 7"
    test_write re2 "1e+309" Infinity "real write 8"

    # array modes
    test_write arrl1 {[(1:3): [(1:2): -128]]} {\[\(1:3\): \[\(1:2\): -128\]\]}\
	"array write 1"
    test_write arrl1 {[(1:3): [(1:2): 0]]} {\[\(1:3\): \[\(1:2\): 0\]\]}\
	"array write 2"
    test_write arrl1 {[(1): [(1:2): 127], (2): [(1:2): -128], (3): [(1:2): 127]]} {\[\(1\): \[\(1:2\): 127\], \(2\): \[\(1:2\): -128\], \(3\): \[\(1:2\): 127\]\]}\
	"array write 3"
     test_write arrl1 {[(1:3): [(1:2): 0]]} {\[\(1:3\): \[\(1:2\): 0\]\]}\
 	"array write 4"
     setup_xfail "*-*-*"
     # Bogus test case - type mismatch?
     test_write arrl1 {[(1): 127, (2): -128]} "array write 5"
     test_write arrl1 {[(1:3): [(1:2): 0]]} {\[\(1:3\): \[\(1:2\): 0\]\]}\
 	"array write 6"

    # structure modes
    test_write strul1 {[.a: -32768, .b: 32767, .ch: "ZZZZ"]} \
	{\[\.a: -32768, \.b: 32767, \.ch: \"ZZZZ\"\]} \
	"structure write 1"
    test_write strul1 {[.a: 0, .b: 0, .ch: "0000"]} \
	{\[\.a: 0, \.b: 0, \.ch: \"0000\"\]} \
	"structure write 2"
    test_write strul1 -32768 {\[\.a: -32768, \.b: 0, \.ch: \"0000\"\]} \
	{.a} "structure write 3"
    test_write strul1 {[.a: 0, .b: 0, .ch: "0000"]} \
	{\[\.a: 0, \.b: 0, \.ch: \"0000\"\]} \
	"structure write 4"
    test_write strul1 -32768 {\[\.a: 0, \.b: -32768, \.ch: \"0000\"\]} \
	{.b} "structure write 5"
    test_write strul1 {[.a: 0, .b: 0, .ch: "0000"]} \
	{\[\.a: 0, \.b: 0, \.ch: \"0000\"\]} \
	"structure write 6"
    test_write strul1 \"HUGO\" {\[\.a: 0, \.b: 0, \.ch: \"HUGO\"\]} \
	{.ch} "structure write 7"

    if $passcount then {
	pass "$passcount correct write access tests"
    }
}

# Start with a fresh gdb.

set binfile "tests2.exe"
global passcount

gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir

send "set print sevenbit-strings\n" ; expect -re ".*$prompt $"

if [set_lang_chill] then {
    write_access
} else {
    warning "$test_name tests suppressed."
}