Commit | Line | Data |
---|---|---|
4c38e0a4 | 1 | # Copyright 1998, 1999, 2007, 2008, 2009, 2010 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 | ||
24 | if $tracelevel then { | |
25 | strace $tracelevel | |
26 | } | |
27 | ||
28 | # | |
29 | # test running programs | |
30 | # | |
c906108c | 31 | |
aa81e255 JK |
32 | if { [prepare_for_testing relational.exp relational int-type.c {debug nowarnings}] } { |
33 | return -1 | |
34 | } | |
c906108c | 35 | |
aa81e255 | 36 | if [get_compiler_info not-used] { |
085dd6e6 JM |
37 | return -1; |
38 | } | |
c906108c | 39 | |
c906108c SS |
40 | # |
41 | # set it up at a breakpoint so we can play with the variable values | |
42 | # | |
43 | ||
44 | if ![runto_main] then { | |
45 | perror "couldn't run to breakpoint" | |
46 | continue | |
47 | } | |
48 | ||
49 | # | |
50 | # test expressions with "int" types | |
51 | # | |
52 | ||
53 | gdb_test "set variable x=14" "" "set variable x=14" | |
54 | gdb_test "set variable y=2" "" "set variable y=2" | |
55 | gdb_test "set variable z=2" "" "set variable z=2" | |
56 | gdb_test "set variable w=3" "" "set variable w=3" | |
57 | ||
58 | send_gdb "print x\n" | |
59 | gdb_expect { | |
60 | -re ".*14.*$gdb_prompt $" { | |
61 | pass "print value of x" | |
62 | } | |
63 | -re ".*$gdb_prompt $" { fail "print value of x" } | |
64 | timeout { fail "(timeout) print value of x" } | |
65 | } | |
66 | ||
67 | ||
68 | send_gdb "print y\n" | |
69 | gdb_expect { | |
70 | -re ".*2.*$gdb_prompt $" { | |
71 | pass "print value of y" | |
72 | } | |
73 | -re ".*$gdb_prompt $" { fail "print value of y" } | |
74 | timeout { fail "(timeout) print value of y" } | |
75 | } | |
76 | ||
77 | send_gdb "print z\n" | |
78 | gdb_expect { | |
79 | -re ".*2.*$gdb_prompt $" { | |
80 | pass "print value of z" | |
81 | } | |
82 | -re ".*$gdb_prompt $" { fail "print value of z" } | |
83 | timeout { fail "(timeout) print value of z" } | |
84 | } | |
85 | ||
86 | send_gdb "print w\n" | |
87 | gdb_expect { | |
88 | -re ".*3.*$gdb_prompt $" { | |
89 | pass "print value of w" | |
90 | } | |
91 | -re ".*$gdb_prompt $" { fail "print value of w" } | |
92 | timeout { fail "(timeout) print value of w" } | |
93 | } | |
94 | ||
95 | ||
96 | ||
97 | send_gdb "print x < y\n" | |
98 | gdb_expect { | |
085dd6e6 | 99 | -re ".*$false.*$gdb_prompt $" { |
c906108c SS |
100 | pass "print value of x<y" |
101 | } | |
102 | -re ".*$gdb_prompt $" { fail "print value of x<y" } | |
103 | timeout { fail "(timeout) print value of x<y" } | |
104 | } | |
105 | ||
106 | send_gdb "print x <= y\n" | |
107 | gdb_expect { | |
085dd6e6 | 108 | -re ".*$false.*$gdb_prompt $" { |
c906108c SS |
109 | pass "print value of x<=y" |
110 | } | |
111 | -re ".*$gdb_prompt $" { fail "print value of x<=y" } | |
112 | timeout { fail "(timeout) print value of x<=y" } | |
113 | } | |
114 | ||
115 | send_gdb "print x > y\n" | |
116 | gdb_expect { | |
085dd6e6 | 117 | -re ".*$true.*$gdb_prompt $" { |
c906108c SS |
118 | pass "print value of x>y" |
119 | } | |
120 | -re ".*$gdb_prompt $" { fail "print value of x>y" } | |
121 | timeout { fail "(timeout) print value of x>y" } | |
122 | } | |
123 | ||
124 | send_gdb "print x >= y\n" | |
125 | gdb_expect { | |
085dd6e6 | 126 | -re ".*$true.*$gdb_prompt $" { |
c906108c SS |
127 | pass "print value of x>=y" |
128 | } | |
129 | -re ".*$gdb_prompt $" { fail "print value of x>=y" } | |
130 | timeout { fail "(timeout) print value of x>=y" } | |
131 | } | |
132 | ||
133 | send_gdb "print x == y\n" | |
134 | gdb_expect { | |
085dd6e6 | 135 | -re ".*$false.*$gdb_prompt $" { |
c906108c SS |
136 | pass "print value of x==y" |
137 | } | |
138 | -re ".*$gdb_prompt $" { fail "print value of x==y" } | |
139 | timeout { fail "(timeout) print value of x==y" } | |
140 | } | |
141 | ||
142 | send_gdb "print x != y\n" | |
143 | gdb_expect { | |
085dd6e6 | 144 | -re ".*$true.*$gdb_prompt $" { |
c906108c SS |
145 | pass "print value of x!=y" |
146 | } | |
147 | -re ".*$gdb_prompt $" { fail "print value of x!=y" } | |
148 | timeout { fail "(timeout) print value of x!=y" } | |
149 | } | |
150 | ||
151 | ||
152 | ||
153 | # Test associativity of <, >, <=, >=, ==, != | |
154 | ||
155 | gdb_test "set variable x=3" "" "set variable x" | |
156 | gdb_test "set variable y=5" "" "set variable y" | |
157 | gdb_test "set variable z=2" "" "set variable z" | |
158 | ||
159 | ||
160 | ||
161 | send_gdb "print x < y < z\n" | |
162 | gdb_expect { | |
085dd6e6 | 163 | -re ".*$true.*\r\n$gdb_prompt $" { |
c906108c SS |
164 | pass "print value of x<y<z" |
165 | } | |
166 | -re ".*$gdb_prompt $" { fail "print value of x<y<z" } | |
167 | timeout { fail "(timeout) print value of x<y<z" } | |
168 | } | |
169 | ||
170 | send_gdb "print x <= y <= z\n" | |
171 | gdb_expect { | |
085dd6e6 | 172 | -re ".*$true\r\n$gdb_prompt $" { |
c906108c SS |
173 | pass "print value of x<=y<=z" |
174 | } | |
175 | -re ".*$gdb_prompt $" { fail "print value of x<=y<=z" } | |
176 | timeout { fail "(timeout) print value of x<=y<=z" } | |
177 | } | |
178 | ||
179 | send_gdb "print x > y > z\n" | |
180 | gdb_expect { | |
085dd6e6 | 181 | -re ".*$false.*\r\n$gdb_prompt $" { |
c906108c SS |
182 | pass "print value of x>y>z" |
183 | } | |
184 | -re 8".*$gdb_prompt $" { fail "print value of x>y>z" } | |
185 | timeout { fail "(timeout) print value of x>y>z" } | |
186 | } | |
187 | ||
188 | send_gdb "print x >= y >= z\n" | |
189 | gdb_expect { | |
085dd6e6 | 190 | -re ".*$false.*\r\n$gdb_prompt $" { |
c906108c SS |
191 | pass "print value of x>=y>=z" |
192 | } | |
193 | -re ".*$gdb_prompt $" { fail "print value of x>=y>=z" } | |
194 | timeout { fail "(timeout) print value of x>=y>=z" } | |
195 | } | |
196 | ||
197 | gdb_test "set variable x=2" "" "set variable x" | |
198 | gdb_test "set variable y=2" "" "set variable y" | |
199 | gdb_test "set variable z=1" "" "set variable z" | |
200 | ||
201 | ||
202 | send_gdb "print x == y == z\n" | |
203 | gdb_expect { | |
085dd6e6 | 204 | -re ".*$true.*$gdb_prompt $" { |
c906108c SS |
205 | pass "print value of x==y==z" |
206 | } | |
207 | -re ".*$gdb_prompt $" { fail "print value of x==y==z" } | |
208 | timeout { fail "(timeout) print value of x==y==z" } | |
209 | } | |
210 | ||
211 | gdb_test "set variable z=0" "" "set variable z" | |
212 | ||
213 | ||
214 | send_gdb "print x != y != z\n" | |
215 | gdb_expect { | |
085dd6e6 | 216 | -re ".*$false\r\n$gdb_prompt $" { |
c906108c SS |
217 | pass "print value of x!=y!=z" |
218 | } | |
219 | -re ".*$gdb_prompt $" { fail "print value of x!=y!=z" } | |
220 | timeout { fail "(timeout) print value of x!=y!=z" } | |
221 | } | |
222 | ||
223 | ||
224 | # test precedence rules on pairs of relational operators | |
225 | ||
226 | gdb_test "set variable x=0" "" "set variable x" | |
227 | gdb_test "set variable y=2" "" "set variable y" | |
228 | gdb_test "set variable z=2" "" "set variable z" | |
229 | ||
230 | ||
231 | send_gdb "print x < y == z\n" | |
232 | gdb_expect { | |
085dd6e6 | 233 | -re ".*$false.*$gdb_prompt $" { |
c906108c SS |
234 | pass "print value of x<y==z" |
235 | } | |
236 | -re ".*$gdb_prompt $" { fail "print value of x<y==z" } | |
237 | timeout { fail "(timeout) print value of x<y==z" } | |
238 | } | |
239 | ||
240 | # 0 2 2 | |
241 | send_gdb "print x < y != z\n" | |
242 | gdb_expect { | |
085dd6e6 | 243 | -re ".*$true.*$gdb_prompt $" { |
c906108c SS |
244 | pass "print value of x<y!=z" |
245 | } | |
246 | -re ".*$gdb_prompt $" { fail "print value of x<y!=z" } | |
247 | timeout { fail "(timeout) print value of x<y!=z" } | |
248 | } | |
249 | ||
250 | gdb_test "set variable x=2" "" "set variable x" | |
251 | gdb_test "set variable y=3" "" "set variable y" | |
252 | gdb_test "set variable z=1" "" "set variable z" | |
253 | ||
254 | ||
255 | # 2 3 1 | |
256 | send_gdb "print x < y <= z\n" | |
257 | gdb_expect { | |
085dd6e6 | 258 | -re ".*$true.*$gdb_prompt $" { |
c906108c SS |
259 | pass "print value of x<y<=z" |
260 | } | |
261 | -re ".*$gdb_prompt $" { fail "print value of x<y<=z" } | |
262 | timeout { fail "(timeout) print value of x<y<=z" } | |
263 | } | |
264 | ||
265 | ||
266 | # 2 3 1 | |
267 | send_gdb "print x < y >= z\n" | |
268 | gdb_expect { | |
085dd6e6 | 269 | -re ".*$true.*$gdb_prompt $" { |
c906108c SS |
270 | pass "print value of x<y>=z" |
271 | } | |
272 | -re ".*$gdb_prompt $" { fail "print value of x<y>=z" } | |
273 | timeout { fail "(timeout) print value of x<y>=z" } | |
274 | } | |
275 | ||
276 | ||
277 | gdb_test "set variable z=0" "" " set variable z" | |
278 | ||
279 | ||
280 | # 2 3 0 | |
281 | send_gdb "print x < y > z\n" | |
282 | gdb_expect { | |
085dd6e6 | 283 | -re ".*$true.*$gdb_prompt $" { |
c906108c SS |
284 | pass "print value of x<y>z" |
285 | } | |
286 | -re ".*$gdb_prompt $" { fail "print value of x<y>z" } | |
287 | timeout { fail "(timeout) print value of x<y>z" } | |
288 | } | |
289 | ||
290 | ||
291 | gdb_test "set variable x=1" "" " set variable x" | |
292 | ||
293 | # 1 3 0 | |
294 | send_gdb "print x > y >= z\n" | |
295 | gdb_expect { | |
085dd6e6 | 296 | -re ".*$true.*$gdb_prompt $" { |
c906108c SS |
297 | pass "print value of x>y>=z" |
298 | } | |
299 | -re ".*$gdb_prompt $" { fail "print value of x>y>=z" } | |
300 | timeout { fail "(timeout) print value of x>y>=z" } | |
301 | } | |
302 | ||
303 | ||
304 | gdb_test "set variable z=2" "" " set variable z" | |
305 | ||
306 | # 1 3 2 | |
307 | send_gdb "print x > y == z\n" | |
308 | gdb_expect { | |
085dd6e6 | 309 | -re ".*$false.*$gdb_prompt $" { |
c906108c SS |
310 | pass "print value of x>y==z" |
311 | } | |
312 | -re ".*$gdb_prompt $" { fail "print value of x>y==z" } | |
313 | timeout { fail "(timeout) print value of x>y==z" } | |
314 | } | |
315 | ||
316 | ||
317 | gdb_test "set variable x=2" "" " set variable x" | |
318 | gdb_test "set variable z=0" "" " set variable z" | |
319 | ||
320 | # 2 3 0 | |
321 | send_gdb "print x > y != z\n" | |
322 | gdb_expect { | |
085dd6e6 | 323 | -re ".*$false.*$gdb_prompt $" { |
c906108c SS |
324 | pass "print value of x>y!=z" |
325 | } | |
326 | -re ".*$gdb_prompt $" { fail "print value of x>y!=z" } | |
327 | timeout { fail "(timeout) print value of x>y!=z" } | |
328 | } | |
329 | ||
330 | ||
331 | gdb_test "set variable x=4" "" "set x to 4" | |
332 | ||
333 | # 4 3 0 | |
334 | send_gdb "print x > y <= z\n" | |
335 | gdb_expect { | |
085dd6e6 | 336 | -re ".*$false.*$gdb_prompt $" { |
c906108c SS |
337 | pass "print value of x>y<=z" |
338 | } | |
339 | -re ".*$gdb_prompt $" { fail "print value of x>y<=z" } | |
340 | timeout { fail "(timeout) print value of x>y<=z" } | |
341 | } | |
342 | ||
343 | # 4 3 0 | |
344 | send_gdb "print x >= y == z\n" | |
345 | gdb_expect { | |
085dd6e6 | 346 | -re ".*$false\r\n$gdb_prompt $" { |
c906108c SS |
347 | pass "print value of x>=y==z" |
348 | } | |
349 | -re ".*$gdb_prompt $" { fail "print value of x>=y==z" } | |
350 | timeout { fail "(timeout) print value of x>=y==z" } | |
351 | } | |
352 | ||
353 | ||
354 | gdb_test "set variable x=2" "" " set variable x" | |
355 | ||
356 | # 2 3 0 | |
357 | send_gdb "print x >= y != z\n" | |
358 | gdb_expect { | |
085dd6e6 | 359 | -re ".*$false\r\n$gdb_prompt $" { |
c906108c SS |
360 | pass "print value of x>=y!=z" |
361 | } | |
362 | -re ".*$gdb_prompt $" { fail "print value of x>=y!=z" } | |
363 | timeout { fail "(timeout) print value of x>=y!=z" } | |
364 | } | |
365 | ||
366 | ||
367 | gdb_test "set variable x=0" "" " set variable x" | |
368 | gdb_test "set variable z=4" "" " set variable z" | |
369 | ||
370 | # 0 3 4 | |
371 | send_gdb "print x >= y <= z\n" | |
372 | gdb_expect { | |
085dd6e6 | 373 | -re ".*$true\r\n$gdb_prompt $" { |
c906108c SS |
374 | pass "print value of x>=y<=z" |
375 | } | |
376 | -re ".*$gdb_prompt $" { fail "print value of x>=y<=z" } | |
377 | timeout { fail "(timeout) print value of x>=y<=z" } | |
378 | } | |
379 | ||
380 | # 0 3 4 | |
381 | send_gdb "print x <= y == z\n" | |
382 | gdb_expect { | |
085dd6e6 | 383 | -re ".*$false\r\n$gdb_prompt $" { |
c906108c SS |
384 | pass "print value of x<=y==z" |
385 | } | |
386 | -re ".*$gdb_prompt $" { fail "print value of x<=y==z" } | |
387 | timeout { fail "(timeout) print value of x<=y==z" } | |
388 | } | |
389 | ||
390 | gdb_test "set variable x=2" "" " set variable x" | |
391 | ||
392 | # 2 3 4 | |
393 | send_gdb "print x <= y != z\n" | |
394 | gdb_expect { | |
085dd6e6 | 395 | -re ".*$true\r\n$gdb_prompt $" { |
c906108c SS |
396 | pass "print value of x<=y!=z" |
397 | } | |
398 | -re ".*$gdb_prompt $" { fail "print value of x<=y!=z" } | |
399 | timeout { fail "(timeout) print value of x<=y!=z" } | |
400 | } | |
401 | ||
402 | ||
403 | # 2 3 4 | |
404 | send_gdb "print x == y != z\n" | |
405 | gdb_expect { | |
085dd6e6 | 406 | -re ".*$true\r\n$gdb_prompt $" { |
c906108c SS |
407 | pass "print value of x==y!=z" |
408 | } | |
409 | -re ".*$gdb_prompt $" { fail "print value of x==y!=z" } | |
410 | timeout { fail "(timeout) print value of x==y!=z" } | |
411 | } | |
412 | ||
413 | ||
414 | ||
415 | # test use of parenthesis to enforce different order of evaluation | |
416 | ||
417 | ||
418 | gdb_test "set variable z=0" "" " set variable z" | |
419 | ||
420 | # 2 3 0 | |
421 | send_gdb "print x >= (y < z)\n" | |
422 | gdb_expect { | |
085dd6e6 | 423 | -re ".*$true\r\n$gdb_prompt $" { |
c906108c SS |
424 | pass "print value of x>=(y<z)" |
425 | } | |
426 | -re ".*$gdb_prompt $" { fail "print value of x>=(y<z)" } | |
427 | timeout { fail "(timeout) print value of x>=(y<z)" } | |
428 | } | |
429 | ||
430 | ||
431 | # 2 3 0 | |
432 | send_gdb "print x >= (y != z)\n" | |
433 | gdb_expect { | |
085dd6e6 | 434 | -re ".*$true\r\n$gdb_prompt $" { |
c906108c SS |
435 | pass "print value of x>=(y!=z)" |
436 | } | |
437 | -re ".*$gdb_prompt $" { fail "print value of x>=(y*!=z)" } | |
438 | timeout { fail "(timeout) print value of x>=(y!=z)" } | |
439 | } | |
440 | ||
441 | # 2 3 0 | |
442 | send_gdb "print x == (y == z)\n" | |
443 | gdb_expect { | |
085dd6e6 | 444 | -re ".*$false\r\n$gdb_prompt $" { |
c906108c SS |
445 | pass "print value of x==(y==z)" |
446 | } | |
447 | -re ".*$gdb_prompt $" { fail "print value of x==(y==z)" } | |
448 | timeout { fail "(timeout) print value of x==(y==z)" } | |
449 | } | |
450 | ||
451 | ||
452 | gdb_test "set variable x=1" "" " set variable x" | |
453 | gdb_test "set variable z=4" "" " set variable z" | |
454 | ||
455 | # 1 3 4 | |
456 | send_gdb "print (x == y) < z\n" | |
457 | gdb_expect { | |
085dd6e6 | 458 | -re ".*$true\r\n$gdb_prompt $" { |
c906108c SS |
459 | pass "print value of (x==y)<z" |
460 | } | |
461 | -re ".*$gdb_prompt $" { fail "print value of (x==y)<z" } | |
462 | timeout { fail "(timeout) print value of (x==y)<z" } | |
463 | } | |
464 | ||
465 | ||
466 | ||
467 | ||
468 | ||
469 |