summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDana Robinson <derobins@hdfgroup.org>2021-03-25 07:32:40 (GMT)
committerDana Robinson <derobins@hdfgroup.org>2021-03-25 07:32:40 (GMT)
commit1dbb83aabd9404f4b626e19193b7472a653ed8f5 (patch)
tree8ad3409e9bc2977486d5137240381d719587bc0a /test
parent711d12bb586b23d5bdea4f57fe0101255324cc78 (diff)
downloadhdf5-1dbb83aabd9404f4b626e19193b7472a653ed8f5.zip
hdf5-1dbb83aabd9404f4b626e19193b7472a653ed8f5.tar.gz
hdf5-1dbb83aabd9404f4b626e19193b7472a653ed8f5.tar.bz2
Brings file locking changes from develop
Diffstat (limited to 'test')
-rw-r--r--test/h5test.c60
-rw-r--r--test/h5test.h7
-rw-r--r--test/swmr.c346
-rw-r--r--test/tfile.c76
4 files changed, 373 insertions, 116 deletions
diff --git a/test/h5test.c b/test/h5test.c
index 591cd2b..0d9fccd 100644
--- a/test/h5test.c
+++ b/test/h5test.c
@@ -12,7 +12,7 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
- * Programmer: Robb Matzke <matzke@llnl.gov>
+ * Programmer: Robb Matzke
* Thursday, November 19, 1998
*
* Purpose: Provides support functions for most of the hdf5 tests cases.
@@ -2287,3 +2287,61 @@ done:
HDfree(dup_buf);
return ret_value;
} /* end h5_duplicate_file_by_bytes() */
+
+/*-------------------------------------------------------------------------
+ * Function: h5_check_if_file_locking_enabled
+ *
+ * Purpose: Checks if file locking is enabled on this file system.
+ *
+ * Return: SUCCEED/FAIL
+ * are_enabled will be FALSE if file locking is disabled on
+ * the file system of if there were errors.
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+h5_check_if_file_locking_enabled(hbool_t *is_enabled)
+{
+ const char *filename = "locking_test_file";
+ int pmode = O_RDWR | O_CREAT | O_TRUNC;
+ int fd = -1;
+
+ *is_enabled = TRUE;
+
+ if ((fd = HDopen(filename, pmode, H5_POSIX_CREATE_MODE_RW)) < 0)
+ goto error;
+
+ /* Test HDflock() to see if it works */
+ if (HDflock(fd, LOCK_EX | LOCK_NB) < 0) {
+ if (ENOSYS == errno) {
+ /* When errno is set to ENOSYS, the file system does not support
+ * locking, so ignore it. This is most frequently used on
+ * Lustre. If we also want to check for disabled NFS locks
+ * we'll need to check for ENOLCK, too. That isn't done by
+ * default here since that could also represent an actual
+ * error condition.
+ */
+ errno = 0;
+ *is_enabled = FALSE;
+ }
+ else
+ goto error;
+ }
+ if (HDflock(fd, LOCK_UN) < 0)
+ goto error;
+
+ if (HDclose(fd) < 0)
+ goto error;
+ if (HDremove(filename) < 0)
+ goto error;
+
+ return SUCCEED;
+
+error:
+ *is_enabled = FALSE;
+ if (fd > -1) {
+ HDclose(fd);
+ HDremove(filename);
+ }
+ return FAIL;
+} /* end h5_check_if_file_locking_enabled() */
diff --git a/test/h5test.h b/test/h5test.h
index 5e4c69f..81925b9 100644
--- a/test/h5test.h
+++ b/test/h5test.h
@@ -12,13 +12,13 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
- * Programmer: Robb Matzke <matzke@llnl.gov>
+ * Programmer: Robb Matzke
* Friday, November 20, 1998
*
* Purpose: Test support stuff.
*/
-#ifndef _H5TEST_H
-#define _H5TEST_H
+#ifndef H5TEST_H
+#define H5TEST_H
/*
* Include required headers. This file tests internal library functions,
@@ -262,6 +262,7 @@ 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);
+H5TEST_DLL herr_t h5_check_if_file_locking_enabled(hbool_t *are_enabled);
/* Functions that will replace components of a FAPL */
H5TEST_DLL herr_t h5_get_vfd_fapl(hid_t fapl_id);
diff --git a/test/swmr.c b/test/swmr.c
index 7f531e2..24a0b7c 100644
--- a/test/swmr.c
+++ b/test/swmr.c
@@ -87,7 +87,7 @@ static int test_file_lock_concur(hid_t fapl);
static int test_file_lock_swmr_concur(hid_t fapl);
/* Test file lock environment variable */
-static int test_file_lock_env_var(hid_t fapl);
+static int test_file_locking(hid_t in_fapl, hbool_t turn_locking_on, hbool_t env_var_override);
/* Tests for SWMR VFD flag */
static int test_swmr_vfd_flag(void);
@@ -847,14 +847,17 @@ error:
static int
test_metadata_read_retry_info(hid_t in_fapl)
{
- hid_t fapl, new_fapl; /* File access property list */
- hid_t fid, fid1; /* File IDs */
+ hid_t fapl = H5I_INVALID_HID; /* File access property list */
+ hid_t new_fapl = H5I_INVALID_HID; /* File access property list */
+ hid_t fid = H5I_INVALID_HID; /* File ID */
+ hid_t fid1 = H5I_INVALID_HID; /* File ID */
H5F_retry_info_t info, info1; /* The collection of metadata retries */
H5F_t * f = NULL, *f1 = NULL; /* Internal file object pointers */
unsigned i, j, n; /* Local index variables */
- hid_t did1, did2; /* Dataset IDs */
- hid_t sid; /* Dataspace ID */
- hid_t dcpl; /* Dataset creation property list */
+ hid_t did1 = H5I_INVALID_HID; /* Dataset ID */
+ hid_t did2 = H5I_INVALID_HID; /* Dataset ID */
+ hid_t sid = H5I_INVALID_HID; /* Dataspace ID */
+ hid_t dcpl = H5I_INVALID_HID; /* Dataset creation property list */
hsize_t dims[2] = {6, 10}; /* Dataset dimensions */
char filename[NAME_BUF_SIZE]; /* File name */
int buf[6][10], chkbuf1[6][10], chkbuf2[6][10]; /* Buffers for data */
@@ -1623,7 +1626,7 @@ test_start_swmr_write(hid_t in_fapl, hbool_t new_format)
FAIL_STACK_ERROR
/* Should be 100 */
- if (attempts != (new_format ? H5F_METADATA_READ_ATTEMPTS : H5F_SWMR_METADATA_READ_ATTEMPTS))
+ if (attempts != (unsigned int)(new_format ? H5F_METADATA_READ_ATTEMPTS : H5F_SWMR_METADATA_READ_ATTEMPTS))
TEST_ERROR;
/* Close the property list */
@@ -2392,17 +2395,24 @@ error:
* (5) Parent: open a file with write access; enable SWMR writing mode
* Child: concurrent open of the file with write and SWMR write access (fail)
*/
-#if !(defined(H5_HAVE_FORK) && defined(H5_HAVE_WAITPID))
+#ifndef H5_HAVE_UNISTD_H
static int
-test_start_swmr_write_concur(hid_t H5_ATTR_UNUSED in_fapl, hbool_t H5_ATTR_UNUSED new_format)
+test_start_swmr_write_concur(hid_t H5_ATTR_UNUSED in_fapl, hbool_t new_format)
{
+ if (new_format) {
+ TESTING("H5Fstart_swmr_write()--concurrent access for latest format");
+ }
+ else {
+ TESTING("H5Fstart_swmr_write()--concurrent access for non-latest-format");
+ }
+
SKIPPED();
- HDputs(" Test skipped due to fork or waitpid not defined.");
+ HDputs(" Test skipped due to a lack of unistd.h functionality.");
return 0;
} /* test_start_swmr_write_concur() */
-#else /* defined(H5_HAVE_FORK && defined(H5_HAVE_WAITPID) */
+#else /* H5_HAVE_UNISTD_H */
static int
test_start_swmr_write_concur(hid_t in_fapl, hbool_t new_format)
@@ -2434,7 +2444,7 @@ test_start_swmr_write_concur(hid_t in_fapl, hbool_t new_format)
}
else {
TESTING("H5Fstart_swmr_write()--concurrent access for non-latest-format");
- } /* end if */
+ }
if ((fapl = H5Pcopy(in_fapl)) < 0)
FAIL_STACK_ERROR
@@ -3004,7 +3014,7 @@ error:
return -1;
} /* test_start_swmr_write_concur() */
-#endif /* !(defined(H5_HAVE_FORK) && defined(H5_HAVE_WAITPID)) */
+#endif /* H5_HAVE_UNISTD_H */
/*
* test_start_swmr_write_stress_ohdr():
@@ -4332,8 +4342,11 @@ test_file_lock_same(hid_t in_fapl)
/* Output message about test being performed */
TESTING("File open with different combinations of flags--single process access");
+ /* Set locking in the fapl */
if ((fapl = H5Pcopy(in_fapl)) < 0)
FAIL_STACK_ERROR
+ if (H5Pset_file_locking(fapl, TRUE, TRUE) < 0)
+ FAIL_STACK_ERROR
/* Set the filename to use for this test (dependent on fapl) */
h5_fixname(FILENAME[1], fapl, filename, sizeof(filename));
@@ -4489,14 +4502,15 @@ error:
static int
test_file_lock_swmr_same(hid_t in_fapl)
{
- hid_t fid, fid2; /* File IDs */
- hid_t fapl; /* File access property list */
+ hid_t fid = H5I_INVALID_HID; /* File IDs */
+ hid_t fid2 = H5I_INVALID_HID;
+ hid_t fapl = H5I_INVALID_HID; /* File access property list */
char filename[NAME_BUF_SIZE]; /* file name */
/* Output message about test being performed */
TESTING("File open with different combinations of flags + SWMR flags--single process access");
- /* Get a copy of the parameter in_fapl */
+ /* Set locking in the fapl */
if ((fapl = H5Pcopy(in_fapl)) < 0)
FAIL_STACK_ERROR
@@ -4795,7 +4809,7 @@ error:
** This is for concurrent access.
**
*****************************************************************/
-#if !(defined(H5_HAVE_FORK) && defined(H5_HAVE_WAITPID) && defined(H5_HAVE_FLOCK))
+#ifndef H5_HAVE_UNISTD_H
static int
test_file_lock_concur(hid_t H5_ATTR_UNUSED in_fapl)
@@ -4803,12 +4817,12 @@ test_file_lock_concur(hid_t H5_ATTR_UNUSED in_fapl)
/* Output message about test being performed */
TESTING("File open with different combinations of flags--concurrent access");
SKIPPED();
- HDputs(" Test skipped due to fork, waitpid, or flock not defined.");
+ HDputs(" Test skipped due to a lack of unistd.h functionality.");
return 0;
} /* end test_file_lock_concur() */
-#else
+#else /* H5_HAVE_UNISTD_H */
static int
test_file_lock_concur(hid_t in_fapl)
@@ -4825,8 +4839,11 @@ test_file_lock_concur(hid_t in_fapl)
/* Output message about test being performed */
TESTING("File open with different combinations of flags--concurrent access");
+ /* Set locking in the fapl */
if ((fapl = H5Pcopy(in_fapl)) < 0)
FAIL_STACK_ERROR
+ if (H5Pset_file_locking(fapl, TRUE, TRUE) < 0)
+ FAIL_STACK_ERROR
/* Set the filename to use for this test (dependent on fapl) */
h5_fixname(FILENAME[1], fapl, filename, sizeof(filename));
@@ -5175,7 +5192,7 @@ error:
} /* end test_file_lock_concur() */
-#endif /* !(defined(H5_HAVE_FORK) && defined(H5_HAVE_WAITPID) && defined(H5_HAVE_FLOCK)) */
+#endif /* H5_HAVE_UNISTD_H */
/****************************************************************
**
@@ -5185,7 +5202,7 @@ error:
** This is for concurrent access.
**
*****************************************************************/
-#if !(defined(H5_HAVE_FORK) && defined(H5_HAVE_WAITPID))
+#ifndef H5_HAVE_UNISTD_H
static int
test_file_lock_swmr_concur(hid_t H5_ATTR_UNUSED in_fapl)
@@ -5193,12 +5210,12 @@ test_file_lock_swmr_concur(hid_t H5_ATTR_UNUSED in_fapl)
/* Output message about test being performed */
TESTING("File open with different combintations of flags + SWMR flags--concurrent access");
SKIPPED();
- HDputs(" Test skipped due to fork or waitpid not defined.");
+ HDputs(" Test skipped due to a lack of unistd.h functionality.");
return 0;
} /* end test_file_lock_swmr_concur() */
-#else
+#else /* H5_HAVE_UNISTD_H */
static int
test_file_lock_swmr_concur(hid_t in_fapl)
@@ -5215,8 +5232,11 @@ test_file_lock_swmr_concur(hid_t in_fapl)
/* Output message about test being performed */
TESTING("File open with different combintations of flags + SWMR flags--concurrent access");
+ /* Set locking in the fapl */
if ((fapl = H5Pcopy(in_fapl)) < 0)
FAIL_STACK_ERROR
+ if (H5Pset_file_locking(fapl, TRUE, TRUE) < 0)
+ FAIL_STACK_ERROR
/* Set the filename to use for this test (dependent on fapl) */
h5_fixname(FILENAME[2], fapl, filename, sizeof(filename));
@@ -5730,7 +5750,7 @@ test_file_lock_swmr_concur(hid_t in_fapl)
/* Open the test file */
H5E_BEGIN_TRY
{
- child_fid = H5Fopen(filename, H5F_ACC_RDWR, H5P_DEFAULT);
+ child_fid = H5Fopen(filename, H5F_ACC_RDWR, fapl);
}
H5E_END_TRY;
@@ -6065,7 +6085,7 @@ test_file_lock_swmr_concur(hid_t in_fapl)
FAIL_STACK_ERROR
/* Open the test file */
- if ((fid = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0)
+ if ((fid = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0)
FAIL_STACK_ERROR
/* Notify child process */
@@ -6195,42 +6215,73 @@ error:
} /* end test_file_lock_swmr_concur() */
-#endif /* !(defined(H5_HAVE_FORK && defined(H5_HAVE_WAITPID)) */
+#endif /* H5_HAVE_UNISTD_H */
/****************************************************************
**
-** test_file_lock_swmr_concur(): low-level file test routine.
-** With the implementation of file locking, this test checks file
-** open with different combinations of flags + SWMR flags.
-** This is for concurrent access.
+** test_file_locking():
+** Tests various combinations of file locking flags and
+** and environment variables.
**
*****************************************************************/
static int
-test_file_lock_env_var(hid_t in_fapl)
+test_file_locking(hid_t in_fapl, hbool_t turn_locking_on, hbool_t env_var_override)
{
-#if !(defined(H5_HAVE_FORK) && defined(H5_HAVE_WAITPID))
+#ifndef H5_HAVE_UNISTD_H
+ if (turn_locking_on && env_var_override)
+ TESTING("File locking: ON w/ env var override")
+ else if (turn_locking_on && !env_var_override)
+ TESTING("File locking: ON")
+ else if (!turn_locking_on && env_var_override)
+ TESTING("File locking: OFF w/ env var override")
+ else
+ TESTING("File locking: OFF")
SKIPPED();
- HDputs(" Test skipped due to fork or waitpid not defined.");
+ HDputs(" Test skipped due to a lack of unistd.h functionality.");
return 0;
-#else
- hid_t fid = -1; /* File ID */
- hid_t fapl = -1; /* File access property list */
- char filename[NAME_BUF_SIZE]; /* file name */
- pid_t childpid = 0; /* Child process ID */
- int child_status; /* Status passed to waitpid */
- int child_wait_option = 0; /* Options passed to waitpid */
- int out_pdf[2];
- int notify = 0;
-
- TESTING("File locking environment variable");
+#else /* H5_HAVE_UNISTD_H */
+ hid_t fid = -1; /* File ID */
+ hid_t fapl = -1; /* File access property list */
+ char filename[NAME_BUF_SIZE]; /* file name */
+ pid_t childpid = 0; /* Child process ID */
+ int child_status; /* Status passed to waitpid */
+ int child_wait_option = 0; /* Options passed to waitpid */
+ int out_pdf[2];
+ int notify = 0;
+ int exit_status = 0;
+ herr_t ret;
+
+ if (turn_locking_on && env_var_override)
+ TESTING("File locking: ON w/ env var override")
+ else if (turn_locking_on && !env_var_override)
+ TESTING("File locking: ON")
+ else if (!turn_locking_on && env_var_override)
+ TESTING("File locking: OFF w/ env var override")
+ else
+ TESTING("File locking: OFF")
- /* Set the environment variable */
- if (HDsetenv("HDF5_USE_FILE_LOCKING", "FALSE", TRUE) < 0)
+ /* Copy the incoming fapl */
+ if ((fapl = H5Pcopy(in_fapl)) < 0)
TEST_ERROR
- if ((fapl = H5Pcopy(in_fapl)) < 0)
+ /* Set locking in the fapl */
+ if (H5Pset_file_locking(fapl, turn_locking_on ? TRUE : FALSE, TRUE) < 0)
TEST_ERROR
+ /* If requested, set the environment variable */
+ if (env_var_override) {
+ if (HDsetenv("HDF5_USE_FILE_LOCKING", turn_locking_on ? "FALSE" : "TRUE", TRUE) < 0)
+ TEST_ERROR
+ if (H5F__reparse_file_lock_variable_test() < 0)
+ TEST_ERROR
+ }
+ else {
+ if (HDsetenv("HDF5_USE_FILE_LOCKING", "", TRUE) < 0)
+ TEST_ERROR
+ if (H5F__reparse_file_lock_variable_test() < 0)
+ TEST_ERROR
+ }
+
/* Set the filename to use for this test (dependent on fapl) */
h5_fixname(FILENAME[1], fapl, filename, sizeof(filename));
@@ -6242,10 +6293,8 @@ test_file_lock_env_var(hid_t in_fapl)
if (H5Fclose(fid) < 0)
TEST_ERROR
- /* Open a file for read-only and then read-write. This would
- * normally fail due to the file locking scheme but should
- * pass when the environment variable is set to disable file
- * locking.
+ /* Open a file for read-only and then read-write. This will fail
+ * when the locking scheme is turned on.
*/
/* Create 1 pipe */
@@ -6260,7 +6309,7 @@ test_file_lock_env_var(hid_t in_fapl)
/* Child process */
- hid_t child_fid; /* File ID */
+ hid_t child_fid = H5I_INVALID_HID; /* File ID */
int child_notify = 0;
/* Close unused write end for out_pdf */
@@ -6271,18 +6320,25 @@ test_file_lock_env_var(hid_t in_fapl)
while (child_notify != 1) {
if (HDread(out_pdf[0], &child_notify, sizeof(int)) < 0)
HDexit(EXIT_FAILURE);
- } /* end while */
+ }
- /* Open the test file */
- if ((child_fid = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
- TEST_ERROR
+ /* Open and close the test file */
+ H5E_BEGIN_TRY
+ {
+ child_fid = H5Fopen(filename, H5F_ACC_RDWR, fapl);
+ ret = H5Fclose(child_fid);
+ }
+ H5E_END_TRY;
/* Close the pipe */
if (HDclose(out_pdf[0]) < 0)
HDexit(EXIT_FAILURE);
- HDexit(EXIT_SUCCESS);
- } /* end if */
+ if (H5I_INVALID_HID == child_fid || FAIL == ret)
+ HDexit(EXIT_FAILURE);
+ else
+ HDexit(EXIT_SUCCESS);
+ } /* end child process work */
/* close unused read end for out_pdf */
if (HDclose(out_pdf[0]) < 0)
@@ -6305,15 +6361,28 @@ test_file_lock_env_var(hid_t in_fapl)
if (HDwaitpid(childpid, &child_status, child_wait_option) < 0)
TEST_ERROR
- /* Check if child terminated normally */
- if (WIFEXITED(child_status)) {
- /* Check exit status of the child */
- if (WEXITSTATUS(child_status) != 0)
- TEST_ERROR
- } /* end if */
+ /* Check exit status of the child */
+ if (WIFEXITED(child_status))
+ exit_status = WEXITSTATUS(child_status);
else
TEST_ERROR
+ /* The child process should have passed or failed as follows:
+ *
+ * locks on: FAIL
+ * locks off: PASS
+ * locks on, env var override: PASS
+ * locks off, env var override: FAIL
+ */
+ if (turn_locking_on && !env_var_override && (0 == exit_status))
+ TEST_ERROR
+ else if (!turn_locking_on && !env_var_override && (0 != exit_status))
+ TEST_ERROR
+ else if (turn_locking_on && env_var_override && (0 != exit_status))
+ TEST_ERROR
+ else if (!turn_locking_on && env_var_override && (0 == exit_status))
+ TEST_ERROR
+
/* Close the file */
if (H5Fclose(fid) < 0)
TEST_ERROR
@@ -6336,9 +6405,86 @@ error:
return -1;
-#endif /* !(defined(H5_HAVE_FORK && defined(H5_HAVE_WAITPID)) */
+#endif /* H5_HAVE_UNISTD_H */
-} /* end test_file_lock_env_var() */
+} /* end test_file_locking() */
+
+/****************************************************************
+**
+** test_different_lock_flags():
+** Tests opening a file multiple times with different lock
+** flags.
+**
+*****************************************************************/
+static int
+test_different_lock_flags(hid_t in_fapl)
+{
+ hid_t fid1 = H5I_INVALID_HID; /* File ID */
+ hid_t fid2 = H5I_INVALID_HID; /* File ID */
+ hid_t fid3 = H5I_INVALID_HID; /* File ID */
+ hid_t fapl_id = H5I_INVALID_HID; /* File access property list */
+ char filename[NAME_BUF_SIZE]; /* File name */
+
+ TESTING("Using different lock flags")
+
+ /* Copy the incoming fapl */
+ if ((fapl_id = H5Pcopy(in_fapl)) < 0)
+ TEST_ERROR
+
+ /* Set locking in the fapl */
+ if (H5Pset_file_locking(fapl_id, TRUE, TRUE) < 0)
+ TEST_ERROR
+
+ /* Set the filename to use for this test (dependent on fapl) */
+ h5_fixname(FILENAME[1], fapl_id, filename, sizeof(filename));
+
+ /* Create the test file */
+ if ((fid1 = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id)) < 0)
+ TEST_ERROR
+
+ /* Open the test file with the same flags (should pass) */
+ if ((fid2 = H5Fopen(filename, H5F_ACC_RDWR, fapl_id)) < 0)
+ TEST_ERROR
+
+ /* Unset locking in the fapl */
+ if (H5Pset_file_locking(fapl_id, FALSE, FALSE) < 0)
+ TEST_ERROR
+
+ /* Open the test file with different flags (should FAIL) */
+ H5E_BEGIN_TRY
+ {
+ fid3 = H5Fopen(filename, H5F_ACC_RDWR, fapl_id);
+ }
+ H5E_END_TRY;
+ if (H5I_INVALID_HID != fid3)
+ FAIL_PUTS_ERROR("Should not have been able to open a file with different locking flags")
+
+ /* Close the files */
+ if (H5Fclose(fid1) < 0)
+ TEST_ERROR
+ if (H5Fclose(fid2) < 0)
+ TEST_ERROR
+
+ /* Close the copied property list */
+ if (H5Pclose(fapl_id) < 0)
+ TEST_ERROR
+
+ PASSED();
+
+ return 0;
+
+error:
+ H5E_BEGIN_TRY
+ {
+ H5Pclose(fapl_id);
+ H5Fclose(fid1);
+ H5Fclose(fid2);
+ H5Fclose(fid3);
+ }
+ H5E_END_TRY;
+
+ return -1;
+} /* end test_different_lock_flags() */
static int
test_swmr_vfd_flag(void)
@@ -6414,10 +6560,18 @@ error:
static int
test_bug_refresh(hid_t in_fapl)
{
- hid_t fid = -1; /* File ID */
- hid_t fapl;
+ hid_t fid = H5I_INVALID_HID;
+ hid_t fapl = H5I_INVALID_HID;
H5F_t *f;
- hid_t gid1, gid2, gid3, gid4, gid5, gid6, gid7, gid8, gid9;
+ hid_t gid1 = H5I_INVALID_HID;
+ hid_t gid2 = H5I_INVALID_HID;
+ hid_t gid3 = H5I_INVALID_HID;
+ hid_t gid4 = H5I_INVALID_HID;
+ hid_t gid5 = H5I_INVALID_HID;
+ hid_t gid6 = H5I_INVALID_HID;
+ hid_t gid7 = H5I_INVALID_HID;
+ hid_t gid8 = H5I_INVALID_HID;
+ hid_t gid9 = H5I_INVALID_HID;
char filename[NAME_BUF_SIZE]; /* File name */
/* Create a copy of the input parameter in_fapl */
@@ -6545,17 +6699,24 @@ error:
* (7) Refresh the dataset
* (8) Verify the dataset's dimension and data are correct
*/
-#if !(defined(H5_HAVE_FORK) && defined(H5_HAVE_WAITPID))
+#ifndef H5_HAVE_UNISTD_H
static int
-test_refresh_concur(hid_t H5_ATTR_UNUSED in_fapl, hbool_t H5_ATTR_UNUSED new_format)
+test_refresh_concur(hid_t H5_ATTR_UNUSED in_fapl, hbool_t new_format)
{
+ if (new_format) {
+ TESTING("H5Drefresh()--concurrent access for latest format");
+ }
+ else {
+ TESTING("H5Drefresh()--concurrent access for non-latest-format");
+ }
+
SKIPPED();
- HDputs(" Test skipped due to fork or waitpid not defined.");
+ HDputs(" Test skipped due to a lack of unistd.h functionality.");
return 0;
} /* test_refresh_concur() */
-#else /* defined(H5_HAVE_FORK && defined(H5_HAVE_WAITPID) */
+#else /* H5_HAVE_UNISTD_H */
static int
test_refresh_concur(hid_t in_fapl, hbool_t new_format)
@@ -6855,7 +7016,7 @@ error:
return -1;
} /* test_refresh_concur() */
-#endif /* !(defined(H5_HAVE_FORK) && defined(H5_HAVE_WAITPID)) */
+#endif /* H5_HAVE_UNISTD_H */
/*
* test_multiple_same():
@@ -7184,7 +7345,7 @@ error:
}
H5E_END_TRY;
- return -1;
+ return 1;
} /* test_multiple_same() */
@@ -7196,11 +7357,12 @@ error:
int
main(void)
{
- int nerrors = 0; /* The # of errors */
- hid_t fapl = -1; /* File access property list ID */
- char * driver = NULL; /* VFD string (from env variable) */
- char * lock_env_var = NULL; /* file locking env var pointer */
- hbool_t use_file_locking; /* read from env var */
+ int nerrors = 0; /* The # of errors */
+ hid_t fapl = -1; /* File access property list ID */
+ char * driver = NULL; /* VFD string (from env variable) */
+ char * lock_env_var = NULL; /* file locking env var pointer */
+ hbool_t use_file_locking; /* read from env var */
+ hbool_t file_locking_enabled = FALSE; /* Checks if the file system supports locks */
/* Skip this test if SWMR I/O is not supported for the VFD specified
* by the environment variable.
@@ -7221,6 +7383,13 @@ main(void)
else
use_file_locking = TRUE;
+ /* Check if file locking is enabled on this file system */
+ if (use_file_locking)
+ if (h5_check_if_file_locking_enabled(&file_locking_enabled) < 0) {
+ HDprintf("Error when determining if file locks are enabled\n");
+ return EXIT_FAILURE;
+ }
+
/* Set up */
h5_reset();
@@ -7262,7 +7431,7 @@ main(void)
nerrors += test_append_flush_dataset_fixed(fapl);
nerrors += test_append_flush_dataset_multiple(fapl);
- if (use_file_locking) {
+ if (use_file_locking && file_locking_enabled) {
/*
* Tests for:
* file open flags--single process access
@@ -7289,10 +7458,19 @@ main(void)
if (NULL == driver || !HDstrcmp(driver, "") || !HDstrcmp(driver, "sec2"))
nerrors += test_swmr_vfd_flag();
- /* This test changes the HDF5_USE_FILE_LOCKING environment variable
- * so it should be run last.
+ /* Test multiple opens via different locking flags */
+ if (use_file_locking && file_locking_enabled)
+ nerrors += test_different_lock_flags(fapl);
+
+ /* These tests change the HDF5_USE_FILE_LOCKING environment variable
+ * so they should be run last.
*/
- nerrors += test_file_lock_env_var(fapl);
+ if (use_file_locking && file_locking_enabled) {
+ nerrors += test_file_locking(fapl, TRUE, TRUE);
+ nerrors += test_file_locking(fapl, TRUE, FALSE);
+ nerrors += test_file_locking(fapl, FALSE, TRUE);
+ nerrors += test_file_locking(fapl, FALSE, FALSE);
+ }
if (nerrors)
goto error;
diff --git a/test/tfile.c b/test/tfile.c
index b4048b4..34f3389 100644
--- a/test/tfile.c
+++ b/test/tfile.c
@@ -1666,6 +1666,29 @@ test_file_is_accessible(const char *env_h5_drvr)
is_hdf5 = H5Fis_accessible(filename, fapl_id);
VERIFY(is_hdf5, TRUE, "H5Fis_accessible");
+ /*****************************************/
+ /* Newly created file that is still open */
+ /*****************************************/
+
+ /* On Windows, file locking is mandatory so this check ensures that
+ * H5Fis_accessible() works on files that have an exclusive lock.
+ * Previous versions of this API call created an additional file handle
+ * and attempted to read through it, which will not work when locks
+ * are enforced by the OS.
+ */
+
+ /* Create a file and hold it open */
+ fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id);
+ CHECK(fid, H5I_INVALID_HID, "H5Fcreate");
+
+ /* Verify that the file is an HDF5 file */
+ is_hdf5 = H5Fis_accessible(filename, fapl_id);
+ VERIFY(is_hdf5, TRUE, "H5Fis_accessible");
+
+ /* Close file */
+ ret = H5Fclose(fid);
+ CHECK(ret, FAIL, "H5Fclose");
+
/*******************************/
/* Non-default user block size */
/*******************************/
@@ -3134,7 +3157,6 @@ test_rw_noupdate(void)
** test_userblock_alignment() test, to handle common testing
**
** Programmer: Quincey Koziol
-** koziol@hdfgroup.org
** Septmber 10, 2009
**
*****************************************************************/
@@ -3196,7 +3218,6 @@ test_userblock_alignment_helper1(hid_t fcpl, hid_t fapl)
** test_userblock_alignment() test, to handle common testing
**
** Programmer: Quincey Koziol
-** koziol@hdfgroup.org
** Septmber 10, 2009
**
*****************************************************************/
@@ -3266,7 +3287,6 @@ test_userblock_alignment_helper2(hid_t fapl, hbool_t open_rw)
** object [allocation] alignment size set interact properly.
**
** Programmer: Quincey Koziol
-** koziol@hdfgroup.org
** Septmber 8, 2009
**
*****************************************************************/
@@ -4300,7 +4320,7 @@ set_multi_split(hid_t fapl, hsize_t pagesize, hbool_t split)
/* Free memb_name */
for (mt = H5FD_MEM_DEFAULT; mt < H5FD_MEM_NTYPES; mt++)
- free(memb_name[mt]);
+ HDfree(memb_name[mt]);
return 0;
@@ -5799,7 +5819,7 @@ test_libver_bounds_super_create(hid_t fapl, hid_t fcpl, htri_t is_swmr, htri_t n
/* Get the internal file pointer if the create succeeds */
if (fid >= 0) {
f = (H5F_t *)H5VL_object(fid);
- CHECK(f, NULL, "H5VL_object");
+ CHECK_PTR(f, "H5VL_object");
}
/* Retrieve the low/high bounds */
@@ -5975,7 +5995,7 @@ test_libver_bounds_super_open(hid_t fapl, hid_t fcpl, htri_t is_swmr, htri_t non
/* Get the internal file pointer */
f = (H5F_t *)H5VL_object(fid);
- CHECK(f, NULL, "H5VL_object");
+ CHECK_PTR(f, "H5VL_object");
/* The file's superblock version */
super_vers = f->shared->sblock->super_vers;
@@ -6016,7 +6036,7 @@ test_libver_bounds_super_open(hid_t fapl, hid_t fcpl, htri_t is_swmr, htri_t non
/* Get the internal file pointer if the open succeeds */
if (fid >= 0) {
f = (H5F_t *)H5VL_object(fid);
- CHECK(f, NULL, "H5VL_object");
+ CHECK_PTR(f, "H5VL_object");
}
/* Verify the file open succeeds or fails */
@@ -6194,7 +6214,7 @@ test_libver_bounds_obj(hid_t fapl)
/* Get the internal file pointer */
f = (H5F_t *)H5VL_object(fid);
- CHECK(f, NULL, "H5VL_object");
+ CHECK_PTR(f, "H5VL_object");
/* Create a group in the file */
gid = H5Gcreate2(fid, GRP_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
@@ -6302,7 +6322,7 @@ test_libver_bounds_dataset(hid_t fapl)
/* Get the internal dataset pointer */
dset = (H5D_t *)H5VL_object(did);
- CHECK(dset, NULL, "H5VL_object");
+ CHECK_PTR(dset, "H5VL_object");
/* Verify version for layout and fill value messages */
if (low == H5F_LIBVER_EARLIEST) {
@@ -6350,7 +6370,7 @@ test_libver_bounds_dataset(hid_t fapl)
/* Get the internal dataset pointer */
dset = (H5D_t *)H5VL_object(did);
- CHECK(dset, NULL, "H5VL_object");
+ CHECK_PTR(dset, "H5VL_object");
/* Verify layout message version and chunk indexing type */
VERIFY(dset->shared->layout.version, H5O_LAYOUT_VERSION_4, "H5O_layout_ver_bounds");
@@ -6412,7 +6432,7 @@ test_libver_bounds_dataset(hid_t fapl)
/* Get the internal file pointer */
f = (H5F_t *)H5VL_object(fid);
- CHECK(f, NULL, "H5VL_object");
+ CHECK_PTR(f, "H5VL_object");
/* Create the chunked dataset */
did = H5Dcreate2(fid, DSETC, H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
@@ -6420,7 +6440,7 @@ test_libver_bounds_dataset(hid_t fapl)
/* Get the internal file pointer */
dset = (H5D_t *)H5VL_object(did);
- CHECK(dset, NULL, "H5VL_object");
+ CHECK_PTR(dset, "H5VL_object");
/* Verify the dataset's layout, fill value and filter pipeline message versions */
/* Also verify the chunk indexing type */
@@ -6541,7 +6561,7 @@ test_libver_bounds_dataspace(hid_t fapl)
sid = H5Dget_space(did);
CHECK(sid, H5I_INVALID_HID, "H5Dget_space");
space = (H5S_t *)H5I_object(sid);
- CHECK(space, NULL, "H5I_object");
+ CHECK_PTR(space, "H5I_object");
/* Verify the dataspace version */
VERIFY(space->extent.version, H5O_sdspace_ver_bounds[low], "H5O_sdspace_ver_bounds");
@@ -6558,7 +6578,7 @@ test_libver_bounds_dataspace(hid_t fapl)
sid_null = H5Dget_space(did_null);
CHECK(sid_null, H5I_INVALID_HID, "H5Dget_space");
space_null = (H5S_t *)H5I_object(sid_null);
- CHECK(space_null, NULL, "H5I_object");
+ CHECK_PTR(space_null, "H5I_object");
/* Verify the dataspace version */
VERIFY(space_null->extent.version, H5O_SDSPACE_VERSION_2, "H5O_sdspace_ver_bounds");
@@ -6636,7 +6656,7 @@ test_libver_bounds_dataspace(hid_t fapl)
/* Get the internal file pointer */
f = (H5F_t *)H5VL_object(fid);
- CHECK(f, NULL, "H5VL_object");
+ CHECK_PTR(f, "H5VL_object");
/* Create the chunked dataset */
did = H5Dcreate2(fid, DSETA, H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
@@ -6646,7 +6666,7 @@ test_libver_bounds_dataspace(hid_t fapl)
tmp_sid = H5Dget_space(did);
CHECK(tmp_sid, H5I_INVALID_HID, "H5Dget_space");
tmp_space = (H5S_t *)H5I_object(tmp_sid);
- CHECK(tmp_space, NULL, "H5I_object");
+ CHECK_PTR(tmp_space, "H5I_object");
/* Create the compact dataset */
did_compact = H5Dcreate2(fid, DSETB, H5T_NATIVE_INT, sid_compact, H5P_DEFAULT, dcpl_compact,
@@ -6657,7 +6677,7 @@ test_libver_bounds_dataspace(hid_t fapl)
tmp_sid_compact = H5Dget_space(did_compact);
CHECK(tmp_sid_compact, H5I_INVALID_HID, "H5Dget_space");
tmp_space_compact = (H5S_t *)H5I_object(tmp_sid_compact);
- CHECK(tmp_space_compact, NULL, "H5I_object");
+ CHECK_PTR(tmp_space_compact, "H5I_object");
/* Create the contiguous dataset */
did_contig =
@@ -6668,7 +6688,7 @@ test_libver_bounds_dataspace(hid_t fapl)
tmp_sid_contig = H5Dget_space(did_contig);
CHECK(tmp_sid_contig, H5I_INVALID_HID, "H5Dget_space");
tmp_space_contig = (H5S_t *)H5I_object(tmp_sid_contig);
- CHECK(tmp_space_contig, NULL, "H5I_object");
+ CHECK_PTR(tmp_space_contig, "H5I_object");
/* Verify versions for the three dataspaces */
VERIFY(tmp_space->extent.version, H5O_sdspace_ver_bounds[f->shared->low_bound],
@@ -6892,7 +6912,7 @@ test_libver_bounds_datatype_check(hid_t fapl, hid_t tid)
/* Get the internal datatype pointer */
dtype = (H5T_t *)H5I_object(dtid);
- CHECK(dtype, NULL, "H5I_object");
+ CHECK_PTR(dtype, "H5I_object");
/* Verify the datatype message version */
/* H5T_COMPOUND, H5T_ENUM, H5T_ARRAY:
@@ -6966,13 +6986,13 @@ test_libver_bounds_datatype_check(hid_t fapl, hid_t tid)
/* Get the internal file pointer */
f = (H5F_t *)H5VL_object(fid);
- CHECK(f, NULL, "H5VL_object");
+ CHECK_PTR(f, "H5VL_object");
/* Open the committed datatype */
str_tid = H5Topen2(fid, "datatype", H5P_DEFAULT);
CHECK(str_tid, FAIL, "H5Topen2");
str_dtype = (H5T_t *)H5VL_object(str_tid);
- CHECK(str_dtype, NULL, "H5VL_object");
+ CHECK_PTR(str_dtype, "H5VL_object");
/* Verify the committed datatype message version */
VERIFY(str_dtype->shared->version, H5O_dtype_ver_bounds[H5F_LIBVER_EARLIEST],
@@ -6992,7 +7012,7 @@ test_libver_bounds_datatype_check(hid_t fapl, hid_t tid)
/* Get the internal datatype pointer */
dtype = (H5T_t *)H5I_object(dtid);
- CHECK(dtype, NULL, "H5I_object");
+ CHECK_PTR(dtype, "H5I_object");
/* Verify the dataset's datatype message version */
/* H5T_COMPOUND, H5T_ENUM, H5T_ARRAY:
@@ -7125,7 +7145,7 @@ test_libver_bounds_attributes(hid_t fapl)
/* Get the internal attribute pointer */
attr = (H5A_t *)H5VL_object(aid);
- CHECK(attr, NULL, "H5VL_object");
+ CHECK_PTR(attr, "H5VL_object");
/* Verify the attribute version */
if (low == H5F_LIBVER_EARLIEST)
@@ -7144,7 +7164,7 @@ test_libver_bounds_attributes(hid_t fapl)
/* Get the internal attribute pointer */
attr = (H5A_t *)H5VL_object(aid);
- CHECK(attr, NULL, "H5VL_object");
+ CHECK_PTR(attr, "H5VL_object");
/* Verify attribute version */
VERIFY(attr->shared->version, H5O_attr_ver_bounds[low], "H5O_attr_ver_bounds");
@@ -7165,7 +7185,7 @@ test_libver_bounds_attributes(hid_t fapl)
/* Get internal attribute pointer */
attr = (H5A_t *)H5VL_object(aid);
- CHECK(attr, NULL, "H5VL_object");
+ CHECK_PTR(attr, "H5VL_object");
/* Verify attribute version */
if (low == H5F_LIBVER_EARLIEST)
@@ -7230,7 +7250,7 @@ test_libver_bounds_attributes(hid_t fapl)
/* Get the internal attribute pointer */
attr = (H5A_t *)H5VL_object(aid);
- CHECK(attr, NULL, "H5VL_object");
+ CHECK_PTR(attr, "H5VL_object");
/* Verify the attribute version */
if (low == H5F_LIBVER_EARLIEST)
@@ -7292,7 +7312,7 @@ test_libver_bounds_attributes(hid_t fapl)
/* Get the internal file pointer */
f = (H5F_t *)H5VL_object(fid);
- CHECK(f, NULL, "H5VL_object");
+ CHECK_PTR(f, "H5VL_object");
/* Open the group */
gid = H5Gopen2(fid, GRP_NAME, H5P_DEFAULT);
@@ -7304,7 +7324,7 @@ test_libver_bounds_attributes(hid_t fapl)
/* Get the internal attribute pointer */
attr = (H5A_t *)H5VL_object(aid);
- CHECK(attr, NULL, "H5VL_object");
+ CHECK_PTR(attr, "H5VL_object");
/* Verify the attribute message version */
VERIFY(attr->shared->version, H5O_attr_ver_bounds[f->shared->low_bound],