diff options
author | Vailin Choi <vchoi@hdfgroup.org> | 2010-11-18 19:11:51 (GMT) |
---|---|---|
committer | Vailin Choi <vchoi@hdfgroup.org> | 2010-11-18 19:11:51 (GMT) |
commit | 64a7862ffef32f17f8ec6632c201c99a233f419f (patch) | |
tree | 4a8dc9f80c0b8f6b72a955ba89cad501079034a0 | |
parent | 116391d56a1142b08c4c02eb13ed8e4598af507b (diff) | |
download | hdf5-64a7862ffef32f17f8ec6632c201c99a233f419f.zip hdf5-64a7862ffef32f17f8ec6632c201c99a233f419f.tar.gz hdf5-64a7862ffef32f17f8ec6632c201c99a233f419f.tar.bz2 |
[svn-r19824] 1. Made fixes as in rev #19813 in trunk:
a) Add comments to test_4() in test/external.c about the name "/ link".
b) Fix one memory leak in src/H5Lexternal.c: free memory pointed to by tmp_env_prefix for HDF5_EXT_PREFIX case.
3. Made changes for bug #1930 as in rev #19783, #19781 in trunk.
4. Made corresponding CMake changes as in rev #19782 in trunk.
-rw-r--r-- | MANIFEST | 3 | ||||
-rwxr-xr-x | configure | 3 | ||||
-rw-r--r-- | configure.in | 1 | ||||
-rw-r--r-- | src/H5Lexternal.c | 12 | ||||
-rw-r--r-- | test/CMakeLists.txt | 21 | ||||
-rw-r--r-- | test/Makefile.am | 8 | ||||
-rw-r--r-- | test/Makefile.in | 31 | ||||
-rw-r--r-- | test/external.c | 2 | ||||
-rw-r--r-- | test/links.c | 104 | ||||
-rw-r--r-- | test/links_env.c | 192 | ||||
-rw-r--r-- | test/testfiles/links_env.out | 6 | ||||
-rw-r--r-- | test/testlinks_env.sh.in | 46 |
12 files changed, 307 insertions, 122 deletions
@@ -808,6 +808,7 @@ ./test/external.c ./test/error_test.c ./test/err_compat.c +./test/links_env.c ./test/family_v16_00000.h5 ./test/family_v16_00001.h5 ./test/family_v16_00002.h5 @@ -876,6 +877,7 @@ ./test/tcoords.c ./test/testcheck_version.sh.in ./test/testerror.sh.in +./test/testlinks_env.sh.in ./test/testframe.c ./test/testhdf5.c ./test/testhdf5.h @@ -922,6 +924,7 @@ ./test/testfiles/err_compat_2 ./test/testfiles/error_test_1 ./test/testfiles/error_test_2 +./test/testfiles/links_env.out ./testpar/COPYING ./testpar/Makefile.am @@ -28513,7 +28513,7 @@ if test -n "$TESTPARALLEL"; then fi fi -ac_config_files="$ac_config_files src/libhdf5.settings Makefile src/Makefile test/Makefile test/testcheck_version.sh test/testerror.sh test/H5srcdir_str.h test/testlibinfo.sh testpar/Makefile testpar/testph5.sh perform/Makefile tools/Makefile tools/h5dump/Makefile tools/h5dump/testh5dump.sh tools/h5dump/testh5dumpxml.sh tools/h5ls/testh5ls.sh tools/h5import/Makefile tools/h5diff/Makefile tools/h5jam/Makefile tools/h5jam/testh5jam.sh tools/h5repack/Makefile tools/h5repack/h5repack.sh tools/h5ls/Makefile tools/h5copy/Makefile tools/lib/Makefile tools/misc/Makefile tools/misc/h5cc tools/misc/testh5repart.sh tools/h5stat/testh5stat.sh tools/h5stat/Makefile examples/Makefile examples/run-c-ex.sh examples/testh5cc.sh c++/Makefile c++/src/Makefile c++/src/h5c++ c++/test/Makefile c++/test/H5srcdir_str.h c++/examples/Makefile c++/examples/run-c++-ex.sh c++/examples/testh5c++.sh fortran/Makefile fortran/src/h5fc fortran/src/Makefile fortran/test/Makefile fortran/testpar/Makefile fortran/examples/Makefile fortran/examples/run-fortran-ex.sh fortran/examples/testh5fc.sh hl/Makefile hl/src/Makefile hl/test/Makefile hl/test/H5srcdir_str.h hl/tools/Makefile hl/tools/gif2h5/Makefile hl/examples/Makefile hl/examples/run-hlc-ex.sh hl/c++/Makefile hl/c++/src/Makefile hl/c++/test/Makefile hl/c++/examples/Makefile hl/c++/examples/run-hlc++-ex.sh hl/fortran/Makefile hl/fortran/src/Makefile hl/fortran/test/Makefile hl/fortran/examples/Makefile hl/fortran/examples/run-hlfortran-ex.sh" +ac_config_files="$ac_config_files src/libhdf5.settings Makefile src/Makefile test/Makefile test/testcheck_version.sh test/testerror.sh test/H5srcdir_str.h test/testlibinfo.sh test/testlinks_env.sh testpar/Makefile testpar/testph5.sh perform/Makefile tools/Makefile tools/h5dump/Makefile tools/h5dump/testh5dump.sh tools/h5dump/testh5dumpxml.sh tools/h5ls/testh5ls.sh tools/h5import/Makefile tools/h5diff/Makefile tools/h5jam/Makefile tools/h5jam/testh5jam.sh tools/h5repack/Makefile tools/h5repack/h5repack.sh tools/h5ls/Makefile tools/h5copy/Makefile tools/lib/Makefile tools/misc/Makefile tools/misc/h5cc tools/misc/testh5repart.sh tools/h5stat/testh5stat.sh tools/h5stat/Makefile examples/Makefile examples/run-c-ex.sh examples/testh5cc.sh c++/Makefile c++/src/Makefile c++/src/h5c++ c++/test/Makefile c++/test/H5srcdir_str.h c++/examples/Makefile c++/examples/run-c++-ex.sh c++/examples/testh5c++.sh fortran/Makefile fortran/src/h5fc fortran/src/Makefile fortran/test/Makefile fortran/testpar/Makefile fortran/examples/Makefile fortran/examples/run-fortran-ex.sh fortran/examples/testh5fc.sh hl/Makefile hl/src/Makefile hl/test/Makefile hl/test/H5srcdir_str.h hl/tools/Makefile hl/tools/gif2h5/Makefile hl/examples/Makefile hl/examples/run-hlc-ex.sh hl/c++/Makefile hl/c++/src/Makefile hl/c++/test/Makefile hl/c++/examples/Makefile hl/c++/examples/run-hlc++-ex.sh hl/fortran/Makefile hl/fortran/src/Makefile hl/fortran/test/Makefile hl/fortran/examples/Makefile hl/fortran/examples/run-hlfortran-ex.sh" cat >confcache <<\_ACEOF @@ -29747,6 +29747,7 @@ do "test/testerror.sh") CONFIG_FILES="$CONFIG_FILES test/testerror.sh" ;; "test/H5srcdir_str.h") CONFIG_FILES="$CONFIG_FILES test/H5srcdir_str.h" ;; "test/testlibinfo.sh") CONFIG_FILES="$CONFIG_FILES test/testlibinfo.sh" ;; + "test/testlinks_env.sh") CONFIG_FILES="$CONFIG_FILES test/testlinks_env.sh" ;; "testpar/Makefile") CONFIG_FILES="$CONFIG_FILES testpar/Makefile" ;; "testpar/testph5.sh") CONFIG_FILES="$CONFIG_FILES testpar/testph5.sh" ;; "perform/Makefile") CONFIG_FILES="$CONFIG_FILES perform/Makefile" ;; diff --git a/configure.in b/configure.in index f6342d7..794c664 100644 --- a/configure.in +++ b/configure.in @@ -4390,6 +4390,7 @@ AC_CONFIG_FILES([src/libhdf5.settings test/testerror.sh test/H5srcdir_str.h test/testlibinfo.sh + test/testlinks_env.sh testpar/Makefile testpar/testph5.sh perform/Makefile diff --git a/src/H5Lexternal.c b/src/H5Lexternal.c index 9cab8cf..4700fee 100644 --- a/src/H5Lexternal.c +++ b/src/H5Lexternal.c @@ -188,6 +188,9 @@ done: * Otherwise, the file access property retrieved from H5Pget_elink_fapl() * is used to H5F_open() the target file. * + * Vailin Choi; Nov 2010 + * Free memory pointed to by tmp_env_prefix for HDF5_EXT_PREFIX case. + * *------------------------------------------------------------------------- */ static hid_t @@ -343,9 +346,9 @@ H5L_extern_traverse(const char UNUSED *link_name, hid_t cur_group, char *env_prefix; if(NULL != (env_prefix = HDgetenv("HDF5_EXT_PREFIX"))) { - char *tmp_env_prefix; + char *tmp_env_prefix, *saved_env; - if(NULL == (tmp_env_prefix = H5MM_strdup(env_prefix))) + if(NULL == (saved_env = tmp_env_prefix = H5MM_strdup(env_prefix))) HGOTO_ERROR(H5E_LINK, H5E_NOSPACE, FAIL, "memory allocation failed") while((tmp_env_prefix) && (*tmp_env_prefix)) { @@ -353,8 +356,10 @@ H5L_extern_traverse(const char UNUSED *link_name, hid_t cur_group, out_prefix_name = H5L_getenv_prefix_name(&tmp_env_prefix/*in,out*/); if(out_prefix_name && (*out_prefix_name)) { - if(H5L_build_name(out_prefix_name, temp_file_name, &full_name/*out*/) < 0) + if(H5L_build_name(out_prefix_name, temp_file_name, &full_name/*out*/) < 0) { + saved_env = (char *)H5MM_xfree(saved_env); HGOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "can't prepend prefix to filename") + } ext_file = H5F_open(full_name, intent, H5P_FILE_CREATE_DEFAULT, fapl_id, H5AC_dxpl_id); full_name = (char *)H5MM_xfree(full_name); @@ -363,6 +368,7 @@ H5L_extern_traverse(const char UNUSED *link_name, hid_t cur_group, H5E_clear_stack(NULL); } /* end if */ } /* end while */ + saved_env = (char *)H5MM_xfree(saved_env); } /* end if */ } /* end if */ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 1bb1b48..158110b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -55,6 +55,7 @@ SET (HDF5_REFERENCE_FILES err_compat_2 error_test_1 error_test_2 + links_env.out ) FOREACH (ref_file ${HDF5_REFERENCE_FILES}) @@ -283,6 +284,7 @@ SET (H5_TESTS #err_compat tcheck_version testmeta + #links_env ) FOREACH (test ${H5_TESTS}) @@ -362,6 +364,24 @@ ADD_TEST (NAME error_test COMMAND "${CMAKE_COMMAND}" -P "${HDF5_RESOURCES_DIR}/runTest.cmake" ) +#-- Adding test for links_env +ADD_EXECUTABLE (links_env ${HDF5_TEST_SOURCE_DIR}/links_env.c) +H5_NAMING (links_env) +TARGET_WIN_PROPERTIES (links_env) +TARGET_LINK_LIBRARIES (links_env ${HDF5_LIB_TARGET} ${HDF5_TEST_LIB_TARGET}) + +ADD_TEST (NAME links_env COMMAND "${CMAKE_COMMAND}" + -D "TEST_PROGRAM=$<TARGET_FILE:links_env>" + -D "TEST_ARGS:STRING=" + -D "TEST_ENV_VAR:STRING=HDF5_EXT_PREFIX" + -D "TEST_ENV_VALUE:STRING=.:tmp" + -D "TEST_EXPECT=0" + -D "TEST_OUTPUT=links_env.txt" + -D "TEST_REFERENCE=links_env.out" + -D "TEST_FOLDER=${PROJECT_BINARY_DIR}" + -P "${HDF5_RESOURCES_DIR}/runTest.cmake" +) + IF (HDF5_TEST_VFD) SET (VFD_LIST @@ -421,6 +441,7 @@ IF (HDF5_TEST_VFD) err_compat tcheck_version testmeta + links_env ) IF (DIRECT_VFD) diff --git a/test/Makefile.am b/test/Makefile.am index b37ad53..4493f4f 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -24,9 +24,9 @@ include $(top_srcdir)/config/commence.am INCLUDES=-I$(top_srcdir)/src -I$(top_builddir)/src # Test script for error_test and err_compat -TEST_SCRIPT = testerror.sh testlibinfo.sh testcheck_version.sh +TEST_SCRIPT = testerror.sh testlibinfo.sh testcheck_version.sh testlinks_env.sh check_SCRIPTS = $(TEST_SCRIPT) -SCRIPT_DEPEND = error_test$(EXEEXT) err_compat$(EXEEXT) +SCRIPT_DEPEND = error_test$(EXEEXT) err_compat$(EXEEXT) links_env$(EXEEXT) # These are our main targets. They should be listed in the order to be @@ -50,7 +50,7 @@ TEST_PROG=testhdf5 lheap ohdr stab gheap cache cache_api \ # 'make check' doesn't run them directly, so they are not included in TEST_PROG. # Also build testmeta, which is used for timings test. It builds quickly, # and this lets automake keep all its test programs in one place. -check_PROGRAMS=$(TEST_PROG) error_test err_compat tcheck_version testmeta +check_PROGRAMS=$(TEST_PROG) error_test err_compat tcheck_version testmeta links_env # These programs generate test files for the tests. They don't need to be @@ -133,6 +133,6 @@ testhdf5_SOURCES=testhdf5.c tarray.c tattr.c tchecksum.c tconfig.c tfile.c \ tvlstr.c tvltypes.c # Temporary files. -DISTCLEANFILES=testerror.sh testlibinfo.sh testcheck_version.sh +DISTCLEANFILES=testerror.sh testlibinfo.sh testcheck_version.sh testlinks_env.sh include $(top_srcdir)/config/conclude.am diff --git a/test/Makefile.in b/test/Makefile.in index 0d996e7..c8ebf75 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -55,10 +55,11 @@ host_triplet = @host@ DIST_COMMON = $(srcdir)/H5srcdir_str.h.in $(srcdir)/Makefile.am \ $(srcdir)/Makefile.in $(srcdir)/testcheck_version.sh.in \ $(srcdir)/testerror.sh.in $(srcdir)/testlibinfo.sh.in \ - $(top_srcdir)/config/commence.am \ + $(srcdir)/testlinks_env.sh.in $(top_srcdir)/config/commence.am \ $(top_srcdir)/config/conclude.am COPYING check_PROGRAMS = $(am__EXEEXT_1) error_test$(EXEEXT) \ - err_compat$(EXEEXT) tcheck_version$(EXEEXT) testmeta$(EXEEXT) + err_compat$(EXEEXT) tcheck_version$(EXEEXT) testmeta$(EXEEXT) \ + links_env$(EXEEXT) @BUILD_ALL_CONDITIONAL_TRUE@noinst_PROGRAMS = $(am__EXEEXT_2) TESTS = $(check_PROGRAMS) $(check_SCRIPTS) subdir = test @@ -69,7 +70,7 @@ am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ mkinstalldirs = $(SHELL) $(top_srcdir)/bin/mkinstalldirs CONFIG_HEADER = $(top_builddir)/src/H5config.h CONFIG_CLEAN_FILES = testcheck_version.sh testerror.sh H5srcdir_str.h \ - testlibinfo.sh + testlibinfo.sh testlinks_env.sh CONFIG_CLEAN_VPATH_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) libh5test_la_LIBADD = @@ -280,6 +281,10 @@ links_SOURCES = links.c links_OBJECTS = links.$(OBJEXT) links_LDADD = $(LDADD) links_DEPENDENCIES = libh5test.la $(LIBHDF5) +links_env_SOURCES = links_env.c +links_env_OBJECTS = links_env.$(OBJEXT) +links_env_LDADD = $(LDADD) +links_env_DEPENDENCIES = libh5test.la $(LIBHDF5) mf_SOURCES = mf.c mf_OBJECTS = mf.$(OBJEXT) mf_LDADD = $(LDADD) @@ -380,8 +385,8 @@ SOURCES = $(libh5test_la_SOURCES) accum.c app_ref.c big.c bittests.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_sizes_lheap.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 \ + istore.c lheap.c links.c links_env.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 DIST_SOURCES = $(libh5test_la_SOURCES) accum.c app_ref.c big.c \ @@ -394,8 +399,8 @@ DIST_SOURCES = $(libh5test_la_SOURCES) accum.c app_ref.c big.c \ gen_new_group.c gen_new_mtime.c gen_new_super.c \ gen_noencoder.c gen_nullspace.c gen_sizes_lheap.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 \ + links.c links_env.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 @@ -704,9 +709,9 @@ CHECK_CLEANFILES = *.chkexe *.chklog *.clog accum.h5 cmpd_dset.h5 \ INCLUDES = -I$(top_srcdir)/src -I$(top_builddir)/src # Test script for error_test and err_compat -TEST_SCRIPT = testerror.sh testlibinfo.sh testcheck_version.sh +TEST_SCRIPT = testerror.sh testlibinfo.sh testcheck_version.sh testlinks_env.sh check_SCRIPTS = $(TEST_SCRIPT) -SCRIPT_DEPEND = error_test$(EXEEXT) err_compat$(EXEEXT) +SCRIPT_DEPEND = error_test$(EXEEXT) err_compat$(EXEEXT) links_env$(EXEEXT) # These are our main targets. They should be listed in the order to be # executed, generally most specific tests to least specific tests. @@ -758,7 +763,7 @@ testhdf5_SOURCES = testhdf5.c tarray.c tattr.c tchecksum.c tconfig.c tfile.c \ # Temporary files. -DISTCLEANFILES = testerror.sh testlibinfo.sh testcheck_version.sh +DISTCLEANFILES = testerror.sh testlibinfo.sh testcheck_version.sh testlinks_env.sh # Automake needs to be taught how to build lib, progs, and tests targets. # These will be filled in automatically for the most part (e.g., @@ -817,6 +822,8 @@ H5srcdir_str.h: $(top_builddir)/config.status $(srcdir)/H5srcdir_str.h.in cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ testlibinfo.sh: $(top_builddir)/config.status $(srcdir)/testlibinfo.sh.in cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ +testlinks_env.sh: $(top_builddir)/config.status $(srcdir)/testlinks_env.sh.in + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ clean-noinstLTLIBRARIES: -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES) @@ -984,6 +991,9 @@ lheap$(EXEEXT): $(lheap_OBJECTS) $(lheap_DEPENDENCIES) links$(EXEEXT): $(links_OBJECTS) $(links_DEPENDENCIES) @rm -f links$(EXEEXT) $(LINK) $(links_OBJECTS) $(links_LDADD) $(LIBS) +links_env$(EXEEXT): $(links_env_OBJECTS) $(links_env_DEPENDENCIES) + @rm -f links_env$(EXEEXT) + $(LINK) $(links_env_OBJECTS) $(links_env_LDADD) $(LIBS) mf$(EXEEXT): $(mf_OBJECTS) $(mf_DEPENDENCIES) @rm -f mf$(EXEEXT) $(LINK) $(mf_OBJECTS) $(mf_LDADD) $(LIBS) @@ -1090,6 +1100,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/istore.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lheap.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/links.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/links_env.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mf.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mount.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mtime.Po@am__quote@ diff --git a/test/external.c b/test/external.c index 7c859d4..484236a 100644 --- a/test/external.c +++ b/test/external.c @@ -888,7 +888,7 @@ test_4 (hid_t fapl) if((fid = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0) goto error; - /* Open the external link */ + /* Open the external link which is "/ link" as created previously via H5Lcreate_external() */ if((xid = H5Gopen2(fid, "/ link", H5P_DEFAULT)) < 0) goto error; diff --git a/test/links.c b/test/links.c index 650f9e8..a1718ed 100644 --- a/test/links.c +++ b/test/links.c @@ -2724,110 +2724,9 @@ external_link_dangling(hid_t fapl, hbool_t new_format) return -1; } /* end external_link_dangling() */ - - -/*------------------------------------------------------------------------- - * Function: external_link_env: test 1 - * - * Purpose: - * 1. target link: "extlinks1" - * 2. main file: "extlinks0" - * 3. target file: "tmp/extlinks1" - * 4. The environment variable "HDF5_EXT_PREFIX" should be set to ".:tmp" - * Should be able to access the target file in tmp directory through searching - * the pathnames set in HDF5_EXT_PREFIX. - * This test will be skipped if HDF5_EXT_PREFIX is not set as expected. - * - * - * Return: Success: 0 - * Failure: -1 - * - * Programmer: Vailin Choi - * Feb. 20, 2008 - * - * Modifications: - * - *------------------------------------------------------------------------- - */ -static int -external_link_env(hid_t fapl, hbool_t new_format) -{ - hid_t fid = (-1); /* File ID */ - hid_t gid = (-1); /* Group IDs */ - const char *envval = NULL; - - char filename1[NAME_BUF_SIZE], - filename2[NAME_BUF_SIZE], - filename3[NAME_BUF_SIZE]; - - if(new_format) - TESTING("external links via environment variable (w/new group format)") - else - TESTING("external links via environment variable") - - if ((envval = HDgetenv("HDF5_EXT_PREFIX")) == NULL) - envval = "nomatch"; - if (HDstrcmp(envval, ".:tmp")) { - SKIPPED(); - return(0); - } - - /* set up name for main file:"extlinks0" */ - h5_fixname(FILENAME[12], fapl, filename1, sizeof filename1); - /* set up name for external linked target file: "extlinks1" */ - h5_fixname(FILENAME[14], fapl, filename2, sizeof filename2); - - if(HDmkdir(TMPDIR, (mode_t)0755) < 0 && errno != EEXIST) - TEST_ERROR - - /* set up name for target file: "tmp/extlinks1" */ - h5_fixname(FILENAME[15], fapl, filename3, sizeof filename3); - - /* Create the target file */ - if((fid=H5Fcreate(filename3, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR - if((gid=H5Gcreate2(fid, "A", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR - - /* closing for target file */ - if(H5Gclose(gid) < 0) TEST_ERROR - if(H5Fclose(fid) < 0) TEST_ERROR - - - /* Create the main file */ - if((fid=H5Fcreate(filename1, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR - - /* Create external link to target file */ - if(H5Lcreate_external(filename2, "/A", fid, "ext_link", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR - - /* Open object through external link */ - H5E_BEGIN_TRY { - gid = H5Gopen2(fid, "ext_link", H5P_DEFAULT); - } H5E_END_TRY; - - /* should be able to find the target file from pathnames set via environment variable */ - if (gid < 0) { - H5_FAILED(); - puts(" Should have found the file in tmp directory."); - goto error; - } - - /* closing for main file */ - if(H5Gclose(gid) < 0) TEST_ERROR - if(H5Fclose(fid) < 0) TEST_ERROR - - PASSED(); - return 0; - - error: - H5E_BEGIN_TRY { - H5Gclose (gid); - H5Fclose (fid); - } H5E_END_TRY; - return -1; -} /* end external_link_env() */ - /*------------------------------------------------------------------------- - * Function: external_link_prefix: test 2 + * Function: external_link_prefix * * Purpose: 1. target link: "extlinks2" * 2. main file: "extlinks0" @@ -14058,7 +13957,6 @@ main(void) nerrors += external_link_strong(my_fapl, new_format) < 0 ? 1 : 0; /* tests for external link */ - nerrors += external_link_env(my_fapl, new_format) < 0 ? 1 : 0; nerrors += external_link_prefix(my_fapl, new_format) < 0 ? 1 : 0; nerrors += external_link_abs_mainpath(my_fapl, new_format) < 0 ? 1 : 0; nerrors += external_link_rel_mainpath(my_fapl, new_format) < 0 ? 1 : 0; diff --git a/test/links_env.c b/test/links_env.c new file mode 100644 index 0000000..c792386 --- /dev/null +++ b/test/links_env.c @@ -0,0 +1,192 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * 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. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* + * Purpose: Tests hard, soft (symbolic) & external links. + */ + +#define H5G_PACKAGE +#define H5G_TESTING + +#include "h5test.h" +#include "H5srcdir.h" +#include "H5Gpkg.h" /* Groups */ +#include "H5Iprivate.h" /* IDs */ +#include "H5Lprivate.h" /* Links */ + +#ifdef H5_VMS +#define TMPDIR "[.tmp]" +#else /* H5_VMS */ +#define TMPDIR "tmp/" +#endif /* H5_VMS */ +#define NAME_BUF_SIZE 1024 + +const char *FILENAME[] = { + "extlinks_env0", /* 0: main file */ + "extlinks_env1", /* 1: target file */ + TMPDIR "extlinks_env1", /* 2 */ + NULL +}; + +static int external_link_env(hid_t fapl, hbool_t new_format); + + +/*------------------------------------------------------------------------- + * Function: external_link_env (moved from links.c) + * + * Purpose: Verify that the target file is found successfully in "tmp" directory + * via searching the pathnames set in the environment variable HDF5_EXT_PREFIX. + * 1. Target link: "extlinks_env1" + * 2. Main file: "extlinks_env0" + * 3. Target file is created in: "tmp/extlinks_env1" + * 4. The environment variable "HDF5_EXT_PREFIX" is set to ".:tmp" + * + * Return: Success: 0 + * Failure: -1 + * + * Programmer: Vailin Choi + * Feb. 20, 2008 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static int +external_link_env(hid_t fapl, hbool_t new_format) +{ + hid_t fid = (-1); /* File ID */ + hid_t gid = (-1); /* Group IDs */ + const char *envval = NULL; /* Pointer to environment variable */ + char filename1[NAME_BUF_SIZE], + filename2[NAME_BUF_SIZE], + filename3[NAME_BUF_SIZE]; /* Holders for filename */ + + if(new_format) + TESTING("external links via environment variable (w/new group format)") + else + TESTING("external links via environment variable") + + if ((envval = HDgetenv("HDF5_EXT_PREFIX")) == NULL) + envval = "nomatch"; + if (HDstrcmp(envval, ".:tmp")) TEST_ERROR + + /* Set up name for main file:"extlinks_env0" */ + h5_fixname(FILENAME[0], fapl, filename1, sizeof filename1); + + /* Set up name for external linked target file: "extlinks_env1" */ + h5_fixname(FILENAME[1], fapl, filename2, sizeof filename2); + + /* Create "tmp" directory */ + if(HDmkdir(TMPDIR, (mode_t)0755) < 0 && errno != EEXIST) + TEST_ERROR + + /* Set up name (location) for the target file: "tmp/extlinks1" */ + h5_fixname(FILENAME[2], fapl, filename3, sizeof filename3); + + /* Create the target file in "tmp" directory */ + if((fid=H5Fcreate(filename3, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + if((gid=H5Gcreate2(fid, "A", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR + + /* Closing for target file */ + if(H5Gclose(gid) < 0) TEST_ERROR + if(H5Fclose(fid) < 0) TEST_ERROR + + + /* Create the main file */ + if((fid=H5Fcreate(filename1, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + + /* Create external link to target file */ + if(H5Lcreate_external(filename2, "/A", fid, "ext_link", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR + + /* Open object through external link */ + H5E_BEGIN_TRY { + gid = H5Gopen2(fid, "ext_link", H5P_DEFAULT); + } H5E_END_TRY; + + /* Should be able to find the target file from pathnames set via HDF5_EXT_PREFIX */ + if (gid < 0) { + H5_FAILED(); + puts(" Should have found the file in tmp directory."); + goto error; + } + + /* closing for main file */ + if(H5Gclose(gid) < 0) TEST_ERROR + if(H5Fclose(fid) < 0) TEST_ERROR + + PASSED(); + return 0; + + error: + H5E_BEGIN_TRY { + H5Gclose (gid); + H5Fclose (fid); + } H5E_END_TRY; + return -1; +} /* end external_link_env() */ + + +/*------------------------------------------------------------------------- + * Function: main + * + * Purpose: Test external link with environment variable HDF5_EXT_PREFIX + * + * Return: Success: exit(0) + * Failure: exit(non-zero) + * + * Programmer: Vailin Choi; Nov 2010 + * + *------------------------------------------------------------------------- + */ +int +main(void) +{ + hid_t fapl; /* File access property lists */ + int nerrors = 0; /* Error from tests */ + const char *env_h5_drvr; /* File Driver value from environment */ + + env_h5_drvr = HDgetenv("HDF5_DRIVER"); + if(env_h5_drvr == NULL) + env_h5_drvr = "nomatch"; + + h5_reset(); + fapl = h5_fileaccess(); + + nerrors += external_link_env(fapl, FALSE) < 0 ? 1 : 0; + + /* Set the "use the latest version of the format" bounds for creating objects in the file */ + if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) TEST_ERROR + + nerrors += external_link_env(fapl, TRUE) < 0 ? 1 : 0; + + h5_cleanup(FILENAME, fapl); + + /* Results */ + if(nerrors) { + printf("***** %d External Link (HDF5_EXT_PREFIX) test%s FAILED! *****\n", + nerrors, 1 == nerrors ? "" : "s"); + exit(1); + } + printf("All external Link (HDF5_EXT_PREFIX) tests passed.\n"); + + /* clean up tmp directory created by external link tests */ + HDrmdir(TMPDIR); + + return 0; + +error: + puts("*** TESTS FAILED ***"); + return 1; +} diff --git a/test/testfiles/links_env.out b/test/testfiles/links_env.out new file mode 100644 index 0000000..3ca9b99 --- /dev/null +++ b/test/testfiles/links_env.out @@ -0,0 +1,6 @@ +############################# +Expected output for links_env +############################# +Testing external links via environment variable PASSED +Testing external links via environment variable (w/new group format) PASSED +All external Link (HDF5_EXT_PREFIX) tests passed. diff --git a/test/testlinks_env.sh.in b/test/testlinks_env.sh.in new file mode 100644 index 0000000..e71dfc8 --- /dev/null +++ b/test/testlinks_env.sh.in @@ -0,0 +1,46 @@ +#! /bin/sh +# +# 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. +# +# Test for external link with environment variable: HDF5_EXT_PREFIX + +nerrors=0 + +# The build (current) directory might be different than the source directory. +if test -z "$srcdir"; then + srcdir=. +fi + +############################################################################## +############################################################################## +### T H E T E S T S ### +############################################################################## +############################################################################## + +# test for external links with HDF5_EXT_PREFIX +echo "Testing external link with HDF5_EXT_PREFIX" +TEST_NAME=links_env # The test name +TEST_BIN=`pwd`/$TEST_NAME # The path of the test binary +ENVCMD="env HDF5_EXT_PREFIX=.:tmp" # The environment variable & value +# +# Run the test +$ENVCMD $TEST_BIN +exitcode=$? +if [ $exitcode -eq 0 ]; then + echo "Test for HDF5_EXT_PREFIX PASSED" + else + nerrors="`expr $nerrors + 1`" + echo "***Error encountered for HDF5_EXT_PREFIX test***" +fi +exit $nerrors |