diff options
author | Albert Cheng <acheng@hdfgroup.org> | 2005-06-24 14:32:05 (GMT) |
---|---|---|
committer | Albert Cheng <acheng@hdfgroup.org> | 2005-06-24 14:32:05 (GMT) |
commit | 40e51ae04729fbeb1d789b5310655887b2f66538 (patch) | |
tree | c9920f625615b104af137eb809acb22f5bb99ad0 /test | |
parent | 7f8e3460261851cdad1e344d8929d2817e3149ad (diff) | |
download | hdf5-40e51ae04729fbeb1d789b5310655887b2f66538.zip hdf5-40e51ae04729fbeb1d789b5310655887b2f66538.tar.gz hdf5-40e51ae04729fbeb1d789b5310655887b2f66538.tar.bz2 |
[svn-r10979] Purpose:
Renamed file_handle.c as vfd.c since its tests have evloved from
merely file handles tests to other basic features of VFD's.
Did some minor cosmetic changes in vfd.c.
Updated Makefile.am with the new name.
Makefile.in is regenerated.
Platforms tested:
In heping only since the changes are trivial.
Misc. update:
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile.am | 2 | ||||
-rw-r--r-- | test/Makefile.in | 42 | ||||
-rw-r--r-- | test/vfd.c | 739 |
3 files changed, 761 insertions, 22 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index 1243639..e4cdc00 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -34,7 +34,7 @@ TEST_PROG=testhdf5 lheap ohdr stab gheap cache btree2 blocktrack sheap \ dtypes dsets cmpd_dset extend external links unlink big mtime \ fillval mount flush1 flush2 enum \ set_extent ttsafe stream_test \ - getname file_handle ntypes dangle dtransform filename reserved + getname vfd ntypes dangle dtransform filename reserved # 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. diff --git a/test/Makefile.in b/test/Makefile.in index 305904a..caeb4bc 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -29,7 +29,7 @@ # # HDF5 Library Test Makefile(.in) # -SOURCES = $(libh5test_la_SOURCES) big.c bittests.c blocktrack.c btree2.c cache.c cmpd_dset.c dangle.c dsets.c dt_arith.c dtransform.c dtypes.c enum.c err_compat.c error_test.c extend.c external.c file_handle.c filename.c fillval.c flush1.c flush2.c getname.c gheap.c hyperslab.c istore.c lheap.c links.c mount.c mtime.c ntypes.c ohdr.c pool.c reserved.c set_extent.c sheap.c stab.c stream_test.c $(testhdf5_SOURCES) testmeta.c $(ttsafe_SOURCES) unlink.c +SOURCES = $(libh5test_la_SOURCES) big.c bittests.c blocktrack.c btree2.c cache.c cmpd_dset.c dangle.c dsets.c dt_arith.c dtransform.c dtypes.c enum.c err_compat.c error_test.c extend.c external.c filename.c fillval.c flush1.c flush2.c getname.c gheap.c hyperslab.c istore.c lheap.c links.c mount.c mtime.c ntypes.c ohdr.c pool.c reserved.c set_extent.c sheap.c stab.c stream_test.c $(testhdf5_SOURCES) testmeta.c $(ttsafe_SOURCES) unlink.c vfd.c srcdir = @srcdir@ top_srcdir = @top_srcdir@ @@ -80,7 +80,7 @@ am__EXEEXT_1 = testhdf5$(EXEEXT) lheap$(EXEEXT) ohdr$(EXEEXT) \ fillval$(EXEEXT) mount$(EXEEXT) flush1$(EXEEXT) \ flush2$(EXEEXT) enum$(EXEEXT) set_extent$(EXEEXT) \ ttsafe$(EXEEXT) stream_test$(EXEEXT) getname$(EXEEXT) \ - file_handle$(EXEEXT) ntypes$(EXEEXT) dangle$(EXEEXT) \ + vfd$(EXEEXT) ntypes$(EXEEXT) dangle$(EXEEXT) \ dtransform$(EXEEXT) filename$(EXEEXT) reserved$(EXEEXT) big_SOURCES = big.c big_OBJECTS = big.$(OBJEXT) @@ -146,10 +146,6 @@ external_SOURCES = external.c external_OBJECTS = external.$(OBJEXT) external_LDADD = $(LDADD) external_DEPENDENCIES = libh5test.la $(am__DEPENDENCIES_1) -file_handle_SOURCES = file_handle.c -file_handle_OBJECTS = file_handle.$(OBJEXT) -file_handle_LDADD = $(LDADD) -file_handle_DEPENDENCIES = libh5test.la $(am__DEPENDENCIES_1) filename_SOURCES = filename.c filename_OBJECTS = filename.$(OBJEXT) filename_LDADD = $(LDADD) @@ -255,6 +251,10 @@ unlink_SOURCES = unlink.c unlink_OBJECTS = unlink.$(OBJEXT) unlink_LDADD = $(LDADD) unlink_DEPENDENCIES = libh5test.la $(am__DEPENDENCIES_1) +vfd_SOURCES = vfd.c +vfd_OBJECTS = vfd.$(OBJEXT) +vfd_LDADD = $(LDADD) +vfd_DEPENDENCIES = libh5test.la $(am__DEPENDENCIES_1) DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/src depcomp = $(SHELL) $(top_srcdir)/bin/depcomp am__depfiles_maybe = depfiles @@ -269,19 +269,19 @@ LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ SOURCES = $(libh5test_la_SOURCES) big.c bittests.c blocktrack.c \ btree2.c cache.c cmpd_dset.c dangle.c dsets.c dt_arith.c \ dtransform.c dtypes.c enum.c err_compat.c error_test.c \ - extend.c external.c file_handle.c filename.c fillval.c \ - flush1.c flush2.c getname.c gheap.c hyperslab.c istore.c \ - lheap.c links.c mount.c mtime.c ntypes.c ohdr.c pool.c \ - reserved.c set_extent.c sheap.c stab.c stream_test.c \ - $(testhdf5_SOURCES) testmeta.c $(ttsafe_SOURCES) unlink.c + extend.c external.c filename.c fillval.c flush1.c flush2.c \ + getname.c gheap.c hyperslab.c istore.c lheap.c links.c mount.c \ + mtime.c ntypes.c ohdr.c pool.c reserved.c set_extent.c sheap.c \ + stab.c stream_test.c $(testhdf5_SOURCES) testmeta.c \ + $(ttsafe_SOURCES) unlink.c vfd.c DIST_SOURCES = $(libh5test_la_SOURCES) big.c bittests.c blocktrack.c \ btree2.c cache.c cmpd_dset.c dangle.c dsets.c dt_arith.c \ dtransform.c dtypes.c enum.c err_compat.c error_test.c \ - extend.c external.c file_handle.c filename.c fillval.c \ - flush1.c flush2.c getname.c gheap.c hyperslab.c istore.c \ - lheap.c links.c mount.c mtime.c ntypes.c ohdr.c pool.c \ - reserved.c set_extent.c sheap.c stab.c stream_test.c \ - $(testhdf5_SOURCES) testmeta.c $(ttsafe_SOURCES) unlink.c + extend.c external.c filename.c fillval.c flush1.c flush2.c \ + getname.c gheap.c hyperslab.c istore.c lheap.c links.c mount.c \ + mtime.c ntypes.c ohdr.c pool.c reserved.c set_extent.c sheap.c \ + stab.c stream_test.c $(testhdf5_SOURCES) testmeta.c \ + $(ttsafe_SOURCES) unlink.c vfd.c ETAGS = etags CTAGS = ctags DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) @@ -504,7 +504,7 @@ TEST_PROG = testhdf5 lheap ohdr stab gheap cache btree2 blocktrack sheap \ dtypes dsets cmpd_dset extend external links unlink big mtime \ fillval mount flush1 flush2 enum \ set_extent ttsafe stream_test \ - getname file_handle ntypes dangle dtransform filename reserved + getname vfd ntypes dangle dtransform filename reserved # The libh5test.a library provides common support code for the tests. @@ -664,9 +664,6 @@ extend$(EXEEXT): $(extend_OBJECTS) $(extend_DEPENDENCIES) external$(EXEEXT): $(external_OBJECTS) $(external_DEPENDENCIES) @rm -f external$(EXEEXT) $(LINK) $(external_LDFLAGS) $(external_OBJECTS) $(external_LDADD) $(LIBS) -file_handle$(EXEEXT): $(file_handle_OBJECTS) $(file_handle_DEPENDENCIES) - @rm -f file_handle$(EXEEXT) - $(LINK) $(file_handle_LDFLAGS) $(file_handle_OBJECTS) $(file_handle_LDADD) $(LIBS) filename$(EXEEXT): $(filename_OBJECTS) $(filename_DEPENDENCIES) @rm -f filename$(EXEEXT) $(LINK) $(filename_LDFLAGS) $(filename_OBJECTS) $(filename_LDADD) $(LIBS) @@ -739,6 +736,9 @@ ttsafe$(EXEEXT): $(ttsafe_OBJECTS) $(ttsafe_DEPENDENCIES) unlink$(EXEEXT): $(unlink_OBJECTS) $(unlink_DEPENDENCIES) @rm -f unlink$(EXEEXT) $(LINK) $(unlink_LDFLAGS) $(unlink_OBJECTS) $(unlink_LDADD) $(LIBS) +vfd$(EXEEXT): $(vfd_OBJECTS) $(vfd_DEPENDENCIES) + @rm -f vfd$(EXEEXT) + $(LINK) $(vfd_LDFLAGS) $(vfd_OBJECTS) $(vfd_LDADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -762,7 +762,6 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/error_test.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/extend.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/external.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/file_handle.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/filename.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fillval.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/flush1.Po@am__quote@ @@ -813,6 +812,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tvlstr.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tvltypes.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/unlink.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vfd.Po@am__quote@ .c.o: @am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \ diff --git a/test/vfd.c b/test/vfd.c new file mode 100644 index 0000000..16038c3 --- /dev/null +++ b/test/vfd.c @@ -0,0 +1,739 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * 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://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* + * Programmer: Raymond Lu<slu@ncsa.uiuc.edu> + * Tuesday, Sept 24, 2002 + * + * Purpose: Tests the basic features of Virtual File Drivers + */ + +#include "h5test.h" + +#define KB 1024 +#define FAMILY_NUMBER 4 +#define FAMILY_SIZE (1*KB) +#define FAMILY_SIZE2 (5*KB) +#define MULTI_SIZE 128 +#define CORE_INCREMENT (4*KB) + +const char *FILENAME[] = { + "sec2_file", + "core_file", + "family_file", + "multi_file", + NULL +}; + +#define COMPAT_BASENAME "family_v1.6_" + + +/*------------------------------------------------------------------------- + * Function: test_sec2 + * + * Purpose: Tests the file handle interface for SEC2 driver + * + * Return: Success: exit(0) + * + * Failure: exit(1) + * + * Programmer: Raymond Lu + * Tuesday, Sept 24, 2002 + * + * Modifications: + * + * Raymond Lu + * Wednesday, June 23, 2004 + * Added test for H5Fget_filesize. + * + *------------------------------------------------------------------------- + */ +static herr_t +test_sec2(void) +{ + hid_t file=(-1), fapl, access_fapl = -1; + char filename[1024]; + int *fhandle=NULL; + hsize_t file_size; + + TESTING("SEC2 file driver"); + + /* Set property list and file name for SEC2 driver. */ + fapl = h5_fileaccess(); + if(H5Pset_fapl_sec2(fapl)<0) + goto error; + h5_fixname(FILENAME[0], fapl, filename, sizeof filename); + + if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0) + goto error; + + /* Retrieve the access property list... */ + if ((access_fapl = H5Fget_access_plist(file)) < 0) + goto error; + + /* ...and close the property list */ + if (H5Pclose(access_fapl) < 0) + goto error; + + /* Check file handle API */ + if(H5Fget_vfd_handle(file, H5P_DEFAULT, (void **)&fhandle)<0) + goto error; + if(*fhandle<0) + goto error; + + /* Check file size API */ + if(H5Fget_filesize(file, &file_size) < 0) + goto error; + + /* There is no garantee the size of metadata in file is constant. + * Just try to check if it's reasonable. It's 2KB right now. + */ + if(file_size<1*KB || file_size>4*KB) + goto error; + + if(H5Fclose(file)<0) + goto error; + h5_cleanup(FILENAME, fapl); + PASSED(); + return 0; + +error: + H5E_BEGIN_TRY { + H5Pclose (fapl); + H5Fclose(file); + } H5E_END_TRY; + return -1; +} + + +/*------------------------------------------------------------------------- + * Function: test_core + * + * Purpose: Tests the file handle interface for CORE driver + * + * Return: Success: exit(0) + * + * Failure: exit(1) + * + * Programmer: Raymond Lu + * Tuesday, Sept 24, 2002 + * + * Modifications: + * + * Raymond Lu + * Wednesday, June 23, 2004 + * Added test for H5Fget_filesize. + * + *------------------------------------------------------------------------- + */ +static herr_t +test_core(void) +{ + hid_t file=(-1), fapl, access_fapl = -1; + char filename[1024]; + void *fhandle=NULL; + hsize_t file_size; + + TESTING("CORE file driver"); + + /* Set property list and file name for CORE driver */ + fapl = h5_fileaccess(); + if(H5Pset_fapl_core(fapl, CORE_INCREMENT, TRUE)<0) + goto error; + h5_fixname(FILENAME[1], fapl, filename, sizeof filename); + + if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0) + goto error; + + /* Retrieve the access property list... */ + if ((access_fapl = H5Fget_access_plist(file)) < 0) + goto error; + + /* ...and close the property list */ + if (H5Pclose(access_fapl) < 0) + goto error; + + if(H5Fget_vfd_handle(file, H5P_DEFAULT, &fhandle)<0) + goto error; + if(fhandle==NULL) + { + printf("fhandle==NULL\n"); + goto error; + } + + /* Check file size API */ + if(H5Fget_filesize(file, &file_size) < 0) + goto error; + + /* There is no garantee the size of metadata in file is constant. + * Just try to check if it's reasonable. Why is this 4KB? + */ + if(file_size<2*KB || file_size>6*KB) + goto error; + + if(H5Fclose(file)<0) + goto error; + h5_cleanup(FILENAME, fapl); + PASSED(); + return 0; + +error: + H5E_BEGIN_TRY { + H5Pclose (fapl); + H5Fclose(file); + } H5E_END_TRY; + return -1; +} + + +/*------------------------------------------------------------------------- + * Function: test_family_opens + * + * Purpose: Private function for test_family() to tests wrong ways of + * reopening family file. + * + * Return: Success: exit(0) + * + * Failure: exit(1) + * + * Programmer: Raymond Lu + * Thursday, May 19, 2005 + * + * Modifications: + *------------------------------------------------------------------------- + */ +static herr_t +test_family_opens(char *fname, hid_t fa_pl) +{ + hid_t file; + char first_name[1024]; + char wrong_name[1024]; + int i; + + /* Case 1: reopen file with 1st member file name and default property list */ + sprintf(first_name, fname, 0); + + H5E_BEGIN_TRY { + file=H5Fopen(first_name, H5F_ACC_RDWR, H5P_DEFAULT); + } H5E_END_TRY; + + /* Case 2: reopen file with correct name template but default property list */ + H5E_BEGIN_TRY { + file=H5Fopen(fname, H5F_ACC_RDWR, H5P_DEFAULT); + } H5E_END_TRY; + + /* Case 3: reopen file with wrong member size */ + if(H5Pset_fapl_family(fa_pl, (hsize_t)128, H5P_DEFAULT)<0) + goto error; + + H5E_BEGIN_TRY { + file=H5Fopen(fname, H5F_ACC_RDWR, fa_pl); + } H5E_END_TRY; + + /* Case 4: reopen file with wrong name template */ + strcpy(wrong_name, fname); + for(i=0; i<1024; i++) { + if(wrong_name[i] == '5') { + wrong_name[i] = '4'; + break; + } + } + + if(H5Pset_fapl_family(fa_pl, (hsize_t)FAMILY_SIZE, H5P_DEFAULT)<0) + goto error; + + H5E_BEGIN_TRY { + file=H5Fopen(wrong_name, H5F_ACC_RDWR, fa_pl); + } H5E_END_TRY; + + return 0; +error: + return -1; +} + + +/*------------------------------------------------------------------------- + * Function: test_family + * + * Purpose: Tests the file handle interface for FAMILY driver + * + * Return: Success: exit(0) + * + * Failure: exit(1) + * + * Programmer: Raymond Lu + * Tuesday, Sept 24, 2002 + * + * Modifications: + * + * Raymond Lu + * Wednesday, June 23, 2004 + * Added test for H5Fget_filesize. + * + * Raymond Lu + * June 2, 2005 + * Added a function test_family_opens() to test different + * wrong way to reopen family files. + * + *------------------------------------------------------------------------- + */ +static herr_t +test_family(void) +{ + hid_t file=(-1), fapl, fapl2=(-1), space=(-1), dset=(-1); + hid_t access_fapl = -1; + char filename[1024]; + char dname[]="dataset"; + int i, j; + int *fhandle=NULL, *fhandle2=NULL; + int buf[FAMILY_NUMBER][FAMILY_SIZE]; + hsize_t dims[2]={FAMILY_NUMBER, FAMILY_SIZE}; + hsize_t file_size; + + TESTING("FAMILY file driver"); + + /* Set property list and file name for FAMILY driver */ + fapl = h5_fileaccess(); + + if(H5Pset_fapl_family(fapl, (hsize_t)FAMILY_SIZE, H5P_DEFAULT)<0) + goto error; + h5_fixname(FILENAME[2], fapl, filename, sizeof filename); + + if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0) + goto error; + + if(H5Fclose(file)<0) + goto error; + + /* Test different wrong ways to reopen family files where there's only + * one member file existing. */ + if(test_family_opens(filename, fapl)<0) + goto error; + + /* Reopen the file with default member file size */ + if(H5Pset_fapl_family(fapl, (hsize_t)H5F_FAMILY_DEFAULT, H5P_DEFAULT)<0) + goto error; + + if((file=H5Fopen(filename, H5F_ACC_RDWR, fapl))<0) + goto error; + + /* Check file size API */ + if(H5Fget_filesize(file, &file_size) < 0) + goto error; + + /* The file size is supposed to be about 1024 bytes right now. */ + if(file_size<KB/2 || file_size>4*KB) + goto error; + + /* Create and write dataset */ + if((space=H5Screate_simple(2, dims, NULL))<0) + goto error; + + /* Retrieve the access property list... */ + if ((access_fapl = H5Fget_access_plist(file)) < 0) + goto error; + + /* ...and close the property list */ + if (H5Pclose(access_fapl) < 0) + goto error; + + if((dset=H5Dcreate(file, dname, H5T_NATIVE_INT, space, H5P_DEFAULT))<0) + goto error; + + for(i=0; i<FAMILY_NUMBER; i++) + for(j=0; j<FAMILY_SIZE; j++) + buf[i][j] = i*10000+j; + if(H5Dwrite(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf)<0) + goto error; + + /* check file handle API */ + if((fapl2=H5Pcreate(H5P_FILE_ACCESS))<0) + goto error; + if(H5Pset_family_offset(fapl2, (hsize_t)0)<0) + goto error; + + if(H5Fget_vfd_handle(file, fapl2, (void **)&fhandle)<0) + goto error; + if(*fhandle<0) + goto error; + + if(H5Pset_family_offset(fapl2, (hsize_t)(FAMILY_SIZE*2))<0) + goto error; + if(H5Fget_vfd_handle(file, fapl2, (void **)&fhandle2)<0) + goto error; + if(*fhandle2<0) + goto error; + + /* Check file size API */ + if(H5Fget_filesize(file, &file_size) < 0) + goto error; + + /* Some data has been written. The file size should be bigger(18KB+976 + * bytes if int size is 4 bytes) now. */ + if(sizeof(int)<=4) { + if(file_size<18*KB || file_size>20*KB) + goto error; + } else if(sizeof(int)>=8) { + if(file_size<32*KB || file_size>40*KB) + goto error; + } + + if(H5Sclose(space)<0) + goto error; + if(H5Dclose(dset)<0) + goto error; + if(H5Pclose(fapl2)<0) + goto error; + if(H5Fclose(file)<0) + goto error; + + /* Test different wrong ways to reopen family files when there're multiple + * member files existing. */ + if(test_family_opens(filename, fapl)<0) + goto error; + + /* Reopen the file with correct member file size. */ + if(H5Pset_fapl_family(fapl, (hsize_t)FAMILY_SIZE, H5P_DEFAULT)<0) + goto error; + + if((file=H5Fopen(filename, H5F_ACC_RDWR, fapl))<0) + goto error; + + if(H5Fclose(file)<0) + goto error; + + h5_cleanup(FILENAME, fapl); + PASSED(); + return 0; + +error: + H5E_BEGIN_TRY { + H5Sclose(space); + H5Dclose(dset); + H5Pclose (fapl2); + H5Fclose(file); + } H5E_END_TRY; + return -1; +} + + +/*------------------------------------------------------------------------- + * Function: test_family_compat + * + * Purpose: Tests the backward compatibility for FAMILY driver. + * See if we can open files created with v1.6 library. + * The source file was created by the test/file_handle.c + * of the v1.6 library. Then tools/misc/h5repart.c was + * used to concantenated. The command was "h5repart -m 5k + * family_file%05d.h5 family_v1.6_%05d.h5". + * + * Return: Success: exit(0) + * + * Failure: exit(1) + * + * Programmer: Raymond Lu + * June 3, 2005 + * + * Modifications: + *------------------------------------------------------------------------- + */ +static herr_t +test_family_compat(void) +{ + hid_t file=(-1), fapl; + char filename[1024]; + char pathname[1024]; + char *srcdir = getenv("srcdir"); /*where the src code is located*/ + + TESTING("FAMILY file driver backward compatibility"); + +#ifndef H5_WANT_H5_V1_6_COMPAT + SKIPPED(); + return 0; +#else /*H5_WANT_H5_V1_6_COMPAT*/ + + /* Set property list and file name for FAMILY driver */ + fapl = h5_fileaccess(); + + if(H5Pset_fapl_family(fapl, (hsize_t)FAMILY_SIZE2, H5P_DEFAULT)<0) + goto error; + + h5_fixname(COMPAT_BASENAME, fapl, filename, sizeof filename); + + /* Generate correct name for test file by prepending the source path */ + if(srcdir && ((strlen(srcdir) + strlen(filename) + 1) < sizeof(pathname))) { + strcpy(pathname, srcdir); + strcat(pathname, "/"); + } + strcat(pathname, filename); + + if((file=H5Fopen(pathname, H5F_ACC_RDONLY, fapl))<0) + goto error; + + if(H5Fclose(file)<0) + goto error; + + if(H5Pclose(fapl)<0) + goto error; + + PASSED(); + return 0; + +error: + H5E_BEGIN_TRY { + H5Fclose(file); + } H5E_END_TRY; + return -1; +#endif /*H5_WANT_H5_V1_6_COMPAT*/ +} + + +/*------------------------------------------------------------------------- + * Function: test_multi_opens + * + * Purpose: Private function for test_multi() to tests wrong ways of + * reopening multi file. + * + * Return: Success: exit(0) + * + * Failure: exit(1) + * + * Programmer: Raymond Lu + * Thursday, May 19, 2005 + * + * Modifications: + *------------------------------------------------------------------------- + */ +static herr_t +test_multi_opens(char *fname, hid_t fa_pl) +{ + hid_t file; + char super_name[1024]; /*name string "%%s-s.h5"*/ + char sf_name[1024]; /*name string "multi_file-s.h5"*/ + + /* Case: reopen with the name of super file and default property list */ + sprintf(super_name, "%%s-%c.h5", 's'); + sprintf(sf_name, super_name, fname); + + H5E_BEGIN_TRY { + file=H5Fopen(sf_name, H5F_ACC_RDWR, H5P_DEFAULT); + } H5E_END_TRY; + + return 0; +} + + +/*------------------------------------------------------------------------- + * Function: test_multi + * + * Purpose: Tests the file handle interface for MUTLI driver + * + * Return: Success: exit(0) + * + * Failure: exit(1) + * + * Programmer: Raymond Lu + * Tuesday, Sept 24, 2002 + * + * Modifications: + * + * Raymond Lu + * Wednesday, June 23, 2004 + * Added test for H5Fget_filesize. + * + *------------------------------------------------------------------------- + */ +static herr_t +test_multi(void) +{ + hid_t file=(-1), fapl, fapl2=(-1), dset=(-1), space=(-1); + hid_t access_fapl = -1; + char filename[1024]; + int *fhandle2=NULL, *fhandle=NULL; + hsize_t file_size; + H5FD_mem_t mt, memb_map[H5FD_MEM_NTYPES]; + hid_t memb_fapl[H5FD_MEM_NTYPES]; + haddr_t memb_addr[H5FD_MEM_NTYPES]; + const char *memb_name[H5FD_MEM_NTYPES]; + char sv[H5FD_MEM_NTYPES][32]; + hsize_t dims[2]={MULTI_SIZE, MULTI_SIZE}; + char dname[]="dataset"; + int i, j; + int buf[MULTI_SIZE][MULTI_SIZE]; + + TESTING("MULTI file driver"); + /* Set file access property list for MULTI driver */ + fapl = h5_fileaccess(); + + HDmemset(memb_map, 0, sizeof memb_map); + HDmemset(memb_fapl, 0, sizeof memb_fapl); + HDmemset(memb_name, 0, sizeof memb_name); + HDmemset(memb_addr, 0, sizeof memb_addr); + HDmemset(sv, 0, sizeof sv); + + for(mt=H5FD_MEM_DEFAULT; mt<H5FD_MEM_NTYPES; H5_INC_ENUM(H5FD_mem_t,mt)) + memb_map[mt] = H5FD_MEM_SUPER; + memb_map[H5FD_MEM_DRAW] = H5FD_MEM_DRAW; + + memb_fapl[H5FD_MEM_SUPER] = H5P_DEFAULT; + sprintf(sv[H5FD_MEM_SUPER], "%%s-%c.h5", 's'); + memb_name[H5FD_MEM_SUPER] = sv[H5FD_MEM_SUPER]; + memb_addr[H5FD_MEM_SUPER] = 0; + + memb_fapl[H5FD_MEM_DRAW] = H5P_DEFAULT; + sprintf(sv[H5FD_MEM_DRAW], "%%s-%c.h5", 'r'); + memb_name[H5FD_MEM_DRAW] = sv[H5FD_MEM_DRAW]; + memb_addr[H5FD_MEM_DRAW] = HADDR_MAX/2; + + if(H5Pset_fapl_multi(fapl, memb_map, memb_fapl, memb_name, memb_addr, TRUE)<0) + goto error; + h5_fixname(FILENAME[3], fapl, filename, sizeof filename); + + if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0) + goto error; + + if(H5Fclose(file)<0) + goto error; + + /* Test wrong ways to reopen multi files */ + if(test_multi_opens(filename, fapl)<0) + goto error; + + /* Reopen the file */ + if((file=H5Fopen(filename, H5F_ACC_RDWR, fapl))<0) + goto error; + + /* Create and write data set */ + if((space=H5Screate_simple(2, dims, NULL))<0) + goto error; + + /* Retrieve the access property list... */ + if ((access_fapl = H5Fget_access_plist(file)) < 0) + goto error; + + /* ...and close the property list */ + if (H5Pclose(access_fapl) < 0) + goto error; + + /* Check file size API */ + if(H5Fget_filesize(file, &file_size) < 0) + goto error; + + /* Before any data is written, the raw data file is empty. So + * the file size is only the size of metadata file. It's supposed + * to be 2KB. + */ + if(file_size<1*KB || file_size>4*KB) + goto error; + + if((dset=H5Dcreate(file, dname, H5T_NATIVE_INT, space, H5P_DEFAULT))<0) + goto error; + + for(i=0; i<MULTI_SIZE; i++) + for(j=0; j<MULTI_SIZE; j++) + buf[i][j] = i*10000+j; + if(H5Dwrite(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf)<0) + goto error; + + if((fapl2=H5Pcreate(H5P_FILE_ACCESS))<0) + goto error; + if(H5Pset_multi_type(fapl2, H5FD_MEM_SUPER)<0) + goto error; + if(H5Fget_vfd_handle(file, fapl2, (void **)&fhandle)<0) + goto error; + if(*fhandle<0) + goto error; + + if(H5Pset_multi_type(fapl2, H5FD_MEM_DRAW)<0) + goto error; + if(H5Fget_vfd_handle(file, fapl2, (void **)&fhandle2)<0) + goto error; + if(*fhandle2<0) + goto error; + + /* Check file size API */ + if(H5Fget_filesize(file, &file_size) < 0) + goto error; + + /* After the data is written, the file size is huge because the + * beginning of raw data file is set at HADDR_MAX/2. It's supposed + * to be (HADDR_MAX/2 + 128*128*4) + */ + if(file_size < HADDR_MAX/2 || file_size > HADDR_MAX) + goto error; + + if(H5Sclose(space)<0) + goto error; + if(H5Dclose(dset)<0) + goto error; + if(H5Pclose(fapl2)<0) + goto error; + if(H5Fclose(file)<0) + goto error; + + h5_cleanup(FILENAME, fapl); + PASSED(); + + return 0; + +error: + H5E_BEGIN_TRY { + H5Sclose(space); + H5Dclose(dset); + H5Pclose(fapl); + H5Pclose(fapl2); + H5Fclose(file); + } H5E_END_TRY; + return -1; +} + + +/*------------------------------------------------------------------------- + * Function: main + * + * Purpose: Tests the basic features of Virtual File Drivers + * + * Return: Success: exit(0) + * + * Failure: exit(1) + * + * Programmer: Raymond Lu + * Tuesday, Sept 24, 2002 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +int +main(void) +{ + int nerrors=0; + + h5_reset(); + + nerrors += test_sec2()<0 ?1:0; + nerrors += test_core()<0 ?1:0; + nerrors += test_family()<0 ?1:0; + nerrors += test_family_compat()<0 ?1:0; + nerrors += test_multi()<0 ?1:0; + + if (nerrors){ + printf("***** %d Virtual File Driver TEST%s FAILED! *****\n", + nerrors, nerrors > 1 ? "S" : ""); + return 1; + } + + printf("All Virtual File Driver tests passed.\n"); + return 0; +} |