1 # Copyright 1998, 1999, 2007, 2008, 2009, 2010 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 3 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, see <http://www.gnu.org/licenses/>.
16 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
18 # This file is part of the gdb testsuite
20 # tests for correctenss of relational operators, associativity and precedence
21 # with integer type variables
29 # test running programs
32 if { [prepare_for_testing relational.exp relational int-type.c {debug nowarnings}] } {
36 if [get_compiler_info not-used] {
41 # set it up at a breakpoint so we can play with the variable values
44 if ![runto_main] then {
45 perror "couldn't run to breakpoint"
50 # test expressions with "int" types
53 gdb_test "set variable x=14" "" "set variable x=14"
54 gdb_test "set variable y=2" "" "set variable y=2"
55 gdb_test "set variable z=2" "" "set variable z=2"
56 gdb_test "set variable w=3" "" "set variable w=3"
60 -re ".*14.*$gdb_prompt $" {
61 pass "print value of x"
63 -re ".*$gdb_prompt $" { fail "print value of x" }
64 timeout { fail "(timeout) print value of x" }
70 -re ".*2.*$gdb_prompt $" {
71 pass "print value of y"
73 -re ".*$gdb_prompt $" { fail "print value of y" }
74 timeout { fail "(timeout) print value of y" }
79 -re ".*2.*$gdb_prompt $" {
80 pass "print value of z"
82 -re ".*$gdb_prompt $" { fail "print value of z" }
83 timeout { fail "(timeout) print value of z" }
88 -re ".*3.*$gdb_prompt $" {
89 pass "print value of w"
91 -re ".*$gdb_prompt $" { fail "print value of w" }
92 timeout { fail "(timeout) print value of w" }
97 send_gdb "print x < y\n"
99 -re ".*$false.*$gdb_prompt $" {
100 pass "print value of x<y"
102 -re ".*$gdb_prompt $" { fail "print value of x<y" }
103 timeout { fail "(timeout) print value of x<y" }
106 send_gdb "print x <= y\n"
108 -re ".*$false.*$gdb_prompt $" {
109 pass "print value of x<=y"
111 -re ".*$gdb_prompt $" { fail "print value of x<=y" }
112 timeout { fail "(timeout) print value of x<=y" }
115 send_gdb "print x > y\n"
117 -re ".*$true.*$gdb_prompt $" {
118 pass "print value of x>y"
120 -re ".*$gdb_prompt $" { fail "print value of x>y" }
121 timeout { fail "(timeout) print value of x>y" }
124 send_gdb "print x >= y\n"
126 -re ".*$true.*$gdb_prompt $" {
127 pass "print value of x>=y"
129 -re ".*$gdb_prompt $" { fail "print value of x>=y" }
130 timeout { fail "(timeout) print value of x>=y" }
133 send_gdb "print x == y\n"
135 -re ".*$false.*$gdb_prompt $" {
136 pass "print value of x==y"
138 -re ".*$gdb_prompt $" { fail "print value of x==y" }
139 timeout { fail "(timeout) print value of x==y" }
142 send_gdb "print x != y\n"
144 -re ".*$true.*$gdb_prompt $" {
145 pass "print value of x!=y"
147 -re ".*$gdb_prompt $" { fail "print value of x!=y" }
148 timeout { fail "(timeout) print value of x!=y" }
153 # Test associativity of <, >, <=, >=, ==, !=
155 gdb_test "set variable x=3" "" "set variable x"
156 gdb_test "set variable y=5" "" "set variable y"
157 gdb_test "set variable z=2" "" "set variable z"
161 send_gdb "print x < y < z\n"
163 -re ".*$true.*\r\n$gdb_prompt $" {
164 pass "print value of x<y<z"
166 -re ".*$gdb_prompt $" { fail "print value of x<y<z" }
167 timeout { fail "(timeout) print value of x<y<z" }
170 send_gdb "print x <= y <= z\n"
172 -re ".*$true\r\n$gdb_prompt $" {
173 pass "print value of x<=y<=z"
175 -re ".*$gdb_prompt $" { fail "print value of x<=y<=z" }
176 timeout { fail "(timeout) print value of x<=y<=z" }
179 send_gdb "print x > y > z\n"
181 -re ".*$false.*\r\n$gdb_prompt $" {
182 pass "print value of x>y>z"
184 -re 8".*$gdb_prompt $" { fail "print value of x>y>z" }
185 timeout { fail "(timeout) print value of x>y>z" }
188 send_gdb "print x >= y >= z\n"
190 -re ".*$false.*\r\n$gdb_prompt $" {
191 pass "print value of x>=y>=z"
193 -re ".*$gdb_prompt $" { fail "print value of x>=y>=z" }
194 timeout { fail "(timeout) print value of x>=y>=z" }
197 gdb_test "set variable x=2" "" "set variable x"
198 gdb_test "set variable y=2" "" "set variable y"
199 gdb_test "set variable z=1" "" "set variable z"
202 send_gdb "print x == y == z\n"
204 -re ".*$true.*$gdb_prompt $" {
205 pass "print value of x==y==z"
207 -re ".*$gdb_prompt $" { fail "print value of x==y==z" }
208 timeout { fail "(timeout) print value of x==y==z" }
211 gdb_test "set variable z=0" "" "set variable z"
214 send_gdb "print x != y != z\n"
216 -re ".*$false\r\n$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" }
224 # test precedence rules on pairs of relational operators
226 gdb_test "set variable x=0" "" "set variable x"
227 gdb_test "set variable y=2" "" "set variable y"
228 gdb_test "set variable z=2" "" "set variable z"
231 send_gdb "print x < y == z\n"
233 -re ".*$false.*$gdb_prompt $" {
234 pass "print value of x<y==z"
236 -re ".*$gdb_prompt $" { fail "print value of x<y==z" }
237 timeout { fail "(timeout) print value of x<y==z" }
241 send_gdb "print x < y != z\n"
243 -re ".*$true.*$gdb_prompt $" {
244 pass "print value of x<y!=z"
246 -re ".*$gdb_prompt $" { fail "print value of x<y!=z" }
247 timeout { fail "(timeout) print value of x<y!=z" }
250 gdb_test "set variable x=2" "" "set variable x"
251 gdb_test "set variable y=3" "" "set variable y"
252 gdb_test "set variable z=1" "" "set variable 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" }
267 send_gdb "print x < y >= z\n"
269 -re ".*$true.*$gdb_prompt $" {
270 pass "print value of x<y>=z"
272 -re ".*$gdb_prompt $" { fail "print value of x<y>=z" }
273 timeout { fail "(timeout) print value of x<y>=z" }
277 gdb_test "set variable z=0" "" " set variable z"
281 send_gdb "print x < y > z\n"
283 -re ".*$true.*$gdb_prompt $" {
284 pass "print value of x<y>z"
286 -re ".*$gdb_prompt $" { fail "print value of x<y>z" }
287 timeout { fail "(timeout) print value of x<y>z" }
291 gdb_test "set variable x=1" "" " set variable x"
294 send_gdb "print x > y >= z\n"
296 -re ".*$true.*$gdb_prompt $" {
297 pass "print value of x>y>=z"
299 -re ".*$gdb_prompt $" { fail "print value of x>y>=z" }
300 timeout { fail "(timeout) print value of x>y>=z" }
304 gdb_test "set variable z=2" "" " set variable z"
307 send_gdb "print x > y == z\n"
309 -re ".*$false.*$gdb_prompt $" {
310 pass "print value of x>y==z"
312 -re ".*$gdb_prompt $" { fail "print value of x>y==z" }
313 timeout { fail "(timeout) print value of x>y==z" }
317 gdb_test "set variable x=2" "" " set variable x"
318 gdb_test "set variable z=0" "" " set variable z"
321 send_gdb "print x > y != z\n"
323 -re ".*$false.*$gdb_prompt $" {
324 pass "print value of x>y!=z"
326 -re ".*$gdb_prompt $" { fail "print value of x>y!=z" }
327 timeout { fail "(timeout) print value of x>y!=z" }
331 gdb_test "set variable x=4" "" "set x to 4"
334 send_gdb "print x > y <= z\n"
336 -re ".*$false.*$gdb_prompt $" {
337 pass "print value of x>y<=z"
339 -re ".*$gdb_prompt $" { fail "print value of x>y<=z" }
340 timeout { fail "(timeout) print value of x>y<=z" }
344 send_gdb "print x >= y == z\n"
346 -re ".*$false\r\n$gdb_prompt $" {
347 pass "print value of x>=y==z"
349 -re ".*$gdb_prompt $" { fail "print value of x>=y==z" }
350 timeout { fail "(timeout) print value of x>=y==z" }
354 gdb_test "set variable x=2" "" " set variable x"
357 send_gdb "print x >= y != z\n"
359 -re ".*$false\r\n$gdb_prompt $" {
360 pass "print value of x>=y!=z"
362 -re ".*$gdb_prompt $" { fail "print value of x>=y!=z" }
363 timeout { fail "(timeout) print value of x>=y!=z" }
367 gdb_test "set variable x=0" "" " set variable x"
368 gdb_test "set variable z=4" "" " set variable z"
371 send_gdb "print x >= y <= z\n"
373 -re ".*$true\r\n$gdb_prompt $" {
374 pass "print value of x>=y<=z"
376 -re ".*$gdb_prompt $" { fail "print value of x>=y<=z" }
377 timeout { fail "(timeout) print value of x>=y<=z" }
381 send_gdb "print x <= y == z\n"
383 -re ".*$false\r\n$gdb_prompt $" {
384 pass "print value of x<=y==z"
386 -re ".*$gdb_prompt $" { fail "print value of x<=y==z" }
387 timeout { fail "(timeout) print value of x<=y==z" }
390 gdb_test "set variable x=2" "" " set variable x"
393 send_gdb "print x <= y != z\n"
395 -re ".*$true\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" }
404 send_gdb "print x == y != z\n"
406 -re ".*$true\r\n$gdb_prompt $" {
407 pass "print value of x==y!=z"
409 -re ".*$gdb_prompt $" { fail "print value of x==y!=z" }
410 timeout { fail "(timeout) print value of x==y!=z" }
415 # test use of parenthesis to enforce different order of evaluation
418 gdb_test "set variable z=0" "" " set variable z"
421 send_gdb "print x >= (y < z)\n"
423 -re ".*$true\r\n$gdb_prompt $" {
424 pass "print value of x>=(y<z)"
426 -re ".*$gdb_prompt $" { fail "print value of x>=(y<z)" }
427 timeout { fail "(timeout) print value of x>=(y<z)" }
432 send_gdb "print x >= (y != z)\n"
434 -re ".*$true\r\n$gdb_prompt $" {
435 pass "print value of x>=(y!=z)"
437 -re ".*$gdb_prompt $" { fail "print value of x>=(y*!=z)" }
438 timeout { fail "(timeout) print value of x>=(y!=z)" }
442 send_gdb "print x == (y == z)\n"
444 -re ".*$false\r\n$gdb_prompt $" {
445 pass "print value of x==(y==z)"
447 -re ".*$gdb_prompt $" { fail "print value of x==(y==z)" }
448 timeout { fail "(timeout) print value of x==(y==z)" }
452 gdb_test "set variable x=1" "" " set variable x"
453 gdb_test "set variable z=4" "" " set variable z"
456 send_gdb "print (x == y) < z\n"
458 -re ".*$true\r\n$gdb_prompt $" {
459 pass "print value of (x==y)<z"
461 -re ".*$gdb_prompt $" { fail "print value of (x==y)<z" }
462 timeout { fail "(timeout) print value of (x==y)<z" }