diff options
author | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2018-12-15 01:06:25 (GMT) |
---|---|---|
committer | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2018-12-15 01:06:25 (GMT) |
commit | 22bc8ba7bfb2c82b6cea6b5f5d1da2f2119c348b (patch) | |
tree | a15437bcf06df4a5c30b924fbcd7be135c992037 /test | |
parent | 1cffc3ff0f3454fedf6edcdb93dcde5ed1b910d6 (diff) | |
download | hdf5-22bc8ba7bfb2c82b6cea6b5f5d1da2f2119c348b.zip hdf5-22bc8ba7bfb2c82b6cea6b5f5d1da2f2119c348b.tar.gz hdf5-22bc8ba7bfb2c82b6cea6b5f5d1da2f2119c348b.tar.bz2 |
Addressed HDFFV-10661
Description:
- Fixed a bug triggered by tests in chunk_info.c. The returned value
from a callback function was not checked in H5EA_iterate(), H5FA_iterate(),
and H5D__none_idx_iterate(). This oversight caused a callback function
to continue iterating even though it's supposed to stop. Vailin confirmed.
- Addressed review comments and made various improvements on the tests.
Platforms tested:
Linux/64 (jelly)
Linux/64 (platypus)
Darwin (osx1010test)
Diffstat (limited to 'test')
-rw-r--r-- | test/chunk_info.c | 1531 |
1 files changed, 1356 insertions, 175 deletions
diff --git a/test/chunk_info.c b/test/chunk_info.c index 9c84953..f5a6fdc 100644 --- a/test/chunk_info.c +++ b/test/chunk_info.c @@ -16,29 +16,63 @@ * April 7, 2008 * * Purpose: Tests chunk query API functions + * + * Modification: + * Many tests were added for HDFFV-10615. -BMR, October 2018 + * + * Test structure: + * main() + * test_get_chunk_info_highest18() + * test_get_chunk_info_110() + * test_chunk_info_single_chunk() + * test_chunk_info_implicit() + * test_chunk_info_fixed_array() + * test_chunk_info_extensible_array() + * test_chunk_info_version2_btrees() + * */ +#define H5D_FRIEND +#define H5D_TESTING /* to use H5D__ functions */ +#include "H5Dpkg.h" -#include "h5test.h" +#include "testhdf5.h" - /* #define PRINT_DATA - */ -#define H5FILE_NAME "chunk_info.h5" +/* Test file names */ +const char *FILENAME[] = { + "tchunk_info_18", + "tchunk_info_110", + "chunk_info", + NULL +}; + +/* From original test */ #define DATASETNAME "2d" -#define RANK 2 -#define FILENAME_BUF_SIZE 1024 /* Parameters for testing chunk querying */ -#define FILENAME "tchunk_info" +#define RANK 2 +#define FILENAME_BUF_SIZE 1024 #define DSET_SIMPLE_CHUNKED "Chunked Dataset" #define DSET_EMPTY "Empty Dataset" -#define NX 16 -#define NY 16 -#define CHUNK_NX 4 -#define CHUNK_NY 4 -#define CHUNK_SIZE 64 -#define NUM_CHUNKS_WRITTEN 4 - -void reinit_vars(unsigned *read_filter_mask, haddr_t *addr, hsize_t *size); +#define DSET_EMPTY_ALLOC "Empty Dataset with ALLOC_TIME_EARLY" +#define DSET_SINGLE_CHUNK "Single Chunk Index Dataset" +#define DSET_IMPLICIT_INDEX "Implicit Index Dataset" +#define DSET_FIXED_ARR_INDEX "Fixed Array Index Dataset" +#define DSET_EXT_ARR_INDEX "Extensible Array Index Dataset" +#define DSET_V2_BTREE_INDEX "Version 2 B-Tree Index Dataset" +#define NX 24 +#define NY 16 +#define CHUNK_NX 6 +#define CHUNK_NY 4 +#define SINGLE_CHUNK_SIZE (NX*NY*sizeof(int)) +#define CHUNK_SIZE 96 +#define NUM_CHUNKS 16 +#define NUM_CHUNKS_WRITTEN 4 + +/* Artifact of original file, maybe removed */ +/* #define PRINT_DATA */ + +/* Utility function to initialize arguments */ +void reinit_vars(unsigned *read_flt_msk, haddr_t *addr, hsize_t *size); /*------------------------------------------------------------------------- * Function: read_each_chunk (helper function) @@ -54,21 +88,23 @@ void reinit_vars(unsigned *read_filter_mask, haddr_t *addr, hsize_t *size); * *------------------------------------------------------------------------- */ +//EIP - May be this function should take a pointer to an array of chunk dimensions +//EIP and its size, so it is not restricted to 2 dims only? static herr_t read_each_chunk(hid_t dset_id, hsize_t offset1, hsize_t offset2, void *direct_buf) { int read_buf[CHUNK_NX][CHUNK_NY]; hsize_t offset[2] = {offset1, offset2}; - unsigned read_filter_mask = 0; + unsigned read_flt_msk = 0; + herr_t ret; /* Return value */ - /* Read the raw chunk back */ HDmemset(&read_buf, 0, sizeof(read_buf)); /* Read the chunk specified by its offset */ - if (H5Dread_chunk(dset_id, H5P_DEFAULT, offset, &read_filter_mask, read_buf) < 0) - return(FAIL); + ret = H5Dread_chunk(dset_id, H5P_DEFAULT, offset, &read_flt_msk, read_buf); + if(ret < 0) return(FAIL); /* Verify that read chunk is the same as the corresponding written one */ - if (HDmemcmp(direct_buf, read_buf, CHUNK_NX*CHUNK_NY) != 0) + if(HDmemcmp(direct_buf, read_buf, CHUNK_NX*CHUNK_NY) != 0) { HDfprintf(stderr, "Read chunk differs from written chunk at offset (%d,%d)\n", offset1, offset2); return(FAIL); @@ -89,18 +125,18 @@ static herr_t read_each_chunk(hid_t dset_id, hsize_t offset1, hsize_t offset2, v * *------------------------------------------------------------------------- */ -void reinit_vars(unsigned *read_filter_mask, haddr_t *addr, hsize_t *size) +void reinit_vars(unsigned *read_flt_msk, haddr_t *addr, hsize_t *size) { - if (read_filter_mask) - *read_filter_mask = 0; - if (addr) + if(read_flt_msk) + *read_flt_msk = 0; + if(addr) *addr = 0; - if (size) + if(size) *size = 0; } /*------------------------------------------------------------------------- - * Function: test_get_chunk_info + * Function: test_get_chunk_info_highest18 * * Purpose: Test getting various chunk information * @@ -112,226 +148,1277 @@ void reinit_vars(unsigned *read_filter_mask, haddr_t *addr, hsize_t *size) * will be implemented in the next version. * * Description: - * This function tests the new API functions added for HDFFV-10615: - * H5Dget_num_chunks, H5Dget_chunk_info, and H5Dget_chunk_info_by_coord. + * This function tests the new API functions added for EED-343: + * H5Dget_num_chunks, H5Dget_chunk_info, and + * H5Dget_chunk_info_by_coord for high bound up to 1.8. * * Date: September 2018 * *------------------------------------------------------------------------- */ static herr_t -test_get_chunk_info(void) +test_get_chunk_info_highest18(hid_t fapl) { - hid_t chunkfile = -1, fapl = -1; - hid_t fspace = -1, dset = -1; - hid_t mspace = -1; - hid_t cparms = -1, dxpl = -1; - hsize_t dims[2] = {NX, NY}; - hsize_t maxdims[2] = {H5S_UNLIMITED, H5S_UNLIMITED}; - hsize_t chunk_dims[2] ={CHUNK_NX, CHUNK_NY}; - int fillvalue = -1; - char filename[FILENAME_BUF_SIZE]; - unsigned filter_mask = 0; - int direct_buf[16][CHUNK_NX][CHUNK_NY]; - int out_buf[NX][NY]; - size_t buf_size = CHUNK_NX*CHUNK_NY*sizeof(int); - int aggression = 9; /* Compression aggression setting */ - unsigned read_filter_mask = 0; /* filter mask after direct read */ - H5F_libver_t low, high; /* File format bounds */ - hsize_t offset[2]; - hsize_t out_offset[2] = {0, 0}; - hsize_t size = 0; - hsize_t nchunks = 0; - haddr_t addr = 0; - hsize_t index = 0; - hsize_t i, j; - int n; /* for use on buffer, to avoid conversion warning */ + char filename[FILENAME_BUF_SIZE]; + hid_t chunkfile = -1; /* File ID */ + hid_t dspace = -1; /* Dataspace ID */ + hid_t dset = -1; /* Dataset ID */ + hid_t cparms = -1; /* Creation plist */ + hsize_t dims[2] = {NX, NY};/* Dataset dimensions */ + hsize_t maxdims[2] = {H5S_UNLIMITED, H5S_UNLIMITED}; + hsize_t chunk_dims[2] = {CHUNK_NX, CHUNK_NY}; /* Chunk dimensions */ + int direct_buf[NUM_CHUNKS][CHUNK_NX][CHUNK_NY];/* Data in chunks */ + int out_buf[NX][NY]; /* Buffer to read data in */ + size_t buf_size = CHUNK_NX*CHUNK_NY*sizeof(int); /* Buffer size of a chk */ + unsigned filter_mask = 0; /* Filter mask */ + unsigned read_flt_msk = 0; /* Filter mask after direct read */ + int fillvalue = -1; /* Fill value */ + int aggression = 9; /* Compression aggression setting */ + H5F_libver_t low, high; /* File format bounds */ + hsize_t offset[2]; /* Offset coordinates of a chunk */ + hsize_t out_offset[2] = {0, 0}; /* Buffer to get offset coordinates */ + hsize_t size = 0; /* Size of an allocated/written chunk */ + hsize_t nchunks = 0; /* Number of chunks */ + haddr_t addr = 0; /* Address of an allocated/written chunk */ + hsize_t index = 0; /* Index of a chunk */ + int n; /* Used on buffer, to avoid conversion warning */ + hsize_t i, j; + herr_t ret; + + TESTING("getting chunk information in file with version prior to 1.10"); + + /* Create the file */ + h5_fixname(FILENAME[0], fapl, filename, sizeof filename); + + /* Set high bound to V18 to test chunked dataset that use B-tree v1 + structures to index chunks */ + high = H5F_LIBVER_V18; + + /* Low bound can be anything below 1.10, which was when the new chunk storage + was introduced */ + low = H5F_LIBVER_EARLIEST; + + /* Set version bounds for creating the file */ + if(H5Pset_libver_bounds(fapl, low, high) < 0) + TEST_ERROR + + chunkfile = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl); + if(chunkfile < 0) + TEST_ERROR + + /* Create the file and memory dataspaces */ + if((dspace = H5Screate_simple(RANK, dims, maxdims)) < 0) + TEST_ERROR + + /* Set dset creation properties with chunking, compression, and fillvalue */ + if((cparms = H5Pcreate(H5P_DATASET_CREATE)) < 0) TEST_ERROR + if(H5Pset_chunk(cparms, RANK, chunk_dims) < 0) TEST_ERROR + +#ifdef H5_HAVE_FILTER_DEFLATE + if(H5Pset_deflate(cparms, (unsigned)aggression) < 0) TEST_ERROR +#endif /* end H5_HAVE_FILTER_DEFLATE */ + + /* Set fill value */ + if(H5Pset_fill_value(cparms, H5T_NATIVE_INT, &fillvalue) < 0) TEST_ERROR + + /* Create a new dataset using cparms creation properties */ + dset = H5Dcreate2(chunkfile, DSET_SIMPLE_CHUNKED, H5T_NATIVE_INT, dspace, H5P_DEFAULT, cparms, H5P_DEFAULT); + if(dset < 0) TEST_ERROR + + /* Indicate skipping the compression filter */ + filter_mask = 0x00000001; + + /* Initialize the array of chunk data for all NUM_CHUNKS chunks */ + for(n = 0; n < NUM_CHUNKS; n++) + for(i = 0; i < CHUNK_NX; i++) + for(j = 0; j < CHUNK_NY; j++) + direct_buf[n][i][j] = n + 1; + + /* Write only NUM_CHUNKS_WRITTEN chunks at the following logical coords: + (0,2) (0,3) (1,2) (1,3) */ + n = 0; + for (i = 0; i < 2; i++) + for (j = 2; j < 4; j++, n++) + { + offset[0] = i * CHUNK_NX; + offset[1] = j * CHUNK_NY; + ret = H5Dwrite_chunk(dset, H5P_DEFAULT, filter_mask, offset, buf_size, (void*)direct_buf[n]); + if(ret < 0) TEST_ERROR + } + + if(H5Fflush(dset, H5F_SCOPE_LOCAL) < 0) + goto error; + + /* Close the dataset then... */ + if(H5Dclose(dset) < 0) TEST_ERROR + + /* ...open it again to test the chunk query functions */ + if((dset = H5Dopen2(chunkfile, DSET_SIMPLE_CHUNKED, H5P_DEFAULT)) < 0) + TEST_ERROR + + /* Get and verify the number of chunks written */ + if(H5Dget_num_chunks(dset, dspace, &nchunks) < 0) TEST_ERROR + if(nchunks != NUM_CHUNKS_WRITTEN) TEST_ERROR + + /* Read the entire dataset back */ + ret = H5Dread(dset, H5T_NATIVE_INT, dspace, dspace, H5P_DEFAULT, out_buf); + if(ret < 0) TEST_ERROR + + /* Get and verify info of the first chunk */ + index = 0; + reinit_vars(&read_flt_msk, &addr, &size); + out_offset[0] = out_offset[1] = 0; + ret = H5Dget_chunk_info(dset, dspace, index, out_offset, &read_flt_msk, &addr, &size); + if(ret < 0) TEST_ERROR + if(read_flt_msk != filter_mask) TEST_ERROR + if(size != CHUNK_SIZE) TEST_ERROR + if(out_offset[0] != 0 || out_offset[1] != 8) TEST_ERROR + + /* Get and verify info of the second chunk */ + index = 1; + reinit_vars(&read_flt_msk, &addr, &size); + out_offset[0] = out_offset[1] = 0; + ret = H5Dget_chunk_info(dset, dspace, index, out_offset, &read_flt_msk, &addr, &size); + if(ret < 0) TEST_ERROR + if(read_flt_msk != filter_mask) TEST_ERROR + if(size != CHUNK_SIZE) TEST_ERROR + if(out_offset[0] != 0 || out_offset[1] != 12) TEST_ERROR + + /* Get and verify info of the third chunk */ + index = 2; + reinit_vars(&read_flt_msk, &addr, &size); + out_offset[0] = out_offset[1] = 0; + ret = H5Dget_chunk_info(dset, dspace, index, out_offset, &read_flt_msk, &addr, &size); + if(ret < 0) TEST_ERROR + + if(read_flt_msk != filter_mask) TEST_ERROR + if(size != CHUNK_SIZE) TEST_ERROR + if(out_offset[0] != 6 || out_offset[1] != 8) TEST_ERROR + + /* Get and verify info of the last chunk */ + index = 3; + reinit_vars(&read_flt_msk, &addr, &size); + out_offset[0] = out_offset[1] = 0; + ret = H5Dget_chunk_info(dset, dspace, index, out_offset, &read_flt_msk, &addr, &size); + if(ret < 0) TEST_ERROR + if(read_flt_msk != filter_mask) TEST_ERROR + if(size != CHUNK_SIZE) TEST_ERROR + if(out_offset[0] != 6 || out_offset[1] != 12) TEST_ERROR + + /* Attempt to get info of empty chunk and verify the returned address and size */ + index = 5; + reinit_vars(&read_flt_msk, &addr, &size); + out_offset[0] = out_offset[1] = 0; + ret = H5Dget_chunk_info(dset, dspace, index, out_offset, &read_flt_msk, &addr, &size); + if(ret < 0) TEST_ERROR + if(addr != HADDR_UNDEF) TEST_ERROR + if(size != 0) TEST_ERROR + + /* Get info of the chunk at logical coordinates (0,2) */ + offset[0] = 0; + offset[1] = 2 * CHUNK_NY; + ret = H5Dget_chunk_info_by_coord(dset, offset, &read_flt_msk, &addr, &size); + if(ret < 0) TEST_ERROR + if(read_flt_msk != filter_mask) TEST_ERROR + if(size != CHUNK_SIZE) TEST_ERROR + + /* Get info of the chunk at logical coordinates (1,3) */ + offset[0] = 1 * CHUNK_NX; + offset[1] = 3 * CHUNK_NY; + ret = H5Dget_chunk_info_by_coord(dset, offset, &read_flt_msk, &addr, &size); + if(ret < 0) TEST_ERROR + if(read_flt_msk != filter_mask) TEST_ERROR + if(size != CHUNK_SIZE) TEST_ERROR + + /* Attempt to get info of empty chunks, verify the returned addr and size */ + offset[0] = 0; + offset[1] = 0; + ret = H5Dget_chunk_info_by_coord(dset, offset, &read_flt_msk, &addr, &size); + if(ret < 0) TEST_ERROR + if(addr != HADDR_UNDEF) TEST_ERROR + if(size != 0) TEST_ERROR - TESTING("getting chunk information"); + offset[0] = 3 * CHUNK_NX; + offset[1] = 3 * CHUNK_NY; + ret = H5Dget_chunk_info_by_coord(dset, offset, &read_flt_msk, &addr, &size); + if(ret < 0) TEST_ERROR + if(addr != HADDR_UNDEF) TEST_ERROR + if(size != 0) TEST_ERROR + + /* Read each chunk and verify the values */ + n = 0; + for (i = 0; i < 2; i++) + for (j = 2; j < 4; j++, n++) + if(read_each_chunk(dset, i*CHUNK_NX, j*CHUNK_NY, (void*)direct_buf[n]) < 0) + TEST_ERROR + + /* Close the first dataset */ + if(H5Dclose(dset) < 0) TEST_ERROR + + /* Create an empty dataset and close it */ + dset = H5Dcreate2(chunkfile, DSET_EMPTY, H5T_NATIVE_INT, dspace, H5P_DEFAULT, cparms, H5P_DEFAULT); + if(dset < 0) TEST_ERROR + if(H5Dclose(dset) < 0) TEST_ERROR + + /* Reopen the empty dataset to verify the chunk query functions on it */ + if((dset = H5Dopen2(chunkfile, DSET_EMPTY, H5P_DEFAULT)) < 0) + TEST_ERROR + + /* Verify that the number of chunks is 0 */ + if(H5Dget_num_chunks(dset, dspace, &nchunks) < 0) TEST_ERROR + if(nchunks != 0) TEST_ERROR - /* Create a file */ - h5_fixname(FILENAME, H5P_DEFAULT, filename, sizeof filename); - if((chunkfile = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) + /* Attempt to get info of a chunk from an empty dataset, verify the + returned address and size */ + index = 0; + reinit_vars(&read_flt_msk, &addr, &size); + ret = H5Dget_chunk_info(dset, dspace, index, out_offset, &read_flt_msk, &addr, &size); + if(ret < 0) TEST_ERROR + if(addr != HADDR_UNDEF) TEST_ERROR + if(size != 0) TEST_ERROR + + /* Attempt to get info of a chunk given its coords from an empty dataset, + verify the returned address and size */ + offset[0] = 0; + offset[1] = 0; + ret = H5Dget_chunk_info_by_coord(dset, offset, &read_flt_msk, &addr, &size); + if(ret < 0) TEST_ERROR + if(addr != HADDR_UNDEF) TEST_ERROR + if(size != 0) TEST_ERROR + + if(H5Dclose(dset) < 0) TEST_ERROR + + /************************************************************************ + * Test empty dataset with H5P_ALLOC_TIME_EARLY * + ************************************************************************/ + + /* Set space allocation to early so that chunk query functions will + retrieve chunk information even though the dataset is empty */ + if(H5Pset_alloc_time(cparms, H5D_ALLOC_TIME_EARLY) < 0) TEST_ERROR - /* Create the data space */ - if((fspace = H5Screate_simple(RANK, dims, maxdims)) < 0) + /* Create an empty dataset and close it */ + dset = H5Dcreate2(chunkfile, DSET_EMPTY_ALLOC, H5T_NATIVE_INT, dspace, H5P_DEFAULT, cparms, H5P_DEFAULT); + if(dset < 0) TEST_ERROR + if(H5Dclose(dset) < 0) TEST_ERROR + + /* Reopen the empty dataset to verify the chunk query functions on it */ + if((dset = H5Dopen2(chunkfile, DSET_EMPTY_ALLOC, H5P_DEFAULT)) < 0) + TEST_ERROR + + /* Verify that the number of chunks is NUM_CHUNKS */ + if(H5Dget_num_chunks(dset, dspace, &nchunks) < 0) TEST_ERROR + if(nchunks != NUM_CHUNKS) TEST_ERROR + + /* Attempt to get info of a chunk from an empty dataset, verify the + returned address and size */ + index = 0; + reinit_vars(&read_flt_msk, &addr, &size); + ret = H5Dget_chunk_info(dset, dspace, index, out_offset, &read_flt_msk, &addr, &size); + if(ret < 0) TEST_ERROR + + /* Because of H5P_ALLOC_TIME_EARLY, addr cannot be HADDR_UNDEF and size not 0 */ + if(addr == HADDR_UNDEF) TEST_ERROR + if(size == 0) TEST_ERROR + + index = 10; + reinit_vars(&read_flt_msk, &addr, &size); + ret = H5Dget_chunk_info(dset, dspace, index, out_offset, &read_flt_msk, &addr, &size); + if(ret < 0) TEST_ERROR + + /* Because of H5P_ALLOC_TIME_EARLY, addr cannot be HADDR_UNDEF and size not 0 */ + if(addr == HADDR_UNDEF) TEST_ERROR + if(size == 0) TEST_ERROR + + /* Attempt to get info of a chunk given its coords from an empty dataset, + verify the returned address and size */ + offset[0] = 0; + offset[1] = 0; + if(H5Dget_chunk_info_by_coord(dset, offset, &read_flt_msk, &addr, &size) < 0) TEST_ERROR + /* Because of H5P_ALLOC_TIME_EARLY, addr cannot be HADDR_UNDEF and size not 0 */ + if(addr == HADDR_UNDEF) TEST_ERROR + if(size == 0) TEST_ERROR + + if(H5Dclose(dset) < 0) TEST_ERROR + + /* Close/release resources. */ + if(H5Sclose(dspace) < 0) TEST_ERROR + if(H5Pclose(cparms) < 0) TEST_ERROR + if(H5Fclose(chunkfile) < 0) TEST_ERROR + + PASSED(); + return SUCCEED; - if((mspace = H5Screate_simple(RANK, chunk_dims, NULL)) < 0) +error: + H5E_BEGIN_TRY { + H5Dclose(dset); + H5Sclose(dspace); + H5Pclose(cparms); + H5Fclose(chunkfile); + } H5E_END_TRY; + + H5_FAILED(); + return FAIL; +} /* test_get_chunk_info_highest18() */ + +/*------------------------------------------------------------------------- + * Function: test_chunk_info_single_chunk + * + * Purpose: Test getting various chunk information when Single Chunk + * index type is used + * + * Return: Success: SUCCEED + * Failure: FAIL + * + * Note: Note that the dataspace argument in these new functions are + * currently not used. The functionality involved the dataspace + * will be implemented in the next version. + * + * Date: November 2018 + * + *------------------------------------------------------------------------- + */ +static herr_t +test_chunk_info_single_chunk(char *filename, hid_t fapl) +{ + hid_t chunkfile = -1; /* File ID */ + hid_t dspace = -1; /* Dataspace ID */ + hid_t dset = -1; /* Dataset ID */ + hid_t cparms = -1; /* Creation plist */ + hsize_t dims[2] = {NX, NY};/* Dataset dimensions */ + hsize_t chunk_dims[2] = {NX, NY}; /* Chunk dimensions */ + int in_buf[NX][NY]; /* Input buffer */ + unsigned filter_mask = 0; /* Filter mask */ + unsigned read_flt_msk = 0; /* Filter mask after direct read */ + H5D_chunk_index_t idx_type; /* Dataset chunk index type */ + hsize_t offset[2]; /* Offset coordinates of a chunk */ + hsize_t out_offset[2] = {0, 0}; /* Buffer to get offset coordinates */ + hsize_t size = 0; /* Size of an allocated/written chunk */ + hsize_t nchunks = 0; /* Number of chunks */ + haddr_t addr = 0; /* Address of an allocated/written chunk */ + hsize_t index = 0; /* Index of a chunk */ + int i, j; + + TESTING(" Single Chunk index"); + + /* Open the file for reading/writing */ + if((chunkfile = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0) + TEST_ERROR + + /* Create dataspace */ + if((dspace = H5Screate_simple(RANK, dims, NULL)) < 0) TEST_ERROR - /* Modify dataset creation properties, i.e. enable chunking and compression */ + /* Enable chunking */ if((cparms = H5Pcreate(H5P_DATASET_CREATE)) < 0) TEST_ERROR if(H5Pset_chunk(cparms, RANK, chunk_dims) < 0) TEST_ERROR - if(H5Pset_deflate(cparms, (unsigned ) aggression) < 0) + /* Create a new dataset using cparms creation properties */ + dset = H5Dcreate2(chunkfile, DSET_SINGLE_CHUNK, H5T_NATIVE_INT, dspace, H5P_DEFAULT, cparms, H5P_DEFAULT); + if(dset < 0) TEST_ERROR + + /* Ensure we're using the correct chunk indexing scheme */ + if(H5D__layout_idx_type_test(dset, &idx_type) < 0) + TEST_ERROR + if(idx_type != H5D_CHUNK_IDX_SINGLE) + FAIL_PUTS_ERROR("should be using Single Chunk index type"); + + /* Close the dataset then... */ + if(H5Dclose(dset) < 0) TEST_ERROR + + /* ...open it again to test the chunk query functions on a single empty + chunk */ + if((dset = H5Dopen2(chunkfile, DSET_SINGLE_CHUNK, H5P_DEFAULT)) < 0) + TEST_ERROR + + /* Get the number of chunks and verify that no chunk has been written */ + if(H5Dget_num_chunks(dset, dspace, &nchunks) < 0) TEST_ERROR + if(nchunks != 0) TEST_ERROR + + /* Initialize the array of chunk data for the single chunk */ + for(i = 0; i < NX; i++) + for(j = 0; j < NY; j++) + in_buf[i][j] = (i*j); + + /* Write the chunk */ + if(H5Dwrite(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, in_buf) < 0) + TEST_ERROR + + /* Get and verify that one chunk had been written */ + if(H5Dget_num_chunks(dset, dspace, &nchunks) < 0) TEST_ERROR + if(nchunks != 1) TEST_ERROR + + /* Get and verify info of the first and only chunk */ + index = 0; + reinit_vars(&read_flt_msk, &addr, &size); + if(H5Dget_chunk_info(dset, dspace, index, out_offset, &read_flt_msk, &addr, &size) < 0) + TEST_ERROR + if(read_flt_msk != filter_mask) TEST_ERROR + if(size != SINGLE_CHUNK_SIZE) TEST_ERROR + if(out_offset[0] != 0 || out_offset[1] != 0) TEST_ERROR + + /* Get info of the chunk at logical coordinates (0,0) */ + offset[0] = 0; + offset[1] = 0; + if(H5Dget_chunk_info_by_coord(dset, offset, &read_flt_msk, &addr, &size) < 0) + TEST_ERROR + if (read_flt_msk != filter_mask) TEST_ERROR + if (size != SINGLE_CHUNK_SIZE) TEST_ERROR + + /* Release resourse */ + if(H5Dclose(dset) < 0) TEST_ERROR + if(H5Sclose(dspace) < 0) TEST_ERROR + if(H5Fclose(chunkfile) < 0) TEST_ERROR + + PASSED(); + return SUCCEED; + +error: + H5E_BEGIN_TRY { + H5Dclose(dset); + H5Sclose(dspace); + H5Pclose(cparms); + H5Fclose(chunkfile); + } H5E_END_TRY; + + H5_FAILED(); + return FAIL; +} /* test_chunk_info_single_chunk() */ + +/*------------------------------------------------------------------------- + * Function: test_chunk_info_implicit + * + * Purpose: Test getting various chunk information when Implicit + * index type is used + * + * Return: Success: SUCCEED + * Failure: FAIL + * + * Note: Note that the dataspace argument in these new functions are + * currently not used. The functionality involved the dataspace + * will be implemented in the next version. + * + * Date: November 2018 + * + *------------------------------------------------------------------------- + */ +static herr_t +test_chunk_info_implicit(char *filename, hid_t fapl) +{ + hid_t chunkfile = -1; /* File ID */ + hid_t dspace = -1; /* Dataspace ID */ + hid_t dset = -1; /* Dataset ID */ + hid_t cparms = -1; /* Creation plist */ + hsize_t dims[2] = {NX, NY};/* Dataset dimensions */ + hsize_t chunk_dims[2] = {CHUNK_NX, CHUNK_NY}; /* Chunk dimensions */ + int direct_buf[NUM_CHUNKS][CHUNK_NX][CHUNK_NY];/* Data in chunks */ + int out_buf[NX][NY]; /* Buffer to read data in */ + size_t buf_size = CHUNK_NX*CHUNK_NY*sizeof(int); /* Buffer size of a chk */ + unsigned filter_mask = 0; /* Filter mask */ + unsigned read_flt_msk = 0; /* Filter mask after direct read */ + H5D_chunk_index_t idx_type; /* Dataset chunk index type */ + hsize_t offset[2]; /* Offset coordinates of a chunk */ + hsize_t out_offset[2] = {0, 0}; /* Buffer to get offset coordinates */ + hsize_t size = 0; /* Size of an allocated/written chunk */ + hsize_t nchunks = 0; /* Number of chunks */ + haddr_t addr = 0; /* Address of an allocated/written chunk */ + hsize_t index = 0; /* Index of a chunk */ + int n; /* Used on buffer, to avoid conversion warning */ + hsize_t i, j; + herr_t ret; + + TESTING(" Implicit index"); + + /* Open the file for reading/writing */ + if((chunkfile = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0) + TEST_ERROR + + /* Create dataspace */ + if((dspace = H5Screate_simple(RANK, dims, NULL)) < 0) + TEST_ERROR + + /* Enable chunking */ + if((cparms = H5Pcreate(H5P_DATASET_CREATE)) < 0) TEST_ERROR - if (H5Pset_fill_value(cparms, H5T_NATIVE_INT, &fillvalue) < 0) - TEST_ERROR; + if(H5Pset_chunk(cparms, RANK, chunk_dims) < 0) + TEST_ERROR + + if(H5Pset_alloc_time(cparms, H5D_ALLOC_TIME_EARLY) < 0) + TEST_ERROR /* Create a new dataset using cparms creation properties */ - if((dset = H5Dcreate2(chunkfile, DSET_SIMPLE_CHUNKED, H5T_NATIVE_INT, fspace, - H5P_DEFAULT, cparms, H5P_DEFAULT)) < 0) TEST_ERROR + dset = H5Dcreate2(chunkfile, DSET_IMPLICIT_INDEX, H5T_NATIVE_INT, dspace, H5P_DEFAULT, cparms, H5P_DEFAULT); + if(dset < 0) TEST_ERROR - if((dxpl = H5Pcreate(H5P_DATASET_XFER)) < 0) + /* Ensure we're using the correct chunk indexing scheme */ + if(H5D__layout_idx_type_test(dset, &idx_type) < 0) TEST_ERROR + if(idx_type != H5D_CHUNK_IDX_NONE) /* Implicit: No Index */ + FAIL_PUTS_ERROR("should be using Implicit index type"); - /* Indicate skipping the compression filter. */ - filter_mask = 0x00000001; + /* Close the dataset then... */ + if(H5Dclose(dset) < 0) TEST_ERROR + + /* ...open it again to test the chunk query functions */ + if((dset = H5Dopen2(chunkfile, DSET_IMPLICIT_INDEX, H5P_DEFAULT)) < 0) + TEST_ERROR + + /* Get and verify the number of chunks */ + if(H5Dget_num_chunks(dset, dspace, &nchunks) < 0) TEST_ERROR - /* Initialize the array of chunk data, that is for all 16 chunks */ - for(n = 0; n < 16; n++) + /* All chunks because of H5D_ALLOC_TIME_EARLY */ + if(nchunks != NUM_CHUNKS) TEST_ERROR + + /* Initialize the array of chunk data for all NUM_CHUNKS chunks */ + for(n = 0; n < NUM_CHUNKS; n++) for(i = 0; i < CHUNK_NX; i++) for(j = 0; j < CHUNK_NY; j++) direct_buf[n][i][j] = n + 1; - /* Write NUM_CHUNKS_WRITTEN chunks: (0,2) (0,3) (1,2) (1,3) */ + /* Write only NUM_CHUNKS_WRITTEN chunks at the following logical coords: + (0,2) (0,3) (1,2) (1,3) */ n = 0; for (i = 0; i < 2; i++) for (j = 2; j < 4; j++, n++) { offset[0] = i * CHUNK_NX; offset[1] = j * CHUNK_NY; - if (H5Dwrite_chunk(dset, dxpl, filter_mask, offset, buf_size, (void*)direct_buf[n]) < 0) - TEST_ERROR + ret = H5Dwrite_chunk(dset, H5P_DEFAULT, filter_mask, offset, buf_size, (void*)direct_buf[n]); + if(ret < 0) TEST_ERROR } + /* Get and verify the number of chunks written */ + if(H5Dget_num_chunks(dset, dspace, &nchunks) < 0) TEST_ERROR + + /* Should still be all chunks, because of H5D_ALLOC_TIME_EARLY */ + if(nchunks != NUM_CHUNKS) TEST_ERROR + + /* Read the entire dataset back */ + if(H5Dread(dset, H5T_NATIVE_INT, dspace, dspace, H5P_DEFAULT, out_buf) < 0) + TEST_ERROR + + /* Get and verify info of the first chunk */ + index = 0; + reinit_vars(&read_flt_msk, &addr, &size); + out_offset[0] = out_offset[1] = 0; + if(H5Dget_chunk_info(dset, dspace, index, out_offset, &read_flt_msk, &addr, &size) < 0) + TEST_ERROR + if(read_flt_msk != filter_mask) TEST_ERROR + if(size != CHUNK_SIZE) TEST_ERROR + if(out_offset[0] != 0 || out_offset[1] != 0) TEST_ERROR + + /* Get and verify info of the second chunk */ + index = 1; + reinit_vars(&read_flt_msk, &addr, &size); + out_offset[0] = out_offset[1] = 0; + if(H5Dget_chunk_info(dset, dspace, index, out_offset, &read_flt_msk, &addr, &size) < 0) + TEST_ERROR + if(read_flt_msk != filter_mask) TEST_ERROR + if(size != CHUNK_SIZE) TEST_ERROR + if(out_offset[0] != 0 || out_offset[1] != 4) TEST_ERROR + + /* Get and verify info of the third chunk */ + index = 2; + reinit_vars(&read_flt_msk, &addr, &size); + out_offset[0] = out_offset[1] = 0; + if(H5Dget_chunk_info(dset, dspace, index, out_offset, &read_flt_msk, &addr, &size) < 0) + TEST_ERROR + + if(read_flt_msk != filter_mask) TEST_ERROR + if(size != CHUNK_SIZE) TEST_ERROR + if(out_offset[0] != 0 || out_offset[1] != 8) TEST_ERROR + + /* Get and verify info of the last chunk */ + index = 3; + reinit_vars(&read_flt_msk, &addr, &size); + out_offset[0] = out_offset[1] = 0; + if(H5Dget_chunk_info(dset, dspace, index, out_offset, &read_flt_msk, &addr, &size) < 0) + TEST_ERROR + if(read_flt_msk != filter_mask) TEST_ERROR + if(size != CHUNK_SIZE) TEST_ERROR + if(out_offset[0] != 0 || out_offset[1] != 12) TEST_ERROR + + /* Attempt to get info of empty chunk and verify the returned address and size */ + index = 5; + reinit_vars(&read_flt_msk, &addr, &size); + out_offset[0] = out_offset[1] = 0; + if(H5Dget_chunk_info(dset, dspace, index, out_offset, &read_flt_msk, &addr, &size) < 0) + TEST_ERROR + if(addr == HADDR_UNDEF) TEST_ERROR + if(size != CHUNK_SIZE) TEST_ERROR + if(out_offset[0] != 6 || out_offset[1] != 4) TEST_ERROR + + /* Get info of the chunk at logical coordinates (0,2) */ + offset[0] = 0; + offset[1] = 2 * CHUNK_NY; + if(H5Dget_chunk_info_by_coord(dset, offset, &read_flt_msk, &addr, &size) < 0) + TEST_ERROR + if(read_flt_msk != filter_mask) TEST_ERROR + if(size != CHUNK_SIZE) TEST_ERROR + + /* Get info of the chunk at logical coordinates (1,3) */ + offset[0] = 1 * CHUNK_NX; + offset[1] = 3 * CHUNK_NY; + if(H5Dget_chunk_info_by_coord(dset, offset, &read_flt_msk, &addr, &size) < 0) + TEST_ERROR + if(read_flt_msk != filter_mask) TEST_ERROR + + /* Attempt to get info of empty chunks, verify the returned address and size */ + offset[0] = 0; + offset[1] = 0; + if(H5Dget_chunk_info_by_coord(dset, offset, &read_flt_msk, &addr, &size) < 0) + TEST_ERROR + /* Because of H5P_ALLOC_TIME_EARLY, addr cannot be HADDR_UNDEF */ + if(addr == HADDR_UNDEF) TEST_ERROR + if(size != CHUNK_SIZE) TEST_ERROR + + offset[0] = 3 * CHUNK_NX; + offset[1] = 3 * CHUNK_NY; + if(H5Dget_chunk_info_by_coord(dset, offset, &read_flt_msk, &addr, &size) < 0) + TEST_ERROR + /* Because of H5P_ALLOC_TIME_EARLY, addr cannot be HADDR_UNDEF */ + if(addr == HADDR_UNDEF) TEST_ERROR + if(size != CHUNK_SIZE) TEST_ERROR + + /* Read each chunk and verify the values */ + n = 0; + for (i = 0; i < 2; i++) + for (j = 2; j < 4; j++, n++) + if(read_each_chunk(dset, i*CHUNK_NX, j*CHUNK_NY, (void*)direct_buf[n]) < 0) + TEST_ERROR + + /* Release resourse */ + if(H5Dclose(dset) < 0) TEST_ERROR + if(H5Sclose(dspace) < 0) TEST_ERROR + if(H5Fclose(chunkfile) < 0) TEST_ERROR + + PASSED(); + return SUCCEED; + +error: + H5E_BEGIN_TRY { + H5Dclose(dset); + H5Sclose(dspace); + H5Pclose(cparms); + H5Fclose(chunkfile); + } H5E_END_TRY; + + H5_FAILED(); + return FAIL; +} /* test_chunk_info_implicit() */ + +/*------------------------------------------------------------------------- + * Function: test_chunk_info_fixed_array + * + * Purpose: Test getting various chunk information when Fixed Array + * index type is used + * + * Return: Success: SUCCEED + * Failure: FAIL + * + * Note: Note that the dataspace argument in these new functions are + * currently not used. The functionality involved the dataspace + * will be implemented in the next version. + * + * Date: November 2018 + * + *------------------------------------------------------------------------- + */ +static herr_t +test_chunk_info_fixed_array(char *filename, hid_t fapl) +{ + hid_t chunkfile = -1; /* File ID */ + hid_t dspace = -1; /* Dataspace ID */ + hid_t dset = -1; /* Dataset ID */ + hid_t cparms = -1; /* Creation plist */ + hsize_t dims[2] = {NX, NY};/* Dataset dimensions */ + hsize_t chunk_dims[2] = {CHUNK_NX, CHUNK_NY}; /* Chunk dimensions */ + int direct_buf[NUM_CHUNKS][CHUNK_NX][CHUNK_NY];/* Data in chunks */ + int out_buf[NX][NY]; /* Buffer to read data in */ + size_t buf_size = CHUNK_NX*CHUNK_NY*sizeof(int); /* Buffer size of a chk */ + unsigned filter_mask = 0; /* Filter mask */ + unsigned read_flt_msk = 0; /* Filter mask after direct read */ + H5D_chunk_index_t idx_type; /* Dataset chunk index type */ + hsize_t offset[2]; /* Offset coordinates of a chunk */ + hsize_t out_offset[2] = {0, 0}; /* Buffer to get offset coordinates */ + hsize_t size = 0; /* Size of an allocated/written chunk */ + hsize_t nchunks = 0; /* Number of chunks */ + haddr_t addr = 0; /* Address of an allocated/written chunk */ + hsize_t index = 0; /* Index of a chunk */ + int n; /* Used on buffer, to avoid conversion warning */ + hsize_t i, j; + herr_t ret; + + TESTING(" Fixed Array index"); + + /* Open the file for reading/writing */ + if((chunkfile = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0) + TEST_ERROR + + /* Create dataspace */ + if((dspace = H5Screate_simple(RANK, dims, NULL)) < 0) + TEST_ERROR + + /* Enable chunking */ + if((cparms = H5Pcreate(H5P_DATASET_CREATE)) < 0) + TEST_ERROR + + if(H5Pset_chunk(cparms, RANK, chunk_dims) < 0) + TEST_ERROR + + /* Create a new dataset using cparms creation properties */ + dset = H5Dcreate2(chunkfile, DSET_FIXED_ARR_INDEX, H5T_NATIVE_INT, dspace, H5P_DEFAULT, cparms, H5P_DEFAULT); + if(dset < 0) TEST_ERROR + + /* Ensure we're using the correct chunk indexing scheme */ + if(H5D__layout_idx_type_test(dset, &idx_type) < 0) + TEST_ERROR + if(idx_type != H5D_CHUNK_IDX_FARRAY) + FAIL_PUTS_ERROR("should be using Fixed Array index type"); + /* Close the dataset then... */ if(H5Dclose(dset) < 0) TEST_ERROR /* ...open it again to test the chunk query functions */ - if((dset = H5Dopen2(chunkfile, DSET_SIMPLE_CHUNKED, H5P_DEFAULT)) < 0) TEST_ERROR + if((dset = H5Dopen2(chunkfile, DSET_FIXED_ARR_INDEX, H5P_DEFAULT)) < 0) + TEST_ERROR - /* Get and verify the number of chunks written */ - if (H5Dget_num_chunks(dset, mspace, &nchunks) < 0) TEST_ERROR; - if (nchunks != NUM_CHUNKS_WRITTEN) TEST_ERROR; + /* Get the number of chunks and verify that no chunk has been written */ + if(H5Dget_num_chunks(dset, dspace, &nchunks) < 0) TEST_ERROR + if(nchunks != 0) TEST_ERROR + + /* Initialize the array of chunk data for all NUM_CHUNKS chunks */ + for(n = 0; n < NUM_CHUNKS; n++) + for(i = 0; i < CHUNK_NX; i++) + for(j = 0; j < CHUNK_NY; j++) + direct_buf[n][i][j] = n + 1; + + /* Write only NUM_CHUNKS_WRITTEN chunks at the following logical coords: + (0,2) (0,3) (1,2) (1,3) */ + n = 0; + for (i = 0; i < 2; i++) + for (j = 2; j < 4; j++, n++) + { + offset[0] = i * CHUNK_NX; + offset[1] = j * CHUNK_NY; + ret = H5Dwrite_chunk(dset, H5P_DEFAULT, filter_mask, offset, buf_size, (void*)direct_buf[n]); + if(ret < 0) TEST_ERROR + } /* Read the entire dataset back */ - if(H5Dread(dset, H5T_NATIVE_INT, fspace, fspace, H5P_DEFAULT, out_buf) < 0) + if(H5Dread(dset, H5T_NATIVE_INT, dspace, dspace, H5P_DEFAULT, out_buf) < 0) + TEST_ERROR + + /* Get and verify the number of chunks written */ + if(H5Dget_num_chunks(dset, dspace, &nchunks) < 0) TEST_ERROR + if(nchunks != NUM_CHUNKS_WRITTEN) TEST_ERROR + + /* Get and verify info of the first chunk */ + index = 0; + reinit_vars(&read_flt_msk, &addr, &size); + out_offset[0] = out_offset[1] = 0; + if(H5Dget_chunk_info(dset, dspace, index, out_offset, &read_flt_msk, &addr, &size) < 0) + TEST_ERROR + if(read_flt_msk != filter_mask) TEST_ERROR + if(size != CHUNK_SIZE) TEST_ERROR + if(out_offset[0] != 0 || out_offset[1] != 8) TEST_ERROR + + /* Get and verify info of the second chunk */ + index = 1; + reinit_vars(&read_flt_msk, &addr, &size); + out_offset[0] = out_offset[1] = 0; + if(H5Dget_chunk_info(dset, dspace, index, out_offset, &read_flt_msk, &addr, &size) < 0) + TEST_ERROR + if(read_flt_msk != filter_mask) TEST_ERROR + if(size != CHUNK_SIZE) TEST_ERROR + if(out_offset[0] != 0 || out_offset[1] != 12) TEST_ERROR + + /* Get and verify info of the third chunk */ + index = 2; + reinit_vars(&read_flt_msk, &addr, &size); + out_offset[0] = out_offset[1] = 0; + if(H5Dget_chunk_info(dset, dspace, index, out_offset, &read_flt_msk, &addr, &size) < 0) + TEST_ERROR + if(read_flt_msk != filter_mask) TEST_ERROR + if(size != CHUNK_SIZE) TEST_ERROR + if(out_offset[0] != 6 || out_offset[1] != 8) TEST_ERROR + + /* Get and verify info of the last chunk */ + index = 3; + reinit_vars(&read_flt_msk, &addr, &size); + out_offset[0] = out_offset[1] = 0; + if(H5Dget_chunk_info(dset, dspace, index, out_offset, &read_flt_msk, &addr, &size) < 0) + TEST_ERROR + if(read_flt_msk != filter_mask) TEST_ERROR + if(size != CHUNK_SIZE) TEST_ERROR + if(out_offset[0] != 6 || out_offset[1] != 12) TEST_ERROR + + /* Attempt to get info of empty chunk and verify the returned address and size */ + index = 5; + reinit_vars(&read_flt_msk, &addr, &size); + out_offset[0] = out_offset[1] = 0; + if(H5Dget_chunk_info(dset, dspace, index, out_offset, &read_flt_msk, &addr, &size) < 0) + TEST_ERROR + if(addr != HADDR_UNDEF) TEST_ERROR + if(size != 0) TEST_ERROR + + /* Get info of the chunk at logical coordinates (0,2) */ + offset[0] = 0; + offset[1] = 2 * CHUNK_NY; + if(H5Dget_chunk_info_by_coord(dset, offset, &read_flt_msk, &addr, &size) < 0) TEST_ERROR + if(read_flt_msk != filter_mask) TEST_ERROR + if(size != CHUNK_SIZE) TEST_ERROR + + /* Get info of the chunk at logical coordinates (1,3) */ + offset[0] = 1 * CHUNK_NX; + offset[1] = 3 * CHUNK_NY; + if(H5Dget_chunk_info_by_coord(dset, offset, &read_flt_msk, &addr, &size) < 0) TEST_ERROR + if(read_flt_msk != filter_mask) TEST_ERROR + if(size != CHUNK_SIZE) TEST_ERROR + + /* Attempt to get info of empty chunks, verify the returned address and size */ + offset[0] = 0; + offset[1] = 0; + if(H5Dget_chunk_info_by_coord(dset, offset, &read_flt_msk, &addr, &size) < 0) TEST_ERROR + if(addr != HADDR_UNDEF) TEST_ERROR + if(size != 0) TEST_ERROR + + offset[0] = 3 * CHUNK_NX; + offset[1] = 3 * CHUNK_NY; + if(H5Dget_chunk_info_by_coord(dset, offset, &read_flt_msk, &addr, &size) < 0) TEST_ERROR + if(addr != HADDR_UNDEF) TEST_ERROR + if(size != 0) TEST_ERROR + + /* Read each chunk and verify the values */ + n = 0; + for (i = 0; i < 2; i++) + for (j = 2; j < 4; j++, n++) + if(read_each_chunk(dset, i*CHUNK_NX, j*CHUNK_NY, (void*)direct_buf[n]) < 0) + TEST_ERROR + + /* Release resourse */ + if(H5Dclose(dset) < 0) TEST_ERROR + if(H5Sclose(dspace) < 0) TEST_ERROR + if(H5Fclose(chunkfile) < 0) TEST_ERROR + + PASSED(); + return SUCCEED; + +error: + H5E_BEGIN_TRY { + H5Dclose(dset); + H5Sclose(dspace); + H5Pclose(cparms); + H5Fclose(chunkfile); + } H5E_END_TRY; + + H5_FAILED(); + return FAIL; +} /* test_chunk_info_fixed_array() */ + +/*------------------------------------------------------------------------- + * Function: test_chunk_info_extensible_array + * + * Purpose: Test getting various chunk information when Extensible Array + * index type is used + * + * Return: Success: SUCCEED + * Failure: FAIL + * + * Note: Note that the dataspace argument in these new functions are + * currently not used. The functionality involved the dataspace + * will be implemented in the next version. + * + * Date: November 2018 + * + *------------------------------------------------------------------------- + */ +static herr_t +test_chunk_info_extensible_array(char *filename, hid_t fapl) +{ + hid_t chunkfile = -1; /* File ID */ + hid_t dspace = -1; /* Dataspace ID */ + hid_t dset = -1; /* Dataset ID */ + hid_t cparms = -1; /* Creation plist */ + hsize_t dims[2] = {NX, NY};/* Dataset dimensions */ + hsize_t chunk_dims[2] = {CHUNK_NX, CHUNK_NY}; /* Chunk dimensions */ + hsize_t maxdims[2] = {H5S_UNLIMITED, NY}; /* One unlimited dimension */ + int direct_buf[NUM_CHUNKS][CHUNK_NX][CHUNK_NY];/* Data in chunks */ + int out_buf[NX][NY]; /* Buffer to read data in */ + size_t buf_size = CHUNK_NX*CHUNK_NY*sizeof(int); /* Buffer size of a chk */ + unsigned filter_mask = 0; /* Filter mask */ + unsigned read_flt_msk = 0; /* Filter mask after direct read */ + H5D_chunk_index_t idx_type; /* Dataset chunk index type */ + hsize_t offset[2]; /* Offset coordinates of a chunk */ + hsize_t out_offset[2] = {0, 0}; /* Buffer to get offset coordinates */ + hsize_t size = 0; /* Size of an allocated/written chunk */ + hsize_t nchunks = 0; /* Number of chunks */ + haddr_t addr = 0; /* Address of an allocated/written chunk */ + hsize_t index = 0; /* Index of a chunk */ + int n; /* Used on buffer, to avoid conversion warning */ + hsize_t i, j; + herr_t ret; + + TESTING(" Extensible Array index"); + + /* Open the file for reading/writing */ + if((chunkfile = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0) + TEST_ERROR + + /* Create dataspace */ + if((dspace = H5Screate_simple(RANK, dims, maxdims)) < 0) + TEST_ERROR + + /* Enable chunking */ + if((cparms = H5Pcreate(H5P_DATASET_CREATE)) < 0) + TEST_ERROR + + if(H5Pset_chunk(cparms, RANK, chunk_dims) < 0) + TEST_ERROR + + /* Create a new dataset using cparms creation properties */ + dset = H5Dcreate2(chunkfile, DSET_EXT_ARR_INDEX, H5T_NATIVE_INT, dspace, H5P_DEFAULT, cparms, H5P_DEFAULT); + if(dset < 0) TEST_ERROR + + /* Ensure we're using the correct chunk indexing scheme */ + if(H5D__layout_idx_type_test(dset, &idx_type) < 0) TEST_ERROR + if(idx_type != H5D_CHUNK_IDX_EARRAY) + FAIL_PUTS_ERROR("should be using Extensible Array index type"); + + /* Close the dataset then... */ + if(H5Dclose(dset) < 0) TEST_ERROR + + /* ...open it again to test the chunk query functions */ + if((dset = H5Dopen2(chunkfile, DSET_EXT_ARR_INDEX, H5P_DEFAULT)) < 0) + TEST_ERROR + + /* Get the number of chunks and verify that no chunk has been written */ + if(H5Dget_num_chunks(dset, dspace, &nchunks) < 0) TEST_ERROR + if(nchunks != 0) TEST_ERROR + + /* Initialize the array of chunk data for all NUM_CHUNKS chunks */ + for(n = 0; n < NUM_CHUNKS; n++) + for(i = 0; i < CHUNK_NX; i++) + for(j = 0; j < CHUNK_NY; j++) + direct_buf[n][i][j] = n + 1; + + /* Write only NUM_CHUNKS_WRITTEN chunks at the following logical coords: + (0,2) (0,3) (1,2) (1,3) */ + n = 0; + for (i = 0; i < 2; i++) + for (j = 2; j < 4; j++, n++) + { + offset[0] = i * CHUNK_NX; + offset[1] = j * CHUNK_NY; + ret = H5Dwrite_chunk(dset, H5P_DEFAULT, filter_mask, offset, buf_size, (void*)direct_buf[n]); + if(ret < 0) TEST_ERROR + } + + /* Get and verify the number of chunks written */ + if(H5Dget_num_chunks(dset, dspace, &nchunks) < 0) TEST_ERROR + if(nchunks != NUM_CHUNKS_WRITTEN) TEST_ERROR /* Get and verify info of the first chunk */ index = 0; - reinit_vars(&read_filter_mask, &addr, &size); - if (H5Dget_chunk_info(dset, fspace, index, out_offset, &read_filter_mask, &addr, &size) < 0) + reinit_vars(&read_flt_msk, &addr, &size); + out_offset[0] = out_offset[1] = 0; + if(H5Dget_chunk_info(dset, dspace, index, out_offset, &read_flt_msk, &addr, &size) < 0) TEST_ERROR - if (read_filter_mask != filter_mask) TEST_ERROR; - if (size != CHUNK_SIZE) TEST_ERROR; - if (out_offset[0] != 0 || out_offset[1] != 8) TEST_ERROR; + if(read_flt_msk != filter_mask) TEST_ERROR + if(size != CHUNK_SIZE) TEST_ERROR + if(out_offset[0] != 0 || out_offset[1] != 8) TEST_ERROR /* Get and verify info of the second chunk */ index = 1; - reinit_vars(&read_filter_mask, &addr, &size); - if (H5Dget_chunk_info(dset, fspace, index, out_offset, &read_filter_mask, &addr, &size) < 0) + reinit_vars(&read_flt_msk, &addr, &size); + out_offset[0] = out_offset[1] = 0; + if(H5Dget_chunk_info(dset, dspace, index, out_offset, &read_flt_msk, &addr, &size) < 0) TEST_ERROR - if (read_filter_mask != filter_mask) TEST_ERROR; - if (size != CHUNK_SIZE) TEST_ERROR; - if (out_offset[0] != 0 || out_offset[1] != 12) TEST_ERROR; + if(read_flt_msk != filter_mask) TEST_ERROR + if(size != CHUNK_SIZE) TEST_ERROR + if(out_offset[0] != 0 || out_offset[1] != 12) TEST_ERROR /* Get and verify info of the third chunk */ index = 2; - reinit_vars(&read_filter_mask, &addr, &size); - if (H5Dget_chunk_info(dset, fspace, index, out_offset, &read_filter_mask, &addr, &size) < 0) + reinit_vars(&read_flt_msk, &addr, &size); + out_offset[0] = out_offset[1] = 0; + if(H5Dget_chunk_info(dset, dspace, index, out_offset, &read_flt_msk, &addr, &size) < 0) TEST_ERROR - if (read_filter_mask != filter_mask) TEST_ERROR; - if (size != CHUNK_SIZE) TEST_ERROR; - if (out_offset[0] != 4 || out_offset[1] != 8) TEST_ERROR; + if(read_flt_msk != filter_mask) TEST_ERROR + if(size != CHUNK_SIZE) TEST_ERROR + if(out_offset[0] != 6 || out_offset[1] != 8) TEST_ERROR /* Get and verify info of the last chunk */ index = 3; - reinit_vars(&read_filter_mask, &addr, &size); - if (H5Dget_chunk_info(dset, fspace, index, out_offset, &read_filter_mask, &addr, &size) < 0) + reinit_vars(&read_flt_msk, &addr, &size); + out_offset[0] = out_offset[1] = 0; + if(H5Dget_chunk_info(dset, dspace, index, out_offset, &read_flt_msk, &addr, &size) < 0) TEST_ERROR - if (read_filter_mask != filter_mask) TEST_ERROR; - if (size != CHUNK_SIZE) TEST_ERROR; - if (out_offset[0] != 4 || out_offset[1] != 12) TEST_ERROR; + if(read_flt_msk != filter_mask) TEST_ERROR + if(size != CHUNK_SIZE) TEST_ERROR + if(out_offset[0] != 6 || out_offset[1] != 12) TEST_ERROR /* Attempt to get info of empty chunk and verify the returned address and size */ index = 5; - reinit_vars(&read_filter_mask, &addr, &size); - if (H5Dget_chunk_info(dset, fspace, index, out_offset, &read_filter_mask, &addr, &size) < 0) + reinit_vars(&read_flt_msk, &addr, &size); + out_offset[0] = out_offset[1] = 0; + if(H5Dget_chunk_info(dset, dspace, index, out_offset, &read_flt_msk, &addr, &size) < 0) TEST_ERROR - if (addr != HADDR_UNDEF) TEST_ERROR; - if (size != 0) TEST_ERROR; + if(addr != HADDR_UNDEF) TEST_ERROR + if(size != 0) TEST_ERROR /* Get info of the chunk at logical coordinates (0,2) */ offset[0] = 0; offset[1] = 2 * CHUNK_NY; - if (H5Dget_chunk_info_by_coord(dset, offset, &read_filter_mask, &addr, &size) < 0) TEST_ERROR; - if (read_filter_mask != filter_mask) TEST_ERROR; - if (size != CHUNK_SIZE) TEST_ERROR; + if(H5Dget_chunk_info_by_coord(dset, offset, &read_flt_msk, &addr, &size) < 0) TEST_ERROR + if(read_flt_msk != filter_mask) TEST_ERROR + if(size != CHUNK_SIZE) TEST_ERROR /* Get info of the chunk at logical coordinates (1,3) */ offset[0] = 1 * CHUNK_NX; offset[1] = 3 * CHUNK_NY; - if (H5Dget_chunk_info_by_coord(dset, offset, &read_filter_mask, &addr, &size) < 0) TEST_ERROR; - if (read_filter_mask != filter_mask) TEST_ERROR; - if (size != CHUNK_SIZE) TEST_ERROR; + if(H5Dget_chunk_info_by_coord(dset, offset, &read_flt_msk, &addr, &size) < 0) TEST_ERROR + if(read_flt_msk != filter_mask) TEST_ERROR + if(size != CHUNK_SIZE) TEST_ERROR /* Attempt to get info of empty chunks, verify the returned address and size */ offset[0] = 0; offset[1] = 0; - if (H5Dget_chunk_info_by_coord(dset, offset, &read_filter_mask, &addr, &size) < 0) TEST_ERROR; - if (addr != HADDR_UNDEF) TEST_ERROR; - if (size != 0) TEST_ERROR; + if(H5Dget_chunk_info_by_coord(dset, offset, &read_flt_msk, &addr, &size) < 0) TEST_ERROR + if(addr != HADDR_UNDEF) TEST_ERROR + if(size != 0) TEST_ERROR offset[0] = 3 * CHUNK_NX; offset[1] = 3 * CHUNK_NY; - if (H5Dget_chunk_info_by_coord(dset, offset, &read_filter_mask, &addr, &size) < 0) TEST_ERROR; - if (addr != HADDR_UNDEF) TEST_ERROR; - if (size != 0) TEST_ERROR; + if(H5Dget_chunk_info_by_coord(dset, offset, &read_flt_msk, &addr, &size) < 0) TEST_ERROR + if(addr != HADDR_UNDEF) TEST_ERROR + if(size != 0) TEST_ERROR /* Read each chunk and verify the values */ n = 0; for (i = 0; i < 2; i++) for (j = 2; j < 4; j++, n++) - if (read_each_chunk(dset, i*CHUNK_NX, j*CHUNK_NY, (void*)direct_buf[n]) < 0) + if(read_each_chunk(dset, i*CHUNK_NX, j*CHUNK_NY, (void*)direct_buf[n]) < 0) TEST_ERROR - /* Close the first dataset */ - if (H5Dclose(dset) < 0) TEST_ERROR + /* Release resourse */ + if(H5Dclose(dset) < 0) TEST_ERROR + if(H5Sclose(dspace) < 0) TEST_ERROR + if(H5Fclose(chunkfile) < 0) TEST_ERROR - /* Create an empty dataset */ - if((dset = H5Dcreate2(chunkfile, DSET_EMPTY, H5T_NATIVE_INT, fspace, - H5P_DEFAULT, cparms, H5P_DEFAULT)) < 0) TEST_ERROR - if (H5Dclose(dset) < 0) TEST_ERROR + PASSED(); + return SUCCEED; - /* Reopen the empty dataset to verify the chunk query functions on it */ - if((dset = H5Dopen2(chunkfile, DSET_EMPTY, H5P_DEFAULT)) < 0) TEST_ERROR +error: + H5E_BEGIN_TRY { + H5Dclose(dset); + H5Sclose(dspace); + H5Pclose(cparms); + H5Fclose(chunkfile); + } H5E_END_TRY; - /* Verify that the number of chunks is 0 */ - if (H5Dget_num_chunks(dset, mspace, &nchunks) < 0) TEST_ERROR; - if (nchunks != 0) TEST_ERROR; + H5_FAILED(); + return FAIL; +} /* test_chunk_info_extensible_array() */ - /* Attempt to get info of a chunk from an empty dataset, verify the - returned address and size */ +/*------------------------------------------------------------------------- + * Function: test_chunk_info_version2_btrees + * + * Purpose: Test getting various chunk information when Version 2 B-trees + * index type is used + * + * Return: Success: SUCCEED + * Failure: FAIL + * + * Note: Note that the dataspace argument in these new functions are + * currently not used. The functionality involved the dataspace + * will be implemented in the next version. + * + * Date: November 2018 + * + *------------------------------------------------------------------------- + */ +static herr_t +test_chunk_info_version2_btrees(char *filename, hid_t fapl) +{ + hid_t chunkfile = -1; /* File ID */ + hid_t dspace = -1; /* Dataspace ID */ + hid_t dset = -1; /* Dataset ID */ + hid_t cparms = -1; /* Creation plist */ + hsize_t dims[2] = {NX, NY};/* Dataset dimensions */ + hsize_t chunk_dims[2] = {CHUNK_NX, CHUNK_NY}; /* Chunk dimensions */ + hsize_t maxdims[2] = {H5S_UNLIMITED, H5S_UNLIMITED}; /* Two unlimited dims */ + int direct_buf[NUM_CHUNKS][CHUNK_NX][CHUNK_NY];/* Data in chunks */ + int out_buf[NX][NY]; /* Buffer to read data in */ + size_t buf_size = CHUNK_NX*CHUNK_NY*sizeof(int); /* Buffer size of a chk */ + unsigned filter_mask = 0; /* Filter mask */ + unsigned read_flt_msk = 0; /* Filter mask after direct read */ + H5D_chunk_index_t idx_type; /* Dataset chunk index type */ + hsize_t offset[2]; /* Offset coordinates of a chunk */ + hsize_t out_offset[2] = {0, 0}; /* Buffer to get offset coordinates */ + hsize_t size = 0; /* Size of an allocated/written chunk */ + hsize_t nchunks = 0; /* Number of chunks */ + haddr_t addr = 0; /* Address of an allocated/written chunk */ + hsize_t index = 0; /* Index of a chunk */ + int n; /* Used on buffer, to avoid conversion warning */ + hsize_t i, j; + herr_t ret; + + TESTING(" Version 2 B-trees index"); + + /* Open the file for reading/writing */ + if((chunkfile = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0) + TEST_ERROR + + /* Create dataspace */ + if((dspace = H5Screate_simple(RANK, dims, maxdims)) < 0) + TEST_ERROR + + /* Enable chunking */ + if((cparms = H5Pcreate(H5P_DATASET_CREATE)) < 0) + TEST_ERROR + + if(H5Pset_chunk(cparms, RANK, chunk_dims) < 0) + TEST_ERROR + + /* Create a new dataset using cparms creation properties */ + dset = H5Dcreate2(chunkfile, DSET_V2_BTREE_INDEX, H5T_NATIVE_INT, dspace, H5P_DEFAULT, cparms, H5P_DEFAULT); + if(dset < 0) TEST_ERROR + + /* Ensure we're using the correct chunk indexing scheme */ + if(H5D__layout_idx_type_test(dset, &idx_type) < 0) + TEST_ERROR + if(idx_type != H5D_CHUNK_IDX_BT2) + FAIL_PUTS_ERROR("should be using Version 2 B-tree index type"); + + /* Close the dataset then... */ + if(H5Dclose(dset) < 0) TEST_ERROR + + /* ...open it again to test the chunk query functions */ + if((dset = H5Dopen2(chunkfile, DSET_V2_BTREE_INDEX, H5P_DEFAULT)) < 0) + TEST_ERROR + + /* Get the number of chunks and verify that no chunk has been written */ + if(H5Dget_num_chunks(dset, dspace, &nchunks) < 0) TEST_ERROR + if(nchunks != 0) TEST_ERROR + + /* Initialize the array of chunk data for all NUM_CHUNKS chunks */ + for(n = 0; n < NUM_CHUNKS; n++) + for(i = 0; i < CHUNK_NX; i++) + for(j = 0; j < CHUNK_NY; j++) + direct_buf[n][i][j] = n + 1; + + /* Write only NUM_CHUNKS_WRITTEN chunks at the following logical coords: + (0,2) (0,3) (1,2) (1,3) */ + n = 0; + for (i = 0; i < 2; i++) + for (j = 2; j < 4; j++, n++) + { + offset[0] = i * CHUNK_NX; + offset[1] = j * CHUNK_NY; + ret = H5Dwrite_chunk(dset, H5P_DEFAULT, filter_mask, offset, buf_size, (void*)direct_buf[n]); + if(ret < 0) TEST_ERROR + } + + /* Get and verify the number of chunks written */ + if(H5Dget_num_chunks(dset, dspace, &nchunks) < 0) TEST_ERROR + if(nchunks != NUM_CHUNKS_WRITTEN) TEST_ERROR + + /* Get and verify info of the first chunk */ index = 0; - reinit_vars(&read_filter_mask, &addr, &size); - if (H5Dget_chunk_info(dset, fspace, index, out_offset, &read_filter_mask, &addr, &size) < 0) + reinit_vars(&read_flt_msk, &addr, &size); + out_offset[0] = out_offset[1] = 0; + if(H5Dget_chunk_info(dset, dspace, index, out_offset, &read_flt_msk, &addr, &size) < 0) TEST_ERROR - if (addr != HADDR_UNDEF) TEST_ERROR; - if (size != 0) TEST_ERROR; + if(read_flt_msk != filter_mask) TEST_ERROR + if(size != CHUNK_SIZE) TEST_ERROR + if(out_offset[0] != 0 || out_offset[1] != 8) TEST_ERROR - /* Attempt to get info of a chunk given its coords from an empty dataset, - verify the returned address and size */ + /* Get and verify info of the second chunk */ + index = 1; + reinit_vars(&read_flt_msk, &addr, &size); + out_offset[0] = out_offset[1] = 0; + if(H5Dget_chunk_info(dset, dspace, index, out_offset, &read_flt_msk, &addr, &size) < 0) + TEST_ERROR + if(read_flt_msk != filter_mask) TEST_ERROR + if(size != CHUNK_SIZE) TEST_ERROR + if(out_offset[0] != 0 || out_offset[1] != 12) TEST_ERROR + + /* Get and verify info of the third chunk */ + index = 2; + reinit_vars(&read_flt_msk, &addr, &size); + out_offset[0] = out_offset[1] = 0; + if(H5Dget_chunk_info(dset, dspace, index, out_offset, &read_flt_msk, &addr, &size) < 0) + TEST_ERROR + + if(read_flt_msk != filter_mask) TEST_ERROR + if(size != CHUNK_SIZE) TEST_ERROR + if(out_offset[0] != 6 || out_offset[1] != 8) TEST_ERROR + + /* Get and verify info of the last chunk */ + index = 3; + reinit_vars(&read_flt_msk, &addr, &size); + out_offset[0] = out_offset[1] = 0; + if(H5Dget_chunk_info(dset, dspace, index, out_offset, &read_flt_msk, &addr, &size) < 0) + TEST_ERROR + if(read_flt_msk != filter_mask) TEST_ERROR + if(size != CHUNK_SIZE) TEST_ERROR + if(out_offset[0] != 6 || out_offset[1] != 12) TEST_ERROR + + /* Attempt to get info of empty chunk and verify the returned address and size */ + index = 5; + reinit_vars(&read_flt_msk, &addr, &size); + out_offset[0] = out_offset[1] = 0; + if(H5Dget_chunk_info(dset, dspace, index, out_offset, &read_flt_msk, &addr, &size) < 0) + TEST_ERROR + if(addr != HADDR_UNDEF) TEST_ERROR + if(size != 0) TEST_ERROR + + /* Get info of the chunk at logical coordinates (0,2) */ + offset[0] = 0; + offset[1] = 2 * CHUNK_NY; + if(H5Dget_chunk_info_by_coord(dset, offset, &read_flt_msk, &addr, &size) < 0) TEST_ERROR + if(read_flt_msk != filter_mask) TEST_ERROR + if(size != CHUNK_SIZE) TEST_ERROR + + /* Get info of the chunk at logical coordinates (1,3) */ + offset[0] = 1 * CHUNK_NX; + offset[1] = 3 * CHUNK_NY; + if(H5Dget_chunk_info_by_coord(dset, offset, &read_flt_msk, &addr, &size) < 0) TEST_ERROR + if(read_flt_msk != filter_mask) TEST_ERROR + if(size != CHUNK_SIZE) TEST_ERROR + + /* Attempt to get info of empty chunks, verify the returned address and size */ offset[0] = 0; offset[1] = 0; - if (H5Dget_chunk_info_by_coord(dset, offset, &read_filter_mask, &addr, &size) < 0) TEST_ERROR; - if (addr != HADDR_UNDEF) TEST_ERROR; - if (size != 0) TEST_ERROR; + if(H5Dget_chunk_info_by_coord(dset, offset, &read_flt_msk, &addr, &size) < 0) TEST_ERROR + if(addr != HADDR_UNDEF) TEST_ERROR + if(size != 0) TEST_ERROR - /* Close/release resources. */ - if (H5Sclose(mspace) < 0) TEST_ERROR - if (H5Sclose(fspace) < 0) TEST_ERROR - if (H5Pclose(cparms) < 0) TEST_ERROR - if (H5Pclose(dxpl) < 0) TEST_ERROR - if (H5Fclose(chunkfile) < 0) TEST_ERROR + offset[0] = 3 * CHUNK_NX; + offset[1] = 3 * CHUNK_NY; + if(H5Dget_chunk_info_by_coord(dset, offset, &read_flt_msk, &addr, &size) < 0) TEST_ERROR + if(addr != HADDR_UNDEF) TEST_ERROR + if(size != 0) TEST_ERROR + + /* Read each chunk and verify the values */ + n = 0; + for (i = 0; i < 2; i++) + for (j = 2; j < 4; j++, n++) + if(read_each_chunk(dset, i*CHUNK_NX, j*CHUNK_NY, (void*)direct_buf[n]) < 0) + TEST_ERROR + + /* Release resourse */ + if(H5Dclose(dset) < 0) TEST_ERROR + if(H5Sclose(dspace) < 0) TEST_ERROR + if(H5Fclose(chunkfile) < 0) TEST_ERROR PASSED(); return SUCCEED; @@ -339,16 +1426,92 @@ test_get_chunk_info(void) error: H5E_BEGIN_TRY { H5Dclose(dset); - H5Sclose(mspace); - H5Sclose(fspace); + H5Sclose(dspace); H5Pclose(cparms); - H5Pclose(dxpl); H5Fclose(chunkfile); } H5E_END_TRY; H5_FAILED(); return FAIL; -} /* test_get_chunk_info() */ +} /* test_chunk_info_version2_btrees() */ + + +/*------------------------------------------------------------------------- + * Function: test_get_chunk_info_110 + * + * Purpose: Test getting various chunk information in version 1.10. + * + * Return: Success: SUCCEED + * Failure: FAIL + * + * Note: Note that the dataspace argument in these new functions are + * currently not used. The functionality involved the dataspace + * will be implemented in the next version. + * + * Description: + * This function tests the new API functions added for EED-343: + * H5Dget_num_chunks, H5Dget_chunk_info, and H5Dget_chunk_info_by_coord + * for high bound beyond 1.8. + * + * Date: October 2018 + * + *------------------------------------------------------------------------- + */ +static herr_t +test_get_chunk_info_110(hid_t fapl) +{ + hid_t chunkfile = -1; /* File ID */ + char filename[FILENAME_BUF_SIZE]; + H5F_libver_t low, high; /* File format bounds */ + + TESTING("getting chunk information in file with versions 1.10"); + HDprintf("\n"); /* to list sub-tests */ + + /* Create the file */ + h5_fixname(FILENAME[1], fapl, filename, sizeof filename); + chunkfile = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + if(chunkfile < 0) TEST_ERROR + + /* Close the file, individual tests will re-open the file with different + libvers via the fapl */ + if(H5Fclose(chunkfile) < 0) TEST_ERROR + + /* Set high bound to the current latest version */ + high = H5F_LIBVER_LATEST; + + /* Test getting info of chunked datasets in version combo up to 1.10 */ + for (low = H5F_LIBVER_V110; low <= H5F_LIBVER_LATEST; low++) { + /* Set version bounds for creating file */ + if(H5Pset_libver_bounds(fapl, low, high) < 0) + TEST_ERROR + + /* Test getting chunk info when Single Chunk index type is used */ + if(test_chunk_info_single_chunk(filename, fapl) < 0) + TEST_ERROR + + /* Test getting chunk info when Implicit index type is used */ + if(test_chunk_info_implicit(filename, fapl) < 0) + TEST_ERROR + + /* Test getting chunk info when Fixed Array index type is used */ + if(test_chunk_info_fixed_array(filename, fapl) < 0) + TEST_ERROR + + /* Test getting chunk info when Extensible Array index type is used */ + if(test_chunk_info_extensible_array(filename, fapl) < 0) + TEST_ERROR + + /* Test getting chunk info when Version 2 B-trees index type is used */ + if(test_chunk_info_version2_btrees(filename, fapl) < 0) + TEST_ERROR + } /* for low libver bound */ + + return SUCCEED; + +error: + H5_FAILED(); + return FAIL; +} /* test_get_chunk_info_110() */ /*------------------------------------------------------------------------- * Function: create_4x4_dset @@ -375,8 +1538,8 @@ error: * *------------------------------------------------------------------------- */ -int -create_4x4_dset(void) +static int +create_4x4_dset(hid_t fapl) { hid_t fid; /* file ID */ hid_t did; /* dataset ID */ @@ -389,19 +1552,21 @@ create_4x4_dset(void) int chunk_data[2][2] = { {1, 1}, {1, 1} }; int buf[4][4]; int fillvalue = 0; + char filename[FILENAME_BUF_SIZE]; hsize_t i, j; /* create a new file using default properties. */ - if ((fid = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; + h5_fixname(FILENAME[2], fapl, filename, sizeof filename); + if((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR /* create the file space */ - if ((f_sid = H5Screate_simple(RANK, dims, dims)) < 0) TEST_ERROR; + if((f_sid = H5Screate_simple(RANK, dims, dims)) < 0) TEST_ERROR /* create the memory space with chunk dimensions */ - if ((m_sid = H5Screate_simple(RANK, chunk_dims, chunk_dims)) < 0) TEST_ERROR; + if((m_sid = H5Screate_simple(RANK, chunk_dims, chunk_dims)) < 0) TEST_ERROR start[0] = 0; start[1] = 0; - if (H5Sselect_hyperslab(m_sid, H5S_SELECT_SET, start, NULL, chunk_dims, NULL) < 0) TEST_ERROR; + if(H5Sselect_hyperslab(m_sid, H5S_SELECT_SET, start, NULL, chunk_dims, NULL) < 0) TEST_ERROR /*------------------------------------------------------------------------- * create a dataset @@ -409,13 +1574,13 @@ create_4x4_dset(void) */ /* modify dataset creation properties, i.e. enable chunking. */ - if ((pid = H5Pcreate (H5P_DATASET_CREATE)) < 0) TEST_ERROR; - if (H5Pset_chunk(pid, RANK, chunk_dims) < 0) TEST_ERROR; - if (H5Pset_fill_value(pid, H5T_NATIVE_INT, &fillvalue) < 0) TEST_ERROR; + if((pid = H5Pcreate (H5P_DATASET_CREATE)) < 0) TEST_ERROR + if(H5Pset_chunk(pid, RANK, chunk_dims) < 0) TEST_ERROR + if(H5Pset_fill_value(pid, H5T_NATIVE_INT, &fillvalue) < 0) TEST_ERROR /* create a new dataset */ - if((did = H5Dcreate2(fid , DATASETNAME, H5T_NATIVE_INT, f_sid, H5P_DEFAULT, pid, H5P_DEFAULT)) < 0) TEST_ERROR; - + did = H5Dcreate2(fid , DATASETNAME, H5T_NATIVE_INT, f_sid, H5P_DEFAULT, pid, H5P_DEFAULT); + if(did < 0) TEST_ERROR /*------------------------------------------------------------------------- * write the dataset in 2x2 chunks @@ -430,13 +1595,13 @@ create_4x4_dset(void) /* iterate in dim 1 */ for (i = 0; i < chunk_dims[1]; i++) { /* select file hyperslab to save a 2x2 chunk */ - if (H5Sselect_hyperslab(f_sid, H5S_SELECT_SET, start, NULL, chunk_dims, NULL) < 0) TEST_ERROR; + if(H5Sselect_hyperslab(f_sid, H5S_SELECT_SET, start, NULL, chunk_dims, NULL) < 0) TEST_ERROR /* write the data to the hyperslab. */ - if (H5Dwrite(did, H5T_NATIVE_INT, m_sid, f_sid, H5P_DEFAULT, chunk_data) < 0) TEST_ERROR; + if(H5Dwrite(did, H5T_NATIVE_INT, m_sid, f_sid, H5P_DEFAULT, chunk_data) < 0) TEST_ERROR /* read back and display complete dataset 4x4 */ - if (H5Dread(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) TEST_ERROR; + if(H5Dread(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) TEST_ERROR #if defined (PRINT_DATA) printf("\n"); @@ -457,11 +1622,11 @@ create_4x4_dset(void) * close *------------------------------------------------------------------------- */ - if (H5Dclose(did) < 0) TEST_ERROR - if (H5Sclose(f_sid) < 0) TEST_ERROR - if (H5Sclose(m_sid) < 0) TEST_ERROR - if (H5Pclose(pid) < 0) TEST_ERROR - if (H5Fclose(fid) < 0) TEST_ERROR + if(H5Dclose(did) < 0) TEST_ERROR + if(H5Sclose(f_sid) < 0) TEST_ERROR + if(H5Sclose(m_sid) < 0) TEST_ERROR + if(H5Pclose(pid) < 0) TEST_ERROR + if(H5Fclose(fid) < 0) TEST_ERROR return SUCCEED; @@ -491,22 +1656,31 @@ error: int main(void) { - int nerrors = 0; + hid_t fapl = -1; /* File access property list */ + int nerrors = 0; /* Number of errors so far */ + + h5_reset(); + + /* Create a copy of file access property list */ + if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) TEST_ERROR - /* Tests getting chunk information */ - nerrors += (test_get_chunk_info() < 0 ? 1 : 0); + /* Tests getting chunk information of version 1.8 and prior */ + nerrors += test_get_chunk_info_highest18(fapl) < 0 ? 1 : 0; + + /* Tests getting chunk information of version 1.10 */ + nerrors += test_get_chunk_info_110(fapl) < 0 ? 1 : 0; /* Create a 4x4 dataset (using the existing code to avoid compilation warnings for now) */ - nerrors += (create_4x4_dset() < 0 ? 1 : 0); + nerrors += create_4x4_dset(fapl) < 0 ? 1 : 0; - if(nerrors) { + if(nerrors) goto error; - } /* end if */ - HDprintf("All chunk query tests passed.\n"); + h5_cleanup(FILENAME, fapl); + return SUCCEED; error: @@ -516,5 +1690,12 @@ error: return FAIL; } +/**************************************************************************** + Additional tests to be added: +- create/write to a dataset, do the query before closing the dataset +- do the query when extending the dataset (shrink or expand) +- verify that invalid input parameters are handled properly +- do the query on a non-chunked dataset... +- test for filter or non-filter - +****************************************************************************/ |