From 8e14c386aaa9e09dd9bc7d2b28995ff73b1a9903 Mon Sep 17 00:00:00 2001 From: songyulu Date: Fri, 5 Mar 2021 09:44:36 -0600 Subject: Changed the signal handling to named pipes for communication between the writer and reader, mainly in the zoo test as a starting point. --- test/genall5.c | 15 +++-- test/testvfdswmr.sh.in | 12 ++-- test/vfd_swmr.c | 15 ----- test/vfd_swmr_common.c | 15 +++++ test/vfd_swmr_common.h | 1 + test/vfd_swmr_zoo_writer.c | 162 ++++++++++++++++++++++++++++++++++++++------- 6 files changed, 165 insertions(+), 55 deletions(-) diff --git a/test/genall5.c b/test/genall5.c index 2874b59..1d9c86b 100644 --- a/test/genall5.c +++ b/test/genall5.c @@ -416,7 +416,7 @@ vrfy_ns_grp_c(hid_t fid, const char *group_name, unsigned nlinks) gid = H5Gopen2(fid, group_name, H5P_DEFAULT); if (gid <= 0) { - failure_mssg = "vrfy_ns_grp_c: H5Gopen2() failed"; + failure_mssg = "vrfy_ns_grp_c: H5Gopen2 failed"; return false; } @@ -2755,12 +2755,13 @@ tend_zoo(hid_t fid, const char *base_path, struct timespec *lastmsgtime, } out: if (!ok) { - if (strcmp(failure_mssg, last_failure_mssg) != 0) - *lastmsgtime = (struct timespec){.tv_sec = 0, .tv_nsec = 0}; - - if (below_speed_limit(lastmsgtime, &config.msgival)) { - last_failure_mssg = failure_mssg; - warnx("%s: %s", __func__, failure_mssg); + /* Only the zoo test for VFD SWMR does this step, making sure it doesn't take too long. + * other tests sets config.msgival to 0 */ + if (strcmp(failure_mssg, last_failure_mssg) != 0 && ((config.msgival.tv_sec || config.msgival.tv_nsec))) { + if (below_speed_limit(lastmsgtime, &config.msgival)) { + last_failure_mssg = failure_mssg; + warnx("%s: %s", __func__, failure_mssg); + } } } return ok; diff --git a/test/testvfdswmr.sh.in b/test/testvfdswmr.sh.in index a66ddf4..97c13cf 100644 --- a/test/testvfdswmr.sh.in +++ b/test/testvfdswmr.sh.in @@ -547,16 +547,14 @@ done # read and written by VFD SWMR. # if [ ${do_zoo:-no} = yes ]; then - [ -e ./fifo ] && rm -f ./fifo - mkfifo -m 0600 ./fifo rm -f ./shared_tick_num echo launch vfd_swmr_zoo_writer - STDIN_PATH="./fifo" catch_out_err_and_rc vfd_swmr_zoo_writer \ - ../vfd_swmr_zoo_writer -m 1000 -q & + catch_out_err_and_rc vfd_swmr_zoo_writer \ + ../vfd_swmr_zoo_writer -l 5 -m 1000 -q & pid_writer=$! - STDOUT_PATH="./fifo" catch_out_err_and_rc vfd_swmr_zoo_reader \ - ../vfd_swmr_zoo_reader -q -W & + catch_out_err_and_rc vfd_swmr_zoo_reader \ + ../vfd_swmr_zoo_reader -l 10 -q -W & pid_reader=$! # Wait for the reader to finish before signalling the @@ -564,7 +562,6 @@ if [ ${do_zoo:-no} = yes ]; then # reader will find the shadow file when it opens # the .h5 file. wait $pid_reader - kill -USR1 $(cat vfd_swmr_zoo_writer.pid) wait $pid_writer # Collect exit code of the reader @@ -580,7 +577,6 @@ if [ ${do_zoo:-no} = yes ]; then fi # Clean up output files - rm -f ./fifo rm -f vfd_swmr_zoo_writer.{out,rc} rm -f vfd_swmr_zoo_reader.*.{out,rc} fi diff --git a/test/vfd_swmr.c b/test/vfd_swmr.c index d49629f..9d2c2c0 100644 --- a/test/vfd_swmr.c +++ b/test/vfd_swmr.c @@ -824,21 +824,6 @@ error: return 1; } /* test_writer_create_open_flush() */ -/* Sleep for `tenths` tenths of a second. - * - * This routine may quietly perform a too-short sleep if an error occurs - * in nanosleep(2). - */ -static void -decisleep(uint32_t tenths) -{ - struct timespec delay = {.tv_sec = tenths / 10, - .tv_nsec = tenths * 100 * 1000 * 1000}; - - while (nanosleep(&delay, &delay) == -1 && errno == EINTR) - ; // do nothing -} - /*------------------------------------------------------------------------- * Function: test_writer_md() diff --git a/test/vfd_swmr_common.c b/test/vfd_swmr_common.c index 043b7ed..bc68617 100644 --- a/test/vfd_swmr_common.c +++ b/test/vfd_swmr_common.c @@ -63,6 +63,21 @@ below_speed_limit(struct timespec *last, const struct timespec *ival) return result; } +/* Sleep for `tenths` tenths of a second. + * + * This routine may quietly perform a too-short sleep if an error occurs + * in nanosleep(2). + */ +void +decisleep(uint32_t tenths) +{ + struct timespec delay = {.tv_sec = tenths / 10, + .tv_nsec = tenths * 100 * 1000 * 1000}; + + while (nanosleep(&delay, &delay) == -1 && errno == EINTR) + ; // do nothing +} + /* Like vsnprintf(3), but abort the program with an error message on * `stderr` if the buffer is too small or some other error occurs. */ diff --git a/test/vfd_swmr_common.h b/test/vfd_swmr_common.h index a4bf50e..90c0f36 100644 --- a/test/vfd_swmr_common.h +++ b/test/vfd_swmr_common.h @@ -62,6 +62,7 @@ extern "C" { #endif H5TEST_DLL bool below_speed_limit(struct timespec *, const struct timespec *); +H5TEST_DLL void decisleep(uint32_t tenths); H5TEST_DLL estack_state_t estack_get_state(void); H5TEST_DLL estack_state_t disable_estack(void); diff --git a/test/vfd_swmr_zoo_writer.c b/test/vfd_swmr_zoo_writer.c index c98b2e1..a7ae40a 100644 --- a/test/vfd_swmr_zoo_writer.c +++ b/test/vfd_swmr_zoo_writer.c @@ -37,6 +37,8 @@ #define _arraycount(_a) (sizeof(_a)/sizeof(_a[0])) #endif +#define MAX_READ_TIME 10 + typedef struct _shared_ticks { uint64_t reader_tick; } shared_ticks_t; @@ -93,7 +95,8 @@ usage(const char *progname) fprintf(stderr, " -W: do not wait for SIGINT or SIGUSR1\n"); fprintf(stderr, " -a: run all tests, including variable-length data\n"); fprintf(stderr, " -e: print error stacks\n"); - fprintf(stderr, " -m ms: maximum `ms` milliseconds pause between\n"); + fprintf(stderr, " -l secs: maximal seconds for reader to validate the zoo\n"); + fprintf(stderr, " -m ms: maximal `ms` milliseconds pause between\n"); fprintf(stderr, " each create/delete step\n"); fprintf(stderr, " -q: be quiet: few/no progress messages\n"); fprintf(stderr, " -v: be verbose: most progress messages\n"); @@ -112,6 +115,9 @@ vfd_swmr_writer_may_increase_tick_to(uint64_t new_tick, bool wait_for_reader) dbgf(3, "%s: enter\n", __func__); if (fd == -1) { + if (access("./shared_tick_num", F_OK ) < 0) + return true; + fd = open("./shared_tick_num", O_RDONLY); if (fd == -1) { warn("%s: open", __func__); // TBD ratelimit/silence this warning @@ -208,14 +214,13 @@ main(int argc, char **argv) hid_t fapl, fcpl, fid; H5F_t *f; H5C_t *cache; - sigset_t oldsigs; herr_t ret; zoo_config_t config = { .proc_num = 0 , .skip_compact = false , .skip_varlen = true , .max_pause_msecs = 0 - , .msgival = {.tv_sec = 5, .tv_nsec = 0} + , .msgival = {.tv_sec = MAX_READ_TIME, .tv_nsec = 0} }; struct timespec lastmsgtime = {.tv_sec = 0, .tv_nsec = 0}; bool wait_for_signal; @@ -230,8 +235,14 @@ main(int argc, char **argv) const char *progname = basename(argv[0]); const char *personality = strstr(progname, "vfd_swmr_zoo_"); estack_state_t es; - char step = 'b'; H5F_vfd_swmr_config_t vfd_swmr_config; + int fd_writer_to_reader, fd_reader_to_writer; + const char *fifo_writer_to_reader = "./fifo_writer_to_reader"; + const char *fifo_reader_to_writer = "./fifo_reader_to_writer"; + int notify = 0; + unsigned int i; + struct timespec last = {0, 0}; + struct timespec ival = {MAX_READ_TIME, 0}; /* Expected maximal time for reader's validation */ if (personality != NULL && strcmp(personality, "vfd_swmr_zoo_writer") == 0) writer = wait_for_signal = true; @@ -246,7 +257,7 @@ main(int argc, char **argv) if (writer) config.max_pause_msecs = 50; - while ((ch = getopt(argc, argv, "CSWaem:qv")) != -1) { + while ((ch = getopt(argc, argv, "CSWael:m:qv")) != -1) { switch(ch) { case 'C': config.skip_compact = true; @@ -263,6 +274,18 @@ main(int argc, char **argv) case 'e': print_estack = true; break; + case 'l': + /* Expected maximal time for reader's validation of zoo creation or deletion */ + errno = 0; + tmpl = strtoul(optarg, &end, 0); + if (end == optarg || *end != '\0') + errx(EXIT_FAILURE, "couldn't parse `-l` argument `%s`", optarg); + else if (errno != 0) + err(EXIT_FAILURE, "couldn't parse `-l` argument `%s`", optarg); + else if (tmpl > UINT_MAX) + errx(EXIT_FAILURE, "`-l` argument `%lu` too large", tmpl); + ival.tv_sec = (unsigned)tmpl; + break; case 'm': errno = 0; tmpl = strtoul(optarg, &end, 0); @@ -328,14 +351,26 @@ main(int argc, char **argv) cache = f->shared->cache; - if (wait_for_signal) - block_signals(&oldsigs); + /* Writer creates two named pipes(FIFO) to coordinate two-way communication */ + if (writer) { + if (HDmkfifo(fifo_writer_to_reader, 0666) < 0) + errx(EXIT_FAILURE, "HDmkfifo"); + + if (HDmkfifo(fifo_reader_to_writer, 0666) < 0) + errx(EXIT_FAILURE, "HDmkfifo"); + } + + /* Both the writer and reader open the pipes */ + if ((fd_writer_to_reader = HDopen(fifo_writer_to_reader, O_RDWR)) < 0) + errx(EXIT_FAILURE, "fifo_writer_to_reader open failed"); + + if ((fd_reader_to_writer = HDopen(fifo_reader_to_writer, O_RDWR)) < 0) + errx(EXIT_FAILURE, "fifo_reader_to_writer open failed"); print_cache_hits(cache); es = print_estack ? estack_get_state() : disable_estack(); if (writer) { - dbgf(2, "Writing zoo...\n"); /* get seed from environment or else from time(3) */ @@ -350,44 +385,108 @@ main(int argc, char **argv) break; } - dbgf(1, "To reproduce, set seed (%s) to %u.\n", seedvar, seed); + dbgf(2, "To reproduce, set seed (%s) to %u.\n", seedvar, seed); + + /* Writer tells reader to start */ + notify = 1; + if (HDwrite(fd_writer_to_reader, ¬ify, sizeof(int)) < 0) + err(EXIT_FAILURE, "write failed"); ostate = initstate(seed, vector, _arraycount(vector)); + if (clock_gettime(CLOCK_MONOTONIC, &lastmsgtime) < 0) + errx(EXIT_FAILURE, "%s: clock_gettime", __func__); + if (!create_zoo(fid, ".", &lastmsgtime, config)) errx(EXIT_FAILURE, "create_zoo didn't pass self-check"); - /* Avoid deadlock: flush the file before waiting for the reader's - * message. - */ - if (H5Fflush(fid, H5F_SCOPE_GLOBAL) < 0) - errx(EXIT_FAILURE, "%s: H5Fflush failed", __func__); + /* Notify the reader of finishing zoo creation */ + notify = 2; + if (HDwrite(fd_writer_to_reader, ¬ify, sizeof(int)) < 0) + err(EXIT_FAILURE, "write failed"); - if (read(STDIN_FILENO, &step, sizeof(step)) == -1) - err(EXIT_FAILURE, "read"); + /* During the wait, writer makes repeated HDF5 API calls so as to trigger + * EOT at approximately the correct time */ + for(i = 0; i < swmr_config.max_lag + 1; i++) { + decisleep(swmr_config.tick_len); + + H5Aexists(fid, "nonexistent"); + } - if (step != 'b') - errx(EXIT_FAILURE, "expected 'b' read '%c'", step); + /* Wait until the reader finishes validating zoo creation */ + if (HDread(fd_reader_to_writer, ¬ify, sizeof(int)) < 0) + err(EXIT_FAILURE, "read failed"); + if (notify != 3) + errx(EXIT_FAILURE, "expected 2 but read %d", notify); + + if (clock_gettime(CLOCK_MONOTONIC, &lastmsgtime) == -1) + errx(EXIT_FAILURE, "%s: clock_gettime", __func__); if (!delete_zoo(fid, ".", &lastmsgtime, config)) errx(EXIT_FAILURE, "delete_zoo failed"); (void)setstate(ostate); + + /* Notify the reader about finishing zoo deletion */ + notify = 4; + if (HDwrite(fd_writer_to_reader, ¬ify, sizeof(int)) == -1) + err(EXIT_FAILURE, "write failed"); + } else { dbgf(2, "Reading zoo...\n"); + /* Start to validate zoo creation after receiving the writer's notice */ + if (HDread(fd_writer_to_reader, ¬ify, sizeof(int)) < 0) + err(EXIT_FAILURE, "read failed"); + if (notify != 1) + errx(EXIT_FAILURE, "unexpected message %d", notify); + + /* Get the current time */ + if (clock_gettime(CLOCK_MONOTONIC, &lastmsgtime) < 0) + errx(EXIT_FAILURE, "%s: clock_gettime", __func__); + + last.tv_sec = lastmsgtime.tv_sec; + last.tv_nsec = lastmsgtime.tv_nsec; + while (!validate_zoo(fid, ".", &lastmsgtime, config)) ; - if (write(STDOUT_FILENO, &step, sizeof(step)) == -1) - err(EXIT_FAILURE, "write"); + /* Make sure zoo validation doesn't take longer than the expected time */ + if (below_speed_limit(&last, &ival)) + warnx("validate_zoo took too long to finish"); + + /* Receive the notice of the writer finishing zoo creation */ + if (HDread(fd_writer_to_reader, ¬ify, sizeof(int)) < 0) + err(EXIT_FAILURE, "read failed"); + if (notify != 2) + errx(EXIT_FAILURE, "unexpected message %d", notify); + + /* Notify the writer that zoo validation is finished */ + notify = 3; + if (HDwrite(fd_reader_to_writer, ¬ify, sizeof(int)) < 0) + err(EXIT_FAILURE, "write failed"); + + /* Get the current time before validating zoo deletion */ + if (clock_gettime(CLOCK_MONOTONIC, &lastmsgtime) < 0) + errx(EXIT_FAILURE, "%s: clock_gettime", __func__); + + last.tv_sec = lastmsgtime.tv_sec; + last.tv_nsec = lastmsgtime.tv_nsec; + while (!validate_deleted_zoo(fid, ".", &lastmsgtime, config)) ; + + /* Make sure validation of zoo deletion doesn't take longer than the expected time */ + if (below_speed_limit(&last, &ival)) + warnx("validate_deleted_zoo took too long to finish"); + + /* Receive the finish notice from the writer */ + if (HDread(fd_writer_to_reader, ¬ify, sizeof(int)) < 0) + err(EXIT_FAILURE, "read failed"); + if (notify != 4) + errx(EXIT_FAILURE, "unexpected message %d", notify); } restore_estack(es); - if (use_vfd_swmr && wait_for_signal) - await_signal(fid); - if (writer && tick_stats != NULL) { uint64_t lead; @@ -417,8 +516,21 @@ main(int argc, char **argv) if (H5Fclose(fid) < 0) errx(EXIT_FAILURE, "H5Fclose"); - if (wait_for_signal) - restore_signals(&oldsigs); + /* Close the named pipes */ + if (HDclose(fd_writer_to_reader) < 0) + errx(EXIT_FAILURE, "HDclose"); + + if (HDclose(fd_reader_to_writer) < 0) + errx(EXIT_FAILURE, "HDclose"); + + /* Reader finishes last and deletes the named pipes */ + if(!writer) { + if(HDremove(fifo_writer_to_reader) != 0) + errx(EXIT_FAILURE, "fifo_writer_to_reader deletion failed"); + + if(HDremove(fifo_reader_to_writer) != 0) + errx(EXIT_FAILURE, "fifo_reader_to_writer deletion failed"); + } return EXIT_SUCCESS; } -- cgit v0.12 From 79a94e0f431ac715d5cc0ca85c144901147207ab Mon Sep 17 00:00:00 2001 From: Songyu Lu Date: Thu, 25 Mar 2021 11:50:34 -0500 Subject: Added the HDF5 prefix (HD_) to several system calls. --- test/genall5.c | 2 +- test/vfd_swmr_zoo_writer.c | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/test/genall5.c b/test/genall5.c index 1d9c86b..bb77157 100644 --- a/test/genall5.c +++ b/test/genall5.c @@ -2756,7 +2756,7 @@ tend_zoo(hid_t fid, const char *base_path, struct timespec *lastmsgtime, out: if (!ok) { /* Only the zoo test for VFD SWMR does this step, making sure it doesn't take too long. - * other tests sets config.msgival to 0 */ + * Other tests sets config.msgival to 0 and will skip this step */ if (strcmp(failure_mssg, last_failure_mssg) != 0 && ((config.msgival.tv_sec || config.msgival.tv_nsec))) { if (below_speed_limit(lastmsgtime, &config.msgival)) { last_failure_mssg = failure_mssg; diff --git a/test/vfd_swmr_zoo_writer.c b/test/vfd_swmr_zoo_writer.c index 60c61d6..f529340 100644 --- a/test/vfd_swmr_zoo_writer.c +++ b/test/vfd_swmr_zoo_writer.c @@ -111,16 +111,16 @@ vfd_swmr_writer_may_increase_tick_to(uint64_t new_tick, bool wait_for_reader) dbgf(3, "%s: enter\n", __func__); if (fd == -1) { - if (access("./shared_tick_num", F_OK ) < 0) + if (HDaccess("./shared_tick_num", F_OK ) < 0) return true; - fd = open("./shared_tick_num", O_RDONLY); + fd = HDopen("./shared_tick_num", O_RDONLY); if (fd == -1) { warn("%s: open", __func__); // TBD ratelimit/silence this warning return true; } assert(tick_stats == NULL); - tick_stats = calloc(1, sizeof(*tick_stats) + + tick_stats = HDcalloc(1, sizeof(*tick_stats) + (swmr_config.max_lag - 1) * sizeof(tick_stats->writer_lead_reader_by[0])); if (tick_stats == NULL) @@ -136,7 +136,7 @@ vfd_swmr_writer_may_increase_tick_to(uint64_t new_tick, bool wait_for_reader) tick_stats->writer_read_shared_file++; - if ((nread = pread(fd, &shared, sizeof(shared), 0)) == -1) + if ((nread = HDpread(fd, &shared, sizeof(shared), 0)) == -1) err(EXIT_FAILURE, "%s: pread", __func__); if (nread != sizeof(shared)) @@ -180,7 +180,7 @@ vfd_swmr_reader_did_increase_tick_to(uint64_t new_tick) if (fd == -1) { // TBD create a temporary file, here, and move it to its final path // after writing it. - fd = open("./shared_tick_num", O_RDWR|O_CREAT, 0600); + fd = HDopen("./shared_tick_num", O_RDWR|O_CREAT, 0600); if (fd == -1) err(EXIT_FAILURE, "%s: open", __func__); } @@ -189,7 +189,7 @@ vfd_swmr_reader_did_increase_tick_to(uint64_t new_tick) // TBD convert endianness - if ((nwritten = pwrite(fd, &shared, sizeof(shared), 0)) == -1) + if ((nwritten = HDpwrite(fd, &shared, sizeof(shared), 0)) == -1) errx(EXIT_FAILURE, "%s: pwrite", __func__); if (nwritten != sizeof(shared)) @@ -273,7 +273,7 @@ main(int argc, char **argv) case 'l': /* Expected maximal time for reader's validation of zoo creation or deletion */ errno = 0; - tmpl = strtoul(optarg, &end, 0); + tmpl = HDstrtoul(optarg, &end, 0); if (end == optarg || *end != '\0') errx(EXIT_FAILURE, "couldn't parse `-l` argument `%s`", optarg); else if (errno != 0) @@ -284,7 +284,7 @@ main(int argc, char **argv) break; case 'm': errno = 0; - tmpl = strtoul(optarg, &end, 0); + tmpl = HDstrtoul(optarg, &end, 0); if (end == optarg || *end != '\0') errx(EXIT_FAILURE, "couldn't parse `-m` argument `%s`", optarg); else if (errno != 0) @@ -349,10 +349,10 @@ main(int argc, char **argv) /* Writer creates two named pipes(FIFO) to coordinate two-way communication */ if (writer) { - if (HDmkfifo(fifo_writer_to_reader, 0666) < 0) + if (HDmkfifo(fifo_writer_to_reader, 0600) < 0) errx(EXIT_FAILURE, "HDmkfifo"); - if (HDmkfifo(fifo_reader_to_writer, 0666) < 0) + if (HDmkfifo(fifo_reader_to_writer, 0600) < 0) errx(EXIT_FAILURE, "HDmkfifo"); } -- cgit v0.12 From 209a194993925166dd70815059e437074a3c2be4 Mon Sep 17 00:00:00 2001 From: Songyu Lu Date: Fri, 26 Mar 2021 12:25:14 -0500 Subject: Added the prefix (HD) to several C functions. --- test/vfd_swmr_zoo_writer.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/test/vfd_swmr_zoo_writer.c b/test/vfd_swmr_zoo_writer.c index 06d165d..fdfdd6b 100644 --- a/test/vfd_swmr_zoo_writer.c +++ b/test/vfd_swmr_zoo_writer.c @@ -179,11 +179,7 @@ vfd_swmr_reader_did_increase_tick_to(uint64_t new_tick) if (fd == -1) { // TBD create a temporary file, here, and move it to its final path // after writing it. -<<<<<<< HEAD - fd = open("./shared_tick_num", O_RDWR | O_CREAT, 0600); -======= - fd = HDopen("./shared_tick_num", O_RDWR|O_CREAT, 0600); ->>>>>>> 79a94e0f431ac715d5cc0ca85c144901147207ab + fd = HDopen("./shared_tick_num", O_RDWR | O_CREAT, 0600); if (fd == -1) err(EXIT_FAILURE, "%s: open", __func__); } @@ -224,15 +220,14 @@ main(int argc, char **argv) struct timespec lastmsgtime = {.tv_sec = 0, .tv_nsec = 0}; bool wait_for_signal; int ch; - char vector[8]; unsigned seed; unsigned long tmpl; - char *end, *ostate; + char *end; const char *seedvar = "H5_ZOO_STEP_SEED"; bool use_vfd_swmr = true; bool print_estack = false; - const char *progname = HDbasename(argv[0]); - const char *personality = strstr(progname, "vfd_swmr_zoo_"); + char *progname = NULL; + char *personality; estack_state_t es; H5F_vfd_swmr_config_t vfd_swmr_config; int fd_writer_to_reader, fd_reader_to_writer; @@ -243,6 +238,11 @@ main(int argc, char **argv) struct timespec last = {0, 0}; struct timespec ival = {MAX_READ_TIME, 0}; /* Expected maximal time for reader's validation */ + if (H5_basename(argv[0], &progname) < 0) + errx(EXIT_FAILURE, "H5_basename failed"); + + personality = HDstrstr(progname, "vfd_swmr_zoo_"); + if (personality != NULL && strcmp(personality, "vfd_swmr_zoo_writer") == 0) writer = wait_for_signal = true; else if (personality != NULL && strcmp(personality, "vfd_swmr_zoo_reader") == 0) @@ -422,8 +422,6 @@ main(int argc, char **argv) if (!delete_zoo(fid, ".", &lastmsgtime, config)) errx(EXIT_FAILURE, "delete_zoo failed"); - (void)setstate(ostate); - /* Notify the reader about finishing zoo deletion */ notify = 4; if (HDwrite(fd_writer_to_reader, ¬ify, sizeof(int)) == -1) @@ -509,6 +507,9 @@ main(int argc, char **argv) if (H5Fclose(fid) < 0) errx(EXIT_FAILURE, "H5Fclose"); + if (progname) + HDfree(progname); + /* Close the named pipes */ if (HDclose(fd_writer_to_reader) < 0) errx(EXIT_FAILURE, "HDclose"); -- cgit v0.12 From da80917711737e600fceda8f1068f0b35f2eda25 Mon Sep 17 00:00:00 2001 From: Songyu Lu Date: Mon, 5 Apr 2021 11:29:15 -0500 Subject: Two main changes include: re-arranging the communication between the writer and reader through the named pipes; using the error report consistent with other tests. --- test/genall5.c | 6 +- test/testvfdswmr.sh.in | 4 +- test/vfd_swmr.c | 9 - test/vfd_swmr_common.c | 12 +- test/vfd_swmr_group_writer.c | 9 - test/vfd_swmr_zoo_writer.c | 383 +++++++++++++++++++++++++++---------------- 6 files changed, 248 insertions(+), 175 deletions(-) diff --git a/test/genall5.c b/test/genall5.c index 2cb7b9e..016b368 100644 --- a/test/genall5.c +++ b/test/genall5.c @@ -19,6 +19,7 @@ * of the same name. */ +#include #include "cache_common.h" #include "vfd_swmr_common.h" /* for below_speed_limit() */ #include "genall5.h" @@ -2754,8 +2755,9 @@ tend_zoo(hid_t fid, const char *base_path, struct timespec *lastmsgtime, zoo_con out: if (!ok) { /* Only the zoo test for VFD SWMR does this step, making sure it doesn't take too long. - * Other tests sets config.msgival to 0 and will skip this step */ - if (strcmp(failure_mssg, last_failure_mssg) != 0 && ((config.msgival.tv_sec || config.msgival.tv_nsec))) { + * Other tests sets config.msgival or lastmsgtime to 0 and will skip this step */ + if (strcmp(failure_mssg, last_failure_mssg) != 0 && ((config.msgival.tv_sec || config.msgival.tv_nsec)) + && (lastmsgtime->tv_sec || lastmsgtime->tv_nsec)) { if (below_speed_limit(lastmsgtime, &config.msgival)) { last_failure_mssg = failure_mssg; warnx("%s: %s", __func__, failure_mssg); diff --git a/test/testvfdswmr.sh.in b/test/testvfdswmr.sh.in index e326ec3..67c1201 100644 --- a/test/testvfdswmr.sh.in +++ b/test/testvfdswmr.sh.in @@ -574,11 +574,11 @@ if [ ${do_zoo:-no} = yes ]; then rm -f ./shared_tick_num echo launch vfd_swmr_zoo_writer catch_out_err_and_rc vfd_swmr_zoo_writer \ - ../vfd_swmr_zoo_writer -l 5 -m 1000 -q & + ../vfd_swmr_zoo_writer -q & pid_writer=$! catch_out_err_and_rc vfd_swmr_zoo_reader \ - ../vfd_swmr_zoo_reader -l 10 -q -W & + ../vfd_swmr_zoo_reader -l 3 -q & pid_reader=$! # Wait for the reader to finish before signalling the diff --git a/test/vfd_swmr.c b/test/vfd_swmr.c index 0910409..542c07b 100644 --- a/test/vfd_swmr.c +++ b/test/vfd_swmr.c @@ -848,15 +848,6 @@ error: return 1; } /* test_writer_create_open_flush() */ -/* Sleep for `tenths` tenths of a second */ -static void -decisleep(uint32_t tenths) -{ - uint64_t nsec = tenths * 100 * 1000 * 1000; - - H5_nanosleep(nsec); -} - /*------------------------------------------------------------------------- * Function: test_writer_md() * diff --git a/test/vfd_swmr_common.c b/test/vfd_swmr_common.c index 0a5025d..f7152b9 100644 --- a/test/vfd_swmr_common.c +++ b/test/vfd_swmr_common.c @@ -72,19 +72,13 @@ below_speed_limit(struct timespec *last, const struct timespec *ival) return result; } -/* Sleep for `tenths` tenths of a second. - * - * This routine may quietly perform a too-short sleep if an error occurs - * in nanosleep(2). - */ +/* Sleep for `tenths` tenths of a second. */ void decisleep(uint32_t tenths) { - struct timespec delay = {.tv_sec = tenths / 10, - .tv_nsec = tenths * 100 * 1000 * 1000}; + uint64_t nsec = tenths * 100 * 1000 * 1000; - while (nanosleep(&delay, &delay) == -1 && errno == EINTR) - ; // do nothing + H5_nanosleep(nsec); } /* Like vsnprintf(3), but abort the program with an error message on diff --git a/test/vfd_swmr_group_writer.c b/test/vfd_swmr_group_writer.c index aa87b72f..ab1c1a4 100644 --- a/test/vfd_swmr_group_writer.c +++ b/test/vfd_swmr_group_writer.c @@ -245,15 +245,6 @@ verify_group(state_t *s, unsigned int which) return result; } -/* Sleep for `tenths` tenths of a second */ -static void -decisleep(uint32_t tenths) -{ - uint64_t nsec = tenths * 100 * 1000 * 1000; - - H5_nanosleep(nsec); -} - int main(int argc, char **argv) { diff --git a/test/vfd_swmr_zoo_writer.c b/test/vfd_swmr_zoo_writer.c index fdfdd6b..0b3c608 100644 --- a/test/vfd_swmr_zoo_writer.c +++ b/test/vfd_swmr_zoo_writer.c @@ -32,7 +32,8 @@ #define _arraycount(_a) (sizeof(_a) / sizeof(_a[0])) #endif -#define MAX_READ_TIME 10 +#define MAX_READ_LEN_IN_SECONDS 2 +#define TICK_LEN 4 typedef struct _shared_ticks { uint64_t reader_tick; @@ -53,7 +54,6 @@ typedef struct _tick_stats { static H5F_vfd_swmr_config_t swmr_config; static tick_stats_t * tick_stats = NULL; -static const hid_t badhid = H5I_INVALID_HID; static bool writer; static void @@ -99,6 +99,7 @@ usage(const char *progname) exit(EXIT_FAILURE); } +#ifndef TMP bool vfd_swmr_writer_may_increase_tick_to(uint64_t new_tick, bool wait_for_reader) { @@ -179,7 +180,7 @@ vfd_swmr_reader_did_increase_tick_to(uint64_t new_tick) if (fd == -1) { // TBD create a temporary file, here, and move it to its final path // after writing it. - fd = HDopen("./shared_tick_num", O_RDWR | O_CREAT, 0600); + fd = HDopen("./shared_tick_num", O_RDWR|O_CREAT, 0600); if (fd == -1) err(EXIT_FAILURE, "%s: open", __func__); } @@ -202,44 +203,45 @@ vfd_swmr_reader_did_increase_tick_to(uint64_t new_tick) fd = -1; } } +#endif int main(int argc, char **argv) { - hid_t fapl, fcpl, fid; + hid_t fapl = H5I_INVALID_HID, fcpl = H5I_INVALID_HID, fid = H5I_INVALID_HID; H5F_t *f; H5C_t *cache; - herr_t ret; zoo_config_t config = { .proc_num = 0 , .skip_compact = false , .skip_varlen = true , .max_pause_msecs = 0 - , .msgival = {.tv_sec = MAX_READ_TIME, .tv_nsec = 0} + , .msgival = {.tv_sec = 0, .tv_nsec = 0} }; struct timespec lastmsgtime = {.tv_sec = 0, .tv_nsec = 0}; bool wait_for_signal; int ch; - unsigned seed; unsigned long tmpl; char *end; - const char *seedvar = "H5_ZOO_STEP_SEED"; bool use_vfd_swmr = true; - bool print_estack = false; char *progname = NULL; char *personality; estack_state_t es; + bool print_estack = false; H5F_vfd_swmr_config_t vfd_swmr_config; - int fd_writer_to_reader, fd_reader_to_writer; + int fd_writer_to_reader = -1, fd_reader_to_writer = -1; const char *fifo_writer_to_reader = "./fifo_writer_to_reader"; const char *fifo_reader_to_writer = "./fifo_reader_to_writer"; int notify = 0; unsigned int i; struct timespec last = {0, 0}; - struct timespec ival = {MAX_READ_TIME, 0}; /* Expected maximal time for reader's validation */ + struct timespec ival = {MAX_READ_LEN_IN_SECONDS, 0}; /* Expected maximal time for reader's validation */ - if (H5_basename(argv[0], &progname) < 0) - errx(EXIT_FAILURE, "H5_basename failed"); + if (H5_basename(argv[0], &progname) < 0) { + H5_FAILED(); AT(); + printf("H5_basename failed\n"); + goto error; + } personality = HDstrstr(progname, "vfd_swmr_zoo_"); @@ -248,13 +250,15 @@ main(int argc, char **argv) else if (personality != NULL && strcmp(personality, "vfd_swmr_zoo_reader") == 0) writer = false; else { - errx(EXIT_FAILURE, "unknown personality, expected vfd_swmr_zoo_{reader,writer}"); + H5_FAILED(); AT(); + printf("unknown personality, expected vfd_swmr_zoo_{reader,writer}"); + goto error; } if (writer) config.max_pause_msecs = 50; - while ((ch = getopt(argc, argv, "CSWael:m:qv")) != -1) { + while ((ch = getopt(argc, argv, "CSael:qv")) != -1) { switch(ch) { case 'C': config.skip_compact = true; @@ -262,9 +266,6 @@ main(int argc, char **argv) case 'S': use_vfd_swmr = false; break; - case 'W': - wait_for_signal = false; - break; case 'a': config.skip_varlen = false; break; @@ -272,7 +273,7 @@ main(int argc, char **argv) print_estack = true; break; case 'l': - /* Expected maximal time for reader's validation of zoo creation or deletion */ + /* Expected maximal number of ticks for reader's validation of zoo creation or deletion */ errno = 0; tmpl = HDstrtoul(optarg, &end, 0); if (end == optarg || *end != '\0') @@ -281,18 +282,15 @@ main(int argc, char **argv) err(EXIT_FAILURE, "couldn't parse `-l` argument `%s`", optarg); else if (tmpl > UINT_MAX) errx(EXIT_FAILURE, "`-l` argument `%lu` too large", tmpl); - ival.tv_sec = (unsigned)tmpl; - break; - case 'm': - errno = 0; - tmpl = HDstrtoul(optarg, &end, 0); - if (end == optarg || *end != '\0') - errx(EXIT_FAILURE, "couldn't parse `-m` argument `%s`", optarg); - else if (errno != 0) - err(EXIT_FAILURE, "couldn't parse `-m` argument `%s`", optarg); - else if (tmpl > UINT_MAX) - errx(EXIT_FAILURE, "`-m` argument `%lu` too large", tmpl); - config.max_pause_msecs = (unsigned)tmpl; + { + /* Translate the tick number to time represented by the timespec struct */ + float time = (float)(((unsigned)tmpl * TICK_LEN) / 10.0); + unsigned sec = (unsigned)time; + unsigned nsec = (unsigned)((time - sec) * 10 * 1000 * 1000); + + ival.tv_sec = sec; + ival.tv_nsec = nsec; + } break; case 'q': verbosity = 1; @@ -308,61 +306,94 @@ main(int argc, char **argv) argv += optind; argc -= optind; - if (argc > 0) - errx(EXIT_FAILURE, "unexpected command-line arguments"); + if (argc > 0) { + H5_FAILED(); AT(); + printf("unexpected command-line arguments"); + goto error; + } /* config, tick_len, max_lag, writer, flush_raw_data, md_pages_reserved, md_file_path */ - init_vfd_swmr_config(&vfd_swmr_config, 4, 7, writer, FALSE, 128, "./zoo-shadow"); + init_vfd_swmr_config(&vfd_swmr_config, TICK_LEN, 7, writer, FALSE, 128, "./zoo-shadow"); /* ? turn off use latest format argument via 1st argument? since later on it reset to early format */ /* use_latest_format, use_vfd_swmr, only_meta_page, config */ - fapl = vfd_swmr_create_fapl(true, use_vfd_swmr, true, &vfd_swmr_config); - - if (use_vfd_swmr && H5Pget_vfd_swmr_config(fapl, &swmr_config) < 0) - errx(EXIT_FAILURE, "H5Pget_vfd_swmr_config"); + if ((fapl = vfd_swmr_create_fapl(true, use_vfd_swmr, true, &vfd_swmr_config)) < 0) { + H5_FAILED(); AT(); + printf("vfd_swmr_create_fapl"); + goto error; + } - if (fapl < 0) - errx(EXIT_FAILURE, "vfd_swmr_create_fapl"); + if (use_vfd_swmr && H5Pget_vfd_swmr_config(fapl, &swmr_config) < 0) { + H5_FAILED(); AT(); + printf("H5Pget_vfd_swmr_config failed"); + goto error; + } if (H5Pset_libver_bounds(fapl, H5F_LIBVER_EARLIEST, H5F_LIBVER_LATEST) < 0) { - errx(EXIT_FAILURE, "%s.%d: H5Pset_libver_bounds", __func__, __LINE__); + H5_FAILED(); AT(); + printf("H5Pset_libver_bounds failed"); + goto error; } - if ((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0) - errx(EXIT_FAILURE, "H5Pcreate"); + if ((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0) { + H5_FAILED(); AT(); + printf("H5Pcreate failed"); + goto error; + } - ret = H5Pset_file_space_strategy(fcpl, H5F_FSPACE_STRATEGY_PAGE, false, 1); - if (ret < 0) - errx(EXIT_FAILURE, "H5Pset_file_space_strategy"); + if (H5Pset_file_space_strategy(fcpl, H5F_FSPACE_STRATEGY_PAGE, false, 1) < 0) { + H5_FAILED(); AT(); + printf("H5Pset_file_space_strategy failed"); + goto error; + } if (writer) fid = H5Fcreate("vfd_swmr_zoo.h5", H5F_ACC_TRUNC, fcpl, fapl); else fid = H5Fopen("vfd_swmr_zoo.h5", H5F_ACC_RDONLY, fapl); - if (fid == badhid) + if (fid < 0) { errx(EXIT_FAILURE, writer ? "H5Fcreate" : "H5Fopen"); + H5_FAILED(); AT(); + printf(writer ? "H5Fcreate failed" : "H5Fopen failed"); + goto error; + } - if ((f = H5VL_object_verify(fid, H5I_FILE)) == NULL) - errx(EXIT_FAILURE, "H5VL_object_verify"); + if ((f = H5VL_object_verify(fid, H5I_FILE)) == NULL) { + H5_FAILED(); AT(); + printf("H5VL_object_verify failed"); + goto error; + } cache = f->shared->cache; /* Writer creates two named pipes(FIFO) to coordinate two-way communication */ if (writer) { - if (HDmkfifo(fifo_writer_to_reader, 0600) < 0) - errx(EXIT_FAILURE, "HDmkfifo"); + if (HDmkfifo(fifo_writer_to_reader, 0600) < 0) { + H5_FAILED(); AT(); + printf("HDmkfifo failed"); + goto error; + } - if (HDmkfifo(fifo_reader_to_writer, 0600) < 0) - errx(EXIT_FAILURE, "HDmkfifo"); + if (HDmkfifo(fifo_reader_to_writer, 0600) < 0) { + H5_FAILED(); AT(); + printf("HDmkfifo failed"); + goto error; + } } /* Both the writer and reader open the pipes */ - if ((fd_writer_to_reader = HDopen(fifo_writer_to_reader, O_RDWR)) < 0) - errx(EXIT_FAILURE, "fifo_writer_to_reader open failed"); + if ((fd_writer_to_reader = HDopen(fifo_writer_to_reader, O_RDWR)) < 0) { + H5_FAILED(); AT(); + printf("fifo_writer_to_reader open failed"); + goto error; + } - if ((fd_reader_to_writer = HDopen(fifo_reader_to_writer, O_RDWR)) < 0) - errx(EXIT_FAILURE, "fifo_reader_to_writer open failed"); + if ((fd_reader_to_writer = HDopen(fifo_reader_to_writer, O_RDWR)) < 0) { + H5_FAILED(); AT(); + printf("fifo_reader_to_writer open failed"); + goto error; + } print_cache_hits(cache); @@ -370,116 +401,139 @@ main(int argc, char **argv) if (writer) { dbgf(2, "Writing zoo...\n"); - /* get seed from environment or else from time(3) */ - switch (fetch_env_ulong(seedvar, UINT_MAX, &tmpl)) { - case -1: - errx(EXIT_FAILURE, "%s: fetch_env_ulong", __func__); - case 0: - seed = (unsigned int)time(NULL); - break; - default: - seed = (unsigned int)tmpl; - break; - } - - dbgf(2, "To reproduce, set seed (%s) to %u.\n", seedvar, seed); - /* Writer tells reader to start */ notify = 1; - if (HDwrite(fd_writer_to_reader, ¬ify, sizeof(int)) < 0) - err(EXIT_FAILURE, "write failed"); - - HDsrandom(seed); + if (HDwrite(fd_writer_to_reader, ¬ify, sizeof(int)) < 0) { + H5_FAILED(); AT(); + printf("HDwrite failed"); + goto error; + } - if (clock_gettime(CLOCK_MONOTONIC, &lastmsgtime) < 0) - errx(EXIT_FAILURE, "%s: clock_gettime", __func__); + if (!create_zoo(fid, ".", &lastmsgtime, config)) { + H5_FAILED(); AT(); + printf("create_zoo failed"); + notify = -1; + HDwrite(fd_writer_to_reader, ¬ify, sizeof(int)); + goto error; + } - if (!create_zoo(fid, ".", &lastmsgtime, config)) - errx(EXIT_FAILURE, "create_zoo didn't pass self-check"); + /* Get the current time */ + if (HDclock_gettime(CLOCK_MONOTONIC, &last) < 0) { + H5_FAILED(); AT(); + printf("HDclock_gettime failed"); + goto error; + } - /* Notify the reader of finishing zoo creation */ - notify = 2; - if (HDwrite(fd_writer_to_reader, ¬ify, sizeof(int)) < 0) - err(EXIT_FAILURE, "write failed"); + /* Notify the reader of finishing zoo creation by sending the timestamp */ + if (HDwrite(fd_writer_to_reader, &last, sizeof(last)) < 0) { + H5_FAILED(); AT(); + printf("HDwrite failed"); + goto error; + } /* During the wait, writer makes repeated HDF5 API calls so as to trigger * EOT at approximately the correct time */ for(i = 0; i < swmr_config.max_lag + 1; i++) { decisleep(swmr_config.tick_len); - H5Aexists(fid, "nonexistent"); + H5E_BEGIN_TRY { + H5Aexists(fid, "nonexistent"); + } H5E_END_TRY; } /* Wait until the reader finishes validating zoo creation */ - if (HDread(fd_reader_to_writer, ¬ify, sizeof(int)) < 0) - err(EXIT_FAILURE, "read failed"); - if (notify != 3) - errx(EXIT_FAILURE, "expected 2 but read %d", notify); + if (HDread(fd_reader_to_writer, ¬ify, sizeof(int)) < 0) { + H5_FAILED(); AT(); + printf("HDread failed"); + goto error; + } - if (clock_gettime(CLOCK_MONOTONIC, &lastmsgtime) == -1) - errx(EXIT_FAILURE, "%s: clock_gettime", __func__); + if (notify != 2) { + H5_FAILED(); AT(); + printf("expected 2 but read %d", notify); + notify = -1; + HDwrite(fd_writer_to_reader, ¬ify, sizeof(int)); + goto error; + } - if (!delete_zoo(fid, ".", &lastmsgtime, config)) - errx(EXIT_FAILURE, "delete_zoo failed"); + /* Start to delete the zoo */ + if (!delete_zoo(fid, ".", &lastmsgtime, config)) { + H5_FAILED(); AT(); + printf("delete_zoo failed"); + notify = -1; + HDwrite(fd_writer_to_reader, ¬ify, sizeof(int)); + goto error; + } - /* Notify the reader about finishing zoo deletion */ - notify = 4; - if (HDwrite(fd_writer_to_reader, ¬ify, sizeof(int)) == -1) - err(EXIT_FAILURE, "write failed"); + /* Get the current time */ + if (HDclock_gettime(CLOCK_MONOTONIC, &last) < 0) { + H5_FAILED(); AT(); + printf("HDclock_gettime failed"); + goto error; + } + /* Notify the reader about finishing zoo deletion by sending the timestamp */ + if (HDwrite(fd_writer_to_reader, &last, sizeof(last)) < 0) { + H5_FAILED(); AT(); + printf("HDwrite failed"); + goto error; + } } else { dbgf(2, "Reading zoo...\n"); /* Start to validate zoo creation after receiving the writer's notice */ - if (HDread(fd_writer_to_reader, ¬ify, sizeof(int)) < 0) - err(EXIT_FAILURE, "read failed"); - if (notify != 1) - errx(EXIT_FAILURE, "unexpected message %d", notify); - - /* Get the current time */ - if (clock_gettime(CLOCK_MONOTONIC, &lastmsgtime) < 0) - errx(EXIT_FAILURE, "%s: clock_gettime", __func__); + if (HDread(fd_writer_to_reader, ¬ify, sizeof(int)) < 0) { + H5_FAILED(); AT(); + printf("HDread failed"); + goto error; + } - last.tv_sec = lastmsgtime.tv_sec; - last.tv_nsec = lastmsgtime.tv_nsec; + if (notify != 1) { + H5_FAILED(); AT(); + printf("expected 1 but read %d", notify); + goto error; + } while (!validate_zoo(fid, ".", &lastmsgtime, config)) ; + /* Receive the notice of the writer finishing zoo creation (timestamp) */ + if (HDread(fd_writer_to_reader, &last, sizeof(last)) < 0) { + H5_FAILED(); AT(); + printf("HDread failed"); + goto error; + } + /* Make sure zoo validation doesn't take longer than the expected time */ - if (below_speed_limit(&last, &ival)) + if (below_speed_limit(&last, &ival)) { + AT(); warnx("validate_zoo took too long to finish"); - - /* Receive the notice of the writer finishing zoo creation */ - if (HDread(fd_writer_to_reader, ¬ify, sizeof(int)) < 0) - err(EXIT_FAILURE, "read failed"); - if (notify != 2) - errx(EXIT_FAILURE, "unexpected message %d", notify); + } /* Notify the writer that zoo validation is finished */ - notify = 3; - if (HDwrite(fd_reader_to_writer, ¬ify, sizeof(int)) < 0) - err(EXIT_FAILURE, "write failed"); - - /* Get the current time before validating zoo deletion */ - if (clock_gettime(CLOCK_MONOTONIC, &lastmsgtime) < 0) - errx(EXIT_FAILURE, "%s: clock_gettime", __func__); - - last.tv_sec = lastmsgtime.tv_sec; - last.tv_nsec = lastmsgtime.tv_nsec; + notify = 2; + if (HDwrite(fd_reader_to_writer, ¬ify, sizeof(int)) < 0) { + H5_FAILED(); AT(); + printf("HDwrite failed"); + goto error; + } while (!validate_deleted_zoo(fid, ".", &lastmsgtime, config)) ; + /* Receive the finish notice (timestamp) from the writer */ + //if (HDread(fd_writer_to_reader, ¬ify, sizeof(int)) < 0) { + if (HDread(fd_writer_to_reader, &last, sizeof(last)) < 0) { + H5_FAILED(); AT(); + printf("HDread failed"); + goto error; + } + /* Make sure validation of zoo deletion doesn't take longer than the expected time */ - if (below_speed_limit(&last, &ival)) + if (below_speed_limit(&last, &ival)) { + AT(); warnx("validate_deleted_zoo took too long to finish"); - - /* Receive the finish notice from the writer */ - if (HDread(fd_writer_to_reader, ¬ify, sizeof(int)) < 0) - err(EXIT_FAILURE, "read failed"); - if (notify != 4) - errx(EXIT_FAILURE, "unexpected message %d", notify); + } } restore_estack(es); @@ -498,33 +552,74 @@ main(int argc, char **argv) } } - if (H5Pclose(fapl) < 0) - errx(EXIT_FAILURE, "H5Pclose(fapl)"); + if (H5Pclose(fapl) < 0) { + H5_FAILED(); AT(); + printf("H5Pclose failed"); + goto error; + } - if (H5Pclose(fcpl) < 0) - errx(EXIT_FAILURE, "H5Pclose(fcpl)"); + if (H5Pclose(fcpl) < 0) { + H5_FAILED(); AT(); + printf("H5Pclose failed"); + goto error; + } - if (H5Fclose(fid) < 0) - errx(EXIT_FAILURE, "H5Fclose"); + if (H5Fclose(fid) < 0) { + H5_FAILED(); AT(); + printf("H5Fclose failed"); + goto error; + } if (progname) HDfree(progname); /* Close the named pipes */ - if (HDclose(fd_writer_to_reader) < 0) - errx(EXIT_FAILURE, "HDclose"); + if (HDclose(fd_writer_to_reader) < 0) { + H5_FAILED(); AT(); + printf("HDclose failed\n"); + goto error; + } - if (HDclose(fd_reader_to_writer) < 0) - errx(EXIT_FAILURE, "HDclose"); + if (HDclose(fd_reader_to_writer) < 0) { + H5_FAILED(); AT(); + printf("HDclose failed\n"); + goto error; + } /* Reader finishes last and deletes the named pipes */ if(!writer) { - if(HDremove(fifo_writer_to_reader) != 0) - errx(EXIT_FAILURE, "fifo_writer_to_reader deletion failed"); + if(HDremove(fifo_writer_to_reader) != 0) { + H5_FAILED(); AT(); + printf("HDremove failed\n"); + goto error; + } - if(HDremove(fifo_reader_to_writer) != 0) - errx(EXIT_FAILURE, "fifo_reader_to_writer deletion failed"); + if(HDremove(fifo_reader_to_writer) != 0) { + H5_FAILED(); AT(); + printf("HDremove failed\n"); + goto error; + } } return EXIT_SUCCESS; + +error: + H5E_BEGIN_TRY { + H5Pclose(fapl); + H5Pclose(fcpl); + H5Fclose(fid); + } H5E_END_TRY; + + if (fd_writer_to_reader >= 0) + HDclose(fd_writer_to_reader); + + if (fd_reader_to_writer >= 0) + HDclose(fd_reader_to_writer); + + if(!writer) { + HDremove(fifo_writer_to_reader); + HDremove(fifo_reader_to_writer); + } + + return EXIT_FAILURE; } -- cgit v0.12 From 422c48af68314481492811a45dd6a084cd603785 Mon Sep 17 00:00:00 2001 From: Songyu Lu Date: Tue, 6 Apr 2021 12:00:17 -0500 Subject: Removed the two functions (vfd_swmr_writer_may_increase_tick_to and vfd_swmr_reader_did_increase_tick_to) that overrode the functions of the same names in the SWMR driver. Also added a command-line option to disable named pipes so that the writer and reader can run seperately. --- test/genall5.c | 4 +- test/testvfdswmr.sh.in | 2 +- test/vfd_swmr_zoo_writer.c | 352 +++++++++++++++------------------------------ 3 files changed, 115 insertions(+), 243 deletions(-) diff --git a/test/genall5.c b/test/genall5.c index 016b368..70190c6 100644 --- a/test/genall5.c +++ b/test/genall5.c @@ -2754,8 +2754,8 @@ tend_zoo(hid_t fid, const char *base_path, struct timespec *lastmsgtime, zoo_con } out: if (!ok) { - /* Only the zoo test for VFD SWMR does this step, making sure it doesn't take too long. - * Other tests sets config.msgival or lastmsgtime to 0 and will skip this step */ + /* Currently not used: this step makes sure the operation doesn't take too long. + * Any test that sets config.msgival or lastmsgtime to 0 will skip this step */ if (strcmp(failure_mssg, last_failure_mssg) != 0 && ((config.msgival.tv_sec || config.msgival.tv_nsec)) && (lastmsgtime->tv_sec || lastmsgtime->tv_nsec)) { if (below_speed_limit(lastmsgtime, &config.msgival)) { diff --git a/test/testvfdswmr.sh.in b/test/testvfdswmr.sh.in index 67c1201..72b00b3 100644 --- a/test/testvfdswmr.sh.in +++ b/test/testvfdswmr.sh.in @@ -578,7 +578,7 @@ if [ ${do_zoo:-no} = yes ]; then pid_writer=$! catch_out_err_and_rc vfd_swmr_zoo_reader \ - ../vfd_swmr_zoo_reader -l 3 -q & + ../vfd_swmr_zoo_reader -l 4 -q & pid_reader=$! # Wait for the reader to finish before signalling the diff --git a/test/vfd_swmr_zoo_writer.c b/test/vfd_swmr_zoo_writer.c index 0b3c608..1048586 100644 --- a/test/vfd_swmr_zoo_writer.c +++ b/test/vfd_swmr_zoo_writer.c @@ -39,21 +39,7 @@ typedef struct _shared_ticks { uint64_t reader_tick; } shared_ticks_t; -typedef struct _tick_stats { - uint64_t writer_tried_increase; - uint64_t writer_aborted_increase; - uint64_t writer_read_shared_file; - uint64_t reader_tick_was_zero; // writer read reader tick equal to 0 - uint64_t reader_tick_lead_writer; // writer read reader tick greater than - // proposed writer tick - uint64_t writer_lead_reader_by[1]; // proposed writer tick lead reader - // tick by `lead` ticks - // `writer_lead_reader_by[lead]` - // times, for `0 <= lead <= max_lag - 1` -} tick_stats_t; - static H5F_vfd_swmr_config_t swmr_config; -static tick_stats_t * tick_stats = NULL; static bool writer; static void @@ -75,136 +61,28 @@ print_cache_hits(H5C_t H5_ATTR_UNUSED *cache) #endif void -zoo_create_hook(hid_t fid) +zoo_create_hook(hid_t H5_ATTR_UNUSED fid) { dbgf(3, "%s: enter\n", __func__); if (writer) - H5Fvfd_swmr_end_tick(fid); + decisleep(1); } static void usage(const char *progname) { - fprintf(stderr, "usage: %s [-C] [-S] [-W] [-a] [-e] [-m] [-q] [-v]\n", progname); + fprintf(stderr, "usage: %s [-C] [-S] [-a] [-e] [-p] [-q] [-v]\n", progname); fprintf(stderr, "\n -C: skip compact dataset tests\n"); fprintf(stderr, " -S: do not use VFD SWMR\n"); - fprintf(stderr, " -W: do not wait for SIGINT or SIGUSR1\n"); fprintf(stderr, " -a: run all tests, including variable-length data\n"); fprintf(stderr, " -e: print error stacks\n"); fprintf(stderr, " -l secs: maximal seconds for reader to validate the zoo\n"); - fprintf(stderr, " -m ms: maximal `ms` milliseconds pause between\n"); - fprintf(stderr, " each create/delete step\n"); + fprintf(stderr, " -p: do not use named pipes\n"); fprintf(stderr, " -q: be quiet: few/no progress messages\n"); fprintf(stderr, " -v: be verbose: most progress messages\n"); exit(EXIT_FAILURE); } -#ifndef TMP -bool -vfd_swmr_writer_may_increase_tick_to(uint64_t new_tick, bool wait_for_reader) -{ - static int fd = -1; - shared_ticks_t shared; - ssize_t nread; - h5_retry_t retry; - bool do_try; - - dbgf(3, "%s: enter\n", __func__); - - if (fd == -1) { - if (HDaccess("./shared_tick_num", F_OK ) < 0) - return true; - - fd = HDopen("./shared_tick_num", O_RDONLY); - if (fd == -1) { - warn("%s: open", __func__); // TBD ratelimit/silence this warning - return true; - } - assert(tick_stats == NULL); - tick_stats = HDcalloc(1, sizeof(*tick_stats) + - (swmr_config.max_lag - 1) * - sizeof(tick_stats->writer_lead_reader_by[0])); - - if (tick_stats == NULL) - err(EXIT_FAILURE, "%s: calloc", __func__); - } - - tick_stats->writer_tried_increase++; - - for (do_try = h5_retry_init(&retry, 14, 10 * 1000 * 1000, 100 * 1000 * 1000); do_try; - do_try = wait_for_reader && h5_retry_next(&retry)) { - - tick_stats->writer_read_shared_file++; - - if ((nread = HDpread(fd, &shared, sizeof(shared), 0)) == -1) - err(EXIT_FAILURE, "%s: pread", __func__); - - if (nread != sizeof(shared)) - errx(EXIT_FAILURE, "%s: pread", __func__); - - // TBD convert endianness - - if (shared.reader_tick == 0) { - tick_stats->reader_tick_was_zero++; - return true; - } - - if (new_tick < shared.reader_tick) { - tick_stats->reader_tick_lead_writer++; - return true; - } - if (new_tick <= shared.reader_tick + swmr_config.max_lag - 1) { - uint64_t lead = new_tick - shared.reader_tick; - assert(lead <= swmr_config.max_lag - 1); - tick_stats->writer_lead_reader_by[lead]++; - return true; - } - } - if (wait_for_reader && !do_try) - errx(EXIT_FAILURE, "%s: timed out waiting for reader", __func__); - - tick_stats->writer_aborted_increase++; - - return false; -} - -void -vfd_swmr_reader_did_increase_tick_to(uint64_t new_tick) -{ - static int fd = -1; - shared_ticks_t shared; - ssize_t nwritten; - - dbgf(3, "%s: enter\n", __func__); - - if (fd == -1) { - // TBD create a temporary file, here, and move it to its final path - // after writing it. - fd = HDopen("./shared_tick_num", O_RDWR|O_CREAT, 0600); - if (fd == -1) - err(EXIT_FAILURE, "%s: open", __func__); - } - - shared.reader_tick = new_tick; - - // TBD convert endianness - - if ((nwritten = HDpwrite(fd, &shared, sizeof(shared), 0)) == -1) - errx(EXIT_FAILURE, "%s: pwrite", __func__); - - if (nwritten != sizeof(shared)) - errx(EXIT_FAILURE, "%s: pwrite", __func__); - - if (new_tick == 0) { - if (unlink("./shared_tick_num") == -1) - warn("%s: unlink", __func__); - if (close(fd) == -1) - err(EXIT_FAILURE, "%s: close", __func__); - fd = -1; - } -} -#endif - int main(int argc, char **argv) { @@ -224,6 +102,7 @@ main(int argc, char **argv) unsigned long tmpl; char *end; bool use_vfd_swmr = true; + bool use_named_pipe = true; char *progname = NULL; char *personality; estack_state_t es; @@ -255,10 +134,7 @@ main(int argc, char **argv) goto error; } - if (writer) - config.max_pause_msecs = 50; - - while ((ch = getopt(argc, argv, "CSael:qv")) != -1) { + while ((ch = getopt(argc, argv, "CSael:pqv")) != -1) { switch(ch) { case 'C': config.skip_compact = true; @@ -292,6 +168,10 @@ main(int argc, char **argv) ival.tv_nsec = nsec; } break; + case 'p': + /* Disable named pipes, mainly for running the writer and reader seperately */ + use_named_pipe = false; + break; case 'q': verbosity = 1; break; @@ -368,7 +248,7 @@ main(int argc, char **argv) cache = f->shared->cache; /* Writer creates two named pipes(FIFO) to coordinate two-way communication */ - if (writer) { + if (use_named_pipe && writer) { if (HDmkfifo(fifo_writer_to_reader, 0600) < 0) { H5_FAILED(); AT(); printf("HDmkfifo failed"); @@ -383,13 +263,13 @@ main(int argc, char **argv) } /* Both the writer and reader open the pipes */ - if ((fd_writer_to_reader = HDopen(fifo_writer_to_reader, O_RDWR)) < 0) { + if (use_named_pipe && (fd_writer_to_reader = HDopen(fifo_writer_to_reader, O_RDWR)) < 0) { H5_FAILED(); AT(); printf("fifo_writer_to_reader open failed"); goto error; } - if ((fd_reader_to_writer = HDopen(fifo_reader_to_writer, O_RDWR)) < 0) { + if (use_named_pipe && (fd_reader_to_writer = HDopen(fifo_reader_to_writer, O_RDWR)) < 0) { H5_FAILED(); AT(); printf("fifo_reader_to_writer open failed"); goto error; @@ -403,7 +283,7 @@ main(int argc, char **argv) /* Writer tells reader to start */ notify = 1; - if (HDwrite(fd_writer_to_reader, ¬ify, sizeof(int)) < 0) { + if (use_named_pipe && HDwrite(fd_writer_to_reader, ¬ify, sizeof(int)) < 0) { H5_FAILED(); AT(); printf("HDwrite failed"); goto error; @@ -412,146 +292,138 @@ main(int argc, char **argv) if (!create_zoo(fid, ".", &lastmsgtime, config)) { H5_FAILED(); AT(); printf("create_zoo failed"); - notify = -1; - HDwrite(fd_writer_to_reader, ¬ify, sizeof(int)); goto error; } - /* Get the current time */ - if (HDclock_gettime(CLOCK_MONOTONIC, &last) < 0) { - H5_FAILED(); AT(); - printf("HDclock_gettime failed"); - goto error; - } + if (use_named_pipe) { + /* Get the time when finishing zoo creation */ + if (HDclock_gettime(CLOCK_MONOTONIC, &last) < 0) { + H5_FAILED(); AT(); + printf("HDclock_gettime failed"); + goto error; + } - /* Notify the reader of finishing zoo creation by sending the timestamp */ - if (HDwrite(fd_writer_to_reader, &last, sizeof(last)) < 0) { - H5_FAILED(); AT(); - printf("HDwrite failed"); - goto error; - } + /* Notify the reader of finishing zoo creation by sending the timestamp */ + if (HDwrite(fd_writer_to_reader, &last, sizeof(last)) < 0) { + H5_FAILED(); AT(); + printf("HDwrite failed"); + goto error; + } - /* During the wait, writer makes repeated HDF5 API calls so as to trigger - * EOT at approximately the correct time */ - for(i = 0; i < swmr_config.max_lag + 1; i++) { - decisleep(swmr_config.tick_len); + /* During the wait, writer makes repeated HDF5 API calls so as to trigger + * EOT at approximately the correct time */ + for(i = 0; i < swmr_config.max_lag + 1; i++) { + decisleep(swmr_config.tick_len); - H5E_BEGIN_TRY { - H5Aexists(fid, "nonexistent"); - } H5E_END_TRY; - } + H5E_BEGIN_TRY { + H5Aexists(fid, "nonexistent"); + } H5E_END_TRY; + } - /* Wait until the reader finishes validating zoo creation */ - if (HDread(fd_reader_to_writer, ¬ify, sizeof(int)) < 0) { - H5_FAILED(); AT(); - printf("HDread failed"); - goto error; - } + /* Wait until the reader finishes validating zoo creation */ + if (HDread(fd_reader_to_writer, ¬ify, sizeof(int)) < 0) { + H5_FAILED(); AT(); + printf("HDread failed"); + goto error; + } - if (notify != 2) { - H5_FAILED(); AT(); - printf("expected 2 but read %d", notify); - notify = -1; - HDwrite(fd_writer_to_reader, ¬ify, sizeof(int)); - goto error; + if (notify != 2) { + H5_FAILED(); AT(); + printf("expected 2 but read %d", notify); + goto error; + } } /* Start to delete the zoo */ if (!delete_zoo(fid, ".", &lastmsgtime, config)) { H5_FAILED(); AT(); printf("delete_zoo failed"); - notify = -1; - HDwrite(fd_writer_to_reader, ¬ify, sizeof(int)); goto error; } - /* Get the current time */ - if (HDclock_gettime(CLOCK_MONOTONIC, &last) < 0) { - H5_FAILED(); AT(); - printf("HDclock_gettime failed"); - goto error; - } + if (use_named_pipe) { + /* Get the time when finishing zoo deletion */ + if (HDclock_gettime(CLOCK_MONOTONIC, &last) < 0) { + H5_FAILED(); AT(); + printf("HDclock_gettime failed"); + goto error; + } - /* Notify the reader about finishing zoo deletion by sending the timestamp */ - if (HDwrite(fd_writer_to_reader, &last, sizeof(last)) < 0) { - H5_FAILED(); AT(); - printf("HDwrite failed"); - goto error; + /* Notify the reader about finishing zoo deletion by sending the timestamp */ + if (HDwrite(fd_writer_to_reader, &last, sizeof(last)) < 0) { + H5_FAILED(); AT(); + printf("HDwrite failed"); + goto error; + } } } else { dbgf(2, "Reading zoo...\n"); - /* Start to validate zoo creation after receiving the writer's notice */ - if (HDread(fd_writer_to_reader, ¬ify, sizeof(int)) < 0) { - H5_FAILED(); AT(); - printf("HDread failed"); - goto error; - } + if (use_named_pipe) { + /* Start to validate zoo creation after receiving the writer's notice */ + if (HDread(fd_writer_to_reader, ¬ify, sizeof(int)) < 0) { + H5_FAILED(); AT(); + printf("HDread failed"); + goto error; + } - if (notify != 1) { - H5_FAILED(); AT(); - printf("expected 1 but read %d", notify); - goto error; + if (notify != 1) { + H5_FAILED(); AT(); + printf("expected 1 but read %d", notify); + goto error; + } } while (!validate_zoo(fid, ".", &lastmsgtime, config)) ; - /* Receive the notice of the writer finishing zoo creation (timestamp) */ - if (HDread(fd_writer_to_reader, &last, sizeof(last)) < 0) { - H5_FAILED(); AT(); - printf("HDread failed"); - goto error; - } + if (use_named_pipe) { + /* Receive the notice of the writer finishing zoo creation (timestamp) */ + if (HDread(fd_writer_to_reader, &last, sizeof(last)) < 0) { + H5_FAILED(); AT(); + printf("HDread failed"); + goto error; + } - /* Make sure zoo validation doesn't take longer than the expected time */ - if (below_speed_limit(&last, &ival)) { - AT(); - warnx("validate_zoo took too long to finish"); - } + /* Make sure the zoo validation doesn't take longer than the expected time. + * This time period is from the writer finishing zoo creation to the reader finishing + * the validation of zoo creation */ + if (below_speed_limit(&last, &ival)) { + AT(); + warnx("validate_zoo took too long to finish"); + } - /* Notify the writer that zoo validation is finished */ - notify = 2; - if (HDwrite(fd_reader_to_writer, ¬ify, sizeof(int)) < 0) { - H5_FAILED(); AT(); - printf("HDwrite failed"); - goto error; + /* Notify the writer that zoo validation is finished */ + notify = 2; + if (HDwrite(fd_reader_to_writer, ¬ify, sizeof(int)) < 0) { + H5_FAILED(); AT(); + printf("HDwrite failed"); + goto error; + } } while (!validate_deleted_zoo(fid, ".", &lastmsgtime, config)) ; - /* Receive the finish notice (timestamp) from the writer */ - //if (HDread(fd_writer_to_reader, ¬ify, sizeof(int)) < 0) { - if (HDread(fd_writer_to_reader, &last, sizeof(last)) < 0) { - H5_FAILED(); AT(); - printf("HDread failed"); - goto error; - } + if (use_named_pipe) { + /* Receive the finish notice (timestamp) from the writer */ + if (HDread(fd_writer_to_reader, &last, sizeof(last)) < 0) { + H5_FAILED(); AT(); + printf("HDread failed"); + goto error; + } - /* Make sure validation of zoo deletion doesn't take longer than the expected time */ - if (below_speed_limit(&last, &ival)) { - AT(); - warnx("validate_deleted_zoo took too long to finish"); + /* Make sure validation of zoo deletion doesn't take longer than the expected time. + * This time period is from the writer finishing zoo deletion to the reader finishing + * the validation of zoo deletion */ + if (below_speed_limit(&last, &ival)) { + AT(); + warnx("validate_deleted_zoo took too long to finish"); + } } } restore_estack(es); - if (writer && tick_stats != NULL) { - uint64_t lead; - - dbgf(2, "writer tried tick increase %" PRIu64 "\n", tick_stats->writer_tried_increase); - dbgf(2, "writer aborted tick increase %" PRIu64 "\n", tick_stats->writer_aborted_increase); - dbgf(2, "writer read shared file %" PRIu64 "\n", tick_stats->writer_read_shared_file); - dbgf(2, "writer read reader tick equal to 0 %" PRIu64 "\n", tick_stats->reader_tick_was_zero); - dbgf(2, "writer read reader tick leading writer %" PRIu64 "\n", tick_stats->reader_tick_lead_writer); - - for (lead = 0; lead < swmr_config.max_lag; lead++) { - dbgf(2, "writer tick lead writer by %" PRIu64 " %" PRIu64 "\n", lead, - tick_stats->writer_lead_reader_by[lead]); - } - } - if (H5Pclose(fapl) < 0) { H5_FAILED(); AT(); printf("H5Pclose failed"); @@ -574,20 +446,20 @@ main(int argc, char **argv) HDfree(progname); /* Close the named pipes */ - if (HDclose(fd_writer_to_reader) < 0) { + if (use_named_pipe && HDclose(fd_writer_to_reader) < 0) { H5_FAILED(); AT(); printf("HDclose failed\n"); goto error; } - if (HDclose(fd_reader_to_writer) < 0) { + if (use_named_pipe && HDclose(fd_reader_to_writer) < 0) { H5_FAILED(); AT(); printf("HDclose failed\n"); goto error; } /* Reader finishes last and deletes the named pipes */ - if(!writer) { + if(use_named_pipe && !writer) { if(HDremove(fifo_writer_to_reader) != 0) { H5_FAILED(); AT(); printf("HDremove failed\n"); @@ -610,13 +482,13 @@ error: H5Fclose(fid); } H5E_END_TRY; - if (fd_writer_to_reader >= 0) + if (use_named_pipe && fd_writer_to_reader >= 0) HDclose(fd_writer_to_reader); - if (fd_reader_to_writer >= 0) + if (use_named_pipe && fd_reader_to_writer >= 0) HDclose(fd_reader_to_writer); - if(!writer) { + if(use_named_pipe && !writer) { HDremove(fifo_writer_to_reader); HDremove(fifo_reader_to_writer); } -- cgit v0.12 From 1ddc44852e0bb767c4085be9f60adf6cf41b9213 Mon Sep 17 00:00:00 2001 From: Songyu Lu Date: Tue, 6 Apr 2021 21:32:37 -0500 Subject: Removed an unused macro definition. --- test/vfd_swmr_zoo_writer.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/vfd_swmr_zoo_writer.c b/test/vfd_swmr_zoo_writer.c index 1048586..e9aeede 100644 --- a/test/vfd_swmr_zoo_writer.c +++ b/test/vfd_swmr_zoo_writer.c @@ -28,10 +28,6 @@ #include "genall5.h" #include "vfd_swmr_common.h" -#ifndef _arraycount -#define _arraycount(_a) (sizeof(_a) / sizeof(_a[0])) -#endif - #define MAX_READ_LEN_IN_SECONDS 2 #define TICK_LEN 4 -- cgit v0.12 From 90ee7f67793db85ead72bfefba332ec976e3899d Mon Sep 17 00:00:00 2001 From: Songyu Lu Date: Thu, 8 Apr 2021 10:03:13 -0500 Subject: Changed the command-line option for disabling named pipes from -p to -N to be consistent with other tests. --- test/vfd_swmr_zoo_writer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/vfd_swmr_zoo_writer.c b/test/vfd_swmr_zoo_writer.c index e9aeede..f704b89 100644 --- a/test/vfd_swmr_zoo_writer.c +++ b/test/vfd_swmr_zoo_writer.c @@ -73,7 +73,7 @@ usage(const char *progname) fprintf(stderr, " -a: run all tests, including variable-length data\n"); fprintf(stderr, " -e: print error stacks\n"); fprintf(stderr, " -l secs: maximal seconds for reader to validate the zoo\n"); - fprintf(stderr, " -p: do not use named pipes\n"); + fprintf(stderr, " -N: do not use named pipes\n"); fprintf(stderr, " -q: be quiet: few/no progress messages\n"); fprintf(stderr, " -v: be verbose: most progress messages\n"); exit(EXIT_FAILURE); @@ -130,7 +130,7 @@ main(int argc, char **argv) goto error; } - while ((ch = getopt(argc, argv, "CSael:pqv")) != -1) { + while ((ch = getopt(argc, argv, "CSael:Nqv")) != -1) { switch(ch) { case 'C': config.skip_compact = true; @@ -164,7 +164,7 @@ main(int argc, char **argv) ival.tv_nsec = nsec; } break; - case 'p': + case 'N': /* Disable named pipes, mainly for running the writer and reader seperately */ use_named_pipe = false; break; -- cgit v0.12 From 06380a7c986887516b138a8383c0e410bcb87964 Mon Sep 17 00:00:00 2001 From: Songyu Lu Date: Mon, 12 Apr 2021 12:07:24 -0500 Subject: Refactored the code to reduce the length of the main function. --- test/testvfdswmr.sh.in | 2 + test/vfd_swmr_zoo_writer.c | 509 +++++++++++++++++++++++++++++---------------- 2 files changed, 332 insertions(+), 179 deletions(-) diff --git a/test/testvfdswmr.sh.in b/test/testvfdswmr.sh.in index 72b00b3..81db3b3 100644 --- a/test/testvfdswmr.sh.in +++ b/test/testvfdswmr.sh.in @@ -577,6 +577,8 @@ if [ ${do_zoo:-no} = yes ]; then ../vfd_swmr_zoo_writer -q & pid_writer=$! + # -l is the expected maximal number of ticks from the writer's finishing zoo creation or deletion + # to the reader's finishing validation of zoo creation or deletion catch_out_err_and_rc vfd_swmr_zoo_reader \ ../vfd_swmr_zoo_reader -l 4 -q & pid_reader=$! diff --git a/test/vfd_swmr_zoo_writer.c b/test/vfd_swmr_zoo_writer.c index f704b89..de90139 100644 --- a/test/vfd_swmr_zoo_writer.c +++ b/test/vfd_swmr_zoo_writer.c @@ -35,8 +35,23 @@ typedef struct _shared_ticks { uint64_t reader_tick; } shared_ticks_t; +int fd_writer_to_reader = -1, fd_reader_to_writer = -1; +const char *fifo_writer_to_reader = "./fifo_writer_to_reader"; +const char *fifo_reader_to_writer = "./fifo_reader_to_writer"; +bool use_vfd_swmr = true; +bool use_named_pipe = true; +bool print_estack = false; static H5F_vfd_swmr_config_t swmr_config; static bool writer; +struct timespec ival = {MAX_READ_LEN_IN_SECONDS, 0}; /* Expected maximal time for reader's validation */ + +zoo_config_t config = { + .proc_num = 0 + , .skip_compact = false + , .skip_varlen = true + , .max_pause_msecs = 0 + , .msgival = {.tv_sec = 0, .tv_nsec = 0} +}; static void #ifndef H5C_COLLECT_CACHE_STATS @@ -64,6 +79,7 @@ zoo_create_hook(hid_t H5_ATTR_UNUSED fid) decisleep(1); } +/* Print out the menu for the command-line options */ static void usage(const char *progname) { @@ -72,63 +88,21 @@ usage(const char *progname) fprintf(stderr, " -S: do not use VFD SWMR\n"); fprintf(stderr, " -a: run all tests, including variable-length data\n"); fprintf(stderr, " -e: print error stacks\n"); - fprintf(stderr, " -l secs: maximal seconds for reader to validate the zoo\n"); + fprintf(stderr, " -l tick_num: expected maximal number of ticks from \n"); + fprintf(stderr, " the writer's finishing zoo creation or deletion to the reader's finishing validation\n"); fprintf(stderr, " -N: do not use named pipes\n"); fprintf(stderr, " -q: be quiet: few/no progress messages\n"); fprintf(stderr, " -v: be verbose: most progress messages\n"); exit(EXIT_FAILURE); } -int -main(int argc, char **argv) +/* Private function to help parsing command-line options */ +static int +parse_command_line_options(int argc, char **argv) { - hid_t fapl = H5I_INVALID_HID, fcpl = H5I_INVALID_HID, fid = H5I_INVALID_HID; - H5F_t *f; - H5C_t *cache; - zoo_config_t config = { - .proc_num = 0 - , .skip_compact = false - , .skip_varlen = true - , .max_pause_msecs = 0 - , .msgival = {.tv_sec = 0, .tv_nsec = 0} - }; - struct timespec lastmsgtime = {.tv_sec = 0, .tv_nsec = 0}; - bool wait_for_signal; int ch; unsigned long tmpl; char *end; - bool use_vfd_swmr = true; - bool use_named_pipe = true; - char *progname = NULL; - char *personality; - estack_state_t es; - bool print_estack = false; - H5F_vfd_swmr_config_t vfd_swmr_config; - int fd_writer_to_reader = -1, fd_reader_to_writer = -1; - const char *fifo_writer_to_reader = "./fifo_writer_to_reader"; - const char *fifo_reader_to_writer = "./fifo_reader_to_writer"; - int notify = 0; - unsigned int i; - struct timespec last = {0, 0}; - struct timespec ival = {MAX_READ_LEN_IN_SECONDS, 0}; /* Expected maximal time for reader's validation */ - - if (H5_basename(argv[0], &progname) < 0) { - H5_FAILED(); AT(); - printf("H5_basename failed\n"); - goto error; - } - - personality = HDstrstr(progname, "vfd_swmr_zoo_"); - - if (personality != NULL && strcmp(personality, "vfd_swmr_zoo_writer") == 0) - writer = wait_for_signal = true; - else if (personality != NULL && strcmp(personality, "vfd_swmr_zoo_reader") == 0) - writer = false; - else { - H5_FAILED(); AT(); - printf("unknown personality, expected vfd_swmr_zoo_{reader,writer}"); - goto error; - } while ((ch = getopt(argc, argv, "CSael:Nqv")) != -1) { switch(ch) { @@ -145,15 +119,22 @@ main(int argc, char **argv) print_estack = true; break; case 'l': - /* Expected maximal number of ticks for reader's validation of zoo creation or deletion */ + /* Expected maximal number of ticks from the writer's finishing zoo creation or deletion + * to the reader's finishing validation of zoo creation or deletion */ errno = 0; tmpl = HDstrtoul(optarg, &end, 0); - if (end == optarg || *end != '\0') - errx(EXIT_FAILURE, "couldn't parse `-l` argument `%s`", optarg); - else if (errno != 0) - err(EXIT_FAILURE, "couldn't parse `-l` argument `%s`", optarg); - else if (tmpl > UINT_MAX) - errx(EXIT_FAILURE, "`-l` argument `%lu` too large", tmpl); + + if (end == optarg || *end != '\0') { + printf("couldn't parse `-l` argument `%s`", optarg); + goto error; + } else if (errno != 0) { + printf("couldn't parse `-l` argument `%s`", optarg); + goto error; + } else if (tmpl > UINT_MAX) { + printf("`-l` argument `%lu` too large", tmpl); + goto error; + } + { /* Translate the tick number to time represented by the timespec struct */ float time = (float)(((unsigned)tmpl * TICK_LEN) / 10.0); @@ -188,6 +169,259 @@ main(int argc, char **argv) goto error; } + return 0; + +error: + return -1; +} + +/* Writer creates two named pipes(FIFO) to coordinate two-way communication + * between the writer and the reader. Both the writer and reader open the named pipes */ +static int +create_open_named_pipes(void) +{ + /* Writer creates two named pipes(FIFO) to coordinate two-way communication */ + if (use_named_pipe && writer) { + if (HDmkfifo(fifo_writer_to_reader, 0600) < 0) { + H5_FAILED(); AT(); + printf("HDmkfifo failed"); + goto error; + } + + if (HDmkfifo(fifo_reader_to_writer, 0600) < 0) { + H5_FAILED(); AT(); + printf("HDmkfifo failed"); + goto error; + } + } + + /* Both the writer and reader open the pipes */ + if (use_named_pipe && (fd_writer_to_reader = HDopen(fifo_writer_to_reader, O_RDWR)) < 0) { + H5_FAILED(); AT(); + printf("fifo_writer_to_reader open failed"); + goto error; + } + + if (use_named_pipe && (fd_reader_to_writer = HDopen(fifo_reader_to_writer, O_RDWR)) < 0) { + H5_FAILED(); AT(); + printf("fifo_reader_to_writer open failed"); + goto error; + } + + return 0; + +error: + return -1; +} + +/* Notify the reader of finishing zoo creation by sending the timestamp + * and wait for the reader to finish validation before proceeding */ +static int +notify_and_wait_for_reader(hid_t fid, int verify) +{ + int notify; + unsigned int i; + struct timespec last = {0, 0}; + + if (use_named_pipe) { + /* Get the time when finishing zoo creation */ + if (HDclock_gettime(CLOCK_MONOTONIC, &last) < 0) { + H5_FAILED(); AT(); + printf("HDclock_gettime failed"); + goto error; + } + + /* Notify the reader of finishing zoo creation by sending the timestamp */ + if (HDwrite(fd_writer_to_reader, &last, sizeof(last)) < 0) { + H5_FAILED(); AT(); + printf("HDwrite failed"); + goto error; + } + + /* During the wait, writer makes repeated HDF5 API calls so as to trigger + * EOT at approximately the correct time */ + for(i = 0; i < swmr_config.max_lag + 1; i++) { + decisleep(swmr_config.tick_len); + + H5E_BEGIN_TRY { + H5Aexists(fid, "nonexistent"); + } H5E_END_TRY; + } + + /* Wait until the reader finishes validating zoo creation */ + if (HDread(fd_reader_to_writer, ¬ify, sizeof(int)) < 0) { + H5_FAILED(); AT(); + printf("HDread failed"); + goto error; + } + + if (notify != verify) { + H5_FAILED(); AT(); + printf("expected %d but read %d", verify, notify); + goto error; + } + } + + return 0; + +error: + return -1; +} + +/* Notify the reader of finishing zoo deletion by sending the timestamp */ +static int +notify_reader(void) +{ + struct timespec last = {0, 0}; + + if (use_named_pipe) { + /* Get the time when finishing zoo deletion */ + if (HDclock_gettime(CLOCK_MONOTONIC, &last) < 0) { + H5_FAILED(); AT(); + printf("HDclock_gettime failed"); + goto error; + } + + /* Notify the reader about finishing zoo deletion by sending the timestamp */ + if (HDwrite(fd_writer_to_reader, &last, sizeof(last)) < 0) { + H5_FAILED(); AT(); + printf("HDwrite failed"); + goto error; + } + } + + return 0; + +error: + return -1; +} + +/* Wait for the writer's notice before starting to zoo validation */ +static int +reader_verify(int verify) +{ + int notify; + + if (use_named_pipe) { + if (HDread(fd_writer_to_reader, ¬ify, sizeof(int)) < 0) { + H5_FAILED(); AT(); + printf("HDread failed"); + goto error; + } + + if (notify != verify) { + H5_FAILED(); AT(); + printf("expected %d but read %d", verify, notify); + goto error; + } + } + + return 0; + +error: + return -1; +} + +/* Receive the notice of the writer finishing zoo creation (timestamp) + * Make sure the zoo validation doesn't take longer than the expected time. + * This time period is from the writer finishing zoo creation to the reader finishing + * the validation of zoo creation */ +static int +reader_check_time_and_notify_writer(int notify) +{ + struct timespec last = {0, 0}; + + if (use_named_pipe) { + /* Receive the notice of the writer finishing zoo creation (timestamp) */ + if (HDread(fd_writer_to_reader, &last, sizeof(last)) < 0) { + H5_FAILED(); AT(); + printf("HDread failed"); + goto error; + } + + /* Make sure the zoo validation doesn't take longer than the expected time. + * This time period is from the writer finishing zoo creation to the reader finishing + * the validation of zoo creation */ + if (below_speed_limit(&last, &ival)) { + AT(); + warnx("validate_zoo took too long to finish"); + } + + /* Notify the writer that zoo validation is finished */ + if (HDwrite(fd_reader_to_writer, ¬ify, sizeof(int)) < 0) { + H5_FAILED(); AT(); + printf("HDwrite failed"); + goto error; + } + } + + return 0; + +error: + return -1; +} + +/* Receive the finish notice (timestamp) from the writer. + * Make sure validation of zoo deletion doesn't take longer than the expected time. + * This time period is from the writer finishing zoo deletion to the reader finishing + * the validation of zoo deletion */ +static int +reader_check_time_after_verify_deletion(void) +{ + struct timespec last = {0, 0}; + + if (use_named_pipe) { + if (HDread(fd_writer_to_reader, &last, sizeof(last)) < 0) { + H5_FAILED(); AT(); + printf("HDread failed"); + goto error; + } + + if (below_speed_limit(&last, &ival)) { + AT(); + warnx("validate_deleted_zoo took too long to finish"); + } + } + + return 0; + +error: + return -1; +} + +int +main(int argc, char **argv) +{ + hid_t fapl = H5I_INVALID_HID, fcpl = H5I_INVALID_HID, fid = H5I_INVALID_HID; + H5F_t *f; + H5C_t *cache; + struct timespec lastmsgtime = {.tv_sec = 0, .tv_nsec = 0}; + char *progname = NULL; + char *personality; + estack_state_t es; + H5F_vfd_swmr_config_t vfd_swmr_config; + int notify = 0, verify = 0; + + if (H5_basename(argv[0], &progname) < 0) { + H5_FAILED(); AT(); + printf("H5_basename failed\n"); + goto error; + } + + personality = HDstrstr(progname, "vfd_swmr_zoo_"); + + if (personality != NULL && strcmp(personality, "vfd_swmr_zoo_writer") == 0) + writer = true; + else if (personality != NULL && strcmp(personality, "vfd_swmr_zoo_reader") == 0) + writer = false; + else { + H5_FAILED(); AT(); + printf("unknown personality, expected vfd_swmr_zoo_{reader,writer}"); + goto error; + } + + parse_command_line_options(argc, argv); + /* config, tick_len, max_lag, writer, flush_raw_data, md_pages_reserved, md_file_path */ init_vfd_swmr_config(&vfd_swmr_config, TICK_LEN, 7, writer, FALSE, 128, "./zoo-shadow"); @@ -243,31 +477,11 @@ main(int argc, char **argv) cache = f->shared->cache; - /* Writer creates two named pipes(FIFO) to coordinate two-way communication */ - if (use_named_pipe && writer) { - if (HDmkfifo(fifo_writer_to_reader, 0600) < 0) { - H5_FAILED(); AT(); - printf("HDmkfifo failed"); - goto error; - } - - if (HDmkfifo(fifo_reader_to_writer, 0600) < 0) { - H5_FAILED(); AT(); - printf("HDmkfifo failed"); - goto error; - } - } - - /* Both the writer and reader open the pipes */ - if (use_named_pipe && (fd_writer_to_reader = HDopen(fifo_writer_to_reader, O_RDWR)) < 0) { + /* Writer creates two named pipes(FIFO) to coordinate two-way communication + * between the writer and the reader. Both the writer and reader open the named pipes */ + if (create_open_named_pipes() < 0) { H5_FAILED(); AT(); - printf("fifo_writer_to_reader open failed"); - goto error; - } - - if (use_named_pipe && (fd_reader_to_writer = HDopen(fifo_reader_to_writer, O_RDWR)) < 0) { - H5_FAILED(); AT(); - printf("fifo_reader_to_writer open failed"); + printf("create_open_named_pipes failed"); goto error; } @@ -285,49 +499,20 @@ main(int argc, char **argv) goto error; } + /* Start to create the zoo */ if (!create_zoo(fid, ".", &lastmsgtime, config)) { H5_FAILED(); AT(); printf("create_zoo failed"); goto error; } - if (use_named_pipe) { - /* Get the time when finishing zoo creation */ - if (HDclock_gettime(CLOCK_MONOTONIC, &last) < 0) { - H5_FAILED(); AT(); - printf("HDclock_gettime failed"); - goto error; - } - - /* Notify the reader of finishing zoo creation by sending the timestamp */ - if (HDwrite(fd_writer_to_reader, &last, sizeof(last)) < 0) { - H5_FAILED(); AT(); - printf("HDwrite failed"); - goto error; - } - - /* During the wait, writer makes repeated HDF5 API calls so as to trigger - * EOT at approximately the correct time */ - for(i = 0; i < swmr_config.max_lag + 1; i++) { - decisleep(swmr_config.tick_len); - - H5E_BEGIN_TRY { - H5Aexists(fid, "nonexistent"); - } H5E_END_TRY; - } - - /* Wait until the reader finishes validating zoo creation */ - if (HDread(fd_reader_to_writer, ¬ify, sizeof(int)) < 0) { - H5_FAILED(); AT(); - printf("HDread failed"); - goto error; - } - - if (notify != 2) { - H5_FAILED(); AT(); - printf("expected 2 but read %d", notify); - goto error; - } + /* Notify the reader of finishing zoo creation by sending the timestamp + * and wait for the reader to finish validation before proceeding */ + verify = 2; + if (notify_and_wait_for_reader(fid, verify) < 0) { + H5_FAILED(); AT(); + printf("notify_and_wait_for_reader failed"); + goto error; } /* Start to delete the zoo */ @@ -337,85 +522,51 @@ main(int argc, char **argv) goto error; } - if (use_named_pipe) { - /* Get the time when finishing zoo deletion */ - if (HDclock_gettime(CLOCK_MONOTONIC, &last) < 0) { - H5_FAILED(); AT(); - printf("HDclock_gettime failed"); - goto error; - } - - /* Notify the reader about finishing zoo deletion by sending the timestamp */ - if (HDwrite(fd_writer_to_reader, &last, sizeof(last)) < 0) { - H5_FAILED(); AT(); - printf("HDwrite failed"); - goto error; - } + /* Notify the reader of finishing zoo deletion by sending the timestamp */ + if (notify_reader() < 0) { + H5_FAILED(); AT(); + printf("notify_reader failed"); + goto error; } } else { dbgf(2, "Reading zoo...\n"); - if (use_named_pipe) { - /* Start to validate zoo creation after receiving the writer's notice */ - if (HDread(fd_writer_to_reader, ¬ify, sizeof(int)) < 0) { - H5_FAILED(); AT(); - printf("HDread failed"); - goto error; - } - - if (notify != 1) { - H5_FAILED(); AT(); - printf("expected 1 but read %d", notify); - goto error; - } + /* Wait for the writer's notice before starting to zoo validation */ + verify = 1; + if (reader_verify(verify) < 0) { + H5_FAILED(); AT(); + printf("reader_verify failed"); + goto error; } + /* Validate the zoo creation */ while (!validate_zoo(fid, ".", &lastmsgtime, config)) ; - if (use_named_pipe) { - /* Receive the notice of the writer finishing zoo creation (timestamp) */ - if (HDread(fd_writer_to_reader, &last, sizeof(last)) < 0) { - H5_FAILED(); AT(); - printf("HDread failed"); - goto error; - } - - /* Make sure the zoo validation doesn't take longer than the expected time. - * This time period is from the writer finishing zoo creation to the reader finishing - * the validation of zoo creation */ - if (below_speed_limit(&last, &ival)) { - AT(); - warnx("validate_zoo took too long to finish"); - } - /* Notify the writer that zoo validation is finished */ - notify = 2; - if (HDwrite(fd_reader_to_writer, ¬ify, sizeof(int)) < 0) { - H5_FAILED(); AT(); - printf("HDwrite failed"); - goto error; - } + /* Receive the notice of the writer finishing zoo creation (timestamp) + * Make sure the zoo validation doesn't take longer than the expected time. + * This time period is from the writer finishing zoo creation to the reader finishing + * the validation of zoo creation */ + notify = 2; + if (reader_check_time_and_notify_writer(notify) < 0) { + H5_FAILED(); AT(); + printf("reader_check_time_and_notify_writer failed"); + goto error; } + /* Start to validate the zoo deletion */ while (!validate_deleted_zoo(fid, ".", &lastmsgtime, config)) ; - if (use_named_pipe) { - /* Receive the finish notice (timestamp) from the writer */ - if (HDread(fd_writer_to_reader, &last, sizeof(last)) < 0) { - H5_FAILED(); AT(); - printf("HDread failed"); - goto error; - } - - /* Make sure validation of zoo deletion doesn't take longer than the expected time. - * This time period is from the writer finishing zoo deletion to the reader finishing - * the validation of zoo deletion */ - if (below_speed_limit(&last, &ival)) { - AT(); - warnx("validate_deleted_zoo took too long to finish"); - } + /* Receive the finish notice (timestamp) from the writer. + * Make sure validation of zoo deletion doesn't take longer than the expected time. + * This time period is from the writer finishing zoo deletion to the reader finishing + * the validation of zoo deletion */ + if (reader_check_time_after_verify_deletion() < 0) { + H5_FAILED(); AT(); + printf("reader_check_time_and_notify_writer failed"); + goto error; } } restore_estack(es); -- cgit v0.12 From 625bc5db3c1ba3f9a5897d6c900714583b49d073 Mon Sep 17 00:00:00 2001 From: Songyu Lu Date: Tue, 13 Apr 2021 11:41:58 -0500 Subject: Minor changes: refactored to simplify the code. --- test/vfd_swmr_zoo_writer.c | 236 +++++++++++++++++++++++---------------------- 1 file changed, 121 insertions(+), 115 deletions(-) diff --git a/test/vfd_swmr_zoo_writer.c b/test/vfd_swmr_zoo_writer.c index de90139..c8e7055 100644 --- a/test/vfd_swmr_zoo_writer.c +++ b/test/vfd_swmr_zoo_writer.c @@ -181,7 +181,7 @@ static int create_open_named_pipes(void) { /* Writer creates two named pipes(FIFO) to coordinate two-way communication */ - if (use_named_pipe && writer) { + if (writer) { if (HDmkfifo(fifo_writer_to_reader, 0600) < 0) { H5_FAILED(); AT(); printf("HDmkfifo failed"); @@ -196,13 +196,13 @@ create_open_named_pipes(void) } /* Both the writer and reader open the pipes */ - if (use_named_pipe && (fd_writer_to_reader = HDopen(fifo_writer_to_reader, O_RDWR)) < 0) { + if ((fd_writer_to_reader = HDopen(fifo_writer_to_reader, O_RDWR)) < 0) { H5_FAILED(); AT(); printf("fifo_writer_to_reader open failed"); goto error; } - if (use_named_pipe && (fd_reader_to_writer = HDopen(fifo_reader_to_writer, O_RDWR)) < 0) { + if ((fd_reader_to_writer = HDopen(fifo_reader_to_writer, O_RDWR)) < 0) { H5_FAILED(); AT(); printf("fifo_reader_to_writer open failed"); goto error; @@ -223,43 +223,41 @@ notify_and_wait_for_reader(hid_t fid, int verify) unsigned int i; struct timespec last = {0, 0}; - if (use_named_pipe) { - /* Get the time when finishing zoo creation */ - if (HDclock_gettime(CLOCK_MONOTONIC, &last) < 0) { - H5_FAILED(); AT(); - printf("HDclock_gettime failed"); - goto error; - } + /* Get the time when finishing zoo creation */ + if (HDclock_gettime(CLOCK_MONOTONIC, &last) < 0) { + H5_FAILED(); AT(); + printf("HDclock_gettime failed"); + goto error; + } - /* Notify the reader of finishing zoo creation by sending the timestamp */ - if (HDwrite(fd_writer_to_reader, &last, sizeof(last)) < 0) { - H5_FAILED(); AT(); - printf("HDwrite failed"); - goto error; - } + /* Notify the reader of finishing zoo creation by sending the timestamp */ + if (HDwrite(fd_writer_to_reader, &last, sizeof(last)) < 0) { + H5_FAILED(); AT(); + printf("HDwrite failed"); + goto error; + } - /* During the wait, writer makes repeated HDF5 API calls so as to trigger - * EOT at approximately the correct time */ - for(i = 0; i < swmr_config.max_lag + 1; i++) { - decisleep(swmr_config.tick_len); + /* During the wait, writer makes repeated HDF5 API calls so as to trigger + * EOT at approximately the correct time */ + for(i = 0; i < swmr_config.max_lag + 1; i++) { + decisleep(swmr_config.tick_len); - H5E_BEGIN_TRY { - H5Aexists(fid, "nonexistent"); - } H5E_END_TRY; - } + H5E_BEGIN_TRY { + H5Aexists(fid, "nonexistent"); + } H5E_END_TRY; + } - /* Wait until the reader finishes validating zoo creation */ - if (HDread(fd_reader_to_writer, ¬ify, sizeof(int)) < 0) { - H5_FAILED(); AT(); - printf("HDread failed"); - goto error; - } + /* Wait until the reader finishes validating zoo creation */ + if (HDread(fd_reader_to_writer, ¬ify, sizeof(int)) < 0) { + H5_FAILED(); AT(); + printf("HDread failed"); + goto error; + } - if (notify != verify) { - H5_FAILED(); AT(); - printf("expected %d but read %d", verify, notify); - goto error; - } + if (notify != verify) { + H5_FAILED(); AT(); + printf("expected %d but read %d", verify, notify); + goto error; } return 0; @@ -274,20 +272,18 @@ notify_reader(void) { struct timespec last = {0, 0}; - if (use_named_pipe) { - /* Get the time when finishing zoo deletion */ - if (HDclock_gettime(CLOCK_MONOTONIC, &last) < 0) { - H5_FAILED(); AT(); - printf("HDclock_gettime failed"); - goto error; - } + /* Get the time when finishing zoo deletion */ + if (HDclock_gettime(CLOCK_MONOTONIC, &last) < 0) { + H5_FAILED(); AT(); + printf("HDclock_gettime failed"); + goto error; + } - /* Notify the reader about finishing zoo deletion by sending the timestamp */ - if (HDwrite(fd_writer_to_reader, &last, sizeof(last)) < 0) { - H5_FAILED(); AT(); - printf("HDwrite failed"); - goto error; - } + /* Notify the reader about finishing zoo deletion by sending the timestamp */ + if (HDwrite(fd_writer_to_reader, &last, sizeof(last)) < 0) { + H5_FAILED(); AT(); + printf("HDwrite failed"); + goto error; } return 0; @@ -302,18 +298,16 @@ reader_verify(int verify) { int notify; - if (use_named_pipe) { - if (HDread(fd_writer_to_reader, ¬ify, sizeof(int)) < 0) { - H5_FAILED(); AT(); - printf("HDread failed"); - goto error; - } + if (HDread(fd_writer_to_reader, ¬ify, sizeof(int)) < 0) { + H5_FAILED(); AT(); + printf("HDread failed"); + goto error; + } - if (notify != verify) { - H5_FAILED(); AT(); - printf("expected %d but read %d", verify, notify); - goto error; - } + if (notify != verify) { + H5_FAILED(); AT(); + printf("expected %d but read %d", verify, notify); + goto error; } return 0; @@ -331,28 +325,26 @@ reader_check_time_and_notify_writer(int notify) { struct timespec last = {0, 0}; - if (use_named_pipe) { - /* Receive the notice of the writer finishing zoo creation (timestamp) */ - if (HDread(fd_writer_to_reader, &last, sizeof(last)) < 0) { - H5_FAILED(); AT(); - printf("HDread failed"); - goto error; - } + /* Receive the notice of the writer finishing zoo creation (timestamp) */ + if (HDread(fd_writer_to_reader, &last, sizeof(last)) < 0) { + H5_FAILED(); AT(); + printf("HDread failed"); + goto error; + } - /* Make sure the zoo validation doesn't take longer than the expected time. - * This time period is from the writer finishing zoo creation to the reader finishing - * the validation of zoo creation */ - if (below_speed_limit(&last, &ival)) { - AT(); - warnx("validate_zoo took too long to finish"); - } + /* Make sure the zoo validation doesn't take longer than the expected time. + * This time period is from the writer finishing zoo creation to the reader finishing + * the validation of zoo creation */ + if (below_speed_limit(&last, &ival)) { + AT(); + warnx("validate_zoo took too long to finish"); + } - /* Notify the writer that zoo validation is finished */ - if (HDwrite(fd_reader_to_writer, ¬ify, sizeof(int)) < 0) { - H5_FAILED(); AT(); - printf("HDwrite failed"); - goto error; - } + /* Notify the writer that zoo validation is finished */ + if (HDwrite(fd_reader_to_writer, ¬ify, sizeof(int)) < 0) { + H5_FAILED(); AT(); + printf("HDwrite failed"); + goto error; } return 0; @@ -370,16 +362,52 @@ reader_check_time_after_verify_deletion(void) { struct timespec last = {0, 0}; - if (use_named_pipe) { - if (HDread(fd_writer_to_reader, &last, sizeof(last)) < 0) { + if (HDread(fd_writer_to_reader, &last, sizeof(last)) < 0) { + H5_FAILED(); AT(); + printf("HDread failed"); + goto error; + } + + if (below_speed_limit(&last, &ival)) { + AT(); + warnx("validate_deleted_zoo took too long to finish"); + } + + return 0; + +error: + return -1; +} + +/* Close and remove the named pipes */ +static int +close_named_pipes(void) +{ + /* Close the named pipes */ + if (HDclose(fd_writer_to_reader) < 0) { + H5_FAILED(); AT(); + printf("HDclose failed\n"); + goto error; + } + + if (HDclose(fd_reader_to_writer) < 0) { + H5_FAILED(); AT(); + printf("HDclose failed\n"); + goto error; + } + + /* Reader finishes last and deletes the named pipes */ + if(!writer) { + if(HDremove(fifo_writer_to_reader) != 0) { H5_FAILED(); AT(); - printf("HDread failed"); + printf("HDremove failed\n"); goto error; } - if (below_speed_limit(&last, &ival)) { - AT(); - warnx("validate_deleted_zoo took too long to finish"); + if(HDremove(fifo_reader_to_writer) != 0) { + H5_FAILED(); AT(); + printf("HDremove failed\n"); + goto error; } } @@ -479,7 +507,7 @@ main(int argc, char **argv) /* Writer creates two named pipes(FIFO) to coordinate two-way communication * between the writer and the reader. Both the writer and reader open the named pipes */ - if (create_open_named_pipes() < 0) { + if (use_named_pipe && create_open_named_pipes() < 0) { H5_FAILED(); AT(); printf("create_open_named_pipes failed"); goto error; @@ -509,7 +537,7 @@ main(int argc, char **argv) /* Notify the reader of finishing zoo creation by sending the timestamp * and wait for the reader to finish validation before proceeding */ verify = 2; - if (notify_and_wait_for_reader(fid, verify) < 0) { + if (use_named_pipe && notify_and_wait_for_reader(fid, verify) < 0) { H5_FAILED(); AT(); printf("notify_and_wait_for_reader failed"); goto error; @@ -523,7 +551,7 @@ main(int argc, char **argv) } /* Notify the reader of finishing zoo deletion by sending the timestamp */ - if (notify_reader() < 0) { + if (use_named_pipe && notify_reader() < 0) { H5_FAILED(); AT(); printf("notify_reader failed"); goto error; @@ -533,7 +561,7 @@ main(int argc, char **argv) /* Wait for the writer's notice before starting to zoo validation */ verify = 1; - if (reader_verify(verify) < 0) { + if (use_named_pipe && reader_verify(verify) < 0) { H5_FAILED(); AT(); printf("reader_verify failed"); goto error; @@ -549,7 +577,7 @@ main(int argc, char **argv) * This time period is from the writer finishing zoo creation to the reader finishing * the validation of zoo creation */ notify = 2; - if (reader_check_time_and_notify_writer(notify) < 0) { + if (use_named_pipe && reader_check_time_and_notify_writer(notify) < 0) { H5_FAILED(); AT(); printf("reader_check_time_and_notify_writer failed"); goto error; @@ -563,7 +591,7 @@ main(int argc, char **argv) * Make sure validation of zoo deletion doesn't take longer than the expected time. * This time period is from the writer finishing zoo deletion to the reader finishing * the validation of zoo deletion */ - if (reader_check_time_after_verify_deletion() < 0) { + if (use_named_pipe && reader_check_time_after_verify_deletion() < 0) { H5_FAILED(); AT(); printf("reader_check_time_and_notify_writer failed"); goto error; @@ -592,34 +620,12 @@ main(int argc, char **argv) if (progname) HDfree(progname); - /* Close the named pipes */ - if (use_named_pipe && HDclose(fd_writer_to_reader) < 0) { + if (use_named_pipe && close_named_pipes() < 0) { H5_FAILED(); AT(); - printf("HDclose failed\n"); - goto error; - } - - if (use_named_pipe && HDclose(fd_reader_to_writer) < 0) { - H5_FAILED(); AT(); - printf("HDclose failed\n"); + printf("close_named_pipes failed"); goto error; } - /* Reader finishes last and deletes the named pipes */ - if(use_named_pipe && !writer) { - if(HDremove(fifo_writer_to_reader) != 0) { - H5_FAILED(); AT(); - printf("HDremove failed\n"); - goto error; - } - - if(HDremove(fifo_reader_to_writer) != 0) { - H5_FAILED(); AT(); - printf("HDremove failed\n"); - goto error; - } - } - return EXIT_SUCCESS; error: -- cgit v0.12 From 95718b27fddb8f5d8fe6216b021acba400407cda Mon Sep 17 00:00:00 2001 From: Songyu Lu Date: Tue, 13 Apr 2021 11:45:10 -0500 Subject: Minor change: removed an unused line. --- test/vfd_swmr_zoo_writer.c | 1 - 1 file changed, 1 deletion(-) diff --git a/test/vfd_swmr_zoo_writer.c b/test/vfd_swmr_zoo_writer.c index c8e7055..00dcd9e 100644 --- a/test/vfd_swmr_zoo_writer.c +++ b/test/vfd_swmr_zoo_writer.c @@ -491,7 +491,6 @@ main(int argc, char **argv) fid = H5Fopen("vfd_swmr_zoo.h5", H5F_ACC_RDONLY, fapl); if (fid < 0) { - errx(EXIT_FAILURE, writer ? "H5Fcreate" : "H5Fopen"); H5_FAILED(); AT(); printf(writer ? "H5Fcreate failed" : "H5Fopen failed"); goto error; -- cgit v0.12