From 5345e2394effb206c1f76c95a1eddb937e34a316 Mon Sep 17 00:00:00 2001 From: Jonathan Kim Date: Tue, 9 Mar 2010 16:46:00 -0500 Subject: =?UTF-8?q?[svn-r18400]=20Purpose:=20=20=20=20=20add=20test=20case?= =?UTF-8?q?s=20for=20h5copy=20-=20copy=20external=20links=20with/without?= =?UTF-8?q?=20=E2=80=98=E2=80=93f=20ext=E2=80=99=20=20=20=20=20option=20(r?= =?UTF-8?q?elate=20to=20bug=201733)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Description: merged from hdf5 trunk (r18398 and r18399) Tested: jam --- MANIFEST | 3 + tools/h5copy/h5copygentest.c | 179 ++++++++++++++++++++++ tools/h5copy/testfiles/h5copy_extlinks_src.h5 | Bin 0 -> 2184 bytes tools/h5copy/testfiles/h5copy_extlinks_src.out.ls | 42 +++++ tools/h5copy/testfiles/h5copy_extlinks_trg.h5 | Bin 0 -> 2168 bytes tools/h5copy/testh5copy.sh | 61 +++++++- 6 files changed, 284 insertions(+), 1 deletion(-) create mode 100644 tools/h5copy/testfiles/h5copy_extlinks_src.h5 create mode 100644 tools/h5copy/testfiles/h5copy_extlinks_src.out.ls create mode 100644 tools/h5copy/testfiles/h5copy_extlinks_trg.h5 diff --git a/MANIFEST b/MANIFEST index a631dd0..7ea7193 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1594,6 +1594,9 @@ ./tools/h5copy/testfiles/h5copytst.out.ls ./tools/h5copy/testfiles/h5copy_ref.h5 ./tools/h5copy/testfiles/h5copy_ref.out.ls +./tools/h5copy/testfiles/h5copy_extlinks_src.h5 +./tools/h5copy/testfiles/h5copy_extlinks_trg.h5 +./tools/h5copy/testfiles/h5copy_extlinks_src.out.ls # test files for h5mkgrp ./tools/testfiles/h5mkgrp_help.ls diff --git a/tools/h5copy/h5copygentest.c b/tools/h5copy/h5copygentest.c index cd17295..42bc3cd 100644 --- a/tools/h5copy/h5copygentest.c +++ b/tools/h5copy/h5copygentest.c @@ -24,6 +24,8 @@ /* HDF file names */ #define HDF_FILE1 "h5copytst.h5" #define HDF_FILE2 "h5copy_ref.h5" +#define HDF_EXT_SRC_FILE "h5copy_extlinks_src.h5" +#define HDF_EXT_TRG_FILE "h5copy_extlinks_trg.h5" /* objects in HDF_FILE1 */ #define DATASET_SIMPLE "simple" @@ -704,6 +706,182 @@ out: } /*------------------------------------------------------------------------- + * Function: gen_extlink_trg + * + * Purpose: generate target external link objs + * + * Programmer: Jonathan Kim (March 03, 2010) + *------------------------------------------------------------------------*/ +static herr_t gen_extlink_trg(hid_t loc_id) +{ + hid_t gid=0, tid=0; + int status; + herr_t ret = SUCCEED; + + /*----------------------------------------------------------------------- + * Groups + *------------------------------------------------------------------------*/ + /*-------------- + * target file */ + gid = H5Gcreate2(loc_id, "group", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + if (gid < 0) + { + fprintf(stderr, "Error: %s %d> H5Gcreate2 failed.\n", __FUNCTION__, __LINE__); + ret = FAIL; + goto out; + } + + /*-------------- + * add dataset */ + gent_simple(loc_id); + + /*-------------------- + * add named datatype + */ + tid = H5Tcopy(H5T_NATIVE_INT); + status = H5Tcommit2(loc_id, "datatype", tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + if (status < 0) + { + fprintf(stderr, "Error: %s %d> H5Tcommit2 failed.\n", __FUNCTION__, __LINE__); + ret = FAIL; + goto out; + } + +out: + if(gid > 0) + H5Gclose(gid); + if(tid > 0) + H5Tclose(tid); + + return ret; +} + +/*------------------------------------------------------------------------- + * Function: gen_extlink_src + * + * Purpose: generate source external link objs + * + * Programmer: Jonathan Kim (March 03, 2010) + *------------------------------------------------------------------------*/ +static herr_t gen_extlink_src(hid_t loc_id) +{ + hid_t gid=0; + int status; + herr_t ret = SUCCEED; + + /*----------------------------------------------------------------------- + * Groups + *------------------------------------------------------------------------*/ + gid = H5Gcreate2(loc_id, "/group_ext", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + if (gid < 0) + { + fprintf(stderr, "Error: %s %d> H5Gcreate2 failed.\n", __FUNCTION__, __LINE__); + ret = FAIL; + goto out; + } + + /*----------------------------------------------------------------------- + * External links + *------------------------------------------------------------------------*/ + /* link to dataset */ + status = H5Lcreate_external(HDF_EXT_TRG_FILE, "/simple", gid, "extlink_dset", H5P_DEFAULT, H5P_DEFAULT); + if (status < 0) + { + fprintf(stderr, "Error: %s %d> H5Lcreate_external failed.\n", __FUNCTION__, __LINE__); + ret = FAIL; + goto out; + } + + /* link to group */ + status = H5Lcreate_external(HDF_EXT_TRG_FILE, "/group", gid, "extlink_grp", H5P_DEFAULT, H5P_DEFAULT); + if (status < 0) + { + fprintf(stderr, "Error: %s %d> H5Lcreate_external failed.\n", __FUNCTION__, __LINE__); + ret = FAIL; + goto out; + } + + /* link to datatype */ + status = H5Lcreate_external(HDF_EXT_TRG_FILE, "/datatype", gid, "extlink_datatype", H5P_DEFAULT, H5P_DEFAULT); + if (status < 0) + { + fprintf(stderr, "Error: %s %d> H5Lcreate_external failed.\n", __FUNCTION__, __LINE__); + ret = FAIL; + goto out; + } + + /* dangling link - no obj*/ + status = H5Lcreate_external(HDF_EXT_TRG_FILE, "notyet", gid, "extlink_notyet1", H5P_DEFAULT, H5P_DEFAULT); + if (status < 0) + { + fprintf(stderr, "Error: %s %d> H5Lcreate_external failed.\n", __FUNCTION__, __LINE__); + ret = FAIL; + goto out; + } + + /* dangling link - no file */ + status = H5Lcreate_external("notyet_file.h5", "notyet", gid, "extlink_notyet2", H5P_DEFAULT, H5P_DEFAULT); + if (status < 0) + { + fprintf(stderr, "Error: %s %d> H5Lcreate_external failed.\n", __FUNCTION__, __LINE__); + ret = FAIL; + goto out; + } + +out: + if(gid > 0) + H5Gclose(gid); + + return ret; +} + +/*------------------------------------------------------------------------- + * Function: Test_Extlink_Copy + * + * Purpose: gerenate external link files + * + *------------------------------------------------------------------------*/ +static void Test_Extlink_Copy() +{ + hid_t fid1=0; + hid_t fid2=0; + herr_t status; + + fid1 = H5Fcreate (HDF_EXT_SRC_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + if (fid1 < 0) + { + fprintf(stderr, "Error: %s> H5Fcreate failed.\n", HDF_EXT_SRC_FILE); + goto out; + } + + fid2 = H5Fcreate (HDF_EXT_TRG_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + if (fid2 < 0) + { + fprintf(stderr, "Error: %s> H5Fcreate failed.\n", HDF_EXT_TRG_FILE); + goto out; + } + + /* add links to source external link file */ + status = gen_extlink_src(fid1); + if (status < 0) + fprintf(stderr, "Error: %s> gen_extlink_src failed.\n", HDF_EXT_SRC_FILE); + + /* add objs to target external link file */ + status = gen_extlink_trg(fid2); + if (status < 0) + fprintf(stderr, "Error: %s> gen_extlink_trg failed.\n", HDF_EXT_TRG_FILE); + +out: + /*----------------------------------------------------------------------- + * Close + *------------------------------------------------------------------------*/ + if(fid1 > 0) + H5Fclose(fid1); + if(fid2 > 0) + H5Fclose(fid2); +} + +/*------------------------------------------------------------------------- * Function: main * *------------------------------------------------------------------------- @@ -713,6 +891,7 @@ int main(void) { Test_Obj_Copy(); Test_Ref_Copy(); + Test_Extlink_Copy(); return 0; } diff --git a/tools/h5copy/testfiles/h5copy_extlinks_src.h5 b/tools/h5copy/testfiles/h5copy_extlinks_src.h5 new file mode 100644 index 0000000..7b8621e Binary files /dev/null and b/tools/h5copy/testfiles/h5copy_extlinks_src.h5 differ diff --git a/tools/h5copy/testfiles/h5copy_extlinks_src.out.ls b/tools/h5copy/testfiles/h5copy_extlinks_src.out.ls new file mode 100644 index 0000000..a9927f8 --- /dev/null +++ b/tools/h5copy/testfiles/h5copy_extlinks_src.out.ls @@ -0,0 +1,42 @@ +############################# +Expected output for 'h5ls ./testfiles/h5copy_extlinks_src.out.h5' +############################# +Opened "./testfiles/h5copy_extlinks_src.out.h5" with sec2 driver. +/ Group + Location: 1:96 + Links: 1 +/copy1_dset Dataset {6/6} + Location: 1:800 + Links: 1 + Storage:
+ Type: 32-bit little-endian integer +/copy1_group Group + Location: 1:4344 + Links: 1 +/copy1_group/extlink_datatype External Link {h5copy_extlinks_trg.h5//datatype} +/copy1_group/extlink_dset External Link {h5copy_extlinks_trg.h5//simple} +/copy1_group/extlink_grp External Link {h5copy_extlinks_trg.h5//group} +/copy1_group/extlink_notyet1 External Link {h5copy_extlinks_trg.h5//notyet} +/copy1_group/extlink_notyet2 External Link {notyet_file.h5//notyet} +/copy2_dset Dataset {6/6} + Location: 1:4216 + Links: 1 + Storage:
+ Type: 32-bit little-endian integer +/copy2_group Group + Location: 1:4712 + Links: 1 +/copy2_group/extlink_datatype Type + Location: 1:5912 + Links: 1 + Type: shared-1:5912 32-bit little-endian integer +/copy2_group/extlink_dset Dataset {6/6} + Location: 1:5080 + Links: 1 + Storage:
+ Type: 32-bit little-endian integer +/copy2_group/extlink_grp Group + Location: 1:5872 + Links: 1 +/copy2_group/extlink_notyet1 External Link {h5copy_extlinks_trg.h5//notyet} +/copy2_group/extlink_notyet2 External Link {notyet_file.h5//notyet} diff --git a/tools/h5copy/testfiles/h5copy_extlinks_trg.h5 b/tools/h5copy/testfiles/h5copy_extlinks_trg.h5 new file mode 100644 index 0000000..3a0242d Binary files /dev/null and b/tools/h5copy/testfiles/h5copy_extlinks_trg.h5 differ diff --git a/tools/h5copy/testh5copy.sh b/tools/h5copy/testh5copy.sh index bc19505..d8dfe52 100644 --- a/tools/h5copy/testh5copy.sh +++ b/tools/h5copy/testh5copy.sh @@ -26,6 +26,8 @@ EXIT_FAILURE=1 # Test files HDF_FILE1=h5copytst.h5 HDF_FILE2=h5copy_ref.h5 +HDF_EXT_SRC_FILE=h5copy_extlinks_src.h5 +HDF_EXT_TRG_FILE=h5copy_extlinks_trg.h5 H5COPY=h5copy # The tool name H5COPY_BIN=`pwd`/$H5COPY # The path of the tool binary @@ -49,6 +51,12 @@ OUTDIR=./testfiles test -d $OUTDIR || mkdir $OUTDIR +# Print a "SKIP" message +SKIP() { + TESTING $H5COPY $@ + echo " -SKIP-" +} + # Print a line-line message left justified in a field of 70 characters # beginning with the word "Testing". TESTING() @@ -313,7 +321,6 @@ COPY_REFERENCES() rm -f $FILEOUT echo "Test copying object and region references" - echo "TOOLTEST -f ref -i $TESTFILE -o $FILEOUT -v -s / -d /COPY" TOOLTEST -f ref -i $TESTFILE -o $FILEOUT -v -s / -d /COPY # Verify that the file created above is correct @@ -326,12 +333,64 @@ COPY_REFERENCES() fi } +# Copy external links. +# adding to the destination file each time compare the result +# +# Assumed arguments: +# +COPY_EXT_LINKS() +{ + TESTFILE="$INDIR/$HDF_EXT_SRC_FILE" + FILEOUT="$OUTDIR/`basename $HDF_EXT_SRC_FILE .h5`.out.h5" + + # Remove any output file left over from previous test run + rm -f $FILEOUT + + echo "Test copying external link directly without -f ext" + TOOLTEST -v -i $TESTFILE -o $FILEOUT -s /group_ext/extlink_dset -d /copy1_dset + + echo "Test copying external link directly with -f ext" + TOOLTEST -f ext -i $TESTFILE -o $FILEOUT -v -s /group_ext/extlink_dset -d /copy2_dset + + echo "Test copying dangling external link (no obj) directly without -f ext" + #TOOLTEST -i $TESTFILE -o $FILEOUT -v -s /copy2_group/extlink_notyet1 -d /copy2_dangle1 + SKIP -s /copy2_group/extlink_notyet1 -d /copy2_dangle1 + + echo "Test copying dangling external link (no obj) directly with -f ext" + #TOOLTEST -f ext -i $TESTFILE -o $FILEOUT -v -s /copy2_group/extlink_notyet1 -d /copy2_dangle1 + SKIP -f ext -s /copy2_group/extlink_notyet1 -d /copy2_dangle1 + + echo "Test copying dangling external link (no file) directly without -f ext" + #TOOLTEST -i $TESTFILE -o $FILEOUT -v -s /copy2_group/extlink_notyet2 -d /copy2_dangle2 + SKIP -s /copy2_group/extlink_notyet2 -d /copy2_dangle2 + + echo "Test copying dangling external link (no file) directly with -f ext" + #TOOLTEST -f ext -i $TESTFILE -o $FILEOUT -v -s /copy2_group/extlink_notyet2 -d /copy2_dangle2 + SKIP -f ext -s /copy2_group/extlink_notyet2 -d /copy2_dangle2 + + echo "Test copying a group contains external links without -f ext" + TOOLTEST -v -i $TESTFILE -o $FILEOUT -s /group_ext -d /copy1_group + + echo "Test copying a group contains external links with -f ext" + TOOLTEST -f ext -i $TESTFILE -o $FILEOUT -v -f ext -s /group_ext -d /copy2_group + + # Verify that the file created above is correct + H5LSTEST $FILEOUT + + # Remove output file created, if the "no cleanup" environment variable is + # not defined + if test -z "$HDF5_NOCLEANUP"; then + rm -f $FILEOUT + fi +} + ############################################################################## ### T H E T E S T S ### ############################################################################## COPY_OBJECTS COPY_REFERENCES +COPY_EXT_LINKS if test $nerrors -eq 0 ; then -- cgit v0.12