summaryrefslogtreecommitdiffstats
path: root/test/swmr_sparse_reader.c
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2020-10-01 15:29:53 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2020-10-01 15:29:53 (GMT)
commitec8ad09125032c9c232878d02e90aa86df162841 (patch)
tree5d63105d3a0db7d5bbee41c5b74b097649a2115e /test/swmr_sparse_reader.c
parent453238e90e1574ef1c15e3c79f7fb3d77920e77c (diff)
downloadhdf5-ec8ad09125032c9c232878d02e90aa86df162841.zip
hdf5-ec8ad09125032c9c232878d02e90aa86df162841.tar.gz
hdf5-ec8ad09125032c9c232878d02e90aa86df162841.tar.bz2
Source formatted
Diffstat (limited to 'test/swmr_sparse_reader.c')
-rw-r--r--test/swmr_sparse_reader.c188
1 files changed, 95 insertions, 93 deletions
diff --git a/test/swmr_sparse_reader.c b/test/swmr_sparse_reader.c
index 2d558df..e871226 100644
--- a/test/swmr_sparse_reader.c
+++ b/test/swmr_sparse_reader.c
@@ -48,13 +48,12 @@ static hid_t symbol_tid = (-1);
/* Local Prototypes */
/********************/
-static int check_dataset(hid_t fid, unsigned verbose, const symbol_info_t *symbol,
- symbol_t *record, hid_t rec_sid);
-static int read_records(const char *filename, unsigned verbose, unsigned long nrecords,
- unsigned poll_time, unsigned reopen_count);
+static int check_dataset(hid_t fid, unsigned verbose, const symbol_info_t *symbol, symbol_t *record,
+ hid_t rec_sid);
+static int read_records(const char *filename, unsigned verbose, unsigned long nrecords, unsigned poll_time,
+ unsigned reopen_count);
static void usage(void);
-
/*-------------------------------------------------------------------------
* Function: check_dataset
*
@@ -86,13 +85,12 @@ static void usage(void);
*-------------------------------------------------------------------------
*/
static int
-check_dataset(hid_t fid, unsigned verbose, const symbol_info_t *symbol, symbol_t *record,
- hid_t rec_sid)
+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 */
- hsize_t start[2] = {0, 0}; /* Hyperslab selection values */
- hsize_t count[2] = {1, 1}; /* Hyperslab selection values */
+ hid_t dsid; /* Dataset ID */
+ hid_t file_sid; /* Dataset's space ID */
+ hsize_t start[2] = {0, 0}; /* Hyperslab selection values */
+ hsize_t count[2] = {1, 1}; /* Hyperslab selection values */
HDassert(fid >= 0);
HDassert(symbol);
@@ -100,48 +98,50 @@ check_dataset(hid_t fid, unsigned verbose, const symbol_info_t *symbol, symbol_t
HDassert(rec_sid >= 0);
/* Open dataset for symbol */
- if((dsid = H5Dopen2(fid, symbol->name, H5P_DEFAULT)) < 0)
+ if ((dsid = H5Dopen2(fid, symbol->name, H5P_DEFAULT)) < 0)
return -1;
/* Get the dataset's dataspace */
- if((file_sid = H5Dget_space(dsid)) < 0)
+ if ((file_sid = H5Dget_space(dsid)) < 0)
return -1;
/* 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)
+ if (H5Sselect_hyperslab(file_sid, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
return -1;
/* Emit informational message */
- if(verbose)
- HDfprintf(stderr, "Symbol = '%s', location = %" PRIuMAX ",%" PRIuMAX "\n", symbol->name, (uintmax_t)start[0], (uintmax_t)start[1]);
+ if (verbose)
+ HDfprintf(stderr, "Symbol = '%s', location = %" PRIuMAX ",%" PRIuMAX "\n", symbol->name,
+ (uintmax_t)start[0], (uintmax_t)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)
+ if (H5Dread(dsid, symbol_tid, rec_sid, file_sid, H5P_DEFAULT, record) < 0)
return -1;
/* Verify record value */
- if(record->rec_id != start[1]) {
+ if (record->rec_id != start[1]) {
HDfprintf(stderr, "*** ERROR ***\n");
HDfprintf(stderr, "Incorrect record value!\n");
- HDfprintf(stderr, "Symbol = '%s', location = %" PRIuMAX ",%" PRIuMAX ", record->rec_id = %" PRIu64 "\n", symbol->name, (uintmax_t)start[0], (uintmax_t)start[1], record->rec_id);
+ HDfprintf(stderr,
+ "Symbol = '%s', location = %" PRIuMAX ",%" PRIuMAX ", record->rec_id = %" PRIu64 "\n",
+ symbol->name, (uintmax_t)start[0], (uintmax_t)start[1], record->rec_id);
return -1;
} /* end if */
/* Close the dataset's dataspace */
- if(H5Sclose(file_sid) < 0)
+ if (H5Sclose(file_sid) < 0)
return -1;
/* Close dataset for symbol */
- if(H5Dclose(dsid) < 0)
+ if (H5Dclose(dsid) < 0)
return -1;
return 0;
} /* end check_dataset() */
-
/*-------------------------------------------------------------------------
* Function: read_records
*
@@ -170,42 +170,42 @@ check_dataset(hid_t fid, unsigned verbose, const symbol_info_t *symbol, symbol_t
*-------------------------------------------------------------------------
*/
static int
-read_records(const char *filename, unsigned verbose, unsigned long nrecords,
- unsigned poll_time, unsigned reopen_count)
+read_records(const char *filename, unsigned verbose, unsigned long nrecords, unsigned poll_time,
+ unsigned reopen_count)
{
- hid_t fid; /* File ID */
- hid_t aid; /* Attribute ID */
- time_t start_time; /* Starting time */
- hid_t mem_sid; /* Memory dataspace ID */
- symbol_t record; /* The record to add to the dataset */
- unsigned seed; /* Seed for random number generator */
- unsigned iter_to_reopen = reopen_count; /* # of iterations until reopen */
- unsigned long u; /* Local index variable */
- hid_t fapl;
+ hid_t fid; /* File ID */
+ hid_t aid; /* Attribute ID */
+ time_t start_time; /* Starting time */
+ hid_t mem_sid; /* Memory dataspace ID */
+ symbol_t record; /* The record to add to the dataset */
+ unsigned seed; /* Seed for random number generator */
+ unsigned iter_to_reopen = reopen_count; /* # of iterations until reopen */
+ unsigned long u; /* Local index variable */
+ hid_t fapl;
HDassert(filename);
HDassert(poll_time != 0);
/* Create file access property list */
- if((fapl = h5_fileaccess()) < 0)
+ if ((fapl = h5_fileaccess()) < 0)
return -1;
H5Pset_fclose_degree(fapl, H5F_CLOSE_SEMI);
/* Emit informational message */
- if(verbose)
+ if (verbose)
HDfprintf(stderr, "Opening file: %s\n", filename);
/* Open the file */
- if((fid = H5Fopen(filename, H5F_ACC_RDONLY | H5F_ACC_SWMR_READ, fapl)) < 0)
+ if ((fid = H5Fopen(filename, H5F_ACC_RDONLY | H5F_ACC_SWMR_READ, fapl)) < 0)
return -1;
/* Seed the random number generator with the attribute in the file */
- if((aid = H5Aopen(fid, "seed", H5P_DEFAULT)) < 0)
+ if ((aid = H5Aopen(fid, "seed", H5P_DEFAULT)) < 0)
return -1;
- if(H5Aread(aid, H5T_NATIVE_UINT, &seed) < 0)
+ if (H5Aread(aid, H5T_NATIVE_UINT, &seed) < 0)
return -1;
- if(H5Aclose(aid) < 0)
+ if (H5Aclose(aid) < 0)
return -1;
HDsrandom(seed);
@@ -214,21 +214,21 @@ read_records(const char *filename, unsigned verbose, unsigned long nrecords,
HDmemset(&record, 0, sizeof(record));
/* Create a dataspace for the record to read */
- if((mem_sid = H5Screate(H5S_SCALAR)) < 0)
+ if ((mem_sid = H5Screate(H5S_SCALAR)) < 0)
return -1;
/* Emit informational message */
- if(verbose)
+ if (verbose)
HDfprintf(stderr, "Reading records\n");
/* Get the starting time */
start_time = HDtime(NULL);
/* Read records */
- for(u = 0; u < nrecords; u++) {
- symbol_info_t *symbol = NULL; /* Symbol (dataset) */
- htri_t attr_exists; /* Whether the sequence number attribute exists */
- unsigned long file_u; /* Attribute sequence number (writer's "u") */
+ for (u = 0; u < nrecords; u++) {
+ symbol_info_t *symbol = NULL; /* Symbol (dataset) */
+ htri_t attr_exists; /* Whether the sequence number attribute exists */
+ unsigned long file_u; /* Attribute sequence number (writer's "u") */
/* Get a random dataset, according to the symbol distribution */
symbol = choose_dataset();
@@ -240,26 +240,26 @@ read_records(const char *filename, unsigned verbose, unsigned long nrecords,
/* Wait until we can read the dataset */
do {
/* Check if sequence attribute exists */
- if((attr_exists = H5Aexists_by_name(fid, symbol->name, "seq", H5P_DEFAULT)) < 0)
+ if ((attr_exists = H5Aexists_by_name(fid, symbol->name, "seq", H5P_DEFAULT)) < 0)
return -1;
- if(attr_exists) {
+ if (attr_exists) {
/* Read sequence number attribute */
- if((aid = H5Aopen_by_name(fid, symbol->name, "seq", H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ if ((aid = H5Aopen_by_name(fid, symbol->name, "seq", H5P_DEFAULT, H5P_DEFAULT)) < 0)
return -1;
- if(H5Aread(aid, H5T_NATIVE_ULONG, &file_u) < 0)
+ if (H5Aread(aid, H5T_NATIVE_ULONG, &file_u) < 0)
return -1;
- if(H5Aclose(aid) < 0)
+ if (H5Aclose(aid) < 0)
return -1;
/* Check if sequence number is at least u - if so, this should
* guarantee that this record has been written */
- if(file_u >= u)
+ if (file_u >= u)
break;
} /* end if */
/* Check for timeout */
- if(HDtime(NULL) >= (time_t)(start_time + (time_t)TIMEOUT)) {
+ if (HDtime(NULL) >= (time_t)(start_time + (time_t)TIMEOUT)) {
HDfprintf(stderr, "Reader timed out\n");
return -1;
} /* end if */
@@ -268,56 +268,56 @@ read_records(const char *filename, unsigned verbose, unsigned long nrecords,
HDsleep(poll_time);
/* Retrieve and print the collection of metadata read retries */
- if(print_metadata_retries_info(fid) < 0)
+ if (print_metadata_retries_info(fid) < 0)
HDfprintf(stderr, "Warning: could not obtain metadata retries info\n");
/* Reopen the file */
- if(H5Fclose(fid) < 0)
+ if (H5Fclose(fid) < 0)
return -1;
- if((fid = H5Fopen(filename, H5F_ACC_RDONLY | H5F_ACC_SWMR_READ, fapl)) < 0)
+ if ((fid = H5Fopen(filename, H5F_ACC_RDONLY | H5F_ACC_SWMR_READ, fapl)) < 0)
return -1;
iter_to_reopen = reopen_count;
- } while(1);
+ } while (1);
/* Emit informational message */
- if(verbose)
+ if (verbose)
HDfprintf(stderr, "Checking dataset %lu\n", u);
/* Check dataset */
- if(check_dataset(fid, verbose, symbol, &record, mem_sid) < 0)
+ if (check_dataset(fid, verbose, symbol, &record, mem_sid) < 0)
return -1;
HDmemset(&record, 0, sizeof(record));
/* Check for reopen */
iter_to_reopen--;
- if(iter_to_reopen == 0) {
+ if (iter_to_reopen == 0) {
/* Emit informational message */
- if(verbose)
+ if (verbose)
HDfprintf(stderr, "Reopening file: %s\n", filename);
/* Retrieve and print the collection of metadata read retries */
- if(print_metadata_retries_info(fid) < 0)
+ if (print_metadata_retries_info(fid) < 0)
HDfprintf(stderr, "Warning: could not obtain metadata retries info\n");
/* Reopen the file */
- if(H5Fclose(fid) < 0)
+ if (H5Fclose(fid) < 0)
return -1;
- if((fid = H5Fopen(filename, H5F_ACC_RDONLY | H5F_ACC_SWMR_READ, fapl)) < 0)
+ if ((fid = H5Fopen(filename, H5F_ACC_RDONLY | H5F_ACC_SWMR_READ, fapl)) < 0)
return -1;
iter_to_reopen = reopen_count;
} /* end if */
- } /* end while */
+ } /* end while */
/* Retrieve and print the collection of metadata read retries */
- if(print_metadata_retries_info(fid) < 0)
+ if (print_metadata_retries_info(fid) < 0)
HDfprintf(stderr, "Warning: could not obtain metadata retries info\n");
/* Close file */
- if(H5Fclose(fid) < 0)
+ if (H5Fclose(fid) < 0)
return -1;
/* Close the memory dataspace */
- if(H5Sclose(mem_sid) < 0)
+ if (H5Sclose(mem_sid) < 0)
return -1;
return 0;
@@ -341,26 +341,27 @@ usage(void)
HDexit(EXIT_FAILURE);
} /* end usage() */
-int main(int argc, const char *argv[])
+int
+main(int argc, const char *argv[])
{
- long nrecords = 0; /* # of records to read */
- int poll_time = 1; /* # of seconds to sleep when waiting for writer */
- int reopen_count = 1; /* # of reads between reopens */
- unsigned verbose = 1; /* Whether to emit some informational messages */
- unsigned u; /* Local index variables */
+ long nrecords = 0; /* # of records to read */
+ int poll_time = 1; /* # of seconds to sleep when waiting for writer */
+ int reopen_count = 1; /* # of reads between reopens */
+ unsigned verbose = 1; /* Whether to emit some informational messages */
+ unsigned u; /* Local index variables */
/* Parse command line options */
- if(argc < 2)
+ if (argc < 2)
usage();
- if(argc > 1) {
+ if (argc > 1) {
u = 1;
- while(u < (unsigned)argc) {
- if(argv[u][0] == '-') {
- switch(argv[u][1]) {
+ while (u < (unsigned)argc) {
+ if (argv[u][0] == '-') {
+ switch (argv[u][1]) {
/* # of reads between reopens */
case 'n':
reopen_count = HDatoi(argv[u + 1]);
- if(reopen_count < 0)
+ if (reopen_count < 0)
usage();
u += 2;
break;
@@ -374,7 +375,7 @@ int main(int argc, const char *argv[])
/* # of seconds between polling */
case 's':
poll_time = HDatoi(argv[u + 1]);
- if(poll_time < 0)
+ if (poll_time < 0)
usage();
u += 2;
break;
@@ -383,20 +384,20 @@ int main(int argc, const char *argv[])
usage();
break;
} /* end switch */
- } /* end if */
+ } /* end if */
else {
/* Get the number of records to read */
nrecords = HDatol(argv[u]);
- if(nrecords <= 0)
+ if (nrecords <= 0)
usage();
u++;
} /* end else */
- } /* end while */
- } /* end if */
+ } /* end while */
+ } /* end if */
/* Emit informational message */
- if(verbose) {
+ if (verbose) {
HDfprintf(stderr, "Parameters:\n");
HDfprintf(stderr, "\t# of seconds between polling = %d\n", poll_time);
HDfprintf(stderr, "\t# of reads between reopens = %d\n", reopen_count);
@@ -404,41 +405,42 @@ int main(int argc, const char *argv[])
} /* end if */
/* Emit informational message */
- if(verbose)
+ if (verbose)
HDfprintf(stderr, "Generating symbol names\n");
/* Generate dataset names */
- if(generate_symbols() < 0) {
+ if (generate_symbols() < 0) {
HDfprintf(stderr, "Error generating symbol names!\n");
HDexit(EXIT_FAILURE);
} /* end if */
/* Create datatype for creating datasets */
- if((symbol_tid = create_symbol_datatype()) < 0)
+ if ((symbol_tid = create_symbol_datatype()) < 0)
return -1;
/* Reading records from datasets */
- if(read_records(FILENAME, verbose, (unsigned long) nrecords, (unsigned)poll_time, (unsigned)reopen_count) < 0) {
+ if (read_records(FILENAME, verbose, (unsigned long)nrecords, (unsigned)poll_time,
+ (unsigned)reopen_count) < 0) {
HDfprintf(stderr, "Error reading records from datasets!\n");
HDexit(EXIT_FAILURE);
} /* end if */
/* Emit informational message */
- if(verbose)
+ if (verbose)
HDfprintf(stderr, "Releasing symbols\n");
/* Clean up the symbols */
- if(shutdown_symbols() < 0) {
+ if (shutdown_symbols() < 0) {
HDfprintf(stderr, "Error releasing symbols!\n");
HDexit(EXIT_FAILURE);
} /* end if */
/* Emit informational message */
- if(verbose)
+ if (verbose)
HDfprintf(stderr, "Closing objects\n");
/* Close objects created */
- if(H5Tclose(symbol_tid) < 0) {
+ if (H5Tclose(symbol_tid) < 0) {
HDfprintf(stderr, "Error closing symbol datatype!\n");
HDexit(EXIT_FAILURE);
} /* end if */