summaryrefslogtreecommitdiffstats
path: root/test/ohdr.c
diff options
context:
space:
mode:
authorVailin Choi <vchoi@hdfgroup.org>2013-06-26 20:35:42 (GMT)
committerVailin Choi <vchoi@hdfgroup.org>2013-06-26 20:35:42 (GMT)
commit5845fed5cb1dad347d71ccd2a7c9091ffaccff0a (patch)
tree796fe4a86905b9dd8a8cc7d8e1990a6ce26378b7 /test/ohdr.c
parentd9517c14af7bc68bd093b14eb8eeaab87d1ea80e (diff)
downloadhdf5-5845fed5cb1dad347d71ccd2a7c9091ffaccff0a.zip
hdf5-5845fed5cb1dad347d71ccd2a7c9091ffaccff0a.tar.gz
hdf5-5845fed5cb1dad347d71ccd2a7c9091ffaccff0a.tar.bz2
[svn-r23828] Fix 2 bugs for SWMR access:
1) H5O_load() in H5Ocache.c: when reading a block that is > spec_read siez, read the whole block in again and possibly decode the header. 2) H5F_accum_write() in H5Faccum.c: for a large write that is >= H5F_ACCUM_MAX_SIZE, flush the metadata in the accumulator first before the write. Tests are added to test/ohdr.c and test/accum.c. h5committested.
Diffstat (limited to 'test/ohdr.c')
-rw-r--r--test/ohdr.c132
1 files changed, 132 insertions, 0 deletions
diff --git a/test/ohdr.c b/test/ohdr.c
index 502a8b1..fa00716 100644
--- a/test/ohdr.c
+++ b/test/ohdr.c
@@ -45,6 +45,9 @@ const char *FILENAME[] = {
*/
#define FILE_BOGUS "tbogus.h5"
+/* */
+#define FILE_OHDR_SWMR "ohdr_swmr.h5"
+#define DSET_NAME "COMPACT_DSET"
/*
* Verify that messages are moved forward into a "continuation message":
* Create an object header with several continuation chunks
@@ -295,6 +298,131 @@ error:
return -1;
} /* test_ohdr_cache() */
+/*
+ * To exercise the coding for the re-read of the object header for SWMR access.
+ * When the object header is read in H5O_load() of H5Ocache.c, the library initially reads
+ * 512 bytes for decoding, then reads the remaining bytes later if the object header is
+ * greater than 512 bytes. For SWMR access, the read should be done all at one time.
+ */
+static herr_t
+test_ohdr_swmr(void)
+{
+ hid_t fid = -1; /* File ID */
+ hid_t fapl = -1; /* File access property list */
+ hid_t did = -1; /* Dataset ID */
+ hid_t sid = -1; /* Dataspace ID */
+ hid_t plist = -1; /* Dataset creation property list */
+ size_t compact_size = 1024; /* The size of compact dataset */
+ int wbuf[1024]; /* Buffer for writing */
+ hsize_t dims[1]; /* Dimension sizes */
+ unsigned int n = 0, u; /* Locatl index variable */
+ H5O_info_t obj_info; /* Information for the object */
+
+ TESTING("exercise the coding for the re-read of the object header for SWMR access");
+
+ /* File access property list */
+ if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
+ FAIL_STACK_ERROR
+
+ /* Set to use latest library format */
+ if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
+ FAIL_STACK_ERROR
+
+ /* Initialize data */
+ for(u = 0; u < compact_size; u++)
+ wbuf[u] = n++;
+
+ /* Create the file with the latest format (ensure version 2 object header for SWMR) */
+ if((fid = H5Fcreate(FILE_OHDR_SWMR, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
+ TEST_ERROR
+
+ /* Create a small data space for compact dataset */
+ dims[0] = (hsize_t)compact_size;
+ if((sid = H5Screate_simple(1, dims, NULL)) < 0)
+ FAIL_STACK_ERROR
+
+ /* Create property list for compact dataset creation */
+ if((plist = H5Pcreate(H5P_DATASET_CREATE)) < 0)
+ FAIL_STACK_ERROR
+
+ /* Set the layout for the compact dataset */
+ if(H5Pset_layout(plist, H5D_COMPACT) < 0)
+ FAIL_STACK_ERROR
+
+ /* Create a compact dataset */
+ if((did = H5Dcreate2(fid, DSET_NAME, H5T_NATIVE_INT, sid, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0)
+ FAIL_STACK_ERROR
+
+ /* Write to the compact dataset */
+ if(H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, wbuf) < 0)
+ FAIL_STACK_ERROR
+
+ /* Close the dataset */
+ if(H5Dclose(did) < 0)
+ FAIL_STACK_ERROR
+
+ /* Close the file */
+ if(H5Fclose(fid) < 0)
+ FAIL_STACK_ERROR
+
+ /* Open the file for SWMR write and latest format */
+ if((fid = H5Fopen(FILE_OHDR_SWMR, H5F_ACC_RDWR|H5F_ACC_SWMR_WRITE, fapl)) < 0)
+ FAIL_STACK_ERROR
+
+ /* Open the compact dataset */
+ if((did = H5Dopen2(fid, DSET_NAME, H5P_DEFAULT)) < 0)
+ FAIL_STACK_ERROR
+
+ /* Get the object information */
+ if(H5Oget_info(did, &obj_info) < 0)
+ FAIL_STACK_ERROR
+
+ /* The size of object header should be greater than the speculative read size of 512 */
+ /* This will exercise the coding for the re-read of the object header for SWMR access */
+ if(obj_info.hdr.space.total < 512)
+ TEST_ERROR;
+
+ /* Close the dataset */
+ if(H5Dclose(did) < 0)
+ FAIL_STACK_ERROR
+
+ /* Close the file */
+ if(H5Fclose(fid) < 0)
+ FAIL_STACK_ERROR
+
+ /* Close the dataspace */
+ if(H5Sclose(sid) < 0)
+ FAIL_STACK_ERROR
+
+ /* Close the dataset creation property list */
+ if(H5Pclose(plist) < 0)
+ FAIL_STACK_ERROR
+
+ /* Close the file access property list */
+ if(H5Pclose(fapl) < 0)
+ FAIL_STACK_ERROR
+
+ /* Remove the test file */
+ if(HDremove(FILE_OHDR_SWMR) < 0)
+ FAIL_STACK_ERROR
+
+ PASSED();
+
+ return 0;
+
+error:
+ H5E_BEGIN_TRY {
+ H5Fclose(fid);
+ H5Dclose(did);
+ H5Sclose(sid);
+ H5Pclose(plist);
+ H5Pclose(fapl);
+ HDremove(FILE_OHDR_SWMR);
+ } H5E_END_TRY;
+
+ return -1;
+} /* test_ohdr_swmr() */
+
/*-------------------------------------------------------------------------
* Function: main
@@ -786,6 +914,7 @@ main(void)
PASSED();
}
+
/* Close the file we created */
if(H5Fclose(file) < 0)
TEST_ERROR
@@ -798,6 +927,9 @@ main(void)
/* Verify symbol table messages are cached */
if(h5_verify_cached_stabs(FILENAME, fapl) < 0) TEST_ERROR
+ /* A test to exercise the re-read of the object header for SWMR access */
+ if(test_ohdr_swmr() < 0) TEST_ERROR
+
puts("All object header tests passed.");
h5_cleanup(FILENAME, fapl);
return(0);