summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJacob Smith <jake.smith@hdfgroup.org>2020-06-25 17:24:05 (GMT)
committerJacob Smith <jake.smith@hdfgroup.org>2020-06-25 17:24:05 (GMT)
commite1215177b6b87887233a90992a0264f11d78b88c (patch)
tree57ec1a19a92d97b19ff98cb68bcbc8b0ac19b511 /test
parentd20000ec51d50b66fc1226eeb656b8dc1358f826 (diff)
downloadhdf5-e1215177b6b87887233a90992a0264f11d78b88c.zip
hdf5-e1215177b6b87887233a90992a0264f11d78b88c.tar.gz
hdf5-e1215177b6b87887233a90992a0264f11d78b88c.tar.bz2
* Fix intermittent error with Splitter VFD.
Mismatch in time of test file creation was creating false negatives. Add file-duplication routine: `h5_duplicate_file_by_bytes()`. * Change library calls in `h5test.c:h5_compare_file_bytes()` to their HD-prefixed equivalents.
Diffstat (limited to 'test')
-rw-r--r--test/h5test.c107
-rw-r--r--test/h5test.h1
-rw-r--r--test/vfd.c80
3 files changed, 134 insertions, 54 deletions
diff --git a/test/h5test.c b/test/h5test.c
index 9cca100..1b445dd 100644
--- a/test/h5test.c
+++ b/test/h5test.c
@@ -2057,23 +2057,23 @@ h5_get_version_string(H5F_libver_t libver)
int
h5_compare_file_bytes(char *f1name, char *f2name)
{
- FILE *f1ptr = NULL; /* two file pointers */
- FILE *f2ptr = NULL;
- hsize_t f1size = 0; /* size of the files */
- hsize_t f2size = 0;
- char f1char = 0; /* one char from each file */
- char f2char = 0;
- hsize_t ii = 0;
- int ret_value = 0; /* for error handling */
+ FILE *f1ptr = NULL; /* two file pointers */
+ FILE *f2ptr = NULL;
+ off_t f1size = 0; /* size of the files */
+ off_t f2size = 0;
+ char f1char = 0; /* one char from each file */
+ char f2char = 0;
+ off_t ii = 0;
+ int ret_value = 0; /* for error handling */
/* Open files for reading */
- f1ptr = fopen(f1name, "r");
+ f1ptr = HDfopen(f1name, "r");
if (f1ptr == NULL) {
HDfprintf(stderr, "Unable to fopen() %s\n", f1name);
ret_value = -1;
goto done;
}
- f2ptr = fopen(f2name, "r");
+ f2ptr = HDfopen(f2name, "r");
if (f2ptr == NULL) {
HDfprintf(stderr, "Unable to fopen() %s\n", f2name);
ret_value = -1;
@@ -2081,11 +2081,11 @@ h5_compare_file_bytes(char *f1name, char *f2name)
}
/* Get the file sizes and verify that they equal */
- fseek(f1ptr , 0 , SEEK_END);
- f1size = ftell(f1ptr);
+ HDfseek(f1ptr , 0 , SEEK_END);
+ f1size = HDftell(f1ptr);
- fseek(f2ptr , 0 , SEEK_END);
- f2size = ftell(f2ptr);
+ HDfseek(f2ptr , 0 , SEEK_END);
+ f2size = HDftell(f2ptr);
if (f1size != f2size) {
HDfprintf(stderr, "Files differ in size, %llu vs. %llu\n", f1size, f2size);
@@ -2094,11 +2094,11 @@ h5_compare_file_bytes(char *f1name, char *f2name)
}
/* Compare each byte and fail if a difference is found */
- rewind(f1ptr);
- rewind(f2ptr);
+ HDrewind(f1ptr);
+ HDrewind(f2ptr);
for (ii = 0; ii < f1size; ii++) {
- fread(&f1char, 1, 1, f1ptr);
- fread(&f2char, 1, 1, f2ptr);
+ HDfread(&f1char, 1, 1, f1ptr);
+ HDfread(&f2char, 1, 1, f2ptr);
if (f1char != f2char) {
HDfprintf(stderr, "Mismatch @ 0x%llX: 0x%X != 0x%X\n", ii, f1char, f2char);
ret_value = -1;
@@ -2108,10 +2108,10 @@ h5_compare_file_bytes(char *f1name, char *f2name)
done:
if (f1ptr) {
- fclose(f1ptr);
+ HDfclose(f1ptr);
}
if (f2ptr) {
- fclose(f2ptr);
+ HDfclose(f2ptr);
}
return(ret_value);
} /* end h5_compare_file_bytes() */
@@ -2169,3 +2169,70 @@ const char *H5_get_srcdir(void)
return(NULL);
} /* end H5_get_srcdir() */
+/*-------------------------------------------------------------------------
+ * Function: h5_duplicate_file_by_bytes
+ *
+ * Purpose: Duplicate a file byte-for-byte at filename/path 'orig'
+ * to a new (or replaced) file at 'dest'.
+ *
+ * Return: Success: 0, completed successfully
+ * Failure: -1
+ *
+ * Programmer: Jake Smith
+ * 24 June 2020
+ *
+ *-------------------------------------------------------------------------
+ */
+int
+h5_duplicate_file_by_bytes(const char *orig, const char *dest)
+{
+ FILE *orig_ptr = NULL;
+ FILE *dest_ptr = NULL;
+ hsize_t fsize = 0;
+ hsize_t read_size = 0;
+ hsize_t max_buf = 0;
+ void *dup_buf = NULL;
+ int ret_value = 0;
+
+ max_buf = 4096 * sizeof(char);
+
+ orig_ptr = HDfopen(orig, "r");
+ if (NULL == orig_ptr) {
+ ret_value = -1;
+ goto done;
+ }
+
+ HDfseek(orig_ptr , 0 , SEEK_END);
+ fsize = (hsize_t)HDftell(orig_ptr);
+ HDrewind(orig_ptr);
+
+ dest_ptr = HDfopen(dest, "w");
+ if (NULL == dest_ptr) {
+ ret_value = -1;
+ goto done;
+ }
+
+ read_size = MIN(fsize, max_buf);
+ dup_buf = HDmalloc(read_size);
+ if (NULL == dup_buf) {
+ ret_value = -1;
+ goto done;
+ }
+
+ while (read_size > 0) {
+ HDfread(dup_buf, read_size, 1, orig_ptr); /* warning: no error-check */
+ HDfwrite(dup_buf, read_size, 1, dest_ptr);
+ fsize -= read_size;
+ read_size = MIN(fsize, max_buf);
+ }
+
+done:
+ if (orig_ptr != NULL)
+ HDfclose(orig_ptr);
+ if (dest_ptr != NULL)
+ HDfclose(dest_ptr);
+ if (dup_buf != NULL)
+ HDfree(dup_buf);
+ return ret_value;
+} /* end h5_duplicate_file_by_bytes() */
+
diff --git a/test/h5test.h b/test/h5test.h
index b1ddc58..3eeb1f8 100644
--- a/test/h5test.h
+++ b/test/h5test.h
@@ -210,6 +210,7 @@ H5TEST_DLL H5FD_class_t *h5_get_dummy_vfd_class(void);
H5TEST_DLL H5VL_class_t *h5_get_dummy_vol_class(void);
H5TEST_DLL const char *h5_get_version_string(H5F_libver_t libver);
H5TEST_DLL int h5_compare_file_bytes(char *fname1, char *fname2);
+H5TEST_DLL int h5_duplicate_file_by_bytes(const char *orig, const char *dest);
/* Functions that will replace components of a FAPL */
H5TEST_DLL herr_t h5_get_vfd_fapl(hid_t fapl_id);
diff --git a/test/vfd.c b/test/vfd.c
index d94aec6..038c967 100644
--- a/test/vfd.c
+++ b/test/vfd.c
@@ -2880,6 +2880,7 @@ done:
static int
splitter_tentative_open_test(hid_t child_fapl_id)
{
+ const char filename_tmp[H5FD_SPLITTER_PATH_MAX + 1] = "splitter_tmp.h5";
char filename_rw[H5FD_SPLITTER_PATH_MAX + 1];
H5FD_splitter_vfd_config_t vfd_config;
hid_t fapl_id = H5I_INVALID_HID;
@@ -2926,7 +2927,16 @@ splitter_tentative_open_test(hid_t child_fapl_id)
SPLITTER_TEST_FAULT("set FAPL not SPLITTER\n");
}
- /* H5Fopen() with RDWR access.
+ /* Create instance of file on disk.
+ * Will be copied verbatim as needed, to avoid issues where differences in
+ * the creation time would befoul comparisons.
+ */
+ if (splitter_create_single_file_at(filename_tmp, child_fapl_id, &data) < 0) {
+ SPLITTER_TEST_FAULT("can't write W/O file\n");
+ }
+
+ /*
+ * H5Fopen() with RDWR access.
* Neither file exist already
* Should fail.
*/
@@ -2944,13 +2954,14 @@ splitter_tentative_open_test(hid_t child_fapl_id)
SPLITTER_TEST_FAULT("W/O file unexpectedly created\n");
}
- /* H5Fopen() with RDWR access.
- * W/O file exists already.
+ /*
+ * H5Fopen() with RDWR access.
+ * Only W/O file present.
* Should fail.
*/
- if (splitter_create_single_file_at(vfd_config.wo_path, child_fapl_id, &data) < 0) {
- SPLITTER_TEST_FAULT("can't write W/O file\n");
+ if (h5_duplicate_file_by_bytes(filename_tmp, vfd_config.wo_path) < 0) {
+ SPLITTER_TEST_FAULT("Can't create W/O file copy.\n");
}
H5E_BEGIN_TRY {
file_id = H5Fopen(filename_rw, H5F_ACC_RDWR, fapl_id);
@@ -2969,13 +2980,14 @@ splitter_tentative_open_test(hid_t child_fapl_id)
SPLITTER_TEST_FAULT("failed to remove W/O file\n");
}
- /* H5Fopen() with RDWR access.
- * R/W file exists already.
+ /*
+ * H5Fopen() with RDWR access.
+ * Only R/W file present.
* Should fail.
*/
- if (splitter_create_single_file_at(filename_rw, child_fapl_id, &data) < 0) {
- SPLITTER_TEST_FAULT("can't write R/W file\n");
+ if (h5_duplicate_file_by_bytes(filename_tmp, filename_rw) < 0) {
+ SPLITTER_TEST_FAULT("Can't create R/W file copy.\n");
}
H5E_BEGIN_TRY {
file_id = H5Fopen(filename_rw, H5F_ACC_RDWR, fapl_id);
@@ -2990,12 +3002,13 @@ splitter_tentative_open_test(hid_t child_fapl_id)
SPLITTER_TEST_FAULT("W/O file unexpectedly created\n");
}
- /* H5Fopen() with RDWR access.
- * Both files already exist.
+ /*
+ * H5Fopen() with RDWR access.
+ * Both files present.
*/
- if (splitter_create_single_file_at(vfd_config.wo_path, child_fapl_id, &data) < 0) {
- SPLITTER_TEST_FAULT("can't write W/O file\n");
+ if (h5_duplicate_file_by_bytes(filename_tmp, vfd_config.wo_path) < 0) {
+ SPLITTER_TEST_FAULT("Can't create W/O file copy.\n");
}
file_id = H5Fopen(filename_rw, H5F_ACC_RDWR, fapl_id);
if (file_id == H5I_INVALID_HID) {
@@ -3011,12 +3024,10 @@ splitter_tentative_open_test(hid_t child_fapl_id)
if (!file_exists(vfd_config.wo_path, child_fapl_id)) {
SPLITTER_TEST_FAULT("W/O file mysteriously disappeared\n");
}
- if (h5_compare_file_bytes(filename_rw, vfd_config.wo_path) < 0) {
- SPLITTER_TEST_FAULT("files are not byte-for-byte equivalent\n");
- }
- /* H5Fcreate() with TRUNC access.
- * Both files already exist.
+ /*
+ * H5Fcreate() with TRUNC access.
+ * Both files present.
*/
file_id = H5Fcreate(filename_rw, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id);
@@ -3036,17 +3047,17 @@ splitter_tentative_open_test(hid_t child_fapl_id)
if (h5_compare_file_bytes(filename_rw, vfd_config.wo_path) < 0) {
SPLITTER_TEST_FAULT("files are not byte-for-byte equivalent\n");
}
+ HDremove(filename_rw);
+ HDremove(vfd_config.wo_path);
- /* H5Fcreate() with TRUNC access.
+ /*
+ * H5Fcreate() with TRUNC access.
* R/W already exists.
*/
- HDremove(filename_rw);
- HDremove(vfd_config.wo_path);
- if (splitter_create_single_file_at(filename_rw, child_fapl_id, &data) < 0) {
- SPLITTER_TEST_FAULT("can't write R/W file\n");
+ if (h5_duplicate_file_by_bytes(filename_tmp, filename_rw) < 0) {
+ SPLITTER_TEST_FAULT("Can't create R/W file copy.\n");
}
-
if (file_exists(vfd_config.wo_path, child_fapl_id)) {
SPLITTER_TEST_FAULT("failed to remove W/O file\n");
}
@@ -3067,17 +3078,17 @@ splitter_tentative_open_test(hid_t child_fapl_id)
if (h5_compare_file_bytes(filename_rw, vfd_config.wo_path) < 0) {
SPLITTER_TEST_FAULT("files are not byte-for-byte equivalent\n");
}
+ HDremove(filename_rw);
+ HDremove(vfd_config.wo_path);
- /* H5Fcreate() with TRUNC access.
- * W/O already exists.
+ /*
+ * H5Fcreate() with TRUNC access.
+ * Only W/O present.
*/
- HDremove(filename_rw);
- HDremove(vfd_config.wo_path);
- if (splitter_create_single_file_at(vfd_config.wo_path, child_fapl_id, &data) < 0) {
- SPLITTER_TEST_FAULT("can't write R/W file\n");
+ if (h5_duplicate_file_by_bytes(filename_tmp, vfd_config.wo_path) < 0) {
+ SPLITTER_TEST_FAULT("Can't create W/O file copy.\n");
}
-
if (file_exists(filename_rw, child_fapl_id)) {
SPLITTER_TEST_FAULT("failed to remove R/W file\n");
}
@@ -3098,10 +3109,13 @@ splitter_tentative_open_test(hid_t child_fapl_id)
if (h5_compare_file_bytes(filename_rw, vfd_config.wo_path) < 0) {
SPLITTER_TEST_FAULT("files are not byte-for-byte equivalent\n");
}
+ HDremove(filename_rw);
+ HDremove(vfd_config.wo_path);
/* H5Fcreate with both files absent is tested elsewhere */
- /* Cleanup
+ /*
+ * Cleanup
*/
if (H5Pclose(fapl_id) < 0) {
@@ -3225,7 +3239,6 @@ test_splitter(void)
TEST_ERROR;
}
-
/* Test file creation, utilizing different child FAPLs (default vs.
* specified), logfile, and Write Channel error ignoring behavior.
*/
@@ -3251,7 +3264,6 @@ test_splitter(void)
/* TODO: SWMR open? */
/* Concurrent opens with both drivers using the Splitter */
-
if (H5Pclose(child_fapl_id) == FAIL) {
TEST_ERROR;
}