From e4abe93b217335743ed4787875af49bd16895987 Mon Sep 17 00:00:00 2001 From: bauermann Date: Mon, 7 Jan 2008 22:34:48 +0000 Subject: [PATCH] * gdb.base/dfp-exprs.exp (test_dfp_arithmetic_expressions): Add tests for expressions with decimal float values. (test_dfp_conversions): New function to test casts to and from decimal float types. Call test_dfp_conversions. * gdb.base/dfp-test.c (struct decstruct): Add float4 and double8 elements. (main): Initialize ds.float4 and ds.double8 elements. * gdb.base/dfp-test.exp (d32_set_tests): Fix typo. Adjust expect string to new error message. (d64_set_tests): Likewise. (d128_set_tests): Likewise. Add tests for expressions with decimal float variables. Add tests for conversions to and from decimal float types. --- gdb/testsuite/ChangeLog | 17 ++++ gdb/testsuite/gdb.base/dfp-exprs.exp | 101 ++++++++++++++++++++++-- gdb/testsuite/gdb.base/dfp-test.c | 4 + gdb/testsuite/gdb.base/dfp-test.exp | 146 +++++++++++++++++++++++++++-------- 4 files changed, 230 insertions(+), 38 deletions(-) diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index e2f9933f66..dd100f6848 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,20 @@ +2008-01-07 Thiago Jung Bauermann + + * gdb.base/dfp-exprs.exp (test_dfp_arithmetic_expressions): Add tests + for expressions with decimal float values. + (test_dfp_conversions): New function to test casts to and from + decimal float types. + Call test_dfp_conversions. + * gdb.base/dfp-test.c (struct decstruct): Add float4 and double8 + elements. + (main): Initialize ds.float4 and ds.double8 elements. + * gdb.base/dfp-test.exp (d32_set_tests): Fix typo. Adjust expect + string to new error message. + (d64_set_tests): Likewise. + (d128_set_tests): Likewise. + Add tests for expressions with decimal float variables. Add tests for + conversions to and from decimal float types. + 2008-01-05 Joel Brobecker * gdb.ada/packed_tagged/comp_bug.adb: New file. diff --git a/gdb/testsuite/gdb.base/dfp-exprs.exp b/gdb/testsuite/gdb.base/dfp-exprs.exp index 01b961bcd1..ba56de490d 100644 --- a/gdb/testsuite/gdb.base/dfp-exprs.exp +++ b/gdb/testsuite/gdb.base/dfp-exprs.exp @@ -74,14 +74,102 @@ proc test_dfp_literals_accepted {} { proc test_dfp_arithmetic_expressions {} { -# Arithmetic operations for DFP types are not yet implemented in GDB. -# These tests are to verify that they will generate expected error messages. + # _Decimal32 operands. + gdb_test "p 1.4df + 1.2df" " = 2.6" + gdb_test "p 1.4df - 1.2df" " = 0.2" + gdb_test "p 1.4df * 1.2df" " = 1.68" + gdb_test "p 1.4df / 1.2df" " = 1.166667" + + # _Decimal64 operands. + gdb_test "p 1.4dd + 1.2dd" " = 2.6" + gdb_test "p 1.4dd - 1.2dd" " = 0.2" + gdb_test "p 1.4dd * 1.2dd" " = 1.68" + gdb_test "p 1.4dd / 1.2dd" " = 1.166666666666667" + + # _Decimal128 operands. + gdb_test "p 1.4dl + 1.2dl" " = 2.6" + gdb_test "p 1.4dl - 1.2dl" " = 0.2" + gdb_test "p 1.4dl * 1.2dl" " = 1.68" + gdb_test "p 1.4dl / 1.2dl" " = 1.166666666666666666666666666666667" + + # Test type of operation result. + gdb_test "ptype 2.df + 2.df" "= _Decimal32" + gdb_test "ptype 2.dd + 2.dd" "= _Decimal64" + gdb_test "ptype 2.dl + 2.dl" "= _Decimal128" + + # Mixture of different _Decimal sizes. + gdb_test "p 2.1df + 2.7dd" "= 4.8" + gdb_test "p 2.1dd + 2.7df" "= 4.8" + gdb_test "p 2.6df + 2.7dl" "= 5.3" + gdb_test "p 2.6dl + 2.7df" "= 5.3" + gdb_test "p 2.3dd + 2.2dl" "= 4.5" + gdb_test "p 2.3dl + 2.2dd" "= 4.5" + gdb_test "ptype 2.df + 2.dd" "= _Decimal64" + gdb_test "ptype 2.df + 2.dl" "= _Decimal128" + gdb_test "ptype 2.dd + 2.dl" "= _Decimal128" + + # Mixture of Decimal and integral operands + gdb_test "p 1.2df + 1" " = 2.2" + gdb_test "p 2 + 1.7dd" " = 3.7" + gdb_test "p 3 + 2.1dl" " = 5.1" + gdb_test "ptype 1.2df + 1" " = _Decimal32" + gdb_test "ptype 2 + 1.7dd" " = _Decimal64" + gdb_test "ptype 3 + 2.1dl" " = _Decimal128" + + # Reject operation with integral larger than 32-bits + gdb_test "p 1.2df + 2ll" "Conversion of large integer to a decimal floating type is not supported." + + # Reject operation with DFP and Binary FP + gdb_test "p 1.2df + 1.2f" "Mixing decimal floating types with other floating types is not allowed." + + # Test other operations with DFP operands + gdb_test "p !0.df" " = 1" + gdb_test "p !0.dd" " = 1" + gdb_test "p !0.dl" " = 1" + gdb_test "p !0.5df" " = 0" + gdb_test "p !0.5dd" " = 0" + gdb_test "p !0.5dl" " = 0" + + gdb_test "p 1.2df == 1.2df" " = 1" + gdb_test "p 1.2df == 1.2dd" " = 1" + gdb_test "p 1.2df == 1.2dl" " = 1" + gdb_test "p 1.2dd == 1.2df" " = 1" + gdb_test "p 1.2dd == 1.2dl" " = 1" + gdb_test "p 1.2dl == 1.2df" " = 1" + gdb_test "p 1.2dl == 1.2dd" " = 1" + gdb_test "p 1.2df == 1.3df" " = 0" + gdb_test "p 1.2df == 1.3dd" " = 0" + gdb_test "p 1.2df == 1.3dl" " = 0" + gdb_test "p 1.2dd == 1.3df" " = 0" + gdb_test "p 1.2dd == 1.3dl" " = 0" + gdb_test "p 1.2dl == 1.3df" " = 0" + gdb_test "p 1.2dl == 1.3dd" " = 0" + + gdb_test "p +1.2df" " = 1.2" + gdb_test "p +1.2dd" " = 1.2" + gdb_test "p +1.2dl" " = 1.2" + + gdb_test "p 1.2df < 1.3df" " = 1" + gdb_test "p 1.2df < 1.3dd" " = 1" + gdb_test "p 1.2dl < 1.3df" " = 1" + gdb_test "p 1.2dd < 1.3dd" " = 1" + gdb_test "p 1.2dd < 1.3dl" " = 1" + gdb_test "p 1.2dl < 1.3dl" " = 1" + gdb_test "p 1.2dl < 1.3df" " = 1" + gdb_test "p 1.2df > 1" " = 1" + gdb_test "p 1.2dl > 2" " = 0" + gdb_test "p 2 > 1.2dd" " = 1" + gdb_test "p 2 > 3.1dl" " = 0" +} - gdb_test "p 1.4df + 1.2df" "Argument to arithmetic operation not a number or boolean.*" - gdb_test "p 1.4df - 1.2df" ".*Argument to arithmetic operation not a number or boolean.*" - gdb_test "p 1.4df * 1.2df" "Argument to arithmetic operation not a number or boolean.*" - gdb_test "p 1.4df / 1.2df" "Argument to arithmetic operation not a number or boolean.*" +proc test_dfp_conversions {} { + # Test cast to and from DFP values, and between DFPs of different sizes + gdb_test "p (float) -0.1df" " = -0.(0999.*|1000.*)" + gdb_test "p (int) 8.3dd" " = 8" + gdb_test "p (_Decimal64) 3.1" " = 3.(0999.*|1000.*)" + gdb_test "p (_Decimal128) 3.7df" " = 3.7" + gdb_test "p (_Decimal32) 4" " = 4" } # Start with a fresh gdb. @@ -92,3 +180,4 @@ gdb_reinitialize_dir $srcdir/$subdir test_dfp_literals_accepted test_dfp_arithmetic_expressions +test_dfp_conversions diff --git a/gdb/testsuite/gdb.base/dfp-test.c b/gdb/testsuite/gdb.base/dfp-test.c index 5497ada92b..504833abe9 100644 --- a/gdb/testsuite/gdb.base/dfp-test.c +++ b/gdb/testsuite/gdb.base/dfp-test.c @@ -26,6 +26,8 @@ struct decstruct { int int4; long long8; + float float4; + double double8; _Decimal32 dec32; _Decimal64 dec64; _Decimal128 dec128; @@ -85,6 +87,8 @@ int main() ds.int4 = 1; ds.long8 = 2; + ds.float4 = 3.1; + ds.double8 = 4.2; ds.dec32 = 1.2345df; ds.dec64 = 1.2345dd; ds.dec128 = 1.2345dl; diff --git a/gdb/testsuite/gdb.base/dfp-test.exp b/gdb/testsuite/gdb.base/dfp-test.exp index a42ef3a5f3..2d8f9ea8b2 100644 --- a/gdb/testsuite/gdb.base/dfp-test.exp +++ b/gdb/testsuite/gdb.base/dfp-test.exp @@ -18,6 +18,53 @@ # 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. +if $tracelevel then { + strace $tracelevel +} + +set testfile "dfp-test" +set srcfile ${testfile}.c +set binfile ${objdir}/${subdir}/${testfile} + +# 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}] != "" } { + verbose "Skipping DFP tests." + return -1 +} + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +if ![runto_main] then { + perror "couldn't run to breakpoint" + continue +} + +# Detect the size of the target's basic types (from gdb.base/long_long.exp). + +proc get_valueof { fmt exp default } { + global gdb_prompt + send_gdb "print${fmt} ${exp}\n" + gdb_expect { + -re "\\$\[0-9\]* = (\[-\]*\[0-9\]*).*$gdb_prompt $" { + set val $expect_out(1,string) + } + timeout { + set val ${default} + } + } + return ${val} +} + +proc get_sizeof { type default } { + return [get_valueof "/d" "sizeof (${type})" $default] +} + +set sizeof_long [get_sizeof "long" 4] + proc d32_set_tests {} { gdb_test "p d32=123.45df" " = 123.45" @@ -43,10 +90,10 @@ proc d32_set_tests {} { gdb_test "p d32=1.234567E+97df" " = Infinity" "1.234567E+97 is Infinity" # Test that gdb could detect the errors in the string representation of _Decimal32 - gdb_test "p d32=12345.df" " = 12345" "12345. is an valid number" + gdb_test "p d32=12345.df" " = 12345" "12345. is a valid number" gdb_test "p d32=12345df" ".*Invalid number.*" "12345 is an invalid number" - gdb_test "p d32=1.23Edf" " = NaN" "1.23E is NaN (not a number)" - gdb_test "p d32=1.23E45Adf" " = NaN" "1.23E45A is NaN (not a number)" + gdb_test "p d32=1.23Edf" ".*Conversion syntax.*" "1.23E is an invalid number" + gdb_test "p d32=1.23E45Adf" ".*Conversion syntax.*" "1.23E45A is an invalid number" } proc d64_set_tests {} { @@ -75,8 +122,8 @@ proc d64_set_tests {} { # Test that gdb could detect the errors in the string representation of _Decimal64 gdb_test "p d64=12345dd" ".*Invalid number.*" "12345dd is an invalid number" - gdb_test "p d64=1.23Edd" " = NaN" "1.23E is NaN (not a number)" - gdb_test "p d64=1.23E45Add" "= NaN" "1.23E45A is NaN (not a number)" + gdb_test "p d64=1.23Edd" ".*Conversion syntax.*" "1.23E is an invalid number" + gdb_test "p d64=1.23E45Add" ".*Conversion syntax.*" "1.23E45A is an invalid number" } proc d128_set_tests {} { @@ -104,33 +151,8 @@ proc d128_set_tests {} { # Test that gdb could detect the errors in the string representation of _Decimal128 gdb_test "p d128=12345dl" ".*Invalid number.*" "12345dl is an invalid number" - gdb_test "p d128=1.23Edl" " = NaN" "1.23E is NaN (not a number)" - gdb_test "p d128=1.23E45Adl" "= NaN" "1.23E45A is NaN (not a number)" -} - - -if $tracelevel { - strace $tracelevel -} - -set testfile "dfp-test" -set srcfile ${testfile}.c -set binfile ${objdir}/${subdir}/${testfile} -# 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}] != "" } { - verbose "Skipping DFP tests." - return -1 -} - -gdb_exit -gdb_start -gdb_reinitialize_dir $srcdir/$subdir -gdb_load ${binfile} - -if ![runto_main] then { - perror "couldn't run to breakpoint" - continue + gdb_test "p d128=1.23Edl" ".*Conversion syntax.*" "1.23E is an invalid number" + gdb_test "p d128=1.23E45Adl" ".*Conversion syntax.*" "1.23E45A is an invalid number" } # Different tests on 32-bits decimal floating point, including the printing @@ -237,6 +259,57 @@ gdb_test "print ds.dec32" " = 1.2345" gdb_test "print ds.dec64" " = 1.2345" gdb_test "print ds.dec128" " = 1.2345" +# Test expressions with DFP variables. + +gdb_test "print d32 + ds.dec32" " = 1.3345" +gdb_test "print d64 + ds.dec64" " = 1.3345" +gdb_test "print d128 + ds.dec128" " = 1.3345" + +# Test conversion between different _Decimal sizes. + +gdb_test "ptype d64 + ds.dec32" " = volatile _Decimal64" +gdb_test "ptype d128 + ds.dec32" " = volatile _Decimal128" +gdb_test "ptype 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 "ptype d32 + 1" " = volatile _Decimal32" +gdb_test "ptype ds.int4 + d128" " = volatile _Decimal128" + +# Test other operations with DFP operands +gdb_test "p !d32" " = 0" +gdb_test "p !d64" " = 0" +gdb_test "p !d128" " = 0" +gdb_test "p +d32" " = 0.1" +gdb_test "p +d64" " = 0.1" +gdb_test "p +d128" " = 0.1" +gdb_test "p d64 == d128" " = 1" +gdb_test "p d128 == ds.dec32" " = 0" +gdb_test "p d128 == d32" " = 1" +gdb_test "p ds.dec32 == ds.dec64" " = 1" +gdb_test "p d32 < ds.dec32" " = 1" +gdb_test "p d64 < ds.dec64" " = 1" +gdb_test "p d128 < ds.dec128" " = 1" +gdb_test "p ds.dec32 < d32" " = 0" +gdb_test "p d64 > ds.dec64" " = 0" +gdb_test "p ds.dec128 > d128 " " = 1" +gdb_test "p d32 < ds.int4" " = 1" +gdb_test "p ds.int4 > d32" " = 1" +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." + # The following tests are intended to verify that gdb can handle "d1=d2" # and "d1=-d2" correctly. @@ -246,3 +319,12 @@ gdb_test "print ds.dec128=d128" " = 0.1" gdb_test "print ds.dec32 = -d32" " = -0.1" gdb_test "print ds.dec64 = -d64" " = -0.1" gdb_test "print ds.dec128 = -d128" " = -0.1" + +# Test cast to and from DFP values + +gdb_test "print ds.double8 = ds.dec64" " = -0.(0999.*|1000.*)" +gdb_test "print ds.dec64 = ds.float4" " = 3.(0999.*|1000.*)" +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" -- 2.11.0