2009-02-16 Christophe Lyon <christophe.lyon@st.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.pascal / floats.exp
CommitLineData
0fb0cc75 1# Copyright 2007, 2008, 2009 Free Software Foundation, Inc.
b1c32d35
PM
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
16if $tracelevel then {
17 strace $tracelevel
18}
19
20load_lib "pascal.exp"
21
22set testfile "floats"
23set srcfile ${testfile}.pas
24set binfile ${objdir}/${subdir}/${testfile}$EXEEXT
25
26if {[gdb_compile_pascal "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug ]] != "" } {
27 return -1
28}
29
30gdb_exit
31gdb_start
32gdb_reinitialize_dir $srcdir/$subdir
33gdb_load ${binfile}
34set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
35set bp_location2 [gdb_get_line_number "set breakpoint 2 here"]
36
37if { [gdb_breakpoint ${srcfile}:${bp_location1}] } {
38 pass "setting breakpoint 1"
39}
40if { [gdb_breakpoint ${srcfile}:${bp_location2}] } {
41 pass "setting breakpoint 2"
42}
43
44# Verify that "start" lands inside the right procedure.
45if { [gdb_start_cmd] < 0 } {
46 untested start
47 return -1
48}
49
50gdb_test "" ".* at .*${srcfile}.*" "start"
51
52gdb_test "cont" "Breakpoint .*:${bp_location1}.*" "Going to first breakpoint"
53gdb_test "print r" ".* = 0" "Print r before assigned to 1.25"
54
55gdb_test "next" "r := 1\\.25;" "Next to 'r := 1.25' line"
56gdb_test "next" "s := 2\\.2;" "Next to 's := 2.2' line"
57gdb_test "next" "t := -3\\.2;" "Next to 't := -3.2' line"
58gdb_test "next" "u := 78\\.3;" "Next to 'u := 78.3' line"
59gdb_test "next" "l := 1;" "Next to 'l := 1' line"
60gdb_test "next" "i := 1;" "Next to 'i := 1' line"
61
62# At that point,
63# r should be equal to 1.25
64gdb_test "print r" " = 1\\.25"
65# s should be equal to 2.2
66gdb_test "print s" " = 2\\.(199.*|2|200.*)"
67# t should be equal to -3.2
68gdb_test "print t" " = -3\\.(199.*|2|200.*)"
69# u should be equal to 78.3
70gdb_test "print u" " = 78\\.(3|300.*|299.*)"
71
72# Test addition
73gdb_test "print r + s" " = 3\\.4(499.*|5|500.*)"
74gdb_test "print r + t" " = -1\\.9(499.*|5|500.*)"
75
76#Test addition with float constants
77gdb_test "print r + 1.5" " = 2\\.7(499.*|5|500.*)"
78gdb_test "print r + 0.03" " = 1\\.2(799.*|8|800.*)"
79gdb_test "print r + (-0.2)" " = 1\\.0(499|5|500.*)"
80gdb_test "print r + 1.5E+3" " = 1501\\.2(499.*|5|500.*)"
81gdb_test "print r + 1.5E+2" " = 151\\.2(499.*|5|500.*)"
82gdb_test "print r + 1.5E+1" " = 16\\.2(499|5|500.*)"
83gdb_test "print r + 1.5E+0" " = 2\\.7(499.*|5|500.*)"
84gdb_test "print r + 1.5E-1" " = 1\\.(399.*|4|400.*)"
85gdb_test "print r + 1.5E-2" " = 1\\.26(499.*|5|500.*)"
86gdb_test "print r + 1.5E-3" " = 1\\.251(499.*|5|500.*)"
87
88# Test addition with integer variables
89gdb_test "print r + l" " = 2\\.2(499.*|5|500.*)"
90gdb_test "print l + t" " = -2\\.(199.*|2|200.*)"
91
92# Test addition with integer constants
93gdb_test "print r + 10" " = 11\\.2(499.*|5|500.*)"
94gdb_test "print r + 5" " = 6\\.2(499.*|5|500.*)"
95gdb_test "print r + 1" " = 2\\.2(499.*|5|500.*)"
96gdb_test "print r + 0" " = 1\\.2(499|5|500.*)"
97gdb_test "print r + (-1)" " = 0\\.2(499.*|5|500.*)"
98gdb_test "print r + (-5)" " = -3\\.7(499.*|5|500.*)"
99gdb_test "print r + (-10)" " = -8\\.7(499.*|5|500.*)"
100
101# Test substraction
102gdb_test "print r - s" " = -0\\.9(499.*|5|500.*)"
103gdb_test "print r - t" " = 4\\.4(499.*|5|500.*)"
104
105# Test unany minus
106gdb_test "print -r" " = -1\\.2(499.*|5|500.*)"
107gdb_test "print (-r)" " = -1\\.2(499.*|5|500.*)"
108gdb_test "print -(r)" " = -1.2(499.*|5|500.*)"
109gdb_test "print -(r + s)" " = -3\\.4(499.*|5|500.*)"
110
111# Test multiplication
112gdb_test "print 2 * r" " = 2\\.(499.*|5|500.*)"
113gdb_test "print 2.0 * r" " = 2\\.(499.*|5|500.*)"
114gdb_test "print 1000*r" " = 12(49\\.99.*|50|50\\.00.*)"
115
116#Test division
117gdb_test "print r / 2" " = 0\\.62(499.*|5|500.*)"
118gdb_test "print 35 / 2" " = 17\\.(499.*|5|500.*)"
119
120# 'set r' does not work, as there are set sub-commands starting with 'r'
121# Thus we need to use 'set var r'
122gdb_test "set var r := 2.56" " := 2\\.56"
123gdb_test "print r" " = 2\\.56.*" "Testing new r value"
124
125gdb_test "cont" \
126 "Breakpoint .*:${bp_location2}.*" \
127 "Going to second breakpoint"
128gdb_test "next" "r := cos\\(u\\);" "Advance to 'r := cos(u)' line"
129gdb_test "print u" " = 3\\.14159.*" "Test pi value"
130gdb_test "next" "s := sin\\(u\\);" "Advance to 's := sin(u)' line"
131gdb_test "print r" " = -1" "Test cos(pi) is equal to -1"
132gdb_test "next" "" "Go past 's := sin(u)' line"
133
134set msg "Test sin(pi) is equal to 0"
135
136gdb_test_multiple "print s" $msg {
137 -re ".* = (0|-?\[0-9\]\\.\[0-9\]*\[eE\](-?\[0-9\]*))\[\r\n\]+$gdb_prompt $" {
138 set value "$expect_out(1,string)"
139 verbose "value is $value" 1
140 if [info exists expect_out(2,string)] {
141 set expo $expect_out(2,string)
142 verbose "expo found: $expo" 1
143 } else {
144 set expo "0"
145 regsub ".*\[eE\]" "$value" "" expo;
146 }
147 regsub "^-" "$expo" "" mexpo;
148 verbose "expo is $expo" 1
149 verbose "mexpo is $mexpo" 1
150 if { $value == 0 } {
151 pass $msg
152 } elseif {$mexpo > 8} {
153 pass "$msg '$value' is close to zero"
154 } else {
155 fail "$msg '$value' too large"
156 }
157 verbose "Still here" 1
158 }
159}
This page took 0.12341 seconds and 4 git commands to generate.