Commit | Line | Data |
---|---|---|
9b254dd1 | 1 | # Copyright (C) 2007, 2008 Free Software Foundation, Inc. |
93004d61 TJB |
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 Wu Zhou. (woodzltc@cn.ibm.com) | |
17 | ||
18 | # This file is part of the gdb testsuite. It is intended to test that | |
19 | # gdb could correctly handle decimal floating point introduced in IEEE 754R. | |
20 | ||
f6867ce0 TJB |
21 | if $tracelevel then { |
22 | strace $tracelevel | |
23 | } | |
24 | ||
25 | set testfile "dfp-test" | |
26 | set srcfile ${testfile}.c | |
27 | set binfile ${objdir}/${subdir}/${testfile} | |
28 | ||
29 | # Try to compile the test case. If we can't, assume the | |
30 | # toolchain does not yet provide DFP support and bail out. | |
31 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {quiet debug}] != "" } { | |
32 | verbose "Skipping DFP tests." | |
33 | return -1 | |
34 | } | |
35 | ||
36 | gdb_exit | |
37 | gdb_start | |
38 | gdb_reinitialize_dir $srcdir/$subdir | |
39 | gdb_load ${binfile} | |
40 | ||
41 | if ![runto_main] then { | |
42 | perror "couldn't run to breakpoint" | |
43 | continue | |
44 | } | |
45 | ||
46 | # Detect the size of the target's basic types (from gdb.base/long_long.exp). | |
47 | ||
48 | proc get_valueof { fmt exp default } { | |
49 | global gdb_prompt | |
50 | send_gdb "print${fmt} ${exp}\n" | |
51 | gdb_expect { | |
52 | -re "\\$\[0-9\]* = (\[-\]*\[0-9\]*).*$gdb_prompt $" { | |
53 | set val $expect_out(1,string) | |
54 | } | |
55 | timeout { | |
56 | set val ${default} | |
57 | } | |
58 | } | |
59 | return ${val} | |
60 | } | |
61 | ||
62 | proc get_sizeof { type default } { | |
63 | return [get_valueof "/d" "sizeof (${type})" $default] | |
64 | } | |
65 | ||
66 | set sizeof_long [get_sizeof "long" 4] | |
67 | ||
93004d61 TJB |
68 | proc d32_set_tests {} { |
69 | ||
70 | gdb_test "p d32=123.45df" " = 123.45" | |
71 | gdb_test "p d32=12345.df" " = 12345" | |
72 | gdb_test "p d32=12345.67df" " = 12345.67" | |
73 | gdb_test "p d32=1234567.df" " = 1234567" | |
74 | ||
75 | gdb_test "p d32=1.234567E0df" " = 1.234567" | |
76 | gdb_test "p d32=1.234567E10df" " = 1.234567E\\+10" | |
77 | gdb_test "p d32=1.234567E+96df" " = 1.234567E\\+96" | |
78 | ||
79 | # Test that gdb could handle the max, normalized min and subnormalized min. | |
80 | gdb_test "p d32=9.999999E96df" " = 9.999999E\\+96" | |
81 | gdb_test "p d32=1.0E-95df" " = 1.0E\\-95" | |
82 | gdb_test "p d32=1.E-101df" " = 1E\\-101" | |
83 | gdb_test "p d32=0.000001E-95df" " = 1E\\-101" | |
84 | ||
85 | # Test that gdb could detect coefficient/exponent out of range. | |
86 | # The coefficient out of range will be rounded to its nearest value. | |
87 | # And the exponent out of range will be handled as infinity. | |
88 | gdb_test "p d32=1.2345678df" " = 1.234568" "1.2345678 is rounded to 1.234568" | |
89 | gdb_test "p d32=1.0E-101df" " = 1E-101" "1.0E-101 is rounded to 1E-101" | |
90 | gdb_test "p d32=1.234567E+97df" " = Infinity" "1.234567E+97 is Infinity" | |
91 | ||
92 | # Test that gdb could detect the errors in the string representation of _Decimal32 | |
f6867ce0 | 93 | gdb_test "p d32=12345.df" " = 12345" "12345. is a valid number" |
93004d61 | 94 | gdb_test "p d32=12345df" ".*Invalid number.*" "12345 is an invalid number" |
f6867ce0 TJB |
95 | gdb_test "p d32=1.23Edf" ".*Conversion syntax.*" "1.23E is an invalid number" |
96 | gdb_test "p d32=1.23E45Adf" ".*Conversion syntax.*" "1.23E45A is an invalid number" | |
93004d61 TJB |
97 | } |
98 | ||
99 | proc d64_set_tests {} { | |
100 | ||
101 | gdb_test "p d64=123.45dd" " = 123.45" | |
102 | gdb_test "p d64=12345.dd" " = 12345" | |
103 | gdb_test "p d64=12345.67dd" " = 12345.67" | |
104 | gdb_test "p d64=1.234567890123456dd" " = 1.234567890123456" | |
105 | ||
106 | gdb_test "p d64=1.234567890123456E10dd" " = 12345678901.23456" | |
107 | gdb_test "p d64=1.234567890123456E100dd" " = 1.234567890123456E\\+100" | |
108 | gdb_test "p d64=1.234567890123456E384dd" " = 1.234567890123456E\\+384" | |
109 | ||
110 | # Test that gdb could handle the max, normalized min and subnormalized min. | |
111 | gdb_test "p d64=9.999999999999999E384dd" " = 9.999999999999999E\\+384" | |
112 | gdb_test "p d64=1.E-383dd" " = 1E\\-383" | |
113 | gdb_test "p d64=1.E-398dd" " = 1E\\-398" | |
114 | gdb_test "p d64=0.000000000000001E-383dd" " = 1E\\-398" | |
115 | ||
116 | # Test that gdb could detect coefficient/exponent out of range. | |
117 | # The coefficient out of range will be rounded to its nearest value. | |
118 | # And the exponent out of range will be handled as infinity. | |
119 | gdb_test "p d64=1.2345678901234567dd" " = 1.234567890123457" "1.2345678901234567 is rounded to 1.234567890123457" | |
120 | gdb_test "p d64=9.9999999999999999E384dd" " = Infinity" "d64=9.9999999999999999E384 is Infinity" | |
121 | gdb_test "p d64=1.234567890123456E385dd" " = Infinity" "d64=1.234567890123456E385 is Infinity" | |
122 | ||
123 | # Test that gdb could detect the errors in the string representation of _Decimal64 | |
124 | gdb_test "p d64=12345dd" ".*Invalid number.*" "12345dd is an invalid number" | |
f6867ce0 TJB |
125 | gdb_test "p d64=1.23Edd" ".*Conversion syntax.*" "1.23E is an invalid number" |
126 | gdb_test "p d64=1.23E45Add" ".*Conversion syntax.*" "1.23E45A is an invalid number" | |
93004d61 TJB |
127 | } |
128 | ||
129 | proc d128_set_tests {} { | |
130 | ||
131 | gdb_test "p d128=123.45dl" " = 123.45" | |
132 | gdb_test "p d128=12345.dl" " = 12345" | |
133 | gdb_test "p d128=12345.67dl" " = 12345.67" | |
134 | gdb_test "p d128=1.234567890123456789012345678901234dl" " = 1.234567890123456789012345678901234" | |
135 | ||
136 | gdb_test "p d128=1.234567890123456E10dl" " = 12345678901.23456" | |
137 | gdb_test "p d128=1.234567890123456E100dl" " = 1.234567890123456E\\+100" | |
138 | gdb_test "p d128=1.234567890123456E1000dl" " = 1.234567890123456E\\+1000" | |
139 | ||
140 | # Test that gdb could handle the max, normalized min and subnormalized min. | |
141 | gdb_test "p d128=9.999999999999999999999999999999999E6144dl" " = 9.999999999999999999999999999999999E\\+6144" | |
142 | gdb_test "p d128=1.E-6143dl" " = 1E\\-6143" | |
143 | gdb_test "p d128=1.E-6176dl" " = 1E\\-6176" | |
144 | gdb_test "p d128=0.000000000000000000000000000000001E-6143dl" " = 1E\\-6176" | |
145 | ||
146 | # Test that gdb could detect coefficient/exponent out of range. | |
147 | # The coefficient out of range will be rounded to its nearest value. | |
148 | # And the exponent out of range will be handled as infinity. | |
149 | gdb_test "p d128=1.2345678901234567890123456789012345dl" "1.234567890123456789012345678901234" "1.2345678901234567890123456789012345 is rounded to 1.234567890123456789012345678901234" | |
150 | gdb_test "p d128=1.234567890123456E6145dl" "Infinity" "d128=1.234567890123456E6145 is Infinity" | |
151 | ||
152 | # Test that gdb could detect the errors in the string representation of _Decimal128 | |
153 | gdb_test "p d128=12345dl" ".*Invalid number.*" "12345dl is an invalid number" | |
f6867ce0 TJB |
154 | gdb_test "p d128=1.23Edl" ".*Conversion syntax.*" "1.23E is an invalid number" |
155 | gdb_test "p d128=1.23E45Adl" ".*Conversion syntax.*" "1.23E45A is an invalid number" | |
93004d61 TJB |
156 | } |
157 | ||
158 | # Different tests on 32-bits decimal floating point, including the printing | |
159 | # of finite numbers, infinite and NaN, and also the setting of different | |
160 | # decimal value. | |
161 | ||
162 | if [gdb_test "next" \ | |
163 | ".*Positive infd32.*" \ | |
164 | "next after initializing d32"] then { gdb_suppress_tests } | |
165 | gdb_test "print d32" "1.2345" "d32 is initialized to 1.2345" | |
166 | ||
167 | if [gdb_test "next" \ | |
168 | ".*Negative infd32.*" \ | |
169 | "next after assigning builtin infinity to d32"] then { gdb_suppress_tests } | |
170 | gdb_test "print d32" "Infinity" "d32 is positive Infinity" | |
171 | ||
172 | if [gdb_test "next" \ | |
173 | ".*__builtin_nand32.*" \ | |
174 | "next after assigning negative builtin infinity to d32"] then { gdb_suppress_tests } | |
175 | gdb_test "print d32" "-Infinity" "d32 is negative Infinity" | |
176 | ||
177 | if [gdb_test "next" \ | |
178 | ".*d64 = 1.2345.*" \ | |
179 | "next after assigning builtin NaN to d32"] then { gdb_suppress_tests } | |
180 | gdb_test "print d32" "NaN" "d32 is NaN" | |
181 | ||
182 | d32_set_tests | |
183 | ||
184 | ||
185 | # Different tests on 64-bits decimal floating point, including the display | |
186 | # of finite number, infinite and NaN, and also the setting of different | |
187 | # decimal value. | |
188 | ||
189 | if [gdb_test "next" \ | |
190 | ".*Positive infd64.*" \ | |
191 | "next after initializing d64"] then { gdb_suppress_tests } | |
192 | gdb_test "print d64" "1.2345" "d64 is initialized to 1.2345" | |
193 | ||
194 | if [gdb_test "next" \ | |
195 | ".*Negative infd64.*" \ | |
196 | "next after assigning builtin infinity to d64"] then { gdb_suppress_tests } | |
197 | gdb_test "print d64" "Infinity" "d64 is positive Infinity" | |
198 | ||
199 | if [gdb_test "next" \ | |
200 | ".*__builtin_nand64.*" \ | |
201 | "next after assigning negative builtin infinity to d64"] then { gdb_suppress_tests } | |
202 | gdb_test "print d64" "-Infinity" "d64 is negative Infinity" | |
203 | ||
204 | if [gdb_test "next" \ | |
205 | ".*d128 = 1.2345.*" \ | |
206 | "next after assigning builtin NaN to d64"] then { gdb_suppress_tests } | |
207 | gdb_test "print d64" "NaN" "d64 is NaN" | |
208 | ||
209 | d64_set_tests | |
210 | ||
211 | ||
212 | # Different tests on 128-bits decimal floating point, including the display | |
213 | # of finite number, infinite and NaN, and also the setting of different | |
214 | # decimal value. | |
215 | ||
216 | if [gdb_test "next" \ | |
217 | ".*Positive infd128.*" \ | |
218 | "next after initializing d128"] then { gdb_suppress_tests } | |
219 | gdb_test "print d128" "1.2345" "d128 is initialized to 1.2345" | |
220 | ||
221 | d128_set_tests | |
222 | ||
223 | if [gdb_test "next" \ | |
224 | ".*Negative infd128.*" \ | |
225 | "next after assigning builtin infinity to d128"] then { gdb_suppress_tests } | |
226 | gdb_test "print d128" "Infinity" "d128 is positive Infinity" | |
227 | ||
228 | if [gdb_test "next" \ | |
229 | ".*__builtin_nand128.*" \ | |
230 | "next after assigning negative builtin infinity to d128"] then { gdb_suppress_tests } | |
231 | gdb_test "print d128" "-Infinity" "d128 is negative Infinity" | |
232 | ||
233 | if [gdb_test "next" \ | |
234 | ".*arg0_32.*" \ | |
235 | "next after assigning builtin NaN to d128"] then { gdb_suppress_tests } | |
236 | gdb_test "print d128" "NaN" "d128 is NaN" | |
237 | ||
238 | # The following tests are intended to verify that gdb can correctly handle | |
239 | # DFP types in function arguments. | |
240 | ||
241 | gdb_breakpoint arg0_32 | |
242 | gdb_continue_to_breakpoint "entry to arg0_32" | |
243 | gdb_test "backtrace" ".*arg0_32 \\(arg0=0.1, arg1=1.0, arg2=2.0, arg3=3.0, arg4=4.0, arg5=5.0\\).*" "backtrace at arg0_32" | |
244 | ||
245 | gdb_breakpoint arg0_64 | |
246 | gdb_continue_to_breakpoint "entry to arg0_64" | |
247 | gdb_test "backtrace" ".*arg0_64 \\(arg0=0.1, arg1=1.0, arg2=2.0, arg3=3.0, arg4=4.0, arg5=5.0\\).*" "backtrace at arg0_64" | |
248 | ||
249 | gdb_breakpoint arg0_128 | |
250 | gdb_continue_to_breakpoint "entry to arg0_128" | |
251 | gdb_test "backtrace" ".*arg0_128 \\(arg0=0.1, arg1=1.0, arg2=2.0, arg3=3.0, arg4=4.0, arg5=5.0\\).*" "backtrace at arg0_128" | |
252 | ||
253 | # The following tests are intended to verify that gdb can handle DFP types | |
254 | # correctly in struct. | |
255 | ||
256 | gdb_breakpoint [gdb_get_line_number "Exit point"] | |
257 | gdb_continue_to_breakpoint "Setting a decimal struct" | |
258 | gdb_test "print ds.dec32" " = 1.2345" | |
259 | gdb_test "print ds.dec64" " = 1.2345" | |
260 | gdb_test "print ds.dec128" " = 1.2345" | |
261 | ||
f6867ce0 TJB |
262 | # Test expressions with DFP variables. |
263 | ||
264 | gdb_test "print d32 + ds.dec32" " = 1.3345" | |
265 | gdb_test "print d64 + ds.dec64" " = 1.3345" | |
266 | gdb_test "print d128 + ds.dec128" " = 1.3345" | |
267 | ||
268 | # Test conversion between different _Decimal sizes. | |
269 | ||
270 | gdb_test "ptype d64 + ds.dec32" " = volatile _Decimal64" | |
271 | gdb_test "ptype d128 + ds.dec32" " = volatile _Decimal128" | |
272 | gdb_test "ptype d128 + ds.dec64" " = volatile _Decimal128" | |
273 | ||
274 | # Mixture of Decimal and integral operands | |
275 | gdb_test "p d32 + 1" " = 1.1" | |
276 | gdb_test "p 2 + d64" " = 2.1" | |
277 | gdb_test "p ds.int4 + d128" " = 1.1" | |
278 | gdb_test "ptype d32 + 1" " = volatile _Decimal32" | |
279 | gdb_test "ptype ds.int4 + d128" " = volatile _Decimal128" | |
280 | ||
281 | # Test other operations with DFP operands | |
282 | gdb_test "p !d32" " = 0" | |
283 | gdb_test "p !d64" " = 0" | |
284 | gdb_test "p !d128" " = 0" | |
285 | gdb_test "p +d32" " = 0.1" | |
286 | gdb_test "p +d64" " = 0.1" | |
287 | gdb_test "p +d128" " = 0.1" | |
288 | gdb_test "p d64 == d128" " = 1" | |
289 | gdb_test "p d128 == ds.dec32" " = 0" | |
290 | gdb_test "p d128 == d32" " = 1" | |
291 | gdb_test "p ds.dec32 == ds.dec64" " = 1" | |
292 | gdb_test "p d32 < ds.dec32" " = 1" | |
293 | gdb_test "p d64 < ds.dec64" " = 1" | |
294 | gdb_test "p d128 < ds.dec128" " = 1" | |
295 | gdb_test "p ds.dec32 < d32" " = 0" | |
296 | gdb_test "p d64 > ds.dec64" " = 0" | |
297 | gdb_test "p ds.dec128 > d128 " " = 1" | |
298 | gdb_test "p d32 < ds.int4" " = 1" | |
299 | gdb_test "p ds.int4 > d32" " = 1" | |
300 | gdb_test "p ds.dec32 < ds.int4" " = 0" | |
301 | gdb_test "p ds.int4 > ds.dec64" " = 0" | |
302 | gdb_test "p ds.dec128 > ds.int4" " = 1" | |
303 | ||
304 | # Reject operation with integral larger than 32-bits | |
305 | if { ${sizeof_long} > 4 } { | |
306 | gdb_test "p d32 + ds.long8" "Conversion of large integer to a decimal floating type is not supported." | |
307 | } | |
308 | ||
309 | # Reject operation with DFP and Binary FP | |
310 | gdb_test "p d64 + ds.float4" "Mixing decimal floating types with other floating types is not allowed." | |
311 | gdb_test "p ds.double8 + d128" "Mixing decimal floating types with other floating types is not allowed." | |
312 | ||
93004d61 TJB |
313 | # The following tests are intended to verify that gdb can handle "d1=d2" |
314 | # and "d1=-d2" correctly. | |
315 | ||
316 | gdb_test "print ds.dec32=d32" " = 0.1" | |
317 | gdb_test "print ds.dec64=d64" " = 0.1" | |
318 | gdb_test "print ds.dec128=d128" " = 0.1" | |
319 | gdb_test "print ds.dec32 = -d32" " = -0.1" | |
320 | gdb_test "print ds.dec64 = -d64" " = -0.1" | |
321 | gdb_test "print ds.dec128 = -d128" " = -0.1" | |
f6867ce0 TJB |
322 | |
323 | # Test cast to and from DFP values | |
324 | ||
325 | gdb_test "print ds.double8 = ds.dec64" " = -0.(0999.*|1000.*)" | |
326 | gdb_test "print ds.dec64 = ds.float4" " = 3.(0999.*|1000.*)" | |
327 | gdb_test "print ds.dec128 = -ds.double8" " = 0.(0999.*|1000.*)" | |
328 | gdb_test "print ds.dec128 = ds.dec32" " = -0.1" | |
329 | gdb_test "print ds.dec32 = ds.int4" " = 1" | |
330 | gdb_test "print ds.int4 = 7.3dl" " = 7" |