gdb/testsuite/
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / arithmet.exp
CommitLineData
0fb0cc75 1# Copyright 1998, 1999, 2001, 2007, 2008, 2009 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
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
c906108c 6# (at your option) any later version.
e22f8b7c 7#
c906108c
SS
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.
e22f8b7c 12#
c906108c 13# You should have received a copy of the GNU General Public License
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 15
c906108c 16# This file was written by Elena Zannoni (ezannoni@cygnus.com)
b4127474 17# Rewritten to use gdb_test by Michael Chastain (chastain@redhat.com)
c906108c
SS
18
19# This file is part of the gdb testsuite
20#
21# tests for correctness of arithmetic operators, associativity and precedence
22# with integer type variables
23#
24
25if $tracelevel then {
26 strace $tracelevel
27 }
28
29#
30# test running programs
31#
32set prms_id 0
33set bug_id 0
34
35set testfile "int-type"
36set srcfile ${testfile}.c
37set binfile ${objdir}/${subdir}/${testfile}
38
fc91c6c2 39if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
b60f0898
JB
40 untested arithmet.exp
41 return -1
c906108c
SS
42 }
43
44gdb_exit
45gdb_start
46gdb_reinitialize_dir $srcdir/$subdir
47gdb_load ${binfile}
48
49
50#
51# set it up at a breakpoint so we can play with the variable values
52#
53
54if ![runto_main] then {
55 perror "couldn't run to breakpoint"
56 continue
57}
58
59#
60# test expressions with "int" types
61#
62
b4127474
MC
63gdb_test "set variable x=14" ""
64gdb_test "set variable y=2" ""
65gdb_test "set variable z=2" ""
66gdb_test "set variable w=3" ""
67
68gdb_test "print x" "14"
69gdb_test "print y" "2"
70gdb_test "print z" "2"
71gdb_test "print w" "3"
72
73gdb_test "print x+y" "16"
74gdb_test "print x-y" "12"
75gdb_test "print x*y" "28"
76gdb_test "print x/y" "7"
77gdb_test "print x%y" "0"
78
79# x y z w
80# 14 2 2 3
c906108c
SS
81
82# Test associativity of +, -, *, % ,/
83
b4127474
MC
84gdb_test "print x+y+z" "18"
85gdb_test "print x-y-z" "10"
86gdb_test "print x*y*z" "56"
87gdb_test "print x/y/z" "3"
88gdb_test "print x%y%z" "0"
c906108c
SS
89
90# test precedence rules on pairs of arithmetic operators
91
b4127474
MC
92gdb_test "set variable x=10" ""
93gdb_test "set variable y=4" ""
c906108c 94
b4127474
MC
95# x y z w
96# 10 4 2 3
c906108c 97
b4127474
MC
98gdb_test "print x+y-z" "12"
99gdb_test "print x+y*z" "18"
112f9ab5
MC
100gdb_test "print x+y%w" "11"
101gdb_test "print x+y/w" "11"
b4127474
MC
102gdb_test "print x-y*z" "2"
103gdb_test "print x-y%z" "10"
104gdb_test "print x-y/z" "8"
105gdb_test "print x*y/z" "20"
112f9ab5
MC
106gdb_test "print x*y%w" "1"
107gdb_test "print x/y%w" "2"
c906108c 108
b4127474 109# test use of parentheses to enforce different order of evaluation
c906108c 110
112f9ab5
MC
111gdb_test "print x-(y+w)" "3"
112gdb_test "print x/(y*w)" "0"
113gdb_test "print x-(y/w)" "9"
114gdb_test "print (x+y)*w" "42"
This page took 0.996459 seconds and 4 git commands to generate.