From 3d83546b364c38c29ee80613010047af7a168c4c Mon Sep 17 00:00:00 2001 From: Raymond Lu Date: Thu, 20 Jan 2005 17:19:13 -0500 Subject: [svn-r9849] Purpose: New test and a few bug fix Description: Test conversion from native integer to derived floating-point type and convert back; test conversion from derived floating-point to derived floating-point types and convert back. Fixed a few minor bugs related to type conversion in the library. Platforms tested: h5committest and fuss --- src/H5Tconv.c | 4 +- test/dtypes.c | 183 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 181 insertions(+), 6 deletions(-) diff --git a/src/H5Tconv.c b/src/H5Tconv.c index df87a2d..50e4aa9 100644 --- a/src/H5Tconv.c +++ b/src/H5Tconv.c @@ -3547,7 +3547,7 @@ H5T_conv_f_f (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, msize = bitno; } else if (0==bitno) { msize = 1; - H5T_bit_set(s, src.u.f.mpos, 1, FALSE); + /*H5T_bit_set(s, src.u.f.mpos, 1, FALSE); - Why do this? */ } } else if (H5T_NORM_IMPLIED==src.u.f.norm) { msize = src.u.f.msize; @@ -8868,7 +8868,7 @@ H5T_conv_f_i (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, /* * Find the sign bit value of the source. */ - sign = H5T_bit_get_d(s, src.prec-1, 1); + sign = H5T_bit_get_d(s, src.u.f.sign, 1); /* * Check for special cases: +0, -0, +Inf, -Inf, NaN diff --git a/test/dtypes.c b/test/dtypes.c index 7a321f2..cc691b0 100644 --- a/test/dtypes.c +++ b/test/dtypes.c @@ -2385,9 +2385,19 @@ static int test_derived_flt(void) { hid_t file=-1, tid1=-1, tid2=-1; + hid_t dxpl_id=-1; char filename[1024]; size_t precision, spos, epos, esize, mpos, msize, size, ebias; int offset; + size_t src_size, dst_size; + unsigned char *buf=NULL, *saved_buf=NULL; + int *aligned=NULL; + int endian; /*endianess */ + size_t nelmts = NTESTELEM; + int fails_this_test = 0; + const size_t max_fails=40; /*max number of failures*/ + char str[256]; /*message string */ + int i, j, k; TESTING("user-define and query functions of floating-point types"); @@ -2399,6 +2409,12 @@ test_derived_flt(void) goto error; } + if((dxpl_id = H5Pcreate(H5P_DATASET_XFER))<0) { + H5_FAILED(); + printf("Can't create data transfer property list\n"); + goto error; + } + if((tid1 = H5Tcopy(H5T_IEEE_F64LE))<0) { H5_FAILED(); printf("Can't copy data type\n"); @@ -2508,6 +2524,76 @@ test_derived_flt(void) goto error; } + /* Convert data from native integer to the 1st derived floating-point type. + * Then convert data from the floating-point type back to native integer. + * Compare the final data with the original data. + */ + src_size = H5Tget_size(H5T_NATIVE_INT); + endian = H5Tget_order(H5T_NATIVE_INT); + buf = (unsigned char*)malloc(nelmts*(MAX(src_size, size))); + saved_buf = (unsigned char*)malloc(nelmts*src_size); + aligned = (int*)malloc(src_size); + + for(i=0; i derived floating-point conversions"); + printf("%-70s", str); + HDfflush(stdout); + H5_FAILED(); + } + printf(" test %u elmt %u: \n", 1, (unsigned)i); + + printf(" src = "); + for (j=0; j=max_fails) { + HDputs(" maximum failures reached, aborting test..."); + goto error; + } + } + + fails_this_test = 0; + if(buf) free(buf); + if(saved_buf) free(saved_buf); + if(aligned) free(aligned); + buf = saved_buf = aligned = NULL; + /*-------------------------------------------------------------------------- * 2nd floating-point type * size=3 byte, precision=24 bits, offset=0 bits, mantissa size=16 bits, @@ -2596,12 +2682,96 @@ test_derived_flt(void) goto error; } + /* Convert data from the 2nd to the 1st derived floating-point type. + * Then convert data from the 1st type back to the 2nd type. + * Compare the final data with the original data. + */ + src_size = H5Tget_size(tid2); + dst_size = H5Tget_size(tid1); + endian = H5Tget_order(tid2); + buf = (unsigned char*)malloc(nelmts*(MAX(src_size, dst_size))); + saved_buf = (unsigned char*)malloc(nelmts*src_size); + + for(i=0; i derived floating-point conversions"); + printf("%-70s", str); + HDfflush(stdout); + H5_FAILED(); + } + printf(" test %u elmt %u: \n", 1, (unsigned)i); + + printf(" src = "); + for (j=0; j=max_fails) { + HDputs(" maximum failures reached, aborting test..."); + goto error; + } + } + + if (buf) free(buf); + if (saved_buf) free(saved_buf); + + if(H5Tclose(tid1)<0) { + H5_FAILED(); + printf("Can't close datatype\n"); + goto error; + } + if(H5Tclose(tid2)<0) { H5_FAILED(); printf("Can't close datatype\n"); goto error; } + if(H5Pclose(dxpl_id)<0) { + H5_FAILED(); + printf("Can't close property list\n"); + goto error; + } + if(H5Fclose(file)<0) { H5_FAILED(); printf("Can't close file\n"); @@ -2614,13 +2784,18 @@ test_derived_flt(void) return 0; error: + if (buf) free(buf); + if (saved_buf) free(saved_buf); + if (aligned) free(aligned); + HDfflush(stdout); H5E_BEGIN_TRY { H5Tclose (tid1); H5Tclose (tid2); + H5Pclose (dxpl_id); H5Fclose (file); } H5E_END_TRY; reset_hdf5(); /*print statistics*/ - return 1; + return MAX((int)fails_this_test, 1); } @@ -6658,7 +6833,7 @@ run_int_float_conv(const char *name) nerrors += test_conv_int_float(name, H5T_NATIVE_LLONG, H5T_NATIVE_LDOUBLE); #if H5_ULLONG_TO_FP_CAST_WORKS && H5_ULLONG_TO_LDOUBLE_PRECISION_WORKS nerrors += test_conv_int_float(name, H5T_NATIVE_ULLONG, H5T_NATIVE_LDOUBLE); -#else /* H5_ULLONG_TO_FP_CAST_WORKS */ +#else /* H5_ULLONG_TO_FP_CAST_WORKS && H5_ULLONG_TO_LDOUBLE_PRECISION_WORKS */ { char str[256]; /*hello string */ @@ -6668,7 +6843,7 @@ run_int_float_conv(const char *name) SKIPPED(); HDputs(" Test skipped due to compiler not handling conversion."); } -#endif /* H5_ULLONG_TO_FP_CAST_WORKS */ +#endif /* H5_ULLONG_TO_FP_CAST_WORKS && H5_ULLONG_TO_LDOUBLE_PRECISION_WORKS */ #endif #endif #else /*H5_SW_INTEGER_TO_LDOUBLE_WORKS*/ @@ -7337,7 +7512,7 @@ main(void) /* Test software integer-float conversion functions */ nerrors += run_int_float_conv("sw"); - + reset_hdf5(); if (nerrors) { -- cgit v0.12