1 # Copyright 1998, 1999, 2001, 2007, 2008, 2009, 2010
2 # Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
18 # Rewritten to use gdb_test by Michael Chastain (chastain@redhat.com)
20 # This file is part of the gdb testsuite
22 # tests for correctness of arithmetic operators, associativity and precedence
23 # with integer type variables
31 # test running programs
34 set testfile "int-type"
35 set srcfile ${testfile}.c
36 set binfile ${objdir}/${subdir}/${testfile}
38 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
45 gdb_reinitialize_dir $srcdir/$subdir
50 # set it up at a breakpoint so we can play with the variable values
53 if ![runto_main] then {
54 perror "couldn't run to breakpoint"
59 # test expressions with "int" types
62 gdb_test "set variable x=14" ""
63 gdb_test "set variable y=2" ""
64 gdb_test "set variable z=2" ""
65 gdb_test "set variable w=3" ""
67 gdb_test "print x" "14"
68 gdb_test "print y" "2"
69 gdb_test "print z" "2"
70 gdb_test "print w" "3"
72 gdb_test "print x+y" "16"
73 gdb_test "print x-y" "12"
74 gdb_test "print x*y" "28"
75 gdb_test "print x/y" "7"
76 gdb_test "print x%y" "0"
81 # Test associativity of +, -, *, % ,/
83 gdb_test "print x+y+z" "18"
84 gdb_test "print x-y-z" "10"
85 gdb_test "print x*y*z" "56"
86 gdb_test "print x/y/z" "3"
87 gdb_test "print x%y%z" "0"
89 # test precedence rules on pairs of arithmetic operators
91 gdb_test "set variable x=10" ""
92 gdb_test "set variable y=4" ""
97 gdb_test "print x+y-z" "12"
98 gdb_test "print x+y*z" "18"
99 gdb_test "print x+y%w" "11"
100 gdb_test "print x+y/w" "11"
101 gdb_test "print x-y*z" "2"
102 gdb_test "print x-y%z" "10"
103 gdb_test "print x-y/z" "8"
104 gdb_test "print x*y/z" "20"
105 gdb_test "print x*y%w" "1"
106 gdb_test "print x/y%w" "2"
108 # test use of parentheses to enforce different order of evaluation
110 gdb_test "print x-(y+w)" "3"
111 gdb_test "print x/(y*w)" "0"
112 gdb_test "print x-(y/w)" "9"
113 gdb_test "print (x+y)*w" "42"