]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/relational.exp
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / relational.exp
1 # Copyright 1998, 1999, 2007 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 2 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, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
19
20 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
21
22 # This file is part of the gdb testsuite
23 #
24 # tests for correctenss of relational operators, associativity and precedence
25 # with integer type variables
26 #
27
28 if $tracelevel then {
29 strace $tracelevel
30 }
31
32 #
33 # test running programs
34 #
35 set prms_id 0
36 set bug_id 0
37
38 set testfile "int-type"
39 set srcfile ${testfile}.c
40 set binfile ${objdir}/${subdir}/${testfile}
41 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
42 untested relational.exp
43 return -1
44 }
45
46 if [get_compiler_info ${binfile}] {
47 return -1;
48 }
49
50 gdb_exit
51 gdb_start
52 gdb_reinitialize_dir $srcdir/$subdir
53 gdb_load ${binfile}
54
55
56 #
57 # set it up at a breakpoint so we can play with the variable values
58 #
59
60 if ![runto_main] then {
61 perror "couldn't run to breakpoint"
62 continue
63 }
64
65 #
66 # test expressions with "int" types
67 #
68
69 gdb_test "set variable x=14" "" "set variable x=14"
70 gdb_test "set variable y=2" "" "set variable y=2"
71 gdb_test "set variable z=2" "" "set variable z=2"
72 gdb_test "set variable w=3" "" "set variable w=3"
73
74 send_gdb "print x\n"
75 gdb_expect {
76 -re ".*14.*$gdb_prompt $" {
77 pass "print value of x"
78 }
79 -re ".*$gdb_prompt $" { fail "print value of x" }
80 timeout { fail "(timeout) print value of x" }
81 }
82
83
84 send_gdb "print y\n"
85 gdb_expect {
86 -re ".*2.*$gdb_prompt $" {
87 pass "print value of y"
88 }
89 -re ".*$gdb_prompt $" { fail "print value of y" }
90 timeout { fail "(timeout) print value of y" }
91 }
92
93 send_gdb "print z\n"
94 gdb_expect {
95 -re ".*2.*$gdb_prompt $" {
96 pass "print value of z"
97 }
98 -re ".*$gdb_prompt $" { fail "print value of z" }
99 timeout { fail "(timeout) print value of z" }
100 }
101
102 send_gdb "print w\n"
103 gdb_expect {
104 -re ".*3.*$gdb_prompt $" {
105 pass "print value of w"
106 }
107 -re ".*$gdb_prompt $" { fail "print value of w" }
108 timeout { fail "(timeout) print value of w" }
109 }
110
111
112
113 send_gdb "print x < y\n"
114 gdb_expect {
115 -re ".*$false.*$gdb_prompt $" {
116 pass "print value of x<y"
117 }
118 -re ".*$gdb_prompt $" { fail "print value of x<y" }
119 timeout { fail "(timeout) print value of x<y" }
120 }
121
122 send_gdb "print x <= y\n"
123 gdb_expect {
124 -re ".*$false.*$gdb_prompt $" {
125 pass "print value of x<=y"
126 }
127 -re ".*$gdb_prompt $" { fail "print value of x<=y" }
128 timeout { fail "(timeout) print value of x<=y" }
129 }
130
131 send_gdb "print x > y\n"
132 gdb_expect {
133 -re ".*$true.*$gdb_prompt $" {
134 pass "print value of x>y"
135 }
136 -re ".*$gdb_prompt $" { fail "print value of x>y" }
137 timeout { fail "(timeout) print value of x>y" }
138 }
139
140 send_gdb "print x >= y\n"
141 gdb_expect {
142 -re ".*$true.*$gdb_prompt $" {
143 pass "print value of x>=y"
144 }
145 -re ".*$gdb_prompt $" { fail "print value of x>=y" }
146 timeout { fail "(timeout) print value of x>=y" }
147 }
148
149 send_gdb "print x == y\n"
150 gdb_expect {
151 -re ".*$false.*$gdb_prompt $" {
152 pass "print value of x==y"
153 }
154 -re ".*$gdb_prompt $" { fail "print value of x==y" }
155 timeout { fail "(timeout) print value of x==y" }
156 }
157
158 send_gdb "print x != y\n"
159 gdb_expect {
160 -re ".*$true.*$gdb_prompt $" {
161 pass "print value of x!=y"
162 }
163 -re ".*$gdb_prompt $" { fail "print value of x!=y" }
164 timeout { fail "(timeout) print value of x!=y" }
165 }
166
167
168
169 # Test associativity of <, >, <=, >=, ==, !=
170
171 gdb_test "set variable x=3" "" "set variable x"
172 gdb_test "set variable y=5" "" "set variable y"
173 gdb_test "set variable z=2" "" "set variable z"
174
175
176
177 send_gdb "print x < y < z\n"
178 gdb_expect {
179 -re ".*$true.*\r\n$gdb_prompt $" {
180 pass "print value of x<y<z"
181 }
182 -re ".*$gdb_prompt $" { fail "print value of x<y<z" }
183 timeout { fail "(timeout) print value of x<y<z" }
184 }
185
186 send_gdb "print x <= y <= z\n"
187 gdb_expect {
188 -re ".*$true\r\n$gdb_prompt $" {
189 pass "print value of x<=y<=z"
190 }
191 -re ".*$gdb_prompt $" { fail "print value of x<=y<=z" }
192 timeout { fail "(timeout) print value of x<=y<=z" }
193 }
194
195 send_gdb "print x > y > z\n"
196 gdb_expect {
197 -re ".*$false.*\r\n$gdb_prompt $" {
198 pass "print value of x>y>z"
199 }
200 -re 8".*$gdb_prompt $" { fail "print value of x>y>z" }
201 timeout { fail "(timeout) print value of x>y>z" }
202 }
203
204 send_gdb "print x >= y >= z\n"
205 gdb_expect {
206 -re ".*$false.*\r\n$gdb_prompt $" {
207 pass "print value of x>=y>=z"
208 }
209 -re ".*$gdb_prompt $" { fail "print value of x>=y>=z" }
210 timeout { fail "(timeout) print value of x>=y>=z" }
211 }
212
213 gdb_test "set variable x=2" "" "set variable x"
214 gdb_test "set variable y=2" "" "set variable y"
215 gdb_test "set variable z=1" "" "set variable z"
216
217
218 send_gdb "print x == y == z\n"
219 gdb_expect {
220 -re ".*$true.*$gdb_prompt $" {
221 pass "print value of x==y==z"
222 }
223 -re ".*$gdb_prompt $" { fail "print value of x==y==z" }
224 timeout { fail "(timeout) print value of x==y==z" }
225 }
226
227 gdb_test "set variable z=0" "" "set variable z"
228
229
230 send_gdb "print x != y != z\n"
231 gdb_expect {
232 -re ".*$false\r\n$gdb_prompt $" {
233 pass "print value of x!=y!=z"
234 }
235 -re ".*$gdb_prompt $" { fail "print value of x!=y!=z" }
236 timeout { fail "(timeout) print value of x!=y!=z" }
237 }
238
239
240 # test precedence rules on pairs of relational operators
241
242 gdb_test "set variable x=0" "" "set variable x"
243 gdb_test "set variable y=2" "" "set variable y"
244 gdb_test "set variable z=2" "" "set variable z"
245
246
247 send_gdb "print x < y == z\n"
248 gdb_expect {
249 -re ".*$false.*$gdb_prompt $" {
250 pass "print value of x<y==z"
251 }
252 -re ".*$gdb_prompt $" { fail "print value of x<y==z" }
253 timeout { fail "(timeout) print value of x<y==z" }
254 }
255
256 # 0 2 2
257 send_gdb "print x < y != z\n"
258 gdb_expect {
259 -re ".*$true.*$gdb_prompt $" {
260 pass "print value of x<y!=z"
261 }
262 -re ".*$gdb_prompt $" { fail "print value of x<y!=z" }
263 timeout { fail "(timeout) print value of x<y!=z" }
264 }
265
266 gdb_test "set variable x=2" "" "set variable x"
267 gdb_test "set variable y=3" "" "set variable y"
268 gdb_test "set variable z=1" "" "set variable z"
269
270
271 # 2 3 1
272 send_gdb "print x < y <= z\n"
273 gdb_expect {
274 -re ".*$true.*$gdb_prompt $" {
275 pass "print value of x<y<=z"
276 }
277 -re ".*$gdb_prompt $" { fail "print value of x<y<=z" }
278 timeout { fail "(timeout) print value of x<y<=z" }
279 }
280
281
282 # 2 3 1
283 send_gdb "print x < y >= z\n"
284 gdb_expect {
285 -re ".*$true.*$gdb_prompt $" {
286 pass "print value of x<y>=z"
287 }
288 -re ".*$gdb_prompt $" { fail "print value of x<y>=z" }
289 timeout { fail "(timeout) print value of x<y>=z" }
290 }
291
292
293 gdb_test "set variable z=0" "" " set variable z"
294
295
296 # 2 3 0
297 send_gdb "print x < y > z\n"
298 gdb_expect {
299 -re ".*$true.*$gdb_prompt $" {
300 pass "print value of x<y>z"
301 }
302 -re ".*$gdb_prompt $" { fail "print value of x<y>z" }
303 timeout { fail "(timeout) print value of x<y>z" }
304 }
305
306
307 gdb_test "set variable x=1" "" " set variable x"
308
309 # 1 3 0
310 send_gdb "print x > y >= z\n"
311 gdb_expect {
312 -re ".*$true.*$gdb_prompt $" {
313 pass "print value of x>y>=z"
314 }
315 -re ".*$gdb_prompt $" { fail "print value of x>y>=z" }
316 timeout { fail "(timeout) print value of x>y>=z" }
317 }
318
319
320 gdb_test "set variable z=2" "" " set variable z"
321
322 # 1 3 2
323 send_gdb "print x > y == z\n"
324 gdb_expect {
325 -re ".*$false.*$gdb_prompt $" {
326 pass "print value of x>y==z"
327 }
328 -re ".*$gdb_prompt $" { fail "print value of x>y==z" }
329 timeout { fail "(timeout) print value of x>y==z" }
330 }
331
332
333 gdb_test "set variable x=2" "" " set variable x"
334 gdb_test "set variable z=0" "" " set variable z"
335
336 # 2 3 0
337 send_gdb "print x > y != z\n"
338 gdb_expect {
339 -re ".*$false.*$gdb_prompt $" {
340 pass "print value of x>y!=z"
341 }
342 -re ".*$gdb_prompt $" { fail "print value of x>y!=z" }
343 timeout { fail "(timeout) print value of x>y!=z" }
344 }
345
346
347 gdb_test "set variable x=4" "" "set x to 4"
348
349 # 4 3 0
350 send_gdb "print x > y <= z\n"
351 gdb_expect {
352 -re ".*$false.*$gdb_prompt $" {
353 pass "print value of x>y<=z"
354 }
355 -re ".*$gdb_prompt $" { fail "print value of x>y<=z" }
356 timeout { fail "(timeout) print value of x>y<=z" }
357 }
358
359 # 4 3 0
360 send_gdb "print x >= y == z\n"
361 gdb_expect {
362 -re ".*$false\r\n$gdb_prompt $" {
363 pass "print value of x>=y==z"
364 }
365 -re ".*$gdb_prompt $" { fail "print value of x>=y==z" }
366 timeout { fail "(timeout) print value of x>=y==z" }
367 }
368
369
370 gdb_test "set variable x=2" "" " set variable x"
371
372 # 2 3 0
373 send_gdb "print x >= y != z\n"
374 gdb_expect {
375 -re ".*$false\r\n$gdb_prompt $" {
376 pass "print value of x>=y!=z"
377 }
378 -re ".*$gdb_prompt $" { fail "print value of x>=y!=z" }
379 timeout { fail "(timeout) print value of x>=y!=z" }
380 }
381
382
383 gdb_test "set variable x=0" "" " set variable x"
384 gdb_test "set variable z=4" "" " set variable z"
385
386 # 0 3 4
387 send_gdb "print x >= y <= z\n"
388 gdb_expect {
389 -re ".*$true\r\n$gdb_prompt $" {
390 pass "print value of x>=y<=z"
391 }
392 -re ".*$gdb_prompt $" { fail "print value of x>=y<=z" }
393 timeout { fail "(timeout) print value of x>=y<=z" }
394 }
395
396 # 0 3 4
397 send_gdb "print x <= y == z\n"
398 gdb_expect {
399 -re ".*$false\r\n$gdb_prompt $" {
400 pass "print value of x<=y==z"
401 }
402 -re ".*$gdb_prompt $" { fail "print value of x<=y==z" }
403 timeout { fail "(timeout) print value of x<=y==z" }
404 }
405
406 gdb_test "set variable x=2" "" " set variable x"
407
408 # 2 3 4
409 send_gdb "print x <= y != z\n"
410 gdb_expect {
411 -re ".*$true\r\n$gdb_prompt $" {
412 pass "print value of x<=y!=z"
413 }
414 -re ".*$gdb_prompt $" { fail "print value of x<=y!=z" }
415 timeout { fail "(timeout) print value of x<=y!=z" }
416 }
417
418
419 # 2 3 4
420 send_gdb "print x == y != z\n"
421 gdb_expect {
422 -re ".*$true\r\n$gdb_prompt $" {
423 pass "print value of x==y!=z"
424 }
425 -re ".*$gdb_prompt $" { fail "print value of x==y!=z" }
426 timeout { fail "(timeout) print value of x==y!=z" }
427 }
428
429
430
431 # test use of parenthesis to enforce different order of evaluation
432
433
434 gdb_test "set variable z=0" "" " set variable z"
435
436 # 2 3 0
437 send_gdb "print x >= (y < z)\n"
438 gdb_expect {
439 -re ".*$true\r\n$gdb_prompt $" {
440 pass "print value of x>=(y<z)"
441 }
442 -re ".*$gdb_prompt $" { fail "print value of x>=(y<z)" }
443 timeout { fail "(timeout) print value of x>=(y<z)" }
444 }
445
446
447 # 2 3 0
448 send_gdb "print x >= (y != z)\n"
449 gdb_expect {
450 -re ".*$true\r\n$gdb_prompt $" {
451 pass "print value of x>=(y!=z)"
452 }
453 -re ".*$gdb_prompt $" { fail "print value of x>=(y*!=z)" }
454 timeout { fail "(timeout) print value of x>=(y!=z)" }
455 }
456
457 # 2 3 0
458 send_gdb "print x == (y == z)\n"
459 gdb_expect {
460 -re ".*$false\r\n$gdb_prompt $" {
461 pass "print value of x==(y==z)"
462 }
463 -re ".*$gdb_prompt $" { fail "print value of x==(y==z)" }
464 timeout { fail "(timeout) print value of x==(y==z)" }
465 }
466
467
468 gdb_test "set variable x=1" "" " set variable x"
469 gdb_test "set variable z=4" "" " set variable z"
470
471 # 1 3 4
472 send_gdb "print (x == y) < z\n"
473 gdb_expect {
474 -re ".*$true\r\n$gdb_prompt $" {
475 pass "print value of (x==y)<z"
476 }
477 -re ".*$gdb_prompt $" { fail "print value of (x==y)<z" }
478 timeout { fail "(timeout) print value of (x==y)<z" }
479 }
480
481
482
483
484
485