]>
Commit | Line | Data |
---|---|---|
f7d690e5 AC |
1 | # This testcase is part of GDB, the GNU debugger. |
2 | ||
213516ef | 3 | # Copyright 1998-2023 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 | 28 | standard_testfile int-type.c |
c906108c | 29 | |
fc91c6c2 | 30 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } { |
84c93cd5 | 31 | untested "failed to compile" |
b60f0898 | 32 | return -1 |
f7d690e5 | 33 | } |
c906108c | 34 | |
f8b41b00 | 35 | clean_restart ${binfile} |
c906108c SS |
36 | |
37 | ||
38 | # | |
39 | # set it up at a breakpoint so we can play with the variable values | |
40 | # | |
41 | ||
65a33d75 | 42 | if {![runto_main]} { |
cdd42066 | 43 | return |
c906108c SS |
44 | } |
45 | ||
f7d690e5 AC |
46 | proc 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 | } | |
c906108c | 56 | |
f7d690e5 | 57 | # Unary |
c906108c | 58 | |
f7d690e5 AC |
59 | evaluate { |
60 | {x = 0} {x = 1} | |
61 | } { | |
62 | { {x} 0 1 } | |
63 | { {!x} 1 0 } | |
64 | { {!!x} 0 1 } | |
65 | } | |
c906108c | 66 | |
f7d690e5 AC |
67 | # Binary (with unary) |
68 | ||
69 | evaluate { | |
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 | } | |
c906108c | 89 | |
f7d690e5 | 90 | # Full table of &&, || combinations, followed by random mix of unary ops |
c906108c | 91 | |
f7d690e5 AC |
92 | evaluate { |
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 } | |
c906108c | 100 | |
f7d690e5 AC |
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 | } | |
c906108c | 105 | |
f7d690e5 | 106 | # More complex operations |
c906108c | 107 | |
f7d690e5 AC |
108 | evaluate { |
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 | } |