diff options
author | Vailin Choi <vchoi@hdfgroup.org> | 2010-11-15 04:04:28 (GMT) |
---|---|---|
committer | Vailin Choi <vchoi@hdfgroup.org> | 2010-11-15 04:04:28 (GMT) |
commit | 0c589bf7b56738d9c643718be5f12a72a1e39e83 (patch) | |
tree | e226588cafdaa999c835c31859119ba6eca43e85 /test | |
parent | 7c2fbcb03e6ea67cee77acb46a4f38ba8a24d8ff (diff) | |
download | hdf5-0c589bf7b56738d9c643718be5f12a72a1e39e83.zip hdf5-0c589bf7b56738d9c643718be5f12a72a1e39e83.tar.gz hdf5-0c589bf7b56738d9c643718be5f12a72a1e39e83.tar.bz2 |
[svn-r19781] Fix for bug #1930:
1) Move the test for H5D_EXT_PREFIX in links.c to a separate file: links_env.c
2) links_env.c will be used by testlinks_env.sh to test for the environmental
variable H5D_EXT_PREFIX in searching for the external linked file.
Diffstat (limited to 'test')
-rw-r--r-- | test/CMakeLists.txt | 2 | ||||
-rw-r--r-- | test/Makefile.am | 8 | ||||
-rw-r--r-- | test/Makefile.in | 31 | ||||
-rw-r--r-- | test/links.c | 104 | ||||
-rw-r--r-- | test/links_env.c | 192 | ||||
-rw-r--r-- | test/testlinks_env.sh.in | 41 |
6 files changed, 261 insertions, 117 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0d60993..b39de38 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -287,6 +287,7 @@ SET (H5_TESTS err_compat tcheck_version testmeta + links_env ) FOREACH (test ${H5_TESTS}) @@ -398,6 +399,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 9464d46..6993a35 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 cache_tagging \ # '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 @@ -134,6 +134,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.sh include $(top_srcdir)/config/conclude.am diff --git a/test/Makefile.in b/test/Makefile.in index 8748032..b083741 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 = @@ -298,6 +299,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) @@ -399,8 +404,8 @@ SOURCES = $(libh5test_la_SOURCES) accum.c app_ref.c big.c bittests.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_specmetaread.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 \ @@ -414,8 +419,8 @@ DIST_SOURCES = $(libh5test_la_SOURCES) accum.c app_ref.c big.c \ gen_new_mtime.c gen_new_super.c gen_noencoder.c \ gen_nullspace.c gen_sizes_lheap.c gen_specmetaread.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 @@ -723,9 +728,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. @@ -778,7 +783,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.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., @@ -837,6 +842,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) @@ -1016,6 +1023,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) @@ -1126,6 +1136,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/links.c b/test/links.c index 3596f1f..e4aead6 100644 --- a/test/links.c +++ b/test/links.c @@ -2707,110 +2707,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" @@ -14015,7 +13914,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/testlinks_env.sh.in b/test/testlinks_env.sh.in new file mode 100644 index 0000000..9ea85b1 --- /dev/null +++ b/test/testlinks_env.sh.in @@ -0,0 +1,41 @@ +#! /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" +env "HDF5_EXT_PREFIX=.:tmp" links_env +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 |