1 # This testcase is part of GDB
, the GNU debugger.
3 # Copyright
1998-2019 Free Software Foundation
, Inc.
5 # This
program is free software
; you can redistribute it and
/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation
; either version
3 of the License
, or
8 #
(at your option
) any later version.
10 # This
program is distributed in the hope that it will be useful
,
11 # but WITHOUT
ANY WARRANTY
; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License
for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this
program.
If not
, see
<http
://www.gnu.org
/licenses
/>.
18 # This file was written by Elena Zannoni
(ezannoni@cygnus.com
)
20 # Tests
for correctenss of logical operators
, associativity and
21 # precedence with
integer type variables
25 # test running programs
28 standard_testfile
int-type.c
30 if { [gdb_compile
"${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
31 untested
"failed to compile"
35 if [get_compiler_info
] {
39 clean_restart $
{binfile
}
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"
51 proc evaluate
{ vars ops
} {
52 for {set vari
0} {$vari
< [llength $vars
]} {incr vari
} {
53 set var
[lindex $vars $vari
]
54 for {set opi
0} {$opi
< [llength $ops
]} {incr opi
} {
55 set op
[lindex
[lindex $ops $opi
] 0]
56 set val
[lindex
[lindex $ops $opi
] [expr $vari
+ 1]]
57 gdb_test
"print $var, $op" " = $val" "evaluate $op; variables $var; expecting $val"
75 {x
= 0, y
= 0} {x
= 0, y
= 1} {x
= 1, y
= 0} {x
= 1, y
= 1}
80 { {!x
&& !y
} 1 0 0 0 }
85 { {!x ||
!y
} 1 1 1 0 }
95 # Full table of
&&, || combinations
, followed by
random mix of unary ops
98 {x
= 0, y
= 0, z
= 0} {x
= 0, y
= 0, z
= 1} {x
= 0, y
= 1, z
= 0} {x
= 0, y
= 1, z
= 1}
99 {x
= 1, y
= 0, z
= 0} {x
= 1, y
= 0, z
= 1} {x
= 1, y
= 1, z
= 0} {x
= 1, y
= 1, z
= 1}
101 { {x
&& y
&& z
} 0 0 0 0 0 0 0 1 }
102 { {x || y
&& z
} 0 0 0 1 1 1 1 1 }
103 { {x
&& y || z
} 0 1 0 1 0 1 1 1 }
104 { {x || y || z
} 0 1 1 1 1 1 1 1 }
106 { {x ||
!y
&& z
} 0 1 0 0 1 1 1 1 }
107 { {!x || y
&& z
} 1 1 1 1 0 0 0 1 }
108 { {!x || y
&& !z
} 1 1 1 1 0 0 1 0 }
111 # More complex operations
114 {x
= 1, y
= 2, w
= 3, z
= 3}
115 {x
= 1, y
= 2, w
= 1, z
= 3}
116 {x
= 2, y
= 2, w
= 2, z
= 3}
118 { {x
> y || w
== z
} 1 0 0 }
119 { {x
>= y
&& w
!= z
} 0 0 1 }
120 { {! x
> y || w
+ z
} 1 1 1 }