diff options
author | Dana Robinson <43805+derobins@users.noreply.github.com> | 2022-07-05 23:55:18 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-05 23:55:18 (GMT) |
commit | 5ceaf920eccbf5176065b0deeb27b124b821db76 (patch) | |
tree | 2bca04a4fd6fd27065c3e33335092970ef30b940 /test/vfd_swmr_vlstr_writer.c | |
parent | ac7bddf2af317d4bc34854f5565396da51ff12aa (diff) | |
download | hdf5-feature/vfd_swmr.zip hdf5-feature/vfd_swmr.tar.gz hdf5-feature/vfd_swmr.tar.bz2 |
VFD SWMR: Warning fixes and minor cleanup (#1847)feature/vfd_swmr
* Normalization with develop
* Moves remaining datatype code changes over from develop
* Cleanup in examples files
* Warning cleanup in VFD SWMR code
* Committing clang-format changes
* Warning cleanup
* Warning reduction
* More warning fixes
* Committing clang-format changes
* Even more warning reduction in the VFD SWMR tests
* More warning fixes in the VFD SWMR tests
* Even more VFD SWMR test warning fixes
* Last warning fixes in VFD SWMR
* Committing clang-format changes
* Minor things missed from develop
* Warning fixes from GitHub build failures
* Committing clang-format changes
* Fix for warning due to weird bit shift type promotion
* Yet another attempt at fixing the integral promotion warning
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Diffstat (limited to 'test/vfd_swmr_vlstr_writer.c')
-rw-r--r-- | test/vfd_swmr_vlstr_writer.c | 146 |
1 files changed, 88 insertions, 58 deletions
diff --git a/test/vfd_swmr_vlstr_writer.c b/test/vfd_swmr_vlstr_writer.c index 6a747a2..9fabc23 100644 --- a/test/vfd_swmr_vlstr_writer.c +++ b/test/vfd_swmr_vlstr_writer.c @@ -24,32 +24,35 @@ #ifndef H5_HAVE_WIN32_API -#include <err.h> - enum _step { CREATE = 0, LENGTHEN, SHORTEN, DELETE, NSTEPS } step_t; static hbool_t caught_out_of_bounds = FALSE; -static void +static herr_t write_vl_dset(hid_t dset, hid_t type, hid_t space, char *data) { if (H5Dwrite(dset, type, space, space, H5P_DEFAULT, &data) < 0) - errx(EXIT_FAILURE, "%s: H5Dwrite", __func__); + STACK_ERROR; if (H5Dflush(dset) < 0) - errx(EXIT_FAILURE, "%s: H5Dflush", __func__); + STACK_ERROR; + + return SUCCEED; +error: + return FAIL; } static hid_t create_vl_dset(hid_t file, hid_t type, hid_t space, const char *name) { - hid_t dset; + hid_t dset = H5I_INVALID_HID; - dset = H5Dcreate2(file, name, type, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); - - if (dset == H5I_INVALID_HID) - errx(EXIT_FAILURE, "H5Dcreate2"); + if ((dset = H5Dcreate2(file, name, type, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + STACK_ERROR; return dset; + +error: + return H5I_INVALID_HID; } static void @@ -87,8 +90,12 @@ usage(const char *progname) int main(int argc, char **argv) { - hid_t fapl, fcpl, fid, space, type; - hid_t dset[2]; + hid_t fapl = H5I_INVALID_HID; + hid_t fcpl = H5I_INVALID_HID; + hid_t fid = H5I_INVALID_HID; + hid_t space = H5I_INVALID_HID; + hid_t type = H5I_INVALID_HID; + hid_t dset[2] = {H5I_INVALID_HID, H5I_INVALID_HID}; char content[2][96]; char name[2][96]; H5F_t * f; @@ -102,12 +109,15 @@ main(int argc, char **argv) hbool_t use_vfd_swmr = TRUE; const uint64_t delay_ns = 100 * 1000 * 1000; /* 100 ms */ testsel_t sel = TEST_NONE; - H5F_vfd_swmr_config_t config; - const char * s_opts = "SWfn:qt:"; - struct h5_long_options l_opts[] = {{NULL, 0, '\0'}}; + H5F_vfd_swmr_config_t *config = NULL; + const char * s_opts = "SWfn:qt:"; + struct h5_long_options l_opts[] = {{NULL, 0, '\0'}}; HDassert(H5T_C_S1 != H5I_INVALID_HID); + if (NULL == (config = HDcalloc(1, sizeof(H5F_vfd_swmr_config_t)))) + PUTS_ERROR("unable to allocate memory"); + while ((opt = H5_get_option(argc, (const char *const *)argv, s_opts, l_opts)) != EOF) { switch (opt) { case 'S': @@ -122,12 +132,21 @@ main(int argc, char **argv) case 'n': errno = 0; tmp = HDstrtoul(H5_optarg, &end, 0); - if (end == H5_optarg || *end != '\0') - errx(EXIT_FAILURE, "couldn't parse `-n` argument `%s`", H5_optarg); - else if (errno != 0) - err(EXIT_FAILURE, "couldn't parse `-n` argument `%s`", H5_optarg); - else if (tmp > INT_MAX) - errx(EXIT_FAILURE, "`-n` argument `%lu` too large", tmp); + if (end == H5_optarg || *end != '\0') { + HDfprintf(stderr, "couldn't parse `-n` argument `%s`", H5_optarg); + AT(); + goto error; + } + else if (errno != 0) { + HDfprintf(stderr, "couldn't parse `-n` argument `%s`", H5_optarg); + AT(); + goto error; + } + else if (tmp > INT_MAX) { + HDfprintf(stderr, "`-n` argument `%lu` too large", tmp); + AT(); + goto error; + } ntimes = (int)tmp; break; case 'q': @@ -150,53 +169,48 @@ main(int argc, char **argv) argc -= H5_optind; if (argc > 0) - errx(EXIT_FAILURE, "unexpected command-line arguments"); + PUTS_ERROR("unexpected command-line arguments"); /* config, tick_len, max_lag, presume_posix_semantics, writer, * maintain_metadata_file, generate_updater_files, flush_raw_data, md_pages_reserved, * md_file_path, md_file_name, updater_file_path */ - init_vfd_swmr_config(&config, 4, 7, FALSE, true, TRUE, FALSE, TRUE, 128, "./", "vlstr-shadow", NULL); + init_vfd_swmr_config(config, 4, 7, FALSE, true, TRUE, FALSE, TRUE, 128, "./", "vlstr-shadow", NULL); /* use_latest_format, use_vfd_swmr, only_meta_page, page_buf_size, config */ - fapl = vfd_swmr_create_fapl(TRUE, use_vfd_swmr, sel == TEST_OOB, 4096, &config); - - if (fapl < 0) - errx(EXIT_FAILURE, "vfd_swmr_create_fapl"); + if ((fapl = vfd_swmr_create_fapl(TRUE, use_vfd_swmr, sel == TEST_OOB, 4096, config)) < 0) + STACK_ERROR; /* Set fs_strategy (file space strategy) and fs_page_size (file space page size) */ if ((fcpl = vfd_swmr_create_fcpl(H5F_FSPACE_STRATEGY_PAGE, 4096)) < 0) - errx(EXIT_FAILURE, "vfd_swmr_create_fcpl"); + STACK_ERROR; - fid = H5Fcreate("vfd_swmr_vlstr.h5", H5F_ACC_TRUNC, fcpl, fapl); + if ((fid = H5Fcreate("vfd_swmr_vlstr.h5", H5F_ACC_TRUNC, fcpl, fapl)) < 0) + STACK_ERROR; /* Create the VL string datatype and a scalar dataspace, or a * fixed-length string datatype and a simple dataspace. */ if ((type = H5Tcopy(H5T_C_S1)) == H5I_INVALID_HID) - errx(EXIT_FAILURE, "H5Tcopy"); + STACK_ERROR; if (!variable) { if (H5Tset_size(type, 32) < 0) - errx(EXIT_FAILURE, "H5Tset_size"); - space = H5Screate_simple(1, &dims, NULL); + STACK_ERROR; + if ((space = H5Screate_simple(1, &dims, NULL)) < 0) + STACK_ERROR; } else { if (H5Tset_size(type, H5T_VARIABLE) < 0) - errx(EXIT_FAILURE, "H5Tset_size"); - space = H5Screate(H5S_SCALAR); + STACK_ERROR; + if ((space = H5Screate(H5S_SCALAR)) < 0) + STACK_ERROR; } - if (space == H5I_INVALID_HID) - errx(EXIT_FAILURE, "H5Screate"); - if ((f = H5VL_object_verify(fid, H5I_FILE)) == NULL) - errx(EXIT_FAILURE, "H5VL_object_verify"); + STACK_ERROR; cache = f->shared->cache; - if (fid == H5I_INVALID_HID) - errx(EXIT_FAILURE, "H5Fcreate"); - block_signals(&oldsigs); print_cache_hits(cache); @@ -217,27 +231,29 @@ main(int argc, char **argv) (void)HDsnprintf(content[which], sizeof(content[which]), "content %d seq %d short", which, seq); dset[which] = create_vl_dset(fid, type, space, name[which]); - write_vl_dset(dset[which], type, space, content[which]); + if (write_vl_dset(dset[which], type, space, content[which]) < 0) + PUTS_ERROR("failed to write to VL dataset"); break; case LENGTHEN: (void)HDsnprintf(content[which], sizeof(content[which]), "content %d seq %d long long long long long long long long", which, seq); - write_vl_dset(dset[which], type, space, content[which]); + if (write_vl_dset(dset[which], type, space, content[which]) < 0) + PUTS_ERROR("failed to write to VL dataset"); break; case SHORTEN: (void)HDsnprintf(content[which], sizeof(content[which]), "content %d seq %d medium medium medium", which, seq); - write_vl_dset(dset[which], type, space, content[which]); + if (write_vl_dset(dset[which], type, space, content[which]) < 0) + PUTS_ERROR("failed to write to VL dataset"); break; case DELETE: if (H5Dclose(dset[which]) < 0) - errx(EXIT_FAILURE, "H5Dclose"); - if (H5Ldelete(fid, name[which], H5P_DEFAULT) < 0) { - errx(EXIT_FAILURE, "%s: H5Ldelete(, \"%s\", ) failed", __func__, name[which]); - } + STACK_ERROR; + if (H5Ldelete(fid, name[which], H5P_DEFAULT) < 0) + STACK_ERROR; break; default: - errx(EXIT_FAILURE, "%s: unknown step %d", __func__, step); + PUTS_ERROR("Unknown operation"); } if (caught_out_of_bounds) { @@ -254,21 +270,35 @@ main(int argc, char **argv) restore_signals(&oldsigs); if (H5Pclose(fapl) < 0) - errx(EXIT_FAILURE, "H5Pclose(fapl)"); - + STACK_ERROR; if (H5Pclose(fcpl) < 0) - errx(EXIT_FAILURE, "H5Pclose(fcpl)"); - + STACK_ERROR; if (H5Tclose(type) < 0) - errx(EXIT_FAILURE, "H5Tclose"); - + STACK_ERROR; if (H5Sclose(space) < 0) - errx(EXIT_FAILURE, "H5Sclose"); - + STACK_ERROR; if (H5Fclose(fid) < 0) - errx(EXIT_FAILURE, "H5Fclose"); + STACK_ERROR; + + HDfree(config); return EXIT_SUCCESS; + +error: + + H5E_BEGIN_TRY + { + H5Pclose(fapl); + H5Pclose(fcpl); + H5Tclose(type); + H5Sclose(space); + H5Fclose(fid); + } + H5E_END_TRY; + + HDfree(config); + + return EXIT_FAILURE; } #else /* H5_HAVE_WIN32_API */ |