]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/arithmet.exp
Simplify ada_lookup_encoded_symbol
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / arithmet.exp
CommitLineData
1d506c26 1# Copyright 1998-2024 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 28
a64d2530 29standard_testfile int-type.c
c906108c 30
5b362f04 31if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug nowarnings}]} {
a64d2530
TT
32 return -1
33}
c906108c
SS
34
35
36#
37# set it up at a breakpoint so we can play with the variable values
38#
39
65a33d75 40if {![runto_main]} {
cdd42066 41 return
c906108c
SS
42}
43
44#
45# test expressions with "int" types
46#
47
27d3a1a2
MS
48gdb_test_no_output "set variable x=14"
49gdb_test_no_output "set variable y=2"
50gdb_test_no_output "set variable z=2"
51gdb_test_no_output "set variable w=3"
b4127474
MC
52
53gdb_test "print x" "14"
54gdb_test "print y" "2"
55gdb_test "print z" "2"
56gdb_test "print w" "3"
57
58gdb_test "print x+y" "16"
59gdb_test "print x-y" "12"
60gdb_test "print x*y" "28"
61gdb_test "print x/y" "7"
62gdb_test "print x%y" "0"
63
64# x y z w
65# 14 2 2 3
c906108c
SS
66
67# Test associativity of +, -, *, % ,/
68
b4127474
MC
69gdb_test "print x+y+z" "18"
70gdb_test "print x-y-z" "10"
71gdb_test "print x*y*z" "56"
72gdb_test "print x/y/z" "3"
73gdb_test "print x%y%z" "0"
c906108c
SS
74
75# test precedence rules on pairs of arithmetic operators
76
27d3a1a2
MS
77gdb_test_no_output "set variable x=10"
78gdb_test_no_output "set variable y=4"
c906108c 79
b4127474
MC
80# x y z w
81# 10 4 2 3
c906108c 82
b4127474
MC
83gdb_test "print x+y-z" "12"
84gdb_test "print x+y*z" "18"
112f9ab5
MC
85gdb_test "print x+y%w" "11"
86gdb_test "print x+y/w" "11"
b4127474
MC
87gdb_test "print x-y*z" "2"
88gdb_test "print x-y%z" "10"
89gdb_test "print x-y/z" "8"
90gdb_test "print x*y/z" "20"
112f9ab5
MC
91gdb_test "print x*y%w" "1"
92gdb_test "print x/y%w" "2"
c906108c 93
b4127474 94# test use of parentheses to enforce different order of evaluation
c906108c 95
112f9ab5
MC
96gdb_test "print x-(y+w)" "3"
97gdb_test "print x/(y*w)" "0"
98gdb_test "print x-(y/w)" "9"
99gdb_test "print (x+y)*w" "42"
5a3cf18c
TV
100
101gdb_test "p /x -(-0x7fffffffffffffff - 1)" " = 0x8000000000000000"