summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorJonathan Kim <jkm@hdfgroup.org>2010-03-09 21:46:00 (GMT)
committerJonathan Kim <jkm@hdfgroup.org>2010-03-09 21:46:00 (GMT)
commit5345e2394effb206c1f76c95a1eddb937e34a316 (patch)
treeb63c0c0c99000f86b57b11178ae7fbb5417fd6d1 /tools
parent8833db1c5bc4ea2542781751ca5a9a3657ee5fff (diff)
downloadhdf5-5345e2394effb206c1f76c95a1eddb937e34a316.zip
hdf5-5345e2394effb206c1f76c95a1eddb937e34a316.tar.gz
hdf5-5345e2394effb206c1f76c95a1eddb937e34a316.tar.bz2
[svn-r18400] Purpose:
add test cases for h5copy - copy external links with/without ‘–f ext’ option (relate to bug 1733) Description: merged from hdf5 trunk (r18398 and r18399) Tested: jam
Diffstat (limited to 'tools')
-rw-r--r--tools/h5copy/h5copygentest.c179
-rw-r--r--tools/h5copy/testfiles/h5copy_extlinks_src.h5bin0 -> 2184 bytes
-rw-r--r--tools/h5copy/testfiles/h5copy_extlinks_src.out.ls42
-rw-r--r--tools/h5copy/testfiles/h5copy_extlinks_trg.h5bin0 -> 2168 bytes
-rw-r--r--tools/h5copy/testh5copy.sh61
5 files changed, 281 insertions, 1 deletions
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
--- /dev/null
+++ b/tools/h5copy/testfiles/h5copy_extlinks_src.h5
Binary files 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: <details removed for portability>
+ 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: <details removed for portability>
+ 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: <details removed for portability>
+ 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
--- /dev/null
+++ b/tools/h5copy/testfiles/h5copy_extlinks_trg.h5
Binary files 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:
+# <none>
+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