1 # Copyright 1998, 1999, 2001, 2007, 2008 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 3 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, see <http://www.gnu.org/licenses/>.
16 # Please email any bugs, comments, and/or additions to this file to:
17 # bug-gdb@prep.ai.mit.edu
19 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
20 # Rewritten to use gdb_test by Michael Chastain (chastain@redhat.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 nowarnings}] != "" } {
49 gdb_reinitialize_dir $srcdir/$subdir
54 # set it up at a breakpoint so we can play with the variable values
57 if ![runto_main] then {
58 perror "couldn't run to breakpoint"
63 # test expressions with "int" types
66 gdb_test "set variable x=14" ""
67 gdb_test "set variable y=2" ""
68 gdb_test "set variable z=2" ""
69 gdb_test "set variable w=3" ""
71 gdb_test "print x" "14"
72 gdb_test "print y" "2"
73 gdb_test "print z" "2"
74 gdb_test "print w" "3"
76 gdb_test "print x+y" "16"
77 gdb_test "print x-y" "12"
78 gdb_test "print x*y" "28"
79 gdb_test "print x/y" "7"
80 gdb_test "print x%y" "0"
85 # Test associativity of +, -, *, % ,/
87 gdb_test "print x+y+z" "18"
88 gdb_test "print x-y-z" "10"
89 gdb_test "print x*y*z" "56"
90 gdb_test "print x/y/z" "3"
91 gdb_test "print x%y%z" "0"
93 # test precedence rules on pairs of arithmetic operators
95 gdb_test "set variable x=10" ""
96 gdb_test "set variable y=4" ""
101 gdb_test "print x+y-z" "12"
102 gdb_test "print x+y*z" "18"
103 gdb_test "print x+y%w" "11"
104 gdb_test "print x+y/w" "11"
105 gdb_test "print x-y*z" "2"
106 gdb_test "print x-y%z" "10"
107 gdb_test "print x-y/z" "8"
108 gdb_test "print x*y/z" "20"
109 gdb_test "print x*y%w" "1"
110 gdb_test "print x/y%w" "2"
112 # test use of parentheses to enforce different order of evaluation
114 gdb_test "print x-(y+w)" "3"
115 gdb_test "print x/(y*w)" "0"
116 gdb_test "print x-(y/w)" "9"
117 gdb_test "print (x+y)*w" "42"