From 78931a0d83bc6447d123413604f76cc374aaeca0 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Wed, 20 May 2020 08:57:20 -0700 Subject: Brought the dsets test in line with develop. Brings over the fix for 0-size dataset metadata allocation. --- src/H5Dint.c | 2 +- src/H5Dlayout.c | 44 +-- src/H5Oprivate.h | 12 +- test/dsets.c | 1072 +++++++++++++++++++++++++++++++++++++++++------------- 4 files changed, 845 insertions(+), 285 deletions(-) diff --git a/src/H5Dint.c b/src/H5Dint.c index 696c7d0..8f2178d 100644 --- a/src/H5Dint.c +++ b/src/H5Dint.c @@ -2270,7 +2270,7 @@ H5D__alloc_storage(const H5D_io_info_t *io_info, H5D_time_alloc_t time_alloc, * We assume that external storage is already * allocated by the caller, or at least will be before I/O is performed. */ - if(!(H5S_NULL == H5S_GET_EXTENT_TYPE(dset->shared->space) || dset->shared->dcpl_cache.efl.nused > 0)) { + if(!(0 == H5S_GET_EXTENT_NPOINTS(dset->shared->space) || dset->shared->dcpl_cache.efl.nused > 0)) { /* Get a pointer to the dataset's layout information */ layout = &(dset->shared->layout); diff --git a/src/H5Dlayout.c b/src/H5Dlayout.c index c8afb8e..2447fb6 100644 --- a/src/H5Dlayout.c +++ b/src/H5Dlayout.c @@ -25,7 +25,6 @@ #include "H5Dpkg.h" /* Datasets */ #include "H5Eprivate.h" /* Error handling */ #include "H5HLprivate.h" /* Local heaps */ -#include "H5MMprivate.h" /* Memory management */ /****************/ @@ -82,7 +81,7 @@ const unsigned H5O_layout_ver_bounds[] = { herr_t H5D__layout_set_io_ops(const H5D_t *dataset) { - herr_t ret_value = SUCCEED; /* Return value */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE @@ -335,7 +334,7 @@ done: *------------------------------------------------------------------------- */ herr_t -H5D__layout_set_latest_indexing(H5O_layout_t *layout, const H5S_t *space, +H5D__layout_set_latest_indexing(H5O_layout_t *layout, const H5S_t *space, const H5D_dcpl_cache_t *dcpl_cache) { herr_t ret_value = SUCCEED; /* Return value */ @@ -361,9 +360,9 @@ H5D__layout_set_latest_indexing(H5O_layout_t *layout, const H5S_t *space, if(ndims > 0) { hsize_t max_dims[H5O_LAYOUT_NDIMS]; /* Maximum dimension sizes */ hsize_t cur_dims[H5O_LAYOUT_NDIMS]; /* Current dimension sizes */ - unsigned unlim_count = 0; /* Count of unlimited max. dimensions */ + unsigned unlim_count = 0; /* Count of unlimited max. dimensions */ hbool_t single = TRUE; /* Fulfill single chunk indexing */ - unsigned u; /* Local index variable */ + unsigned u; /* Local index variable */ /* Query the dataspace's dimensions */ if(H5S_get_simple_extent_dims(space, cur_dims, max_dims) < 0) @@ -417,7 +416,7 @@ H5D__layout_set_latest_indexing(H5O_layout_t *layout, const H5S_t *space, layout->storage.u.chunk.idx_type = H5D_CHUNK_IDX_SINGLE; layout->storage.u.chunk.ops = H5D_COPS_SINGLE; } /* end if */ - else if(!dcpl_cache->pline.nused && + else if(!dcpl_cache->pline.nused && dcpl_cache->fill.alloc_time == H5D_ALLOC_TIME_EARLY) { /* Set the chunk index type to "none" Index */ @@ -506,7 +505,7 @@ H5D__layout_oh_create(H5F_t *file, H5O_t *oh, H5D_t *dset, hid_t dapl_id) if(H5D__alloc_storage(&io_info, H5D_ALLOC_CREATE, FALSE, NULL) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize storage") - } /* end if */ + } /* Update external storage message, if it's used */ if(dset->shared->dcpl_cache.efl.nused > 0) { @@ -557,10 +556,13 @@ H5D__layout_oh_create(H5F_t *file, H5O_t *oh, H5D_t *dset, hid_t dapl_id) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to update external file list message") } /* end if */ - /* (Don't make layout message constant unless allocation time is early and non-filtered, since space may not be allocated) */ + /* Create layout message */ + /* (Don't make layout message constant unless allocation time is early and + * non-filtered and has >0 elements, since space may not be allocated -QAK) */ /* (Note: this is relying on H5D__alloc_storage not calling H5O_msg_write during dataset creation) */ if(fill_prop->alloc_time == H5D_ALLOC_TIME_EARLY && H5D_COMPACT != layout->type - && !dset->shared->dcpl_cache.pline.nused) + && !dset->shared->dcpl_cache.pline.nused + && (0 != H5S_GET_EXTENT_NPOINTS(dset->shared->space))) layout_mesg_flags = H5O_MSG_FLAG_CONSTANT; else layout_mesg_flags = 0; @@ -587,15 +589,15 @@ done: /*------------------------------------------------------------------------- - * Function: H5D__layout_oh_read + * Function: H5D__layout_oh_read * - * Purpose: Read layout/pline/efl information for dataset + * Purpose: Read layout/pline/efl information for dataset * - * Return: Success: SUCCEED - * Failure: FAIL + * Return: Success: SUCCEED + * Failure: FAIL * - * Programmer: Quincey Koziol - * Monday, July 27, 2009 + * Programmer: Quincey Koziol + * Monday, July 27, 2009 * *------------------------------------------------------------------------- */ @@ -681,15 +683,15 @@ done: /*------------------------------------------------------------------------- - * Function: H5D__layout_oh_write + * Function: H5D__layout_oh_write * - * Purpose: Write layout information for dataset + * Purpose: Write layout information for dataset * - * Return: Success: SUCCEED - * Failure: FAIL + * Return: Success: SUCCEED + * Failure: FAIL * - * Programmer: Quincey Koziol - * Monday, July 27, 2009 + * Programmer: Quincey Koziol + * Monday, July 27, 2009 * *------------------------------------------------------------------------- */ diff --git a/src/H5Oprivate.h b/src/H5Oprivate.h index 08589c0..32df33f 100644 --- a/src/H5Oprivate.h +++ b/src/H5Oprivate.h @@ -120,7 +120,7 @@ typedef struct H5O_mesg_t H5O_mesg_t; /* If the module using this macro is allowed access to the private variables, access them directly */ #ifdef H5O_MODULE #define H5O_OH_GET_ADDR(O) ((O)->chunk[0].addr) -#define H5O_OH_GET_VERSION ((O)->version) +#define H5O_OH_GET_VERSION(O) ((O)->version) #define H5O_OH_GET_FLAGS(O) ((O)->flags) #define H5O_OH_GET_MTIME(O) ((O)->mtime) #else /* H5O_MODULE */ @@ -222,7 +222,7 @@ typedef struct H5O_copy_t { #define H5O_MDCI_MSG_ID 0x0018 /* Metadata Cache Image Message */ #define H5O_UNKNOWN_ID 0x0019 /* Placeholder message ID for unknown message. */ /* (this should never exist in a file) */ -/* +/* * Note: Must increment H5O_MSG_TYPES in H5Opkg.h and update H5O_msg_class_g * in H5O.c when creating a new message type. Also bump the value of * H5O_BOGUS_INVALID_ID, below, to be one greater than the value of @@ -481,7 +481,7 @@ typedef struct H5O_storage_chunk_t { const struct H5D_chunk_ops_t *ops; /* Pointer to chunked storage operations */ union { H5O_storage_chunk_btree_t btree; /* Information for v1 B-tree index */ - H5O_storage_chunk_bt2_t btree2; /* Information for v2 B-tree index */ + H5O_storage_chunk_bt2_t btree2; /* Information for v2 B-tree index */ H5O_storage_chunk_earray_t earray; /* Information for extensible array index */ H5O_storage_chunk_farray_t farray; /* Information for fixed array index */ H5O_storage_chunk_single_filt_t single; /* Information for single chunk w/ filters index */ @@ -582,8 +582,8 @@ typedef struct H5O_storage_t { typedef struct H5O_layout_chunk_farray_t { /* Creation parameters for fixed array data structure */ struct { - uint8_t max_dblk_page_nelmts_bits; /* Log2(Max. # of elements in a data block page) - - i.e. # of bits needed to store max. # of elements + uint8_t max_dblk_page_nelmts_bits; /* Log2(Max. # of elements in a data block page) - + i.e. # of bits needed to store max. # of elements in a data block page */ } cparam; } H5O_layout_chunk_farray_t; @@ -869,7 +869,6 @@ typedef struct { } u; } H5O_mesg_operator_t; - /* Typedef for abstract object creation */ typedef struct { H5O_type_t obj_type; /* Type of object to create */ @@ -877,6 +876,7 @@ typedef struct { void *new_obj; /* Pointer to new object created */ } H5O_obj_create_t; + /* Forward declarations for prototype arguments */ struct H5P_genplist_t; diff --git a/test/dsets.c b/test/dsets.c index 6c91ba9..f7e90a5 100644 --- a/test/dsets.c +++ b/test/dsets.c @@ -27,7 +27,6 @@ #include "testhdf5.h" #include "H5srcdir.h" -#include "H5Bprivate.h" #include "H5CXprivate.h" /* API Contexts */ #include "H5Iprivate.h" #include "H5Pprivate.h" @@ -84,6 +83,7 @@ const char *FILENAME[] = { "dls_01_strings", /* 23 */ "power2up", /* 24 */ "version_bounds", /* 25 */ + "alloc_0sized", /* 26 */ NULL }; @@ -148,10 +148,12 @@ const char *FILENAME[] = { #define DSET_COPY_DCPL_NAME_1 "copy_dcpl_1" #define DSET_COPY_DCPL_NAME_2 "copy_dcpl_2" #define COPY_DCPL_EXTFILE_NAME "ext_file" +#ifndef H5_NO_DEPRECATED_SYMBOLS #define DSET_DEPREC_NAME "deprecated" #define DSET_DEPREC_NAME_CHUNKED "deprecated_chunked" #define DSET_DEPREC_NAME_COMPACT "deprecated_compact" #define DSET_DEPREC_NAME_FILTER "deprecated_filter" +#endif /* H5_NO_DEPRECATED_SYMBOLS */ /* Dataset names for testing Fixed Array Indexing */ #define DSET_FIXED_MAX "DSET_FIXED_MAX" @@ -177,7 +179,9 @@ const char *FILENAME[] = { #define H5Z_FILTER_CORRUPT 306 #define H5Z_FILTER_CAN_APPLY_TEST 307 #define H5Z_FILTER_SET_LOCAL_TEST 308 +#ifndef H5_NO_DEPRECATED_SYMBOLS #define H5Z_FILTER_DEPREC 309 +#endif /* H5_NO_DEPRECATED_SYMBOLS */ #define H5Z_FILTER_EXPAND 310 #define H5Z_FILTER_CAN_APPLY_TEST2 311 #define H5Z_FILTER_COUNT 312 @@ -280,10 +284,16 @@ const char *FILENAME[] = { /* Shared global arrays */ #define DSET_DIM1 100 #define DSET_DIM2 200 -int points[DSET_DIM1][DSET_DIM2], check[DSET_DIM1][DSET_DIM2]; -double points_dbl[DSET_DIM1][DSET_DIM2], check_dbl[DSET_DIM1][DSET_DIM2]; -size_t count_nbytes_read = 0; -size_t count_nbytes_written = 0; +int **points = NULL; +int *points_data = NULL; +double **points_dbl = NULL; +double *points_dbl_data = NULL; +int **check = NULL; +int *check_data = NULL; +double **check_dbl = NULL; +double *check_dbl_data = NULL; +size_t count_nbytes_read = 0; +size_t count_nbytes_written = 0; /* Temporary buffer dimensions */ #define DSET_TMP_DIM1 50 @@ -519,7 +529,8 @@ test_simple_io(const char *env_h5_drvr, hid_t fapl) void *tconv_buf = NULL; int f = -1; haddr_t offset; - int rdata[DSET_DIM1][DSET_DIM2]; + int **rdata = NULL; + int *rdata_bytes = NULL; TESTING("simple I/O"); @@ -527,6 +538,14 @@ test_simple_io(const char *env_h5_drvr, hid_t fapl) if(HDstrcmp(env_h5_drvr, "split") && HDstrcmp(env_h5_drvr, "multi") && HDstrcmp(env_h5_drvr, "family")) { h5_fixname(FILENAME[4], fapl, filename, sizeof filename); + /* Set up data array */ + if(NULL == (rdata_bytes = (int *)HDcalloc(DSET_DIM1 * DSET_DIM2, sizeof(int)))) + TEST_ERROR; + if(NULL == (rdata = (int **)HDcalloc(DSET_DIM1, sizeof(rdata_bytes)))) + TEST_ERROR; + for (i = 0; i < DSET_DIM1; i++) + rdata[i] = rdata_bytes + (i * DSET_DIM2); + /* Initialize the dataset */ for(i = n = 0; i < DSET_DIM1; i++) for(j = 0; j < DSET_DIM2; j++) @@ -556,7 +575,7 @@ test_simple_io(const char *env_h5_drvr, hid_t fapl) if(H5Dget_offset(dataset) != HADDR_UNDEF) goto error; /* Write the data to the dataset */ - if(H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, xfer, points) < 0) + if(H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, xfer, points_data) < 0) goto error; /* Test dataset address in file. Open the same file as a C file, seek @@ -565,7 +584,7 @@ test_simple_io(const char *env_h5_drvr, hid_t fapl) if((offset=H5Dget_offset(dataset))==HADDR_UNDEF) goto error; /* Read the dataset back */ - if(H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, xfer, check) < 0) + if(H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, xfer, check_data) < 0) goto error; /* Check that the values read are the same as the values written */ @@ -589,7 +608,7 @@ test_simple_io(const char *env_h5_drvr, hid_t fapl) f = HDopen(filename, O_RDONLY); HDlseek(f, (off_t)offset, SEEK_SET); - if(HDread(f, rdata, sizeof(int)*DSET_DIM1*DSET_DIM2) < 0) + if(HDread(f, rdata_bytes, sizeof(int)*DSET_DIM1*DSET_DIM2) < 0) goto error; /* Check that the values read are the same as the values written */ @@ -608,6 +627,9 @@ test_simple_io(const char *env_h5_drvr, hid_t fapl) f = -1; HDfree(tconv_buf); + HDfree(rdata_bytes); + HDfree(rdata); + PASSED(); } /* end if */ else { @@ -628,8 +650,11 @@ error: if(H5Fclose(file) < 0) TEST_ERROR if(f > 0) HDclose(f); - if(tconv_buf) - HDfree(tconv_buf); + + HDfree(tconv_buf); + HDfree(rdata_bytes); + HDfree(rdata); + return FAIL; } /* end test_simple_io() */ @@ -652,7 +677,8 @@ test_userblock_offset(const char *env_h5_drvr, hid_t fapl, hbool_t new_format) hsize_t dims[2]; int f = -1; haddr_t offset; - int rdata[DSET_DIM1][DSET_DIM2]; + int **rdata = NULL; + int *rdata_bytes = NULL; TESTING("dataset offset with user block"); @@ -660,6 +686,14 @@ test_userblock_offset(const char *env_h5_drvr, hid_t fapl, hbool_t new_format) if(HDstrcmp(env_h5_drvr, "split") && HDstrcmp(env_h5_drvr, "multi") && HDstrcmp(env_h5_drvr, "family")) { h5_fixname(FILENAME[2], fapl, filename, sizeof filename); + /* Set up data array */ + if(NULL == (rdata_bytes = (int *)HDcalloc(DSET_DIM1 * DSET_DIM2, sizeof(int)))) + TEST_ERROR; + if(NULL == (rdata = (int **)HDcalloc(DSET_DIM1, sizeof(rdata_bytes)))) + TEST_ERROR; + for (i = 0; i < DSET_DIM1; i++) + rdata[i] = rdata_bytes + (i * DSET_DIM2); + if((fcpl=H5Pcreate(H5P_FILE_CREATE)) < 0) goto error; if(H5Pset_userblock(fcpl, (hsize_t)USER_BLOCK) < 0) goto error; if(new_format) @@ -683,7 +717,7 @@ test_userblock_offset(const char *env_h5_drvr, hid_t fapl, hbool_t new_format) space = -1; /* Write the data to the dataset */ - if(H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, points) < 0) + if(H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, points_data) < 0) goto error; /* Test dataset address in file. Open the same file as a C file, seek @@ -698,7 +732,7 @@ test_userblock_offset(const char *env_h5_drvr, hid_t fapl, hbool_t new_format) f = HDopen(filename, O_RDONLY); HDlseek(f, (off_t)offset, SEEK_SET); - if(HDread(f, rdata, sizeof(int)*DSET_DIM1*DSET_DIM2) < 0) + if(HDread(f, rdata_bytes, sizeof(int)*DSET_DIM1*DSET_DIM2) < 0) goto error; /* Check that the values read are the same as the values written */ @@ -716,6 +750,9 @@ test_userblock_offset(const char *env_h5_drvr, hid_t fapl, hbool_t new_format) HDclose(f); f = -1; + HDfree(rdata_bytes); + HDfree(rdata); + PASSED(); } /* end if */ else { @@ -736,6 +773,10 @@ error: if(H5Fclose(file) < 0) TEST_ERROR if(f > 0) HDclose(f); + + HDfree(rdata_bytes); + HDfree(rdata); + return FAIL; } /* end test_userblock_offset() */ @@ -836,7 +877,7 @@ test_compact_io(hid_t fapl) **************************************/ /* Create a copy of file access property list */ - if((new_fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) TEST_ERROR + if((new_fapl = h5_fileaccess()) < 0) TEST_ERROR /* Loop through all the combinations of low/high library format bounds, skipping invalid combinations. @@ -1794,7 +1835,7 @@ test_filter_internal(hid_t fid, const char *name, hid_t dcpl, int if_fletcher32, */ TESTING(" filters (uninitialized read)"); - if(H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, dxpl, check) < 0) + if(H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, dxpl, check_data) < 0) TEST_ERROR; for(i=0; i<(size_t)size[0]; i++) { @@ -1823,7 +1864,7 @@ test_filter_internal(hid_t fid, const char *name, hid_t dcpl, int if_fletcher32, } } - if(H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, write_dxpl, points) < 0) + if(H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, write_dxpl, points_data) < 0) TEST_ERROR; if((*dset_size=H5Dget_storage_size(dataset))==0) TEST_ERROR; @@ -1841,25 +1882,25 @@ test_filter_internal(hid_t fid, const char *name, hid_t dcpl, int if_fletcher32, /* Default behavior is failure when data is corrupted. */ /* (Use the "write" DXPL in order to make certain corruption is seen) */ H5E_BEGIN_TRY { - status=H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, write_dxpl, check); + status=H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, write_dxpl, check_data); } H5E_END_TRY; if(status>=0) TEST_ERROR; /* Callback decides to continue inspite data is corrupted. */ if(H5Pset_filter_callback(dxpl, filter_cb_cont, NULL) < 0) TEST_ERROR; - if(H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, dxpl, check) < 0) + if(H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, dxpl, check_data) < 0) TEST_ERROR; /* Callback decides to fail when data is corrupted. */ if(H5Pset_filter_callback(write_dxpl, filter_cb_fail, NULL) < 0) TEST_ERROR; /* (Use the "write" DXPL in order to make certain corruption is seen) */ H5E_BEGIN_TRY { - status=H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, write_dxpl, check); + status = H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, write_dxpl, check_data); } H5E_END_TRY; if(status>=0) TEST_ERROR; } else { - if(H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, dxpl, check) < 0) + if(H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, dxpl, check_data) < 0) TEST_ERROR; /* Check that the values read are the same as the values written */ @@ -1893,33 +1934,33 @@ test_filter_internal(hid_t fid, const char *name, hid_t dcpl, int if_fletcher32, points[i][j] = (int)HDrandom (); } } - if(H5Dwrite (dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, write_dxpl, points) < 0) + if(H5Dwrite (dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, write_dxpl, points_data) < 0) TEST_ERROR; if(corrupted) { /* Default behavior is failure when data is corrupted. */ /* (Use the "write" DXPL in order to make certain corruption is seen) */ H5E_BEGIN_TRY { - status=H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, write_dxpl, check); + status = H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, write_dxpl, check_data); } H5E_END_TRY; if(status>=0) TEST_ERROR; /* Callback decides to continue inspite data is corrupted. */ if(H5Pset_filter_callback(dxpl, filter_cb_cont, NULL) < 0) TEST_ERROR; - if(H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, dxpl, check) < 0) + if(H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, dxpl, check_data) < 0) TEST_ERROR; /* Callback decides to fail when data is corrupted. */ if(H5Pset_filter_callback(write_dxpl, filter_cb_fail, NULL) < 0) TEST_ERROR; /* (Use the "write" DXPL in order to make certain corruption is seen) */ H5E_BEGIN_TRY { - status=H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, write_dxpl, check); + status = H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, write_dxpl, check_data); } H5E_END_TRY; if(status>=0) TEST_ERROR; } else { /* Read the dataset back and check it */ - if(H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, dxpl, check) < 0) + if(H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, dxpl, check_data) < 0) TEST_ERROR; /* Check that the values read are the same as the values written */ @@ -1954,13 +1995,13 @@ test_filter_internal(hid_t fid, const char *name, hid_t dcpl, int if_fletcher32, /* Default behavior is failure when data is corrupted. */ /* (Use the "write" DXPL in order to make certain corruption is seen) */ H5E_BEGIN_TRY { - status = H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, write_dxpl, check); + status = H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, write_dxpl, check_data); } H5E_END_TRY; if(status >= 0) TEST_ERROR; /* Callback decides to continue inspite data is corrupted. */ if(H5Pset_filter_callback(dxpl, filter_cb_cont, NULL) < 0) TEST_ERROR; - if(H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, dxpl, check) < 0) + if(H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, dxpl, check_data) < 0) TEST_ERROR; /* Callback decides to fail when data is corrupted. */ @@ -1968,12 +2009,12 @@ test_filter_internal(hid_t fid, const char *name, hid_t dcpl, int if_fletcher32, /* (Use the "write" DXPL in order to make certain corruption is seen) */ H5E_BEGIN_TRY { - status = H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, write_dxpl, check); + status = H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, write_dxpl, check_data); } H5E_END_TRY; if(status >= 0) TEST_ERROR; } /* end if */ else { - if(H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, dxpl, check) < 0) + if(H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, dxpl, check_data) < 0) TEST_ERROR; /* Check that the values read are the same as the values written */ @@ -2007,32 +2048,32 @@ test_filter_internal(hid_t fid, const char *name, hid_t dcpl, int if_fletcher32, if(H5Sselect_hyperslab(sid, H5S_SELECT_SET, hs_offset, NULL, hs_size, NULL) < 0) TEST_ERROR; /* (Use the "read" DXPL because partial I/O on corrupted data test needs to ignore errors during writing) */ - if(H5Dwrite (dataset, H5T_NATIVE_INT, sid, sid, dxpl, points) < 0) + if(H5Dwrite (dataset, H5T_NATIVE_INT, sid, sid, dxpl, points_data) < 0) TEST_ERROR; if(corrupted) { /* Default behavior is failure when data is corrupted. */ /* (Use the "write" DXPL in order to make certain corruption is seen) */ H5E_BEGIN_TRY { - status=H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, write_dxpl, check); + status = H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, write_dxpl, check_data); } H5E_END_TRY; if(status>=0) TEST_ERROR; /* Callback decides to continue inspite data is corrupted. */ if(H5Pset_filter_callback(dxpl, filter_cb_cont, NULL) < 0) TEST_ERROR; - if(H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, dxpl, check) < 0) + if(H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, dxpl, check_data) < 0) TEST_ERROR; /* Callback decides to fail when data is corrupted. */ if(H5Pset_filter_callback(write_dxpl, filter_cb_fail, NULL) < 0) TEST_ERROR; /* (Use the "write" DXPL in order to make certain corruption is seen) */ H5E_BEGIN_TRY { - status=H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, write_dxpl, check); + status = H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, write_dxpl, check_data); } H5E_END_TRY; if(status>=0) TEST_ERROR; } else { - if(H5Dread (dataset, H5T_NATIVE_INT, sid, sid, dxpl, check) < 0) + if(H5Dread(dataset, H5T_NATIVE_INT, sid, sid, dxpl, check_data) < 0) TEST_ERROR; /* Check that the values read are the same as the values written */ @@ -2298,9 +2339,9 @@ H5_ATTR_UNUSED hsize_t shuffle_size; /* Size of dataset with shuffle filter */ -#if(defined H5_HAVE_FILTER_DEFLATE | defined H5_HAVE_FILTER_SZIP) +#if defined(H5_HAVE_FILTER_DEFLATE) || defined(H5_HAVE_FILTER_SZIP) hsize_t combo_size; /* Size of dataset with multiple filters */ -#endif /* defined H5_HAVE_FILTER_DEFLATE | defined H5_HAVE_FILTER_SZIP */ +#endif /* defined(H5_HAVE_FILTER_DEFLATE) || defined(H5_HAVE_FILTER_SZIP) */ /* test the H5Zget_filter_info function */ if(test_get_filter_info() < 0) goto error; @@ -2637,7 +2678,7 @@ test_missing_filter(hid_t file) } /* end if */ /* Write data */ - if(H5Dwrite(dsid, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, points) < 0) { + if(H5Dwrite(dsid, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, points_data) < 0) { H5_FAILED(); HDprintf(" Line %d: Error writing dataset data\n",__LINE__); goto error; @@ -2666,7 +2707,7 @@ test_missing_filter(hid_t file) } /* end if */ /* Read data */ - if(H5Dread(dsid, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, check) < 0) { + if(H5Dread(dsid, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, check_data) < 0) { H5_FAILED(); HDprintf(" Line %d: Error reading dataset data\n",__LINE__); goto error; @@ -2727,7 +2768,7 @@ test_missing_filter(hid_t file) /* Read data (should fail, since deflate filter is missing) */ H5E_BEGIN_TRY { - ret = H5Dread(dsid, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, check); + ret = H5Dread(dsid, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, check_data); } H5E_END_TRY; if(ret>=0) { H5_FAILED(); @@ -3081,7 +3122,7 @@ test_nbit_float(hid_t file) */ for(i = 0; i < (size_t)size[0]; i++) { for(j = 0; j < (size_t)size[1]; j++) { - if(!(orig_data[i][j] == orig_data[i][j])) + if(HDisnan(orig_data[i][j])) continue; /* skip if value is NaN */ if(!H5_FLT_ABS_EQUAL(new_data[i][j], orig_data[i][j])) { H5_FAILED(); @@ -3213,7 +3254,7 @@ test_nbit_double(hid_t file) */ for(i = 0; i < (size_t)size[0]; i++) { for(j = 0; j < (size_t)size[1]; j++) { - if(!(orig_data[i][j] == orig_data[i][j])) + if(HDisnan(orig_data[i][j])) continue; /* skip if value is NaN */ if(!H5_DBL_ABS_EQUAL(new_data[i][j], orig_data[i][j])) { H5_FAILED(); @@ -3548,7 +3589,7 @@ test_nbit_compound(hid_t file) if(((unsigned)new_data[i][j].i & i_mask) != ((unsigned)orig_data[i][j].i & i_mask) || ((unsigned)new_data[i][j].c & c_mask) != ((unsigned)orig_data[i][j].c & c_mask) || ((unsigned)new_data[i][j].s & s_mask) != ((unsigned)orig_data[i][j].s & s_mask) || - (orig_data[i][j].f == orig_data[i][j].f && !H5_FLT_ABS_EQUAL(new_data[i][j].f, orig_data[i][j].f))) + (!HDisnan(orig_data[i][j].f) && !H5_FLT_ABS_EQUAL(new_data[i][j].f, orig_data[i][j].f))) { H5_FAILED(); HDprintf(" Read different values than written.\n"); @@ -3870,7 +3911,7 @@ test_nbit_compound_2(hid_t file) if(((unsigned)new_data[i][j].d[m][n].i & i_mask) != ((unsigned)orig_data[i][j].d[m][n].i & i_mask)|| ((unsigned)new_data[i][j].d[m][n].c & c_mask) != ((unsigned)orig_data[i][j].d[m][n].c & c_mask)|| ((unsigned)new_data[i][j].d[m][n].s & s_mask) != ((unsigned)orig_data[i][j].d[m][n].s & s_mask)|| - (new_data[i][j].d[m][n].f == new_data[i][j].d[m][n].f && !H5_FLT_ABS_EQUAL(new_data[i][j].d[m][n].f, new_data[i][j].d[m][n].f))) { + (!HDisnan(new_data[i][j].d[m][n].f) && !H5_FLT_ABS_EQUAL(new_data[i][j].d[m][n].f, new_data[i][j].d[m][n].f))) { d_failed = 1; goto out; } @@ -3879,7 +3920,7 @@ out: if(((unsigned)new_data[i][j].a.i & i_mask) != ((unsigned)orig_data[i][j].a.i & i_mask)|| ((unsigned)new_data[i][j].a.c & c_mask) != ((unsigned)orig_data[i][j].a.c & c_mask)|| ((unsigned)new_data[i][j].a.s & s_mask) != ((unsigned)orig_data[i][j].a.s & s_mask)|| - (new_data[i][j].a.f == new_data[i][j].a.f && !H5_FLT_ABS_EQUAL(new_data[i][j].a.f, new_data[i][j].a.f)) || + (!HDisnan(new_data[i][j].a.f) && !H5_FLT_ABS_EQUAL(new_data[i][j].a.f, new_data[i][j].a.f)) || new_data[i][j].v != orig_data[i][j].v || b_failed || d_failed) { H5_FAILED(); HDprintf(" Read different values than written.\n"); @@ -4135,149 +4176,164 @@ test_nbit_int_size(hid_t file) hid_t dataspace, dataset, datatype, mem_datatype, dset_create_props; hsize_t dims[2], chunk_size[2]; hsize_t dset_size = 0; - int orig_data[DSET_DIM1][DSET_DIM2]; + int **orig = NULL; + int *orig_data = NULL; double power; int i, j; size_t precision, offset; TESTING(" nbit integer dataset size"); - /* Define dataset datatype (integer), and set precision, offset */ - if((datatype = H5Tcopy(H5T_NATIVE_INT)) < 0) { - H5_FAILED(); - HDprintf(" line %d: H5Tcopy failed\n",__LINE__); - goto error; - } /* end if */ + /* Set up data array */ + if(NULL == (orig_data = (int *)HDcalloc(DSET_DIM1 * DSET_DIM2, sizeof(int)))) + TEST_ERROR; + if(NULL == (orig = (int **)HDcalloc(DSET_DIM1, sizeof(orig_data)))) + TEST_ERROR; + for (i = 0; i < DSET_DIM1; i++) + orig[i] = orig_data + (i * DSET_DIM2); - precision = 16; /* precision includes sign bit */ - if(H5Tset_precision(datatype,precision)<0) { - H5_FAILED(); - HDprintf(" line %d: H5Pset_precision failed\n",__LINE__); - goto error; - } /* end if */ + /* Define dataset datatype (integer), and set precision, offset */ + if((datatype = H5Tcopy(H5T_NATIVE_INT)) < 0) { + H5_FAILED(); + HDprintf(" line %d: H5Tcopy failed\n",__LINE__); + goto error; + } - offset = 8; - if(H5Tset_offset(datatype,offset)<0) { - H5_FAILED(); - HDprintf(" line %d: H5Tset_offset failed\n",__LINE__); - goto error; - } /* end if */ + precision = 16; /* precision includes sign bit */ + if(H5Tset_precision(datatype,precision)<0) { + H5_FAILED(); + HDprintf(" line %d: H5Pset_precision failed\n",__LINE__); + goto error; + } - /* Copy to memory datatype */ - if((mem_datatype = H5Tcopy(datatype)) < 0) { - H5_FAILED(); - HDprintf(" line %d: H5Tcopy failed\n",__LINE__); - goto error; - } /* end if */ + offset = 8; + if(H5Tset_offset(datatype,offset)<0) { + H5_FAILED(); + HDprintf(" line %d: H5Tset_offset failed\n",__LINE__); + goto error; + } - /* Set order of dataset datatype */ - if(H5Tset_order(datatype, H5T_ORDER_BE)<0) { + /* Copy to memory datatype */ + if((mem_datatype = H5Tcopy(datatype)) < 0) { H5_FAILED(); - HDprintf(" line %d: H5Pset_order failed\n",__LINE__); - goto error; - } /* end if */ + HDprintf(" line %d: H5Tcopy failed\n",__LINE__); + goto error; + } - if(H5Tset_size(datatype, 4)<0) { - H5_FAILED(); - HDprintf(" line %d: H5Pset_size failed\n",__LINE__); - goto error; - } /* end if */ + /* Set order of dataset datatype */ + if(H5Tset_order(datatype, H5T_ORDER_BE)<0) { + H5_FAILED(); + HDprintf(" line %d: H5Pset_order failed\n",__LINE__); + goto error; + } - /* Initiliaze data buffer with random data within correct range - * corresponding to the memory datatype's precision and offset. - */ - for (i=0; i < DSET_DIM1; i++) - for (j=0; j < DSET_DIM2; j++) { - power = HDpow(2.0F, (double)(precision-1)); - orig_data[i][j] = HDrandom() % (int)power << offset; - } /* end for */ + if(H5Tset_size(datatype, 4)<0) { + H5_FAILED(); + HDprintf(" line %d: H5Pset_size failed\n",__LINE__); + goto error; + } + /* Initiliaze data buffer with random data within correct range + * corresponding to the memory datatype's precision and offset. + */ + for (i=0; i < DSET_DIM1; i++) + for (j=0; j < DSET_DIM2; j++) { + power = HDpow(2.0F, (double)(precision-1)); + orig[i][j] = HDrandom() % (int)power << offset; + } - /* Describe the dataspace. */ - dims[0] = DSET_DIM1; - dims[1] = DSET_DIM2; - if((dataspace = H5Screate_simple (2, dims, NULL))<0) { - H5_FAILED(); - HDprintf(" line %d: H5Pcreate failed\n",__LINE__); - goto error; - } /* end if */ - /* - * Set the dataset creation property list to specify the chunks - */ - chunk_size[0] = DSET_DIM1/10; - chunk_size[1] = DSET_DIM2/10; - if((dset_create_props = H5Pcreate (H5P_DATASET_CREATE))<0) { - H5_FAILED(); - HDprintf(" line %d: H5Pcreate failed\n",__LINE__); - goto error; - } /* end if */ + /* Describe the dataspace. */ + dims[0] = DSET_DIM1; + dims[1] = DSET_DIM2; + if((dataspace = H5Screate_simple(2, dims, NULL))<0) { + H5_FAILED(); + HDprintf(" line %d: H5Pcreate failed\n",__LINE__); + goto error; + } - if(H5Pset_chunk (dset_create_props, 2, chunk_size)<0) { - H5_FAILED(); - HDprintf(" line %d: H5Pset_chunk failed\n",__LINE__); - goto error; - } /* end if */ + /* + * Set the dataset creation property list to specify the chunks + */ + chunk_size[0] = DSET_DIM1/10; + chunk_size[1] = DSET_DIM2/10; + if((dset_create_props = H5Pcreate(H5P_DATASET_CREATE))<0) { + H5_FAILED(); + HDprintf(" line %d: H5Pcreate failed\n",__LINE__); + goto error; + } - /* - * Set for n-bit compression - */ - if(H5Pset_nbit (dset_create_props)<0) { - H5_FAILED(); - HDprintf(" line %d: H5Pset_nbit failed\n",__LINE__); - goto error; - } /* end if */ + if(H5Pset_chunk(dset_create_props, 2, chunk_size)<0) { + H5_FAILED(); + HDprintf(" line %d: H5Pset_chunk failed\n",__LINE__); + goto error; + } - /* - * Create a new dataset within the file. - */ - if((dataset = H5Dcreate2 (file, DSET_NBIT_INT_SIZE_NAME, datatype, + /* + * Set for n-bit compression + */ + if(H5Pset_nbit(dset_create_props)<0) { + H5_FAILED(); + HDprintf(" line %d: H5Pset_nbit failed\n",__LINE__); + goto error; + } + + /* + * Create a new dataset within the file. + */ + if((dataset = H5Dcreate2(file, DSET_NBIT_INT_SIZE_NAME, datatype, dataspace, H5P_DEFAULT, dset_create_props, H5P_DEFAULT))<0) { - H5_FAILED(); - HDprintf(" line %d: H5dwrite failed\n",__LINE__); - goto error; - } /* end if */ + H5_FAILED(); + HDprintf(" line %d: H5dwrite failed\n",__LINE__); + goto error; + } - /* - * Write the array to the file. - */ - if(H5Dwrite (dataset, mem_datatype, H5S_ALL, H5S_ALL, - H5P_DEFAULT, orig_data)<0) { - H5_FAILED(); - HDprintf(" Line %d: H5Dwrite failed\n",__LINE__); - goto error; - } /* end if */ + /* + * Write the array to the file. + */ + if(H5Dwrite(dataset, mem_datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, orig_data)<0) { + H5_FAILED(); + HDprintf(" Line %d: H5Dwrite failed\n",__LINE__); + goto error; + } - /* - * Get the precision of the data type - */ - if((precision = H5Tget_precision(datatype)) == 0) { - H5_FAILED(); - HDprintf(" Line %d: wrong precision size: %zu\n",__LINE__, precision); - goto error; - } /* end if */ + /* + * Get the precision of the data type + */ + if((precision = H5Tget_precision(datatype)) == 0) { + H5_FAILED(); + HDprintf(" Line %d: wrong precision size: %zu\n",__LINE__, precision); + goto error; + } - /* - * The size of the dataset after compression should around 2 * DSET_DIM1 * DSET_DIM2 - */ - if((dset_size = H5Dget_storage_size(dataset)) < DSET_DIM1*DSET_DIM2*(precision/8) || - dset_size > DSET_DIM1*DSET_DIM2*(precision/8) + 1*KB) { - H5_FAILED(); - HDfprintf(stdout, " Line %d: wrong dataset size: %Hu\n",__LINE__, dset_size); - goto error; - } /* end if */ + /* + * The size of the dataset after compression should around 2 * DSET_DIM1 * DSET_DIM2 + */ + if((dset_size = H5Dget_storage_size(dataset)) < DSET_DIM1*DSET_DIM2*(precision/8) || + dset_size > DSET_DIM1*DSET_DIM2*(precision/8) + 1*KB) { + H5_FAILED(); + HDfprintf(stdout, " Line %d: wrong dataset size: %Hu\n",__LINE__, dset_size); + goto error; + } - H5Tclose (datatype); - H5Tclose (mem_datatype); - H5Dclose (dataset); - H5Sclose (dataspace); - H5Pclose (dset_create_props); + H5Tclose(datatype); + H5Tclose(mem_datatype); + H5Dclose(dataset); + H5Sclose(dataspace); + H5Pclose(dset_create_props); + + HDfree(orig); + HDfree(orig_data); PASSED(); - return SUCCEED; + return SUCCEED; + error: + HDfree(orig); + HDfree(orig_data); + return FAIL; } /* end test_nbit_int_size() */ @@ -4303,13 +4359,22 @@ test_nbit_flt_size(hid_t file) hid_t dataspace, dataset, datatype, dset_create_props; hsize_t dims[2], chunk_size[2]; hsize_t dset_size = 0; - float orig_data[DSET_DIM1][DSET_DIM2]; + float **orig = NULL; + float *orig_data = NULL; int i, j; size_t precision, offset; size_t spos, epos, esize, mpos, msize; TESTING(" nbit floating-number dataset size"); + /* Set up data array */ + if(NULL == (orig_data = (float *)HDcalloc(DSET_DIM1 * DSET_DIM2, sizeof(float)))) + TEST_ERROR; + if(NULL == (orig = (float **)HDcalloc(DSET_DIM1, sizeof(orig_data)))) + TEST_ERROR; + for (i = 0; i < DSET_DIM1; i++) + orig[i] = orig_data + (i * DSET_DIM2); + /* Define floating-point type for dataset *------------------------------------------------------------------- * size=4 byte, precision=16 bits, offset=8 bits, @@ -4388,7 +4453,7 @@ test_nbit_flt_size(hid_t file) */ for (i=0; i < DSET_DIM1; i++) for (j=0; j < DSET_DIM2; j++) - orig_data[i][j] = (float)(HDrandom() % 1234567) / 2; + orig[i][j] = (float)(HDrandom() % 1234567) / 2; /* Describe the dataspace. */ @@ -5301,7 +5366,7 @@ test_types(hid_t file) (space=H5Screate_simple(1, &nelmts, NULL)) < 0 || (dset=H5Dcreate2(grp, "bitfield_1", type, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto error; - for(i=0; i