Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | # Copyright 1998-2020 Free Software Foundation, Inc. |
c906108c SS |
2 | |
3 | # This program is free software; you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
e22f8b7c | 5 | # the Free Software Foundation; either version 3 of the License, or |
c906108c | 6 | # (at your option) any later version. |
e22f8b7c | 7 | # |
c906108c SS |
8 | # This program is distributed in the hope that it will be useful, |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. | |
e22f8b7c | 12 | # |
c906108c | 13 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
c906108c | 15 | |
c906108c SS |
16 | # This file was written by Elena Zannoni (ezannoni@cygnus.com) |
17 | ||
18 | # This file is part of the gdb testsuite | |
19 | # | |
20 | # tests for correctenss of relational operators, associativity and precedence | |
21 | # with integer type variables | |
22 | # | |
23 | ||
c906108c SS |
24 | # |
25 | # test running programs | |
26 | # | |
c906108c | 27 | |
5b362f04 | 28 | if { [prepare_for_testing "failed to prepare" relational int-type.c {debug nowarnings}] } { |
aa81e255 JK |
29 | return -1 |
30 | } | |
c906108c | 31 | |
4c93b1db | 32 | if [get_compiler_info] { |
ae59b1da | 33 | return -1 |
085dd6e6 | 34 | } |
c906108c | 35 | |
c906108c SS |
36 | # |
37 | # set it up at a breakpoint so we can play with the variable values | |
38 | # | |
39 | ||
40 | if ![runto_main] then { | |
41 | perror "couldn't run to breakpoint" | |
42 | continue | |
43 | } | |
44 | ||
45 | # | |
46 | # test expressions with "int" types | |
47 | # | |
48 | ||
2b74ba5a | 49 | with_test_prefix "int types" { |
c906108c | 50 | |
2b74ba5a AB |
51 | gdb_test_no_output "set variable x=14" "set variable x=14" |
52 | gdb_test_no_output "set variable y=2" "set variable y=2" | |
53 | gdb_test_no_output "set variable z=2" "set variable z=2" | |
54 | gdb_test_no_output "set variable w=3" "set variable w=3" | |
c906108c | 55 | |
2b74ba5a | 56 | gdb_test "print x" " = 14" "print value of x" |
02746bbc | 57 | |
2b74ba5a | 58 | gdb_test "print y" " = 2" "print value of y" |
02746bbc | 59 | |
2b74ba5a | 60 | gdb_test "print z" " = 2" "print value of z" |
02746bbc | 61 | |
2b74ba5a | 62 | gdb_test "print w" " = 3" "print value of w" |
02746bbc | 63 | |
2b74ba5a | 64 | gdb_test "print x < y" "$false" "print value of x<y" |
02746bbc | 65 | |
2b74ba5a | 66 | gdb_test "print x <= y" "$false" "print value of x<=y" |
02746bbc | 67 | |
2b74ba5a | 68 | gdb_test "print x > y" "$true" "print value of x>y" |
02746bbc | 69 | |
2b74ba5a | 70 | gdb_test "print x >= y" "$true" "print value of x>=y" |
02746bbc | 71 | |
2b74ba5a | 72 | gdb_test "print x == y" "$false" "print value of x==y" |
c906108c | 73 | |
2b74ba5a AB |
74 | gdb_test "print x != y" "$true" "print value of x!=y" |
75 | } | |
c906108c SS |
76 | |
77 | # Test associativity of <, >, <=, >=, ==, != | |
2b74ba5a | 78 | with_test_prefix "basic associativity" { |
c906108c | 79 | |
2b74ba5a AB |
80 | gdb_test_no_output "set variable x=3" "set variable x=3" |
81 | gdb_test_no_output "set variable y=5" "set variable y=5" | |
82 | gdb_test_no_output "set variable z=2" "set variable z=2" | |
c906108c | 83 | |
2b74ba5a | 84 | gdb_test "print x < y < z" "$true" "print value of x<y<z" |
c906108c | 85 | |
2b74ba5a | 86 | gdb_test "print x <= y <= z" "$true" "print value of x<=y<=z" |
c906108c | 87 | |
2b74ba5a | 88 | gdb_test "print x > y > z" "$false" "print value of x>y>z" |
c906108c | 89 | |
2b74ba5a | 90 | gdb_test "print x >= y >= z" "$false" "print value of x>=y>=z" |
c906108c | 91 | |
2b74ba5a AB |
92 | gdb_test_no_output "set variable x=2" "set variable x=2" |
93 | gdb_test_no_output "set variable y=2" "set variable y=2" | |
94 | gdb_test_no_output "set variable z=1" "set variable z=1" | |
c906108c | 95 | |
2b74ba5a | 96 | gdb_test "print x == y == z" "$true" "print value of x==y==z" |
c906108c | 97 | |
2b74ba5a | 98 | gdb_test_no_output "set variable z=0" "set variable z" |
c906108c | 99 | |
2b74ba5a AB |
100 | gdb_test "print x != y != z" "$false" "print value of x!=y!=z" |
101 | } | |
c906108c | 102 | |
2b74ba5a AB |
103 | # Test precedence rules on pairs of relational operators. The use of |
104 | # with_test_prefix with keys 1, 2, 3, etc is only to ensure that the | |
105 | # test names are unique. Each nested group of tests starts at a | |
106 | # location where we are setting a variable to a value it has had in | |
107 | # the past, which would result in a test name repeating. | |
108 | with_test_prefix "pair associativity" { | |
109 | with_test_prefix "1" { | |
110 | gdb_test_no_output "set variable x=0" "set variable x=0" | |
111 | gdb_test_no_output "set variable y=2" "set variable y=2" | |
112 | gdb_test_no_output "set variable z=2" "set variable z=2" | |
c906108c | 113 | |
2b74ba5a | 114 | gdb_test "print x < y == z" "$false" "print value of x<y==z" |
c906108c | 115 | |
2b74ba5a AB |
116 | # 0 2 2 |
117 | gdb_test "print x < y != z" "$true" "print value of x<y!=z" | |
c906108c | 118 | |
2b74ba5a AB |
119 | gdb_test_no_output "set variable x=2" "set variable x=2" |
120 | gdb_test_no_output "set variable y=3" "set variable y=3" | |
121 | gdb_test_no_output "set variable z=1" "set variable z=1" | |
c906108c | 122 | |
2b74ba5a AB |
123 | # 2 3 1 |
124 | gdb_test "print x < y <= z" "$true" "print value of x<y<=z" | |
c906108c | 125 | |
2b74ba5a AB |
126 | # 2 3 1 |
127 | gdb_test "print x < y >= z" "$true" "print value of x<y>=z" | |
c906108c | 128 | |
2b74ba5a | 129 | gdb_test_no_output "set variable z=0" " set variable z=0" |
c906108c | 130 | |
2b74ba5a AB |
131 | # 2 3 0 |
132 | gdb_test "print x < y > z" "$true" "print value of x<y>z" | |
c906108c | 133 | |
2b74ba5a | 134 | gdb_test_no_output "set variable x=1" " set variable x=1" |
c906108c | 135 | |
2b74ba5a AB |
136 | # 1 3 0 |
137 | gdb_test "print x > y >= z" "$true" "print value of x>y>=z" | |
138 | } | |
c906108c | 139 | |
2b74ba5a AB |
140 | with_test_prefix "2" { |
141 | gdb_test_no_output "set variable z=2" " set variable z=2" | |
c906108c | 142 | |
2b74ba5a AB |
143 | # 1 3 2 |
144 | gdb_test "print x > y == z" "$false" "print value of x>y==z" | |
c906108c | 145 | |
2b74ba5a AB |
146 | gdb_test_no_output "set variable x=2" " set variable x=2" |
147 | gdb_test_no_output "set variable z=0" " set variable z=0" | |
c906108c | 148 | |
2b74ba5a AB |
149 | # 2 3 0 |
150 | gdb_test "print x > y != z" "$false" "print value of x>y!=z" | |
c906108c | 151 | |
2b74ba5a | 152 | gdb_test_no_output "set variable x=4" "set variable x=4" |
c906108c | 153 | |
2b74ba5a AB |
154 | # 4 3 0 |
155 | gdb_test "print x > y <= z" "$false" "print value of x>y<=z" | |
c906108c | 156 | |
2b74ba5a AB |
157 | # 4 3 0 |
158 | gdb_test "print x >= y == z" "$false" "print value of x>=y==z" | |
159 | } | |
c906108c | 160 | |
2b74ba5a AB |
161 | with_test_prefix "3" { |
162 | gdb_test_no_output "set variable x=2" " set variable x=2" | |
c906108c | 163 | |
2b74ba5a AB |
164 | # 2 3 0 |
165 | gdb_test "print x >= y != z" "$false" "print value of x>=y!=z" | |
c906108c | 166 | |
2b74ba5a AB |
167 | gdb_test_no_output "set variable x=0" " set variable x=0" |
168 | gdb_test_no_output "set variable z=4" " set variable z=4" | |
c906108c | 169 | |
2b74ba5a AB |
170 | # 0 3 4 |
171 | gdb_test "print x >= y <= z" "$true" "print value of x>=y<=z" | |
c906108c | 172 | |
2b74ba5a AB |
173 | # 0 3 4 |
174 | gdb_test "print x <= y == z" "$false" "print value of x<=y==z" | |
175 | } | |
c906108c | 176 | |
2b74ba5a AB |
177 | with_test_prefix "4" { |
178 | gdb_test_no_output "set variable x=2" " set variable x=2" | |
c906108c | 179 | |
2b74ba5a AB |
180 | # 2 3 4 |
181 | gdb_test "print x <= y != z" "$true" "print value of x<=y!=z" | |
c906108c | 182 | |
2b74ba5a AB |
183 | # 2 3 4 |
184 | gdb_test "print x == y != z" "$true" "print value of x==y!=z" | |
185 | } | |
186 | } | |
c906108c | 187 | |
02746bbc | 188 | # test use of parenthesis to enforce different order of evaluation |
2b74ba5a AB |
189 | with_test_prefix "with parenthesis" { |
190 | gdb_test_no_output "set variable z=0" " set variable z=0" | |
c906108c | 191 | |
2b74ba5a AB |
192 | # 2 3 0 |
193 | gdb_test "print x >= (y < z)" "$true" "print value of x>=(y<z)" | |
c906108c | 194 | |
2b74ba5a AB |
195 | # 2 3 0 |
196 | gdb_test "print x >= (y != z)" "$true" "print value of x>=(y!=z)" | |
c906108c | 197 | |
2b74ba5a AB |
198 | # 2 3 0 |
199 | gdb_test "print x == (y == z)" "$false" "print value of x==(y==z)" | |
c906108c | 200 | |
2b74ba5a AB |
201 | gdb_test_no_output "set variable x=1" " set variable x=1" |
202 | gdb_test_no_output "set variable z=4" " set variable z=4" | |
c906108c | 203 | |
2b74ba5a AB |
204 | # 1 3 4 |
205 | gdb_test "print (x == y) < z" "$true" "print value of (x==y)<z" | |
206 | } | |
c906108c | 207 |