1 # Copyright 1998, 1999, 2007 Free Software Foundation, Inc.
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.
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.
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.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
20 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
22 # This file is part of the gdb testsuite
24 # tests for correctenss of relational operators, associativity and precedence
25 # with integer type variables
33 # test running programs
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
46 if [get_compiler_info ${binfile}] {
52 gdb_reinitialize_dir $srcdir/$subdir
57 # set it up at a breakpoint so we can play with the variable values
60 if ![runto_main] then {
61 perror "couldn't run to breakpoint"
66 # test expressions with "int" types
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"
76 -re ".*14.*$gdb_prompt $" {
77 pass "print value of x"
79 -re ".*$gdb_prompt $" { fail "print value of x" }
80 timeout { fail "(timeout) print value of x" }
86 -re ".*2.*$gdb_prompt $" {
87 pass "print value of y"
89 -re ".*$gdb_prompt $" { fail "print value of y" }
90 timeout { fail "(timeout) print value of y" }
95 -re ".*2.*$gdb_prompt $" {
96 pass "print value of z"
98 -re ".*$gdb_prompt $" { fail "print value of z" }
99 timeout { fail "(timeout) print value of z" }
104 -re ".*3.*$gdb_prompt $" {
105 pass "print value of w"
107 -re ".*$gdb_prompt $" { fail "print value of w" }
108 timeout { fail "(timeout) print value of w" }
113 send_gdb "print x < y\n"
115 -re ".*$false.*$gdb_prompt $" {
116 pass "print value of x<y"
118 -re ".*$gdb_prompt $" { fail "print value of x<y" }
119 timeout { fail "(timeout) print value of x<y" }
122 send_gdb "print x <= y\n"
124 -re ".*$false.*$gdb_prompt $" {
125 pass "print value of x<=y"
127 -re ".*$gdb_prompt $" { fail "print value of x<=y" }
128 timeout { fail "(timeout) print value of x<=y" }
131 send_gdb "print x > y\n"
133 -re ".*$true.*$gdb_prompt $" {
134 pass "print value of x>y"
136 -re ".*$gdb_prompt $" { fail "print value of x>y" }
137 timeout { fail "(timeout) print value of x>y" }
140 send_gdb "print x >= y\n"
142 -re ".*$true.*$gdb_prompt $" {
143 pass "print value of x>=y"
145 -re ".*$gdb_prompt $" { fail "print value of x>=y" }
146 timeout { fail "(timeout) print value of x>=y" }
149 send_gdb "print x == y\n"
151 -re ".*$false.*$gdb_prompt $" {
152 pass "print value of x==y"
154 -re ".*$gdb_prompt $" { fail "print value of x==y" }
155 timeout { fail "(timeout) print value of x==y" }
158 send_gdb "print x != y\n"
160 -re ".*$true.*$gdb_prompt $" {
161 pass "print value of x!=y"
163 -re ".*$gdb_prompt $" { fail "print value of x!=y" }
164 timeout { fail "(timeout) print value of x!=y" }
169 # Test associativity of <, >, <=, >=, ==, !=
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"
177 send_gdb "print x < y < z\n"
179 -re ".*$true.*\r\n$gdb_prompt $" {
180 pass "print value of x<y<z"
182 -re ".*$gdb_prompt $" { fail "print value of x<y<z" }
183 timeout { fail "(timeout) print value of x<y<z" }
186 send_gdb "print x <= y <= z\n"
188 -re ".*$true\r\n$gdb_prompt $" {
189 pass "print value of x<=y<=z"
191 -re ".*$gdb_prompt $" { fail "print value of x<=y<=z" }
192 timeout { fail "(timeout) print value of x<=y<=z" }
195 send_gdb "print x > y > z\n"
197 -re ".*$false.*\r\n$gdb_prompt $" {
198 pass "print value of x>y>z"
200 -re 8".*$gdb_prompt $" { fail "print value of x>y>z" }
201 timeout { fail "(timeout) print value of x>y>z" }
204 send_gdb "print x >= y >= z\n"
206 -re ".*$false.*\r\n$gdb_prompt $" {
207 pass "print value of x>=y>=z"
209 -re ".*$gdb_prompt $" { fail "print value of x>=y>=z" }
210 timeout { fail "(timeout) print value of x>=y>=z" }
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"
218 send_gdb "print x == y == z\n"
220 -re ".*$true.*$gdb_prompt $" {
221 pass "print value of x==y==z"
223 -re ".*$gdb_prompt $" { fail "print value of x==y==z" }
224 timeout { fail "(timeout) print value of x==y==z" }
227 gdb_test "set variable z=0" "" "set variable z"
230 send_gdb "print x != y != z\n"
232 -re ".*$false\r\n$gdb_prompt $" {
233 pass "print value of x!=y!=z"
235 -re ".*$gdb_prompt $" { fail "print value of x!=y!=z" }
236 timeout { fail "(timeout) print value of x!=y!=z" }
240 # test precedence rules on pairs of relational operators
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"
247 send_gdb "print x < y == z\n"
249 -re ".*$false.*$gdb_prompt $" {
250 pass "print value of x<y==z"
252 -re ".*$gdb_prompt $" { fail "print value of x<y==z" }
253 timeout { fail "(timeout) print value of x<y==z" }
257 send_gdb "print x < y != z\n"
259 -re ".*$true.*$gdb_prompt $" {
260 pass "print value of x<y!=z"
262 -re ".*$gdb_prompt $" { fail "print value of x<y!=z" }
263 timeout { fail "(timeout) print value of x<y!=z" }
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"
272 send_gdb "print x < y <= z\n"
274 -re ".*$true.*$gdb_prompt $" {
275 pass "print value of x<y<=z"
277 -re ".*$gdb_prompt $" { fail "print value of x<y<=z" }
278 timeout { fail "(timeout) print value of x<y<=z" }
283 send_gdb "print x < y >= z\n"
285 -re ".*$true.*$gdb_prompt $" {
286 pass "print value of x<y>=z"
288 -re ".*$gdb_prompt $" { fail "print value of x<y>=z" }
289 timeout { fail "(timeout) print value of x<y>=z" }
293 gdb_test "set variable z=0" "" " set variable z"
297 send_gdb "print x < y > z\n"
299 -re ".*$true.*$gdb_prompt $" {
300 pass "print value of x<y>z"
302 -re ".*$gdb_prompt $" { fail "print value of x<y>z" }
303 timeout { fail "(timeout) print value of x<y>z" }
307 gdb_test "set variable x=1" "" " set variable x"
310 send_gdb "print x > y >= z\n"
312 -re ".*$true.*$gdb_prompt $" {
313 pass "print value of x>y>=z"
315 -re ".*$gdb_prompt $" { fail "print value of x>y>=z" }
316 timeout { fail "(timeout) print value of x>y>=z" }
320 gdb_test "set variable z=2" "" " set variable z"
323 send_gdb "print x > y == z\n"
325 -re ".*$false.*$gdb_prompt $" {
326 pass "print value of x>y==z"
328 -re ".*$gdb_prompt $" { fail "print value of x>y==z" }
329 timeout { fail "(timeout) print value of x>y==z" }
333 gdb_test "set variable x=2" "" " set variable x"
334 gdb_test "set variable z=0" "" " set variable z"
337 send_gdb "print x > y != z\n"
339 -re ".*$false.*$gdb_prompt $" {
340 pass "print value of x>y!=z"
342 -re ".*$gdb_prompt $" { fail "print value of x>y!=z" }
343 timeout { fail "(timeout) print value of x>y!=z" }
347 gdb_test "set variable x=4" "" "set x to 4"
350 send_gdb "print x > y <= z\n"
352 -re ".*$false.*$gdb_prompt $" {
353 pass "print value of x>y<=z"
355 -re ".*$gdb_prompt $" { fail "print value of x>y<=z" }
356 timeout { fail "(timeout) print value of x>y<=z" }
360 send_gdb "print x >= y == z\n"
362 -re ".*$false\r\n$gdb_prompt $" {
363 pass "print value of x>=y==z"
365 -re ".*$gdb_prompt $" { fail "print value of x>=y==z" }
366 timeout { fail "(timeout) print value of x>=y==z" }
370 gdb_test "set variable x=2" "" " set variable x"
373 send_gdb "print x >= y != z\n"
375 -re ".*$false\r\n$gdb_prompt $" {
376 pass "print value of x>=y!=z"
378 -re ".*$gdb_prompt $" { fail "print value of x>=y!=z" }
379 timeout { fail "(timeout) print value of x>=y!=z" }
383 gdb_test "set variable x=0" "" " set variable x"
384 gdb_test "set variable z=4" "" " set variable z"
387 send_gdb "print x >= y <= z\n"
389 -re ".*$true\r\n$gdb_prompt $" {
390 pass "print value of x>=y<=z"
392 -re ".*$gdb_prompt $" { fail "print value of x>=y<=z" }
393 timeout { fail "(timeout) print value of x>=y<=z" }
397 send_gdb "print x <= y == z\n"
399 -re ".*$false\r\n$gdb_prompt $" {
400 pass "print value of x<=y==z"
402 -re ".*$gdb_prompt $" { fail "print value of x<=y==z" }
403 timeout { fail "(timeout) print value of x<=y==z" }
406 gdb_test "set variable x=2" "" " set variable x"
409 send_gdb "print x <= y != z\n"
411 -re ".*$true\r\n$gdb_prompt $" {
412 pass "print value of x<=y!=z"
414 -re ".*$gdb_prompt $" { fail "print value of x<=y!=z" }
415 timeout { fail "(timeout) print value of x<=y!=z" }
420 send_gdb "print x == y != z\n"
422 -re ".*$true\r\n$gdb_prompt $" {
423 pass "print value of x==y!=z"
425 -re ".*$gdb_prompt $" { fail "print value of x==y!=z" }
426 timeout { fail "(timeout) print value of x==y!=z" }
431 # test use of parenthesis to enforce different order of evaluation
434 gdb_test "set variable z=0" "" " set variable z"
437 send_gdb "print x >= (y < z)\n"
439 -re ".*$true\r\n$gdb_prompt $" {
440 pass "print value of x>=(y<z)"
442 -re ".*$gdb_prompt $" { fail "print value of x>=(y<z)" }
443 timeout { fail "(timeout) print value of x>=(y<z)" }
448 send_gdb "print x >= (y != z)\n"
450 -re ".*$true\r\n$gdb_prompt $" {
451 pass "print value of x>=(y!=z)"
453 -re ".*$gdb_prompt $" { fail "print value of x>=(y*!=z)" }
454 timeout { fail "(timeout) print value of x>=(y!=z)" }
458 send_gdb "print x == (y == z)\n"
460 -re ".*$false\r\n$gdb_prompt $" {
461 pass "print value of x==(y==z)"
463 -re ".*$gdb_prompt $" { fail "print value of x==(y==z)" }
464 timeout { fail "(timeout) print value of x==(y==z)" }
468 gdb_test "set variable x=1" "" " set variable x"
469 gdb_test "set variable z=4" "" " set variable z"
472 send_gdb "print (x == y) < z\n"
474 -re ".*$true\r\n$gdb_prompt $" {
475 pass "print value of (x==y)<z"
477 -re ".*$gdb_prompt $" { fail "print value of (x==y)<z" }
478 timeout { fail "(timeout) print value of (x==y)<z" }