Initial import
[gdb.git] / gdb / testsuite / gdb.base / relational.exp
blob503e50b2deb77edc76001804994e65d02d9b7b69
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 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 # Please email any bugs, comments, and/or additions to this file to:
17 # bug-gdb@prep.ai.mit.edu
19 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
21 # This file is part of the gdb testsuite
23 # tests for correctenss of relational operators, associativity and precedence
24 # with integer type variables
27 if $tracelevel then {
28 strace $tracelevel
32 # test running programs
34 set prms_id 0
35 set bug_id 0
37 set testfile "int-type"
38 set srcfile ${testfile}.c
39 set binfile ${objdir}/${subdir}/${testfile}
40 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
41 untested relational.exp
42 return -1
45 if [get_compiler_info ${binfile}] {
46 return -1;
49 gdb_exit
50 gdb_start
51 gdb_reinitialize_dir $srcdir/$subdir
52 gdb_load ${binfile}
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"
61 continue
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"
73 send_gdb "print x\n"
74 gdb_expect {
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" }
83 send_gdb "print y\n"
84 gdb_expect {
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" }
92 send_gdb "print z\n"
93 gdb_expect {
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" }
101 send_gdb "print w\n"
102 gdb_expect {
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"
113 gdb_expect {
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"
122 gdb_expect {
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"
131 gdb_expect {
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"
140 gdb_expect {
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"
149 gdb_expect {
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"
158 gdb_expect {
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"
177 gdb_expect {
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"
186 gdb_expect {
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"
195 gdb_expect {
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"
204 gdb_expect {
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"
218 gdb_expect {
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"
230 gdb_expect {
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"
247 gdb_expect {
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" }
255 # 0 2 2
256 send_gdb "print x < y != z\n"
257 gdb_expect {
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"
270 # 2 3 1
271 send_gdb "print x < y <= z\n"
272 gdb_expect {
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" }
281 # 2 3 1
282 send_gdb "print x < y >= z\n"
283 gdb_expect {
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"
295 # 2 3 0
296 send_gdb "print x < y > z\n"
297 gdb_expect {
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"
308 # 1 3 0
309 send_gdb "print x > y >= z\n"
310 gdb_expect {
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"
321 # 1 3 2
322 send_gdb "print x > y == z\n"
323 gdb_expect {
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"
335 # 2 3 0
336 send_gdb "print x > y != z\n"
337 gdb_expect {
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"
348 # 4 3 0
349 send_gdb "print x > y <= z\n"
350 gdb_expect {
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" }
358 # 4 3 0
359 send_gdb "print x >= y == z\n"
360 gdb_expect {
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"
371 # 2 3 0
372 send_gdb "print x >= y != z\n"
373 gdb_expect {
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"
385 # 0 3 4
386 send_gdb "print x >= y <= z\n"
387 gdb_expect {
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" }
395 # 0 3 4
396 send_gdb "print x <= y == z\n"
397 gdb_expect {
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"
407 # 2 3 4
408 send_gdb "print x <= y != z\n"
409 gdb_expect {
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" }
418 # 2 3 4
419 send_gdb "print x == y != z\n"
420 gdb_expect {
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"
435 # 2 3 0
436 send_gdb "print x >= (y < z)\n"
437 gdb_expect {
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)" }
446 # 2 3 0
447 send_gdb "print x >= (y != z)\n"
448 gdb_expect {
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)" }
456 # 2 3 0
457 send_gdb "print x == (y == z)\n"
458 gdb_expect {
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"
470 # 1 3 4
471 send_gdb "print (x == y) < z\n"
472 gdb_expect {
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" }