diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile.am | 2 | ||||
-rw-r--r-- | test/Makefile.in | 45 | ||||
-rw-r--r-- | test/gen_bad_ohdr.c | 103 | ||||
-rw-r--r-- | test/tbad_msg_count.h5 | bin | 0 -> 1984 bytes | |||
-rw-r--r-- | test/tmisc.c | 61 |
5 files changed, 192 insertions, 19 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index 4f4951c..53df8bb 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -59,7 +59,7 @@ check_PROGRAMS=$(TEST_PROG) error_test err_compat testmeta # --enable-build-all at configure time. # The gen_old_* files can only be compiled with older versions of the library # so do not appear in this list. -BUILD_ALL_PROGS=gen_bogus gen_cross gen_deflate gen_filters gen_new_array \ +BUILD_ALL_PROGS=gen_bad_ohdr gen_bogus gen_cross gen_deflate gen_filters gen_new_array \ gen_new_fill gen_new_group gen_new_mtime gen_new_super gen_noencoder \ gen_nullspace gen_udlinks space_overflow diff --git a/test/Makefile.in b/test/Makefile.in index 84f0737..7e47249 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -81,8 +81,8 @@ am__EXEEXT_1 = testhdf5$(EXEEXT) lheap$(EXEEXT) ohdr$(EXEEXT) \ vfd$(EXEEXT) ntypes$(EXEEXT) dangle$(EXEEXT) \ dtransform$(EXEEXT) reserved$(EXEEXT) cross_read$(EXEEXT) \ btree2$(EXEEXT) fheap$(EXEEXT) -am__EXEEXT_2 = gen_bogus$(EXEEXT) gen_cross$(EXEEXT) \ - gen_deflate$(EXEEXT) gen_filters$(EXEEXT) \ +am__EXEEXT_2 = gen_bad_ohdr$(EXEEXT) gen_bogus$(EXEEXT) \ + gen_cross$(EXEEXT) gen_deflate$(EXEEXT) gen_filters$(EXEEXT) \ gen_new_array$(EXEEXT) gen_new_fill$(EXEEXT) \ gen_new_group$(EXEEXT) gen_new_mtime$(EXEEXT) \ gen_new_super$(EXEEXT) gen_noencoder$(EXEEXT) \ @@ -173,6 +173,10 @@ flush2_SOURCES = flush2.c flush2_OBJECTS = flush2.$(OBJEXT) flush2_LDADD = $(LDADD) flush2_DEPENDENCIES = libh5test.la $(LIBHDF5) +gen_bad_ohdr_SOURCES = gen_bad_ohdr.c +gen_bad_ohdr_OBJECTS = gen_bad_ohdr.$(OBJEXT) +gen_bad_ohdr_LDADD = $(LDADD) +gen_bad_ohdr_DEPENDENCIES = libh5test.la $(LIBHDF5) gen_bogus_SOURCES = gen_bogus.c gen_bogus_OBJECTS = gen_bogus.$(OBJEXT) gen_bogus_LDADD = $(LDADD) @@ -331,24 +335,26 @@ SOURCES = $(libh5test_la_SOURCES) big.c bittests.c btree2.c cache.c \ cache_api.c cmpd_dset.c cross_read.c dangle.c dsets.c \ dt_arith.c dtransform.c dtypes.c enum.c err_compat.c \ error_test.c extend.c external.c fheap.c fillval.c flush1.c \ - flush2.c gen_bogus.c gen_cross.c gen_deflate.c gen_filters.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_udlinks.c \ - getname.c gheap.c hyperslab.c istore.c lheap.c links.c mount.c \ - mtime.c ntypes.c objcopy.c ohdr.c pool.c reserved.c \ - set_extent.c space_overflow.c stab.c $(testhdf5_SOURCES) \ - testmeta.c $(ttsafe_SOURCES) unlink.c vfd.c + flush2.c gen_bad_ohdr.c gen_bogus.c gen_cross.c gen_deflate.c \ + gen_filters.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_udlinks.c getname.c gheap.c hyperslab.c \ + istore.c lheap.c links.c mount.c mtime.c ntypes.c objcopy.c \ + ohdr.c pool.c reserved.c set_extent.c space_overflow.c stab.c \ + $(testhdf5_SOURCES) testmeta.c $(ttsafe_SOURCES) unlink.c \ + vfd.c DIST_SOURCES = $(libh5test_la_SOURCES) big.c bittests.c btree2.c \ cache.c cache_api.c cmpd_dset.c cross_read.c dangle.c dsets.c \ dt_arith.c dtransform.c dtypes.c enum.c err_compat.c \ error_test.c extend.c external.c fheap.c fillval.c flush1.c \ - flush2.c gen_bogus.c gen_cross.c gen_deflate.c gen_filters.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_udlinks.c \ - getname.c gheap.c hyperslab.c istore.c lheap.c links.c mount.c \ - mtime.c ntypes.c objcopy.c ohdr.c pool.c reserved.c \ - set_extent.c space_overflow.c stab.c $(testhdf5_SOURCES) \ - testmeta.c $(ttsafe_SOURCES) unlink.c vfd.c + flush2.c gen_bad_ohdr.c gen_bogus.c gen_cross.c gen_deflate.c \ + gen_filters.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_udlinks.c getname.c gheap.c hyperslab.c \ + istore.c lheap.c links.c mount.c mtime.c ntypes.c objcopy.c \ + ohdr.c pool.c reserved.c set_extent.c space_overflow.c stab.c \ + $(testhdf5_SOURCES) testmeta.c $(ttsafe_SOURCES) unlink.c \ + vfd.c ETAGS = etags CTAGS = ctags DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) @@ -470,6 +476,7 @@ SET_MAKE = @SET_MAKE@ SHELL = /bin/sh SIZE_T = @SIZE_T@ STATIC_SHARED = @STATIC_SHARED@ +STRICT_FORMAT_CHECKS = @STRICT_FORMAT_CHECKS@ STRIP = @STRIP@ TESTPARALLEL = @TESTPARALLEL@ TIME = @TIME@ @@ -631,7 +638,7 @@ TEST_PROG = testhdf5 lheap ohdr stab gheap cache cache_api \ # --enable-build-all at configure time. # The gen_old_* files can only be compiled with older versions of the library # so do not appear in this list. -BUILD_ALL_PROGS = gen_bogus gen_cross gen_deflate gen_filters gen_new_array \ +BUILD_ALL_PROGS = gen_bad_ohdr gen_bogus gen_cross gen_deflate gen_filters gen_new_array \ gen_new_fill gen_new_group gen_new_mtime gen_new_super gen_noencoder \ gen_nullspace gen_udlinks space_overflow @@ -798,6 +805,9 @@ flush1$(EXEEXT): $(flush1_OBJECTS) $(flush1_DEPENDENCIES) flush2$(EXEEXT): $(flush2_OBJECTS) $(flush2_DEPENDENCIES) @rm -f flush2$(EXEEXT) $(LINK) $(flush2_OBJECTS) $(flush2_LDADD) $(LIBS) +gen_bad_ohdr$(EXEEXT): $(gen_bad_ohdr_OBJECTS) $(gen_bad_ohdr_DEPENDENCIES) + @rm -f gen_bad_ohdr$(EXEEXT) + $(LINK) $(gen_bad_ohdr_OBJECTS) $(gen_bad_ohdr_LDADD) $(LIBS) gen_bogus$(EXEEXT): $(gen_bogus_OBJECTS) $(gen_bogus_DEPENDENCIES) @rm -f gen_bogus$(EXEEXT) $(LINK) $(gen_bogus_OBJECTS) $(gen_bogus_LDADD) $(LIBS) @@ -926,6 +936,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fillval.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/flush1.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/flush2.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gen_bad_ohdr.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gen_bogus.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gen_cross.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gen_deflate.Po@am__quote@ diff --git a/test/gen_bad_ohdr.c b/test/gen_bad_ohdr.c new file mode 100644 index 0000000..d04996d --- /dev/null +++ b/test/gen_bad_ohdr.c @@ -0,0 +1,103 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * 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. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* + * Programmer: Quincey Koziol <koziol@hdfgroup.org> + * Jan 5, 2008 + * + * Purpose: This program is run to generate an HDF5 data file with a + * root group that contains the incorrect # of object header + * messages. It must be built/run with a copy of the library + * that has been built with the "H5O_ENABLE_BAD_MESG_COUNT" macro + * defined. + */ + +#include "hdf5.h" +#include "H5private.h" +#include "H5Oprivate.h" + +#define FILENAME "tbad_msg_count.h5" +#define GROUPNAME "Group" +#define ATTRNAME1 "Attribute #1" +#define ATTRNAME2 "Attribute #2" + +#ifndef TRUE +#define TRUE 1 +#endif /* TRUE */ +#ifndef FALSE +#define FALSE 0 +#endif /* FALSE */ + +int main(void) +{ +#ifdef H5O_ENABLE_BAD_MESG_COUNT + hid_t fid = -1; /* File ID */ + hid_t gid = -1; /* Group ID */ + hid_t sid = -1; /* Dataspace ID */ + hid_t aid = -1; /* Attribute ID */ + hid_t gcpl = -1; /* Group creation property list ID */ + hbool_t store_bad_mesg_count; /* Flag for storing a bad message count */ + + /* Create test file */ + if((fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto error; + + /* Create group creation property list */ + if((gcpl = H5Pcreate(H5P_GROUP_CREATE)) < 0) goto error; + + /* Add property for storing bad message count */ + store_bad_mesg_count = TRUE; + if(H5Pinsert2(gcpl, H5O_BAD_MESG_COUNT_NAME, H5O_BAD_MESG_COUNT_SIZE, &store_bad_mesg_count, NULL, NULL, NULL, NULL, NULL, NULL) < 0) goto error; + + /* Create group with bad object header message count */ + if((gid = H5Gcreate2(fid, GROUPNAME, H5P_DEFAULT, gcpl, H5P_DEFAULT)) < 0) goto error; + + /* Close group creation property list */ + if(H5Pclose(gcpl) < 0) goto error; + + /* Create dataspace for attributes */ + if((sid = H5Screate(H5S_SCALAR)) < 0) goto error; + + /* Create attribute on root group */ + if((aid = H5Acreate2(gid, ATTRNAME1, H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto error; + if(H5Aclose(aid) < 0) goto error; + + /* Create another attribute on root group */ + if((aid = H5Acreate2(gid, ATTRNAME2, H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto error; + if(H5Aclose(aid) < 0) goto error; + + /* Close dataspace */ + if(H5Sclose(sid) < 0) goto error; + + /* Close group */ + if(H5Gclose(gid) < 0) goto error; + + /* Close file */ + if(H5Fclose(fid) < 0) goto error; + + return 0; + +error: + H5E_BEGIN_TRY { + H5Dclose(aid); + H5Sclose(sid); + H5Pclose(gcpl); + H5Fclose(fid); + } H5E_END_TRY; +#else /* H5O_ENABLE_BAD_MESG_COUNT */ + HDputs("H5O_BAD_MESG_COUNT compiler macro not defined!"); +#endif /* H5O_ENABLE_BAD_MESG_COUNT */ + return 1; +} + diff --git a/test/tbad_msg_count.h5 b/test/tbad_msg_count.h5 Binary files differnew file mode 100644 index 0000000..ca5eb65 --- /dev/null +++ b/test/tbad_msg_count.h5 diff --git a/test/tmisc.c b/test/tmisc.c index cc4e5ec..915407c 100644 --- a/test/tmisc.c +++ b/test/tmisc.c @@ -295,6 +295,11 @@ unsigned m13_rdata[MISC13_DIM1][MISC13_DIM2]; /* Data read from dataset /* Definitions for misc. test #26 */ #define MISC26_FILE "dcpl_file" +/* Definitions for misc. test #27 */ +/* (Note that this test file is generated by the "gen_bad_ohdr.c" code) */ +#define MISC27_FILE "tbad_msg_count.h5" +#define MISC27_GROUP "Group" + /**************************************************************** ** ** test_misc1(): test unlinking a dataset from a group and immediately @@ -1709,7 +1714,7 @@ test_misc10(void) hid_t dcpl; /* Dataset creation property list */ hid_t space, type; /* Old dataset's dataspace & datatype */ char testfile[512]=""; /* Character buffer for corrected test file name */ - char *srcdir = getenv("srcdir"); /* Pointer to the directory the source code is located within */ + char *srcdir = HDgetenv("srcdir"); /* Pointer to the directory the source code is located within */ herr_t ret; /* Output message about test being performed */ @@ -4796,6 +4801,59 @@ test_misc26(void) CHECK_I(ret, "H5Pclose"); } + +/**************************************************************** +** +** test_misc27(): Ensure that objects with incorrect # of object +** header messages are handled appropriately. +** +** (Note that this test file is generated by the "gen_bad_ohdr.c" code) +** +****************************************************************/ +static void +test_misc27(void) +{ + hid_t fid; /* File ID */ + hid_t gid; /* Group ID */ + char testfile[512]=""; /* Character buffer for corrected test file name */ + char *srcdir = HDgetenv("srcdir"); /* Pointer to the directory the source code is located within */ + herr_t ret; /* Generic return value */ + + /* Output message about test being performed */ + MESSAGE(5, ("Corrupt object header handling\n")); + + /* Generate the correct name for the test file, by prepending the source path */ + if(srcdir && ((HDstrlen(srcdir) + HDstrlen(MISC27_FILE) + 1) < sizeof(testfile))) { + HDstrcpy(testfile, srcdir); + HDstrcat(testfile, "/"); + } + HDstrcat(testfile, MISC27_FILE); + + /* Open the file */ + fid = H5Fopen(testfile, H5F_ACC_RDONLY, H5P_DEFAULT); + CHECK(fid, FAIL, "H5Fopen"); + +#ifdef H5_STRICT_FORMAT_CHECKS + /* Open group with incorrect # of object header messages (should fail) */ + H5E_BEGIN_TRY { + gid = H5Gopen2(fid, MISC27_GROUP, H5P_DEFAULT); + } H5E_END_TRY; + VERIFY(gid, FAIL, "H5Gopen2"); +#else /* H5_STRICT_FORMAT_CHECKS */ + /* Open group with incorrect # of object header messages */ + gid = H5Gopen2(fid, MISC27_GROUP, H5P_DEFAULT); + CHECK(gid, FAIL, "H5Gopen2"); + + /* Close group */ + ret = H5Gclose(gid); + CHECK(ret, FAIL, "H5Gclose"); +#endif /* H5_STRICT_FORMAT_CHECKS */ + + /* Close file */ + ret = H5Fclose(fid); + CHECK(ret, FAIL, "H5Fclose"); +} /* end test_misc27() */ + /**************************************************************** ** ** test_misc(): Main misc. test routine. @@ -4837,6 +4895,7 @@ test_misc(void) test_misc25b(); /* Exercise null object header message merge bug on existing file */ test_misc25c(); /* Exercise another null object header message merge bug */ test_misc26(); /* Test closing property lists with long filter pipelines */ + test_misc27(); /* Test opening file with object that has bad # of object header messages */ } /* test_misc() */ |