diff options
author | Songyu Lu <songyulu@hdfgroup.org> | 2021-03-25 22:42:01 (GMT) |
---|---|---|
committer | Songyu Lu <songyulu@hdfgroup.org> | 2021-03-25 22:42:01 (GMT) |
commit | 998aca32e6336bed6286885a03498c78dadfe511 (patch) | |
tree | b7ebeb1e37bae109c67a7733b94aafaf9e27dd07 /test/vfd_swmr_common.c | |
parent | 9835edcdad2cfb567c7d8af98e8dbbaa4e712eca (diff) | |
parent | c81afbff45edb56b16d17d37c444485b587d51fd (diff) | |
download | hdf5-998aca32e6336bed6286885a03498c78dadfe511.zip hdf5-998aca32e6336bed6286885a03498c78dadfe511.tar.gz hdf5-998aca32e6336bed6286885a03498c78dadfe511.tar.bz2 |
Merge branch 'feature/vfd_swmr' of https://github.com/HDFGroup/hdf5 into raylu_zoo_test
Diffstat (limited to 'test/vfd_swmr_common.c')
-rw-r--r-- | test/vfd_swmr_common.c | 200 |
1 files changed, 106 insertions, 94 deletions
diff --git a/test/vfd_swmr_common.c b/test/vfd_swmr_common.c index 65671fc..0a5025d 100644 --- a/test/vfd_swmr_common.c +++ b/test/vfd_swmr_common.c @@ -1,12 +1,11 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 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. * + * distribution tree, or in https://www.hdfgroup.org/licenses. * * If you do not have access to either file, you may request a copy from * * help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ @@ -19,18 +18,16 @@ /* Headers */ /***********/ -#include <err.h> /* for err(3) */ - -/* Only need the pthread solution if sigtimedwai(2) isn't available */ -#ifndef H5_HAVE_SIGTIMEDWAIT -#include <pthread.h> -#endif - #include "h5test.h" #include "vfd_swmr_common.h" #include "swmr_common.h" -static const hid_t badhid = H5I_INVALID_HID; +/* Only need the pthread solution if sigtimedwait(2) isn't available. + * There's currently no Windows solution, so ignore that for now. + */ +#if !defined(H5_HAVE_SIGTIMEDWAIT) && !defined(H5_HAVE_WIN32_API) +#include <pthread.h> +#endif int verbosity = 2; @@ -43,17 +40,24 @@ int verbosity = 2; * greater than the duration `ival`, then record the current time at * `last` and return true. Otherwise, return false. */ -bool +hbool_t below_speed_limit(struct timespec *last, const struct timespec *ival) { struct timespec now; - bool result; + hbool_t result; - assert(0 <= last->tv_nsec && last->tv_nsec < 1000000000L); - assert(0 <= ival->tv_nsec && ival->tv_nsec < 1000000000L); + HDassert(0 <= last->tv_nsec && last->tv_nsec < 1000000000L); + HDassert(0 <= ival->tv_nsec && ival->tv_nsec < 1000000000L); - if (clock_gettime(CLOCK_MONOTONIC, &now) == -1) - err(EXIT_FAILURE, "%s: clock_gettime", __func__); + /* NOTE: timespec_get() is C11. This may need further tweaks. */ +#ifdef H5_HAVE_WIN32_API + if (timespec_get(&now, TIME_UTC) != TIME_UTC) { +#else + if (HDclock_gettime(CLOCK_MONOTONIC, &now) == -1) { +#endif + HDfprintf(stderr, "%s: clock_gettime", __func__); + HDexit(EXIT_FAILURE); + } if (now.tv_sec - last->tv_sec > ival->tv_sec) result = true; @@ -91,12 +95,16 @@ evsnprintf(char *buf, size_t bufsz, const char *fmt, va_list ap) { int rc; - rc = vsnprintf(buf, bufsz, fmt, ap); + rc = HDvsnprintf(buf, bufsz, fmt, ap); - if (rc < 0) - err(EXIT_FAILURE, "%s: vsnprintf", __func__); - else if ((size_t)rc >= bufsz) - errx(EXIT_FAILURE, "%s: buffer too small", __func__); + if (rc < 0) { + HDfprintf(stderr, "%s: HDvsnprintf", __func__); + HDexit(EXIT_FAILURE); + } + else if ((size_t)rc >= bufsz) { + HDfprintf(stderr, "%s: buffer too small", __func__); + HDexit(EXIT_FAILURE); + } } /* Like snprintf(3), but abort the program with an error message on @@ -107,9 +115,9 @@ esnprintf(char *buf, size_t bufsz, const char *fmt, ...) { va_list ap; - va_start(ap, fmt); + HDva_start(ap, fmt); evsnprintf(buf, bufsz, fmt, ap); - va_end(ap); + HDva_end(ap); } void @@ -120,9 +128,9 @@ dbgf(int level, const char *fmt, ...) if (verbosity < level) return; - va_start(ap, fmt); - (void)vfprintf(stderr, fmt, ap); - va_end(ap); + HDva_start(ap, fmt); + (void)HDvfprintf(stderr, fmt, ap); + HDva_end(ap); } /* Disable HDF5 error-stack printing and return the previous state @@ -158,6 +166,7 @@ restore_estack(estack_state_t es) (void)H5Eset_auto(H5E_DEFAULT, es.efunc, es.edata); } +#ifndef H5_HAVE_WIN32_API /* Store the signal mask at `oldset` and then block all signals. */ void block_signals(sigset_t *oldset) @@ -165,20 +174,24 @@ block_signals(sigset_t *oldset) sigset_t fullset; if (sigfillset(&fullset) == -1) { - err(EXIT_FAILURE, "%s.%d: could not initialize signal masks", - __func__, __LINE__); + HDfprintf(stderr, "%s.%d: could not initialize signal masks", __func__, __LINE__); + HDexit(EXIT_FAILURE); } - if (sigprocmask(SIG_BLOCK, &fullset, oldset) == -1) - err(EXIT_FAILURE, "%s.%d: sigprocmask", __func__, __LINE__); + if (sigprocmask(SIG_BLOCK, &fullset, oldset) == -1) { + HDfprintf(stderr, "%s.%d: sigprocmask", __func__, __LINE__); + HDexit(EXIT_FAILURE); + } } /* Restore the signal mask in `oldset`. */ void restore_signals(sigset_t *oldset) { - if (sigprocmask(SIG_SETMASK, oldset, NULL) == -1) - err(EXIT_FAILURE, "%s.%d: sigprocmask", __func__, __LINE__); + if (sigprocmask(SIG_SETMASK, oldset, NULL) == -1) { + HDfprintf(stderr, "%s.%d: sigprocmask", __func__, __LINE__); + HDexit(EXIT_FAILURE); + } } #if 0 @@ -202,18 +215,18 @@ strsignal(int signum) typedef struct timer_params_t { struct timespec *tick; - hid_t fid; + hid_t fid; } timer_params_t; pthread_mutex_t timer_mutex; -hbool_t timer_stop = FALSE; +hbool_t timer_stop = FALSE; static void * timer_function(void *arg) { timer_params_t *params = (timer_params_t *)arg; - sigset_t sleepset; - hbool_t done = FALSE; + sigset_t sleepset; + hbool_t done = FALSE; /* Ignore any signals */ sigfillset(&sleepset); @@ -256,18 +269,20 @@ void await_signal(hid_t fid) { struct timespec tick = {.tv_sec = 0, .tv_nsec = 1000000000 / 100}; - sigset_t sleepset; + sigset_t sleepset; if (sigfillset(&sleepset) == -1) { - err(EXIT_FAILURE, "%s.%d: could not initialize signal mask", - __func__, __LINE__); + HDfprintf(stderr, "%s.%d: could not initialize signal mask", __func__, __LINE__); + HDexit(EXIT_FAILURE); } /* 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__); + if (H5Fflush(fid, H5F_SCOPE_GLOBAL) < 0) { + HDfprintf(stderr, "%s: H5Fflush failed", __func__); + HDexit(EXIT_FAILURE); + } dbgf(1, "waiting for signal\n"); @@ -277,11 +292,11 @@ await_signal(hid_t fid) * sigtimedwait(2) */ timer_params_t params; - int rc; - pthread_t timer; + int rc; + pthread_t timer; params.tick = &tick; - params.fid = fid; + params.fid = fid; pthread_mutex_init(&timer_mutex, NULL); @@ -290,14 +305,16 @@ await_signal(hid_t fid) rc = sigwait(&sleepset, NULL); if (rc != -1) { - fprintf(stderr, "Received signal, wrapping things up.\n"); + HDfprintf(stderr, "Received signal, wrapping things up.\n"); pthread_mutex_lock(&timer_mutex); timer_stop = TRUE; pthread_mutex_unlock(&timer_mutex); pthread_join(timer, NULL); } - else - err(EXIT_FAILURE, "%s: sigtimedwait", __func__); + else { + HDfprintf(stderr, "%s: sigwait", __func__); + HDexit(EXIT_FAILURE); + } } #else for (;;) { @@ -305,10 +322,10 @@ await_signal(hid_t fid) const int rc = sigtimedwait(&sleepset, NULL, &tick); if (rc != -1) { - fprintf(stderr, "Received %s, wrapping things up.\n", - strsignal(rc)); + HDfprintf(stderr, "Received %s, wrapping things up.\n", strsignal(rc)); break; - } else if (rc == -1 && errno == EAGAIN) { + } + else if (rc == -1 && errno == EAGAIN) { estack_state_t es; /* Avoid deadlock with peer: periodically enter the API so that @@ -319,39 +336,42 @@ await_signal(hid_t fid) * so squelch errors. */ es = disable_estack(); - (void)H5Aexists_by_name(fid, "nonexistent", "nonexistent", - H5P_DEFAULT); + (void)H5Aexists_by_name(fid, "nonexistent", "nonexistent", H5P_DEFAULT); restore_estack(es); - } else if (rc == -1) - err(EXIT_FAILURE, "%s: sigtimedwait", __func__); + } + else if (rc == -1) { + HDfprintf(stderr, "%s: sigtimedwait", __func__); + HDexit(EXIT_FAILURE); + } } #endif /* H5_HAVE_SIGTIMEDWAIT */ } +#endif /* H5_HAVE_WIN32_API */ + /* Revised support routines that can be used for all VFD SWMR integration tests */ /* Initialize fields in config with the input parameters */ void init_vfd_swmr_config(H5F_vfd_swmr_config_t *config, uint32_t tick_len, uint32_t max_lag, hbool_t writer, - hbool_t flush_raw_data, uint32_t md_pages_reserved, const char *md_file_fmtstr, ...) + hbool_t flush_raw_data, uint32_t md_pages_reserved, const char *md_file_fmtstr, ...) { va_list ap; - - memset(config, 0, sizeof(H5F_vfd_swmr_config_t)); - config->version = H5F__CURR_VFD_SWMR_CONFIG_VERSION; - config->pb_expansion_threshold = 0; + HDmemset(config, 0, sizeof(H5F_vfd_swmr_config_t)); - config->tick_len = tick_len; - config->max_lag = max_lag; - config->writer = writer; - config->flush_raw_data = flush_raw_data; + config->version = H5F__CURR_VFD_SWMR_CONFIG_VERSION; + config->pb_expansion_threshold = 0; + + config->tick_len = tick_len; + config->max_lag = max_lag; + config->writer = writer; + config->flush_raw_data = flush_raw_data; config->md_pages_reserved = md_pages_reserved; - va_start(ap, md_file_fmtstr); - evsnprintf(config->md_file_path, sizeof(config->md_file_path), - md_file_fmtstr, ap); - va_end(ap); + HDva_start(ap, md_file_fmtstr); + evsnprintf(config->md_file_path, sizeof(config->md_file_path), md_file_fmtstr, ap); + HDva_end(ap); } /* init_vfd_swmr_config() */ @@ -364,43 +384,35 @@ init_vfd_swmr_config(H5F_vfd_swmr_config_t *config, uint32_t tick_len, uint32_t * --configure for VFD SWMR or not */ hid_t -vfd_swmr_create_fapl(bool use_latest_format, bool use_vfd_swmr, bool only_meta_pages, H5F_vfd_swmr_config_t *config) +vfd_swmr_create_fapl(bool use_latest_format, bool use_vfd_swmr, bool only_meta_pages, + H5F_vfd_swmr_config_t *config) { - hid_t fapl; + hid_t fapl = H5I_INVALID_HID; /* Create file access property list */ - if((fapl = h5_fileaccess()) < 0) { - warnx("h5_fileaccess"); - return badhid; - } + if ((fapl = h5_fileaccess()) < 0) + return H5I_INVALID_HID; - if(use_latest_format) { - if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) { - warnx("H5Pset_libver_bounds"); - return badhid; - } + if (use_latest_format) { + if (H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) + return H5I_INVALID_HID; } /* Enable page buffering */ - if(H5Pset_page_buffer_size(fapl, 4096, only_meta_pages ? 100 : 0, 0) < 0) { - warnx("H5Pset_page_buffer_size"); - return badhid; - } + if (H5Pset_page_buffer_size(fapl, 4096, only_meta_pages ? 100 : 0, 0) < 0) + return H5I_INVALID_HID; /* * Set up to open the file with VFD SWMR configured. */ /* Enable VFD SWMR configuration */ - if(use_vfd_swmr && H5Pset_vfd_swmr_config(fapl, config) < 0) { - warnx("H5Pset_vfd_swmr_config"); - return badhid; - } + if (use_vfd_swmr && H5Pset_vfd_swmr_config(fapl, config) < 0) + return H5I_INVALID_HID; return fapl; } /* vfd_swmr_create_fapl() */ - /* Fetch a variable from the environment and parse it for unsigned long * content. Return 0 if the variable is not present, -1 if it is present * but it does not parse and compare less than `limit`, 1 if it's present, @@ -409,25 +421,25 @@ vfd_swmr_create_fapl(bool use_latest_format, bool use_vfd_swmr, bool only_meta_p int fetch_env_ulong(const char *varname, unsigned long limit, unsigned long *valp) { - char *end; + char * end; unsigned long ul; - char *tmp; + char * tmp; - if ((tmp = getenv(varname)) == NULL) + if ((tmp = HDgetenv(varname)) == NULL) return 0; errno = 0; - ul = strtoul(tmp, &end, 0); + ul = HDstrtoul(tmp, &end, 0); if (ul == ULONG_MAX && errno != 0) { - fprintf(stderr, "could not parse %s: %s\n", varname, strerror(errno)); + HDfprintf(stderr, "could not parse %s: %s\n", varname, HDstrerror(errno)); return -1; } if (end == tmp || *end != '\0') { - fprintf(stderr, "could not parse %s\n", varname); + HDfprintf(stderr, "could not parse %s\n", varname); return -1; } if (ul > limit) { - fprintf(stderr, "%s (%lu) out of range\n", varname, ul); + HDfprintf(stderr, "%s (%lu) out of range\n", varname, ul); return -1; } *valp = ul; |