]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/relational.exp
Update year range in copyright notice of all files owned by the GDB project.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / relational.exp
1 # Copyright 1998-2015 Free Software Foundation, Inc.
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
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
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.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
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
24 #
25 # test running programs
26 #
27
28 if { [prepare_for_testing relational.exp relational int-type.c {debug nowarnings}] } {
29 return -1
30 }
31
32 if [get_compiler_info] {
33 return -1
34 }
35
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
49 gdb_test_no_output "set variable x=14" "set variable x=14"
50 gdb_test_no_output "set variable y=2" "set variable y=2"
51 gdb_test_no_output "set variable z=2" "set variable z=2"
52 gdb_test_no_output "set variable w=3" "set variable w=3"
53
54 gdb_test "print x" " = 14" "print value of x"
55
56 gdb_test "print y" " = 2" "print value of y"
57
58 gdb_test "print z" " = 2" "print value of z"
59
60 gdb_test "print w" " = 3" "print value of w"
61
62 gdb_test "print x < y" "$false" "print value of x<y"
63
64 gdb_test "print x <= y" "$false" "print value of x<=y"
65
66 gdb_test "print x > y" "$true" "print value of x>y"
67
68 gdb_test "print x >= y" "$true" "print value of x>=y"
69
70 gdb_test "print x == y" "$false" "print value of x==y"
71
72 gdb_test "print x != y" "$true" "print value of x!=y"
73
74
75 # Test associativity of <, >, <=, >=, ==, !=
76
77 gdb_test_no_output "set variable x=3" "set variable x"
78 gdb_test_no_output "set variable y=5" "set variable y"
79 gdb_test_no_output "set variable z=2" "set variable z"
80
81 gdb_test "print x < y < z" "$true" "print value of x<y<z"
82
83 gdb_test "print x <= y <= z" "$true" "print value of x<=y<=z"
84
85 gdb_test "print x > y > z" "$false" "print value of x>y>z"
86
87 gdb_test "print x >= y >= z" "$false" "print value of x>=y>=z"
88
89 gdb_test_no_output "set variable x=2" "set variable x"
90 gdb_test_no_output "set variable y=2" "set variable y"
91 gdb_test_no_output "set variable z=1" "set variable z"
92
93 gdb_test "print x == y == z" "$true" "print value of x==y==z"
94
95 gdb_test_no_output "set variable z=0" "set variable z"
96
97 gdb_test "print x != y != z" "$false" "print value of x!=y!=z"
98
99 # test precedence rules on pairs of relational operators
100
101 gdb_test_no_output "set variable x=0" "set variable x"
102 gdb_test_no_output "set variable y=2" "set variable y"
103 gdb_test_no_output "set variable z=2" "set variable z"
104
105 gdb_test "print x < y == z" "$false" "print value of x<y==z"
106
107 # 0 2 2
108 gdb_test "print x < y != z" "$true" "print value of x<y!=z"
109
110 gdb_test_no_output "set variable x=2" "set variable x"
111 gdb_test_no_output "set variable y=3" "set variable y"
112 gdb_test_no_output "set variable z=1" "set variable z"
113
114
115 # 2 3 1
116 gdb_test "print x < y <= z" "$true" "print value of x<y<=z"
117
118 # 2 3 1
119 gdb_test "print x < y >= z" "$true" "print value of x<y>=z"
120
121 gdb_test_no_output "set variable z=0" " set variable z"
122
123 # 2 3 0
124 gdb_test "print x < y > z" "$true" "print value of x<y>z"
125
126 gdb_test_no_output "set variable x=1" " set variable x"
127
128 # 1 3 0
129 gdb_test "print x > y >= z" "$true" "print value of x>y>=z"
130
131 gdb_test_no_output "set variable z=2" " set variable z"
132
133 # 1 3 2
134 gdb_test "print x > y == z" "$false" "print value of x>y==z"
135
136 gdb_test_no_output "set variable x=2" " set variable x"
137 gdb_test_no_output "set variable z=0" " set variable z"
138
139 # 2 3 0
140 gdb_test "print x > y != z" "$false" "print value of x>y!=z"
141
142 gdb_test_no_output "set variable x=4" "set x to 4"
143
144 # 4 3 0
145 gdb_test "print x > y <= z" "$false" "print value of x>y<=z"
146
147 # 4 3 0
148 gdb_test "print x >= y == z" "$false" "print value of x>=y==z"
149
150 gdb_test_no_output "set variable x=2" " set variable x"
151
152 # 2 3 0
153 gdb_test "print x >= y != z" "$false" "print value of x>=y!=z"
154
155 gdb_test_no_output "set variable x=0" " set variable x"
156 gdb_test_no_output "set variable z=4" " set variable z"
157
158 # 0 3 4
159 gdb_test "print x >= y <= z" "$true" "print value of x>=y<=z"
160
161 # 0 3 4
162 gdb_test "print x <= y == z" "$false" "print value of x<=y==z"
163
164 gdb_test_no_output "set variable x=2" " set variable x"
165
166 # 2 3 4
167 gdb_test "print x <= y != z" "$true" "print value of x<=y!=z"
168
169 # 2 3 4
170 gdb_test "print x == y != z" "$true" "print value of x==y!=z"
171
172
173
174 # test use of parenthesis to enforce different order of evaluation
175
176 gdb_test_no_output "set variable z=0" " set variable z"
177
178 # 2 3 0
179 gdb_test "print x >= (y < z)" "$true" "print value of x>=(y<z)"
180
181 # 2 3 0
182 gdb_test "print x >= (y != z)" "$true" "print value of x>=(y!=z)"
183
184 # 2 3 0
185 gdb_test "print x == (y == z)" "$false" "print value of x==(y==z)"
186
187 gdb_test_no_output "set variable x=1" " set variable x"
188 gdb_test_no_output "set variable z=4" " set variable z"
189
190 # 1 3 4
191 gdb_test "print (x == y) < z" "$true" "print value of (x==y)<z"
192