diff options
author | Vailin Choi <vchoi@jam.ad.hdfgroup.org> | 2019-01-31 17:47:43 (GMT) |
---|---|---|
committer | Vailin Choi <vchoi@jam.ad.hdfgroup.org> | 2019-01-31 17:47:43 (GMT) |
commit | 311e4ed32de7fead9d6c26d962fdfbd00222ce2b (patch) | |
tree | d4cb5c0b374a38fa66763397a4b42ea7b1f21c61 /test | |
parent | 6feabcb42d55c1b47fa011ae915746834c3984b9 (diff) | |
download | hdf5-311e4ed32de7fead9d6c26d962fdfbd00222ce2b.zip hdf5-311e4ed32de7fead9d6c26d962fdfbd00222ce2b.tar.gz hdf5-311e4ed32de7fead9d6c26d962fdfbd00222ce2b.tar.bz2 |
Modifications to the vfd swmr concurrent tests:
(1) Increase the # of records to write (Nrecords) in testvfdswmr.sh.in so as to ensure the writer
will not exit before the reader
(2) Use H5E_BEGIN_TRY/END_TRY when H5Fopen() the test file in reader tests
(3) Add "READER" or "WRITER" to debugging messages
(4) Misc cleanup
Diffstat (limited to 'test')
-rw-r--r-- | test/testvfdswmr.sh.in | 2 | ||||
-rw-r--r-- | test/vfd_swmr_addrem_writer.c | 117 | ||||
-rw-r--r-- | test/vfd_swmr_reader.c | 124 | ||||
-rw-r--r-- | test/vfd_swmr_remove_reader.c | 117 | ||||
-rw-r--r-- | test/vfd_swmr_remove_writer.c | 87 | ||||
-rw-r--r-- | test/vfd_swmr_sparse_reader.c | 162 | ||||
-rw-r--r-- | test/vfd_swmr_sparse_writer.c | 125 | ||||
-rw-r--r-- | test/vfd_swmr_writer.c | 26 |
8 files changed, 487 insertions, 273 deletions
diff --git a/test/testvfdswmr.sh.in b/test/testvfdswmr.sh.in index 1e596e0..09fdb23 100644 --- a/test/testvfdswmr.sh.in +++ b/test/testvfdswmr.sh.in @@ -27,7 +27,7 @@ srcdir=@srcdir@ Nreaders=5 # number of readers to launch Nrdrs_spa=3 # number of sparse readers to launch -Nrecords=200000 # number of records to write +Nrecords=400000 # number of records to write Nrecs_rem=40000 # number of times to shrink Nrecs_spa=20000 # number of records to write in the sparse test Nsecs_add=5 # number of seconds per read interval diff --git a/test/vfd_swmr_addrem_writer.c b/test/vfd_swmr_addrem_writer.c index 1bdd835..24285d3 100644 --- a/test/vfd_swmr_addrem_writer.c +++ b/test/vfd_swmr_addrem_writer.c @@ -73,9 +73,9 @@ static void usage(void); static hid_t open_skeleton(const char *filename, unsigned verbose) { - hid_t fid; /* File ID for new HDF5 file */ - hid_t fapl; /* File access property list */ - hid_t sid; /* Dataspace ID */ + hid_t fid = -1; /* File ID for new HDF5 file */ + hid_t fapl = -1; /* File access property list */ + hid_t sid = -1; /* Dataspace ID */ hsize_t dim[2]; /* Dataspace dimension */ unsigned u, v; /* Local index variable */ H5F_vfd_swmr_config_t *config = NULL; /* Configuration for VFD SWMR */ @@ -84,11 +84,11 @@ open_skeleton(const char *filename, unsigned verbose) /* Create file access property list */ if((fapl = h5_fileaccess()) < 0) - return -1; + goto error; /* Set to use the latest library format */ if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) - return -1; + goto error; #ifdef QAK /* Increase the initial size of the metadata cache */ @@ -116,11 +116,11 @@ open_skeleton(const char *filename, unsigned verbose) /* Enable page buffering */ if(H5Pset_page_buffer_size(fapl, 4096, 0, 0) < 0) - return -1; + goto error; /* Allocate memory for the configuration structure */ if((config = (H5F_vfd_swmr_config_t *)HDmalloc(sizeof(H5F_vfd_swmr_config_t))) == NULL) - return -1; + goto error; config->version = H5F__CURR_VFD_SWMR_CONFIG_VERSION; config->tick_len = 4; @@ -131,38 +131,58 @@ open_skeleton(const char *filename, unsigned verbose) /* Enable VFD SWMR configuration */ if(H5Pset_vfd_swmr_config(fapl, config) < 0) - return -1; + goto error; /* Open the file */ if((fid = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0) - return -1; + goto error; /* Close file access property list */ if(H5Pclose(fapl) < 0) - return -1; + goto error; if(config) HDfree(config); /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Opening datasets\n"); + HDfprintf(stderr, "WRITER: Opening datasets\n"); /* Open the datasets */ for(u = 0; u < NLEVELS; u++) for(v = 0; v < symbol_count[u]; v++) { if((symbol_info[u][v].dsid = H5Dopen2(fid, symbol_info[u][v].name, H5P_DEFAULT)) < 0) - return -1; + goto error; + if((sid = H5Dget_space(symbol_info[u][v].dsid)) < 0) - return -1; + goto error; if(2 != H5Sget_simple_extent_ndims(sid)) - return -1; + goto error; if(H5Sget_simple_extent_dims(sid, dim, NULL) < 0) - return -1; + goto error; symbol_info[u][v].nrecords = dim[1]; + + if(H5Sclose(sid) < 0) + goto error; } /* end for */ return fid; + +error: + if(config) + HDfree(config); + + H5E_BEGIN_TRY { + for(u = 0; u < NLEVELS; u++) + for(v = 0; v < symbol_count[u]; v++) + H5Dclose(symbol_info[u][v].dsid); + H5Sclose(sid); + H5Pclose(fapl); + H5Fclose(fid); + } H5E_END_TRY; + + return -1; + } /* open_skeleton() */ @@ -192,8 +212,9 @@ open_skeleton(const char *filename, unsigned verbose) static int addrem_records(hid_t fid, unsigned verbose, unsigned long nops, unsigned long flush_count) { - hid_t tid; /* Datatype ID for records */ - hid_t mem_sid; /* Memory dataspace ID */ + hid_t tid = -1; /* Datatype ID for records */ + hid_t mem_sid = -1; /* Memory dataspace ID */ + hid_t file_sid = -1; /* Dataset's space ID */ hsize_t start[2] = {0, 0}, count[2] = {1, 1}; /* Hyperslab selection values */ hsize_t dim[2] = {1, 0}; /* Dataspace dimensions */ symbol_t buf[MAX_SIZE_CHANGE]; /* Write buffer */ @@ -207,18 +228,17 @@ addrem_records(hid_t fid, unsigned verbose, unsigned long nops, unsigned long fl /* Create a dataspace for the record to add */ if((mem_sid = H5Screate_simple(2, count, NULL)) < 0) - return -1; + goto error; /* Create datatype for appending records */ if((tid = create_symbol_datatype()) < 0) - return -1; + goto error; /* Add and remove records to random datasets, according to frequency * distribution */ op_to_flush = flush_count; for(u=0; u<nops; u++) { symbol_info_t *symbol; /* Symbol to write record to */ - hid_t file_sid; /* Dataset's space ID */ /* Get a random dataset, according to the symbol distribution */ symbol = choose_dataset(); @@ -236,7 +256,7 @@ addrem_records(hid_t fid, unsigned verbose, unsigned long nops, unsigned long fl /* Set the memory space to the correct size */ if(H5Sset_extent_simple(mem_sid, 2, count, NULL) < 0) - return -1; + goto error; /* Get the coordinates to write */ start[1] = symbol->nrecords; @@ -244,33 +264,33 @@ addrem_records(hid_t fid, unsigned verbose, unsigned long nops, unsigned long fl /* Cork the metadata cache, to prevent the object header from being * flushed before the data has been written */ if(H5Odisable_mdc_flushes(symbol->dsid) < 0) - return -1; + goto error; /* Extend the dataset's dataspace to hold the new record */ symbol->nrecords+= count[1]; dim[1] = symbol->nrecords; if(H5Dset_extent(symbol->dsid, dim) < 0) - return -1; + goto error; /* Get the dataset's dataspace */ if((file_sid = H5Dget_space(symbol->dsid)) < 0) - return -1; + goto error; /* Choose the last record in the dataset */ if(H5Sselect_hyperslab(file_sid, H5S_SELECT_SET, start, NULL, count, NULL) < 0) - return -1; + goto error; /* Write record to the dataset */ if(H5Dwrite(symbol->dsid, tid, mem_sid, file_sid, H5P_DEFAULT, &buf) < 0) - return -1; + goto error; /* Uncork the metadata cache */ if(H5Oenable_mdc_flushes(symbol->dsid) < 0) - return -1; + goto error; /* Close the dataset's dataspace */ if(H5Sclose(file_sid) < 0) - return -1; + goto error; } /* end if */ else { /* Shrink the dataset's dataspace */ @@ -280,7 +300,7 @@ addrem_records(hid_t fid, unsigned verbose, unsigned long nops, unsigned long fl symbol->nrecords -= count[1]; dim[1] = symbol->nrecords; if(H5Dset_extent(symbol->dsid, dim) < 0) - return -1; + goto error; } /* end else */ /* Check for flushing file */ @@ -304,7 +324,7 @@ addrem_records(hid_t fid, unsigned verbose, unsigned long nops, unsigned long fl /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Closing datasets\n"); + HDfprintf(stderr, "WRITER: Closing datasets\n"); /* Close the datasets */ for(u = 0; u < NLEVELS; u++) @@ -313,6 +333,21 @@ addrem_records(hid_t fid, unsigned verbose, unsigned long nops, unsigned long fl return -1; return 0; + +error: + H5E_BEGIN_TRY { + H5Sclose(mem_sid); + H5Sclose(file_sid); + H5Tclose(tid); + + for(u = 0; u < NLEVELS; u++) + for(v = 0; v < symbol_count[u]; v++) + H5Dclose(symbol_info[u][v].dsid); + + } H5E_END_TRY; + + return -1; + } /* addrem_records() */ static void @@ -401,7 +436,7 @@ int main(int argc, const char *argv[]) /* Emit informational message */ if(verbose) { - HDfprintf(stderr, "Parameters:\n"); + HDfprintf(stderr, "WRITER: Parameters:\n"); HDfprintf(stderr, "\t# of operations between flushes = %ld\n", flush_count); HDfprintf(stderr, "\t# of operations = %ld\n", nops); } /* end if */ @@ -414,11 +449,11 @@ int main(int argc, const char *argv[]) } /* end if */ HDsrandom(random_seed); /* ALWAYS emit the random seed for possible debugging */ - HDfprintf(stderr, "Using writer random seed: %u\n", random_seed); + HDfprintf(stderr, "WRITER: Using writer random seed: %u\n", random_seed); /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Generating symbol names\n"); + HDfprintf(stderr, "WRITER: Generating symbol names\n"); /* Generate dataset names */ if(generate_symbols() < 0) @@ -426,11 +461,11 @@ int main(int argc, const char *argv[]) /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Opening skeleton file: %s\n", FILENAME); + HDfprintf(stderr, "WRITER: Opening skeleton file: %s\n", FILENAME); /* Open file skeleton */ if((fid = open_skeleton(FILENAME, verbose)) < 0) { - HDfprintf(stderr, "Error opening skeleton file!\n"); + HDfprintf(stderr, "WRITER: Error opening skeleton file!\n"); HDexit(1); } /* end if */ @@ -439,31 +474,31 @@ int main(int argc, const char *argv[]) /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Adding and removing records\n"); + HDfprintf(stderr, "WRITER: Adding and removing records\n"); /* Grow and shrink datasets */ if(addrem_records(fid, verbose, (unsigned long)nops, (unsigned long)flush_count) < 0) { - HDfprintf(stderr, "Error adding and removing records from datasets!\n"); + HDfprintf(stderr, "WRITER: Error adding and removing records from datasets!\n"); HDexit(1); } /* end if */ /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Releasing symbols\n"); + HDfprintf(stderr, "WRITER: Releasing symbols\n"); /* Clean up the symbols */ if(shutdown_symbols() < 0) { - HDfprintf(stderr, "Error releasing symbols!\n"); + HDfprintf(stderr, "WRITER: Error releasing symbols!\n"); HDexit(1); } /* end if */ /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Closing objects\n"); + HDfprintf(stderr, "WRITER: Closing objects\n"); /* Close objects opened */ if(H5Fclose(fid) < 0) { - HDfprintf(stderr, "Error closing file!\n"); + HDfprintf(stderr, "WRITER: Error closing file!\n"); HDexit(1); } /* end if */ diff --git a/test/vfd_swmr_reader.c b/test/vfd_swmr_reader.c index 606d0c8..69613bd 100644 --- a/test/vfd_swmr_reader.c +++ b/test/vfd_swmr_reader.c @@ -97,31 +97,31 @@ check_dataset(hid_t fid, hbool_t verbose, FILE *verbose_file, /* Open dataset for symbol */ if((dsid = H5Dopen2(fid, sym_name, H5P_DEFAULT)) < 0) - return -1; + goto error; /* Get the dataset's dataspace */ if((file_sid = H5Dget_space(dsid)) < 0) - return -1; + goto error; /* Get the number of elements (= records, for 1-D datasets) */ if((snpoints = H5Sget_simple_extent_npoints(file_sid)) < 0) - return -1; + goto error; /* Emit informational message */ if(verbose) - HDfprintf(verbose_file, "Symbol = '%s', # of records = %lld\n", sym_name, (long long)snpoints); + HDfprintf(verbose_file, "READER: Symbol = '%s', # of records = %lld\n", sym_name, (long long)snpoints); /* Check if there are records for symbol */ if(snpoints > 0) { /* Choose the last record in the dataset */ start[1] = (hsize_t)(snpoints - 1); if(H5Sselect_hyperslab(file_sid, H5S_SELECT_SET, start, NULL, count, NULL) < 0) - return -1; + goto error; /* Read record from dataset */ record->rec_id = (uint64_t)ULLONG_MAX; if(H5Dread(dsid, symbol_tid, rec_sid, file_sid, H5P_DEFAULT, record) < 0) - return -1; + goto error; /* Verify record value */ if(record->rec_id != start[1]) { @@ -130,23 +130,31 @@ check_dataset(hid_t fid, hbool_t verbose, FILE *verbose_file, HDgettimeofday(&tv, NULL); if(verbose) { - HDfprintf(verbose_file, "*** ERROR ***\n"); + HDfprintf(verbose_file, "*** READER ERROR ***\n"); HDfprintf(verbose_file, "Incorrect record value!\n"); HDfprintf(verbose_file, "Time = %llu.%llu, Symbol = '%s', # of records = %lld, record->rec_id = %llu\n", (unsigned long long)tv.tv_sec, (unsigned long long)tv.tv_usec, sym_name, (long long)snpoints, (unsigned long long)record->rec_id); } /* end if */ - return -1; + goto error; } /* end if */ } /* end if */ /* Close the dataset's dataspace */ if(H5Sclose(file_sid) < 0) - return -1; + goto error; /* Close dataset for symbol */ if(H5Dclose(dsid) < 0) - return -1; + goto error; return 0; + +error: + H5E_BEGIN_TRY { + H5Sclose(file_sid); + H5Dclose(dsid); + } H5E_END_TRY; + + return -1; } /* end check_dataset() */ @@ -218,13 +226,13 @@ read_records(const char *filename, hbool_t verbose, FILE *verbose_file, /* Emit informational message */ if(verbose) - HDfprintf(verbose_file, "Choosing datasets\n"); + HDfprintf(verbose_file, "READER: Choosing datasets\n"); /* Allocate space for 'common' datasets, if any */ if(ncommon > 0) { /* Allocate array to hold pointers to symbols for common datasets */ if(NULL == (sym_com = (symbol_info_t **)HDmalloc(sizeof(symbol_info_t *) * ncommon))) - return -1; + goto error; /* Open the common datasets */ for(v = 0; v < ncommon; v++) { @@ -237,7 +245,7 @@ read_records(const char *filename, hbool_t verbose, FILE *verbose_file, /* Emit informational message */ if(verbose) - HDfprintf(verbose_file, "Common symbol #%u = '%s'\n", v, symbol_info[0][offset].name); + HDfprintf(verbose_file, "READER: Common symbol #%u = '%s'\n", v, symbol_info[0][offset].name); } /* end for */ } /* end if */ @@ -245,7 +253,7 @@ read_records(const char *filename, hbool_t verbose, FILE *verbose_file, if(nrandom > 0) { /* Allocate array to hold pointers to symbols for random datasets */ if(NULL == (sym_rand = (symbol_info_t **)HDmalloc(sizeof(symbol_info_t *) * nrandom))) - return -1; + goto error; /* Determine the random datasets */ for(v = 0; v < nrandom; v++) { @@ -258,17 +266,17 @@ read_records(const char *filename, hbool_t verbose, FILE *verbose_file, /* Emit informational message */ if(verbose) - HDfprintf(verbose_file, "Random symbol #%u = '%s'\n", v, sym->name); + HDfprintf(verbose_file, "READER: Random symbol #%u = '%s'\n", v, sym->name); } /* end for */ } /* end if */ /* Create a dataspace for the record to read */ if((mem_sid = H5Screate(H5S_SCALAR)) < 0) - return -1; + goto error; /* Emit informational message */ if(verbose) - HDfprintf(verbose_file, "Reading records\n"); + HDfprintf(verbose_file, "READER: Going to open file and read records\n"); /* Get the starting time */ start_time = HDtime(NULL); @@ -276,7 +284,7 @@ read_records(const char *filename, hbool_t verbose, FILE *verbose_file, /* Create file access property list */ if((fapl = h5_fileaccess()) < 0) - return -1; + goto error; /* Log I/O when verbose output it enbabled */ if(use_log_vfd) { @@ -292,11 +300,11 @@ read_records(const char *filename, hbool_t verbose, FILE *verbose_file, */ /* Enable page buffering */ if(H5Pset_page_buffer_size(fapl, 4096, 0, 0) < 0) - return -1; + goto error; /* Allocate memory for the configuration structure */ if((config = (H5F_vfd_swmr_config_t *)HDmalloc(sizeof(H5F_vfd_swmr_config_t))) == NULL) - return -1; + goto error; config->version = H5F__CURR_VFD_SWMR_CONFIG_VERSION; config->tick_len = 4; @@ -307,30 +315,36 @@ read_records(const char *filename, hbool_t verbose, FILE *verbose_file, /* Enable VFD SWMR configuration */ if(H5Pset_vfd_swmr_config(fapl, config) < 0) - return -1; + goto error; /* Loop over reading records until [at least] the correct # of seconds have passed */ while(curr_time < (time_t)(start_time + (time_t)nseconds)) { /* Emit informational message */ if(verbose) - HDfprintf(verbose_file, "Opening file: %s\n", filename); + HDfprintf(verbose_file, "READER: Opening file: %s\n", filename); /* Open the file with VFD SWMR configured */ - if((fid = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0) - return -1; + /* Remove H5E_BEGIN_TRY/END_TRY if you want to see the error stack */ + H5E_BEGIN_TRY { + fid = H5Fopen(filename, H5F_ACC_RDONLY, fapl); + } H5E_END_TRY; + if(fid < 0) { + HDfprintf(stderr, "READER: Error in opening the file: %s\n", filename); + goto error; + } /* Check 'common' datasets, if any */ if(ncommon > 0) { /* Emit informational message */ if(verbose) - HDfprintf(verbose_file, "Checking common symbols\n"); + HDfprintf(verbose_file, "READER: Checking common symbols after FILE OPEN\n"); /* Iterate over common datasets */ for(v = 0; v < ncommon; v++) { /* Check common dataset */ if(check_dataset(fid, verbose, verbose_file, sym_com[v]->name, &record, mem_sid) < 0) - return -1; + goto error; HDmemset(&record, 0, sizeof(record)); } /* end for */ } /* end if */ @@ -339,24 +353,24 @@ read_records(const char *filename, hbool_t verbose, FILE *verbose_file, if(nrandom > 0) { /* Emit informational message */ if(verbose) - HDfprintf(verbose_file, "Checking random symbols\n"); + HDfprintf(verbose_file, "READER: Checking random symbols after FILE OPEN\n"); /* Iterate over random datasets */ for(v = 0; v < nrandom; v++) { /* Check random dataset */ if(check_dataset(fid, verbose, verbose_file, sym_rand[v]->name, &record, mem_sid) < 0) - return -1; + goto error; HDmemset(&record, 0, sizeof(record)); } /* end for */ } /* end if */ /* Emit informational message */ if(verbose) - HDfprintf(verbose_file, "Closing file\n"); + HDfprintf(verbose_file, "READER: Closing file\n"); /* Close the file */ if(H5Fclose(fid) < 0) - return -1; + goto error; /* Sleep for the appropriate # of seconds */ HDsleep(poll_time); @@ -367,18 +381,18 @@ read_records(const char *filename, hbool_t verbose, FILE *verbose_file, /* Close the memory dataspace */ if(H5Sclose(mem_sid) < 0) - return -1; + goto error; /* Close the fapl */ if(H5Pclose(fapl) < 0) - return -1; + goto error; if(config) HDfree(config); /* Emit informational message */ if(verbose) - HDfprintf(verbose_file, "Closing datasets\n"); + HDfprintf(verbose_file, "READER: Closing datasets\n"); /* Close 'random' datasets, if any */ if(nrandom > 0) { @@ -393,6 +407,24 @@ read_records(const char *filename, hbool_t verbose, FILE *verbose_file, } /* end if */ return 0; + +error: + if(config) + HDfree(config); + + if(sym_rand) + HDfree(sym_rand); + + if(sym_com) + HDfree(sym_com); + + H5E_BEGIN_TRY { + H5Sclose(mem_sid); + H5Fclose(fid); + H5Pclose(fapl); + } H5E_END_TRY; + + return -1; } /* end read_records() */ static void @@ -511,14 +543,14 @@ int main(int argc, const char *argv[]) HDsnprintf(verbose_name, sizeof(verbose_name), "vfd_swmr_reader.out.%u", random_seed); if(NULL == (verbose_file = HDfopen(verbose_name, "w"))) { - HDfprintf(stderr, "Can't open verbose output file!\n"); + HDfprintf(stderr, "READER: Can't open verbose output file!\n"); HDexit(1); } } /* end if */ /* Emit informational message */ if(verbose) { - HDfprintf(verbose_file, "Parameters:\n"); + HDfprintf(verbose_file, "READER: Parameters:\n"); HDfprintf(verbose_file, "\t# of seconds between polling = %d\n", poll_time); HDfprintf(verbose_file, "\t# of common symbols to poll = %d\n", ncommon); HDfprintf(verbose_file, "\t# of random symbols to poll = %d\n", nrandom); @@ -526,45 +558,47 @@ int main(int argc, const char *argv[]) } /* end if */ /* ALWAYS emit the random seed for possible debugging */ - HDfprintf(stdout, "Using reader random seed: %u\n", random_seed); + HDfprintf(stdout, "READER: Using reader random seed: %u\n", random_seed); /* Emit informational message */ if(verbose) - HDfprintf(verbose_file, "Generating symbol names\n"); + HDfprintf(verbose_file, "READER: Generating symbol names\n"); /* Generate dataset names */ if(generate_symbols() < 0) { - HDfprintf(stderr, "Error generating symbol names!\n"); + HDfprintf(stderr, "READER: Error generating symbol names!\n"); HDexit(1); } /* end if */ /* Create datatype for creating datasets */ - if((symbol_tid = create_symbol_datatype()) < 0) - return -1; + if((symbol_tid = create_symbol_datatype()) < 0) { + HDfprintf(stderr, "READER: Error creating symbol datatype!\n"); + HDexit(1); + } /* Reading records from datasets */ if(read_records(FILENAME, verbose, verbose_file, random_seed, (unsigned long)nseconds, (unsigned)poll_time, (unsigned)ncommon, (unsigned)nrandom) < 0) { - HDfprintf(stderr, "Error reading records from datasets (random_seed = %u)!\n", random_seed); + HDfprintf(stderr, "READER: Error reading records from datasets (random_seed = %u)!\n", random_seed); HDexit(1); } /* end if */ /* Emit informational message */ if(verbose) - HDfprintf(verbose_file, "Releasing symbols\n"); + HDfprintf(verbose_file, "READER: Releasing symbols\n"); /* Clean up the symbols */ if(shutdown_symbols() < 0) { - HDfprintf(stderr, "Error releasing symbols!\n"); + HDfprintf(stderr, "READER: Error releasing symbols!\n"); HDexit(1); } /* end if */ /* Emit informational message */ if(verbose) - HDfprintf(verbose_file, "Closing objects\n"); + HDfprintf(verbose_file, "READER: Closing objects\n"); /* Close objects created */ if(H5Tclose(symbol_tid) < 0) { - HDfprintf(stderr, "Error closing symbol datatype!\n"); + HDfprintf(stderr, "READER: Error closing symbol datatype!\n"); HDexit(1); } /* end if */ diff --git a/test/vfd_swmr_remove_reader.c b/test/vfd_swmr_remove_reader.c index 1c752cd..49c294e 100644 --- a/test/vfd_swmr_remove_reader.c +++ b/test/vfd_swmr_remove_reader.c @@ -92,19 +92,19 @@ check_dataset(hid_t fid, unsigned verbose, const char *sym_name, symbol_t *recor /* Open dataset for symbol */ if((dsid = H5Dopen2(fid, sym_name, H5P_DEFAULT)) < 0) - return -1; + goto error; /* Get the dataset's dataspace */ if((file_sid = H5Dget_space(dsid)) < 0) - return -1; + goto error; /* Get the number of elements (= records, for 1-D datasets) */ if((snpoints = H5Sget_simple_extent_npoints(file_sid)) < 0) - return -1; + goto error; /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Symbol = '%s', # of records = %lld\n", sym_name, (long long)snpoints); + HDfprintf(stderr, "READER: Symbol = '%s', # of records = %lld\n", sym_name, (long long)snpoints); /* Check if there are records for symbol */ if(snpoints > 0) { @@ -114,7 +114,7 @@ check_dataset(hid_t fid, unsigned verbose, const char *sym_name, symbol_t *recor if(start[1] > (hsize_t)(snpoints - 1)) start[1] = (hsize_t)(snpoints - 1); if(H5Sselect_hyperslab(file_sid, H5S_SELECT_SET, start, NULL, count, NULL) < 0) - return -1; + goto error; /* Read record from dataset */ #ifdef FILLVAL_WORKS @@ -127,13 +127,13 @@ check_dataset(hid_t fid, unsigned verbose, const char *sym_name, symbol_t *recor record->rec_id = (uint64_t)0; #endif /* FILLVAL_WORKS */ if(H5Dread(dsid, symbol_tid, rec_sid, file_sid, H5P_DEFAULT, record) < 0) - return -1; + goto error; /* Verify record value - note that it may be the fill value, because the * chunk may be deleted before the object header has the updated * dimensions */ if(record->rec_id != start[1] && record->rec_id != (uint64_t)0) { - HDfprintf(stderr, "*** ERROR ***\n"); + HDfprintf(stderr, "*** READER: ERROR ***\n"); HDfprintf(stderr, "Incorrect record value!\n"); HDfprintf(stderr, "Symbol = '%s', # of records = %lld, record->rec_id = %llx\n", sym_name, (long long)snpoints, (unsigned long long)record->rec_id); return -1; @@ -142,13 +142,21 @@ check_dataset(hid_t fid, unsigned verbose, const char *sym_name, symbol_t *recor /* Close the dataset's dataspace */ if(H5Sclose(file_sid) < 0) - return -1; + goto error; /* Close dataset for symbol */ if(H5Dclose(dsid) < 0) - return -1; + goto error; return 0; + +error: + H5E_BEGIN_TRY { + H5Sclose(file_sid); + H5Dclose(dsid); + } H5E_END_TRY; + + return -1; } /* end check_dataset() */ @@ -212,13 +220,13 @@ read_records(const char *filename, unsigned verbose, unsigned long nseconds, /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Choosing datasets\n"); + HDfprintf(stderr, "READER: Choosing datasets\n"); /* Allocate space for 'common' datasets, if any */ if(ncommon > 0) { /* Allocate array to hold pointers to symbols for common datasets */ if(NULL == (sym_com = (symbol_info_t **)HDmalloc(sizeof(symbol_info_t *) * ncommon))) - return -1; + goto error; /* Open the common datasets */ for(v = 0; v < ncommon; v++) { @@ -231,7 +239,7 @@ read_records(const char *filename, unsigned verbose, unsigned long nseconds, /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Common symbol #%u = '%s'\n", v, symbol_info[0][offset].name); + HDfprintf(stderr, "READER: Common symbol #%u = '%s'\n", v, symbol_info[0][offset].name); } /* end for */ } /* end if */ @@ -239,7 +247,7 @@ read_records(const char *filename, unsigned verbose, unsigned long nseconds, if(nrandom > 0) { /* Allocate array to hold pointers to symbols for random datasets */ if(NULL == (sym_rand = (symbol_info_t **)HDmalloc(sizeof(symbol_info_t *) * nrandom))) - return -1; + goto error; /* Determine the random datasets */ for(v = 0; v < nrandom; v++) { @@ -247,22 +255,22 @@ read_records(const char *filename, unsigned verbose, unsigned long nseconds, /* Determine the symbol, within all symbols */ if(NULL == (sym = choose_dataset())) - return -1; + goto error; sym_rand[v] = sym; /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Random symbol #%u = '%s'\n", v, sym->name); + HDfprintf(stderr, "READER: Random symbol #%u = '%s'\n", v, sym->name); } /* end for */ } /* end if */ /* Create a dataspace for the record to read */ if((mem_sid = H5Screate(H5S_SCALAR)) < 0) - return -1; + goto error; /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Reading records\n"); + HDfprintf(stderr, "READER: Reading records\n"); /* Get the starting time */ start_time = HDtime(NULL); @@ -270,18 +278,18 @@ read_records(const char *filename, unsigned verbose, unsigned long nseconds, /* Create file access property list */ if((fapl = h5_fileaccess()) < 0) - return -1; + goto error; /* * Set up to open the file with VFD SWMR configured. */ /* Enable page buffering */ if(H5Pset_page_buffer_size(fapl, 4096, 0, 0) < 0) - return -1; + goto error; /* Allocate memory for the configuration structure */ if((config = (H5F_vfd_swmr_config_t *)HDmalloc(sizeof(H5F_vfd_swmr_config_t))) == NULL) - return -1; + goto error; config->version = H5F__CURR_VFD_SWMR_CONFIG_VERSION; config->tick_len = 4; @@ -292,30 +300,36 @@ read_records(const char *filename, unsigned verbose, unsigned long nseconds, /* Enable VFD SWMR configuration */ if(H5Pset_vfd_swmr_config(fapl, config) < 0) - return -1; + goto error; /* Loop over reading records until [at least] the correct # of seconds have passed */ while(curr_time < (time_t)(start_time + (time_t)nseconds)) { /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Opening file: %s\n", filename); + HDfprintf(stderr, "READER: Opening file: %s\n", filename); /* Open the file */ - if((fid = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0) - return -1; + /* Remove H5E_BEGIN_TRY/END_TRY if you want to see the error stack */ + H5E_BEGIN_TRY { + fid = H5Fopen(filename, H5F_ACC_RDONLY, fapl); + } H5E_END_TRY; + if(fid < 0) { + HDfprintf(stderr, "READER: Error in opening the file: %s\n", filename); + goto error; + } /* Check 'common' datasets, if any */ if(ncommon > 0) { /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Checking common symbols\n"); + HDfprintf(stderr, "READER: Checking common symbols\n"); /* Iterate over common datasets */ for(v = 0; v < ncommon; v++) { /* Check common dataset */ if(check_dataset(fid, verbose, sym_com[v]->name, &record, mem_sid) < 0) - return -1; + goto error; HDmemset(&record, 0, sizeof(record)); } /* end for */ } /* end if */ @@ -324,24 +338,24 @@ read_records(const char *filename, unsigned verbose, unsigned long nseconds, if(nrandom > 0) { /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Checking random symbols\n"); + HDfprintf(stderr, "READER: Checking random symbols\n"); /* Iterate over random datasets */ for(v = 0; v < nrandom; v++) { /* Check random dataset */ if(check_dataset(fid, verbose, sym_rand[v]->name, &record, mem_sid) < 0) - return -1; + goto error; HDmemset(&record, 0, sizeof(record)); } /* end for */ } /* end if */ /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Closing file\n"); + HDfprintf(stderr, "READER: Closing file\n"); /* Close the file */ if(H5Fclose(fid) < 0) - return -1; + goto error; /* Sleep for the appropriate # of seconds */ HDsleep(poll_time); @@ -352,18 +366,18 @@ read_records(const char *filename, unsigned verbose, unsigned long nseconds, /* Close the fapl */ if(H5Pclose(fapl) < 0) - return -1; + goto error; if(config) HDfree(config); /* Close the memory dataspace */ if(H5Sclose(mem_sid) < 0) - return -1; + goto error; /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Closing datasets\n"); + HDfprintf(stderr, "READER: Closing datasets\n"); /* Close 'random' datasets, if any */ if(nrandom > 0) { @@ -378,6 +392,25 @@ read_records(const char *filename, unsigned verbose, unsigned long nseconds, } /* end if */ return 0; + +error: + if(config) + HDfree(config); + + if(sym_rand) + HDfree(sym_rand); + + if(sym_com) + HDfree(sym_com); + + H5E_BEGIN_TRY { + H5Sclose(mem_sid); + H5Fclose(fid); + H5Pclose(fapl); + } H5E_END_TRY; + + return -1; + } /* end read_records() */ static void @@ -480,7 +513,7 @@ int main(int argc, const char *argv[]) /* Emit informational message */ if(verbose) { - HDfprintf(stderr, "Parameters:\n"); + HDfprintf(stderr, "READER: Parameters:\n"); HDfprintf(stderr, "\t# of seconds between polling = %d\n", poll_time); HDfprintf(stderr, "\t# of common symbols to poll = %d\n", ncommon); HDfprintf(stderr, "\t# of random symbols to poll = %d\n", nrandom); @@ -495,15 +528,15 @@ int main(int argc, const char *argv[]) } /* end if */ HDsrandom(random_seed); /* ALWAYS emit the random seed for possible debugging */ - HDfprintf(stderr, "Using reader random seed: %u\n", random_seed); + HDfprintf(stderr, "READER: Using reader random seed: %u\n", random_seed); /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Generating symbol names\n"); + HDfprintf(stderr, "READER: Generating symbol names\n"); /* Generate dataset names */ if(generate_symbols() < 0) { - HDfprintf(stderr, "Error generating symbol names!\n"); + HDfprintf(stderr, "READER: Error generating symbol names!\n"); HDexit(1); } /* end if */ @@ -513,27 +546,27 @@ int main(int argc, const char *argv[]) /* Reading records from datasets */ if(read_records(FILENAME, verbose, (unsigned long)nseconds, (unsigned)poll_time, (unsigned)ncommon, (unsigned)nrandom) < 0) { - HDfprintf(stderr, "Error reading records from datasets!\n"); + HDfprintf(stderr, "READER: Error reading records from datasets!\n"); HDexit(1); } /* end if */ /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Releasing symbols\n"); + HDfprintf(stderr, "READER: Releasing symbols\n"); /* Clean up the symbols */ if(shutdown_symbols() < 0) { - HDfprintf(stderr, "Error releasing symbols!\n"); + HDfprintf(stderr, "READER: Error releasing symbols!\n"); HDexit(1); } /* end if */ /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Closing objects\n"); + HDfprintf(stderr, "READER: Closing objects\n"); /* Close objects created */ if(H5Tclose(symbol_tid) < 0) { - HDfprintf(stderr, "Error closing symbol datatype!\n"); + HDfprintf(stderr, "READER: Error closing symbol datatype!\n"); HDexit(1); } /* end if */ diff --git a/test/vfd_swmr_remove_writer.c b/test/vfd_swmr_remove_writer.c index 200c884..658cdbf 100644 --- a/test/vfd_swmr_remove_writer.c +++ b/test/vfd_swmr_remove_writer.c @@ -73,9 +73,9 @@ static void usage(void); static hid_t open_skeleton(const char *filename, unsigned verbose, unsigned old) { - hid_t fid; /* File ID for new HDF5 file */ - hid_t fapl; /* File access property list */ - hid_t sid; /* Dataspace ID */ + hid_t fid = -1; /* File ID for new HDF5 file */ + hid_t fapl = -1; /* File access property list */ + hid_t sid = -1; /* Dataspace ID */ hsize_t dim[2]; /* Dataspace dimensions */ unsigned u, v; /* Local index variable */ H5F_vfd_swmr_config_t *config = NULL; /* Configuration for VFD SWMR */ @@ -84,11 +84,11 @@ open_skeleton(const char *filename, unsigned verbose, unsigned old) /* Create file access property list */ if((fapl = h5_fileaccess()) < 0) - return -1; + goto error; /* FOR NOW: set to use latest format, the "old" parameter is not used */ if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) - return -1; + goto error; #ifdef QAK /* Increase the initial size of the metadata cache */ @@ -116,11 +116,11 @@ open_skeleton(const char *filename, unsigned verbose, unsigned old) /* Enable page buffering */ if(H5Pset_page_buffer_size(fapl, 4096, 0, 0) < 0) - return -1; + goto error; /* Allocate memory for the configuration structure */ if((config = (H5F_vfd_swmr_config_t *)HDmalloc(sizeof(H5F_vfd_swmr_config_t))) == NULL) - return -1; + goto error; config->version = H5F__CURR_VFD_SWMR_CONFIG_VERSION; config->tick_len = 4; @@ -131,38 +131,57 @@ open_skeleton(const char *filename, unsigned verbose, unsigned old) /* Enable VFD SWMR configuration */ if(H5Pset_vfd_swmr_config(fapl, config) < 0) - return -1; + goto error; /* Open the file */ if((fid = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0) - return -1; + goto error; /* Close file access property list */ if(H5Pclose(fapl) < 0) - return -1; + goto error; if(config) HDfree(config); /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Opening datasets\n"); + HDfprintf(stderr, "WRITER: Opening datasets\n"); /* Open the datasets */ for(u = 0; u < NLEVELS; u++) for(v = 0; v < symbol_count[u]; v++) { if((symbol_info[u][v].dsid = H5Dopen2(fid, symbol_info[u][v].name, H5P_DEFAULT)) < 0) - return -1; + goto error; if((sid = H5Dget_space(symbol_info[u][v].dsid)) < 0) - return -1; + goto error; if(2 != H5Sget_simple_extent_ndims(sid)) - return -1; + goto error; if(H5Sget_simple_extent_dims(sid, dim, NULL) < 0) - return -1; + goto error; symbol_info[u][v].nrecords = dim[1]; + + if(H5Sclose(sid) < 0) + goto error; } /* end for */ return fid; + +error: + if(config) + HDfree(config); + + H5E_BEGIN_TRY { + for(u = 0; u < NLEVELS; u++) + for(v = 0; v < symbol_count[u]; v++) + H5Dclose(symbol_info[u][v].dsid); + H5Sclose(sid); + H5Pclose(fapl); + H5Fclose(fid); + } H5E_END_TRY; + + return -1; + } /* open_skeleton() */ @@ -215,7 +234,7 @@ remove_records(hid_t fid, unsigned verbose, unsigned long nshrinks, unsigned lon symbol->nrecords -= remove_size; dim[1] = symbol->nrecords; if(H5Dset_extent(symbol->dsid, dim) < 0) - return -1; + goto error; /* Check for flushing file */ if(flush_count > 0) { @@ -238,15 +257,25 @@ remove_records(hid_t fid, unsigned verbose, unsigned long nshrinks, unsigned lon /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Closing datasets\n"); + HDfprintf(stderr, "WRITER: Closing datasets\n"); /* Close the datasets */ for(u = 0; u < NLEVELS; u++) for(v = 0; v < symbol_count[u]; v++) if(H5Dclose(symbol_info[u][v].dsid) < 0) - return -1; + goto error; return 0; + +error: + H5E_BEGIN_TRY { + for(u = 0; u < NLEVELS; u++) + for(v = 0; v < symbol_count[u]; v++) + H5Dclose(symbol_info[u][v].dsid); + + } H5E_END_TRY; + + return -1; } /* remove_records() */ static void @@ -337,7 +366,7 @@ int main(int argc, const char *argv[]) /* Emit informational message */ if(verbose) { - HDfprintf(stderr, "Parameters:\n"); + HDfprintf(stderr, "WRITER: Parameters:\n"); HDfprintf(stderr, "\t# of shrinks between flushes = %ld\n", flush_count); HDfprintf(stderr, "\t# of shrinks = %ld\n", nshrinks); } /* end if */ @@ -350,11 +379,11 @@ int main(int argc, const char *argv[]) } /* end if */ HDsrandom(random_seed); /* ALWAYS emit the random seed for possible debugging */ - HDfprintf(stderr, "Using writer random seed: %u\n", random_seed); + HDfprintf(stderr, "WRITER: Using writer random seed: %u\n", random_seed); /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Generating symbol names\n"); + HDfprintf(stderr, "WRITER: Generating symbol names\n"); /* Generate dataset names */ if(generate_symbols() < 0) @@ -362,11 +391,11 @@ int main(int argc, const char *argv[]) /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Opening skeleton file: %s\n", FILENAME); + HDfprintf(stderr, "WRITER: Opening skeleton file: %s\n", FILENAME); /* Open file skeleton */ if((fid = open_skeleton(FILENAME, verbose, old)) < 0) { - HDfprintf(stderr, "Error opening skeleton file!\n"); + HDfprintf(stderr, "WRITER: Error opening skeleton file!\n"); HDexit(1); } /* end if */ @@ -375,31 +404,31 @@ int main(int argc, const char *argv[]) /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Removing records\n"); + HDfprintf(stderr, "WRITER: Removing records\n"); /* Remove records from datasets */ if(remove_records(fid, verbose, (unsigned long)nshrinks, (unsigned long)flush_count) < 0) { - HDfprintf(stderr, "Error removing records from datasets!\n"); + HDfprintf(stderr, "WRITER: Error removing records from datasets!\n"); HDexit(1); } /* end if */ /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Releasing symbols\n"); + HDfprintf(stderr, "WRITER: Releasing symbols\n"); /* Clean up the symbols */ if(shutdown_symbols() < 0) { - HDfprintf(stderr, "Error releasing symbols!\n"); + HDfprintf(stderr, "WRITER: Error releasing symbols!\n"); HDexit(1); } /* end if */ /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Closing objects\n"); + HDfprintf(stderr, "WRITER: Closing objects\n"); /* Close objects opened */ if(H5Fclose(fid) < 0) { - HDfprintf(stderr, "Error closing file!\n"); + HDfprintf(stderr, "WRITER: Error closing file!\n"); HDexit(1); } /* end if */ diff --git a/test/vfd_swmr_sparse_reader.c b/test/vfd_swmr_sparse_reader.c index 93c5ba6..e2d7058 100644 --- a/test/vfd_swmr_sparse_reader.c +++ b/test/vfd_swmr_sparse_reader.c @@ -90,8 +90,8 @@ static int check_dataset(hid_t fid, unsigned verbose, const symbol_info_t *symbol, symbol_t *record, hid_t rec_sid) { - hid_t dsid; /* Dataset ID */ - hid_t file_sid; /* Dataset's space ID */ + hid_t dsid = -1; /* Dataset ID */ + hid_t file_sid = -1; /* Dataset's space ID */ hsize_t start[2] = {0, 0}; /* Hyperslab selection values */ hsize_t count[2] = {1, 1}; /* Hyperslab selection values */ @@ -102,44 +102,54 @@ check_dataset(hid_t fid, unsigned verbose, const symbol_info_t *symbol, symbol_t /* Open dataset for symbol */ if((dsid = H5Dopen2(fid, symbol->name, H5P_DEFAULT)) < 0) - return -1; + goto error; /* Get the dataset's dataspace */ if((file_sid = H5Dget_space(dsid)) < 0) - return -1; + goto error; /* Choose the random record in the dataset (will be the same as chosen by * the writer) */ start[1] = (hsize_t)HDrandom() % symbol->nrecords; if(H5Sselect_hyperslab(file_sid, H5S_SELECT_SET, start, NULL, count, NULL) < 0) - return -1; + goto error; /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Symbol = '%s', location = %lld\n", symbol->name, (long long)start); + HDfprintf(stderr, "READER: Symbol = '%s', nrecords = %Hu, name = %s, location = %Hu, %Hu\n", \ + symbol->name, symbol->nrecords, symbol->name, start[0], start[1]); /* Read record from dataset */ record->rec_id = (uint64_t)ULLONG_MAX; if(H5Dread(dsid, symbol_tid, rec_sid, file_sid, H5P_DEFAULT, record) < 0) - return -1; + goto error; /* Verify record value */ if(record->rec_id != start[1]) { - HDfprintf(stderr, "*** ERROR ***\n"); + HDfprintf(stderr, "*** READER: ERROR ***\n"); HDfprintf(stderr, "Incorrect record value!\n"); HDfprintf(stderr, "Symbol = '%s', location = %lld, record->rec_id = %llu\n", symbol->name, (long long)start, (unsigned long long)record->rec_id); - return -1; + goto error; } /* end if */ /* Close the dataset's dataspace */ if(H5Sclose(file_sid) < 0) - return -1; + goto error; /* Close dataset for symbol */ if(H5Dclose(dsid) < 0) - return -1; + goto error; return 0; + +error: + + H5E_BEGIN_TRY { + H5Sclose(file_sid); + H5Dclose(dsid); + } H5E_END_TRY; + + return -1; } /* end check_dataset() */ @@ -190,20 +200,21 @@ read_records(const char *filename, unsigned verbose, unsigned long nrecords, /* Create file access property list */ if((fapl = h5_fileaccess()) < 0) - return -1; + goto error; - H5Pset_fclose_degree(fapl, H5F_CLOSE_SEMI); + if(H5Pset_fclose_degree(fapl, H5F_CLOSE_SEMI) < 0) + goto error; /* * Set up to open the file with VFD SWMR configured. */ /* Enable page buffering */ if(H5Pset_page_buffer_size(fapl, 4096, 0, 0) < 0) - return -1; + goto error; /* Allocate memory for the configuration structure */ if((config = (H5F_vfd_swmr_config_t *)HDmalloc(sizeof(H5F_vfd_swmr_config_t))) == NULL) - return -1; + goto error; config->version = H5F__CURR_VFD_SWMR_CONFIG_VERSION; config->tick_len = 4; @@ -214,23 +225,30 @@ read_records(const char *filename, unsigned verbose, unsigned long nrecords, /* Enable VFD SWMR configuration */ if(H5Pset_vfd_swmr_config(fapl, config) < 0) - return -1; + goto error; /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Opening file: %s\n", filename); + HDfprintf(stderr, "READER: Opening file: %s\n", filename); /* Open the file */ - if((fid = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0) - return -1; + /* Remove H5E_BEGIN_TRY/END_TRY to see the error stack if error */ + H5E_BEGIN_TRY { + fid = H5Fopen(filename, H5F_ACC_RDONLY, fapl); + } H5E_END_TRY; + if(fid < 0) { + HDfprintf(stderr, "READER: Error in opening the file: %s\n", filename); + goto error; + } else + HDfprintf(stderr, "READER: SUCCESS in opening the file: %s\n", filename); /* Seed the random number generator with the attribute in the file */ if((aid = H5Aopen(fid, "seed", H5P_DEFAULT)) < 0) - return -1; + goto error; if(H5Aread(aid, H5T_NATIVE_UINT, &seed) < 0) - return -1; + goto error; if(H5Aclose(aid) < 0) - return -1; + goto error; HDsrandom(seed); /* Reset the record */ @@ -239,11 +257,11 @@ read_records(const char *filename, unsigned verbose, unsigned long nrecords, /* Create a dataspace for the record to read */ if((mem_sid = H5Screate(H5S_SCALAR)) < 0) - return -1; + goto error; /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Reading records\n"); + HDfprintf(stderr, "READER: Reading records\n"); /* Get the starting time */ start_time = HDtime(NULL); @@ -265,16 +283,16 @@ read_records(const char *filename, unsigned verbose, unsigned long nrecords, do { /* Check if sequence attribute exists */ if((attr_exists = H5Aexists_by_name(fid, symbol->name, "seq", H5P_DEFAULT)) < 0) - return -1; + goto error; if(attr_exists) { /* Read sequence number attribute */ if((aid = H5Aopen_by_name(fid, symbol->name, "seq", H5P_DEFAULT, H5P_DEFAULT)) < 0) - return -1; + goto error; if(H5Aread(aid, H5T_NATIVE_ULONG, &file_u) < 0) - return -1; + goto error; if(H5Aclose(aid) < 0) - return -1; + goto error; /* Check if sequence number is at least u - if so, this should * guarantee that this record has been written */ @@ -284,32 +302,43 @@ read_records(const char *filename, unsigned verbose, unsigned long nrecords, /* Check for timeout */ if(HDtime(NULL) >= (time_t)(start_time + (time_t)TIMEOUT)) { - HDfprintf(stderr, "Reader timed out\n"); - return -1; + HDfprintf(stderr, "READER: Reader timed out\n"); + goto error; } /* end if */ /* Pause */ HDsleep(poll_time); + /* Emit informational message */ + if(verbose) + HDfprintf(stderr, "READER: Reopening file (do while loop): %s\n", filename); + /* Retrieve and print the collection of metadata read retries */ if(print_metadata_retries_info(fid) < 0) - HDfprintf(stderr, "Warning: could not obtain metadata retries info\n"); + HDfprintf(stderr, "READER: Warning: could not obtain metadata retries info\n"); /* Reopen the file */ if(H5Fclose(fid) < 0) - return -1; - if((fid = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0) - return -1; + goto error; + + /* Remove H5E_BEGIN_TRY/END_TRY if you want to see the error stack */ + H5E_BEGIN_TRY { + fid = H5Fopen(filename, H5F_ACC_RDONLY, fapl); + } H5E_END_TRY; + if(fid < 0) { + HDfprintf(stderr, "READER: Error in reopening the file (do while loop): %s\n", filename); + goto error; + } iter_to_reopen = reopen_count; } while(1); /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Checking dataset %lu\n", u); + HDfprintf(stderr, "READER: Checking dataset %lu\n", u); /* Check dataset */ if(check_dataset(fid, verbose, symbol, &record, mem_sid) < 0) - return -1; + goto error; HDmemset(&record, 0, sizeof(record)); /* Check for reopen */ @@ -317,41 +346,62 @@ read_records(const char *filename, unsigned verbose, unsigned long nrecords, if(iter_to_reopen == 0) { /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Reopening file: %s\n", filename); + HDfprintf(stderr, "READER: Reopening file (iter_to_reopen): %s\n", filename); /* Retrieve and print the collection of metadata read retries */ if(print_metadata_retries_info(fid) < 0) - HDfprintf(stderr, "Warning: could not obtain metadata retries info\n"); + HDfprintf(stderr, "READER: Warning: could not obtain metadata retries info\n"); /* Reopen the file */ if(H5Fclose(fid) < 0) - return -1; - if((fid = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0) - return -1; + goto error; + + /* Remove H5E_BEGIN_TRY/END_TRY to see the error stack if error */ + H5E_BEGIN_TRY { + fid = H5Fopen(filename, H5F_ACC_RDONLY, fapl); + } H5E_END_TRY; + if(fid < 0) { + HDfprintf(stderr, "READER: Error in reopening the file (iter_to_reopen): %s\n", filename); + goto error; + } + iter_to_reopen = reopen_count; } /* end if */ } /* end while */ /* Retrieve and print the collection of metadata read retries */ if(print_metadata_retries_info(fid) < 0) - HDfprintf(stderr, "Warning: could not obtain metadata retries info\n"); + HDfprintf(stderr, "READER: Warning: could not obtain metadata retries info\n"); /* Close file */ if(H5Fclose(fid) < 0) - return -1; + goto error; /* Close the memory dataspace */ if(H5Sclose(mem_sid) < 0) - return -1; + goto error; /* Close the file access property list */ if(H5Pclose(fapl) < 0) - return -1; + goto error; if(config) HDfree(config); return 0; + +error: + if(config) + HDfree(config); + + H5E_BEGIN_TRY { + H5Aclose(aid); + H5Sclose(mem_sid); + H5Fclose(fid); + H5Pclose(fapl); + } H5E_END_TRY; + + return -1; } /* end read_records() */ static void @@ -428,7 +478,7 @@ int main(int argc, const char *argv[]) /* Emit informational message */ if(verbose) { - HDfprintf(stderr, "Parameters:\n"); + HDfprintf(stderr, "READER: Parameters:\n"); HDfprintf(stderr, "\t# of seconds between polling = %d\n", poll_time); HDfprintf(stderr, "\t# of reads between reopens = %d\n", reopen_count); HDfprintf(stderr, "\t# of records to read = %ld\n", nrecords); @@ -436,41 +486,43 @@ int main(int argc, const char *argv[]) /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Generating symbol names\n"); + HDfprintf(stderr, "READER: Generating symbol names\n"); /* Generate dataset names */ if(generate_symbols() < 0) { - HDfprintf(stderr, "Error generating symbol names!\n"); + HDfprintf(stderr, "READER: Error generating symbol names!\n"); HDexit(1); } /* end if */ /* Create datatype for creating datasets */ - if((symbol_tid = create_symbol_datatype()) < 0) - return -1; + if((symbol_tid = create_symbol_datatype()) < 0) { + HDfprintf(stderr, "READER: Error creating symbol datatype!\n"); + HDexit(1); + } /* Reading records from datasets */ if(read_records(FILENAME, verbose, (unsigned long) nrecords, (unsigned)poll_time, (unsigned)reopen_count) < 0) { - HDfprintf(stderr, "Error reading records from datasets!\n"); + HDfprintf(stderr, "READER: Error reading records from datasets!\n"); HDexit(1); } /* end if */ /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Releasing symbols\n"); + HDfprintf(stderr, "READER: Releasing symbols\n"); /* Clean up the symbols */ if(shutdown_symbols() < 0) { - HDfprintf(stderr, "Error releasing symbols!\n"); + HDfprintf(stderr, "READER: Error releasing symbols!\n"); HDexit(1); } /* end if */ /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Closing objects\n"); + HDfprintf(stderr, "READER: Closing objects\n"); /* Close objects created */ if(H5Tclose(symbol_tid) < 0) { - HDfprintf(stderr, "Error closing symbol datatype!\n"); + HDfprintf(stderr, "READER: Error closing symbol datatype!\n"); HDexit(1); } /* end if */ diff --git a/test/vfd_swmr_sparse_writer.c b/test/vfd_swmr_sparse_writer.c index bf1728a..2411c1f 100644 --- a/test/vfd_swmr_sparse_writer.c +++ b/test/vfd_swmr_sparse_writer.c @@ -72,9 +72,9 @@ static void usage(void); static hid_t open_skeleton(const char *filename, unsigned verbose) { - hid_t fid; /* File ID for new HDF5 file */ - hid_t fapl; /* File access property list */ - hid_t aid; /* Attribute ID */ + hid_t fid = -1; /* File ID for new HDF5 file */ + hid_t fapl = -1; /* File access property list */ + hid_t aid = -1; /* Attribute ID */ unsigned seed; /* Seed for random number generator */ unsigned u, v; /* Local index variable */ H5F_vfd_swmr_config_t *config = NULL; /* Configuration for VFD SWMR */ @@ -83,11 +83,11 @@ open_skeleton(const char *filename, unsigned verbose) /* Create file access property list */ if((fapl = h5_fileaccess()) < 0) - return -1; + goto error; /* Set to use the latest library format */ if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) - return -1; + goto error; #ifdef QAK /* Increase the initial size of the metadata cache */ @@ -115,11 +115,11 @@ open_skeleton(const char *filename, unsigned verbose) /* Enable page buffering */ if(H5Pset_page_buffer_size(fapl, 4096, 0, 0) < 0) - return -1; + goto error; /* Allocate memory for the configuration structure */ if((config = (H5F_vfd_swmr_config_t *)HDmalloc(sizeof(H5F_vfd_swmr_config_t))) == NULL) - return -1; + goto error; config->version = H5F__CURR_VFD_SWMR_CONFIG_VERSION; config->tick_len = 4; @@ -130,30 +130,30 @@ open_skeleton(const char *filename, unsigned verbose) /* Enable VFD SWMR configuration */ if(H5Pset_vfd_swmr_config(fapl, config) < 0) - return -1; + goto error; /* Open the file */ if((fid = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0) - return -1; + goto error; /* Close file access property list */ if(H5Pclose(fapl) < 0) - return -1; + goto error; if(config) HDfree(config); /* Emit informational message */ if(verbose) - fprintf(stderr, "Opening datasets\n"); + fprintf(stderr, "WRITER: Opening datasets\n"); /* Seed the random number generator with the attribute in the file */ if((aid = H5Aopen(fid, "seed", H5P_DEFAULT)) < 0) - return -1; + goto error; if(H5Aread(aid, H5T_NATIVE_UINT, &seed) < 0) - return -1; + goto error; if(H5Aclose(aid) < 0) - return -1; + goto error; HDsrandom(seed); /* Open the datasets */ @@ -165,6 +165,22 @@ open_skeleton(const char *filename, unsigned verbose) } /* end for */ return fid; + +error: + if(config) + HDfree(config); + + H5E_BEGIN_TRY { + for(u = 0; u < NLEVELS; u++) + for(v = 0; v < symbol_count[u]; v++) + H5Dclose(symbol_info[u][v].dsid); + H5Aclose(aid); + H5Pclose(fapl); + H5Fclose(fid); + } H5E_END_TRY; + + return -1; + } /* open_skeleton() */ @@ -194,8 +210,10 @@ open_skeleton(const char *filename, unsigned verbose) static int add_records(hid_t fid, unsigned verbose, unsigned long nrecords, unsigned long flush_count) { - hid_t tid; /* Datatype ID for records */ - hid_t mem_sid; /* Memory dataspace ID */ + hid_t tid = -1; /* Datatype ID for records */ + hid_t mem_sid = -1; /* Memory dataspace ID */ + hid_t file_sid = -1; /* Dataset's space ID */ + hid_t aid = -1; /* Attribute ID */ hsize_t start[2] = {0, 0}; /* Hyperslab selection values */ hsize_t count[2] = {1, 1}; /* Hyperslab selection values */ symbol_t record; /* The record to add to the dataset */ @@ -214,18 +232,16 @@ add_records(hid_t fid, unsigned verbose, unsigned long nrecords, unsigned long f /* Create a dataspace for the record to add */ if((mem_sid = H5Screate(H5S_SCALAR)) < 0) - return -1; + goto error; /* Create datatype for appending records */ if((tid = create_symbol_datatype()) < 0) - return -1; + goto error; /* Add records to random datasets, according to frequency distribution */ rec_to_flush = flush_count; for(u = 0; u < nrecords; u++) { symbol_info_t *symbol; /* Symbol to write record to */ - hid_t file_sid; /* Dataset's space ID */ - hid_t aid; /* Attribute ID */ hbool_t corked; /* Whether the dataset was corked */ /* Get a random dataset, according to the symbol distribution */ @@ -240,22 +256,22 @@ add_records(hid_t fid, unsigned verbose, unsigned long nrecords, unsigned long f /* Cork the metadata cache, to prevent the object header from being * flushed before the data has been written */ if(H5Odisable_mdc_flushes(symbol->dsid) < 0) - return -1; + goto error; corked = TRUE; if(H5Dset_extent(symbol->dsid, dim) < 0) - return -1; + goto error; if((file_sid = H5Screate(H5S_SCALAR)) < 0) - return -1; + goto error; if((aid = H5Acreate2(symbol->dsid, "seq", H5T_NATIVE_ULONG, file_sid, H5P_DEFAULT, H5P_DEFAULT)) < 0) - return -1; + goto error; if(H5Sclose(file_sid) < 0) - return -1; + goto error; } /* end if */ else { if((aid = H5Aopen(symbol->dsid, "seq", H5P_DEFAULT)) < 0) - return -1; + goto error; corked = FALSE; } /* end else */ @@ -267,15 +283,15 @@ add_records(hid_t fid, unsigned verbose, unsigned long nrecords, unsigned long f /* Get the dataset's dataspace */ if((file_sid = H5Dget_space(symbol->dsid)) < 0) - return -1; + goto error; /* Choose a random record in the dataset */ if(H5Sselect_hyperslab(file_sid, H5S_SELECT_SET, start, NULL, count, NULL) < 0) - return -1; + goto error; /* Write record to the dataset */ if(H5Dwrite(symbol->dsid, tid, mem_sid, file_sid, H5P_DEFAULT, &record) < 0) - return -1; + goto error; /* Write the sequence number attribute. Since we synchronize the random * number seed, the readers will always generate the same sequence of @@ -284,20 +300,20 @@ add_records(hid_t fid, unsigned verbose, unsigned long nrecords, unsigned long f * guaranteed to see the written data if the sequence attribute is >=u. */ if(H5Awrite(aid, H5T_NATIVE_ULONG, &u) < 0) - return -1; + goto error; /* Close the attribute */ if(H5Aclose(aid) < 0) - return -1; + goto error; /* Uncork the metadata cache, if it's been */ if(corked) if(H5Oenable_mdc_flushes(symbol->dsid) < 0) - return -1; + goto error; /* Close the dataset's dataspace */ if(H5Sclose(file_sid) < 0) - return -1; + goto error; /* Check for flushing file */ if(flush_count > 0) { @@ -333,23 +349,38 @@ add_records(hid_t fid, unsigned verbose, unsigned long nrecords, unsigned long f /* Close the memory dataspace */ if(H5Sclose(mem_sid) < 0) - return -1; + goto error; /* Close the datatype */ if(H5Tclose(tid) < 0) - return -1; + goto error; /* Emit informational message */ if(verbose) - fprintf(stderr, "Closing datasets\n"); + fprintf(stderr, "WRITER: Closing datasets\n"); /* Close the datasets */ for(u = 0; u < NLEVELS; u++) for(v = 0; v < symbol_count[u]; v++) if(H5Dclose(symbol_info[u][v].dsid) < 0) - return -1; + goto error; return 0; + +error: + H5E_BEGIN_TRY { + H5Sclose(mem_sid); + H5Sclose(file_sid); + H5Tclose(tid); + H5Aclose(aid); + + for(u = 0; u < NLEVELS; u++) + for(v = 0; v < symbol_count[u]; v++) + H5Dclose(symbol_info[u][v].dsid); + + } H5E_END_TRY; + + return -1; } /* add_records() */ static void @@ -422,14 +453,14 @@ int main(int argc, const char *argv[]) /* Emit informational message */ if(verbose) { - HDfprintf(stderr, "Parameters:\n"); + HDfprintf(stderr, "WRITER: Parameters:\n"); HDfprintf(stderr, "\t# of records between flushes = %ld\n", flush_count); HDfprintf(stderr, "\t# of records to write = %ld\n", nrecords); } /* end if */ /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Generating symbol names\n"); + HDfprintf(stderr, "WRITER: Generating symbol names\n"); /* Generate dataset names */ if(generate_symbols() < 0) @@ -437,11 +468,11 @@ int main(int argc, const char *argv[]) /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Opening skeleton file: %s\n", FILENAME); + HDfprintf(stderr, "WRITER: Opening skeleton file: %s\n", FILENAME); /* Open file skeleton */ if((fid = open_skeleton(FILENAME, verbose)) < 0) { - HDfprintf(stderr, "Error opening skeleton file!\n"); + HDfprintf(stderr, "WRITER: Error opening skeleton file!\n"); HDexit(1); } /* end if */ @@ -450,31 +481,31 @@ int main(int argc, const char *argv[]) /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Adding records\n"); + HDfprintf(stderr, "WRITER: Adding records\n"); /* Append records to datasets */ if(add_records(fid, verbose, (unsigned long)nrecords, (unsigned long)flush_count) < 0) { - HDfprintf(stderr, "Error appending records to datasets!\n"); + HDfprintf(stderr, "WRITER: Error appending records to datasets!\n"); HDexit(1); } /* end if */ /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Releasing symbols\n"); + HDfprintf(stderr, "WRITER: Releasing symbols\n"); /* Clean up the symbols */ if(shutdown_symbols() < 0) { - HDfprintf(stderr, "Error releasing symbols!\n"); + HDfprintf(stderr, "WRITER: Error releasing symbols!\n"); HDexit(1); } /* end if */ /* Emit informational message */ if(verbose) - HDfprintf(stderr, "Closing objects\n"); + HDfprintf(stderr, "WRITER: Closing objects/file\n"); /* Close objects opened */ if(H5Fclose(fid) < 0) { - HDfprintf(stderr, "Error closing file!\n"); + HDfprintf(stderr, "WRITER: Error closing file!\n"); HDexit(1); } /* end if */ diff --git a/test/vfd_swmr_writer.c b/test/vfd_swmr_writer.c index 5e19ba7..dbf1f80 100644 --- a/test/vfd_swmr_writer.c +++ b/test/vfd_swmr_writer.c @@ -150,7 +150,7 @@ open_skeleton(const char *filename, hbool_t verbose, FILE *verbose_file, /* Emit informational message */ if(verbose) - HDfprintf(verbose_file, "Opening datasets\n"); + HDfprintf(verbose_file, "WRITER: Opening datasets\n"); /* Open the datasets */ for(u = 0; u < NLEVELS; u++) @@ -291,7 +291,7 @@ add_records(hid_t fid, hbool_t verbose, FILE *verbose_file, /* Emit informational message */ if(verbose) - HDfprintf(verbose_file, "Closing datasets\n"); + HDfprintf(verbose_file, "WRITER: Closing datasets\n"); /* Close the datasets */ for(u = 0; u < NLEVELS; u++) @@ -406,14 +406,14 @@ int main(int argc, const char *argv[]) HDsnprintf(verbose_name, sizeof(verbose_name), "vfd_swmr_writer.out.%u", random_seed); if(NULL == (verbose_file = HDfopen(verbose_name, "w"))) { - HDfprintf(stderr, "Can't open verbose output file!\n"); + HDfprintf(stderr, "WRITER: Can't open verbose output file!\n"); HDexit(1); } } /* end if */ /* Emit informational message */ if(verbose) { - HDfprintf(verbose_file, "Parameters:\n"); + HDfprintf(verbose_file, "WRITER: Parameters:\n"); HDfprintf(verbose_file, "\t# of records between flushes = %ld\n", flush_count); HDfprintf(verbose_file, "\t# of records to write = %ld\n", nrecords); } /* end if */ @@ -423,7 +423,7 @@ int main(int argc, const char *argv[]) /* Emit informational message */ if(verbose) - HDfprintf(verbose_file, "Generating symbol names\n"); + HDfprintf(verbose_file, "WRITER: Generating symbol names\n"); /* Generate dataset names */ if(generate_symbols() < 0) @@ -431,11 +431,11 @@ int main(int argc, const char *argv[]) /* Emit informational message */ if(verbose) - HDfprintf(verbose_file, "Opening skeleton file: %s\n", FILENAME); + HDfprintf(verbose_file, "WRITER: Opening skeleton file: %s\n", FILENAME); /* Open file skeleton */ if((fid = open_skeleton(FILENAME, verbose, verbose_file, random_seed, old)) < 0) { - HDfprintf(stderr, "Error opening skeleton file!\n"); + HDfprintf(stderr, "WRITER: Error opening skeleton file!\n"); HDexit(1); } /* end if */ @@ -444,31 +444,31 @@ int main(int argc, const char *argv[]) /* Emit informational message */ if(verbose) - HDfprintf(verbose_file, "Adding records\n"); + HDfprintf(verbose_file, "WRITER: Adding records\n"); /* Append records to datasets */ if(add_records(fid, verbose, verbose_file, (unsigned long)nrecords, (unsigned long)flush_count) < 0) { - HDfprintf(stderr, "Error appending records to datasets!\n"); + HDfprintf(stderr, "WRITER: Error appending records to datasets!\n"); HDexit(1); } /* end if */ /* Emit informational message */ if(verbose) - HDfprintf(verbose_file, "Releasing symbols\n"); + HDfprintf(verbose_file, "WRITER: Releasing symbols\n"); /* Clean up the symbols */ if(shutdown_symbols() < 0) { - HDfprintf(stderr, "Error releasing symbols!\n"); + HDfprintf(stderr, "WRITER: Error releasing symbols!\n"); HDexit(1); } /* end if */ /* Emit informational message */ if(verbose) - HDfprintf(verbose_file, "Closing objects\n"); + HDfprintf(verbose_file, "WRITER: Closing objects/file\n"); /* Close objects opened */ if(H5Fclose(fid) < 0) { - HDfprintf(stderr, "Error closing file!\n"); + HDfprintf(stderr, "WRITER: Error closing file!\n"); HDexit(1); } /* end if */ |