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."
47 if [get_compiler_info ${binfile}] {
53 gdb_reinitialize_dir $srcdir/$subdir
58 # set it up at a breakpoint so we can play with the variable values
61 if ![runto_main] then {
62 perror "couldn't run to breakpoint"
67 # test expressions with "int" types
70 gdb_test "set variable x=0" "" "set variable x=0"
71 gdb_test "set variable y=0" "" "set variable y=0"
72 gdb_test "set variable z=0" "" "set variable z=0"
76 -re ".*0.*$gdb_prompt $" {
77 pass "print value of x"
79 -re ".*$gdb_prompt $" { fail "print value of x" }
80 timeout { fail "(timeout) print value of x" }
86 -re ".*0.*$gdb_prompt $" {
87 pass "print value of y"
89 -re ".*$gdb_prompt $" { fail "print value of y" }
90 timeout { fail "(timeout) print value of y" }
95 -re ".*0.*$gdb_prompt $" {
96 pass "print value of z"
98 -re ".*$gdb_prompt $" { fail "print value of z" }
99 timeout { fail "(timeout) print value of z" }
103 # truth tables for && , || , !
105 send_gdb "print x && y\n"
107 -re ".*$false.*$gdb_prompt $" {
108 pass "print value of x<y"
110 -re ".*$gdb_prompt $" { fail "print value of x<y" }
111 timeout { fail "(timeout) print value of x<y" }
116 send_gdb "print x || y\n"
118 -re ".*$false.*$gdb_prompt $" {
119 pass "print value of x<=y"
121 -re ".*$gdb_prompt $" { fail "print value of x<=y" }
122 timeout { fail "(timeout) print value of x<=y" }
125 send_gdb "print !x\n"
127 -re ".*$true.*$gdb_prompt $" {
128 pass "print value of x>y"
130 -re ".*$gdb_prompt $" { fail "print value of x>y" }
131 timeout { fail "(timeout) print value of x>y" }
134 gdb_test "set variable y=1" "" "set variable y=1"
136 send_gdb "print x && y\n"
138 -re ".*$false.*$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" }
147 send_gdb "print x || y\n"
149 -re ".*$true.*$gdb_prompt $" {
150 pass "print value of x<=y"
152 -re ".*$gdb_prompt $" { fail "print value of x<=y" }
153 timeout { fail "(timeout) print value of x<=y" }
156 gdb_test "set variable x=1" "" "set variable x=1"
158 send_gdb "print x && y\n"
160 -re ".*$true.*$gdb_prompt $" {
161 pass "print value of x<y"
163 -re ".*$gdb_prompt $" { fail "print value of x<y" }
164 timeout { fail "(timeout) print value of x<y" }
169 send_gdb "print x || y\n"
171 -re ".*$true.*$gdb_prompt $" {
172 pass "print value of x<=y"
174 -re ".*$gdb_prompt $" { fail "print value of x<=y" }
175 timeout { fail "(timeout) print value of x<=y" }
178 send_gdb "print !x\n"
180 -re ".*$false.*$gdb_prompt $" {
181 pass "print value of x>y"
183 -re ".*$gdb_prompt $" { fail "print value of x>y" }
184 timeout { fail "(timeout) print value of x>y" }
187 gdb_test "set variable y=0" "" "set variable y=0"
189 send_gdb "print x && y\n"
191 -re ".*$false.*$gdb_prompt $" {
192 pass "print value of x<y"
194 -re ".*$gdb_prompt $" { fail "print value of x<y" }
195 timeout { fail "(timeout) print value of x<y" }
200 send_gdb "print x || y\n"
202 -re ".*$true.*$gdb_prompt $" {
203 pass "print value of x<=y"
205 -re ".*$gdb_prompt $" { fail "print value of x<=y" }
206 timeout { fail "(timeout) print value of x<=y" }
210 # end truth tables for &&, ||, !
213 # test associativity of && , || , !
215 gdb_test "set variable x=0" "" "set variable x=0"
216 gdb_test "set variable y=0" "" "set variable y=0"
217 gdb_test "set variable z=0" "" "set variable z=0"
219 send_gdb "print x && y && z\n"
221 -re ".*$false.*$gdb_prompt $" {
222 pass "print value of x && y && z (000)"
224 -re ".*$gdb_prompt $" { fail "print value of x && y && z (000) " }
225 timeout { fail "(timeout) print value of x && y && z (000) " }
228 send_gdb "print x || y || z\n"
230 -re ".*$false.*$gdb_prompt $" {
231 pass "print value of x || y || z (000)"
233 -re ".*$gdb_prompt $" { fail "print value of x || y || z (000)" }
234 timeout { fail "(timeout) print value of x || y || z (000) " }
237 send_gdb "print !!x\n"
239 -re ".*$false.*$gdb_prompt $" {
240 pass "print value of !!x (0)"
242 -re ".*$gdb_prompt $" { fail "print value of !!x (0)" }
243 timeout { fail "(timeout) print value of !!x (0) " }
247 gdb_test "set variable y=1" "" "set variable y=1"
249 send_gdb "print x && y && z\n"
251 -re ".*$false.*$gdb_prompt $" {
252 pass "print value of x && y && z (010)"
254 -re ".*$gdb_prompt $" { fail "print value of x && y && z (010) " }
255 timeout { fail "(timeout) print value of x && y && z (010) " }
258 send_gdb "print x || y || z\n"
260 -re ".*$true.*$gdb_prompt $" {
261 pass "print value of x || y || z (010)"
263 -re ".*$gdb_prompt $" { fail "print value of x || y || z (010)" }
264 timeout { fail "(timeout) print value of x || y || z (010) " }
268 gdb_test "set variable z=1" "" "set variable z=1"
270 send_gdb "print x && y && z\n"
272 -re ".*$false.*$gdb_prompt $" {
273 pass "print value of x && y && z (011)"
275 -re ".*$gdb_prompt $" { fail "print value of x && y && z (011) " }
276 timeout { fail "(timeout) print value of x && y && z (011) " }
279 send_gdb "print x || y || z\n"
281 -re ".*$true.*$gdb_prompt $" {
282 pass "print value of x || y || z (011)"
284 -re ".*$gdb_prompt $" { fail "print value of x || y || z (011)" }
285 timeout { fail "(timeout) print value of x || y || z (011) " }
289 gdb_test "set variable x=1" "" "set variable x=1"
291 send_gdb "print x && y && z\n"
293 -re ".*$true.*$gdb_prompt $" {
294 pass "print value of x && y && z (111)"
296 -re ".*$gdb_prompt $" { fail "print value of x && y && z (111) " }
297 timeout { fail "(timeout) print value of x && y && z (111) " }
300 send_gdb "print x || y || z\n"
302 -re ".*$true.*$gdb_prompt $" {
303 pass "print value of x || y || z (111)"
305 -re ".*$gdb_prompt $" { fail "print value of x || y || z (111)" }
306 timeout { fail "(timeout) print value of x || y || z (111) " }
309 send_gdb "print !!x\n"
311 -re ".*$true.*$gdb_prompt $" {
312 pass "print value of !!x (1)"
314 -re ".*$gdb_prompt $" { fail "print value of !!x (1)" }
315 timeout { fail "(timeout) print value of !!x (1) " }
319 gdb_test "set variable z=0" "" "set variable z=0"
321 send_gdb "print x && y && z\n"
323 -re ".*$false.*$gdb_prompt $" {
324 pass "print value of x && y && z (110)"
326 -re ".*$gdb_prompt $" { fail "print value of x && y && z (110) " }
327 timeout { fail "(timeout) print value of x && y && z (110) " }
330 send_gdb "print x || y || z\n"
332 -re ".*$true.*$gdb_prompt $" {
333 pass "print value of x || y || z (110)"
335 -re ".*$gdb_prompt $" { fail "print value of x || y || z (110)" }
336 timeout { fail "(timeout) print value of x || y || z (110) " }
342 gdb_test "set variable y=0" "" "set variable y=0"
344 send_gdb "print x && y && z\n"
346 -re ".*$false.*$gdb_prompt $" {
347 pass "print value of x && y && z (100)"
349 -re ".*$gdb_prompt $" { fail "print value of x && y && z (100) " }
350 timeout { fail "(timeout) print value of x && y && z (100) " }
353 send_gdb "print x || y || z\n"
355 -re ".*$true.*$gdb_prompt $" {
356 pass "print value of x || y || z (100)"
358 -re ".*$gdb_prompt $" { fail "print value of x || y || z (100)" }
359 timeout { fail "(timeout) print value of x || y || z (100) " }
365 gdb_test "set variable z=1" "" "set variable z=1"
367 send_gdb "print x && y && z\n"
369 -re ".*$false.*$gdb_prompt $" {
370 pass "print value of x && y && z (101)"
372 -re ".*$gdb_prompt $" { fail "print value of x && y && z (101) " }
373 timeout { fail "(timeout) print value of x && y && z (101) " }
376 send_gdb "print x || y || z\n"
378 -re ".*$true.*$gdb_prompt $" {
379 pass "print value of x || y || z (101)"
381 -re ".*$gdb_prompt $" { fail "print value of x || y || z (101)" }
382 timeout { fail "(timeout) print value of x || y || z (101) " }
386 gdb_test "set variable x=0" "" "set variable x=0"
388 send_gdb "print x && y && z\n"
390 -re ".*$false.*$gdb_prompt $" {
391 pass "print value of x && y && z (001)"
393 -re ".*$gdb_prompt $" { fail "print value of x && y && z (001) " }
394 timeout { fail "(timeout) print value of x && y && z (001) " }
397 send_gdb "print x || y || z\n"
399 -re ".*$true.*$gdb_prompt $" {
400 pass "print value of x || y || z (001)"
402 -re ".*$gdb_prompt $" { fail "print value of x || y || z (001)" }
403 timeout { fail "(timeout) print value of x || y || z (001) " }
409 # test precedence of &&, || ,!
412 send_gdb "print !x && y\n"
414 -re ".*$false.*$gdb_prompt $" {
415 pass "print value of !x && y (00)"
417 -re ".*$gdb_prompt $" { fail "print value of !x && y (00)" }
418 timeout { fail "(timeout) print value of !x && y (00) " }
422 gdb_test "set variable x=1" "" "set variable x=1"
425 send_gdb "print !x && y\n"
427 -re ".*$false.*$gdb_prompt $" {
428 pass "print value of !x && y (10)"
430 -re ".*$gdb_prompt $" { fail "print value of !x && y (10)" }
431 timeout { fail "(timeout) print value of !x && y (10) " }
437 gdb_test "set variable y=1" "" "set variable y=1"
439 send_gdb "print !x || y\n"
441 -re ".*$true.*$gdb_prompt $" {
442 pass "print value of !x || y (11)"
444 -re ".*$gdb_prompt $" { fail "print value of !x || y (11)" }
445 timeout { fail "(timeout) print value of !x || y (11) " }
449 gdb_test "set variable x=0" "" "set variable x=0"
452 send_gdb "print !x || y\n"
454 -re ".*$true.*$gdb_prompt $" {
455 pass "print value of !x || y (01)"
457 -re ".*$gdb_prompt $" { fail "print value of !x || y (01)" }
458 timeout { fail "(timeout) print value of !x || y (01) " }
463 gdb_test "set variable x=1" "" "set variable x=1"
464 gdb_test "set variable z=0" "" "set variable z=0"
466 send_gdb "print x || y && z\n"
468 -re ".*$true.*$gdb_prompt $" {
469 pass "print value of x || y && z (110)"
471 -re ".*$gdb_prompt $" { fail "print value of x || y && z (110)" }
472 timeout { fail "(timeout) print value of x || y && z (110) " }
476 gdb_test "set variable y=0" "" "set variable y=0"
479 send_gdb "print x || y && z\n"
481 -re ".*$true.*$gdb_prompt $" {
482 pass "print value of x || y && z (100)"
484 -re ".*$gdb_prompt $" { fail "print value of x || y && z (100)" }
485 timeout { fail "(timeout) print value of x || y && z (100) " }
490 gdb_test "set variable x=0" "" "set variable x=0"
492 send_gdb "print x || !y && z\n"
494 -re ".*$false.*$gdb_prompt $" {
496 gdb_test "set variable x=1" "" "set variable x=1"
497 send_gdb "print x || !y && z\n"
499 -re ".*$true.*$gdb_prompt $" {
500 pass "print value of x || !y && z "
502 -re ".*$gdb_prompt $" { fail "print value of x || !y && z" }
503 timeout { fail "(timeout) print value of x || !y && z " }
506 -re ".*$gdb_prompt $" { fail "print value of x || y && z " }
507 timeout { fail "(timeout) print value of x || y && z " }
514 gdb_test "set variable x=1" "" "set variable x=1"
515 gdb_test "set variable y=2" "" "set variable y=2"
516 gdb_test "set variable w=3" "" "set variable w=3"
517 gdb_test "set variable z=3" "" "set variable z=3"
520 send_gdb "print x > y || w == z\n"
522 -re ".*$true.*$gdb_prompt $" {
523 pass "print value of x > y || w == z"
525 -re ".*$gdb_prompt $" { fail "print value of x > y || w == z" }
526 timeout { fail "(timeout) print value of x > y || w == z " }
530 gdb_test "set variable x=1" "" "set variable x=1"
531 gdb_test "set variable y=2" "" "set variable y=2"
532 gdb_test "set variable w=1" "" "set variable w=1"
533 gdb_test "set variable z=3" "" "set variable z=3"
536 send_gdb "print x >= y && w != z\n"
538 -re ".*$false.*$gdb_prompt $" {
539 pass "print value of x >= y || w != z"
541 -re ".*$gdb_prompt $" { fail "print value of x >= y || w != z" }
542 timeout { fail "(timeout) print value of x >= y || w != z " }
547 gdb_test "set variable x=2" "" "set variable x=2"
548 gdb_test "set variable y=2" "" "set variable y=2"
549 gdb_test "set variable w=2" "" "set variable w=2"
550 gdb_test "set variable z=3" "" "set variable z=3"
553 send_gdb "print ! x > y || w + z\n"
555 -re ".*$true.*$gdb_prompt $" {
556 pass "print value of x > y || w != z"
558 -re ".*$gdb_prompt $" { fail "print value of x > y || w != z" }
559 timeout { fail "(timeout) print value of x > y || w != z " }