summaryrefslogtreecommitdiffstats
path: root/test/swmr_remove_reader.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/swmr_remove_reader.c')
-rw-r--r--test/swmr_remove_reader.c148
1 files changed, 88 insertions, 60 deletions
diff --git a/test/swmr_remove_reader.c b/test/swmr_remove_reader.c
index 518ea4e..26c52d8 100644
--- a/test/swmr_remove_reader.c
+++ b/test/swmr_remove_reader.c
@@ -1,7 +1,24 @@
-#include "swmr_common.h"
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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 files COPYING and Copyright.html. COPYING can be found at the root *
+ * of the source code distribution tree; Copyright.html can be found at the *
+ * root level of an installed copy of the electronic HDF5 document set and *
+ * is linked from the top-level documents page. It can also be found at *
+ * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
+ * access to either file, you may request a copy from help@hdfgroup.org. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
#include <unistd.h>
+#include <sys/time.h>
+
+#include "swmr_common.h"
-static hid_t symbol_tid = (-1);
+static hid_t symbol_tid = -1;
static int
check_dataset(hid_t fid, unsigned verbose, const char *sym_name, symbol_t *record,
@@ -14,19 +31,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);
+ return -1;
/* Get the dataset's dataspace */
if((file_sid = H5Dget_space(dsid)) < 0)
- return(-1);
+ return -1;
/* Get the number of elements (= records, for 1-D datasets) */
if((snpoints = H5Sget_simple_extent_npoints(file_sid)) < 0)
- return(-1);
+ return -1;
/* Emit informational message */
if(verbose)
- printf("Symbol = '%s', # of records = %lld\n", sym_name, (long long)snpoints);
+ fprintf(stderr, "Symbol = '%s', # of records = %lld\n", sym_name, (long long)snpoints);
/* Check if there are records for symbol */
if(snpoints > 0) {
@@ -36,7 +53,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);
+ return -1;
/* Read record from dataset */
#ifdef FILLVAL_WORKS
@@ -49,27 +66,28 @@ 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);
+ return -1;
/* 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) {
- printf("Incorrect record value!\n");
- printf("Symbol = '%s', # of records = %lld, record->rec_id = %llx\n", sym_name, (long long)snpoints, (unsigned long long)record->rec_id);
- return(-1);
+ fprintf(stderr, "*** ERROR ***\n");
+ fprintf(stderr, "Incorrect record value!\n");
+ fprintf(stderr, "Symbol = '%s', # of records = %lld, record->rec_id = %llx\n", sym_name, (long long)snpoints, (unsigned long long)record->rec_id);
+ return -1;
} /* end if */
} /* end if */
/* Close the dataset's dataspace */
if(H5Sclose(file_sid) < 0)
- return(-1);
+ return -1;
/* Close dataset for symbol */
if(H5Dclose(dsid) < 0)
- return(-1);
+ return -1;
- return(0);
+ return 0;
} /* end check_dataset() */
static int
@@ -89,13 +107,13 @@ read_records(const char *filename, unsigned verbose, unsigned long nseconds,
/* Emit informational message */
if(verbose)
- printf("Choosing datasets\n");
+ fprintf(stderr, "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 **)malloc(sizeof(symbol_info_t *) * ncommon)))
- return(-1);
+ return -1;
/* Open the common datasets */
for(v = 0; v < ncommon; v++) {
@@ -108,7 +126,7 @@ read_records(const char *filename, unsigned verbose, unsigned long nseconds,
/* Emit informational message */
if(verbose)
- printf("Common symbol #%u = '%s'\n", v, symbol_info[0][offset].name);
+ fprintf(stderr, "Common symbol #%u = '%s'\n", v, symbol_info[0][offset].name);
} /* end for */
} /* end if */
@@ -116,7 +134,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 **)malloc(sizeof(symbol_info_t *) * nrandom)))
- return(-1);
+ return -1;
/* Determine the random datasets */
for(v = 0; v < nrandom; v++) {
@@ -124,22 +142,22 @@ read_records(const char *filename, unsigned verbose, unsigned long nseconds,
/* Determine the symbol, within all symbols */
if(NULL == (sym = choose_dataset()))
- return(-1);
+ return -1;
sym_rand[v] = sym;
/* Emit informational message */
if(verbose)
- printf("Random symbol #%u = '%s'\n", v, sym->name);
+ fprintf(stderr, "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);
+ return -1;
/* Emit informational message */
if(verbose)
- printf("Reading records\n");
+ fprintf(stderr, "Reading records\n");
/* Get the starting time */
start_time = time(NULL);
@@ -151,23 +169,23 @@ read_records(const char *filename, unsigned verbose, unsigned long nseconds,
/* Emit informational message */
if(verbose)
- printf("Opening file: %s\n", filename);
+ fprintf(stderr, "Opening file: %s\n", filename);
/* Open the file */
if((fid = H5Fopen(filename, H5F_ACC_RDONLY | H5F_ACC_SWMR_READ, H5P_DEFAULT)) < 0)
- return(-1);
+ return -1;
/* Check 'common' datasets, if any */
if(ncommon > 0) {
/* Emit informational message */
if(verbose)
- printf("Checking common symbols\n");
+ fprintf(stderr, "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);
+ return -1;
} /* end for */
} /* end if */
@@ -175,23 +193,23 @@ read_records(const char *filename, unsigned verbose, unsigned long nseconds,
if(nrandom > 0) {
/* Emit informational message */
if(verbose)
- printf("Checking random symbols\n");
+ fprintf(stderr, "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);
+ return -1;
} /* end for */
} /* end if */
/* Emit informational message */
if(verbose)
- printf("Closing file\n");
+ fprintf(stderr, "Closing file\n");
/* Close the file */
if(H5Fclose(fid) < 0)
- return(-1);
+ return -1;
/* Sleep for the appropriate # of seconds */
sleep(poll_time);
@@ -202,11 +220,11 @@ read_records(const char *filename, unsigned verbose, unsigned long nseconds,
/* Close the memory dataspace */
if(H5Sclose(mem_sid) < 0)
- return(-1);
+ return -1;
/* Emit informational message */
if(verbose)
- printf("Closing datasets\n");
+ fprintf(stderr, "Closing datasets\n");
/* Close 'random' datasets, if any */
if(nrandom > 0) {
@@ -220,7 +238,7 @@ read_records(const char *filename, unsigned verbose, unsigned long nseconds,
free(sym_com);
} /* end if */
- return(0);
+ return 0;
} /* end read_records() */
static void
@@ -234,13 +252,15 @@ usage(void)
int main(int argc, const char *argv[])
{
- long nseconds = 0; /* # of seconds to test */
- int poll_time = 1; /* # of seconds between polling */
- int ncommon = 5; /* # of common symbols to poll */
- int nrandom = 10; /* # of random symbols to poll */
- unsigned verbose = 1; /* Whether to emit some informational messages */
- int random_seed = 0; /* Random # seed */
- unsigned u; /* Local index variables */
+ long nseconds = 0; /* # of seconds to test */
+ int poll_time = 1; /* # of seconds between polling */
+ int ncommon = 5; /* # of common symbols to poll */
+ int nrandom = 10; /* # of random symbols to poll */
+ unsigned verbose = 1; /* Whether to emit some informational messages */
+ unsigned use_seed = 0; /* Set to 1 if a seed was set on the command line */
+ unsigned random_seed = 0; /* Random # seed */
+ unsigned u; /* Local index variables */
+ int temp;
/* Parse command line options */
if(argc < 2)
@@ -274,9 +294,12 @@ int main(int argc, const char *argv[])
/* Random # seed */
case 'r':
- random_seed = atoi(argv[u + 1]);
- if(random_seed < 0)
+ use_seed = 1;
+ temp = atoi(argv[u + 1]);
+ if(temp < 0)
usage();
+ else
+ random_seed = (unsigned)temp;
u += 2;
break;
@@ -310,57 +333,62 @@ int main(int argc, const char *argv[])
/* Emit informational message */
if(verbose) {
- printf("Parameters:\n");
- printf("\t# of seconds between polling = %d\n", poll_time);
- printf("\t# of common symbols to poll = %d\n", ncommon);
- printf("\t# of random symbols to poll = %d\n", nrandom);
- printf("\t# of seconds to test = %ld\n", nseconds);
+ fprintf(stderr, "Parameters:\n");
+ fprintf(stderr, "\t# of seconds between polling = %d\n", poll_time);
+ fprintf(stderr, "\t# of common symbols to poll = %d\n", ncommon);
+ fprintf(stderr, "\t# of random symbols to poll = %d\n", nrandom);
+ fprintf(stderr, "\t# of seconds to test = %ld\n", nseconds);
} /* end if */
- /* Create randomized set of numbers */
- random_seed += (int)time(NULL);
- srandom((unsigned)random_seed);
+ /* Set the random seed */
+ if(0 == use_seed) {
+ struct timeval t;
+ gettimeofday(&t, NULL);
+ random_seed = (unsigned)((t.tv_sec * 1000) + t.tv_usec);
+ } /* end if */
+ srandom(random_seed);
+ /* ALWAYS emit the random seed for possible debugging */
+ fprintf(stderr, "Using reader random seed: %u\n", random_seed);
/* Emit informational message */
if(verbose)
- printf("Generating symbol names\n");
+ fprintf(stderr, "Generating symbol names\n");
/* Generate dataset names */
if(generate_symbols() < 0) {
- printf("Error generating symbol names!\n");
+ fprintf(stderr, "Error generating symbol names!\n");
exit(1);
} /* end if */
/* Create datatype for creating datasets */
if((symbol_tid = create_symbol_datatype()) < 0)
- return(-1);
+ return -1;
/* Reading records from datasets */
if(read_records(FILENAME, verbose, (unsigned long)nseconds, (unsigned)poll_time, (unsigned)ncommon, (unsigned)nrandom) < 0) {
- printf("Error reading records from datasets!\n");
+ fprintf(stderr, "Error reading records from datasets!\n");
exit(1);
} /* end if */
/* Emit informational message */
if(verbose)
- printf("Releasing symbols\n");
+ fprintf(stderr, "Releasing symbols\n");
/* Clean up the symbols */
if(shutdown_symbols() < 0) {
- printf("Error releasing symbols!\n");
+ fprintf(stderr, "Error releasing symbols!\n");
exit(1);
} /* end if */
/* Emit informational message */
if(verbose)
- printf("Closing objects\n");
+ fprintf(stderr, "Closing objects\n");
/* Close objects created */
if(H5Tclose(symbol_tid) < 0) {
- printf("Error closing symbol datatype!\n");
+ fprintf(stderr, "Error closing symbol datatype!\n");
exit(1);
} /* end if */
- return(0);
+ return 0;
}
-