gdb/testsuite/
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / arithmet.exp
CommitLineData
0b302171 1# Copyright 1998-1999, 2001, 2007-2012 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
c906108c
SS
25#
26# test running programs
27#
c906108c
SS
28
29set testfile "int-type"
30set srcfile ${testfile}.c
31set binfile ${objdir}/${subdir}/${testfile}
32
fc91c6c2 33if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
b60f0898
JB
34 untested arithmet.exp
35 return -1
c906108c
SS
36 }
37
38gdb_exit
39gdb_start
40gdb_reinitialize_dir $srcdir/$subdir
41gdb_load ${binfile}
42
43
44#
45# set it up at a breakpoint so we can play with the variable values
46#
47
48if ![runto_main] then {
49 perror "couldn't run to breakpoint"
50 continue
51}
52
53#
54# test expressions with "int" types
55#
56
27d3a1a2
MS
57gdb_test_no_output "set variable x=14"
58gdb_test_no_output "set variable y=2"
59gdb_test_no_output "set variable z=2"
60gdb_test_no_output "set variable w=3"
b4127474
MC
61
62gdb_test "print x" "14"
63gdb_test "print y" "2"
64gdb_test "print z" "2"
65gdb_test "print w" "3"
66
67gdb_test "print x+y" "16"
68gdb_test "print x-y" "12"
69gdb_test "print x*y" "28"
70gdb_test "print x/y" "7"
71gdb_test "print x%y" "0"
72
73# x y z w
74# 14 2 2 3
c906108c
SS
75
76# Test associativity of +, -, *, % ,/
77
b4127474
MC
78gdb_test "print x+y+z" "18"
79gdb_test "print x-y-z" "10"
80gdb_test "print x*y*z" "56"
81gdb_test "print x/y/z" "3"
82gdb_test "print x%y%z" "0"
c906108c
SS
83
84# test precedence rules on pairs of arithmetic operators
85
27d3a1a2
MS
86gdb_test_no_output "set variable x=10"
87gdb_test_no_output "set variable y=4"
c906108c 88
b4127474
MC
89# x y z w
90# 10 4 2 3
c906108c 91
b4127474
MC
92gdb_test "print x+y-z" "12"
93gdb_test "print x+y*z" "18"
112f9ab5
MC
94gdb_test "print x+y%w" "11"
95gdb_test "print x+y/w" "11"
b4127474
MC
96gdb_test "print x-y*z" "2"
97gdb_test "print x-y%z" "10"
98gdb_test "print x-y/z" "8"
99gdb_test "print x*y/z" "20"
112f9ab5
MC
100gdb_test "print x*y%w" "1"
101gdb_test "print x/y%w" "2"
c906108c 102
b4127474 103# test use of parentheses to enforce different order of evaluation
c906108c 104
112f9ab5
MC
105gdb_test "print x-(y+w)" "3"
106gdb_test "print x/(y*w)" "0"
107gdb_test "print x-(y/w)" "9"
108gdb_test "print (x+y)*w" "42"
This page took 1.382415 seconds and 4 git commands to generate.