1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * Copyright by The HDF Group.                                               *
3  * Copyright by the Board of Trustees of the University of Illinois.         *
4  * All rights reserved.                                                      *
5  *                                                                           *
6  * This file is part of HDF5.  The full HDF5 copyright notice, including     *
7  * terms governing use, modification, and redistribution, is contained in    *
8  * the COPYING file, which can be found at the root of the source code       *
9  * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.  *
10  * If you do not have access to either file, you may request a copy from     *
11  * help@hdfgroup.org.                                                        *
12  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13 
14 /*
15  * Programmer:  Robb Matzke <matzke@llnl.gov>
16  *              Tuesday, December  9, 1997
17  *
18  * Purpose:     Tests the data type interface (H5T)
19  */
20 
21 #include "h5test.h"
22 
23 /* Number of elements in each random test */
24 #define NTESTELEM    10000
25 
26 /* Epsilon for floating-point comparisons */
27 #define FP_EPSILON 0.000001F
28 
29 /*
30  * Offset from alinged memory returned by malloc().  This can be used to test
31  * that type conversions handle non-aligned buffers correctly.
32  */
33 #define ALIGNMENT    1
34 
35 /*
36  * Define if you want to test alignment code on a machine that doesn't
37  * normally require alignment. When set, all native data types must be aligned
38  * on a byte boundary equal to the data size.
39  */
40 #define TEST_ALIGNMENT
41 
42 /* Alignment test stuff */
43 #ifdef TEST_ALIGNMENT
44 #define H5T_FRIEND        /*suppress error about including H5Tpkg      */
45 #include "H5Tpkg.h"
46 #endif
47 #define SET_ALIGNMENT(TYPE,VAL) \
48     H5T_NATIVE_##TYPE##_ALIGN_g=MAX(H5T_NATIVE_##TYPE##_ALIGN_g, VAL)
49 
50 const char *FILENAME[] = {
51     "dt_arith1",
52     "dt_arith2",
53     NULL
54 };
55 
56 /*
57  * Count up or down depending on whether the machine is big endian or little
58  * endian.  If local variable `endian' is H5T_ORDER_BE then the result will
59  * be I, otherwise the result will be Z-(I+1).
60  */
61 #define ENDIAN(Z,I,E)    (H5T_ORDER_BE==E?(I):(Z)-((I)+1))
62 
63 typedef enum dtype_t {
64     INT_SCHAR, INT_UCHAR, INT_SHORT, INT_USHORT, INT_INT, INT_UINT,
65     INT_LONG, INT_ULONG, INT_LLONG, INT_ULLONG, FLT_FLOAT, FLT_DOUBLE,
66 #if H5_SIZEOF_LONG_DOUBLE !=0
67     FLT_LDOUBLE,
68 #endif
69     OTHER
70 } dtype_t;
71 
72 /* Skip overflow tests if non-zero */
73 static int skip_overflow_tests_g = 0;
74 
75 /*
76  * Although we check whether a floating point overflow generates a SIGFPE and
77  * turn off overflow tests in that case, it might still be possible for an
78  * overflow condition to occur.  Once a SIGFPE is raised the program cannot
79  * be allowed to continue (cf. Posix signals) so in order to recover from a
80  * SIGFPE we run tests that might generate one in a child process.
81  */
82 #if defined(H5_HAVE_FORK) && defined(H5_HAVE_WAITPID)
83 #define HANDLE_SIGFPE
84 #endif
85 
86 /*
87  * Decide what values of floating-point number we want to test.  They are
88  * 1 - normalized; 2 - denormalized; 3 - special.
89  */
90 #define TEST_NOOP       0
91 #define TEST_NORMAL     1
92 #define TEST_DENORM     2
93 #define TEST_SPECIAL    3
94 
95 /* Temporary buffer sizes */
96 #define TMP_BUF_DIM1    32
97 #define TMP_BUF_DIM2    100
98 
99 /* Don't use hardware conversions if set */
100 static int without_hardware_g = 0;
101 
102 /* Allocates memory aligned on a certain boundary. */
103 #define aligned_malloc(Z)    ((void*)((char*)HDmalloc(ALIGNMENT+Z)+ALIGNMENT))
104 #define aligned_free(M)        HDfree((char*)(M)-ALIGNMENT)
105 
106 /* Initialize source buffer of integer for integer->integer and integer->floating-point conversion test.
107  * This algorithm is mainly to avoid any casting and comparison between source and destination types
108  * for compiler, because we're testing conversions. */
109 #define INIT_INTEGER(TYPE, SRC_MAX, SRC_MIN, SRC_SIZE, DST_SIZE, SRC_PREC, BUF, SAVED, NELMTS)  \
110 {                                                                                               \
111     unsigned char *buf_p, *saved_p;                                                             \
112     unsigned int n;                                                                             \
113     TYPE value1 = 1;                                                                            \
114     TYPE value2 = 0;                                                                            \
115                                                                                                 \
116     /* Allocate buffers */                                                                      \
117     NELMTS=SRC_PREC*3;                                                                          \
118     BUF = (unsigned char*)aligned_malloc(NELMTS*MAX(SRC_SIZE, DST_SIZE));                       \
119     SAVED = (unsigned char*)aligned_malloc(NELMTS*MAX(SRC_SIZE, DST_SIZE));                     \
120     HDmemset(BUF, 0, NELMTS*MAX(SRC_SIZE, DST_SIZE));                                           \
121     HDmemset(SAVED, 0, NELMTS*MAX(SRC_SIZE, DST_SIZE));                                         \
122                                                                                                 \
123     buf_p = BUF;                                                                                \
124     saved_p = SAVED;                                                                            \
125                                                                                                 \
126     /*positive values, ascending order. VALUE1 starts from 00000001, to 00000010, until 10000000*/ \
127     /*VALUE2 ascends from 00000000, to 00000011, 00000111,...,  until 11111111.*/               \
128     for(n=0; n<SRC_PREC; n++) {                                                                 \
129         {                                                                                       \
130             HDmemcpy(buf_p, &value1, SRC_SIZE);                                                 \
131             HDmemcpy(saved_p, &value1, SRC_SIZE);                                               \
132             buf_p += SRC_SIZE;                                                                  \
133             saved_p += SRC_SIZE;                                                                \
134         }                                                                                       \
135         {                                                                                       \
136             HDmemcpy(buf_p, &value2, SRC_SIZE);                                                 \
137             HDmemcpy(saved_p, &value2, SRC_SIZE);                                               \
138             buf_p += SRC_SIZE;                                                                  \
139             saved_p += SRC_SIZE;                                                                \
140         }                                                                                       \
141                                                                                                 \
142         if(n<SRC_PREC-2) {                                                                      \
143             value1 = (TYPE)(value1 << 1);                                                       \
144             value2 = (TYPE)((value1 - 1) | value1);                                             \
145         } else if(n==SRC_PREC-2) { /*to avoid overflow of negative values for signed integer*/  \
146             value1 = (TYPE)(value1 << 1);                                                       \
147             value2 = (TYPE)((~value1) | value1);                                                \
148         }                                                                                       \
149     }                                                                                           \
150                                                                                                 \
151     /* negative values for signed; descending positive values for unsigned */                   \
152     /* VALUE2 descends from 11111111 to 11111110, 11111100, ..., until 10000000. */             \
153     for(n=0; n<SRC_PREC-1; n++) {                                                               \
154         {                                                                                       \
155             HDmemcpy(buf_p, &value2, SRC_SIZE);                                                 \
156             HDmemcpy(saved_p, &value2, SRC_SIZE);                                               \
157             buf_p += SRC_SIZE;                                                                  \
158             saved_p += SRC_SIZE;                                                                \
159         }                                                                                       \
160         if(n<SRC_PREC-1)                                                                        \
161             value2 = (TYPE)(value2 << 1);                                                       \
162     }                                                                                           \
163 }
164 
165 /* Change a buffer's byte order from big endian to little endian.  It's mainly for library's
166  * bit operations which handle only little endian order.
167  */
168 #define CHANGE_ORDER(EBUF, EORDER, ESIZE)                                                       \
169 {                                                                                               \
170     unsigned int m;                                                                             \
171     if (H5T_ORDER_BE==EORDER) {                                                                 \
172         unsigned char mediator;                                                                 \
173         size_t half_size = ESIZE/2;                                                             \
174         for (m=0; m<half_size; m++) {                                                           \
175             mediator = EBUF[ESIZE-(m+1)];                                                       \
176             EBUF[ESIZE-(m+1)] = EBUF[m];                                                        \
177             EBUF[m] = mediator;                                                                 \
178         }                                                                                       \
179     } else if (H5T_ORDER_VAX==EORDER) {                                                         \
180         unsigned char mediator1, mediator2;                                                     \
181         for (m = 0; m < ESIZE; m += 4) {                                                        \
182             mediator1 = EBUF[m];                                                                \
183             mediator2 = EBUF[m+1];                                                              \
184                                                                                                 \
185             EBUF[m] = EBUF[(ESIZE-2)-m];                                                        \
186             EBUF[m+1] = EBUF[(ESIZE-1)-m];                                                      \
187                                                                                                 \
188             EBUF[(ESIZE-2)-m] = mediator1;                                                      \
189             EBUF[(ESIZE-1)-m] = mediator2;                                                      \
190         }                                                                                       \
191     }                                                                                           \
192 }
193 
194 /* Allocate buffer and initialize it with floating-point normalized values.
195  * It's for conversion test of floating-point as the source.
196  */
197 #define INIT_FP_NORM(TYPE, SRC_MAX, SRC_MIN, SRC_MAX_10_EXP, SRC_MIN_10_EXP, SRC_SIZE,          \
198                 DST_SIZE, BUF, SAVED, NELMTS)                                                   \
199 {                                                                                               \
200     unsigned char *buf_p, *saved_p;                                                             \
201     size_t num_norm, factor, n;                                                                 \
202     TYPE value1, value2;                                                                        \
203     TYPE multiply;                                                                              \
204                                                                                                 \
205     /*Determine the number of normalized values and increment pace.  The values start from      \
206      *minimal normalized value and are multiplied by MULTIPLY each step until reach to maximal  \
207      *normalized value.*/                                                                       \
208     if(SRC_MAX_10_EXP<100) { /*for float*/                                                      \
209         factor = 0;                                                                             \
210         multiply = 10;                                                                          \
211     } else if(SRC_MAX_10_EXP>=100 && SRC_MAX_10_EXP<400) { /*for double*/                       \
212         factor = 2;                                                                             \
213         multiply = 10000;                                                                       \
214     } else { /*for long double*/                                                                \
215         factor = 3;                                                                             \
216         multiply = 100000000;                                                                   \
217     }                                                                                           \
218                                                                                                 \
219     /*The number of values if multiplied by 10 for each step.*/                                 \
220     num_norm =  (SRC_MAX_10_EXP - SRC_MIN_10_EXP);                                              \
221     /*Reduce the number of values by 2^factor. MULTIPLY=10^(2^factor). Using this algorithm     \
222      *instead of arithmatic operation to avoid any conversion*/                                 \
223     num_norm >>= factor;                                                                        \
224                                                                                                 \
225     /*Total number of values*/                                                                  \
226     NELMTS  = 2 *                      /*both positive and negative*/                           \
227                 (num_norm +            /*number of normalized values*/                          \
228                  1);                   /*maximal normalized value*/                             \
229                                                                                                 \
230     /* Allocate buffers */                                                                      \
231     BUF = (unsigned char*)aligned_malloc(NELMTS*MAX(SRC_SIZE, DST_SIZE));                       \
232     SAVED = (unsigned char*)aligned_malloc(NELMTS*MAX(SRC_SIZE, DST_SIZE));                     \
233     HDmemset(BUF, 0, NELMTS*MAX(SRC_SIZE, DST_SIZE));                                           \
234     HDmemset(SAVED, 0, NELMTS*MAX(SRC_SIZE, DST_SIZE));                                         \
235                                                                                                 \
236     buf_p = BUF;                                                                                \
237     saved_p = SAVED;                                                                            \
238                                                                                                 \
239     /*Normalized values*/                                                                       \
240     value1 = SRC_MIN;                                                                           \
241     value2 = -SRC_MIN;                                                                          \
242     for(n=0; n<num_norm; n++) {                                                                 \
243         if(value1<SRC_MAX) { /*positive*/                                                       \
244             HDmemcpy(buf_p, &value1, SRC_SIZE);                                                 \
245             HDmemcpy(saved_p, &value1, SRC_SIZE);                                               \
246             value1 *= multiply;                                                                 \
247             buf_p += SRC_SIZE;                                                                  \
248             saved_p += SRC_SIZE;                                                                \
249         }                                                                                       \
250         if(value2>-SRC_MAX) { /*negative*/                                                      \
251             HDmemcpy(buf_p, &value2, SRC_SIZE);                                                 \
252             HDmemcpy(saved_p, &value2, SRC_SIZE);                                               \
253             value2 *= multiply;                                                                 \
254             buf_p += SRC_SIZE;                                                                  \
255             saved_p += SRC_SIZE;                                                                \
256         }                                                                                       \
257     }                                                                                           \
258                                                                                                 \
259     value1 = SRC_MAX;                              /*maximal value*/                            \
260     HDmemcpy(buf_p, &value1, SRC_SIZE);                                                         \
261     HDmemcpy(saved_p, &value1, SRC_SIZE);                                                       \
262     buf_p += SRC_SIZE;                                                                          \
263     saved_p += SRC_SIZE;                                                                        \
264                                                                                                 \
265     value2 = -SRC_MAX;                             /*negative value*/                           \
266     HDmemcpy(buf_p, &value2, SRC_SIZE);                                                         \
267     HDmemcpy(saved_p, &value2, SRC_SIZE);                                                       \
268     buf_p += SRC_SIZE;                                                                          \
269     saved_p += SRC_SIZE;                                                                        \
270 }
271 
272 /* Allocate buffer and initialize it with floating-point denormalized values.
273  * It's for conversion test of floating-point as the source.
274  */
275 #define INIT_FP_DENORM(TYPE, SRC_MANT_DIG, SRC_SIZE, SRC_PREC, SRC_ORDR, DST_SIZE,              \
276                        BUF, SAVED, NELMTS)                                                      \
277 {                                                                                               \
278     unsigned char *buf_p, *saved_p;                                                             \
279     unsigned char *tmp1, *tmp2;                                                                 \
280     size_t n;                                                                                   \
281                                                                                                 \
282     /*Total number of values*/                                                                  \
283     NELMTS  = 2 *                      /*both positive and negative*/                           \
284                 (SRC_MANT_DIG - 1);    /*number of denormalized values*/                        \
285                                                                                                 \
286     /* Allocate buffers */                                                                      \
287     BUF = (unsigned char*)aligned_malloc(NELMTS*MAX(SRC_SIZE, DST_SIZE));                       \
288     SAVED = (unsigned char*)aligned_malloc(NELMTS*MAX(SRC_SIZE, DST_SIZE));                     \
289     HDmemset(BUF, 0, NELMTS*MAX(SRC_SIZE, DST_SIZE));                                           \
290     HDmemset(SAVED, 0, NELMTS*MAX(SRC_SIZE, DST_SIZE));                                         \
291                                                                                                 \
292     tmp1 = (unsigned char*)HDcalloc((size_t)1, (size_t)SRC_SIZE);                               \
293     tmp2 = (unsigned char*)HDcalloc((size_t)1, (size_t)SRC_SIZE);                               \
294                                                                                                 \
295     buf_p = BUF;                                                                                \
296     saved_p = SAVED;                                                                            \
297                                                                                                 \
298     /*Denormalized values. Exponent is 0. Let mantissa starts from 00000001, 00000011,          \
299      *00000111,..., until 11111111.*/                                                           \
300     HDmemset(tmp1, 0, SRC_SIZE);                                                                \
301     HDmemset(tmp2, 0, SRC_SIZE);                                                                \
302     H5T__bit_set (tmp2, SRC_PREC-1, (size_t)1, TRUE);       /*the negative value*/              \
303     for(n=0; n<SRC_MANT_DIG-1; n++) {                                                           \
304         H5T__bit_set (tmp1, n, (size_t)1, TRUE);            /*turn on 1 bit each time*/         \
305         CHANGE_ORDER(tmp1, SRC_ORDR, SRC_SIZE);    /*change order for big endian*/              \
306         HDmemcpy(buf_p, tmp1, SRC_SIZE);                                                        \
307         HDmemcpy(saved_p, tmp1, SRC_SIZE);                                                      \
308         CHANGE_ORDER(tmp1, SRC_ORDR, SRC_SIZE);    /*change back the order for bit operation*/  \
309         buf_p += SRC_SIZE;                                                                      \
310         saved_p += SRC_SIZE;                                                                    \
311                                                                                                 \
312         /*negative values*/                                                                     \
313         H5T__bit_set (tmp2, n, (size_t)1, TRUE);                                                \
314         CHANGE_ORDER(tmp2, SRC_ORDR, SRC_SIZE);                                                 \
315         HDmemcpy(buf_p, tmp2, SRC_SIZE);                                                        \
316         HDmemcpy(saved_p, tmp2, SRC_SIZE);                                                      \
317         CHANGE_ORDER(tmp2, SRC_ORDR, SRC_SIZE);                                                 \
318         buf_p += SRC_SIZE;                                                                      \
319         saved_p += SRC_SIZE;                                                                    \
320     }                                                                                           \
321     HDfree(tmp1);                                                                               \
322     HDfree(tmp2);                                                                               \
323 }
324 
325 /* Allocate buffer and initialize it with floating-point special values, +/-0, +/-infinity,
326  * +/-QNaN, +/-SNaN.  It's for conversion test of floating-point as the source.
327  */
328 #define INIT_FP_SPECIAL(SRC_SIZE, SRC_PREC, SRC_ORDR, SRC_MANT_DIG, DST_SIZE,                   \
329             BUF, SAVED, NELMTS)                                                                 \
330 {                                                                                               \
331     unsigned char *buf_p;                                                                       \
332     unsigned char *value;                                                                       \
333     int n;                                                                                      \
334                                                                                                 \
335     /*Total number of values*/                                                                  \
336     NELMTS  = 2 *                      /*both positive and negative*/                           \
337                 4;                     /*infinity, SNaN, QNaN      */                           \
338                                                                                                 \
339     /* Allocate buffers */                                                                      \
340     BUF = (unsigned char*)aligned_malloc(NELMTS*MAX(SRC_SIZE, DST_SIZE));                       \
341     SAVED = (unsigned char*)aligned_malloc( NELMTS*MAX(SRC_SIZE, DST_SIZE));                    \
342     HDmemset(BUF, 0, NELMTS*MAX(SRC_SIZE, DST_SIZE));                                           \
343     HDmemset(SAVED, 0, NELMTS*MAX(SRC_SIZE, DST_SIZE));                                         \
344     value = (unsigned char*)HDcalloc(SRC_SIZE, sizeof(unsigned char));                          \
345                                                                                                 \
346     buf_p = BUF;                                                                                \
347                                                                                                 \
348     /* +0 */                                                                                    \
349     H5T__bit_set(value, (size_t)0, SRC_PREC, FALSE);                                            \
350     HDmemcpy(buf_p, value, SRC_SIZE*sizeof(unsigned char));                                     \
351     buf_p += SRC_SIZE;                                                                          \
352                                                                                                 \
353     for(n=0; n<2; n++) {                                                                        \
354         if(n==1) {                                                                              \
355             memset(value, 0, SRC_SIZE*sizeof(unsigned char));                                   \
356             /* -0 */                                                                            \
357             H5T__bit_set(value, (size_t)(SRC_PREC - 1), (size_t)1, TRUE);                       \
358             CHANGE_ORDER(value, SRC_ORDR, SRC_SIZE);/*change order for big endian*/             \
359             HDmemcpy(buf_p, value, SRC_SIZE*sizeof(unsigned char));                             \
360             CHANGE_ORDER(value, SRC_ORDR, SRC_SIZE);/*change back the order for bit operation*/ \
361             buf_p += SRC_SIZE;                                                                  \
362         }                                                                                       \
363                                                                                                 \
364         /* +/-infinity */                                                                       \
365         H5T__bit_set(value, (size_t)(SRC_MANT_DIG - 1), SRC_PREC-SRC_MANT_DIG, TRUE);           \
366         CHANGE_ORDER(value, SRC_ORDR, SRC_SIZE);    /*change order for big endian*/             \
367         HDmemcpy(buf_p, value, SRC_SIZE*sizeof(unsigned char));                                 \
368         CHANGE_ORDER(value, SRC_ORDR, SRC_SIZE);    /*change back the order for bit operation*/ \
369         buf_p += SRC_SIZE;                                                                      \
370                                                                                                 \
371         /* +/-SNaN */                                                                           \
372         H5T__bit_set(value, (size_t)0, (size_t)1, TRUE);                                        \
373         CHANGE_ORDER(value, SRC_ORDR, SRC_SIZE);    /*change order for big endian*/             \
374         HDmemcpy(buf_p, value, SRC_SIZE * sizeof(unsigned char));                               \
375         CHANGE_ORDER(value, SRC_ORDR, SRC_SIZE);    /*change back the order for bit operation*/ \
376         buf_p += SRC_SIZE;                                                                      \
377                                                                                                 \
378         /* +/-QNaN */                                                                           \
379         H5T__bit_set(value, (size_t)(SRC_MANT_DIG - 2), (size_t)1, TRUE);                       \
380         CHANGE_ORDER(value, SRC_ORDR, SRC_SIZE);    /*change order for big endian*/             \
381         HDmemcpy(buf_p, value, SRC_SIZE*sizeof(unsigned char));                                 \
382         CHANGE_ORDER(value, SRC_ORDR, SRC_SIZE);    /*change back the order for bit operation*/ \
383         buf_p += SRC_SIZE;                                                                      \
384     }                                                                                           \
385                                                                                                 \
386     HDmemcpy(SAVED, BUF, NELMTS*MAX(SRC_SIZE, DST_SIZE));                                       \
387     HDfree(value);                                                                              \
388 }
389 
390 void some_dummy_func(float x);
391 static hbool_t overflows(unsigned char *origin_bits, hid_t src_id, size_t dst_num_bits);
392 static int my_isnan(dtype_t type, void *val);
393 static int my_isinf(int endian, unsigned char *val, size_t size,
394         size_t mpos, size_t msize, size_t epos, size_t esize);
395 
396 /*-------------------------------------------------------------------------
397  * Function:    fpe_handler
398  *
399  * Purpose:    Exit with 255
400  *
401  * Return:    void
402  *
403  * Programmer:    Robb Matzke
404  *              Monday, July  6, 1998
405  *
406  * Modifications:
407  *
408  *-------------------------------------------------------------------------
409  */
410 static void
fpe_handler(int H5_ATTR_UNUSED signo)411 fpe_handler(int H5_ATTR_UNUSED signo)
412 {
413     SKIPPED();
414     HDputs("    Test skipped due to SIGFPE.");
415 #ifndef HANDLE_SIGFPE
416     HDputs("    Remaining tests could not be run.");
417     HDputs("    Please turn off SIGFPE on overflows and try again.");
418 #endif
419     HDexit(255);
420 }
421 
422 
423 /*-------------------------------------------------------------------------
424  * Function:    reset_hdf5
425  *
426  * Purpose:    Reset the hdf5 library.  This causes statistics to be printed
427  *        and counters to be reset.
428  *
429  * Return:    void
430  *
431  * Programmer:    Robb Matzke
432  *              Monday, November 16, 1998
433  *
434  * Modifications:
435  *
436  *-------------------------------------------------------------------------
437  */
438 static void
reset_hdf5(void)439 reset_hdf5(void)
440 {
441     h5_reset();
442 
443     if (without_hardware_g) h5_no_hwconv();
444 #ifdef TEST_ALIGNMENT
445     SET_ALIGNMENT(SCHAR,   H5_SIZEOF_CHAR);
446     SET_ALIGNMENT(UCHAR,   H5_SIZEOF_CHAR);
447     SET_ALIGNMENT(SHORT,   H5_SIZEOF_SHORT);
448     SET_ALIGNMENT(USHORT,  H5_SIZEOF_SHORT);
449     SET_ALIGNMENT(INT,     H5_SIZEOF_INT);
450     SET_ALIGNMENT(UINT,    H5_SIZEOF_INT);
451     SET_ALIGNMENT(LONG,    H5_SIZEOF_LONG);
452     SET_ALIGNMENT(ULONG,   H5_SIZEOF_LONG);
453     SET_ALIGNMENT(LLONG,   H5_SIZEOF_LONG_LONG);
454     SET_ALIGNMENT(ULLONG,  H5_SIZEOF_LONG_LONG);
455     SET_ALIGNMENT(FLOAT,   H5_SIZEOF_FLOAT);
456     SET_ALIGNMENT(DOUBLE,  H5_SIZEOF_DOUBLE);
457 #if H5_SIZEOF_LONG_DOUBLE !=0
458     SET_ALIGNMENT(LDOUBLE, H5_SIZEOF_LONG_DOUBLE);
459 #endif
460 #endif
461 
462 }
463 
464 
465 /*-------------------------------------------------------------------------
466  * Function:    except_func
467  *
468  * Purpose:    Gets called for all data type conversion exceptions.
469  *
470  * Return:    H5T_CONV_ABORT:            -1
471  *
472  *              H5T_CONV_UNHANDLED      0
473  *
474  *              H5T_CONV_HANDLED        1
475  *
476  * Programmer:    Raymond Lu
477  *              April 19, 2004
478  *
479  * Modifications:
480  *
481  *-------------------------------------------------------------------------
482  */
483 static H5T_conv_ret_t
except_func(H5T_conv_except_t except_type,hid_t H5_ATTR_UNUSED src_id,hid_t H5_ATTR_UNUSED dst_id,void H5_ATTR_UNUSED * src_buf,void * dst_buf,void * user_data)484 except_func(H5T_conv_except_t except_type, hid_t H5_ATTR_UNUSED src_id, hid_t H5_ATTR_UNUSED dst_id, void H5_ATTR_UNUSED *src_buf,
485         void *dst_buf, void *user_data)
486 {
487     H5T_conv_ret_t      ret = H5T_CONV_HANDLED;
488 
489     if(except_type == H5T_CONV_EXCEPT_RANGE_HI)
490         /*only test integer case*/
491         *(int*)dst_buf = *(int*)user_data;
492     else if(except_type == H5T_CONV_EXCEPT_RANGE_LOW)
493         /*only test integer case*/
494         *(int*)dst_buf = *(int*)user_data;
495     else if(except_type == H5T_CONV_EXCEPT_TRUNCATE)
496         ret = H5T_CONV_UNHANDLED;
497     else if(except_type == H5T_CONV_EXCEPT_PRECISION)
498         ret = H5T_CONV_UNHANDLED;
499     else if(except_type == H5T_CONV_EXCEPT_PINF)
500         /*only test integer case*/
501         *(int*)dst_buf = *(int*)user_data;
502     else if(except_type == H5T_CONV_EXCEPT_NINF)
503         /*only test integer case*/
504         *(int*)dst_buf = *(int*)user_data;
505     else if(except_type == H5T_CONV_EXCEPT_NAN)
506         /*only test integer case*/
507         *(int*)dst_buf = *(int*)user_data;
508 
509     return ret;
510 }
511 
512 
513 /*-------------------------------------------------------------------------
514  * Function:    some_dummy_func
515  *
516  * Purpose:    A dummy function to help check for overflow.
517  *
518  * Note:    DO NOT DECLARE THIS FUNCTION STATIC OR THE COMPILER MIGHT
519  *        PROMOTE ARGUMENT `x' TO DOUBLE AND DEFEAT THE OVERFLOW
520  *        CHECKING.
521  *
522  * Return:    void
523  *
524  * Programmer:    Robb Matzke
525  *              Tuesday, July 21, 1998
526  *
527  *-------------------------------------------------------------------------
528  */
529 void
some_dummy_func(float x)530 some_dummy_func(float x)
531 {
532     char    s[128];
533 
534     HDsnprintf(s, sizeof(s), "%g", (double)x);
535 }
536 
537 
538 /*-------------------------------------------------------------------------
539  * Function:    generates_sigfpe
540  *
541  * Purpose:    Determines if SIGFPE is generated from overflows.  We must be
542  *        able to fork() and waitpid() in order for this test to work
543  *        properly.  Sets skip_overflow_tests_g to non-zero if they
544  *        would generate SIGBUS, zero otherwise.
545  *
546  * Programmer:    Robb Matzke
547  *              Tuesday, July 21, 1998
548  *
549  * Modifications:
550  *
551  *-------------------------------------------------------------------------
552  */
553 static void
generates_sigfpe(void)554 generates_sigfpe(void)
555 {
556 #if defined(H5_HAVE_FORK) && defined(H5_HAVE_WAITPID)
557     pid_t    pid;
558     int        status;
559     size_t    i, j;
560     double    d;
561     unsigned char *dp = (unsigned char*)&d;
562     float    f;
563 
564     HDfflush(stdout);
565     HDfflush(stderr);
566     if ((pid=fork()) < 0) {
567     HDperror("fork");
568     HDexit(EXIT_FAILURE);
569     } else if (0==pid) {
570     for (i=0; i<2000; i++) {
571         for(j = 0; j < sizeof(double); j++)
572                 dp[j] = (unsigned char)HDrand();
573         f = (float)d;
574         some_dummy_func((float)f);
575     }
576     HDexit(EXIT_SUCCESS);
577     }
578 
579     while (pid!=waitpid(pid, &status, 0))
580         /*void*/;
581     if (WIFEXITED(status) && 0==WEXITSTATUS(status)) {
582     HDputs("Floating-point overflow cases will be tested.");
583     skip_overflow_tests_g = FALSE;
584     } else if (WIFSIGNALED(status) && SIGFPE==WTERMSIG(status)) {
585     HDputs("Floating-point overflow cases cannot be safely tested.");
586     skip_overflow_tests_g = TRUE;
587     /* delete the core dump file that SIGFPE may have created */
588     HDunlink("core");
589     }
590 #else
591     HDputs("Cannot determine if floating-point overflows generate a SIGFPE;");
592     HDputs("assuming yes.");
593     HDputs("Overflow cases will not be tested.");
594     skip_overflow_tests_g = TRUE;
595 #endif
596 }
597 
598 
599 /*-------------------------------------------------------------------------
600  * Function:    test_hard_query
601  *
602  * Purpose:     Tests H5Tcompiler_conv() for querying whether a conversion is
603  *              a hard one.
604  *
605  * Return:      Success:        0
606  *
607  *              Failure:        number of errors
608  *
609  * Programmer:  Raymond Lu
610  *              Friday, Sept 2, 2005
611  *
612  * Modifications:
613  *
614  *-------------------------------------------------------------------------
615  */
616 static int
test_hard_query(void)617 test_hard_query(void)
618 {
619     TESTING("query functions of compiler conversion");
620 
621     /* Verify the conversion from int to float is a hard conversion. */
622     if(H5Tcompiler_conv(H5T_NATIVE_INT, H5T_NATIVE_FLOAT) != TRUE) {
623         H5_FAILED();
624         HDprintf("Can't query conversion function\n");
625         goto error;
626     }
627 
628     /* Unregister the hard conversion from int to float.  Verify the conversion
629      * is a soft conversion. */
630     H5Tunregister(H5T_PERS_HARD, NULL, H5T_NATIVE_INT, H5T_NATIVE_FLOAT, (H5T_conv_t)((void (*) (void))H5T__conv_int_float));
631     if(H5Tcompiler_conv(H5T_NATIVE_INT, H5T_NATIVE_FLOAT) != FALSE) {
632         H5_FAILED();
633         HDprintf("Can't query conversion function\n");
634         goto error;
635     }
636 
637     /* Register the hard conversion from int to float.  Verify the conversion
638      * is a hard conversion. */
639     H5Tregister(H5T_PERS_HARD, "int_flt", H5T_NATIVE_INT, H5T_NATIVE_FLOAT, (H5T_conv_t)((void (*) (void))H5T__conv_int_float));
640     if(H5Tcompiler_conv(H5T_NATIVE_INT, H5T_NATIVE_FLOAT) != TRUE) {
641         H5_FAILED();
642         HDprintf("Can't query conversion function\n");
643         goto error;
644     }
645 
646     PASSED();
647 
648     /* Restore the default error handler (set in h5_reset()) */
649     h5_restore_err();
650 
651     reset_hdf5();
652 
653     return 0;
654 
655 error:
656     /* Restore the default error handler (set in h5_reset()) */
657     h5_restore_err();
658 
659     reset_hdf5();
660     return 1;
661 }
662 
663 
664 /*-------------------------------------------------------------------------
665  * Function:    expt_handle
666  *
667  * Purpose:    Gets called from test_particular_fp_integer() for data type
668  *              conversion exceptions.
669  *
670  * Return:    H5T_CONV_HANDLED        1
671  *
672  * Programmer:    Raymond Lu
673  *              Sept 7, 2005
674  *
675  * Modifications:
676  *
677  *-------------------------------------------------------------------------
678  */
679 static H5T_conv_ret_t
expt_handle(H5T_conv_except_t except_type,hid_t H5_ATTR_UNUSED src_id,hid_t H5_ATTR_UNUSED dst_id,void H5_ATTR_UNUSED * src_buf,void * dst_buf,void * user_data)680 expt_handle(H5T_conv_except_t except_type, hid_t H5_ATTR_UNUSED src_id, hid_t H5_ATTR_UNUSED dst_id, void H5_ATTR_UNUSED *src_buf,
681         void *dst_buf, void *user_data)
682 {
683     signed char         fill_value1 = 7;
684     int                 fill_value2 = 13;
685 
686     if(except_type == H5T_CONV_EXCEPT_RANGE_HI || except_type == H5T_CONV_EXCEPT_RANGE_LOW ||
687             except_type == H5T_CONV_EXCEPT_TRUNCATE) {
688         if(*(hbool_t*)user_data)
689             *(signed char*)dst_buf = fill_value1;
690         else
691             *(int*)dst_buf = fill_value2;
692     } /* end if */
693 
694     return H5T_CONV_HANDLED;
695 }
696 
697 
698 /*-------------------------------------------------------------------------
699  * Function:    test_particular_fp_integer
700  *
701  * Purpose:     Tests hard conversions from floating numbers to integers in
702  *              a special situation when the source is "float" and assigned
703  *              the value of "INT_MAX".  A compiler may do roundup making
704  *              this value "INT_MAX+1".  When this float value is casted to
705  *              int, overflow happens.  This test makes sure the library
706  *              returns exception in this situation.
707  *
708  *              Also verifies the library handles conversion from double to
709  *              signed char correctly when the value of double is SCHAR_MAX.
710  *              The test makes sure the signed char doesn't overflow.
711  *
712  *              This test is mainly for netCDF's request.
713  *
714  * Return:      Success:        0
715  *
716  *              Failure:        number of errors
717  *-------------------------------------------------------------------------
718  */
test_particular_fp_integer(void)719 static int test_particular_fp_integer(void)
720 {
721     hid_t       dxpl_id;
722     hbool_t     flag;
723     double      src_d = (double)SCHAR_MAX;
724     signed char dst_c;
725     unsigned char *buf1 = NULL, *buf2 = NULL;
726     unsigned char *saved_buf1 = NULL, *saved_buf2 = NULL;
727     size_t      src_size1, src_size2;
728     size_t      dst_size1, dst_size2;
729     float       src_f = (float)INT_MAX;
730     int         dst_i;
731     int         fill_value = 13;
732     int         endian;            /*endianess            */
733     unsigned int        fails_this_test = 0;
734     size_t      j;
735 
736     TESTING("hard particular floating number -> integer conversions");
737 
738     if((dxpl_id = H5Pcreate(H5P_DATASET_XFER)) < 0) {
739         H5_FAILED();
740         HDprintf("Can't create data transfer property list\n");
741         goto error;
742     }
743 
744     /* Test conversion from double (the value is SCHAR_MAX) to signed char. */
745     endian = H5Tget_order(H5T_NATIVE_DOUBLE);
746     src_size1 = H5Tget_size(H5T_NATIVE_DOUBLE);
747     dst_size1 = H5Tget_size(H5T_NATIVE_SCHAR);
748     buf1 = (unsigned char*)HDcalloc((size_t)1, (size_t)MAX(src_size1, dst_size1));
749     saved_buf1 = (unsigned char*)HDcalloc((size_t)1, (size_t)MAX(src_size1, dst_size1));
750 
751     HDmemcpy(buf1, &src_d, src_size1);
752     HDmemcpy(saved_buf1, &src_d, src_size1);
753 
754     /* Register exception handling function and signal the destination is "signed char". */
755     flag = 1;
756     if(H5Pset_type_conv_cb(dxpl_id, expt_handle, &flag) < 0) {
757         H5_FAILED();
758         HDprintf("Can't register conversion callback\n");
759         goto error;
760     }
761 
762     /* Do conversion */
763     if(H5Tconvert(H5T_NATIVE_DOUBLE, H5T_NATIVE_SCHAR, (size_t)1, buf1, NULL, dxpl_id) < 0) {
764         H5_FAILED();
765         HDprintf("Can't convert data\n");
766         goto error;
767     }
768 
769     HDmemcpy(&dst_c, buf1, dst_size1);
770 
771     /* Print errors */
772     if(dst_c != SCHAR_MAX) {
773         double x;
774         signed char   y;
775 
776         if(0 == fails_this_test++)
777             H5_FAILED();
778 
779         HDprintf("    test double to signed char:\n");
780         HDprintf("        src = ");
781         for (j=0; j<src_size1; j++)
782             HDprintf(" %02x", saved_buf1[ENDIAN(src_size1, j, endian)]);
783 
784         HDmemcpy(&x, saved_buf1, src_size1);
785         HDprintf(" %29.20e\n", x);
786 
787         HDprintf("        dst = ");
788         for (j=0; j<dst_size1; j++)
789             HDprintf(" %02x", buf1[ENDIAN(dst_size1, j, endian)]);
790 
791         HDmemcpy(&y, buf1, dst_size1);
792         HDprintf(" %29d\n", y);
793     }
794 
795     /* Test conversion from float (the value is INT_MAX) to int. */
796     src_size2 = H5Tget_size(H5T_NATIVE_FLOAT);
797     dst_size2 = H5Tget_size(H5T_NATIVE_INT);
798     buf2 = (unsigned char*)HDcalloc((size_t)1, (size_t)MAX(src_size2, dst_size2));
799     saved_buf2 = (unsigned char*)HDcalloc((size_t)1, (size_t)MAX(src_size2, dst_size2));
800     HDmemcpy(buf2, &src_f, src_size2);
801     HDmemcpy(saved_buf2, &src_f, src_size2);
802 
803     /* signal exception handling function that the destination is "int". */
804     flag = 0;
805 
806     /* Do conversion */
807     if(H5Tconvert(H5T_NATIVE_FLOAT, H5T_NATIVE_INT, (size_t)1, buf2, NULL, dxpl_id) < 0) {
808         H5_FAILED();
809         HDprintf("Can't convert data\n");
810         goto error;
811     }
812 
813     HDmemcpy(&dst_i, buf2, dst_size2);
814 
815     /* Print errors */
816     if(dst_i != fill_value) {
817         float x;
818         int   y;
819 
820         if(0 == fails_this_test++)
821             H5_FAILED();
822 
823         HDprintf("    test float to int:\n");
824         HDprintf("        src = ");
825         for (j=0; j<src_size2; j++)
826             HDprintf(" %02x", saved_buf2[ENDIAN(src_size2, j, endian)]);
827 
828         HDmemcpy(&x, saved_buf2, src_size2);
829         HDprintf(" %29.20e\n", (double)x);
830 
831         HDprintf("        dst = ");
832         for (j=0; j<dst_size2; j++)
833             HDprintf(" %02x", buf2[ENDIAN(dst_size2, j, endian)]);
834 
835         HDmemcpy(&y, buf2, dst_size2);
836         HDprintf(" %29d\n", y);
837     }
838 
839     if(fails_this_test)
840         goto error;
841 
842     if(H5Pclose(dxpl_id) < 0) {
843         H5_FAILED();
844         HDprintf("Can't close property list\n");
845         goto error;
846     }
847 
848     if(buf1)
849         HDfree(buf1);
850     if(buf2)
851         HDfree(buf2);
852     if(saved_buf1)
853         HDfree(saved_buf1);
854     if(saved_buf2)
855         HDfree(saved_buf2);
856 
857     PASSED();
858     return 0;
859 
860 error:
861     HDfflush(stdout);
862     H5E_BEGIN_TRY {
863         H5Pclose(dxpl_id);
864     } H5E_END_TRY;
865     if(buf1)
866         HDfree(buf1);
867     if(buf2)
868         HDfree(buf2);
869     if(saved_buf1)
870         HDfree(saved_buf1);
871     if(saved_buf2)
872         HDfree(saved_buf2);
873 
874     /* Restore the default error handler (set in h5_reset()) */
875     h5_restore_err();
876 
877     reset_hdf5(); /*print statistics*/
878 
879     return MAX((int)fails_this_test, 1);
880 }
881 
882 
883 /*-------------------------------------------------------------------------
884  * Function:    test_derived_flt
885  *
886  * Purpose:     Tests user-define and query functions of floating-point types.
887  *
888  * Return:      Success:        0
889  *
890  *              Failure:        number of errors
891  *
892  * Programmer:  Raymond Lu
893  *              Thursday, Jan 6, 2005
894  *
895  * Modifications:
896  *
897  *-------------------------------------------------------------------------
898  */
899 static int
test_derived_flt(void)900 test_derived_flt(void)
901 {
902     hid_t       file=-1, tid1=-1, tid2=-1;
903     hid_t       dxpl_id=-1;
904     char        filename[1024];
905     size_t      spos, epos, esize, mpos, msize, size;
906     size_t      src_size, dst_size;
907     unsigned char        *buf=NULL, *saved_buf=NULL;
908     int         *aligned=NULL;
909     int        endian;            /*endianess            */
910     size_t      nelmts = NTESTELEM;
911     unsigned int        fails_this_test = 0;
912     const size_t    max_fails=40;    /*max number of failures*/
913     char    str[256];        /*message string    */
914     unsigned int         i, j;
915 
916     TESTING("user-define and query functions of floating-point types");
917 
918     /* Create File */
919     h5_fixname(FILENAME[0], H5P_DEFAULT, filename, sizeof filename);
920     if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
921         H5_FAILED();
922         HDprintf("Can't create file\n");
923         goto error;
924     }
925 
926     if((dxpl_id = H5Pcreate(H5P_DATASET_XFER)) < 0) {
927         H5_FAILED();
928         HDprintf("Can't create data transfer property list\n");
929         goto error;
930     }
931 
932     if((tid1 = H5Tcopy(H5T_IEEE_F64LE)) < 0) {
933         H5_FAILED();
934         HDprintf("Can't copy data type\n");
935         goto error;
936     }
937 
938     if((tid2 = H5Tcopy(H5T_IEEE_F32LE)) < 0) {
939         H5_FAILED();
940         HDprintf("Can't copy data type\n");
941         goto error;
942     }
943 
944     /*------------------------------------------------------------------------
945      *                   1st floating-point type
946      * size=7 byte, precision=42 bits, offset=3 bits, mantissa size=31 bits,
947      * mantissa position=3, exponent size=10 bits, exponent position=34,
948      * exponent bias=511.  It can be illustrated in little-endian order as
949      *
950      *          6       5       4       3       2       1       0
951      *    ???????? ???SEEEE EEEEEEMM MMMMMMMM MMMMMMMM MMMMMMMM MMMMM???
952      *
953      * To create a new floating-point type, the following properties must be
954      * set in the order of
955      *   set fields -> set offset -> set precision -> set size.
956      * All these properties must be set before the type can function. Other
957      * properties can be set anytime.  Derived type size cannot be expanded
958      * bigger than original size but can be decreased.  There should be no
959      * holes among the significant bits.  Exponent bias usually is set
960      * 2^(n-1)-1, where n is the exponent size.
961      *-----------------------------------------------------------------------*/
962     if(H5Tset_fields(tid1, (size_t)44, (size_t)34, (size_t)10, (size_t)3, (size_t)31) < 0) {
963         H5_FAILED();
964         HDprintf("Can't set fields\n");
965         goto error;
966     }
967     if(H5Tset_offset(tid1, (size_t)3) < 0) {
968         H5_FAILED();
969         HDprintf("Can't set offset\n");
970         goto error;
971     }
972     if(H5Tset_precision(tid1, (size_t)42) < 0) {
973         H5_FAILED();
974         HDprintf("Can't set precision 1\n");
975         goto error;
976     }
977     if(H5Tset_size(tid1, (size_t)7) < 0) {
978         H5_FAILED();
979         HDprintf("Can't set size\n");
980         goto error;
981     }
982 
983     if(H5Tset_ebias(tid1, (size_t)511) < 0) {
984         H5_FAILED();
985         HDprintf("Can't set exponent bias\n");
986         goto error;
987     }
988     if(H5Tset_pad(tid1, H5T_PAD_ZERO, H5T_PAD_ZERO) < 0) {
989         H5_FAILED();
990         HDprintf("Can't set padding\n");
991         goto error;
992     }
993 
994     if(H5Tcommit2(file, "new float type 1", tid1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) < 0) {
995         H5_FAILED();
996         HDprintf("Can't set inpad\n");
997         goto error;
998     }
999     if(H5Tclose(tid1) < 0) {
1000         H5_FAILED();
1001         HDprintf("Can't close datatype\n");
1002         goto error;
1003     }
1004 
1005     if((tid1 = H5Topen2(file, "new float type 1", H5P_DEFAULT)) < 0)
1006         FAIL_PUTS_ERROR("Can't open datatype")
1007     if(H5Tget_fields(tid1, &spos, &epos, &esize, &mpos, &msize) < 0) {
1008         H5_FAILED();
1009         HDprintf("Can't get fields\n");
1010         goto error;
1011     }
1012     if(spos != 44 || epos != 34 || esize != 10 || mpos != 3 || msize != 31) {
1013         H5_FAILED();
1014         HDprintf("Wrong field values\n");
1015         goto error;
1016     }
1017 
1018     if(H5Tget_precision(tid1) != 42) {
1019         H5_FAILED();
1020         HDprintf("Can't get precision or wrong precision\n");
1021         goto error;
1022     }
1023     if(H5Tget_offset(tid1)!=3) {
1024         H5_FAILED();
1025         HDprintf("Can't get offset or wrong offset\n");
1026         goto error;
1027     }
1028     if((size = H5Tget_size(tid1))!=7) {
1029         H5_FAILED();
1030         HDprintf("Can't get size or wrong size\n");
1031         goto error;
1032     }
1033     if(H5Tget_ebias(tid1)!=511) {
1034         H5_FAILED();
1035         HDprintf("Can't get exponent bias or wrong bias\n");
1036         goto error;
1037     }
1038 
1039     /* Convert data from native integer to the 1st derived floating-point type.
1040      * Then convert data from the floating-point type back to native integer.
1041      * Compare the final data with the original data.
1042      */
1043     src_size = H5Tget_size(H5T_NATIVE_INT);
1044     endian = H5Tget_order(H5T_NATIVE_INT);
1045     buf = (unsigned char *)HDmalloc(nelmts * (MAX(src_size, size)));
1046     saved_buf = (unsigned char *)HDmalloc(nelmts * src_size);
1047     HDmemset(buf, 0, nelmts * MAX(src_size, size));
1048     HDmemset(saved_buf, 0, nelmts * src_size);
1049     aligned = (int *)HDcalloc((size_t)1, src_size);
1050 
1051     for(i = 0; i < nelmts * src_size; i++)
1052         buf[i] = saved_buf[i] = (unsigned char)HDrand();
1053 
1054     /* Convert data from native integer to derived floating-point type.
1055      * The mantissa is big enough to retain the integer's precision. */
1056     if(H5Tconvert(H5T_NATIVE_INT, tid1, nelmts, buf, NULL, dxpl_id) < 0) {
1057         H5_FAILED();
1058         HDprintf("Can't convert data\n");
1059         goto error;
1060     }
1061     /* Convert data from the derived floating-point type back to native integer. */
1062     if(H5Tconvert(tid1, H5T_NATIVE_INT, nelmts, buf, NULL, dxpl_id) < 0) {
1063         H5_FAILED();
1064         HDprintf("Can't convert data\n");
1065         goto error;
1066     }
1067 
1068     /* Are the values still the same?*/
1069     for(i=0; i<nelmts; i++) {
1070         for(j=0; j<src_size; j++)
1071             if(buf[i*src_size+j]!=saved_buf[i*src_size+j])
1072                break;
1073         if(j==src_size)
1074            continue; /*no error*/
1075 
1076         /* Print errors */
1077         if (0==fails_this_test++) {
1078         HDsnprintf(str, sizeof(str), "\nTesting random sw derived floating-point -> derived floating-point conversions");
1079         HDprintf("%-70s", str);
1080         HDfflush(stdout);
1081             H5_FAILED();
1082         }
1083         HDprintf("    test %u elmt %u: \n", 1, (unsigned)i);
1084 
1085         HDprintf("        src = ");
1086         for (j=0; j<src_size; j++)
1087             HDprintf(" %02x", saved_buf[i*src_size+ENDIAN(src_size, j, endian)]);
1088 
1089         HDmemcpy(aligned, saved_buf+i*sizeof(int), sizeof(int));
1090         HDprintf(" %29d\n", *aligned);
1091 
1092         HDprintf("        dst = ");
1093         for (j=0; j<src_size; j++)
1094             HDprintf(" %02x", buf[i*src_size+ENDIAN(src_size, j, endian)]);
1095 
1096         HDmemcpy(aligned, buf+i*sizeof(int), sizeof(int));
1097         HDprintf(" %29d\n", *aligned);
1098 
1099         if (fails_this_test>=max_fails) {
1100             HDputs("    maximum failures reached, aborting test...");
1101             goto error;
1102         }
1103     }
1104 
1105     fails_this_test = 0;
1106     HDfree(buf);
1107     HDfree(saved_buf);
1108     HDfree(aligned);
1109     buf = NULL;
1110     saved_buf = NULL;
1111     aligned = NULL;
1112 
1113     /*--------------------------------------------------------------------------
1114      *                   2nd floating-point type
1115      * size=3 byte, precision=24 bits, offset=0 bits, mantissa size=16 bits,
1116      * mantissa position=0, exponent size=7 bits, exponent position=16, exponent
1117      * bias=63. It can be illustrated in little-endian order as
1118      *
1119      *          2       1       0
1120      *    SEEEEEEE MMMMMMMM MMMMMMMM
1121      *--------------------------------------------------------------------------*/
1122     if(H5Tset_fields(tid2, (size_t)23, (size_t)16, (size_t)7, (size_t)0, (size_t)16) < 0) {
1123         H5_FAILED();
1124         HDprintf("Can't set fields\n");
1125         goto error;
1126     }
1127     if(H5Tset_offset(tid2, (size_t)0) < 0) {
1128         H5_FAILED();
1129         HDprintf("Can't set offset\n");
1130         goto error;
1131     }
1132     if(H5Tset_precision(tid2, (size_t)24) < 0) {
1133         H5_FAILED();
1134         HDprintf("Can't set precision 2\n");
1135         goto error;
1136     }
1137     if(H5Tset_size(tid2, (size_t)3) < 0) {
1138         H5_FAILED();
1139         HDprintf("Can't set size\n");
1140         goto error;
1141     }
1142     if(H5Tset_ebias(tid2, (size_t)63) < 0) {
1143         H5_FAILED();
1144         HDprintf("Can't set size\n");
1145         goto error;
1146     }
1147     if(H5Tset_pad(tid2, H5T_PAD_ZERO, H5T_PAD_ZERO) < 0) {
1148         H5_FAILED();
1149         HDprintf("Can't set padding\n");
1150         goto error;
1151     }
1152 
1153     if(H5Tcommit2(file, "new float type 2", tid2, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) < 0) {
1154         H5_FAILED();
1155         HDprintf("Can't set inpad\n");
1156         goto error;
1157     }
1158     if(H5Tclose(tid2) < 0) {
1159         H5_FAILED();
1160         HDprintf("Can't close datatype\n");
1161         goto error;
1162     }
1163 
1164     if((tid2 = H5Topen2(file, "new float type 2", H5P_DEFAULT)) < 0)
1165         FAIL_PUTS_ERROR("Can't open datatype")
1166     if(H5Tget_fields(tid2, &spos, &epos, &esize, &mpos, &msize) < 0) {
1167         H5_FAILED();
1168         HDprintf("Can't get fields\n");
1169         goto error;
1170     }
1171     if(spos != 23 || epos != 16 || esize != 7 || mpos != 0 || msize != 16) {
1172         H5_FAILED();
1173         HDprintf("Wrong field values\n");
1174         goto error;
1175     }
1176 
1177     if(H5Tget_precision(tid2) != 24) {
1178         H5_FAILED();
1179         HDprintf("Can't get precision or wrong precision\n");
1180         goto error;
1181     }
1182     if(H5Tget_offset(tid2)!=0) {
1183         H5_FAILED();
1184         HDprintf("Can't get offset or wrong offset\n");
1185         goto error;
1186     }
1187     if((size = H5Tget_size(tid2))!=3) {
1188         H5_FAILED();
1189         HDprintf("Can't get size or wrong size\n");
1190         goto error;
1191     }
1192     if(H5Tget_ebias(tid2)!=63) {
1193         H5_FAILED();
1194         HDprintf("Can't get exponent bias or wrong bias\n");
1195         goto error;
1196     }
1197 
1198     /* Convert data from the 2nd to the 1st derived floating-point type.
1199      * Then convert data from the 1st type back to the 2nd type.
1200      * Compare the final data with the original data.
1201      */
1202     src_size = H5Tget_size(tid2);
1203     dst_size = H5Tget_size(tid1);
1204     endian = H5Tget_order(tid2);
1205     buf = (unsigned char *)HDmalloc(nelmts * (MAX(src_size, dst_size)));
1206     saved_buf = (unsigned char *)HDmalloc(nelmts * src_size);
1207     HDmemset(buf, 0, nelmts * MAX(src_size, dst_size));
1208     HDmemset(saved_buf, 0, nelmts*src_size);
1209 
1210     for(i=0; i<nelmts*src_size; i++)
1211         buf[i] = saved_buf[i] = (unsigned char)HDrand();
1212 
1213     /* Convert data from the 2nd to the 1st derived floating-point type.
1214      * The mantissa and exponent of the 2nd type are big enough to retain
1215      * the precision and exponent power. */
1216     if(H5Tconvert(tid2, tid1, nelmts, buf, NULL, dxpl_id) < 0) {
1217         H5_FAILED();
1218         HDprintf("Can't convert data\n");
1219         goto error;
1220     }
1221     /* Convert data from the 1st back to the 2nd derived floating-point type. */
1222     if(H5Tconvert(tid1, tid2, nelmts, buf, NULL, dxpl_id) < 0) {
1223         H5_FAILED();
1224         HDprintf("Can't convert data\n");
1225         goto error;
1226     }
1227 
1228     /* Are the values still the same?*/
1229     for(i=0; i<nelmts; i++) {
1230         for(j=0; j<src_size; j++)
1231             if(buf[i*src_size+j]!=saved_buf[i*src_size+j])
1232                break;
1233         if(j==src_size)
1234            continue; /*no error*/
1235 
1236         /* If original value is NaN(exponent bits are all ones, 11..11),
1237          * the library simply sets all mantissa bits to ones.  So don't
1238          * compare values in this case.
1239          */
1240         if((buf[i*src_size+2]==0x7f && saved_buf[i*src_size+2]==0x7f) ||
1241             (buf[i*src_size+2]==0xff && saved_buf[i*src_size+2]==0xff))
1242             continue;
1243 
1244         /* Print errors */
1245         if (0==fails_this_test++) {
1246         HDsnprintf(str, sizeof(str), "\nTesting random sw derived floating-point -> derived floating-point conversions");
1247         HDprintf("%-70s", str);
1248         HDfflush(stdout);
1249             H5_FAILED();
1250         }
1251         HDprintf("    test %u elmt %u: \n", 1, (unsigned)i);
1252 
1253         HDprintf("        src = ");
1254         for (j=0; j<src_size; j++)
1255             HDprintf(" %02x", saved_buf[i*src_size+ENDIAN(src_size, j, endian)]);
1256         HDprintf("\n");
1257 
1258         HDprintf("        dst = ");
1259         for (j=0; j<src_size; j++)
1260             HDprintf(" %02x", buf[i*src_size+ENDIAN(src_size, j, endian)]);
1261         HDprintf("\n");
1262 
1263         if (fails_this_test>=max_fails) {
1264             HDputs("    maximum failures reached, aborting test...");
1265             goto error;
1266         }
1267     }
1268 
1269     if (buf) HDfree(buf);
1270     if (saved_buf) HDfree(saved_buf);
1271 
1272     if(H5Tclose(tid1) < 0) {
1273         H5_FAILED();
1274         HDprintf("Can't close datatype\n");
1275         goto error;
1276     }
1277 
1278     if(H5Tclose(tid2) < 0) {
1279         H5_FAILED();
1280         HDprintf("Can't close datatype\n");
1281         goto error;
1282     }
1283 
1284     if(H5Pclose(dxpl_id) < 0) {
1285         H5_FAILED();
1286         HDprintf("Can't close property list\n");
1287         goto error;
1288     }
1289 
1290     if(H5Fclose(file) < 0) {
1291         H5_FAILED();
1292         HDprintf("Can't close file\n");
1293         goto error;
1294     } /* end if */
1295 
1296     PASSED();
1297 
1298     /* Restore the default error handler (set in h5_reset()) */
1299     h5_restore_err();
1300 
1301     reset_hdf5();    /*print statistics*/
1302 
1303     return 0;
1304 
1305  error:
1306     if (buf) HDfree(buf);
1307     if (saved_buf) HDfree(saved_buf);
1308     if (aligned) HDfree(aligned);
1309     HDfflush(stdout);
1310     H5E_BEGIN_TRY {
1311         H5Tclose (tid1);
1312         H5Tclose (tid2);
1313         H5Pclose (dxpl_id);
1314         H5Fclose (file);
1315     } H5E_END_TRY;
1316 
1317     /* Restore the default error handler (set in h5_reset()) */
1318     h5_restore_err();
1319 
1320     reset_hdf5(); /*print statistics*/
1321 
1322     return MAX((int)fails_this_test, 1);
1323 }
1324 
1325 
1326 /*-------------------------------------------------------------------------
1327  * Function:    test_derived_integer
1328  *
1329  * Purpose:     Tests user-define and query functions of integer types.
1330  *
1331  * Return:      Success:        0
1332  *
1333  *              Failure:        number of errors
1334  *
1335  * Programmer:  Raymond Lu
1336  *              Saturday, Jan 29, 2005
1337  *
1338  * Modifications:
1339  *
1340  *-------------------------------------------------------------------------
1341  */
1342 static int
test_derived_integer(void)1343 test_derived_integer(void)
1344 {
1345     hid_t       file=-1, tid1=-1, tid2=-1;
1346     hid_t       dxpl_id=-1;
1347     char        filename[1024];
1348     size_t      src_size, dst_size;
1349     unsigned char        *buf=NULL, *saved_buf=NULL;
1350     int        endian;            /*endianess            */
1351     size_t      nelmts = NTESTELEM;
1352     unsigned int        fails_this_test = 0;
1353     const size_t    max_fails=40;    /*max number of failures*/
1354     char    str[256];        /*message string    */
1355     unsigned int         i, j;
1356 
1357     TESTING("user-define and query functions of integer types");
1358 
1359     /* Create File */
1360     h5_fixname(FILENAME[1], H5P_DEFAULT, filename, sizeof filename);
1361     if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
1362         H5_FAILED();
1363         HDprintf("Can't create file\n");
1364         goto error;
1365     }
1366 
1367     if((dxpl_id = H5Pcreate(H5P_DATASET_XFER)) < 0) {
1368         H5_FAILED();
1369         HDprintf("Can't create data transfer property list\n");
1370         goto error;
1371     }
1372 
1373     if((tid1 = H5Tcopy(H5T_STD_I32LE)) < 0) {
1374         H5_FAILED();
1375         HDprintf("Can't copy data type\n");
1376         goto error;
1377     }
1378 
1379     if((tid2 = H5Tcopy(H5T_STD_U64LE)) < 0) {
1380         H5_FAILED();
1381         HDprintf("Can't copy data type\n");
1382         goto error;
1383     }
1384 
1385     /*--------------------------------------------------------------------------
1386      *                   1st integer type
1387      * size=3 byte, precision=24 bits, offset=0 bits, order=big endian.
1388      * It can be illustrated in big-endian order as
1389      *
1390      *          0       1       2
1391      *    SIIIIIII IIIIIIII IIIIIIII
1392      *
1393      * There's no specific order for these functions to define the attributes
1394      * of a new integer type, H5Tset_precision, H5Tset_offset, H5Tset_size,
1395      * H5Tset_order, H5Tset_pad, H5Tset_sign.
1396      *--------------------------------------------------------------------------*/
1397     if(H5Tset_offset(tid1, (size_t)0) < 0) {
1398         H5_FAILED();
1399         HDprintf("Can't set offset\n");
1400         goto error;
1401     }
1402 
1403     if(H5Tset_size(tid1, (size_t)3) < 0) {
1404         H5_FAILED();
1405         HDprintf("Can't set size\n");
1406         goto error;
1407     }
1408 
1409     if(H5Tset_precision(tid1, (size_t)24) < 0) {
1410         H5_FAILED();
1411         HDprintf("Can't set precision\n");
1412         goto error;
1413     }
1414 
1415     if(H5Tset_order(tid1, H5T_ORDER_BE) < 0) {
1416         H5_FAILED();
1417         HDprintf("Can't set order\n");
1418         goto error;
1419     }
1420 
1421     if(H5Tcommit2(file, "new integer type 1", tid1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) < 0) {
1422         H5_FAILED();
1423         HDprintf("Can't commit data type\n");
1424         goto error;
1425     }
1426 
1427     if(H5Tclose(tid1) < 0) {
1428         H5_FAILED();
1429         HDprintf("Can't close datatype\n");
1430         goto error;
1431     }
1432 
1433     if((tid1 = H5Topen2(file, "new integer type 1", H5P_DEFAULT)) < 0)
1434         FAIL_PUTS_ERROR("Can't open datatype")
1435     if(H5Tget_precision(tid1) != 24) {
1436         H5_FAILED();
1437         HDprintf("Can't get precision or wrong precision\n");
1438         goto error;
1439     }
1440     if(H5Tget_offset(tid1) != 0) {
1441         H5_FAILED();
1442         HDprintf("Can't get offset or wrong offset\n");
1443         goto error;
1444     }
1445     if(H5Tget_size(tid1) != 3) {
1446         H5_FAILED();
1447         HDprintf("Can't get size or wrong size\n");
1448         goto error;
1449     }
1450     if(H5Tget_order(tid1)!=H5T_ORDER_BE) {
1451         H5_FAILED();
1452         HDprintf("Can't get order or wrong order\n");
1453         goto error;
1454     }
1455 
1456     /*--------------------------------------------------------------------------
1457      *                   2nd integer type
1458      * size=8 byte, precision=48 bits, offset=10 bits, order=little endian.
1459      * It can be illustrated in little-endian order as
1460      *
1461      *          7       6       5       4       3       2       1       0
1462      *   ??????SI IIIIIIII IIIIIIII IIIIIIII IIIIIIII IIIIIIII IIIIII?? ????????
1463      *--------------------------------------------------------------------------*/
1464     if(H5Tset_precision(tid2, (size_t)48) < 0) {
1465         H5_FAILED();
1466         HDprintf("Can't set precision\n");
1467         goto error;
1468     }
1469 
1470     if(H5Tset_offset(tid2, (size_t)10) < 0) {
1471         H5_FAILED();
1472         HDprintf("Can't set offset\n");
1473         goto error;
1474     }
1475 
1476     if(H5Tset_sign(tid2, H5T_SGN_2) < 0) {
1477         H5_FAILED();
1478         HDprintf("Can't set offset\n");
1479         goto error;
1480     }
1481 
1482     if(H5Tcommit2(file, "new integer type 2", tid2, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) < 0) {
1483         H5_FAILED();
1484         HDprintf("Can't commit data type\n");
1485         goto error;
1486     }
1487 
1488     if(H5Tclose(tid2) < 0) {
1489         H5_FAILED();
1490         HDprintf("Can't close datatype\n");
1491         goto error;
1492     }
1493 
1494     if((tid2 = H5Topen2(file, "new integer type 2", H5P_DEFAULT)) < 0)
1495         FAIL_PUTS_ERROR("Can't open datatype")
1496     if(H5Tget_precision(tid2) != 48) {
1497         H5_FAILED();
1498         HDprintf("Can't get precision or wrong precision\n");
1499         goto error;
1500     }
1501     if(H5Tget_offset(tid2) != 10) {
1502         H5_FAILED();
1503         HDprintf("Can't get offset or wrong offset\n");
1504         goto error;
1505     }
1506     if(H5Tget_size(tid2) != 8) {
1507         H5_FAILED();
1508         HDprintf("Can't get size or wrong size\n");
1509         goto error;
1510     }
1511     if(H5Tget_sign(tid2)!=H5T_SGN_2) {
1512         H5_FAILED();
1513         HDprintf("Can't get sign or wrong sign\n");
1514         goto error;
1515     }
1516 
1517     /* Convert data from the 1st to the 2nd derived integer type.
1518      * Then convert data from the 2nd type back to the 1st type.
1519      * Compare the final data with the original data.
1520      */
1521     src_size = H5Tget_size(tid1);
1522     dst_size = H5Tget_size(tid2);
1523     endian = H5Tget_order(tid1);
1524     buf = (unsigned char *)HDmalloc(nelmts*(MAX(src_size, dst_size)));
1525     saved_buf = (unsigned char *)HDmalloc(nelmts*src_size);
1526     HDmemset(buf, 0, nelmts * MAX(src_size, dst_size));
1527     HDmemset(saved_buf, 0, nelmts*src_size);
1528 
1529     for(i=0; i<nelmts * src_size; i++)
1530         buf[i] = saved_buf[i] = (unsigned char)HDrand();
1531 
1532     /* Convert data from the 1st to the 2nd derived integer type.
1533      * The precision of the 2nd type are big enough to retain
1534      * the 1st type's precision. */
1535     if(H5Tconvert(tid1, tid2, nelmts, buf, NULL, dxpl_id) < 0) {
1536         H5_FAILED();
1537         HDprintf("Can't convert data\n");
1538         goto error;
1539     }
1540     /* Convert data from the 2nd back to the 1st derived integer type. */
1541     if(H5Tconvert(tid2, tid1, nelmts, buf, NULL, dxpl_id) < 0) {
1542         H5_FAILED();
1543         HDprintf("Can't convert data\n");
1544         goto error;
1545     }
1546 
1547     /* Are the values still the same?*/
1548     for(i=0; i<nelmts; i++) {
1549         for(j=0; j<src_size; j++)
1550             if(buf[i*src_size+j]!=saved_buf[i*src_size+j])
1551                break;
1552         if(j==src_size)
1553            continue; /*no error*/
1554 
1555         /* Print errors */
1556         if (0==fails_this_test++) {
1557         HDsnprintf(str, sizeof(str), "\nTesting random sw derived integer -> derived integer conversions");
1558         HDprintf("%-70s", str);
1559         HDfflush(stdout);
1560             H5_FAILED();
1561         }
1562         HDprintf("    test %u elmt %u: \n", 1, (unsigned)i);
1563 
1564         HDprintf("        src = ");
1565         for (j=0; j<src_size; j++)
1566             HDprintf(" %02x", saved_buf[i*src_size+ENDIAN(src_size, j, endian)]);
1567         HDprintf("\n");
1568 
1569         HDprintf("        dst = ");
1570         for (j=0; j<src_size; j++)
1571             HDprintf(" %02x", buf[i*src_size+ENDIAN(src_size, j, endian)]);
1572         HDprintf("\n");
1573 
1574         if (fails_this_test>=max_fails) {
1575             HDputs("    maximum failures reached, aborting test...");
1576             goto error;
1577         }
1578     }
1579 
1580     if(H5Tclose(tid1) < 0) {
1581         H5_FAILED();
1582         HDprintf("Can't close datatype\n");
1583         goto error;
1584     }
1585 
1586     if(H5Tclose(tid2) < 0) {
1587         H5_FAILED();
1588         HDprintf("Can't close datatype\n");
1589         goto error;
1590     }
1591 
1592     if(H5Pclose(dxpl_id) < 0) {
1593         H5_FAILED();
1594         HDprintf("Can't close property list\n");
1595         goto error;
1596     }
1597 
1598     if(H5Fclose(file) < 0) {
1599         H5_FAILED();
1600         HDprintf("Can't close file\n");
1601         goto error;
1602     } /* end if */
1603 
1604     HDfree(buf);
1605     HDfree(saved_buf);
1606 
1607     PASSED();
1608 
1609     /* Restore the default error handler (set in h5_reset()) */
1610     h5_restore_err();
1611 
1612     reset_hdf5();    /*print statistics*/
1613 
1614     return 0;
1615 
1616  error:
1617     if (buf) HDfree(buf);
1618     if (saved_buf) HDfree(saved_buf);
1619     HDfflush(stdout);
1620     H5E_BEGIN_TRY {
1621         H5Tclose (tid1);
1622         H5Tclose (tid2);
1623         H5Pclose (dxpl_id);
1624         H5Fclose (file);
1625     } H5E_END_TRY;
1626 
1627     /* Restore the default error handler (set in h5_reset()) */
1628     h5_restore_err();
1629 
1630     reset_hdf5(); /*print statistics*/
1631 
1632     return MAX((int)fails_this_test, 1);
1633 }
1634 
1635 
1636 /*-------------------------------------------------------------------------
1637  * Function:    test_conv_int_1
1638  *
1639  * Purpose:    Test conversion of integer values from SRC to DST.
1640  *        These types should be any combination of:
1641  *
1642  *             H5T_NATIVE_SCHAR    H5T_NATIVE_UCHAR
1643  *            H5T_NATIVE_SHORT    H5T_NATIVE_USHORT
1644  *            H5T_NATIVE_INT        H5T_NATIVE_UINT
1645  *            H5T_NATIVE_LONG        H5T_NATIVE_ULONG
1646  *            H5T_NATIVE_LLONG    H5T_NATIVE_ULLONG
1647  *
1648  * Return:    Success:    0
1649  *
1650  *        Failure:    number of errors
1651  *
1652  * Programmer:    Robb Matzke
1653  *              Monday, November 16, 1998
1654  *
1655  * Modifications:
1656  *
1657  *-------------------------------------------------------------------------
1658  */
1659 static int
test_conv_int_1(const char * name,hid_t src,hid_t dst)1660 test_conv_int_1(const char *name, hid_t src, hid_t dst)
1661 {
1662     size_t            nelmts=0;        /*num values per test    */
1663     const size_t    max_fails=8;        /*max number of failures*/
1664     size_t        fails_all_tests=0;    /*number of failures    */
1665     size_t        fails_this_test;    /*fails for this test    */
1666     char        str[256];        /*hello string        */
1667     dtype_t        src_type, dst_type;    /*data types        */
1668     const char        *src_type_name=NULL;    /*source type name    */
1669     const char        *dst_type_name=NULL;    /*destination type name    */
1670     int            endian;            /*machine endianess    */
1671     size_t        src_size, dst_size;    /*type sizes        */
1672     unsigned char    *buf=NULL;        /*buffer for conversion    */
1673     unsigned char    *saved=NULL;        /*original values    */
1674     size_t        j, k;            /*counters        */
1675     unsigned char    *hw=NULL;        /*hardware conv result    */
1676     unsigned char    src_bits[32];        /*src value in LE order    */
1677     unsigned char    dst_bits[32];        /*dest value in LE order*/
1678     size_t        src_nbits;        /*source length in bits    */
1679     size_t        dst_nbits;        /*dst length in bits    */
1680     H5T_sign_t          src_sign;               /*source sign type      */
1681     H5T_sign_t          dst_sign;               /*dst sign type         */
1682     void        *aligned=NULL;        /*aligned temp buffer    */
1683     signed char        hw_char;
1684     unsigned char    hw_uchar;
1685     short        hw_short;
1686     unsigned short    hw_ushort;
1687     int            hw_int;
1688     unsigned        hw_uint;
1689     long        hw_long;
1690     unsigned long    hw_ulong;
1691     long long        hw_llong;
1692     unsigned long long    hw_ullong;
1693 
1694     /* What are the names of the source and destination types */
1695     if (H5Tequal(src, H5T_NATIVE_SCHAR)) {
1696     src_type_name = "signed char";
1697     src_type = INT_SCHAR;
1698     } else if (H5Tequal(src, H5T_NATIVE_UCHAR)) {
1699     src_type_name = "unsigned char";
1700     src_type = INT_UCHAR;
1701     } else if (H5Tequal(src, H5T_NATIVE_SHORT)) {
1702     src_type_name = "short";
1703     src_type = INT_SHORT;
1704     } else if (H5Tequal(src, H5T_NATIVE_USHORT)) {
1705     src_type_name = "unsigned short";
1706     src_type = INT_USHORT;
1707     } else if (H5Tequal(src, H5T_NATIVE_INT)) {
1708     src_type_name = "int";
1709     src_type = INT_INT;
1710     } else if (H5Tequal(src, H5T_NATIVE_UINT)) {
1711     src_type_name = "unsigned int";
1712     src_type = INT_UINT;
1713     } else if (H5Tequal(src, H5T_NATIVE_LONG)) {
1714     src_type_name = "long";
1715     src_type = INT_LONG;
1716     } else if (H5Tequal(src, H5T_NATIVE_ULONG)) {
1717     src_type_name = "unsigned long";
1718     src_type = INT_ULONG;
1719     } else if (H5Tequal(src, H5T_NATIVE_LLONG)) {
1720     src_type_name = "long long";
1721     src_type = INT_LLONG;
1722     } else if (H5Tequal(src, H5T_NATIVE_ULLONG)) {
1723     src_type_name = "unsigned long long";
1724     src_type = INT_ULLONG;
1725     } else {
1726     src_type_name = "UNKNOWN";
1727     src_type = OTHER;
1728     }
1729 
1730     if (H5Tequal(dst, H5T_NATIVE_SCHAR)) {
1731     dst_type_name = "signed char";
1732     dst_type = INT_SCHAR;
1733     } else if (H5Tequal(dst, H5T_NATIVE_UCHAR)) {
1734     dst_type_name = "unsigned char";
1735     dst_type = INT_UCHAR;
1736     } else if (H5Tequal(dst, H5T_NATIVE_SHORT)) {
1737     dst_type_name = "short";
1738     dst_type = INT_SHORT;
1739     } else if (H5Tequal(dst, H5T_NATIVE_USHORT)) {
1740     dst_type_name = "unsigned short";
1741     dst_type = INT_USHORT;
1742     } else if (H5Tequal(dst, H5T_NATIVE_INT)) {
1743     dst_type_name = "int";
1744     dst_type = INT_INT;
1745     } else if (H5Tequal(dst, H5T_NATIVE_UINT)) {
1746     dst_type_name = "unsigned int";
1747     dst_type = INT_UINT;
1748     } else if (H5Tequal(dst, H5T_NATIVE_LONG)) {
1749     dst_type_name = "long";
1750     dst_type = INT_LONG;
1751     } else if (H5Tequal(dst, H5T_NATIVE_ULONG)) {
1752     dst_type_name = "unsigned long";
1753     dst_type = INT_ULONG;
1754     } else if (H5Tequal(dst, H5T_NATIVE_LLONG)) {
1755     dst_type_name = "long long";
1756     dst_type = INT_LLONG;
1757     } else if (H5Tequal(dst, H5T_NATIVE_ULLONG)) {
1758     dst_type_name = "unsigned long long";
1759     dst_type = INT_ULLONG;
1760     } else {
1761     dst_type_name = "UNKNOWN";
1762     dst_type = OTHER;
1763     }
1764 
1765     /* Sanity checks */
1766     if (OTHER==src_type || OTHER==dst_type) {
1767     HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions",
1768         name, src_type_name, dst_type_name);
1769     HDprintf("%-70s", str);
1770     H5_FAILED();
1771     HDputs("    Unknown data type.");
1772     goto error;
1773     } else {
1774         HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions",
1775             name, src_type_name, dst_type_name);
1776         HDprintf("%-70s", str);
1777         HDfflush(stdout);
1778         fails_this_test=0;
1779     }
1780 
1781     /* Some information about datatypes */
1782     endian = H5Tget_order(H5T_NATIVE_INT);
1783     src_size = H5Tget_size(src);
1784     dst_size = H5Tget_size(dst);
1785     src_nbits = H5Tget_precision(src); /* not 8*src_size, esp on J90 - QAK */
1786     dst_nbits = H5Tget_precision(dst); /* not 8*dst_size, esp on J90 - QAK */
1787     src_sign = H5Tget_sign(src);
1788     dst_sign = H5Tget_sign(dst);
1789     aligned = HDcalloc((size_t)1, sizeof(long long));
1790 
1791     /* Allocate and initialize the source buffer through macro INIT_INTEGER.  The BUF
1792      * will be used for the conversion while the SAVED buffer will be
1793      * used for the comparison later.
1794      */
1795     if(src_type == INT_SCHAR) {
1796         INIT_INTEGER(signed char, SCHAR_MAX, SCHAR_MIN, src_size, dst_size, src_nbits, buf, saved, nelmts);
1797     } else if(src_type == INT_UCHAR) {
1798         INIT_INTEGER(unsigned char, UCHAR_MAX, 0, src_size, dst_size, src_nbits, buf, saved, nelmts);
1799     } else if(src_type == INT_SHORT) {
1800         INIT_INTEGER(short, SHRT_MAX, SHRT_MIN, src_size, dst_size, src_nbits, buf, saved, nelmts);
1801     } else if(src_type == INT_USHORT) {
1802         INIT_INTEGER(unsigned short, USHRT_MAX, 0, src_size, dst_size, src_nbits, buf, saved, nelmts);
1803     } else if(src_type == INT_INT) {
1804         INIT_INTEGER(int, INT_MAX, INT_MIN, src_size, dst_size, src_nbits, buf, saved, nelmts);
1805     } else if(src_type == INT_UINT) {
1806         INIT_INTEGER(unsigned int, UINT_MAX, 0, src_size, dst_size, src_nbits, buf, saved, nelmts);
1807     } else if(src_type == INT_LONG) {
1808         INIT_INTEGER(long, LONG_MAX, LONG_MIN, src_size, dst_size, src_nbits, buf, saved, nelmts);
1809     } else if(src_type == INT_ULONG) {
1810         INIT_INTEGER(unsigned long, ULONG_MAX, 0, src_size, dst_size, src_nbits, buf, saved, nelmts);
1811     } else if(src_type == INT_LLONG) {
1812         INIT_INTEGER(long long, LLONG_MAX, LLONG_MIN, src_size, dst_size, src_nbits, buf, saved, nelmts);
1813     } else if(src_type == INT_ULLONG) {
1814         INIT_INTEGER(unsigned long long, ULLONG_MAX, 0, src_size, dst_size, src_nbits, buf, saved, nelmts);
1815     } else
1816         goto error;
1817 
1818     /* Perform the conversion */
1819     if (H5Tconvert(src, dst, nelmts, buf, NULL, H5P_DEFAULT) < 0)
1820         goto error;
1821 
1822     /* Check the results from the library against hardware */
1823     for (j=0; j<nelmts; j++) {
1824         if (INT_SCHAR==dst_type) {
1825             hw = (unsigned char*)&hw_char;
1826             switch (src_type) {
1827             case INT_SCHAR:
1828                 HDmemcpy(aligned, saved+j*sizeof(signed char), sizeof(signed char));
1829                 hw_char = (signed char)(*((signed char*)aligned));
1830                 break;
1831             case INT_UCHAR:
1832                 HDmemcpy(aligned, saved+j*sizeof(unsigned char), sizeof(unsigned char));
1833                 hw_char = (signed char)(*((unsigned char*)aligned));
1834                 break;
1835             case INT_SHORT:
1836                 HDmemcpy(aligned, saved+j*sizeof(short), sizeof(short));
1837                 hw_char = (signed char)(*((short*)aligned));
1838                 break;
1839             case INT_USHORT:
1840                 HDmemcpy(aligned, saved+j*sizeof(unsigned short), sizeof(unsigned short));
1841                 hw_char = (signed char)(*((unsigned short*)aligned));
1842                 break;
1843             case INT_INT:
1844                 HDmemcpy(aligned, saved+j*sizeof(int), sizeof(int));
1845                 hw_char = (signed char)(*((int*)aligned));
1846                 break;
1847             case INT_UINT:
1848                 HDmemcpy(aligned, saved+j*sizeof(unsigned), sizeof(unsigned));
1849                 hw_char = (signed char)(*((unsigned*)aligned));
1850                 break;
1851             case INT_LONG:
1852                 HDmemcpy(aligned, saved+j*sizeof(long), sizeof(long));
1853                 hw_char = (signed char)(*((long*)aligned));
1854                 break;
1855             case INT_ULONG:
1856                 HDmemcpy(aligned, saved+j*sizeof(unsigned long), sizeof(unsigned long));
1857                 hw_char = (signed char)(*((unsigned long*)aligned));
1858                 break;
1859             case INT_LLONG:
1860                 HDmemcpy(aligned, saved+j*sizeof(long long), sizeof(long long));
1861                 hw_char = (signed char)(*((long long*)aligned));
1862                 break;
1863             case INT_ULLONG:
1864                 HDmemcpy(aligned, saved+j*sizeof(unsigned long long), sizeof(unsigned long long));
1865                 hw_char = (signed char)(*((unsigned long long*)aligned));
1866                 break;
1867             case FLT_FLOAT:
1868             case FLT_DOUBLE:
1869             case FLT_LDOUBLE:
1870             case OTHER:
1871             default:
1872                 HDassert(0 && "Unknown type");
1873                 break;
1874             }
1875         } else if (INT_UCHAR==dst_type) {
1876             hw = (unsigned char*)&hw_uchar;
1877             switch (src_type) {
1878             case INT_SCHAR:
1879                 HDmemcpy(aligned, saved+j*sizeof(signed char), sizeof(signed char));
1880                 hw_uchar = (unsigned char)(*((signed char*)aligned));
1881                 break;
1882             case INT_UCHAR:
1883                 HDmemcpy(aligned, saved+j*sizeof(unsigned char), sizeof(unsigned char));
1884                 hw_uchar = (unsigned char)(*((unsigned char*)aligned));
1885                 break;
1886             case INT_SHORT:
1887                 HDmemcpy(aligned, saved+j*sizeof(short), sizeof(short));
1888                 hw_uchar = (unsigned char)(*((short*)aligned));
1889                 break;
1890             case INT_USHORT:
1891                 HDmemcpy(aligned, saved+j*sizeof(unsigned short), sizeof(unsigned short));
1892                 hw_uchar = (unsigned char)(*((unsigned short*)aligned));
1893                 break;
1894             case INT_INT:
1895                 HDmemcpy(aligned, saved+j*sizeof(int), sizeof(int));
1896                 hw_uchar = (unsigned char)(*((int*)aligned));
1897                 break;
1898             case INT_UINT:
1899                 HDmemcpy(aligned, saved+j*sizeof(unsigned), sizeof(unsigned));
1900                 hw_uchar = (unsigned char)(*((unsigned*)aligned));
1901                 break;
1902             case INT_LONG:
1903                 HDmemcpy(aligned, saved+j*sizeof(long), sizeof(long));
1904                 hw_uchar = (unsigned char)(*((long*)aligned));
1905                 break;
1906             case INT_ULONG:
1907                 HDmemcpy(aligned, saved+j*sizeof(unsigned long), sizeof(unsigned long));
1908                 hw_uchar = (unsigned char)(*((unsigned long*)aligned));
1909                 break;
1910             case INT_LLONG:
1911                 HDmemcpy(aligned, saved+j*sizeof(long long), sizeof(long long));
1912                 hw_uchar = (unsigned char)(*((long long*)aligned));
1913                 break;
1914             case INT_ULLONG:
1915                 HDmemcpy(aligned, saved+j*sizeof(unsigned long long), sizeof(unsigned long long));
1916                 hw_uchar = (unsigned char)(*((unsigned long long*)aligned));
1917                 break;
1918             case FLT_FLOAT:
1919             case FLT_DOUBLE:
1920             case FLT_LDOUBLE:
1921             case OTHER:
1922             default:
1923                 HDassert(0 && "Unknown type");
1924                 break;
1925             }
1926         } else if (INT_SHORT==dst_type) {
1927             hw = (unsigned char*)&hw_short;
1928             switch (src_type) {
1929             case INT_SCHAR:
1930                 HDmemcpy(aligned, saved+j*sizeof(char), sizeof(char));
1931                 hw_short = (short)(*((char*)aligned));
1932                 break;
1933             case INT_UCHAR:
1934                 HDmemcpy(aligned, saved+j*sizeof(unsigned char), sizeof(unsigned char));
1935                 hw_short = (short)(*((unsigned char*)aligned));
1936                 break;
1937             case INT_SHORT:
1938                 HDmemcpy(aligned, saved+j*sizeof(short), sizeof(short));
1939                 hw_short = (short)(*((short*)aligned));
1940                 break;
1941             case INT_USHORT:
1942                 HDmemcpy(aligned, saved+j*sizeof(unsigned short), sizeof(unsigned short));
1943                 hw_short = (short)(*((unsigned short*)aligned));
1944                 break;
1945             case INT_INT:
1946                 HDmemcpy(aligned, saved+j*sizeof(int), sizeof(int));
1947                 hw_short = (short)(*((int*)aligned));
1948                 break;
1949             case INT_UINT:
1950                 HDmemcpy(aligned, saved+j*sizeof(unsigned), sizeof(unsigned));
1951                 hw_short = (short)(*((unsigned*)aligned));
1952                 break;
1953             case INT_LONG:
1954                 HDmemcpy(aligned, saved+j*sizeof(long), sizeof(long));
1955                 hw_short = (short)(*((long*)aligned));
1956                 break;
1957             case INT_ULONG:
1958                 HDmemcpy(aligned, saved+j*sizeof(unsigned long), sizeof(unsigned long));
1959                 hw_short = (short)(*((unsigned long*)aligned));
1960                 break;
1961             case INT_LLONG:
1962                 HDmemcpy(aligned, saved+j*sizeof(long long), sizeof(long long));
1963                 hw_short = (short)(*((long long*)aligned));
1964                 break;
1965             case INT_ULLONG:
1966                 HDmemcpy(aligned, saved+j*sizeof(unsigned long long), sizeof(unsigned long long));
1967                 hw_short = (short)(*((unsigned long long*)aligned));
1968                 break;
1969 
1970             case FLT_FLOAT:
1971             case FLT_DOUBLE:
1972             case FLT_LDOUBLE:
1973             case OTHER:
1974             default:
1975                 HDassert(0 && "Unknown type");
1976                 break;
1977             }
1978         } else if (INT_USHORT==dst_type) {
1979             hw = (unsigned char*)&hw_ushort;
1980             switch (src_type) {
1981             case INT_SCHAR:
1982                 HDmemcpy(aligned, saved+j*sizeof(signed char), sizeof(signed char));
1983                 hw_ushort = (unsigned short)(*((signed char*)aligned));
1984                 break;
1985             case INT_UCHAR:
1986                 HDmemcpy(aligned, saved+j*sizeof(unsigned char), sizeof(unsigned char));
1987                 hw_ushort = (unsigned short)(*((unsigned char*)aligned));
1988                 break;
1989             case INT_SHORT:
1990                 HDmemcpy(aligned, saved+j*sizeof(short), sizeof(short));
1991                 hw_ushort = (unsigned short)(*((short*)aligned));
1992                 break;
1993             case INT_USHORT:
1994                 HDmemcpy(aligned, saved+j*sizeof(unsigned short), sizeof(unsigned short));
1995                 hw_ushort = (unsigned short)(*((unsigned short*)aligned));
1996                 break;
1997             case INT_INT:
1998                 HDmemcpy(aligned, saved+j*sizeof(int), sizeof(int));
1999                 hw_ushort = (unsigned short)(*((int*)aligned));
2000                 break;
2001             case INT_UINT:
2002                 HDmemcpy(aligned, saved+j*sizeof(unsigned), sizeof(unsigned));
2003                 hw_ushort = (unsigned short)(*((unsigned*)aligned));
2004                 break;
2005             case INT_LONG:
2006                 HDmemcpy(aligned, saved+j*sizeof(long), sizeof(long));
2007                 hw_ushort = (unsigned short)(*((long*)aligned));
2008                 break;
2009             case INT_ULONG:
2010                 HDmemcpy(aligned, saved+j*sizeof(unsigned long), sizeof(unsigned long));
2011                 hw_ushort = (unsigned short)(*((unsigned long*)aligned));
2012                 break;
2013             case INT_LLONG:
2014                 HDmemcpy(aligned, saved+j*sizeof(long long), sizeof(long long));
2015                 hw_ushort = (unsigned short)(*((long long*)aligned));
2016                 break;
2017             case INT_ULLONG:
2018                 HDmemcpy(aligned, saved+j*sizeof(unsigned long long), sizeof(unsigned long long));
2019                 hw_ushort = (unsigned short)(*((unsigned long long*)aligned));
2020                 break;
2021             case FLT_FLOAT:
2022             case FLT_DOUBLE:
2023             case FLT_LDOUBLE:
2024             case OTHER:
2025             default:
2026                 HDassert(0 && "Unknown type");
2027                 break;
2028             }
2029         } else if (INT_INT==dst_type) {
2030             hw = (unsigned char*)&hw_int;
2031             switch (src_type) {
2032             case INT_SCHAR:
2033                 HDmemcpy(aligned, saved+j*sizeof(signed char), sizeof(signed char));
2034                 hw_int = (int)(*((signed char*)aligned));
2035                 break;
2036             case INT_UCHAR:
2037                 HDmemcpy(aligned, saved+j*sizeof(unsigned char), sizeof(unsigned char));
2038                 hw_int = (int)(*((unsigned char*)aligned));
2039                 break;
2040             case INT_SHORT:
2041                 HDmemcpy(aligned, saved+j*sizeof(short), sizeof(short));
2042                 hw_int = (int)(*((short*)aligned));
2043                 break;
2044             case INT_USHORT:
2045                 HDmemcpy(aligned, saved+j*sizeof(unsigned short), sizeof(unsigned short));
2046                 hw_int = (int)(*((unsigned short*)aligned));
2047                 break;
2048             case INT_INT:
2049                 HDmemcpy(aligned, saved+j*sizeof(int), sizeof(int));
2050                 hw_int = (int)(*((int*)aligned));
2051                 break;
2052             case INT_UINT:
2053                 HDmemcpy(aligned, saved+j*sizeof(unsigned), sizeof(unsigned));
2054                 hw_int = (int)(*((unsigned*)aligned));
2055                 break;
2056             case INT_LONG:
2057                 HDmemcpy(aligned, saved+j*sizeof(long), sizeof(long));
2058                 hw_int = (int)(*((long*)aligned));
2059                 break;
2060             case INT_ULONG:
2061                 HDmemcpy(aligned, saved+j*sizeof(unsigned long), sizeof(unsigned long));
2062                 hw_int = (int)(*((unsigned long*)aligned));
2063                 break;
2064             case INT_LLONG:
2065                 HDmemcpy(aligned, saved+j*sizeof(long long), sizeof(long long));
2066                 hw_int = (int)(*((long long*)aligned));
2067                 break;
2068             case INT_ULLONG:
2069                 HDmemcpy(aligned, saved+j*sizeof(unsigned long long), sizeof(unsigned long long));
2070                 hw_int = (int)(*((unsigned long long*)aligned));
2071                 break;
2072             case FLT_FLOAT:
2073             case FLT_DOUBLE:
2074             case FLT_LDOUBLE:
2075             case OTHER:
2076             default:
2077                 HDassert(0 && "Unknown type");
2078                 break;
2079             }
2080         } else if (INT_UINT==dst_type) {
2081             hw = (unsigned char*)&hw_uint;
2082             switch (src_type) {
2083             case INT_SCHAR:
2084                 HDmemcpy(aligned, saved+j*sizeof(signed char), sizeof(signed char));
2085                 hw_uint = (unsigned int)(*((signed char*)aligned));
2086                 break;
2087             case INT_UCHAR:
2088                 HDmemcpy(aligned, saved+j*sizeof(unsigned char), sizeof(unsigned char));
2089                 hw_uint = (unsigned int)(*((unsigned char*)aligned));
2090                 break;
2091             case INT_SHORT:
2092                 HDmemcpy(aligned, saved+j*sizeof(short), sizeof(short));
2093                 hw_uint = (unsigned int)(*((short*)aligned));
2094                 break;
2095             case INT_USHORT:
2096                 HDmemcpy(aligned, saved+j*sizeof(unsigned short), sizeof(unsigned short));
2097                 hw_uint = (unsigned int)(*((unsigned short*)aligned));
2098                 break;
2099             case INT_INT:
2100                 HDmemcpy(aligned, saved+j*sizeof(int), sizeof(int));
2101                 hw_uint = (unsigned int)(*((int*)aligned));
2102                 break;
2103             case INT_UINT:
2104                 HDmemcpy(aligned, saved+j*sizeof(unsigned), sizeof(unsigned));
2105                 hw_uint = (unsigned int)(*((unsigned*)aligned));
2106                 break;
2107             case INT_LONG:
2108                 HDmemcpy(aligned, saved+j*sizeof(long), sizeof(long));
2109                 hw_uint = (unsigned int)(*((long*)aligned));
2110                 break;
2111             case INT_ULONG:
2112                 HDmemcpy(aligned, saved+j*sizeof(unsigned long), sizeof(unsigned long));
2113                 hw_uint = (unsigned int)(*((unsigned long*)aligned));
2114                 break;
2115             case INT_LLONG:
2116                 HDmemcpy(aligned, saved+j*sizeof(long long), sizeof(long long));
2117                 hw_uint = (unsigned int)(*((long long*)aligned));
2118                 break;
2119             case INT_ULLONG:
2120                 HDmemcpy(aligned, saved+j*sizeof(unsigned long long), sizeof(unsigned long long));
2121                 hw_uint = (unsigned int)(*((unsigned long long*)aligned));
2122                 break;
2123             case FLT_FLOAT:
2124             case FLT_DOUBLE:
2125             case FLT_LDOUBLE:
2126             case OTHER:
2127             default:
2128                 HDassert(0 && "Unknown type");
2129                 break;
2130             }
2131         } else if (INT_LONG==dst_type) {
2132             hw = (unsigned char*)&hw_long;
2133             switch (src_type) {
2134             case INT_SCHAR:
2135                 HDmemcpy(aligned, saved+j*sizeof(signed char), sizeof(signed char));
2136                 hw_long = (long int)(*((signed char*)aligned));
2137                 break;
2138             case INT_UCHAR:
2139                 HDmemcpy(aligned, saved+j*sizeof(unsigned char), sizeof(unsigned char));
2140                 hw_long = (long int)(*((unsigned char*)aligned));
2141                 break;
2142             case INT_SHORT:
2143                 HDmemcpy(aligned, saved+j*sizeof(short), sizeof(short));
2144                 hw_long = (long int)(*((short*)aligned));
2145                 break;
2146             case INT_USHORT:
2147                 HDmemcpy(aligned, saved+j*sizeof(unsigned short), sizeof(unsigned short));
2148                 hw_long = (long int)(*((unsigned short*)aligned));
2149                 break;
2150             case INT_INT:
2151                 HDmemcpy(aligned, saved+j*sizeof(int), sizeof(int));
2152                 hw_long = (long int)(*((int*)aligned));
2153                 break;
2154             case INT_UINT:
2155                 HDmemcpy(aligned, saved+j*sizeof(unsigned), sizeof(unsigned));
2156                 hw_long = (long int)(*((unsigned*)aligned));
2157                 break;
2158             case INT_LONG:
2159                 HDmemcpy(aligned, saved+j*sizeof(long), sizeof(long));
2160                 hw_long = (long int)(*((long*)aligned));
2161                 break;
2162             case INT_ULONG:
2163                 HDmemcpy(aligned, saved+j*sizeof(unsigned long), sizeof(unsigned long));
2164                 hw_long = (long int)(*((unsigned long*)aligned));
2165                 break;
2166             case INT_LLONG:
2167                 HDmemcpy(aligned, saved+j*sizeof(long long), sizeof(long long));
2168                 hw_long = (long int)(*((long long*)aligned));
2169                 break;
2170             case INT_ULLONG:
2171                 HDmemcpy(aligned, saved+j*sizeof(unsigned long long), sizeof(unsigned long long));
2172                 hw_long = (long int)(*((unsigned long long*)aligned));
2173                 break;
2174             case FLT_FLOAT:
2175             case FLT_DOUBLE:
2176             case FLT_LDOUBLE:
2177             case OTHER:
2178             default:
2179                 HDassert(0 && "Unknown type");
2180                 break;
2181             }
2182         } else if (INT_ULONG==dst_type) {
2183             hw = (unsigned char*)&hw_ulong;
2184             switch (src_type) {
2185             case INT_SCHAR:
2186                 HDmemcpy(aligned, saved+j*sizeof(signed char), sizeof(signed char));
2187                 hw_ulong = (unsigned long)(*((signed char*)aligned));
2188                 break;
2189             case INT_UCHAR:
2190                 HDmemcpy(aligned, saved+j*sizeof(unsigned char), sizeof(unsigned char));
2191                 hw_ulong = (unsigned long)(*((unsigned char*)aligned));
2192                 break;
2193             case INT_SHORT:
2194                 HDmemcpy(aligned, saved+j*sizeof(short), sizeof(short));
2195                 hw_ulong = (unsigned long)(*((short*)aligned));
2196                 break;
2197             case INT_USHORT:
2198                 HDmemcpy(aligned, saved+j*sizeof(unsigned short), sizeof(unsigned short));
2199                 hw_ulong = (unsigned long)(*((unsigned short*)aligned));
2200                 break;
2201             case INT_INT:
2202                 HDmemcpy(aligned, saved+j*sizeof(int), sizeof(int));
2203                 hw_ulong = (unsigned long)(*((int*)aligned));
2204                 break;
2205             case INT_UINT:
2206                 HDmemcpy(aligned, saved+j*sizeof(unsigned), sizeof(unsigned));
2207                 hw_ulong = (unsigned long)(*((unsigned*)aligned));
2208                 break;
2209             case INT_LONG:
2210                 HDmemcpy(aligned, saved+j*sizeof(long), sizeof(long));
2211                 hw_ulong = (unsigned long)(*((long*)aligned));
2212                 break;
2213             case INT_ULONG:
2214                 HDmemcpy(aligned, saved+j*sizeof(unsigned long), sizeof(unsigned long));
2215                 hw_ulong = (unsigned long)(*((unsigned long*)aligned));
2216                 break;
2217             case INT_LLONG:
2218                 HDmemcpy(aligned, saved+j*sizeof(long long), sizeof(long long));
2219                 hw_ulong = (unsigned long)(*((long long*)aligned));
2220                 break;
2221             case INT_ULLONG:
2222                 HDmemcpy(aligned, saved+j*sizeof(unsigned long long), sizeof(unsigned long long));
2223                 hw_ulong = (unsigned long)(*((unsigned long long*)aligned));
2224                 break;
2225             case FLT_FLOAT:
2226             case FLT_DOUBLE:
2227             case FLT_LDOUBLE:
2228             case OTHER:
2229             default:
2230                 HDassert(0 && "Unknown type");
2231                 break;
2232             }
2233         } else if (INT_LLONG==dst_type) {
2234             hw = (unsigned char*)&hw_llong;
2235             switch (src_type) {
2236             case INT_SCHAR:
2237                 HDmemcpy(aligned, saved+j*sizeof(char), sizeof(char));
2238                 hw_llong = (long long)(*((char*)aligned));
2239                 break;
2240             case INT_UCHAR:
2241                 HDmemcpy(aligned, saved+j*sizeof(unsigned char), sizeof(unsigned char));
2242                 hw_llong = (long long)(*((unsigned char*)aligned));
2243                 break;
2244             case INT_SHORT:
2245                 HDmemcpy(aligned, saved+j*sizeof(short), sizeof(short));
2246                 hw_llong = (long long)(*((short*)aligned));
2247                 break;
2248             case INT_USHORT:
2249                 HDmemcpy(aligned, saved+j*sizeof(unsigned short), sizeof(unsigned short));
2250                 hw_llong = (long long)(*((unsigned short*)aligned));
2251                 break;
2252             case INT_INT:
2253                 HDmemcpy(aligned, saved+j*sizeof(int), sizeof(int));
2254                 hw_llong = (long long)(*((int*)aligned));
2255                 break;
2256             case INT_UINT:
2257                 HDmemcpy(aligned, saved+j*sizeof(unsigned), sizeof(unsigned));
2258                 hw_llong = (long long)(*((unsigned*)aligned));
2259                 break;
2260             case INT_LONG:
2261                 HDmemcpy(aligned, saved+j*sizeof(long), sizeof(long));
2262                 hw_llong = (long long)(*((long*)aligned));
2263                 break;
2264             case INT_ULONG:
2265                 HDmemcpy(aligned, saved+j*sizeof(unsigned long), sizeof(unsigned long));
2266                 hw_llong = (long long)(*((unsigned long*)aligned));
2267                 break;
2268             case INT_LLONG:
2269                 HDmemcpy(aligned, saved+j*sizeof(long long), sizeof(long long));
2270                 hw_llong = (long long)(*((long long*)aligned));
2271                 break;
2272             case INT_ULLONG:
2273                 HDmemcpy(aligned, saved+j*sizeof(unsigned long long), sizeof(unsigned long long));
2274                 hw_llong = (long long)(*((unsigned long long*)aligned));
2275                 break;
2276             case FLT_FLOAT:
2277             case FLT_DOUBLE:
2278             case FLT_LDOUBLE:
2279             case OTHER:
2280             default:
2281                 HDassert(0 && "Unknown type");
2282                 break;
2283             }
2284         } else if (INT_ULLONG==dst_type) {
2285             hw = (unsigned char*)&hw_ullong;
2286             switch (src_type) {
2287             case INT_SCHAR:
2288                 HDmemcpy(aligned, saved+j*sizeof(signed char), sizeof(signed char));
2289                 hw_ullong = (unsigned long long)(*((signed char*)aligned));
2290                 break;
2291             case INT_UCHAR:
2292                 HDmemcpy(aligned, saved+j*sizeof(unsigned char), sizeof(unsigned char));
2293                 hw_ullong = (unsigned long long)(*((unsigned char*)aligned));
2294                 break;
2295             case INT_SHORT:
2296                 HDmemcpy(aligned, saved+j*sizeof(short), sizeof(short));
2297                 hw_ullong = (unsigned long long)(*((short*)aligned));
2298                 break;
2299             case INT_USHORT:
2300                 HDmemcpy(aligned, saved+j*sizeof(unsigned short), sizeof(unsigned short));
2301                 hw_ullong = (unsigned long long)(*((unsigned short*)aligned));
2302                 break;
2303             case INT_INT:
2304                 HDmemcpy(aligned, saved+j*sizeof(int), sizeof(int));
2305                 hw_ullong = (unsigned long long)(*((int*)aligned));
2306                 break;
2307             case INT_UINT:
2308                 HDmemcpy(aligned, saved+j*sizeof(unsigned), sizeof(unsigned));
2309                 hw_ullong = (unsigned long long)(*((unsigned*)aligned));
2310                 break;
2311             case INT_LONG:
2312                 HDmemcpy(aligned, saved+j*sizeof(long), sizeof(long));
2313                 hw_ullong = (unsigned long long)(*((long*)aligned));
2314                 break;
2315             case INT_ULONG:
2316                 HDmemcpy(aligned, saved+j*sizeof(unsigned long), sizeof(unsigned long));
2317                 hw_ullong = (unsigned long long)(*((unsigned long*)aligned));
2318                 break;
2319             case INT_LLONG:
2320                 HDmemcpy(aligned, saved+j*sizeof(long long), sizeof(long long));
2321                 hw_ullong = (unsigned long long)(*((long long*)aligned));
2322                 break;
2323             case INT_ULLONG:
2324                 HDmemcpy(aligned, saved+j*sizeof(unsigned long long), sizeof(unsigned long long));
2325                 hw_ullong = (unsigned long long)(*((unsigned long long*)aligned));
2326                 break;
2327             case FLT_FLOAT:
2328             case FLT_DOUBLE:
2329             case FLT_LDOUBLE:
2330             case OTHER:
2331             default:
2332                 HDassert(0 && "Unknown type");
2333                 break;
2334             }
2335         }
2336 
2337         /* Make certain that there isn't some weird number of destination bits */
2338         assert(dst_nbits%8==0);
2339 
2340         /* Are the two results the same? */
2341         for (k=(dst_size-(dst_nbits/8)); k<dst_size; k++)
2342             if (buf[j*dst_size+k]!=hw[k])
2343                 break;
2344         if (k==dst_size)
2345             continue; /*no error*/
2346 
2347         /*
2348          * Convert the source and destination values to little endian
2349          * order so we can use the HDF5 bit vector operations to test
2350          * certain things.  These routines have already been tested by
2351          * the `bittests' program.
2352          */
2353         for (k=0; k<src_size; k++)
2354             src_bits[src_size-(k+1)] = saved[j*src_size+ENDIAN(src_size, k, endian)];
2355 
2356         for (k=0; k<dst_size; k++)
2357             dst_bits[dst_size-(k+1)] = buf[j*dst_size+ENDIAN(dst_size, k, endian)];
2358 
2359         /*
2360          * Hardware usually doesn't handle overflows too gracefully. The
2361          * hardware conversion result during overflows is usually garbage
2362          * so we must handle those cases differetly when checking results.
2363          */
2364         if (H5T_SGN_2==src_sign && H5T_SGN_2==dst_sign) {
2365             if (src_nbits>dst_nbits) {
2366                 if(0==H5T__bit_get_d(src_bits, src_nbits-1, (size_t)1) &&
2367                         H5T__bit_find(src_bits, dst_nbits-1, (src_nbits-dst_nbits),
2368                             H5T_BIT_MSB, 1)>=0) {
2369                     /*
2370                      * Source is positive and the magnitude is too large for
2371                      * the destination.  The destination should be set to the
2372                      * maximum possible value: 0x7f...f
2373                      */
2374                     if (0==H5T__bit_get_d(dst_bits, dst_nbits-1, (size_t)1) &&
2375                             H5T__bit_find(dst_bits, (size_t)0, dst_nbits-1, H5T_BIT_LSB, 0) < 0)
2376                         continue; /*no error*/
2377                 } else if (1==H5T__bit_get_d(src_bits, src_nbits-1, (size_t)1) &&
2378                        H5T__bit_find(src_bits, (size_t)0, src_nbits-1, H5T_BIT_MSB,
2379                             0)+1>=(ssize_t)dst_nbits) {
2380                     /*
2381                      * Source is negative but the magnitude is too large for
2382                      * the destination. The destination should be set to the
2383                      * smallest possible value: 0x80...0
2384                      */
2385                     if (1==H5T__bit_get_d(dst_bits, dst_nbits-1, (size_t)1) &&
2386                             H5T__bit_find(dst_bits, (size_t)0, dst_nbits-1, H5T_BIT_LSB, 1) < 0)
2387                         continue; /*no error*/
2388                 }
2389             } else if(src_nbits<dst_nbits) {
2390                 /* Source is smaller than the destination */
2391                 if(0==H5T__bit_get_d(src_bits, src_nbits-1, (size_t)1)) {
2392                     /*
2393                      * Source is positive, so the excess bits in the
2394                      * destination should be set to 0's.
2395                      */
2396                     if (0==H5T__bit_get_d(dst_bits, src_nbits-1, (size_t)1) &&
2397                             H5T__bit_find(dst_bits, src_nbits, dst_nbits-src_nbits, H5T_BIT_LSB, 1) < 0)
2398                         continue; /*no error*/
2399                 } else {
2400                     /*
2401                      * Source is negative, so the excess bits in the
2402                      * destination should be set to 1's.
2403                      */
2404                     if (1==H5T__bit_get_d(dst_bits, src_nbits-1, (size_t)1) &&
2405                             H5T__bit_find(dst_bits, src_nbits, dst_nbits-src_nbits, H5T_BIT_LSB, 0) < 0)
2406                         continue; /*no error*/
2407                 }
2408             }
2409         } else if (H5T_SGN_2==src_sign && H5T_SGN_NONE==dst_sign) {
2410             if (H5T__bit_get_d(src_bits, src_nbits-1, (size_t)1)) {
2411                 /*
2412                  * The source is negative so the result should be zero.
2413                  * The source is negative if the most significant bit is
2414                  * set.  The destination is zero if all bits are zero.
2415                  */
2416                 if (H5T__bit_find(dst_bits, (size_t)0, dst_nbits, H5T_BIT_LSB, 1) < 0)
2417                     continue; /*no error*/
2418             } else if (src_nbits>dst_nbits &&
2419                    H5T__bit_find(src_bits, dst_nbits-1,
2420                         src_nbits-dst_nbits, H5T_BIT_LSB, 1)>=0) {
2421                 /*
2422                  * The source is a value with a magnitude too large for
2423                  * the destination.  The destination should be the
2424                  * largest possible value: 0xff...f
2425                  */
2426                 if (H5T__bit_find(dst_bits, (size_t)0, dst_nbits, H5T_BIT_LSB, 0) < 0)
2427                     continue; /*no error*/
2428             }
2429         } else if (H5T_SGN_NONE==src_sign && H5T_SGN_2==dst_sign) {
2430             if (src_nbits>=dst_nbits &&
2431                     H5T__bit_find(src_bits, dst_nbits-1, (src_nbits-dst_nbits)+1,
2432                         H5T_BIT_LSB, 1)>=0) {
2433                 /*
2434                  * The source value has a magnitude that is larger than
2435                  * the destination can handle.  The destination should be
2436                  * set to the largest possible positive value: 0x7f...f
2437                  */
2438                 if (0==H5T__bit_get_d(dst_bits, dst_nbits-1, (size_t)1) &&
2439                         H5T__bit_find(dst_bits, (size_t)0, dst_nbits-1, H5T_BIT_LSB, 0) < 0)
2440                     continue; /*no error*/
2441             }
2442         } else {
2443             if (src_nbits>dst_nbits &&
2444                     H5T__bit_find(src_bits, dst_nbits, src_nbits-dst_nbits,
2445                          H5T_BIT_LSB, 1)>=0) {
2446                 /*
2447                  * The unsigned source has a value which is too large for
2448                  * the unsigned destination.  The destination should be
2449                  * set to the largest possible value: 0xff...f
2450                  */
2451                 if (H5T__bit_find(dst_bits, (size_t)0, dst_nbits, H5T_BIT_LSB, 0) < 0)
2452                     continue; /*no error*/
2453             }
2454         }
2455 
2456         /* Print errors */
2457         if (0==fails_this_test++)
2458             H5_FAILED();
2459         HDprintf("    elmt %u\n", (unsigned)j);
2460 
2461         HDprintf("        src = ");
2462         for (k=0; k<src_size; k++)
2463             HDprintf(" %02x", saved[j*src_size+ENDIAN(src_size, k, endian)]);
2464         HDprintf("%*s", (int)(3*MAX(0, (ssize_t)dst_size-(ssize_t)src_size)), "");
2465         switch (src_type) {
2466             case INT_SCHAR:
2467                 HDmemcpy(aligned, saved+j*sizeof(signed char), sizeof(signed char));
2468                 HDprintf(" %29d\n", (int)*((signed char*)aligned));
2469                 break;
2470             case INT_UCHAR:
2471                 HDmemcpy(aligned, saved+j*sizeof(unsigned char), sizeof(unsigned char));
2472                 HDprintf(" %29u\n", (unsigned)*((unsigned char*)aligned));
2473                 break;
2474             case INT_SHORT:
2475                 HDmemcpy(aligned, saved+j*sizeof(short), sizeof(short));
2476                 HDprintf(" %29hd\n", *((short*)aligned));
2477                 break;
2478             case INT_USHORT:
2479                 HDmemcpy(aligned, saved+j*sizeof(unsigned short), sizeof(unsigned short));
2480                 HDprintf(" %29hu\n", *((unsigned short*)aligned));
2481                 break;
2482             case INT_INT:
2483                 HDmemcpy(aligned, saved+j*sizeof(int), sizeof(int));
2484                 HDprintf(" %29d\n", *((int*)aligned));
2485                 break;
2486             case INT_UINT:
2487                 HDmemcpy(aligned, saved+j*sizeof(unsigned), sizeof(unsigned));
2488                 HDprintf(" %29u\n", *((unsigned*)aligned));
2489                 break;
2490             case INT_LONG:
2491                 HDmemcpy(aligned, saved+j*sizeof(long), sizeof(long));
2492                 HDprintf(" %29ld\n", *((long*)aligned));
2493                 break;
2494             case INT_ULONG:
2495                 HDmemcpy(aligned, saved+j*sizeof(unsigned long), sizeof(unsigned long));
2496                 HDprintf(" %29lu\n", *((unsigned long*)aligned));
2497                 break;
2498             case INT_LLONG:
2499                 HDmemcpy(aligned, saved+j*sizeof(long long), sizeof(long long));
2500                 HDfprintf(stdout," %29"H5_PRINTF_LL_WIDTH"d\n", *((long long*)aligned));
2501                 break;
2502             case INT_ULLONG:
2503                 HDmemcpy(aligned, saved+j*sizeof(unsigned long long), sizeof(unsigned long long));
2504                 HDfprintf(stdout," %29"H5_PRINTF_LL_WIDTH"u\n", *((unsigned long long*)aligned));
2505                 break;
2506             case FLT_FLOAT:
2507             case FLT_DOUBLE:
2508             case FLT_LDOUBLE:
2509             case OTHER:
2510             default:
2511                 HDassert(0 && "Unknown type");
2512                 break;
2513         }
2514 
2515         HDprintf("        dst = ");
2516         for (k=0; k<dst_size; k++)
2517             HDprintf(" %02x", buf[j*dst_size+ENDIAN(dst_size, k, endian)]);
2518         HDprintf("%*s", (int)(3*MAX(0, (ssize_t)src_size-(ssize_t)dst_size)), "");
2519         switch (dst_type) {
2520             case INT_SCHAR:
2521                 HDmemcpy(aligned, buf+j*sizeof(signed char), sizeof(signed char));
2522                 HDprintf(" %29d\n", (int)*((signed char*)aligned));
2523                 break;
2524             case INT_UCHAR:
2525                 HDmemcpy(aligned, buf+j*sizeof(unsigned char), sizeof(unsigned char));
2526                 HDprintf(" %29u\n", (unsigned)*((unsigned char*)aligned));
2527                 break;
2528             case INT_SHORT:
2529                 HDmemcpy(aligned, buf+j*sizeof(short), sizeof(short));
2530                 HDprintf(" %29hd\n", *((short*)aligned));
2531                 break;
2532             case INT_USHORT:
2533                 HDmemcpy(aligned, buf+j*sizeof(unsigned short), sizeof(unsigned short));
2534                 HDprintf(" %29hu\n", *((unsigned short*)aligned));
2535                 break;
2536             case INT_INT:
2537                 HDmemcpy(aligned, buf+j*sizeof(int), sizeof(int));
2538                 HDprintf(" %29d\n", *((int*)aligned));
2539                 break;
2540             case INT_UINT:
2541                 HDmemcpy(aligned, buf+j*sizeof(unsigned), sizeof(unsigned));
2542                 HDprintf(" %29u\n", *((unsigned*)aligned));
2543                 break;
2544             case INT_LONG:
2545                 HDmemcpy(aligned, buf+j*sizeof(long), sizeof(long));
2546                 HDprintf(" %29ld\n", *((long*)aligned));
2547                 break;
2548             case INT_ULONG:
2549                 HDmemcpy(aligned, buf+j*sizeof(unsigned long), sizeof(unsigned long));
2550                 HDprintf(" %29lu\n", *((unsigned long*)aligned));
2551                 break;
2552             case INT_LLONG:
2553                 HDmemcpy(aligned, buf+j*sizeof(long long), sizeof(long long));
2554                 HDfprintf(stdout," %29"H5_PRINTF_LL_WIDTH"d\n", *((long long*)aligned));
2555                 break;
2556             case INT_ULLONG:
2557                 HDmemcpy(aligned, buf+j*sizeof(long long), sizeof(unsigned long long));
2558                 HDfprintf(stdout," %29"H5_PRINTF_LL_WIDTH"u\n", *((unsigned long long*)aligned));
2559                 break;
2560             case FLT_FLOAT:
2561             case FLT_DOUBLE:
2562             case FLT_LDOUBLE:
2563             case OTHER:
2564             default:
2565                 HDassert(0 && "Unknown type");
2566                 break;
2567         }
2568 
2569         HDprintf("        ans = ");
2570         for (k=0; k<dst_size; k++)
2571             HDprintf(" %02x", hw[ENDIAN(dst_size, k, endian)]);
2572         HDprintf("%*s", (int)(3*MAX(0, (ssize_t)src_size-(ssize_t)dst_size)), "");
2573         switch (dst_type) {
2574             case INT_SCHAR:
2575                 HDprintf(" %29d\n", (int)*((signed char*)((void *)hw)));
2576                 break;
2577             case INT_UCHAR:
2578                 HDprintf(" %29u\n", (unsigned)*((unsigned char*)((void *)hw)));
2579                 break;
2580             case INT_SHORT:
2581                 HDprintf(" %29hd\n", *((short*)((void *)hw)));
2582                 break;
2583             case INT_USHORT:
2584                 HDprintf(" %29hu\n", *((unsigned short*)((void *)hw)));
2585                 break;
2586             case INT_INT:
2587                 HDprintf(" %29d\n", *((int*)((void *)hw)));
2588                 break;
2589             case INT_UINT:
2590                 HDprintf(" %29u\n", *((unsigned*)((void *)hw)));
2591                 break;
2592             case INT_LONG:
2593                 HDprintf(" %29ld\n", *((long*)((void *)hw)));
2594                 break;
2595             case INT_ULONG:
2596                 HDprintf(" %29lu\n", *((unsigned long*)((void *)hw)));
2597                 break;
2598             case INT_LLONG:
2599                 HDfprintf(stdout," %29"H5_PRINTF_LL_WIDTH"d\n", *((long long*)((void *)hw)));
2600                 break;
2601             case INT_ULLONG:
2602                 HDfprintf(stdout," %29"H5_PRINTF_LL_WIDTH"u\n", *((unsigned long long*)((void *)hw)));
2603                 break;
2604             case FLT_FLOAT:
2605             case FLT_DOUBLE:
2606             case FLT_LDOUBLE:
2607             case OTHER:
2608             default:
2609                 HDassert(0 && "Unknown type");
2610                 break;
2611         }
2612 
2613         if (++fails_all_tests>=max_fails) {
2614             HDputs("    maximum failures reached, aborting test...");
2615             HDputs("    (dst is library's conversion output. ans is compiler's conversion output.)");
2616             goto done;
2617         }
2618     }
2619     PASSED();
2620 
2621 done:
2622     if (buf) aligned_free(buf);
2623     if (saved) aligned_free(saved);
2624     if (aligned) HDfree(aligned);
2625     HDfflush(stdout);
2626 
2627     /* Restore the default error handler (set in h5_reset()) */
2628     h5_restore_err();
2629 
2630     reset_hdf5();    /*print statistics*/
2631 
2632     return (int)fails_all_tests;
2633 
2634 error:
2635     if (buf) aligned_free(buf);
2636     if (saved) aligned_free(saved);
2637     if (aligned) HDfree(aligned);
2638     HDfflush(stdout);
2639 
2640     /* Restore the default error handler (set in h5_reset()) */
2641     h5_restore_err();
2642 
2643     reset_hdf5();    /*print statistics*/
2644 
2645     return MAX((int)fails_all_tests, 1);
2646 }
2647 
2648 
2649 /*-------------------------------------------------------------------------
2650  * Function:    test_conv_int_2
2651  *
2652  * Purpose:    Tests overlap calculates in H5T__conv_i_i(), which should be
2653  *        the same as for H5T__conv_f_f() and H5T__conv_s_s().
2654  *
2655  * Return:    Success:    0
2656  *
2657  *        Failure:    number of errors
2658  *
2659  * Programmer:    Robb Matzke
2660  *              Friday, April 30, 1999
2661  *
2662  * Modifications:
2663  *
2664  *-------------------------------------------------------------------------
2665  */
2666 static int
test_conv_int_2(void)2667 test_conv_int_2(void)
2668 {
2669     int        i, j;
2670     hid_t    src_type, dst_type;
2671     char    *buf;
2672 
2673     HDprintf("%-70s", "Testing overlap calculations");
2674     HDfflush(stdout);
2675 
2676     buf = (char *)HDcalloc(TMP_BUF_DIM1, TMP_BUF_DIM2);
2677     HDassert(buf);
2678 
2679     for(i = 1; i <= TMP_BUF_DIM1; i++) {
2680     for(j = 1; j <= TMP_BUF_DIM1; j++) {
2681 
2682         /* Source type */
2683         src_type = H5Tcopy(H5T_NATIVE_CHAR);
2684         H5Tset_size(src_type, (size_t)i);
2685 
2686         /* Destination type */
2687         dst_type = H5Tcopy(H5T_NATIVE_CHAR);
2688         H5Tset_size(dst_type, (size_t)j);
2689 
2690         /*
2691         * Conversion. If overlap calculations aren't right then an
2692         * assertion will fail in H5T__conv_i_i()
2693         */
2694         H5Tconvert(src_type, dst_type, (size_t)TMP_BUF_DIM2, buf, NULL, H5P_DEFAULT);
2695         H5Tclose(src_type);
2696         H5Tclose(dst_type);
2697     }
2698     }
2699     PASSED();
2700     HDfree(buf);
2701     return 0;
2702 }
2703 
2704 
2705 /*-------------------------------------------------------------------------
2706  * Function:    my_isnan
2707  *
2708  * Purpose:    Determines whether VAL points to NaN.
2709  *
2710  * Return:    TRUE or FALSE
2711  *
2712  * Programmer:    Robb Matzke
2713  *              Monday, July  6, 1998
2714  *
2715  * Modifications:
2716  *
2717  *-------------------------------------------------------------------------
2718  */
2719 static int
my_isnan(dtype_t type,void * val)2720 my_isnan(dtype_t type, void *val)
2721 {
2722     int retval = 0;
2723     char s[256];
2724 
2725     if (FLT_FLOAT==type) {
2726     float x;
2727     HDmemcpy(&x, val, sizeof(float));
2728     retval = (x!=x);
2729     } else if (FLT_DOUBLE==type) {
2730     double x;
2731     HDmemcpy(&x, val, sizeof(double));
2732     retval = (x!=x);
2733 #if H5_SIZEOF_LONG_DOUBLE!=H5_SIZEOF_DOUBLE && H5_SIZEOF_LONG_DOUBLE!=0
2734     } else if (FLT_LDOUBLE==type) {
2735     long double x;
2736     HDmemcpy(&x, val, sizeof(long double));
2737     retval = (x!=x);
2738 #endif
2739     } else {
2740     return 0;
2741     }
2742 
2743     /*
2744      * Sometimes NaN==NaN (e.g., DEC Alpha) so we try to print it and see if
2745      * the result contains a NaN string.
2746      */
2747     if (!retval) {
2748     if (FLT_FLOAT==type) {
2749         float x;
2750 
2751         HDmemcpy(&x, val, sizeof(float));
2752         HDsnprintf(s, sizeof(s), "%g", (double)x);
2753     } else if (FLT_DOUBLE==type) {
2754         double x;
2755 
2756         HDmemcpy(&x, val, sizeof(double));
2757         HDsnprintf(s, sizeof(s), "%g", x);
2758 #if H5_SIZEOF_LONG_DOUBLE!=H5_SIZEOF_DOUBLE && H5_SIZEOF_LONG_DOUBLE!=0
2759     } else if (FLT_LDOUBLE==type) {
2760         long double x;
2761 
2762         HDmemcpy(&x, val, sizeof(long double));
2763         HDsnprintf(s, sizeof(s), "%Lg", x);
2764 #endif
2765     } else {
2766         return 0;
2767     }
2768     if (HDstrstr(s, "NaN") || HDstrstr(s, "NAN") || HDstrstr(s, "nan"))
2769         retval = 1;
2770     }
2771 
2772     return retval;
2773 }
2774 
2775 
2776 /*-------------------------------------------------------------------------
2777  * Function:    my_isinf
2778  *
2779  * Purpose:    Determines whether VAL points to +/-infinity.
2780  *
2781  * Return:    TRUE or FALSE
2782  *
2783  * Programmer:    Raymond Lu
2784  *              Monday, June 20, 2005
2785  *
2786  * Modifications:
2787  *
2788  *-------------------------------------------------------------------------
2789  */
2790 static int
my_isinf(int endian,unsigned char * val,size_t size,size_t mpos,size_t msize,size_t epos,size_t esize)2791 my_isinf(int endian, unsigned char *val, size_t size,
2792         size_t mpos, size_t msize, size_t epos, size_t esize)
2793 {
2794     unsigned char *bits;
2795     int retval = 0;
2796     size_t i;
2797 
2798     bits = (unsigned char*)HDcalloc((size_t)1, size);
2799 
2800     for (i=0; i<size; i++)
2801         bits[size-(i+1)] = *(val + ENDIAN(size, i, endian));
2802 
2803     if(H5T__bit_find(bits, mpos, msize, H5T_BIT_LSB, 1) < 0 &&
2804             H5T__bit_find(bits, epos, esize, H5T_BIT_LSB, 0) < 0)
2805         retval = 1;
2806 
2807     HDfree(bits);
2808 
2809     return retval;
2810 }
2811 
2812 
2813 /*-------------------------------------------------------------------------
2814  * Function:    test_conv_flt_1
2815  *
2816  * Purpose:    Test conversion of floating point values from SRC to
2817  *        DST.  These types should be H5T_NATIVE_FLOAT,
2818  *        H5T_NATIVE_DOUBLE, or H5T_NATIVE_LDOUBLE.
2819  *
2820  * Return:    Success:    0
2821  *
2822  *        Failure:    number of errors
2823  *
2824  * Programmer:    Robb Matzke
2825  *              Tuesday, June 23, 1998
2826  *
2827  * Modifications:
2828  *         Albert Cheng, Apr 16, 2004
2829  *         Check for underflow condition. If the src number is
2830  *         smaller than the dst MIN float number, consider it okay
2831  *         if the converted sw and hw dst are both less than or
2832  *         equal to the dst MIN float number.
2833  *
2834  *-------------------------------------------------------------------------
2835  */
2836 static int
test_conv_flt_1(const char * name,int run_test,hid_t src,hid_t dst)2837 test_conv_flt_1 (const char *name, int run_test, hid_t src, hid_t dst)
2838 {
2839     dtype_t        src_type, dst_type;    /*data types        */
2840     size_t            nelmts=0;        /*num values per test    */
2841     const size_t    max_fails=8;        /*max number of failures*/
2842     size_t        fails_all_tests=0;    /*number of failures    */
2843     size_t        fails_this_test;    /*fails for this test    */
2844     const char        *src_type_name = NULL;    /*source type name    */
2845     const char        *dst_type_name = NULL;    /*destination type name    */
2846     size_t        src_size, dst_size;    /*type sizes        */
2847     unsigned char    *buf = NULL;        /*buffer for conversion    */
2848     unsigned char    *saved = NULL;        /*original values    */
2849     char        str[256];        /*hello string        */
2850     void        *aligned=NULL;        /*aligned buffer    */
2851     float        hw_f;            /*hardware-converted     */
2852     double        hw_d;            /*hardware-converted    */
2853 #if H5_SIZEOF_LONG_DOUBLE!=H5_SIZEOF_DOUBLE
2854     long double        hw_ld;            /*hardware-converted    */
2855 #endif
2856     unsigned char    *hw=NULL;        /*ptr to hardware-conv'd*/
2857     int            underflow;        /*underflow occurred    */
2858     int            overflow = 0;    /*overflow occurred    */
2859     int         uflow=0;        /*underflow debug counters*/
2860     size_t        j, k;            /*counters        */
2861     int            sendian;        /* source type endianess */
2862     int            dendian;        /* Destination type endianess */
2863     size_t        dst_ebias;        /* Destination type's exponent bias */
2864     size_t        src_epos;        /* Source type's exponent position */
2865     size_t        src_esize;        /* Source type's exponent size */
2866     size_t        dst_epos;        /* Destination type's exponent position */
2867     size_t        dst_esize;        /* Destination type's exponent size */
2868     size_t        dst_mpos;        /* Destination type's mantissa position */
2869     size_t        dst_msize;        /* Destination type's mantissa size */
2870     size_t        src_nbits;        /* source length in bits */
2871     size_t        dst_nbits;        /* dst length in bits */
2872 
2873 #ifdef HANDLE_SIGFPE
2874     pid_t        child_pid;        /*process ID of child    */
2875     int            status;            /*child exit status    */
2876 
2877     /*
2878      * Some systems generage SIGFPE during floating point overflow and we
2879      * cannot assume that we can continue from such a signal.  Therefore, we
2880      * fork here and let the child run the test and return the number of
2881      * failures with the exit status.
2882      */
2883     HDfflush(stdout);
2884     HDfflush(stderr);
2885     if ((child_pid=fork()) < 0) {
2886     HDperror("fork");
2887     return 1;
2888     } else if (child_pid>0) {
2889     while (child_pid!=waitpid(child_pid, &status, 0)) /*void*/;
2890     if (WIFEXITED(status) && 255==WEXITSTATUS(status)) {
2891         return 0; /*child exit after catching SIGFPE*/
2892     } else if (WIFEXITED(status)) {
2893         return WEXITSTATUS(status);
2894     } else if (WIFSIGNALED(status)) {
2895         HDsnprintf(str, sizeof(str), "   Child caught signal %d.", WTERMSIG(status));
2896         HDputs(str);
2897         return 1; /*child exit after catching non-SIGFPE signal */
2898     } else {
2899         HDputs("   Child didn't exit normally.");
2900         return 1;
2901     }
2902     }
2903 #endif
2904 
2905     /*
2906      * The remainder of this function is executed only by the child if
2907      * HANDLE_SIGFPE is defined.
2908      */
2909     HDsignal(SIGFPE,fpe_handler);
2910 
2911     /* What are the names of the source and destination types */
2912     if (H5Tequal(src, H5T_NATIVE_FLOAT)) {
2913     src_type_name = "float";
2914     src_type = FLT_FLOAT;
2915     } else if (H5Tequal(src, H5T_NATIVE_DOUBLE)) {
2916     src_type_name = "double";
2917     src_type = FLT_DOUBLE;
2918 #if H5_SIZEOF_LONG_DOUBLE!=H5_SIZEOF_DOUBLE && H5_SIZEOF_LONG_DOUBLE!=0
2919     } else if (H5Tequal(src, H5T_NATIVE_LDOUBLE)) {
2920     src_type_name = "long double";
2921     src_type = FLT_LDOUBLE;
2922 #endif
2923     } else {
2924     src_type_name = "UNKNOWN";
2925     src_type = OTHER;
2926     }
2927 
2928     if (H5Tequal(dst, H5T_NATIVE_FLOAT)) {
2929     dst_type_name = "float";
2930     dst_type = FLT_FLOAT;
2931     } else if (H5Tequal(dst, H5T_NATIVE_DOUBLE)) {
2932     dst_type_name = "double";
2933     dst_type = FLT_DOUBLE;
2934 #if H5_SIZEOF_LONG_DOUBLE!=H5_SIZEOF_DOUBLE && H5_SIZEOF_LONG_DOUBLE!=0
2935     } else if (H5Tequal(dst, H5T_NATIVE_LDOUBLE)) {
2936     dst_type_name = "long double";
2937     dst_type = FLT_LDOUBLE;
2938 #endif
2939     } else {
2940     dst_type_name = "UNKNOWN";
2941     dst_type = OTHER;
2942     }
2943 
2944     /* Sanity checks */
2945     if(sizeof(float)==sizeof(double))
2946         HDputs("Sizeof(float)==sizeof(double) - some tests may not be sensible.");
2947     if (OTHER==src_type || OTHER==dst_type) {
2948         if(!strcmp(name, "noop"))
2949         HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions",
2950         name, src_type_name, dst_type_name);
2951         else if(run_test==TEST_SPECIAL)
2952         HDsnprintf(str, sizeof(str), "Testing %s special %s -> %s conversions",
2953         name, src_type_name, dst_type_name);
2954         else if(run_test==TEST_NORMAL)
2955         HDsnprintf(str, sizeof(str), "Testing %s normalized %s -> %s conversions",
2956         name, src_type_name, dst_type_name);
2957         else if(run_test==TEST_DENORM)
2958         HDsnprintf(str, sizeof(str), "Testing %s denormalized %s -> %s conversions",
2959         name, src_type_name, dst_type_name);
2960 
2961     HDprintf("%-70s", str);
2962     H5_FAILED();
2963     HDputs("    Unknown data type.");
2964     goto error;
2965     } else {
2966         if(!strcmp(name, "noop"))
2967             HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions",
2968                 name, src_type_name, dst_type_name);
2969         else if(run_test==TEST_SPECIAL)
2970             HDsnprintf(str, sizeof(str), "Testing %s special %s -> %s conversions",
2971                 name, src_type_name, dst_type_name);
2972         else if(run_test==TEST_NORMAL)
2973             HDsnprintf(str, sizeof(str), "Testing %s normalized %s -> %s conversions",
2974                 name, src_type_name, dst_type_name);
2975         else if(run_test==TEST_DENORM)
2976             HDsnprintf(str, sizeof(str), "Testing %s denormalized %s -> %s conversions",
2977                 name, src_type_name, dst_type_name);
2978 
2979         HDprintf("%-70s", str);
2980         HDfflush(stdout);
2981         fails_this_test = 0;
2982     }
2983 
2984     /* Get "interesting" values */
2985     src_size = H5Tget_size(src);
2986     dst_size = H5Tget_size(dst);
2987     src_nbits = H5Tget_precision(src); /* not 8*src_size, esp on J90 - QAK */
2988     dst_nbits = H5Tget_precision(dst); /* not 8*dst_size, esp on J90 - QAK */
2989     dst_ebias=H5Tget_ebias(dst);
2990     H5Tget_fields(src,NULL,&src_epos,&src_esize,NULL,NULL);
2991     H5Tget_fields(dst,NULL,&dst_epos,&dst_esize,&dst_mpos,&dst_msize);
2992     sendian = H5Tget_order(src);
2993     dendian = H5Tget_order(dst);
2994 
2995     /* Allocate buffers */
2996     aligned = HDcalloc((size_t)1, MAX(sizeof(long double), sizeof(double)));
2997 
2998     /* Allocate and initialize the source buffer through macro INIT_FP_NORM or INIT_FP_SPECIAL.
2999      * The BUF will be used for the conversion while the SAVED buffer will be used for
3000      * the comparison later.  INIT_FP_NORM will fill in the buffer with regular values like
3001      * normalized and denormalized values; INIT_FP_SPECIAL will fill with special values
3002      * like infinity, NaN.
3003      */
3004     switch (run_test) {
3005         case TEST_NOOP:
3006         case TEST_NORMAL:
3007             if(src_type == FLT_FLOAT) {
3008                 INIT_FP_NORM(float, FLT_MAX, FLT_MIN, FLT_MAX_10_EXP, FLT_MIN_10_EXP,
3009                         src_size, dst_size, buf, saved, nelmts);
3010             } else if(src_type == FLT_DOUBLE) {
3011                 INIT_FP_NORM(double, DBL_MAX, DBL_MIN, DBL_MAX_10_EXP, DBL_MIN_10_EXP,
3012                         src_size, dst_size, buf, saved, nelmts);
3013 #if H5_SIZEOF_LONG_DOUBLE!=H5_SIZEOF_DOUBLE && H5_SIZEOF_LONG_DOUBLE!=0
3014             } else if(src_type == FLT_LDOUBLE) {
3015                 INIT_FP_NORM(long double, LDBL_MAX, LDBL_MIN, LDBL_MAX_10_EXP, LDBL_MIN_10_EXP,
3016                         src_size, dst_size, buf, saved, nelmts);
3017 #endif
3018             } else
3019                 goto error;
3020 
3021             break;
3022         case TEST_DENORM:
3023             if(src_type == FLT_FLOAT) {
3024                 INIT_FP_DENORM(float, FLT_MANT_DIG, src_size, src_nbits, sendian, dst_size,
3025                         buf, saved, nelmts);
3026             } else if(src_type == FLT_DOUBLE) {
3027                 INIT_FP_DENORM(double, DBL_MANT_DIG, src_size, src_nbits, sendian, dst_size,
3028                         buf, saved, nelmts);
3029 #if H5_SIZEOF_LONG_DOUBLE!=H5_SIZEOF_DOUBLE && H5_SIZEOF_LONG_DOUBLE!=0
3030             } else if(src_type == FLT_LDOUBLE) {
3031                 INIT_FP_DENORM(long double, LDBL_MANT_DIG, src_size, src_nbits, sendian, dst_size,
3032                         buf, saved, nelmts);
3033 #endif
3034             } else
3035                 goto error;
3036 
3037             break;
3038 
3039         case TEST_SPECIAL:
3040             if(src_type == FLT_FLOAT) {
3041                 INIT_FP_SPECIAL(src_size, src_nbits, sendian, FLT_MANT_DIG, dst_size,
3042                         buf, saved, nelmts);
3043             } else if(src_type == FLT_DOUBLE) {
3044                  INIT_FP_SPECIAL(src_size, src_nbits, sendian, DBL_MANT_DIG, dst_size,
3045                         buf, saved, nelmts);
3046 #if H5_SIZEOF_LONG_DOUBLE!=H5_SIZEOF_DOUBLE && H5_SIZEOF_LONG_DOUBLE!=0
3047             } else if(src_type == FLT_LDOUBLE) {
3048                  INIT_FP_SPECIAL(src_size, src_nbits, sendian, LDBL_MANT_DIG, dst_size,
3049                         buf, saved, nelmts);
3050 #endif
3051             } else
3052                 goto error;
3053 
3054             break;
3055         default:
3056             goto error;
3057     }
3058 
3059     /* Perform the conversion in software */
3060     if (H5Tconvert(src, dst, nelmts, buf, NULL, H5P_DEFAULT) < 0)
3061         goto error;
3062 
3063     /* Check the software results against the hardware */
3064     for (j=0; j<nelmts; j++) {
3065         underflow = 0;
3066         hw_f = 911.0f;
3067         hw_d = 911.0f;
3068 #if H5_SIZEOF_LONG_DOUBLE!=H5_SIZEOF_DOUBLE
3069         hw_ld = 911.0f;
3070 #endif
3071 
3072         /* The hardware conversion */
3073         /* Check for underflow when src is a "larger" float than dst.*/
3074         if (FLT_FLOAT==src_type) {
3075             HDmemcpy(aligned, saved+j*sizeof(float), sizeof(float));
3076             if (FLT_FLOAT==dst_type) {
3077                 hw_f = *((float*)aligned);
3078                 hw = (unsigned char*)&hw_f;
3079             } else if (FLT_DOUBLE==dst_type) {
3080                 hw_d = *((float*)aligned);
3081                 hw = (unsigned char*)&hw_d;
3082 #if H5_SIZEOF_LONG_DOUBLE!=H5_SIZEOF_DOUBLE
3083             } else {
3084                 hw_ld = *((float*)aligned);
3085                 hw = (unsigned char*)&hw_ld;
3086 #endif
3087             }
3088         } else if (FLT_DOUBLE==src_type) {
3089             HDmemcpy(aligned, saved+j*sizeof(double), sizeof(double));
3090             if (FLT_FLOAT==dst_type) {
3091                 hw_f = (float)(*((double*)aligned));
3092                 hw = (unsigned char*)&hw_f;
3093                 underflow = HDfabs(*((double*)aligned)) < (double)FLT_MIN;
3094                 overflow = HDfabs(*((double*)aligned)) > (double)FLT_MAX;
3095             } else if (FLT_DOUBLE==dst_type) {
3096                 hw_d = *((double*)aligned);
3097                 hw = (unsigned char*)&hw_d;
3098 #if H5_SIZEOF_LONG_DOUBLE!=H5_SIZEOF_DOUBLE
3099             } else {
3100                 hw_ld = *((double*)aligned);
3101                 hw = (unsigned char*)&hw_ld;
3102 #endif
3103             }
3104 #if H5_SIZEOF_LONG_DOUBLE!=H5_SIZEOF_DOUBLE
3105         } else {
3106             HDmemcpy(aligned, saved+j*sizeof(long double), sizeof(long double));
3107             if (FLT_FLOAT==dst_type) {
3108                 hw_f = (float)*((long double*)aligned);
3109                 hw = (unsigned char*)&hw_f;
3110                 underflow = HDfabsl(*((long double*)aligned)) < FLT_MIN;
3111                 overflow = HDfabsl(*((long double*)aligned)) > FLT_MAX;
3112             } else if (FLT_DOUBLE==dst_type) {
3113                 hw_d = (double)*((long double*)aligned);
3114                 hw = (unsigned char*)&hw_d;
3115                 underflow = HDfabsl(*((long double*)aligned)) < DBL_MIN;
3116                 overflow = HDfabsl(*((long double*)aligned)) > DBL_MAX;
3117             } else {
3118                 hw_ld = *((long double*)aligned);
3119                 hw = (unsigned char*)&hw_ld;
3120             }
3121 #endif
3122         }
3123         if (underflow){
3124             uflow++;
3125         }
3126 
3127         /* For Intel machines, the size of "long double" is 12 bytes, precision
3128          * is 80 bits; for Intel IA64 and AMD processors, the size of "long double"
3129          * is 16 bytes, precision is 80 bits.  During hardware conversion, the
3130          * last few unused bytes may have garbage in them.  Clean them out with
3131          * 0s before compare the values.
3132          */
3133 #if H5_SIZEOF_LONG_DOUBLE !=0
3134         if(sendian == H5T_ORDER_LE && dst_type == FLT_LDOUBLE) {
3135             size_t q;
3136 
3137             for(q = dst_nbits / 8; q < dst_size; q++) {
3138                 buf[j * dst_size + q] = 0x00;
3139                 hw[q] = 0x00;
3140             }
3141         }
3142 #endif
3143 
3144         /* Are the two results the same? */
3145         for (k=(dst_size-(dst_nbits/8)); k<dst_size; k++)
3146             if (buf[j*dst_size+k]!=hw[k])
3147                 break;
3148         if (k==dst_size)
3149             continue; /*no error*/
3150 
3151 
3152         /*
3153          * Assume same if both results are NaN.  There are many NaN bit
3154          * patterns and the software doesn't attemt to emulate the
3155          * hardware in this regard.  Instead, software uses a single bit
3156          * pattern for NaN by setting the significand to all ones.
3157          */
3158         if (FLT_FLOAT==dst_type &&
3159                 my_isnan(dst_type, buf+j*sizeof(float)) &&
3160                 my_isnan(dst_type, hw)) {
3161             continue;
3162         } else if (FLT_DOUBLE==dst_type &&
3163                 my_isnan(dst_type, buf+j*sizeof(double)) &&
3164                 my_isnan(dst_type, hw)) {
3165             continue;
3166 #if H5_SIZEOF_LONG_DOUBLE!=H5_SIZEOF_DOUBLE && H5_SIZEOF_LONG_DOUBLE!=0
3167         } else if (FLT_LDOUBLE==dst_type &&
3168                 my_isnan(dst_type, buf+j*sizeof(long double)) &&
3169                 my_isnan(dst_type, hw)) {
3170             continue;
3171 #endif
3172         }
3173 
3174         /*
3175          * Assume same if hardware result is NaN.  This is because the
3176          * hardware conversions on some machines return NaN instead of
3177          * overflowing to +Inf or -Inf or underflowing to +0 or -0.
3178          */
3179         if (my_isnan(dst_type, hw))
3180             continue;
3181 
3182         /*
3183          * Instead of matching down to the bit, just make sure the
3184          * exponents are the same and the mantissa is the same to a
3185          * certain precision.  This is needed on machines that don't
3186          * round as expected.
3187          * If the src number is smaller than the dst MIN float number,
3188          * consider it okay if the converted sw and hw dst are both
3189          * less than or equal to the dst MIN float number.
3190          * If overflow happens when the src value is greater than
3191          * the maximum dst value, the library assign INFINITY to dst.
3192          * This might be different from what the compiler does, i.e.
3193          * the SGI compiler assigns the dst's maximal value.
3194          */
3195         {
3196             double        check_mant[2];
3197             int        check_expo[2];
3198 
3199             if (FLT_FLOAT==dst_type) {
3200                 float x;
3201                 HDmemcpy(&x, &buf[j*dst_size], sizeof(float));
3202                 if (underflow &&
3203                         HDfabsf(x) <= FLT_MIN && HDfabsf(hw_f) <= FLT_MIN)
3204                     continue;    /* all underflowed, no error */
3205                 if (overflow && my_isinf(dendian, buf+j*sizeof(float),
3206                         dst_size, dst_mpos, dst_msize, dst_epos, dst_esize))
3207                     continue;    /* all overflowed, no error */
3208                 check_mant[0] = HDfrexpf(x, check_expo+0);
3209                 check_mant[1] = HDfrexpf(hw_f, check_expo+1);
3210             } else if (FLT_DOUBLE==dst_type) {
3211                 double x;
3212                 HDmemcpy(&x, &buf[j*dst_size], sizeof(double));
3213                 if (underflow &&
3214                         HDfabs(x) <= DBL_MIN && HDfabs(hw_d) <= DBL_MIN)
3215                     continue;    /* all underflowed, no error */
3216                 if (overflow && my_isinf(dendian, buf+j*sizeof(double),
3217                         dst_size, dst_mpos, dst_msize, dst_epos, dst_esize))
3218                     continue;    /* all overflowed, no error */
3219                 check_mant[0] = HDfrexp(x, check_expo+0);
3220                 check_mant[1] = HDfrexp(hw_d, check_expo+1);
3221 #if H5_SIZEOF_LONG_DOUBLE !=0 && (H5_SIZEOF_LONG_DOUBLE!=H5_SIZEOF_DOUBLE)
3222             } else {
3223                 long double x;
3224                 HDmemcpy(&x, &buf[j*dst_size], sizeof(long double));
3225                 /* dst is largest float, no need to check underflow. */
3226                 check_mant[0] = (double)HDfrexpl(x, check_expo+0);
3227                 check_mant[1] = (double)HDfrexpl(hw_ld, check_expo+1);
3228 #endif
3229             }
3230             /* Special check for denormalized values */
3231             if(check_expo[0]<(-(int)dst_ebias) || check_expo[1]<(-(int)dst_ebias)) {
3232                 int expo_diff = check_expo[0] - check_expo[1];
3233                 int valid_bits = (int)((dst_ebias + dst_msize) + (size_t)MIN(check_expo[0], check_expo[1])) - 1;
3234                 double epsilon = 1.0F;
3235 
3236                 /* Re-scale the mantissas based on any exponent difference */
3237                 if(expo_diff!=0)
3238                     check_mant[0] = HDldexp(check_mant[0],expo_diff);
3239 
3240                 /* Compute the proper epsilon */
3241                 epsilon=HDldexp(epsilon,-valid_bits);
3242 
3243                 /* Check for "close enough" fit with scaled epsilon value */
3244                 if (HDfabs(check_mant[0]-check_mant[1])<=epsilon)
3245                     continue;
3246             } /* end if */
3247             else {
3248                 if(check_expo[0] == check_expo[1] &&
3249                         HDfabs(check_mant[0] - check_mant[1]) < (double)FP_EPSILON)
3250                     continue;
3251             } /* end else */
3252         }
3253 
3254         if (0==fails_this_test++) {
3255             if(run_test==TEST_NOOP || run_test==TEST_NORMAL) {
3256                 H5_FAILED();
3257             } else if(run_test==TEST_DENORM || run_test==TEST_SPECIAL) {
3258                 H5_WARNING();
3259             }
3260         }
3261         HDprintf("    elmt %u\n", (unsigned)j);
3262 
3263         HDprintf("        src =");
3264         for (k=0; k<src_size; k++)
3265             HDprintf(" %02x", saved[j*src_size+ENDIAN(src_size,k,sendian)]);
3266         HDprintf("%*s", (int)(3*MAX(0, (ssize_t)dst_size-(ssize_t)src_size)), "");
3267         if (FLT_FLOAT==src_type) {
3268             float x;
3269             HDmemcpy(&x, &saved[j*src_size], sizeof(float));
3270             HDprintf(" %29.20e\n", (double)x);
3271         } else if (FLT_DOUBLE==src_type) {
3272             double x;
3273             HDmemcpy(&x, &saved[j*src_size], sizeof(double));
3274             HDprintf(" %29.20e\n", x);
3275 #if H5_SIZEOF_LONG_DOUBLE!=H5_SIZEOF_DOUBLE
3276         } else {
3277             long double x;
3278             HDmemcpy(&x, &saved[j*src_size], sizeof(long double));
3279             HDfprintf(stdout," %29.20Le\n", x);
3280 #endif
3281         }
3282 
3283         HDprintf("        dst =");
3284         for (k=0; k<dst_size; k++)
3285             HDprintf(" %02x", buf[j*dst_size+ENDIAN(dst_size,k,dendian)]);
3286         HDprintf("%*s", (int)(3*MAX(0, (ssize_t)src_size-(ssize_t)dst_size)), "");
3287         if (FLT_FLOAT==dst_type) {
3288             float x;
3289             HDmemcpy(&x, &buf[j*dst_size], sizeof(float));
3290             HDprintf(" %29.20e\n", (double)x);
3291         } else if (FLT_DOUBLE==dst_type) {
3292             double x;
3293             HDmemcpy(&x, &buf[j*dst_size], sizeof(double));
3294             HDprintf(" %29.20e\n", x);
3295 #if H5_SIZEOF_LONG_DOUBLE!=H5_SIZEOF_DOUBLE
3296         } else {
3297             long double x;
3298             HDmemcpy(&x, &buf[j*dst_size], sizeof(long double));
3299             HDfprintf(stdout," %29.20Le\n", x);
3300 #endif
3301         }
3302 
3303         HDprintf("        ans =");
3304         for (k=0; k<dst_size; k++)
3305             HDprintf(" %02x", hw[ENDIAN(dst_size,k,dendian)]);
3306         HDprintf("%*s", (int)(3*MAX(0, (ssize_t)src_size-(ssize_t)dst_size)), "");
3307         if (FLT_FLOAT==dst_type)
3308             HDprintf(" %29.20e\n", (double)hw_f);
3309         else if (FLT_DOUBLE==dst_type)
3310             HDprintf(" %29.20e\n", hw_d);
3311 #if H5_SIZEOF_LONG_DOUBLE!=H5_SIZEOF_DOUBLE
3312         else
3313             HDfprintf(stdout," %29.20Le\n", hw_ld);
3314 #endif
3315 
3316         /* If the source is normalized values, print out error message; if it is
3317          * denormalized or special values, print out warning message.*/
3318         if (++fails_all_tests>=max_fails) {
3319             if(run_test==TEST_NORMAL)
3320                 HDputs("    maximum failures reached, aborting test...");
3321             else if(run_test==TEST_DENORM || run_test==TEST_SPECIAL)
3322                 HDputs("    maximum warnings reached, aborting test...");
3323             HDputs("    (dst is library's conversion output. ans is compiler's conversion output.)");
3324 
3325             goto done;
3326         }
3327     }
3328 
3329     if(!fails_all_tests)
3330         PASSED();
3331 
3332 done:
3333     if (buf) aligned_free(buf);
3334     if (saved) aligned_free(saved);
3335     if (aligned) HDfree(aligned);
3336     HDfflush(stdout);
3337 #ifdef HANDLE_SIGFPE
3338     if(run_test==TEST_NOOP || run_test==TEST_NORMAL)
3339         HDexit(MIN((int)fails_all_tests, 254));
3340     else if(run_test==TEST_DENORM || run_test==TEST_SPECIAL)
3341         HDexit(EXIT_SUCCESS);
3342     HDassert(0 && "Should not reach this point!");
3343     return 1;
3344 #else
3345     /* Restore the default error handler (set in h5_reset()) */
3346     h5_restore_err();
3347 
3348     reset_hdf5();
3349 
3350     /* If the source is normalized values, treat the failures as error;
3351      * if it is denormalized or special values, treat the failure as warning.*/
3352     if(run_test==TEST_NOOP || run_test==TEST_NORMAL)
3353         return (int)fails_all_tests;
3354     else if(run_test==TEST_DENORM || run_test==TEST_SPECIAL)
3355         return 0;
3356 #endif
3357 
3358 error:
3359     if (buf) aligned_free(buf);
3360     if (saved) aligned_free(saved);
3361     if (aligned) HDfree(aligned);
3362     HDfflush(stdout);
3363 #ifdef HANDLE_SIGFPE
3364     if(run_test==TEST_NOOP || run_test==TEST_NORMAL)
3365         HDexit(MIN(MAX((int)fails_all_tests, 1), 254));
3366     else if(run_test==TEST_DENORM || run_test==TEST_SPECIAL)
3367         HDexit(EXIT_FAILURE);
3368     HDassert(0 && "Should not reach this point!");
3369     return 1;
3370 #else
3371     /* Restore the default error handler (set in h5_reset()) */
3372     h5_restore_err();
3373 
3374     reset_hdf5();
3375 
3376     if(run_test==TEST_NOOP || run_test==TEST_NORMAL)
3377         return MAX((int)fails_all_tests, 1);
3378     else if(run_test==TEST_DENORM || run_test==TEST_SPECIAL)
3379         return 1;
3380 #endif
3381 }
3382 
3383 
3384 /*-------------------------------------------------------------------------
3385  * Function:    test_conv_int_fp
3386  *
3387  * Purpose:    Test conversion between integer and float values
3388  *              from SRC to DST.  These types should be any combination of:
3389  *
3390  *             H5T_NATIVE_SCHAR    H5T_NATIVE_FLOAT
3391  *            H5T_NATIVE_SHORT    H5T_NATIVE_DOUBLE
3392  *            H5T_NATIVE_INT        H5T_NATIVE_LDOUBLE
3393  *            H5T_NATIVE_LONG
3394  *            H5T_NATIVE_LLONG
3395  *
3396  * Return:    Success:    0
3397  *
3398  *        Failure:    number of errors
3399  *
3400  * Programmer:    Raymond Lu
3401  *              Thursday, November 6, 2003
3402  *
3403  * Modifications:
3404  *
3405  *-------------------------------------------------------------------------
3406  */
3407 static int
test_conv_int_fp(const char * name,int run_test,hid_t src,hid_t dst)3408 test_conv_int_fp(const char *name, int run_test, hid_t src, hid_t dst)
3409 {
3410     hid_t               dxpl_id;                /*dataset transfer property list*/
3411     int                 fill_value=9;           /*fill value for conversion exception*/
3412     H5T_conv_except_func_t   op;                /*returned callback function for conversion exception*/
3413     void                *user_data;             /*returned pointer to user data passed in to the callback*/
3414     hbool_t             except_set = FALSE;     /*whether user's exception handling is set*/
3415     size_t            nelmts=0;            /*num values per test    */
3416     const size_t    max_fails=40;        /*max number of failures*/
3417     size_t        fails_all_tests=0;    /*number of failures    */
3418     size_t        fails_this_test;    /*fails for this test    */
3419     char        str[256];        /*hello string        */
3420     dtype_t        src_type;            /*data types        */
3421     dtype_t        dst_type;            /*data types        */
3422     const char        *src_type_name=NULL;    /*source type name    */
3423     const char        *dst_type_name=NULL;    /*destination type name    */
3424     int            sendian;        /*source endianess    */
3425     int            dendian;        /*destination endianess    */
3426     size_t        src_size, dst_size;    /*type sizes        */
3427     unsigned char    *buf=NULL;        /*buffer for conversion    */
3428     unsigned char    *saved=NULL;        /*original values    */
3429     size_t        j, k;            /*counters        */
3430     unsigned char     *hw=NULL;        /*hardware conv result    */
3431     unsigned char    src_bits[32];        /*src value in LE order    */
3432     unsigned char    dst_bits[32];        /*dest value in LE order*/
3433     size_t        src_nbits;        /*source length in bits    */
3434     size_t        dst_nbits;        /*dst length in bits    */
3435     void        *aligned=NULL;        /*aligned temp buffer    */
3436     float        hw_float=0;
3437     double            hw_double=0;
3438     long double        hw_ldouble=0;
3439     signed char        hw_schar=0;
3440     unsigned char    hw_uchar=0;
3441     short        hw_short=0;
3442     unsigned short    hw_ushort=0;
3443     int            hw_int=0;
3444     unsigned        hw_uint=0;
3445     long        hw_long=0;
3446     unsigned long    hw_ulong=0;
3447     long long        hw_llong=0;
3448     unsigned long long    hw_ullong=0;
3449 
3450     /* What is the name of the source type */
3451     if (H5Tequal(src, H5T_NATIVE_SCHAR)) {
3452     src_type_name = "signed char";
3453     src_type = INT_SCHAR;
3454     } else if (H5Tequal(src, H5T_NATIVE_UCHAR)) {
3455     src_type_name = "unsigned char";
3456     src_type = INT_UCHAR;
3457     } else if (H5Tequal(src, H5T_NATIVE_SHORT)) {
3458     src_type_name = "short";
3459     src_type = INT_SHORT;
3460     } else if (H5Tequal(src, H5T_NATIVE_USHORT)) {
3461     src_type_name = "unsigned short";
3462     src_type = INT_USHORT;
3463     } else if (H5Tequal(src, H5T_NATIVE_INT)) {
3464     src_type_name = "int";
3465     src_type = INT_INT;
3466     } else if (H5Tequal(src, H5T_NATIVE_UINT)) {
3467     src_type_name = "unsigned int";
3468     src_type = INT_UINT;
3469     } else if (H5Tequal(src, H5T_NATIVE_LONG)) {
3470     src_type_name = "long";
3471     src_type = INT_LONG;
3472     } else if (H5Tequal(src, H5T_NATIVE_ULONG)) {
3473     src_type_name = "unsigned long";
3474     src_type = INT_ULONG;
3475     } else if (H5Tequal(src, H5T_NATIVE_LLONG)) {
3476     src_type_name = "long long";
3477     src_type = INT_LLONG;
3478     } else if (H5Tequal(src, H5T_NATIVE_ULLONG)) {
3479     src_type_name = "unsigned long long";
3480     src_type = INT_ULLONG;
3481     } else if (H5Tequal(src, H5T_NATIVE_FLOAT)) {
3482     src_type_name = "float";
3483     src_type = FLT_FLOAT;
3484     } else if (H5Tequal(src, H5T_NATIVE_DOUBLE)) {
3485     src_type_name = "double";
3486     src_type = FLT_DOUBLE;
3487 #if H5_SIZEOF_LONG_DOUBLE!=H5_SIZEOF_DOUBLE && H5_SIZEOF_LONG_DOUBLE!=0
3488     } else if (H5Tequal(src, H5T_NATIVE_LDOUBLE)) {
3489     src_type_name = "long double";
3490     src_type = FLT_LDOUBLE;
3491 #endif
3492     } else {
3493     src_type_name = "UNKNOWN";
3494     src_type = OTHER;
3495     }
3496 
3497     /* What is the name of the destination type */
3498     if (H5Tequal(dst, H5T_NATIVE_SCHAR)) {
3499     dst_type_name = "signed char";
3500     dst_type = INT_SCHAR;
3501     } else if (H5Tequal(dst, H5T_NATIVE_UCHAR)) {
3502     dst_type_name = "unsigned char";
3503     dst_type = INT_UCHAR;
3504     } else if (H5Tequal(dst, H5T_NATIVE_SHORT)) {
3505     dst_type_name = "short";
3506     dst_type = INT_SHORT;
3507     } else if (H5Tequal(dst, H5T_NATIVE_USHORT)) {
3508     dst_type_name = "unsigned short";
3509     dst_type = INT_USHORT;
3510     } else if (H5Tequal(dst, H5T_NATIVE_INT)) {
3511     dst_type_name = "int";
3512     dst_type = INT_INT;
3513     } else if (H5Tequal(dst, H5T_NATIVE_UINT)) {
3514     dst_type_name = "unsigned int";
3515     dst_type = INT_UINT;
3516     } else if (H5Tequal(dst, H5T_NATIVE_LONG)) {
3517     dst_type_name = "long";
3518     dst_type = INT_LONG;
3519     } else if (H5Tequal(dst, H5T_NATIVE_ULONG)) {
3520     dst_type_name = "unsigned long";
3521     dst_type = INT_ULONG;
3522     } else if (H5Tequal(dst, H5T_NATIVE_LLONG)) {
3523     dst_type_name = "long long";
3524     dst_type = INT_LLONG;
3525     } else if (H5Tequal(dst, H5T_NATIVE_ULLONG)) {
3526     dst_type_name = "unsigned long long";
3527     dst_type = INT_ULLONG;
3528     } else if (H5Tequal(dst, H5T_NATIVE_FLOAT)) {
3529     dst_type_name = "float";
3530     dst_type = FLT_FLOAT;
3531     } else if (H5Tequal(dst, H5T_NATIVE_DOUBLE)) {
3532     dst_type_name = "double";
3533     dst_type = FLT_DOUBLE;
3534 #if H5_SIZEOF_LONG_DOUBLE!=H5_SIZEOF_DOUBLE && H5_SIZEOF_LONG_DOUBLE!=0
3535     } else if (H5Tequal(dst, H5T_NATIVE_LDOUBLE)) {
3536     dst_type_name = "long double";
3537     dst_type = FLT_LDOUBLE;
3538 #endif
3539     } else {
3540     dst_type_name = "UNKNOWN";
3541     dst_type = OTHER;
3542     }
3543 
3544     /* Sanity checks */
3545     if (OTHER==src_type || OTHER==dst_type) {
3546     HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions",
3547         name, src_type_name, dst_type_name);
3548     HDprintf("%-70s", str);
3549     H5_FAILED();
3550     HDputs("    Unknown data type.");
3551     goto error;
3552     }
3553 
3554     if ((INT_SCHAR==src_type || INT_UCHAR==src_type || INT_SHORT==src_type ||
3555             INT_USHORT==src_type || INT_INT==src_type || INT_UINT==src_type ||
3556             INT_LONG==src_type || INT_ULONG==src_type || INT_LLONG==src_type ||
3557             INT_ULLONG==src_type) &&
3558             (FLT_FLOAT!=dst_type && FLT_DOUBLE!=dst_type
3559 #if H5_SIZEOF_LONG_DOUBLE !=0
3560             && FLT_LDOUBLE!=dst_type
3561 #endif
3562             )) {
3563     HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions",
3564         name, src_type_name, dst_type_name);
3565     HDprintf("%-70s", str);
3566     H5_FAILED();
3567     HDputs("    1. Not an integer-float conversion.");
3568     goto error;
3569     }
3570 
3571     if ((FLT_FLOAT==src_type || FLT_DOUBLE==src_type
3572 #if H5_SIZEOF_LONG_DOUBLE !=0
3573             || FLT_LDOUBLE==src_type
3574 #endif
3575             )
3576             && (INT_SCHAR!=dst_type && INT_UCHAR!=dst_type && INT_SHORT!=dst_type
3577             && INT_USHORT!=dst_type && INT_INT!=dst_type && INT_UINT!=dst_type
3578             && INT_LONG!=dst_type && INT_ULONG!=dst_type && INT_LLONG!=dst_type
3579             && INT_ULLONG!=dst_type)) {
3580     HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions",
3581         name, src_type_name, dst_type_name);
3582     HDprintf("%-70s", str);
3583     H5_FAILED();
3584     HDputs("    2. Not a float-integer conversion.");
3585     goto error;
3586     }
3587 
3588     if (INT_SCHAR==src_type || INT_UCHAR==src_type || INT_SHORT==src_type ||
3589             INT_USHORT==src_type || INT_INT==src_type || INT_UINT==src_type ||
3590             INT_LONG==src_type || INT_ULONG==src_type || INT_LLONG==src_type ||
3591             INT_ULLONG==src_type) {
3592         HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions",
3593             name, src_type_name, dst_type_name);
3594         HDprintf("%-70s", str);
3595         HDfflush(stdout);
3596         fails_this_test=0;
3597     } else {
3598         if(run_test==TEST_NORMAL)
3599             HDsnprintf(str, sizeof(str), "Testing %s normalized %s -> %s conversions",
3600                     name, src_type_name, dst_type_name);
3601         else if(run_test==TEST_DENORM)
3602             HDsnprintf(str, sizeof(str), "Testing %s denormalized %s -> %s conversions",
3603                     name, src_type_name, dst_type_name);
3604         else
3605             HDsnprintf(str, sizeof(str), "Testing %s special %s -> %s conversions",
3606                     name, src_type_name, dst_type_name);
3607         HDprintf("%-70s", str);
3608         HDfflush(stdout);
3609         fails_this_test=0;
3610     }
3611 
3612     /* Some information about datatypes */
3613     sendian = H5Tget_order(src);
3614     dendian = H5Tget_order(dst);
3615     src_size = H5Tget_size(src);
3616     dst_size = H5Tget_size(dst);
3617     src_nbits = H5Tget_precision(src); /* not 8*src_size, esp on J90 - QAK */
3618     dst_nbits = H5Tget_precision(dst); /* not 8*dst_size, esp on J90 - QAK */
3619     aligned = HDcalloc((size_t)1, MAX(sizeof(long double), sizeof(long long)));
3620 #ifdef SHOW_OVERFLOWS
3621     noverflows_g = 0;
3622 #endif
3623 
3624     /* This is for some Linux systems where long double has the size
3625      * 12 bytes but precision is 10 bytes.  The 2 unused bytes may
3626      * have garbage causing wrong value comparison.
3627      */
3628     HDmemset(&hw_ldouble, 0, sizeof(long double));
3629 
3630     /* Create a dataset transfer property list and datatype conversion
3631      * exception handler function and pass in fill value.  This is mainly
3632      * for NetCDF compatibility, which requests fill in fill value when
3633      * conversion exception happens.  We only test (unsigned) int - float
3634      * and float - (unsigned) int conversions, which should cover more cases.
3635      */
3636     if((dxpl_id = H5Pcreate(H5P_DATASET_XFER)) < 0)
3637         goto error;
3638 
3639     if((src_type == INT_INT && dst_type == FLT_FLOAT) ||
3640             (src_type == INT_UINT && dst_type == FLT_FLOAT) ||
3641             (src_type == FLT_FLOAT && dst_type == INT_UINT) ||
3642             (src_type == FLT_FLOAT && dst_type == INT_INT)) {
3643         if(H5Pset_type_conv_cb(dxpl_id, except_func, &fill_value) < 0)
3644             goto error;
3645         else
3646             except_set = TRUE;
3647 
3648         if(H5Pget_type_conv_cb(dxpl_id, &op, &user_data) < 0)
3649             goto error;
3650 
3651         if(op != except_func || *(int*)user_data != fill_value)
3652             goto error;
3653     }
3654 
3655     /* Allocate and initialize the source buffer through macro INIT_INTEGER if the source is integer,
3656      * INIT_FP_NORM if floating-point.  The BUF will be used for the conversion while the SAVED buffer will be
3657      * used for the comparison later.
3658      */
3659     if(src_type == INT_SCHAR) {
3660         INIT_INTEGER(signed char, SCHAR_MAX, SCHAR_MIN, src_size, dst_size, src_nbits, buf, saved, nelmts);
3661     } else if(src_type == INT_UCHAR) {
3662         INIT_INTEGER(unsigned char, UCHAR_MAX, 0, src_size, dst_size, src_nbits, buf, saved, nelmts);
3663     } else if(src_type == INT_SHORT) {
3664         INIT_INTEGER(short, SHRT_MAX, SHRT_MIN, src_size, dst_size, src_nbits, buf, saved, nelmts);
3665     } else if(src_type == INT_USHORT) {
3666         INIT_INTEGER(unsigned short, USHRT_MAX, 0, src_size, dst_size, src_nbits, buf, saved, nelmts);
3667     } else if(src_type == INT_INT) {
3668         INIT_INTEGER(int, INT_MAX, INT_MIN, src_size, dst_size, src_nbits, buf, saved, nelmts);
3669     } else if(src_type == INT_UINT) {
3670         INIT_INTEGER(unsigned int, UINT_MAX, 0, src_size, dst_size, src_nbits, buf, saved, nelmts);
3671     } else if(src_type == INT_LONG) {
3672         INIT_INTEGER(long, LONG_MAX, LONG_MIN, src_size, dst_size, src_nbits, buf, saved, nelmts);
3673     } else if(src_type == INT_ULONG) {
3674         INIT_INTEGER(unsigned long, ULONG_MAX, 0, src_size, dst_size, src_nbits, buf, saved, nelmts);
3675     } else if(src_type == INT_LLONG) {
3676         INIT_INTEGER(long long, LLONG_MAX, LLONG_MIN, src_size, dst_size, src_nbits, buf, saved, nelmts);
3677     } else if(src_type == INT_ULLONG) {
3678         INIT_INTEGER(unsigned long long, ULLONG_MAX, 0, src_size, dst_size, src_nbits, buf, saved, nelmts);
3679     } else if(src_type == FLT_FLOAT) {
3680         if(run_test==TEST_NORMAL) {
3681             INIT_FP_NORM(float, FLT_MAX, FLT_MIN, FLT_MAX_10_EXP, FLT_MIN_10_EXP,
3682                     src_size, dst_size, buf, saved, nelmts);
3683         } else if(run_test==TEST_DENORM) {
3684             INIT_FP_DENORM(float, FLT_MANT_DIG, src_size, src_nbits, sendian, dst_size,
3685                     buf, saved, nelmts);
3686         } else {
3687             INIT_FP_SPECIAL(src_size, src_nbits, sendian, FLT_MANT_DIG, dst_size, buf, saved, nelmts);
3688         }
3689     } else if(src_type == FLT_DOUBLE) {
3690         if(run_test==TEST_NORMAL) {
3691             INIT_FP_NORM(double, DBL_MAX, DBL_MIN, DBL_MAX_10_EXP, DBL_MIN_10_EXP,
3692                     src_size, dst_size, buf, saved, nelmts);
3693         } else if(run_test==TEST_DENORM) {
3694             INIT_FP_DENORM(double, DBL_MANT_DIG, src_size, src_nbits, sendian, dst_size,
3695                     buf, saved, nelmts);
3696         } else {
3697             INIT_FP_SPECIAL(src_size, src_nbits, sendian, DBL_MANT_DIG, dst_size, buf, saved, nelmts);
3698         }
3699 #if H5_SIZEOF_LONG_DOUBLE!=H5_SIZEOF_DOUBLE && H5_SIZEOF_LONG_DOUBLE!=0
3700     } else if(src_type == FLT_LDOUBLE) {
3701         if(run_test==TEST_NORMAL) {
3702             INIT_FP_NORM(long double, LDBL_MAX, LDBL_MIN, LDBL_MAX_10_EXP, LDBL_MIN_10_EXP,
3703                     src_size, dst_size, buf, saved, nelmts);
3704         } else if(run_test==TEST_DENORM) {
3705             INIT_FP_DENORM(long double, LDBL_MANT_DIG, src_size, src_nbits, sendian, dst_size,
3706                     buf, saved, nelmts);
3707         } else {
3708             INIT_FP_SPECIAL(src_size, src_nbits, sendian, LDBL_MANT_DIG, dst_size, buf, saved, nelmts);
3709         }
3710 #endif
3711     } else
3712         goto error;
3713 
3714     /* Perform the conversion */
3715     if(H5Tconvert(src, dst, nelmts, buf, NULL, dxpl_id) < 0)
3716         goto error;
3717 
3718     /* Check the results from the library against hardware */
3719     for (j=0; j<nelmts; j++) {
3720         if(FLT_FLOAT==src_type || FLT_DOUBLE==src_type
3721 #if H5_SIZEOF_LONG_DOUBLE !=0
3722             || FLT_LDOUBLE==src_type
3723 #endif
3724             )
3725             if(my_isnan(src_type, saved+j*src_size))
3726                 continue;
3727 
3728         if (FLT_FLOAT==dst_type) {
3729             hw = (unsigned char*)&hw_float;
3730             switch (src_type) {
3731             case INT_SCHAR:
3732                 HDmemcpy(aligned, saved+j*sizeof(signed char), sizeof(signed char));
3733                 hw_float = (float)(*((signed char*)aligned));
3734                 break;
3735             case INT_UCHAR:
3736                 HDmemcpy(aligned, saved+j*sizeof(unsigned char), sizeof(unsigned char));
3737                 hw_float = (float)(*((unsigned char*)aligned));
3738                 break;
3739             case INT_SHORT:
3740                 HDmemcpy(aligned, saved+j*sizeof(short), sizeof(short));
3741                 hw_float = (float)(*((short*)aligned));
3742                 break;
3743             case INT_USHORT:
3744                 HDmemcpy(aligned, saved+j*sizeof(unsigned short), sizeof(unsigned short));
3745                 hw_float = (float)(*((unsigned short*)aligned));
3746                 break;
3747             case INT_INT:
3748                 HDmemcpy(aligned, saved+j*sizeof(int), sizeof(int));
3749                 hw_float = (float)(*((int*)aligned));
3750                 break;
3751             case INT_UINT:
3752                 HDmemcpy(aligned, saved+j*sizeof(unsigned), sizeof(unsigned));
3753                 hw_float = (float)(*((unsigned*)aligned));
3754                 break;
3755             case INT_LONG:
3756                 HDmemcpy(aligned, saved+j*sizeof(long), sizeof(long));
3757                 hw_float = (float)(*((long*)aligned));
3758                 break;
3759             case INT_ULONG:
3760                 HDmemcpy(aligned, saved+j*sizeof(unsigned long), sizeof(unsigned long));
3761                 hw_float = (float)(*((unsigned long*)aligned));
3762                 break;
3763             case INT_LLONG:
3764                 HDmemcpy(aligned, saved+j*sizeof(long long), sizeof(long long));
3765                 hw_float = (float)(*((long long*)aligned));
3766                 break;
3767             case INT_ULLONG:
3768                 HDmemcpy(aligned, saved+j*sizeof(unsigned long long), sizeof(unsigned long long));
3769                 hw_float = (float)(*((unsigned long long*)aligned));
3770                 break;
3771             case FLT_FLOAT:
3772             case FLT_DOUBLE:
3773             case FLT_LDOUBLE:
3774             case OTHER:
3775             default:
3776                 HDassert(0 && "Unknown type");
3777                 break;
3778             }
3779         } else if (FLT_DOUBLE==dst_type) {
3780             hw = (unsigned char*)&hw_double;
3781             switch (src_type) {
3782             case INT_SCHAR:
3783                 HDmemcpy(aligned, saved+j*sizeof(signed char), sizeof(signed char));
3784                 hw_double = (double)(*((signed char*)aligned));
3785                 break;
3786             case INT_UCHAR:
3787                 HDmemcpy(aligned, saved+j*sizeof(unsigned char), sizeof(unsigned char));
3788                 hw_double = (double)(*((unsigned char*)aligned));
3789                 break;
3790             case INT_SHORT:
3791                 HDmemcpy(aligned, saved+j*sizeof(short), sizeof(short));
3792                 hw_double = (double)(*((short*)aligned));
3793                 break;
3794             case INT_USHORT:
3795                 HDmemcpy(aligned, saved+j*sizeof(unsigned short), sizeof(unsigned short));
3796                 hw_double = (double)(*((unsigned short*)aligned));
3797                 break;
3798             case INT_INT:
3799                 HDmemcpy(aligned, saved+j*sizeof(int), sizeof(int));
3800                 hw_double = (double)(*((int*)aligned));
3801                 break;
3802             case INT_UINT:
3803                 HDmemcpy(aligned, saved+j*sizeof(unsigned), sizeof(unsigned));
3804                 hw_double = (double)(*((unsigned*)aligned));
3805                 break;
3806             case INT_LONG:
3807                 HDmemcpy(aligned, saved+j*sizeof(long), sizeof(long));
3808                 hw_double = (double)(*((long*)aligned));
3809                 break;
3810             case INT_ULONG:
3811                 HDmemcpy(aligned, saved+j*sizeof(unsigned long), sizeof(unsigned long));
3812                 hw_double = (double)(*((unsigned long*)aligned));
3813                 break;
3814             case INT_LLONG:
3815                 HDmemcpy(aligned, saved+j*sizeof(long long), sizeof(long long));
3816                 hw_double = (double)(*((long long*)aligned));
3817                 break;
3818             case INT_ULLONG:
3819                 HDmemcpy(aligned, saved+j*sizeof(unsigned long long), sizeof(unsigned long long));
3820                 hw_double = (double)(*((unsigned long long*)aligned));
3821                 break;
3822             case FLT_FLOAT:
3823             case FLT_DOUBLE:
3824             case FLT_LDOUBLE:
3825             case OTHER:
3826             default:
3827                 HDassert(0 && "Unknown type");
3828                 break;
3829             }
3830 #if H5_SIZEOF_LONG_DOUBLE !=0
3831         } else if (FLT_LDOUBLE==dst_type) {
3832             hw = (unsigned char*)&hw_ldouble;
3833             switch (src_type) {
3834             case INT_SCHAR:
3835                 HDmemcpy(aligned, saved+j*sizeof(signed char), sizeof(signed char));
3836                 hw_ldouble = (long double)(*((signed char*)aligned));
3837                 break;
3838             case INT_UCHAR:
3839                 HDmemcpy(aligned, saved+j*sizeof(unsigned char), sizeof(unsigned char));
3840                 hw_ldouble = (long double)(*((unsigned char*)aligned));
3841                 break;
3842             case INT_SHORT:
3843                 HDmemcpy(aligned, saved+j*sizeof(short), sizeof(short));
3844                 hw_ldouble = (long double)(*((short*)aligned));
3845                 break;
3846             case INT_USHORT:
3847                 HDmemcpy(aligned, saved+j*sizeof(unsigned short), sizeof(unsigned short));
3848                 hw_ldouble = (long double)(*((unsigned short*)aligned));
3849                 break;
3850             case INT_INT:
3851                 HDmemcpy(aligned, saved+j*sizeof(int), sizeof(int));
3852                 hw_ldouble = (long double)(*((int*)aligned));
3853                 break;
3854             case INT_UINT:
3855                 HDmemcpy(aligned, saved+j*sizeof(unsigned), sizeof(unsigned));
3856                 hw_ldouble = (long double)(*((unsigned*)aligned));
3857                 break;
3858             case INT_LONG:
3859                 HDmemcpy(aligned, saved+j*sizeof(long), sizeof(long));
3860                 hw_ldouble = (long double)(*((long*)aligned));
3861                 break;
3862             case INT_ULONG:
3863                 HDmemcpy(aligned, saved+j*sizeof(unsigned long), sizeof(unsigned long));
3864                 hw_ldouble = (long double)(*((unsigned long*)aligned));
3865                 break;
3866             case INT_LLONG:
3867                 HDmemcpy(aligned, saved+j*sizeof(long long), sizeof(long long));
3868                 hw_ldouble = (long double)(*((long long*)aligned));
3869                 break;
3870             case INT_ULLONG:
3871                 HDmemcpy(aligned, saved+j*sizeof(unsigned long long), sizeof(unsigned long long));
3872                 hw_ldouble = (long double)(*((unsigned long long*)aligned));
3873                 break;
3874             case FLT_FLOAT:
3875             case FLT_DOUBLE:
3876             case FLT_LDOUBLE:
3877             case OTHER:
3878             default:
3879                 HDassert(0 && "Unknown type");
3880                 break;
3881             }
3882 #endif
3883         } else if (INT_SCHAR==dst_type) {
3884             hw = (unsigned char*)&hw_schar;
3885             switch (src_type) {
3886             case FLT_FLOAT:
3887                 HDmemcpy(aligned, saved+j*sizeof(float), sizeof(float));
3888                 hw_schar = (signed char)(*((float*)aligned));
3889                 break;
3890             case FLT_DOUBLE:
3891                 HDmemcpy(aligned, saved+j*sizeof(double), sizeof(double));
3892                 hw_schar = (signed char)(*((double*)aligned));
3893                 break;
3894 #if H5_SIZEOF_LONG_DOUBLE !=0
3895             case FLT_LDOUBLE:
3896                 HDmemcpy(aligned, saved+j*sizeof(long double), sizeof(long double));
3897                 hw_schar = (signed char)(*((long double*)aligned));
3898                 break;
3899 #endif
3900             case INT_SCHAR:
3901             case INT_UCHAR:
3902             case INT_SHORT:
3903             case INT_USHORT:
3904             case INT_INT:
3905             case INT_UINT:
3906             case INT_LONG:
3907             case INT_ULONG:
3908             case INT_LLONG:
3909             case INT_ULLONG:
3910             case OTHER:
3911             default:
3912                 HDassert(0 && "Unknown type");
3913                 break;
3914             }
3915         } else if (INT_UCHAR==dst_type) {
3916             hw = (unsigned char*)&hw_uchar;
3917             switch (src_type) {
3918             case FLT_FLOAT:
3919                 HDmemcpy(aligned, saved+j*sizeof(float), sizeof(float));
3920                 hw_uchar = (unsigned char)(*((float*)aligned));
3921                 break;
3922             case FLT_DOUBLE:
3923                 HDmemcpy(aligned, saved+j*sizeof(double), sizeof(double));
3924                 hw_uchar = (unsigned char)(*((double*)aligned));
3925                 break;
3926 #if H5_SIZEOF_LONG_DOUBLE !=0
3927             case FLT_LDOUBLE:
3928                 HDmemcpy(aligned, saved+j*sizeof(long double), sizeof(long double));
3929                 hw_uchar = (unsigned char)(*((long double*)aligned));
3930                 break;
3931 #endif
3932             case INT_SCHAR:
3933             case INT_UCHAR:
3934             case INT_SHORT:
3935             case INT_USHORT:
3936             case INT_INT:
3937             case INT_UINT:
3938             case INT_LONG:
3939             case INT_ULONG:
3940             case INT_LLONG:
3941             case INT_ULLONG:
3942             case OTHER:
3943             default:
3944                 HDassert(0 && "Unknown type");
3945                 break;
3946             }
3947         } else if (INT_SHORT==dst_type) {
3948             hw = (unsigned char*)&hw_short;
3949             switch (src_type) {
3950             case FLT_FLOAT:
3951                 HDmemcpy(aligned, saved+j*sizeof(float), sizeof(float));
3952                 hw_short = (short)(*((float*)aligned));
3953                 break;
3954             case FLT_DOUBLE:
3955                 HDmemcpy(aligned, saved+j*sizeof(double), sizeof(double));
3956                 hw_short = (short)(*((double*)aligned));
3957                 break;
3958 #if H5_SIZEOF_LONG_DOUBLE !=0
3959             case FLT_LDOUBLE:
3960                 HDmemcpy(aligned, saved+j*sizeof(long double), sizeof(long double));
3961                 hw_short = (short)(*((long double*)aligned));
3962                 break;
3963 #endif
3964             case INT_SCHAR:
3965             case INT_UCHAR:
3966             case INT_SHORT:
3967             case INT_USHORT:
3968             case INT_INT:
3969             case INT_UINT:
3970             case INT_LONG:
3971             case INT_ULONG:
3972             case INT_LLONG:
3973             case INT_ULLONG:
3974             case OTHER:
3975             default:
3976                 HDassert(0 && "Unknown type");
3977                 break;
3978             }
3979         } else if (INT_USHORT==dst_type) {
3980             hw = (unsigned char*)&hw_ushort;
3981             switch (src_type) {
3982             case FLT_FLOAT:
3983                 HDmemcpy(aligned, saved+j*sizeof(float), sizeof(float));
3984                 hw_ushort = (unsigned short)(*((float*)aligned));
3985                 break;
3986             case FLT_DOUBLE:
3987                 HDmemcpy(aligned, saved+j*sizeof(double), sizeof(double));
3988                 hw_ushort = (unsigned short)(*((double*)aligned));
3989                 break;
3990 #if H5_SIZEOF_LONG_DOUBLE !=0
3991             case FLT_LDOUBLE:
3992                 HDmemcpy(aligned, saved+j*sizeof(long double), sizeof(long double));
3993                 hw_ushort = (unsigned short)(*((long double*)aligned));
3994                 break;
3995 #endif
3996             case INT_SCHAR:
3997             case INT_UCHAR:
3998             case INT_SHORT:
3999             case INT_USHORT:
4000             case INT_INT:
4001             case INT_UINT:
4002             case INT_LONG:
4003             case INT_ULONG:
4004             case INT_LLONG:
4005             case INT_ULLONG:
4006             case OTHER:
4007             default:
4008                 HDassert(0 && "Unknown type");
4009                 break;
4010             }
4011         } else if (INT_INT==dst_type) {
4012             hw = (unsigned char*)&hw_int;
4013             switch (src_type) {
4014             case FLT_FLOAT:
4015                 HDmemcpy(aligned, saved+j*sizeof(float), sizeof(float));
4016                 hw_int = (int)(*((float*)aligned));
4017                 break;
4018             case FLT_DOUBLE:
4019                 HDmemcpy(aligned, saved+j*sizeof(double), sizeof(double));
4020                 hw_int = (int)(*((double*)aligned));
4021                 break;
4022 #if H5_SIZEOF_LONG_DOUBLE !=0
4023             case FLT_LDOUBLE:
4024                 HDmemcpy(aligned, saved+j*sizeof(long double), sizeof(long double));
4025                 hw_int = (int)(*((long double*)aligned));
4026                 break;
4027 #endif
4028             case INT_SCHAR:
4029             case INT_UCHAR:
4030             case INT_SHORT:
4031             case INT_USHORT:
4032             case INT_INT:
4033             case INT_UINT:
4034             case INT_LONG:
4035             case INT_ULONG:
4036             case INT_LLONG:
4037             case INT_ULLONG:
4038             case OTHER:
4039             default:
4040                 HDassert(0 && "Unknown type");
4041                 break;
4042             }
4043         } else if (INT_UINT==dst_type) {
4044             hw = (unsigned char*)&hw_uint;
4045             switch (src_type) {
4046             case FLT_FLOAT:
4047                 HDmemcpy(aligned, saved+j*sizeof(float), sizeof(float));
4048                 hw_uint = (unsigned int)(*((float*)aligned));
4049                 break;
4050             case FLT_DOUBLE:
4051                 HDmemcpy(aligned, saved+j*sizeof(double), sizeof(double));
4052                 hw_uint = (unsigned int)(*((double*)aligned));
4053                 break;
4054 #if H5_SIZEOF_LONG_DOUBLE !=0
4055             case FLT_LDOUBLE:
4056                 HDmemcpy(aligned, saved+j*sizeof(long double), sizeof(long double));
4057                 hw_uint = (unsigned int)(*((long double*)aligned));
4058                 break;
4059 #endif
4060             case INT_SCHAR:
4061             case INT_UCHAR:
4062             case INT_SHORT:
4063             case INT_USHORT:
4064             case INT_INT:
4065             case INT_UINT:
4066             case INT_LONG:
4067             case INT_ULONG:
4068             case INT_LLONG:
4069             case INT_ULLONG:
4070             case OTHER:
4071             default:
4072                 HDassert(0 && "Unknown type");
4073                 break;
4074             }
4075         } else if (INT_LONG==dst_type) {
4076             hw = (unsigned char*)&hw_long;
4077             switch (src_type) {
4078             case FLT_FLOAT:
4079                 HDmemcpy(aligned, saved+j*sizeof(float), sizeof(float));
4080                 hw_long = (long)(*((float*)aligned));
4081                 break;
4082             case FLT_DOUBLE:
4083                 HDmemcpy(aligned, saved+j*sizeof(double), sizeof(double));
4084                 hw_long = (long)(*((double*)aligned));
4085                 break;
4086 #if H5_SIZEOF_LONG_DOUBLE !=0
4087             case FLT_LDOUBLE:
4088                 HDmemcpy(aligned, saved+j*sizeof(long double), sizeof(long double));
4089                 hw_long = (long)(*((long double*)aligned));
4090                 break;
4091 #endif
4092             case INT_SCHAR:
4093             case INT_UCHAR:
4094             case INT_SHORT:
4095             case INT_USHORT:
4096             case INT_INT:
4097             case INT_UINT:
4098             case INT_LONG:
4099             case INT_ULONG:
4100             case INT_LLONG:
4101             case INT_ULLONG:
4102             case OTHER:
4103             default:
4104                 HDassert(0 && "Unknown type");
4105                 break;
4106             }
4107         } else if (INT_ULONG==dst_type) {
4108             hw = (unsigned char*)&hw_ulong;
4109             switch (src_type) {
4110             case FLT_FLOAT:
4111                 HDmemcpy(aligned, saved+j*sizeof(float), sizeof(float));
4112                 hw_ulong = (unsigned long)(*((float*)aligned));
4113                 break;
4114             case FLT_DOUBLE:
4115                 HDmemcpy(aligned, saved+j*sizeof(double), sizeof(double));
4116                 hw_ulong = (unsigned long)(*((double*)aligned));
4117                 break;
4118 #if H5_SIZEOF_LONG_DOUBLE !=0
4119             case FLT_LDOUBLE:
4120                 HDmemcpy(aligned, saved+j*sizeof(long double), sizeof(long double));
4121                 hw_ulong = (unsigned long)(*((long double*)aligned));
4122                 break;
4123 #endif
4124             case INT_SCHAR:
4125             case INT_UCHAR:
4126             case INT_SHORT:
4127             case INT_USHORT:
4128             case INT_INT:
4129             case INT_UINT:
4130             case INT_LONG:
4131             case INT_ULONG:
4132             case INT_LLONG:
4133             case INT_ULLONG:
4134             case OTHER:
4135             default:
4136                 HDassert(0 && "Unknown type");
4137                 break;
4138             }
4139         } else if (INT_LLONG==dst_type) {
4140             hw = (unsigned char*)&hw_llong;
4141             switch (src_type) {
4142             case FLT_FLOAT:
4143                 HDmemcpy(aligned, saved+j*sizeof(float), sizeof(float));
4144                 hw_llong = (long long)(*((float*)aligned));
4145                 break;
4146             case FLT_DOUBLE:
4147                 HDmemcpy(aligned, saved+j*sizeof(double), sizeof(double));
4148                 hw_llong = (long long)(*((double*)aligned));
4149                 break;
4150 #if H5_SIZEOF_LONG_DOUBLE !=0
4151             case FLT_LDOUBLE:
4152                 HDmemcpy(aligned, saved+j*sizeof(long double), sizeof(long double));
4153                 hw_llong = (long long)(*((long double*)aligned));
4154                 break;
4155 #endif
4156             case INT_SCHAR:
4157             case INT_UCHAR:
4158             case INT_SHORT:
4159             case INT_USHORT:
4160             case INT_INT:
4161             case INT_UINT:
4162             case INT_LONG:
4163             case INT_ULONG:
4164             case INT_LLONG:
4165             case INT_ULLONG:
4166             case OTHER:
4167             default:
4168                 HDassert(0 && "Unknown type");
4169                 break;
4170             }
4171         } else if (INT_ULLONG==dst_type) {
4172             hw = (unsigned char*)&hw_ullong;
4173             switch (src_type) {
4174             case FLT_FLOAT:
4175                 HDmemcpy(aligned, saved+j*sizeof(float), sizeof(float));
4176                 hw_ullong = (unsigned long long)(*((float*)aligned));
4177                 break;
4178             case FLT_DOUBLE:
4179                 HDmemcpy(aligned, saved+j*sizeof(double), sizeof(double));
4180                 hw_ullong = (unsigned long long)(*((double*)aligned));
4181                 break;
4182 #if H5_SIZEOF_LONG_DOUBLE !=0
4183             case FLT_LDOUBLE:
4184                 HDmemcpy(aligned, saved+j*sizeof(long double), sizeof(long double));
4185                 hw_ullong = (unsigned long long)(*((long double*)aligned));
4186                 break;
4187 #endif
4188             case INT_SCHAR:
4189             case INT_UCHAR:
4190             case INT_SHORT:
4191             case INT_USHORT:
4192             case INT_INT:
4193             case INT_UINT:
4194             case INT_LONG:
4195             case INT_ULONG:
4196             case INT_LLONG:
4197             case INT_ULLONG:
4198             case OTHER:
4199             default:
4200                 HDassert(0 && "Unknown type");
4201                 break;
4202             }
4203         }
4204 
4205         /* Make certain that there isn't some weird number of destination bits */
4206         assert(dst_nbits%8==0);
4207 
4208         /* For Intel machines, the size of "long double" is 12 bytes, precision
4209          * is 80 bits; for AMD processors, the size of "long double" is 16 bytes,
4210          * precision is 80 bits.  During hardware conversion, the last few unused
4211          * bytes may have garbage in them.  Clean them out with 0s before compare
4212          * the values.
4213          */
4214 #if H5_SIZEOF_LONG_DOUBLE !=0
4215         if(dendian==H5T_ORDER_LE && dst_type==FLT_LDOUBLE) {
4216             size_t q;
4217 
4218             for(q = dst_nbits / 8; q < dst_size; q++)
4219                 buf[j * dst_size + q] = 0x00;
4220         }
4221 #endif
4222 
4223         /* Are the two results the same? */
4224         for (k=(dst_size-(dst_nbits/8)); k<dst_size; k++)
4225             if (buf[j*dst_size+k]!=hw[k])
4226                 break;
4227         if (k==dst_size)
4228             continue; /*no error*/
4229 
4230         /*
4231          * Convert the source and destination values to little endian
4232          * order so we can use the HDF5 bit vector operations to test
4233          * certain things.  These routines have already been tested by
4234          * the `bittests' program.
4235          */
4236 
4237         if ((FLT_FLOAT==src_type || FLT_DOUBLE==src_type) && sendian==H5T_ORDER_VAX) {
4238             for (k = 0; k < src_size; k += 2) {
4239                 src_bits[k] = saved[j*src_size + (src_size - 2) - k];
4240                 src_bits[k + 1] = saved[j*src_size + (src_size - 1) - k];
4241             }
4242         } else {
4243             for (k=0; k<src_size; k++)
4244                 src_bits[src_size-(k+1)] = saved[j*src_size+ENDIAN(src_size, k, sendian)];
4245         }
4246 
4247         for (k=0; k<dst_size; k++)
4248             dst_bits[dst_size-(k+1)] = buf[j*dst_size+ENDIAN(dst_size, k, dendian)];
4249 
4250         /*          Test library's default overflow handling:
4251          * Hardware usually doesn't handle overflows too gracefully. The
4252          * hardware conversion result during overflows is usually garbage
4253          * so we must handle those cases differetly when checking results.
4254          *
4255          *          Test user's exception handler when overflows:
4256          * Try to follow the except_func callback function to check if the
4257          * desired value was set.
4258          */
4259         if ((FLT_FLOAT==src_type || FLT_DOUBLE==src_type
4260 #if H5_SIZEOF_LONG_DOUBLE !=0
4261                     || FLT_LDOUBLE==src_type
4262 #endif
4263                     )
4264                 && (INT_SCHAR==dst_type || INT_SHORT==dst_type || INT_INT==dst_type
4265                 || INT_LONG==dst_type || INT_LLONG==dst_type)) {
4266             if(0==H5T__bit_get_d(src_bits, src_nbits-1, (size_t)1) &&
4267                     overflows(src_bits, src, dst_nbits-1)) {
4268                 /*
4269                  * Source is positive and the magnitude is too large for
4270                  * the destination.  The destination should be set to the
4271                  * maximum possible value: 0x7f...f
4272                  */
4273                 if(!except_set) {
4274                     if (0==H5T__bit_get_d(dst_bits, dst_nbits-1, (size_t)1) &&
4275                             H5T__bit_find(dst_bits, (size_t)0, dst_nbits-1, H5T_BIT_LSB, 0) < 0)
4276                         continue; /*no error*/
4277                 } else {
4278                     /* fill_value is small so we know only the 1st byte is set */
4279                     if (dst_bits[0] == fill_value)
4280                         continue; /*no error*/
4281                 }
4282             } else if (1==H5T__bit_get_d(src_bits, src_nbits-1, (size_t)1) &&
4283                     overflows(src_bits, src, dst_nbits-1)) {
4284                 /*
4285                  * Source is negative but the magnitude is too large for
4286                  * the destination. The destination should be set to the
4287                  * smallest possible value: 0x80...0
4288                  */
4289                 if(!except_set) {
4290                     if (1==H5T__bit_get_d(dst_bits, dst_nbits-1, (size_t)1) &&
4291                             H5T__bit_find(dst_bits, (size_t)0, dst_nbits-1, H5T_BIT_LSB, 1) < 0)
4292                         continue; /*no error*/
4293                 } else {
4294                     if (dst_bits[0] == fill_value)
4295                         continue; /*no error*/
4296                 }
4297             }
4298         }
4299 
4300         if ((FLT_FLOAT==src_type || FLT_DOUBLE==src_type
4301 #if H5_SIZEOF_LONG_DOUBLE !=0
4302                     || FLT_LDOUBLE==src_type
4303 #endif
4304                 )
4305                 && (INT_UCHAR==dst_type || INT_USHORT==dst_type || INT_UINT==dst_type
4306                 || INT_ULONG==dst_type || INT_ULLONG==dst_type)) {
4307             if (H5T__bit_get_d(src_bits, src_nbits-1, (size_t)1)) {
4308                 /*
4309                  * The source is negative so the result should be zero.
4310                  * The source is negative if the most significant bit is
4311                  * set.  The destination is zero if all bits are zero.
4312                  */
4313                 if(!except_set) {
4314                     if (H5T__bit_find(dst_bits, (size_t)0, dst_nbits, H5T_BIT_LSB, 1) < 0)
4315                         continue; /*no error*/
4316                 } else {
4317                     if (dst_bits[0] == fill_value)
4318                         continue; /*no error*/
4319                 }
4320             } else if (overflows(src_bits, src, dst_nbits)) {
4321                 /*
4322                  * The source is a value with a magnitude too large for
4323                  * the destination.  The destination should be the
4324                  * largest possible value: 0xff...f
4325                  */
4326                 if(!except_set) {
4327                     if (H5T__bit_find(dst_bits, (size_t)0, dst_nbits, H5T_BIT_LSB, 0) < 0)
4328                         continue; /*no error*/
4329                 } else {
4330                     if (dst_bits[0] == fill_value)
4331                         continue; /*no error*/
4332                 }
4333             }
4334         }
4335 
4336         /* Print errors */
4337         if (0==fails_this_test++) {
4338             if(run_test==TEST_NORMAL) {
4339                 H5_FAILED();
4340             } else if(run_test==TEST_DENORM || run_test==TEST_SPECIAL) {
4341                 H5_WARNING();
4342             }
4343         }
4344         HDprintf("    elmt %u: \n", (unsigned)j);
4345 
4346         HDprintf("        src = ");
4347         for (k=0; k<src_size; k++)
4348             HDprintf(" %02x", saved[j*src_size+ENDIAN(src_size, k, sendian)]);
4349         HDprintf("%*s", (int)(3*MAX(0, (ssize_t)dst_size-(ssize_t)src_size)), "");
4350         switch (src_type) {
4351             case INT_SCHAR:
4352                 HDmemcpy(aligned, saved+j*sizeof(signed char), sizeof(signed char));
4353                 HDprintf(" %29d\n", (int)*((signed char*)aligned));
4354                 break;
4355             case INT_UCHAR:
4356                 HDmemcpy(aligned, saved+j*sizeof(unsigned char), sizeof(unsigned char));
4357                 HDprintf(" %29u\n", (unsigned)*((unsigned char*)aligned));
4358                 break;
4359             case INT_SHORT:
4360                 HDmemcpy(aligned, saved+j*sizeof(short), sizeof(short));
4361                 HDprintf(" %29hd\n", *((short*)aligned));
4362                 break;
4363             case INT_USHORT:
4364                 HDmemcpy(aligned, saved+j*sizeof(unsigned short), sizeof(unsigned short));
4365                 HDprintf(" %29hu\n", *((unsigned short*)aligned));
4366                 break;
4367             case INT_INT:
4368                 HDmemcpy(aligned, saved+j*sizeof(int), sizeof(int));
4369                 HDprintf(" %29d\n", *((int*)aligned));
4370                 break;
4371             case INT_UINT:
4372                 HDmemcpy(aligned, saved+j*sizeof(unsigned), sizeof(unsigned));
4373                 HDprintf(" %29u\n", *((unsigned*)aligned));
4374                 break;
4375             case INT_LONG:
4376                 HDmemcpy(aligned, saved+j*sizeof(long), sizeof(long));
4377                 HDprintf(" %29ld\n", *((long*)aligned));
4378                 break;
4379             case INT_ULONG:
4380                 HDmemcpy(aligned, saved+j*sizeof(unsigned long), sizeof(unsigned long));
4381                 HDprintf(" %29lu\n", *((unsigned long*)aligned));
4382                 break;
4383             case INT_LLONG:
4384                 HDmemcpy(aligned, saved+j*sizeof(long long), sizeof(long long));
4385                 HDfprintf(stdout," %29"H5_PRINTF_LL_WIDTH"d\n", *((long long*)aligned));
4386                 break;
4387             case INT_ULLONG:
4388                 HDmemcpy(aligned, saved+j*sizeof(unsigned long long), sizeof(unsigned long long));
4389                 HDfprintf(stdout," %29"H5_PRINTF_LL_WIDTH"u\n", *((unsigned long long*)aligned));
4390                 break;
4391             case FLT_FLOAT:
4392                 HDmemcpy(aligned, saved+j*sizeof(float), sizeof(float));
4393                 HDprintf(" %29f\n", (double)*((float*)aligned));
4394                 break;
4395             case FLT_DOUBLE:
4396                 HDmemcpy(aligned, saved+j*sizeof(double), sizeof(double));
4397                 HDprintf(" %29f\n", *((double*)aligned));
4398                 break;
4399 #if H5_SIZEOF_LONG_DOUBLE !=0
4400             case FLT_LDOUBLE:
4401                 HDmemcpy(aligned, saved+j*sizeof(long double), sizeof(long double));
4402                 HDprintf(" %29Lf\n", *((long double*)aligned));
4403                 break;
4404 #endif
4405             case OTHER:
4406             default:
4407                 HDassert(0 && "Unknown type");
4408                 break;
4409         }
4410 
4411         HDprintf("        dst = ");
4412         for (k=0; k<dst_size; k++)
4413             HDprintf(" %02x", buf[j*dst_size+ENDIAN(dst_size, k, dendian)]);
4414         HDprintf("%*s", (int)(3*MAX(0, (ssize_t)src_size-(ssize_t)dst_size)), "");
4415         switch (dst_type) {
4416             case INT_SCHAR:
4417                 HDmemcpy(aligned, buf+j*sizeof(signed char), sizeof(signed char));
4418                 HDprintf(" %29d\n", (int)*((signed char*)aligned));
4419                 break;
4420             case INT_UCHAR:
4421                 HDmemcpy(aligned, buf+j*sizeof(unsigned char), sizeof(unsigned char));
4422                 HDprintf(" %29u\n", (unsigned)*((unsigned char*)aligned));
4423                 break;
4424             case INT_SHORT:
4425                 HDmemcpy(aligned, buf+j*sizeof(short), sizeof(short));
4426                 HDprintf(" %29hd\n", *((short*)aligned));
4427                 break;
4428             case INT_USHORT:
4429                 HDmemcpy(aligned, buf+j*sizeof(unsigned short), sizeof(unsigned short));
4430                 HDprintf(" %29hu\n", *((unsigned short*)aligned));
4431                 break;
4432             case INT_INT:
4433                 HDmemcpy(aligned, buf+j*sizeof(int), sizeof(int));
4434                 HDprintf(" %29d\n", *((int*)aligned));
4435                 break;
4436             case INT_UINT:
4437                 HDmemcpy(aligned, buf+j*sizeof(unsigned), sizeof(unsigned));
4438                 HDprintf(" %29u\n", *((unsigned*)aligned));
4439                 break;
4440             case INT_LONG:
4441                 HDmemcpy(aligned, buf+j*sizeof(long), sizeof(long));
4442                 HDprintf(" %29ld\n", *((long*)aligned));
4443                 break;
4444             case INT_ULONG:
4445                 HDmemcpy(aligned, buf+j*sizeof(unsigned long), sizeof(unsigned long));
4446                 HDprintf(" %29lu\n", *((unsigned long*)aligned));
4447                 break;
4448             case INT_LLONG:
4449                 HDmemcpy(aligned, buf+j*sizeof(long long), sizeof(long long));
4450                 HDfprintf(stdout," %29"H5_PRINTF_LL_WIDTH"d\n", *((long long*)aligned));
4451                 break;
4452             case INT_ULLONG:
4453                 HDmemcpy(aligned, buf+j*sizeof(unsigned long long), sizeof(unsigned long long));
4454                 HDfprintf(stdout," %29"H5_PRINTF_LL_WIDTH"u\n", *((unsigned long long*)aligned));
4455                 break;
4456             case FLT_FLOAT:
4457                 HDmemcpy(aligned, buf+j*sizeof(float), sizeof(float));
4458                 HDprintf(" %29f\n", (double)*((float*)aligned));
4459                 break;
4460             case FLT_DOUBLE:
4461                 HDmemcpy(aligned, buf+j*sizeof(double), sizeof(double));
4462                 HDprintf(" %29f\n", *((double*)aligned));
4463                 break;
4464 #if H5_SIZEOF_LONG_DOUBLE !=0
4465             case FLT_LDOUBLE:
4466                 HDmemcpy(aligned, buf+j*sizeof(long double), sizeof(long double));
4467                 HDprintf(" %29Lf\n", *((long double*)aligned));
4468                 break;
4469 #endif
4470             case OTHER:
4471             default:
4472                 HDassert(0 && "Unknown type");
4473                 break;
4474         }
4475 
4476         HDprintf("        ans = ");
4477         for (k=0; k<dst_size; k++)
4478             HDprintf(" %02x", hw[ENDIAN(dst_size, k, dendian)]);
4479         HDprintf("%*s", (int)(3*MAX(0, (ssize_t)src_size-(ssize_t)dst_size)), "");
4480         switch (dst_type) {
4481             case INT_SCHAR:
4482                 HDprintf(" %29d\n", (int)*((signed char*)((void *)hw)));
4483                 break;
4484             case INT_UCHAR:
4485                 HDprintf(" %29u\n", (unsigned)*((unsigned char*)((void *)hw)));
4486                 break;
4487             case INT_SHORT:
4488                 HDprintf(" %29hd\n", *((short*)((void *)hw)));
4489                 break;
4490             case INT_USHORT:
4491                 HDprintf(" %29hu\n", *((unsigned short*)((void *)hw)));
4492                 break;
4493             case INT_INT:
4494                 HDprintf(" %29d\n", *((int*)((void *)hw)));
4495                 break;
4496             case INT_UINT:
4497                 HDprintf(" %29u\n", *((unsigned int*)((void *)hw)));
4498                 break;
4499             case INT_LONG:
4500                 HDprintf(" %29ld\n", *((long*)((void *)hw)));
4501                 break;
4502             case INT_ULONG:
4503                 HDprintf(" %29lu\n", *((unsigned long*)((void *)hw)));
4504                 break;
4505             case INT_LLONG:
4506                 HDfprintf(stdout, " %29"H5_PRINTF_LL_WIDTH"d\n", *((long long*)((void *)hw)));
4507                 break;
4508             case INT_ULLONG:
4509                 HDfprintf(stdout, " %29"H5_PRINTF_LL_WIDTH"u\n", *((unsigned long long*)((void *)hw)));
4510                 break;
4511             case FLT_FLOAT:
4512                 HDprintf(" %29f\n", (double)*((float*)((void *)hw)));
4513                 break;
4514             case FLT_DOUBLE:
4515                 HDprintf(" %29f\n", *((double*)((void *)hw)));
4516                 break;
4517 #if H5_SIZEOF_LONG_DOUBLE !=0
4518             case FLT_LDOUBLE:
4519                 HDprintf(" %29Lf\n", *((long double*)((void *)hw)));
4520                 break;
4521 #endif
4522             case OTHER:
4523             default:
4524                 HDassert(0 && "Unknown type");
4525                 break;
4526         }
4527 
4528         /* If the source is normalized values, print out error message; if it is
4529          * denormalized or special values, print out warning message.*/
4530         if (++fails_all_tests>=max_fails) {
4531             if(run_test==TEST_NORMAL)
4532                 HDputs("    maximum failures reached, aborting test...");
4533             else if(run_test==TEST_DENORM || run_test==TEST_SPECIAL)
4534                 HDputs("    maximum warnings reached, aborting test...");
4535             HDputs("    (dst is library's conversion output. ans is compiler's conversion output.)");
4536 
4537             goto done;
4538         }
4539     }
4540 
4541     if(!fails_all_tests)
4542         PASSED();
4543 
4544  done:
4545     if (buf) aligned_free(buf);
4546     if (saved) aligned_free(saved);
4547     if (aligned) HDfree(aligned);
4548     HDfflush(stdout);
4549     /* Restore the default error handler (set in h5_reset()) */
4550     h5_restore_err();
4551 
4552     reset_hdf5();    /*print statistics*/
4553 
4554     /* If the source is normalized floating values, treat the failures as error;
4555      * if it is denormalized or special floating values, treat the failure as warning.*/
4556     if(run_test==TEST_NORMAL)
4557         return (int)fails_all_tests;
4558     else if(run_test==TEST_DENORM || run_test==TEST_SPECIAL)
4559         return 0;
4560 
4561  error:
4562     if (buf) aligned_free(buf);
4563     if (saved) aligned_free(saved);
4564     if (aligned) HDfree(aligned);
4565     HDfflush(stdout);
4566 
4567     /* Restore the default error handler (set in h5_reset()) */
4568     h5_restore_err();
4569 
4570     reset_hdf5();    /*print statistics*/
4571 
4572     if(run_test==TEST_NORMAL)
4573         return MAX((int)fails_all_tests, 1);
4574     else {
4575         HDassert(run_test==TEST_DENORM || run_test==TEST_SPECIAL);
4576         return 1;
4577     }
4578 }
4579 
4580 
4581 /*-------------------------------------------------------------------------
4582  * Function:    overflows
4583  *
4584  * Purpose:    When convert from float or double to any integer type,
4585  *              check if overflow occurs.
4586  *
4587  *
4588  * Return:    TRUE:           overflow happens
4589  *
4590  *              FALSE:          no overflow
4591  *
4592  * Programmer:    Raymond Lu
4593  *              Monday, Nov 17, 2003
4594  *
4595  * Modifications:
4596  *
4597  *-------------------------------------------------------------------------
4598  */
4599 static hbool_t
overflows(unsigned char * origin_bits,hid_t src_id,size_t dst_num_bits)4600 overflows(unsigned char *origin_bits, hid_t src_id, size_t dst_num_bits)
4601 {
4602     hbool_t     ret_value=FALSE;
4603     hsize_t     expt;
4604     size_t      mant_digits=0, expt_digits=0, bias=0;
4605     size_t      epos, mpos;
4606     size_t      src_prec=0;             /*source type precision in bits*/
4607     H5T_norm_t  norm;
4608     ssize_t     indx;
4609     unsigned char        bits[32], mant_bits[32];
4610 
4611     HDmemset(bits, 0, (size_t)32);
4612     HDmemset(mant_bits, 0, (size_t)32);
4613 
4614     /*
4615      * Sometimes, type size isn't equal to the precision like Linux's "long
4616      * double", where size is 96 bits and precision is 80 bits.
4617      */
4618 
4619     src_prec = H5Tget_precision(src_id);
4620     H5Tget_fields(src_id, NULL, &epos, &expt_digits, &mpos, &mant_digits);
4621     bias = H5Tget_ebias(src_id);
4622     norm = H5Tget_norm(src_id);
4623 
4624     HDmemcpy(bits, origin_bits, src_prec/8+1);
4625 
4626     /*Check for special cases: +Inf, -Inf*/
4627     if (H5T__bit_find (bits, mpos, mant_digits, H5T_BIT_LSB, TRUE) < 0) {
4628         if (H5T__bit_find (bits, epos, expt_digits, H5T_BIT_LSB, FALSE) < 0) {
4629             ret_value=TRUE;
4630             goto done;
4631         }
4632     } else if (H5T_NORM_NONE==norm && H5T__bit_find (bits, mpos, mant_digits-1,
4633         H5T_BIT_LSB, TRUE) < 0 && H5T__bit_find (bits, epos, expt_digits,
4634         H5T_BIT_LSB, FALSE) < 0) {
4635         /*This is a special case for the source of no implied mantissa bit.
4636          *If the exponent bits are all 1s and only the 1st bit of mantissa
4637          *is set to 1.  It's infinity. The Intel-Linux "long double" is this case.*/
4638             ret_value=TRUE;
4639             goto done;
4640     }
4641 
4642     /* get exponent */
4643     expt = H5T__bit_get_d(bits, mant_digits, expt_digits) - bias;
4644 
4645     if(expt>=(dst_num_bits-1)) {
4646        ret_value=TRUE;
4647        goto done;
4648     }
4649 
4650     /* get significand */
4651     H5T__bit_copy (mant_bits, (size_t)0, bits, (size_t)0, mant_digits);
4652 
4653 
4654     /* restore implicit bit if normalization is implied*/
4655     if(norm == H5T_NORM_IMPLIED) {
4656         H5T__bit_inc(mant_bits, mant_digits, (size_t)1);
4657         mant_digits++;
4658     }
4659 
4660     /* shift significand */
4661     H5T__bit_shift (mant_bits, (ssize_t)(expt-expt_digits), (size_t)0, (size_t)(32 * 8));
4662 
4663     indx = H5T__bit_find(mant_bits, (size_t)0, (size_t)(32 * 8), H5T_BIT_MSB, 1);
4664 
4665     if((size_t)indx>=dst_num_bits)
4666         ret_value=TRUE;
4667 
4668 done:
4669     return ret_value;
4670 }
4671 
4672 
4673 /*-------------------------------------------------------------------------
4674  * Function:    run_integer_tests
4675  *
4676  * Purpose:    Runs all integer tests.
4677  *
4678  * Return:    Number of errors
4679  *
4680  * Programmer:    Robb Matzke
4681  *              Tuesday, November 24, 1998
4682  *
4683  * Modifications:
4684  *
4685  *-------------------------------------------------------------------------
4686  */
4687 static int
run_integer_tests(const char * name)4688 run_integer_tests(const char *name)
4689 {
4690     int        nerrors = 0;
4691 
4692     nerrors += test_conv_int_1(name, H5T_NATIVE_SCHAR, H5T_NATIVE_UCHAR);
4693     nerrors += test_conv_int_1(name, H5T_NATIVE_SCHAR, H5T_NATIVE_SHORT);
4694     nerrors += test_conv_int_1(name, H5T_NATIVE_SCHAR, H5T_NATIVE_USHORT);
4695     nerrors += test_conv_int_1(name, H5T_NATIVE_SCHAR, H5T_NATIVE_INT);
4696     nerrors += test_conv_int_1(name, H5T_NATIVE_SCHAR, H5T_NATIVE_UINT);
4697 #if H5_SIZEOF_LONG!=H5_SIZEOF_INT
4698     nerrors += test_conv_int_1(name, H5T_NATIVE_SCHAR, H5T_NATIVE_LONG);
4699     nerrors += test_conv_int_1(name, H5T_NATIVE_SCHAR, H5T_NATIVE_ULONG);
4700 #endif
4701 #if H5_SIZEOF_LONG_LONG!=H5_SIZEOF_LONG
4702     nerrors += test_conv_int_1(name, H5T_NATIVE_SCHAR, H5T_NATIVE_LLONG);
4703     nerrors += test_conv_int_1(name, H5T_NATIVE_SCHAR, H5T_NATIVE_ULLONG);
4704 #endif
4705 
4706     nerrors += test_conv_int_1(name, H5T_NATIVE_UCHAR, H5T_NATIVE_SCHAR);
4707     nerrors += test_conv_int_1(name, H5T_NATIVE_UCHAR, H5T_NATIVE_SHORT);
4708     nerrors += test_conv_int_1(name, H5T_NATIVE_UCHAR, H5T_NATIVE_USHORT);
4709     nerrors += test_conv_int_1(name, H5T_NATIVE_UCHAR, H5T_NATIVE_INT);
4710     nerrors += test_conv_int_1(name, H5T_NATIVE_UCHAR, H5T_NATIVE_UINT);
4711 #if H5_SIZEOF_LONG!=H5_SIZEOF_INT
4712     nerrors += test_conv_int_1(name, H5T_NATIVE_UCHAR, H5T_NATIVE_LONG);
4713     nerrors += test_conv_int_1(name, H5T_NATIVE_UCHAR, H5T_NATIVE_ULONG);
4714 #endif
4715 #if H5_SIZEOF_LONG_LONG!=H5_SIZEOF_LONG
4716     nerrors += test_conv_int_1(name, H5T_NATIVE_UCHAR, H5T_NATIVE_LLONG);
4717     nerrors += test_conv_int_1(name, H5T_NATIVE_UCHAR, H5T_NATIVE_ULLONG);
4718 #endif
4719 
4720     nerrors += test_conv_int_1(name, H5T_NATIVE_SHORT, H5T_NATIVE_SCHAR);
4721     nerrors += test_conv_int_1(name, H5T_NATIVE_SHORT, H5T_NATIVE_UCHAR);
4722     nerrors += test_conv_int_1(name, H5T_NATIVE_SHORT, H5T_NATIVE_USHORT);
4723     nerrors += test_conv_int_1(name, H5T_NATIVE_SHORT, H5T_NATIVE_INT);
4724     nerrors += test_conv_int_1(name, H5T_NATIVE_SHORT, H5T_NATIVE_UINT);
4725 #if H5_SIZEOF_LONG!=H5_SIZEOF_INT
4726     nerrors += test_conv_int_1(name, H5T_NATIVE_SHORT, H5T_NATIVE_LONG);
4727     nerrors += test_conv_int_1(name, H5T_NATIVE_SHORT, H5T_NATIVE_ULONG);
4728 #endif
4729 #if H5_SIZEOF_LONG_LONG!=H5_SIZEOF_LONG
4730     nerrors += test_conv_int_1(name, H5T_NATIVE_SHORT, H5T_NATIVE_LLONG);
4731     nerrors += test_conv_int_1(name, H5T_NATIVE_SHORT, H5T_NATIVE_ULLONG);
4732 #endif
4733 
4734     nerrors += test_conv_int_1(name, H5T_NATIVE_USHORT, H5T_NATIVE_SCHAR);
4735     nerrors += test_conv_int_1(name, H5T_NATIVE_USHORT, H5T_NATIVE_UCHAR);
4736     nerrors += test_conv_int_1(name, H5T_NATIVE_USHORT, H5T_NATIVE_SHORT);
4737     nerrors += test_conv_int_1(name, H5T_NATIVE_USHORT, H5T_NATIVE_INT);
4738     nerrors += test_conv_int_1(name, H5T_NATIVE_USHORT, H5T_NATIVE_UINT);
4739 #if H5_SIZEOF_LONG!=H5_SIZEOF_INT
4740     nerrors += test_conv_int_1(name, H5T_NATIVE_USHORT, H5T_NATIVE_LONG);
4741     nerrors += test_conv_int_1(name, H5T_NATIVE_USHORT, H5T_NATIVE_ULONG);
4742 #endif
4743 #if H5_SIZEOF_LONG_LONG!=H5_SIZEOF_LONG
4744     nerrors += test_conv_int_1(name, H5T_NATIVE_USHORT, H5T_NATIVE_LLONG);
4745     nerrors += test_conv_int_1(name, H5T_NATIVE_USHORT, H5T_NATIVE_ULLONG);
4746 #endif
4747 
4748     nerrors += test_conv_int_1(name, H5T_NATIVE_INT, H5T_NATIVE_SCHAR);
4749     nerrors += test_conv_int_1(name, H5T_NATIVE_INT, H5T_NATIVE_UCHAR);
4750     nerrors += test_conv_int_1(name, H5T_NATIVE_INT, H5T_NATIVE_SHORT);
4751     nerrors += test_conv_int_1(name, H5T_NATIVE_INT, H5T_NATIVE_USHORT);
4752     nerrors += test_conv_int_1(name, H5T_NATIVE_INT, H5T_NATIVE_UINT);
4753 #if H5_SIZEOF_LONG!=H5_SIZEOF_INT
4754     nerrors += test_conv_int_1(name, H5T_NATIVE_INT, H5T_NATIVE_LONG);
4755     nerrors += test_conv_int_1(name, H5T_NATIVE_INT, H5T_NATIVE_ULONG);
4756 #endif
4757 #if H5_SIZEOF_LONG_LONG!=H5_SIZEOF_LONG
4758     nerrors += test_conv_int_1(name, H5T_NATIVE_INT, H5T_NATIVE_LLONG);
4759     nerrors += test_conv_int_1(name, H5T_NATIVE_INT, H5T_NATIVE_ULLONG);
4760 #endif
4761 
4762     nerrors += test_conv_int_1(name, H5T_NATIVE_UINT, H5T_NATIVE_SCHAR);
4763     nerrors += test_conv_int_1(name, H5T_NATIVE_UINT, H5T_NATIVE_UCHAR);
4764     nerrors += test_conv_int_1(name, H5T_NATIVE_UINT, H5T_NATIVE_SHORT);
4765     nerrors += test_conv_int_1(name, H5T_NATIVE_UINT, H5T_NATIVE_USHORT);
4766     nerrors += test_conv_int_1(name, H5T_NATIVE_UINT, H5T_NATIVE_INT);
4767 #if H5_SIZEOF_LONG!=H5_SIZEOF_INT
4768     nerrors += test_conv_int_1(name, H5T_NATIVE_UINT, H5T_NATIVE_LONG);
4769     nerrors += test_conv_int_1(name, H5T_NATIVE_UINT, H5T_NATIVE_ULONG);
4770 #endif
4771 #if H5_SIZEOF_LONG_LONG!=H5_SIZEOF_LONG
4772     nerrors += test_conv_int_1(name, H5T_NATIVE_UINT, H5T_NATIVE_LLONG);
4773     nerrors += test_conv_int_1(name, H5T_NATIVE_UINT, H5T_NATIVE_ULLONG);
4774 #endif
4775 
4776 #if H5_SIZEOF_LONG!=H5_SIZEOF_INT
4777     nerrors += test_conv_int_1(name, H5T_NATIVE_LONG, H5T_NATIVE_SCHAR);
4778     nerrors += test_conv_int_1(name, H5T_NATIVE_LONG, H5T_NATIVE_UCHAR);
4779     nerrors += test_conv_int_1(name, H5T_NATIVE_LONG, H5T_NATIVE_SHORT);
4780     nerrors += test_conv_int_1(name, H5T_NATIVE_LONG, H5T_NATIVE_USHORT);
4781     nerrors += test_conv_int_1(name, H5T_NATIVE_LONG, H5T_NATIVE_INT);
4782     nerrors += test_conv_int_1(name, H5T_NATIVE_LONG, H5T_NATIVE_UINT);
4783     nerrors += test_conv_int_1(name, H5T_NATIVE_LONG, H5T_NATIVE_ULONG);
4784 #if H5_SIZEOF_LONG_LONG!=H5_SIZEOF_LONG
4785     nerrors += test_conv_int_1(name, H5T_NATIVE_LONG, H5T_NATIVE_LLONG);
4786     nerrors += test_conv_int_1(name, H5T_NATIVE_LONG, H5T_NATIVE_ULLONG);
4787 #endif
4788 #endif
4789 
4790 #if H5_SIZEOF_LONG!=H5_SIZEOF_INT
4791     nerrors += test_conv_int_1(name, H5T_NATIVE_ULONG, H5T_NATIVE_SCHAR);
4792     nerrors += test_conv_int_1(name, H5T_NATIVE_ULONG, H5T_NATIVE_UCHAR);
4793     nerrors += test_conv_int_1(name, H5T_NATIVE_ULONG, H5T_NATIVE_SHORT);
4794     nerrors += test_conv_int_1(name, H5T_NATIVE_ULONG, H5T_NATIVE_USHORT);
4795     nerrors += test_conv_int_1(name, H5T_NATIVE_ULONG, H5T_NATIVE_INT);
4796     nerrors += test_conv_int_1(name, H5T_NATIVE_ULONG, H5T_NATIVE_UINT);
4797     nerrors += test_conv_int_1(name, H5T_NATIVE_ULONG, H5T_NATIVE_LONG);
4798 #if H5_SIZEOF_LONG_LONG!=H5_SIZEOF_LONG
4799     nerrors += test_conv_int_1(name, H5T_NATIVE_ULONG, H5T_NATIVE_LLONG);
4800     nerrors += test_conv_int_1(name, H5T_NATIVE_ULONG, H5T_NATIVE_ULLONG);
4801 #endif
4802 #endif
4803 
4804 #if H5_SIZEOF_LONG_LONG!=H5_SIZEOF_LONG
4805     nerrors += test_conv_int_1(name, H5T_NATIVE_LLONG, H5T_NATIVE_SCHAR);
4806     nerrors += test_conv_int_1(name, H5T_NATIVE_LLONG, H5T_NATIVE_UCHAR);
4807     nerrors += test_conv_int_1(name, H5T_NATIVE_LLONG, H5T_NATIVE_SHORT);
4808     nerrors += test_conv_int_1(name, H5T_NATIVE_LLONG, H5T_NATIVE_USHORT);
4809     nerrors += test_conv_int_1(name, H5T_NATIVE_LLONG, H5T_NATIVE_INT);
4810     nerrors += test_conv_int_1(name, H5T_NATIVE_LLONG, H5T_NATIVE_UINT);
4811 #if H5_SIZEOF_LONG!=H5_SIZEOF_INT
4812     nerrors += test_conv_int_1(name, H5T_NATIVE_LLONG, H5T_NATIVE_LONG);
4813     nerrors += test_conv_int_1(name, H5T_NATIVE_LLONG, H5T_NATIVE_ULONG);
4814 #endif
4815     nerrors += test_conv_int_1(name, H5T_NATIVE_LLONG, H5T_NATIVE_ULLONG);
4816 #endif
4817 
4818 #if H5_SIZEOF_LONG_LONG!=H5_SIZEOF_LONG
4819     nerrors += test_conv_int_1(name, H5T_NATIVE_ULLONG, H5T_NATIVE_SCHAR);
4820     nerrors += test_conv_int_1(name, H5T_NATIVE_ULLONG, H5T_NATIVE_UCHAR);
4821     nerrors += test_conv_int_1(name, H5T_NATIVE_ULLONG, H5T_NATIVE_SHORT);
4822     nerrors += test_conv_int_1(name, H5T_NATIVE_ULLONG, H5T_NATIVE_USHORT);
4823     nerrors += test_conv_int_1(name, H5T_NATIVE_ULLONG, H5T_NATIVE_INT);
4824     nerrors += test_conv_int_1(name, H5T_NATIVE_ULLONG, H5T_NATIVE_UINT);
4825 #if H5_SIZEOF_LONG!=H5_SIZEOF_INT
4826     nerrors += test_conv_int_1(name, H5T_NATIVE_ULLONG, H5T_NATIVE_LONG);
4827     nerrors += test_conv_int_1(name, H5T_NATIVE_ULLONG, H5T_NATIVE_ULONG);
4828 #endif
4829     nerrors += test_conv_int_1(name, H5T_NATIVE_ULLONG, H5T_NATIVE_LLONG);
4830 #endif
4831 
4832     return nerrors;
4833 }
4834 
4835 
4836 /*-------------------------------------------------------------------------
4837  * Function:    run_fp_tests
4838  *
4839  * Purpose:    Runs all floating-point tests.
4840  *
4841  * Return:    Number of errors
4842  *
4843  * Programmer:    Raymond Lu
4844  *              Tuesday, March 22, 2005
4845  *
4846  * Modifications:
4847  *
4848  *-------------------------------------------------------------------------
4849  */
4850 static int
run_fp_tests(const char * name)4851 run_fp_tests(const char *name)
4852 {
4853     int        nerrors = 0;
4854 
4855     if(!strcmp(name, "noop")) {
4856         nerrors += test_conv_flt_1("noop", TEST_NOOP, H5T_NATIVE_FLOAT, H5T_NATIVE_FLOAT);
4857         nerrors += test_conv_flt_1("noop", TEST_NOOP, H5T_NATIVE_DOUBLE, H5T_NATIVE_DOUBLE);
4858 #if H5_SIZEOF_LONG_DOUBLE !=0
4859         nerrors += test_conv_flt_1("noop", TEST_NOOP, H5T_NATIVE_LDOUBLE, H5T_NATIVE_LDOUBLE);
4860 #endif
4861         goto done;
4862     }
4863 
4864     /*Test normalized values.  TEST_NORMAL indicates normalized values.*/
4865     nerrors += test_conv_flt_1(name, TEST_NORMAL, H5T_NATIVE_FLOAT, H5T_NATIVE_DOUBLE);
4866     nerrors += test_conv_flt_1(name, TEST_NORMAL, H5T_NATIVE_DOUBLE, H5T_NATIVE_FLOAT);
4867 #if H5_SIZEOF_LONG_DOUBLE!=H5_SIZEOF_DOUBLE && H5_SIZEOF_LONG_DOUBLE !=0
4868     nerrors += test_conv_flt_1(name, TEST_NORMAL, H5T_NATIVE_FLOAT, H5T_NATIVE_LDOUBLE);
4869     nerrors += test_conv_flt_1(name, TEST_NORMAL, H5T_NATIVE_DOUBLE, H5T_NATIVE_LDOUBLE);
4870     nerrors += test_conv_flt_1(name, TEST_NORMAL, H5T_NATIVE_LDOUBLE, H5T_NATIVE_FLOAT);
4871     nerrors += test_conv_flt_1(name, TEST_NORMAL, H5T_NATIVE_LDOUBLE, H5T_NATIVE_DOUBLE);
4872 #endif
4873 
4874     /*Test denormalized values.  TEST_DENORM indicates denormalized values.*/
4875     nerrors += test_conv_flt_1(name, TEST_DENORM, H5T_NATIVE_FLOAT, H5T_NATIVE_DOUBLE);
4876     nerrors += test_conv_flt_1(name, TEST_DENORM, H5T_NATIVE_DOUBLE, H5T_NATIVE_FLOAT);
4877 #if H5_SIZEOF_LONG_DOUBLE!=H5_SIZEOF_DOUBLE && H5_SIZEOF_LONG_DOUBLE!=0
4878     nerrors += test_conv_flt_1(name, TEST_DENORM, H5T_NATIVE_FLOAT, H5T_NATIVE_LDOUBLE);
4879     nerrors += test_conv_flt_1(name, TEST_DENORM, H5T_NATIVE_DOUBLE, H5T_NATIVE_LDOUBLE);
4880 #ifndef H5_DISABLE_SOME_LDOUBLE_CONV
4881     nerrors += test_conv_flt_1(name, TEST_DENORM, H5T_NATIVE_LDOUBLE, H5T_NATIVE_FLOAT);
4882 #else
4883     {
4884         char        str[256];        /*string        */
4885 
4886         HDsnprintf(str, sizeof(str), "Testing %s denormalized %s -> %s conversions",
4887                 name, "long double", "float");
4888         HDprintf("%-70s", str);
4889         SKIPPED();
4890 #if H5_SIZEOF_LONG_DOUBLE!=0
4891         HDputs("    Test skipped due to the conversion problem on IBM ppc64le cpu.");
4892 #else
4893         HDputs("    Test skipped due to disabled long double.");
4894 #endif
4895     }
4896 #endif
4897 
4898     nerrors += test_conv_flt_1(name, TEST_DENORM, H5T_NATIVE_LDOUBLE, H5T_NATIVE_DOUBLE);
4899 #endif
4900 
4901     /*Test special values, +/-0, +/-infinity, +/-QNaN, +/-SNaN.*/
4902     nerrors += test_conv_flt_1(name, TEST_SPECIAL, H5T_NATIVE_FLOAT, H5T_NATIVE_DOUBLE);
4903     nerrors += test_conv_flt_1(name, TEST_SPECIAL, H5T_NATIVE_DOUBLE, H5T_NATIVE_FLOAT);
4904 #if H5_SIZEOF_LONG_DOUBLE!=H5_SIZEOF_DOUBLE && H5_SIZEOF_LONG_DOUBLE!=0
4905     nerrors += test_conv_flt_1(name, TEST_SPECIAL, H5T_NATIVE_FLOAT, H5T_NATIVE_LDOUBLE);
4906     nerrors += test_conv_flt_1(name, TEST_SPECIAL, H5T_NATIVE_DOUBLE, H5T_NATIVE_LDOUBLE);
4907 #ifndef H5_DISABLE_SOME_LDOUBLE_CONV
4908     nerrors += test_conv_flt_1(name, TEST_SPECIAL, H5T_NATIVE_LDOUBLE, H5T_NATIVE_FLOAT);
4909     nerrors += test_conv_flt_1(name, TEST_SPECIAL, H5T_NATIVE_LDOUBLE, H5T_NATIVE_DOUBLE);
4910 #else
4911     {
4912         char        str[256];        /*string        */
4913 
4914         HDsnprintf(str, sizeof(str), "Testing %s special %s -> %s conversions",
4915                 name, "long double", "float or double");
4916         HDprintf("%-70s", str);
4917         SKIPPED();
4918 #if H5_SIZEOF_LONG_DOUBLE!=0
4919         HDputs("    Test skipped due to the conversion problem on IBM ppc64le cpu.");
4920 #else
4921         HDputs("    Test skipped due to disabled long double.");
4922 #endif
4923     }
4924 #endif
4925 #endif
4926 
4927 done:
4928     return nerrors;
4929 }
4930 
4931 
4932 /*-------------------------------------------------------------------------
4933  * Function:    run_int_fp_conv
4934  *
4935  * Purpose:    Runs all integer-float tests.
4936  *
4937  * Return:    Number of errors
4938  *
4939  * Programmer:    Raymond Lu
4940  *              Monday, November 10, 2003
4941  *
4942  * Modifications:
4943  *
4944  *-------------------------------------------------------------------------
4945  */
4946 static int
run_int_fp_conv(const char * name)4947 run_int_fp_conv(const char *name)
4948 {
4949     int        nerrors = 0;
4950 
4951     nerrors += test_conv_int_fp(name, TEST_NORMAL, H5T_NATIVE_SCHAR, H5T_NATIVE_FLOAT);
4952     nerrors += test_conv_int_fp(name, TEST_NORMAL, H5T_NATIVE_SCHAR, H5T_NATIVE_DOUBLE);
4953 
4954     nerrors += test_conv_int_fp(name, TEST_NORMAL, H5T_NATIVE_UCHAR, H5T_NATIVE_FLOAT);
4955     nerrors += test_conv_int_fp(name, TEST_NORMAL, H5T_NATIVE_UCHAR, H5T_NATIVE_DOUBLE);
4956 
4957     nerrors += test_conv_int_fp(name, TEST_NORMAL, H5T_NATIVE_SHORT, H5T_NATIVE_FLOAT);
4958     nerrors += test_conv_int_fp(name, TEST_NORMAL, H5T_NATIVE_SHORT, H5T_NATIVE_DOUBLE);
4959 
4960     nerrors += test_conv_int_fp(name, TEST_NORMAL, H5T_NATIVE_USHORT, H5T_NATIVE_FLOAT);
4961     nerrors += test_conv_int_fp(name, TEST_NORMAL, H5T_NATIVE_USHORT, H5T_NATIVE_DOUBLE);
4962 
4963     nerrors += test_conv_int_fp(name, TEST_NORMAL, H5T_NATIVE_INT, H5T_NATIVE_FLOAT);
4964     nerrors += test_conv_int_fp(name, TEST_NORMAL, H5T_NATIVE_INT, H5T_NATIVE_DOUBLE);
4965 
4966     nerrors += test_conv_int_fp(name, TEST_NORMAL, H5T_NATIVE_UINT, H5T_NATIVE_FLOAT);
4967     nerrors += test_conv_int_fp(name, TEST_NORMAL, H5T_NATIVE_UINT, H5T_NATIVE_DOUBLE);
4968 
4969 #if H5_SIZEOF_LONG!=H5_SIZEOF_INT
4970     nerrors += test_conv_int_fp(name, TEST_NORMAL, H5T_NATIVE_LONG, H5T_NATIVE_FLOAT);
4971     nerrors += test_conv_int_fp(name, TEST_NORMAL, H5T_NATIVE_LONG, H5T_NATIVE_DOUBLE);
4972 
4973     nerrors += test_conv_int_fp(name, TEST_NORMAL, H5T_NATIVE_ULONG, H5T_NATIVE_FLOAT);
4974     nerrors += test_conv_int_fp(name, TEST_NORMAL, H5T_NATIVE_ULONG, H5T_NATIVE_DOUBLE);
4975 #endif
4976 
4977 #if H5_SIZEOF_LONG_LONG!=H5_SIZEOF_LONG
4978     nerrors += test_conv_int_fp(name, TEST_NORMAL, H5T_NATIVE_LLONG, H5T_NATIVE_FLOAT);
4979     nerrors += test_conv_int_fp(name, TEST_NORMAL, H5T_NATIVE_LLONG, H5T_NATIVE_DOUBLE);
4980 
4981     nerrors += test_conv_int_fp(name, TEST_NORMAL, H5T_NATIVE_ULLONG, H5T_NATIVE_FLOAT);
4982     nerrors += test_conv_int_fp(name, TEST_NORMAL, H5T_NATIVE_ULLONG, H5T_NATIVE_DOUBLE);
4983 #endif
4984 
4985 #if H5_SIZEOF_LONG_DOUBLE!=H5_SIZEOF_DOUBLE
4986     nerrors += test_conv_int_fp(name, TEST_NORMAL, H5T_NATIVE_SCHAR, H5T_NATIVE_LDOUBLE);
4987     nerrors += test_conv_int_fp(name, TEST_NORMAL, H5T_NATIVE_UCHAR, H5T_NATIVE_LDOUBLE);
4988     nerrors += test_conv_int_fp(name, TEST_NORMAL, H5T_NATIVE_SHORT, H5T_NATIVE_LDOUBLE);
4989     nerrors += test_conv_int_fp(name, TEST_NORMAL, H5T_NATIVE_USHORT, H5T_NATIVE_LDOUBLE);
4990     nerrors += test_conv_int_fp(name, TEST_NORMAL, H5T_NATIVE_INT, H5T_NATIVE_LDOUBLE);
4991     nerrors += test_conv_int_fp(name, TEST_NORMAL, H5T_NATIVE_UINT, H5T_NATIVE_LDOUBLE);
4992 #if H5_SIZEOF_LONG!=H5_SIZEOF_INT
4993 #if !defined(H5_LONG_TO_LDOUBLE_SPECIAL) && !defined(H5_DISABLE_SOME_LDOUBLE_CONV)
4994     nerrors += test_conv_int_fp(name, TEST_NORMAL, H5T_NATIVE_LONG, H5T_NATIVE_LDOUBLE);
4995     nerrors += test_conv_int_fp(name, TEST_NORMAL, H5T_NATIVE_ULONG, H5T_NATIVE_LDOUBLE);
4996 #else
4997     {
4998         char        str[256];        /*string        */
4999 
5000         HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions",
5001                 name, "(unsigned) long", "long double");
5002         HDprintf("%-70s", str);
5003         SKIPPED();
5004 #if H5_SIZEOF_LONG_DOUBLE!=0
5005         HDputs("    Test skipped due to the special algorithm of hardware conversion.");
5006 #else
5007         HDputs("    Test skipped due to disabled long double.");
5008 #endif
5009     }
5010 #endif
5011 #endif /* H5_SIZEOF_LONG!=H5_SIZEOF_INT */
5012 #if H5_SIZEOF_LONG_LONG!=H5_SIZEOF_LONG
5013 #if H5_LLONG_TO_LDOUBLE_CORRECT
5014     nerrors += test_conv_int_fp(name, TEST_NORMAL, H5T_NATIVE_LLONG, H5T_NATIVE_LDOUBLE);
5015 #else /* H5_LLONG_TO_LDOUBLE_CORRECT */
5016     {
5017         char        str[256];        /*hello string        */
5018 
5019         HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions",
5020                 name, "long long", "long double");
5021         HDprintf("%-70s", str);
5022         SKIPPED();
5023         HDputs("    Test skipped due to compiler error in handling conversion.");
5024     }
5025 #endif /* H5_LLONG_TO_LDOUBLE_CORRECT */
5026 #if H5_LLONG_TO_LDOUBLE_CORRECT
5027     nerrors += test_conv_int_fp(name, TEST_NORMAL, H5T_NATIVE_ULLONG, H5T_NATIVE_LDOUBLE);
5028 #else /* H5_LLONG_TO_LDOUBLE_CORRECT */
5029     {
5030         char        str[256];        /*hello string        */
5031 
5032         HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions",
5033                 name, "unsigned long long", "long double");
5034         HDprintf("%-70s", str);
5035         SKIPPED();
5036         HDputs("    Test skipped due to compiler not handling conversion.");
5037     }
5038 #endif /* H5_LLONG_TO_LDOUBLE_CORRECT */
5039 #endif
5040 #endif
5041 
5042     return nerrors;
5043 }
5044 
5045 
5046 /*-------------------------------------------------------------------------
5047  * Function:    run_fp_int_conv
5048  *
5049  * Purpose:    Runs all float-integer tests.
5050  *
5051  * Return:    Number of errors
5052  *
5053  * Programmer:    Raymond Lu
5054  *              Monday, November 10, 2003
5055  *
5056  * Modifications:
5057  *
5058  *-------------------------------------------------------------------------
5059  */
5060 static int
run_fp_int_conv(const char * name)5061 run_fp_int_conv(const char *name)
5062 {
5063     int        nerrors = 0;
5064     int         test_values;
5065 
5066     for(test_values = TEST_NORMAL; test_values <= TEST_SPECIAL; test_values++) {
5067 
5068         nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_FLOAT, H5T_NATIVE_SCHAR);
5069         nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_DOUBLE, H5T_NATIVE_SCHAR);
5070 
5071         nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_FLOAT, H5T_NATIVE_UCHAR);
5072         nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_DOUBLE, H5T_NATIVE_UCHAR);
5073 
5074         nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_FLOAT, H5T_NATIVE_SHORT);
5075         nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_DOUBLE, H5T_NATIVE_SHORT);
5076 
5077         nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_FLOAT, H5T_NATIVE_USHORT);
5078         nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_DOUBLE, H5T_NATIVE_USHORT);
5079 
5080         nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_FLOAT, H5T_NATIVE_INT);
5081         nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_DOUBLE, H5T_NATIVE_INT);
5082 
5083         nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_FLOAT, H5T_NATIVE_UINT);
5084         nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_DOUBLE, H5T_NATIVE_UINT);
5085 
5086 #if H5_SIZEOF_LONG!=H5_SIZEOF_INT
5087         nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_FLOAT, H5T_NATIVE_LONG);
5088         nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_DOUBLE, H5T_NATIVE_LONG);
5089 
5090         nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_FLOAT, H5T_NATIVE_ULONG);
5091         nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_DOUBLE, H5T_NATIVE_ULONG);
5092 #endif
5093 
5094 #if H5_SIZEOF_LONG_LONG!=H5_SIZEOF_LONG
5095         if(!strcmp(name, "hw")) { /* Hardware conversion */
5096             nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_FLOAT, H5T_NATIVE_LLONG);
5097             nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_DOUBLE, H5T_NATIVE_LLONG);
5098         } else {  /* Software conversion */
5099             nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_FLOAT, H5T_NATIVE_LLONG);
5100             nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_DOUBLE, H5T_NATIVE_LLONG);
5101         }
5102         nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_FLOAT, H5T_NATIVE_ULLONG);
5103         nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_DOUBLE, H5T_NATIVE_ULLONG);
5104 #endif
5105 
5106 #if H5_SIZEOF_LONG_DOUBLE!=H5_SIZEOF_DOUBLE
5107         if(test_values != TEST_SPECIAL) {
5108         nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_LDOUBLE, H5T_NATIVE_SCHAR);
5109             nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_LDOUBLE, H5T_NATIVE_UCHAR);
5110             nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_LDOUBLE, H5T_NATIVE_SHORT);
5111             nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_LDOUBLE, H5T_NATIVE_USHORT);
5112             nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_LDOUBLE, H5T_NATIVE_INT);
5113             nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_LDOUBLE, H5T_NATIVE_UINT);
5114         } else {
5115 #ifndef H5_DISABLE_SOME_LDOUBLE_CONV
5116         nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_LDOUBLE, H5T_NATIVE_SCHAR);
5117             nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_LDOUBLE, H5T_NATIVE_UCHAR);
5118             nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_LDOUBLE, H5T_NATIVE_SHORT);
5119             nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_LDOUBLE, H5T_NATIVE_USHORT);
5120             nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_LDOUBLE, H5T_NATIVE_INT);
5121             nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_LDOUBLE, H5T_NATIVE_UINT);
5122 #else
5123             char        str[256];        /*string        */
5124 
5125             HDsnprintf(str, sizeof(str), "Testing %s special %s -> %s conversions",
5126                 name, "long double", "signed and unsigned char, short, int, long");
5127             HDprintf("%-70s", str);
5128             SKIPPED();
5129 #if H5_SIZEOF_LONG_DOUBLE!=0
5130             HDputs("    Test skipped due to the conversion problem on IBM ppc64le cpu.");
5131 #else
5132             HDputs("    Test skipped due to disabled long double.");
5133 #endif
5134 #endif
5135         }
5136 #if H5_SIZEOF_LONG!=H5_SIZEOF_INT && H5_SIZEOF_LONG_DOUBLE!=0
5137 #ifndef H5_LDOUBLE_TO_LONG_SPECIAL
5138         if(test_values != TEST_SPECIAL && test_values != TEST_NORMAL) {
5139             nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_LDOUBLE, H5T_NATIVE_LONG);
5140             nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_LDOUBLE, H5T_NATIVE_ULONG);
5141         } else {
5142 #ifndef H5_DISABLE_SOME_LDOUBLE_CONV
5143             nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_LDOUBLE, H5T_NATIVE_LONG);
5144             nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_LDOUBLE, H5T_NATIVE_ULONG);
5145 #endif
5146         }
5147 #else
5148         {
5149             char        str[256];        /*string        */
5150 
5151             HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions",
5152                     name, "long double", "(unsigned) long");
5153             HDprintf("%-70s", str);
5154             SKIPPED();
5155 #if H5_SIZEOF_LONG_DOUBLE!=0
5156             HDputs("    Test skipped due to the special algorithm of hardware conversion.");
5157 #else
5158             HDputs("    Test skipped due to disabled long double.");
5159 #endif
5160         }
5161 #endif
5162 #endif /*H5_SIZEOF_LONG!=H5_SIZEOF_INT && H5_SIZEOF_LONG_DOUBLE!=0 */
5163 
5164 #if H5_SIZEOF_LONG_LONG!=H5_SIZEOF_LONG && H5_SIZEOF_LONG_DOUBLE!=0
5165 #ifdef H5_LDOUBLE_TO_LLONG_ACCURATE
5166         nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_LDOUBLE, H5T_NATIVE_LLONG);
5167 #else /*H5_LDOUBLE_TO_LLONG_ACCURATE*/
5168         {
5169             char        str[256];        /*string        */
5170 
5171             HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions",
5172                     name, "long double", "long long");
5173             HDprintf("%-70s", str);
5174             SKIPPED();
5175 #if H5_SIZEOF_LONG_DOUBLE!=0
5176             HDputs("    Test skipped due to hardware conversion error.");
5177 #else
5178             HDputs("    Test skipped due to disabled long double.");
5179 #endif
5180         }
5181 #endif /*H5_LDOUBLE_TO_LLONG_ACCURATE*/
5182 #if defined(H5_LDOUBLE_TO_LLONG_ACCURATE)
5183         nerrors += test_conv_int_fp(name, test_values, H5T_NATIVE_LDOUBLE, H5T_NATIVE_ULLONG);
5184 #else /*H5_LDOUBLE_TO_LLONG_ACCURATE*/
5185         {
5186             char        str[256];        /*string        */
5187 
5188             HDsnprintf(str, sizeof(str), "Testing %s %s -> %s conversions",
5189                     name, "long double", "unsigned long long");
5190             HDprintf("%-70s", str);
5191             SKIPPED();
5192 #if H5_SIZEOF_LONG_DOUBLE!=0
5193             HDputs("    Test skipped due to hardware conversion error.");
5194 #else
5195             HDputs("    Test skipped due to disabled long double.");
5196 #endif
5197         }
5198 #endif /*H5_LDOUBLE_TO_LLONG_ACCURATE*/
5199 #endif
5200 #endif
5201     } /* end for */
5202 
5203     return nerrors;
5204 }
5205 
5206 
5207 /*-------------------------------------------------------------------------
5208  * Function:    main
5209  *
5210  * Purpose:     Test the data type(integer and floating-point number).
5211  *
5212  * Return:      Success:
5213  *
5214  *              Failure:
5215  *
5216  * Programmer:  Robb Matzke
5217  *              Tuesday, December 9, 1997
5218  *
5219  * Modifications:
5220  *              Raymond Lu
5221  *              Monday, April 4, 2005
5222  *              These tests were split from dtypes.c because dtypes.c
5223  *              has grown too big.
5224  *
5225  *-------------------------------------------------------------------------
5226  */
5227 int
main(void)5228 main(void)
5229 {
5230     unsigned long    nerrors = 0;
5231 
5232     /* Set the random # seed */
5233     HDsrandom((unsigned)HDtime(NULL));
5234 
5235     reset_hdf5();
5236 
5237     if (ALIGNMENT)
5238     HDprintf("Testing non-aligned conversions (ALIGNMENT=%d)....\n", ALIGNMENT);
5239 
5240     /* Do the tests */
5241 
5242     /* Test H5Tcompiler_conv() for querying hard conversion. */
5243     nerrors += (unsigned long)test_hard_query();
5244 
5245     /* Test user-define, query functions and software conversion
5246      * for user-defined floating-point types */
5247     nerrors += (unsigned long)test_derived_flt();
5248 
5249     /* Test user-define, query functions and software conversion
5250      * for user-defined integer types */
5251     nerrors += (unsigned long)test_derived_integer();
5252 
5253     /* Does floating point overflow generate a SIGFPE? */
5254     generates_sigfpe();
5255 
5256     /* Test degenerate cases */
5257     nerrors += (unsigned long)run_fp_tests("noop");
5258 
5259     /* Test hardware floating-point conversion functions */
5260     nerrors += (unsigned long)run_fp_tests("hard");
5261 
5262     /* Test hardware integer conversion functions */
5263     nerrors += (unsigned long)run_integer_tests("hard");
5264 
5265     /* Test hardware integer-float conversion functions */
5266     nerrors += (unsigned long)run_int_fp_conv("hard");
5267 
5268     /* Test hardware float-integer conversion functions */
5269     nerrors += (unsigned long)run_fp_int_conv("hard");
5270 
5271     /* Test a few special values for hardware float-integer conversions */
5272     nerrors += (unsigned long)test_particular_fp_integer();
5273 
5274     /*----------------------------------------------------------------------
5275      * Software tests
5276      *----------------------------------------------------------------------
5277      */
5278     without_hardware_g = TRUE;
5279 
5280     /* Restore the default error handler (set in h5_reset()) */
5281     h5_restore_err();
5282 
5283     reset_hdf5();
5284 
5285     /* Test software floating-point conversion functions */
5286     nerrors += (unsigned long)run_fp_tests("soft");
5287 
5288     /* Test software integer conversion functions */
5289     nerrors += (unsigned long)test_conv_int_2();
5290     nerrors += (unsigned long)run_integer_tests("soft");
5291 
5292     /* Test software float-integer conversion functions */
5293     nerrors += (unsigned long)run_fp_int_conv("soft");
5294 
5295     /* Test software integer-float conversion functions */
5296     nerrors += (unsigned long)run_int_fp_conv("soft");
5297 
5298     /* Restore the default error handler (set in h5_reset()) */
5299     h5_restore_err();
5300 
5301     reset_hdf5();
5302 
5303     /* Restore the default error handler (set in h5_reset()) */
5304     h5_restore_err();
5305 
5306     if (nerrors) {
5307         HDprintf("***** %lu FAILURE%s! *****\n",
5308                nerrors, 1==nerrors?"":"S");
5309         HDexit(EXIT_FAILURE);
5310     }
5311     HDprintf("All data type tests passed.\n");
5312     return 0;
5313 }
5314 
5315