summaryrefslogtreecommitdiffstats
path: root/test/genall5.c
diff options
context:
space:
mode:
authorDavid Young <dyoung@hdfgroup.org>2020-04-30 20:39:35 (GMT)
committerDavid Young <dyoung@hdfgroup.org>2020-04-30 20:39:35 (GMT)
commitc07a958e1d047bbe33e544a322720843ae3cfce4 (patch)
tree012857fad73f4f5a37db16f4a1b7721dcb800ee4 /test/genall5.c
parentfdeeac1c1b6c240d172519cd65a8f43378a62630 (diff)
downloadhdf5-c07a958e1d047bbe33e544a322720843ae3cfce4.zip
hdf5-c07a958e1d047bbe33e544a322720843ae3cfce4.tar.gz
hdf5-c07a958e1d047bbe33e544a322720843ae3cfce4.tar.bz2
Insert a random delay between zoo-writer test steps. Let us control
the random seed with an environment variable, H5_ZOO_STEP_SEED, and the maximum delay in milliseconds with a command-line option, `-m ms`.
Diffstat (limited to 'test/genall5.c')
-rw-r--r--test/genall5.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/test/genall5.c b/test/genall5.c
index b9a66f8..dfc835e 100644
--- a/test/genall5.c
+++ b/test/genall5.c
@@ -2676,6 +2676,31 @@ create_or_validate_selection(hid_t fid, const char *full_path,
return true;
}
+/* Sleep for no more than `max_pause_msecs` milliseconds. */
+static void
+random_pause(unsigned int max_pause_msecs)
+{
+ struct timespec delay;
+ const uint64_t nsecs_per_sec = 1000 * 1000 * 1000;
+ uint64_t nsecs_per_msec, nsecs;
+
+ if (max_pause_msecs == 0)
+ return;
+
+ nsecs_per_msec = 1 + (uint64_t)random() % (1000 * 1000);
+ nsecs = max_pause_msecs * nsecs_per_msec;
+
+ delay.tv_sec = (time_t)(nsecs / nsecs_per_sec);
+ delay.tv_nsec = (long)(nsecs % nsecs_per_sec);
+ for (;;) {
+ if (nanosleep(&delay, &delay) == 0)
+ break;
+ if (errno == EINTR)
+ continue;
+ errx(EXIT_FAILURE, "%s: nanosleep", __func__);
+ }
+}
+
/* Create and validate objects or, if `only_validate` is true, only
* validate objects in file `fid` under group `base_path`. `config.proc_num`
* tells the processor number the test runs on. If `config.skip_varlen` is
@@ -2688,7 +2713,6 @@ static bool
tend_zoo(hid_t fid, const char *base_path, zoo_config_t config,
const phase_t *phase, size_t nphases)
{
- struct timespec delay = {.tv_sec = 0, .tv_nsec = 50 * 1000 * 1000};
char full_path[1024];
int i, nwritten;
size_t j;
@@ -2716,8 +2740,8 @@ tend_zoo(hid_t fid, const char *base_path, zoo_config_t config,
if (phase[j] == PHASE_CREATE || phase[j] == PHASE_DELETE)
zoo_create_hook(fid);
}
+ random_pause(config.max_pause_msecs);
}
- nanosleep(&delay, NULL);
out:
if (!ok)
warnx("%s: %s", __func__, failure_mssg);