summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDavid Young <dyoung@hdfgroup.org>2020-09-17 19:35:54 (GMT)
committerDavid Young <dyoung@hdfgroup.org>2020-09-17 19:35:54 (GMT)
commit8e2053bb3d29ab8f90cd28d7e66641ac2472063e (patch)
tree089e994dc2e2bd4bbea63b15f08fdbdc36bbc80a /test
parentda688311afebd2d6b188c50cbf78c5e05e757ba9 (diff)
downloadhdf5-8e2053bb3d29ab8f90cd28d7e66641ac2472063e.zip
hdf5-8e2053bb3d29ab8f90cd28d7e66641ac2472063e.tar.gz
hdf5-8e2053bb3d29ab8f90cd28d7e66641ac2472063e.tar.bz2
Move below_speed_limit() from vfd_swmr_bigset_writer.c to
vfd_swmr_common.c, document it, and fix a bug.
Diffstat (limited to 'test')
-rw-r--r--test/vfd_swmr_bigset_writer.c24
-rw-r--r--test/vfd_swmr_common.c37
-rw-r--r--test/vfd_swmr_common.h2
3 files changed, 39 insertions, 24 deletions
diff --git a/test/vfd_swmr_bigset_writer.c b/test/vfd_swmr_bigset_writer.c
index 001edd7..98824b5 100644
--- a/test/vfd_swmr_bigset_writer.c
+++ b/test/vfd_swmr_bigset_writer.c
@@ -694,30 +694,6 @@ close_extensible_dset(state_t *s, unsigned int which)
}
}
-static bool
-below_speed_limit(struct timespec *last, const struct timespec *ival)
-{
- struct timespec now;
- bool result;
-
- assert(0 <= last->tv_nsec && last->tv_nsec < 1000000000L);
- assert(0 <= ival->tv_nsec && ival->tv_nsec < 1000000000L);
-
- if (clock_gettime(CLOCK_MONOTONIC, &now) == -1)
- err(EXIT_FAILURE, "%s: clock_gettime", __func__);
-
- if (now.tv_sec - last->tv_sec > ival->tv_sec)
- result = true;
- else if (now.tv_sec - last->tv_sec < ival->tv_sec)
- return false;
- else
- result = (now.tv_nsec - last->tv_nsec > ival->tv_nsec);
-
- *last = now;
-
- return result;
-}
-
static void
open_extensible_dset(state_t *s, unsigned int which)
{
diff --git a/test/vfd_swmr_common.c b/test/vfd_swmr_common.c
index f09336e..b986b31 100644
--- a/test/vfd_swmr_common.c
+++ b/test/vfd_swmr_common.c
@@ -28,6 +28,43 @@ static const hid_t badhid = H5I_INVALID_HID;
int verbosity = 2;
+/* Return true no more than once in any `ival` interval of time,
+ * as measured by the system's monotonically increasing timer, to
+ * help rate-limit activities.
+ *
+ * Read the system's current time and compare it with the time stored in
+ * `last`. If the difference between `last` and the current time is
+ * greater than the duration `ival`, then record the current time at
+ * `last` and return true. Otherwise, return false.
+ */
+bool
+below_speed_limit(struct timespec *last, const struct timespec *ival)
+{
+ struct timespec now;
+ bool result;
+
+ assert(0 <= last->tv_nsec && last->tv_nsec < 1000000000L);
+ assert(0 <= ival->tv_nsec && ival->tv_nsec < 1000000000L);
+
+ if (clock_gettime(CLOCK_MONOTONIC, &now) == -1)
+ err(EXIT_FAILURE, "%s: clock_gettime", __func__);
+
+ if (now.tv_sec - last->tv_sec > ival->tv_sec)
+ result = true;
+ else if (now.tv_sec - last->tv_sec < ival->tv_sec)
+ result = false;
+ else
+ result = (now.tv_nsec - last->tv_nsec >= ival->tv_nsec);
+
+ if (result)
+ *last = now;
+
+ return result;
+}
+
+/* Like vsnprintf(3), but abort the program with an error message on
+ * `stderr` if the buffer is too small or some other error occurs.
+ */
void
evsnprintf(char *buf, size_t bufsz, const char *fmt, va_list ap)
{
diff --git a/test/vfd_swmr_common.h b/test/vfd_swmr_common.h
index 8e1f877..51e8c80 100644
--- a/test/vfd_swmr_common.h
+++ b/test/vfd_swmr_common.h
@@ -81,6 +81,8 @@ H5TEST_DLLVAR unsigned symbol_count[NLEVELS];
extern "C" {
#endif
+H5TEST_DLL bool below_speed_limit(struct timespec *, const struct timespec *);
+
H5TEST_DLL estack_state_t estack_get_state(void);
H5TEST_DLL estack_state_t disable_estack(void);
H5TEST_DLL void restore_estack(estack_state_t);