]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/relational.exp
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / relational.exp
CommitLineData
6aba47ca 1# Copyright 1998, 1999, 2007 Free Software Foundation, Inc.
c906108c
SS
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
28if $tracelevel then {
29 strace $tracelevel
30 }
31
32#
33# test running programs
34#
35set prms_id 0
36set bug_id 0
37
38set testfile "int-type"
39set srcfile ${testfile}.c
40set binfile ${objdir}/${subdir}/${testfile}
fc91c6c2 41if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
b60f0898
JB
42 untested relational.exp
43 return -1
c906108c
SS
44 }
45
085dd6e6
JM
46if [get_compiler_info ${binfile}] {
47 return -1;
48}
c906108c
SS
49
50gdb_exit
51gdb_start
52gdb_reinitialize_dir $srcdir/$subdir
53gdb_load ${binfile}
54
55
56#
57# set it up at a breakpoint so we can play with the variable values
58#
59
60if ![runto_main] then {
61 perror "couldn't run to breakpoint"
62 continue
63}
64
65#
66# test expressions with "int" types
67#
68
69gdb_test "set variable x=14" "" "set variable x=14"
70gdb_test "set variable y=2" "" "set variable y=2"
71gdb_test "set variable z=2" "" "set variable z=2"
72gdb_test "set variable w=3" "" "set variable w=3"
73
74send_gdb "print x\n"
75gdb_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
84send_gdb "print y\n"
85gdb_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
93send_gdb "print z\n"
94gdb_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
102send_gdb "print w\n"
103gdb_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
113send_gdb "print x < y\n"
114gdb_expect {
085dd6e6 115 -re ".*$false.*$gdb_prompt $" {
c906108c
SS
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
122send_gdb "print x <= y\n"
123gdb_expect {
085dd6e6 124 -re ".*$false.*$gdb_prompt $" {
c906108c
SS
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
131send_gdb "print x > y\n"
132gdb_expect {
085dd6e6 133 -re ".*$true.*$gdb_prompt $" {
c906108c
SS
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
140send_gdb "print x >= y\n"
141gdb_expect {
085dd6e6 142 -re ".*$true.*$gdb_prompt $" {
c906108c
SS
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
149send_gdb "print x == y\n"
150gdb_expect {
085dd6e6 151 -re ".*$false.*$gdb_prompt $" {
c906108c
SS
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
158send_gdb "print x != y\n"
159gdb_expect {
085dd6e6 160 -re ".*$true.*$gdb_prompt $" {
c906108c
SS
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
171gdb_test "set variable x=3" "" "set variable x"
172gdb_test "set variable y=5" "" "set variable y"
173gdb_test "set variable z=2" "" "set variable z"
174
175
176
177send_gdb "print x < y < z\n"
178gdb_expect {
085dd6e6 179 -re ".*$true.*\r\n$gdb_prompt $" {
c906108c
SS
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
186send_gdb "print x <= y <= z\n"
187gdb_expect {
085dd6e6 188 -re ".*$true\r\n$gdb_prompt $" {
c906108c
SS
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
195send_gdb "print x > y > z\n"
196gdb_expect {
085dd6e6 197 -re ".*$false.*\r\n$gdb_prompt $" {
c906108c
SS
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
204send_gdb "print x >= y >= z\n"
205gdb_expect {
085dd6e6 206 -re ".*$false.*\r\n$gdb_prompt $" {
c906108c
SS
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
213gdb_test "set variable x=2" "" "set variable x"
214gdb_test "set variable y=2" "" "set variable y"
215gdb_test "set variable z=1" "" "set variable z"
216
217
218send_gdb "print x == y == z\n"
219gdb_expect {
085dd6e6 220 -re ".*$true.*$gdb_prompt $" {
c906108c
SS
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
227gdb_test "set variable z=0" "" "set variable z"
228
229
230send_gdb "print x != y != z\n"
231gdb_expect {
085dd6e6 232 -re ".*$false\r\n$gdb_prompt $" {
c906108c
SS
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
242gdb_test "set variable x=0" "" "set variable x"
243gdb_test "set variable y=2" "" "set variable y"
244gdb_test "set variable z=2" "" "set variable z"
245
246
247send_gdb "print x < y == z\n"
248gdb_expect {
085dd6e6 249 -re ".*$false.*$gdb_prompt $" {
c906108c
SS
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
257send_gdb "print x < y != z\n"
258gdb_expect {
085dd6e6 259 -re ".*$true.*$gdb_prompt $" {
c906108c
SS
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
266gdb_test "set variable x=2" "" "set variable x"
267gdb_test "set variable y=3" "" "set variable y"
268gdb_test "set variable z=1" "" "set variable z"
269
270
271# 2 3 1
272send_gdb "print x < y <= z\n"
273gdb_expect {
085dd6e6 274 -re ".*$true.*$gdb_prompt $" {
c906108c
SS
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
283send_gdb "print x < y >= z\n"
284gdb_expect {
085dd6e6 285 -re ".*$true.*$gdb_prompt $" {
c906108c
SS
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
293gdb_test "set variable z=0" "" " set variable z"
294
295
296# 2 3 0
297send_gdb "print x < y > z\n"
298gdb_expect {
085dd6e6 299 -re ".*$true.*$gdb_prompt $" {
c906108c
SS
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
307gdb_test "set variable x=1" "" " set variable x"
308
309# 1 3 0
310send_gdb "print x > y >= z\n"
311gdb_expect {
085dd6e6 312 -re ".*$true.*$gdb_prompt $" {
c906108c
SS
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
320gdb_test "set variable z=2" "" " set variable z"
321
322# 1 3 2
323send_gdb "print x > y == z\n"
324gdb_expect {
085dd6e6 325 -re ".*$false.*$gdb_prompt $" {
c906108c
SS
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
333gdb_test "set variable x=2" "" " set variable x"
334gdb_test "set variable z=0" "" " set variable z"
335
336# 2 3 0
337send_gdb "print x > y != z\n"
338gdb_expect {
085dd6e6 339 -re ".*$false.*$gdb_prompt $" {
c906108c
SS
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
347gdb_test "set variable x=4" "" "set x to 4"
348
349# 4 3 0
350send_gdb "print x > y <= z\n"
351gdb_expect {
085dd6e6 352 -re ".*$false.*$gdb_prompt $" {
c906108c
SS
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
360send_gdb "print x >= y == z\n"
361gdb_expect {
085dd6e6 362 -re ".*$false\r\n$gdb_prompt $" {
c906108c
SS
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
370gdb_test "set variable x=2" "" " set variable x"
371
372# 2 3 0
373send_gdb "print x >= y != z\n"
374gdb_expect {
085dd6e6 375 -re ".*$false\r\n$gdb_prompt $" {
c906108c
SS
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
383gdb_test "set variable x=0" "" " set variable x"
384gdb_test "set variable z=4" "" " set variable z"
385
386# 0 3 4
387send_gdb "print x >= y <= z\n"
388gdb_expect {
085dd6e6 389 -re ".*$true\r\n$gdb_prompt $" {
c906108c
SS
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
397send_gdb "print x <= y == z\n"
398gdb_expect {
085dd6e6 399 -re ".*$false\r\n$gdb_prompt $" {
c906108c
SS
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
406gdb_test "set variable x=2" "" " set variable x"
407
408# 2 3 4
409send_gdb "print x <= y != z\n"
410gdb_expect {
085dd6e6 411 -re ".*$true\r\n$gdb_prompt $" {
c906108c
SS
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
420send_gdb "print x == y != z\n"
421gdb_expect {
085dd6e6 422 -re ".*$true\r\n$gdb_prompt $" {
c906108c
SS
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
434gdb_test "set variable z=0" "" " set variable z"
435
436# 2 3 0
437send_gdb "print x >= (y < z)\n"
438gdb_expect {
085dd6e6 439 -re ".*$true\r\n$gdb_prompt $" {
c906108c
SS
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
448send_gdb "print x >= (y != z)\n"
449gdb_expect {
085dd6e6 450 -re ".*$true\r\n$gdb_prompt $" {
c906108c
SS
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
458send_gdb "print x == (y == z)\n"
459gdb_expect {
085dd6e6 460 -re ".*$false\r\n$gdb_prompt $" {
c906108c
SS
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
468gdb_test "set variable x=1" "" " set variable x"
469gdb_test "set variable z=4" "" " set variable z"
470
471# 1 3 4
472send_gdb "print (x == y) < z\n"
473gdb_expect {
085dd6e6 474 -re ".*$true\r\n$gdb_prompt $" {
c906108c
SS
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