1 # Copyright 1998, 1999, 2007, 2008, 2009 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
34 if { [prepare_for_testing relational.exp relational int-type.c {debug nowarnings}] } {
38 if [get_compiler_info not-used] {
43 # set it up at a breakpoint so we can play with the variable values
46 if ![runto_main] then {
47 perror "couldn't run to breakpoint"
52 # test expressions with "int" types
55 gdb_test "set variable x=14" "" "set variable x=14"
56 gdb_test "set variable y=2" "" "set variable y=2"
57 gdb_test "set variable z=2" "" "set variable z=2"
58 gdb_test "set variable w=3" "" "set variable w=3"
62 -re ".*14.*$gdb_prompt $" {
63 pass "print value of x"
65 -re ".*$gdb_prompt $" { fail "print value of x" }
66 timeout { fail "(timeout) print value of x" }
72 -re ".*2.*$gdb_prompt $" {
73 pass "print value of y"
75 -re ".*$gdb_prompt $" { fail "print value of y" }
76 timeout { fail "(timeout) print value of y" }
81 -re ".*2.*$gdb_prompt $" {
82 pass "print value of z"
84 -re ".*$gdb_prompt $" { fail "print value of z" }
85 timeout { fail "(timeout) print value of z" }
90 -re ".*3.*$gdb_prompt $" {
91 pass "print value of w"
93 -re ".*$gdb_prompt $" { fail "print value of w" }
94 timeout { fail "(timeout) print value of w" }
99 send_gdb "print x < y\n"
101 -re ".*$false.*$gdb_prompt $" {
102 pass "print value of x<y"
104 -re ".*$gdb_prompt $" { fail "print value of x<y" }
105 timeout { fail "(timeout) print value of x<y" }
108 send_gdb "print x <= y\n"
110 -re ".*$false.*$gdb_prompt $" {
111 pass "print value of x<=y"
113 -re ".*$gdb_prompt $" { fail "print value of x<=y" }
114 timeout { fail "(timeout) print value of x<=y" }
117 send_gdb "print x > y\n"
119 -re ".*$true.*$gdb_prompt $" {
120 pass "print value of x>y"
122 -re ".*$gdb_prompt $" { fail "print value of x>y" }
123 timeout { fail "(timeout) print value of x>y" }
126 send_gdb "print x >= y\n"
128 -re ".*$true.*$gdb_prompt $" {
129 pass "print value of x>=y"
131 -re ".*$gdb_prompt $" { fail "print value of x>=y" }
132 timeout { fail "(timeout) print value of x>=y" }
135 send_gdb "print x == y\n"
137 -re ".*$false.*$gdb_prompt $" {
138 pass "print value of x==y"
140 -re ".*$gdb_prompt $" { fail "print value of x==y" }
141 timeout { fail "(timeout) print value of x==y" }
144 send_gdb "print x != y\n"
146 -re ".*$true.*$gdb_prompt $" {
147 pass "print value of x!=y"
149 -re ".*$gdb_prompt $" { fail "print value of x!=y" }
150 timeout { fail "(timeout) print value of x!=y" }
155 # Test associativity of <, >, <=, >=, ==, !=
157 gdb_test "set variable x=3" "" "set variable x"
158 gdb_test "set variable y=5" "" "set variable y"
159 gdb_test "set variable z=2" "" "set variable z"
163 send_gdb "print x < y < z\n"
165 -re ".*$true.*\r\n$gdb_prompt $" {
166 pass "print value of x<y<z"
168 -re ".*$gdb_prompt $" { fail "print value of x<y<z" }
169 timeout { fail "(timeout) print value of x<y<z" }
172 send_gdb "print x <= y <= z\n"
174 -re ".*$true\r\n$gdb_prompt $" {
175 pass "print value of x<=y<=z"
177 -re ".*$gdb_prompt $" { fail "print value of x<=y<=z" }
178 timeout { fail "(timeout) print value of x<=y<=z" }
181 send_gdb "print x > y > z\n"
183 -re ".*$false.*\r\n$gdb_prompt $" {
184 pass "print value of x>y>z"
186 -re 8".*$gdb_prompt $" { fail "print value of x>y>z" }
187 timeout { fail "(timeout) print value of x>y>z" }
190 send_gdb "print x >= y >= z\n"
192 -re ".*$false.*\r\n$gdb_prompt $" {
193 pass "print value of x>=y>=z"
195 -re ".*$gdb_prompt $" { fail "print value of x>=y>=z" }
196 timeout { fail "(timeout) print value of x>=y>=z" }
199 gdb_test "set variable x=2" "" "set variable x"
200 gdb_test "set variable y=2" "" "set variable y"
201 gdb_test "set variable z=1" "" "set variable z"
204 send_gdb "print x == y == z\n"
206 -re ".*$true.*$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 z=0" "" "set variable z"
216 send_gdb "print x != y != z\n"
218 -re ".*$false\r\n$gdb_prompt $" {
219 pass "print value of x!=y!=z"
221 -re ".*$gdb_prompt $" { fail "print value of x!=y!=z" }
222 timeout { fail "(timeout) print value of x!=y!=z" }
226 # test precedence rules on pairs of relational operators
228 gdb_test "set variable x=0" "" "set variable x"
229 gdb_test "set variable y=2" "" "set variable y"
230 gdb_test "set variable z=2" "" "set variable z"
233 send_gdb "print x < y == z\n"
235 -re ".*$false.*$gdb_prompt $" {
236 pass "print value of x<y==z"
238 -re ".*$gdb_prompt $" { fail "print value of x<y==z" }
239 timeout { fail "(timeout) print value of x<y==z" }
243 send_gdb "print x < y != z\n"
245 -re ".*$true.*$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" }
252 gdb_test "set variable x=2" "" "set variable x"
253 gdb_test "set variable y=3" "" "set variable y"
254 gdb_test "set variable z=1" "" "set variable z"
258 send_gdb "print x < y <= z\n"
260 -re ".*$true.*$gdb_prompt $" {
261 pass "print value of x<y<=z"
263 -re ".*$gdb_prompt $" { fail "print value of x<y<=z" }
264 timeout { fail "(timeout) print value of x<y<=z" }
269 send_gdb "print x < y >= z\n"
271 -re ".*$true.*$gdb_prompt $" {
272 pass "print value of x<y>=z"
274 -re ".*$gdb_prompt $" { fail "print value of x<y>=z" }
275 timeout { fail "(timeout) print value of x<y>=z" }
279 gdb_test "set variable z=0" "" " set variable 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 x=1" "" " set variable x"
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 z=2" "" " set variable z"
309 send_gdb "print x > y == z\n"
311 -re ".*$false.*$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 x=2" "" " set variable x"
320 gdb_test "set variable z=0" "" " 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=4" "" "set x to 4"
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 send_gdb "print x >= y == z\n"
348 -re ".*$false\r\n$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 gdb_test "set variable x=2" "" " set variable x"
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=0" "" " set variable x"
370 gdb_test "set variable z=4" "" " set variable z"
373 send_gdb "print x >= y <= z\n"
375 -re ".*$true\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 send_gdb "print x <= y == z\n"
385 -re ".*$false\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" }
392 gdb_test "set variable x=2" "" " set variable x"
395 send_gdb "print x <= y != z\n"
397 -re ".*$true\r\n$gdb_prompt $" {
398 pass "print value of x<=y!=z"
400 -re ".*$gdb_prompt $" { fail "print value of x<=y!=z" }
401 timeout { fail "(timeout) print value of x<=y!=z" }
406 send_gdb "print x == y != z\n"
408 -re ".*$true\r\n$gdb_prompt $" {
409 pass "print value of x==y!=z"
411 -re ".*$gdb_prompt $" { fail "print value of x==y!=z" }
412 timeout { fail "(timeout) print value of x==y!=z" }
417 # test use of parenthesis to enforce different order of evaluation
420 gdb_test "set variable z=0" "" " set variable z"
423 send_gdb "print x >= (y < z)\n"
425 -re ".*$true\r\n$gdb_prompt $" {
426 pass "print value of x>=(y<z)"
428 -re ".*$gdb_prompt $" { fail "print value of x>=(y<z)" }
429 timeout { fail "(timeout) print value of x>=(y<z)" }
434 send_gdb "print x >= (y != z)\n"
436 -re ".*$true\r\n$gdb_prompt $" {
437 pass "print value of x>=(y!=z)"
439 -re ".*$gdb_prompt $" { fail "print value of x>=(y*!=z)" }
440 timeout { fail "(timeout) print value of x>=(y!=z)" }
444 send_gdb "print x == (y == z)\n"
446 -re ".*$false\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 gdb_test "set variable x=1" "" " set variable x"
455 gdb_test "set variable z=4" "" " set variable z"
458 send_gdb "print (x == y) < z\n"
460 -re ".*$true\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" }