From 51b8fa3ffefc17309ec45b36fa155486f9fbfec2 Mon Sep 17 00:00:00 2001 From: David Young Date: Fri, 20 Mar 2020 15:20:51 -0500 Subject: Take a stab at a "zoo" writer for VFD SWMR: write all of the same objects as the cache_image test does. The zoo writer is a work in progress. This version is useful as a reproducer for the hang in the global heap that I stumbled over, yesterday. I run this to reproduce, env HLOG="pbio=on" ./vfd_swmr_zoo_writer -W -a --- test/Makefile.am | 7 +- test/vfd_swmr_zoo_writer.c | 188 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 193 insertions(+), 2 deletions(-) create mode 100644 test/vfd_swmr_zoo_writer.c diff --git a/test/Makefile.am b/test/Makefile.am index 953816c..85350fb 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -47,7 +47,7 @@ SCRIPT_DEPEND = error_test$(EXEEXT) err_compat$(EXEEXT) links_env$(EXEEXT) \ vfd_swmr_remove_reader$(EXEEXT) vfd_swmr_remove_writer$(EXEEXT) \ vfd_swmr_addrem_writer$(EXEEXT) vfd_swmr_sparse_reader$(EXEEXT) \ vfd_swmr_sparse_writer$(EXEEXT) vfd_swmr_vlstr_writer$(EXEEXT) \ - vfd_swmr_vlstr_reader$(EXEEXT) \ + vfd_swmr_vlstr_reader$(EXEEXT) vfd_swmr_zoo_writer$(EXEEXT) \ vds_env$(EXEEXT) \ vds_swmr_gen$(EXEEXT) vds_swmr_reader$(EXEEXT) vds_swmr_writer$(EXEEXT) if HAVE_SHARED_CONDITIONAL @@ -97,7 +97,7 @@ check_PROGRAMS=$(TEST_PROG) error_test err_compat tcheck_version \ vfd_swmr_generator vfd_swmr_reader vfd_swmr_writer \ vfd_swmr_remove_reader vfd_swmr_remove_writer vfd_swmr_addrem_writer \ vfd_swmr_sparse_reader vfd_swmr_sparse_writer \ - vfd_swmr_vlstr_reader vfd_swmr_vlstr_writer \ + vfd_swmr_vlstr_reader vfd_swmr_vlstr_writer vfd_swmr_zoo_writer \ swmr_check_compat_vfd vds_env vds_swmr_gen vds_swmr_reader vds_swmr_writer if HAVE_SHARED_CONDITIONAL check_PROGRAMS+= filter_plugin vol_plugin @@ -156,6 +156,9 @@ ttsafe_SOURCES=ttsafe.c ttsafe_dcreate.c ttsafe_error.c ttsafe_cancel.c \ ttsafe_acreate.c cache_image_SOURCES=cache_image.c genall5.c + +vfd_swmr_zoo_writer_SOURCES=vfd_swmr_zoo_writer.c genall5.c + VFD_LIST = sec2 stdio core core_paged split multi family if DIRECT_VFD_CONDITIONAL VFD_LIST += direct diff --git a/test/vfd_swmr_zoo_writer.c b/test/vfd_swmr_zoo_writer.c new file mode 100644 index 0000000..ad2288f --- /dev/null +++ b/test/vfd_swmr_zoo_writer.c @@ -0,0 +1,188 @@ +/* + * Copyright by The HDF Group. + * Copyright by the Board of Trustees of the University of Illinois. + * All rights reserved. + * + * This file is part of HDF5. The full HDF5 copyright notice, including + * terms governing use, modification, and redistribution, is contained in + * the COPYING file, which can be found at the root of the source code + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. + * If you do not have access to either file, you may request a copy from + * help@hdfgroup.org. + */ + +#include +#include /* nanosleep(2) */ +#include /* getopt(3) */ + +#define H5C_FRIEND /*suppress error about including H5Cpkg */ +#define H5F_FRIEND /*suppress error about including H5Fpkg */ + +#include "hdf5.h" + +#include "H5Cpkg.h" +#include "H5Fpkg.h" +// #include "H5Iprivate.h" +#include "H5HGprivate.h" +#include "H5VLprivate.h" + +#include "testhdf5.h" +#include "genall5.h" +#include "vfd_swmr_common.h" + +enum _step { + CREATE = 0 +, LENGTHEN +, SHORTEN +, DELETE +, NSTEPS +} step_t; + +static const hid_t badhid = H5I_INVALID_HID; // abbreviate +static bool caught_out_of_bounds = false; + +static void +print_cache_hits(H5C_t *cache) +{ + int i; + + for (i = 0; i < H5AC_NTYPES; i++) { + dbgf(3, "type-%d cache hits %" PRId64 "%s\n", + i, cache->hits[i], (i == H5AC_GHEAP_ID) ? " *" : ""); + } + dbgf(3, "\n"); +} + +static void +usage(const char *progname) +{ + fprintf(stderr, "usage: %s [-W] [-V]\n", progname); + fprintf(stderr, "\n -W: do not wait for SIGINT or SIGUSR1\n"); + fprintf(stderr, "\n -S: do not use VFD SWMR\n"); + fprintf(stderr, " -a: run all tests, including variable-length data\n"); + fprintf(stderr, " -n: number of test steps to perform\n"); + fprintf(stderr, " -q: be quiet: few/no progress messages\n"); + fprintf(stderr, " -t (oob|null): select out-of-bounds or NULL test\n"); + exit(EXIT_FAILURE); +} + +bool +H5HG_trap(const char *reason) +{ + if (strcmp(reason, "out of bounds") == 0) { + caught_out_of_bounds = true; + return false; + } + return true; +} + +int +main(int argc, char **argv) +{ + hid_t fapl, fcpl, fid; + H5F_t *f; + H5C_t *cache; + sigset_t oldsigs; + herr_t ret; + bool skip_varlen = true, wait_for_signal = true; + int ch; + bool use_vfd_swmr = true; +#if 0 + unsigned long tmp; + char *end; + int i, ntimes = 100; + const struct timespec delay = + {.tv_sec = 0, .tv_nsec = 1000 * 1000 * 1000 / 10}; +#endif + testsel_t sel = TEST_NONE; + + while ((ch = getopt(argc, argv, "SWan:qt:")) != -1) { + switch(ch) { + case 'S': + use_vfd_swmr = false; + break; + case 'W': + wait_for_signal = false; + break; +#if 0 + case 'n': + errno = 0; + tmp = strtoul(optarg, &end, 0); + if (end == optarg || *end != '\0') + errx(EXIT_FAILURE, "couldn't parse `-n` argument `%s`", optarg); + else if (errno != 0) + err(EXIT_FAILURE, "couldn't parse `-n` argument `%s`", optarg); + else if (tmp > INT_MAX) + errx(EXIT_FAILURE, "`-n` argument `%lu` too large", tmp); + ntimes = (int)tmp; + break; +#endif + case 'q': + verbosity = 1; + break; + case 't': + if (strcmp(optarg, "oob") == 0) + sel = TEST_OOB; + else if (strcmp(optarg, "null") == 0) + sel = TEST_NULL; + else + usage(argv[0]); + break; + case 'a': + skip_varlen = false; + break; + default: + usage(argv[0]); + break; + } + } + argv += optind; + argc -= optind; + + if (argc > 0) + errx(EXIT_FAILURE, "unexpected command-line arguments"); + + if ((fapl = vfd_swmr_create_fapl(true, sel == TEST_OOB, use_vfd_swmr)) < 0) + errx(EXIT_FAILURE, "vfd_swmr_create_fapl"); + + if ((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0) + errx(EXIT_FAILURE, "H5Pcreate"); + + ret = H5Pset_file_space_strategy(fcpl, H5F_FSPACE_STRATEGY_PAGE, false, 1); + if (ret < 0) + errx(EXIT_FAILURE, "H5Pset_file_space_strategy"); + + fid = H5Fcreate("vfd_swmr_vlstr.h5", H5F_ACC_TRUNC, fcpl, fapl); + + if ((f = H5VL_object_verify(fid, H5I_FILE)) == NULL) + errx(EXIT_FAILURE, "H5VL_object_verify"); + + cache = f->shared->cache; + + if (fid == badhid) + errx(EXIT_FAILURE, "H5Fcreate"); + + if (wait_for_signal) + block_signals(&oldsigs); + + print_cache_hits(cache); + + create_zoo(fid, ".", 0, skip_varlen); + + if (use_vfd_swmr && wait_for_signal) + await_signal(fid); + + if (wait_for_signal) + restore_signals(&oldsigs); + + if (H5Pclose(fapl) < 0) + errx(EXIT_FAILURE, "H5Pclose(fapl)"); + + if (H5Pclose(fcpl) < 0) + errx(EXIT_FAILURE, "H5Pclose(fcpl)"); + + if (H5Fclose(fid) < 0) + errx(EXIT_FAILURE, "H5Fclose"); + + return EXIT_SUCCESS; +} -- cgit v0.12