1 # Copyright (C) 1998 Free Software Foundation, Inc.
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.
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.
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.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
20 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
22 # This file is part of the gdb testsuite
24 # tests for correctness of arithmetic operators, associativity and precedence
25 # with integer type variables
33 # test running programs
38 set testfile "int-type"
39 set srcfile ${testfile}.c
40 set binfile ${objdir}/${subdir}/${testfile}
42 if { [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."
48 gdb_reinitialize_dir $srcdir/$subdir
53 # set it up at a breakpoint so we can play with the variable values
56 if ![runto_main] then {
57 perror "couldn't run to breakpoint"
62 # test expressions with "int" types
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"
72 -re ".*14.*$gdb_prompt $" {
73 pass "print value of x"
75 -re ".*$gdb_prompt $" { fail "print value of x" }
76 timeout { fail "(timeout) print value of x" }
82 -re ".*2.*$gdb_prompt $" {
83 pass "print value of y"
85 -re ".*$gdb_prompt $" { fail "print value of y" }
86 timeout { fail "(timeout) print value of y" }
91 -re ".*2.*$gdb_prompt $" {
92 pass "print value of z"
94 -re ".*$gdb_prompt $" { fail "print value of z" }
95 timeout { fail "(timeout) print value of z" }
100 -re ".*3.*$gdb_prompt $" {
101 pass "print value of w"
103 -re ".*$gdb_prompt $" { fail "print value of w" }
104 timeout { fail "(timeout) print value of w" }
109 send_gdb "print x+y\n"
111 -re ".*16.*$gdb_prompt $" {
112 pass "print value of x+y"
114 -re ".*$gdb_prompt $" { fail "print value of x+y" }
115 timeout { fail "(timeout) print value of x+y" }
118 send_gdb "print x-y\n"
120 -re ".*12.*$gdb_prompt $" {
121 pass "print value of x-y"
123 -re ".*$gdb_prompt $" { fail "print value of x-y" }
124 timeout { fail "(timeout) print value of x-y" }
127 send_gdb "print x*y\n"
129 -re ".*28.*$gdb_prompt $" {
130 pass "print value of x*y"
132 -re ".*$gdb_prompt $" { fail "print value of x*y" }
133 timeout { fail "(timeout) print value of x*y" }
136 send_gdb "print x/y\n"
138 -re ".*7.*$gdb_prompt $" {
139 pass "print value of x/y"
141 -re ".*$gdb_prompt $" { fail "print value of x/y" }
142 timeout { fail "(timeout) print value of x/y" }
145 send_gdb "print x%y\n"
147 -re ".*0.*$gdb_prompt $" {
148 pass "print value of x%y"
150 -re ".*$gdb_prompt $" { fail "print value of x%y" }
151 timeout { fail "(timeout) print value of x%y" }
156 # Test associativity of +, -, *, % ,/
159 send_gdb "print x+y+z\n"
161 -re ".*18.*$gdb_prompt $" {
162 pass "print value of x+y"
164 -re ".*$gdb_prompt $" { fail "print value of x+y" }
165 timeout { fail "(timeout) print value of x+y" }
168 send_gdb "print x-y-z\n"
170 -re ".*10.*$gdb_prompt $" {
171 pass "print value of x-y"
173 -re ".*$gdb_prompt $" { fail "print value of x-y" }
174 timeout { fail "(timeout) print value of x-y" }
177 send_gdb "print x*y*z\n"
179 -re ".*56.*$gdb_prompt $" {
180 pass "print value of x*y"
182 -re 8".*$gdb_prompt $" { fail "print value of x*y" }
183 timeout { fail "(timeout) print value of x*y" }
186 send_gdb "print x/y/z\n"
188 -re ".*3.*$gdb_prompt $" {
189 pass "print value of x/y"
191 -re ".*$gdb_prompt $" { fail "print value of x/y" }
192 timeout { fail "(timeout) print value of x/y" }
195 send_gdb "print x%y%z\n"
197 -re ".*0.*$gdb_prompt $" {
198 pass "print value of x%y"
200 -re ".*$gdb_prompt $" { fail "print value of x%y" }
201 timeout { fail "(timeout) print value of x%y" }
205 # test precedence rules on pairs of arithmetic operators
207 gdb_test "set variable x=10" "" "set variable x"
208 gdb_test "set variable y=4" "" "set variable y"
209 gdb_test "set variable z=2" "" "set variable z"
215 send_gdb "print x+y-z\n"
217 -re ".*12.*$gdb_prompt $" {
218 pass "print value of x+y-z"
220 -re ".*$gdb_prompt $" { fail "print value of x+y-z" }
221 timeout { fail "(timeout) print value of x+y-z" }
225 send_gdb "print x+y*z\n"
227 -re ".*18.*$gdb_prompt $" {
228 pass "print value of x+y*z"
230 -re ".*$gdb_prompt $" { fail "print value of x+y*z" }
231 timeout { fail "(timeout) print value of x+y*z" }
235 gdb_test "set variable z=3" "" "set variable z"
239 send_gdb "print x+y%z\n"
241 -re ".*11.*$gdb_prompt $" {
242 pass "print value of x+y%z"
244 -re ".*$gdb_prompt $" { fail "print value of x+y%z" }
245 timeout { fail "(timeout) print value of x+y%z" }
250 send_gdb "print x+y/z\n"
252 -re ".*11.*$gdb_prompt $" {
253 pass "print value of x+y/z"
255 -re ".*$gdb_prompt $" { fail "print value of x+y/z" }
256 timeout { fail "(timeout) print value of x+y/z" }
259 gdb_test "set variable z=2" "" " set variable z"
263 send_gdb "print x-y*z\n"
265 -re ".*2.*$gdb_prompt $" {
266 pass "print value of x-y*z"
268 -re ".*$gdb_prompt $" { fail "print value of x-y*z" }
269 timeout { fail "(timeout) print value of x-y*z" }
273 send_gdb "print x-y%z\n"
275 -re ".*10.*$gdb_prompt $" {
276 pass "print value of x-y%z"
278 -re ".*$gdb_prompt $" { fail "print value of x-y%z" }
279 timeout { fail "(timeout) print value of x-y%z" }
284 send_gdb "print x-y/z\n"
286 -re ".*8.*$gdb_prompt $" {
287 pass "print value of x-y/z"
289 -re ".*$gdb_prompt $" { fail "print value of x-y/z" }
290 timeout { fail "(timeout) print value of x-y/z" }
294 send_gdb "print x*y/z\n"
296 -re ".*20.*$gdb_prompt $" {
297 pass "print value of x*y/z"
299 -re ".*$gdb_prompt $" { fail "print value of x*y/z" }
300 timeout { fail "(timeout) print value of x*y/z" }
303 gdb_test "set variable z=3" "" "set z to 3"
306 send_gdb "print x*y%z\n"
308 -re ".*1.*$gdb_prompt $" {
309 pass "print value of x*y%z"
311 -re ".*$gdb_prompt $" { fail "print value of x*y%z" }
312 timeout { fail "(timeout) print value of x*y%z" }
316 send_gdb "print x/y%z\n"
318 -re ".*2\r\n$gdb_prompt $" {
319 pass "print value of x/y%z"
321 -re ".*$gdb_prompt $" { fail "print value of x/y%z" }
322 timeout { fail "(timeout) print value of x/y%z" }
327 # test use of parenthesis to enforce different order of evaluation
330 send_gdb "print x-(y+z)\n"
332 -re ".*3\r\n$gdb_prompt $" {
333 pass "print value of x-(y+z)"
335 -re ".*$gdb_prompt $" { fail "print value of x-(y+z)" }
336 timeout { fail "(timeout) print value of x-(y+z)" }
341 send_gdb "print x/(y*z)\n"
343 -re ".*0\r\n$gdb_prompt $" {
344 pass "print value of x/(y*z)"
346 -re ".*$gdb_prompt $" { fail "print value of x/(y*z)" }
347 timeout { fail "(timeout) print value of x/(y*z)" }
351 send_gdb "print x-(y/z)\n"
353 -re ".*9\r\n$gdb_prompt $" {
354 pass "print value of x-(y/z)"
356 -re ".*$gdb_prompt $" { fail "print value of x-(y/z)" }
357 timeout { fail "(timeout) print value of x-(y/z)" }
362 send_gdb "print (x+y)*z\n"
364 -re ".*42\r\n$gdb_prompt $" {
365 pass "print value of (x+y)*z"
367 -re ".*$gdb_prompt $" { fail "print value of (x+y)*z" }
368 timeout { fail "(timeout) print value of (x+y)*z" }