summaryrefslogtreecommitdiffstats
path: root/test/swmr.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/swmr.c')
-rw-r--r--test/swmr.c190
1 files changed, 126 insertions, 64 deletions
diff --git a/test/swmr.c b/test/swmr.c
index bab91bd..a839a74 100644
--- a/test/swmr.c
+++ b/test/swmr.c
@@ -91,7 +91,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);
@@ -4256,8 +4256,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));
@@ -4416,9 +4419,11 @@ test_file_lock_swmr_same(hid_t in_fapl)
/* 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
+ 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));
@@ -4726,8 +4731,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));
@@ -5102,8 +5110,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));
@@ -5134,7 +5145,7 @@ test_file_lock_swmr_concur(hid_t in_fapl)
if(childpid == 0) { /* Child process */
hid_t child_fid; /* File ID */
- int child_notify = 0;
+ int child_notify = 0;
/* Close unused write end for out_pdf */
if(HDclose(out_pdf[1]) < 0)
@@ -5155,7 +5166,7 @@ test_file_lock_swmr_concur(hid_t in_fapl)
if(child_fid == FAIL)
HDexit(EXIT_SUCCESS);
- /* Close the pipe */
+ /* Close the pipe */
if(HDclose(out_pdf[0]) < 0)
HDexit(EXIT_FAILURE);
@@ -5205,13 +5216,13 @@ test_file_lock_swmr_concur(hid_t in_fapl)
/* Fork child process */
if((childpid = HDfork()) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
if(childpid == 0) { /* Child process */
hid_t child_fid; /* File ID */
- int child_notify = 0;
+ int child_notify = 0;
- /* Close unused write end for out_pdf */
+ /* Close unused write end for out_pdf */
if(HDclose(out_pdf[1]) < 0)
HDexit(EXIT_FAILURE);
@@ -5230,7 +5241,7 @@ test_file_lock_swmr_concur(hid_t in_fapl)
if(child_fid == FAIL)
HDexit(EXIT_SUCCESS);
- /* Close the pipe */
+ /* Close the pipe */
if(HDclose(out_pdf[0]) < 0)
HDexit(EXIT_FAILURE);
@@ -5243,7 +5254,7 @@ test_file_lock_swmr_concur(hid_t in_fapl)
/* Open the test file */
if((fid = H5Fopen(filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
/* Notify child process */
notify = 1;
@@ -5256,7 +5267,7 @@ test_file_lock_swmr_concur(hid_t in_fapl)
/* Wait for child process to complete */
if(HDwaitpid(childpid, &child_status, child_wait_option) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
/* Check if child terminated normally */
if(WIFEXITED(child_status)) {
@@ -5284,7 +5295,7 @@ test_file_lock_swmr_concur(hid_t in_fapl)
if(childpid == 0) { /* Child process */
hid_t child_fid; /* File ID */
- int child_notify = 0;
+ int child_notify = 0;
/* Close unused write end for out_pdf */
if(HDclose(out_pdf[1]) < 0)
@@ -5305,7 +5316,7 @@ test_file_lock_swmr_concur(hid_t in_fapl)
if(child_fid == FAIL)
HDexit(EXIT_SUCCESS);
- /* Close the pipe */
+ /* Close the pipe */
if(HDclose(out_pdf[0]) < 0)
HDexit(EXIT_FAILURE);
@@ -5354,11 +5365,11 @@ test_file_lock_swmr_concur(hid_t in_fapl)
/* Fork child process */
if((childpid = HDfork()) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
if(childpid == 0) { /* Child process */
hid_t child_fid; /* File ID */
- int child_notify = 0;
+ int child_notify = 0;
/* Close unused write end for out_pdf */
if(HDclose(out_pdf[1]) < 0)
@@ -5379,7 +5390,7 @@ test_file_lock_swmr_concur(hid_t in_fapl)
if(child_fid == FAIL)
HDexit(EXIT_SUCCESS);
- /* Close the pipe */
+ /* Close the pipe */
if(HDclose(out_pdf[0]) < 0)
HDexit(EXIT_FAILURE);
@@ -5392,7 +5403,7 @@ test_file_lock_swmr_concur(hid_t in_fapl)
/* Open the test file */
if((fid = H5Fopen(filename, H5F_ACC_RDWR|H5F_ACC_SWMR_WRITE, fapl)) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
/* Notify child process */
notify = 1;
@@ -5405,7 +5416,7 @@ test_file_lock_swmr_concur(hid_t in_fapl)
/* Wait for child process to complete */
if(HDwaitpid(childpid, &child_status, child_wait_option) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
/* Check if child terminated normally */
if(WIFEXITED(child_status)) {
@@ -5428,11 +5439,11 @@ test_file_lock_swmr_concur(hid_t in_fapl)
/* Fork child process */
if((childpid = HDfork()) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
if(childpid == 0) { /* Child process */
hid_t child_fid; /* File ID */
- int child_notify = 0;
+ int child_notify = 0;
/* Close unused write end for out_pdf */
if(HDclose(out_pdf[1]) < 0)
@@ -5456,7 +5467,7 @@ test_file_lock_swmr_concur(hid_t in_fapl)
HDexit(EXIT_SUCCESS);
}
- /* Close the pipe */
+ /* Close the pipe */
if(HDclose(out_pdf[0]) < 0)
HDexit(EXIT_FAILURE);
@@ -5469,7 +5480,7 @@ test_file_lock_swmr_concur(hid_t in_fapl)
/* Open the test file */
if((fid = H5Fopen(filename, H5F_ACC_RDWR|H5F_ACC_SWMR_WRITE, fapl)) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
/* Notify child process */
notify = 1;
@@ -5482,7 +5493,7 @@ test_file_lock_swmr_concur(hid_t in_fapl)
/* Wait for child process to complete */
if(HDwaitpid(childpid, &child_status, child_wait_option) < 0)
- FAIL_STACK_ERROR
+ FAIL_STACK_ERROR
/* Check if child terminated normally */
if(WIFEXITED(child_status)) {
@@ -5509,7 +5520,7 @@ test_file_lock_swmr_concur(hid_t in_fapl)
if(childpid == 0) { /* Child process */
hid_t child_fid; /* File ID */
- int child_notify = 0;
+ int child_notify = 0;
/* Close unused write end for out_pdf */
if(HDclose(out_pdf[1]) < 0)
@@ -5530,7 +5541,7 @@ test_file_lock_swmr_concur(hid_t in_fapl)
if(child_fid == FAIL)
HDexit(EXIT_SUCCESS);
- /* Close the pipe */
+ /* Close the pipe */
if(HDclose(out_pdf[0]) < 0)
HDexit(EXIT_FAILURE);
@@ -5584,7 +5595,7 @@ test_file_lock_swmr_concur(hid_t in_fapl)
if(childpid == 0) { /* Child process */
hid_t child_fid; /* File ID */
- int child_notify = 0;
+ int child_notify = 0;
/* Close unused write end for out_pdf */
if(HDclose(out_pdf[1]) < 0)
@@ -5598,14 +5609,14 @@ 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;
/* Should fail */
if(child_fid == FAIL)
HDexit(EXIT_SUCCESS);
- /* Close the pipe */
+ /* Close the pipe */
if(HDclose(out_pdf[0]) < 0)
HDexit(EXIT_FAILURE);
@@ -5659,7 +5670,7 @@ test_file_lock_swmr_concur(hid_t in_fapl)
if(childpid == 0) { /* Child process */
hid_t child_fid; /* File ID */
- int child_notify = 0;
+ int child_notify = 0;
/* Close unused write end for out_pdf */
if(HDclose(out_pdf[1]) < 0)
@@ -5734,7 +5745,7 @@ test_file_lock_swmr_concur(hid_t in_fapl)
if(childpid == 0) { /* Child process */
hid_t child_fid; /* File ID */
- int child_notify = 0;
+ int child_notify = 0;
/* Close unused write end for out_pdf */
if(HDclose(out_pdf[1]) < 0)
@@ -5812,7 +5823,7 @@ test_file_lock_swmr_concur(hid_t in_fapl)
if(childpid == 0) { /* Child process */
hid_t child_fid; /* File ID */
- int child_notify = 0;
+ int child_notify = 0;
/* Close unused write end for out_pdf */
if(HDclose(out_pdf[1]) < 0)
@@ -5835,7 +5846,7 @@ test_file_lock_swmr_concur(hid_t in_fapl)
HDexit(EXIT_SUCCESS);
}
- /* Close the pipe */
+ /* Close the pipe */
if(HDclose(out_pdf[0]) < 0)
HDexit(EXIT_FAILURE);
@@ -5889,7 +5900,7 @@ test_file_lock_swmr_concur(hid_t in_fapl)
if(childpid == 0) { /* Child process */
hid_t child_fid; /* File ID */
- int child_notify = 0;
+ int child_notify = 0;
/* Close unused write end for out_pdf */
if(HDclose(out_pdf[1]) < 0)
@@ -5910,7 +5921,7 @@ test_file_lock_swmr_concur(hid_t in_fapl)
if(child_fid == FAIL)
HDexit(EXIT_SUCCESS);
- /* Close the pipe */
+ /* Close the pipe */
if(HDclose(out_pdf[0]) < 0)
HDexit(EXIT_FAILURE);
@@ -5922,7 +5933,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 */
@@ -5964,7 +5975,7 @@ test_file_lock_swmr_concur(hid_t in_fapl)
if(childpid == 0) { /* Child process */
hid_t child_fid; /* File ID */
- int child_notify = 0;
+ int child_notify = 0;
/* Close unused write end for out_pdf */
if(HDclose(out_pdf[1]) < 0)
@@ -6059,7 +6070,7 @@ error:
**
*****************************************************************/
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))
SKIPPED();
@@ -6074,18 +6085,40 @@ test_file_lock_env_var(hid_t in_fapl)
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")
-
- TESTING("File locking environment variable");
-
-
- /* 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));
@@ -6097,10 +6130,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 */
@@ -6115,7 +6146,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 */
@@ -6126,18 +6157,23 @@ 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)
@@ -6160,15 +6196,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
@@ -6192,7 +6241,7 @@ error:
#endif /* !(defined(H5_HAVE_FORK && defined(H5_HAVE_WAITPID)) */
-} /* end test_file_lock_env_var() */
+} /* end test_file_locking() */
static int
@@ -7019,7 +7068,7 @@ error:
H5Fclose(fid3);
} H5E_END_TRY;
- return -1;
+ return 1;
} /* test_multiple_same() */
@@ -7036,6 +7085,7 @@ main(void)
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.
@@ -7056,6 +7106,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();
@@ -7097,7 +7154,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
@@ -7127,7 +7184,12 @@ main(void)
/* This test changes the HDF5_USE_FILE_LOCKING environment variable
* so it 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;