hdf5/test/file_image.c

1430 lines
48 KiB
C
Raw Normal View History

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* 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://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/***********************************************************
2020-09-30 22:27:10 +08:00
*
* Test program: file_image
*
* Test setting file images
*
*************************************************************/
#include "h5test.h"
#include "H5Fprivate.h" /* required to test property removals */
2020-09-30 22:27:10 +08:00
#define VERIFY(condition, string) \
do { \
if (!(condition)) \
FAIL_PUTS_ERROR(string); \
2020-09-30 22:27:10 +08:00
} while (0)
/* Values for callback bit field */
2020-09-30 22:27:10 +08:00
#define MALLOC 0x01
#define MEMCPY 0x02
#define REALLOC 0x04
#define FREE 0x08
#define UDATA_COPY 0x10
#define UDATA_FREE 0x20
#define RANK 2
#define DIM0 1024
#define DIM1 32
#define DSET_NAME "test_dset"
#define FAMILY_SIZE (2 * 1024)
#define USERBLOCK_SIZE 512
2020-09-30 22:27:10 +08:00
const char *FILENAME[] = {"file_image_core_test", NULL};
/* need a second file name array, as the first file name array contains
* files we don't want to delete on cleanup.
*/
2020-09-30 22:27:10 +08:00
const char *FILENAME2[] = {"sec2_get_file_image_test",
"stdio_get_file_image_test",
"core_get_file_image_test",
"family_get_file_image_test",
"multi_get_file_image_test",
"split_get_file_image_test",
"get_file_image_error_rejection_test",
NULL};
typedef struct {
2020-09-30 22:27:10 +08:00
unsigned char used_callbacks; /* Bitfield for tracking callbacks */
H5FD_file_image_op_t malloc_src; /* Source of file image callbacks */
H5FD_file_image_op_t memcpy_src;
H5FD_file_image_op_t realloc_src;
H5FD_file_image_op_t free_src;
} udata_t;
/******************************************************************************
* Function: test_properties
*
* Purpose: Tests that the file image properties (buffer pointer and length)
* are set properly. Image callbacks are not set in this test.
*
* Returns: Success: 0
* Failure: 1
*
* Programmer: Jacob Gruber
* Monday, August 22, 2011
*
******************************************************************************
*/
static int
test_properties(void)
{
2020-09-30 22:27:10 +08:00
hid_t fapl_1 = -1;
hid_t fapl_2 = -1;
char *buffer = 0;
2020-09-30 22:27:10 +08:00
int count = 10;
void *temp = 0;
char *temp2 = 0;
2020-09-30 22:27:10 +08:00
int i;
size_t size;
size_t temp_size;
int retval = 1;
TESTING("File image property list functions");
2020-04-21 07:12:00 +08:00
/* Initialize file image buffer
*
* Note: this image will not contain a valid HDF5 file, as it complicates testing
* property list functions. In the file driver tests further down, this will
* not be the case.
*/
2021-06-17 04:45:26 +08:00
size = (size_t)count * sizeof(char);
if (NULL == (buffer = (char *)HDmalloc(size)))
TEST_ERROR;
2020-09-30 22:27:10 +08:00
for (i = 0; i < count - 1; i++)
buffer[i] = (char)(65 + i);
buffer[count - 1] = '\0';
/* Create fapl */
2020-09-30 22:27:10 +08:00
if ((fapl_1 = H5Pcreate(H5P_FILE_ACCESS)) < 0)
FAIL_STACK_ERROR;
/* Get file image stuff */
2020-09-30 22:27:10 +08:00
if (H5Pget_file_image(fapl_1, (void **)&temp, &temp_size) < 0)
FAIL_STACK_ERROR;
/* Check default values */
VERIFY(temp == NULL, "Default pointer is wrong");
VERIFY(temp_size == 0, "Default size is wrong");
/* Set file image stuff */
2020-09-30 22:27:10 +08:00
if (H5Pset_file_image(fapl_1, (void *)buffer, size) < 0)
FAIL_STACK_ERROR;
2020-04-21 07:12:00 +08:00
/* Get the same */
2020-09-30 22:27:10 +08:00
if (H5Pget_file_image(fapl_1, (void **)&temp, &temp_size) < 0)
FAIL_STACK_ERROR;
/* Check that sizes are the same, and that the buffers are identical but separate */
VERIFY(temp != NULL, "temp is null!");
VERIFY(temp_size == size, "Sizes of buffers don't match");
VERIFY(temp != buffer, "Retrieved buffer is the same as original");
VERIFY(0 == HDmemcmp(temp, buffer, size), "Buffers contain different data");
/* Copy the fapl */
2020-09-30 22:27:10 +08:00
if ((fapl_2 = H5Pcopy(fapl_1)) < 0)
FAIL_STACK_ERROR;
/* Get values from the new fapl */
2020-09-30 22:27:10 +08:00
if (H5Pget_file_image(fapl_2, (void **)&temp2, &temp_size) < 0)
FAIL_STACK_ERROR;
2020-04-21 07:12:00 +08:00
/* Check that sizes are the same, and that the buffers are identical but separate */
2020-09-30 22:27:10 +08:00
VERIFY(temp_size == size, "Sizes of buffers don't match");
VERIFY(temp2 != NULL, "Received buffer not set");
VERIFY(temp2 != buffer, "Retrieved buffer is the same as original");
VERIFY(temp2 != temp, "Retrieved buffer is the same as previously retrieved buffer");
2020-09-30 22:27:10 +08:00
VERIFY(0 == HDmemcmp(temp2, buffer, size), "Buffers contain different data");
retval = 0;
error:
/* Close everything */
2020-09-30 22:27:10 +08:00
if (H5Pclose(fapl_1) < 0)
retval = 1;
if (H5Pclose(fapl_2) < 0)
retval = 1;
HDfree(buffer);
H5free_memory(temp);
H5free_memory(temp2);
2020-09-30 22:27:10 +08:00
if (retval == 0)
PASSED();
return retval;
} /* end test_properties() */
/******************************************************************************
* Function: malloc_cb
*
* Purpose: This function allows calls to the malloc callback to be tracked.
*
* Returns: The result of a standard malloc
*
* Programmer: Jacob Gruber
* Monday, August 22, 2011
*
******************************************************************************
*/
static void *
malloc_cb(size_t size, H5FD_file_image_op_t op, void *udata)
{
udata_t *u = (udata_t *)udata;
u->used_callbacks |= MALLOC;
u->malloc_src = op;
return HDmalloc(size);
}
/******************************************************************************
* Function: memcpy_cb
*
* Purpose: This function allows calls to the memcpy callback to be tracked.
*
* Returns: The result of a standard memcpy
*
* Programmer: Jacob Gruber
* Monday, August 22, 2011
*
******************************************************************************
*/
static void *
memcpy_cb(void *dest, const void *src, size_t size, H5FD_file_image_op_t op, void *udata)
{
udata_t *u = (udata_t *)udata;
u->used_callbacks |= MEMCPY;
u->memcpy_src = op;
return HDmemcpy(dest, src, size);
}
/******************************************************************************
* Function: realloc_cb
*
* Purpose: This function allows calls to the realloc callback to be tracked.
*
* Returns: The result of a standard realloc
*
* Programmer: Jacob Gruber
* Monday, August 22, 2011
*
******************************************************************************
*/
static void *
realloc_cb(void *ptr, size_t size, H5FD_file_image_op_t op, void *udata)
{
udata_t *u = (udata_t *)udata;
u->used_callbacks |= REALLOC;
u->realloc_src = op;
2020-09-30 22:27:10 +08:00
return HDrealloc(ptr, size);
}
/******************************************************************************
* Function: free_cb
*
* Purpose: This function allows calls to the free callback to be tracked.
*
* Programmer: Jacob Gruber
* Monday, August 22, 2011
*
******************************************************************************
*/
static herr_t
free_cb(void *ptr, H5FD_file_image_op_t op, void *udata)
{
udata_t *u = (udata_t *)udata;
u->used_callbacks |= FREE;
u->free_src = op;
HDfree(ptr);
2020-09-30 22:27:10 +08:00
return (SUCCEED);
}
/******************************************************************************
* Function: udata_copy_cb
*
* Purpose: This function allows calls to the udata_copy callback to be tracked.
* No copying actually takes place; it is easier to deal with only one
* instance of the udata.
*
* Returns: A pointer to the same udata that was passed in.
*
* Programmer: Jacob Gruber
* Monday, August 22, 2011
*
******************************************************************************
*/
static void *
udata_copy_cb(void *udata)
{
udata_t *u = (udata_t *)udata;
u->used_callbacks |= UDATA_COPY;
return udata;
}
/******************************************************************************
* Function: udata_free_cb
*
* Purpose: This function allows calls to the udata_free callback to be tracked.
*
* Note: this callback doesn't actually do anything. Since the
* udata_copy callback doesn't copy, only one instance of the udata
* is kept alive and such it must be freed explicitly at the end of the tests.
*
* Programmer: Jacob Gruber
* Monday, August 22, 2011
*
******************************************************************************
*/
static herr_t
udata_free_cb(void *udata)
{
udata_t *u = (udata_t *)udata;
u->used_callbacks |= UDATA_FREE;
2020-09-30 22:27:10 +08:00
return (SUCCEED);
}
/******************************************************************************
* Function: reset_udata
*
* Purpose: Resets the udata to default values. This facilitates storing only
* the results of a single operation in the udata.
*
* Programmer: Jacob Gruber
* Monday, August 22, 2011
*
******************************************************************************
*/
static void
reset_udata(udata_t *u)
{
u->used_callbacks = 0;
u->malloc_src = u->memcpy_src = u->realloc_src = u->free_src = H5FD_FILE_IMAGE_OP_NO_OP;
}
/******************************************************************************
* Function: test_callbacks
*
* Purpose: Tests that callbacks are called properly in property list functions.
*
* Programmer: Jacob Gruber
* Monday, August 22, 2011
*
******************************************************************************
*/
static int
test_callbacks(void)
{
2020-09-30 22:27:10 +08:00
H5FD_file_image_callbacks_t real_callbacks = {&malloc_cb, &memcpy_cb, &realloc_cb, &free_cb,
&udata_copy_cb, &udata_free_cb, NULL};
H5FD_file_image_callbacks_t null_callbacks = {NULL, NULL, NULL, NULL, NULL, NULL, NULL};
H5FD_file_image_callbacks_t callbacks;
2020-09-30 22:27:10 +08:00
hid_t fapl_1;
hid_t fapl_2;
udata_t *udata = NULL;
char *file_image = NULL;
char *temp_file_image;
2020-09-30 22:27:10 +08:00
int count = 10;
int i;
size_t size;
size_t temp_size;
TESTING("Callback use in property list operations");
/* Allocate and initialize udata */
udata = (udata_t *)HDmalloc(sizeof(udata_t));
2021-06-17 04:45:26 +08:00
VERIFY(udata != NULL, "udata malloc failed");
reset_udata(udata);
/* copy the address of the user data into read_callbacks */
real_callbacks.udata = (void *)udata;
/* Allocate and initialize file image buffer */
2020-09-30 22:27:10 +08:00
size = (size_t)count * sizeof(char);
file_image = (char *)HDmalloc(size);
2021-06-17 04:45:26 +08:00
VERIFY(file_image != NULL, "file_image malloc failed");
2020-09-30 22:27:10 +08:00
for (i = 0; i < count - 1; i++)
file_image[i] = (char)(65 + i);
file_image[count - 1] = '\0';
/* Create fapl */
2020-09-30 22:27:10 +08:00
if ((fapl_1 = H5Pcreate(H5P_FILE_ACCESS)) < 0)
FAIL_STACK_ERROR;
/* Get file image stuff */
callbacks = real_callbacks;
2020-09-30 22:27:10 +08:00
if (H5Pget_file_image_callbacks(fapl_1, &callbacks) < 0)
FAIL_STACK_ERROR;
/* Check default values */
VERIFY(callbacks.image_malloc == NULL, "Default malloc callback is wrong");
VERIFY(callbacks.image_memcpy == NULL, "Default memcpy callback is wrong");
VERIFY(callbacks.image_realloc == NULL, "Default realloc callback is wrong");
VERIFY(callbacks.image_free == NULL, "Default free callback is wrong");
VERIFY(callbacks.udata_copy == NULL, "Default udata copy callback is wrong");
VERIFY(callbacks.udata_free == NULL, "Default udata free callback is wrong");
VERIFY(callbacks.udata == NULL, "Default udata is wrong");
/* Set file image callbacks */
callbacks = real_callbacks;
2020-09-30 22:27:10 +08:00
if (H5Pset_file_image_callbacks(fapl_1, &callbacks) < 0)
FAIL_STACK_ERROR;
/* Get file image callbacks */
callbacks = null_callbacks;
2020-09-30 22:27:10 +08:00
if (H5Pget_file_image_callbacks(fapl_1, &callbacks) < 0)
FAIL_STACK_ERROR;
2020-04-21 07:12:00 +08:00
/* Verify values */
2020-04-21 07:12:00 +08:00
VERIFY(callbacks.image_malloc == &malloc_cb, "malloc callback was not set or retrieved properly");
VERIFY(callbacks.image_memcpy == &memcpy_cb, "memcpy callback was not set or retrieved properly");
VERIFY(callbacks.image_realloc == &realloc_cb, "realloc callback was not set or retrieved properly");
VERIFY(callbacks.image_free == &free_cb, "free callback was not set or retrieved properly");
VERIFY(callbacks.udata_copy == &udata_copy_cb, "udata copy callback was not set or retrieved properly");
VERIFY(callbacks.udata_free == &udata_free_cb, "udata free callback was not set or retrieved properly");
VERIFY(callbacks.udata == udata, "udata was not set or retrieved properly");
/*
* Check callbacks in internal function without a previously set file image
*/
/* Copy fapl */
reset_udata(udata);
2020-09-30 22:27:10 +08:00
if ((fapl_2 = H5Pcopy(fapl_1)) < 0)
FAIL_STACK_ERROR;
2020-04-21 07:12:00 +08:00
/* Verify that the property's copy callback used the correct image callbacks */
VERIFY(udata->used_callbacks == (UDATA_COPY), "Copying a fapl with no image used incorrect callbacks");
/* Close fapl */
reset_udata(udata);
2020-09-30 22:27:10 +08:00
if (H5Pclose(fapl_2) < 0)
FAIL_STACK_ERROR;
/* Verify that the udata free callback was used */
VERIFY(udata->used_callbacks == (UDATA_FREE), "Closing a fapl with no image used incorrect callbacks");
/* Copy again */
2020-09-30 22:27:10 +08:00
if ((fapl_2 = H5Pcopy(fapl_1)) < 0)
FAIL_STACK_ERROR;
2020-04-21 07:12:00 +08:00
/* Remove property from fapl */
reset_udata(udata);
2020-09-30 22:27:10 +08:00
if (H5Premove(fapl_2, H5F_ACS_FILE_IMAGE_INFO_NAME) < 0)
FAIL_STACK_ERROR;
/* Verify that the property's delete callback was called using the correct image callbacks */
2020-09-30 22:27:10 +08:00
VERIFY(udata->used_callbacks == (UDATA_FREE),
"Removing a property from a fapl with no image used incorrect callbacks");
2020-04-21 07:12:00 +08:00
/* Close it again */
2020-09-30 22:27:10 +08:00
if (H5Pclose(fapl_2) < 0)
FAIL_STACK_ERROR;
/* Get file image */
reset_udata(udata);
2020-09-30 22:27:10 +08:00
if (H5Pget_file_image(fapl_1, (void **)&temp_file_image, &temp_size) < 0)
FAIL_STACK_ERROR;
/* Verify that the correct callbacks were used */
2020-09-30 22:27:10 +08:00
VERIFY(udata->used_callbacks == 0,
"attempting to retrieve the image from a fapl without an image has an unexpected callback");
/* Set file image */
reset_udata(udata);
2020-09-30 22:27:10 +08:00
if (H5Pset_file_image(fapl_1, (void *)file_image, size) < 0)
FAIL_STACK_ERROR;
2020-09-30 22:27:10 +08:00
VERIFY(udata->used_callbacks == (MALLOC | MEMCPY),
"Setting a file image (first time) used incorrect callbacks");
2020-04-21 07:12:00 +08:00
/*
* Check callbacks in internal functions with a previously set file image
*/
2020-04-21 07:12:00 +08:00
/* Copy fapl */
reset_udata(udata);
2020-09-30 22:27:10 +08:00
if ((fapl_2 = H5Pcopy(fapl_1)) < 0)
FAIL_STACK_ERROR;
2020-04-21 07:12:00 +08:00
/* Verify that the property's copy callback used the correct image callbacks */
2020-09-30 22:27:10 +08:00
VERIFY(udata->used_callbacks == (MALLOC | MEMCPY | UDATA_COPY),
"Copying a fapl with an image used incorrect callbacks");
VERIFY(udata->malloc_src == H5FD_FILE_IMAGE_OP_PROPERTY_LIST_COPY, "malloc callback has wrong source");
VERIFY(udata->memcpy_src == H5FD_FILE_IMAGE_OP_PROPERTY_LIST_COPY, "memcpy callback has wrong source");
/* Close fapl */
reset_udata(udata);
2020-09-30 22:27:10 +08:00
if (H5Pclose(fapl_2) < 0)
FAIL_STACK_ERROR;
/* Verify that the udata free callback was used */
2020-09-30 22:27:10 +08:00
VERIFY(udata->used_callbacks == (FREE | UDATA_FREE),
"Closing a fapl with an image used incorrect callbacks");
VERIFY(udata->free_src == H5FD_FILE_IMAGE_OP_PROPERTY_LIST_CLOSE, "free callback has wrong source");
/* Copy again */
2020-09-30 22:27:10 +08:00
if ((fapl_2 = H5Pcopy(fapl_1)) < 0)
FAIL_STACK_ERROR;
2020-04-21 07:12:00 +08:00
/* Remove property from fapl */
reset_udata(udata);
2020-09-30 22:27:10 +08:00
if (H5Premove(fapl_2, H5F_ACS_FILE_IMAGE_INFO_NAME) < 0)
FAIL_STACK_ERROR;
/* Verify that the property's delete callback was called using the correct image callbacks */
2020-09-30 22:27:10 +08:00
VERIFY(udata->used_callbacks == (FREE | UDATA_FREE),
"Removing a property from a fapl with an image used incorrect callbacks");
VERIFY(udata->free_src == H5FD_FILE_IMAGE_OP_PROPERTY_LIST_CLOSE, "free callback has wrong source");
2020-04-21 07:12:00 +08:00
/* Close it again */
2020-09-30 22:27:10 +08:00
if (H5Pclose(fapl_2) < 0)
FAIL_STACK_ERROR;
2020-04-21 07:12:00 +08:00
/* Get file image */
reset_udata(udata);
2020-09-30 22:27:10 +08:00
if (H5Pget_file_image(fapl_1, (void **)&temp_file_image, &temp_size) < 0)
FAIL_STACK_ERROR;
/* Verify that the correct callbacks were used */
2020-09-30 22:27:10 +08:00
VERIFY(udata->used_callbacks == (MALLOC | MEMCPY),
"attempting to retrieve the image from a fapl with an image has an unexpected callback");
VERIFY(udata->malloc_src == H5FD_FILE_IMAGE_OP_PROPERTY_LIST_GET, "malloc callback has wrong source");
VERIFY(udata->memcpy_src == H5FD_FILE_IMAGE_OP_PROPERTY_LIST_GET, "memcpy callback has wrong source");
/* Set file image */
reset_udata(udata);
2020-09-30 22:27:10 +08:00
if (H5Pset_file_image(fapl_1, (void *)file_image, size) < 0)
FAIL_STACK_ERROR;
2020-09-30 22:27:10 +08:00
VERIFY(udata->used_callbacks == (FREE | MALLOC | MEMCPY),
"Setting a file image (second time) used incorrect callbacks");
VERIFY(udata->malloc_src == H5FD_FILE_IMAGE_OP_PROPERTY_LIST_SET, "malloc callback has wrong source");
VERIFY(udata->memcpy_src == H5FD_FILE_IMAGE_OP_PROPERTY_LIST_SET, "memcpy callback has wrong source");
VERIFY(udata->free_src == H5FD_FILE_IMAGE_OP_PROPERTY_LIST_SET, "freec callback has wrong source");
/* Close stuff */
2020-09-30 22:27:10 +08:00
if (H5Pclose(fapl_1) < 0)
FAIL_STACK_ERROR;
HDfree(file_image);
HDfree(temp_file_image);
HDfree(udata);
PASSED();
return 0;
error:
2021-06-17 04:45:26 +08:00
HDfree(file_image);
HDfree(udata);
return 1;
} /* test_callbacks() */
/******************************************************************************
* Function: test_core
*
* Purpose: Tests that callbacks are called properly in the core VFD and
* that the initial file image works properly.
*
* Programmer: Jacob Gruber
* Monday, August 22, 2011
*
******************************************************************************
*/
static int
test_core(void)
{
2020-09-30 22:27:10 +08:00
hid_t fapl;
hid_t file;
hid_t dset;
hid_t space;
udata_t *udata;
unsigned char *file_image;
2020-09-30 22:27:10 +08:00
char filename[1024];
char copied_filename[1024];
const char *tmp = NULL;
2020-09-30 22:27:10 +08:00
size_t size;
hsize_t dims[2];
int fd;
h5_stat_t sb;
herr_t ret;
H5FD_file_image_callbacks_t callbacks = {&malloc_cb, &memcpy_cb, &realloc_cb, &free_cb,
&udata_copy_cb, &udata_free_cb, NULL};
TESTING("Initial file image and callbacks in Core VFD");
2020-04-21 07:12:00 +08:00
/* Create fapl */
fapl = h5_fileaccess();
VERIFY(fapl >= 0, "fapl creation failed");
/* Set up the core VFD */
ret = H5Pset_fapl_core(fapl, (size_t)0, 0);
VERIFY(ret >= 0, "setting core driver in fapl failed");
tmp = h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));
VERIFY(tmp != NULL, "h5_fixname failed");
/* Append ".copy" to the filename from the source directory */
VERIFY(HDstrlen(filename) < (1023 - 5), "file name too long.");
HDstrncpy(copied_filename, filename, (size_t)1023);
copied_filename[1023] = '\0';
HDstrcat(copied_filename, ".copy");
/* Make a copy of the data file from svn. */
ret = h5_make_local_copy(filename, copied_filename);
VERIFY(ret >= 0, "h5_make_local_copy");
/* Allocate and initialize udata */
udata = (udata_t *)HDmalloc(sizeof(udata_t));
VERIFY(udata != NULL, "udata malloc failed");
/* copy the address of the udata into the callbacks structure */
callbacks.udata = (void *)udata;
/* Set file image callbacks */
ret = H5Pset_file_image_callbacks(fapl, &callbacks);
VERIFY(ret >= 0, "set image callbacks failed");
/* Test open (no file image) */
reset_udata(udata);
file = H5Fopen(copied_filename, H5F_ACC_RDONLY, fapl);
VERIFY(file >= 0, "H5Fopen failed");
2020-09-30 22:27:10 +08:00
VERIFY((udata->used_callbacks == MALLOC) || (udata->used_callbacks == (MALLOC | UDATA_COPY | UDATA_FREE)),
"opening a core file used the wrong callbacks");
VERIFY(udata->malloc_src == H5FD_FILE_IMAGE_OP_FILE_OPEN,
"Malloc callback came from wrong source in core open");
/* Close file */
reset_udata(udata);
ret = H5Fclose(file);
VERIFY(ret >= 0, "H5Fclose failed");
VERIFY(udata->used_callbacks == FREE, "Closing a core file used the wrong callbacks");
2020-09-30 22:27:10 +08:00
VERIFY(udata->free_src == H5FD_FILE_IMAGE_OP_FILE_CLOSE,
"Free callback came from wrong source in core close");
/* Reopen file */
file = H5Fopen(copied_filename, H5F_ACC_RDWR, fapl);
VERIFY(file >= 0, "H5Fopen failed");
/* Set up a new dset */
dims[0] = DIM0;
dims[1] = DIM1;
2020-09-30 22:27:10 +08:00
space = H5Screate_simple(RANK, dims, dims);
VERIFY(space >= 0, "H5Screate failed");
2020-04-21 07:12:00 +08:00
/* Create new dset, invoking H5FD_core_write */
reset_udata(udata);
dset = H5Dcreate2(file, DSET_NAME, H5T_NATIVE_INT, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
2020-09-30 22:27:10 +08:00
VERIFY(dset >= 0, "H5Dcreate failed");
2020-04-21 07:12:00 +08:00
/* Flush the write and check the realloc callback */
ret = H5Fflush(file, H5F_SCOPE_LOCAL);
VERIFY(ret >= 0, "H5Fflush failed");
VERIFY(udata->used_callbacks == (REALLOC), "core write used the wrong callbacks");
2020-09-30 22:27:10 +08:00
VERIFY(udata->realloc_src == H5FD_FILE_IMAGE_OP_FILE_RESIZE,
"Realloc callback came from wrong source in core write");
2020-04-21 07:12:00 +08:00
/* Close dset and space */
ret = H5Dclose(dset);
VERIFY(ret >= 0, "H5Dclose failed");
ret = H5Sclose(space);
VERIFY(ret >= 0, "H5Sclose failed");
2020-04-21 07:12:00 +08:00
/* Test file close */
reset_udata(udata);
ret = H5Fclose(file);
VERIFY(ret >= 0, "H5Fclose failed");
VERIFY(udata->used_callbacks == (FREE), "Closing a core file used the wrong callbacks");
2020-09-30 22:27:10 +08:00
VERIFY(udata->free_src == H5FD_FILE_IMAGE_OP_FILE_CLOSE,
"Free callback came from wrong source in core close");
/* Create file image buffer */
fd = HDopen(copied_filename, O_RDONLY);
VERIFY(fd > 0, "open failed");
ret = HDfstat(fd, &sb);
VERIFY(ret == 0, "fstat failed");
2020-09-30 22:27:10 +08:00
size = (size_t)sb.st_size;
file_image = (unsigned char *)HDmalloc(size);
2020-09-30 22:27:10 +08:00
if (HDread(fd, file_image, size) < 0)
FAIL_PUTS_ERROR("unable to read from file descriptor");
ret = HDclose(fd);
VERIFY(ret == 0, "close failed");
/* Set file image in plist */
2020-09-30 22:27:10 +08:00
if (H5Pset_file_image(fapl, file_image, size) < 0)
FAIL_STACK_ERROR;
/* Test open with file image */
2020-09-30 22:27:10 +08:00
if ((file = H5Fopen("dne.h5", H5F_ACC_RDONLY, fapl)) < 0)
FAIL_STACK_ERROR;
2020-09-30 22:27:10 +08:00
if (H5Fclose(file) < 0)
FAIL_STACK_ERROR;
/* Release resources */
2020-04-21 07:12:00 +08:00
h5_clean_files(FILENAME, fapl);
HDfree(udata);
HDfree(file_image);
HDremove(copied_filename);
2020-04-21 07:12:00 +08:00
PASSED();
return 0;
error:
return 1;
} /* end test_core() */
/******************************************************************************
* Function: test_get_file_image
*
* Purpose: Test the H5Fget_file_image() call.
*
* Programmer: John Mainzer
* Tuesday, November 15, 2011
*
* Modifications:
* Vailin Choi; July 2013
* Add the creation of user block to the file as indicated by the parameter "user".
*
******************************************************************************
*/
/* Disable warning for "format not a string literal" here -QAK */
/*
* This pragma only needs to surround the snprintf() calls with
* 'member_file_name' in the code below, but early (4.4.7, at least) gcc only
* allows diagnostic pragmas to be toggled outside of functions.
*/
H5_GCC_CLANG_DIAG_OFF("format-nonliteral")
static int
2020-09-30 22:27:10 +08:00
test_get_file_image(const char *test_banner, const int file_name_num, hid_t fapl, hbool_t user)
{
2020-09-30 22:27:10 +08:00
char file_name[1024] = "\0";
void *insertion_ptr = NULL;
void *image_ptr = NULL;
void *file_image_ptr = NULL;
2020-09-30 22:27:10 +08:00
hbool_t is_family_file = FALSE;
hbool_t identical;
int data[100];
int i;
int fd = -1;
int result;
hid_t driver = -1;
hid_t file_id = -1;
hid_t dset_id = -1;
hid_t space_id = -1;
hid_t core_fapl_id = -1;
hid_t core_file_id = -1;
herr_t err;
hsize_t dims[2];
ssize_t bytes_read;
ssize_t image_size;
ssize_t file_size;
h5_stat_t stat_buf;
2020-09-30 22:27:10 +08:00
hid_t fcpl = -1;
herr_t ret;
TESTING(test_banner);
/* set flag if we are dealing with a family file */
driver = H5Pget_driver(fapl);
VERIFY(driver >= 0, "H5Pget_driver(fapl) failed");
2020-09-30 22:27:10 +08:00
if (driver == H5FD_FAMILY)
is_family_file = TRUE;
2020-04-21 07:12:00 +08:00
/* setup the file name */
h5_fixname(FILENAME2[file_name_num], fapl, file_name, sizeof(file_name));
2020-09-30 22:27:10 +08:00
VERIFY(HDstrlen(file_name) > 0, "h5_fixname failed");
fcpl = H5Pcreate(H5P_FILE_CREATE);
VERIFY(fcpl >= 0, "H5Pcreate");
2020-09-30 22:27:10 +08:00
if (user) {
ret = H5Pset_userblock(fcpl, (hsize_t)USERBLOCK_SIZE);
2020-09-30 22:27:10 +08:00
VERIFY(ret >= 0, "H5Pset_userblock");
}
/* create the file */
file_id = H5Fcreate(file_name, 0, fcpl, fapl);
VERIFY(file_id >= 0, "H5Fcreate() failed.");
/* Set up data space for new new data set */
2020-09-30 22:27:10 +08:00
dims[0] = 10;
dims[1] = 10;
space_id = H5Screate_simple(2, dims, dims);
VERIFY(space_id >= 0, "H5Screate() failed");
/* Create a dataset */
2020-09-30 22:27:10 +08:00
dset_id = H5Dcreate2(file_id, "dset 0", H5T_NATIVE_INT, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
VERIFY(dset_id >= 0, "H5Dcreate() failed");
/* write some data to the data set */
for (i = 0; i < 100; i++)
data[i] = i;
err = H5Dwrite(dset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, (void *)data);
VERIFY(err >= 0, "H5Dwrite() failed.");
2020-04-21 07:12:00 +08:00
/* Flush the file */
err = H5Fflush(file_id, H5F_SCOPE_GLOBAL);
VERIFY(err >= 0, "H5Fflush failed");
/* get the size of the file */
image_size = H5Fget_file_image(file_id, NULL, (size_t)0);
VERIFY(image_size > 0, "H5Fget_file_image(1) failed.");
/* allocate a buffer of the appropriate size */
image_ptr = HDmalloc((size_t)image_size);
VERIFY(image_ptr != NULL, "HDmalloc(1) failed.");
/* load the image of the file into the buffer */
bytes_read = H5Fget_file_image(file_id, image_ptr, (size_t)image_size);
VERIFY(bytes_read == image_size, "H5Fget_file_image(2) failed.");
/* Close dset and space */
2020-04-21 07:12:00 +08:00
err = H5Dclose(dset_id);
VERIFY(err >= 0, "H5Dclose failed");
err = H5Sclose(space_id);
VERIFY(err >= 0, "H5Sclose failed");
/* close the test file */
err = H5Fclose(file_id);
VERIFY(err == SUCCEED, "H5Fclose(file_id) failed.");
2020-09-30 22:27:10 +08:00
if (is_family_file) {
char member_file_name[1024];
ssize_t bytes_to_read;
ssize_t member_size;
ssize_t size_remaining;
2020-09-30 22:27:10 +08:00
/*
* Modifications need to be made to accommodate userblock when
* H5Fget_file_image() works for family driver
*/
2020-09-30 22:27:10 +08:00
i = 0;
file_size = 0;
do {
HDsnprintf(member_file_name, (size_t)1024, file_name, i);
/* get the size of the member file */
result = HDstat(member_file_name, &stat_buf);
VERIFY(result == 0, "HDstat() failed.");
member_size = (ssize_t)stat_buf.st_size;
i++;
file_size += member_size;
2020-09-30 22:27:10 +08:00
} while (member_size > 0);
/* Since we use the eoa to calculate the image size, the file size
* may be larger. This is OK, as long as (in this specialized instance)
* the remainder of the file is all '\0's.
*/
VERIFY(file_size >= image_size, "file size != image size.");
/* allocate a buffer for the test file image */
file_image_ptr = HDmalloc((size_t)file_size);
VERIFY(file_image_ptr != NULL, "HDmalloc(2f) failed.");
size_remaining = image_size;
2020-09-30 22:27:10 +08:00
insertion_ptr = file_image_ptr;
i = 0;
2020-09-30 22:27:10 +08:00
while (size_remaining > 0) {
/* construct the member file name */
HDsnprintf(member_file_name, 1024, file_name, i);
/* open the test file using standard I/O calls */
fd = HDopen(member_file_name, O_RDONLY);
VERIFY(fd >= 0, "HDopen() failed.");
2020-09-30 22:27:10 +08:00
if (size_remaining >= FAMILY_SIZE) {
bytes_to_read = FAMILY_SIZE;
size_remaining -= FAMILY_SIZE;
2020-09-30 22:27:10 +08:00
}
else {
bytes_to_read = size_remaining;
size_remaining = 0;
}
/* read the member file from disk into the buffer */
bytes_read = HDread(fd, insertion_ptr, (size_t)bytes_to_read);
VERIFY(bytes_read == bytes_to_read, "HDread() failed.");
insertion_ptr = (void *)(((char *)insertion_ptr) + bytes_to_read);
i++;
/* close the test file */
result = HDclose(fd);
VERIFY(result == 0, "HDclose() failed.");
}
2020-09-30 22:27:10 +08:00
}
else {
/* get the size of the test file */
result = HDstat(file_name, &stat_buf);
VERIFY(result == 0, "HDstat() failed.");
/* Since we use the eoa to calculate the image size, the file size
* may be larger. This is OK, as long as (in this specialized instance)
* the remainder of the file is all '\0's.
*/
file_size = (ssize_t)stat_buf.st_size;
2020-09-30 22:27:10 +08:00
if (user) {
VERIFY(file_size > USERBLOCK_SIZE, "file size !> userblock size.");
file_size -= USERBLOCK_SIZE;
}
2020-09-30 22:27:10 +08:00
/* with latest mods to truncate call in core file drive,
2020-04-21 07:12:00 +08:00
* file size should match image size
*/
VERIFY(file_size == image_size, "file size != image size.");
/* allocate a buffer for the test file image */
file_image_ptr = HDmalloc((size_t)file_size);
VERIFY(file_image_ptr != NULL, "HDmalloc(2) failed.");
/* open the test file using standard I/O calls */
fd = HDopen(file_name, O_RDONLY);
VERIFY(fd >= 0, "HDopen() failed.");
2020-09-30 22:27:10 +08:00
if (user) {
HDoff_t off;
/* Position at userblock */
off = HDlseek(fd, (off_t)USERBLOCK_SIZE, SEEK_SET);
VERIFY(off >= 0, "HDlseek() failed.");
}
/* read the test file from disk into the buffer */
bytes_read = HDread(fd, file_image_ptr, (size_t)file_size);
VERIFY(bytes_read == file_size, "HDread() failed.");
/* close the test file */
result = HDclose(fd);
VERIFY(result == 0, "HDclose() failed.");
}
/* verify that the file and the image contain the same data */
identical = TRUE;
2020-09-30 22:27:10 +08:00
i = 0;
while ((i < (int)image_size) && identical) {
if (((char *)image_ptr)[i] != ((char *)file_image_ptr)[i])
identical = FALSE;
i++;
}
VERIFY(identical, "file and image differ.");
/* finally, verify that we can use the core file driver to open the image */
/* create fapl for core file driver */
core_fapl_id = H5Pcreate(H5P_FILE_ACCESS);
2020-09-30 22:27:10 +08:00
VERIFY(core_fapl_id >= 0, "H5Pcreate() failed");
/* setup core_fapl_id to use the core file driver */
err = H5Pset_fapl_core(core_fapl_id, (size_t)(64 * 1024), FALSE);
VERIFY(err == SUCCEED, "H5Pset_fapl_core() failed.");
/* Set file image in core fapl */
err = H5Pset_file_image(core_fapl_id, image_ptr, (size_t)image_size);
VERIFY(err == SUCCEED, "H5Pset_file_image() failed.");
/* open the file image with the core file driver */
core_file_id = H5Fopen("nonesuch", H5F_ACC_RDWR, core_fapl_id);
VERIFY(core_file_id >= 0, "H5Fopen() of file image failed.");
/* close the file image with the core file driver */
err = H5Fclose(core_file_id);
VERIFY(err == SUCCEED, "H5Fclose(core_file_id) failed.");
/* discard core fapl */
err = H5Pclose(core_fapl_id);
VERIFY(err == SUCCEED, "H5Pclose(core_fapl_id) failed.");
/* tidy up */
h5_clean_files(FILENAME2, fapl);
/* discard the image buffer if it exists */
2020-09-30 22:27:10 +08:00
if (image_ptr != NULL)
HDfree(image_ptr);
/* discard the image buffer if it exists */
2020-09-30 22:27:10 +08:00
if (file_image_ptr != NULL)
HDfree(file_image_ptr);
2020-04-21 07:12:00 +08:00
PASSED();
return 0;
error:
return 1;
} /* end test_get_file_image() */
H5_GCC_CLANG_DIAG_ON("format-nonliteral")
2020-09-05 05:51:30 +08:00
/******************************************************************************
* Function: test_get_file_image_error_rejection
*
* Purpose: Verify that H5Fget_file_image() rejects invalid input.
*
* Programmer: John Mainzer
* Tuesday, November 22, 2011
*
******************************************************************************
*/
#define TYPE_SLICE ((haddr_t)0x10000LL)
static int
test_get_file_image_error_rejection(void)
{
2020-09-30 22:27:10 +08:00
const char *memb_name[H5FD_MEM_NTYPES];
char file_name[1024] = "\0";
void *image_ptr = NULL;
2020-09-30 22:27:10 +08:00
int data[100];
int i;
hid_t fapl_id = -1;
hid_t file_id = -1;
hid_t dset_id = -1;
hid_t space_id = -1;
herr_t err;
hsize_t dims[2];
ssize_t bytes_read;
ssize_t image_size;
hid_t memb_fapl[H5FD_MEM_NTYPES];
haddr_t memb_addr[H5FD_MEM_NTYPES];
H5FD_mem_t mt;
H5FD_mem_t memb_map[H5FD_MEM_NTYPES];
TESTING("H5Fget_file_image() error rejection");
/************************ Sub-Test #1 ********************************/
2020-04-21 07:12:00 +08:00
/* set up a test file, and try to get its image with a buffer that is
* too small. Call to H5Fget_file_image() should fail.
*
2020-04-21 07:12:00 +08:00
* Since we have already done the necessary setup, verify that
* H5Fget_file_image() will fail with:
*
* bad file id, or
*
* good id, but not a file id
*/
/* setup fapl -- driver type doesn't matter much, so make it stdio */
fapl_id = H5Pcreate(H5P_FILE_ACCESS);
VERIFY(fapl_id >= 0, "H5Pcreate(1) failed");
err = H5Pset_fapl_stdio(fapl_id);
VERIFY(err >= 0, "H5Pset_fapl_stdio() failed");
/* setup the file name */
h5_fixname(FILENAME2[6], fapl_id, file_name, sizeof(file_name));
2020-09-30 22:27:10 +08:00
VERIFY(HDstrlen(file_name) > 0, "h5_fixname failed");
/* create the file */
file_id = H5Fcreate(file_name, 0, H5P_DEFAULT, fapl_id);
VERIFY(file_id >= 0, "H5Fcreate() failed.");
/* Set up data space for new new data set */
2020-09-30 22:27:10 +08:00
dims[0] = 10;
dims[1] = 10;
space_id = H5Screate_simple(2, dims, dims);
VERIFY(space_id >= 0, "H5Screate() failed");
/* Create a dataset */
2020-09-30 22:27:10 +08:00
dset_id = H5Dcreate2(file_id, "dset 0", H5T_NATIVE_INT, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
VERIFY(dset_id >= 0, "H5Dcreate() failed");
/* write some data to the data set */
for (i = 0; i < 100; i++)
data[i] = i;
2020-09-30 22:27:10 +08:00
err = H5Dwrite(dset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, (void *)data);
VERIFY(err >= 0, "H5Dwrite() failed.");
2020-04-21 07:12:00 +08:00
/* Flush the file */
err = H5Fflush(file_id, H5F_SCOPE_GLOBAL);
VERIFY(err >= 0, "H5Fflush failed");
/* get the size of the file */
image_size = H5Fget_file_image(file_id, NULL, (size_t)0);
VERIFY(image_size > 0, "H5Fget_file_image(1 -- test 1) failed.");
/* allocate a buffer of the appropriate size */
image_ptr = HDmalloc((size_t)image_size);
VERIFY(image_ptr != NULL, "HDmalloc(1) failed.");
/* load the image of the file into the buffer */
H5E_BEGIN_TRY
{
bytes_read = H5Fget_file_image(file_id, image_ptr, (size_t)(image_size - 1));
}
2020-09-30 22:27:10 +08:00
H5E_END_TRY;
VERIFY(bytes_read < 0, "H5Fget_file_image(2 -- test 1) succeeded.");
/* Call H5Fget_file_image() with good buffer and buffer size,
* but non-existent file_id. Should fail.
*/
H5E_BEGIN_TRY
{
bytes_read = H5Fget_file_image((hid_t)0, image_ptr, (size_t)(image_size));
}
2020-09-30 22:27:10 +08:00
H5E_END_TRY;
VERIFY(bytes_read < 0, "H5Fget_file_image(3 -- test 1) succeeded.");
/* Call H5Fget_file_image() with good buffer and buffer size,
* but a file_id of the wrong type. Should fail.
*/
H5E_BEGIN_TRY
{
bytes_read = H5Fget_file_image(dset_id, image_ptr, (size_t)(image_size));
}
2020-09-30 22:27:10 +08:00
H5E_END_TRY;
VERIFY(bytes_read < 0, "H5Fget_file_image(4 -- test 1) succeeded.");
/* Close dset and space */
2020-04-21 07:12:00 +08:00
err = H5Dclose(dset_id);
VERIFY(err >= 0, "H5Dclose failed");
err = H5Sclose(space_id);
VERIFY(err >= 0, "H5Sclose failed");
/* close the test file */
err = H5Fclose(file_id);
VERIFY(err == SUCCEED, "H5Fclose(file_id) failed.");
/* tidy up */
h5_clean_files(FILENAME2, fapl_id);
/* discard the image buffer if it exists */
2020-09-30 22:27:10 +08:00
if (image_ptr != NULL)
HDfree(image_ptr);
/************************** Test #2 **********************************/
2020-04-21 07:12:00 +08:00
/* set up a multi file driver test file, and try to get its image
* with H5Fget_file_image(). Attempt should fail.
*/
/* setup parameters for multi file driver */
2020-09-30 22:27:10 +08:00
for (mt = (H5FD_mem_t)0; mt < H5FD_MEM_NTYPES; mt = (H5FD_mem_t)(mt + 1)) {
memb_addr[mt] = HADDR_UNDEF;
memb_fapl[mt] = H5P_DEFAULT;
memb_map[mt] = H5FD_MEM_DRAW;
memb_name[mt] = NULL;
}
memb_map[H5FD_MEM_SUPER] = H5FD_MEM_SUPER;
memb_fapl[H5FD_MEM_SUPER] = H5P_DEFAULT;
memb_name[H5FD_MEM_SUPER] = "%s-s.h5";
memb_addr[H5FD_MEM_SUPER] = 0;
memb_map[H5FD_MEM_BTREE] = H5FD_MEM_BTREE;
memb_fapl[H5FD_MEM_BTREE] = H5P_DEFAULT;
memb_name[H5FD_MEM_BTREE] = "%s-b.h5";
memb_addr[H5FD_MEM_BTREE] = memb_addr[H5FD_MEM_SUPER] + TYPE_SLICE;
2020-09-30 22:27:10 +08:00
memb_map[H5FD_MEM_DRAW] = H5FD_MEM_DRAW;
memb_fapl[H5FD_MEM_DRAW] = H5P_DEFAULT;
memb_name[H5FD_MEM_DRAW] = "%s-r.h5";
memb_addr[H5FD_MEM_DRAW] = memb_addr[H5FD_MEM_BTREE] + TYPE_SLICE;
memb_map[H5FD_MEM_GHEAP] = H5FD_MEM_GHEAP;
memb_fapl[H5FD_MEM_GHEAP] = H5P_DEFAULT;
memb_name[H5FD_MEM_GHEAP] = "%s-g.h5";
memb_addr[H5FD_MEM_GHEAP] = memb_addr[H5FD_MEM_DRAW] + TYPE_SLICE;
memb_map[H5FD_MEM_LHEAP] = H5FD_MEM_LHEAP;
memb_fapl[H5FD_MEM_LHEAP] = H5P_DEFAULT;
memb_name[H5FD_MEM_LHEAP] = "%s-l.h5";
memb_addr[H5FD_MEM_LHEAP] = memb_addr[H5FD_MEM_GHEAP] + TYPE_SLICE;
2020-09-30 22:27:10 +08:00
memb_map[H5FD_MEM_OHDR] = H5FD_MEM_OHDR;
memb_fapl[H5FD_MEM_OHDR] = H5P_DEFAULT;
memb_name[H5FD_MEM_OHDR] = "%s-o.h5";
memb_addr[H5FD_MEM_OHDR] = memb_addr[H5FD_MEM_LHEAP] + TYPE_SLICE;
/* setup fapl */
fapl_id = H5Pcreate(H5P_FILE_ACCESS);
VERIFY(fapl_id >= 0, "H5Pcreate(2) failed");
/* setup the fapl for the multi file driver */
2020-09-30 22:27:10 +08:00
err = H5Pset_fapl_multi(fapl_id, memb_map, memb_fapl, memb_name, memb_addr, FALSE);
VERIFY(err >= 0, "H5Pset_fapl_multi failed");
/* setup the file name */
h5_fixname(FILENAME2[4], fapl_id, file_name, sizeof(file_name));
2020-09-30 22:27:10 +08:00
VERIFY(HDstrlen(file_name) > 0, "h5_fixname failed");
/* create the file */
file_id = H5Fcreate(file_name, 0, H5P_DEFAULT, fapl_id);
VERIFY(file_id >= 0, "H5Fcreate() failed.");
/* Set up data space for new new data set */
2020-09-30 22:27:10 +08:00
dims[0] = 10;
dims[1] = 10;
space_id = H5Screate_simple(2, dims, dims);
VERIFY(space_id >= 0, "H5Screate() failed");
/* Create a dataset */
2020-09-30 22:27:10 +08:00
dset_id = H5Dcreate2(file_id, "dset 0", H5T_NATIVE_INT, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
VERIFY(dset_id >= 0, "H5Dcreate() failed");
/* write some data to the data set */
for (i = 0; i < 100; i++)
data[i] = i;
2020-09-30 22:27:10 +08:00
err = H5Dwrite(dset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, (void *)data);
VERIFY(err >= 0, "H5Dwrite() failed.");
2020-04-21 07:12:00 +08:00
/* Flush the file */
err = H5Fflush(file_id, H5F_SCOPE_GLOBAL);
VERIFY(err >= 0, "H5Fflush failed");
/* attempt to get the size of the file -- should fail */
H5E_BEGIN_TRY
{
image_size = H5Fget_file_image(file_id, NULL, (size_t)0);
}
2020-09-30 22:27:10 +08:00
H5E_END_TRY;
VERIFY(image_size == -1, "H5Fget_file_image(5) succeeded.");
/* Close dset and space */
2020-04-21 07:12:00 +08:00
err = H5Dclose(dset_id);
VERIFY(err >= 0, "H5Dclose failed");
err = H5Sclose(space_id);
VERIFY(err >= 0, "H5Sclose failed");
/* close the test file */
err = H5Fclose(file_id);
VERIFY(err == SUCCEED, "H5Fclose(2) failed.");
/* tidy up */
h5_clean_files(FILENAME2, fapl_id);
/************************** Test #3 **********************************/
2020-04-21 07:12:00 +08:00
/* set up a split file driver test file, and try to get its image
* with H5Fget_file_image(). Attempt should fail.
*/
2020-04-21 07:12:00 +08:00
/* create fapl */
fapl_id = H5Pcreate(H5P_FILE_ACCESS);
VERIFY(fapl_id >= 0, "H5Pcreate(3) failed");
/* setup the fapl for the split file driver */
err = H5Pset_fapl_split(fapl_id, "-m.h5", H5P_DEFAULT, "-r.h5", H5P_DEFAULT);
VERIFY(err >= 0, "H5Pset_fapl_split failed");
/* setup the file name */
h5_fixname(FILENAME2[5], fapl_id, file_name, sizeof(file_name));
2020-09-30 22:27:10 +08:00
VERIFY(HDstrlen(file_name) > 0, "h5_fixname failed");
/* create the file */
file_id = H5Fcreate(file_name, 0, H5P_DEFAULT, fapl_id);
VERIFY(file_id >= 0, "H5Fcreate() failed.");
/* Set up data space for new new data set */
2020-09-30 22:27:10 +08:00
dims[0] = 10;
dims[1] = 10;
space_id = H5Screate_simple(2, dims, dims);
VERIFY(space_id >= 0, "H5Screate() failed");
/* Create a dataset */
2020-09-30 22:27:10 +08:00
dset_id = H5Dcreate2(file_id, "dset 0", H5T_NATIVE_INT, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
VERIFY(dset_id >= 0, "H5Dcreate() failed");
/* write some data to the data set */
for (i = 0; i < 100; i++)
data[i] = i;
2020-09-30 22:27:10 +08:00
err = H5Dwrite(dset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, (void *)data);
VERIFY(err >= 0, "H5Dwrite() failed.");
2020-04-21 07:12:00 +08:00
/* Flush the file */
err = H5Fflush(file_id, H5F_SCOPE_GLOBAL);
VERIFY(err >= 0, "H5Fflush failed");
/* attempt to get the size of the file -- should fail */
H5E_BEGIN_TRY
{
image_size = H5Fget_file_image(file_id, NULL, (size_t)0);
}
2020-09-30 22:27:10 +08:00
H5E_END_TRY;
VERIFY(image_size == -1, "H5Fget_file_image(6) succeeded.");
/* Close dset and space */
2020-04-21 07:12:00 +08:00
err = H5Dclose(dset_id);
VERIFY(err >= 0, "H5Dclose failed");
err = H5Sclose(space_id);
VERIFY(err >= 0, "H5Sclose failed");
/* close the test file */
err = H5Fclose(file_id);
VERIFY(err == SUCCEED, "H5Fclose(2) failed.");
/* tidy up */
h5_clean_files(FILENAME2, fapl_id);
/************************** Test #4 **********************************/
2020-04-21 07:12:00 +08:00
/* set up a family file driver test file, and try to get its image
* with H5Fget_file_image(). Attempt should fail.
*/
2020-04-21 07:12:00 +08:00
/* create fapl */
fapl_id = H5Pcreate(H5P_FILE_ACCESS);
VERIFY(fapl_id >= 0, "H5Pcreate(3) failed");
err = H5Pset_fapl_family(fapl_id, (hsize_t)FAMILY_SIZE, H5P_DEFAULT);
VERIFY(err >= 0, "H5Pset_fapl_family failed");
h5_fixname(FILENAME2[3], fapl_id, file_name, sizeof(file_name));
2020-09-30 22:27:10 +08:00
VERIFY(HDstrlen(file_name) > 0, "h5_fixname failed");
/* create the file */
file_id = H5Fcreate(file_name, 0, H5P_DEFAULT, fapl_id);
VERIFY(file_id >= 0, "H5Fcreate() failed.");
/* Set up data space for new new data set */
2020-09-30 22:27:10 +08:00
dims[0] = 10;
dims[1] = 10;
space_id = H5Screate_simple(2, dims, dims);
VERIFY(space_id >= 0, "H5Screate() failed");
/* Create a dataset */
2020-09-30 22:27:10 +08:00
dset_id = H5Dcreate2(file_id, "dset 0", H5T_NATIVE_INT, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
VERIFY(dset_id >= 0, "H5Dcreate() failed");
/* write some data to the data set */
for (i = 0; i < 100; i++)
data[i] = i;
2020-09-30 22:27:10 +08:00
err = H5Dwrite(dset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, (void *)data);
VERIFY(err >= 0, "H5Dwrite() failed.");
2020-04-21 07:12:00 +08:00
/* Flush the file */
err = H5Fflush(file_id, H5F_SCOPE_GLOBAL);
VERIFY(err >= 0, "H5Fflush failed");
/* attempt to get the size of the file -- should fail */
H5E_BEGIN_TRY
{
image_size = H5Fget_file_image(file_id, NULL, (size_t)0);
}
2020-09-30 22:27:10 +08:00
H5E_END_TRY;
VERIFY(image_size == -1, "H5Fget_file_image(7) succeeded.");
/* Close dset and space */
2020-04-21 07:12:00 +08:00
err = H5Dclose(dset_id);
VERIFY(err >= 0, "H5Dclose failed");
err = H5Sclose(space_id);
VERIFY(err >= 0, "H5Sclose failed");
/* close the test file */
err = H5Fclose(file_id);
VERIFY(err == SUCCEED, "H5Fclose(2) failed.");
/* tidy up */
h5_clean_files(FILENAME2, fapl_id);
2020-04-21 07:12:00 +08:00
PASSED();
return 0;
error:
return 1;
} /* test_get_file_image_error_rejection() */
/*
* Modifications:
* Add testing for file image with or without user block in the file.
*/
int
main(void)
{
2020-09-30 22:27:10 +08:00
int errors = 0;
hid_t fapl;
Subfiling VFD (#1883) * Added support for vector I/O calls to the VFD layer, and associated test code. Note that this includes the optimization to allow shortened sizes and types arrays to allow more space efficient representations of vectors in which all entries are of the same size and/or type. See the Selection I/o RFC for further details. Tested serial and parallel, debug and production on Charis. serial and parallel debug only on Jelly. * ran code formatter quick serial build and test on jelly * Add H5FD_read_selection() and H5FD_write_selection(). Currently only translate to scalar calls. Fix const buf in H5FD_write_vector(). * Format source * Fix comments * Add selection I/O to chunk code, used when: not using chunk cache, no datatype conversion, no I/O filters, no page buffer, not using collective I/O. Requires global variable H5_use_selection_io_g be set to TRUE. Implemented selection to vector I/O transaltion at the file driver layer. * Fix formatting unrelated to previous change to stop github from complaining. * Add full API support for selection I/O. Add tests for this. * Implement selection I/O for contiguous datasets. Fix bug in selection I/O translation. Add const qualifiers to some internal selection I/O routines to maintain const-correctness while avoiding memcpys. * Added vector read / write support to the MPIO VFD, with associated test code (see testpar/t_vfd.c). Note that this implementation does NOT support vector entries of size greater than 2 GB. This must be repaired before release, but it should be good enough for correctness testing. As MPIO requires vector I/O requests to be sorted in increasing address order, also added a vector sort utility in H5FDint.c This function is tested in passing by the MPIO vector I/O extension. In passing, repaired a bug in size / type vector extension management in H5FD_read/write_vector() Tested parallel debug and production on charis and Jelly. * Ran source code formatter * Add support for independent parallel I/O with selection I/O. Add HDF5_USE_SELECTION_IO env var to control selection I/O (default off). * Implement parallel collective support for selection I/O. * Fix comments and run formatter. * Update selection IO branch with develop (#1215) Merged branch 'develop' into selection_io * Sync with develop (#1262) Updated the branch with develop changes. * Implement big I/O support for vector I/O requests in the MPIO file driver. * Free arrays in H5FD__mpio_read/write_vector() as soon as they're not needed, to cut down on memory usage during I/O. * Address comments from code review. Fix const warnings with H5S_SEL_ITER_INIT(). * Committing clang-format changes * Feature/subfiling (#1464) * Initial checkin of merged sub-filing VFD. Passes regression tests (debug/shared/paralle) on Jelly. However, bugs and many compiler warnings remain -- not suitable for merge to develop. * Minor mods to src/H5FDsubfile_mpi.c to address errors reported by autogen.sh * Code formatting run -- no test * Merged my subfiling code fixes into the new selection_io_branch * Forgot to add the FindMERCURY.cmake file. This will probably disappear soon * attempting to make a more reliable subfile file open which doesn't return errors. For some unknown reason, the regular posix open will occasionally fail to create a subfile. Some better error handling for file close has been added. * added NULL option for H5FD_subfiling_config_t in H5Pset_fapl_subfiling (#1034) * NULL option automatically stacks IOC VFD for subfiling and returns a valid fapl. * added doxygen subfiling APIs * Various fixes which allow the IOR benchmark to run correctly * Lots of updates including the packaging up of the mercury_util source files to enable easier builds for our Benchmarking * Interim checkin of selection_io_with_subfiling_vfd branch Moddified testpar/t_vfd.c to test the subfiling vfd with default configuration. Must update this code to run with a variety of configurations -- most particularly multiple IO concentrators, and stripe depth small enough to test the other IO concentrators. testpar/t_vfd.c exposed a large number of race condidtions -- symtoms included: 1) Crashes (usually seg faults) 2) Heap corruption 3) Stack corruption 4) Double frees of heap space 5) Hangs 6) Out of order execution of I/O requests / violations of POSIX semantics 7) Swapped write requests Items 1 - 4 turned out to be primarily caused by file close issues -- specifically, the main I/O concentrator thread and its pool of worker threads were not being shut down properly on file close. Addressing this issue in combination with some other minor fixes seems to have addressed these issues. Items 5 & 6 appear to have been caused by issue of I/O requests to the thread pool in an order that did not maintain POSIX semantics. A rewrite of the I/O request dispatch code appears to have solved these issues. Item 7 seems to have been caused by multiple write requests from a given rank being read by the wrong worker thread. Code to issue "unique" tags for each write request via the ACK message appears to have cleaned this up. Note that the code is still in poor condtition. A partial list of known defects includes: a) Race condiditon on file close that allows superblock writes to arrive at the I/O concentrator after it has been shutdown. This defect is most evident when testpar/t_subfiling_vfd is run with 8 ranks. b) No error reporting from I/O concentrators -- must design and implement this. For now, mostly just asserts, which suggests that it should be run in debug mode. c) Much commented out and/or un-used code. d) Code orgnaization e) Build system with bits of Mercury is awkward -- think of shifting to pthreads with our own thread pool code. f) Need to add native support for vector and selection I/O to the subfiling VFD. g) Need to review, and posibly rework configuration code. h) Need to store subfile configuration data in a superblock extension message, and add code to use this data on file open. i) Test code is inadequate -- expect more issues as it is extended. In particular, there is no unit test code for the I/O request dispatch code. While I think it is correct at present, we need test code to verify this. Similarly, we need to test with multiple I/O concentrators and much smaller stripe depth. My actual code changes were limited to: src/H5FDioc.c src/H5FDioc_threads.c src/H5FDsubfile_int.c src/H5FDsubfile_mpi.c src/H5FDsubfiling.c src/H5FDsubfiling.h src/H5FDsubfiling_priv.h testpar/t_subfiling_vfd.c testpar/t_vfd.c I'm not sure what is going on with the deletions in src/mercury/src/util. Tested parallel/debug on Charis and Jelly * subfiling with selection IO (#1219) Merged branch 'selection_io' into subfiling branch. * Subfile name fixes (#1250) * fixed subfiling naming convention, and added leading zero to rank names. * Merge branch 'selection_io' into selection_io_with_subfiling_vfd (#1265) * Added script to join subfiles into a single HDF5 file (#1350) * Modified H5FD__subfiling_query() to report that the sub-filing VFD supports MPI This exposed issues with truncate and get EOF in the sub-filing VFD. I believe I have addressed these issues (get EOF not as fully tested as it should be), howeer, it exposed race conditions resulting in hangs. As of this writing, I have not been able to chase these down. Note that the tests that expose these race conditions are in testpar/t_subfiling_vfd.c, and are currently skipped. Unskip these tests to reproduce the race conditions. tested (to the extent possible) debug/parallel on charis and jelly. * Committing clang-format changes * fixed H5MM_free Co-authored-by: mainzer <mainzer#hdfgroup.org> Co-authored-by: jrmainzer <72230804+jrmainzer@users.noreply.github.com> Co-authored-by: Richard Warren <Richard.Warren@hdfgroup.org> Co-authored-by: Richard.Warren <richard.warren@jelly.ad.hdfgroup.org> Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> * Move Subfiling VFD components into H5FDsubfiling source directory * Update Autotools build and add H5_HAVE_SUBFILING_VFD macro to H5pubconf.h * Tidy up CMake build of subfiling sources * Merge branch 'develop' into feature/subfiling (#1539) Merge branch 'develop' into feature/subfiling * Add VFD interface version field to Subfiling and IOC VFDs * Merge branch 'develop' into feature/subfiling (#1557) Merge branch 'develop' into feature/subfiling * Merge branch 'develop' into feature/subfiling (#1563) Merge branch 'develop' into feature/subfiling * Tidy up merge artifacts after rebase on develop * Fix incorrect variable in mirror VFD utils CMake * Ensure VFD values are always defined * Add subfiling to CMake VFD_LIST if built * Mark MPI I/O driver self-initialization global as static * Add Subfiling VFD to predefined VFDs for HDF5_DRIVER env. variable * Initial progress towards separating private vs. public subfiling code * include libgen.h in t_vfd tests for correct dirname/basename * Committing clang-format changes * removed mercury option, included subfiling header path (#1577) Added subfiling status to configure output, installed h5fuse.sh to build directory for use in future tests. * added check for stdatomic.h (#1578) * added check for stdatomic.h with subfiling * added H5_HAVE_SUBFILING_VFD for cmake * fix old-style-definition warning (#1582) * fix old-style-definition warning * added test for enable parallel with subfiling VFD (#1586) Fails if subfiling VFD is not used with parallel support. * Subfiling/IOC VFD fixes and tidying (#1619) * Rename CMake option for Subfiling VFD to be consistent with other VFDs * Miscellaneous Subfiling fixes Add error message for unset MPI communicator Support dynamic loading of subfiling VFD with default configuration * Temporary fix for subfile name issue * Added subfile checks (#1634) * added subfile checks * Feature/subfiling (#1655) * Subfiling/IOC VFD cleanup Fix misuse of MPI_COMM_WORLD in IOC VFD Propagate Subfiling FAPL MPI settings down to IOC FAPL in default configuration case Cleanup IOC VFD debugging code Change sprintf to snprintf in a few places * Major work on separating Subfiling and IOC VFDs from each other * Re-write async_completion func to not overuse stack * Replace usage of MPI_COMM_WORLD with file's actual MPI communicator * Refactor H5FDsubfile_mpi.c * Remove empty file H5FDsubfile_mpi.c * Separate IOC VFD errors to its own error stack * Committing clang-format changes * Remove H5TRACE macros from H5FDioc.c * Integrate H5FDioc_threads.c with IOC error stack * Fix for subfile name generation Use number of I/O concentrators from existing subfiling configuration file, if one exists * Add temporary barrier in "Get EOF" operation to prevent races on EOF Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> * Fix for retrieval of machine Host ID * Default to MPI_COMM_WORLD if no MPI params set * added libs rt and pthreads (#1673) * added libs rt and pthreads * Feature/subfiling (#1689) * More tidying of IOC VFD and subfiling debug code * Remove old unused log file code * Clear FID from active file map on failure * Fix bug in generation of subfile names when truncating file * Change subfile names to start from 1 instead of 0 * Use long long for user-specified stripe size from environment variable * Skip 0-sized I/Os in low-level IOC I/O routines * Don't update EOF on read * Convert printed warning about data size mismatch to assertion * Don't add base file address to I/O addresses twice Base address should already be applied as part of H5FDwrite/read_vector calls * Account for 0-sized I/O vector entries in subfile write/read functions * Rewrite init_indep_io for clarity * Correction for IOC wraparound calculations * Some corrections to iovec calculations * Remove temporary barrier on EOF retrieval * Complete work request queue entry on error instead of skipping over * Account for stripe size wraparound for sf_col_offset calculation * Committing clang-format changes Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> * Re-write and fix bugs in I/O vector filling routines (#1703) * Rewrite I/O vector filling routines for clarity * Fix bug with iovec_fill_last when last I/O size is 0 * added subfiling_dir line read (#1714) * added subfiling_dir line read and use it * shellcheck fixes * I/O request dispatch logic update (#1731) Short-circuit I/O request dispatch when head of I/O queue is an in-progress get EOF or truncate operation. This prevents an issue where a write operation can be dispatched alongside a get EOF/truncate operation, whereas all I/O requests are supposed to be ineligible for dispatch until the get EOF/truncate is completed * h5fuse.sh.in clean-up (#1757) * Added command-line options * Committing clang-format changes * Align with changes from develop * Mimic MPI I/O VFD for EOF handling * Initialize context_id field for work request objects * Use logfile for some debugging information * Use atomic store to set IOC ready flag * Use separate communicator for sending file EOF data Minor IOC cleanup * Use H5_subfile_fid_to_context to get context ID for file in Subfiling VFD * IOVEC calculation fixes * Updates for debugging code * Minor fixes for threaded code * Committing clang-format changes * Use separate MPI communicator for barrier operations * Committing clang-format changes * Rewrite EOF routine to use nonblocking MPI communication * Committing clang-format changes * Always dispatch I/O work requests in IOC main loop * Return distinct MPI communicator to library when requested * Minor warning cleanup * Committing clang-format changes * Generate h5fuse.sh from h5fuse.sh.in in CMake * Send truncate messages to correct IOC rank * Committing clang-format changes * Miscellaneous cleanup Post some MPI receives before sends Free some duplicated MPI communicator/Info objects Remove unnecessary extra MPI_Barrier * Warning cleanup * Fix for leaked MPI communicator * Retrieve file EOF on single rank and bcast it * Fixes for a few failure paths * Cleanup of IOC file opens * Committing clang-format changes * Use plan MPI_Send for send of EOF messages * Always check MPI thread support level during Subfiling init * Committing clang-format changes * Handle a hang on failure when IOCs can't open subfiles * Committing clang-format changes * Refactor file open status consensus check * Committing clang-format changes * Fix for MPI_Comm_free being called after MPI_Finalize * Fix VFD test by setting MPI params before setting subfiling on FAPL * Update Subfiling VFD error handling and error stack usage * Improvements for Subfiling logfiles * Remove prototypes for currently unused routines * Disable I/O queue stat collecting by default * Remove unused serialization mutex variable * Update VFD testing to take subfiling VFD into account * Fix usage of global subfiling application layout object * Minor fixes for failure pathways * Keep track of the number of failures in an IOC I/O queue * Make sure not to exceed MPI_TAG_UB value for data communication messages * Committing clang-format changes * Update for rename of some H5FD 'ctl' opcodes * Always include Subfiling's public header files in hdf5.h * Remove old unused code and comments * Implement support for per-file I/O queues Allows the subfiling VFD to have multiple HDF5 files open simultaneously * Use simple MPI_Iprobe over unnecessary MPI_Improbe * Committing clang-format changes * Update HDF5 testing to query driver for H5FD_FEAT_DEFAULT_VFD_COMPATIBLE flag * Fix a few bugs related to file multi-opens * Avoid calling MPI routines if subfiling gets reinitialized * Fix issue when files are closed in a random order * Update HDF5 testing to query VFD for "using MPI" feature flag * Register atexit handler in subfiling VFD to call MPI_Finalize after HDF5 closes * Fail for collective I/O requests until support is implemented * Correct VOL test function prototypes * Minor cleanup of old code and comments * Update mercury dependency * Cleanup of subfiling configuration structure * Committing clang-format changes * Build system updates for Subfiling VFD * Fix possible hang on failure in t_vfd tests caused by mismatched MPI_Barrier calls * Copy subfiling IOC fapl in "fapl get" method * Mirror subfiling superblock writes to stub file for legacy POSIX-y HDF5 applications * Allow collective I/O for MPI_BYTE types and rank 0 bcast strategy * Committing clang-format changes * Use different scheme for subfiling write message MPI tag calculations * Committing clang-format changes * Avoid performing fstat calls on all MPI ranks * Add MPI_Barrier before finalizing IOC threads * Use try_lock in I/O queue dispatch to minimize contention from worker threads * Use simple Waitall for nonblocking I/O waits * Add configurable IOC main thread delay and try_lock option to I/O queue dispatch * Fix bug that could cause serialization of non-overlapping I/O requests * Temporarily treat collective subfiling vector I/O calls as independent * Removed unused mercury bits * Add stubs for subfiling and IOC file delete callback * Update VFD testing for Subfiling VFD * Work around HDF5 metadata cache bug for Subfiling VFD when MPI Comm size = 1 * Committing clang-format changes Co-authored-by: mainzer <mainzer#hdfgroup.org> Co-authored-by: Neil Fortner <nfortne2@hdfgroup.org> Co-authored-by: Scot Breitenfeld <brtnfld@hdfgroup.org> Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: jrmainzer <72230804+jrmainzer@users.noreply.github.com> Co-authored-by: Richard Warren <Richard.Warren@hdfgroup.org> Co-authored-by: Richard.Warren <richard.warren@jelly.ad.hdfgroup.org>
2022-07-23 04:03:12 +08:00
hbool_t driver_is_default_compatible;
unsigned user;
h5_reset();
HDprintf("Testing File Image Functionality.\n");
errors += test_properties();
errors += test_callbacks();
Subfiling VFD (#1883) * Added support for vector I/O calls to the VFD layer, and associated test code. Note that this includes the optimization to allow shortened sizes and types arrays to allow more space efficient representations of vectors in which all entries are of the same size and/or type. See the Selection I/o RFC for further details. Tested serial and parallel, debug and production on Charis. serial and parallel debug only on Jelly. * ran code formatter quick serial build and test on jelly * Add H5FD_read_selection() and H5FD_write_selection(). Currently only translate to scalar calls. Fix const buf in H5FD_write_vector(). * Format source * Fix comments * Add selection I/O to chunk code, used when: not using chunk cache, no datatype conversion, no I/O filters, no page buffer, not using collective I/O. Requires global variable H5_use_selection_io_g be set to TRUE. Implemented selection to vector I/O transaltion at the file driver layer. * Fix formatting unrelated to previous change to stop github from complaining. * Add full API support for selection I/O. Add tests for this. * Implement selection I/O for contiguous datasets. Fix bug in selection I/O translation. Add const qualifiers to some internal selection I/O routines to maintain const-correctness while avoiding memcpys. * Added vector read / write support to the MPIO VFD, with associated test code (see testpar/t_vfd.c). Note that this implementation does NOT support vector entries of size greater than 2 GB. This must be repaired before release, but it should be good enough for correctness testing. As MPIO requires vector I/O requests to be sorted in increasing address order, also added a vector sort utility in H5FDint.c This function is tested in passing by the MPIO vector I/O extension. In passing, repaired a bug in size / type vector extension management in H5FD_read/write_vector() Tested parallel debug and production on charis and Jelly. * Ran source code formatter * Add support for independent parallel I/O with selection I/O. Add HDF5_USE_SELECTION_IO env var to control selection I/O (default off). * Implement parallel collective support for selection I/O. * Fix comments and run formatter. * Update selection IO branch with develop (#1215) Merged branch 'develop' into selection_io * Sync with develop (#1262) Updated the branch with develop changes. * Implement big I/O support for vector I/O requests in the MPIO file driver. * Free arrays in H5FD__mpio_read/write_vector() as soon as they're not needed, to cut down on memory usage during I/O. * Address comments from code review. Fix const warnings with H5S_SEL_ITER_INIT(). * Committing clang-format changes * Feature/subfiling (#1464) * Initial checkin of merged sub-filing VFD. Passes regression tests (debug/shared/paralle) on Jelly. However, bugs and many compiler warnings remain -- not suitable for merge to develop. * Minor mods to src/H5FDsubfile_mpi.c to address errors reported by autogen.sh * Code formatting run -- no test * Merged my subfiling code fixes into the new selection_io_branch * Forgot to add the FindMERCURY.cmake file. This will probably disappear soon * attempting to make a more reliable subfile file open which doesn't return errors. For some unknown reason, the regular posix open will occasionally fail to create a subfile. Some better error handling for file close has been added. * added NULL option for H5FD_subfiling_config_t in H5Pset_fapl_subfiling (#1034) * NULL option automatically stacks IOC VFD for subfiling and returns a valid fapl. * added doxygen subfiling APIs * Various fixes which allow the IOR benchmark to run correctly * Lots of updates including the packaging up of the mercury_util source files to enable easier builds for our Benchmarking * Interim checkin of selection_io_with_subfiling_vfd branch Moddified testpar/t_vfd.c to test the subfiling vfd with default configuration. Must update this code to run with a variety of configurations -- most particularly multiple IO concentrators, and stripe depth small enough to test the other IO concentrators. testpar/t_vfd.c exposed a large number of race condidtions -- symtoms included: 1) Crashes (usually seg faults) 2) Heap corruption 3) Stack corruption 4) Double frees of heap space 5) Hangs 6) Out of order execution of I/O requests / violations of POSIX semantics 7) Swapped write requests Items 1 - 4 turned out to be primarily caused by file close issues -- specifically, the main I/O concentrator thread and its pool of worker threads were not being shut down properly on file close. Addressing this issue in combination with some other minor fixes seems to have addressed these issues. Items 5 & 6 appear to have been caused by issue of I/O requests to the thread pool in an order that did not maintain POSIX semantics. A rewrite of the I/O request dispatch code appears to have solved these issues. Item 7 seems to have been caused by multiple write requests from a given rank being read by the wrong worker thread. Code to issue "unique" tags for each write request via the ACK message appears to have cleaned this up. Note that the code is still in poor condtition. A partial list of known defects includes: a) Race condiditon on file close that allows superblock writes to arrive at the I/O concentrator after it has been shutdown. This defect is most evident when testpar/t_subfiling_vfd is run with 8 ranks. b) No error reporting from I/O concentrators -- must design and implement this. For now, mostly just asserts, which suggests that it should be run in debug mode. c) Much commented out and/or un-used code. d) Code orgnaization e) Build system with bits of Mercury is awkward -- think of shifting to pthreads with our own thread pool code. f) Need to add native support for vector and selection I/O to the subfiling VFD. g) Need to review, and posibly rework configuration code. h) Need to store subfile configuration data in a superblock extension message, and add code to use this data on file open. i) Test code is inadequate -- expect more issues as it is extended. In particular, there is no unit test code for the I/O request dispatch code. While I think it is correct at present, we need test code to verify this. Similarly, we need to test with multiple I/O concentrators and much smaller stripe depth. My actual code changes were limited to: src/H5FDioc.c src/H5FDioc_threads.c src/H5FDsubfile_int.c src/H5FDsubfile_mpi.c src/H5FDsubfiling.c src/H5FDsubfiling.h src/H5FDsubfiling_priv.h testpar/t_subfiling_vfd.c testpar/t_vfd.c I'm not sure what is going on with the deletions in src/mercury/src/util. Tested parallel/debug on Charis and Jelly * subfiling with selection IO (#1219) Merged branch 'selection_io' into subfiling branch. * Subfile name fixes (#1250) * fixed subfiling naming convention, and added leading zero to rank names. * Merge branch 'selection_io' into selection_io_with_subfiling_vfd (#1265) * Added script to join subfiles into a single HDF5 file (#1350) * Modified H5FD__subfiling_query() to report that the sub-filing VFD supports MPI This exposed issues with truncate and get EOF in the sub-filing VFD. I believe I have addressed these issues (get EOF not as fully tested as it should be), howeer, it exposed race conditions resulting in hangs. As of this writing, I have not been able to chase these down. Note that the tests that expose these race conditions are in testpar/t_subfiling_vfd.c, and are currently skipped. Unskip these tests to reproduce the race conditions. tested (to the extent possible) debug/parallel on charis and jelly. * Committing clang-format changes * fixed H5MM_free Co-authored-by: mainzer <mainzer#hdfgroup.org> Co-authored-by: jrmainzer <72230804+jrmainzer@users.noreply.github.com> Co-authored-by: Richard Warren <Richard.Warren@hdfgroup.org> Co-authored-by: Richard.Warren <richard.warren@jelly.ad.hdfgroup.org> Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> * Move Subfiling VFD components into H5FDsubfiling source directory * Update Autotools build and add H5_HAVE_SUBFILING_VFD macro to H5pubconf.h * Tidy up CMake build of subfiling sources * Merge branch 'develop' into feature/subfiling (#1539) Merge branch 'develop' into feature/subfiling * Add VFD interface version field to Subfiling and IOC VFDs * Merge branch 'develop' into feature/subfiling (#1557) Merge branch 'develop' into feature/subfiling * Merge branch 'develop' into feature/subfiling (#1563) Merge branch 'develop' into feature/subfiling * Tidy up merge artifacts after rebase on develop * Fix incorrect variable in mirror VFD utils CMake * Ensure VFD values are always defined * Add subfiling to CMake VFD_LIST if built * Mark MPI I/O driver self-initialization global as static * Add Subfiling VFD to predefined VFDs for HDF5_DRIVER env. variable * Initial progress towards separating private vs. public subfiling code * include libgen.h in t_vfd tests for correct dirname/basename * Committing clang-format changes * removed mercury option, included subfiling header path (#1577) Added subfiling status to configure output, installed h5fuse.sh to build directory for use in future tests. * added check for stdatomic.h (#1578) * added check for stdatomic.h with subfiling * added H5_HAVE_SUBFILING_VFD for cmake * fix old-style-definition warning (#1582) * fix old-style-definition warning * added test for enable parallel with subfiling VFD (#1586) Fails if subfiling VFD is not used with parallel support. * Subfiling/IOC VFD fixes and tidying (#1619) * Rename CMake option for Subfiling VFD to be consistent with other VFDs * Miscellaneous Subfiling fixes Add error message for unset MPI communicator Support dynamic loading of subfiling VFD with default configuration * Temporary fix for subfile name issue * Added subfile checks (#1634) * added subfile checks * Feature/subfiling (#1655) * Subfiling/IOC VFD cleanup Fix misuse of MPI_COMM_WORLD in IOC VFD Propagate Subfiling FAPL MPI settings down to IOC FAPL in default configuration case Cleanup IOC VFD debugging code Change sprintf to snprintf in a few places * Major work on separating Subfiling and IOC VFDs from each other * Re-write async_completion func to not overuse stack * Replace usage of MPI_COMM_WORLD with file's actual MPI communicator * Refactor H5FDsubfile_mpi.c * Remove empty file H5FDsubfile_mpi.c * Separate IOC VFD errors to its own error stack * Committing clang-format changes * Remove H5TRACE macros from H5FDioc.c * Integrate H5FDioc_threads.c with IOC error stack * Fix for subfile name generation Use number of I/O concentrators from existing subfiling configuration file, if one exists * Add temporary barrier in "Get EOF" operation to prevent races on EOF Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> * Fix for retrieval of machine Host ID * Default to MPI_COMM_WORLD if no MPI params set * added libs rt and pthreads (#1673) * added libs rt and pthreads * Feature/subfiling (#1689) * More tidying of IOC VFD and subfiling debug code * Remove old unused log file code * Clear FID from active file map on failure * Fix bug in generation of subfile names when truncating file * Change subfile names to start from 1 instead of 0 * Use long long for user-specified stripe size from environment variable * Skip 0-sized I/Os in low-level IOC I/O routines * Don't update EOF on read * Convert printed warning about data size mismatch to assertion * Don't add base file address to I/O addresses twice Base address should already be applied as part of H5FDwrite/read_vector calls * Account for 0-sized I/O vector entries in subfile write/read functions * Rewrite init_indep_io for clarity * Correction for IOC wraparound calculations * Some corrections to iovec calculations * Remove temporary barrier on EOF retrieval * Complete work request queue entry on error instead of skipping over * Account for stripe size wraparound for sf_col_offset calculation * Committing clang-format changes Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> * Re-write and fix bugs in I/O vector filling routines (#1703) * Rewrite I/O vector filling routines for clarity * Fix bug with iovec_fill_last when last I/O size is 0 * added subfiling_dir line read (#1714) * added subfiling_dir line read and use it * shellcheck fixes * I/O request dispatch logic update (#1731) Short-circuit I/O request dispatch when head of I/O queue is an in-progress get EOF or truncate operation. This prevents an issue where a write operation can be dispatched alongside a get EOF/truncate operation, whereas all I/O requests are supposed to be ineligible for dispatch until the get EOF/truncate is completed * h5fuse.sh.in clean-up (#1757) * Added command-line options * Committing clang-format changes * Align with changes from develop * Mimic MPI I/O VFD for EOF handling * Initialize context_id field for work request objects * Use logfile for some debugging information * Use atomic store to set IOC ready flag * Use separate communicator for sending file EOF data Minor IOC cleanup * Use H5_subfile_fid_to_context to get context ID for file in Subfiling VFD * IOVEC calculation fixes * Updates for debugging code * Minor fixes for threaded code * Committing clang-format changes * Use separate MPI communicator for barrier operations * Committing clang-format changes * Rewrite EOF routine to use nonblocking MPI communication * Committing clang-format changes * Always dispatch I/O work requests in IOC main loop * Return distinct MPI communicator to library when requested * Minor warning cleanup * Committing clang-format changes * Generate h5fuse.sh from h5fuse.sh.in in CMake * Send truncate messages to correct IOC rank * Committing clang-format changes * Miscellaneous cleanup Post some MPI receives before sends Free some duplicated MPI communicator/Info objects Remove unnecessary extra MPI_Barrier * Warning cleanup * Fix for leaked MPI communicator * Retrieve file EOF on single rank and bcast it * Fixes for a few failure paths * Cleanup of IOC file opens * Committing clang-format changes * Use plan MPI_Send for send of EOF messages * Always check MPI thread support level during Subfiling init * Committing clang-format changes * Handle a hang on failure when IOCs can't open subfiles * Committing clang-format changes * Refactor file open status consensus check * Committing clang-format changes * Fix for MPI_Comm_free being called after MPI_Finalize * Fix VFD test by setting MPI params before setting subfiling on FAPL * Update Subfiling VFD error handling and error stack usage * Improvements for Subfiling logfiles * Remove prototypes for currently unused routines * Disable I/O queue stat collecting by default * Remove unused serialization mutex variable * Update VFD testing to take subfiling VFD into account * Fix usage of global subfiling application layout object * Minor fixes for failure pathways * Keep track of the number of failures in an IOC I/O queue * Make sure not to exceed MPI_TAG_UB value for data communication messages * Committing clang-format changes * Update for rename of some H5FD 'ctl' opcodes * Always include Subfiling's public header files in hdf5.h * Remove old unused code and comments * Implement support for per-file I/O queues Allows the subfiling VFD to have multiple HDF5 files open simultaneously * Use simple MPI_Iprobe over unnecessary MPI_Improbe * Committing clang-format changes * Update HDF5 testing to query driver for H5FD_FEAT_DEFAULT_VFD_COMPATIBLE flag * Fix a few bugs related to file multi-opens * Avoid calling MPI routines if subfiling gets reinitialized * Fix issue when files are closed in a random order * Update HDF5 testing to query VFD for "using MPI" feature flag * Register atexit handler in subfiling VFD to call MPI_Finalize after HDF5 closes * Fail for collective I/O requests until support is implemented * Correct VOL test function prototypes * Minor cleanup of old code and comments * Update mercury dependency * Cleanup of subfiling configuration structure * Committing clang-format changes * Build system updates for Subfiling VFD * Fix possible hang on failure in t_vfd tests caused by mismatched MPI_Barrier calls * Copy subfiling IOC fapl in "fapl get" method * Mirror subfiling superblock writes to stub file for legacy POSIX-y HDF5 applications * Allow collective I/O for MPI_BYTE types and rank 0 bcast strategy * Committing clang-format changes * Use different scheme for subfiling write message MPI tag calculations * Committing clang-format changes * Avoid performing fstat calls on all MPI ranks * Add MPI_Barrier before finalizing IOC threads * Use try_lock in I/O queue dispatch to minimize contention from worker threads * Use simple Waitall for nonblocking I/O waits * Add configurable IOC main thread delay and try_lock option to I/O queue dispatch * Fix bug that could cause serialization of non-overlapping I/O requests * Temporarily treat collective subfiling vector I/O calls as independent * Removed unused mercury bits * Add stubs for subfiling and IOC file delete callback * Update VFD testing for Subfiling VFD * Work around HDF5 metadata cache bug for Subfiling VFD when MPI Comm size = 1 * Committing clang-format changes Co-authored-by: mainzer <mainzer#hdfgroup.org> Co-authored-by: Neil Fortner <nfortne2@hdfgroup.org> Co-authored-by: Scot Breitenfeld <brtnfld@hdfgroup.org> Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: jrmainzer <72230804+jrmainzer@users.noreply.github.com> Co-authored-by: Richard Warren <Richard.Warren@hdfgroup.org> Co-authored-by: Richard.Warren <richard.warren@jelly.ad.hdfgroup.org>
2022-07-23 04:03:12 +08:00
if (h5_driver_is_default_vfd_compatible(H5P_DEFAULT, &driver_is_default_compatible) < 0)
errors++;
else if (driver_is_default_compatible) {
errors += test_core();
}
/* Perform tests with/without user block */
2020-09-30 22:27:10 +08:00
for (user = FALSE; user <= TRUE; user++) {
/* test H5Fget_file_image() with sec2 driver */
fapl = H5Pcreate(H5P_FILE_ACCESS);
if (H5Pset_fapl_sec2(fapl) < 0)
errors++;
else
errors += test_get_file_image("H5Fget_file_image() with sec2 driver", 0, fapl, user);
/* test H5Fget_file_image() with stdio driver */
fapl = H5Pcreate(H5P_FILE_ACCESS);
if (H5Pset_fapl_stdio(fapl) < 0)
errors++;
else
errors += test_get_file_image("H5Fget_file_image() with stdio driver", 1, fapl, user);
/* test H5Fget_file_image() with core driver */
fapl = H5Pcreate(H5P_FILE_ACCESS);
if (H5Pset_fapl_core(fapl, (size_t)(64 * 1024), TRUE) < 0)
errors++;
else
errors += test_get_file_image("H5Fget_file_image() with core driver", 2, fapl, user);
} /* end for */
#if 0
2020-04-21 07:12:00 +08:00
/* at present, H5Fget_file_image() rejects files opened with the
* family file driver, due to the addition of a driver info message
* in the super block. This message prevents the image being opened
2020-04-21 07:12:00 +08:00
* with any driver other than the family file driver, which sort of
* defeats the purpose of the get file image operation.
*
* While this issues is quite fixable, we don't have time or resources
2020-04-21 07:12:00 +08:00
* for this right now. Once we do, the following code should be
* suitable for testing the fix.
*/
/* test H5Fget_file_image() with family file driver */
fapl = H5Pcreate(H5P_FILE_ACCESS);
if(H5Pset_fapl_family(fapl, (hsize_t)FAMILY_SIZE, H5P_DEFAULT) < 0)
errors++;
else
errors += test_get_file_image("H5Fget_file_image() with family driver",
3, fapl);
#endif
errors += test_get_file_image_error_rejection();
/* Restore the default error handler (set in h5_reset()) */
h5_restore_err();
2020-09-30 22:27:10 +08:00
if (errors) {
HDprintf("***** %d File Image TEST%s FAILED! *****\n", errors, errors > 1 ? "S" : "");
2020-04-21 07:12:00 +08:00
return 1;
}
HDprintf("All File Image tests passed.\n");
return 0;
}