Commit | Line | Data |
---|---|---|
b6ba6518 | 1 | # Copyright 1998, 1999 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 | |
5 | # the Free Software Foundation; either version 2 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, write to the Free Software | |
15 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
16 | ||
17 | # Please email any bugs, comments, and/or additions to this file to: | |
18 | # bug-gdb@prep.ai.mit.edu | |
19 | ||
20 | # This file was written by Elena Zannoni (ezannoni@cygnus.com) | |
21 | ||
22 | # This file is part of the gdb testsuite | |
23 | # | |
24 | # tests for correctenss of relational operators, associativity and precedence | |
25 | # with integer type variables | |
26 | # | |
27 | ||
28 | if $tracelevel then { | |
29 | strace $tracelevel | |
30 | } | |
31 | ||
32 | # | |
33 | # test running programs | |
34 | # | |
35 | set prms_id 0 | |
36 | set bug_id 0 | |
37 | ||
38 | set testfile "int-type" | |
39 | set srcfile ${testfile}.c | |
40 | set binfile ${objdir}/${subdir}/${testfile} | |
fc91c6c2 | 41 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } { |
c906108c SS |
42 | gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." |
43 | } | |
44 | ||
085dd6e6 JM |
45 | if [get_compiler_info ${binfile}] { |
46 | return -1; | |
47 | } | |
c906108c SS |
48 | |
49 | gdb_exit | |
50 | gdb_start | |
51 | gdb_reinitialize_dir $srcdir/$subdir | |
52 | gdb_load ${binfile} | |
53 | ||
54 | ||
55 | # | |
56 | # set it up at a breakpoint so we can play with the variable values | |
57 | # | |
58 | ||
59 | if ![runto_main] then { | |
60 | perror "couldn't run to breakpoint" | |
61 | continue | |
62 | } | |
63 | ||
64 | # | |
65 | # test expressions with "int" types | |
66 | # | |
67 | ||
68 | gdb_test "set variable x=14" "" "set variable x=14" | |
69 | gdb_test "set variable y=2" "" "set variable y=2" | |
70 | gdb_test "set variable z=2" "" "set variable z=2" | |
71 | gdb_test "set variable w=3" "" "set variable w=3" | |
72 | ||
73 | send_gdb "print x\n" | |
74 | gdb_expect { | |
75 | -re ".*14.*$gdb_prompt $" { | |
76 | pass "print value of x" | |
77 | } | |
78 | -re ".*$gdb_prompt $" { fail "print value of x" } | |
79 | timeout { fail "(timeout) print value of x" } | |
80 | } | |
81 | ||
82 | ||
83 | send_gdb "print y\n" | |
84 | gdb_expect { | |
85 | -re ".*2.*$gdb_prompt $" { | |
86 | pass "print value of y" | |
87 | } | |
88 | -re ".*$gdb_prompt $" { fail "print value of y" } | |
89 | timeout { fail "(timeout) print value of y" } | |
90 | } | |
91 | ||
92 | send_gdb "print z\n" | |
93 | gdb_expect { | |
94 | -re ".*2.*$gdb_prompt $" { | |
95 | pass "print value of z" | |
96 | } | |
97 | -re ".*$gdb_prompt $" { fail "print value of z" } | |
98 | timeout { fail "(timeout) print value of z" } | |
99 | } | |
100 | ||
101 | send_gdb "print w\n" | |
102 | gdb_expect { | |
103 | -re ".*3.*$gdb_prompt $" { | |
104 | pass "print value of w" | |
105 | } | |
106 | -re ".*$gdb_prompt $" { fail "print value of w" } | |
107 | timeout { fail "(timeout) print value of w" } | |
108 | } | |
109 | ||
110 | ||
111 | ||
112 | send_gdb "print x < y\n" | |
113 | gdb_expect { | |
085dd6e6 | 114 | -re ".*$false.*$gdb_prompt $" { |
c906108c SS |
115 | pass "print value of x<y" |
116 | } | |
117 | -re ".*$gdb_prompt $" { fail "print value of x<y" } | |
118 | timeout { fail "(timeout) print value of x<y" } | |
119 | } | |
120 | ||
121 | send_gdb "print x <= y\n" | |
122 | gdb_expect { | |
085dd6e6 | 123 | -re ".*$false.*$gdb_prompt $" { |
c906108c SS |
124 | pass "print value of x<=y" |
125 | } | |
126 | -re ".*$gdb_prompt $" { fail "print value of x<=y" } | |
127 | timeout { fail "(timeout) print value of x<=y" } | |
128 | } | |
129 | ||
130 | send_gdb "print x > y\n" | |
131 | gdb_expect { | |
085dd6e6 | 132 | -re ".*$true.*$gdb_prompt $" { |
c906108c SS |
133 | pass "print value of x>y" |
134 | } | |
135 | -re ".*$gdb_prompt $" { fail "print value of x>y" } | |
136 | timeout { fail "(timeout) print value of x>y" } | |
137 | } | |
138 | ||
139 | send_gdb "print x >= y\n" | |
140 | gdb_expect { | |
085dd6e6 | 141 | -re ".*$true.*$gdb_prompt $" { |
c906108c SS |
142 | pass "print value of x>=y" |
143 | } | |
144 | -re ".*$gdb_prompt $" { fail "print value of x>=y" } | |
145 | timeout { fail "(timeout) print value of x>=y" } | |
146 | } | |
147 | ||
148 | send_gdb "print x == y\n" | |
149 | gdb_expect { | |
085dd6e6 | 150 | -re ".*$false.*$gdb_prompt $" { |
c906108c SS |
151 | pass "print value of x==y" |
152 | } | |
153 | -re ".*$gdb_prompt $" { fail "print value of x==y" } | |
154 | timeout { fail "(timeout) print value of x==y" } | |
155 | } | |
156 | ||
157 | send_gdb "print x != y\n" | |
158 | gdb_expect { | |
085dd6e6 | 159 | -re ".*$true.*$gdb_prompt $" { |
c906108c SS |
160 | pass "print value of x!=y" |
161 | } | |
162 | -re ".*$gdb_prompt $" { fail "print value of x!=y" } | |
163 | timeout { fail "(timeout) print value of x!=y" } | |
164 | } | |
165 | ||
166 | ||
167 | ||
168 | # Test associativity of <, >, <=, >=, ==, != | |
169 | ||
170 | gdb_test "set variable x=3" "" "set variable x" | |
171 | gdb_test "set variable y=5" "" "set variable y" | |
172 | gdb_test "set variable z=2" "" "set variable z" | |
173 | ||
174 | ||
175 | ||
176 | send_gdb "print x < y < z\n" | |
177 | gdb_expect { | |
085dd6e6 | 178 | -re ".*$true.*\r\n$gdb_prompt $" { |
c906108c SS |
179 | pass "print value of x<y<z" |
180 | } | |
181 | -re ".*$gdb_prompt $" { fail "print value of x<y<z" } | |
182 | timeout { fail "(timeout) print value of x<y<z" } | |
183 | } | |
184 | ||
185 | send_gdb "print x <= y <= z\n" | |
186 | gdb_expect { | |
085dd6e6 | 187 | -re ".*$true\r\n$gdb_prompt $" { |
c906108c SS |
188 | pass "print value of x<=y<=z" |
189 | } | |
190 | -re ".*$gdb_prompt $" { fail "print value of x<=y<=z" } | |
191 | timeout { fail "(timeout) print value of x<=y<=z" } | |
192 | } | |
193 | ||
194 | send_gdb "print x > y > z\n" | |
195 | gdb_expect { | |
085dd6e6 | 196 | -re ".*$false.*\r\n$gdb_prompt $" { |
c906108c SS |
197 | pass "print value of x>y>z" |
198 | } | |
199 | -re 8".*$gdb_prompt $" { fail "print value of x>y>z" } | |
200 | timeout { fail "(timeout) print value of x>y>z" } | |
201 | } | |
202 | ||
203 | send_gdb "print x >= y >= z\n" | |
204 | gdb_expect { | |
085dd6e6 | 205 | -re ".*$false.*\r\n$gdb_prompt $" { |
c906108c SS |
206 | pass "print value of x>=y>=z" |
207 | } | |
208 | -re ".*$gdb_prompt $" { fail "print value of x>=y>=z" } | |
209 | timeout { fail "(timeout) print value of x>=y>=z" } | |
210 | } | |
211 | ||
212 | gdb_test "set variable x=2" "" "set variable x" | |
213 | gdb_test "set variable y=2" "" "set variable y" | |
214 | gdb_test "set variable z=1" "" "set variable z" | |
215 | ||
216 | ||
217 | send_gdb "print x == y == z\n" | |
218 | gdb_expect { | |
085dd6e6 | 219 | -re ".*$true.*$gdb_prompt $" { |
c906108c SS |
220 | pass "print value of x==y==z" |
221 | } | |
222 | -re ".*$gdb_prompt $" { fail "print value of x==y==z" } | |
223 | timeout { fail "(timeout) print value of x==y==z" } | |
224 | } | |
225 | ||
226 | gdb_test "set variable z=0" "" "set variable z" | |
227 | ||
228 | ||
229 | send_gdb "print x != y != z\n" | |
230 | gdb_expect { | |
085dd6e6 | 231 | -re ".*$false\r\n$gdb_prompt $" { |
c906108c SS |
232 | pass "print value of x!=y!=z" |
233 | } | |
234 | -re ".*$gdb_prompt $" { fail "print value of x!=y!=z" } | |
235 | timeout { fail "(timeout) print value of x!=y!=z" } | |
236 | } | |
237 | ||
238 | ||
239 | # test precedence rules on pairs of relational operators | |
240 | ||
241 | gdb_test "set variable x=0" "" "set variable x" | |
242 | gdb_test "set variable y=2" "" "set variable y" | |
243 | gdb_test "set variable z=2" "" "set variable z" | |
244 | ||
245 | ||
246 | send_gdb "print x < y == z\n" | |
247 | gdb_expect { | |
085dd6e6 | 248 | -re ".*$false.*$gdb_prompt $" { |
c906108c SS |
249 | pass "print value of x<y==z" |
250 | } | |
251 | -re ".*$gdb_prompt $" { fail "print value of x<y==z" } | |
252 | timeout { fail "(timeout) print value of x<y==z" } | |
253 | } | |
254 | ||
255 | # 0 2 2 | |
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 | gdb_test "set variable x=2" "" "set variable x" | |
266 | gdb_test "set variable y=3" "" "set variable y" | |
267 | gdb_test "set variable z=1" "" "set variable z" | |
268 | ||
269 | ||
270 | # 2 3 1 | |
271 | send_gdb "print x < y <= z\n" | |
272 | gdb_expect { | |
085dd6e6 | 273 | -re ".*$true.*$gdb_prompt $" { |
c906108c SS |
274 | pass "print value of x<y<=z" |
275 | } | |
276 | -re ".*$gdb_prompt $" { fail "print value of x<y<=z" } | |
277 | timeout { fail "(timeout) print value of x<y<=z" } | |
278 | } | |
279 | ||
280 | ||
281 | # 2 3 1 | |
282 | send_gdb "print x < y >= z\n" | |
283 | gdb_expect { | |
085dd6e6 | 284 | -re ".*$true.*$gdb_prompt $" { |
c906108c SS |
285 | pass "print value of x<y>=z" |
286 | } | |
287 | -re ".*$gdb_prompt $" { fail "print value of x<y>=z" } | |
288 | timeout { fail "(timeout) print value of x<y>=z" } | |
289 | } | |
290 | ||
291 | ||
292 | gdb_test "set variable z=0" "" " set variable z" | |
293 | ||
294 | ||
295 | # 2 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 x=1" "" " set variable x" | |
307 | ||
308 | # 1 3 0 | |
309 | send_gdb "print x > y >= z\n" | |
310 | gdb_expect { | |
085dd6e6 | 311 | -re ".*$true.*$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 z=2" "" " set variable z" | |
320 | ||
321 | # 1 3 2 | |
322 | send_gdb "print x > y == z\n" | |
323 | gdb_expect { | |
085dd6e6 | 324 | -re ".*$false.*$gdb_prompt $" { |
c906108c SS |
325 | pass "print value of x>y==z" |
326 | } | |
327 | -re ".*$gdb_prompt $" { fail "print value of x>y==z" } | |
328 | timeout { fail "(timeout) print value of x>y==z" } | |
329 | } | |
330 | ||
331 | ||
332 | gdb_test "set variable x=2" "" " set variable x" | |
333 | gdb_test "set variable z=0" "" " set variable z" | |
334 | ||
335 | # 2 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 | ||
346 | gdb_test "set variable x=4" "" "set x to 4" | |
347 | ||
348 | # 4 3 0 | |
349 | send_gdb "print x > y <= z\n" | |
350 | gdb_expect { | |
085dd6e6 | 351 | -re ".*$false.*$gdb_prompt $" { |
c906108c SS |
352 | pass "print value of x>y<=z" |
353 | } | |
354 | -re ".*$gdb_prompt $" { fail "print value of x>y<=z" } | |
355 | timeout { fail "(timeout) print value of x>y<=z" } | |
356 | } | |
357 | ||
358 | # 4 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=2" "" " set variable x" | |
370 | ||
371 | # 2 3 0 | |
372 | send_gdb "print x >= y != z\n" | |
373 | gdb_expect { | |
085dd6e6 | 374 | -re ".*$false\r\n$gdb_prompt $" { |
c906108c SS |
375 | pass "print value of x>=y!=z" |
376 | } | |
377 | -re ".*$gdb_prompt $" { fail "print value of x>=y!=z" } | |
378 | timeout { fail "(timeout) print value of x>=y!=z" } | |
379 | } | |
380 | ||
381 | ||
382 | gdb_test "set variable x=0" "" " set variable x" | |
383 | gdb_test "set variable z=4" "" " set variable z" | |
384 | ||
385 | # 0 3 4 | |
386 | send_gdb "print x >= y <= z\n" | |
387 | gdb_expect { | |
085dd6e6 | 388 | -re ".*$true\r\n$gdb_prompt $" { |
c906108c SS |
389 | pass "print value of x>=y<=z" |
390 | } | |
391 | -re ".*$gdb_prompt $" { fail "print value of x>=y<=z" } | |
392 | timeout { fail "(timeout) print value of x>=y<=z" } | |
393 | } | |
394 | ||
395 | # 0 3 4 | |
396 | send_gdb "print x <= y == z\n" | |
397 | gdb_expect { | |
085dd6e6 | 398 | -re ".*$false\r\n$gdb_prompt $" { |
c906108c SS |
399 | pass "print value of x<=y==z" |
400 | } | |
401 | -re ".*$gdb_prompt $" { fail "print value of x<=y==z" } | |
402 | timeout { fail "(timeout) print value of x<=y==z" } | |
403 | } | |
404 | ||
405 | gdb_test "set variable x=2" "" " set variable x" | |
406 | ||
407 | # 2 3 4 | |
408 | send_gdb "print x <= y != z\n" | |
409 | gdb_expect { | |
085dd6e6 | 410 | -re ".*$true\r\n$gdb_prompt $" { |
c906108c SS |
411 | pass "print value of x<=y!=z" |
412 | } | |
413 | -re ".*$gdb_prompt $" { fail "print value of x<=y!=z" } | |
414 | timeout { fail "(timeout) print value of x<=y!=z" } | |
415 | } | |
416 | ||
417 | ||
418 | # 2 3 4 | |
419 | send_gdb "print x == y != z\n" | |
420 | gdb_expect { | |
085dd6e6 | 421 | -re ".*$true\r\n$gdb_prompt $" { |
c906108c SS |
422 | pass "print value of x==y!=z" |
423 | } | |
424 | -re ".*$gdb_prompt $" { fail "print value of x==y!=z" } | |
425 | timeout { fail "(timeout) print value of x==y!=z" } | |
426 | } | |
427 | ||
428 | ||
429 | ||
430 | # test use of parenthesis to enforce different order of evaluation | |
431 | ||
432 | ||
433 | gdb_test "set variable z=0" "" " set variable z" | |
434 | ||
435 | # 2 3 0 | |
436 | send_gdb "print x >= (y < z)\n" | |
437 | gdb_expect { | |
085dd6e6 | 438 | -re ".*$true\r\n$gdb_prompt $" { |
c906108c SS |
439 | pass "print value of x>=(y<z)" |
440 | } | |
441 | -re ".*$gdb_prompt $" { fail "print value of x>=(y<z)" } | |
442 | timeout { fail "(timeout) print value of x>=(y<z)" } | |
443 | } | |
444 | ||
445 | ||
446 | # 2 3 0 | |
447 | send_gdb "print x >= (y != z)\n" | |
448 | gdb_expect { | |
085dd6e6 | 449 | -re ".*$true\r\n$gdb_prompt $" { |
c906108c SS |
450 | pass "print value of x>=(y!=z)" |
451 | } | |
452 | -re ".*$gdb_prompt $" { fail "print value of x>=(y*!=z)" } | |
453 | timeout { fail "(timeout) print value of x>=(y!=z)" } | |
454 | } | |
455 | ||
456 | # 2 3 0 | |
457 | send_gdb "print x == (y == z)\n" | |
458 | gdb_expect { | |
085dd6e6 | 459 | -re ".*$false\r\n$gdb_prompt $" { |
c906108c SS |
460 | pass "print value of x==(y==z)" |
461 | } | |
462 | -re ".*$gdb_prompt $" { fail "print value of x==(y==z)" } | |
463 | timeout { fail "(timeout) print value of x==(y==z)" } | |
464 | } | |
465 | ||
466 | ||
467 | gdb_test "set variable x=1" "" " set variable x" | |
468 | gdb_test "set variable z=4" "" " set variable z" | |
469 | ||
470 | # 1 3 4 | |
471 | send_gdb "print (x == y) < z\n" | |
472 | gdb_expect { | |
085dd6e6 | 473 | -re ".*$true\r\n$gdb_prompt $" { |
c906108c SS |
474 | pass "print value of (x==y)<z" |
475 | } | |
476 | -re ".*$gdb_prompt $" { fail "print value of (x==y)<z" } | |
477 | timeout { fail "(timeout) print value of (x==y)<z" } | |
478 | } | |
479 | ||
480 | ||
481 | ||
482 | ||
483 | ||
484 |