Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / logical.exp
CommitLineData
f7d690e5
AC
1# This testcase is part of GDB, the GNU debugger.
2
88b9d363 3# Copyright 1998-2022 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 27
f8b41b00 28standard_testfile int-type.c
c906108c 29
fc91c6c2 30if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
84c93cd5 31 untested "failed to compile"
b60f0898 32 return -1
f7d690e5 33}
c906108c 34
4c93b1db 35if [get_compiler_info] {
ae59b1da 36 return -1
085dd6e6 37}
c906108c 38
f8b41b00 39clean_restart ${binfile}
c906108c
SS
40
41
42#
43# set it up at a breakpoint so we can play with the variable values
44#
45
46if ![runto_main] then {
47 perror "couldn't run to breakpoint"
48 continue
49}
50
f7d690e5
AC
51proc 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"
58 }
59 }
60}
c906108c 61
f7d690e5 62# Unary
c906108c 63
f7d690e5
AC
64evaluate {
65 {x = 0} {x = 1}
66} {
67 { {x} 0 1 }
68 { {!x} 1 0 }
69 { {!!x} 0 1 }
70}
c906108c 71
f7d690e5
AC
72# Binary (with unary)
73
74evaluate {
75 {x = 0, y = 0} {x = 0, y = 1} {x = 1, y = 0} {x = 1, y = 1}
76} {
77 { {x && y} 0 0 0 1 }
78 { {!x && y} 0 1 0 0 }
79 { {x && !y} 0 0 1 0 }
80 { {!x && !y} 1 0 0 0 }
81
82 { {x || y} 0 1 1 1 }
83 { {!x || y} 1 1 0 1 }
84 { {x || !y} 1 0 1 1 }
85 { {!x || !y} 1 1 1 0 }
86
87 { {x < y} 0 1 0 0 }
88 { {x <= y} 1 1 0 1 }
89 { {x == y} 1 0 0 1 }
90 { {x != y} 0 1 1 0 }
91 { {x >= y} 1 0 1 1 }
92 { {x > y} 0 0 1 0 }
93}
c906108c 94
f7d690e5 95# Full table of &&, || combinations, followed by random mix of unary ops
c906108c 96
f7d690e5
AC
97evaluate {
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}
100} {
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 }
c906108c 105
f7d690e5
AC
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 }
109}
c906108c 110
f7d690e5 111# More complex operations
c906108c 112
f7d690e5
AC
113evaluate {
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}
117} {
118 { {x > y || w == z} 1 0 0 }
119 { {x >= y && w != z} 0 0 1 }
120 { {! x > y || w + z} 1 1 1 }
121}
This page took 2.394055 seconds and 4 git commands to generate.