1 # Copyright (C) 1998 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 additional_flags=-w}] != "" } {
42 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
45 if [get_compiler_info ${binfile}] {
51 gdb_reinitialize_dir $srcdir/$subdir
56 # set it up at a breakpoint so we can play with the variable values
59 if ![runto_main] then {
60 perror "couldn't run to breakpoint"
65 # test expressions with "int" types
68 gdb_test "set variable x=14" "" "set variable x=14"
69 gdb_test "set variable y=2" "" "set variable y=2"
70 gdb_test "set variable z=2" "" "set variable z=2"
71 gdb_test "set variable w=3" "" "set variable w=3"
75 -re ".*14.*$gdb_prompt $" {
76 pass "print value of x"
78 -re ".*$gdb_prompt $" { fail "print value of x" }
79 timeout { fail "(timeout) print value of x" }
85 -re ".*2.*$gdb_prompt $" {
86 pass "print value of y"
88 -re ".*$gdb_prompt $" { fail "print value of y" }
89 timeout { fail "(timeout) print value of y" }
94 -re ".*2.*$gdb_prompt $" {
95 pass "print value of z"
97 -re ".*$gdb_prompt $" { fail "print value of z" }
98 timeout { fail "(timeout) print value of z" }
103 -re ".*3.*$gdb_prompt $" {
104 pass "print value of w"
106 -re ".*$gdb_prompt $" { fail "print value of w" }
107 timeout { fail "(timeout) print value of w" }
112 send_gdb "print x < y\n"
114 -re ".*$false.*$gdb_prompt $" {
115 pass "print value of x<y"
117 -re ".*$gdb_prompt $" { fail "print value of x<y" }
118 timeout { fail "(timeout) print value of x<y" }
121 send_gdb "print x <= y\n"
123 -re ".*$false.*$gdb_prompt $" {
124 pass "print value of x<=y"
126 -re ".*$gdb_prompt $" { fail "print value of x<=y" }
127 timeout { fail "(timeout) print value of x<=y" }
130 send_gdb "print x > y\n"
132 -re ".*$true.*$gdb_prompt $" {
133 pass "print value of x>y"
135 -re ".*$gdb_prompt $" { fail "print value of x>y" }
136 timeout { fail "(timeout) print value of x>y" }
139 send_gdb "print x >= y\n"
141 -re ".*$true.*$gdb_prompt $" {
142 pass "print value of x>=y"
144 -re ".*$gdb_prompt $" { fail "print value of x>=y" }
145 timeout { fail "(timeout) print value of x>=y" }
148 send_gdb "print x == y\n"
150 -re ".*$false.*$gdb_prompt $" {
151 pass "print value of x==y"
153 -re ".*$gdb_prompt $" { fail "print value of x==y" }
154 timeout { fail "(timeout) print value of x==y" }
157 send_gdb "print x != y\n"
159 -re ".*$true.*$gdb_prompt $" {
160 pass "print value of x!=y"
162 -re ".*$gdb_prompt $" { fail "print value of x!=y" }
163 timeout { fail "(timeout) print value of x!=y" }
168 # Test associativity of <, >, <=, >=, ==, !=
170 gdb_test "set variable x=3" "" "set variable x"
171 gdb_test "set variable y=5" "" "set variable y"
172 gdb_test "set variable z=2" "" "set variable z"
176 send_gdb "print x < y < z\n"
178 -re ".*$true.*\r\n$gdb_prompt $" {
179 pass "print value of x<y<z"
181 -re ".*$gdb_prompt $" { fail "print value of x<y<z" }
182 timeout { fail "(timeout) print value of x<y<z" }
185 send_gdb "print x <= y <= z\n"
187 -re ".*$true\r\n$gdb_prompt $" {
188 pass "print value of x<=y<=z"
190 -re ".*$gdb_prompt $" { fail "print value of x<=y<=z" }
191 timeout { fail "(timeout) print value of x<=y<=z" }
194 send_gdb "print x > y > z\n"
196 -re ".*$false.*\r\n$gdb_prompt $" {
197 pass "print value of x>y>z"
199 -re 8".*$gdb_prompt $" { fail "print value of x>y>z" }
200 timeout { fail "(timeout) print value of x>y>z" }
203 send_gdb "print x >= y >= z\n"
205 -re ".*$false.*\r\n$gdb_prompt $" {
206 pass "print value of x>=y>=z"
208 -re ".*$gdb_prompt $" { fail "print value of x>=y>=z" }
209 timeout { fail "(timeout) print value of x>=y>=z" }
212 gdb_test "set variable x=2" "" "set variable x"
213 gdb_test "set variable y=2" "" "set variable y"
214 gdb_test "set variable z=1" "" "set variable z"
217 send_gdb "print x == y == z\n"
219 -re ".*$true.*$gdb_prompt $" {
220 pass "print value of x==y==z"
222 -re ".*$gdb_prompt $" { fail "print value of x==y==z" }
223 timeout { fail "(timeout) print value of x==y==z" }
226 gdb_test "set variable z=0" "" "set variable z"
229 send_gdb "print x != y != z\n"
231 -re ".*$false\r\n$gdb_prompt $" {
232 pass "print value of x!=y!=z"
234 -re ".*$gdb_prompt $" { fail "print value of x!=y!=z" }
235 timeout { fail "(timeout) print value of x!=y!=z" }
239 # test precedence rules on pairs of relational operators
241 gdb_test "set variable x=0" "" "set variable x"
242 gdb_test "set variable y=2" "" "set variable y"
243 gdb_test "set variable z=2" "" "set variable z"
246 send_gdb "print x < y == z\n"
248 -re ".*$false.*$gdb_prompt $" {
249 pass "print value of x<y==z"
251 -re ".*$gdb_prompt $" { fail "print value of x<y==z" }
252 timeout { fail "(timeout) print value of x<y==z" }
256 send_gdb "print x < y != z\n"
258 -re ".*$true.*$gdb_prompt $" {
259 pass "print value of x<y!=z"
261 -re ".*$gdb_prompt $" { fail "print value of x<y!=z" }
262 timeout { fail "(timeout) print value of x<y!=z" }
265 gdb_test "set variable x=2" "" "set variable x"
266 gdb_test "set variable y=3" "" "set variable y"
267 gdb_test "set variable z=1" "" "set variable z"
271 send_gdb "print x < y <= z\n"
273 -re ".*$true.*$gdb_prompt $" {
274 pass "print value of x<y<=z"
276 -re ".*$gdb_prompt $" { fail "print value of x<y<=z" }
277 timeout { fail "(timeout) print value of x<y<=z" }
282 send_gdb "print x < y >= z\n"
284 -re ".*$true.*$gdb_prompt $" {
285 pass "print value of x<y>=z"
287 -re ".*$gdb_prompt $" { fail "print value of x<y>=z" }
288 timeout { fail "(timeout) print value of x<y>=z" }
292 gdb_test "set variable z=0" "" " set variable z"
296 send_gdb "print x < y > z\n"
298 -re ".*$true.*$gdb_prompt $" {
299 pass "print value of x<y>z"
301 -re ".*$gdb_prompt $" { fail "print value of x<y>z" }
302 timeout { fail "(timeout) print value of x<y>z" }
306 gdb_test "set variable x=1" "" " set variable x"
309 send_gdb "print x > y >= z\n"
311 -re ".*$true.*$gdb_prompt $" {
312 pass "print value of x>y>=z"
314 -re ".*$gdb_prompt $" { fail "print value of x>y>=z" }
315 timeout { fail "(timeout) print value of x>y>=z" }
319 gdb_test "set variable z=2" "" " set variable z"
322 send_gdb "print x > y == z\n"
324 -re ".*$false.*$gdb_prompt $" {
325 pass "print value of x>y==z"
327 -re ".*$gdb_prompt $" { fail "print value of x>y==z" }
328 timeout { fail "(timeout) print value of x>y==z" }
332 gdb_test "set variable x=2" "" " set variable x"
333 gdb_test "set variable z=0" "" " set variable z"
336 send_gdb "print x > y != z\n"
338 -re ".*$false.*$gdb_prompt $" {
339 pass "print value of x>y!=z"
341 -re ".*$gdb_prompt $" { fail "print value of x>y!=z" }
342 timeout { fail "(timeout) print value of x>y!=z" }
346 gdb_test "set variable x=4" "" "set x to 4"
349 send_gdb "print x > y <= z\n"
351 -re ".*$false.*$gdb_prompt $" {
352 pass "print value of x>y<=z"
354 -re ".*$gdb_prompt $" { fail "print value of x>y<=z" }
355 timeout { fail "(timeout) print value of x>y<=z" }
359 send_gdb "print x >= y == z\n"
361 -re ".*$false\r\n$gdb_prompt $" {
362 pass "print value of x>=y==z"
364 -re ".*$gdb_prompt $" { fail "print value of x>=y==z" }
365 timeout { fail "(timeout) print value of x>=y==z" }
369 gdb_test "set variable x=2" "" " set variable x"
372 send_gdb "print x >= y != z\n"
374 -re ".*$false\r\n$gdb_prompt $" {
375 pass "print value of x>=y!=z"
377 -re ".*$gdb_prompt $" { fail "print value of x>=y!=z" }
378 timeout { fail "(timeout) print value of x>=y!=z" }
382 gdb_test "set variable x=0" "" " set variable x"
383 gdb_test "set variable z=4" "" " set variable z"
386 send_gdb "print x >= y <= z\n"
388 -re ".*$true\r\n$gdb_prompt $" {
389 pass "print value of x>=y<=z"
391 -re ".*$gdb_prompt $" { fail "print value of x>=y<=z" }
392 timeout { fail "(timeout) print value of x>=y<=z" }
396 send_gdb "print x <= y == z\n"
398 -re ".*$false\r\n$gdb_prompt $" {
399 pass "print value of x<=y==z"
401 -re ".*$gdb_prompt $" { fail "print value of x<=y==z" }
402 timeout { fail "(timeout) print value of x<=y==z" }
405 gdb_test "set variable x=2" "" " set variable x"
408 send_gdb "print x <= y != z\n"
410 -re ".*$true\r\n$gdb_prompt $" {
411 pass "print value of x<=y!=z"
413 -re ".*$gdb_prompt $" { fail "print value of x<=y!=z" }
414 timeout { fail "(timeout) print value of x<=y!=z" }
419 send_gdb "print x == y != z\n"
421 -re ".*$true\r\n$gdb_prompt $" {
422 pass "print value of x==y!=z"
424 -re ".*$gdb_prompt $" { fail "print value of x==y!=z" }
425 timeout { fail "(timeout) print value of x==y!=z" }
430 # test use of parenthesis to enforce different order of evaluation
433 gdb_test "set variable z=0" "" " set variable z"
436 send_gdb "print x >= (y < z)\n"
438 -re ".*$true\r\n$gdb_prompt $" {
439 pass "print value of x>=(y<z)"
441 -re ".*$gdb_prompt $" { fail "print value of x>=(y<z)" }
442 timeout { fail "(timeout) print value of x>=(y<z)" }
447 send_gdb "print x >= (y != z)\n"
449 -re ".*$true\r\n$gdb_prompt $" {
450 pass "print value of x>=(y!=z)"
452 -re ".*$gdb_prompt $" { fail "print value of x>=(y*!=z)" }
453 timeout { fail "(timeout) print value of x>=(y!=z)" }
457 send_gdb "print x == (y == z)\n"
459 -re ".*$false\r\n$gdb_prompt $" {
460 pass "print value of x==(y==z)"
462 -re ".*$gdb_prompt $" { fail "print value of x==(y==z)" }
463 timeout { fail "(timeout) print value of x==(y==z)" }
467 gdb_test "set variable x=1" "" " set variable x"
468 gdb_test "set variable z=4" "" " set variable z"
471 send_gdb "print (x == y) < z\n"
473 -re ".*$true\r\n$gdb_prompt $" {
474 pass "print value of (x==y)<z"
476 -re ".*$gdb_prompt $" { fail "print value of (x==y)<z" }
477 timeout { fail "(timeout) print value of (x==y)<z" }