diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2009-10-02 02:08:59 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2009-10-02 02:08:59 (GMT) |
commit | 37ec6dc75e85ebd7f9fb9b32fe978e47ab3fe918 (patch) | |
tree | 387658306d99e60d807c2eb8b3888a12aca4a75f /test | |
parent | 006071f2338faa14f2784562279cb78b4341bce0 (diff) | |
download | hdf5-37ec6dc75e85ebd7f9fb9b32fe978e47ab3fe918.zip hdf5-37ec6dc75e85ebd7f9fb9b32fe978e47ab3fe918.tar.gz hdf5-37ec6dc75e85ebd7f9fb9b32fe978e47ab3fe918.tar.bz2 |
[svn-r17582] Description:
Bring changes from file free space branch back to the trunk. *yay!*
Tested on:
FreeBSD/32 6.3 (duty) in debug mode
FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (jam) w/PGI compilers, w/default API=1.8.x,
w/C++ & FORTRAN, w/threadsafe, in debug mode
Linux/64-amd64 2.6 (smirom) w/Intel compilers, w/default API=1.6.x,
w/C++ & FORTRAN, in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in debug mode
Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode
Mac OS X/32 10.5.8 (amazon) in debug mode
Mac OS X/32 10.5.8 (amazon) w/C++ & FORTRAN, w/threadsafe,
in production mode
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile.am | 2 | ||||
-rw-r--r-- | test/Makefile.in | 38 | ||||
-rw-r--r-- | test/filespace_1_6.h5 | bin | 0 -> 2448 bytes | |||
-rw-r--r-- | test/filespace_1_8.h5 | bin | 0 -> 2448 bytes | |||
-rw-r--r-- | test/gen_filespace.c | 81 | ||||
-rw-r--r-- | test/mf.c | 1365 | ||||
-rw-r--r-- | test/tfile.c | 705 | ||||
-rw-r--r-- | test/tmisc.c | 67 |
8 files changed, 2202 insertions, 56 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index 85409dc..d233f96 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -62,7 +62,7 @@ check_PROGRAMS=$(TEST_PROG) error_test err_compat tcheck_version testmeta # so do not appear in this list. 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 + gen_nullspace gen_udlinks space_overflow gen_filespace if BUILD_ALL_CONDITIONAL noinst_PROGRAMS=$(BUILD_ALL_PROGS) diff --git a/test/Makefile.in b/test/Makefile.in index 39fc2ef..b52c920 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -92,7 +92,7 @@ am__EXEEXT_2 = gen_bad_ohdr$(EXEEXT) gen_bogus$(EXEEXT) \ gen_new_group$(EXEEXT) gen_new_mtime$(EXEEXT) \ gen_new_super$(EXEEXT) gen_noencoder$(EXEEXT) \ gen_nullspace$(EXEEXT) gen_udlinks$(EXEEXT) \ - space_overflow$(EXEEXT) + space_overflow$(EXEEXT) gen_filespace$(EXEEXT) PROGRAMS = $(noinst_PROGRAMS) app_ref_SOURCES = app_ref.c app_ref_OBJECTS = app_ref.$(OBJEXT) @@ -210,6 +210,10 @@ gen_deflate_SOURCES = gen_deflate.c gen_deflate_OBJECTS = gen_deflate.$(OBJEXT) gen_deflate_LDADD = $(LDADD) gen_deflate_DEPENDENCIES = libh5test.la $(LIBHDF5) +gen_filespace_SOURCES = gen_filespace.c +gen_filespace_OBJECTS = gen_filespace.$(OBJEXT) +gen_filespace_LDADD = $(LDADD) +gen_filespace_DEPENDENCIES = libh5test.la $(LIBHDF5) gen_filters_SOURCES = gen_filters.c gen_filters_OBJECTS = gen_filters.$(OBJEXT) gen_filters_LDADD = $(LDADD) @@ -366,11 +370,11 @@ SOURCES = $(libh5test_la_SOURCES) app_ref.c big.c bittests.c btree2.c \ dt_arith.c dtransform.c dtypes.c earray.c enum.c err_compat.c \ error_test.c extend.c external.c farray.c fheap.c fillval.c \ flush1.c flush2.c freespace.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 mf.c mount.c \ - mtime.c ntypes.c objcopy.c ohdr.c pool.c reserved.c \ + gen_cross.c gen_deflate.c gen_filespace.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 mf.c \ + mount.c mtime.c ntypes.c objcopy.c ohdr.c pool.c reserved.c \ set_extent.c space_overflow.c stab.c tcheck_version.c \ $(testhdf5_SOURCES) testmeta.c $(ttsafe_SOURCES) unlink.c \ vfd.c @@ -379,14 +383,14 @@ DIST_SOURCES = $(libh5test_la_SOURCES) app_ref.c big.c bittests.c \ dsets.c dt_arith.c dtransform.c dtypes.c earray.c enum.c \ err_compat.c error_test.c extend.c external.c farray.c fheap.c \ fillval.c flush1.c flush2.c freespace.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 mf.c \ - mount.c mtime.c ntypes.c objcopy.c ohdr.c pool.c reserved.c \ - set_extent.c space_overflow.c stab.c tcheck_version.c \ - $(testhdf5_SOURCES) testmeta.c $(ttsafe_SOURCES) unlink.c \ - vfd.c + gen_bogus.c gen_cross.c gen_deflate.c gen_filespace.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 mf.c mount.c mtime.c ntypes.c \ + objcopy.c ohdr.c pool.c reserved.c set_extent.c \ + space_overflow.c stab.c tcheck_version.c $(testhdf5_SOURCES) \ + testmeta.c $(ttsafe_SOURCES) unlink.c vfd.c ETAGS = etags CTAGS = ctags am__tty_colors = \ @@ -701,7 +705,7 @@ TEST_PROG = testhdf5 lheap ohdr stab gheap cache cache_api \ # so do not appear in this list. 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 + gen_nullspace gen_udlinks space_overflow gen_filespace # The libh5test library provides common support code for the tests. @@ -899,6 +903,9 @@ gen_cross$(EXEEXT): $(gen_cross_OBJECTS) $(gen_cross_DEPENDENCIES) gen_deflate$(EXEEXT): $(gen_deflate_OBJECTS) $(gen_deflate_DEPENDENCIES) @rm -f gen_deflate$(EXEEXT) $(LINK) $(gen_deflate_OBJECTS) $(gen_deflate_LDADD) $(LIBS) +gen_filespace$(EXEEXT): $(gen_filespace_OBJECTS) $(gen_filespace_DEPENDENCIES) + @rm -f gen_filespace$(EXEEXT) + $(LINK) $(gen_filespace_OBJECTS) $(gen_filespace_LDADD) $(LIBS) gen_filters$(EXEEXT): $(gen_filters_OBJECTS) $(gen_filters_DEPENDENCIES) @rm -f gen_filters$(EXEEXT) $(LINK) $(gen_filters_OBJECTS) $(gen_filters_LDADD) $(LIBS) @@ -1032,6 +1039,7 @@ distclean-compile: @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@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gen_filespace.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gen_filters.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gen_new_array.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gen_new_fill.Po@am__quote@ diff --git a/test/filespace_1_6.h5 b/test/filespace_1_6.h5 Binary files differnew file mode 100644 index 0000000..5afc718 --- /dev/null +++ b/test/filespace_1_6.h5 diff --git a/test/filespace_1_8.h5 b/test/filespace_1_8.h5 Binary files differnew file mode 100644 index 0000000..85138b0 --- /dev/null +++ b/test/filespace_1_8.h5 diff --git a/test/gen_filespace.c b/test/gen_filespace.c new file mode 100644 index 0000000..e9dee1c --- /dev/null +++ b/test/gen_filespace.c @@ -0,0 +1,81 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * 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. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "hdf5.h" + +#define NELMTS(X) (sizeof(X)/sizeof(X[0])) /* # of elements */ +#define TEST_THRESHOLD2 2 /* Free space section threshold */ + +const char *FILENAMES[] = { + "filespace_persist.h5", /* H5F_FILE_SPACE_ALL_PERSIST */ + "filespace_default.h5", /* H5F_FILE_SPACE_ALL */ + "filespace_aggr_vfd.h5", /* H5F_FILE_SPACE_AGGR_VFD */ + "filespace_vfd.h5", /* H5F_FILE_SPACE_VFD */ + "filespace_threshold.h5" /* H5F_FILE_SPACE_ALL, non-default threshold */ +}; + +#define DATASET "dset" +#define NUM_ELMTS 100 + +/* + * Compile and run this program in file-space branch to generate + * HDF5 files with different kinds of file space strategies + * Move the HDF5 files to the 1.6 and 1.8 branch for compatibility + * testing:test_filespace_compatible() will use the files + */ +static void gen_file(void) +{ + hid_t fid; + hid_t fcpl; + hid_t dataset, space; + hsize_t dim[1]; + int data[NUM_ELMTS]; + unsigned i, j; /* Local index variable */ + H5F_file_space_type_t fs_type; /* File space handling strategy */ + + for(j = 0, fs_type = H5F_FILE_SPACE_ALL_PERSIST; j < NELMTS(FILENAMES); j++, (H5F_file_space_type_t)(fs_type)++) { + /* Get a copy of the default file creation property */ + fcpl = H5Pcreate(H5P_FILE_CREATE); + + if(fs_type == H5F_FILE_SPACE_NTYPES) /* last file */ + /* Set default strategy but non-default threshold */ + H5Pset_file_space(fcpl, H5F_FILE_SPACE_ALL, (hsize_t)TEST_THRESHOLD2); + else + /* Set specified file space strategy and free space section threshold */ + H5Pset_file_space(fcpl, fs_type, (hsize_t)0); + + /* Create the file with the file space info */ + fid = H5Fcreate(FILENAMES[j], H5F_ACC_TRUNC, fcpl, H5P_DEFAULT); + + dim[0] = NUM_ELMTS; + space = H5Screate_simple(1, dim, NULL); + dataset = H5Dcreate2(fid, DATASET, H5T_NATIVE_INT, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + + for(i = 0; i < NUM_ELMTS; i++) + data[i] = i; + + H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data); + H5Dclose(dataset); + H5Sclose(space); + H5Fclose(fid); + } +} + +int main(void) +{ + gen_file(); + + return 0; +} @@ -19,6 +19,7 @@ * test_mf_fs_*() tests for file memory that interact with the free-space manager * test_mf_aggr_*() tests for file memory that interact with the aggregators * test_mf_align_*() tests for file memory with alignment setting + * test_filespace_*() tests for file space management */ #include "h5test.h" @@ -39,7 +40,14 @@ #define FILENAME_LEN 1024 +#define TEST_BLOCK_SIZE1 1 +#define TEST_BLOCK_SIZE2 2 +#define TEST_BLOCK_SIZE3 3 +#define TEST_BLOCK_SIZE4 4 #define TEST_BLOCK_SIZE5 5 +#define TEST_BLOCK_SIZE6 6 +#define TEST_BLOCK_SIZE7 7 +#define TEST_BLOCK_SIZE8 8 #define TEST_BLOCK_SIZE20 20 #define TEST_BLOCK_SIZE30 30 #define TEST_BLOCK_SIZE40 40 @@ -60,6 +68,12 @@ #define TEST_ALIGN1024 1024 #define TEST_ALIGN4096 4096 +#define TEST_THRESHOLD10 10 +#define TEST_THRESHOLD3 3 + +#define CORE_INCREMENT 1024 +#define FAMILY_SIZE 1024 + const char *FILENAME[] = { "mf", NULL @@ -105,6 +119,11 @@ static unsigned test_mf_align_alloc3(const char *env_h5_drvr, hid_t fapl, hid_t static unsigned test_mf_align_alloc4(const char *env_h5_drvr, hid_t fapl, hid_t new_fapl); static unsigned test_mf_align_alloc5(const char *env_h5_drvr, hid_t fapl, hid_t new_fapl); static unsigned test_mf_align_alloc6(const char *env_h5_drvr, hid_t fapl, hid_t new_fapl); +static unsigned test_mf_fs_persist(hid_t fapl_new, hid_t fcpl); +static unsigned test_mf_fs_gone(hid_t fapl_new, hid_t fcpl); +static unsigned test_mf_fs_split(hid_t fapl_new, hid_t fcpl); +static unsigned test_mf_fs_multi(hid_t fapl, hid_t fcpl); +static unsigned test_mf_fs_drivers(hid_t fapl); /* * Verify statistics for the free-space manager @@ -5846,6 +5865,1345 @@ error: } /* test_mf_align_alloc6() */ +/* + * Verify that the file's free-space manager persists where there are free sections in the manager + */ +static unsigned +test_mf_fs_persist(hid_t fapl_new, hid_t fcpl) +{ + hid_t file = -1; /* File ID */ + char filename[FILENAME_LEN]; /* Filename to use */ + H5F_t *f = NULL; /* Internal file object pointer */ + H5FD_mem_t type; /* File allocation type */ + H5FS_stat_t fs_stat; /* Information for free-space manager */ + haddr_t addr1, addr2, addr3, addr4, addr5, addr6; /* File address for H5FD_MEM_SUPER */ + haddr_t tmp_addr; /* Temporary variable for address */ + + TESTING("file's free-space manager is persistent"); + + /* Set the filename to use for this test (dependent on fapl) */ + h5_fixname(FILENAME[0], fapl_new, filename, sizeof(filename)); + + /* Create the file to work on */ + if((file = H5Fcreate(filename, H5F_ACC_TRUNC, fcpl, fapl_new)) < 0) + FAIL_STACK_ERROR + + /* Get a pointer to the internal file object */ + if(NULL == (f = (H5F_t *)H5I_object(file))) + FAIL_STACK_ERROR + + /* Allocate 6 blocks */ + type = H5FD_MEM_SUPER; + if(HADDR_UNDEF == (addr1 = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE1))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (addr2 = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE2))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (addr3 = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE3))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (addr4 = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE4))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (addr5 = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE5))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (addr6 = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE6))) + FAIL_STACK_ERROR + + /* Put block #1, #3, #5 to H5FD_MEM_SUPER free-space manager */ + if(H5MF_xfree(f, type, H5P_DATASET_XFER_DEFAULT, addr1, (hsize_t)TEST_BLOCK_SIZE1) < 0) + FAIL_STACK_ERROR + if(H5MF_xfree(f, type, H5P_DATASET_XFER_DEFAULT, addr3, (hsize_t)TEST_BLOCK_SIZE3) < 0) + FAIL_STACK_ERROR + if(H5MF_xfree(f, type, H5P_DATASET_XFER_DEFAULT, addr5, (hsize_t)TEST_BLOCK_SIZE5) < 0) + FAIL_STACK_ERROR + + if(H5Fclose(file) < 0) + FAIL_STACK_ERROR + + /* Re-open the file */ + if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl_new)) < 0) + FAIL_STACK_ERROR + + /* Get a pointer to the internal file object */ + if(NULL == (f = (H5F_t *)H5I_object(file))) + FAIL_STACK_ERROR + + /* Verify that H5FD_MEM_SUPER free-space manager is there */ + if(!H5F_addr_defined(f->shared->fs_addr[type])) + TEST_ERROR + + /* Start up H5FD_MEM_SUPER free-space manager */ + if(H5MF_alloc_open(f, H5P_DATASET_XFER_DEFAULT, type) < 0) + FAIL_STACK_ERROR + + /* Get info for free-space manager */ + if(H5FS_stat_info(f, f->shared->fs_man[type], &fs_stat) < 0) + FAIL_STACK_ERROR + + /* Verify free-space info */ + if(fs_stat.tot_space < (TEST_BLOCK_SIZE1+TEST_BLOCK_SIZE3+TEST_BLOCK_SIZE5)) + TEST_ERROR + + if(fs_stat.serial_sect_count < 3) + TEST_ERROR + + /* Retrieve block #3 from H5FD_MEM_SUPER free-space manager */ + if(HADDR_UNDEF == (tmp_addr = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE3))) + FAIL_STACK_ERROR + if(tmp_addr != addr3) + TEST_ERROR + + /* Retrieve block #1 from H5FD_MEM_SUPER free-space manager */ + if(HADDR_UNDEF == (tmp_addr = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE1))) + FAIL_STACK_ERROR + if(tmp_addr != addr1) + TEST_ERROR + + if(H5Fclose(file) < 0) + FAIL_STACK_ERROR + + /* Re-open the file */ + if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl_new)) < 0) + FAIL_STACK_ERROR + + /* Get a pointer to the internal file object */ + if(NULL == (f = (H5F_t *)H5I_object(file))) + FAIL_STACK_ERROR + + /* Verify that H5FD_MEM_SUPER free-space manager is there */ + if(!H5F_addr_defined(f->shared->fs_addr[type])) + TEST_ERROR + + /* Retrieve block #5 from H5FD_MEM_SUPER free-space manager */ + if(HADDR_UNDEF == (tmp_addr = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE5))) + FAIL_STACK_ERROR + if(tmp_addr != addr5) + TEST_ERROR + + if(H5Fclose(file) < 0) + FAIL_STACK_ERROR + + PASSED() + + return(0); + +error: + H5E_BEGIN_TRY { + H5Fclose(file); + } H5E_END_TRY; + return(1); +} /* test_mf_fs_persist() */ + +/* + * Verify that the free-space manager goes away + */ +static unsigned +test_mf_fs_gone(hid_t fapl_new, hid_t fcpl) +{ + hid_t file = -1; /* File ID */ + char filename[FILENAME_LEN]; /* Filename to use */ + H5F_t *f = NULL; /* Internal file object pointer */ + H5FD_mem_t type; /* File allocation type */ + H5FS_stat_t fs_stat; /* Information for free-space manager */ + haddr_t addr1, addr2, addr3, addr4; /* File address for H5FD_MEM_SUPER */ + + TESTING("file's free-space manager is going away"); + + /* Set the filename to use for this test (dependent on fapl) */ + h5_fixname(FILENAME[0], fapl_new, filename, sizeof(filename)); + + /* Create the file to work on */ + if((file = H5Fcreate(filename, H5F_ACC_TRUNC, fcpl, fapl_new)) < 0) + FAIL_STACK_ERROR + + /* Get a pointer to the internal file object */ + if(NULL == (f = (H5F_t *)H5I_object(file))) + FAIL_STACK_ERROR + + /* Allocate 4 blocks */ + type = H5FD_MEM_SUPER; + if(HADDR_UNDEF == (addr1 = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE1))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (addr2 = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE2))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (addr3 = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE3))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (addr4 = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE4))) + FAIL_STACK_ERROR + + /* Put block #1, #3 to H5FD_MEM_SUPER free-space manager */ + if(H5MF_xfree(f, type, H5P_DATASET_XFER_DEFAULT, addr1, (hsize_t)TEST_BLOCK_SIZE1) < 0) + FAIL_STACK_ERROR + if(H5MF_xfree(f, type, H5P_DATASET_XFER_DEFAULT, addr3, (hsize_t)TEST_BLOCK_SIZE3) < 0) + FAIL_STACK_ERROR + + /* Retrieve block #1, #3 from H5FD_MEM_SUPER free-space manager */ + if(HADDR_UNDEF == (addr3 = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE3))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (addr1 = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE1))) + FAIL_STACK_ERROR + + if(H5Fclose(file) < 0) + FAIL_STACK_ERROR + + /* Re-open the file */ + if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl_new)) < 0) + FAIL_STACK_ERROR + + /* Get a pointer to the internal file object */ + if(NULL == (f = (H5F_t *)H5I_object(file))) + FAIL_STACK_ERROR + + /* Verify that the H5FD_MEM_SUPER free-space manager is not there */ + if(H5F_addr_defined(f->shared->fs_addr[type])) + TEST_ERROR + + /* Put block #3 to H5FD_MEM_SUPER free-space manager */ + if(H5MF_xfree(f, type, H5P_DATASET_XFER_DEFAULT, addr3, (hsize_t)TEST_BLOCK_SIZE3) < 0) + FAIL_STACK_ERROR + + if(H5Fclose(file) < 0) + FAIL_STACK_ERROR + + /* Re-open the file */ + if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl_new)) < 0) + FAIL_STACK_ERROR + + /* Get a pointer to the internal file object */ + if(NULL == (f = (H5F_t *)H5I_object(file))) + FAIL_STACK_ERROR + + /* Verify that H5FD_MEM_SUPER free-space manager is there */ + if(!H5F_addr_defined(f->shared->fs_addr[type])) + TEST_ERROR + + /* Start up H5FD_MEM_SUPER free-space manager */ + if(H5MF_alloc_open(f, H5P_DATASET_XFER_DEFAULT, type) < 0) + FAIL_STACK_ERROR + + /* Get info for H5FD_MEM_SUPER free-space manager */ + if(H5FS_stat_info(f, f->shared->fs_man[type], &fs_stat) < 0) + FAIL_STACK_ERROR + + /* Verify free-space info */ + if(!H5F_addr_defined(fs_stat.addr) || !H5F_addr_defined(fs_stat.sect_addr)) + TEST_ERROR + if(fs_stat.tot_space < TEST_BLOCK_SIZE3) + TEST_ERROR + + /* Put block #4 to H5FD_MEM_SUPER free-space manager */ + if(H5MF_xfree(f, type, H5P_DATASET_XFER_DEFAULT, addr4, (hsize_t)TEST_BLOCK_SIZE4) < 0) + FAIL_STACK_ERROR + + /* The H5FD_MEM_SUPER free-space manager will go away at H5MF_close() */ + if(H5Fclose(file) < 0) + FAIL_STACK_ERROR + + /* Re-open the file */ + if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl_new)) < 0) + FAIL_STACK_ERROR + + /* Get a pointer to the internal file object */ + if(NULL == (f = (H5F_t *)H5I_object(file))) + FAIL_STACK_ERROR + + /* Verify that the H5FD_MEM_SUPER free-space manager is not there */ + if(H5F_addr_defined(f->shared->fs_addr[type])) + TEST_ERROR + + if(H5Fclose(file) < 0) + FAIL_STACK_ERROR + + PASSED() + + return(0); + +error: + H5E_BEGIN_TRY { + H5Fclose(file); + } H5E_END_TRY; + return(1); +} /* test_mf_fs_gone() */ + + +/* + * Verify that the file's free-space manager(s) are persistent for a split-file + */ +static unsigned +test_mf_fs_split(hid_t fapl_new, hid_t fcpl) +{ + hid_t file = -1; /* File ID */ + char filename[FILENAME_LEN]; /* Filename to use */ + H5F_t *f = NULL; /* Internal file object pointer */ + H5FD_mem_t type, stype, btype; /* File allocation type */ + H5FS_stat_t fs_stat; /* Information for free-space manager */ + haddr_t addr1, addr2, addr3, addr4; /* File address for H5FD_MEM_SUPER */ + haddr_t saddr1, saddr2, saddr3, saddr4; /* File address for H5FD_MEM_DRAW */ + haddr_t baddr5, baddr6, baddr7, baddr8; /* File address for H5FD_MEM_BTREE */ + haddr_t tmp_addr; /* temporary variable for address */ + + TESTING("file's free-space managers are persistent for split-file"); + + /* Set the filename to use for this test (dependent on fapl) */ + h5_fixname(FILENAME[0], fapl_new, filename, sizeof(filename)); + + /* Create the file to work on */ + if((file = H5Fcreate(filename, H5F_ACC_TRUNC, fcpl, fapl_new)) < 0) + FAIL_STACK_ERROR + + /* Get a pointer to the internal file object */ + if(NULL == (f = (H5F_t *)H5I_object(file))) + FAIL_STACK_ERROR + + /* Allocate 4 blocks of type H5FD_MEM_SUPER */ + type = H5FD_MEM_SUPER; + if(HADDR_UNDEF == (addr1 = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE1))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (addr2 = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE2))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (addr3 = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE3))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (addr4 = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE4))) + FAIL_STACK_ERROR + + /* Put block #1, #3 into H5FD_MEM_SUPER free-space manager */ + if(H5MF_xfree(f, type, H5P_DATASET_XFER_DEFAULT, addr1, (hsize_t)TEST_BLOCK_SIZE1) < 0) + FAIL_STACK_ERROR + if(H5MF_xfree(f, type, H5P_DATASET_XFER_DEFAULT, addr3, (hsize_t)TEST_BLOCK_SIZE3) < 0) + FAIL_STACK_ERROR + + /* Allocate 4 blocks of type H5FD_MEM_DRAW */ + stype = H5FD_MEM_DRAW; + if(HADDR_UNDEF == (saddr1 = H5MF_alloc(f, stype, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE1))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (saddr2 = H5MF_alloc(f, stype, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE2))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (saddr3 = H5MF_alloc(f, stype, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE3))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (saddr4 = H5MF_alloc(f, stype, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE4))) + FAIL_STACK_ERROR + + /* Put block #1, #3 into H5FD_MEM_DRAW free-space manager */ + if(H5MF_xfree(f, stype, H5P_DATASET_XFER_DEFAULT, saddr1, (hsize_t)TEST_BLOCK_SIZE1) < 0) + FAIL_STACK_ERROR + if(H5MF_xfree(f, stype, H5P_DATASET_XFER_DEFAULT, saddr3, (hsize_t)TEST_BLOCK_SIZE3) < 0) + FAIL_STACK_ERROR + + if(H5Fclose(file) < 0) + FAIL_STACK_ERROR + + /* Re-open the file */ + if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl_new)) < 0) + FAIL_STACK_ERROR + + /* Get a pointer to the internal file object */ + if(NULL == (f = (H5F_t *)H5I_object(file))) + FAIL_STACK_ERROR + + /* Verify that the H5FD_MEM_SUPER free-space manager is there */ + if(!H5F_addr_defined(f->shared->fs_addr[type])) + TEST_ERROR + + /* Start up H5FD_MEM_SUPER free-space manager */ + if(H5MF_alloc_open(f, H5P_DATASET_XFER_DEFAULT, type) < 0) + FAIL_STACK_ERROR + + /* Get free-space info */ + if(H5FS_stat_info(f, f->shared->fs_man[type], &fs_stat) < 0) + FAIL_STACK_ERROR + + /* Verify free-space info */ + if(fs_stat.tot_space < (TEST_BLOCK_SIZE1+TEST_BLOCK_SIZE3)) + TEST_ERROR + if(fs_stat.serial_sect_count < 2) + TEST_ERROR + + /* Retrieve block #1 from H5FD_MEM_SUPER free-space manager; block #2 still in free-space */ + if(HADDR_UNDEF == (tmp_addr = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE1))) + FAIL_STACK_ERROR + if(tmp_addr != addr1) + TEST_ERROR + + /* Verify that the free-space manager for H5FD_MEM_DRAW is there */ + if(!H5F_addr_defined(f->shared->fs_addr[stype])) + TEST_ERROR + + /* Start up H5FD_MEM_DRAW free-space manager */ + if(H5MF_alloc_open(f, H5P_DATASET_XFER_DEFAULT, stype) < 0) + FAIL_STACK_ERROR + + /* Get free-space info */ + if(H5FS_stat_info(f, f->shared->fs_man[stype], &fs_stat) < 0) + FAIL_STACK_ERROR + + /* Verify free-space info */ + if(fs_stat.tot_space < (TEST_BLOCK_SIZE1+TEST_BLOCK_SIZE3)) + TEST_ERROR + if(fs_stat.serial_sect_count < 2) + TEST_ERROR + + /* Retrieve blocks #1 from H5FD_MEM_DRAW free-space manager */ + if(HADDR_UNDEF == (tmp_addr = H5MF_alloc(f, stype, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE1))) + FAIL_STACK_ERROR + if(tmp_addr != saddr1) + TEST_ERROR + + /* Retrieve blocks #3 from H5FD_MEM_DRAW free-space manager */ + if(HADDR_UNDEF == (tmp_addr = H5MF_alloc(f, stype, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE3))) + FAIL_STACK_ERROR + if(tmp_addr != saddr3) + TEST_ERROR + /* H5FD_MEM_DRAW free-space manager is going away at closing */ + /* works for this one because the freeing of sect_addr is to H5FD_MEM_SUPER fs, not against itself */ + + /* Allocate 4 blocks of type H5FD_MEM_BTREE */ + btype = H5FD_MEM_BTREE; + if(HADDR_UNDEF == (baddr5 = H5MF_alloc(f, btype, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE5))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (baddr6 = H5MF_alloc(f, btype, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE6))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (baddr7 = H5MF_alloc(f, btype, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE7))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (baddr8 = H5MF_alloc(f, btype, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE8))) + FAIL_STACK_ERROR + + /* Put block #5 & #7 into H5FD_MEM_BTREE free-space manager */ + if(H5MF_xfree(f, btype, H5P_DATASET_XFER_DEFAULT, baddr5, (hsize_t)TEST_BLOCK_SIZE5) < 0) + FAIL_STACK_ERROR + if(H5MF_xfree(f, btype, H5P_DATASET_XFER_DEFAULT, baddr7, (hsize_t)TEST_BLOCK_SIZE7) < 0) + FAIL_STACK_ERROR + + if(H5Fclose(file) < 0) + FAIL_STACK_ERROR + + /* Re-open the file */ + if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl_new)) < 0) + FAIL_STACK_ERROR + + /* Get a pointer to the internal file object */ + if(NULL == (f = (H5F_t *)H5I_object(file))) + FAIL_STACK_ERROR + + /* Verify that the free-space manager for H5FD_MEM_DRAW is not there */ + if(H5F_addr_defined(f->shared->fs_addr[stype])) + TEST_ERROR + + /* Verify that the free-space manager for H5FD_MEM_SUPER is there */ + if(!H5F_addr_defined(f->shared->fs_addr[type])) + TEST_ERROR + + /* Start up H5FD_MEM_SUPER free-space manager */ + if(H5MF_alloc_open(f, H5P_DATASET_XFER_DEFAULT, type) < 0) + FAIL_STACK_ERROR + + /* Get free-space info */ + if(H5FS_stat_info(f, f->shared->fs_man[type], &fs_stat) < 0) + FAIL_STACK_ERROR + + /* Verify free-space info */ + if(fs_stat.tot_space < (TEST_BLOCK_SIZE3+TEST_BLOCK_SIZE5+TEST_BLOCK_SIZE7)) + TEST_ERROR + + /* Retrieve block #3 from H5FD_MEM_SUPER free-space manager */ + if(HADDR_UNDEF == (tmp_addr = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE3))) + FAIL_STACK_ERROR + if(tmp_addr != addr3) + TEST_ERROR + + /* Retrieve block #7 from H5FD_MEM_BTREE free-space manager */ + if(HADDR_UNDEF == (tmp_addr = H5MF_alloc(f, btype, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE7))) + FAIL_STACK_ERROR + if(tmp_addr != baddr7) + TEST_ERROR + + /* There should still be block #5 of H5FD_MEM_BTREE in H5FD_MEM_BTREE free-space manager */ + if(H5Fclose(file) < 0) + FAIL_STACK_ERROR + + /* Re-open the file */ + if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl_new)) < 0) + FAIL_STACK_ERROR + + /* Get a pointer to the internal file object */ + if(NULL == (f = (H5F_t *)H5I_object(file))) + FAIL_STACK_ERROR + + /* Verify that the H5FD_MEM_SUPER free-space manager is there */ + if(!H5F_addr_defined(f->shared->fs_addr[type])) + TEST_ERROR + + /* Start up H5FD_MEM_SUPER free-space manager */ + if(H5MF_alloc_open(f, H5P_DATASET_XFER_DEFAULT, type) < 0) + FAIL_STACK_ERROR + + /* Get free-space info */ + if(H5FS_stat_info(f, f->shared->fs_man[type], &fs_stat) < 0) + FAIL_STACK_ERROR + + /* Verify free-space info */ + if(fs_stat.tot_space < TEST_BLOCK_SIZE5) + TEST_ERROR + + if(H5Fclose(file) < 0) + FAIL_STACK_ERROR + + PASSED() + + return(0); + +error: + H5E_BEGIN_TRY { + H5Fclose(file); + } H5E_END_TRY; + return(1); +} /* test_mf_fs_split() */ + +/* + * Verify that the file's free-space manager(s) are persistent for a multi-file + */ +static unsigned +test_mf_fs_multi(hid_t fapl_new, hid_t fcpl) +{ + hid_t file = -1; /* File ID */ + char filename[FILENAME_LEN]; /* Filename to use */ + H5F_t *f = NULL; /* Internal file object pointer */ + H5FD_mem_t type, stype, btype, gtype; /* File allocation type */ + H5FS_stat_t fs_stat; /* Information for free-space manager */ + haddr_t addr1, addr2, addr3, addr4; /* File allocation type */ + haddr_t saddr1, saddr2, saddr3, saddr4; /* File address for H5FD_MEM_SUPER */ + haddr_t baddr1, baddr2, baddr3, baddr4; /* File address for H5FD_MEM_DRAW */ + haddr_t gaddr1, gaddr2; /* File address for H5FD_MEM_GHEAP */ + haddr_t tmp_addr; /* Temporary variable for address */ + H5FS_section_info_t *node; /* Free space section node */ + htri_t node_found = FALSE; /* Indicate section is in free-space */ + + TESTING("file's free-space managers are persistent for multi-file"); + + /* Set the filename to use for this test (dependent on fapl) */ + h5_fixname(FILENAME[0], fapl_new, filename, sizeof(filename)); + + /* Create the file to work on */ + if((file = H5Fcreate(filename, H5F_ACC_TRUNC, fcpl, fapl_new)) < 0) + FAIL_STACK_ERROR + + /* Get a pointer to the internal file object */ + if(NULL == (f = (H5F_t *)H5I_object(file))) + FAIL_STACK_ERROR + + /* Allocate 4 blocks of type H5FD_MEM_SUPER */ + type = H5FD_MEM_SUPER; + if(HADDR_UNDEF == (addr1 = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE1))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (addr2 = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE2))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (addr3 = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE3))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (addr4 = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE4))) + FAIL_STACK_ERROR + + /* Put block #1, #3 into H5FD_MEM_SUPER free-space manager */ + if(H5MF_xfree(f, type, H5P_DATASET_XFER_DEFAULT, addr1, (hsize_t)TEST_BLOCK_SIZE1) < 0) + FAIL_STACK_ERROR + if(H5MF_xfree(f, type, H5P_DATASET_XFER_DEFAULT, addr3, (hsize_t)TEST_BLOCK_SIZE3) < 0) + FAIL_STACK_ERROR + + /* Allocate 4 blocks of type H5FD_MEM_DRAW */ + stype = H5FD_MEM_DRAW; + if(HADDR_UNDEF == (saddr1 = H5MF_alloc(f, stype, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE1))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (saddr2 = H5MF_alloc(f, stype, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE2))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (saddr3 = H5MF_alloc(f, stype, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE3))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (saddr4 = H5MF_alloc(f, stype, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE4))) + FAIL_STACK_ERROR + + /* Put block #1, #3 into H5FD_MEM_DRAW free-space manager */ + if(H5MF_xfree(f, stype, H5P_DATASET_XFER_DEFAULT, saddr1, (hsize_t)TEST_BLOCK_SIZE1) < 0) + FAIL_STACK_ERROR + if(H5MF_xfree(f, stype, H5P_DATASET_XFER_DEFAULT, saddr3, (hsize_t)TEST_BLOCK_SIZE3) < 0) + FAIL_STACK_ERROR + + if(H5Fclose(file) < 0) + FAIL_STACK_ERROR + + /* Re-open the file */ + if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl_new)) < 0) + FAIL_STACK_ERROR + + /* Get a pointer to the internal file object */ + if(NULL == (f = (H5F_t *)H5I_object(file))) + FAIL_STACK_ERROR + + /* Verify that the H5FD_MEM_SUPER free-space manager is there */ + if(!H5F_addr_defined(f->shared->fs_addr[type])) + TEST_ERROR + + /* Start up H5FD_MEM_SUPER free-space manager */ + if(H5MF_alloc_open(f, H5P_DATASET_XFER_DEFAULT, type) < 0) + FAIL_STACK_ERROR + + /* Get free-space info */ + if(H5FS_stat_info(f, f->shared->fs_man[type], &fs_stat) < 0) + FAIL_STACK_ERROR + + /* Verify free-space info */ + if(fs_stat.tot_space < (TEST_BLOCK_SIZE1+TEST_BLOCK_SIZE3)) + TEST_ERROR + if(fs_stat.serial_sect_count < 2) + TEST_ERROR + + /* Retrieve block #1 from H5FD_MEM_SUPER free-space manager; block #2 still in free-space */ + if(HADDR_UNDEF == (tmp_addr = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE1))) + FAIL_STACK_ERROR + if(tmp_addr != addr1) + TEST_ERROR + + /* Verify that the free-space manager for H5FD_MEM_DRAW is there */ + if(!H5F_addr_defined(f->shared->fs_addr[stype])) + TEST_ERROR + + /* Start up H5FD_MEM_DRAW free-space manager */ + if(H5MF_alloc_open(f, H5P_DATASET_XFER_DEFAULT, stype) < 0) + FAIL_STACK_ERROR + + /* Get free-space info */ + if(H5FS_stat_info(f, f->shared->fs_man[stype], &fs_stat) < 0) + FAIL_STACK_ERROR + + /* Verify free-space info */ + if(fs_stat.tot_space < (TEST_BLOCK_SIZE1+TEST_BLOCK_SIZE3)) + TEST_ERROR + if(fs_stat.serial_sect_count < 2) + TEST_ERROR + + /* Retrieve blocks #1 from H5FD_MEM_DRAW free-space manager */ + if(HADDR_UNDEF == (tmp_addr = H5MF_alloc(f, stype, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE1))) + FAIL_STACK_ERROR + if(tmp_addr != saddr1) + TEST_ERROR + + /* Retrieve blocks #3 from H5FD_MEM_DRAW free-space manager */ + if(HADDR_UNDEF == (tmp_addr = H5MF_alloc(f, stype, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE3))) + FAIL_STACK_ERROR + if(tmp_addr != saddr3) + TEST_ERROR + + /* Allocate 4 blocks of type H5FD_MEM_BTREE */ + btype = H5FD_MEM_BTREE; + if(HADDR_UNDEF == (baddr1 = H5MF_alloc(f, btype, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE1))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (baddr2 = H5MF_alloc(f, btype, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE2))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (baddr3 = H5MF_alloc(f, btype, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE3))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (baddr4 = H5MF_alloc(f, btype, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE4))) + FAIL_STACK_ERROR + + /* Put block #1 & #3 into H5FD_MEM_BTREE free-space manager */ + if(H5MF_xfree(f, btype, H5P_DATASET_XFER_DEFAULT, baddr1, (hsize_t)TEST_BLOCK_SIZE1) < 0) + FAIL_STACK_ERROR + if(H5MF_xfree(f, btype, H5P_DATASET_XFER_DEFAULT, baddr3, (hsize_t)TEST_BLOCK_SIZE3) < 0) + FAIL_STACK_ERROR + + if(H5Fclose(file) < 0) + FAIL_STACK_ERROR + + /* Re-open the file */ + if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl_new)) < 0) + FAIL_STACK_ERROR + + /* Get a pointer to the internal file object */ + if(NULL == (f = (H5F_t *)H5I_object(file))) + FAIL_STACK_ERROR + + /* Verify that the free-space manager for H5FD_MEM_SUPER is there */ + if(!H5F_addr_defined(f->shared->fs_addr[type])) + TEST_ERROR + + /* Start up H5FD_MEM_SUPER free-space manager */ + if(H5MF_alloc_open(f, H5P_DATASET_XFER_DEFAULT, type) < 0) + FAIL_STACK_ERROR + + /* Get free-space info */ + if(H5FS_stat_info(f, f->shared->fs_man[type], &fs_stat) < 0) + FAIL_STACK_ERROR + + /* Verify free-space info */ + if(fs_stat.tot_space < TEST_BLOCK_SIZE3) + TEST_ERROR + + /* Retrieve block #3 from H5FD_MEM_SUPER free-space manager */ + if(HADDR_UNDEF == (tmp_addr = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE3))) + FAIL_STACK_ERROR + if(tmp_addr != addr3) + TEST_ERROR + + /* Verify that the free-space manager for H5FD_MEM_DRAW is not there */ + if(H5F_addr_defined(f->shared->fs_addr[stype])) + TEST_ERROR + + /* Verify that the free-space manager for H5FD_MEM_BTREE is there */ + if(!H5F_addr_defined(f->shared->fs_addr[btype])) + TEST_ERROR + + /* Start up H5FD_MEM_BTREE free-space manager */ + if(H5MF_alloc_open(f, H5P_DATASET_XFER_DEFAULT, btype) < 0) + FAIL_STACK_ERROR + + /* Get free-space info */ + if(H5FS_stat_info(f, f->shared->fs_man[btype], &fs_stat) < 0) + FAIL_STACK_ERROR + + /* Verify free-space info */ + if(fs_stat.tot_space < (TEST_BLOCK_SIZE1+TEST_BLOCK_SIZE3)) + TEST_ERROR + if(fs_stat.serial_sect_count < 2) + TEST_ERROR + + /* Allocate 2 blocks of type H5FD_MEM_GHEAP */ + gtype = H5FD_MEM_GHEAP; + if(HADDR_UNDEF == (gaddr2 = H5MF_alloc(f, gtype, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE2))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (gaddr1 = H5MF_alloc(f, gtype, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE1))) + FAIL_STACK_ERROR + + /* Put block #2 into H5FD_MEM_GHEAP free-space manager */ + if(H5MF_xfree(f, gtype, H5P_DATASET_XFER_DEFAULT, gaddr2, (hsize_t)TEST_BLOCK_SIZE2) < 0) + FAIL_STACK_ERROR + + if(H5Fclose(file) < 0) + FAIL_STACK_ERROR + + /* Re-open the file */ + if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl_new)) < 0) + FAIL_STACK_ERROR + + /* Get a pointer to the internal file object */ + if(NULL == (f = (H5F_t *)H5I_object(file))) + FAIL_STACK_ERROR + + /* If H5FD_MEM_SUPER is there, should not find block #1 & #3 */ + if(H5F_addr_defined(f->shared->fs_addr[type])) { + /* Start up H5FD_MEM_SUPER free-space manager */ + if(H5MF_alloc_open(f, H5P_DATASET_XFER_DEFAULT, type) < 0) + FAIL_STACK_ERROR + + if((node_found = H5FS_sect_find(f, H5P_DATASET_XFER_DEFAULT, f->shared->fs_man[type], + (hsize_t)TEST_BLOCK_SIZE1, (H5FS_section_info_t **)&node)) < 0) + FAIL_STACK_ERROR + if(node_found) TEST_ERROR + + if((node_found = H5FS_sect_find(f, H5P_DATASET_XFER_DEFAULT, f->shared->fs_man[type], + (hsize_t)TEST_BLOCK_SIZE3, (H5FS_section_info_t **)&node)) < 0) + FAIL_STACK_ERROR + if(node_found) TEST_ERROR + } + + /* Verify that the H5FD_MEM_GHEAP free-space manager is there */ + if(!H5F_addr_defined(f->shared->fs_addr[gtype])) + TEST_ERROR + + /* Start up H5FD_MEM_GHEAP free-space manager */ + if(H5MF_alloc_open(f, H5P_DATASET_XFER_DEFAULT, gtype) < 0) + FAIL_STACK_ERROR + + /* Get free-space info */ + if(H5FS_stat_info(f, f->shared->fs_man[gtype], &fs_stat) < 0) + FAIL_STACK_ERROR + + /* Verify free-space info */ + if(fs_stat.tot_space < TEST_BLOCK_SIZE2) + TEST_ERROR + + if(H5Fclose(file) < 0) + FAIL_STACK_ERROR + + PASSED() + + return(0); + +error: + H5E_BEGIN_TRY { + H5Fclose(file); + } H5E_END_TRY; + return(1); +} /* test_mf_fs_multi() */ + +#define MULTI_SETUP(memb_map, memb_fapl, memb_name, memb_addr, sv) { \ + H5FD_mem_t mt; \ + 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 = 0; mt < H5FD_MEM_NTYPES; mt++) { \ + memb_map[mt] = H5FD_MEM_SUPER; \ + memb_fapl[mt] = H5P_DEFAULT; \ + } \ + memb_map[H5FD_MEM_BTREE] = H5FD_MEM_BTREE; \ + memb_map[H5FD_MEM_DRAW] = H5FD_MEM_DRAW; \ + memb_map[H5FD_MEM_GHEAP] = H5FD_MEM_GHEAP; \ + memb_map[H5FD_MEM_LHEAP] = H5FD_MEM_LHEAP; \ + sprintf(sv[H5FD_MEM_SUPER], "%%s-%c.h5", 's'); \ + memb_name[H5FD_MEM_SUPER] = sv[H5FD_MEM_SUPER]; \ + memb_addr[H5FD_MEM_SUPER] = 0; \ + sprintf(sv[H5FD_MEM_BTREE], "%%s-%c.h5", 'b'); \ + memb_name[H5FD_MEM_BTREE] = sv[H5FD_MEM_BTREE]; \ + memb_addr[H5FD_MEM_BTREE] = HADDR_MAX/6; \ + 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/3; \ + sprintf(sv[H5FD_MEM_GHEAP], "%%s-%c.h5", 'g'); \ + memb_name[H5FD_MEM_GHEAP] = sv[H5FD_MEM_GHEAP]; \ + memb_addr[H5FD_MEM_GHEAP] = HADDR_MAX/2; \ + sprintf(sv[H5FD_MEM_LHEAP], "%%s-%c.h5", 'l'); \ + memb_name[H5FD_MEM_LHEAP] = sv[H5FD_MEM_LHEAP]; \ + memb_addr[H5FD_MEM_LHEAP] = HADDR_MAX*2/3; \ + sprintf(sv[H5FD_MEM_OHDR], "%%s-%c.h5", 'o'); \ + memb_name[H5FD_MEM_OHDR] = sv[H5FD_MEM_OHDR]; \ + memb_addr[H5FD_MEM_OHDR] = HADDR_MAX*5/6; \ +} + +/* + * Tests to verify that file's free-space managers are persistent or going away + * for different drivers. + */ +static unsigned +test_mf_fs_drivers(hid_t fapl) +{ + hid_t fcpl; /* file creation property list */ + hid_t fapl_new; /* copy of file access property list */ + hid_t fapl2; /* copy of file access property list */ + hbool_t new_format; /* To use new library format or not */ + unsigned ret = 0; /* return value */ + + H5FD_mem_t memb_map[H5FD_MEM_NTYPES]; /* Memory usage map */ + hid_t memb_fapl[H5FD_MEM_NTYPES]; /* Member access properties */ + char sv[H5FD_MEM_NTYPES][500]; /* Name generators */ + const char *memb_name[H5FD_MEM_NTYPES]; /* Name generators */ + haddr_t memb_addr[H5FD_MEM_NTYPES]; /* Member starting address */ + + /* Create a non-standard file-creation template */ + fcpl = H5Pcreate(H5P_FILE_CREATE); + if(H5Pset_file_space(fcpl, H5F_FILE_SPACE_ALL_PERSIST, (hsize_t)0) < 0) + TEST_ERROR + + /* Copy the file access property list */ + if((fapl2 = H5Pcopy(fapl)) < 0) TEST_ERROR + + /* Set the "use the latest version of the format" bounds for creating objects in the file */ + if(H5Pset_libver_bounds(fapl2, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) + TEST_ERROR + + /* Test with old and new format */ + for(new_format = FALSE; new_format <= TRUE; new_format++) { + + if(new_format) + HDputs("Testing the following tests for free-space managers with new library format..."); + else + HDputs("Testing the following tests for free-space managers with old library format..."); + + /* SEC2 */ + HDputs("Testing free-space manager(s) with sec2 driver"); + + if((fapl_new = H5Pcopy(new_format ? fapl2 : fapl)) < 0) TEST_ERROR + + if(H5Pset_fapl_sec2(fapl_new) < 0) + FAIL_STACK_ERROR + + ret += test_mf_fs_gone(fapl_new, fcpl); + ret += test_mf_fs_persist(fapl_new, fcpl); + + h5_cleanup(FILENAME, fapl_new); + + + /* STDIO */ + HDputs("Testing free-space managers with stdio driver"); + + if((fapl_new = H5Pcopy(new_format?fapl2:fapl)) < 0) + FAIL_STACK_ERROR + if(H5Pset_fapl_stdio(fapl_new) < 0) + FAIL_STACK_ERROR + + ret += test_mf_fs_gone(fapl_new, fcpl); + ret += test_mf_fs_persist(fapl_new, fcpl); + + h5_cleanup(FILENAME, fapl_new); + + /* CORE */ + HDputs("Testing free-space managers with core driver"); + + /* create fapl to be a "core" file */ + if((fapl_new = H5Pcopy(new_format?fapl2:fapl)) < 0) + FAIL_STACK_ERROR + if(H5Pset_fapl_core(fapl_new, (size_t)CORE_INCREMENT, TRUE) < 0) + FAIL_STACK_ERROR + + ret += test_mf_fs_gone(fapl_new, fcpl); + ret += test_mf_fs_persist(fapl_new, fcpl); + + h5_cleanup(FILENAME, fapl_new); + + /* FAMILY */ + HDputs("Testing free-space managers with family driver"); + + if((fapl_new = H5Pcopy(new_format?fapl2:fapl)) < 0) + FAIL_STACK_ERROR + if(H5Pset_fapl_family(fapl_new, (hsize_t)FAMILY_SIZE, H5P_DEFAULT) < 0) + FAIL_STACK_ERROR + + ret += test_mf_fs_persist(fapl_new, fcpl); + + h5_cleanup(FILENAME, fapl_new); + + /* SPLIT */ + HDputs("Testing free-space managers with split driver"); + + if((fapl_new = H5Pcopy(new_format?fapl2:fapl)) < 0) + FAIL_STACK_ERROR + if(H5Pset_fapl_split(fapl_new, "-m.h5", H5P_DEFAULT, "-r.h5", H5P_DEFAULT)<0) + FAIL_STACK_ERROR + + ret += test_mf_fs_persist(fapl_new, fcpl); + ret += test_mf_fs_split(fapl_new, fcpl); + + h5_cleanup(FILENAME, fapl_new); + + /* MULTI */ + HDputs("Testing free-space managers with multi driver"); + + MULTI_SETUP(memb_map, memb_fapl, memb_name, memb_addr, sv) + + if((fapl_new = H5Pcopy(new_format?fapl2:fapl)) < 0) + FAIL_STACK_ERROR + if(H5Pset_fapl_multi(fapl_new, memb_map, memb_fapl, memb_name, memb_addr, TRUE) < 0) + TEST_ERROR; + + ret += test_mf_fs_multi(fapl_new, fcpl); + + h5_cleanup(FILENAME, fapl_new); + + } /* end for new_format */ + + if (H5Pclose(fcpl) < 0) + FAIL_STACK_ERROR + if (H5Pclose(fapl2) < 0) + FAIL_STACK_ERROR + + return(ret); + +error: + return(1); +} /* test_mf_fs_drivers() */ + + +/* + * Verify that file space management performs according to the + * file space strategy and free space threshold as specified. + */ +static unsigned +test_filespace_strategy_threshold(hid_t fapl_new) +{ + hid_t file = -1; /* File ID */ + hid_t fcpl; /* File creation property list template */ + char filename[FILENAME_LEN]; /* Filename to use */ + H5F_t *f = NULL; /* Internal file object pointer */ + H5FD_mem_t type; /* File allocation type */ + haddr_t addr1, addr2, addr3, addr4, addr5, addr6; /* File address for H5FD_MEM_SUPER */ + haddr_t tmp_addr; /* Temporary variable for address */ + H5F_file_space_type_t fs_type; /* File space handling strategy */ + hsize_t fs_threshold; /* Free space section threshold */ + hsize_t tot_space, saved_tot_space; /* Total amount of free space */ + hsize_t tot_sect_count, saved_tot_sect_count; /* # of free-space sections */ + + TESTING("file space strategy and threshold"); + + /* Set the filename to use for this test (dependent on fapl) */ + h5_fixname(FILENAME[0], fapl_new, filename, sizeof(filename)); + + for(fs_threshold = 0; fs_threshold <= TEST_THRESHOLD10; fs_threshold++) { + + for(fs_type = H5F_FILE_SPACE_ALL_PERSIST; fs_type < H5F_FILE_SPACE_NTYPES; H5_INC_ENUM(H5F_file_space_type_t, fs_type)) { + + /* Create file-creation template */ + if((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0) + FAIL_STACK_ERROR + + /* Set default file space information */ + if(H5Pset_file_space(fcpl, fs_type, fs_threshold) < 0) + FAIL_STACK_ERROR + + /* Create the file to work on */ + if((file = H5Fcreate(filename, H5F_ACC_TRUNC, fcpl, fapl_new)) < 0) + FAIL_STACK_ERROR + + /* Get a pointer to the internal file object */ + if(NULL == (f = (H5F_t *)H5I_object(file))) + FAIL_STACK_ERROR + + /* Allocate 6 blocks */ + type = H5FD_MEM_SUPER; + if(HADDR_UNDEF == (addr1 = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE1))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (addr2 = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE2))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (addr3 = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE3))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (addr4 = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE4))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (addr5 = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE5))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (addr6 = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE6))) + FAIL_STACK_ERROR + + /* Put block #1, #3, #5 to H5FD_MEM_SUPER free-space manager */ + if(H5MF_xfree(f, type, H5P_DATASET_XFER_DEFAULT, addr1, (hsize_t)TEST_BLOCK_SIZE1) < 0) + FAIL_STACK_ERROR + if(H5MF_xfree(f, type, H5P_DATASET_XFER_DEFAULT, addr3, (hsize_t)TEST_BLOCK_SIZE3) < 0) + FAIL_STACK_ERROR + if(H5MF_xfree(f, type, H5P_DATASET_XFER_DEFAULT, addr5, (hsize_t)TEST_BLOCK_SIZE5) < 0) + FAIL_STACK_ERROR + + /* Retrieve the total amount of free space and # of free-space sections */ + if(f->shared->fs_man[type] && + H5FS_sect_stats(f->shared->fs_man[type], &saved_tot_space, &saved_tot_sect_count) < 0) + FAIL_STACK_ERROR + + /* H5F_FILE_SPACE_AGGR_VFD and H5F_FILE_SPACE_VFD: should not have free-space manager */ + if(fs_type > H5F_FILE_SPACE_ALL && f->shared->fs_man[type]) + TEST_ERROR + + /* Close the file */ + if(H5Fclose(file) < 0) + FAIL_STACK_ERROR + + /* Re-open the file */ + if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl_new)) < 0) + FAIL_STACK_ERROR + + /* Get a pointer to the internal file object */ + if(NULL == (f = (H5F_t *)H5I_object(file))) + FAIL_STACK_ERROR + + switch(fs_type) { + case H5F_FILE_SPACE_ALL_PERSIST: + if(fs_threshold <= TEST_BLOCK_SIZE5) { + if(!H5F_addr_defined(f->shared->fs_addr[type])) + TEST_ERROR + + /* Open the free-space manager */ + if(H5MF_alloc_open(f, H5P_DATASET_XFER_DEFAULT, type) < 0) + FAIL_STACK_ERROR + + /* Retrieve the total amount of free space and # of free-space sections */ + if(H5FS_sect_stats(f->shared->fs_man[type], &tot_space, &tot_sect_count) < 0) + FAIL_STACK_ERROR + + /* Verify that tot_space should be >= saved_tot_space */ + /* Verify that tot_sect_count should be >= saved_tot_sect_count */ + if(tot_space < saved_tot_space || tot_sect_count < saved_tot_sect_count) + TEST_ERROR + + /* Retrieve block #5 from H5FD_MEM_SUPER free-space manager */ + if(HADDR_UNDEF == + (tmp_addr = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE5))) + FAIL_STACK_ERROR + + /* Should be the same as before */ + if(tmp_addr != addr5) + TEST_ERROR + } else if(H5F_addr_defined(f->shared->fs_addr[type])) + TEST_ERROR + break; + + case H5F_FILE_SPACE_ALL: + case H5F_FILE_SPACE_AGGR_VFD: + case H5F_FILE_SPACE_VFD: + if(H5F_addr_defined(f->shared->fs_addr[type])) + TEST_ERROR + break; + + default: + break; + } /* end switch */ + + /* Closing */ + if(H5Fclose(file) < 0) + FAIL_STACK_ERROR + if(H5Pclose(fcpl) < 0) + FAIL_STACK_ERROR + + } /* end for fs_type */ + } /* end for fs_threshold */ + + PASSED() + + return(0); + +error: + H5E_BEGIN_TRY { + H5Fclose(file); + } H5E_END_TRY; + return(1); +} /* test_filespace_strategy_threshold() */ + +/* + * Verify section is merged/shrunk away for + * H5F_FILE_SPACE_ALL_PERSIST and H5F_FILE_SPACE_ALL strategy. + */ +static unsigned +test_filespace_gone(hid_t fapl_new) +{ + hid_t file = -1; /* File ID */ + hid_t fcpl; /* File creation propertly list template */ + char filename[FILENAME_LEN]; /* Filename to use */ + H5F_t *f = NULL; /* Internal file object pointer */ + H5FD_mem_t type; /* File allocation type */ + haddr_t addr1, addr2, addr3, addr4, addr5, addr6; /* File address for H5FD_MEM_SUPER */ + H5F_file_space_type_t fs_type; /* File space handling strategy */ + hsize_t fs_threshold; /* Free space section threshold */ + frspace_state_t state; /* State of free space manager */ + + TESTING("file space merge/shrink for section size < threshold"); + + /* Set the filename to use for this test (dependent on fapl) */ + h5_fixname(FILENAME[0], fapl_new, filename, sizeof(filename)); + + /* Set free-space threshold */ + fs_threshold = TEST_THRESHOLD3; + + for(fs_type = H5F_FILE_SPACE_ALL_PERSIST; fs_type <= H5F_FILE_SPACE_ALL; H5_INC_ENUM(H5F_file_space_type_t, fs_type)) { + /* Create file-creation template */ + if((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0) + FAIL_STACK_ERROR + + /* Set default file space information */ + if(H5Pset_file_space(fcpl, fs_type, fs_threshold) < 0) + FAIL_STACK_ERROR + + /* Create the file to work on */ + if((file = H5Fcreate(filename, H5F_ACC_TRUNC, fcpl, fapl_new)) < 0) + FAIL_STACK_ERROR + + /* Get a pointer to the internal file object */ + if(NULL == (f = (H5F_t *)H5I_object(file))) + FAIL_STACK_ERROR + + /* Allocate 6 blocks */ + type = H5FD_MEM_SUPER; + if(HADDR_UNDEF == (addr1 = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE1))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (addr2 = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE2))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (addr3 = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE3))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (addr4 = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE4))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (addr5 = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE5))) + FAIL_STACK_ERROR + if(HADDR_UNDEF == (addr6 = H5MF_alloc(f, type, H5P_DATASET_XFER_DEFAULT, (hsize_t)TEST_BLOCK_SIZE6))) + FAIL_STACK_ERROR + + /* Put block #3, #5 to H5FD_MEM_SUPER free-space manager */ + if(H5MF_xfree(f, type, H5P_DATASET_XFER_DEFAULT, addr3, (hsize_t)TEST_BLOCK_SIZE3) < 0) + FAIL_STACK_ERROR + if(H5MF_xfree(f, type, H5P_DATASET_XFER_DEFAULT, addr5, (hsize_t)TEST_BLOCK_SIZE5) < 0) + FAIL_STACK_ERROR + + HDmemset(&state, 0, sizeof(frspace_state_t)); + state.tot_space += TEST_BLOCK_SIZE3 + TEST_BLOCK_SIZE5; + state.tot_sect_count += 2; + state.serial_sect_count += 2; + + if(check_stats(f, f->shared->fs_man[type], &state)) + TEST_ERROR + + /* section #2 is less than threshold but is merged into section #3 */ + if(H5MF_xfree(f, type, H5P_DATASET_XFER_DEFAULT, addr2, (hsize_t)TEST_BLOCK_SIZE2) < 0) + FAIL_STACK_ERROR + + state.tot_space += TEST_BLOCK_SIZE2; + if(check_stats(f, f->shared->fs_man[type], &state)) + TEST_ERROR + + if(H5MF_xfree(f, type, H5P_DATASET_XFER_DEFAULT, addr4, (hsize_t)TEST_BLOCK_SIZE4) < 0) + FAIL_STACK_ERROR + + if(H5MF_xfree(f, type, H5P_DATASET_XFER_DEFAULT, addr6, (hsize_t)TEST_BLOCK_SIZE6) < 0) + FAIL_STACK_ERROR + + /* all sections should be shrunk away except section #1 */ + HDmemset(&state, 0, sizeof(frspace_state_t)); + if(check_stats(f, f->shared->fs_man[type], &state)) + TEST_ERROR + + /* section #1 is less than threshold but is shrunk away */ + if(H5MF_xfree(f, type, H5P_DATASET_XFER_DEFAULT, addr1, (hsize_t)TEST_BLOCK_SIZE1) < 0) + FAIL_STACK_ERROR + + /* free-space manager should be empty */ + HDmemset(&state, 0, sizeof(frspace_state_t)); + if(check_stats(f, f->shared->fs_man[type], &state)) + TEST_ERROR + + if(H5Fclose(file) < 0) + FAIL_STACK_ERROR + + /* Re-open the file */ + if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl_new)) < 0) + FAIL_STACK_ERROR + + /* Get a pointer to the internal file object */ + if(NULL == (f = (H5F_t *)H5I_object(file))) + FAIL_STACK_ERROR + + /* free-space manager should be empty */ + if(H5F_addr_defined(f->shared->fs_addr[type])) + TEST_ERROR + + if(H5Fclose(file) < 0) + FAIL_STACK_ERROR + + if(H5Pclose(fcpl) < 0) + FAIL_STACK_ERROR + + } /* end for fs_type */ + + PASSED() + + return(0); + +error: + H5E_BEGIN_TRY { + H5Fclose(file); + } H5E_END_TRY; + return(1); +} /* test_filespace_gone() */ + +/* + * Tests to verify file space management for different drivers. + */ +static unsigned +test_filespace_drivers(hid_t fapl) +{ + hid_t fapl_new; /* copy of file access property list */ + hid_t fapl2; /* copy of file access property list */ + hbool_t new_format; /* Using library new format or not */ + unsigned ret = 0; /* return value */ + + H5FD_mem_t memb_map[H5FD_MEM_NTYPES]; /* Memory usage map */ + hid_t memb_fapl[H5FD_MEM_NTYPES]; /* Member access properties */ + char sv[H5FD_MEM_NTYPES][500]; /* Name generators */ + const char *memb_name[H5FD_MEM_NTYPES]; /* Name generators */ + haddr_t memb_addr[H5FD_MEM_NTYPES]; /* Member starting address */ + + /* Copy the file access property list */ + if((fapl2 = H5Pcopy(fapl)) < 0) TEST_ERROR + + /* Set the "use the latest version of the format" bounds for creating objects in the file */ + if(H5Pset_libver_bounds(fapl2, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) + TEST_ERROR + + /* Test with old and new format */ + for(new_format = FALSE; new_format <= TRUE; new_format++) { + + if(new_format) + HDputs("Testing the following tests for file space management with new library format..."); + else + HDputs("Testing the following tests for file space management with old library format..."); + + /* SEC2 */ + HDputs("Testing file space management with sec2 driver"); + + if((fapl_new = H5Pcopy(new_format?fapl2:fapl)) < 0) + FAIL_STACK_ERROR + if(H5Pset_fapl_sec2(fapl_new) < 0) + FAIL_STACK_ERROR + + ret += test_filespace_strategy_threshold(fapl_new); + ret += test_filespace_gone(fapl_new); + + h5_cleanup(FILENAME, fapl_new); + + /* STDIO */ + HDputs("Testing file space management with stdio driver"); + + if((fapl_new = H5Pcopy(new_format?fapl2:fapl)) < 0) + FAIL_STACK_ERROR + if(H5Pset_fapl_stdio(fapl_new) < 0) + FAIL_STACK_ERROR + + ret += test_filespace_strategy_threshold(fapl_new); + ret += test_filespace_gone(fapl_new); + + h5_cleanup(FILENAME, fapl_new); + + /* CORE */ + HDputs("Testing file space management with core driver"); + + /* create fapl to be a "core" file */ + if((fapl_new = H5Pcopy(new_format?fapl2:fapl)) < 0) + FAIL_STACK_ERROR + if(H5Pset_fapl_core(fapl_new, (size_t)CORE_INCREMENT, TRUE) < 0) + FAIL_STACK_ERROR + + ret += test_filespace_strategy_threshold(fapl_new); + ret += test_filespace_gone(fapl_new); + + h5_cleanup(FILENAME, fapl_new); + + /* FAMILY */ + HDputs("Testing file space managers with family driver"); + + if((fapl_new = H5Pcopy(new_format?fapl2:fapl)) < 0) + FAIL_STACK_ERROR + if(H5Pset_fapl_family(fapl_new, (hsize_t)FAMILY_SIZE, H5P_DEFAULT) < 0) + FAIL_STACK_ERROR + + ret += test_filespace_strategy_threshold(fapl_new); + ret += test_filespace_gone(fapl_new); + + h5_cleanup(FILENAME, fapl_new); + + + /* SPLIT */ + HDputs("Testing file space managers with split driver"); + + if((fapl_new = H5Pcopy(new_format?fapl2:fapl)) < 0) + FAIL_STACK_ERROR + if(H5Pset_fapl_split(fapl_new, "-m.h5", H5P_DEFAULT, "-r.h5", H5P_DEFAULT)<0) + FAIL_STACK_ERROR + + ret += test_filespace_strategy_threshold(fapl_new); + ret += test_filespace_gone(fapl_new); + + h5_cleanup(FILENAME, fapl_new); + + /* MULTI */ + HDputs("Testing file space managers with multi driver"); + + MULTI_SETUP(memb_map, memb_fapl, memb_name, memb_addr, sv) + + if((fapl_new = H5Pcopy(new_format?fapl2:fapl)) < 0) + TEST_ERROR + if(H5Pset_fapl_multi(fapl_new, memb_map, memb_fapl, memb_name, memb_addr, TRUE) < 0) + TEST_ERROR; + + ret += test_filespace_strategy_threshold(fapl_new); + ret += test_filespace_gone(fapl_new); + + h5_cleanup(FILENAME, fapl_new); + + } /* end for new_format */ + + if (H5Pclose(fapl2) < 0) + FAIL_STACK_ERROR + + return(ret); + +error: + return(1); +} /* test_filespace_drivers() */ + int main(void) { @@ -5930,6 +7288,12 @@ main(void) nerrors += test_mf_align_alloc6(env_h5_drvr, fapl, new_fapl); } /* end if */ + /* tests to verify that file's free-space managers are persistent */ + nerrors += test_mf_fs_drivers(fapl); + + /* tests for file space management */ + nerrors += test_filespace_drivers(fapl); + if (H5Pclose(new_fapl) < 0) FAIL_STACK_ERROR h5_cleanup(FILENAME, fapl); @@ -5947,3 +7311,4 @@ error: } H5E_END_TRY; return (1); } /* main() */ + diff --git a/test/tfile.c b/test/tfile.c index 8103881..454f339 100644 --- a/test/tfile.c +++ b/test/tfile.c @@ -98,6 +98,35 @@ #define USERBLOCK_SIZE ((hsize_t) 512) +/* Declarations for test_filespace_*() */ +#define FILENAME_LEN 1024 /* length of file name */ +#define CORE_INCREMENT 1024 /* core file */ +#define FAMILY_SIZE 1024 /* family file */ +#define DSETNAME "dset" /* Name of dataset */ +#define NELMTS(X) (sizeof(X)/sizeof(X[0])) /* # of elements */ +#define READ_OLD_BUFSIZE 1024 /* Buffer for holding file data */ +#define FILE5 "tfile5.h5" /* Test file */ +#define TEST_THRESHOLD10 10 /* Free space section threshold */ + +const char *OLD_FILENAME[] = { /* Files created under 1.6 branch and 1.8 branch */ + "filespace_1_6.h5", /* 1.6 HDF5 file */ + "filespace_1_8.h5" /* 1.8 HDF5 file */ +}; +const char *FILESPACE_NAME[] = { + "tfilespace", + NULL +}; + +const char *FILENAME[] = { + "sec2_tfile", + "split_tfile", + "stdio_tfile", + "core_tfile", + "family_tfile", + NULL +}; + + static void create_objects(hid_t, hid_t, hid_t *, hid_t *, hid_t *, hid_t *); static void @@ -2504,6 +2533,675 @@ test_userblock_alignment(void) /**************************************************************** ** +** test_free_sections(): +** This routine does the actual work of checking information for +** free space sections available in a file in various situations. +** +*****************************************************************/ +static void +test_free_sections(hid_t fapl, char *fname) +{ + hid_t file; /* File ID */ + hid_t fcpl; /* File creation property list template */ + hssize_t free_space; /* Amount of free space in file */ + hid_t dspace; /* Dataspace ID */ + hid_t dset; /* Dataset ID */ + hid_t dcpl; /* Dataset creation property list */ + unsigned u; /* Local index variable */ + char name[32]; /* Dataset name */ + hssize_t nsects; /* # of free-space sections */ + hssize_t saved_nsects; /* saved copy for the # of free-space sections */ + int i; /* local index variable */ + hsize_t total; /* sum of the free-space section sizes */ + hsize_t last_size; /* size of last free-space section */ + H5F_sect_info_t *sect_info; /* array to hold the free-space information */ + H5F_sect_info_t *saved_sect_info; /* array to hold the free-space information */ + herr_t ret; /* return value */ + + /* Create file-creation template */ + fcpl = H5Pcreate(H5P_FILE_CREATE); + CHECK(fcpl, FAIL, "H5Pcreate"); + + /* Set file space strategy and free space section threshold */ + ret = H5Pset_file_space(fcpl, H5F_FILE_SPACE_ALL_PERSIST, (hsize_t)0); + CHECK(ret, FAIL, "H5Pget_file_space"); + + /* Create the file */ + file = H5Fcreate(fname, H5F_ACC_TRUNC, fcpl, fapl); + CHECK(file, FAIL, "H5Fcreate"); + + /* Create dataspace for datasets */ + dspace = H5Screate(H5S_SCALAR); + CHECK(dspace, FAIL, "H5Screate"); + + /* Create a dataset creation property list */ + dcpl = H5Pcreate(H5P_DATASET_CREATE); + CHECK(dcpl, FAIL, "H5Pcreate"); + + /* Set the space allocation time to early */ + ret = H5Pset_alloc_time(dcpl, H5D_ALLOC_TIME_EARLY); + CHECK(ret, FAIL, "H5Pset_alloc_time"); + + /* Create datasets in file */ + for(u = 0; u < 10; u++) { + sprintf(name, "Dataset %u", u); + dset = H5Dcreate2(file, name, H5T_STD_U32LE, dspace, H5P_DEFAULT, dcpl, H5P_DEFAULT); + CHECK(dset, FAIL, "H5Dcreate2"); + + ret = H5Dclose(dset); + CHECK(ret, FAIL, "H5Dclose"); + } /* end for */ + + /* Close dataspace */ + ret = H5Sclose(dspace); + CHECK(ret, FAIL, "H5Sclose"); + + /* Close dataset creation property list */ + ret = H5Pclose(dcpl); + CHECK(ret, FAIL, "H5Pclose"); + + /* Delete odd-numbered datasets in file */ + for(u = 0; u < 10; u++) { + sprintf(name, "Dataset %u", u); + if(u % 2) { + ret = H5Ldelete(file, name, H5P_DEFAULT); + CHECK(ret, FAIL, "H5Ldelete"); + } /* end if */ + } /* end for */ + + /* Close file */ + ret = H5Fclose(file); + CHECK(ret, FAIL, "H5Fclose"); + + /* Re-open the file with read-only permission */ + file = H5Fopen(fname, H5F_ACC_RDONLY, fapl); + CHECK_I(file, "H5Fopen"); + + /* Get the amount of free space in the file */ + free_space = H5Fget_freespace(file); + CHECK(free_space, FAIL, "H5Fget_freespace"); + + /* Get the # of free-space sections in the file */ + saved_nsects = H5Fget_free_sections(file, H5FD_MEM_DEFAULT, (size_t)0, NULL); + CHECK(saved_nsects, FAIL, "H5Fget_free_sections"); + + /* Allocate storage for the free space section information */ + saved_sect_info = (H5F_sect_info_t *)HDcalloc((size_t)saved_nsects, sizeof(H5F_sect_info_t)); + CHECK(saved_sect_info, NULL, "HDcalloc"); + + /* Should return failure when nsects is 0 with a nonnull sect_info */ + nsects = H5Fget_free_sections(file, H5FD_MEM_DEFAULT, (size_t)0, saved_sect_info); + VERIFY(nsects, FAIL, "H5Fget_free_sections"); + + /* Verify the correct # of free-space sections */ + nsects = H5Fget_free_sections(file, H5FD_MEM_DEFAULT, (size_t)saved_nsects, saved_sect_info); + VERIFY(nsects, saved_nsects, "H5Fget_free_sections"); + + /* Verify the amount of free-space is correct */ + total = 0; + for(i = 0; i < nsects; i++) + total += saved_sect_info[i].size; + VERIFY(free_space, total, "H5Fget_free_sections"); + + /* save the last section's size */ + last_size = saved_sect_info[nsects-1].size; + + /* Allocate storage for -1 free space section information */ + sect_info = (H5F_sect_info_t *)HDcalloc((size_t)(saved_nsects - 1), sizeof(H5F_sect_info_t)); + CHECK(sect_info, NULL, "HDcalloc"); + + /* Retrieve free space info for -1 sections */ + nsects = H5Fget_free_sections(file, H5FD_MEM_DEFAULT, (size_t)(saved_nsects - 1), sect_info); + VERIFY(nsects, saved_nsects, "H5Fget_free_sections"); + + /* Verify the amount of free-space is correct */ + total = 0; + for(i = 0; i < (saved_nsects - 1); i++) { + VERIFY(sect_info[i].addr, saved_sect_info[i].addr, "H5Fget_free_sections"); + VERIFY(sect_info[i].size, saved_sect_info[i].size, "H5Fget_free_sections"); + total += sect_info[i].size; + } + + VERIFY(((hsize_t)free_space - last_size), total, "H5Fget_free_sections"); + HDfree(sect_info); + + /* Allocate storage for +1 free space section information */ + sect_info = (H5F_sect_info_t *)HDcalloc((size_t)(saved_nsects + 1), sizeof(H5F_sect_info_t)); + CHECK(sect_info, NULL, "HDcalloc"); + + /* Retrieve free-space info for +1 sections */ + nsects = H5Fget_free_sections(file, H5FD_MEM_DEFAULT, (size_t)(saved_nsects + 1), sect_info); + VERIFY(nsects, saved_nsects, "H5Fget_free_sections"); + + /* Verify free-space info is correct */ + total = 0; + for(i = 0; i < nsects; i++) { + VERIFY(sect_info[i].addr, saved_sect_info[i].addr, "H5Fget_free_sections"); + VERIFY(sect_info[i].size, saved_sect_info[i].size, "H5Fget_free_sections"); + total += sect_info[i].size; + } + + VERIFY(sect_info[nsects].addr, 0, "H5Fget_free_sections"); + VERIFY(sect_info[nsects].size, 0, "H5Fget_free_sections"); + VERIFY(free_space, total, "H5Fget_free_sections"); + HDfree(sect_info); + + /* Verify that there is no free-space section for this type */ + nsects = H5Fget_free_sections(file, H5FD_MEM_BTREE, (size_t)0, NULL); + VERIFY(nsects, 0, "H5Fget_free_sections"); + + /* Close file */ + ret = H5Fclose(file); + CHECK(ret, FAIL, "H5Fclose"); + + ret = H5Pclose(fcpl); + CHECK(fcpl, FAIL, "H5Pclose"); + + HDfree(saved_sect_info); + +} /* end test_free_sections() */ + +/**************************************************************** +** +** test_filespace_sects(): +** This test checks free space section info for +** files created with sec2 and split drivers. +** +*****************************************************************/ +static void +test_filespace_sects(void) +{ + hid_t fapl_sec2; /* File access property id with sec2 driver */ + hid_t fapl_split; /* File access property id with split driver */ + hid_t fapl_core; /* File access property id with core driver */ + hid_t fapl_stdio; /* File access property id with stdio driver */ + hid_t fapl_family; /* File access property id with family driver */ + char filename[FILENAME_LEN]; /* Filename to use */ + herr_t ret; /* Return value */ + + /* SEC2 */ + MESSAGE(5, ("Testing File free space information for a sec2 file\n")); + + fapl_sec2 = H5Pcreate(H5P_FILE_ACCESS); + + ret = H5Pset_fapl_sec2(fapl_sec2); + CHECK(ret, FAIL, "H5Pset_fapl_sec2"); + + /* Set the filename to use for this test (dependent on fapl) */ + h5_fixname(FILENAME[0], fapl_sec2, filename, sizeof(filename)); + + /* perform free space information test for file with sec2 driver */ + test_free_sections(fapl_sec2, filename); + + /* close fapl_sec2 and remove the file */ + h5_cleanup(FILENAME, fapl_sec2); + + + /* SPLIT */ + MESSAGE(5, ("Testing File free space information for a split file\n")); + + fapl_split = H5Pcreate(H5P_FILE_ACCESS); + CHECK(fapl_split, FAIL, "h5_fileaccess"); + + ret = H5Pset_fapl_split(fapl_split, "-m.h5", H5P_DEFAULT, "-r.h5", H5P_DEFAULT); + CHECK(ret, FAIL, "H5Pset_fapl_split"); + + /* Set the filename to use for this test (dependent on fapl) */ + h5_fixname(FILENAME[1], fapl_split, filename, sizeof(filename)); + + /* perform free space information test for file with split driver */ + test_free_sections(fapl_split, filename); + + /* close fapl and remove the file */ + h5_cleanup(FILENAME, fapl_split); + + + /* STDIO */ + MESSAGE(5, ("Testing File free space information for a stdio file\n")); + + fapl_stdio = H5Pcreate(H5P_FILE_ACCESS); + CHECK(fapl_stdio, FAIL, "h5_fileaccess"); + + ret = H5Pset_fapl_stdio(fapl_stdio); + CHECK(ret, FAIL, "H5Pset_fapl_split"); + + /* Set the filename to use for this test (dependent on fapl) */ + h5_fixname(FILENAME[2], fapl_stdio, filename, sizeof(filename)); + + /* perform free space information test for file with stdio driver */ + test_free_sections(fapl_stdio, filename); + + /* close fapl and remove the file */ + h5_cleanup(FILENAME, fapl_split); + + /* CORE */ + MESSAGE(5, ("Testing File free space information for a core file\n")); + + fapl_core = H5Pcreate(H5P_FILE_ACCESS); + CHECK(fapl_core, FAIL, "h5_fileaccess"); + + ret = H5Pset_fapl_core(fapl_core, (size_t)CORE_INCREMENT, TRUE); + CHECK(ret, FAIL, "H5Pset_fapl_core"); + + /* Set the filename to use for this test (dependent on fapl) */ + h5_fixname(FILENAME[3], fapl_core, filename, sizeof(filename)); + + /* perform free space information test for file with core driver */ + test_free_sections(fapl_core, filename); + + /* close fapl_ and remove the file */ + h5_cleanup(FILENAME, fapl_core); + + + /* FAMILY */ + MESSAGE(5, ("Testing File free space information for a family file\n")); + + fapl_family = H5Pcreate(H5P_FILE_ACCESS); + CHECK(fapl_family, FAIL, "h5_fileaccess"); + + ret = H5Pset_fapl_family(fapl_family, (hsize_t)FAMILY_SIZE, H5P_DEFAULT); + CHECK(ret, FAIL, "H5Pset_fapl_family"); + + /* Set the filename to use for this test (dependent on fapl) */ + h5_fixname(FILENAME[4], fapl_family, filename, sizeof(filename)); + + /* perform free space information test for file with family driver */ + test_free_sections(fapl_family, filename); + + /* close fapl and remove the file */ + h5_cleanup(FILENAME, fapl_family); + +} /* end test_filespace_sects() */ + +/**************************************************************** +** +** test_filespace_info(): +** Verify that the public routines H5Pget/set_file_space() +** retrieve and set the file space strategy and free space +** section threshold as specified. +** +****************************************************************/ +static void +test_filespace_info(void) +{ + hid_t fid1, fid2; /* HDF5 File IDs */ + hid_t fapl, new_fapl; /* File access property */ + hid_t fcpl, fcpl1, fcpl2; /* File creation property */ + char filename[FILENAME_LEN]; /* Filename to use */ + H5F_file_space_type_t strategy, fs_type, def_type; /* File space handling strategy */ + hsize_t threshold, fs_size, def_size; /* Free space section threshold */ + hbool_t new_format; /* new format or old format */ + herr_t ret; /* return value */ + + /* Output message about test being performed */ + MESSAGE(5, ("Testing File Space Management public routines: H5Pget/set_file_space()\n")); + + fapl = h5_fileaccess(); + h5_fixname(FILESPACE_NAME[0], fapl, filename, sizeof filename); + + new_fapl = H5Pcopy(fapl); + CHECK(new_fapl, FAIL, "H5Pcopy"); + + /* Set the "use the latest version of the format" bounds */ + ret = H5Pset_libver_bounds(new_fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST); + CHECK(ret, FAIL, "H5Pset_libver_bounds"); + + /* Create file-creation template */ + fcpl = H5Pcreate(H5P_FILE_CREATE); + CHECK(fcpl, FAIL, "H5Pcreate"); + + /* Get default file space information */ + ret = H5Pget_file_space(fcpl, &def_type, &def_size); + CHECK(ret, FAIL, "H5Pget_file_space"); + + /* Test with old & new format groups */ + for(new_format = FALSE; new_format <= TRUE; new_format++) { + hid_t my_fapl; + + /* Set the FAPL for the type of format */ + if(new_format) { + MESSAGE(5, ("Testing with new group format\n")); + my_fapl = new_fapl; + } /* end if */ + else { + MESSAGE(5, ("Testing with old group format\n")); + my_fapl = fapl; + } /* end else */ + + /* Test with different sized free space section threshold */ + for(fs_size = 0; fs_size <= TEST_THRESHOLD10; fs_size++) { + + /* Test with different file space handling strategies */ + for(fs_type = 0; fs_type < H5F_FILE_SPACE_NTYPES; H5_INC_ENUM(H5F_file_space_type_t, fs_type)) { + + /* Get a copy of the default file creation property */ + fcpl1 = H5Pcopy(fcpl); + CHECK(fcpl1, FAIL, "H5Pcopy"); + + /* Set file space strategy and free space section threshold */ + ret = H5Pset_file_space(fcpl1, fs_type, fs_size); + CHECK(ret, FAIL, "H5Pget_file_space"); + + /* Get the file space info from the creation property */ + ret = H5Pget_file_space(fcpl1, &strategy, &threshold); + CHECK(ret, FAIL, "H5Pget_file_space"); + + /* A 0 value for strategy retains existing strategy in use */ + VERIFY(strategy, (H5F_file_space_type_t)(fs_type ? fs_type : def_type), "H5Pget_file_space"); + /* A 0 value for threshold retains existing threshold in use */ + VERIFY(threshold, (hsize_t)(fs_size ? fs_size : def_size), "H5Pget_file_space"); + + /* Create the file with the specified file space info */ + fid1 = H5Fcreate(filename, H5F_ACC_TRUNC, fcpl1, my_fapl); + CHECK(ret, FAIL, "H5Fcreate"); + + /* Close the file */ + ret = H5Fclose(fid1); + CHECK(ret, FAIL, "H5Fclose"); + + /* Re-open the file */ + fid2 = H5Fopen(filename, H5F_ACC_RDWR, my_fapl); + CHECK(ret, FAIL, "H5Fopen"); + + /* Get the file's creation property */ + fcpl2 = H5Fget_create_plist(fid2); + CHECK(fcpl2, FAIL, "H5Fget_create_plist"); + + strategy = threshold = 0; + + /* Get the file space info from the creation property list */ + ret = H5Pget_file_space(fcpl2, &strategy, &threshold); + CHECK(ret, FAIL, "H5Pget_file_space"); + + VERIFY(strategy, (H5F_file_space_type_t)(fs_type ? fs_type : def_type), "H5Pget_file_space"); + VERIFY(threshold, (hsize_t)(fs_size ? fs_size : def_size), "H5Pget_file_space"); + + /* Close the file */ + ret = H5Fclose(fid2); + CHECK(ret, FAIL, "H5Fclose"); + + /* Release file-creation template */ + ret = H5Pclose(fcpl1); + CHECK(ret, FAIL, "H5Pclose"); + ret = H5Pclose(fcpl2); + CHECK(ret, FAIL, "H5Pclose"); + } /* end for file space strategy type */ + } /* end for free space threshold */ + + h5_cleanup(FILESPACE_NAME, my_fapl); + + } /* end for new/old format */ + + /* Close the file creation property list */ + ret = H5Pclose(fcpl); + CHECK(ret, FAIL, "H5Pclose"); +} /* test_filespace_info() */ + +/**************************************************************** +** +** test_filespace_compatible(): +** Verify that the branch with file space management enhancement +** can open, read and modify 1.6 HDF5 file and 1.8 HDF5 file. +** Also verify the correct file space strategy/threshold in use +** and the amount of free space. +** +****************************************************************/ +static void +test_filespace_compatible(void) +{ + int fd_old = (-1), fd_new = (-1); /* File descriptors for copying data */ + hid_t fid; /* File id */ + hid_t fcpl; /* File creation property list template */ + hid_t did; /* Dataset id */ + int check[100]; /* Temporary buffer for verifying dataset data */ + int rdbuf[100]; /* Temporary buffer for reading in dataset data */ + uint8_t buf[READ_OLD_BUFSIZE]; /* temporary buffer for reading */ + ssize_t nread; /* Number of bytes read in */ + char *srcdir = HDgetenv("srcdir"); /* where the src code is located */ + char filename[FILENAME_LEN] = ""; /* old test file name */ + unsigned i, j; /* Local index variable */ + hssize_t free_space; /* Amount of free space in the file */ + hsize_t threshold; /* Free space section threshold */ + H5F_file_space_type_t strategy; /* File space handling strategy */ + herr_t ret; /* Return value */ + + /* Output message about test being performed */ + MESSAGE(5, ("Testing File space compatibility for 1.6 and 1.8 files\n")); + + for(j = 0; j < NELMTS(OLD_FILENAME); j++) { + + /* Generate correct name for test file by prepending the source path */ + if(srcdir && ((HDstrlen(srcdir) + HDstrlen(OLD_FILENAME[j]) + 1) < sizeof(filename))) { + HDstrcpy(filename, srcdir); + HDstrcat(filename, "/"); + } + HDstrcat(filename, OLD_FILENAME[j]); + + /* Copy old file into test file */ + fd_old = HDopen(filename, O_RDONLY, 0666); + CHECK(fd_old, FAIL, "HDopen"); + fd_new = HDopen(FILE5, O_RDWR|O_CREAT|O_TRUNC, 0666); + CHECK(fd_new, FAIL, "HDopen"); + + /* Copy data */ + while((nread = HDread(fd_old, buf, (size_t)READ_OLD_BUFSIZE)) > 0) + HDwrite(fd_new, buf, (size_t)nread); + + /* Close the files */ + ret = HDclose(fd_old); + CHECK(ret, FAIL, "HDclose"); + ret = HDclose(fd_new); + CHECK(ret, FAIL, "HDclose"); + + /* Open the test file */ + fid = H5Fopen(FILE5, H5F_ACC_RDWR, H5P_DEFAULT); + CHECK(fid, FAIL, "H5Fopen"); + + /* There should not be any free space in the file */ + free_space = H5Fget_freespace(fid); + CHECK(free_space, FAIL, "H5Fget_freespace"); + VERIFY(free_space, (hssize_t)0, "H5Fget_freespace"); + + /* Get the file's file creation property list */ + /* Retrieve the file space handling stretegy and threshold */ + fcpl = H5Fget_create_plist(fid); + CHECK(fcpl, FAIL, "H5Fget_create_plist"); + ret = H5Pget_file_space(fcpl, &strategy, &threshold); + CHECK(ret, FAIL, "H5Pget_file_space"); + + /* File space handling strategy should be H5F_FILE_SPACE_ALL = 2 */ + /* Free space section threshold should be 1 */ + VERIFY(strategy, 2, "H5Pget_file_space"); + VERIFY(threshold, 1, "H5Pget_file_space"); + + /* Generate raw data */ + for(i = 0; i < 100; i++) + check[i] = (int)i; + + /* Open and read the dataset */ + did = H5Dopen2(fid, DSETNAME, H5P_DEFAULT); + CHECK(did, FAIL, "H5Dopen"); + ret = H5Dread(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &rdbuf); + CHECK(ret, FAIL, "H5Dread"); + + /* Verify the data read is correct */ + for(i = 0; i < 100; i++) + VERIFY(rdbuf[i], check[i], "test_compatible"); + + /* Close the dataset */ + ret = H5Dclose(did); + CHECK(ret, FAIL, "H5Dclose"); + + /* Remove the dataset */ + ret = H5Ldelete(fid, DSETNAME, H5P_DEFAULT); + CHECK(ret, FAIL, "H5Ldelete"); + + /* Close the file */ + ret = H5Fclose(fid); + CHECK(ret, FAIL, "H5Fclose"); + + /* Re-Open the file */ + fid = H5Fopen(FILE5, H5F_ACC_RDONLY, H5P_DEFAULT); + CHECK(fid, FAIL, "H5Fopen"); + + /* The dataset should not be there */ + did = H5Dopen2(fid, DSETNAME, H5P_DEFAULT); + VERIFY(did, FAIL, "H5Dopen"); + + /* There should not be any free space in the file */ + free_space = H5Fget_freespace(fid); + CHECK(free_space, FAIL, "H5Fget_freespace"); + VERIFY(free_space, (hssize_t)0, "H5Fget_freespace"); + + /* Close the file */ + ret = H5Fclose(fid); + CHECK(ret, FAIL, "H5Fclose"); + } /* end for */ +} /* test_filespace_compatible */ + +/**************************************************************** +** +** test_deprec(): +** Test deprecated functionality. +** +****************************************************************/ +#ifndef H5_NO_DEPRECATED_SYMBOLS +static void +test_deprec(void) +{ + hid_t file; /* File IDs for old & new files */ + hid_t fcpl; /* File creation property list */ + unsigned super; /* Superblock version # */ + unsigned freelist; /* Free list version # */ + unsigned stab; /* Symbol table entry version # */ + unsigned shhdr; /* Shared object header version # */ + H5F_info1_t finfo; /* global information about file */ + herr_t ret; /* Generic return value */ + + /* Output message about test being performed */ + MESSAGE(5, ("Testing deprecated routines\n")); + + /* Creating a file with the default file creation property list should + * create a version 0 superblock + */ + + /* Create file with default file creation property list */ + file= H5Fcreate(FILE1, H5F_ACC_TRUNC , H5P_DEFAULT, H5P_DEFAULT); + CHECK(file, FAIL, "H5Fcreate"); + + /* Get the file's version information */ + ret = H5Fget_info1(file, &finfo); + CHECK(ret, FAIL, "H5Fget_info1"); + VERIFY(finfo.super_ext_size, 0,"H5Fget_info1"); + VERIFY(finfo.sohm.hdr_size, 0,"H5Fget_info1"); + VERIFY(finfo.sohm.msgs_info.index_size, 0,"H5Fget_info1"); + VERIFY(finfo.sohm.msgs_info.heap_size, 0,"H5Fget_info1"); + + /* Get the file's dataset creation property list */ + fcpl = H5Fget_create_plist(file); + CHECK(fcpl, FAIL, "H5Fget_create_plist"); + + /* Get the file's version information */ + ret=H5Pget_version(fcpl, &super, &freelist, &stab, &shhdr); + CHECK(ret, FAIL, "H5Pget_version"); + VERIFY(super,0,"H5Pget_version"); + VERIFY(freelist,0,"H5Pget_version"); + VERIFY(stab,0,"H5Pget_version"); + VERIFY(shhdr,0,"H5Pget_version"); + + /* Close FCPL */ + ret=H5Pclose(fcpl); + CHECK(ret, FAIL, "H5Pclose"); + + /* Close file */ + ret=H5Fclose(file); + CHECK(ret, FAIL, "H5Fclose"); + + + /* Create a file creation property list */ + fcpl = H5Pcreate(H5P_FILE_CREATE); + CHECK(fcpl, FAIL, "H5Pcreate"); + + /* Set a property in the FCPL that will push the superblock version up */ + ret = H5Pset_file_space(fcpl, H5F_FILE_SPACE_VFD, 0); + CHECK(ret, FAIL, "H5Pset_file_space"); + + /* Creating a file with the non-default file creation property list should + * create a version 2 superblock + */ + + /* Create file with custom file creation property list */ + file= H5Fcreate(FILE1, H5F_ACC_TRUNC , fcpl, H5P_DEFAULT); + CHECK(file, FAIL, "H5Fcreate"); + + /* Close FCPL */ + ret=H5Pclose(fcpl); + CHECK(ret, FAIL, "H5Pclose"); + + /* Get the file's version information */ + ret = H5Fget_info1(file, &finfo); + CHECK(ret, FAIL, "H5Fget_info1"); + VERIFY(finfo.super_ext_size, 40,"H5Fget_info1"); + VERIFY(finfo.sohm.hdr_size, 0,"H5Fget_info1"); + VERIFY(finfo.sohm.msgs_info.index_size, 0,"H5Fget_info1"); + VERIFY(finfo.sohm.msgs_info.heap_size, 0,"H5Fget_info1"); + + /* Get the file's dataset creation property list */ + fcpl = H5Fget_create_plist(file); + CHECK(fcpl, FAIL, "H5Fget_create_plist"); + + /* Get the file's version information */ + ret=H5Pget_version(fcpl, &super, &freelist, &stab, &shhdr); + CHECK(ret, FAIL, "H5Pget_version"); + VERIFY(super,2,"H5Pget_version"); + VERIFY(freelist,0,"H5Pget_version"); + VERIFY(stab,0,"H5Pget_version"); + VERIFY(shhdr,0,"H5Pget_version"); + + /* Close FCPL */ + ret=H5Pclose(fcpl); + CHECK(ret, FAIL, "H5Pclose"); + + /* Close file */ + ret=H5Fclose(file); + CHECK(ret, FAIL, "H5Fclose"); + + /* Re-open the file */ + file = H5Fopen(FILE1, H5F_ACC_RDONLY, H5P_DEFAULT); + CHECK(file, FAIL, "H5Fcreate"); + + /* Get the file's version information */ + ret = H5Fget_info1(file, &finfo); + CHECK(ret, FAIL, "H5Fget_info1"); + VERIFY(finfo.super_ext_size, 40,"H5Fget_info1"); + VERIFY(finfo.sohm.hdr_size, 0,"H5Fget_info1"); + VERIFY(finfo.sohm.msgs_info.index_size, 0,"H5Fget_info1"); + VERIFY(finfo.sohm.msgs_info.heap_size, 0,"H5Fget_info1"); + + /* Get the file's creation property list */ + fcpl = H5Fget_create_plist(file); + CHECK(fcpl, FAIL, "H5Fget_create_plist"); + + /* Get the file's version information */ + ret=H5Pget_version(fcpl, &super, &freelist, &stab, &shhdr); + CHECK(ret, FAIL, "H5Pget_version"); + VERIFY(super,2,"H5Pget_version"); + VERIFY(freelist,0,"H5Pget_version"); + VERIFY(stab,0,"H5Pget_version"); + VERIFY(shhdr,0,"H5Pget_version"); + + /* Close FCPL */ + ret=H5Pclose(fcpl); + CHECK(ret, FAIL, "H5Pclose"); + + /* Close file */ + ret=H5Fclose(file); + CHECK(ret, FAIL, "H5Fclose"); +} /* test_deprec */ +#endif /* H5_NO_DEPRECATED_SYMBOLS */ + +/**************************************************************** +** ** test_file(): Main low-level file I/O test routine. ** ****************************************************************/ @@ -2537,6 +3235,12 @@ test_file(void) test_cached_stab_info(); /* Tests that files are created with cached stab info in the superblock */ test_rw_noupdate(); /* Test to ensure that RW permissions don't write the file unless dirtied */ test_userblock_alignment(); /* Tests that files created with a userblock and alignment interact properly */ + test_filespace_sects(); /* Test file free space section information */ + test_filespace_info(); /* Test file creation public routines:H5Pget/set_file_space */ + test_filespace_compatible();/* Test compatibility for file space management */ +#ifndef H5_NO_DEPRECATED_SYMBOLS + test_deprec(); /* Test deprecated routines */ +#endif /* H5_NO_DEPRECATED_SYMBOLS */ } /* test_file() */ @@ -2562,5 +3266,6 @@ cleanup_file(void) HDremove(FILE2); HDremove(FILE3); HDremove(FILE4); + HDremove(FILE5); } diff --git a/test/tmisc.c b/test/tmisc.c index b646a69..41128a2 100644 --- a/test/tmisc.c +++ b/test/tmisc.c @@ -1797,11 +1797,10 @@ test_misc11(void) unsigned sym_ik; /* Symbol table B-tree initial 'K' value */ unsigned istore_ik; /* Indexed storage B-tree initial 'K' value */ unsigned sym_lk; /* Symbol table B-tree leaf 'K' value */ - unsigned super; /* Superblock version # */ - unsigned freelist; /* Free list version # */ - unsigned stab; /* Symbol table entry version # */ - unsigned shhdr; /* Shared object header version # */ unsigned nindexes; /* Shared message number of indexes */ + H5F_info2_t finfo; /* global information about file */ + H5F_file_space_type_t strategy; /* File/free space strategy */ + hsize_t threshold; /* Free-space section threshold */ herr_t ret; /* Generic return value */ /* Output message about test being performed */ @@ -1815,21 +1814,12 @@ test_misc11(void) file= H5Fcreate(MISC11_FILE, H5F_ACC_TRUNC , H5P_DEFAULT, H5P_DEFAULT); CHECK(file, FAIL, "H5Fcreate"); - /* Get the file's dataset creation property list */ - fcpl = H5Fget_create_plist(file); - CHECK(fcpl, FAIL, "H5Fget_create_plist"); - /* Get the file's version information */ - ret=H5Pget_version(fcpl, &super, &freelist, &stab, &shhdr); - CHECK(ret, FAIL, "H5Pget_version"); - VERIFY(super,0,"H5Pget_version"); - VERIFY(freelist,0,"H5Pget_version"); - VERIFY(stab,0,"H5Pget_version"); - VERIFY(shhdr,0,"H5Pget_version"); - - /* Close FCPL */ - ret=H5Pclose(fcpl); - CHECK(ret, FAIL, "H5Pclose"); + ret = H5Fget_info2(file, &finfo); + CHECK(ret, FAIL, "H5Fget_info2"); + VERIFY(finfo.super.version, 0,"H5Fget_info2"); + VERIFY(finfo.free.version, 0,"H5Fget_info2"); + VERIFY(finfo.sohm.version, 0,"H5Fget_info2"); /* Close file */ ret=H5Fclose(file); @@ -1856,6 +1846,9 @@ test_misc11(void) ret=H5Pset_shared_mesg_nindexes(fcpl,MISC11_NINDEXES); CHECK(ret, FAIL, "H5Pset_shared_mesg"); + ret = H5Pset_file_space(fcpl, H5F_FILE_SPACE_VFD, 0); + CHECK(ret, FAIL, "H5Pset_file_space"); + /* Creating a file with the non-default file creation property list should * create a version 1 superblock */ @@ -1868,21 +1861,12 @@ test_misc11(void) ret=H5Pclose(fcpl); CHECK(ret, FAIL, "H5Pclose"); - /* Get the file's dataset creation property list */ - fcpl = H5Fget_create_plist(file); - CHECK(fcpl, FAIL, "H5Fget_create_plist"); - /* Get the file's version information */ - ret=H5Pget_version(fcpl, &super, &freelist, &stab, &shhdr); - CHECK(ret, FAIL, "H5Pget_version"); - VERIFY(super,2,"H5Pget_version"); - VERIFY(freelist,0,"H5Pget_version"); - VERIFY(stab,0,"H5Pget_version"); - VERIFY(shhdr,0,"H5Pget_version"); - - /* Close FCPL */ - ret=H5Pclose(fcpl); - CHECK(ret, FAIL, "H5Pclose"); + ret = H5Fget_info2(file, &finfo); + CHECK(ret, FAIL, "H5Fget_info2"); + VERIFY(finfo.super.version, 2,"H5Fget_info2"); + VERIFY(finfo.free.version, 0,"H5Fget_info2"); + VERIFY(finfo.sohm.version, 0,"H5Fget_info2"); /* Close file */ ret=H5Fclose(file); @@ -1892,17 +1876,16 @@ test_misc11(void) file = H5Fopen(MISC11_FILE, H5F_ACC_RDONLY, H5P_DEFAULT); CHECK(file, FAIL, "H5Fcreate"); - /* Get the file's dataset creation property list */ + /* Get the file's creation property list */ fcpl = H5Fget_create_plist(file); CHECK(fcpl, FAIL, "H5Fget_create_plist"); /* Get the file's version information */ - ret=H5Pget_version(fcpl, &super, &freelist, &stab, &shhdr); - CHECK(ret, FAIL, "H5Pget_version"); - VERIFY(super,2,"H5Pget_version"); - VERIFY(freelist,0,"H5Pget_version"); - VERIFY(stab,0,"H5Pget_version"); - VERIFY(shhdr,0,"H5Pget_version"); + ret = H5Fget_info2(file, &finfo); + CHECK(ret, FAIL, "H5Fget_info2"); + VERIFY(finfo.super.version, 2,"H5Fget_info2"); + VERIFY(finfo.free.version, 0,"H5Fget_info2"); + VERIFY(finfo.sohm.version, 0,"H5Fget_info2"); /* Retrieve all the property values & check them */ ret=H5Pget_userblock(fcpl,&userblock); @@ -1927,6 +1910,11 @@ test_misc11(void) CHECK(ret, FAIL, "H5Pget_shared_mesg_nindexes"); VERIFY(nindexes, MISC11_NINDEXES, "H5Pget_shared_mesg_nindexes"); + ret = H5Pget_file_space(fcpl, &strategy, &threshold); + CHECK(ret, FAIL, "H5Pget_file_space"); + VERIFY(strategy, 4, "H5Pget_file_space"); + VERIFY(threshold, 1, "H5Pget_file_space"); + /* Close file */ ret=H5Fclose(file); CHECK(ret, FAIL, "H5Fclose"); @@ -5162,7 +5150,6 @@ test_misc(void) test_misc27(); /* Test opening file with object that has bad # of object header messages */ test_misc28(); /* Test that chunks are cached appropriately */ - } /* test_misc() */ |