Updated copyright notices for most files.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / logical.exp
CommitLineData
f7d690e5
AC
1# This testcase is part of GDB, the GNU debugger.
2
9b254dd1 3# Copyright 1998, 1999, 2004, 2007, 2008 Free Software Foundation, Inc.
c906108c
SS
4
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
e22f8b7c 7# the Free Software Foundation; either version 3 of the License, or
c906108c 8# (at your option) any later version.
e22f8b7c 9#
c906108c
SS
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.
e22f8b7c 14#
c906108c 15# You should have received a copy of the GNU General Public License
e22f8b7c 16# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 17
c906108c
SS
18# This file was written by Elena Zannoni (ezannoni@cygnus.com)
19
f7d690e5
AC
20# Tests for correctenss of logical operators, associativity and
21# precedence with integer type variables
c906108c 22
c906108c
SS
23
24if $tracelevel then {
f7d690e5
AC
25 strace $tracelevel
26}
c906108c
SS
27
28#
29# test running programs
30#
31set prms_id 0
32set bug_id 0
33
34set testfile "int-type"
35set srcfile ${testfile}.c
36set binfile ${objdir}/${subdir}/${testfile}
37
fc91c6c2 38if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
b60f0898
JB
39 untested logical.exp
40 return -1
f7d690e5 41}
c906108c 42
085dd6e6
JM
43if [get_compiler_info ${binfile}] {
44 return -1;
45}
c906108c
SS
46
47gdb_exit
48gdb_start
49gdb_reinitialize_dir $srcdir/$subdir
50gdb_load ${binfile}
51
52
53#
54# set it up at a breakpoint so we can play with the variable values
55#
56
57if ![runto_main] then {
58 perror "couldn't run to breakpoint"
59 continue
60}
61
f7d690e5
AC
62proc evaluate { vars ops } {
63 for {set vari 0} {$vari < [llength $vars]} {incr vari} {
64 set var [lindex $vars $vari]
65 for {set opi 0} {$opi < [llength $ops]} {incr opi} {
66 set op [lindex [lindex $ops $opi] 0]
67 set val [lindex [lindex $ops $opi] [expr $vari + 1]]
68 gdb_test "print $var, $op" " = $val" "evaluate $op; variables $var; expecting $val"
69 }
70 }
71}
c906108c 72
f7d690e5 73# Unary
c906108c 74
f7d690e5
AC
75evaluate {
76 {x = 0} {x = 1}
77} {
78 { {x} 0 1 }
79 { {!x} 1 0 }
80 { {!!x} 0 1 }
81}
c906108c 82
f7d690e5
AC
83# Binary (with unary)
84
85evaluate {
86 {x = 0, y = 0} {x = 0, y = 1} {x = 1, y = 0} {x = 1, y = 1}
87} {
88 { {x && y} 0 0 0 1 }
89 { {!x && y} 0 1 0 0 }
90 { {x && !y} 0 0 1 0 }
91 { {!x && !y} 1 0 0 0 }
92
93 { {x || y} 0 1 1 1 }
94 { {!x || y} 1 1 0 1 }
95 { {x || !y} 1 0 1 1 }
96 { {!x || !y} 1 1 1 0 }
97
98 { {x < y} 0 1 0 0 }
99 { {x <= y} 1 1 0 1 }
100 { {x == y} 1 0 0 1 }
101 { {x != y} 0 1 1 0 }
102 { {x >= y} 1 0 1 1 }
103 { {x > y} 0 0 1 0 }
104}
c906108c 105
f7d690e5 106# Full table of &&, || combinations, followed by random mix of unary ops
c906108c 107
f7d690e5
AC
108evaluate {
109 {x = 0, y = 0, z = 0} {x = 0, y = 0, z = 1} {x = 0, y = 1, z = 0} {x = 0, y = 1, z = 1}
110 {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} {
112 { {x && y && z} 0 0 0 0 0 0 0 1 }
113 { {x || y && z} 0 0 0 1 1 1 1 1 }
114 { {x && y || z} 0 1 0 1 0 1 1 1 }
115 { {x || y || z} 0 1 1 1 1 1 1 1 }
c906108c 116
f7d690e5
AC
117 { {x || !y && z} 0 1 0 0 1 1 1 1 }
118 { {!x || y && z} 1 1 1 1 0 0 0 1 }
119 { {!x || y && !z} 1 1 1 1 0 0 1 0 }
120}
c906108c 121
f7d690e5 122# More complex operations
c906108c 123
f7d690e5
AC
124evaluate {
125 {x = 1, y = 2, w = 3, z = 3}
126 {x = 1, y = 2, w = 1, z = 3}
127 {x = 2, y = 2, w = 2, z = 3}
128} {
129 { {x > y || w == z} 1 0 0 }
130 { {x >= y && w != z} 0 0 1 }
131 { {! x > y || w + z} 1 1 1 }
132}
This page took 0.72736 seconds and 4 git commands to generate.