gdb: testsuite: print explicit test result for gdb.base/dfp-test.exp
[binutils-gdb.git] / gdb / testsuite / gdb.base / dfp-test.exp
1 # Copyright (C) 2007-2022 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 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
21 standard_testfile .c
22
23 # Try to compile the test case. If we can't, assume the
24 # toolchain does not yet provide DFP support and bail out.
25 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {quiet debug}] != "" } {
26 unsupported "decimal floating point not supported for this target."
27 verbose "Skipping DFP tests."
28 return -1
29 }
30
31 clean_restart ${binfile}
32
33 if ![runto_main] then {
34 perror "couldn't run to breakpoint"
35 continue
36 }
37
38 set sizeof_long [get_sizeof "long" 4]
39
40 proc_with_prefix d32_set_tests {} {
41
42 gdb_test "p d32=123.45df" " = 123.45"
43 gdb_test "p d32=12345.df" " = 12345"
44 gdb_test "p d32=12345.67df" " = 12345.67"
45 gdb_test "p d32=1234567.df" " = 1234567"
46
47 gdb_test "p d32=1.234567E0df" " = 1.234567"
48 gdb_test "p d32=1.234567E10df" " = 1.234567E\\+10"
49 gdb_test "p d32=1.234567E+96df" " = 1.234567E\\+96"
50
51 # Test that gdb could handle the max, normalized min and subnormalized min.
52 gdb_test "p d32=9.999999E96df" " = 9.999999E\\+96"
53 gdb_test "p d32=1.0E-95df" " = 1.0E\\-95"
54 gdb_test "p d32=1.E-101df" " = 1E\\-101"
55 gdb_test "p d32=0.000001E-95df" " = 1E\\-101"
56
57 # Test that gdb could detect coefficient/exponent out of range.
58 # The coefficient out of range will be rounded to its nearest value.
59 # And the exponent out of range will be handled as infinity.
60 gdb_test "p d32=1.2345678df" " = 1.234568" "1.2345678 is rounded to 1.234568"
61 gdb_test "p d32=1.0E-101df" " = 1E-101" "1.0E-101 is rounded to 1E-101"
62 gdb_test "p d32=1.234567E+97df" " = Infinity" "1.234567E+97 is Infinity"
63
64 # Test that gdb could detect the errors in the string representation of _Decimal32
65 gdb_test "p d32=12345.df" " = 12345" "12345. is a valid number"
66 gdb_test "p d32=12345df" ".*Invalid number.*" "12345 is an invalid number"
67 gdb_test "p d32=1.23Edf" ".*Conversion syntax.*" "1.23E is an invalid number"
68 gdb_test "p d32=1.23E45Adf" ".*Conversion syntax.*" "1.23E45A is an invalid number"
69 }
70
71 proc_with_prefix d64_set_tests {} {
72
73 gdb_test "p d64=123.45dd" " = 123.45"
74 gdb_test "p d64=12345.dd" " = 12345"
75 gdb_test "p d64=12345.67dd" " = 12345.67"
76 gdb_test "p d64=1.234567890123456dd" " = 1.234567890123456"
77
78 gdb_test "p d64=1.234567890123456E10dd" " = 12345678901.23456"
79 gdb_test "p d64=1.234567890123456E100dd" " = 1.234567890123456E\\+100"
80 gdb_test "p d64=1.234567890123456E384dd" " = 1.234567890123456E\\+384"
81
82 # Test that gdb could handle the max, normalized min and subnormalized min.
83 gdb_test "p d64=9.999999999999999E384dd" " = 9.999999999999999E\\+384"
84 gdb_test "p d64=1.E-383dd" " = 1E\\-383"
85 gdb_test "p d64=1.E-398dd" " = 1E\\-398"
86 gdb_test "p d64=0.000000000000001E-383dd" " = 1E\\-398"
87
88 # Test that gdb could detect coefficient/exponent out of range.
89 # The coefficient out of range will be rounded to its nearest value.
90 # And the exponent out of range will be handled as infinity.
91 gdb_test "p d64=1.2345678901234567dd" " = 1.234567890123457" "1.2345678901234567 is rounded to 1.234567890123457"
92 gdb_test "p d64=9.9999999999999999E384dd" " = Infinity" "d64=9.9999999999999999E384 is Infinity"
93 gdb_test "p d64=1.234567890123456E385dd" " = Infinity" "d64=1.234567890123456E385 is Infinity"
94
95 # Test that gdb could detect the errors in the string representation of _Decimal64
96 gdb_test "p d64=12345dd" ".*Invalid number.*" "12345dd is an invalid number"
97 gdb_test "p d64=1.23Edd" ".*Conversion syntax.*" "1.23E is an invalid number"
98 gdb_test "p d64=1.23E45Add" ".*Conversion syntax.*" "1.23E45A is an invalid number"
99 }
100
101 proc_with_prefix d128_set_tests {} {
102
103 gdb_test "p d128=123.45dl" " = 123.45"
104 gdb_test "p d128=12345.dl" " = 12345"
105 gdb_test "p d128=12345.67dl" " = 12345.67"
106 gdb_test "p d128=1.234567890123456789012345678901234dl" " = 1.234567890123456789012345678901234"
107
108 gdb_test "p d128=1.234567890123456E10dl" " = 12345678901.23456"
109 gdb_test "p d128=1.234567890123456E100dl" " = 1.234567890123456E\\+100"
110 gdb_test "p d128=1.234567890123456E1000dl" " = 1.234567890123456E\\+1000"
111
112 # Test that gdb could handle the max, normalized min and subnormalized min.
113 gdb_test "p d128=9.999999999999999999999999999999999E6144dl" " = 9.999999999999999999999999999999999E\\+6144"
114 gdb_test "p d128=1.E-6143dl" " = 1E\\-6143"
115 gdb_test "p d128=1.E-6176dl" " = 1E\\-6176"
116 gdb_test "p d128=0.000000000000000000000000000000001E-6143dl" " = 1E\\-6176"
117
118 # Test that gdb could detect coefficient/exponent out of range.
119 # The coefficient out of range will be rounded to its nearest value.
120 # And the exponent out of range will be handled as infinity.
121 gdb_test "p d128=1.2345678901234567890123456789012345dl" "1.234567890123456789012345678901234" "1.2345678901234567890123456789012345 is rounded to 1.234567890123456789012345678901234"
122 gdb_test "p d128=1.234567890123456E6145dl" "Infinity" "d128=1.234567890123456E6145 is Infinity"
123
124 # Test that gdb could detect the errors in the string representation of _Decimal128
125 gdb_test "p d128=12345dl" ".*Invalid number.*" "12345dl is an invalid number"
126 gdb_test "p d128=1.23Edl" ".*Conversion syntax.*" "1.23E is an invalid number"
127 gdb_test "p d128=1.23E45Adl" ".*Conversion syntax.*" "1.23E45A is an invalid number"
128 }
129
130 # Different tests on 32-bits decimal floating point, including the printing
131 # of finite numbers, infinite and NaN, and also the setting of different
132 # decimal value.
133
134 gdb_test "next" \
135 ".*Positive infd32.*" \
136 "next after initializing d32"
137 gdb_test "print d32" "1.2345" "d32 is initialized to 1.2345"
138
139 gdb_test "next" \
140 ".*Negative infd32.*" \
141 "next after assigning builtin infinity to d32"
142 gdb_test "print d32" "Infinity" "d32 is positive Infinity"
143
144 gdb_test "next" \
145 ".*__builtin_nand32.*" \
146 "next after assigning negative builtin infinity to d32"
147 gdb_test "print d32" "-Infinity" "d32 is negative Infinity"
148
149 gdb_test "next" \
150 ".*d64 = 1.2345.*" \
151 "next after assigning builtin NaN to d32"
152 gdb_test "print d32" "NaN" "d32 is NaN"
153
154 d32_set_tests
155
156
157 # Different tests on 64-bits decimal floating point, including the display
158 # of finite number, infinite and NaN, and also the setting of different
159 # decimal value.
160
161 gdb_test "next" \
162 ".*Positive infd64.*" \
163 "next after initializing d64"
164 gdb_test "print d64" "1.2345" "d64 is initialized to 1.2345"
165
166 gdb_test "next" \
167 ".*Negative infd64.*" \
168 "next after assigning builtin infinity to d64"
169 gdb_test "print d64" "Infinity" "d64 is positive Infinity"
170
171 gdb_test "next" \
172 ".*__builtin_nand64.*" \
173 "next after assigning negative builtin infinity to d64"
174 gdb_test "print d64" "-Infinity" "d64 is negative Infinity"
175
176 gdb_test "next" \
177 ".*d128 = 1.2345.*" \
178 "next after assigning builtin NaN to d64"
179 gdb_test "print d64" "NaN" "d64 is NaN"
180
181 d64_set_tests
182
183
184 # Different tests on 128-bits decimal floating point, including the display
185 # of finite number, infinite and NaN, and also the setting of different
186 # decimal value.
187
188 gdb_test "next" \
189 ".*Positive infd128.*" \
190 "next after initializing d128"
191 gdb_test "print d128" "1.2345" "d128 is initialized to 1.2345"
192
193 d128_set_tests
194
195 gdb_test "next" \
196 ".*Negative infd128.*" \
197 "next after assigning builtin infinity to d128"
198 gdb_test "print d128" "Infinity" "d128 is positive Infinity"
199
200 gdb_test "next" \
201 ".*__builtin_nand128.*" \
202 "next after assigning negative builtin infinity to d128"
203 gdb_test "print d128" "-Infinity" "d128 is negative Infinity"
204
205 gdb_test "next" \
206 ".*arg0_32.*" \
207 "next after assigning builtin NaN to d128"
208 gdb_test "print d128" "NaN" "d128 is NaN"
209
210 # The following tests are intended to verify that gdb can correctly handle
211 # DFP types in function arguments.
212
213 gdb_breakpoint arg0_32
214 gdb_continue_to_breakpoint "entry to arg0_32"
215 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"
216
217 gdb_breakpoint arg0_64
218 gdb_continue_to_breakpoint "entry to arg0_64"
219 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"
220
221 gdb_breakpoint arg0_128
222 gdb_continue_to_breakpoint "entry to arg0_128"
223 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"
224
225 # Test calling inferior function with DFP arguments or return value.
226
227 gdb_test "call arg0_32 (1.2df, 2.2df, 3.2df, 4.2df, 5.2df, 6.2df)" "Breakpoint.*arg0_32.*" "call function with correct _Decimal32 arguments."
228 gdb_test "backtrace 1" "\n#\[0-9\]+ arg0_32 \\(arg0=1.2, arg1=2.2, arg2=3.2, arg3=4.2, arg4=5.2, arg5=6.2\\).*" "backtrace function with correct _Decimal32 arguments."
229 gdb_test "finish" " = 1.2" "correct _Decimal32 return value from called function."
230
231 gdb_test "call arg0_64 (1.2dd, 2.2dd, 3.2dd, 4.2dd, 5.2dd, 6.2dd)" "Breakpoint.*arg0_64.*" "call function with correct _Decimal64 arguments."
232 gdb_test "backtrace 1" "\n#\[0-9\]+ arg0_64 \\(arg0=1.2, arg1=2.2, arg2=3.2, arg3=4.2, arg4=5.2, arg5=6.2\\).*" "backtrace function with correct _Decimal64 arguments."
233 gdb_test "finish" " = 1.2" "correct _Decimal64 return value from called function."
234
235 gdb_test "call arg0_128 (1.2dl, 2.2dl, 3.2dl, 4.2dl, 5.2dl, 6.2dl)" "Breakpoint.*arg0_128.*" "call function with correct _Decimal128 arguments."
236 gdb_test "backtrace 1" "\n#\[0-9\]+ arg0_128 \\(arg0=1.2, arg1=2.2, arg2=3.2, arg3=4.2, arg4=5.2, arg5=6.2\\).*" "backtrace function with correct _Decimal128 arguments."
237 gdb_test "finish" " = 1.2" "correct _Decimal128 return value from called function."
238
239 gdb_test "call decimal_dec128_align (double_val1, dec128_val2, double_val3, double_val4, double_val5, double_val6, double_val7, double_val8, double_val9, double_val10, double_val11, double_val12, double_val13, double_val14)" " = 1" \
240 "Call function with mixed decimal float arguments TEST."
241
242 gdb_test "call decimal_mixed (dec32_val1, dec64_val1, dec128_val1)" " = 1" \
243 "Call function with mixed decimal float arguments."
244
245 gdb_test "call decimal_many_args_dec32 (dec32_val1, dec32_val2, dec32_val3, dec32_val4, dec32_val5, dec32_val6, dec32_val7, dec32_val8, dec32_val9, dec32_val10, dec32_val11, dec32_val12, dec32_val13, dec32_val14, dec32_val15, dec32_val16)" " = 1" \
246 "Call function with many _Decimal32 arguments."
247
248 gdb_test "call decimal_many_args_dec64 (dec64_val1, dec64_val2, dec64_val3, dec64_val4, dec64_val5, dec64_val6, dec64_val7, dec64_val8, dec64_val9, dec64_val10, dec64_val11, dec64_val12, dec64_val13, dec64_val14, dec64_val15, dec64_val16)" " = 1" \
249 "Call function with many _Decimal64 arguments."
250
251 gdb_test "call decimal_many_args_dec128 (dec128_val1, dec128_val2, dec128_val3, dec128_val4, dec128_val5, dec128_val6, dec128_val7, dec128_val8, dec128_val9, dec128_val10, dec128_val11, dec128_val12, dec128_val13, dec128_val14, dec128_val15, dec128_val16)" " = 1" \
252 "Call function with many _Decimal128 arguments."
253
254 gdb_test "call decimal_many_args_mixed (dec32_val1, dec32_val2, dec32_val3, dec64_val4, dec64_val5, dec64_val6, dec64_val7, dec128_val8, dec128_val9, dec128_val10, dec32_val11, dec64_val12, dec32_val13, dec64_val14, dec128_val15)" " = 1" \
255 "Call function with many mixed decimal float arguments."
256
257 # The following tests are intended to verify that gdb can handle DFP types
258 # correctly in struct.
259
260 gdb_breakpoint [gdb_get_line_number "Exit point"]
261 gdb_continue_to_breakpoint "Setting a decimal struct"
262 gdb_test "print ds.dec32" " = 1.2345"
263 gdb_test "print ds.dec64" " = 1.2345"
264 gdb_test "print ds.dec128" " = 1.2345"
265
266 # Test expressions with DFP variables.
267
268 gdb_test "print d32 + ds.dec32" " = 1.3345"
269 gdb_test "print d64 + ds.dec64" " = 1.3345"
270 gdb_test "print d128 + ds.dec128" " = 1.3345"
271
272 # Test conversion between different _Decimal sizes.
273
274 gdb_test "ptype d64 + ds.dec32" " = volatile _Decimal64"
275 gdb_test "ptype d128 + ds.dec32" " = volatile _Decimal128"
276 gdb_test "ptype d128 + ds.dec64" " = volatile _Decimal128"
277
278 gdb_test "whatis d64 + ds.dec32" " = volatile _Decimal64"
279 gdb_test "whatis d128 + ds.dec32" " = volatile _Decimal128"
280 gdb_test "whatis d128 + ds.dec64" " = volatile _Decimal128"
281
282 # Mixture of Decimal and integral operands
283 gdb_test "p d32 + 1" " = 1.1"
284 gdb_test "p 2 + d64" " = 2.1"
285 gdb_test "p ds.int4 + d128" " = 1.1"
286 gdb_test "p d32 + ds.long8" " = 2.1"
287 gdb_test "ptype d32 + 1" " = volatile _Decimal32"
288 gdb_test "ptype ds.int4 + d128" " = volatile _Decimal128"
289
290 # Test other operations with DFP operands
291 gdb_test "p !d32" " = 0"
292 gdb_test "p !d64" " = 0"
293 gdb_test "p !d128" " = 0"
294 gdb_test "p +d32" " = 0.1"
295 gdb_test "p +d64" " = 0.1"
296 gdb_test "p +d128" " = 0.1"
297 gdb_test "p d64 == d128" " = 1"
298 gdb_test "p d128 == ds.dec32" " = 0"
299 gdb_test "p d128 == d32" " = 1"
300 gdb_test "p ds.dec32 == ds.dec64" " = 1"
301 gdb_test "p d32 < ds.dec32" " = 1"
302 gdb_test "p d64 < ds.dec64" " = 1"
303 gdb_test "p d128 < ds.dec128" " = 1"
304 gdb_test "p ds.dec32 < d32" " = 0"
305 gdb_test "p d64 > ds.dec64" " = 0"
306 gdb_test "p ds.dec128 > d128 " " = 1"
307 gdb_test "p d32 < ds.int4" " = 1"
308 gdb_test "p ds.int4 > d32" " = 1"
309 gdb_test "p ds.dec32 < ds.int4" " = 0"
310 gdb_test "p ds.int4 > ds.dec64" " = 0"
311 gdb_test "p ds.dec128 > ds.int4" " = 1"
312
313 # Reject operation with DFP and Binary FP
314 gdb_test "p d64 + ds.float4" "Mixing decimal floating types with other floating types is not allowed."
315 gdb_test "p ds.double8 + d128" "Mixing decimal floating types with other floating types is not allowed."
316
317 # The following tests are intended to verify that gdb can handle "d1=d2"
318 # and "d1=-d2" correctly.
319
320 gdb_test "print ds.dec32=d32" " = 0.1"
321 gdb_test "print ds.dec64=d64" " = 0.1"
322 gdb_test "print ds.dec128=d128" " = 0.1"
323 gdb_test "print ds.dec32 = -d32" " = -0.1"
324 gdb_test "print ds.dec64 = -d64" " = -0.1"
325 gdb_test "print ds.dec128 = -d128" " = -0.1"
326
327 # Test cast to and from DFP values
328
329 gdb_test "print ds.double8 = ds.dec64" " = -0.(0999.*|1000.*)"
330 gdb_test "print ds.dec64 = ds.float4" " = 3.(0999.*|1000.*)"
331 gdb_test "print ds.dec128 = -ds.double8" " = 0.(0999.*|1000.*)"
332 gdb_test "print ds.dec128 = ds.dec32" " = -0.1"
333 gdb_test "print ds.dec32 = ds.int4" " = 1"
334 gdb_test "print ds.int4 = 7.3dl" " = 7"
335
336 # Test "whatis"/"ptype" of expressions involving casts to/from dfp
337 # typedefs.
338
339 # This list is composed by sub-lists, and their elements are (in
340 # order):
341 #
342 # - Type to cast to. This is also what "whatis" should print.
343 # - What "ptype" should print.
344
345 # Columns in the sublists represent:
346 # to/whatis # ptype
347 foreach elem {
348 {"_Decimal32" "_Decimal32"}
349 {"_Decimal64" "_Decimal64"}
350 {"_Decimal128" "_Decimal128"}
351 {"d32_t" "_Decimal32"}
352 {"d64_t" "_Decimal64"}
353 {"d128_t" "_Decimal128"}
354 {"d32_t2" "_Decimal32"}
355 {"d64_t2" "_Decimal64"}
356 {"d128_t2" "_Decimal128"}
357 } {
358 set type [lindex $elem 0]
359 set ptype [lindex $elem 1]
360 gdb_test "whatis ($type) 0" " = $type"
361 gdb_test "ptype ($type) 0" " = $ptype"
362 }
363
364 # Test:
365 # - whatis/ptype of variables of typedef type.
366 # - whatis/ptype of typedef type names.
367 # - whatis/ptype of typedef-of-typedef type names.
368
369 # Columns in the sublists represent:
370 # Type name # whatis # ptype
371 foreach elem {
372 {"v_d32_t" "d32_t" "_Decimal32"}
373 {"v_d64_t" "d64_t" "_Decimal64"}
374 {"v_d128_t" "d128_t" "_Decimal128"}
375
376 {"d32_t" "_Decimal32" "_Decimal32"}
377 {"d64_t" "_Decimal64" "_Decimal64"}
378 {"d128_t" "_Decimal128" "_Decimal128"}
379
380 {"d32_t2" "d32_t" "_Decimal32"}
381 {"d64_t2" "d64_t" "_Decimal64"}
382 {"d128_t2" "d128_t" "_Decimal128"}
383 } {
384 set type [lindex $elem 0]
385 set whatis [lindex $elem 1]
386 set ptype [lindex $elem 2]
387 gdb_test "whatis $type" " = $whatis"
388 gdb_test "ptype $type" " = $ptype"
389 }