]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/arithmet.exp
Switch the license of all .exp files to GPLv3.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / arithmet.exp
CommitLineData
6aba47ca 1# Copyright 1998, 1999, 2001, 2007 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
SS
15
16# Please email any bugs, comments, and/or additions to this file to:
17# bug-gdb@prep.ai.mit.edu
18
19# This file was written by Elena Zannoni (ezannoni@cygnus.com)
b4127474 20# Rewritten to use gdb_test by Michael Chastain (chastain@redhat.com)
c906108c
SS
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
fc91c6c2 42if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
b60f0898
JB
43 untested arithmet.exp
44 return -1
c906108c
SS
45 }
46
47gdb_exit
48gdb_start
49gdb_reinitialize_dir $srcdir/$subdir
50gdb_load ${binfile}
51
52
53#
54# set it up at a breakpoint so we can play with the variable values
55#
56
57if ![runto_main] then {
58 perror "couldn't run to breakpoint"
59 continue
60}
61
62#
63# test expressions with "int" types
64#
65
b4127474
MC
66gdb_test "set variable x=14" ""
67gdb_test "set variable y=2" ""
68gdb_test "set variable z=2" ""
69gdb_test "set variable w=3" ""
70
71gdb_test "print x" "14"
72gdb_test "print y" "2"
73gdb_test "print z" "2"
74gdb_test "print w" "3"
75
76gdb_test "print x+y" "16"
77gdb_test "print x-y" "12"
78gdb_test "print x*y" "28"
79gdb_test "print x/y" "7"
80gdb_test "print x%y" "0"
81
82# x y z w
83# 14 2 2 3
c906108c
SS
84
85# Test associativity of +, -, *, % ,/
86
b4127474
MC
87gdb_test "print x+y+z" "18"
88gdb_test "print x-y-z" "10"
89gdb_test "print x*y*z" "56"
90gdb_test "print x/y/z" "3"
91gdb_test "print x%y%z" "0"
c906108c
SS
92
93# test precedence rules on pairs of arithmetic operators
94
b4127474
MC
95gdb_test "set variable x=10" ""
96gdb_test "set variable y=4" ""
c906108c 97
b4127474
MC
98# x y z w
99# 10 4 2 3
c906108c 100
b4127474
MC
101gdb_test "print x+y-z" "12"
102gdb_test "print x+y*z" "18"
112f9ab5
MC
103gdb_test "print x+y%w" "11"
104gdb_test "print x+y/w" "11"
b4127474
MC
105gdb_test "print x-y*z" "2"
106gdb_test "print x-y%z" "10"
107gdb_test "print x-y/z" "8"
108gdb_test "print x*y/z" "20"
112f9ab5
MC
109gdb_test "print x*y%w" "1"
110gdb_test "print x/y%w" "2"
c906108c 111
b4127474 112# test use of parentheses to enforce different order of evaluation
c906108c 113
112f9ab5
MC
114gdb_test "print x-(y+w)" "3"
115gdb_test "print x/(y*w)" "0"
116gdb_test "print x-(y/w)" "9"
117gdb_test "print (x+y)*w" "42"