1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 1998, 1999, 2004, 2007, 2008, 2009, 2010, 2011
4 # Free Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
21 # Tests for correctenss of logical operators, associativity and
22 # precedence with integer type variables
30 # test running programs
33 set testfile "int-type"
34 set srcfile ${testfile}.c
35 set binfile ${objdir}/${subdir}/${testfile}
37 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
42 if [get_compiler_info ${binfile}] {
48 gdb_reinitialize_dir $srcdir/$subdir
53 # set it up at a breakpoint so we can play with the variable values
56 if ![runto_main] then {
57 perror "couldn't run to breakpoint"
61 proc evaluate { vars ops } {
62 for {set vari 0} {$vari < [llength $vars]} {incr vari} {
63 set var [lindex $vars $vari]
64 for {set opi 0} {$opi < [llength $ops]} {incr opi} {
65 set op [lindex [lindex $ops $opi] 0]
66 set val [lindex [lindex $ops $opi] [expr $vari + 1]]
67 gdb_test "print $var, $op" " = $val" "evaluate $op; variables $var; expecting $val"
85 {x = 0, y = 0} {x = 0, y = 1} {x = 1, y = 0} {x = 1, y = 1}
90 { {!x && !y} 1 0 0 0 }
95 { {!x || !y} 1 1 1 0 }
105 # Full table of &&, || combinations, followed by random mix of unary ops
108 {x = 0, y = 0, z = 0} {x = 0, y = 0, z = 1} {x = 0, y = 1, z = 0} {x = 0, y = 1, z = 1}
109 {x = 1, y = 0, z = 0} {x = 1, y = 0, z = 1} {x = 1, y = 1, z = 0} {x = 1, y = 1, z = 1}
111 { {x && y && z} 0 0 0 0 0 0 0 1 }
112 { {x || y && z} 0 0 0 1 1 1 1 1 }
113 { {x && y || z} 0 1 0 1 0 1 1 1 }
114 { {x || y || z} 0 1 1 1 1 1 1 1 }
116 { {x || !y && z} 0 1 0 0 1 1 1 1 }
117 { {!x || y && z} 1 1 1 1 0 0 0 1 }
118 { {!x || y && !z} 1 1 1 1 0 0 1 0 }
121 # More complex operations
124 {x = 1, y = 2, w = 3, z = 3}
125 {x = 1, y = 2, w = 1, z = 3}
126 {x = 2, y = 2, w = 2, z = 3}
128 { {x > y || w == z} 1 0 0 }
129 { {x >= y && w != z} 0 0 1 }
130 { {! x > y || w + z} 1 1 1 }