1# Copyright 1998-2016 Free Software Foundation, Inc. 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 5# the Free Software Foundation; either version 3 of the License, or 6# (at your option) any later version. 7# 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. 12# 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/>. 15 16# This file was written by Elena Zannoni (ezannoni@cygnus.com) 17# Rewritten to use gdb_test by Michael Chastain (chastain@redhat.com) 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 25# 26# test running programs 27# 28 29standard_testfile int-type.c 30 31if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug nowarnings}]} { 32 untested $testfile.exp 33 return -1 34} 35 36 37# 38# set it up at a breakpoint so we can play with the variable values 39# 40 41if ![runto_main] then { 42 perror "couldn't run to breakpoint" 43 continue 44} 45 46# 47# test expressions with "int" types 48# 49 50gdb_test_no_output "set variable x=14" 51gdb_test_no_output "set variable y=2" 52gdb_test_no_output "set variable z=2" 53gdb_test_no_output "set variable w=3" 54 55gdb_test "print x" "14" 56gdb_test "print y" "2" 57gdb_test "print z" "2" 58gdb_test "print w" "3" 59 60gdb_test "print x+y" "16" 61gdb_test "print x-y" "12" 62gdb_test "print x*y" "28" 63gdb_test "print x/y" "7" 64gdb_test "print x%y" "0" 65 66# x y z w 67# 14 2 2 3 68 69# Test associativity of +, -, *, % ,/ 70 71gdb_test "print x+y+z" "18" 72gdb_test "print x-y-z" "10" 73gdb_test "print x*y*z" "56" 74gdb_test "print x/y/z" "3" 75gdb_test "print x%y%z" "0" 76 77# test precedence rules on pairs of arithmetic operators 78 79gdb_test_no_output "set variable x=10" 80gdb_test_no_output "set variable y=4" 81 82# x y z w 83# 10 4 2 3 84 85gdb_test "print x+y-z" "12" 86gdb_test "print x+y*z" "18" 87gdb_test "print x+y%w" "11" 88gdb_test "print x+y/w" "11" 89gdb_test "print x-y*z" "2" 90gdb_test "print x-y%z" "10" 91gdb_test "print x-y/z" "8" 92gdb_test "print x*y/z" "20" 93gdb_test "print x*y%w" "1" 94gdb_test "print x/y%w" "2" 95 96# test use of parentheses to enforce different order of evaluation 97 98gdb_test "print x-(y+w)" "3" 99gdb_test "print x/(y*w)" "0" 100gdb_test "print x-(y/w)" "9" 101gdb_test "print (x+y)*w" "42" 102