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