diff options
author | Dana Robinson <derobins@hdfgroup.org> | 2015-10-21 23:13:38 (GMT) |
---|---|---|
committer | Dana Robinson <derobins@hdfgroup.org> | 2015-10-21 23:13:38 (GMT) |
commit | 0caf00455f00fe28af7947970dd3b9a2462f3f2d (patch) | |
tree | dfe47692240c41d925a8658035447cd9527252e0 | |
parent | 30adc68b2423d23663f9c88fba9111ce36fc979a (diff) | |
download | hdf5-0caf00455f00fe28af7947970dd3b9a2462f3f2d.zip hdf5-0caf00455f00fe28af7947970dd3b9a2462f3f2d.tar.gz hdf5-0caf00455f00fe28af7947970dd3b9a2462f3f2d.tar.bz2 |
[svn-r28178] Updates to existing VDS + SWMR test code and added reader code.
NOTE: Tests are still manual for now and the reader does not
reflect source dataset changes.
Tested on: Ubuntu 15.04 (Linux 3.19 x86_64) gcc 4.9.2
serial only
-rw-r--r-- | test/vds_swmr.h | 2 | ||||
-rw-r--r-- | test/vds_swmr_gen.c | 16 | ||||
-rw-r--r-- | test/vds_swmr_reader.c | 119 | ||||
-rw-r--r-- | test/vds_swmr_writer.c | 33 |
4 files changed, 161 insertions, 9 deletions
diff --git a/test/vds_swmr.h b/test/vds_swmr.h index eb51db5..f4b37e9 100644 --- a/test/vds_swmr.h +++ b/test/vds_swmr.h @@ -89,7 +89,7 @@ #define N_MAX_PLANES H5S_UNLIMITED /* Number of planes each writer will write */ -#define N_PLANES_TO_WRITE 1000 +#define N_PLANES_TO_WRITE 100 /* Dataset datatypes */ #define SOURCE_DATATYPE H5T_STD_I32LE diff --git a/test/vds_swmr_gen.c b/test/vds_swmr_gen.c index d71a741..1706844 100644 --- a/test/vds_swmr_gen.c +++ b/test/vds_swmr_gen.c @@ -19,6 +19,8 @@ int main(int argc, char *argv[]) { + hid_t faplid = -1; /* file access property list ID (all files) */ + hid_t src_sid = -1; /* source dataset's dataspace ID */ hid_t src_dcplid = -1; /* source dataset property list ID */ @@ -60,6 +62,12 @@ main(int argc, char *argv[]) start[2] = 0; map_start = 0; + /* All SWMR files need to use the latest file format */ + if((faplid = H5Pcreate(H5P_FILE_ACCESS)) < 0) + TEST_ERROR + if(H5Pset_libver_bounds(faplid, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) + TEST_ERROR + for(i = 0; i < N_SOURCES; i++) { /* source dataset dcpl */ @@ -78,7 +86,7 @@ main(int argc, char *argv[]) /* Create source file, dataspace, and dataset */ if((fid = H5Fcreate(FILE_NAMES[i], H5F_ACC_TRUNC, - H5P_DEFAULT, H5P_DEFAULT)) < 0) + H5P_DEFAULT, faplid)) < 0) TEST_ERROR if((src_sid = H5Screate_simple(RANK, DIMS[i], MAX_DIMS[i])) < 0) @@ -123,7 +131,7 @@ main(int argc, char *argv[]) /* file */ if((fid = H5Fcreate(VDS_FILE_NAME, H5F_ACC_TRUNC, - H5P_DEFAULT, H5P_DEFAULT)) < 0) + H5P_DEFAULT, faplid)) < 0) TEST_ERROR /* dataset */ @@ -132,6 +140,8 @@ main(int argc, char *argv[]) TEST_ERROR /* close */ + if(H5Pclose(faplid) < 0) + TEST_ERROR if(H5Pclose(vds_dcplid) < 0) TEST_ERROR if(H5Sclose(vds_sid) < 0) @@ -146,6 +156,8 @@ main(int argc, char *argv[]) error: H5E_BEGIN_TRY { + if(faplid >= 0) + (void)H5Pclose(faplid); if(src_sid >= 0) (void)H5Sclose(src_sid); if(src_dcplid >= 0) diff --git a/test/vds_swmr_reader.c b/test/vds_swmr_reader.c index 133295b..d1969fb 100644 --- a/test/vds_swmr_reader.c +++ b/test/vds_swmr_reader.c @@ -19,6 +19,125 @@ int main(int argc, char *argv[]) { + hid_t fid = -1; /* HDF5 file ID */ + hid_t did = -1; /* dataset ID */ + hid_t msid = -1; /* memory dataspace ID */ + hid_t fsid = -1; /* file dataspace ID */ + + hsize_t start[RANK]; /* hyperslab start point */ + + int n_elements = 0; /* size of buffer (elements) */ + size_t size = 0; /* size of buffer (bytes) */ + int *buffer = NULL; /* data buffer */ + + int n_dims = -1; /* # dimensions in dataset */ + hsize_t dims[RANK]; /* current size of dataset */ + hsize_t max_dims[RANK]; /* max size of dataset */ + + hbool_t has_errors = FALSE;/* if the read data contains errors */ + + int i; /* iterator */ + + + /* Open the VDS file and dataset */ + if((fid = H5Fopen(VDS_FILE_NAME, H5F_ACC_RDONLY | H5F_ACC_SWMR_READ, H5P_DEFAULT)) < 0) + TEST_ERROR + if((did = H5Dopen2(fid, VDS_DSET_NAME, H5P_DEFAULT)) < 0) + TEST_ERROR + + /* Create the read buffer */ + n_elements = VDS_PLANE[1] * VDS_PLANE[2]; + size = n_elements * sizeof(int); + if(NULL == (buffer = (int *)HDmalloc(size))) + TEST_ERROR + + /* Create memory dataspace */ + if((msid = H5Screate_simple(RANK, VDS_PLANE, NULL)) < 0) + TEST_ERROR + + /* Read data until the dataset is full (via the writer) */ + do { + + /* Refresh metadata */ + if(H5Drefresh(did) < 0) + TEST_ERROR + + /* Get the dataset dimensions */ + if((fsid = H5Dget_space(did)) < 0) + TEST_ERROR + if(H5Sget_simple_extent_dims(fsid, dims, max_dims) < 0) + TEST_ERROR + + /* Check the reported size of the VDS */ + if((n_dims = H5Sget_simple_extent_ndims(fsid)) < 0) + TEST_ERROR + if(n_dims != RANK) + TEST_ERROR + if(H5Sget_simple_extent_dims(fsid, dims, max_dims) < 0) + TEST_ERROR + /* NOTE: Don't care what dims[0] is. */ + if(dims[1] != FULL_HEIGHT) + TEST_ERROR + if(dims[2] != WIDTH) + TEST_ERROR + if(max_dims[0] != H5S_UNLIMITED) + TEST_ERROR + if(max_dims[1] != FULL_HEIGHT) + TEST_ERROR + if(max_dims[2] != WIDTH) + TEST_ERROR + + /* Continue if there's nothing to read */ + if(0 == dims[0]) { + if(H5Sclose(fsid) < 0) + TEST_ERROR + continue; + } + + /* Read a plane from the VDS */ + /* At this time, we just make sure we can read planes without errors. */ + start[0] = dims[0] - 1; + start[1] = 0; + start[2] = 0; + if(H5Sselect_hyperslab(fsid, H5S_SELECT_SET, start, NULL, VDS_PLANE, NULL) < 0) + TEST_ERROR + if(H5Dread(did, H5T_NATIVE_INT, msid, fsid, H5P_DEFAULT, buffer) < 0) + TEST_ERROR + + if(H5Sclose(fsid) < 0) + TEST_ERROR + + HDfprintf(stderr, "read plane: %d\n", dims[0]); + + } while (dims[0] < N_PLANES_TO_WRITE); + + /* Close file and dataset */ + if(H5Sclose(msid) < 0) + TEST_ERROR + if(H5Dclose(did) < 0) + TEST_ERROR + if(H5Fclose(fid) < 0) + TEST_ERROR + + HDfree(buffer); + + return EXIT_SUCCESS; + +error: + + H5E_BEGIN_TRY { + if(fid >= 0) + (void)H5Fclose(fid); + if(did >= 0) + (void)H5Dclose(did); + if(msid >= 0) + (void)H5Sclose(msid); + if(fsid >= 0) + (void)H5Sclose(fsid); + if(buffer != NULL) + free(buffer); + } H5E_END_TRY + return EXIT_FAILURE; } /* end main */ diff --git a/test/vds_swmr_writer.c b/test/vds_swmr_writer.c index 90dee62..27be7cf 100644 --- a/test/vds_swmr_writer.c +++ b/test/vds_swmr_writer.c @@ -23,6 +23,7 @@ main(int argc, char *argv[]) int file_number = -1; /* Source file number */ hid_t fid = -1; /* HDF5 file ID */ + hid_t faplid = -1; /* file access property list ID */ hid_t did = -1; /* dataset ID */ hid_t msid = -1; /* memory dataspace ID */ hid_t fsid = -1; /* file dataspace ID */ @@ -47,7 +48,7 @@ main(int argc, char *argv[]) * This is an integer index into the FILE_NAMES array. */ if(argc != 2) { - fprintf(stderr, "ERROR: Must pass the source file number on the command line.\n"); + HDfprintf(stderr, "ERROR: Must pass the source file number on the command line.\n"); return EXIT_FAILURE; } @@ -56,7 +57,12 @@ main(int argc, char *argv[]) TEST_ERROR /* Open the source file and dataset */ - if((fid = H5Fopen(FILE_NAMES[file_number], H5F_ACC_RDWR, H5P_DEFAULT)) < 0) + /* All SWMR files need to use the latest file format */ + if((faplid = H5Pcreate(H5P_FILE_ACCESS)) < 0) + TEST_ERROR + if(H5Pset_libver_bounds(faplid, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) + TEST_ERROR + if((fid = H5Fopen(FILE_NAMES[file_number], H5F_ACC_RDWR | H5F_ACC_SWMR_WRITE, faplid)) < 0) TEST_ERROR if((did = H5Dopen2(fid, SOURCE_DSET_PATH, H5P_DEFAULT)) < 0) TEST_ERROR @@ -64,7 +70,7 @@ main(int argc, char *argv[]) /* Create a data buffer that represents a plane */ n_elements = PLANES[file_number][1] * PLANES[file_number][2]; - if(NULL == (buffer = (int *)malloc(n_elements * sizeof(int)))) + if(NULL == (buffer = (int *)HDmalloc(n_elements * sizeof(int)))) TEST_ERROR /* Create the memory dataspace */ @@ -74,6 +80,8 @@ main(int argc, char *argv[]) /* Write planes to the dataset */ for(i = 0; i < N_PLANES_TO_WRITE; i++) { + unsigned delay; /* Time interval between plane writes */ + /* Set the dataset's extent. This is inefficient but that's ok here. */ extent[0] = i + 1; extent[1] = PLANES[file_number][1]; @@ -98,11 +106,22 @@ main(int argc, char *argv[]) TEST_ERROR /* Write the plane to the dataset. */ + printf("Writing plane: %d\n", i); if(H5Dwrite(did, H5T_NATIVE_INT, msid, fsid, H5P_DEFAULT, buffer) < 0) TEST_ERROR - } /* end for */ + /* Wait one second between writing planes */ + delay = time(0) + 1; + while(time(0) < delay) + ; + /* Flush */ + if(H5Fflush(fid, H5F_SCOPE_GLOBAL) < 0) + TEST_ERROR + + } /* end for */ + if(H5Pclose(faplid) < 0) + TEST_ERROR if(H5Sclose(msid) < 0) TEST_ERROR if(H5Sclose(fsid) < 0) @@ -111,7 +130,7 @@ main(int argc, char *argv[]) TEST_ERROR if(H5Fclose(fid) < 0) TEST_ERROR - free(buffer); + HDfree(buffer); return EXIT_SUCCESS; @@ -120,6 +139,8 @@ error: H5E_BEGIN_TRY { if(fid >= 0) (void)H5Fclose(fid); + if(faplid >= 0) + (void)H5Pclose(faplid); if(did >= 0) (void)H5Dclose(did); if(msid >= 0) @@ -127,7 +148,7 @@ error: if(fsid >= 0) (void)H5Sclose(fsid); if(buffer != NULL) - free(buffer); + HDfree(buffer); } H5E_END_TRY return EXIT_FAILURE; |