Initial creation of sourceware repository
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / relational.exp
CommitLineData
c906108c
SS
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
28if $tracelevel then {
29 strace $tracelevel
30 }
31
32#
33# test running programs
34#
35set prms_id 0
36set bug_id 0
37
38set testfile "int-type"
39set srcfile ${testfile}.c
40set binfile ${objdir}/${subdir}/${testfile}
41if { [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
46gdb_exit
47gdb_start
48gdb_reinitialize_dir $srcdir/$subdir
49gdb_load ${binfile}
50
51
52#
53# set it up at a breakpoint so we can play with the variable values
54#
55
56if ![runto_main] then {
57 perror "couldn't run to breakpoint"
58 continue
59}
60
61#
62# test expressions with "int" types
63#
64
65gdb_test "set variable x=14" "" "set variable x=14"
66gdb_test "set variable y=2" "" "set variable y=2"
67gdb_test "set variable z=2" "" "set variable z=2"
68gdb_test "set variable w=3" "" "set variable w=3"
69
70send_gdb "print x\n"
71gdb_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
80send_gdb "print y\n"
81gdb_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
89send_gdb "print z\n"
90gdb_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
98send_gdb "print w\n"
99gdb_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
109send_gdb "print x < y\n"
110gdb_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
118send_gdb "print x <= y\n"
119gdb_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
127send_gdb "print x > y\n"
128gdb_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
136send_gdb "print x >= y\n"
137gdb_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
145send_gdb "print x == y\n"
146gdb_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
154send_gdb "print x != y\n"
155gdb_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
167gdb_test "set variable x=3" "" "set variable x"
168gdb_test "set variable y=5" "" "set variable y"
169gdb_test "set variable z=2" "" "set variable z"
170
171
172
173send_gdb "print x < y < z\n"
174gdb_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
182send_gdb "print x <= y <= z\n"
183gdb_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
191send_gdb "print x > y > z\n"
192gdb_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
200send_gdb "print x >= y >= z\n"
201gdb_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
209gdb_test "set variable x=2" "" "set variable x"
210gdb_test "set variable y=2" "" "set variable y"
211gdb_test "set variable z=1" "" "set variable z"
212
213
214send_gdb "print x == y == z\n"
215gdb_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
223gdb_test "set variable z=0" "" "set variable z"
224
225
226send_gdb "print x != y != z\n"
227gdb_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
238gdb_test "set variable x=0" "" "set variable x"
239gdb_test "set variable y=2" "" "set variable y"
240gdb_test "set variable z=2" "" "set variable z"
241
242
243send_gdb "print x < y == z\n"
244gdb_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
253send_gdb "print x < y != z\n"
254gdb_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
262gdb_test "set variable x=2" "" "set variable x"
263gdb_test "set variable y=3" "" "set variable y"
264gdb_test "set variable z=1" "" "set variable z"
265
266
267# 2 3 1
268send_gdb "print x < y <= z\n"
269gdb_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
279send_gdb "print x < y >= z\n"
280gdb_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
289gdb_test "set variable z=0" "" " set variable z"
290
291
292# 2 3 0
293send_gdb "print x < y > z\n"
294gdb_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
303gdb_test "set variable x=1" "" " set variable x"
304
305# 1 3 0
306send_gdb "print x > y >= z\n"
307gdb_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
316gdb_test "set variable z=2" "" " set variable z"
317
318# 1 3 2
319send_gdb "print x > y == z\n"
320gdb_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
329gdb_test "set variable x=2" "" " set variable x"
330gdb_test "set variable z=0" "" " set variable z"
331
332# 2 3 0
333send_gdb "print x > y != z\n"
334gdb_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
343gdb_test "set variable x=4" "" "set x to 4"
344
345# 4 3 0
346send_gdb "print x > y <= z\n"
347gdb_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
356send_gdb "print x >= y == z\n"
357gdb_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
366gdb_test "set variable x=2" "" " set variable x"
367
368# 2 3 0
369send_gdb "print x >= y != z\n"
370gdb_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
379gdb_test "set variable x=0" "" " set variable x"
380gdb_test "set variable z=4" "" " set variable z"
381
382# 0 3 4
383send_gdb "print x >= y <= z\n"
384gdb_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
393send_gdb "print x <= y == z\n"
394gdb_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
402gdb_test "set variable x=2" "" " set variable x"
403
404# 2 3 4
405send_gdb "print x <= y != z\n"
406gdb_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
416send_gdb "print x == y != z\n"
417gdb_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
430gdb_test "set variable z=0" "" " set variable z"
431
432# 2 3 0
433send_gdb "print x >= (y < z)\n"
434gdb_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
444send_gdb "print x >= (y != z)\n"
445gdb_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
454send_gdb "print x == (y == z)\n"
455gdb_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
464gdb_test "set variable x=1" "" " set variable x"
465gdb_test "set variable z=4" "" " set variable z"
466
467# 1 3 4
468send_gdb "print (x == y) < z\n"
469gdb_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
This page took 0.045734 seconds and 4 git commands to generate.