This commit was generated by cvs2svn to track changes on a CVS vendor
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / arithmet.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 correctness of arithmetic 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}
41
42if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-w}] != "" } {
43 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
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 ".*16.*$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 ".*12.*$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 ".*28.*$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 ".*7.*$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
154
155
156# Test associativity of +, -, *, % ,/
157
158
159send_gdb "print x+y+z\n"
160gdb_expect {
161 -re ".*18.*$gdb_prompt $" {
162 pass "print value of x+y"
163 }
164 -re ".*$gdb_prompt $" { fail "print value of x+y" }
165 timeout { fail "(timeout) print value of x+y" }
166 }
167
168send_gdb "print x-y-z\n"
169gdb_expect {
170 -re ".*10.*$gdb_prompt $" {
171 pass "print value of x-y"
172 }
173 -re ".*$gdb_prompt $" { fail "print value of x-y" }
174 timeout { fail "(timeout) print value of x-y" }
175 }
176
177send_gdb "print x*y*z\n"
178gdb_expect {
179 -re ".*56.*$gdb_prompt $" {
180 pass "print value of x*y"
181 }
182 -re 8".*$gdb_prompt $" { fail "print value of x*y" }
183 timeout { fail "(timeout) print value of x*y" }
184 }
185
186send_gdb "print x/y/z\n"
187gdb_expect {
188 -re ".*3.*$gdb_prompt $" {
189 pass "print value of x/y"
190 }
191 -re ".*$gdb_prompt $" { fail "print value of x/y" }
192 timeout { fail "(timeout) print value of x/y" }
193 }
194
195send_gdb "print x%y%z\n"
196gdb_expect {
197 -re ".*0.*$gdb_prompt $" {
198 pass "print value of x%y"
199 }
200 -re ".*$gdb_prompt $" { fail "print value of x%y" }
201 timeout { fail "(timeout) print value of x%y" }
202 }
203
204
205# test precedence rules on pairs of arithmetic operators
206
207gdb_test "set variable x=10" "" "set variable x"
208gdb_test "set variable y=4" "" "set variable y"
209gdb_test "set variable z=2" "" "set variable z"
210
211
212
213# x y z
214# 10 4 2
215send_gdb "print x+y-z\n"
216gdb_expect {
217 -re ".*12.*$gdb_prompt $" {
218 pass "print value of x+y-z"
219 }
220 -re ".*$gdb_prompt $" { fail "print value of x+y-z" }
221 timeout { fail "(timeout) print value of x+y-z" }
222 }
223
224# 10 4 2
225send_gdb "print x+y*z\n"
226gdb_expect {
227 -re ".*18.*$gdb_prompt $" {
228 pass "print value of x+y*z"
229 }
230 -re ".*$gdb_prompt $" { fail "print value of x+y*z" }
231 timeout { fail "(timeout) print value of x+y*z" }
232 }
233
234
235gdb_test "set variable z=3" "" "set variable z"
236
237
238# 10 4 3
239send_gdb "print x+y%z\n"
240gdb_expect {
241 -re ".*11.*$gdb_prompt $" {
242 pass "print value of x+y%z"
243 }
244 -re ".*$gdb_prompt $" { fail "print value of x+y%z" }
245 timeout { fail "(timeout) print value of x+y%z" }
246 }
247
248
249# 10 4 3
250send_gdb "print x+y/z\n"
251gdb_expect {
252 -re ".*11.*$gdb_prompt $" {
253 pass "print value of x+y/z"
254 }
255 -re ".*$gdb_prompt $" { fail "print value of x+y/z" }
256 timeout { fail "(timeout) print value of x+y/z" }
257 }
258
259gdb_test "set variable z=2" "" " set variable z"
260
261
262# 10 4 2
263send_gdb "print x-y*z\n"
264gdb_expect {
265 -re ".*2.*$gdb_prompt $" {
266 pass "print value of x-y*z"
267 }
268 -re ".*$gdb_prompt $" { fail "print value of x-y*z" }
269 timeout { fail "(timeout) print value of x-y*z" }
270 }
271
272# 10 4 2
273send_gdb "print x-y%z\n"
274gdb_expect {
275 -re ".*10.*$gdb_prompt $" {
276 pass "print value of x-y%z"
277 }
278 -re ".*$gdb_prompt $" { fail "print value of x-y%z" }
279 timeout { fail "(timeout) print value of x-y%z" }
280 }
281
282
283# 10 4 2
284send_gdb "print x-y/z\n"
285gdb_expect {
286 -re ".*8.*$gdb_prompt $" {
287 pass "print value of x-y/z"
288 }
289 -re ".*$gdb_prompt $" { fail "print value of x-y/z" }
290 timeout { fail "(timeout) print value of x-y/z" }
291 }
292
293# 10 4 2
294send_gdb "print x*y/z\n"
295gdb_expect {
296 -re ".*20.*$gdb_prompt $" {
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
303gdb_test "set variable z=3" "" "set z to 3"
304
305# 10 4 3
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# 10 4 3
316send_gdb "print x/y%z\n"
317gdb_expect {
318 -re ".*2\r\n$gdb_prompt $" {
319 pass "print value of x/y%z"
320 }
321 -re ".*$gdb_prompt $" { fail "print value of x/y%z" }
322 timeout { fail "(timeout) print value of x/y%z" }
323 }
324
325
326
327# test use of parenthesis to enforce different order of evaluation
328
329# 10 4 3
330send_gdb "print x-(y+z)\n"
331gdb_expect {
332 -re ".*3\r\n$gdb_prompt $" {
333 pass "print value of x-(y+z)"
334 }
335 -re ".*$gdb_prompt $" { fail "print value of x-(y+z)" }
336 timeout { fail "(timeout) print value of x-(y+z)" }
337 }
338
339
340# 10 4 3
341send_gdb "print x/(y*z)\n"
342gdb_expect {
343 -re ".*0\r\n$gdb_prompt $" {
344 pass "print value of x/(y*z)"
345 }
346 -re ".*$gdb_prompt $" { fail "print value of x/(y*z)" }
347 timeout { fail "(timeout) print value of x/(y*z)" }
348 }
349
350# 10 4 3
351send_gdb "print x-(y/z)\n"
352gdb_expect {
353 -re ".*9\r\n$gdb_prompt $" {
354 pass "print value of x-(y/z)"
355 }
356 -re ".*$gdb_prompt $" { fail "print value of x-(y/z)" }
357 timeout { fail "(timeout) print value of x-(y/z)" }
358 }
359
360
361# 10 4 3
362send_gdb "print (x+y)*z\n"
363gdb_expect {
364 -re ".*42\r\n$gdb_prompt $" {
365 pass "print value of (x+y)*z"
366 }
367 -re ".*$gdb_prompt $" { fail "print value of (x+y)*z" }
368 timeout { fail "(timeout) print value of (x+y)*z" }
369 }
370
371
372
373
374
375
This page took 0.03688 seconds and 4 git commands to generate.