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."
48 gdb_reinitialize_dir $srcdir/$subdir
53 # set it up at a breakpoint so we can play with the variable values
56 if ![runto_main] then {
57 perror "couldn't run to breakpoint"
62 # test expressions with "int" types
65 gdb_test "set variable x=14" "" "set variable x=14"
66 gdb_test "set variable y=2" "" "set variable y=2"
67 gdb_test "set variable z=2" "" "set variable z=2"
68 gdb_test "set variable w=3" "" "set variable w=3"
72 -re ".*14.*$gdb_prompt $" {
73 pass "print value of x"
75 -re ".*$gdb_prompt $" { fail "print value of x" }
76 timeout { fail "(timeout) print value of x" }
82 -re ".*2.*$gdb_prompt $" {
83 pass "print value of y"
85 -re ".*$gdb_prompt $" { fail "print value of y" }
86 timeout { fail "(timeout) print value of y" }
91 -re ".*2.*$gdb_prompt $" {
92 pass "print value of z"
94 -re ".*$gdb_prompt $" { fail "print value of z" }
95 timeout { fail "(timeout) print value of z" }
100 -re ".*3.*$gdb_prompt $" {
101 pass "print value of w"
103 -re ".*$gdb_prompt $" { fail "print value of w" }
104 timeout { fail "(timeout) print value of w" }
109 send_gdb "print x < y\n"
111 -re ".*0.*$gdb_prompt $" {
112 pass "print value of x<y"
114 -re ".*$gdb_prompt $" { fail "print value of x<y" }
115 timeout { fail "(timeout) print value of x<y" }
118 send_gdb "print x <= y\n"
120 -re ".*0.*$gdb_prompt $" {
121 pass "print value of x<=y"
123 -re ".*$gdb_prompt $" { fail "print value of x<=y" }
124 timeout { fail "(timeout) print value of x<=y" }
127 send_gdb "print x > y\n"
129 -re ".*1.*$gdb_prompt $" {
130 pass "print value of x>y"
132 -re ".*$gdb_prompt $" { fail "print value of x>y" }
133 timeout { fail "(timeout) print value of x>y" }
136 send_gdb "print x >= y\n"
138 -re ".*1.*$gdb_prompt $" {
139 pass "print value of x>=y"
141 -re ".*$gdb_prompt $" { fail "print value of x>=y" }
142 timeout { fail "(timeout) print value of x>=y" }
145 send_gdb "print x == y\n"
147 -re ".*0.*$gdb_prompt $" {
148 pass "print value of x==y"
150 -re ".*$gdb_prompt $" { fail "print value of x==y" }
151 timeout { fail "(timeout) print value of x==y" }
154 send_gdb "print x != y\n"
156 -re ".*1.*$gdb_prompt $" {
157 pass "print value of x!=y"
159 -re ".*$gdb_prompt $" { fail "print value of x!=y" }
160 timeout { fail "(timeout) print value of x!=y" }
165 # Test associativity of <, >, <=, >=, ==, !=
167 gdb_test "set variable x=3" "" "set variable x"
168 gdb_test "set variable y=5" "" "set variable y"
169 gdb_test "set variable z=2" "" "set variable z"
173 send_gdb "print x < y < z\n"
175 -re ".*1\r\n$gdb_prompt $" {
176 pass "print value of x<y<z"
178 -re ".*$gdb_prompt $" { fail "print value of x<y<z" }
179 timeout { fail "(timeout) print value of x<y<z" }
182 send_gdb "print x <= y <= z\n"
184 -re ".*1\r\n$gdb_prompt $" {
185 pass "print value of x<=y<=z"
187 -re ".*$gdb_prompt $" { fail "print value of x<=y<=z" }
188 timeout { fail "(timeout) print value of x<=y<=z" }
191 send_gdb "print x > y > z\n"
193 -re ".*0\r\n$gdb_prompt $" {
194 pass "print value of x>y>z"
196 -re 8".*$gdb_prompt $" { fail "print value of x>y>z" }
197 timeout { fail "(timeout) print value of x>y>z" }
200 send_gdb "print x >= y >= z\n"
202 -re ".*0\r\n$gdb_prompt $" {
203 pass "print value of x>=y>=z"
205 -re ".*$gdb_prompt $" { fail "print value of x>=y>=z" }
206 timeout { fail "(timeout) print value of x>=y>=z" }
209 gdb_test "set variable x=2" "" "set variable x"
210 gdb_test "set variable y=2" "" "set variable y"
211 gdb_test "set variable z=1" "" "set variable z"
214 send_gdb "print x == y == z\n"
216 -re ".*1.*$gdb_prompt $" {
217 pass "print value of x==y==z"
219 -re ".*$gdb_prompt $" { fail "print value of x==y==z" }
220 timeout { fail "(timeout) print value of x==y==z" }
223 gdb_test "set variable z=0" "" "set variable z"
226 send_gdb "print x != y != z\n"
228 -re ".*0\r\n$gdb_prompt $" {
229 pass "print value of x!=y!=z"
231 -re ".*$gdb_prompt $" { fail "print value of x!=y!=z" }
232 timeout { fail "(timeout) print value of x!=y!=z" }
236 # test precedence rules on pairs of relational operators
238 gdb_test "set variable x=0" "" "set variable x"
239 gdb_test "set variable y=2" "" "set variable y"
240 gdb_test "set variable z=2" "" "set variable z"
243 send_gdb "print x < y == z\n"
245 -re ".*0.*$gdb_prompt $" {
246 pass "print value of x<y==z"
248 -re ".*$gdb_prompt $" { fail "print value of x<y==z" }
249 timeout { fail "(timeout) print value of x<y==z" }
253 send_gdb "print x < y != z\n"
255 -re ".*1.*$gdb_prompt $" {
256 pass "print value of x<y!=z"
258 -re ".*$gdb_prompt $" { fail "print value of x<y!=z" }
259 timeout { fail "(timeout) print value of x<y!=z" }
262 gdb_test "set variable x=2" "" "set variable x"
263 gdb_test "set variable y=3" "" "set variable y"
264 gdb_test "set variable z=1" "" "set variable z"
268 send_gdb "print x < y <= z\n"
270 -re ".*1.*$gdb_prompt $" {
271 pass "print value of x<y<=z"
273 -re ".*$gdb_prompt $" { fail "print value of x<y<=z" }
274 timeout { fail "(timeout) print value of x<y<=z" }
279 send_gdb "print x < y >= z\n"
281 -re ".*1.*$gdb_prompt $" {
282 pass "print value of x<y>=z"
284 -re ".*$gdb_prompt $" { fail "print value of x<y>=z" }
285 timeout { fail "(timeout) print value of x<y>=z" }
289 gdb_test "set variable z=0" "" " set variable z"
293 send_gdb "print x < y > z\n"
295 -re ".*1.*$gdb_prompt $" {
296 pass "print value of x<y>z"
298 -re ".*$gdb_prompt $" { fail "print value of x<y>z" }
299 timeout { fail "(timeout) print value of x<y>z" }
303 gdb_test "set variable x=1" "" " set variable x"
306 send_gdb "print x > y >= z\n"
308 -re ".*1.*$gdb_prompt $" {
309 pass "print value of x>y>=z"
311 -re ".*$gdb_prompt $" { fail "print value of x>y>=z" }
312 timeout { fail "(timeout) print value of x>y>=z" }
316 gdb_test "set variable z=2" "" " set variable z"
319 send_gdb "print x > y == z\n"
321 -re ".*0.*$gdb_prompt $" {
322 pass "print value of x>y==z"
324 -re ".*$gdb_prompt $" { fail "print value of x>y==z" }
325 timeout { fail "(timeout) print value of x>y==z" }
329 gdb_test "set variable x=2" "" " set variable x"
330 gdb_test "set variable z=0" "" " set variable z"
333 send_gdb "print x > y != z\n"
335 -re ".*0.*$gdb_prompt $" {
336 pass "print value of x>y!=z"
338 -re ".*$gdb_prompt $" { fail "print value of x>y!=z" }
339 timeout { fail "(timeout) print value of x>y!=z" }
343 gdb_test "set variable x=4" "" "set x to 4"
346 send_gdb "print x > y <= z\n"
348 -re ".*0.*$gdb_prompt $" {
349 pass "print value of x>y<=z"
351 -re ".*$gdb_prompt $" { fail "print value of x>y<=z" }
352 timeout { fail "(timeout) print value of x>y<=z" }
356 send_gdb "print x >= y == z\n"
358 -re ".*0\r\n$gdb_prompt $" {
359 pass "print value of x>=y==z"
361 -re ".*$gdb_prompt $" { fail "print value of x>=y==z" }
362 timeout { fail "(timeout) print value of x>=y==z" }
366 gdb_test "set variable x=2" "" " set variable x"
369 send_gdb "print x >= y != z\n"
371 -re ".*0\r\n$gdb_prompt $" {
372 pass "print value of x>=y!=z"
374 -re ".*$gdb_prompt $" { fail "print value of x>=y!=z" }
375 timeout { fail "(timeout) print value of x>=y!=z" }
379 gdb_test "set variable x=0" "" " set variable x"
380 gdb_test "set variable z=4" "" " set variable z"
383 send_gdb "print x >= y <= z\n"
385 -re ".*1\r\n$gdb_prompt $" {
386 pass "print value of x>=y<=z"
388 -re ".*$gdb_prompt $" { fail "print value of x>=y<=z" }
389 timeout { fail "(timeout) print value of x>=y<=z" }
393 send_gdb "print x <= y == z\n"
395 -re ".*0\r\n$gdb_prompt $" {
396 pass "print value of x<=y==z"
398 -re ".*$gdb_prompt $" { fail "print value of x<=y==z" }
399 timeout { fail "(timeout) print value of x<=y==z" }
402 gdb_test "set variable x=2" "" " set variable x"
405 send_gdb "print x <= y != z\n"
407 -re ".*1\r\n$gdb_prompt $" {
408 pass "print value of x<=y!=z"
410 -re ".*$gdb_prompt $" { fail "print value of x<=y!=z" }
411 timeout { fail "(timeout) print value of x<=y!=z" }
416 send_gdb "print x == y != z\n"
418 -re ".*1\r\n$gdb_prompt $" {
419 pass "print value of x==y!=z"
421 -re ".*$gdb_prompt $" { fail "print value of x==y!=z" }
422 timeout { fail "(timeout) print value of x==y!=z" }
427 # test use of parenthesis to enforce different order of evaluation
430 gdb_test "set variable z=0" "" " set variable z"
433 send_gdb "print x >= (y < z)\n"
435 -re ".*1\r\n$gdb_prompt $" {
436 pass "print value of x>=(y<z)"
438 -re ".*$gdb_prompt $" { fail "print value of x>=(y<z)" }
439 timeout { fail "(timeout) print value of x>=(y<z)" }
444 send_gdb "print x >= (y != z)\n"
446 -re ".*1\r\n$gdb_prompt $" {
447 pass "print value of x>=(y!=z)"
449 -re ".*$gdb_prompt $" { fail "print value of x>=(y*!=z)" }
450 timeout { fail "(timeout) print value of x>=(y!=z)" }
454 send_gdb "print x == (y == z)\n"
456 -re ".*0\r\n$gdb_prompt $" {
457 pass "print value of x==(y==z)"
459 -re ".*$gdb_prompt $" { fail "print value of x==(y==z)" }
460 timeout { fail "(timeout) print value of x==(y==z)" }
464 gdb_test "set variable x=1" "" " set variable x"
465 gdb_test "set variable z=4" "" " set variable z"
468 send_gdb "print (x == y) < z\n"
470 -re ".*1\r\n$gdb_prompt $" {
471 pass "print value of (x==y)<z"
473 -re ".*$gdb_prompt $" { fail "print value of (x==y)<z" }
474 timeout { fail "(timeout) print value of (x==y)<z" }