]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/relational.exp
Initial creation of sourceware repository
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / relational.exp
1 # Copyright (C) 1998 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 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}
41 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-w}] != "" } {
42 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
43 }
44
45
46 gdb_exit
47 gdb_start
48 gdb_reinitialize_dir $srcdir/$subdir
49 gdb_load ${binfile}
50
51
52 #
53 # set it up at a breakpoint so we can play with the variable values
54 #
55
56 if ![runto_main] then {
57 perror "couldn't run to breakpoint"
58 continue
59 }
60
61 #
62 # test expressions with "int" types
63 #
64
65 gdb_test "set variable x=14" "" "set variable x=14"
66 gdb_test "set variable y=2" "" "set variable y=2"
67 gdb_test "set variable z=2" "" "set variable z=2"
68 gdb_test "set variable w=3" "" "set variable w=3"
69
70 send_gdb "print x\n"
71 gdb_expect {
72 -re ".*14.*$gdb_prompt $" {
73 pass "print value of x"
74 }
75 -re ".*$gdb_prompt $" { fail "print value of x" }
76 timeout { fail "(timeout) print value of x" }
77 }
78
79
80 send_gdb "print y\n"
81 gdb_expect {
82 -re ".*2.*$gdb_prompt $" {
83 pass "print value of y"
84 }
85 -re ".*$gdb_prompt $" { fail "print value of y" }
86 timeout { fail "(timeout) print value of y" }
87 }
88
89 send_gdb "print z\n"
90 gdb_expect {
91 -re ".*2.*$gdb_prompt $" {
92 pass "print value of z"
93 }
94 -re ".*$gdb_prompt $" { fail "print value of z" }
95 timeout { fail "(timeout) print value of z" }
96 }
97
98 send_gdb "print w\n"
99 gdb_expect {
100 -re ".*3.*$gdb_prompt $" {
101 pass "print value of w"
102 }
103 -re ".*$gdb_prompt $" { fail "print value of w" }
104 timeout { fail "(timeout) print value of w" }
105 }
106
107
108
109 send_gdb "print x < y\n"
110 gdb_expect {
111 -re ".*0.*$gdb_prompt $" {
112 pass "print value of x<y"
113 }
114 -re ".*$gdb_prompt $" { fail "print value of x<y" }
115 timeout { fail "(timeout) print value of x<y" }
116 }
117
118 send_gdb "print x <= y\n"
119 gdb_expect {
120 -re ".*0.*$gdb_prompt $" {
121 pass "print value of x<=y"
122 }
123 -re ".*$gdb_prompt $" { fail "print value of x<=y" }
124 timeout { fail "(timeout) print value of x<=y" }
125 }
126
127 send_gdb "print x > y\n"
128 gdb_expect {
129 -re ".*1.*$gdb_prompt $" {
130 pass "print value of x>y"
131 }
132 -re ".*$gdb_prompt $" { fail "print value of x>y" }
133 timeout { fail "(timeout) print value of x>y" }
134 }
135
136 send_gdb "print x >= y\n"
137 gdb_expect {
138 -re ".*1.*$gdb_prompt $" {
139 pass "print value of x>=y"
140 }
141 -re ".*$gdb_prompt $" { fail "print value of x>=y" }
142 timeout { fail "(timeout) print value of x>=y" }
143 }
144
145 send_gdb "print x == y\n"
146 gdb_expect {
147 -re ".*0.*$gdb_prompt $" {
148 pass "print value of x==y"
149 }
150 -re ".*$gdb_prompt $" { fail "print value of x==y" }
151 timeout { fail "(timeout) print value of x==y" }
152 }
153
154 send_gdb "print x != y\n"
155 gdb_expect {
156 -re ".*1.*$gdb_prompt $" {
157 pass "print value of x!=y"
158 }
159 -re ".*$gdb_prompt $" { fail "print value of x!=y" }
160 timeout { fail "(timeout) print value of x!=y" }
161 }
162
163
164
165 # Test associativity of <, >, <=, >=, ==, !=
166
167 gdb_test "set variable x=3" "" "set variable x"
168 gdb_test "set variable y=5" "" "set variable y"
169 gdb_test "set variable z=2" "" "set variable z"
170
171
172
173 send_gdb "print x < y < z\n"
174 gdb_expect {
175 -re ".*1\r\n$gdb_prompt $" {
176 pass "print value of x<y<z"
177 }
178 -re ".*$gdb_prompt $" { fail "print value of x<y<z" }
179 timeout { fail "(timeout) print value of x<y<z" }
180 }
181
182 send_gdb "print x <= y <= z\n"
183 gdb_expect {
184 -re ".*1\r\n$gdb_prompt $" {
185 pass "print value of x<=y<=z"
186 }
187 -re ".*$gdb_prompt $" { fail "print value of x<=y<=z" }
188 timeout { fail "(timeout) print value of x<=y<=z" }
189 }
190
191 send_gdb "print x > y > z\n"
192 gdb_expect {
193 -re ".*0\r\n$gdb_prompt $" {
194 pass "print value of x>y>z"
195 }
196 -re 8".*$gdb_prompt $" { fail "print value of x>y>z" }
197 timeout { fail "(timeout) print value of x>y>z" }
198 }
199
200 send_gdb "print x >= y >= z\n"
201 gdb_expect {
202 -re ".*0\r\n$gdb_prompt $" {
203 pass "print value of x>=y>=z"
204 }
205 -re ".*$gdb_prompt $" { fail "print value of x>=y>=z" }
206 timeout { fail "(timeout) print value of x>=y>=z" }
207 }
208
209 gdb_test "set variable x=2" "" "set variable x"
210 gdb_test "set variable y=2" "" "set variable y"
211 gdb_test "set variable z=1" "" "set variable z"
212
213
214 send_gdb "print x == y == z\n"
215 gdb_expect {
216 -re ".*1.*$gdb_prompt $" {
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 gdb_test "set variable z=0" "" "set variable z"
224
225
226 send_gdb "print x != y != z\n"
227 gdb_expect {
228 -re ".*0\r\n$gdb_prompt $" {
229 pass "print value of x!=y!=z"
230 }
231 -re ".*$gdb_prompt $" { fail "print value of x!=y!=z" }
232 timeout { fail "(timeout) print value of x!=y!=z" }
233 }
234
235
236 # test precedence rules on pairs of relational operators
237
238 gdb_test "set variable x=0" "" "set variable x"
239 gdb_test "set variable y=2" "" "set variable y"
240 gdb_test "set variable z=2" "" "set variable z"
241
242
243 send_gdb "print x < y == z\n"
244 gdb_expect {
245 -re ".*0.*$gdb_prompt $" {
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 # 0 2 2
253 send_gdb "print x < y != z\n"
254 gdb_expect {
255 -re ".*1.*$gdb_prompt $" {
256 pass "print value of x<y!=z"
257 }
258 -re ".*$gdb_prompt $" { fail "print value of x<y!=z" }
259 timeout { fail "(timeout) print value of x<y!=z" }
260 }
261
262 gdb_test "set variable x=2" "" "set variable x"
263 gdb_test "set variable y=3" "" "set variable y"
264 gdb_test "set variable z=1" "" "set variable z"
265
266
267 # 2 3 1
268 send_gdb "print x < y <= z\n"
269 gdb_expect {
270 -re ".*1.*$gdb_prompt $" {
271 pass "print value of x<y<=z"
272 }
273 -re ".*$gdb_prompt $" { fail "print value of x<y<=z" }
274 timeout { fail "(timeout) print value of x<y<=z" }
275 }
276
277
278 # 2 3 1
279 send_gdb "print x < y >= z\n"
280 gdb_expect {
281 -re ".*1.*$gdb_prompt $" {
282 pass "print value of x<y>=z"
283 }
284 -re ".*$gdb_prompt $" { fail "print value of x<y>=z" }
285 timeout { fail "(timeout) print value of x<y>=z" }
286 }
287
288
289 gdb_test "set variable z=0" "" " set variable z"
290
291
292 # 2 3 0
293 send_gdb "print x < y > z\n"
294 gdb_expect {
295 -re ".*1.*$gdb_prompt $" {
296 pass "print value of x<y>z"
297 }
298 -re ".*$gdb_prompt $" { fail "print value of x<y>z" }
299 timeout { fail "(timeout) print value of x<y>z" }
300 }
301
302
303 gdb_test "set variable x=1" "" " set variable x"
304
305 # 1 3 0
306 send_gdb "print x > y >= z\n"
307 gdb_expect {
308 -re ".*1.*$gdb_prompt $" {
309 pass "print value of x>y>=z"
310 }
311 -re ".*$gdb_prompt $" { fail "print value of x>y>=z" }
312 timeout { fail "(timeout) print value of x>y>=z" }
313 }
314
315
316 gdb_test "set variable z=2" "" " set variable z"
317
318 # 1 3 2
319 send_gdb "print x > y == z\n"
320 gdb_expect {
321 -re ".*0.*$gdb_prompt $" {
322 pass "print value of x>y==z"
323 }
324 -re ".*$gdb_prompt $" { fail "print value of x>y==z" }
325 timeout { fail "(timeout) print value of x>y==z" }
326 }
327
328
329 gdb_test "set variable x=2" "" " set variable x"
330 gdb_test "set variable z=0" "" " set variable z"
331
332 # 2 3 0
333 send_gdb "print x > y != z\n"
334 gdb_expect {
335 -re ".*0.*$gdb_prompt $" {
336 pass "print value of x>y!=z"
337 }
338 -re ".*$gdb_prompt $" { fail "print value of x>y!=z" }
339 timeout { fail "(timeout) print value of x>y!=z" }
340 }
341
342
343 gdb_test "set variable x=4" "" "set x to 4"
344
345 # 4 3 0
346 send_gdb "print x > y <= z\n"
347 gdb_expect {
348 -re ".*0.*$gdb_prompt $" {
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 # 4 3 0
356 send_gdb "print x >= y == z\n"
357 gdb_expect {
358 -re ".*0\r\n$gdb_prompt $" {
359 pass "print value of x>=y==z"
360 }
361 -re ".*$gdb_prompt $" { fail "print value of x>=y==z" }
362 timeout { fail "(timeout) print value of x>=y==z" }
363 }
364
365
366 gdb_test "set variable x=2" "" " set variable x"
367
368 # 2 3 0
369 send_gdb "print x >= y != z\n"
370 gdb_expect {
371 -re ".*0\r\n$gdb_prompt $" {
372 pass "print value of x>=y!=z"
373 }
374 -re ".*$gdb_prompt $" { fail "print value of x>=y!=z" }
375 timeout { fail "(timeout) print value of x>=y!=z" }
376 }
377
378
379 gdb_test "set variable x=0" "" " set variable x"
380 gdb_test "set variable z=4" "" " set variable z"
381
382 # 0 3 4
383 send_gdb "print x >= y <= z\n"
384 gdb_expect {
385 -re ".*1\r\n$gdb_prompt $" {
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 # 0 3 4
393 send_gdb "print x <= y == z\n"
394 gdb_expect {
395 -re ".*0\r\n$gdb_prompt $" {
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 gdb_test "set variable x=2" "" " set variable x"
403
404 # 2 3 4
405 send_gdb "print x <= y != z\n"
406 gdb_expect {
407 -re ".*1\r\n$gdb_prompt $" {
408 pass "print value of x<=y!=z"
409 }
410 -re ".*$gdb_prompt $" { fail "print value of x<=y!=z" }
411 timeout { fail "(timeout) print value of x<=y!=z" }
412 }
413
414
415 # 2 3 4
416 send_gdb "print x == y != z\n"
417 gdb_expect {
418 -re ".*1\r\n$gdb_prompt $" {
419 pass "print value of x==y!=z"
420 }
421 -re ".*$gdb_prompt $" { fail "print value of x==y!=z" }
422 timeout { fail "(timeout) print value of x==y!=z" }
423 }
424
425
426
427 # test use of parenthesis to enforce different order of evaluation
428
429
430 gdb_test "set variable z=0" "" " set variable z"
431
432 # 2 3 0
433 send_gdb "print x >= (y < z)\n"
434 gdb_expect {
435 -re ".*1\r\n$gdb_prompt $" {
436 pass "print value of x>=(y<z)"
437 }
438 -re ".*$gdb_prompt $" { fail "print value of x>=(y<z)" }
439 timeout { fail "(timeout) print value of x>=(y<z)" }
440 }
441
442
443 # 2 3 0
444 send_gdb "print x >= (y != z)\n"
445 gdb_expect {
446 -re ".*1\r\n$gdb_prompt $" {
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 # 2 3 0
454 send_gdb "print x == (y == z)\n"
455 gdb_expect {
456 -re ".*0\r\n$gdb_prompt $" {
457 pass "print value of x==(y==z)"
458 }
459 -re ".*$gdb_prompt $" { fail "print value of x==(y==z)" }
460 timeout { fail "(timeout) print value of x==(y==z)" }
461 }
462
463
464 gdb_test "set variable x=1" "" " set variable x"
465 gdb_test "set variable z=4" "" " set variable z"
466
467 # 1 3 4
468 send_gdb "print (x == y) < z\n"
469 gdb_expect {
470 -re ".*1\r\n$gdb_prompt $" {
471 pass "print value of (x==y)<z"
472 }
473 -re ".*$gdb_prompt $" { fail "print value of (x==y)<z" }
474 timeout { fail "(timeout) print value of (x==y)<z" }
475 }
476
477
478
479
480
481