summaryrefslogtreecommitdiffstats
path: root/test/h5test.c
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2017-03-29 21:44:23 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2017-03-29 21:44:23 (GMT)
commitba2cfde1fda880bf9d4b18dd439100ee5c4680bb (patch)
treeb071863eb782a1ad32e161a60197f33e30cdf5be /test/h5test.c
parent096aac122ed6b6e8d07a30330bd95992887cd2be (diff)
downloadhdf5-ba2cfde1fda880bf9d4b18dd439100ee5c4680bb.zip
hdf5-ba2cfde1fda880bf9d4b18dd439100ee5c4680bb.tar.gz
hdf5-ba2cfde1fda880bf9d4b18dd439100ee5c4680bb.tar.bz2
Merge/port changes from develop back to 1.8 for tools and cmake
Diffstat (limited to 'test/h5test.c')
-rw-r--r--test/h5test.c419
1 files changed, 306 insertions, 113 deletions
diff --git a/test/h5test.c b/test/h5test.c
index 4d841f1..188c12f 100644
--- a/test/h5test.c
+++ b/test/h5test.c
@@ -22,8 +22,7 @@
*/
#undef NDEBUG /*override -DNDEBUG */
-#include <sys/types.h>
-#include <sys/stat.h>
+
#include "h5test.h"
#include "H5srcdir.h"
@@ -75,7 +74,7 @@ char *paraprefix = NULL; /* for command line option para-prefix */
MPI_Info h5_io_info_g=MPI_INFO_NULL;/* MPI INFO object for IO */
#endif
-#define READ_BUF_SIZE 4096
+#define READ_BUF_SIZE 65536
/*
* These are the letters that are appended to the file name when generating
@@ -91,6 +90,12 @@ MPI_Info h5_io_info_g=MPI_INFO_NULL;/* MPI INFO object for IO */
*/
static const char *multi_letters = "msbrglo";
+/* Length of multi-file VFD filename buffers */
+#define H5TEST_MULTI_FILENAME_LEN 1024
+
+/* Previous error reporting function */
+static H5E_auto2_t err_func = NULL;
+
static herr_t h5_errors(hid_t estack, void *client_data);
static char * h5_fixname_real(const char *base_name, hid_t fapl, const char *suffix,
char *fullname, size_t size);
@@ -120,77 +125,228 @@ h5_errors(hid_t estack, void H5_ATTR_UNUSED *client_data)
return 0;
}
-
+
/*-------------------------------------------------------------------------
- * Function: h5_cleanup
+ * Function: h5_clean_files
*
- * Purpose: Cleanup temporary test files.
+ * Purpose: Cleanup temporary test files (always).
* base_name contains the list of test file names.
- * The file access property list is also closed.
*
- * Return: Non-zero if cleanup actions were performed; zero otherwise.
+ * Return: void
*
- * Programmer: Albert Cheng
- * May 28, 1998
+ * Programmer: Neil Fortner
+ * June 1, 2015
*
*-------------------------------------------------------------------------
*/
-int
-h5_cleanup(const char *base_name[], hid_t fapl)
+void
+h5_clean_files(const char *base_name[], hid_t fapl)
{
- int retval = 0;
+ int i;
- if(GetTestCleanup()) {
- int i;
+ for(i = 0; base_name[i]; i++) {
+ char filename[1024];
+ char temp[2048];
+ hid_t driver;
+
+ if(NULL == h5_fixname(base_name[i], fapl, filename, sizeof(filename)))
+ continue;
- for(i = 0; base_name[i]; i++) {
- char filename[1024];
- char temp[2048];
- hid_t driver;
+ driver = H5Pget_driver(fapl);
- if(NULL == h5_fixname(base_name[i], fapl, filename, sizeof(filename)))
- continue;
+ if(driver == H5FD_FAMILY) {
+ int j;
- driver = H5Pget_driver(fapl);
+ for(j = 0; /*void*/; j++) {
+ HDsnprintf(temp, sizeof temp, filename, j);
- if(driver == H5FD_FAMILY) {
- int j;
+ if(HDaccess(temp, F_OK) < 0)
+ break;
- for(j = 0; /*void*/; j++) {
- HDsnprintf(temp, sizeof temp, filename, j);
+ HDremove(temp);
+ } /* end for */
+ } else if(driver == H5FD_CORE) {
+ hbool_t backing; /* Whether the core file has backing store */
- if(HDaccess(temp, F_OK) < 0)
- break;
+ H5Pget_fapl_core(fapl, NULL, &backing);
- HDremove(temp);
- } /* end for */
- } else if(driver == H5FD_CORE) {
- hbool_t backing; /* Whether the core file has backing store */
+ /* If the file was stored to disk with bacing store, remove it */
+ if(backing)
+ HDremove(filename);
+ } else if (driver == H5FD_MULTI) {
+ H5FD_mem_t mt;
- H5Pget_fapl_core(fapl, NULL, &backing);
+ HDassert(HDstrlen(multi_letters)==H5FD_MEM_NTYPES);
- /* If the file was stored to disk with bacing store, remove it */
- if(backing)
- HDremove(filename);
- } else if (driver == H5FD_MULTI) {
- H5FD_mem_t mt;
+ for(mt = H5FD_MEM_DEFAULT; mt < H5FD_MEM_NTYPES; H5_INC_ENUM(H5FD_mem_t,mt)) {
+ HDsnprintf(temp, sizeof temp, "%s-%c.h5", filename, multi_letters[mt]);
+ HDremove(temp); /*don't care if it fails*/
+ } /* end for */
+ } else {
+ HDremove(filename);
+ }
+ } /* end for */
- HDassert(HDstrlen(multi_letters)==H5FD_MEM_NTYPES);
+ /* Close the FAPL used to access the file */
+ H5Pclose(fapl);
- for(mt = H5FD_MEM_DEFAULT; mt < H5FD_MEM_NTYPES; H5_INC_ENUM(H5FD_mem_t,mt)) {
- HDsnprintf(temp, sizeof temp, "%s-%c.h5", filename, multi_letters[mt]);
- HDremove(temp); /*don't care if it fails*/
- } /* end for */
- } else {
- HDremove(filename);
- }
+ return;
+} /* end h5_clean_files() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: h5_delete_test_file
+ *
+ * Purpose Clean up temporary test files.
+ *
+ * When a test calls h5_fixname() to get a VFD-dependent
+ * test file name, this function can be used to clean it up.
+ *
+ * Return: void
+ *
+ * Since this is a cleanup file, we don't care if it fails.
+ *
+ * Programmer: Dana Robinson
+ * February 2016
+ *
+ *-------------------------------------------------------------------------
+ */
+void
+h5_delete_test_file(const char *base_name, hid_t fapl)
+{
+ char filename[1024]; /* VFD-dependent filename to delete */
+ char sub_filename[2048]; /* sub-files in multi & family VFDs */
+ hid_t driver = -1; /* VFD ID */
+
+ /* Get the VFD-dependent filename */
+ if(NULL == h5_fixname(base_name, fapl, filename, sizeof(filename)))
+ return;
+
+ driver = H5Pget_driver(fapl);
+
+ if(driver == H5FD_FAMILY) {
+ int j;
+ for(j = 0; /*void*/; j++) {
+ HDsnprintf(sub_filename, sizeof(sub_filename), filename, j);
+
+ /* If we can't access the file, it probably doesn't exist
+ * and we are done deleting the sub-files.
+ */
+ if(HDaccess(sub_filename, F_OK) < 0)
+ break;
+
+ HDremove(sub_filename);
+ } /* end for */
+ } else if(driver == H5FD_CORE) {
+ hbool_t backing; /* Whether the core file has backing store */
+
+ H5Pget_fapl_core(fapl, NULL, &backing);
+
+ /* If the file was stored to disk with bacing store, remove it */
+ if(backing)
+ HDremove(filename);
+ } else if (driver == H5FD_MULTI) {
+ H5FD_mem_t mt;
+
+ HDassert(HDstrlen(multi_letters) == H5FD_MEM_NTYPES);
+
+ for(mt = H5FD_MEM_DEFAULT; mt < H5FD_MEM_NTYPES; H5_INC_ENUM(H5FD_mem_t,mt)) {
+ HDsnprintf(sub_filename, sizeof(sub_filename), "%s-%c.h5", filename, multi_letters[mt]);
+ HDremove(sub_filename);
} /* end for */
+ } else {
+ HDremove(filename);
+ } /* end if */
+
+ return;
+} /* end h5_delete_test_file() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: h5_delete_all_test_files
+ *
+ * Purpose Clean up temporary test files.
+ *
+ * When a test calls h5_fixname() get a VFD-dependent
+ * test file name, this function can be used to clean it up.
+ *
+ * This function takes an array of filenames that ends with
+ * a NULL string and cleans them all.
+ *
+ * Return: void
+ *
+ * Since this is a cleanup file, we don't care if it fails.
+ *
+ * Programmer: Dana Robinson
+ * February 2016
+ *
+ *-------------------------------------------------------------------------
+ */
+void
+h5_delete_all_test_files(const char *base_name[], hid_t fapl)
+{
+ int i; /* iterator */
+
+ for(i = 0; base_name[i]; i++) {
+ h5_delete_test_file(base_name[i], fapl);
+ } /* end for */
+
+ return;
+} /* end h5_delete_all_test_files() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: h5_cleanup
+ *
+ * Purpose: Cleanup temporary test files.
+ * base_name contains the list of test file names.
+ * The file access property list is also closed.
+ *
+ * Return: Non-zero if cleanup actions were performed; zero otherwise.
+ *
+ * Programmer: Albert Cheng
+ * May 28, 1998
+ *
+ *-------------------------------------------------------------------------
+ */
+int
+h5_cleanup(const char *base_name[], hid_t fapl)
+{
+ int retval = 0;
+
+ if(GetTestCleanup()) {
+ /* Clean up files in base_name, and the FAPL */
+ h5_clean_files(base_name, fapl);
retval = 1;
} /* end if */
- H5Pclose(fapl);
+ /* Restore the original error reporting routine */
+ h5_restore_err();
+
return retval;
+} /* end h5_cleanup() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: h5_restore_err
+ *
+ * Purpose: Restore the default error handler.
+ *
+ * Return: N/A
+ *
+ * Programmer: Quincey Koziol
+ * Sept 10, 2015
+ *
+ *-------------------------------------------------------------------------
+ */
+void
+h5_restore_err(void)
+{
+ /* Restore the original error reporting routine */
+ HDassert(err_func != NULL);
+ H5Eset_auto2(H5E_DEFAULT, err_func, NULL);
+ err_func = NULL;
}
@@ -212,6 +368,10 @@ h5_reset(void)
HDfflush(stdout);
HDfflush(stderr);
H5close();
+
+ /* Save current error stack reporting routine and redirect to our local one */
+ HDassert(err_func == NULL);
+ H5Eget_auto2(H5E_DEFAULT, &err_func, NULL);
H5Eset_auto2(H5E_DEFAULT, h5_errors, NULL);
/*
@@ -233,12 +393,12 @@ h5_reset(void)
*/
sprintf(filename, "/tmp/h5emit-%05d.h5", HDgetpid());
H5E_BEGIN_TRY {
- hid_t file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT,
- H5P_DEFAULT);
- hid_t grp = H5Gcreate2(file, "emit", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
- H5Gclose(grp);
- H5Fclose(file);
- HDunlink(filename);
+ hid_t file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT,
+ H5P_DEFAULT);
+ hid_t grp = H5Gcreate2(file, "emit", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ H5Gclose(grp);
+ H5Fclose(file);
+ HDunlink(filename);
} H5E_END_TRY;
}
#endif /* OLD_WAY */
@@ -528,30 +688,27 @@ h5_rmprefix(const char *filename)
const char *ret_ptr;
if ((ret_ptr = HDstrstr(filename, ":")) == NULL)
- ret_ptr = filename;
+ ret_ptr = filename;
else
- ret_ptr++;
+ ret_ptr++;
return(ret_ptr);
}
/*-------------------------------------------------------------------------
- * Function: h5_fileaccess
- *
- * Purpose: Returns a file access template which is the default template
- * but with a file driver set according to the constant or
- * environment variable HDF5_DRIVER
+ * Function: h5_fileaccess
*
- * Return: Success: A file access property list
+ * Purpose: Returns a file access template which is the default template
+ * but with a file driver set according to the constant or
+ * environment variable HDF5_DRIVER
*
- * Failure: -1
+ * Return: Success: A file access property list
+ * Failure: -1
*
* Programmer: Robb Matzke
* Thursday, November 19, 1998
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
hid_t
@@ -559,50 +716,61 @@ h5_fileaccess(void)
{
const char *val = NULL;
const char *name;
- char s[1024];
- hid_t fapl = -1;
+ char s[1024];
+ hid_t fapl = -1;
/* First use the environment variable, then the constant */
val = HDgetenv("HDF5_DRIVER");
#ifdef HDF5_DRIVER
- if (!val)
+ if(!val)
val = HDF5_DRIVER;
#endif
- if ((fapl=H5Pcreate(H5P_FILE_ACCESS))<0)
+ if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
return -1;
- if (!val || !*val)
- return fapl; /*use default*/
+ if(!val || !*val)
+ return fapl; /* use default */
HDstrncpy(s, val, sizeof s);
s[sizeof(s)-1] = '\0';
- if (NULL==(name=HDstrtok(s, " \t\n\r"))) return fapl;
+ if(NULL == (name = HDstrtok(s, " \t\n\r")))
+ return fapl;
- if (!HDstrcmp(name, "sec2")) {
+ if(!HDstrcmp(name, "sec2")) {
/* Unix read() and write() system calls */
- if (H5Pset_fapl_sec2(fapl)<0) return -1;
- } else if (!HDstrcmp(name, "stdio")) {
+ if (H5Pset_fapl_sec2(fapl) < 0)
+ return -1;
+ }
+ else if(!HDstrcmp(name, "stdio")) {
/* Standard C fread() and fwrite() system calls */
- if (H5Pset_fapl_stdio(fapl)<0) return -1;
- } else if (!HDstrcmp(name, "core")) {
+ if (H5Pset_fapl_stdio(fapl) < 0)
+ return -1;
+ }
+ else if(!HDstrcmp(name, "core")) {
/* In-memory driver settings (backing store on, 1 MB increment) */
- if (H5Pset_fapl_core(fapl, (size_t)1, TRUE)<0) return -1;
- } else if (!HDstrcmp(name, "core_paged")) {
+ if(H5Pset_fapl_core(fapl, (size_t)1, TRUE) < 0)
+ return -1;
+ }
+ else if(!HDstrcmp(name, "core_paged")) {
/* In-memory driver with write tracking and paging on */
- if (H5Pset_fapl_core(fapl, (size_t)1, TRUE)<0) return -1;
- if (H5Pset_core_write_tracking(fapl, TRUE, (size_t)524288)<0) return -1;
- } else if (!HDstrcmp(name, "split")) {
+ if(H5Pset_fapl_core(fapl, (size_t)1, TRUE) < 0)
+ return -1;
+ if(H5Pset_core_write_tracking(fapl, TRUE, (size_t)4096) < 0)
+ return -1;
+ }
+ else if(!HDstrcmp(name, "split")) {
/* Split meta data and raw data each using default driver */
- if (H5Pset_fapl_split(fapl,
+ if(H5Pset_fapl_split(fapl,
"-m.h5", H5P_DEFAULT,
- "-r.h5", H5P_DEFAULT)<0)
+ "-r.h5", H5P_DEFAULT) < 0)
return -1;
- } else if (!HDstrcmp(name, "multi")) {
+ }
+ else if(!HDstrcmp(name, "multi")) {
/* Multi-file driver, general case of the split driver */
H5FD_mem_t memb_map[H5FD_MEM_NTYPES];
hid_t memb_fapl[H5FD_MEM_NTYPES];
const char *memb_name[H5FD_MEM_NTYPES];
- char sv[H5FD_MEM_NTYPES][1024];
+ char *sv[H5FD_MEM_NTYPES];
haddr_t memb_addr[H5FD_MEM_NTYPES];
H5FD_mem_t mt;
@@ -613,45 +781,52 @@ h5_fileaccess(void)
HDassert(HDstrlen(multi_letters)==H5FD_MEM_NTYPES);
for(mt = H5FD_MEM_DEFAULT; mt < H5FD_MEM_NTYPES; H5_INC_ENUM(H5FD_mem_t, mt)) {
- memb_fapl[mt] = H5P_DEFAULT;
- sprintf(sv[mt], "%%s-%c.h5", multi_letters[mt]);
+ memb_fapl[mt] = H5P_DEFAULT;
+ if(NULL == (sv[mt] = (char *)HDmalloc(H5TEST_MULTI_FILENAME_LEN)))
+ return -1;
+ HDsprintf(sv[mt], "%%s-%c.h5", multi_letters[mt]);
memb_name[mt] = sv[mt];
memb_addr[mt] = (haddr_t)MAX(mt - 1, 0) * (HADDR_MAX / 10);
} /* end for */
- if (H5Pset_fapl_multi(fapl, memb_map, memb_fapl, memb_name,
- memb_addr, FALSE)<0) {
+ if(H5Pset_fapl_multi(fapl, memb_map, memb_fapl, memb_name, memb_addr, FALSE) < 0)
return -1;
- }
- } else if (!HDstrcmp(name, "family")) {
+
+ for(mt = H5FD_MEM_DEFAULT; mt < H5FD_MEM_NTYPES; H5_INC_ENUM(H5FD_mem_t, mt))
+ HDfree(sv[mt]);
+ }
+ else if(!HDstrcmp(name, "family")) {
hsize_t fam_size = 100*1024*1024; /*100 MB*/
/* Family of files, each 1MB and using the default driver */
- if ((val=HDstrtok(NULL, " \t\n\r")))
+ if((val = HDstrtok(NULL, " \t\n\r")))
fam_size = (hsize_t)(HDstrtod(val, NULL) * 1024*1024);
- if (H5Pset_fapl_family(fapl, fam_size, H5P_DEFAULT)<0)
+ if(H5Pset_fapl_family(fapl, fam_size, H5P_DEFAULT)<0)
return -1;
- } else if (!HDstrcmp(name, "log")) {
+ }
+ else if(!HDstrcmp(name, "log")) {
unsigned log_flags = H5FD_LOG_LOC_IO | H5FD_LOG_ALLOC;
/* Log file access */
- if ((val = HDstrtok(NULL, " \t\n\r")))
+ if((val = HDstrtok(NULL, " \t\n\r")))
log_flags = (unsigned)HDstrtol(val, NULL, 0);
-
- if (H5Pset_fapl_log(fapl, NULL, log_flags, (size_t)0) < 0)
+ if(H5Pset_fapl_log(fapl, NULL, log_flags, (size_t)0) < 0)
return -1;
- } else if (!HDstrcmp(name, "direct")) {
+ }
+ else if(!HDstrcmp(name, "direct")) {
#ifdef H5_HAVE_DIRECT
/* Linux direct read() and write() system calls. Set memory boundary, file block size,
* and copy buffer size to the default values. */
- if (H5Pset_fapl_direct(fapl, 1024, 4096, 8*4096)<0)
+ if(H5Pset_fapl_direct(fapl, 1024, 4096, 8 * 4096) < 0)
return -1;
#endif
- } else if(!HDstrcmp(name, "latest")) {
+ }
+ else if(!HDstrcmp(name, "latest")) {
/* use the latest format */
if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
return -1;
- } else {
+ }
+ else {
/* Unknown driver */
return -1;
}
@@ -1180,8 +1355,6 @@ getenv_all(MPI_Comm comm, int root, const char* name)
* Programmer: Larry Knox
* Monday, October 13, 2009
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
int
@@ -1189,24 +1362,44 @@ h5_make_local_copy(const char *origfilename, const char *local_copy_name)
{
int fd_old = (-1), fd_new = (-1); /* File descriptors for copying data */
ssize_t nread; /* Number of bytes read in */
- char buf[READ_BUF_SIZE]; /* Buffer for copying data */
- const char *filename = H5_get_srcdir_filename(origfilename);; /* Get the test file name to copy */
+ void *buf = NULL; /* Buffer for copying data */
+ const char *filename = H5_get_srcdir_filename(origfilename); /* Get the test file name to copy */
+
+ /* Allocate copy buffer */
+ if(NULL == (buf = HDcalloc((size_t)1, (size_t)READ_BUF_SIZE)))
+ goto error;
/* Copy old file into temporary file */
- if((fd_old = HDopen(filename, O_RDONLY, 0666)) < 0) return -1;
- if((fd_new = HDopen(local_copy_name, O_RDWR|O_CREAT|O_TRUNC, 0666))
- < 0) return -1;
+ if((fd_old = HDopen(filename, O_RDONLY, 0666)) < 0)
+ goto error;
+ if((fd_new = HDopen(local_copy_name, O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0)
+ goto error;
/* Copy data */
while((nread = HDread(fd_old, buf, (size_t)READ_BUF_SIZE)) > 0)
- HDwrite(fd_new, buf, (size_t)nread);
-
+ if(HDwrite(fd_new, buf, (size_t)nread) < 0)
+ goto error;
+
/* Close files */
- if(HDclose(fd_old) < 0) return -1;
- if(HDclose(fd_new) < 0) return -1;
+ if(HDclose(fd_old) < 0)
+ goto error;
+ if(HDclose(fd_new) < 0)
+ goto error;
+
+ /* Release memory */
+ HDfree(buf);
return 0;
-}
+
+error:
+ /* ignore return values since we're already noted the problem */
+ if(fd_old > 0)
+ HDclose(fd_old);
+ if(fd_new > 0)
+ HDclose(fd_new);
+ HDfree(buf);
+ return -1;
+} /* end h5_make_local_copy() */
/*-------------------------------------------------------------------------