summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorvchoi <vchoi@jelly.ad.hdfgroup.org>2021-03-02 00:04:33 (GMT)
committervchoi <vchoi@jelly.ad.hdfgroup.org>2021-03-02 00:04:33 (GMT)
commitf792bdbbc5b3669ac08a77a87e072c98d53fff60 (patch)
tree2cf64cd4cb05ca59e696e04c33365f1e23530882 /test
parentf6e7edcedf0339bd18ca0a995f9877a778180f5f (diff)
parentdb95737047fbbf967d928bf9a693d470884f4890 (diff)
downloadhdf5-f792bdbbc5b3669ac08a77a87e072c98d53fff60.zip
hdf5-f792bdbbc5b3669ac08a77a87e072c98d53fff60.tar.gz
hdf5-f792bdbbc5b3669ac08a77a87e072c98d53fff60.tar.bz2
Merge remote-tracking branch 'canonical/feature/vfd_swmr' into feature/vfd_swmr
Diffstat (limited to 'test')
-rw-r--r--test/CMakeLists.txt8
-rw-r--r--test/vfd_swmr_common.c87
-rw-r--r--test/vfd_swmr_common.h6
3 files changed, 97 insertions, 4 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 023c07e..ad6b258 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -46,6 +46,11 @@ if (NOT ONLY_SHARED_LIBS)
endif ()
H5_SET_LIB_OPTIONS (${HDF5_TEST_LIB_TARGET} ${HDF5_TEST_LIB_NAME} STATIC 0)
set_target_properties (${HDF5_TEST_LIB_TARGET} PROPERTIES FOLDER libraries/test)
+
+ # Always link to pthreads for VFD SWMR tests
+ if (NOT WIN32)
+ target_link_libraries (${HDF5_TEST_LIB_TARGET} PRIVATE Threads::Threads)
+ endif ()
endif ()
if (BUILD_SHARED_LIBS)
@@ -66,6 +71,9 @@ if (BUILD_SHARED_LIBS)
endif ()
H5_SET_LIB_OPTIONS (${HDF5_TEST_LIBSH_TARGET} ${HDF5_TEST_LIB_NAME} SHARED "LIB")
set_target_properties (${HDF5_TEST_LIBSH_TARGET} PROPERTIES FOLDER libraries/test)
+
+ # Always link to pthreads for VFD SWMR tests
+ target_link_libraries (${HDF5_TEST_LIBSH_TARGET} PRIVATE Threads::Threads)
endif ()
#################################################################################
diff --git a/test/vfd_swmr_common.c b/test/vfd_swmr_common.c
index 9da0640..9352a37 100644
--- a/test/vfd_swmr_common.c
+++ b/test/vfd_swmr_common.c
@@ -21,6 +21,11 @@
#include <err.h> /* for err(3) */
+/* Only need the pthread solution if sigtimedwai(2) isn't available */
+#ifndef H5_HAVE_SIGTIMEDWAIT
+#include <pthread.h>
+#endif
+
#include "h5test.h"
#include "vfd_swmr_common.h"
#include "swmr_common.h"
@@ -178,6 +183,55 @@ strsignal(int signum)
}
#endif
+#ifndef H5_HAVE_SIGTIMEDWAIT
+
+typedef struct timer_params_t {
+ struct timespec *tick;
+ hid_t fid;
+} timer_params_t;
+
+pthread_mutex_t timer_mutex;
+hbool_t timer_stop = FALSE;
+
+static void *
+timer_function(void *arg)
+{
+ timer_params_t *params = (timer_params_t *)arg;
+ sigset_t sleepset;
+ hbool_t done = FALSE;
+
+ /* Ignore any signals */
+ sigfillset(&sleepset);
+ pthread_sigmask(SIG_SETMASK, &sleepset, NULL);
+
+ for (;;) {
+ estack_state_t es;
+
+ nanosleep(params->tick, NULL);
+
+ /* Check the mutex */
+ pthread_mutex_lock(&timer_mutex);
+ done = timer_stop;
+ pthread_mutex_unlock(&timer_mutex);
+ if (done)
+ break;
+
+ /* Avoid deadlock with peer: periodically enter the API so that
+ * tick processing occurs and data is flushed so that the peer
+ * can see it.
+ *
+ * The call we make will fail, but that's ok,
+ * so squelch errors.
+ */
+ es = disable_estack();
+ (void)H5Aexists_by_name(params->fid, "nonexistent", "nonexistent", H5P_DEFAULT);
+ restore_estack(es);
+ }
+
+ return NULL;
+}
+#endif /* H5_HAVE_SIGTIMEDWAIT */
+
/* Wait for any signal to occur and then return. Wake periodically
* during the wait to perform API calls: in this way, the
* VFD SWMR tick number advances and recent changes do not languish
@@ -186,8 +240,8 @@ strsignal(int signum)
void
await_signal(hid_t fid)
{
- sigset_t sleepset;
struct timespec tick = {.tv_sec = 0, .tv_nsec = 1000000000 / 100};
+ sigset_t sleepset;
if (sigfillset(&sleepset) == -1) {
err(EXIT_FAILURE, "%s.%d: could not initialize signal mask",
@@ -202,7 +256,37 @@ await_signal(hid_t fid)
dbgf(1, "waiting for signal\n");
+#ifndef H5_HAVE_SIGTIMEDWAIT
+ {
+ /* Use an alternative scheme for platforms like MacOS that do not have
+ * sigtimedwait(2)
+ */
+ timer_params_t params;
+ int rc;
+ pthread_t timer;
+
+ params.tick = &tick;
+ params.fid = fid;
+
+ pthread_mutex_init(&timer_mutex, NULL);
+
+ pthread_create(&timer, NULL, timer_function, &params);
+
+ rc = sigwait(&sleepset, NULL);
+
+ if (rc != -1) {
+ fprintf(stderr, "Received signal, wrapping things up.\n");
+ pthread_mutex_lock(&timer_mutex);
+ timer_stop = TRUE;
+ pthread_mutex_unlock(&timer_mutex);
+ pthread_join(timer, NULL);
+ }
+ else
+ err(EXIT_FAILURE, "%s: sigtimedwait", __func__);
+ }
+#else
for (;;) {
+ /* Linux and other systems */
const int rc = sigtimedwait(&sleepset, NULL, &tick);
if (rc != -1) {
@@ -226,6 +310,7 @@ await_signal(hid_t fid)
} else if (rc == -1)
err(EXIT_FAILURE, "%s: sigtimedwait", __func__);
}
+#endif /* H5_HAVE_SIGTIMEDWAIT */
}
/* Revised support routines that can be used for all VFD SWMR integration tests
diff --git a/test/vfd_swmr_common.h b/test/vfd_swmr_common.h
index 86f5f45..bbcb28a 100644
--- a/test/vfd_swmr_common.h
+++ b/test/vfd_swmr_common.h
@@ -11,8 +11,8 @@
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-#ifndef _VFD_SWMR_COMMON_H
-#define _VFD_SWMR_COMMON_H
+#ifndef VFD_SWMR_COMMON_H
+#define VFD_SWMR_COMMON_H
/***********/
/* Headers */
@@ -103,4 +103,4 @@ H5TEST_DLL size_t strlcpy(char *, const char *, size_t);
extern int verbosity;
-#endif /* _SWMR_COMMON_H */
+#endif /* SWMR_COMMON_H */