gdb: testsuite: print explicit test result for gdb.base/dfp-test.exp
[binutils-gdb.git] / gdb / testsuite / gdb.base / dfp-test.exp
index f1218085b5e86cc2084751b5baeca8a49873a148..6c3de2863eac2e2d5544d28f69357956b4d7ceba 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2007-2013 Free Software Foundation, Inc.
+# Copyright (C) 2007-2022 Free Software Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # This file is part of the gdb testsuite.  It is intended to test that
 # gdb could correctly handle decimal floating point introduced in IEEE 754R.
 
-set testfile "dfp-test"
-set srcfile ${testfile}.c
-set binfile ${objdir}/${subdir}/${testfile}
+standard_testfile .c
 
 # Try to compile the test case.  If we can't, assume the
 # toolchain does not yet provide DFP support and bail out.
 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {quiet debug}] != "" } {
+    unsupported "decimal floating point not supported for this target."
     verbose "Skipping DFP tests."
     return -1
 }
 
-gdb_exit
-gdb_start
-gdb_reinitialize_dir $srcdir/$subdir
-gdb_load ${binfile}
+clean_restart ${binfile}
 
 if ![runto_main] then {
     perror "couldn't run to breakpoint"
@@ -41,7 +37,7 @@ if ![runto_main] then {
 
 set sizeof_long [get_sizeof "long" 4]
 
-proc d32_set_tests {} {
+proc_with_prefix d32_set_tests {} {
 
     gdb_test "p d32=123.45df" " = 123.45"
     gdb_test "p d32=12345.df" " = 12345"
@@ -72,7 +68,7 @@ proc d32_set_tests {} {
     gdb_test "p d32=1.23E45Adf" ".*Conversion syntax.*" "1.23E45A is an invalid number"
 }
 
-proc d64_set_tests {} {
+proc_with_prefix d64_set_tests {} {
 
     gdb_test "p d64=123.45dd" " = 123.45"
     gdb_test "p d64=12345.dd" " = 12345"
@@ -102,7 +98,7 @@ proc d64_set_tests {} {
     gdb_test "p d64=1.23E45Add" ".*Conversion syntax.*" "1.23E45A is an invalid number"
 }
 
-proc d128_set_tests {} {
+proc_with_prefix d128_set_tests {} {
 
     gdb_test "p d128=123.45dl" " = 123.45"
     gdb_test "p d128=12345.dl" " = 12345"
@@ -135,24 +131,24 @@ proc d128_set_tests {} {
 # of finite numbers, infinite and NaN, and also the setting of different
 # decimal value.
 
-if [gdb_test "next" \
+gdb_test "next" \
     ".*Positive infd32.*" \
-    "next after initializing d32"] then { gdb_suppress_tests }
+    "next after initializing d32"
 gdb_test "print d32" "1.2345" "d32 is initialized to 1.2345"
 
-if [gdb_test "next" \
+gdb_test "next" \
     ".*Negative infd32.*" \
-    "next after assigning builtin infinity to d32"] then { gdb_suppress_tests }
+    "next after assigning builtin infinity to d32"
 gdb_test "print d32" "Infinity" "d32 is positive Infinity"
 
-if [gdb_test "next" \
+gdb_test "next" \
     ".*__builtin_nand32.*" \
-    "next after assigning negative builtin infinity to d32"] then { gdb_suppress_tests }
+    "next after assigning negative builtin infinity to d32"
 gdb_test "print d32" "-Infinity" "d32 is negative Infinity"
 
-if [gdb_test "next" \
+gdb_test "next" \
     ".*d64 = 1.2345.*" \
-    "next after assigning builtin NaN to d32"] then { gdb_suppress_tests }
+    "next after assigning builtin NaN to d32"
 gdb_test "print d32" "NaN" "d32 is NaN"
 
 d32_set_tests
@@ -162,24 +158,24 @@ d32_set_tests
 # of finite number, infinite and NaN, and also the setting of different
 # decimal value.
 
-if [gdb_test "next" \
+gdb_test "next" \
     ".*Positive infd64.*" \
-    "next after initializing d64"] then { gdb_suppress_tests }
+    "next after initializing d64"
 gdb_test "print d64" "1.2345" "d64 is initialized to 1.2345"
 
-if [gdb_test "next" \
+gdb_test "next" \
     ".*Negative infd64.*" \
-    "next after assigning builtin infinity to d64"] then { gdb_suppress_tests }
+    "next after assigning builtin infinity to d64"
 gdb_test "print d64" "Infinity" "d64 is positive Infinity"
 
-if [gdb_test "next" \
+gdb_test "next" \
     ".*__builtin_nand64.*" \
-    "next after assigning negative builtin infinity to d64"] then { gdb_suppress_tests }
+    "next after assigning negative builtin infinity to d64"
 gdb_test "print d64" "-Infinity" "d64 is negative Infinity"
 
-if [gdb_test "next" \
+gdb_test "next" \
     ".*d128 = 1.2345.*" \
-    "next after assigning builtin NaN to d64"] then { gdb_suppress_tests }
+    "next after assigning builtin NaN to d64"
 gdb_test "print d64" "NaN" "d64 is NaN"
 
 d64_set_tests
@@ -189,26 +185,26 @@ d64_set_tests
 # of finite number, infinite and NaN, and also the setting of different
 # decimal value.
 
-if [gdb_test "next" \
+gdb_test "next" \
     ".*Positive infd128.*" \
-    "next after initializing d128"] then { gdb_suppress_tests }
+    "next after initializing d128"
 gdb_test "print d128" "1.2345" "d128 is initialized to 1.2345"
 
 d128_set_tests
 
-if [gdb_test "next" \
+gdb_test "next" \
     ".*Negative infd128.*" \
-    "next after assigning builtin infinity to d128"] then { gdb_suppress_tests }
+    "next after assigning builtin infinity to d128"
 gdb_test "print d128" "Infinity" "d128 is positive Infinity"
 
-if [gdb_test "next" \
+gdb_test "next" \
     ".*__builtin_nand128.*" \
-    "next after assigning negative builtin infinity to d128"] then { gdb_suppress_tests }
+    "next after assigning negative builtin infinity to d128"
 gdb_test "print d128" "-Infinity" "d128 is negative Infinity"
 
-if [gdb_test "next" \
+gdb_test "next" \
     ".*arg0_32.*" \
-    "next after assigning builtin NaN to d128"] then { gdb_suppress_tests }
+    "next after assigning builtin NaN to d128"
 gdb_test "print d128" "NaN" "d128 is NaN"
 
 # The following tests are intended to verify that gdb can correctly handle
@@ -228,17 +224,17 @@ gdb_test "backtrace" ".*arg0_128 \\(arg0=0.1, arg1=1.0, arg2=2.0, arg3=3.0, arg4
 
 # Test calling inferior function with DFP arguments or return value.
 
-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."
-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."
-gdb_test "finish" " = 1.2" "Correct _Decimal32 return value from called function."
+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."
+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."
+gdb_test "finish" " = 1.2" "correct _Decimal32 return value from called function."
 
-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."
-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."
-gdb_test "finish" " = 1.2" "Correct _Decimal64 return value from called function."
+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."
+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."
+gdb_test "finish" " = 1.2" "correct _Decimal64 return value from called function."
 
-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."
-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."
-gdb_test "finish" " = 1.2" "Correct _Decimal128 return value from called function."
+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."
+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."
+gdb_test "finish" " = 1.2" "correct _Decimal128 return value from called function."
 
 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" \
   "Call function with mixed decimal float arguments TEST."
@@ -279,10 +275,15 @@ gdb_test "ptype d64 + ds.dec32" " = volatile _Decimal64"
 gdb_test "ptype d128 + ds.dec32" " = volatile _Decimal128"
 gdb_test "ptype d128 + ds.dec64" " = volatile _Decimal128"
 
+gdb_test "whatis d64 + ds.dec32" " = volatile _Decimal64"
+gdb_test "whatis d128 + ds.dec32" " = volatile _Decimal128"
+gdb_test "whatis d128 + ds.dec64" " = volatile _Decimal128"
+
 # Mixture of Decimal and integral operands
 gdb_test "p d32 + 1" " = 1.1"
 gdb_test "p 2 + d64" " = 2.1"
 gdb_test "p ds.int4 + d128" " = 1.1"
+gdb_test "p d32 + ds.long8" " = 2.1"
 gdb_test "ptype d32 + 1" " = volatile _Decimal32"
 gdb_test "ptype ds.int4 + d128" " = volatile _Decimal128"
 
@@ -309,11 +310,6 @@ gdb_test "p ds.dec32 < ds.int4" " = 0"
 gdb_test "p ds.int4 > ds.dec64" " = 0"
 gdb_test "p ds.dec128 > ds.int4" " = 1"
 
-# Reject operation with integral larger than 32-bits
-if { ${sizeof_long} > 4 } {
-  gdb_test "p d32 + ds.long8" "Conversion of large integer to a decimal floating type is not supported."
-}
-
 # Reject operation with DFP and Binary FP
 gdb_test "p d64 + ds.float4" "Mixing decimal floating types with other floating types is not allowed."
 gdb_test "p ds.double8 + d128" "Mixing decimal floating types with other floating types is not allowed."
@@ -336,3 +332,58 @@ gdb_test "print ds.dec128 = -ds.double8" " = 0.(0999.*|1000.*)"
 gdb_test "print ds.dec128 = ds.dec32" " = -0.1"
 gdb_test "print ds.dec32 = ds.int4" " = 1"
 gdb_test "print ds.int4 = 7.3dl" " = 7"
+
+# Test "whatis"/"ptype" of expressions involving casts to/from dfp
+# typedefs.
+
+# This list is composed by sub-lists, and their elements are (in
+# order):
+#
+# - Type to cast to.  This is also what "whatis" should print.
+# - What "ptype" should print.
+
+# Columns in the sublists represent:
+     # to/whatis   # ptype
+foreach elem {
+    {"_Decimal32"  "_Decimal32"}
+    {"_Decimal64"  "_Decimal64"}
+    {"_Decimal128" "_Decimal128"}
+    {"d32_t"       "_Decimal32"}
+    {"d64_t"       "_Decimal64"}
+    {"d128_t"      "_Decimal128"}
+    {"d32_t2"      "_Decimal32"}
+    {"d64_t2"      "_Decimal64"}
+    {"d128_t2"     "_Decimal128"}
+} {
+    set type [lindex $elem 0]
+    set ptype [lindex $elem 1]
+    gdb_test "whatis ($type) 0" " = $type"
+    gdb_test "ptype ($type) 0" " = $ptype"
+}
+
+# Test:
+# - whatis/ptype of variables of typedef type.
+# - whatis/ptype of typedef type names.
+# - whatis/ptype of typedef-of-typedef type names.
+
+# Columns in the sublists represent:
+    # Type name    # whatis      # ptype
+foreach elem {
+    {"v_d32_t"     "d32_t"       "_Decimal32"}
+    {"v_d64_t"     "d64_t"       "_Decimal64"}
+    {"v_d128_t"    "d128_t"      "_Decimal128"}
+
+    {"d32_t"       "_Decimal32"  "_Decimal32"}
+    {"d64_t"       "_Decimal64"  "_Decimal64"}
+    {"d128_t"      "_Decimal128" "_Decimal128"}
+
+    {"d32_t2"      "d32_t"       "_Decimal32"}
+    {"d64_t2"      "d64_t"       "_Decimal64"}
+    {"d128_t2"     "d128_t"      "_Decimal128"}
+} {
+    set type [lindex $elem 0]
+    set whatis [lindex $elem 1]
+    set ptype [lindex $elem 2]
+    gdb_test "whatis $type" " = $whatis"
+    gdb_test "ptype $type" " = $ptype"
+}