* gdb.base/help.exp: Remove testing of individual command help text,
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / logical.exp
CommitLineData
f7d690e5
AC
1# This testcase is part of GDB, the GNU debugger.
2
0b302171 3# Copyright 1998-1999, 2004, 2007-2012 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 23
c906108c
SS
24#
25# test running programs
26#
c906108c
SS
27
28set testfile "int-type"
29set srcfile ${testfile}.c
30set binfile ${objdir}/${subdir}/${testfile}
31
fc91c6c2 32if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
b60f0898
JB
33 untested logical.exp
34 return -1
f7d690e5 35}
c906108c 36
4c93b1db 37if [get_compiler_info] {
085dd6e6
JM
38 return -1;
39}
c906108c
SS
40
41gdb_exit
42gdb_start
43gdb_reinitialize_dir $srcdir/$subdir
44gdb_load ${binfile}
45
46
47#
48# set it up at a breakpoint so we can play with the variable values
49#
50
51if ![runto_main] then {
52 perror "couldn't run to breakpoint"
53 continue
54}
55
f7d690e5
AC
56proc evaluate { vars ops } {
57 for {set vari 0} {$vari < [llength $vars]} {incr vari} {
58 set var [lindex $vars $vari]
59 for {set opi 0} {$opi < [llength $ops]} {incr opi} {
60 set op [lindex [lindex $ops $opi] 0]
61 set val [lindex [lindex $ops $opi] [expr $vari + 1]]
62 gdb_test "print $var, $op" " = $val" "evaluate $op; variables $var; expecting $val"
63 }
64 }
65}
c906108c 66
f7d690e5 67# Unary
c906108c 68
f7d690e5
AC
69evaluate {
70 {x = 0} {x = 1}
71} {
72 { {x} 0 1 }
73 { {!x} 1 0 }
74 { {!!x} 0 1 }
75}
c906108c 76
f7d690e5
AC
77# Binary (with unary)
78
79evaluate {
80 {x = 0, y = 0} {x = 0, y = 1} {x = 1, y = 0} {x = 1, y = 1}
81} {
82 { {x && y} 0 0 0 1 }
83 { {!x && y} 0 1 0 0 }
84 { {x && !y} 0 0 1 0 }
85 { {!x && !y} 1 0 0 0 }
86
87 { {x || y} 0 1 1 1 }
88 { {!x || y} 1 1 0 1 }
89 { {x || !y} 1 0 1 1 }
90 { {!x || !y} 1 1 1 0 }
91
92 { {x < y} 0 1 0 0 }
93 { {x <= y} 1 1 0 1 }
94 { {x == y} 1 0 0 1 }
95 { {x != y} 0 1 1 0 }
96 { {x >= y} 1 0 1 1 }
97 { {x > y} 0 0 1 0 }
98}
c906108c 99
f7d690e5 100# Full table of &&, || combinations, followed by random mix of unary ops
c906108c 101
f7d690e5
AC
102evaluate {
103 {x = 0, y = 0, z = 0} {x = 0, y = 0, z = 1} {x = 0, y = 1, z = 0} {x = 0, y = 1, z = 1}
104 {x = 1, y = 0, z = 0} {x = 1, y = 0, z = 1} {x = 1, y = 1, z = 0} {x = 1, y = 1, z = 1}
105} {
106 { {x && y && z} 0 0 0 0 0 0 0 1 }
107 { {x || y && z} 0 0 0 1 1 1 1 1 }
108 { {x && y || z} 0 1 0 1 0 1 1 1 }
109 { {x || y || z} 0 1 1 1 1 1 1 1 }
c906108c 110
f7d690e5
AC
111 { {x || !y && z} 0 1 0 0 1 1 1 1 }
112 { {!x || y && z} 1 1 1 1 0 0 0 1 }
113 { {!x || y && !z} 1 1 1 1 0 0 1 0 }
114}
c906108c 115
f7d690e5 116# More complex operations
c906108c 117
f7d690e5
AC
118evaluate {
119 {x = 1, y = 2, w = 3, z = 3}
120 {x = 1, y = 2, w = 1, z = 3}
121 {x = 2, y = 2, w = 2, z = 3}
122} {
123 { {x > y || w == z} 1 0 0 }
124 { {x >= y && w != z} 0 0 1 }
125 { {! x > y || w + z} 1 1 1 }
126}
This page took 1.258675 seconds and 4 git commands to generate.