From a4cf8aea727e869ffc91b89d4bfd602336a37434 Mon Sep 17 00:00:00 2001 From: vchoi Date: Tue, 4 May 2021 18:02:36 -0500 Subject: Add new test vfd_swmr_dsetops_writer.c to test writing operations for: Dataset types: --dataset with compact layout --dataset with contiguous layout --datasets with chunked layout: single/implicit/fixed array/extensible array/btree2 indexes Types of writes: --Sequential writes --Random writes --Regular hyperslab writes --Raw data modifications --- test/Makefile.am | 3 + test/testvfdswmr.sh.in | 69 +- test/vfd_swmr_dsetops_writer.c | 1760 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1825 insertions(+), 7 deletions(-) create mode 100644 test/vfd_swmr_dsetops_writer.c diff --git a/test/Makefile.am b/test/Makefile.am index d6e030b..a6dfaf1 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -50,6 +50,7 @@ SCRIPT_DEPEND = error_test$(EXEEXT) err_compat$(EXEEXT) links_env$(EXEEXT) \ vfd_swmr_addrem_writer$(EXEEXT) vfd_swmr_sparse_reader$(EXEEXT) \ vfd_swmr_sparse_writer$(EXEEXT) \ vfd_swmr_bigset_reader$(EXEEXT) vfd_swmr_bigset_writer$(EXEEXT) \ + vfd_swmr_dsetops_reader$(EXEEXT) vfd_swmr_dsetops_writer$(EXEEXT) \ vfd_swmr_group_reader$(EXEEXT) vfd_swmr_group_writer$(EXEEXT) \ vfd_swmr_vlstr_reader$(EXEEXT) vfd_swmr_vlstr_writer$(EXEEXT) \ vfd_swmr_zoo_reader$(EXEEXT) vfd_swmr_zoo_writer$(EXEEXT) \ @@ -104,6 +105,7 @@ check_PROGRAMS=$(TEST_PROG) error_test err_compat tcheck_version \ vfd_swmr_remove_reader vfd_swmr_remove_writer vfd_swmr_addrem_writer \ vfd_swmr_sparse_reader vfd_swmr_sparse_writer \ vfd_swmr_bigset_reader vfd_swmr_bigset_writer \ + vfd_swmr_dsetops_reader vfd_swmr_dsetops_writer \ vfd_swmr_group_reader vfd_swmr_group_writer \ vfd_swmr_vlstr_reader vfd_swmr_vlstr_writer \ vfd_swmr_zoo_reader vfd_swmr_zoo_writer \ @@ -173,6 +175,7 @@ vfd_swmr_zoo_reader_SOURCES=vfd_swmr_zoo_writer.c genall5.c vfd_swmr_bigset_reader_SOURCES=vfd_swmr_bigset_writer.c vfd_swmr_group_reader_SOURCES=vfd_swmr_group_writer.c +vfd_swmr_dsetops_reader_SOURCES=vfd_swmr_dsetops_writer.c vfd_swmr_attrdset_writer_SOURCES=vfd_swmr_attrdset_writer.c vfd_swmr_attrdset_reader_SOURCES=vfd_swmr_attrdset_writer.c diff --git a/test/testvfdswmr.sh.in b/test/testvfdswmr.sh.in index a50d7ab..815c443 100644 --- a/test/testvfdswmr.sh.in +++ b/test/testvfdswmr.sh.in @@ -81,8 +81,14 @@ MESSAGE_TIMEOUT=300 # Message timeout length in secs ############################################################################### ## For attrdset test: definitions for fifo files to coordinate test runs ############################################################################### -FIFO_WRITER_TO_READER=fifo_attrdset_writer_to_reader -FIFO_READER_TO_WRITER=fifo_attrdset_reader_to_writer +ATTRDSET_FIFO_WRITER_TO_READER=fifo_attrdset_writer_to_reader +ATTRDSET_FIFO_READER_TO_WRITER=fifo_attrdset_reader_to_writer + +############################################################################### +## For dsetops test: definitions for fifo files to coordinate test runs +############################################################################### +DSETOPS_FIFO_WRITER_TO_READER=fifo_dsetops_writer_to_reader +DSETOPS_FIFO_READER_TO_WRITER=fifo_dsetops_reader_to_writer ############################################################################### ## short hands and function definitions @@ -155,7 +161,7 @@ if [ $rc -ne 0 ] ; then exit 0 fi -all_tests="generator expand shrink expand_shrink sparse vlstr_null vlstr_oob zoo groups attrdset" +all_tests="generator expand shrink expand_shrink sparse vlstr_null vlstr_oob zoo groups attrdset dsetops" all_tests="${all_tests} groups_attrs os_groups_attrs few_big many_small" tests=${all_tests} @@ -201,6 +207,7 @@ mkdir vfd_swmr_test cd vfd_swmr_test + # Loop over index types for index_type in "-i ea" "-i b2" do @@ -631,11 +638,11 @@ for options in "-p -g -a 10 -v -m -d 10 -c 3 -u 5" "-k -a 20 -v -m -d 5"; do fi # Clean up any existing fifo files from previous runs - if [ -e ./$FIFO_WRITER_TO_READER ]; then # If writer fifo file is found - rm -f ./$FIFO_WRITER_TO_READER + if [ -e ./$ATTRDSET_FIFO_WRITER_TO_READER ]; then # If writer fifo file is found + rm -f ./$ATTRDSET_FIFO_WRITER_TO_READER fi - if [ -e ./$FIFO_READER_TO_WRITER ]; then # If reader fifo file is found - rm -f ./$FIFO_READER_TO_WRITER + if [ -e ./$ATTRDSET_FIFO_READER_TO_WRITER ]; then # If reader fifo file is found + rm -f ./$ATTRDSET_FIFO_READER_TO_WRITER fi echo launch vfd_swmr_attrdset_writer attrdset, options $options @@ -671,6 +678,54 @@ for options in "-p -g -a 10 -v -m -d 10 -c 3 -u 5" "-k -a 20 -v -m -d 5"; do rm -f vfd_swmr_attrdset_reader.*.{out,rc} done +# dsetops test +for options in "-p -e 20 -t" "-g -m 5 -n 2 -s 10 -w 7" "-k -m 10 -n 5 -r 5 -l 10"; do + # + # + if [ ${do_dsetops:-no} = no ]; then + continue + fi + # Clean up any existing fifo files from previous runs + if [ -e ./$DSETOPS_FIFO_WRITER_TO_READER ]; then # If writer fifo file is found + rm -f ./$DSETOPS_FIFO_WRITER_TO_READER + fi + if [ -e ./$DSETOPS_FIFO_READER_TO_WRITER ]; then # If reader fifo file is found + rm -f ./$DSETOPS_FIFO_READER_TO_WRITER + fi + # + echo launch vfd_swmr_dsetops_writer dsetops, options $options + catch_out_err_and_rc vfd_swmr_dsetops_writer \ + ../vfd_swmr_dsetops_writer $options & + pid_writer=$! + + catch_out_err_and_rc vfd_swmr_dsetops_reader \ + ../vfd_swmr_dsetops_reader $options & + pid_reader=$! + + # Wait for the reader to finish before signaling the + # writer to quit: the writer holds the file open so that the + # reader will find the shadow file when it opens + # the .h5 file. + wait $pid_reader + wait $pid_writer + + # Collect exit code of the reader + if [ $(cat vfd_swmr_dsetops_reader.rc) -ne 0 ]; then + echo reader had error + nerrors=$((nerrors + 1)) + fi + + # Collect exit code of the writer + if [ $(cat vfd_swmr_dsetops_writer.rc) -ne 0 ]; then + echo writer had error + nerrors=$((nerrors + 1)) + fi + + # Clean up output files + rm -f vfd_swmr_dsetops_writer.{out,rc} + rm -f vfd_swmr_dsetops_reader.*.{out,rc} +done + # # Make sure that we can create GROUP_n groups (20, 40, or 400 depending on the HDF5TestExpress level) # while a reader waits for each to appear. diff --git a/test/vfd_swmr_dsetops_writer.c b/test/vfd_swmr_dsetops_writer.c new file mode 100644 index 0000000..3133efc --- /dev/null +++ b/test/vfd_swmr_dsetops_writer.c @@ -0,0 +1,1760 @@ +/* + * 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. + */ + +/* + * Purpose: To test writing operations for different dataset types. + * Dataset types: + * --dataset with compact layout + * --dataset with contiguous layout + * --datasets with chunked layout: single/implicit/fixed array/extensible array/btree2 indexes + * + * Types of writes: + * -- Sequential writes + * -- Random writes + * -- Regular hyperslab writes + * -- Raw data modifications + */ +#include +#include +#include /* getopt(3) */ + +#include "hdf5.h" +#include "testhdf5.h" +#include "vfd_swmr_common.h" + +#define READER_WAIT_TICKS 4 +#define MAX_COMPACT_SIZE 65520 /* max obj header message size 65536) - other layout message fields (16) */ +#define MAX_COMPACT_ELMS (MAX_COMPACT_SIZE/sizeof(unsigned int)) +#define RANDOM_SEED 9 /* Random seed used by both writer and reader for random writes */ + +/* Structure to hold info for options specified */ +typedef struct { + char filename[PATH_MAX]; /* File name */ + char progname[PATH_MAX]; /* Program name */ + hid_t file; /* File ID */ + hid_t filetype; /* Datatype ID */ + unsigned int update_interval; /* For -u option */ + unsigned int csteps; /* For -c option */ + bool use_np; /* For -N option */ + bool use_vfd_swmr; /* For -S option */ + bool compact; /* -p option: create compact dataset */ + bool compact_write; /* -o option: write to the whole compact dataset */ + unsigned int compact_elmts; /* -e option: # of elments for the compact dataset */ + bool contig; /* -g option: create contiguous dataset */ + bool chunked; /* -k option: create chunked datasets with 5 indexing types */ + unsigned int rows; /* -m option for contiguous and/or chunked datasets */ + unsigned int cols; /* -n option: sequential writes to contiguous and/or chunked datasets */ + unsigned int rwrites; /* -r option: random writes to contiguous and/or chunked datasets */ + unsigned int lwrites; /* -l option: hyperslab writes to contiguous and/or chunked datasets */ + unsigned int wwrites; /* -w option: modify raw data to contiguous and/or chunked datasets */ +} state_t; + +/* Initializations for state_t */ +#define ALL_HID_INITIALIZER (state_t) { \ + .filename = "" \ + , .file = H5I_INVALID_HID \ + , .filetype = H5T_NATIVE_UINT32 \ + , .update_interval = READER_WAIT_TICKS \ + , .csteps = 1 \ + , .use_np = true \ + , .use_vfd_swmr = true \ + , .compact = false \ + , .compact_write = false \ + , .compact_elmts = MAX_COMPACT_ELMS \ + , .contig = false \ + , .rows = 256 \ + , .cols = 512 \ + , .swrites = 0 \ + , .rwrites = 0 \ + , .lwrites = 0 \ + , .wwrites = 0 } + +/* Structure to hold info for different dataset types */ +typedef struct { + hid_t compact_did; /* ID for compact dataset */ + hid_t contig_did; /* ID for contiguous dataset */ + hid_t single_did; /* ID for chunked dataset: single index */ + hid_t implicit_did; /* ID for chunked dataset: implicit index */ + hid_t fa_did; /* ID for chunked dataset: fixed array index */ + hid_t ea_did; /* ID for chunked dataset: extensible array index */ + hid_t bt2_did; /* ID for chunked dataset: version 2 btree index */ + hid_t compact_sid; /* Dataspace ID for compact dataset */ + hid_t contig_sid; /* Dataspace ID for contiguous dataset */ + hid_t single_sid; /* Dataspace ID for chunked dataset */ + hid_t implicit_sid; /* Dataspace ID for chunked dataset */ + hid_t fa_sid; /* Dataspace ID for chunked dataset */ + hid_t ea_sid; /* Dataspace ID for chunked dataset */ + hid_t bt2_sid; /* Dataspace ID for chunked dataset */ +} dsets_state_t; + +/* Initializations for dsets_state_t */ +#define DSETS_INITIALIZER (dsets_state_t) { \ + .compact_did = H5I_INVALID_HID \ + , .compact_sid = H5I_INVALID_HID \ + , .contig_did = H5I_INVALID_HID \ + , .contig_sid = H5I_INVALID_HID \ + , .single_did = H5I_INVALID_HID \ + , .single_sid = H5I_INVALID_HID \ + , .implicit_did = H5I_INVALID_HID \ + , .implicit_sid = H5I_INVALID_HID \ + , .fa_did = H5I_INVALID_HID \ + , .fa_sid = H5I_INVALID_HID \ + , .ea_did = H5I_INVALID_HID \ + , .ea_sid = H5I_INVALID_HID \ + , .bt2_did = H5I_INVALID_HID \ + , .bt2_sid = H5I_INVALID_HID } + +/* Structure to hold info for named pipes */ +typedef struct { + const char *fifo_writer_to_reader; /* Name of fifo for writer to reader */ + const char *fifo_reader_to_writer; /* Name of fifo for reader to writer */ + int fd_writer_to_reader; /* File ID for fifo from writer to reader */ + int fd_reader_to_writer; /* File ID for fifo from reader to writer */ + int notify; /* Value to notify between writer and reader */ + int verify; /* Value to verify between writer and reader */ +} np_state_t; + +/* Initializations for np_state_t */ +#define NP_INITIALIZER (np_state_t) { \ + .fifo_writer_to_reader = "./fifo_dsetops_writer_to_reader" \ + , .fifo_reader_to_writer = "./fifo_dsetops_reader_to_writer" \ + , .fd_writer_to_reader = -1 \ + , .fd_reader_to_writer = -1 \ + , .notify = 0 \ + , .verify = 0 } + +static bool state_init(state_t *, int, char **); + +static bool np_init(np_state_t *np, bool writer); +static bool np_close(np_state_t *np, bool writer); +static bool np_writer(bool result, unsigned step, const state_t *s, np_state_t *np, H5F_vfd_swmr_config_t *config); +static bool np_reader(bool result, unsigned step, const state_t *s, np_state_t *np); +static bool np_confirm_verify_notify(int fd, unsigned step, const state_t *s, np_state_t *np); + +static bool create_dsets(const state_t *s, dsets_state_t *ds); +static bool open_dsets(const state_t *s, dsets_state_t *ds); +static bool open_dset_real(const state_t *s, hid_t *did, hid_t *sid, const char *name); +static bool close_dsets(const dsets_state_t *ds); +static bool close_dset_real(hid_t did, hid_t sid); + +static bool dsets_action(unsigned action, const state_t *s, const dsets_state_t *ds, unsigned step); +static bool dset_setup(unsigned action, unsigned which, const state_t *s, + hsize_t *start, hsize_t *stride, hsize_t *count, hsize_t *block, + hid_t *mem_sid, unsigned int **buf); +static bool write_dset(hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, + hsize_t *start, hsize_t *stride, hsize_t *count, hsize_t *block, unsigned int *buf); +static bool write_dset_compact(const state_t *s, const dsets_state_t *ds); + +static bool verify_dsets_action(unsigned action, const state_t *s, const dsets_state_t *ds, unsigned which); +static bool verify_read_dset(hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, + hsize_t *start, hsize_t *stride, hsize_t *count, hsize_t *block, unsigned int *vbuf); +static bool verify_read_dset_compact(const state_t *s, const dsets_state_t *ds); + +static const hid_t badhid = H5I_INVALID_HID; + +/* Names for datasets */ +#define DSET_COMPACT_NAME "compact_dset" +#define DSET_CONTIG_NAME "contig_dset" +#define DSET_SINGLE_NAME "chunked_single" +#define DSET_IMPLICIT_NAME "chunked_implicit" +#define DSET_FA_NAME "chunked_fa" +#define DSET_EA_NAME "chunked_ea" +#define DSET_BT2_NAME "chunked_bt2" + +/* Action for writes */ +#define SEQ_WRITE 1 /* Sequential write */ +#define RANDOM_WRITE 2 /* Random write */ +#define HYPER_WRITE 3 /* Hyperslab write */ +#define MODIFY_DATA 4 /* Modify raw data */ + +/* Test program usage info */ +static void +usage(const char *progname) +{ + fprintf(stderr, "usage: %s \n" + " [-p] [-e elmts] [-o]\n" + " [-g] [-k] [-m rows] [-n cols]\n" + " [-s swrites] [-r rwrites] [-l lwrites] [-w writes]\n" + " [-u nticks] [-c csteps] [-S] [-N] [-q] [-b]\n" + "\n" + "-p: create a dataset with compact layout\n" + "-e elmts: # of for the compact dataset\n" + " (default is 16380)\n" + "-t: perform write to the compact dataset\n" + "-g: create a dataset with contiguous layout\n" + "-k: create 5 datasets with chunked layout for the 5 indexing types\n" + "-m rows: # of rows for the contiguous and/or chunked datasets\n" + "-n cols: # of columns for the contiguous and/or chunked datasets\n" + "-s swrites: perform sequential writes to all datasets\n" + "-r rwrites: perform random writes to all datasets\n" + "-l lwrites: perform hyperslab writes to all datasets\n" + " # of rows to write: every other element is selected per row\n" + "-w wwrites: perform raw data modifications to all datasets\n" + "-u nticks: `nticks` ticks for the reader to wait before verification\n" + " (default is 4)\n" + "-c csteps: `csteps` steps communication interval between reader and writer\n" + " (default is 1)\n" + "-S: do not use VFD SWMR\n" + "-N: do not use named pipes for test synchronization\n" + "-q: silence printouts, few messages\n" + "-b: write data in big-endian byte order\n" + " (default is H5T_NATIVE_UINT32)\n\n" + "Note:\n" + "1. Require to specify at least -p, -g or -k option\n" + "2. -c option cannot exceed -s or -r \n" + " or -l or -w option\n" + "\n", + progname); + exit(EXIT_FAILURE); +} /* usage() */ + +/* + * Initialize option info in state_t + */ +static bool +state_init(state_t *s, int argc, char **argv) +{ + unsigned long tmp; + int ch; + char tfile[PATH_MAX]; + char *end; + + *s = ALL_HID_INITIALIZER; + esnprintf(tfile, sizeof(tfile), "%s", argv[0]); + esnprintf(s->progname, sizeof(s->progname), "%s", basename(tfile)); + + while ((ch = getopt(argc, argv, "pte:gkm:n:s:r:l:w:bqSNu:c:")) != -1) { + switch (ch) { + + case 'p': /* compact dataset */ + s->compact = true; + break; + + case 't': /* compact write */ + s->compact_write = true; + break; + + case 'g': /* contiguous dataset */ + s->contig = true; + break; + + case 'k': /* chunked datasets */ + s->chunked = true; + break; + + case 'q': + verbosity = 0; + break; + + case 'b': + s->filetype = H5T_STD_U32BE; + break; + + case 'S': + s->use_vfd_swmr = false; + break; + + case 'N': + s->use_np = false; + break; + + case 'e': /* # of elements for compact dataset */ + case 'm': /* # of rows for -g and/or -k */ + case 'n': /* # of cols for -g and/or -k */ + case 's': /* # of sequential writes for -g and/or -k */ + case 'r': /* # of random writes for -g and/or -k */ + case 'l': /* # of hyperslab writes for -g and/or -k */ + case 'w': /* # of raw data modifications for -g and/or -k */ + case 'u': /* ticks for raeder to wait before verification */ + case 'c': /* communication interval */ + errno = 0; + tmp = strtoul(optarg, &end, 0); + if (end == optarg || *end != '\0') { + printf("couldn't parse `-%c` argument `%s`\n", ch, optarg); + TEST_ERROR; + } else if (errno != 0) { + printf("couldn't parse `-%c` argument `%s`\n", ch, optarg); + TEST_ERROR; + } else if (tmp > UINT_MAX) { + printf("`-%c` argument `%lu` too large\n", ch, tmp); + TEST_ERROR; + } + + if (ch == 'e') + s->compact_elmts = (unsigned)tmp; + else if (ch == 'm') + s->rows = (unsigned)tmp; + else if (ch == 'n') + s->cols = (unsigned)tmp; + else if (ch == 's') + s->swrites = (unsigned)tmp; + else if (ch == 'r') + s->rwrites = (unsigned)tmp; + else if (ch == 'l') + s->lwrites = (unsigned)tmp; + else if (ch == 'w') + s->wwrites = (unsigned)tmp; + else if (ch == 'u') + s->update_interval = (unsigned)tmp; + else if (ch == 'c') + s->csteps = (unsigned)tmp; + + break; + + case '?': + default: + usage(s->progname); + break; + } + } + argc -= optind; + argv += optind; + + /* Require to specify at least -p or -g or -k option */ + if(!s->compact && !s->contig &&!s->chunked) { + printf("Require to specify at least -p or -g or -k option\n"); + usage(s->progname); + goto error; + } + + /* -e */ + if(s->compact_elmts > MAX_COMPACT_ELMS) { + printf("size of compact dataset cannot exceed 16380 elements\n"); + TEST_ERROR; + } + + /* -c cannot be zero */ + if(!s->csteps) { + printf("communication interval cannot be zero\n"); + TEST_ERROR; + } + + /* -c and -s options */ + if(s->swrites && s->csteps > s->swrites) { + printf("communication interval with sequential writes is out of bounds\n"); + TEST_ERROR; + } + + /* -c and -r options */ + if(s->rwrites && s->csteps > s->rwrites) { + printf("communication interval with random writes is out of bounds\n"); + TEST_ERROR; + } + + /* -c and -l options */ + if(s->lwrites && s->csteps > s->lwrites) { + printf("communication interval with hyperslab writes is out of bounds\n"); + TEST_ERROR; + } + + /* -c and -w options */ + if(s->wwrites && s->csteps > s->wwrites) { + printf("communication interval with raw data modification is out of bounds\n"); + TEST_ERROR; + } + + /* The test file name */ + esnprintf(s->filename, sizeof(s->filename), "vfd_swmr_dsetops.h5"); + + return true; + +error: + return false; + +} /* state_init() */ + +/* + * Create the datasets as specified on the command line. + */ +static bool +create_dsets(const state_t *s, dsets_state_t *ds) +{ + hid_t dcpl = badhid; + hid_t dtid = badhid; + + *ds = DSETS_INITIALIZER; + + /* Create the named datatype that will be used by compact and contiguous datasets */ + if((dtid = H5Tcopy(s->filetype)) < 0) { + printf("H5Tcopy failed\n"); + TEST_ERROR; + } + + if(H5Tcommit2(s->file, "named_dtype", dtid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) < 0) { + printf("H5Tcommit2 failed\n"); + TEST_ERROR; + } + + /* Dataset with compact layout, 1d, named datatype */ + if(s->compact) { + hsize_t dims[1]; + hid_t sid; + + if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) { + printf("H5Pcreate failed\n"); + TEST_ERROR; + } + if(H5Pset_layout(dcpl, H5D_COMPACT) < 0) { + printf("H5Pset_layout failed\n"); + TEST_ERROR; + } + + dims[0] = s->compact_elmts; + + /* Dataspace for compact dataset */ + if ((ds->compact_sid = H5Screate_simple(1, dims, dims)) < 0) { + printf("H5Screate_simple failed\n"); + TEST_ERROR; + } + + /* Create the compact dataset with named datatype */ + if((ds->compact_did = H5Dcreate2(s->file, DSET_COMPACT_NAME, dtid, + ds->compact_sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) { + printf("H5Dcreate2 compact dataset failed\n"); + TEST_ERROR; + } + + if(H5Pclose(dcpl) < 0) { + printf("H5Pclose failed\n"); + TEST_ERROR; + } + } + + /* Dataset with contiguous layout, 2d, named datatype */ + if(s->contig) { + hsize_t dims[2]; + hid_t sid; + unsigned i; + + dims[0] = s->rows; + dims[1] = s->cols; + + /* Dataspace for contiguous dataset */ + if ((ds->contig_sid = H5Screate_simple(2, dims, dims)) < 0) { + printf("H5Screate_simple failed\n"); + TEST_ERROR; + } + + if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) { + printf("H5Pcreate failed\n"); + TEST_ERROR; + } + + if(H5Pset_layout(dcpl, H5D_CONTIGUOUS) < 0) { + printf("H5Pset_layout failed\n"); + TEST_ERROR; + } + + /* Create the contiguous dataset with the named datatype */ + if((ds->contig_did = H5Dcreate2(s->file, DSET_CONTIG_NAME, dtid, + ds->contig_sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) { + printf("H5Dcreate2 contiguous dataset failed\n"); + TEST_ERROR; + } + + if(H5Pclose(dcpl) < 0) { + printf("H5Pclose failed\n"); + TEST_ERROR; + } + } + + /* Dataset with chunked layout, 2d, named datatype */ + if(s->chunked) { + hsize_t dims[2]; + hsize_t max_dims[2]; + hsize_t chunk_dims[2]; + hid_t sid; + unsigned i; + + dims[0] = s->rows; + dims[1] = s->cols; + + /* Default chunk size is 2x2 unless s->rows or s->cols indicates otherwise */ + chunk_dims[0] = MAX(1, s->rows/2); + chunk_dims[1] = MAX(1, s->cols/2); + + if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) { + printf("H5Pcreate failed\n"); + TEST_ERROR; + } + + if(H5Pset_layout(dcpl, H5D_CHUNKED) < 0) { + printf("H5Pset_layout failed\n"); + TEST_ERROR; + } + + /* Create 2-D chunked dataset with single index */ + /* Chunked, dims=max_dims=chunk_dims */ + + if(H5Pset_chunk(dcpl, 2, dims) < 0) { + printf("H5Pset_chunk failed\n"); + TEST_ERROR; + } + + if ((ds->single_sid = H5Screate_simple(2, dims, dims)) < 0) { + printf("H5Screate_simple failed\n"); + TEST_ERROR; + } + + /* Create the chunked dataset (single index) with the named datatype */ + if((ds->single_did = H5Dcreate2(s->file, DSET_SINGLE_NAME, dtid, + ds->single_sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) { + printf("H5Dcreate2 chunked dataset:single index failed\n"); + TEST_ERROR; + } + + /* Create 2-D chunked dataset with implicit index */ + /* Chunked, dims=max_dims, early allocation */ + + if(H5Pset_alloc_time(dcpl, H5D_ALLOC_TIME_EARLY) < 0) { + printf("H5Pset_alloc_time\n"); + TEST_ERROR; + } + + if(H5Pset_chunk(dcpl, 2, chunk_dims) < 0) { + printf("H5Pset_chunk failed\n"); + TEST_ERROR; + } + + if ((ds->implicit_sid = H5Screate_simple(2, dims, dims)) < 0) { + printf("H5Screate_simple failed\n"); + TEST_ERROR; + } + + /* Create the chunked dataset (implicit index) with the named datatype */ + if((ds->implicit_did = H5Dcreate2(s->file, DSET_IMPLICIT_NAME, dtid, + ds->implicit_sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) { + printf("H5Dcreate2 chunked dataset:implicit index failed\n"); + TEST_ERROR; + } + + if(H5Pclose(dcpl) < 0) { + printf("H5Pclose failed\n"); + TEST_ERROR; + } + + /* Create 2-D chunked dataset with fixed array index */ + /* Chunked, fixed max_dims */ + + if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) { + printf("H5Pcreate failed\n"); + TEST_ERROR; + } + + if(H5Pset_chunk(dcpl, 2, chunk_dims) < 0) { + printf("H5Pset_chunk failed\n"); + TEST_ERROR; + } + + max_dims[0] = dims[0] + 10; + max_dims[1] = dims[1] + 10; + + if((ds->fa_sid = H5Screate_simple(2, dims, max_dims)) < 0) { + printf("H5Screate_simple failed\n"); + TEST_ERROR; + } + + /* Create the chunked dataset (fixed array index) with the named datatype */ + if((ds->fa_did = H5Dcreate2(s->file, DSET_FA_NAME, dtid, + ds->fa_sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) { + printf("H5Dcreaet2 chunked dataset: fa index failed\n"); + TEST_ERROR; + } + + /* Create 2-D chunked dataset with extensible array index */ + /* Chunked, 1 unlimited max_dims */ + + max_dims[1] = H5S_UNLIMITED; + if((ds->ea_sid = H5Screate_simple(2, dims, max_dims)) < 0) { + printf("H5Screate_simple failed\n"); + TEST_ERROR; + } + + /* Create the chunked dataset (extensible array index) with the named datatype */ + if((ds->ea_did = H5Dcreate2(s->file, DSET_EA_NAME, dtid, + ds->ea_sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) { + printf("H5Dcreate2 chunked dataset: ea index failed\n"); + TEST_ERROR; + } + + /* Create 2-D chunked dataset with bt2 index */ + /* Chunked, 2 unlimited max_dims */ + max_dims[0] = H5S_UNLIMITED; + + if((ds->bt2_sid = H5Screate_simple(2, dims, max_dims)) < 0) { + printf("H5Screate_simple failed\n"); + TEST_ERROR; + } + + /* Create the chunked dataset (btree2 index) with the named datatype */ + if((ds->bt2_did = H5Dcreate2(s->file, DSET_BT2_NAME, dtid, + ds->bt2_sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) { + printf("H5Dcreate2 chunked dataset: bt2 index failed\n"); + TEST_ERROR; + } + + if(H5Pclose(dcpl) < 0) { + printf("H5Pclose failed\n"); + TEST_ERROR; + } + + } + + if(H5Tclose(dtid) < 0) { + printf("H5Tclose failed\n"); + TEST_ERROR; + } + + return true; + +error: + H5E_BEGIN_TRY { + H5Pclose(dcpl); + H5Tclose(dtid); + H5Sclose(ds->compact_sid); + H5Sclose(ds->contig_sid); + H5Sclose(ds->single_sid); + H5Sclose(ds->implicit_sid); + H5Sclose(ds->fa_sid); + H5Sclose(ds->ea_sid); + H5Sclose(ds->bt2_sid); + H5Dclose(ds->compact_did); + H5Dclose(ds->contig_did); + H5Dclose(ds->single_did); + H5Dclose(ds->implicit_did); + H5Dclose(ds->fa_did); + H5Dclose(ds->ea_did); + H5Dclose(ds->bt2_did); + } H5E_END_TRY; + + return false; + +} /* create_dsets() */ + +/* + * Open the datasets as specified. + */ +static bool +open_dsets(const state_t *s, dsets_state_t *ds) +{ + *ds = DSETS_INITIALIZER; + + if(s->compact) { + if(!open_dset_real(s, &ds->compact_did, &ds->compact_sid, DSET_COMPACT_NAME)) { + printf("open_dset_real() for compact dataset failed\n"); + TEST_ERROR; + } + } + + if(s->contig) { + hsize_t dims[2]; + + if(!open_dset_real(s, &ds->contig_did, &ds->contig_sid, DSET_CONTIG_NAME)) { + printf("open_dset_real() for contiguous dataset failed\n"); + TEST_ERROR; + } + } + + if(s->chunked) { + hsize_t dims[2]; + + if(!open_dset_real(s, &ds->single_did, &ds->single_sid, DSET_SINGLE_NAME)) { + printf("open_dset_real() for chunked dataset: single index failed\n"); + TEST_ERROR; + } + + if(!open_dset_real(s, &ds->implicit_did, &ds->implicit_sid, DSET_IMPLICIT_NAME)) { + printf("open_dset_real() for chunked dataset: implicit index failed\n"); + TEST_ERROR; + } + + if(!open_dset_real(s, &ds->fa_did, &ds->fa_sid, DSET_FA_NAME)) { + printf("open_dset_real() for chunked dataset: fa index failed\n"); + TEST_ERROR; + } + + if(!open_dset_real(s, &ds->ea_did, &ds->ea_sid, DSET_EA_NAME)) { + printf("open_dset_real() for chunked dataset: ea index failed\n"); + TEST_ERROR; + } + + if(!open_dset_real(s, &ds->bt2_did, &ds->bt2_sid, DSET_BT2_NAME)) { + printf("open_dset_real() for chunked dataset: bt2 index failed\n"); + TEST_ERROR; + } + } + + return true; + +error: + return false; + +} /* open_dsets() */ + +/* + * Do the real work of opening the dataset. + * Verify the dimension sizes are as expected. + */ +static bool +open_dset_real(const state_t *s, hid_t *did, hid_t *sid, const char *name) +{ + hid_t dcpl = badhid; + hsize_t dims[2]; + + if ((*did = H5Dopen2(s->file, name, H5P_DEFAULT)) < 0) { + printf("H5Dopen dataset failed\n"); + TEST_ERROR; + } + + if ((*sid = H5Dget_space(*did)) < 0) { + printf("H5Dget_space failed\n"); + TEST_ERROR; + } + if (H5Sget_simple_extent_dims(*sid, dims, NULL) < 0) + TEST_ERROR; + + if (!HDstrcmp(name, DSET_COMPACT_NAME)) { + if(dims[0] != s->compact_elmts) + TEST_ERROR; + } else { /* contiguous or chunked dataset */ + if (dims[0] != s->rows) + TEST_ERROR; + if (dims[1] != s->cols) + TEST_ERROR; + } + + return true; + +error: + H5E_BEGIN_TRY { + H5Dclose(*did); + H5Dclose(*sid); + } H5E_END_TRY; + + return false; +} /* open_dset_real() */ + +/* + * Close all the datasets and dataspaces as specified. + */ +static bool +close_dsets(const dsets_state_t *ds) +{ + if(!close_dset_real(ds->compact_did, ds->compact_sid)) { + printf("H5Dclose compact dataset failed\n"); + TEST_ERROR; + } + + if(!close_dset_real(ds->contig_did, ds->contig_sid)) { + printf("H5Dclose contiguous dataset failed\n"); + TEST_ERROR; + } + + if(!close_dset_real(ds->single_did, ds->single_sid)) { + printf("H5Dclose chunked dataset: single index failed\n"); + TEST_ERROR; + } + + if(!close_dset_real(ds->implicit_did, ds->implicit_sid)) { + printf("H5Dclose chunked dataset: implicit index failed\n"); + TEST_ERROR; + } + + if(!close_dset_real(ds->fa_did, ds->fa_sid)) { + printf("H5Dclose chunked dataset: fa index failed\n"); + TEST_ERROR; + } + + if(!close_dset_real(ds->ea_did, ds->ea_sid)) { + printf("H5Dclose chunked dataset: ea index failed\n"); + TEST_ERROR; + } + + if(!close_dset_real(ds->bt2_did, ds->bt2_sid)) { + printf("H5Dclose chunked dataset: bt2 index failed\n"); + TEST_ERROR; + } + + return true; + +error: + return false; + +} /* close_dsets() */ + +/* + * Do the real work of closing the dataset. + */ +static bool +close_dset_real(hid_t did, hid_t sid) +{ + if(did != badhid && H5Dclose(did) < 0) { + printf("H5Dclose dataset failed\n"); + TEST_ERROR; + } + + if(sid != badhid && H5Sclose(sid) < 0) { + printf("H5Sclose dataspace for dataset failed\n"); + TEST_ERROR; + } + + return true; + +error: + H5E_BEGIN_TRY { + H5Dclose(did); + H5Sclose(sid); + } H5E_END_TRY; + + return false; +} /* close_dset_real() */ + +/* + * Writer + */ + + +/* + * Perform the "action" for each of the datasets specified on the command line: + * SEQ_WRITE: perform `which` sequential write + * RANDOM_WRITE: perform `which` random write + * HYPER_WRITE: perform `which` hyperslab write + * MODIFY_DATA: perform `which` raw data modification + */ +static bool +dsets_action(unsigned action, const state_t *s, const dsets_state_t *ds, unsigned which) +{ + int nerrors = 0; + bool ret = false; + hsize_t dims[2]; + hsize_t start[2]; + hsize_t stride[2]; + hsize_t count[2]; + hsize_t block[2]; + hid_t mem_sid; + unsigned kk, i; + unsigned int *wbuf = NULL; + + /* Set up selection, dataspace and data buffer according to the specified action */ + if(!dset_setup(action, which, s, start, stride, count, block, &mem_sid, &wbuf)) { + printf("dset_setup() failed\n"); + TEST_ERROR; + } + + /* Write to the contiguous dataset */ + if(s->contig) { + + if(!write_dset(ds->contig_did, s->filetype, mem_sid, ds->contig_sid, start, stride, count, block, wbuf)) { + printf("H5Dwrite to contiguous dataset failed\n"); + TEST_ERROR; + } + } + + /* Write to the 5 chunked datasets */ + if(s->chunked) { + + if(!write_dset(ds->single_did, s->filetype, mem_sid, ds->single_sid, start, stride, count, block, wbuf)) { + printf("H5Dwrite to chunked dataset: single index dataset failed\n"); + TEST_ERROR; + } + + if(!write_dset(ds->implicit_did, s->filetype, mem_sid, ds->implicit_sid, start, stride, count, block, wbuf)) { + printf("H5Dwrite to chunked dataset: implicit index dataset failed\n"); + TEST_ERROR; + } + + if(!write_dset(ds->fa_did, s->filetype, mem_sid, ds->fa_sid, start, stride, count, block, wbuf)) { + printf("H5Dwrite to chunked dataset: fa index dataset failed\n"); + TEST_ERROR; + } + + if(!write_dset(ds->ea_did, s->filetype, mem_sid, ds->ea_sid, start, stride, count, block, wbuf)) { + printf("H5Dwrite to chunked dataset: ea index dataset failed\n"); + TEST_ERROR; + } + + if(!write_dset(ds->bt2_did, s->filetype, mem_sid, ds->bt2_sid, start, stride, count, block, wbuf)) { + printf("H5Dwrite to chunked dataset: bt2 index dataset failed\n"); + TEST_ERROR; + } + } + + if(wbuf) HDfree(wbuf); + return true; + +error: + if(wbuf) HDfree(wbuf); + return false; + +} /* dsets_action() */ + +/* + * Set up selection info: start, stride, count, block + * Set up the memory dataspace + * Initialize the data buffer + */ +static bool +dset_setup(unsigned action, unsigned which, const state_t *s, + hsize_t *start, hsize_t *stride, hsize_t *count, hsize_t *block, + hid_t *mem_sid, unsigned int **buf) +{ + hsize_t mem_dims[1]; + unsigned kk, i; + unsigned int *tmp_buf; + + start[0] = which / s->cols; + start[1] = which % s->cols; + block[0] = block[1] = 1; + + /* For SEQ_WRITE, RANDOM_WRITE, MODIFY_DATA: writing 1 element at a time */ + /* For HYPER_WRITE: writing 1 row at a time: selecting every other element per row */ + switch(action) { + case SEQ_WRITE: + case RANDOM_WRITE: + case MODIFY_DATA: + count[0] = count[1] = 1; + stride[0] = stride[1] = 1; + mem_dims[0] = 1; + *mem_sid = H5Screate_simple(1, mem_dims, NULL); + break; + + case HYPER_WRITE: + count[0] = 1; + count[1] = MAX(1, s->cols/2); + stride[0] = 1; + stride[1] = 2; + + mem_dims[0] = count[1]; + *mem_sid = H5Screate_simple(1, mem_dims, NULL); + break; + + default: + HDassert(0 && "Unknown action?!?"); + } /* end switch */ + + /* Allocating the buffer for writing */ + if((tmp_buf = HDmalloc(count[1] * sizeof(unsigned int))) == NULL) { + printf("HDmalloc failed\n"); + TEST_ERROR; + } + + /* Initialize the data in the buffer */ + switch(action) { + case SEQ_WRITE: + tmp_buf[0] = which + 1; + break; + + case RANDOM_WRITE: + tmp_buf[0] = 777; + break; + + case MODIFY_DATA: + tmp_buf[0] = 999; + break; + + case HYPER_WRITE: + kk = which + 1; + for (i = 0; i < count[1]; i++) { + tmp_buf[i] = kk; + kk += 2; + } + + break; + + default: + HDassert(0 && "Unknown action?!?"); + } /* end switch */ + + *buf = tmp_buf; + return true; + +error: + return false; + +} /* dset_setup() */ + +/* + * Make the selection and then write to the dataset. + */ +static bool +write_dset(hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, + hsize_t *start, hsize_t *stride, hsize_t *count, hsize_t *block, unsigned int *buf) +{ + + if(H5Sselect_hyperslab(file_sid, H5S_SELECT_SET, start, stride, count, block) < 0) { + printf("H5Sselect to dataset failed\n"); + TEST_ERROR; + } + + if(H5Dwrite(did, tid, mem_sid, file_sid, H5P_DEFAULT, buf) < 0) { + printf("H5Dwrite to dataset failed\n"); + TEST_ERROR; + } + + return true; + +error: + return false; + +} /* write_dset() */ + +/* + * Write to whole compact dataset. + */ +static bool +write_dset_compact(const state_t *s, const dsets_state_t *ds) +{ + unsigned int *buf = NULL; + unsigned i; + + if((buf = HDmalloc(s->compact_elmts * sizeof(unsigned int))) == NULL) { + printf("HDmalloc buffer for compact dataset failed\n"); + goto error; + } + + for (i = 0; i < s->compact_elmts; i++) + buf[i] = i + 1; + + if(H5Dwrite(ds->compact_did, s->filetype, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) { + printf("H5Dwrite to compact dataset failed\n"); + TEST_ERROR; + } + + if(buf) HDfree(buf); + return true; + +error: + if(buf) HDfree(buf); + return false; + +} /* write_dset_compact() */ + +/* + * Reader + */ + + + +/* + * Verify the data read from each of the datasets specified on the command line + * according to "action": + * SEQ_WRITE: `which` sequential write + * RANDOM_WRITE: `which` random write + * HYPER_WRITE: `which` hyperslab write + * MODIFY_DATA: `which` raw data modification + */ +static bool +verify_dsets_action(unsigned action, const state_t *s, const dsets_state_t *ds, unsigned which) +{ + int nerrors = 0; + bool ret = false; + hsize_t dims[2]; + hsize_t start[2]; + hsize_t stride[2]; + hsize_t count[2]; + hsize_t block[2]; + hid_t mem_sid; + unsigned mm; + unsigned kk, i; + unsigned int *dd; + unsigned int *vbuf = NULL; + + /* Set up selection, dataspace and data buffer according to the specified action */ + if(!dset_setup(action, which, s, start, stride, count, block, &mem_sid, &vbuf)) { + printf("dset_setup() failed\n"); + TEST_ERROR; + } + + /* Verify the data read for the contiguous dataset */ + if(s->contig) { + if(!verify_read_dset(ds->contig_did, s->filetype, mem_sid, ds->contig_sid, start, stride, count, block, vbuf)) { + printf("H5Dwrite to contiguous dataset failed\n"); + TEST_ERROR; + } + } + + /* Verify the data read for the chunked datasets */ + if(s->chunked) { + + if(!verify_read_dset(ds->single_did, s->filetype, mem_sid, ds->single_sid, start, stride, count, block, vbuf)) { + printf("H5Dwrite to chunked dataset: single index dataset failed\n"); + TEST_ERROR; + } + + if(!verify_read_dset(ds->implicit_did, s->filetype, mem_sid, ds->implicit_sid, start, stride, count, block, vbuf)) { + printf("H5Dwrite to chunked dataset: implicit index dataset failed\n"); + TEST_ERROR; + } + + if(!verify_read_dset(ds->fa_did, s->filetype, mem_sid, ds->fa_sid, start, stride, count, block, vbuf)) { + printf("H5Dwrite to chunked dataset: fa index dataset failed\n"); + TEST_ERROR; + } + + if(!verify_read_dset(ds->ea_did, s->filetype, mem_sid, ds->ea_sid, start, stride, count, block, vbuf)) { + printf("H5Dwrite to chunked dataset: ea index dataset failed\n"); + TEST_ERROR; + } + + if(!verify_read_dset(ds->bt2_did, s->filetype, mem_sid, ds->bt2_sid, start, stride, count, block, vbuf)) { + printf("H5Dwrite to chunked dataset: bt2 index dataset failed\n"); + TEST_ERROR; + } + } + + if(vbuf) HDfree(vbuf); + + return true; + +error: + if(vbuf) HDfree(vbuf); + + return false; + +} /* verify_dsets_action() */ + +/* + * Verify the data read from the dataset is as expected. + * `vbuf` contains the data expected from the read. + */ +static bool +verify_read_dset(hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, + hsize_t *start, hsize_t *stride, hsize_t *count, hsize_t *block, unsigned int *vbuf) +{ + unsigned int *rbuf = NULL; + unsigned i; + + /* Refresh the dataset */ + if(H5Drefresh(did) < 0) { + printf("H5Drefresh dataset failed\n"); + TEST_ERROR; + } + + /* Allocate the buffer for reading */ + if((rbuf = HDmalloc(count[1] * sizeof(unsigned int))) == NULL) { + printf("HDmalloc failed\n"); + TEST_ERROR; + } + + /* Make the selection the file dataspace */ + if(H5Sselect_hyperslab(file_sid, H5S_SELECT_SET, start, stride, count, block) < 0) { + printf("H5Sselect to dataset failed\n"); + TEST_ERROR; + } + + /* Read the data from the dataset into `rbuf` */ + if(H5Dread(did, tid, mem_sid, file_sid, H5P_DEFAULT, rbuf) < 0) { + printf("H5Dread from dataset failed\n"); + TEST_ERROR; + } + + /* Verify the data read in `rbuf` is as `vbuf` */ + for (i = 0; i < count[1]; i++) + if(rbuf[i] != vbuf[i]) + TEST_ERROR; + + if(rbuf) HDfree(rbuf); + + return true; + +error: + if(rbuf) HDfree(rbuf); + return false; + +} /* verify_read_dset() */ + + +/* + * Verify that the data read from the compact dataset is as unexpected. + */ +static bool +verify_read_dset_compact(const state_t *s, const dsets_state_t *ds) +{ + unsigned int *vbuf, *rbuf; + unsigned i; + + if((rbuf = HDmalloc(s->compact_elmts * sizeof(unsigned int))) == NULL) { + printf("HDmalloc buffer for compact dataset failed\n"); + goto error; + } + + if(H5Dread(ds->compact_did, s->filetype, H5S_ALL, H5S_ALL, H5P_DEFAULT, rbuf) < 0) { + printf("H5Dwrite to compact dataset failed\n"); + TEST_ERROR; + } + + for (i = 0; i < s->compact_elmts; i++) + if(rbuf[i] != (i + 1)) { + printf("Invalid value for compact dataset element\n"); + TEST_ERROR; + } + + if(rbuf) HDfree(rbuf); + + return true; + +error: + if(rbuf) HDfree(rbuf); + return false; + +} /* verify_read_dset_compact() */ + +/* + * Named pipes handling + */ + +/* + * Initialize the named pipes for test synchronization. + */ +static bool +np_init(np_state_t *np, bool writer) +{ + *np = NP_INITIALIZER; + + /* + * 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) { + /* If the named pipes are present at the start of the test, remove them */ + if (HDaccess(np->fifo_writer_to_reader, F_OK) == 0) + if(HDremove(np->fifo_writer_to_reader) != 0) { + printf("HDremove fifo_writer_to_reader failed\n"); + TEST_ERROR; + } + + if (HDaccess(np->fifo_reader_to_writer, F_OK) == 0) + if(HDremove(np->fifo_reader_to_writer) != 0) { + printf("HDremove fifo_reader_to_writer failed\n"); + TEST_ERROR; + } + + /* Writer creates two named pipes(FIFO) */ + if (HDmkfifo(np->fifo_writer_to_reader, 0600) < 0) { + printf("HDmkfifo fifo_writer_to_reader failed\n"); + TEST_ERROR; + } + + if (HDmkfifo(np->fifo_reader_to_writer, 0600) < 0) { + printf("HDmkfifo fifo_reader_to_writer failed\n"); + TEST_ERROR; + } + } + + /* Both the writer and reader open the pipes */ + if ((np->fd_writer_to_reader = HDopen(np->fifo_writer_to_reader, O_RDWR)) < 0) { + printf("HDopen fifo_writer_to_reader failed\n"); + TEST_ERROR; + } + + if ((np->fd_reader_to_writer = HDopen(np->fifo_reader_to_writer, O_RDWR)) < 0) { + printf("HDopen fifo_reader_to_writer failed\n"); + TEST_ERROR; + } + + return true; + +error: + return false; + +} /* np_init() */ + +/* + * Close the named pipes. + */ +static bool +np_close(np_state_t *np, bool writer) +{ + /* Both the writer and reader close the named pipes */ + if (HDclose(np->fd_writer_to_reader) < 0) { + printf("HDclose fd_writer_to_reader failed\n"); + TEST_ERROR; + } + + if (HDclose(np->fd_reader_to_writer) < 0) { + printf("HDclose fd_reader_to_writer failed\n"); + TEST_ERROR; + } + + /* Reader finishes last and deletes the named pipes */ + if(!writer) { + if(HDremove(np->fifo_writer_to_reader) != 0) { + printf("HDremove fifo_writer_to_reader failed\n"); + TEST_ERROR; + } + + if(HDremove(np->fifo_reader_to_writer) != 0) { + printf("HDremove fifo_reader_to_writer failed\n"); + TEST_ERROR; + } + } + return true; + +error: + return false; +} /* np_close() */ + +/* + * Writer synchronization depending on the result from the attribute action performed. + */ +static bool +np_writer(bool result, unsigned step, const state_t *s, np_state_t *np, H5F_vfd_swmr_config_t *config) +{ + unsigned int i; + + /* The action fails */ + if(!result) { + printf("attribute action failed\n"); + H5_FAILED(); AT(); + + /* At communication interval, notify the reader about the failure and quit */ + if (step % s->csteps == 0) { + np->notify = -1; + HDwrite(np->fd_writer_to_reader, &np->notify, sizeof(int)); + goto error; + } + /* The action succeeds */ + } else { + /* At communication interval, notify the reader and wait for its response */ + if (step % s->csteps == 0) { + /* Bump up the value of notify to tell the reader to start reading */ + np->notify++; + if (HDwrite(np->fd_writer_to_reader, &np->notify, sizeof(int)) < 0) { + printf("HDwrite failed\n"); + TEST_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; + } + + /* Handshake between writer and reader */ + if(!np_confirm_verify_notify(np->fd_reader_to_writer, step, s, np)) { + printf("np_confirm_verify_notify() verify/notify not in sync failed\n"); + TEST_ERROR; + } + } + } + return true; + +error: + return false; + +} /* np_writer() */ + +/* + * + * Reader synchronization depending on the result from the verification. + */ +static bool +np_reader(bool result, unsigned step, const state_t *s, np_state_t *np) +{ + /* The verification fails */ + if(!result) { + printf("verify action failed\n"); + H5_FAILED(); AT(); + + /* At communication interval, tell the writer about the failure and exit */ + if (step % s->csteps == 0) { + np->notify = -1; + HDwrite(np->fd_reader_to_writer, &np->notify, sizeof(int)); + goto error; + } + /* The verification succeeds */ + } else { + if (step % s->csteps == 0) { + /* Send back the same notify value for acknowledgement: + * --inform the writer to move to the next step */ + if (HDwrite(np->fd_reader_to_writer, &np->notify, sizeof(int)) < 0) { + printf("HDwrite failed\n"); + TEST_ERROR; + } + } + } + return true; + +error: + return false; + +} /* np_reader() */ + +/* + * Handshake between writer and reader: + * Confirm `verify` is same as `notify`. + */ +static bool +np_confirm_verify_notify(int fd, unsigned step, const state_t *s, np_state_t *np) +{ + if (step % s->csteps == 0) { + np->verify++; + if (HDread(fd, &np->notify, sizeof(int)) < 0) { + printf("HDread failed\n"); + TEST_ERROR; + } + + if (np->notify == -1) { + printf("reader/writer failed to verify\n"); + TEST_ERROR; + } + + if (np->notify != np->verify) { + printf("received message %d, expecting %d\n", np->notify, np->verify); + TEST_ERROR; + } + } + + return true; + +error: + return false; +} /* np_confirm_verify_notify() */ + +/* + * Main + */ +int +main(int argc, char **argv) +{ + hid_t fapl, fcpl; + unsigned step; + bool writer; + state_t s; + const char *personality; + H5F_vfd_swmr_config_t config; + np_state_t np; + dsets_state_t ds; + bool result; + + if(!state_init(&s, argc, argv)) { + printf("state_init() failed\n"); + TEST_ERROR; + } + + personality = strstr(s.progname, "vfd_swmr_dsetops_"); + + if (personality != NULL && + strcmp(personality, "vfd_swmr_dsetops_writer") == 0) + writer = true; + else if (personality != NULL && + strcmp(personality, "vfd_swmr_dsetops_reader") == 0) + writer = false; + else { + printf("unknown personality, expected vfd_swmr_dsetops_{reader,writer}\n"); + TEST_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, "./dsetops-shadow"); + + /* use_latest_format, use_vfd_swmr, only_meta_page, config */ + if((fapl = vfd_swmr_create_fapl(true, s.use_vfd_swmr, true, &config)) < 0) { + printf("vfd_swmr_create_fapl() failed\n"); + TEST_ERROR; + } + + if ((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0) { + printf("H5Pcreate failed\n"); + TEST_ERROR; + } + + if(H5Pset_file_space_strategy(fcpl, H5F_FSPACE_STRATEGY_PAGE, false, 1) < 0) { + printf("H5Pset_file_space_strategy failed\n"); + TEST_ERROR; + } + + if (writer) { + if((s.file = H5Fcreate(s.filename, H5F_ACC_TRUNC, fcpl, fapl)) < 0) { + printf("H5Fcreate failed\n"); + TEST_ERROR; + } + + if(!create_dsets(&s, &ds)) { + printf("create_dsets() failed\n"); + TEST_ERROR; + } + + } else { + if ((s.file = H5Fopen(s.filename, H5F_ACC_RDONLY, fapl)) < 0) { + printf("H5Fopen failed\n"); + TEST_ERROR; + } + if(!open_dsets(&s, &ds)) { + printf("open_dsets() failed\n"); + TEST_ERROR; + } + } + + /* Initiailze named pipes */ + if(s.use_np && !np_init(&np, writer)) { + printf("np_init() failed\n"); + TEST_ERROR; + } + + if (writer) { + + /* Perform writes to the whole compact dataset */ + if(s.compact && s.compact_write) { + dbgf(2, "Writes all to compact dataset\n"); + + result = write_dset_compact(&s, &ds); + + if(s.use_np && !np_writer(result, 0, &s, &np, &config)) { + printf("np_writer() for addition failed\n"); + TEST_ERROR; + } + } + + /* Perform sequential writes for contiguous and/or chunked datasets */ + if((s.contig || s.chunked) && s.swrites) { + + for (step = 0; (step < s.swrites && step < (s.rows*s.cols)); step++) { + dbgf(2, "Sequential writes %u to dataset\n", step); + + result = dsets_action(SEQ_WRITE, &s, &ds, step); + + if(s.use_np && !np_writer(result, step, &s, &np, &config)) { + printf("np_writer() for sequential writes failed\n"); + TEST_ERROR; + } + } + } + + /* Perform random writes for contiguous and/or chunked datasets */ + if((s.contig || s.chunked ) && s.rwrites) { + unsigned newstep; + + /* Set up random seed which will be the same for both writer and reader */ + HDsrandom(RANDOM_SEED); + + for (step = 0; (step < s.rwrites && step < (s.rows*s.cols)); step++) { + dbgf(2, "Random writes %u to dataset\n", step); + + newstep = HDrandom() % (s.rows*s.cols); + printf("Random step is %u\n", newstep); + result = dsets_action(RANDOM_WRITE, &s, &ds, newstep); + + if(s.use_np && !np_writer(result, step, &s, &np, &config)) { + printf("np_writer() for random writes failed\n"); + TEST_ERROR; + } + } + + } + + /* Perform hyperslab writes for contiguous and/or chunked datasets */ + if((s.contig || s.chunked) && s.lwrites) { + unsigned k; + for (step = 0, k = 0; (step < s.lwrites && k < (s.rows*s.cols)); step++, k+=s.cols) { + dbgf(2, "Hyperslab writes %u to dataset\n", step); + + result = dsets_action(HYPER_WRITE, &s, &ds, k); + + if(s.use_np && !np_writer(result, step, &s, &np, &config)) { + printf("np_writer() for hyperslab writes failed\n"); + TEST_ERROR; + } + } + } + + /* Perform raw data modifications for contiguous and/or chunked datasets */ + if((s.contig || s.chunked) && s.wwrites) { + + for (step = 0; (step < s.wwrites && step < (s.rows*s.cols)); step++) { + dbgf(2, "Modify raw data %u to dataset\n", step); + + result = dsets_action(MODIFY_DATA, &s, &ds, step); + + if(s.use_np && !np_writer(result, step, &s, &np, &config)) { + printf("np_writer() for modify raw data failed\n"); + TEST_ERROR; + } + } + } + + } else { + + /* Start verifying data written to the compact dataset */ + if(s.compact && s.compact_write) { + dbgf(2, "Verify writes to compact dataset\n"); + + if(s.use_np && !np_confirm_verify_notify(np.fd_writer_to_reader, 0, &s, &np)) { + printf("np_confirm_verify_notify() verify/notify not in sync failed\n"); + TEST_ERROR; + } + /* Wait for a few ticks for the update to happen */ + decisleep(config.tick_len * s.update_interval); + + result = verify_read_dset_compact(&s, &ds); + + if(s.use_np && !np_reader(result, 0, &s, &np)) { + printf("np_reader() for verifying addition failed\n"); + TEST_ERROR; + } + } + + /* Start verifying sequential writes for contiguous and/or chunked datasets */ + if((s.contig || s.chunked) && s.swrites) { + + for (step = 0; (step < s.swrites && step < (s.rows*s.cols)); step++) { + dbgf(2, "Verify sequential writes %u to dataset\n", step); + + if(s.use_np && !np_confirm_verify_notify(np.fd_writer_to_reader, step, &s, &np)) { + printf("np_confirm_verify_notify() verify/notify not in sync failed\n"); + TEST_ERROR; + } + /* Wait for a few ticks for the update to happen */ + decisleep(config.tick_len * s.update_interval); + + result = verify_dsets_action(SEQ_WRITE, &s, &ds, step); + + if(s.use_np && !np_reader(result, step, &s, &np)) { + printf("np_reader() for verifying addition failed\n"); + TEST_ERROR; + } + } + } + + /* Start verifying random writes for contiguous and/or chunked datasets */ + if((s.contig || s.chunked) && s.rwrites) { + unsigned newstep; + + /* Set up random seed which will be the same for both writer and reader */ + HDsrandom(RANDOM_SEED); + + for (step = 0; (step < s.rwrites && step < (s.rows*s.cols)); step++) { + dbgf(2, "Verify random writes %u to dataset\n", step); + + newstep = HDrandom() % (s.rows*s.cols); + printf("Random step is %u\n", newstep); + + if(s.use_np && !np_confirm_verify_notify(np.fd_writer_to_reader, step, &s, &np)) { + printf("np_confirm_verify_notify() verify/notify not in sync failed\n"); + TEST_ERROR; + } + + /* Wait for a few ticks for the update to happen */ + decisleep(config.tick_len * s.update_interval); + + result = verify_dsets_action(RANDOM_WRITE, &s, &ds, newstep); + + if(s.use_np && !np_reader(result, step, &s, &np)) { + printf("np_reader() for verifying addition failed\n"); + TEST_ERROR; + } + } + } + + /* Start verifying hyperslab writes for contiguous and/or chunked datasets */ + if((s.contig || s.chunked) && s.lwrites) { + unsigned k; + + for (step = 0, k = 0; (step < s.lwrites && k < (s.rows*s.cols)); step++, k+=s.cols) { + dbgf(2, "Verify hyperslab writes %u to dataset\n", step); + + if(s.use_np && !np_confirm_verify_notify(np.fd_writer_to_reader, step, &s, &np)) { + printf("np_confirm_verify_notify() verify/notify not in sync failed\n"); + TEST_ERROR; + } + + /* Wait for a few ticks for the update to happen */ + decisleep(config.tick_len * s.update_interval); + + result = verify_dsets_action(HYPER_WRITE, &s, &ds, k); + + if(s.use_np && !np_reader(result, step, &s, &np)) { + printf("np_reader() for verifying addition failed\n"); + TEST_ERROR; + } + } + } + + /* Start verifying raw data modifications for contiguous and/or chunked datasets */ + if((s.contig || s.chunked) && s.wwrites) { + unsigned k; + + for (step = 0; (step < s.wwrites && step < (s.rows*s.cols)); step++) { + dbgf(2, "Verify raw data modification %u to dataset\n", step); + + if(s.use_np && !np_confirm_verify_notify(np.fd_writer_to_reader, step, &s, &np)) { + printf("np_confirm_verify_notify() verify/notify not in sync failed\n"); + TEST_ERROR; + } + + /* Wait for a few ticks for the update to happen */ + decisleep(config.tick_len * s.update_interval); + + result = verify_dsets_action(MODIFY_DATA, &s, &ds, step); + + if(s.use_np && !np_reader(result, step, &s, &np)) { + printf("np_reader() for verifying addition failed\n"); + TEST_ERROR; + } + } + } + } + + if(!close_dsets(&ds)) { + printf("close_dsets() failed\n"); + TEST_ERROR; + } + + if (H5Pclose(fapl) < 0) { + printf("H5Pclose failed\n"); + TEST_ERROR; + } + + if (H5Pclose(fcpl) < 0) { + printf("H5Pclose failed\n"); + TEST_ERROR; + } + + if (H5Fclose(s.file) < 0) { + printf("H5Fclose failed\n"); + TEST_ERROR; + } + + if(s.use_np && !np_close(&np, writer)) { + printf("np_close() failed\n"); + TEST_ERROR; + } + + return EXIT_SUCCESS; + +error: + H5E_BEGIN_TRY { + H5Pclose(fapl); + H5Pclose(fcpl); + H5Fclose(s.file); + } H5E_END_TRY; + + if (s.use_np && np.fd_writer_to_reader >= 0) + HDclose(np.fd_writer_to_reader); + + if (s.use_np && np.fd_reader_to_writer >= 0) + HDclose(np.fd_reader_to_writer); + + if(s.use_np && !writer) { + HDremove(np.fifo_writer_to_reader); + HDremove(np.fifo_reader_to_writer); + } + + return EXIT_FAILURE; +} /* main */ -- cgit v0.12 From 1b1fcf979b27c992b61e8d214897aa5d8fda5807 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 4 May 2021 23:08:14 +0000 Subject: Committing clang-format changes --- test/vfd_swmr_dsetops_writer.c | 992 +++++++++++++++++++++-------------------- 1 file changed, 502 insertions(+), 490 deletions(-) diff --git a/test/vfd_swmr_dsetops_writer.c b/test/vfd_swmr_dsetops_writer.c index 3133efc..b2c79c0 100644 --- a/test/vfd_swmr_dsetops_writer.c +++ b/test/vfd_swmr_dsetops_writer.c @@ -32,113 +32,98 @@ #include "testhdf5.h" #include "vfd_swmr_common.h" -#define READER_WAIT_TICKS 4 -#define MAX_COMPACT_SIZE 65520 /* max obj header message size 65536) - other layout message fields (16) */ -#define MAX_COMPACT_ELMS (MAX_COMPACT_SIZE/sizeof(unsigned int)) -#define RANDOM_SEED 9 /* Random seed used by both writer and reader for random writes */ +#define READER_WAIT_TICKS 4 +#define MAX_COMPACT_SIZE 65520 /* max obj header message size 65536) - other layout message fields (16) */ +#define MAX_COMPACT_ELMS (MAX_COMPACT_SIZE / sizeof(unsigned int)) +#define RANDOM_SEED 9 /* Random seed used by both writer and reader for random writes */ /* Structure to hold info for options specified */ typedef struct { - char filename[PATH_MAX]; /* File name */ - char progname[PATH_MAX]; /* Program name */ - hid_t file; /* File ID */ - hid_t filetype; /* Datatype ID */ - unsigned int update_interval; /* For -u option */ - unsigned int csteps; /* For -c option */ - bool use_np; /* For -N option */ - bool use_vfd_swmr; /* For -S option */ - bool compact; /* -p option: create compact dataset */ - bool compact_write; /* -o option: write to the whole compact dataset */ - unsigned int compact_elmts; /* -e option: # of elments for the compact dataset */ - bool contig; /* -g option: create contiguous dataset */ - bool chunked; /* -k option: create chunked datasets with 5 indexing types */ - unsigned int rows; /* -m option for contiguous and/or chunked datasets */ - unsigned int cols; /* -n option: sequential writes to contiguous and/or chunked datasets */ - unsigned int rwrites; /* -r option: random writes to contiguous and/or chunked datasets */ - unsigned int lwrites; /* -l option: hyperslab writes to contiguous and/or chunked datasets */ - unsigned int wwrites; /* -w option: modify raw data to contiguous and/or chunked datasets */ + char filename[PATH_MAX]; /* File name */ + char progname[PATH_MAX]; /* Program name */ + hid_t file; /* File ID */ + hid_t filetype; /* Datatype ID */ + unsigned int update_interval; /* For -u option */ + unsigned int csteps; /* For -c option */ + bool use_np; /* For -N option */ + bool use_vfd_swmr; /* For -S option */ + bool compact; /* -p option: create compact dataset */ + bool compact_write; /* -o option: write to the whole compact dataset */ + unsigned int compact_elmts; /* -e option: # of elments for the compact dataset */ + bool contig; /* -g option: create contiguous dataset */ + bool chunked; /* -k option: create chunked datasets with 5 indexing types */ + unsigned int rows; /* -m option for contiguous and/or chunked datasets */ + unsigned int cols; /* -n option: sequential writes to contiguous and/or chunked datasets */ + unsigned int rwrites; /* -r option: random writes to contiguous and/or chunked datasets */ + unsigned int lwrites; /* -l option: hyperslab writes to contiguous and/or chunked datasets */ + unsigned int wwrites; /* -w option: modify raw data to contiguous and/or chunked datasets */ } state_t; /* Initializations for state_t */ -#define ALL_HID_INITIALIZER (state_t) { \ - .filename = "" \ - , .file = H5I_INVALID_HID \ - , .filetype = H5T_NATIVE_UINT32 \ - , .update_interval = READER_WAIT_TICKS \ - , .csteps = 1 \ - , .use_np = true \ - , .use_vfd_swmr = true \ - , .compact = false \ - , .compact_write = false \ - , .compact_elmts = MAX_COMPACT_ELMS \ - , .contig = false \ - , .rows = 256 \ - , .cols = 512 \ - , .swrites = 0 \ - , .rwrites = 0 \ - , .lwrites = 0 \ - , .wwrites = 0 } +#define ALL_HID_INITIALIZER \ + (state_t) \ + { \ + .filename = "", .file = H5I_INVALID_HID, .filetype = H5T_NATIVE_UINT32, \ + .update_interval = READER_WAIT_TICKS, .csteps = 1, .use_np = true, .use_vfd_swmr = true, \ + .compact = false, .compact_write = false, .compact_elmts = MAX_COMPACT_ELMS, .contig = false, \ + .rows = 256, .cols = 512, .swrites = 0, .rwrites = 0, .lwrites = 0, .wwrites = 0 \ + } /* Structure to hold info for different dataset types */ typedef struct { - hid_t compact_did; /* ID for compact dataset */ - hid_t contig_did; /* ID for contiguous dataset */ - hid_t single_did; /* ID for chunked dataset: single index */ - hid_t implicit_did; /* ID for chunked dataset: implicit index */ - hid_t fa_did; /* ID for chunked dataset: fixed array index */ - hid_t ea_did; /* ID for chunked dataset: extensible array index */ - hid_t bt2_did; /* ID for chunked dataset: version 2 btree index */ - hid_t compact_sid; /* Dataspace ID for compact dataset */ - hid_t contig_sid; /* Dataspace ID for contiguous dataset */ - hid_t single_sid; /* Dataspace ID for chunked dataset */ - hid_t implicit_sid; /* Dataspace ID for chunked dataset */ - hid_t fa_sid; /* Dataspace ID for chunked dataset */ - hid_t ea_sid; /* Dataspace ID for chunked dataset */ - hid_t bt2_sid; /* Dataspace ID for chunked dataset */ + hid_t compact_did; /* ID for compact dataset */ + hid_t contig_did; /* ID for contiguous dataset */ + hid_t single_did; /* ID for chunked dataset: single index */ + hid_t implicit_did; /* ID for chunked dataset: implicit index */ + hid_t fa_did; /* ID for chunked dataset: fixed array index */ + hid_t ea_did; /* ID for chunked dataset: extensible array index */ + hid_t bt2_did; /* ID for chunked dataset: version 2 btree index */ + hid_t compact_sid; /* Dataspace ID for compact dataset */ + hid_t contig_sid; /* Dataspace ID for contiguous dataset */ + hid_t single_sid; /* Dataspace ID for chunked dataset */ + hid_t implicit_sid; /* Dataspace ID for chunked dataset */ + hid_t fa_sid; /* Dataspace ID for chunked dataset */ + hid_t ea_sid; /* Dataspace ID for chunked dataset */ + hid_t bt2_sid; /* Dataspace ID for chunked dataset */ } dsets_state_t; /* Initializations for dsets_state_t */ -#define DSETS_INITIALIZER (dsets_state_t) { \ - .compact_did = H5I_INVALID_HID \ - , .compact_sid = H5I_INVALID_HID \ - , .contig_did = H5I_INVALID_HID \ - , .contig_sid = H5I_INVALID_HID \ - , .single_did = H5I_INVALID_HID \ - , .single_sid = H5I_INVALID_HID \ - , .implicit_did = H5I_INVALID_HID \ - , .implicit_sid = H5I_INVALID_HID \ - , .fa_did = H5I_INVALID_HID \ - , .fa_sid = H5I_INVALID_HID \ - , .ea_did = H5I_INVALID_HID \ - , .ea_sid = H5I_INVALID_HID \ - , .bt2_did = H5I_INVALID_HID \ - , .bt2_sid = H5I_INVALID_HID } +#define DSETS_INITIALIZER \ + (dsets_state_t) \ + { \ + .compact_did = H5I_INVALID_HID, .compact_sid = H5I_INVALID_HID, .contig_did = H5I_INVALID_HID, \ + .contig_sid = H5I_INVALID_HID, .single_did = H5I_INVALID_HID, .single_sid = H5I_INVALID_HID, \ + .implicit_did = H5I_INVALID_HID, .implicit_sid = H5I_INVALID_HID, .fa_did = H5I_INVALID_HID, \ + .fa_sid = H5I_INVALID_HID, .ea_did = H5I_INVALID_HID, .ea_sid = H5I_INVALID_HID, \ + .bt2_did = H5I_INVALID_HID, .bt2_sid = H5I_INVALID_HID \ + } /* Structure to hold info for named pipes */ typedef struct { - const char *fifo_writer_to_reader; /* Name of fifo for writer to reader */ - const char *fifo_reader_to_writer; /* Name of fifo for reader to writer */ - int fd_writer_to_reader; /* File ID for fifo from writer to reader */ - int fd_reader_to_writer; /* File ID for fifo from reader to writer */ - int notify; /* Value to notify between writer and reader */ - int verify; /* Value to verify between writer and reader */ + const char *fifo_writer_to_reader; /* Name of fifo for writer to reader */ + const char *fifo_reader_to_writer; /* Name of fifo for reader to writer */ + int fd_writer_to_reader; /* File ID for fifo from writer to reader */ + int fd_reader_to_writer; /* File ID for fifo from reader to writer */ + int notify; /* Value to notify between writer and reader */ + int verify; /* Value to verify between writer and reader */ } np_state_t; /* Initializations for np_state_t */ -#define NP_INITIALIZER (np_state_t) { \ - .fifo_writer_to_reader = "./fifo_dsetops_writer_to_reader" \ - , .fifo_reader_to_writer = "./fifo_dsetops_reader_to_writer" \ - , .fd_writer_to_reader = -1 \ - , .fd_reader_to_writer = -1 \ - , .notify = 0 \ - , .verify = 0 } +#define NP_INITIALIZER \ + (np_state_t) \ + { \ + .fifo_writer_to_reader = "./fifo_dsetops_writer_to_reader", \ + .fifo_reader_to_writer = "./fifo_dsetops_reader_to_writer", .fd_writer_to_reader = -1, \ + .fd_reader_to_writer = -1, .notify = 0, .verify = 0 \ + } static bool state_init(state_t *, int, char **); static bool np_init(np_state_t *np, bool writer); static bool np_close(np_state_t *np, bool writer); -static bool np_writer(bool result, unsigned step, const state_t *s, np_state_t *np, H5F_vfd_swmr_config_t *config); +static bool np_writer(bool result, unsigned step, const state_t *s, np_state_t *np, + H5F_vfd_swmr_config_t *config); static bool np_reader(bool result, unsigned step, const state_t *s, np_state_t *np); static bool np_confirm_verify_notify(int fd, unsigned step, const state_t *s, np_state_t *np); @@ -149,74 +134,74 @@ static bool close_dsets(const dsets_state_t *ds); static bool close_dset_real(hid_t did, hid_t sid); static bool dsets_action(unsigned action, const state_t *s, const dsets_state_t *ds, unsigned step); -static bool dset_setup(unsigned action, unsigned which, const state_t *s, - hsize_t *start, hsize_t *stride, hsize_t *count, hsize_t *block, - hid_t *mem_sid, unsigned int **buf); -static bool write_dset(hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, - hsize_t *start, hsize_t *stride, hsize_t *count, hsize_t *block, unsigned int *buf); +static bool dset_setup(unsigned action, unsigned which, const state_t *s, hsize_t *start, hsize_t *stride, + hsize_t *count, hsize_t *block, hid_t *mem_sid, unsigned int **buf); +static bool write_dset(hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hsize_t *start, hsize_t *stride, + hsize_t *count, hsize_t *block, unsigned int *buf); static bool write_dset_compact(const state_t *s, const dsets_state_t *ds); static bool verify_dsets_action(unsigned action, const state_t *s, const dsets_state_t *ds, unsigned which); -static bool verify_read_dset(hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, - hsize_t *start, hsize_t *stride, hsize_t *count, hsize_t *block, unsigned int *vbuf); +static bool verify_read_dset(hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hsize_t *start, + hsize_t *stride, hsize_t *count, hsize_t *block, unsigned int *vbuf); static bool verify_read_dset_compact(const state_t *s, const dsets_state_t *ds); static const hid_t badhid = H5I_INVALID_HID; /* Names for datasets */ -#define DSET_COMPACT_NAME "compact_dset" -#define DSET_CONTIG_NAME "contig_dset" -#define DSET_SINGLE_NAME "chunked_single" -#define DSET_IMPLICIT_NAME "chunked_implicit" -#define DSET_FA_NAME "chunked_fa" -#define DSET_EA_NAME "chunked_ea" -#define DSET_BT2_NAME "chunked_bt2" +#define DSET_COMPACT_NAME "compact_dset" +#define DSET_CONTIG_NAME "contig_dset" +#define DSET_SINGLE_NAME "chunked_single" +#define DSET_IMPLICIT_NAME "chunked_implicit" +#define DSET_FA_NAME "chunked_fa" +#define DSET_EA_NAME "chunked_ea" +#define DSET_BT2_NAME "chunked_bt2" /* Action for writes */ -#define SEQ_WRITE 1 /* Sequential write */ -#define RANDOM_WRITE 2 /* Random write */ -#define HYPER_WRITE 3 /* Hyperslab write */ -#define MODIFY_DATA 4 /* Modify raw data */ +#define SEQ_WRITE 1 /* Sequential write */ +#define RANDOM_WRITE 2 /* Random write */ +#define HYPER_WRITE 3 /* Hyperslab write */ +#define MODIFY_DATA 4 /* Modify raw data */ /* Test program usage info */ static void usage(const char *progname) { - fprintf(stderr, "usage: %s \n" - " [-p] [-e elmts] [-o]\n" - " [-g] [-k] [-m rows] [-n cols]\n" - " [-s swrites] [-r rwrites] [-l lwrites] [-w writes]\n" - " [-u nticks] [-c csteps] [-S] [-N] [-q] [-b]\n" - "\n" - "-p: create a dataset with compact layout\n" - "-e elmts: # of for the compact dataset\n" - " (default is 16380)\n" - "-t: perform write to the compact dataset\n" - "-g: create a dataset with contiguous layout\n" - "-k: create 5 datasets with chunked layout for the 5 indexing types\n" - "-m rows: # of rows for the contiguous and/or chunked datasets\n" - "-n cols: # of columns for the contiguous and/or chunked datasets\n" - "-s swrites: perform sequential writes to all datasets\n" - "-r rwrites: perform random writes to all datasets\n" - "-l lwrites: perform hyperslab writes to all datasets\n" - " # of rows to write: every other element is selected per row\n" - "-w wwrites: perform raw data modifications to all datasets\n" - "-u nticks: `nticks` ticks for the reader to wait before verification\n" - " (default is 4)\n" - "-c csteps: `csteps` steps communication interval between reader and writer\n" - " (default is 1)\n" - "-S: do not use VFD SWMR\n" - "-N: do not use named pipes for test synchronization\n" - "-q: silence printouts, few messages\n" - "-b: write data in big-endian byte order\n" - " (default is H5T_NATIVE_UINT32)\n\n" - "Note:\n" - "1. Require to specify at least -p, -g or -k option\n" - "2. -c option cannot exceed -s or -r \n" - " or -l or -w option\n" - "\n", - progname); - exit(EXIT_FAILURE); + fprintf(stderr, + "usage: %s \n" + " [-p] [-e elmts] [-o]\n" + " [-g] [-k] [-m rows] [-n cols]\n" + " [-s swrites] [-r rwrites] [-l lwrites] [-w writes]\n" + " [-u nticks] [-c csteps] [-S] [-N] [-q] [-b]\n" + "\n" + "-p: create a dataset with compact layout\n" + "-e elmts: # of for the compact dataset\n" + " (default is 16380)\n" + "-t: perform write to the compact dataset\n" + "-g: create a dataset with contiguous layout\n" + "-k: create 5 datasets with chunked layout for the 5 indexing types\n" + "-m rows: # of rows for the contiguous and/or chunked datasets\n" + "-n cols: # of columns for the contiguous and/or chunked datasets\n" + "-s swrites: perform sequential writes to all datasets\n" + "-r rwrites: perform random writes to all datasets\n" + "-l lwrites: perform hyperslab writes to all datasets\n" + " # of rows to write: every other element is selected per row\n" + "-w wwrites: perform raw data modifications to all datasets\n" + "-u nticks: `nticks` ticks for the reader to wait before verification\n" + " (default is 4)\n" + "-c csteps: `csteps` steps communication interval between reader and writer\n" + " (default is 1)\n" + "-S: do not use VFD SWMR\n" + "-N: do not use named pipes for test synchronization\n" + "-q: silence printouts, few messages\n" + "-b: write data in big-endian byte order\n" + " (default is H5T_NATIVE_UINT32)\n\n" + "Note:\n" + "1. Require to specify at least -p, -g or -k option\n" + "2. -c option cannot exceed -s or -r \n" + " or -l or -w option\n" + "\n", + progname); + exit(EXIT_FAILURE); } /* usage() */ /* @@ -226,9 +211,9 @@ static bool state_init(state_t *s, int argc, char **argv) { unsigned long tmp; - int ch; - char tfile[PATH_MAX]; - char *end; + int ch; + char tfile[PATH_MAX]; + char * end; *s = ALL_HID_INITIALIZER; esnprintf(tfile, sizeof(tfile), "%s", argv[0]); @@ -237,129 +222,131 @@ state_init(state_t *s, int argc, char **argv) while ((ch = getopt(argc, argv, "pte:gkm:n:s:r:l:w:bqSNu:c:")) != -1) { switch (ch) { - case 'p': /* compact dataset */ - s->compact = true; - break; - - case 't': /* compact write */ - s->compact_write = true; - break; - - case 'g': /* contiguous dataset */ - s->contig = true; - break; - - case 'k': /* chunked datasets */ - s->chunked = true; - break; - - case 'q': - verbosity = 0; - break; - - case 'b': - s->filetype = H5T_STD_U32BE; - break; - - case 'S': - s->use_vfd_swmr = false; - break; - - case 'N': - s->use_np = false; - break; - - case 'e': /* # of elements for compact dataset */ - case 'm': /* # of rows for -g and/or -k */ - case 'n': /* # of cols for -g and/or -k */ - case 's': /* # of sequential writes for -g and/or -k */ - case 'r': /* # of random writes for -g and/or -k */ - case 'l': /* # of hyperslab writes for -g and/or -k */ - case 'w': /* # of raw data modifications for -g and/or -k */ - case 'u': /* ticks for raeder to wait before verification */ - case 'c': /* communication interval */ - errno = 0; - tmp = strtoul(optarg, &end, 0); - if (end == optarg || *end != '\0') { - printf("couldn't parse `-%c` argument `%s`\n", ch, optarg); - TEST_ERROR; - } else if (errno != 0) { - printf("couldn't parse `-%c` argument `%s`\n", ch, optarg); - TEST_ERROR; - } else if (tmp > UINT_MAX) { - printf("`-%c` argument `%lu` too large\n", ch, tmp); - TEST_ERROR; - } - - if (ch == 'e') - s->compact_elmts = (unsigned)tmp; - else if (ch == 'm') - s->rows = (unsigned)tmp; - else if (ch == 'n') - s->cols = (unsigned)tmp; - else if (ch == 's') - s->swrites = (unsigned)tmp; - else if (ch == 'r') - s->rwrites = (unsigned)tmp; - else if (ch == 'l') - s->lwrites = (unsigned)tmp; - else if (ch == 'w') - s->wwrites = (unsigned)tmp; - else if (ch == 'u') - s->update_interval = (unsigned)tmp; - else if (ch == 'c') - s->csteps = (unsigned)tmp; - - break; + case 'p': /* compact dataset */ + s->compact = true; + break; + + case 't': /* compact write */ + s->compact_write = true; + break; + + case 'g': /* contiguous dataset */ + s->contig = true; + break; + + case 'k': /* chunked datasets */ + s->chunked = true; + break; + + case 'q': + verbosity = 0; + break; + + case 'b': + s->filetype = H5T_STD_U32BE; + break; + + case 'S': + s->use_vfd_swmr = false; + break; + + case 'N': + s->use_np = false; + break; + + case 'e': /* # of elements for compact dataset */ + case 'm': /* # of rows for -g and/or -k */ + case 'n': /* # of cols for -g and/or -k */ + case 's': /* # of sequential writes for -g and/or -k */ + case 'r': /* # of random writes for -g and/or -k */ + case 'l': /* # of hyperslab writes for -g and/or -k */ + case 'w': /* # of raw data modifications for -g and/or -k */ + case 'u': /* ticks for raeder to wait before verification */ + case 'c': /* communication interval */ + errno = 0; + tmp = strtoul(optarg, &end, 0); + if (end == optarg || *end != '\0') { + printf("couldn't parse `-%c` argument `%s`\n", ch, optarg); + TEST_ERROR; + } + else if (errno != 0) { + printf("couldn't parse `-%c` argument `%s`\n", ch, optarg); + TEST_ERROR; + } + else if (tmp > UINT_MAX) { + printf("`-%c` argument `%lu` too large\n", ch, tmp); + TEST_ERROR; + } - case '?': - default: - usage(s->progname); - break; + if (ch == 'e') + s->compact_elmts = (unsigned)tmp; + else if (ch == 'm') + s->rows = (unsigned)tmp; + else if (ch == 'n') + s->cols = (unsigned)tmp; + else if (ch == 's') + s->swrites = (unsigned)tmp; + else if (ch == 'r') + s->rwrites = (unsigned)tmp; + else if (ch == 'l') + s->lwrites = (unsigned)tmp; + else if (ch == 'w') + s->wwrites = (unsigned)tmp; + else if (ch == 'u') + s->update_interval = (unsigned)tmp; + else if (ch == 'c') + s->csteps = (unsigned)tmp; + + break; + + case '?': + default: + usage(s->progname); + break; } } argc -= optind; argv += optind; /* Require to specify at least -p or -g or -k option */ - if(!s->compact && !s->contig &&!s->chunked) { + if (!s->compact && !s->contig && !s->chunked) { printf("Require to specify at least -p or -g or -k option\n"); usage(s->progname); goto error; } /* -e */ - if(s->compact_elmts > MAX_COMPACT_ELMS) { + if (s->compact_elmts > MAX_COMPACT_ELMS) { printf("size of compact dataset cannot exceed 16380 elements\n"); TEST_ERROR; } /* -c cannot be zero */ - if(!s->csteps) { + if (!s->csteps) { printf("communication interval cannot be zero\n"); TEST_ERROR; } /* -c and -s options */ - if(s->swrites && s->csteps > s->swrites) { + if (s->swrites && s->csteps > s->swrites) { printf("communication interval with sequential writes is out of bounds\n"); TEST_ERROR; } /* -c and -r options */ - if(s->rwrites && s->csteps > s->rwrites) { + if (s->rwrites && s->csteps > s->rwrites) { printf("communication interval with random writes is out of bounds\n"); TEST_ERROR; } /* -c and -l options */ - if(s->lwrites && s->csteps > s->lwrites) { + if (s->lwrites && s->csteps > s->lwrites) { printf("communication interval with hyperslab writes is out of bounds\n"); TEST_ERROR; } /* -c and -w options */ - if(s->wwrites && s->csteps > s->wwrites) { + if (s->wwrites && s->csteps > s->wwrites) { printf("communication interval with raw data modification is out of bounds\n"); TEST_ERROR; } @@ -386,26 +373,26 @@ create_dsets(const state_t *s, dsets_state_t *ds) *ds = DSETS_INITIALIZER; /* Create the named datatype that will be used by compact and contiguous datasets */ - if((dtid = H5Tcopy(s->filetype)) < 0) { - printf("H5Tcopy failed\n"); - TEST_ERROR; + if ((dtid = H5Tcopy(s->filetype)) < 0) { + printf("H5Tcopy failed\n"); + TEST_ERROR; } - if(H5Tcommit2(s->file, "named_dtype", dtid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) < 0) { - printf("H5Tcommit2 failed\n"); - TEST_ERROR; + if (H5Tcommit2(s->file, "named_dtype", dtid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) < 0) { + printf("H5Tcommit2 failed\n"); + TEST_ERROR; } /* Dataset with compact layout, 1d, named datatype */ - if(s->compact) { + if (s->compact) { hsize_t dims[1]; - hid_t sid; + hid_t sid; - if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) { + if ((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) { printf("H5Pcreate failed\n"); TEST_ERROR; } - if(H5Pset_layout(dcpl, H5D_COMPACT) < 0) { + if (H5Pset_layout(dcpl, H5D_COMPACT) < 0) { printf("H5Pset_layout failed\n"); TEST_ERROR; } @@ -419,22 +406,22 @@ create_dsets(const state_t *s, dsets_state_t *ds) } /* Create the compact dataset with named datatype */ - if((ds->compact_did = H5Dcreate2(s->file, DSET_COMPACT_NAME, dtid, - ds->compact_sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) { + if ((ds->compact_did = H5Dcreate2(s->file, DSET_COMPACT_NAME, dtid, ds->compact_sid, H5P_DEFAULT, + dcpl, H5P_DEFAULT)) < 0) { printf("H5Dcreate2 compact dataset failed\n"); TEST_ERROR; } - if(H5Pclose(dcpl) < 0) { + if (H5Pclose(dcpl) < 0) { printf("H5Pclose failed\n"); TEST_ERROR; } } /* Dataset with contiguous layout, 2d, named datatype */ - if(s->contig) { - hsize_t dims[2]; - hid_t sid; + if (s->contig) { + hsize_t dims[2]; + hid_t sid; unsigned i; dims[0] = s->rows; @@ -446,50 +433,50 @@ create_dsets(const state_t *s, dsets_state_t *ds) TEST_ERROR; } - if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) { + if ((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) { printf("H5Pcreate failed\n"); TEST_ERROR; } - if(H5Pset_layout(dcpl, H5D_CONTIGUOUS) < 0) { + if (H5Pset_layout(dcpl, H5D_CONTIGUOUS) < 0) { printf("H5Pset_layout failed\n"); TEST_ERROR; } /* Create the contiguous dataset with the named datatype */ - if((ds->contig_did = H5Dcreate2(s->file, DSET_CONTIG_NAME, dtid, - ds->contig_sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) { + if ((ds->contig_did = H5Dcreate2(s->file, DSET_CONTIG_NAME, dtid, ds->contig_sid, H5P_DEFAULT, dcpl, + H5P_DEFAULT)) < 0) { printf("H5Dcreate2 contiguous dataset failed\n"); TEST_ERROR; } - if(H5Pclose(dcpl) < 0) { + if (H5Pclose(dcpl) < 0) { printf("H5Pclose failed\n"); TEST_ERROR; } } /* Dataset with chunked layout, 2d, named datatype */ - if(s->chunked) { - hsize_t dims[2]; - hsize_t max_dims[2]; - hsize_t chunk_dims[2]; - hid_t sid; + if (s->chunked) { + hsize_t dims[2]; + hsize_t max_dims[2]; + hsize_t chunk_dims[2]; + hid_t sid; unsigned i; dims[0] = s->rows; dims[1] = s->cols; /* Default chunk size is 2x2 unless s->rows or s->cols indicates otherwise */ - chunk_dims[0] = MAX(1, s->rows/2); - chunk_dims[1] = MAX(1, s->cols/2); + chunk_dims[0] = MAX(1, s->rows / 2); + chunk_dims[1] = MAX(1, s->cols / 2); - if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) { + if ((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) { printf("H5Pcreate failed\n"); TEST_ERROR; } - if(H5Pset_layout(dcpl, H5D_CHUNKED) < 0) { + if (H5Pset_layout(dcpl, H5D_CHUNKED) < 0) { printf("H5Pset_layout failed\n"); TEST_ERROR; } @@ -497,7 +484,7 @@ create_dsets(const state_t *s, dsets_state_t *ds) /* Create 2-D chunked dataset with single index */ /* Chunked, dims=max_dims=chunk_dims */ - if(H5Pset_chunk(dcpl, 2, dims) < 0) { + if (H5Pset_chunk(dcpl, 2, dims) < 0) { printf("H5Pset_chunk failed\n"); TEST_ERROR; } @@ -508,8 +495,8 @@ create_dsets(const state_t *s, dsets_state_t *ds) } /* Create the chunked dataset (single index) with the named datatype */ - if((ds->single_did = H5Dcreate2(s->file, DSET_SINGLE_NAME, dtid, - ds->single_sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) { + if ((ds->single_did = H5Dcreate2(s->file, DSET_SINGLE_NAME, dtid, ds->single_sid, H5P_DEFAULT, dcpl, + H5P_DEFAULT)) < 0) { printf("H5Dcreate2 chunked dataset:single index failed\n"); TEST_ERROR; } @@ -517,12 +504,12 @@ create_dsets(const state_t *s, dsets_state_t *ds) /* Create 2-D chunked dataset with implicit index */ /* Chunked, dims=max_dims, early allocation */ - if(H5Pset_alloc_time(dcpl, H5D_ALLOC_TIME_EARLY) < 0) { + if (H5Pset_alloc_time(dcpl, H5D_ALLOC_TIME_EARLY) < 0) { printf("H5Pset_alloc_time\n"); TEST_ERROR; } - if(H5Pset_chunk(dcpl, 2, chunk_dims) < 0) { + if (H5Pset_chunk(dcpl, 2, chunk_dims) < 0) { printf("H5Pset_chunk failed\n"); TEST_ERROR; } @@ -533,13 +520,13 @@ create_dsets(const state_t *s, dsets_state_t *ds) } /* Create the chunked dataset (implicit index) with the named datatype */ - if((ds->implicit_did = H5Dcreate2(s->file, DSET_IMPLICIT_NAME, dtid, - ds->implicit_sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) { + if ((ds->implicit_did = H5Dcreate2(s->file, DSET_IMPLICIT_NAME, dtid, ds->implicit_sid, H5P_DEFAULT, + dcpl, H5P_DEFAULT)) < 0) { printf("H5Dcreate2 chunked dataset:implicit index failed\n"); TEST_ERROR; } - if(H5Pclose(dcpl) < 0) { + if (H5Pclose(dcpl) < 0) { printf("H5Pclose failed\n"); TEST_ERROR; } @@ -547,12 +534,12 @@ create_dsets(const state_t *s, dsets_state_t *ds) /* Create 2-D chunked dataset with fixed array index */ /* Chunked, fixed max_dims */ - if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) { + if ((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) { printf("H5Pcreate failed\n"); TEST_ERROR; } - if(H5Pset_chunk(dcpl, 2, chunk_dims) < 0) { + if (H5Pset_chunk(dcpl, 2, chunk_dims) < 0) { printf("H5Pset_chunk failed\n"); TEST_ERROR; } @@ -560,14 +547,14 @@ create_dsets(const state_t *s, dsets_state_t *ds) max_dims[0] = dims[0] + 10; max_dims[1] = dims[1] + 10; - if((ds->fa_sid = H5Screate_simple(2, dims, max_dims)) < 0) { + if ((ds->fa_sid = H5Screate_simple(2, dims, max_dims)) < 0) { printf("H5Screate_simple failed\n"); TEST_ERROR; } /* Create the chunked dataset (fixed array index) with the named datatype */ - if((ds->fa_did = H5Dcreate2(s->file, DSET_FA_NAME, dtid, - ds->fa_sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) { + if ((ds->fa_did = + H5Dcreate2(s->file, DSET_FA_NAME, dtid, ds->fa_sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) { printf("H5Dcreaet2 chunked dataset: fa index failed\n"); TEST_ERROR; } @@ -576,14 +563,14 @@ create_dsets(const state_t *s, dsets_state_t *ds) /* Chunked, 1 unlimited max_dims */ max_dims[1] = H5S_UNLIMITED; - if((ds->ea_sid = H5Screate_simple(2, dims, max_dims)) < 0) { + if ((ds->ea_sid = H5Screate_simple(2, dims, max_dims)) < 0) { printf("H5Screate_simple failed\n"); TEST_ERROR; } /* Create the chunked dataset (extensible array index) with the named datatype */ - if((ds->ea_did = H5Dcreate2(s->file, DSET_EA_NAME, dtid, - ds->ea_sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) { + if ((ds->ea_did = + H5Dcreate2(s->file, DSET_EA_NAME, dtid, ds->ea_sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) { printf("H5Dcreate2 chunked dataset: ea index failed\n"); TEST_ERROR; } @@ -592,26 +579,25 @@ create_dsets(const state_t *s, dsets_state_t *ds) /* Chunked, 2 unlimited max_dims */ max_dims[0] = H5S_UNLIMITED; - if((ds->bt2_sid = H5Screate_simple(2, dims, max_dims)) < 0) { + if ((ds->bt2_sid = H5Screate_simple(2, dims, max_dims)) < 0) { printf("H5Screate_simple failed\n"); TEST_ERROR; } /* Create the chunked dataset (btree2 index) with the named datatype */ - if((ds->bt2_did = H5Dcreate2(s->file, DSET_BT2_NAME, dtid, - ds->bt2_sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) { + if ((ds->bt2_did = + H5Dcreate2(s->file, DSET_BT2_NAME, dtid, ds->bt2_sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) { printf("H5Dcreate2 chunked dataset: bt2 index failed\n"); TEST_ERROR; } - if(H5Pclose(dcpl) < 0) { + if (H5Pclose(dcpl) < 0) { printf("H5Pclose failed\n"); TEST_ERROR; } - } - if(H5Tclose(dtid) < 0) { + if (H5Tclose(dtid) < 0) { printf("H5Tclose failed\n"); TEST_ERROR; } @@ -619,7 +605,8 @@ create_dsets(const state_t *s, dsets_state_t *ds) return true; error: - H5E_BEGIN_TRY { + H5E_BEGIN_TRY + { H5Pclose(dcpl); H5Tclose(dtid); H5Sclose(ds->compact_sid); @@ -636,13 +623,14 @@ error: H5Dclose(ds->fa_did); H5Dclose(ds->ea_did); H5Dclose(ds->bt2_did); - } H5E_END_TRY; + } + H5E_END_TRY; return false; } /* create_dsets() */ -/* +/* * Open the datasets as specified. */ static bool @@ -650,46 +638,46 @@ open_dsets(const state_t *s, dsets_state_t *ds) { *ds = DSETS_INITIALIZER; - if(s->compact) { - if(!open_dset_real(s, &ds->compact_did, &ds->compact_sid, DSET_COMPACT_NAME)) { + if (s->compact) { + if (!open_dset_real(s, &ds->compact_did, &ds->compact_sid, DSET_COMPACT_NAME)) { printf("open_dset_real() for compact dataset failed\n"); TEST_ERROR; } } - if(s->contig) { + if (s->contig) { hsize_t dims[2]; - if(!open_dset_real(s, &ds->contig_did, &ds->contig_sid, DSET_CONTIG_NAME)) { + if (!open_dset_real(s, &ds->contig_did, &ds->contig_sid, DSET_CONTIG_NAME)) { printf("open_dset_real() for contiguous dataset failed\n"); TEST_ERROR; } } - if(s->chunked) { + if (s->chunked) { hsize_t dims[2]; - if(!open_dset_real(s, &ds->single_did, &ds->single_sid, DSET_SINGLE_NAME)) { + if (!open_dset_real(s, &ds->single_did, &ds->single_sid, DSET_SINGLE_NAME)) { printf("open_dset_real() for chunked dataset: single index failed\n"); TEST_ERROR; } - if(!open_dset_real(s, &ds->implicit_did, &ds->implicit_sid, DSET_IMPLICIT_NAME)) { + if (!open_dset_real(s, &ds->implicit_did, &ds->implicit_sid, DSET_IMPLICIT_NAME)) { printf("open_dset_real() for chunked dataset: implicit index failed\n"); TEST_ERROR; } - if(!open_dset_real(s, &ds->fa_did, &ds->fa_sid, DSET_FA_NAME)) { + if (!open_dset_real(s, &ds->fa_did, &ds->fa_sid, DSET_FA_NAME)) { printf("open_dset_real() for chunked dataset: fa index failed\n"); TEST_ERROR; } - if(!open_dset_real(s, &ds->ea_did, &ds->ea_sid, DSET_EA_NAME)) { + if (!open_dset_real(s, &ds->ea_did, &ds->ea_sid, DSET_EA_NAME)) { printf("open_dset_real() for chunked dataset: ea index failed\n"); TEST_ERROR; } - if(!open_dset_real(s, &ds->bt2_did, &ds->bt2_sid, DSET_BT2_NAME)) { + if (!open_dset_real(s, &ds->bt2_did, &ds->bt2_sid, DSET_BT2_NAME)) { printf("open_dset_real() for chunked dataset: bt2 index failed\n"); TEST_ERROR; } @@ -709,7 +697,7 @@ error: static bool open_dset_real(const state_t *s, hid_t *did, hid_t *sid, const char *name) { - hid_t dcpl = badhid; + hid_t dcpl = badhid; hsize_t dims[2]; if ((*did = H5Dopen2(s->file, name, H5P_DEFAULT)) < 0) { @@ -725,9 +713,10 @@ open_dset_real(const state_t *s, hid_t *did, hid_t *sid, const char *name) TEST_ERROR; if (!HDstrcmp(name, DSET_COMPACT_NAME)) { - if(dims[0] != s->compact_elmts) + if (dims[0] != s->compact_elmts) TEST_ERROR; - } else { /* contiguous or chunked dataset */ + } + else { /* contiguous or chunked dataset */ if (dims[0] != s->rows) TEST_ERROR; if (dims[1] != s->cols) @@ -737,10 +726,12 @@ open_dset_real(const state_t *s, hid_t *did, hid_t *sid, const char *name) return true; error: - H5E_BEGIN_TRY { + H5E_BEGIN_TRY + { H5Dclose(*did); H5Dclose(*sid); - } H5E_END_TRY; + } + H5E_END_TRY; return false; } /* open_dset_real() */ @@ -751,37 +742,37 @@ error: static bool close_dsets(const dsets_state_t *ds) { - if(!close_dset_real(ds->compact_did, ds->compact_sid)) { + if (!close_dset_real(ds->compact_did, ds->compact_sid)) { printf("H5Dclose compact dataset failed\n"); TEST_ERROR; } - if(!close_dset_real(ds->contig_did, ds->contig_sid)) { + if (!close_dset_real(ds->contig_did, ds->contig_sid)) { printf("H5Dclose contiguous dataset failed\n"); TEST_ERROR; } - if(!close_dset_real(ds->single_did, ds->single_sid)) { + if (!close_dset_real(ds->single_did, ds->single_sid)) { printf("H5Dclose chunked dataset: single index failed\n"); TEST_ERROR; } - if(!close_dset_real(ds->implicit_did, ds->implicit_sid)) { + if (!close_dset_real(ds->implicit_did, ds->implicit_sid)) { printf("H5Dclose chunked dataset: implicit index failed\n"); TEST_ERROR; } - if(!close_dset_real(ds->fa_did, ds->fa_sid)) { + if (!close_dset_real(ds->fa_did, ds->fa_sid)) { printf("H5Dclose chunked dataset: fa index failed\n"); TEST_ERROR; } - if(!close_dset_real(ds->ea_did, ds->ea_sid)) { + if (!close_dset_real(ds->ea_did, ds->ea_sid)) { printf("H5Dclose chunked dataset: ea index failed\n"); TEST_ERROR; } - if(!close_dset_real(ds->bt2_did, ds->bt2_sid)) { + if (!close_dset_real(ds->bt2_did, ds->bt2_sid)) { printf("H5Dclose chunked dataset: bt2 index failed\n"); TEST_ERROR; } @@ -799,12 +790,12 @@ error: static bool close_dset_real(hid_t did, hid_t sid) { - if(did != badhid && H5Dclose(did) < 0) { + if (did != badhid && H5Dclose(did) < 0) { printf("H5Dclose dataset failed\n"); TEST_ERROR; } - if(sid != badhid && H5Sclose(sid) < 0) { + if (sid != badhid && H5Sclose(sid) < 0) { printf("H5Sclose dataspace for dataset failed\n"); TEST_ERROR; } @@ -812,10 +803,12 @@ close_dset_real(hid_t did, hid_t sid) return true; error: - H5E_BEGIN_TRY { + H5E_BEGIN_TRY + { H5Dclose(did); H5Sclose(sid); - } H5E_END_TRY; + } + H5E_END_TRY; return false; } /* close_dset_real() */ @@ -824,7 +817,6 @@ error: * Writer */ - /* * Perform the "action" for each of the datasets specified on the command line: * SEQ_WRITE: perform `which` sequential write @@ -832,69 +824,74 @@ error: * HYPER_WRITE: perform `which` hyperslab write * MODIFY_DATA: perform `which` raw data modification */ -static bool +static bool dsets_action(unsigned action, const state_t *s, const dsets_state_t *ds, unsigned which) { - int nerrors = 0; - bool ret = false; - hsize_t dims[2]; - hsize_t start[2]; - hsize_t stride[2]; - hsize_t count[2]; - hsize_t block[2]; - hid_t mem_sid; - unsigned kk, i; + int nerrors = 0; + bool ret = false; + hsize_t dims[2]; + hsize_t start[2]; + hsize_t stride[2]; + hsize_t count[2]; + hsize_t block[2]; + hid_t mem_sid; + unsigned kk, i; unsigned int *wbuf = NULL; /* Set up selection, dataspace and data buffer according to the specified action */ - if(!dset_setup(action, which, s, start, stride, count, block, &mem_sid, &wbuf)) { + if (!dset_setup(action, which, s, start, stride, count, block, &mem_sid, &wbuf)) { printf("dset_setup() failed\n"); TEST_ERROR; } /* Write to the contiguous dataset */ - if(s->contig) { + if (s->contig) { - if(!write_dset(ds->contig_did, s->filetype, mem_sid, ds->contig_sid, start, stride, count, block, wbuf)) { + if (!write_dset(ds->contig_did, s->filetype, mem_sid, ds->contig_sid, start, stride, count, block, + wbuf)) { printf("H5Dwrite to contiguous dataset failed\n"); TEST_ERROR; } } /* Write to the 5 chunked datasets */ - if(s->chunked) { + if (s->chunked) { - if(!write_dset(ds->single_did, s->filetype, mem_sid, ds->single_sid, start, stride, count, block, wbuf)) { + if (!write_dset(ds->single_did, s->filetype, mem_sid, ds->single_sid, start, stride, count, block, + wbuf)) { printf("H5Dwrite to chunked dataset: single index dataset failed\n"); TEST_ERROR; } - if(!write_dset(ds->implicit_did, s->filetype, mem_sid, ds->implicit_sid, start, stride, count, block, wbuf)) { + if (!write_dset(ds->implicit_did, s->filetype, mem_sid, ds->implicit_sid, start, stride, count, block, + wbuf)) { printf("H5Dwrite to chunked dataset: implicit index dataset failed\n"); TEST_ERROR; } - if(!write_dset(ds->fa_did, s->filetype, mem_sid, ds->fa_sid, start, stride, count, block, wbuf)) { + if (!write_dset(ds->fa_did, s->filetype, mem_sid, ds->fa_sid, start, stride, count, block, wbuf)) { printf("H5Dwrite to chunked dataset: fa index dataset failed\n"); TEST_ERROR; } - if(!write_dset(ds->ea_did, s->filetype, mem_sid, ds->ea_sid, start, stride, count, block, wbuf)) { + if (!write_dset(ds->ea_did, s->filetype, mem_sid, ds->ea_sid, start, stride, count, block, wbuf)) { printf("H5Dwrite to chunked dataset: ea index dataset failed\n"); TEST_ERROR; } - if(!write_dset(ds->bt2_did, s->filetype, mem_sid, ds->bt2_sid, start, stride, count, block, wbuf)) { + if (!write_dset(ds->bt2_did, s->filetype, mem_sid, ds->bt2_sid, start, stride, count, block, wbuf)) { printf("H5Dwrite to chunked dataset: bt2 index dataset failed\n"); TEST_ERROR; } } - if(wbuf) HDfree(wbuf); + if (wbuf) + HDfree(wbuf); return true; error: - if(wbuf) HDfree(wbuf); + if (wbuf) + HDfree(wbuf); return false; } /* dsets_action() */ @@ -905,12 +902,11 @@ error: * Initialize the data buffer */ static bool -dset_setup(unsigned action, unsigned which, const state_t *s, - hsize_t *start, hsize_t *stride, hsize_t *count, hsize_t *block, - hid_t *mem_sid, unsigned int **buf) +dset_setup(unsigned action, unsigned which, const state_t *s, hsize_t *start, hsize_t *stride, hsize_t *count, + hsize_t *block, hid_t *mem_sid, unsigned int **buf) { - hsize_t mem_dims[1]; - unsigned kk, i; + hsize_t mem_dims[1]; + unsigned kk, i; unsigned int *tmp_buf; start[0] = which / s->cols; @@ -919,24 +915,24 @@ dset_setup(unsigned action, unsigned which, const state_t *s, /* For SEQ_WRITE, RANDOM_WRITE, MODIFY_DATA: writing 1 element at a time */ /* For HYPER_WRITE: writing 1 row at a time: selecting every other element per row */ - switch(action) { - case SEQ_WRITE: - case RANDOM_WRITE: - case MODIFY_DATA: + switch (action) { + case SEQ_WRITE: + case RANDOM_WRITE: + case MODIFY_DATA: count[0] = count[1] = 1; stride[0] = stride[1] = 1; - mem_dims[0] = 1; - *mem_sid = H5Screate_simple(1, mem_dims, NULL); + mem_dims[0] = 1; + *mem_sid = H5Screate_simple(1, mem_dims, NULL); break; - case HYPER_WRITE: - count[0] = 1; - count[1] = MAX(1, s->cols/2); + case HYPER_WRITE: + count[0] = 1; + count[1] = MAX(1, s->cols / 2); stride[0] = 1; stride[1] = 2; mem_dims[0] = count[1]; - *mem_sid = H5Screate_simple(1, mem_dims, NULL); + *mem_sid = H5Screate_simple(1, mem_dims, NULL); break; default: @@ -944,26 +940,26 @@ dset_setup(unsigned action, unsigned which, const state_t *s, } /* end switch */ /* Allocating the buffer for writing */ - if((tmp_buf = HDmalloc(count[1] * sizeof(unsigned int))) == NULL) { + if ((tmp_buf = HDmalloc(count[1] * sizeof(unsigned int))) == NULL) { printf("HDmalloc failed\n"); TEST_ERROR; } /* Initialize the data in the buffer */ - switch(action) { - case SEQ_WRITE: + switch (action) { + case SEQ_WRITE: tmp_buf[0] = which + 1; break; - case RANDOM_WRITE: + case RANDOM_WRITE: tmp_buf[0] = 777; break; - case MODIFY_DATA: + case MODIFY_DATA: tmp_buf[0] = 999; break; - case HYPER_WRITE: + case HYPER_WRITE: kk = which + 1; for (i = 0; i < count[1]; i++) { tmp_buf[i] = kk; @@ -987,17 +983,17 @@ error: /* * Make the selection and then write to the dataset. */ -static bool -write_dset(hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, - hsize_t *start, hsize_t *stride, hsize_t *count, hsize_t *block, unsigned int *buf) +static bool +write_dset(hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hsize_t *start, hsize_t *stride, + hsize_t *count, hsize_t *block, unsigned int *buf) { - - if(H5Sselect_hyperslab(file_sid, H5S_SELECT_SET, start, stride, count, block) < 0) { + + if (H5Sselect_hyperslab(file_sid, H5S_SELECT_SET, start, stride, count, block) < 0) { printf("H5Sselect to dataset failed\n"); TEST_ERROR; } - if(H5Dwrite(did, tid, mem_sid, file_sid, H5P_DEFAULT, buf) < 0) { + if (H5Dwrite(did, tid, mem_sid, file_sid, H5P_DEFAULT, buf) < 0) { printf("H5Dwrite to dataset failed\n"); TEST_ERROR; } @@ -1016,9 +1012,9 @@ static bool write_dset_compact(const state_t *s, const dsets_state_t *ds) { unsigned int *buf = NULL; - unsigned i; + unsigned i; - if((buf = HDmalloc(s->compact_elmts * sizeof(unsigned int))) == NULL) { + if ((buf = HDmalloc(s->compact_elmts * sizeof(unsigned int))) == NULL) { printf("HDmalloc buffer for compact dataset failed\n"); goto error; } @@ -1026,27 +1022,27 @@ write_dset_compact(const state_t *s, const dsets_state_t *ds) for (i = 0; i < s->compact_elmts; i++) buf[i] = i + 1; - if(H5Dwrite(ds->compact_did, s->filetype, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) { + if (H5Dwrite(ds->compact_did, s->filetype, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) { printf("H5Dwrite to compact dataset failed\n"); TEST_ERROR; } - if(buf) HDfree(buf); + if (buf) + HDfree(buf); return true; error: - if(buf) HDfree(buf); + if (buf) + HDfree(buf); return false; } /* write_dset_compact() */ -/* +/* * Reader */ - - -/* +/* * Verify the data read from each of the datasets specified on the command line * according to "action": * SEQ_WRITE: `which` sequential write @@ -1054,71 +1050,79 @@ error: * HYPER_WRITE: `which` hyperslab write * MODIFY_DATA: `which` raw data modification */ -static bool +static bool verify_dsets_action(unsigned action, const state_t *s, const dsets_state_t *ds, unsigned which) { - int nerrors = 0; - bool ret = false; - hsize_t dims[2]; - hsize_t start[2]; - hsize_t stride[2]; - hsize_t count[2]; - hsize_t block[2]; - hid_t mem_sid; - unsigned mm; - unsigned kk, i; + int nerrors = 0; + bool ret = false; + hsize_t dims[2]; + hsize_t start[2]; + hsize_t stride[2]; + hsize_t count[2]; + hsize_t block[2]; + hid_t mem_sid; + unsigned mm; + unsigned kk, i; unsigned int *dd; unsigned int *vbuf = NULL; /* Set up selection, dataspace and data buffer according to the specified action */ - if(!dset_setup(action, which, s, start, stride, count, block, &mem_sid, &vbuf)) { + if (!dset_setup(action, which, s, start, stride, count, block, &mem_sid, &vbuf)) { printf("dset_setup() failed\n"); TEST_ERROR; } /* Verify the data read for the contiguous dataset */ - if(s->contig) { - if(!verify_read_dset(ds->contig_did, s->filetype, mem_sid, ds->contig_sid, start, stride, count, block, vbuf)) { + if (s->contig) { + if (!verify_read_dset(ds->contig_did, s->filetype, mem_sid, ds->contig_sid, start, stride, count, + block, vbuf)) { printf("H5Dwrite to contiguous dataset failed\n"); TEST_ERROR; } } /* Verify the data read for the chunked datasets */ - if(s->chunked) { + if (s->chunked) { - if(!verify_read_dset(ds->single_did, s->filetype, mem_sid, ds->single_sid, start, stride, count, block, vbuf)) { + if (!verify_read_dset(ds->single_did, s->filetype, mem_sid, ds->single_sid, start, stride, count, + block, vbuf)) { printf("H5Dwrite to chunked dataset: single index dataset failed\n"); TEST_ERROR; } - if(!verify_read_dset(ds->implicit_did, s->filetype, mem_sid, ds->implicit_sid, start, stride, count, block, vbuf)) { + if (!verify_read_dset(ds->implicit_did, s->filetype, mem_sid, ds->implicit_sid, start, stride, count, + block, vbuf)) { printf("H5Dwrite to chunked dataset: implicit index dataset failed\n"); TEST_ERROR; } - if(!verify_read_dset(ds->fa_did, s->filetype, mem_sid, ds->fa_sid, start, stride, count, block, vbuf)) { + if (!verify_read_dset(ds->fa_did, s->filetype, mem_sid, ds->fa_sid, start, stride, count, block, + vbuf)) { printf("H5Dwrite to chunked dataset: fa index dataset failed\n"); TEST_ERROR; } - if(!verify_read_dset(ds->ea_did, s->filetype, mem_sid, ds->ea_sid, start, stride, count, block, vbuf)) { + if (!verify_read_dset(ds->ea_did, s->filetype, mem_sid, ds->ea_sid, start, stride, count, block, + vbuf)) { printf("H5Dwrite to chunked dataset: ea index dataset failed\n"); TEST_ERROR; } - if(!verify_read_dset(ds->bt2_did, s->filetype, mem_sid, ds->bt2_sid, start, stride, count, block, vbuf)) { + if (!verify_read_dset(ds->bt2_did, s->filetype, mem_sid, ds->bt2_sid, start, stride, count, block, + vbuf)) { printf("H5Dwrite to chunked dataset: bt2 index dataset failed\n"); TEST_ERROR; } } - if(vbuf) HDfree(vbuf); + if (vbuf) + HDfree(vbuf); return true; error: - if(vbuf) HDfree(vbuf); + if (vbuf) + HDfree(vbuf); return false; @@ -1128,53 +1132,54 @@ error: * Verify the data read from the dataset is as expected. * `vbuf` contains the data expected from the read. */ -static bool -verify_read_dset(hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, - hsize_t *start, hsize_t *stride, hsize_t *count, hsize_t *block, unsigned int *vbuf) +static bool +verify_read_dset(hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hsize_t *start, hsize_t *stride, + hsize_t *count, hsize_t *block, unsigned int *vbuf) { unsigned int *rbuf = NULL; - unsigned i; - + unsigned i; + /* Refresh the dataset */ - if(H5Drefresh(did) < 0) { + if (H5Drefresh(did) < 0) { printf("H5Drefresh dataset failed\n"); TEST_ERROR; } /* Allocate the buffer for reading */ - if((rbuf = HDmalloc(count[1] * sizeof(unsigned int))) == NULL) { + if ((rbuf = HDmalloc(count[1] * sizeof(unsigned int))) == NULL) { printf("HDmalloc failed\n"); TEST_ERROR; } /* Make the selection the file dataspace */ - if(H5Sselect_hyperslab(file_sid, H5S_SELECT_SET, start, stride, count, block) < 0) { + if (H5Sselect_hyperslab(file_sid, H5S_SELECT_SET, start, stride, count, block) < 0) { printf("H5Sselect to dataset failed\n"); TEST_ERROR; } /* Read the data from the dataset into `rbuf` */ - if(H5Dread(did, tid, mem_sid, file_sid, H5P_DEFAULT, rbuf) < 0) { + if (H5Dread(did, tid, mem_sid, file_sid, H5P_DEFAULT, rbuf) < 0) { printf("H5Dread from dataset failed\n"); TEST_ERROR; } - + /* Verify the data read in `rbuf` is as `vbuf` */ for (i = 0; i < count[1]; i++) - if(rbuf[i] != vbuf[i]) + if (rbuf[i] != vbuf[i]) TEST_ERROR; - if(rbuf) HDfree(rbuf); + if (rbuf) + HDfree(rbuf); return true; error: - if(rbuf) HDfree(rbuf); + if (rbuf) + HDfree(rbuf); return false; } /* verify_read_dset() */ - /* * Verify that the data read from the compact dataset is as unexpected. */ @@ -1182,30 +1187,32 @@ static bool verify_read_dset_compact(const state_t *s, const dsets_state_t *ds) { unsigned int *vbuf, *rbuf; - unsigned i; + unsigned i; - if((rbuf = HDmalloc(s->compact_elmts * sizeof(unsigned int))) == NULL) { + if ((rbuf = HDmalloc(s->compact_elmts * sizeof(unsigned int))) == NULL) { printf("HDmalloc buffer for compact dataset failed\n"); goto error; } - if(H5Dread(ds->compact_did, s->filetype, H5S_ALL, H5S_ALL, H5P_DEFAULT, rbuf) < 0) { + if (H5Dread(ds->compact_did, s->filetype, H5S_ALL, H5S_ALL, H5P_DEFAULT, rbuf) < 0) { printf("H5Dwrite to compact dataset failed\n"); TEST_ERROR; } for (i = 0; i < s->compact_elmts; i++) - if(rbuf[i] != (i + 1)) { + if (rbuf[i] != (i + 1)) { printf("Invalid value for compact dataset element\n"); TEST_ERROR; } - if(rbuf) HDfree(rbuf); + if (rbuf) + HDfree(rbuf); return true; error: - if(rbuf) HDfree(rbuf); + if (rbuf) + HDfree(rbuf); return false; } /* verify_read_dset_compact() */ @@ -1222,7 +1229,7 @@ np_init(np_state_t *np, bool writer) { *np = NP_INITIALIZER; - /* + /* * 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. @@ -1231,13 +1238,13 @@ np_init(np_state_t *np, bool writer) if (writer) { /* If the named pipes are present at the start of the test, remove them */ if (HDaccess(np->fifo_writer_to_reader, F_OK) == 0) - if(HDremove(np->fifo_writer_to_reader) != 0) { + if (HDremove(np->fifo_writer_to_reader) != 0) { printf("HDremove fifo_writer_to_reader failed\n"); TEST_ERROR; } if (HDaccess(np->fifo_reader_to_writer, F_OK) == 0) - if(HDremove(np->fifo_reader_to_writer) != 0) { + if (HDremove(np->fifo_reader_to_writer) != 0) { printf("HDremove fifo_reader_to_writer failed\n"); TEST_ERROR; } @@ -1290,13 +1297,13 @@ np_close(np_state_t *np, bool writer) } /* Reader finishes last and deletes the named pipes */ - if(!writer) { - if(HDremove(np->fifo_writer_to_reader) != 0) { + if (!writer) { + if (HDremove(np->fifo_writer_to_reader) != 0) { printf("HDremove fifo_writer_to_reader failed\n"); TEST_ERROR; } - if(HDremove(np->fifo_reader_to_writer) != 0) { + if (HDremove(np->fifo_reader_to_writer) != 0) { printf("HDremove fifo_reader_to_writer failed\n"); TEST_ERROR; } @@ -1311,14 +1318,15 @@ error: * Writer synchronization depending on the result from the attribute action performed. */ static bool -np_writer(bool result, unsigned step, const state_t *s, np_state_t *np, H5F_vfd_swmr_config_t *config) +np_writer(bool result, unsigned step, const state_t *s, np_state_t *np, H5F_vfd_swmr_config_t *config) { unsigned int i; /* The action fails */ - if(!result) { + if (!result) { printf("attribute action failed\n"); - H5_FAILED(); AT(); + H5_FAILED(); + AT(); /* At communication interval, notify the reader about the failure and quit */ if (step % s->csteps == 0) { @@ -1326,8 +1334,9 @@ np_writer(bool result, unsigned step, const state_t *s, np_state_t *np, H5F_vfd HDwrite(np->fd_writer_to_reader, &np->notify, sizeof(int)); goto error; } - /* The action succeeds */ - } else { + /* The action succeeds */ + } + else { /* At communication interval, notify the reader and wait for its response */ if (step % s->csteps == 0) { /* Bump up the value of notify to tell the reader to start reading */ @@ -1339,15 +1348,17 @@ np_writer(bool result, unsigned step, const state_t *s, np_state_t *np, H5F_vfd /* 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++) { + for (i = 0; i < config->max_lag + 1; i++) { decisleep(config->tick_len); - H5E_BEGIN_TRY { + H5E_BEGIN_TRY + { H5Aexists(s->file, "nonexistent"); - } H5E_END_TRY; + } + H5E_END_TRY; } /* Handshake between writer and reader */ - if(!np_confirm_verify_notify(np->fd_reader_to_writer, step, s, np)) { + if (!np_confirm_verify_notify(np->fd_reader_to_writer, step, s, np)) { printf("np_confirm_verify_notify() verify/notify not in sync failed\n"); TEST_ERROR; } @@ -1368,9 +1379,10 @@ static bool np_reader(bool result, unsigned step, const state_t *s, np_state_t *np) { /* The verification fails */ - if(!result) { + if (!result) { printf("verify action failed\n"); - H5_FAILED(); AT(); + H5_FAILED(); + AT(); /* At communication interval, tell the writer about the failure and exit */ if (step % s->csteps == 0) { @@ -1378,8 +1390,9 @@ np_reader(bool result, unsigned step, const state_t *s, np_state_t *np) HDwrite(np->fd_reader_to_writer, &np->notify, sizeof(int)); goto error; } - /* The verification succeeds */ - } else { + /* The verification succeeds */ + } + else { if (step % s->csteps == 0) { /* Send back the same notify value for acknowledgement: * --inform the writer to move to the next step */ @@ -1433,28 +1446,26 @@ error: int main(int argc, char **argv) { - hid_t fapl, fcpl; - unsigned step; - bool writer; - state_t s; - const char *personality; + hid_t fapl, fcpl; + unsigned step; + bool writer; + state_t s; + const char * personality; H5F_vfd_swmr_config_t config; - np_state_t np; - dsets_state_t ds; - bool result; + np_state_t np; + dsets_state_t ds; + bool result; - if(!state_init(&s, argc, argv)) { + if (!state_init(&s, argc, argv)) { printf("state_init() failed\n"); TEST_ERROR; } personality = strstr(s.progname, "vfd_swmr_dsetops_"); - if (personality != NULL && - strcmp(personality, "vfd_swmr_dsetops_writer") == 0) + if (personality != NULL && strcmp(personality, "vfd_swmr_dsetops_writer") == 0) writer = true; - else if (personality != NULL && - strcmp(personality, "vfd_swmr_dsetops_reader") == 0) + else if (personality != NULL && strcmp(personality, "vfd_swmr_dsetops_reader") == 0) writer = false; else { printf("unknown personality, expected vfd_swmr_dsetops_{reader,writer}\n"); @@ -1465,7 +1476,7 @@ main(int argc, char **argv) init_vfd_swmr_config(&config, 4, 7, writer, FALSE, 128, "./dsetops-shadow"); /* use_latest_format, use_vfd_swmr, only_meta_page, config */ - if((fapl = vfd_swmr_create_fapl(true, s.use_vfd_swmr, true, &config)) < 0) { + if ((fapl = vfd_swmr_create_fapl(true, s.use_vfd_swmr, true, &config)) < 0) { printf("vfd_swmr_create_fapl() failed\n"); TEST_ERROR; } @@ -1475,35 +1486,35 @@ main(int argc, char **argv) TEST_ERROR; } - if(H5Pset_file_space_strategy(fcpl, H5F_FSPACE_STRATEGY_PAGE, false, 1) < 0) { + if (H5Pset_file_space_strategy(fcpl, H5F_FSPACE_STRATEGY_PAGE, false, 1) < 0) { printf("H5Pset_file_space_strategy failed\n"); TEST_ERROR; } if (writer) { - if((s.file = H5Fcreate(s.filename, H5F_ACC_TRUNC, fcpl, fapl)) < 0) { + if ((s.file = H5Fcreate(s.filename, H5F_ACC_TRUNC, fcpl, fapl)) < 0) { printf("H5Fcreate failed\n"); TEST_ERROR; } - if(!create_dsets(&s, &ds)) { + if (!create_dsets(&s, &ds)) { printf("create_dsets() failed\n"); TEST_ERROR; } - - } else { - if ((s.file = H5Fopen(s.filename, H5F_ACC_RDONLY, fapl)) < 0) { + } + else { + if ((s.file = H5Fopen(s.filename, H5F_ACC_RDONLY, fapl)) < 0) { printf("H5Fopen failed\n"); TEST_ERROR; } - if(!open_dsets(&s, &ds)) { + if (!open_dsets(&s, &ds)) { printf("open_dsets() failed\n"); TEST_ERROR; } } /* Initiailze named pipes */ - if(s.use_np && !np_init(&np, writer)) { + if (s.use_np && !np_init(&np, writer)) { printf("np_init() failed\n"); TEST_ERROR; } @@ -1511,26 +1522,26 @@ main(int argc, char **argv) if (writer) { /* Perform writes to the whole compact dataset */ - if(s.compact && s.compact_write) { + if (s.compact && s.compact_write) { dbgf(2, "Writes all to compact dataset\n"); result = write_dset_compact(&s, &ds); - if(s.use_np && !np_writer(result, 0, &s, &np, &config)) { + if (s.use_np && !np_writer(result, 0, &s, &np, &config)) { printf("np_writer() for addition failed\n"); TEST_ERROR; } } /* Perform sequential writes for contiguous and/or chunked datasets */ - if((s.contig || s.chunked) && s.swrites) { + if ((s.contig || s.chunked) && s.swrites) { - for (step = 0; (step < s.swrites && step < (s.rows*s.cols)); step++) { + for (step = 0; (step < s.swrites && step < (s.rows * s.cols)); step++) { dbgf(2, "Sequential writes %u to dataset\n", step); result = dsets_action(SEQ_WRITE, &s, &ds, step); - if(s.use_np && !np_writer(result, step, &s, &np, &config)) { + if (s.use_np && !np_writer(result, step, &s, &np, &config)) { printf("np_writer() for sequential writes failed\n"); TEST_ERROR; } @@ -1538,36 +1549,35 @@ main(int argc, char **argv) } /* Perform random writes for contiguous and/or chunked datasets */ - if((s.contig || s.chunked ) && s.rwrites) { + if ((s.contig || s.chunked) && s.rwrites) { unsigned newstep; /* Set up random seed which will be the same for both writer and reader */ HDsrandom(RANDOM_SEED); - for (step = 0; (step < s.rwrites && step < (s.rows*s.cols)); step++) { + for (step = 0; (step < s.rwrites && step < (s.rows * s.cols)); step++) { dbgf(2, "Random writes %u to dataset\n", step); - newstep = HDrandom() % (s.rows*s.cols); + newstep = HDrandom() % (s.rows * s.cols); printf("Random step is %u\n", newstep); result = dsets_action(RANDOM_WRITE, &s, &ds, newstep); - if(s.use_np && !np_writer(result, step, &s, &np, &config)) { + if (s.use_np && !np_writer(result, step, &s, &np, &config)) { printf("np_writer() for random writes failed\n"); TEST_ERROR; } } - } /* Perform hyperslab writes for contiguous and/or chunked datasets */ - if((s.contig || s.chunked) && s.lwrites) { + if ((s.contig || s.chunked) && s.lwrites) { unsigned k; - for (step = 0, k = 0; (step < s.lwrites && k < (s.rows*s.cols)); step++, k+=s.cols) { + for (step = 0, k = 0; (step < s.lwrites && k < (s.rows * s.cols)); step++, k += s.cols) { dbgf(2, "Hyperslab writes %u to dataset\n", step); result = dsets_action(HYPER_WRITE, &s, &ds, k); - if(s.use_np && !np_writer(result, step, &s, &np, &config)) { + if (s.use_np && !np_writer(result, step, &s, &np, &config)) { printf("np_writer() for hyperslab writes failed\n"); TEST_ERROR; } @@ -1575,27 +1585,27 @@ main(int argc, char **argv) } /* Perform raw data modifications for contiguous and/or chunked datasets */ - if((s.contig || s.chunked) && s.wwrites) { + if ((s.contig || s.chunked) && s.wwrites) { - for (step = 0; (step < s.wwrites && step < (s.rows*s.cols)); step++) { + for (step = 0; (step < s.wwrites && step < (s.rows * s.cols)); step++) { dbgf(2, "Modify raw data %u to dataset\n", step); result = dsets_action(MODIFY_DATA, &s, &ds, step); - if(s.use_np && !np_writer(result, step, &s, &np, &config)) { + if (s.use_np && !np_writer(result, step, &s, &np, &config)) { printf("np_writer() for modify raw data failed\n"); TEST_ERROR; } } } - - } else { + } + else { /* Start verifying data written to the compact dataset */ - if(s.compact && s.compact_write) { + if (s.compact && s.compact_write) { dbgf(2, "Verify writes to compact dataset\n"); - if(s.use_np && !np_confirm_verify_notify(np.fd_writer_to_reader, 0, &s, &np)) { + if (s.use_np && !np_confirm_verify_notify(np.fd_writer_to_reader, 0, &s, &np)) { printf("np_confirm_verify_notify() verify/notify not in sync failed\n"); TEST_ERROR; } @@ -1604,19 +1614,19 @@ main(int argc, char **argv) result = verify_read_dset_compact(&s, &ds); - if(s.use_np && !np_reader(result, 0, &s, &np)) { + if (s.use_np && !np_reader(result, 0, &s, &np)) { printf("np_reader() for verifying addition failed\n"); TEST_ERROR; } } /* Start verifying sequential writes for contiguous and/or chunked datasets */ - if((s.contig || s.chunked) && s.swrites) { + if ((s.contig || s.chunked) && s.swrites) { - for (step = 0; (step < s.swrites && step < (s.rows*s.cols)); step++) { + for (step = 0; (step < s.swrites && step < (s.rows * s.cols)); step++) { dbgf(2, "Verify sequential writes %u to dataset\n", step); - if(s.use_np && !np_confirm_verify_notify(np.fd_writer_to_reader, step, &s, &np)) { + if (s.use_np && !np_confirm_verify_notify(np.fd_writer_to_reader, step, &s, &np)) { printf("np_confirm_verify_notify() verify/notify not in sync failed\n"); TEST_ERROR; } @@ -1625,7 +1635,7 @@ main(int argc, char **argv) result = verify_dsets_action(SEQ_WRITE, &s, &ds, step); - if(s.use_np && !np_reader(result, step, &s, &np)) { + if (s.use_np && !np_reader(result, step, &s, &np)) { printf("np_reader() for verifying addition failed\n"); TEST_ERROR; } @@ -1633,19 +1643,19 @@ main(int argc, char **argv) } /* Start verifying random writes for contiguous and/or chunked datasets */ - if((s.contig || s.chunked) && s.rwrites) { + if ((s.contig || s.chunked) && s.rwrites) { unsigned newstep; /* Set up random seed which will be the same for both writer and reader */ HDsrandom(RANDOM_SEED); - for (step = 0; (step < s.rwrites && step < (s.rows*s.cols)); step++) { + for (step = 0; (step < s.rwrites && step < (s.rows * s.cols)); step++) { dbgf(2, "Verify random writes %u to dataset\n", step); - newstep = HDrandom() % (s.rows*s.cols); + newstep = HDrandom() % (s.rows * s.cols); printf("Random step is %u\n", newstep); - if(s.use_np && !np_confirm_verify_notify(np.fd_writer_to_reader, step, &s, &np)) { + if (s.use_np && !np_confirm_verify_notify(np.fd_writer_to_reader, step, &s, &np)) { printf("np_confirm_verify_notify() verify/notify not in sync failed\n"); TEST_ERROR; } @@ -1655,7 +1665,7 @@ main(int argc, char **argv) result = verify_dsets_action(RANDOM_WRITE, &s, &ds, newstep); - if(s.use_np && !np_reader(result, step, &s, &np)) { + if (s.use_np && !np_reader(result, step, &s, &np)) { printf("np_reader() for verifying addition failed\n"); TEST_ERROR; } @@ -1663,13 +1673,13 @@ main(int argc, char **argv) } /* Start verifying hyperslab writes for contiguous and/or chunked datasets */ - if((s.contig || s.chunked) && s.lwrites) { + if ((s.contig || s.chunked) && s.lwrites) { unsigned k; - for (step = 0, k = 0; (step < s.lwrites && k < (s.rows*s.cols)); step++, k+=s.cols) { + for (step = 0, k = 0; (step < s.lwrites && k < (s.rows * s.cols)); step++, k += s.cols) { dbgf(2, "Verify hyperslab writes %u to dataset\n", step); - if(s.use_np && !np_confirm_verify_notify(np.fd_writer_to_reader, step, &s, &np)) { + if (s.use_np && !np_confirm_verify_notify(np.fd_writer_to_reader, step, &s, &np)) { printf("np_confirm_verify_notify() verify/notify not in sync failed\n"); TEST_ERROR; } @@ -1679,7 +1689,7 @@ main(int argc, char **argv) result = verify_dsets_action(HYPER_WRITE, &s, &ds, k); - if(s.use_np && !np_reader(result, step, &s, &np)) { + if (s.use_np && !np_reader(result, step, &s, &np)) { printf("np_reader() for verifying addition failed\n"); TEST_ERROR; } @@ -1687,13 +1697,13 @@ main(int argc, char **argv) } /* Start verifying raw data modifications for contiguous and/or chunked datasets */ - if((s.contig || s.chunked) && s.wwrites) { + if ((s.contig || s.chunked) && s.wwrites) { unsigned k; - for (step = 0; (step < s.wwrites && step < (s.rows*s.cols)); step++) { + for (step = 0; (step < s.wwrites && step < (s.rows * s.cols)); step++) { dbgf(2, "Verify raw data modification %u to dataset\n", step); - if(s.use_np && !np_confirm_verify_notify(np.fd_writer_to_reader, step, &s, &np)) { + if (s.use_np && !np_confirm_verify_notify(np.fd_writer_to_reader, step, &s, &np)) { printf("np_confirm_verify_notify() verify/notify not in sync failed\n"); TEST_ERROR; } @@ -1703,7 +1713,7 @@ main(int argc, char **argv) result = verify_dsets_action(MODIFY_DATA, &s, &ds, step); - if(s.use_np && !np_reader(result, step, &s, &np)) { + if (s.use_np && !np_reader(result, step, &s, &np)) { printf("np_reader() for verifying addition failed\n"); TEST_ERROR; } @@ -1711,7 +1721,7 @@ main(int argc, char **argv) } } - if(!close_dsets(&ds)) { + if (!close_dsets(&ds)) { printf("close_dsets() failed\n"); TEST_ERROR; } @@ -1731,7 +1741,7 @@ main(int argc, char **argv) TEST_ERROR; } - if(s.use_np && !np_close(&np, writer)) { + if (s.use_np && !np_close(&np, writer)) { printf("np_close() failed\n"); TEST_ERROR; } @@ -1739,11 +1749,13 @@ main(int argc, char **argv) return EXIT_SUCCESS; error: - H5E_BEGIN_TRY { + H5E_BEGIN_TRY + { H5Pclose(fapl); H5Pclose(fcpl); H5Fclose(s.file); - } H5E_END_TRY; + } + H5E_END_TRY; if (s.use_np && np.fd_writer_to_reader >= 0) HDclose(np.fd_writer_to_reader); @@ -1751,7 +1763,7 @@ error: if (s.use_np && np.fd_reader_to_writer >= 0) HDclose(np.fd_reader_to_writer); - if(s.use_np && !writer) { + if (s.use_np && !writer) { HDremove(np.fifo_writer_to_reader); HDremove(np.fifo_reader_to_writer); } -- cgit v0.12 From f8a856182bd42c942f826294ab0b40185f38306c Mon Sep 17 00:00:00 2001 From: vchoi Date: Sun, 9 May 2021 00:06:00 -0500 Subject: Modifications based on PR feedback plus some cleaning up. --- test/vfd_swmr_dsetops_writer.c | 61 +++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/test/vfd_swmr_dsetops_writer.c b/test/vfd_swmr_dsetops_writer.c index 3133efc..597a42a 100644 --- a/test/vfd_swmr_dsetops_writer.c +++ b/test/vfd_swmr_dsetops_writer.c @@ -32,6 +32,8 @@ #include "testhdf5.h" #include "vfd_swmr_common.h" +#ifndef H5_HAVE_WIN32_API + #define READER_WAIT_TICKS 4 #define MAX_COMPACT_SIZE 65520 /* max obj header message size 65536) - other layout message fields (16) */ #define MAX_COMPACT_ELMS (MAX_COMPACT_SIZE/sizeof(unsigned int)) @@ -73,8 +75,8 @@ typedef struct { , .compact_write = false \ , .compact_elmts = MAX_COMPACT_ELMS \ , .contig = false \ - , .rows = 256 \ - , .cols = 512 \ + , .rows = 10 \ + , .cols = 5 \ , .swrites = 0 \ , .rwrites = 0 \ , .lwrites = 0 \ @@ -227,12 +229,17 @@ state_init(state_t *s, int argc, char **argv) { unsigned long tmp; int ch; - char tfile[PATH_MAX]; + char *tfile; char *end; *s = ALL_HID_INITIALIZER; - esnprintf(tfile, sizeof(tfile), "%s", argv[0]); - esnprintf(s->progname, sizeof(s->progname), "%s", basename(tfile)); + + if(H5_basename(argv[0], &tfile) < 0) { + printf("H5_basename failed\n"); + TEST_ERROR; + } + + esnprintf(s->progname, sizeof(s->progname), "%s", tfile); while ((ch = getopt(argc, argv, "pte:gkm:n:s:r:l:w:bqSNu:c:")) != -1) { switch (ch) { @@ -279,7 +286,7 @@ state_init(state_t *s, int argc, char **argv) case 'u': /* ticks for raeder to wait before verification */ case 'c': /* communication interval */ errno = 0; - tmp = strtoul(optarg, &end, 0); + tmp = HDstrtoul(optarg, &end, 0); if (end == optarg || *end != '\0') { printf("couldn't parse `-%c` argument `%s`\n", ch, optarg); TEST_ERROR; @@ -399,7 +406,6 @@ create_dsets(const state_t *s, dsets_state_t *ds) /* Dataset with compact layout, 1d, named datatype */ if(s->compact) { hsize_t dims[1]; - hid_t sid; if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) { printf("H5Pcreate failed\n"); @@ -434,8 +440,6 @@ create_dsets(const state_t *s, dsets_state_t *ds) /* Dataset with contiguous layout, 2d, named datatype */ if(s->contig) { hsize_t dims[2]; - hid_t sid; - unsigned i; dims[0] = s->rows; dims[1] = s->cols; @@ -474,8 +478,6 @@ create_dsets(const state_t *s, dsets_state_t *ds) hsize_t dims[2]; hsize_t max_dims[2]; hsize_t chunk_dims[2]; - hid_t sid; - unsigned i; dims[0] = s->rows; dims[1] = s->cols; @@ -658,7 +660,6 @@ open_dsets(const state_t *s, dsets_state_t *ds) } if(s->contig) { - hsize_t dims[2]; if(!open_dset_real(s, &ds->contig_did, &ds->contig_sid, DSET_CONTIG_NAME)) { printf("open_dset_real() for contiguous dataset failed\n"); @@ -667,7 +668,6 @@ open_dsets(const state_t *s, dsets_state_t *ds) } if(s->chunked) { - hsize_t dims[2]; if(!open_dset_real(s, &ds->single_did, &ds->single_sid, DSET_SINGLE_NAME)) { printf("open_dset_real() for chunked dataset: single index failed\n"); @@ -709,7 +709,6 @@ error: static bool open_dset_real(const state_t *s, hid_t *did, hid_t *sid, const char *name) { - hid_t dcpl = badhid; hsize_t dims[2]; if ((*did = H5Dopen2(s->file, name, H5P_DEFAULT)) < 0) { @@ -835,15 +834,11 @@ error: static bool dsets_action(unsigned action, const state_t *s, const dsets_state_t *ds, unsigned which) { - int nerrors = 0; - bool ret = false; - hsize_t dims[2]; hsize_t start[2]; hsize_t stride[2]; hsize_t count[2]; hsize_t block[2]; hid_t mem_sid; - unsigned kk, i; unsigned int *wbuf = NULL; /* Set up selection, dataspace and data buffer according to the specified action */ @@ -1057,17 +1052,11 @@ error: static bool verify_dsets_action(unsigned action, const state_t *s, const dsets_state_t *ds, unsigned which) { - int nerrors = 0; - bool ret = false; - hsize_t dims[2]; hsize_t start[2]; hsize_t stride[2]; hsize_t count[2]; hsize_t block[2]; hid_t mem_sid; - unsigned mm; - unsigned kk, i; - unsigned int *dd; unsigned int *vbuf = NULL; /* Set up selection, dataspace and data buffer according to the specified action */ @@ -1181,7 +1170,7 @@ error: static bool verify_read_dset_compact(const state_t *s, const dsets_state_t *ds) { - unsigned int *vbuf, *rbuf; + unsigned int *rbuf; unsigned i; if((rbuf = HDmalloc(s->compact_elmts * sizeof(unsigned int))) == NULL) { @@ -1448,13 +1437,13 @@ main(int argc, char **argv) TEST_ERROR; } - personality = strstr(s.progname, "vfd_swmr_dsetops_"); + personality = HDstrstr(s.progname, "vfd_swmr_dsetops_"); if (personality != NULL && - strcmp(personality, "vfd_swmr_dsetops_writer") == 0) + HDstrcmp(personality, "vfd_swmr_dsetops_writer") == 0) writer = true; else if (personality != NULL && - strcmp(personality, "vfd_swmr_dsetops_reader") == 0) + HDstrcmp(personality, "vfd_swmr_dsetops_reader") == 0) writer = false; else { printf("unknown personality, expected vfd_swmr_dsetops_{reader,writer}\n"); @@ -1547,7 +1536,7 @@ main(int argc, char **argv) for (step = 0; (step < s.rwrites && step < (s.rows*s.cols)); step++) { dbgf(2, "Random writes %u to dataset\n", step); - newstep = HDrandom() % (s.rows*s.cols); + newstep = (unsigned int)HDrandom() % (s.rows*s.cols); printf("Random step is %u\n", newstep); result = dsets_action(RANDOM_WRITE, &s, &ds, newstep); @@ -1642,7 +1631,7 @@ main(int argc, char **argv) for (step = 0; (step < s.rwrites && step < (s.rows*s.cols)); step++) { dbgf(2, "Verify random writes %u to dataset\n", step); - newstep = HDrandom() % (s.rows*s.cols); + newstep = (unsigned int)HDrandom() % (s.rows*s.cols); printf("Random step is %u\n", newstep); if(s.use_np && !np_confirm_verify_notify(np.fd_writer_to_reader, step, &s, &np)) { @@ -1688,7 +1677,6 @@ main(int argc, char **argv) /* Start verifying raw data modifications for contiguous and/or chunked datasets */ if((s.contig || s.chunked) && s.wwrites) { - unsigned k; for (step = 0; (step < s.wwrites && step < (s.rows*s.cols)); step++) { dbgf(2, "Verify raw data modification %u to dataset\n", step); @@ -1758,3 +1746,14 @@ error: return EXIT_FAILURE; } /* main */ + +#else /* H5_HAVE_WIN32_API */ + +int +main(void) +{ + HDfprintf(stderr, "Non-POSIX platform. Skipping.\n"); + return EXIT_SUCCESS; +} /* end main() */ + +#endif /* H5_HAVE_WIN32_API */ -- cgit v0.12 From 5bef1625491de4ceb10a816d50508ce54a1b5f3a Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 10 May 2021 04:44:03 +0000 Subject: Committing clang-format changes --- test/vfd_swmr_dsetops_writer.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/vfd_swmr_dsetops_writer.c b/test/vfd_swmr_dsetops_writer.c index f3053d6..a92641f 100644 --- a/test/vfd_swmr_dsetops_writer.c +++ b/test/vfd_swmr_dsetops_writer.c @@ -219,7 +219,7 @@ state_init(state_t *s, int argc, char **argv) *s = ALL_HID_INITIALIZER; - if(H5_basename(argv[0], &tfile) < 0) { + if (H5_basename(argv[0], &tfile) < 0) { printf("H5_basename failed\n"); TEST_ERROR; } @@ -426,7 +426,7 @@ create_dsets(const state_t *s, dsets_state_t *ds) /* Dataset with contiguous layout, 2d, named datatype */ if (s->contig) { - hsize_t dims[2]; + hsize_t dims[2]; dims[0] = s->rows; dims[1] = s->cols; @@ -462,9 +462,9 @@ create_dsets(const state_t *s, dsets_state_t *ds) /* Dataset with chunked layout, 2d, named datatype */ if (s->chunked) { - hsize_t dims[2]; - hsize_t max_dims[2]; - hsize_t chunk_dims[2]; + hsize_t dims[2]; + hsize_t max_dims[2]; + hsize_t chunk_dims[2]; dims[0] = s->rows; dims[1] = s->cols; -- cgit v0.12 From e25e384dcf1b4dd93318ad1c6eef6fc838ad852f Mon Sep 17 00:00:00 2001 From: vchoi Date: Wed, 19 May 2021 15:06:33 -0500 Subject: Address feedback from PR review: 1) Remove unnecessary header files 2) Move coding from main() to subroutines --- test/vfd_swmr_dsetops_writer.c | 389 ++++++++++++++++++++++++----------------- 1 file changed, 228 insertions(+), 161 deletions(-) diff --git a/test/vfd_swmr_dsetops_writer.c b/test/vfd_swmr_dsetops_writer.c index f3053d6..db6b5dc 100644 --- a/test/vfd_swmr_dsetops_writer.c +++ b/test/vfd_swmr_dsetops_writer.c @@ -24,9 +24,6 @@ * -- Regular hyperslab writes * -- Raw data modifications */ -#include -#include -#include /* getopt(3) */ #include "hdf5.h" #include "testhdf5.h" @@ -135,6 +132,8 @@ static bool open_dset_real(const state_t *s, hid_t *did, hid_t *sid, const char static bool close_dsets(const dsets_state_t *ds); static bool close_dset_real(hid_t did, hid_t sid); +static bool write_dset_contig_chunked(state_t *s, dsets_state_t *ds, + H5F_vfd_swmr_config_t *config, np_state_t *np); static bool dsets_action(unsigned action, const state_t *s, const dsets_state_t *ds, unsigned step); static bool dset_setup(unsigned action, unsigned which, const state_t *s, hsize_t *start, hsize_t *stride, hsize_t *count, hsize_t *block, hid_t *mem_sid, unsigned int **buf); @@ -142,6 +141,8 @@ static bool write_dset(hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hsiz hsize_t *count, hsize_t *block, unsigned int *buf); static bool write_dset_compact(const state_t *s, const dsets_state_t *ds); +static bool verify_write_dset_contig_chunked(state_t *s, dsets_state_t *ds, + H5F_vfd_swmr_config_t *config, np_state_t *np); static bool verify_dsets_action(unsigned action, const state_t *s, const dsets_state_t *ds, unsigned which); static bool verify_read_dset(hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hsize_t *start, hsize_t *stride, hsize_t *count, hsize_t *block, unsigned int *vbuf); @@ -817,6 +818,95 @@ error: */ /* + * Perform writes for contiguous and chunked datasets: + * --SEQ_WRITE: sequential writes + * --RANDOM_WRITE: random writes + * --HYPER_WRITE: hyperslab writes + * --MODIFY_DATA: raw data modifications + */ +static bool +write_dset_contig_chunked(state_t *s, dsets_state_t *ds, H5F_vfd_swmr_config_t *config, np_state_t *np) +{ + unsigned step; + bool result; + + HDassert(s->contig || s->chunked); + + /* Perform sequential writes for contiguous and/or chunked datasets */ + if (s->swrites) { + + for (step = 0; (step < s->swrites && step < (s->rows * s->cols)); step++) { + dbgf(2, "Sequential writes %u to dataset\n", step); + + result = dsets_action(SEQ_WRITE, s, ds, step); + + if (s->use_np && !np_writer(result, step, s, np, config)) { + printf("np_writer() for sequential writes failed\n"); + TEST_ERROR; + } + } + } + + /* Perform random writes for contiguous and/or chunked datasets */ + if (s->rwrites) { + unsigned newstep; + + /* Set up random seed which will be the same for both writer and reader */ + HDsrandom(RANDOM_SEED); + + for (step = 0; (step < s->rwrites && step < (s->rows * s->cols)); step++) { + dbgf(2, "Random writes %u to dataset\n", step); + + newstep = (unsigned int)HDrandom() % (s->rows * s->cols); + printf("Random step is %u\n", newstep); + result = dsets_action(RANDOM_WRITE, s, ds, newstep); + + if (s->use_np && !np_writer(result, step, s, np, config)) { + printf("np_writer() for random writes failed\n"); + TEST_ERROR; + } + } + } + + /* Perform hyperslab writes for contiguous and/or chunked datasets */ + if (s->lwrites) { + unsigned k; + + for (step = 0, k = 0; (step < s->lwrites && k < (s->rows * s->cols)); step++, k += s->cols) { + dbgf(2, "Hyperslab writes %u to dataset\n", step); + + result = dsets_action(HYPER_WRITE, s, ds, k); + + if (s->use_np && !np_writer(result, step, s, np, config)) { + printf("np_writer() for hyperslab writes failed\n"); + TEST_ERROR; + } + } + } + + /* Perform raw data modifications for contiguous and/or chunked datasets */ + if (s->wwrites) { + + for (step = 0; (step < s->wwrites && step < (s->rows * s->cols)); step++) { + dbgf(2, "Modify raw data %u to dataset\n", step); + + result = dsets_action(MODIFY_DATA, s, ds, step); + + if (s->use_np && !np_writer(result, step, s, np, config)) { + printf("np_writer() for modify raw data failed\n"); + TEST_ERROR; + } + } + } + + return true; + +error: + return false; + +} /* write_dset_contig_chunked() */ + +/* * Perform the "action" for each of the datasets specified on the command line: * SEQ_WRITE: perform `which` sequential write * RANDOM_WRITE: perform `which` random write @@ -1038,6 +1128,128 @@ error: */ /* + * Verify writes for contiguous and chunked datasets: + * --SEQ_WRITE: sequential writes + * --RANDOM_WRITE: random writes + * --HYPER_WRITE: hyperslab writes + * --MODIFY_DATA: raw data modifications + */ +static bool +verify_write_dset_contig_chunked(state_t *s, dsets_state_t *ds, H5F_vfd_swmr_config_t *config, np_state_t *np) +{ + unsigned step; + bool result; + + HDassert(s->contig || s->chunked); + + /* Start verifying sequential writes for contiguous and/or chunked datasets */ + if (s->swrites) { + + for (step = 0; (step < s->swrites && step < (s->rows * s->cols)); step++) { + dbgf(2, "Verify sequential writes %u to dataset\n", step); + + if (s->use_np && !np_confirm_verify_notify(np->fd_writer_to_reader, step, s, np)) { + printf("np_confirm_verify_notify() verify/notify not in sync failed\n"); + TEST_ERROR; + } + + /* Wait for a few ticks for the update to happen */ + decisleep(config->tick_len * s->update_interval); + + result = verify_dsets_action(SEQ_WRITE, s, ds, step); + + if (s->use_np && !np_reader(result, step, s, np)) { + printf("np_reader() for verifying addition failed\n"); + TEST_ERROR; + } + } + } + + /* Start verifying random writes for contiguous and/or chunked datasets */ + if (s->rwrites) { + unsigned newstep; + + /* Set up random seed which will be the same for both writer and reader */ + HDsrandom(RANDOM_SEED); + + for (step = 0; (step < s->rwrites && step < (s->rows * s->cols)); step++) { + dbgf(2, "Verify random writes %u to dataset\n", step); + + newstep = (unsigned int)HDrandom() % (s->rows * s->cols); + printf("Random step is %u\n", newstep); + + if (s->use_np && !np_confirm_verify_notify(np->fd_writer_to_reader, step, s, np)) { + printf("np_confirm_verify_notify() verify/notify not in sync failed\n"); + TEST_ERROR; + } + + /* Wait for a few ticks for the update to happen */ + decisleep(config->tick_len * s->update_interval); + + result = verify_dsets_action(RANDOM_WRITE, s, ds, newstep); + + if (s->use_np && !np_reader(result, step, s, np)) { + printf("np_reader() for verifying addition failed\n"); + TEST_ERROR; + } + } + } + + /* Start verifying hyperslab writes for contiguous and/or chunked datasets */ + if (s->lwrites) { + unsigned k; + + for (step = 0, k = 0; (step < s->lwrites && k < (s->rows * s->cols)); step++, k += s->cols) { + dbgf(2, "Verify hyperslab writes %u to dataset\n", step); + + if (s->use_np && !np_confirm_verify_notify(np->fd_writer_to_reader, step, s, np)) { + printf("np_confirm_verify_notify() verify/notify not in sync failed\n"); + TEST_ERROR; + } + + /* Wait for a few ticks for the update to happen */ + decisleep(config->tick_len * s->update_interval); + + result = verify_dsets_action(HYPER_WRITE, s, ds, k); + + if (s->use_np && !np_reader(result, step, s, np)) { + printf("np_reader() for verifying addition failed\n"); + TEST_ERROR; + } + } + } + + /* Start verifying raw data modifications for contiguous and/or chunked datasets */ + if (s->wwrites) { + + for (step = 0; (step < s->wwrites && step < (s->rows * s->cols)); step++) { + dbgf(2, "Verify raw data modification %u to dataset\n", step); + + if (s->use_np && !np_confirm_verify_notify(np->fd_writer_to_reader, step, s, np)) { + printf("np_confirm_verify_notify() verify/notify not in sync failed\n"); + TEST_ERROR; + } + + /* Wait for a few ticks for the update to happen */ + decisleep(config->tick_len * s->update_interval); + + result = verify_dsets_action(MODIFY_DATA, s, ds, step); + + if (s->use_np && !np_reader(result, step, s, np)) { + printf("np_reader() for verifying addition failed\n"); + TEST_ERROR; + } + } + } + + return true; + +error: + return false; + +} /* verify_write_dset_contig_chunked() */ + +/* * Verify the data read from each of the datasets specified on the command line * according to "action": * SEQ_WRITE: `which` sequential write @@ -1429,6 +1641,8 @@ error: return false; } /* np_confirm_verify_notify() */ + + /* * Main */ @@ -1522,71 +1736,14 @@ main(int argc, char **argv) } } - /* Perform sequential writes for contiguous and/or chunked datasets */ - if ((s.contig || s.chunked) && s.swrites) { - - for (step = 0; (step < s.swrites && step < (s.rows * s.cols)); step++) { - dbgf(2, "Sequential writes %u to dataset\n", step); - - result = dsets_action(SEQ_WRITE, &s, &ds, step); - - if (s.use_np && !np_writer(result, step, &s, &np, &config)) { - printf("np_writer() for sequential writes failed\n"); - TEST_ERROR; - } - } - } - - /* Perform random writes for contiguous and/or chunked datasets */ - if ((s.contig || s.chunked) && s.rwrites) { - unsigned newstep; - - /* Set up random seed which will be the same for both writer and reader */ - HDsrandom(RANDOM_SEED); - - for (step = 0; (step < s.rwrites && step < (s.rows * s.cols)); step++) { - dbgf(2, "Random writes %u to dataset\n", step); - - newstep = (unsigned int)HDrandom() % (s.rows * s.cols); - printf("Random step is %u\n", newstep); - result = dsets_action(RANDOM_WRITE, &s, &ds, newstep); - - if (s.use_np && !np_writer(result, step, &s, &np, &config)) { - printf("np_writer() for random writes failed\n"); - TEST_ERROR; - } - } - } - - /* Perform hyperslab writes for contiguous and/or chunked datasets */ - if ((s.contig || s.chunked) && s.lwrites) { - unsigned k; - for (step = 0, k = 0; (step < s.lwrites && k < (s.rows * s.cols)); step++, k += s.cols) { - dbgf(2, "Hyperslab writes %u to dataset\n", step); - - result = dsets_action(HYPER_WRITE, &s, &ds, k); - - if (s.use_np && !np_writer(result, step, &s, &np, &config)) { - printf("np_writer() for hyperslab writes failed\n"); - TEST_ERROR; - } + if (s.contig || s.chunked) { + /* Perform writes for contiguous and/or chunked datasets */ + if(!write_dset_contig_chunked(&s, &ds, &config, &np)) { + printf("write_dset_contig_chunked() failed\n"); + TEST_ERROR; } } - /* Perform raw data modifications for contiguous and/or chunked datasets */ - if ((s.contig || s.chunked) && s.wwrites) { - - for (step = 0; (step < s.wwrites && step < (s.rows * s.cols)); step++) { - dbgf(2, "Modify raw data %u to dataset\n", step); - - result = dsets_action(MODIFY_DATA, &s, &ds, step); - - if (s.use_np && !np_writer(result, step, &s, &np, &config)) { - printf("np_writer() for modify raw data failed\n"); - TEST_ERROR; - } - } - } } else { @@ -1609,102 +1766,12 @@ main(int argc, char **argv) } } - /* Start verifying sequential writes for contiguous and/or chunked datasets */ - if ((s.contig || s.chunked) && s.swrites) { - - for (step = 0; (step < s.swrites && step < (s.rows * s.cols)); step++) { - dbgf(2, "Verify sequential writes %u to dataset\n", step); - - if (s.use_np && !np_confirm_verify_notify(np.fd_writer_to_reader, step, &s, &np)) { - printf("np_confirm_verify_notify() verify/notify not in sync failed\n"); - TEST_ERROR; - } - /* Wait for a few ticks for the update to happen */ - decisleep(config.tick_len * s.update_interval); - - result = verify_dsets_action(SEQ_WRITE, &s, &ds, step); - - if (s.use_np && !np_reader(result, step, &s, &np)) { - printf("np_reader() for verifying addition failed\n"); - TEST_ERROR; - } - } - } - - /* Start verifying random writes for contiguous and/or chunked datasets */ - if ((s.contig || s.chunked) && s.rwrites) { - unsigned newstep; - - /* Set up random seed which will be the same for both writer and reader */ - HDsrandom(RANDOM_SEED); - - for (step = 0; (step < s.rwrites && step < (s.rows * s.cols)); step++) { - dbgf(2, "Verify random writes %u to dataset\n", step); - - newstep = (unsigned int)HDrandom() % (s.rows * s.cols); - printf("Random step is %u\n", newstep); - - if (s.use_np && !np_confirm_verify_notify(np.fd_writer_to_reader, step, &s, &np)) { - printf("np_confirm_verify_notify() verify/notify not in sync failed\n"); - TEST_ERROR; - } - - /* Wait for a few ticks for the update to happen */ - decisleep(config.tick_len * s.update_interval); - - result = verify_dsets_action(RANDOM_WRITE, &s, &ds, newstep); - - if (s.use_np && !np_reader(result, step, &s, &np)) { - printf("np_reader() for verifying addition failed\n"); - TEST_ERROR; - } - } - } - - /* Start verifying hyperslab writes for contiguous and/or chunked datasets */ - if ((s.contig || s.chunked) && s.lwrites) { - unsigned k; - - for (step = 0, k = 0; (step < s.lwrites && k < (s.rows * s.cols)); step++, k += s.cols) { - dbgf(2, "Verify hyperslab writes %u to dataset\n", step); - - if (s.use_np && !np_confirm_verify_notify(np.fd_writer_to_reader, step, &s, &np)) { - printf("np_confirm_verify_notify() verify/notify not in sync failed\n"); - TEST_ERROR; - } - - /* Wait for a few ticks for the update to happen */ - decisleep(config.tick_len * s.update_interval); - - result = verify_dsets_action(HYPER_WRITE, &s, &ds, k); - - if (s.use_np && !np_reader(result, step, &s, &np)) { - printf("np_reader() for verifying addition failed\n"); - TEST_ERROR; - } - } - } - - /* Start verifying raw data modifications for contiguous and/or chunked datasets */ - if ((s.contig || s.chunked) && s.wwrites) { - - for (step = 0; (step < s.wwrites && step < (s.rows * s.cols)); step++) { - dbgf(2, "Verify raw data modification %u to dataset\n", step); - - if (s.use_np && !np_confirm_verify_notify(np.fd_writer_to_reader, step, &s, &np)) { - printf("np_confirm_verify_notify() verify/notify not in sync failed\n"); - TEST_ERROR; - } - - /* Wait for a few ticks for the update to happen */ - decisleep(config.tick_len * s.update_interval); - - result = verify_dsets_action(MODIFY_DATA, &s, &ds, step); - - if (s.use_np && !np_reader(result, step, &s, &np)) { - printf("np_reader() for verifying addition failed\n"); - TEST_ERROR; - } + if (s.contig || s.chunked) { + + /* Verify writes for contiguous and/or chunked datasets */ + if(!verify_write_dset_contig_chunked(&s, &ds, &config, &np)) { + printf("verify_write_dset_contig_chunked() failed\n"); + TEST_ERROR; } } } -- cgit v0.12 From b99c806f80331b6ebe7cc75a7cfdb4ee9a866e4c Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 19 May 2021 20:12:14 +0000 Subject: Committing clang-format changes --- test/vfd_swmr_dsetops_writer.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/test/vfd_swmr_dsetops_writer.c b/test/vfd_swmr_dsetops_writer.c index 5618e2e..8c21806 100644 --- a/test/vfd_swmr_dsetops_writer.c +++ b/test/vfd_swmr_dsetops_writer.c @@ -132,8 +132,8 @@ static bool open_dset_real(const state_t *s, hid_t *did, hid_t *sid, const char static bool close_dsets(const dsets_state_t *ds); static bool close_dset_real(hid_t did, hid_t sid); -static bool write_dset_contig_chunked(state_t *s, dsets_state_t *ds, - H5F_vfd_swmr_config_t *config, np_state_t *np); +static bool write_dset_contig_chunked(state_t *s, dsets_state_t *ds, H5F_vfd_swmr_config_t *config, + np_state_t *np); static bool dsets_action(unsigned action, const state_t *s, const dsets_state_t *ds, unsigned step); static bool dset_setup(unsigned action, unsigned which, const state_t *s, hsize_t *start, hsize_t *stride, hsize_t *count, hsize_t *block, hid_t *mem_sid, unsigned int **buf); @@ -141,8 +141,8 @@ static bool write_dset(hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hsiz hsize_t *count, hsize_t *block, unsigned int *buf); static bool write_dset_compact(const state_t *s, const dsets_state_t *ds); -static bool verify_write_dset_contig_chunked(state_t *s, dsets_state_t *ds, - H5F_vfd_swmr_config_t *config, np_state_t *np); +static bool verify_write_dset_contig_chunked(state_t *s, dsets_state_t *ds, H5F_vfd_swmr_config_t *config, + np_state_t *np); static bool verify_dsets_action(unsigned action, const state_t *s, const dsets_state_t *ds, unsigned which); static bool verify_read_dset(hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hsize_t *start, hsize_t *stride, hsize_t *count, hsize_t *block, unsigned int *vbuf); @@ -827,9 +827,9 @@ error: static bool write_dset_contig_chunked(state_t *s, dsets_state_t *ds, H5F_vfd_swmr_config_t *config, np_state_t *np) { - unsigned step; - bool result; - + unsigned step; + bool result; + HDassert(s->contig || s->chunked); /* Perform sequential writes for contiguous and/or chunked datasets */ @@ -882,9 +882,9 @@ write_dset_contig_chunked(state_t *s, dsets_state_t *ds, H5F_vfd_swmr_config_t * TEST_ERROR; } } - } + } - /* Perform raw data modifications for contiguous and/or chunked datasets */ + /* Perform raw data modifications for contiguous and/or chunked datasets */ if (s->wwrites) { for (step = 0; (step < s->wwrites && step < (s->rows * s->cols)); step++) { @@ -1137,9 +1137,9 @@ error: static bool verify_write_dset_contig_chunked(state_t *s, dsets_state_t *ds, H5F_vfd_swmr_config_t *config, np_state_t *np) { - unsigned step; - bool result; - + unsigned step; + bool result; + HDassert(s->contig || s->chunked); /* Start verifying sequential writes for contiguous and/or chunked datasets */ @@ -1641,8 +1641,6 @@ error: return false; } /* np_confirm_verify_notify() */ - - /* * Main */ @@ -1738,12 +1736,11 @@ main(int argc, char **argv) if (s.contig || s.chunked) { /* Perform writes for contiguous and/or chunked datasets */ - if(!write_dset_contig_chunked(&s, &ds, &config, &np)) { + if (!write_dset_contig_chunked(&s, &ds, &config, &np)) { printf("write_dset_contig_chunked() failed\n"); TEST_ERROR; } } - } else { @@ -1767,9 +1764,9 @@ main(int argc, char **argv) } if (s.contig || s.chunked) { - + /* Verify writes for contiguous and/or chunked datasets */ - if(!verify_write_dset_contig_chunked(&s, &ds, &config, &np)) { + if (!verify_write_dset_contig_chunked(&s, &ds, &config, &np)) { printf("verify_write_dset_contig_chunked() failed\n"); TEST_ERROR; } -- cgit v0.12