diff options
author | Songyu Lu <songyulu@hdfgroup.org> | 2021-03-19 16:25:22 (GMT) |
---|---|---|
committer | Songyu Lu <songyulu@hdfgroup.org> | 2021-03-19 16:25:22 (GMT) |
commit | 1cc3f187ee3524e412babf5059fed4757b3769fd (patch) | |
tree | 4bf3ee3312867008882dffeff2c90214a17be2d0 /test | |
parent | 84b31b5a558bdc816e91c414f98155bf72ae1502 (diff) | |
download | hdf5-1cc3f187ee3524e412babf5059fed4757b3769fd.zip hdf5-1cc3f187ee3524e412babf5059fed4757b3769fd.tar.gz hdf5-1cc3f187ee3524e412babf5059fed4757b3769fd.tar.bz2 |
Rearranged the test in the following way:
1. Reader waits for a number of ticks (3 by default) before verifying the creation of groups and attributes;
2. Error handling is consistent with traditional setup of the test suite.
Diffstat (limited to 'test')
-rw-r--r-- | test/testvfdswmr.sh.in | 7 | ||||
-rw-r--r-- | test/vfd_swmr_group_writer.c | 538 |
2 files changed, 411 insertions, 134 deletions
diff --git a/test/testvfdswmr.sh.in b/test/testvfdswmr.sh.in index a2e47b1..fc6b0df 100644 --- a/test/testvfdswmr.sh.in +++ b/test/testvfdswmr.sh.in @@ -610,17 +610,17 @@ if [ ${do_zoo:-no} = yes ]; then fi # -# Make sure that we can create 10000 groups while a reader waits +# Make sure that we can create 1000 groups while a reader waits # for each to appear. # if [ ${do_groups:-no} = yes ]; then echo launch vfd_swmr_group_writer catch_out_err_and_rc vfd_swmr_group_writer \ - ../vfd_swmr_group_writer -q -u 10 -n 10000 & + ../vfd_swmr_group_writer -q -c 100 -n 1000 & pid_writer=$! catch_out_err_and_rc vfd_swmr_group_reader \ - ../vfd_swmr_group_reader -q -u 10 -n 10000 -W & + ../vfd_swmr_group_reader -q -c 100 -n 1000 -u 5 & pid_reader=$! # Wait for the reader to finish before signalling the @@ -628,7 +628,6 @@ if [ ${do_groups:-no} = yes ]; then # reader will find the shadow file when it opens # the .h5 file. wait $pid_reader - kill -USR1 $(cat vfd_swmr_group_writer.pid) wait $pid_writer # Collect exit code of the reader diff --git a/test/vfd_swmr_group_writer.c b/test/vfd_swmr_group_writer.c index 2f355c2..4e323ef 100644 --- a/test/vfd_swmr_group_writer.c +++ b/test/vfd_swmr_group_writer.c @@ -18,21 +18,22 @@ #include "hdf5.h" #include "H5Fpkg.h" -// #include "H5Iprivate.h" #include "H5HGprivate.h" #include "H5VLprivate.h" #include "testhdf5.h" #include "vfd_swmr_common.h" +#define READER_WAIT_TICKS 3 + typedef struct { hid_t file, filetype, one_by_one_sid; char filename[PATH_MAX]; char progname[PATH_MAX]; - struct timespec update_interval; unsigned int asteps; + unsigned int csteps; unsigned int nsteps; - bool wait_for_signal; + unsigned int update_interval; bool use_vfd_swmr; } state_t; @@ -42,37 +43,29 @@ typedef struct { , .filename = "" \ , .filetype = H5T_NATIVE_UINT32 \ , .asteps = 10 \ + , .csteps = 10 \ , .nsteps = 100 \ - , .wait_for_signal = true \ - , .use_vfd_swmr = true \ - , .update_interval = (struct timespec){ \ - .tv_sec = 0 \ - , .tv_nsec = 1000000000UL / 30 /* 1/30 second */}} - -static void state_init(state_t *, int, char **); - -static const hid_t badhid = H5I_INVALID_HID; + , .update_interval = READER_WAIT_TICKS \ + , .use_vfd_swmr = true} static void usage(const char *progname) { - fprintf(stderr, "usage: %s [-S] [-W] [-a steps] [-b]\n" - " [-n iterations] [-u milliseconds]\n" + fprintf(stderr, "usage: %s [-S] [-a steps] [-b] [-c]\n" + " [-n iterations] [-u numb_ticks]\n" "\n" "-S: do not use VFD SWMR\n" - "-W: do not wait for a signal before\n" - " exiting\n" "-a steps: `steps` between adding attributes\n" "-b: write data in big-endian byte order\n" - "-n iterations: how many times to expand each dataset\n" - "-u ms: milliseconds interval between updates\n" - " to %s.h5\n" + "-c steps: `steps` between communication between the writer and reader\n" + "-n ngroups: the number of groups\n" + "-u numb_tcks: `numb_ticks` for the reader to wait before verification\n" "\n", - progname, progname); + progname); exit(EXIT_FAILURE); } -static void +static bool state_init(state_t *s, int argc, char **argv) { unsigned long tmp; @@ -80,37 +73,44 @@ state_init(state_t *s, int argc, char **argv) const hsize_t dims = 1; char tfile[PATH_MAX]; char *end; - unsigned long millis; *s = ALL_HID_INITIALIZER; esnprintf(tfile, sizeof(tfile), "%s", argv[0]); esnprintf(s->progname, sizeof(s->progname), "%s", HDbasename(tfile)); - while ((ch = getopt(argc, argv, "SWa:bn:qu:")) != -1) { + while ((ch = getopt(argc, argv, "SWa:bc:n:qu:")) != -1) { switch (ch) { case 'S': s->use_vfd_swmr = false; break; - case 'W': - s->wait_for_signal = false; - break; case 'a': + case 'c': case 'n': + case 'u': errno = 0; tmp = strtoul(optarg, &end, 0); if (end == optarg || *end != '\0') { - errx(EXIT_FAILURE, "couldn't parse `-%c` argument `%s`", ch, - optarg); + H5_FAILED(); AT(); + printf("couldn't parse `-%c` argument `%s`\n", ch, optarg); + goto error; } else if (errno != 0) { - err(EXIT_FAILURE, "couldn't parse `-%c` argument `%s`", ch, - optarg); - } else if (tmp > UINT_MAX) - errx(EXIT_FAILURE, "`-%c` argument `%lu` too large", ch, tmp); + H5_FAILED(); AT(); + printf("couldn't parse `-%c` argument `%s`\n", ch, optarg); + goto error; + } else if (tmp > UINT_MAX) { + H5_FAILED(); AT(); + printf("`-%c` argument `%lu` too large\n", ch, tmp); + goto error; + } if (ch == 'a') s->asteps = (unsigned)tmp; - else + else if (ch == 'c') + s->csteps = (unsigned)tmp; + else if (ch == 'n') s->nsteps = (unsigned)tmp; + else if (ch == 'u') + s->update_interval = (unsigned)tmp; break; case 'b': s->filetype = H5T_STD_U32BE; @@ -118,21 +118,6 @@ state_init(state_t *s, int argc, char **argv) case 'q': verbosity = 0; break; - case 'u': - errno = 0; - millis = strtoul(optarg, &end, 0); - if (millis == ULONG_MAX && errno == ERANGE) { - err(EXIT_FAILURE, - "option -p argument \"%s\"", optarg); - } else if (*end != '\0') { - errx(EXIT_FAILURE, - "garbage after -p argument \"%s\"", optarg); - } - s->update_interval.tv_sec = (time_t)(millis / 1000UL); - s->update_interval.tv_nsec = - (long)((millis * 1000000UL) % 1000000000UL); - dbgf(1, "%lu milliseconds between updates\n", millis); - break; case '?': default: usage(s->progname); @@ -143,16 +128,39 @@ state_init(state_t *s, int argc, char **argv) argv += optind; /* space for attributes */ - if ((s->one_by_one_sid = H5Screate_simple(1, &dims, &dims)) < 0) - errx(EXIT_FAILURE, "H5Screate_simple failed"); + if ((s->one_by_one_sid = H5Screate_simple(1, &dims, &dims)) < 0) { + H5_FAILED(); AT(); + printf("H5Screate_simple failed\n"); + goto error; + } + + if( s->csteps < 1 || s->csteps > s->nsteps) { + H5_FAILED(); AT(); + printf("communication interval is out of bounds\n"); + goto error; + } - if (argc > 0) - errx(EXIT_FAILURE, "unexpected command-line arguments"); + if( s->asteps < 1 || s->asteps > s->nsteps) { + H5_FAILED(); AT(); + printf("attribute interval is out of bounds\n"); + goto error; + } + + if (argc > 0) { + H5_FAILED(); AT(); + printf("unexpected command-line arguments\n"); + goto error; + } esnprintf(s->filename, sizeof(s->filename), "vfd_swmr_group.h5"); + + return true; + +error: + return false; } -static void +static bool add_group_attribute(const state_t *s, hid_t g, hid_t sid, unsigned int which) { hid_t aid; @@ -163,42 +171,78 @@ add_group_attribute(const state_t *s, hid_t g, hid_t sid, unsigned int which) dbgf(1, "setting attribute %s on group %u to %u\n", name, which, which); if ((aid = H5Acreate2(g, name, s->filetype, sid, H5P_DEFAULT, - H5P_DEFAULT)) < 0) - errx(EXIT_FAILURE, "H5Acreate2 failed"); + H5P_DEFAULT)) < 0) { + H5_FAILED(); AT(); + printf("H5Acreate2 failed\n"); + goto error; + } - if (H5Awrite(aid, H5T_NATIVE_UINT, &which) < 0) - errx(EXIT_FAILURE, "H5Awrite failed"); - if (H5Aclose(aid) < 0) - errx(EXIT_FAILURE, "H5Aclose failed"); + if (H5Awrite(aid, H5T_NATIVE_UINT, &which) < 0) { + H5_FAILED(); AT(); + printf("H5Awrite failed\n"); + goto error; + } + + if (H5Aclose(aid) < 0) { + H5_FAILED(); AT(); + printf("H5Aclose failed\n"); + goto error; + } + + return true; + +error: + H5E_BEGIN_TRY { + H5Aclose(aid); + } H5E_END_TRY; + + return false; } -static void +static bool write_group(state_t *s, unsigned int which) { char name[sizeof("/group-9999999999")]; - hid_t g; + hid_t g = H5I_INVALID_HID; + bool result = true; - assert(which < s->nsteps); + if (which >= s->nsteps) { + H5_FAILED(); AT(); + printf("group order is out of bounds\n"); + goto error; + } esnprintf(name, sizeof(name), "/group-%d", which); - g = H5Gcreate2(s->file, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); - - if (g < 0) - errx(EXIT_FAILURE, "H5Gcreate(, \"%s\", ) failed", name); + if ((g = H5Gcreate2(s->file, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { + H5_FAILED(); AT(); + printf("H5Gcreate2 failed\n"); + goto error; + } if (s->asteps != 0 && which % s->asteps == 0) - add_group_attribute(s, g, s->one_by_one_sid, which); + result = add_group_attribute(s, g, s->one_by_one_sid, which); - if (H5Gclose(g) < 0) - errx(EXIT_FAILURE, "H5Gclose failed"); + if (H5Gclose(g) < 0) { + H5_FAILED(); AT(); + printf("H5Gclose failed\n"); + goto error; + } + + return result; + +error: + H5E_BEGIN_TRY { + H5Gclose(g); + } H5E_END_TRY; + + return false; } static bool verify_group_attribute(hid_t g, unsigned int which) { - estack_state_t es; unsigned int read_which; hid_t aid; char name[sizeof("attr-9999999999")]; @@ -208,70 +252,111 @@ verify_group_attribute(hid_t g, unsigned int which) dbgf(1, "verifying attribute %s on group %u equals %u\n", name, which, which); - es = disable_estack(); if ((aid = H5Aopen(g, name, H5P_DEFAULT)) < 0) { - restore_estack(es); - return false; + H5_FAILED(); AT(); + printf("H5Aopen failed\n"); + goto error; } if (H5Aread(aid, H5T_NATIVE_UINT, &read_which) < 0) { - restore_estack(es); - if (H5Aclose(aid) < 0) - errx(EXIT_FAILURE, "H5Aclose failed"); - return false; + H5_FAILED(); AT(); + printf("H5Aread failed\n"); + goto error; } - restore_estack(es); + if (read_which != which) { + H5_FAILED(); AT(); + printf("H5Aread wrong value\n"); + goto error; + } - if (H5Aclose(aid) < 0) - errx(EXIT_FAILURE, "H5Aclose failed"); + if (H5Aclose(aid) < 0) { + H5_FAILED(); AT(); + printf("H5Aread failed\n"); + goto error; + } - return read_which == which; + return true; + +error: + H5E_BEGIN_TRY { + H5Aclose(aid); + } H5E_END_TRY; + + return false; } static bool verify_group(state_t *s, unsigned int which) { char name[sizeof("/group-9999999999")]; - hid_t g; - estack_state_t es; - bool result; + hid_t g = H5I_INVALID_HID; + bool result = true; - assert(which < s->nsteps); + if (which >= s->nsteps) { + H5_FAILED(); AT(); + printf("Group order is out of bounds\n"); + goto error; + } esnprintf(name, sizeof(name), "/group-%d", which); - es = disable_estack(); - g = H5Gopen(s->file, name, H5P_DEFAULT); - restore_estack(es); - - if (g < 0) - return false; + if ((g = H5Gopen(s->file, name, H5P_DEFAULT)) < 0) { + H5_FAILED(); AT(); + printf("H5Gopen failed\n"); + goto error; + } if (s->asteps != 0 && which % s->asteps == 0) result = verify_group_attribute(g, which); else result = true; - if (H5Gclose(g) < 0) - errx(EXIT_FAILURE, "H5Gclose failed"); + if (H5Gclose(g) < 0) { + H5_FAILED(); AT(); + printf("H5Gclose failed\n"); + goto error; + } return result; + +error: + H5E_BEGIN_TRY { + H5Gclose(g); + } H5E_END_TRY; + + return false; +} + +/* 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) { - hid_t fapl, fcpl; - sigset_t oldsigs; - herr_t ret; + hid_t fapl = H5I_INVALID_HID, fcpl = H5I_INVALID_HID; unsigned step; - bool writer; + bool writer = false; state_t s; const char *personality; H5F_vfd_swmr_config_t config; - - state_init(&s, argc, argv); + const char *fifo_writer_to_reader = "./fifo_group_writer_to_reader"; + const char *fifo_reader_to_writer = "./fifo_group_reader_to_writer"; + int fd_writer_to_reader = -1, fd_reader_to_writer = -1; + int notify = 0, verify = 0; + unsigned int i; + + if (!state_init(&s, argc, argv)) { + H5_FAILED(); AT(); + printf("state_init failed\n"); + goto error; + } personality = strstr(s.progname, "vfd_swmr_group_"); @@ -282,64 +367,257 @@ main(int argc, char **argv) strcmp(personality, "vfd_swmr_group_reader") == 0) writer = false; else { - errx(EXIT_FAILURE, - "unknown personality, expected vfd_swmr_group_{reader,writer}"); + H5_FAILED(); AT(); + printf("unknown personality, expected vfd_swmr_group_{reader,writer}\n"); + goto error; } /* config, tick_len, max_lag, writer, flush_raw_data, md_pages_reserved, md_file_path */ init_vfd_swmr_config(&config, 4, 7, writer, FALSE, 128, "./group-shadow"); /* use_latest_format, use_vfd_swmr, only_meta_page, config */ - fapl = vfd_swmr_create_fapl(true, s.use_vfd_swmr, true, &config); - - if (fapl < 0) - errx(EXIT_FAILURE, "vfd_swmr_create_fapl"); + if ((fapl = vfd_swmr_create_fapl(true, s.use_vfd_swmr, true, &config)) < 0) { + H5_FAILED(); AT(); + printf("vfd_swmr_create_fapl failed\n"); + 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\n"); + 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\n"); + goto error; + } if (writer) s.file = H5Fcreate(s.filename, H5F_ACC_TRUNC, fcpl, fapl); else s.file = H5Fopen(s.filename, H5F_ACC_RDONLY, fapl); - if (s.file == badhid) - errx(EXIT_FAILURE, writer ? "H5Fcreate" : "H5Fopen"); + if (s.file < 0) { + H5_FAILED(); AT(); + printf("H5Fcreate/open failed\n"); + goto error; + } + + /* Use two named pipes(FIFO) to coordinate the writer and reader for + * two-way communication so that the two sides can move forward together. + * One is for the writer to write to the reader. + * The other one is for the reader to signal the writer. */ + if (writer) { + /* Writer creates two named pipes(FIFO) */ + if (HDmkfifo(fifo_writer_to_reader, 0600) < 0) { + H5_FAILED(); AT(); + printf("HDmkfifo failed\n"); + goto error; + } + + if (HDmkfifo(fifo_reader_to_writer, 0600) < 0) { + H5_FAILED(); AT(); + printf("HDmkfifo failed\n"); + goto error; + } + + } + + /* Both the writer and reader open the pipes */ + if ((fd_writer_to_reader = HDopen(fifo_writer_to_reader, O_RDWR)) < 0) { + H5_FAILED(); AT(); + printf("HDopen failed\n"); + goto error; + } - block_signals(&oldsigs); + if ((fd_reader_to_writer = HDopen(fifo_reader_to_writer, O_RDWR)) < 0) { + H5_FAILED(); AT(); + printf("HDopen failed\n"); + goto error; + } if (writer) { for (step = 0; step < s.nsteps; step++) { - dbgf(2, "step %d\n", step); - write_group(&s, step); - nanosleep(&s.update_interval, NULL); + dbgf(2, "writer: step %d\n", step); + + if (!write_group(&s, step)) { + H5_FAILED(); AT(); + printf("write_group failed\n"); + + /* At communication interval, notifies the reader about the failture and quit */ + if (step % s.csteps == 0) { + notify = -1; + HDwrite(fd_writer_to_reader, ¬ify, sizeof(int)); + goto error; + } + } else { + /* At communication interval, notifies the reader and waits for its response */ + if (step % s.csteps == 0) { + /* Bump up the value of notify to notice the reader to start to read */ + notify++; + if (HDwrite(fd_writer_to_reader, ¬ify, sizeof(int)) < 0) { + H5_FAILED(); AT(); + printf("HDwrite failed\n"); + goto error; + } + + /* During the wait, writer makes repeated HDF5 API calls + * to trigger EOT at approximately the correct time */ + for(i = 0; i < config.max_lag + 1; i++) { + decisleep(config.tick_len); + H5E_BEGIN_TRY { + H5Aexists(s.file, "nonexistent"); + } H5E_END_TRY; + } + + /* Receive the same value from the reader and verify it before + * going to the next step */ + verify++; + if (HDread(fd_reader_to_writer, ¬ify, sizeof(int)) < 0) { + H5_FAILED(); AT(); + printf("HDread failed\n"); + goto error; + } + + if (notify == -1) { + H5_FAILED(); AT(); + printf("reader failed to verify group\n"); + goto error; + } + + if (notify != verify) { + H5_FAILED(); AT(); + printf("received message %d, expecting %d\n", notify, verify); + goto error; + } + } + } } } else { - for (step = 0; step < s.nsteps;) { - dbgf(2, "step %d\n", step); - if (verify_group(&s, step)) - step++; - nanosleep(&s.update_interval, NULL); + for (step = 0; step < s.nsteps; step++) { + dbgf(2, "reader: step %d\n", step); + + /* At communication interval, waits for the writer to finish creation before starting verification */ + if (step % s.csteps == 0) { + /* The writer should have bumped up the value of notify. + * Do the same with verify and confirm it */ + verify++; + + /* Receive the notify that the writer bumped up the value */ + if (HDread(fd_writer_to_reader, ¬ify, sizeof(int)) < 0) { + H5_FAILED(); AT(); + printf("HDread failed\n"); + goto error; + } + + if (notify == -1) { + H5_FAILED(); AT(); + printf("writer failed to create group\n"); + goto error; + } + + if (notify != verify) { + H5_FAILED(); AT(); + printf("received message %d, expecting %d\n", notify, verify); + goto error; + } + } + + /* Wait for a few ticks for the update to happen */ + decisleep(config.tick_len * s.update_interval); + + /* Start to verify group */ + if (!verify_group(&s, step)) { + H5_FAILED(); AT(); + printf("verify_group failed\n"); + + /* At communication interval, tell the writer about the failure and exit */ + if (step % s.csteps == 0) { + notify = -1; + HDwrite(fd_reader_to_writer, ¬ify, sizeof(int)); + goto error; + } + } else { + if (step % s.csteps == 0) { + /* Send back the same nofity value for acknowledgement to tell the writer + * move to the next step */ + if (HDwrite(fd_reader_to_writer, ¬ify, sizeof(int)) < 0) { + H5_FAILED(); AT(); + printf("HDwrite failed\n"); + goto error; + } + } + } } } - if (s.use_vfd_swmr && s.wait_for_signal) - await_signal(s.file); + if (H5Pclose(fapl) < 0) { + H5_FAILED(); AT(); + printf("H5Pclose failed\n"); + goto error; + } - restore_signals(&oldsigs); + if (H5Pclose(fcpl) < 0) { + H5_FAILED(); AT(); + printf("H5Pclose failed\n"); + goto error; + } - if (H5Pclose(fapl) < 0) - errx(EXIT_FAILURE, "H5Pclose(fapl)"); + if (H5Fclose(s.file) < 0) { + H5_FAILED(); AT(); + printf("H5Fclose failed\n"); + goto error; + } - if (H5Pclose(fcpl) < 0) - errx(EXIT_FAILURE, "H5Pclose(fcpl)"); + /* Both the writer and reader close the named pipes */ + if (HDclose(fd_writer_to_reader) < 0) { + H5_FAILED(); AT(); + printf("HDclose failed\n"); + goto error; + } - if (H5Fclose(s.file) < 0) - errx(EXIT_FAILURE, "H5Fclose"); + 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("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: + H5E_BEGIN_TRY { + H5Pclose(fapl); + H5Pclose(fcpl); + H5Fclose(s.file); + } H5E_END_TRY; + + if (fd_writer_to_reader >= 0) + HDclose(fd_writer_to_reader); + + if (fd_writer_to_reader >= 0) + HDclose(fd_reader_to_writer); + + if(!writer) { + HDremove(fifo_writer_to_reader); + HDremove(fifo_reader_to_writer); + } + + return EXIT_FAILURE; } |