diff options
author | Vailin Choi <vchoi@hdfgroup.org> | 2013-06-26 20:35:42 (GMT) |
---|---|---|
committer | Vailin Choi <vchoi@hdfgroup.org> | 2013-06-26 20:35:42 (GMT) |
commit | 5845fed5cb1dad347d71ccd2a7c9091ffaccff0a (patch) | |
tree | 796fe4a86905b9dd8a8cc7d8e1990a6ce26378b7 /test | |
parent | d9517c14af7bc68bd093b14eb8eeaab87d1ea80e (diff) | |
download | hdf5-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')
-rw-r--r-- | test/Makefile.am | 4 | ||||
-rw-r--r-- | test/Makefile.in | 61 | ||||
-rw-r--r-- | test/accum.c | 168 | ||||
-rw-r--r-- | test/accum_swmr_reader.c | 80 | ||||
-rw-r--r-- | test/ohdr.c | 132 |
5 files changed, 418 insertions, 27 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index 50060eb..0c77646 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -51,7 +51,7 @@ TEST_PROG= testhdf5 lheap ohdr stab gheap cache cache_api cache_tagging \ bin_PROGRAMS=swmr_generator swmr_reader swmr_writer swmr_remove_reader \ swmr_remove_writer swmr_addrem_writer swmr_sparse_reader swmr_sparse_writer \ - use_append_chunk use_append_mchunks atomic_writer atomic_reader + use_append_chunk use_append_mchunks atomic_writer atomic_reader accum_swmr_reader # List programs to be built when testing here. error_test and err_compat are # built at the same time as the other tests, but executed by testerror.sh. @@ -162,7 +162,7 @@ CHECK_CLEANFILES+=accum.h5 cmpd_dset.h5 compact_dataset.h5 dataset.h5 \ swmr_data.h5 use_append_chunk.h5 use_append_mchunks.h5 \ flushrefresh.h5 flushrefresh_VERIFICATION_START \ flushrefresh_VERIFICATION_CHECKPOINT1 flushrefresh_VERIFICATION_CHECKPOINT2 \ - flushrefresh_VERIFICATION_DONE atomic_data + flushrefresh_VERIFICATION_DONE atomic_data accum_swmr_big.h5 ohdr_swmr.h5 # Sources for testhdf5 executable testhdf5_SOURCES=testhdf5.c tarray.c tattr.c tchecksum.c tconfig.c tfile.c \ diff --git a/test/Makefile.in b/test/Makefile.in index bbe07d5..faed943 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -84,7 +84,8 @@ bin_PROGRAMS = swmr_generator$(EXEEXT) swmr_reader$(EXEEXT) \ swmr_remove_writer$(EXEEXT) swmr_addrem_writer$(EXEEXT) \ swmr_sparse_reader$(EXEEXT) swmr_sparse_writer$(EXEEXT) \ use_append_chunk$(EXEEXT) use_append_mchunks$(EXEEXT) \ - atomic_writer$(EXEEXT) atomic_reader$(EXEEXT) + atomic_writer$(EXEEXT) atomic_reader$(EXEEXT) \ + accum_swmr_reader$(EXEEXT) check_PROGRAMS = $(am__EXEEXT_1) error_test$(EXEEXT) \ err_compat$(EXEEXT) tcheck_version$(EXEEXT) testmeta$(EXEEXT) \ links_env$(EXEEXT) flushrefresh$(EXEEXT) $(am__EXEEXT_2) @@ -191,6 +192,10 @@ accum_SOURCES = accum.c accum_OBJECTS = accum.$(OBJEXT) accum_LDADD = $(LDADD) accum_DEPENDENCIES = libh5test.la $(LIBHDF5) +accum_swmr_reader_SOURCES = accum_swmr_reader.c +accum_swmr_reader_OBJECTS = accum_swmr_reader.$(OBJEXT) +accum_swmr_reader_LDADD = $(LDADD) +accum_swmr_reader_DEPENDENCIES = libh5test.la $(LIBHDF5) app_ref_SOURCES = app_ref.c app_ref_OBJECTS = app_ref.$(OBJEXT) app_ref_LDADD = $(LDADD) @@ -592,17 +597,18 @@ am__v_CCLD_0 = @echo " CCLD " $@; am__v_CCLD_1 = SOURCES = $(libdynlib1_la_SOURCES) $(libdynlib2_la_SOURCES) \ $(libdynlib3_la_SOURCES) $(libh5test_la_SOURCES) accum.c \ - app_ref.c atomic_reader.c atomic_writer.c big.c bittests.c \ - btree2.c cache.c cache_api.c cache_tagging.c cmpd_dset.c \ - cross_read.c dangle.c dsets.c dt_arith.c dtransform.c dtypes.c \ - earray.c efc.c enc_dec_plist.c enc_dec_plist_with_endianess.c \ - enum.c err_compat.c error_test.c extend.c external.c farray.c \ - fheap.c file_image.c fillval.c filter_fail.c flush1.c flush2.c \ - flushrefresh.c freespace.c gen_bad_ohdr.c gen_bogus.c \ - gen_cross.c gen_deflate.c gen_file_image.c gen_filespace.c \ - gen_filters.c gen_idx.c gen_new_array.c gen_new_fill.c \ - gen_new_group.c gen_new_mtime.c gen_new_super.c \ - gen_noencoder.c gen_nullspace.c gen_plist.c gen_sizes_lheap.c \ + accum_swmr_reader.c app_ref.c atomic_reader.c atomic_writer.c \ + big.c bittests.c btree2.c cache.c cache_api.c cache_tagging.c \ + cmpd_dset.c cross_read.c dangle.c dsets.c dt_arith.c \ + dtransform.c dtypes.c earray.c efc.c enc_dec_plist.c \ + enc_dec_plist_with_endianess.c enum.c err_compat.c \ + error_test.c extend.c external.c farray.c fheap.c file_image.c \ + fillval.c filter_fail.c flush1.c flush2.c flushrefresh.c \ + freespace.c gen_bad_ohdr.c gen_bogus.c gen_cross.c \ + gen_deflate.c gen_file_image.c gen_filespace.c gen_filters.c \ + gen_idx.c gen_new_array.c gen_new_fill.c gen_new_group.c \ + gen_new_mtime.c gen_new_super.c gen_noencoder.c \ + gen_nullspace.c gen_plist.c gen_sizes_lheap.c \ gen_specmetaread.c gen_udlinks.c getname.c gheap.c hyperslab.c \ istore.c lheap.c links.c links_env.c mf.c mount.c mtime.c \ ntypes.c objcopy.c ohdr.c plugin.c pool.c reserved.c \ @@ -615,18 +621,18 @@ SOURCES = $(libdynlib1_la_SOURCES) $(libdynlib2_la_SOURCES) \ DIST_SOURCES = $(am__libdynlib1_la_SOURCES_DIST) \ $(am__libdynlib2_la_SOURCES_DIST) \ $(am__libdynlib3_la_SOURCES_DIST) $(libh5test_la_SOURCES) \ - accum.c app_ref.c atomic_reader.c atomic_writer.c big.c \ - bittests.c btree2.c cache.c cache_api.c cache_tagging.c \ - cmpd_dset.c cross_read.c dangle.c dsets.c dt_arith.c \ - dtransform.c dtypes.c earray.c efc.c enc_dec_plist.c \ - enc_dec_plist_with_endianess.c enum.c err_compat.c \ - error_test.c extend.c external.c farray.c fheap.c file_image.c \ - fillval.c filter_fail.c flush1.c flush2.c flushrefresh.c \ - freespace.c gen_bad_ohdr.c gen_bogus.c gen_cross.c \ - gen_deflate.c gen_file_image.c gen_filespace.c gen_filters.c \ - gen_idx.c gen_new_array.c gen_new_fill.c gen_new_group.c \ - gen_new_mtime.c gen_new_super.c gen_noencoder.c \ - gen_nullspace.c gen_plist.c gen_sizes_lheap.c \ + accum.c accum_swmr_reader.c app_ref.c atomic_reader.c \ + atomic_writer.c big.c bittests.c btree2.c cache.c cache_api.c \ + cache_tagging.c cmpd_dset.c cross_read.c dangle.c dsets.c \ + dt_arith.c dtransform.c dtypes.c earray.c efc.c \ + enc_dec_plist.c enc_dec_plist_with_endianess.c enum.c \ + err_compat.c error_test.c extend.c external.c farray.c fheap.c \ + file_image.c fillval.c filter_fail.c flush1.c flush2.c \ + flushrefresh.c freespace.c gen_bad_ohdr.c gen_bogus.c \ + gen_cross.c gen_deflate.c gen_file_image.c gen_filespace.c \ + gen_filters.c gen_idx.c gen_new_array.c gen_new_fill.c \ + gen_new_group.c gen_new_mtime.c gen_new_super.c \ + gen_noencoder.c gen_nullspace.c gen_plist.c gen_sizes_lheap.c \ gen_specmetaread.c gen_udlinks.c getname.c gheap.c hyperslab.c \ istore.c lheap.c links.c links_env.c mf.c mount.c mtime.c \ ntypes.c objcopy.c ohdr.c plugin.c pool.c reserved.c \ @@ -961,7 +967,8 @@ CHECK_CLEANFILES = *.chkexe *.chklog *.clog accum.h5 cmpd_dset.h5 \ flushrefresh.h5 flushrefresh_VERIFICATION_START \ flushrefresh_VERIFICATION_CHECKPOINT1 \ flushrefresh_VERIFICATION_CHECKPOINT2 \ - flushrefresh_VERIFICATION_DONE atomic_data + flushrefresh_VERIFICATION_DONE atomic_data accum_swmr_big.h5 \ + ohdr_swmr.h5 INCLUDES = -I$(top_srcdir)/src -I$(top_builddir)/src # Test script for error_test and err_compat @@ -1223,6 +1230,9 @@ clean-noinstPROGRAMS: accum$(EXEEXT): $(accum_OBJECTS) $(accum_DEPENDENCIES) $(EXTRA_accum_DEPENDENCIES) @rm -f accum$(EXEEXT) $(AM_V_CCLD)$(LINK) $(accum_OBJECTS) $(accum_LDADD) $(LIBS) +accum_swmr_reader$(EXEEXT): $(accum_swmr_reader_OBJECTS) $(accum_swmr_reader_DEPENDENCIES) $(EXTRA_accum_swmr_reader_DEPENDENCIES) + @rm -f accum_swmr_reader$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(accum_swmr_reader_OBJECTS) $(accum_swmr_reader_LDADD) $(LIBS) app_ref$(EXEEXT): $(app_ref_OBJECTS) $(app_ref_DEPENDENCIES) $(EXTRA_app_ref_DEPENDENCIES) @rm -f app_ref$(EXEEXT) $(AM_V_CCLD)$(LINK) $(app_ref_OBJECTS) $(app_ref_LDADD) $(LIBS) @@ -1495,6 +1505,7 @@ distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/accum.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/accum_swmr_reader.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/app_ref.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/atomic_reader.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/atomic_writer.Po@am__quote@ diff --git a/test/accum.c b/test/accum.c index 488b866..6c89765 100644 --- a/test/accum.c +++ b/test/accum.c @@ -25,6 +25,11 @@ /* Filename */ #define FILENAME "accum.h5" +/* The file name is the same as the define in accum_swmr_reader.c */ +#define SWMR_FILENAME "accum_swmr_big.h5" +/* The reader forked by test_swmr_write_big() */ +#define SWMR_READER "accum_swmr_reader" + /* "big" I/O test values */ #define BIG_BUF_SIZE (6 * 1024 * 1024) @@ -50,6 +55,7 @@ unsigned test_read_after(void); unsigned test_free(void); unsigned test_big(void); unsigned test_random_write(void); +unsigned test_swmr_write_big(void); /* Helper Function Prototypes */ void accum_printf(void); @@ -119,6 +125,9 @@ main(void) if(H5Fclose(fid) < 0) TEST_ERROR HDremove(FILENAME); + /* This test uses a different file */ + nerrors += test_swmr_write_big(); + if(nerrors) goto error; puts("All metadata accumulator tests passed."); @@ -1772,6 +1781,165 @@ error: return 1; } /* end test_random_write() */ +/*------------------------------------------------------------------------- + * Function: test_swmr_write_big + * + * Purpose: A SWMR test: verifies that writing "large" metadata to a file + * opened with SWMR_WRITE will flush the existing metadata in the + * accumulator to disk first before writing the "large" metadata + * to disk. + * This test will fork and exec a reader "accum_swmr_reader" which + * opens the same file with SWMR_READ and verifies that the correct + * metadata is read from disk. + * + * Return: Success: 0 + * Failure: 1 + * + * Programmer: Vailin Choi; April 2013 + * + *------------------------------------------------------------------------- + */ +unsigned +test_swmr_write_big(void) +{ + hid_t fid = -1; /* File ID */ + hid_t fapl = -1; /* File access property list */ + H5F_t *rf = NULL; /* File pointer */ + uint8_t *wbuf2, *rbuf; /* Buffers for reading & writing */ + uint8_t wbuf[1024]; /* Buffer for reading & writing */ + unsigned u; /* Local index variable */ + pid_t pid; /* Process ID */ + int status; /* Status returned from child process */ + + TESTING("SWMR write of large metadata"); + + /* 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 + + /* Create a test file with latest format (ensure version 2 object header for SWMR) */ + if((fid = H5Fcreate(SWMR_FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) + FAIL_STACK_ERROR + + /* Close the file */ + if(H5Fclose(fid) < 0) + FAIL_STACK_ERROR + + /* Open the file with SWMR_WRITE */ + if((fid = H5Fopen(SWMR_FILENAME, H5F_ACC_RDWR | H5F_ACC_SWMR_WRITE, fapl)) < 0) + FAIL_STACK_ERROR + + /* Get H5F_t * to internal file structure */ + if(NULL == (rf = (H5F_t *)H5I_object(fid))) FAIL_STACK_ERROR + + /* We'll be writing lots of garbage data, so extend the + file a ways. 10MB should do. */ + if(H5FD_set_eoa(rf->shared->lf, H5FD_MEM_DEFAULT, (haddr_t)(1024*1024*10)) < 0) FAIL_STACK_ERROR + + /* Reset metadata accumulator for the file */ + if(H5F_accum_reset(rf, H5P_DATASET_XFER_DEFAULT, TRUE) < 0) + FAIL_STACK_ERROR; + + /* Allocate space for the write & read buffers */ + if((wbuf2 = (uint8_t *)HDmalloc(BIG_BUF_SIZE)) == NULL) + FAIL_STACK_ERROR; + if((rbuf = (uint8_t *)HDmalloc(BIG_BUF_SIZE)) == NULL) + FAIL_STACK_ERROR; + + /* Initialize wbuf with "0, 1, 2...1024"*/ + for(u = 0; u < 1024; u++) + wbuf[u] = (uint8_t)u; + + /* Write [1024, 1024] bytes with wbuf */ + if(H5F_block_write(rf, H5FD_MEM_DEFAULT, (haddr_t)1024, (size_t)1024, H5P_DATASET_XFER_DEFAULT, wbuf) < 0) + FAIL_STACK_ERROR; + /* Read the data */ + if(H5F_block_read(rf, H5FD_MEM_DEFAULT, (haddr_t)1024, (size_t)1024, H5P_DATASET_XFER_DEFAULT, rbuf) < 0) + FAIL_STACK_ERROR; + /* Verify the data read is correct */ + if(HDmemcmp(wbuf, rbuf, 1024) != 0) TEST_ERROR; + /* Flush the data to disk */ + if(H5F_accum_reset(rf, H5P_DATASET_XFER_DEFAULT, TRUE) < 0) + FAIL_STACK_ERROR; + + /* Initialize wbuf with all 1s */ + for(u = 0; u < 1024; u++) + wbuf[u] = (uint8_t)1; + + /* Initialize wbuf2 */ + for(u = 0; u < BIG_BUF_SIZE; u++) + wbuf2[u] = (uint8_t)(u + 1); + + /* Write [1024,1024] with wbuf--all 1s */ + if(H5F_block_write(rf, H5FD_MEM_DEFAULT, (haddr_t)1024, (size_t)1024, H5P_DATASET_XFER_DEFAULT, wbuf) < 0) + FAIL_STACK_ERROR; + /* Read the data */ + if(H5F_block_read(rf, H5FD_MEM_DEFAULT, (haddr_t)1024, (size_t)1024, H5P_DATASET_XFER_DEFAULT, rbuf) < 0) + FAIL_STACK_ERROR; + /* Verify the data read is correct */ + if(HDmemcmp(wbuf, rbuf, 1024) != 0) TEST_ERROR; + /* The data stays in the accumulator */ + + /* Write a large piece of metadata [2048, BIG_BUF_SIZE] with wbuf2 */ + if(H5F_block_write(rf, H5FD_MEM_DEFAULT, (haddr_t)2048, (size_t)BIG_BUF_SIZE, H5P_DATASET_XFER_DEFAULT, wbuf2) < 0) + FAIL_STACK_ERROR; + /* Read the data */ + if(H5F_block_read(rf, H5FD_MEM_DEFAULT, (haddr_t)2048, (size_t)BIG_BUF_SIZE, H5P_DATASET_XFER_DEFAULT, rbuf) < 0) + FAIL_STACK_ERROR; + /* Verify the data read is correct */ + if(HDmemcmp(wbuf2, rbuf, BIG_BUF_SIZE) != 0) TEST_ERROR; + + /* Fork child process to verify that the data at [1024, 2014] does get written to disk */ + if((pid = HDfork()) < 0) { + HDperror("fork"); + FAIL_STACK_ERROR; + } else if(0 == pid) { /* Child process */ + /* Run the reader */ + status = HDexecve(SWMR_READER, NULL, NULL); + FAIL_STACK_ERROR; + } + + /* Parent process -- wait for the child process to complete */ + while(pid != HDwaitpid(pid, &status, 0)) + /*void*/; + + /* Check if child process terminates normally and its return value */ + if(WIFEXITED(status) && !WEXITSTATUS(status)) { + /* Flush the accumulator */ + if(H5F_accum_reset(rf, H5P_DATASET_XFER_DEFAULT, TRUE) < 0) + FAIL_STACK_ERROR; + /* Close the property list */ + if(H5Pclose(fapl) < 0) + FAIL_STACK_ERROR; + + /* Close and remove the file */ + if(H5Fclose(fid) < 0) + FAIL_STACK_ERROR; + HDremove(SWMR_FILENAME); + + /* Release memory */ + if(wbuf2) HDfree(wbuf2); + if(rbuf) HDfree(rbuf); + PASSED(); + return 0; + } + +error: + /* Closing and remove the file */ + H5Pclose(fapl); + H5Fclose(fid); + HDremove(SWMR_FILENAME); + /* Release memory */ + if(wbuf2) HDfree(wbuf2); + if(rbuf) HDfree(rbuf); + + return 1; +} /* end test_swmr_write_big() */ + /*------------------------------------------------------------------------- * Function: accum_printf diff --git a/test/accum_swmr_reader.c b/test/accum_swmr_reader.c new file mode 100644 index 0000000..b9bf98d --- /dev/null +++ b/test/accum_swmr_reader.c @@ -0,0 +1,80 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * 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 "h5test.h" + +#define H5F_PACKAGE +#include "H5Fpkg.h" +#include "H5FDprivate.h" +#include "H5Iprivate.h" + +/* Filename: this is the same as the define in accum.c used by test_swmr_write_big() */ +#define SWMR_FILENAME "accum_swmr_big.h5" + + +/*------------------------------------------------------------------------- + * Function: main + * + * Purpose: This is the reader forked/execved by "test_swmr_write_big()" + * test in accum.c. The reader reads at address 1024 from the file + * and verifies that the metadata in the accumulator at address + * 1024 does get written to disk. + * + * Return: Success: 0 + * Failure: 1 + * + * Programmer: Vailin Choi; June 2013 + * + *------------------------------------------------------------------------- + */ +int +main(void) +{ + hid_t fid = -1; /* File ID */ + H5F_t *f = NULL; /* File pointer */ + unsigned u; /* Local index variable */ + uint8_t rbuf[1024]; /* Buffer for reading */ + uint8_t buf[1024]; /* Buffer for holding the expected data */ + + /* Initialize buffers */ + for(u = 0; u < 1024; u++) { + rbuf[u] = 0; /* The buffer for reading */ + buf[u] = 1; /* The expected data should be all 1s */ + } + + /* Open the file with SWMR_READ */ + if((fid = H5Fopen(SWMR_FILENAME, H5F_ACC_RDONLY | H5F_ACC_SWMR_READ, H5P_DEFAULT)) < 0) + FAIL_STACK_ERROR + + /* Get H5F_t * to internal file structure */ + if(NULL == (f = (H5F_t *)H5I_object(fid))) + FAIL_STACK_ERROR + + /* Should read in [1024, 2024] with buf data */ + if(H5F_block_read(f, H5FD_MEM_DEFAULT, (haddr_t)1024, (size_t)1024, H5P_DATASET_XFER_DEFAULT, rbuf) < 0) + FAIL_STACK_ERROR; + + /* Verify the data read is correct */ + if(HDmemcmp(buf, rbuf, 1024) != 0) + TEST_ERROR; + + /* CLose the file */ + if(H5Fclose(fid) < 0) + FAIL_STACK_ERROR; + + return 0; + +error: + H5Fclose(fid); + return 1; +} /* end main() */ 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); |