summaryrefslogtreecommitdiffstats
path: root/hl/test/test_file_image.c
diff options
context:
space:
mode:
Diffstat (limited to 'hl/test/test_file_image.c')
-rw-r--r--hl/test/test_file_image.c180
1 files changed, 97 insertions, 83 deletions
diff --git a/hl/test/test_file_image.c b/hl/test/test_file_image.c
index 504a3f5..712107e 100644
--- a/hl/test/test_file_image.c
+++ b/hl/test/test_file_image.c
@@ -1,15 +1,15 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-* Copyright by The HDF Group. *
-* Copyright by the Board of Trustees of the University of Illinois. *
-* All rights reserved. *
-* *
-* This file is part of HDF5. The full HDF5 copyright notice, including *
-* terms governing use, modification, and redistribution, is contained in *
+ * Copyright by The HDF Group. *
+ * Copyright by the Board of Trustees of the University of Illinois. *
+ * All rights reserved. *
+ * *
+ * This file is part of HDF5. The full HDF5 copyright notice, including *
+ * terms governing use, modification, and redistribution, is contained in *
* the COPYING file, which can be found at the root of the source code *
* distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
-* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "h5hltest.h"
#include "H5LTpublic.h"
@@ -21,8 +21,8 @@
/* For superblock version 0, 1: the offset to "file consistency flags" is 20 with size of 4 bytes */
/* The file consistency flags is the "status_flags" field in H5F_super_t */
/* Note: the offset and size will be different when using superblock version 2 for the test file */
-#define SUPER_STATUS_FLAGS_OFF_V0_V1 20
-#define SUPER_STATUS_FLAGS_SIZE_V0_V1 4
+#define SUPER_STATUS_FLAGS_OFF_V0_V1 20
+#define SUPER_STATUS_FLAGS_SIZE_V0_V1 4
/* Test of file image operations.
@@ -47,32 +47,32 @@
buffers if appropriate. */
/*-------------------------------------------------------------------------
-* test file image operations
-*-------------------------------------------------------------------------
-*/
+ * test file image operations
+ *-------------------------------------------------------------------------
+ */
static int
test_file_image(size_t open_images, size_t nflags, unsigned *flags)
{
- hid_t *file_id, *dset_id, file_space, plist; /* HDF5 ids */
- hsize_t dims1[RANK] = {2,3}; /* original dimension of datasets */
- hsize_t max_dims[RANK] = {H5S_UNLIMITED, H5S_UNLIMITED};
- int data1[6] = {1,2,3,4,5,6}; /* original contents of dataset */
- int data2[6] = {7,8,9,10,11,12}; /* "wrong" contents of dataset */
- hsize_t dims3[RANK]; /* array to read dataset dimensions */
- int data3[15]; /* array to read dataset contents */
- hsize_t dims4[RANK] = {3,5}; /* extended dimensions of datasets */
- int data4[15] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
- /* extended contents of dataset */
- ssize_t *buf_size; /* pointer to array of buffer sizes */
- void **buf_ptr; /* pointer to array of pointers to image buffers */
- char **filename; /* pointer to array of pointers to filenames */
- unsigned *input_flags; /* pointer to array of flag combinations */
- size_t i, j, k, nrow, n_values;
- herr_t status1;
- void *handle_ptr = NULL; /* pointers to driver buffer */
+ hid_t * file_id, *dset_id, file_space, plist; /* HDF5 ids */
+ hsize_t dims1[RANK] = {2, 3}; /* original dimension of datasets */
+ hsize_t max_dims[RANK] = {H5S_UNLIMITED, H5S_UNLIMITED};
+ int data1[6] = {1, 2, 3, 4, 5, 6}; /* original contents of dataset */
+ int data2[6] = {7, 8, 9, 10, 11, 12}; /* "wrong" contents of dataset */
+ hsize_t dims3[RANK]; /* array to read dataset dimensions */
+ int data3[15]; /* array to read dataset contents */
+ hsize_t dims4[RANK] = {3, 5}; /* extended dimensions of datasets */
+ int data4[15] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
+ /* extended contents of dataset */
+ ssize_t * buf_size; /* pointer to array of buffer sizes */
+ void ** buf_ptr; /* pointer to array of pointers to image buffers */
+ char ** filename; /* pointer to array of pointers to filenames */
+ unsigned * input_flags; /* pointer to array of flag combinations */
+ size_t i, j, k, nrow, n_values;
+ herr_t status1;
+ void * handle_ptr = NULL; /* pointers to driver buffer */
unsigned char **core_buf_ptr_ptr = NULL;
- VERIFY(open_images > 1 , "The number of open images must be greater than 1");
+ VERIFY(open_images > 1, "The number of open images must be greater than 1");
VERIFY(nflags > 0, "The number of flag combinations must be greater than 0");
@@ -131,7 +131,8 @@ test_file_image(size_t open_images, size_t nflags, unsigned *flags)
FAIL_PUTS_ERROR("H5Pset_chunk() failed");
/* create and write an integer type dataset named "dset" */
- if ((dset_id[i] = H5Dcreate2(file_id[i], DSET_NAME, H5T_NATIVE_INT, file_space, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0)
+ if ((dset_id[i] = H5Dcreate2(file_id[i], DSET_NAME, H5T_NATIVE_INT, file_space, H5P_DEFAULT, plist,
+ H5P_DEFAULT)) < 0)
FAIL_PUTS_ERROR("H5Dcreate() failed");
/* dataset in open image 1 is written with "wrong" data */
@@ -172,7 +173,7 @@ test_file_image(size_t open_images, size_t nflags, unsigned *flags)
/* buffer for file image 2 is filled with counter data (non-valid image) */
if (i == 2) {
for (j = 0; j < (size_t)buf_size[i]; j++)
- ((char*)(buf_ptr[i]))[j] = (char)j;
+ ((char *)(buf_ptr[i]))[j] = (char)j;
} /* end if */
/* buffers for the rest of the file images are filled with data from the respective files */
else {
@@ -181,7 +182,7 @@ test_file_image(size_t open_images, size_t nflags, unsigned *flags)
} /* end else */
/* file close */
- if (H5Fclose (file_id[i]) < 0)
+ if (H5Fclose(file_id[i]) < 0)
FAIL_PUTS_ERROR("H5Fclose() failed");
} /* end for */
@@ -193,10 +194,12 @@ test_file_image(size_t open_images, size_t nflags, unsigned *flags)
for (i = 0; i < open_images; i++) {
/* open file image 2 filled with counter data (non-valid image) */
if (i == 2) {
- H5E_BEGIN_TRY {
+ H5E_BEGIN_TRY
+ {
/* attempt to set file image in the core driver */
file_id[i] = H5LTopen_file_image(buf_ptr[i], (size_t)buf_size[i], input_flags[i]);
- } H5E_END_TRY
+ }
+ H5E_END_TRY
VERIFY(file_id[i] < 0, "H5LTopen_file_image() should have failed");
} /* end if */
@@ -208,36 +211,41 @@ test_file_image(size_t open_images, size_t nflags, unsigned *flags)
/* get pointer to the image buffer of the core driver */
if (H5Fget_vfd_handle(file_id[i], H5P_DEFAULT, &handle_ptr) < 0)
- FAIL_PUTS_ERROR("H5Fget_vfd_handle() failed");
+ FAIL_PUTS_ERROR("H5Fget_vfd_handle() failed");
core_buf_ptr_ptr = (unsigned char **)handle_ptr;
/* test whether the user buffer has been copied or not */
if (input_flags[i] & H5LT_FILE_IMAGE_DONT_COPY)
- VERIFY(*core_buf_ptr_ptr == buf_ptr[i], "vfd buffer and user buffer should have been the same");
+ VERIFY(*core_buf_ptr_ptr == buf_ptr[i],
+ "vfd buffer and user buffer should have been the same");
else
VERIFY(*core_buf_ptr_ptr != buf_ptr[i], "vfd buffer and user buffer should be different");
- /*
+ /*
* When the vfd and user buffers are different and H5LT_FILE_IMAGE_OPEN_RW is enabled,
* status_flags in the superblock needs to be cleared in the vfd buffer for
* the comparison to proceed as expected. The user buffer as returned from H5Fget_file_image()
* has already cleared status_flags. The superblock's status_flags is used for the
* implementation of file locking.
*/
- if(input_flags[i] & H5LT_FILE_IMAGE_OPEN_RW && !(input_flags[i] & H5LT_FILE_IMAGE_DONT_COPY)) {
+ if (input_flags[i] & H5LT_FILE_IMAGE_OPEN_RW && !(input_flags[i] & H5LT_FILE_IMAGE_DONT_COPY)) {
void *tmp_ptr = HDmalloc((size_t)buf_size[i]);
/* Copy vfd buffer to a temporary buffer */
HDmemcpy(tmp_ptr, (void *)*core_buf_ptr_ptr, (size_t)buf_size[i]);
- /* Clear status_flags in the superblock for the vfd buffer: file locking is using status_flags */
- HDmemset((uint8_t *)tmp_ptr + SUPER_STATUS_FLAGS_OFF_V0_V1, (int)0, (size_t)SUPER_STATUS_FLAGS_SIZE_V0_V1);
+ /* Clear status_flags in the superblock for the vfd buffer: file locking is using status_flags
+ */
+ HDmemset((uint8_t *)tmp_ptr + SUPER_STATUS_FLAGS_OFF_V0_V1, (int)0,
+ (size_t)SUPER_STATUS_FLAGS_SIZE_V0_V1);
/* Does the comparision */
- if(HDmemcmp(tmp_ptr, buf_ptr[i], (size_t)buf_size[i]) != 0)
+ if (HDmemcmp(tmp_ptr, buf_ptr[i], (size_t)buf_size[i]) != 0)
FAIL_PUTS_ERROR("comparison of TMP vfd and user buffer failed");
/* Free the temporary buffer */
- if(tmp_ptr) HDfree(tmp_ptr);
- } else {
+ if (tmp_ptr)
+ HDfree(tmp_ptr);
+ }
+ else {
/* test whether the contents of the user buffer and driver buffer */
/* are equal. */
@@ -245,7 +253,7 @@ test_file_image(size_t open_images, size_t nflags, unsigned *flags)
FAIL_PUTS_ERROR("comparison of vfd and user buffer failed");
}
} /* end else */
- } /* end for */
+ } /* end for */
PASSED();
@@ -272,7 +280,7 @@ test_file_image(size_t open_images, size_t nflags, unsigned *flags)
FAIL_PUTS_ERROR("H5Sget_simple_extent_dims() failed");
/* read dataset */
- if (H5Dread(dset_id[i], H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data3) < 0)
+ if (H5Dread(dset_id[i], H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data3) < 0)
FAIL_PUTS_ERROR("H5Dread() failed");
/* compute number of elements in dataset */
@@ -286,7 +294,7 @@ test_file_image(size_t open_images, size_t nflags, unsigned *flags)
/* compare file image values with original data */
for (j = 0; j < n_values / nrow; j++)
for (k = 0; k < nrow; k++)
- if (data3[j * nrow + k ] == data1[j * nrow + k ])
+ if (data3[j * nrow + k] == data1[j * nrow + k])
FAIL_PUTS_ERROR("comparison of image values with original data should have failed");
} /* end if */
/* verify contents for the rest of the file images */
@@ -294,12 +302,12 @@ test_file_image(size_t open_images, size_t nflags, unsigned *flags)
/* compare file image values with original data */
for (j = 0; j < n_values / nrow; j++)
for (k = 0; k < nrow; k++)
- if (data3[j * nrow + k ] != data1[j * nrow + k ])
+ if (data3[j * nrow + k] != data1[j * nrow + k])
FAIL_PUTS_ERROR("comparison of image values with original data failed");
} /* end else */
/* close dataspace */
- if (H5Sclose (file_space) < 0)
+ if (H5Sclose(file_space) < 0)
FAIL_PUTS_ERROR("H5Sclose() failed");
} /* end for */
@@ -318,23 +326,26 @@ test_file_image(size_t open_images, size_t nflags, unsigned *flags)
/* test data write when file image access is read-only */
if (!(input_flags[i] & H5LT_FILE_IMAGE_OPEN_RW)) {
/* write dataset without extending it */
- H5E_BEGIN_TRY {
- status1 = H5Dwrite(dset_id[i], H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data1);
- } H5E_END_TRY;
+ H5E_BEGIN_TRY
+ {
+ status1 = H5Dwrite(dset_id[i], H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data1);
+ }
+ H5E_END_TRY;
VERIFY(status1 < 0, "H5Dwrite() should have failed");
/* extend dimensions of dataset */
- H5E_BEGIN_TRY {
- status1 = H5Dset_extent(dset_id[i], dims4);
- } H5E_END_TRY;
+ H5E_BEGIN_TRY { status1 = H5Dset_extent(dset_id[i], dims4); }
+ H5E_END_TRY;
VERIFY(status1 < 0, "H5Dset_extent() should have failed");
/* write extended dataset */
- H5E_BEGIN_TRY {
- status1 = H5Dwrite(dset_id[i], H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data4);
- } H5E_END_TRY;
+ H5E_BEGIN_TRY
+ {
+ status1 = H5Dwrite(dset_id[i], H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data4);
+ }
+ H5E_END_TRY;
VERIFY(status1 < 0, "H5Dwrite() should have failed");
@@ -344,7 +355,8 @@ test_file_image(size_t open_images, size_t nflags, unsigned *flags)
} /* end if */
/* test data write where file image access is read-write */
else {
- if ((input_flags[i] & H5LT_FILE_IMAGE_DONT_COPY) && (input_flags[i] & H5LT_FILE_IMAGE_DONT_RELEASE)) {
+ if ((input_flags[i] & H5LT_FILE_IMAGE_DONT_COPY) &&
+ (input_flags[i] & H5LT_FILE_IMAGE_DONT_RELEASE)) {
/* This test is disabled currently, since the new attribute causes the file
* to increase in size, but the realloc call in H5FD_core_write() fails, causing
* the flush operation to fail and the file to fail to close, eventually
@@ -396,13 +408,13 @@ test_file_image(size_t open_images, size_t nflags, unsigned *flags)
H5Aclose(attr_id);
} H5E_END_TRY;
#endif
- if (H5Dclose(dset_id[i]) < 0)
- FAIL_PUTS_ERROR("H5Dclose() failed");
- dset_id[i] = -1;
+ if (H5Dclose(dset_id[i]) < 0)
+ FAIL_PUTS_ERROR("H5Dclose() failed");
+ dset_id[i] = -1;
} /* end if */
else {
/* write dataset without extending it */
- if (H5Dwrite(dset_id[i], H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data1) < 0)
+ if (H5Dwrite(dset_id[i], H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data1) < 0)
FAIL_PUTS_ERROR("H5Dwrite() failed");
/* extend dimensions of dataset */
@@ -410,15 +422,15 @@ test_file_image(size_t open_images, size_t nflags, unsigned *flags)
FAIL_PUTS_ERROR("H5Dset_extent() failed");
/* write extended dataset */
- if (H5Dwrite(dset_id[i], H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data4) < 0)
+ if (H5Dwrite(dset_id[i], H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data4) < 0)
FAIL_PUTS_ERROR("H5Dwrite() failed");
/* close dataset */
if (H5Dclose(dset_id[i]) < 0)
FAIL_PUTS_ERROR("H5Dclose() failed");
} /* end else */
- } /* end else */
- } /* end for */
+ } /* end else */
+ } /* end for */
PASSED();
@@ -427,7 +439,7 @@ test_file_image(size_t open_images, size_t nflags, unsigned *flags)
/* read open file images and verify data */
for (i = 0; i < open_images; i++) {
/* if opening the file image failed, continue next iteration */
- if ((dset_id[i] < 0) || (file_id[i] < 0) || (!(input_flags[i] & H5LT_FILE_IMAGE_OPEN_RW )))
+ if ((dset_id[i] < 0) || (file_id[i] < 0) || (!(input_flags[i] & H5LT_FILE_IMAGE_OPEN_RW)))
continue;
/* open dataset in file image */
@@ -443,7 +455,7 @@ test_file_image(size_t open_images, size_t nflags, unsigned *flags)
FAIL_PUTS_ERROR("H5Sget_simple_extent_dims() failed");
/* read dataset */
- if (H5Dread(dset_id[i], H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data3) < 0)
+ if (H5Dread(dset_id[i], H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data3) < 0)
FAIL_PUTS_ERROR("H5Dread() failed");
/* compute number of elements in dataset */
@@ -455,11 +467,11 @@ test_file_image(size_t open_images, size_t nflags, unsigned *flags)
/* verify contents for the file images */
for (j = 0; j < n_values / nrow; j++)
for (k = 0; k < nrow; k++)
- if (data3[j * nrow + k ] != data4[j * nrow + k ])
+ if (data3[j * nrow + k] != data4[j * nrow + k])
FAIL_PUTS_ERROR("comparison of image values with original data failed");
/* close dataspace */
- if (H5Sclose (file_space) < 0)
+ if (H5Sclose(file_space) < 0)
FAIL_PUTS_ERROR("H5Sclose() failed");
/* close dataset */
@@ -485,7 +497,8 @@ test_file_image(size_t open_images, size_t nflags, unsigned *flags)
FAIL_PUTS_ERROR("HDremove() failed");
/* free shared buffer if appropriate */
- if (!(input_flags[i] & H5LT_FILE_IMAGE_DONT_COPY) || (input_flags[i] & H5LT_FILE_IMAGE_DONT_RELEASE)) {
+ if (!(input_flags[i] & H5LT_FILE_IMAGE_DONT_COPY) ||
+ (input_flags[i] & H5LT_FILE_IMAGE_DONT_RELEASE)) {
VERIFY(buf_ptr[i] != NULL, "buffer pointer must be non NULL");
HDfree(buf_ptr[i]);
} /* end if */
@@ -512,15 +525,16 @@ error:
}
/*-------------------------------------------------------------------------
-* the main program
-*-------------------------------------------------------------------------
-*/
-int main( void )
+ * the main program
+ *-------------------------------------------------------------------------
+ */
+int
+main(void)
{
- int nerrors = 0;
- size_t open_images = 10; /* number of open file images */
- size_t nflags = 8; /* number of flag combinations */
- unsigned flags[8]; /* array with flag combinations */
+ int nerrors = 0;
+ size_t open_images = 10; /* number of open file images */
+ size_t nflags = 8; /* number of flag combinations */
+ unsigned flags[8]; /* array with flag combinations */
/* set flag combinations for testing */
flags[0] = 0;
@@ -533,14 +547,14 @@ int main( void )
flags[7] = H5LT_FILE_IMAGE_OPEN_RW | H5LT_FILE_IMAGE_DONT_COPY | H5LT_FILE_IMAGE_DONT_RELEASE;
/* Test file image operations. The flag combinations are assigned to file images in round-robin fashion */
- nerrors += test_file_image(open_images, nflags, flags) < 0? 1 : 0;
+ nerrors += test_file_image(open_images, nflags, flags) < 0 ? 1 : 0;
- if (nerrors) goto error;
+ if (nerrors)
+ goto error;
HDprintf("File image tests passed.\n");
return 0;
error:
- HDprintf("***** %d IMAGE TEST%s FAILED! *****\n",nerrors, 1 == nerrors ? "" : "S");
+ HDprintf("***** %d IMAGE TEST%s FAILED! *****\n", nerrors, 1 == nerrors ? "" : "S");
return 1;
}
-