xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.base/logical.exp (revision 8b657b0747480f8989760d71343d6dd33f8d4cf9)
1# This testcase is part of GDB, the GNU debugger.
2
3# Copyright 1998-2023 Free Software Foundation, Inc.
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
7# the Free Software Foundation; either version 3 of the License, or
8# (at your option) any later version.
9#
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.
14#
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/>.
17
18# This file was written by Elena Zannoni (ezannoni@cygnus.com)
19
20# Tests for correctenss of logical operators, associativity and
21# precedence with integer type variables
22
23
24#
25# test running programs
26#
27
28standard_testfile int-type.c
29
30if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
31    untested "failed to compile"
32    return -1
33}
34
35clean_restart ${binfile}
36
37
38#
39# set it up at a breakpoint so we can play with the variable values
40#
41
42if {![runto_main]} {
43    return
44}
45
46proc evaluate { vars ops } {
47    for {set vari 0} {$vari < [llength $vars]} {incr vari} {
48	set var [lindex $vars $vari]
49	for {set opi 0} {$opi < [llength $ops]} {incr opi} {
50	    set op [lindex [lindex $ops $opi] 0]
51	    set val [lindex [lindex $ops $opi] [expr $vari + 1]]
52	    gdb_test "print $var, $op" " = $val" "evaluate $op; variables $var; expecting $val"
53	}
54    }
55}
56
57# Unary
58
59evaluate {
60    {x = 0} {x = 1}
61} {
62    { {x}   0 1 }
63    { {!x}  1 0 }
64    { {!!x} 0 1 }
65}
66
67# Binary (with unary)
68
69evaluate {
70    {x = 0, y = 0} {x = 0, y = 1} {x = 1, y = 0} {x = 1, y = 1}
71} {
72    { {x && y}   0 0 0 1 }
73    { {!x && y}  0 1 0 0 }
74    { {x && !y}  0 0 1 0 }
75    { {!x && !y} 1 0 0 0 }
76
77    { {x || y}   0 1 1 1 }
78    { {!x || y}  1 1 0 1 }
79    { {x || !y}  1 0 1 1 }
80    { {!x || !y} 1 1 1 0 }
81
82    { {x < y}    0 1 0 0 }
83    { {x <= y}   1 1 0 1 }
84    { {x == y}   1 0 0 1 }
85    { {x != y}   0 1 1 0 }
86    { {x >= y}   1 0 1 1 }
87    { {x > y}    0 0 1 0 }
88}
89
90# Full table of &&, || combinations, followed by random mix of unary ops
91
92evaluate {
93    {x = 0, y = 0, z = 0} {x = 0, y = 0, z = 1} {x = 0, y = 1, z = 0} {x = 0, y = 1, z = 1}
94    {x = 1, y = 0, z = 0} {x = 1, y = 0, z = 1} {x = 1, y = 1, z = 0} {x = 1, y = 1, z = 1}
95} {
96    { {x && y && z}    0 0 0 0  0 0 0 1 }
97    { {x || y && z}    0 0 0 1  1 1 1 1 }
98    { {x && y || z}    0 1 0 1  0 1 1 1 }
99    { {x || y || z}    0 1 1 1  1 1 1 1 }
100
101    { {x || !y && z}   0 1 0 0  1 1 1 1 }
102    { {!x || y && z}   1 1 1 1  0 0 0 1 }
103    { {!x || y && !z}  1 1 1 1  0 0 1 0 }
104}
105
106# More complex operations
107
108evaluate {
109    {x = 1, y = 2, w = 3, z = 3}
110    {x = 1, y = 2, w = 1, z = 3}
111    {x = 2, y = 2, w = 2, z = 3}
112} {
113    { {x > y || w == z}   1 0 0 }
114    { {x >= y && w != z}  0 0 1 }
115    { {! x > y || w + z}  1 1 1 }
116}
117