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
25 # tests for correctenss of logical operators, associativity and precedence
26 # with integer type variables
34 # test running programs
39 set testfile "int-type"
40 set srcfile ${testfile}.c
41 set binfile ${objdir}/${subdir}/${testfile}
43 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-w}] != "" } {
44 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
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=0" "" "set variable x=0"
69 gdb_test "set variable y=0" "" "set variable y=0"
70 gdb_test "set variable z=0" "" "set variable z=0"
74 -re ".*0.*$gdb_prompt $" {
75 pass "print value of x"
77 -re ".*$gdb_prompt $" { fail "print value of x" }
78 timeout { fail "(timeout) print value of x" }
84 -re ".*0.*$gdb_prompt $" {
85 pass "print value of y"
87 -re ".*$gdb_prompt $" { fail "print value of y" }
88 timeout { fail "(timeout) print value of y" }
93 -re ".*0.*$gdb_prompt $" {
94 pass "print value of z"
96 -re ".*$gdb_prompt $" { fail "print value of z" }
97 timeout { fail "(timeout) print value of z" }
101 # truth tables for && , || , !
103 send_gdb "print x && y\n"
105 -re ".*0.*$gdb_prompt $" {
106 pass "print value of x<y"
108 -re ".*$gdb_prompt $" { fail "print value of x<y" }
109 timeout { fail "(timeout) print value of x<y" }
114 send_gdb "print x || y\n"
116 -re ".*0.*$gdb_prompt $" {
117 pass "print value of x<=y"
119 -re ".*$gdb_prompt $" { fail "print value of x<=y" }
120 timeout { fail "(timeout) print value of x<=y" }
123 send_gdb "print !x\n"
125 -re ".*1.*$gdb_prompt $" {
126 pass "print value of x>y"
128 -re ".*$gdb_prompt $" { fail "print value of x>y" }
129 timeout { fail "(timeout) print value of x>y" }
132 gdb_test "set variable y=1" "" "set variable y=1"
134 send_gdb "print x && y\n"
136 -re ".*0.*$gdb_prompt $" {
137 pass "print value of x<y"
139 -re ".*$gdb_prompt $" { fail "print value of x<y" }
140 timeout { fail "(timeout) print value of x<y" }
145 send_gdb "print x || y\n"
147 -re ".*1.*$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 gdb_test "set variable x=1" "" "set variable x=1"
156 send_gdb "print x && y\n"
158 -re ".*1.*$gdb_prompt $" {
159 pass "print value of x<y"
161 -re ".*$gdb_prompt $" { fail "print value of x<y" }
162 timeout { fail "(timeout) print value of x<y" }
167 send_gdb "print x || y\n"
169 -re ".*1.*$gdb_prompt $" {
170 pass "print value of x<=y"
172 -re ".*$gdb_prompt $" { fail "print value of x<=y" }
173 timeout { fail "(timeout) print value of x<=y" }
176 send_gdb "print !x\n"
178 -re ".*0.*$gdb_prompt $" {
179 pass "print value of x>y"
181 -re ".*$gdb_prompt $" { fail "print value of x>y" }
182 timeout { fail "(timeout) print value of x>y" }
185 gdb_test "set variable y=0" "" "set variable y=0"
187 send_gdb "print x && y\n"
189 -re ".*0.*$gdb_prompt $" {
190 pass "print value of x<y"
192 -re ".*$gdb_prompt $" { fail "print value of x<y" }
193 timeout { fail "(timeout) print value of x<y" }
198 send_gdb "print x || y\n"
200 -re ".*1.*$gdb_prompt $" {
201 pass "print value of x<=y"
203 -re ".*$gdb_prompt $" { fail "print value of x<=y" }
204 timeout { fail "(timeout) print value of x<=y" }
208 # end truth tables for &&, ||, !
211 # test associativity of && , || , !
213 gdb_test "set variable x=0" "" "set variable x=0"
214 gdb_test "set variable y=0" "" "set variable y=0"
215 gdb_test "set variable z=0" "" "set variable z=0"
217 send_gdb "print x && y && z\n"
219 -re ".*0.*$gdb_prompt $" {
220 pass "print value of x && y && z (000)"
222 -re ".*$gdb_prompt $" { fail "print value of x && y && z (000) " }
223 timeout { fail "(timeout) print value of x && y && z (000) " }
226 send_gdb "print x || y || z\n"
228 -re ".*0.*$gdb_prompt $" {
229 pass "print value of x || y || z (000)"
231 -re ".*$gdb_prompt $" { fail "print value of x || y || z (000)" }
232 timeout { fail "(timeout) print value of x || y || z (000) " }
235 send_gdb "print !!x\n"
237 -re ".*0.*$gdb_prompt $" {
238 pass "print value of !!x (0)"
240 -re ".*$gdb_prompt $" { fail "print value of !!x (0)" }
241 timeout { fail "(timeout) print value of !!x (0) " }
245 gdb_test "set variable y=1" "" "set variable y=1"
247 send_gdb "print x && y && z\n"
249 -re ".*0.*$gdb_prompt $" {
250 pass "print value of x && y && z (010)"
252 -re ".*$gdb_prompt $" { fail "print value of x && y && z (010) " }
253 timeout { fail "(timeout) print value of x && y && z (010) " }
256 send_gdb "print x || y || z\n"
258 -re ".*1.*$gdb_prompt $" {
259 pass "print value of x || y || z (010)"
261 -re ".*$gdb_prompt $" { fail "print value of x || y || z (010)" }
262 timeout { fail "(timeout) print value of x || y || z (010) " }
266 gdb_test "set variable z=1" "" "set variable z=1"
268 send_gdb "print x && y && z\n"
270 -re ".*0.*$gdb_prompt $" {
271 pass "print value of x && y && z (011)"
273 -re ".*$gdb_prompt $" { fail "print value of x && y && z (011) " }
274 timeout { fail "(timeout) print value of x && y && z (011) " }
277 send_gdb "print x || y || z\n"
279 -re ".*1.*$gdb_prompt $" {
280 pass "print value of x || y || z (011)"
282 -re ".*$gdb_prompt $" { fail "print value of x || y || z (011)" }
283 timeout { fail "(timeout) print value of x || y || z (011) " }
287 gdb_test "set variable x=1" "" "set variable x=1"
289 send_gdb "print x && y && z\n"
291 -re ".*1.*$gdb_prompt $" {
292 pass "print value of x && y && z (111)"
294 -re ".*$gdb_prompt $" { fail "print value of x && y && z (111) " }
295 timeout { fail "(timeout) print value of x && y && z (111) " }
298 send_gdb "print x || y || z\n"
300 -re ".*1.*$gdb_prompt $" {
301 pass "print value of x || y || z (111)"
303 -re ".*$gdb_prompt $" { fail "print value of x || y || z (111)" }
304 timeout { fail "(timeout) print value of x || y || z (111) " }
307 send_gdb "print !!x\n"
309 -re ".*1.*$gdb_prompt $" {
310 pass "print value of !!x (1)"
312 -re ".*$gdb_prompt $" { fail "print value of !!x (1)" }
313 timeout { fail "(timeout) print value of !!x (1) " }
317 gdb_test "set variable z=0" "" "set variable z=0"
319 send_gdb "print x && y && z\n"
321 -re ".*0.*$gdb_prompt $" {
322 pass "print value of x && y && z (110)"
324 -re ".*$gdb_prompt $" { fail "print value of x && y && z (110) " }
325 timeout { fail "(timeout) print value of x && y && z (110) " }
328 send_gdb "print x || y || z\n"
330 -re ".*1.*$gdb_prompt $" {
331 pass "print value of x || y || z (110)"
333 -re ".*$gdb_prompt $" { fail "print value of x || y || z (110)" }
334 timeout { fail "(timeout) print value of x || y || z (110) " }
340 gdb_test "set variable y=0" "" "set variable y=0"
342 send_gdb "print x && y && z\n"
344 -re ".*0.*$gdb_prompt $" {
345 pass "print value of x && y && z (100)"
347 -re ".*$gdb_prompt $" { fail "print value of x && y && z (100) " }
348 timeout { fail "(timeout) print value of x && y && z (100) " }
351 send_gdb "print x || y || z\n"
353 -re ".*1.*$gdb_prompt $" {
354 pass "print value of x || y || z (100)"
356 -re ".*$gdb_prompt $" { fail "print value of x || y || z (100)" }
357 timeout { fail "(timeout) print value of x || y || z (100) " }
363 gdb_test "set variable z=1" "" "set variable z=1"
365 send_gdb "print x && y && z\n"
367 -re ".*0.*$gdb_prompt $" {
368 pass "print value of x && y && z (101)"
370 -re ".*$gdb_prompt $" { fail "print value of x && y && z (101) " }
371 timeout { fail "(timeout) print value of x && y && z (101) " }
374 send_gdb "print x || y || z\n"
376 -re ".*1.*$gdb_prompt $" {
377 pass "print value of x || y || z (101)"
379 -re ".*$gdb_prompt $" { fail "print value of x || y || z (101)" }
380 timeout { fail "(timeout) print value of x || y || z (101) " }
384 gdb_test "set variable x=0" "" "set variable x=0"
386 send_gdb "print x && y && z\n"
388 -re ".*0.*$gdb_prompt $" {
389 pass "print value of x && y && z (001)"
391 -re ".*$gdb_prompt $" { fail "print value of x && y && z (001) " }
392 timeout { fail "(timeout) print value of x && y && z (001) " }
395 send_gdb "print x || y || z\n"
397 -re ".*1.*$gdb_prompt $" {
398 pass "print value of x || y || z (001)"
400 -re ".*$gdb_prompt $" { fail "print value of x || y || z (001)" }
401 timeout { fail "(timeout) print value of x || y || z (001) " }
407 # test precedence of &&, || ,!
410 send_gdb "print !x && y\n"
412 -re ".*0.*$gdb_prompt $" {
413 pass "print value of !x && y (00)"
415 -re ".*$gdb_prompt $" { fail "print value of !x && y (00)" }
416 timeout { fail "(timeout) print value of !x && y (00) " }
420 gdb_test "set variable x=1" "" "set variable x=1"
423 send_gdb "print !x && y\n"
425 -re ".*0.*$gdb_prompt $" {
426 pass "print value of !x && y (10)"
428 -re ".*$gdb_prompt $" { fail "print value of !x && y (10)" }
429 timeout { fail "(timeout) print value of !x && y (10) " }
435 gdb_test "set variable y=1" "" "set variable y=1"
437 send_gdb "print !x || y\n"
439 -re ".*1.*$gdb_prompt $" {
440 pass "print value of !x || y (11)"
442 -re ".*$gdb_prompt $" { fail "print value of !x || y (11)" }
443 timeout { fail "(timeout) print value of !x || y (11) " }
447 gdb_test "set variable x=0" "" "set variable x=0"
450 send_gdb "print !x || y\n"
452 -re ".*1.*$gdb_prompt $" {
453 pass "print value of !x || y (01)"
455 -re ".*$gdb_prompt $" { fail "print value of !x || y (01)" }
456 timeout { fail "(timeout) print value of !x || y (01) " }
461 gdb_test "set variable x=1" "" "set variable x=1"
462 gdb_test "set variable z=0" "" "set variable z=0"
464 send_gdb "print x || y && z\n"
466 -re ".*1.*$gdb_prompt $" {
467 pass "print value of x || y && z (110)"
469 -re ".*$gdb_prompt $" { fail "print value of x || y && z (110)" }
470 timeout { fail "(timeout) print value of x || y && z (110) " }
474 gdb_test "set variable y=0" "" "set variable y=0"
477 send_gdb "print x || y && z\n"
479 -re ".*1.*$gdb_prompt $" {
480 pass "print value of x || y && z (100)"
482 -re ".*$gdb_prompt $" { fail "print value of x || y && z (100)" }
483 timeout { fail "(timeout) print value of x || y && z (100) " }
488 gdb_test "set variable x=0" "" "set variable x=0"
490 send_gdb "print x || !y && z\n"
492 -re ".*0.*$gdb_prompt $" {
494 gdb_test "set variable x=1" "" "set variable x=1"
495 send_gdb "print x || !y && z\n"
497 -re ".*1.*$gdb_prompt $" {
498 pass "print value of x || !y && z "
500 -re ".*$gdb_prompt $" { fail "print value of x || !y && z" }
501 timeout { fail "(timeout) print value of x || !y && z " }
504 -re ".*$gdb_prompt $" { fail "print value of x || y && z " }
505 timeout { fail "(timeout) print value of x || y && z " }
512 gdb_test "set variable x=1" "" "set variable x=1"
513 gdb_test "set variable y=2" "" "set variable y=2"
514 gdb_test "set variable w=3" "" "set variable w=3"
515 gdb_test "set variable z=3" "" "set variable z=3"
518 send_gdb "print x > y || w == z\n"
520 -re ".*1.*$gdb_prompt $" {
521 pass "print value of x > y || w == z"
523 -re ".*$gdb_prompt $" { fail "print value of x > y || w == z" }
524 timeout { fail "(timeout) print value of x > y || w == z " }
528 gdb_test "set variable x=1" "" "set variable x=1"
529 gdb_test "set variable y=2" "" "set variable y=2"
530 gdb_test "set variable w=1" "" "set variable w=1"
531 gdb_test "set variable z=3" "" "set variable z=3"
534 send_gdb "print x >= y && w != z\n"
536 -re ".*0.*$gdb_prompt $" {
537 pass "print value of x >= y || w != z"
539 -re ".*$gdb_prompt $" { fail "print value of x >= y || w != z" }
540 timeout { fail "(timeout) print value of x >= y || w != z " }
545 gdb_test "set variable x=2" "" "set variable x=2"
546 gdb_test "set variable y=2" "" "set variable y=2"
547 gdb_test "set variable w=2" "" "set variable w=2"
548 gdb_test "set variable z=3" "" "set variable z=3"
551 send_gdb "print ! x > y || w + z\n"
553 -re ".*1.*$gdb_prompt $" {
554 pass "print value of x > y || w != z"
556 -re ".*$gdb_prompt $" { fail "print value of x > y || w != z" }
557 timeout { fail "(timeout) print value of x > y || w != z " }