summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorJonathan Kim <jkm@hdfgroup.org>2010-02-23 19:23:29 (GMT)
committerJonathan Kim <jkm@hdfgroup.org>2010-02-23 19:23:29 (GMT)
commit07be86a8eab87b514f908afbd620d1050f73d543 (patch)
tree696199c4a383a9f9dd58b921e0491dae076fed1a /tools
parent28a9bf5f47d04bdaae781ec8843bcbe651780d0e (diff)
downloadhdf5-07be86a8eab87b514f908afbd620d1050f73d543.zip
hdf5-07be86a8eab87b514f908afbd620d1050f73d543.tar.gz
hdf5-07be86a8eab87b514f908afbd620d1050f73d543.tar.bz2
[svn-r18319] Purpose:
Bug1727 - h5copy: add test cases for object and region references File added: tools/h5copy/testfiles/h5copy_ref.out.ls tools/h5copy/testfiles/h5copy_ref.h5 Tested: jam, linew
Diffstat (limited to 'tools')
-rw-r--r--tools/h5copy/h5copygentest.c339
-rw-r--r--tools/h5copy/testfiles/h5copy_ref.h5bin0 -> 9104 bytes
-rw-r--r--tools/h5copy/testfiles/h5copy_ref.out.ls34
-rw-r--r--tools/h5copy/testfiles/h5copytst.out.ls4
-rw-r--r--tools/h5copy/testh5copy.sh51
5 files changed, 407 insertions, 21 deletions
diff --git a/tools/h5copy/h5copygentest.c b/tools/h5copy/h5copygentest.c
index 7842b38..c1e21f3 100644
--- a/tools/h5copy/h5copygentest.c
+++ b/tools/h5copy/h5copygentest.c
@@ -18,8 +18,14 @@
*/
#include <stdlib.h>
#include "hdf5.h"
+#include "H5private.h"
+#include "h5tools.h"
-#define FILENAME "h5copytst.h5"
+/* HDF file names */
+#define HDF_FILE1 "h5copytst.h5"
+#define HDF_FILE2 "h5copy_ref.h5"
+
+/* objects in HDF_FILE1 */
#define DATASET_SIMPLE "simple"
#define DATASET_CHUNK "chunk"
#define DATASET_COMPACT "compact"
@@ -31,6 +37,13 @@
#define GROUP_DATASETS "grp_dsets"
#define GROUP_NESTED "grp_nested"
+/* Obj reference */
+#define OBJ_REF_DS "Dset1"
+#define OBJ_REF_GRP "Group"
+/* Region reference */
+#define REG_REF_DS1 "Dset_REGREF"
+#define REG_REF_DS2 "Dset2"
+
/*-------------------------------------------------------------------------
* Function: gent_simple
@@ -210,7 +223,8 @@ static void gent_compressed(hid_t loc_id)
/*-------------------------------------------------------------------------
* Function: gent_named_vl
*
- * Purpose: Generate a variable lenght named datatype for a dataset in LOC_ID
+ * Purpose: Generate a variable lenght named datatype for a dataset in
+ LOC_ID
*
*-------------------------------------------------------------------------
*/
@@ -386,23 +400,330 @@ static void gent_nested_group(hid_t loc_id)
H5Gclose(gid);
}
+
/*-------------------------------------------------------------------------
- * Function: main
+ * Function: gen_obj_ref
*
- *-------------------------------------------------------------------------
- */
+ * Purpose: Generate object references to dataset and group
+ *
+ * Programmer: Jonathan Kim (Feb 23, 2010)
+ *------------------------------------------------------------------------*/
+static herr_t gen_obj_ref(hid_t loc_id)
+{
+ hid_t sid=0, tid=0, oid=0;
+ hsize_t dims1[1]={3};
+ hsize_t dims2[1]={2};
+ int data[3] = {10,20,30};
+ int status;
+ herr_t ret = SUCCEED;
+
+ /*--------------
+ * add dataset */
+ sid = H5Screate_simple(1, dims1, NULL);
+ if (sid < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Screate_simple failed.\n", __FUNCTION__, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
-int main(void)
+ tid = H5Tcopy(H5T_NATIVE_INT);
+ if (tid < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Tcopy failed.\n", __FUNCTION__, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+
+ oid = H5Dcreate2 (loc_id, OBJ_REF_DS, tid, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ if (oid < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Dcreate2 failed.\n", __FUNCTION__, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+
+ status = H5Dwrite(oid, tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
+ if (status < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Dwrite failed.\n", __FUNCTION__, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+
+ H5Dclose(oid);
+ H5Tclose(tid);
+ H5Sclose(sid);
+
+ /*--------------
+ * add group */
+ oid = H5Gcreate (loc_id, OBJ_REF_GRP, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ if (oid < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Gcreate failed.\n", __FUNCTION__, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+ H5Gclose(oid);
+
+ /*---------------------
+ * create obj references to the previously created objects.
+ * Passing -1 as reference is an object.*/
+ hobj_ref_t or_data[2]; /* write buffer */
+
+ status = H5Rcreate (&or_data[0], loc_id, OBJ_REF_DS, H5R_OBJECT, -1);
+ if (status < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Rcreate failed.\n", __FUNCTION__, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+ status = H5Rcreate (&or_data[1], loc_id, OBJ_REF_GRP, H5R_OBJECT, -1);
+ if (status < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Rcreate failed.\n", __FUNCTION__, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+
+ sid = H5Screate_simple (1, dims2, NULL);
+ if (sid < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Screate_simple failed.\n", __FUNCTION__, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+
+ oid = H5Dcreate2 (loc_id, "Dset_OBJREF", H5T_STD_REF_OBJ, sid, H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
+ if (oid < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Dcreate2 failed.\n", __FUNCTION__, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+
+ status = H5Dwrite(oid, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, or_data);
+ if (status < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Dwrite failed.\n", __FUNCTION__, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+
+out:
+ if(oid > 0)
+ H5Dclose(oid);
+ if(sid > 0)
+ H5Sclose(sid);
+ if(tid > 0)
+ H5Tclose(tid);
+
+ return ret;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: gen_region_ref
+ *
+ * Purpose: Generate dataset region references
+ *
+ * Programmer: Jonathan Kim (Feb 23, 2010)
+ *------------------------------------------------------------------------*/
+static herr_t gen_region_ref(hid_t loc_id)
+{
+ hid_t sid=0, oid1=0, oid2=0;
+ int status;
+ herr_t ret = SUCCEED;
+ char data[3][16] = {"The quick brown", "fox jumps over ", "the 5 lazy dogs"};
+ hsize_t dims2[2] = {3,16};
+ hsize_t coords[4][2] = { {0,1}, {2,11}, {1,0}, {2,4} };
+
+ hdset_reg_ref_t rr_data[2];
+ hsize_t start[2] = {0,0};
+ hsize_t stride[2] = {2,11};
+ hsize_t count[2] = {2,2};
+ hsize_t block[2] = {1,3};
+ hsize_t dims1[1] = {2};
+
+ sid = H5Screate_simple (2, dims2, NULL);
+ if (sid < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Screate_simple failed.\n", __FUNCTION__, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+
+ /* create normal dataset which is refered */
+ oid2 = H5Dcreate2 (loc_id, REG_REF_DS2, H5T_STD_I8LE, sid, H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
+ if (oid2 < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Dcreate2 failed.\n", __FUNCTION__, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+
+ /* write values to dataset */
+ status = H5Dwrite (oid2, H5T_NATIVE_CHAR, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
+ if (status < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Dwrite failed.\n", __FUNCTION__, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+
+ /* select elements space for reference */
+ status = H5Sselect_elements (sid, H5S_SELECT_SET, 4, coords[0]);
+ if (status < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Sselect_elements failed.\n", __FUNCTION__, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+
+ /* create region reference from elements space */
+ status = H5Rcreate (&rr_data[0], loc_id, REG_REF_DS2, H5R_DATASET_REGION, sid);
+ if (status < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Rcreate failed.\n", __FUNCTION__, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+
+ /* select hyperslab space for reference */
+ status = H5Sselect_hyperslab (sid, H5S_SELECT_SET, start, stride, count, block);
+ if (status < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Sselect_hyperslab failed.\n", __FUNCTION__, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+
+ /* create region reference from hyperslab space */
+ status = H5Rcreate (&rr_data[1], loc_id, REG_REF_DS2, H5R_DATASET_REGION, sid);
+ if (status < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Rcreate failed.\n", __FUNCTION__, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+
+ H5Sclose (sid);
+
+ /* Create dataspace. */
+ sid = H5Screate_simple (1, dims1, NULL);
+ if (sid < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Screate_simple failed.\n", __FUNCTION__, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+
+ /* create region reference dataset */
+ oid1 = H5Dcreate2 (loc_id, REG_REF_DS1, H5T_STD_REF_DSETREG, sid, H5P_DEFAULT,H5P_DEFAULT,H5P_DEFAULT);
+ if (oid1 < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Dcreate2 failed.\n", __FUNCTION__, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+
+ /* write data as region references */
+ status = H5Dwrite (oid1, H5T_STD_REF_DSETREG, H5S_ALL, H5S_ALL, H5P_DEFAULT, rr_data);
+ if (status < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Dwrite failed.\n", __FUNCTION__, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+
+out:
+ if (oid1 > 0)
+ H5Dclose (oid1);
+ if (oid2 > 0)
+ H5Dclose (oid2);
+ if (sid > 0)
+ H5Sclose (sid);
+
+ return ret;
+}
+
+/*-------------------------------------------------------------------------
+ * Function: Test_Obj_Copy
+ *
+ * Purpose: Testing with various objects
+ *
+ *------------------------------------------------------------------------*/
+static void Test_Obj_Copy()
{
- hid_t fid;
+ hid_t fid=0;
/* Create source file */
- fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ fid = H5Fcreate(HDF_FILE1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ if (fid < 0)
+ {
+ fprintf(stderr, "Error: %s> H5Fcreate failed.\n", HDF_FILE1);
+ goto out;
+ }
+
gent_datasets(fid);
gent_empty_group(fid);
gent_nested_datasets(fid);
gent_nested_group(fid);
- H5Fclose(fid);
+
+out:
+ /*-----------------------------------------------------------------------
+ * Close
+ *------------------------------------------------------------------------*/
+ if(fid > 0)
+ H5Fclose(fid);
+}
+
+/*-------------------------------------------------------------------------
+ * Function: Test_Ref_Copy
+ *
+ * Purpose: Testing with various references
+ *
+ *------------------------------------------------------------------------*/
+static void Test_Ref_Copy()
+{
+ hid_t fid=0;
+ herr_t status;
+
+ fid = H5Fcreate (HDF_FILE2, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ if (fid < 0)
+ {
+ fprintf(stderr, "Error: %s> H5Fcreate failed.\n", HDF_FILE2);
+ goto out;
+ }
+
+ /* add object reference */
+ status = gen_obj_ref(fid);
+ if (status < 0)
+ fprintf(stderr, "Failed to generate object reference.\n");
+
+ /* add region reference */
+ status = gen_region_ref(fid);
+ if (status < 0)
+ fprintf(stderr, "Failed to generate region reference.\n");
+
+out:
+ /*-----------------------------------------------------------------------
+ * Close
+ *------------------------------------------------------------------------*/
+ if(fid > 0)
+ H5Fclose(fid);
+}
+
+/*-------------------------------------------------------------------------
+ * Function: main
+ *
+ *-------------------------------------------------------------------------
+ */
+
+int main(void)
+{
+ Test_Obj_Copy();
+ Test_Ref_Copy();
return 0;
}
diff --git a/tools/h5copy/testfiles/h5copy_ref.h5 b/tools/h5copy/testfiles/h5copy_ref.h5
new file mode 100644
index 0000000..bd727e6
--- /dev/null
+++ b/tools/h5copy/testfiles/h5copy_ref.h5
Binary files differ
diff --git a/tools/h5copy/testfiles/h5copy_ref.out.ls b/tools/h5copy/testfiles/h5copy_ref.out.ls
new file mode 100644
index 0000000..8549842
--- /dev/null
+++ b/tools/h5copy/testfiles/h5copy_ref.out.ls
@@ -0,0 +1,34 @@
+#############################
+Expected output for 'h5ls ./testfiles/h5copy_ref.out.h5'
+#############################
+Opened "./testfiles/h5copy_ref.out.h5" with sec2 driver.
+/ Group
+ Location: 1:96
+ Links: 1
+/COPY Group
+ Location: 1:1464
+ Links: 1
+/COPY/Dset1 Dataset {3/3}
+ Location: 1:1504
+ Links: 2
+ Storage: <details removed for portability>
+ Type: 32-bit little-endian integer
+/COPY/Dset2 Dataset {3/3, 16/16}
+ Location: 1:1960
+ Links: 3
+ Storage: <details removed for portability>
+ Type: 8-bit integer
+/COPY/Dset_OBJREF Dataset {2/2}
+ Location: 1:5184
+ Links: 1
+ Storage: <details removed for portability>
+ Type: object reference
+/COPY/Dset_REGREF Dataset {2/2}
+ Location: 1:9400
+ Links: 1
+ Storage: <details removed for portability>
+ Type: dataset region reference
+/COPY/Group Group
+ Location: 1:2096
+ Links: 3
+/~obj_pointed_by_2096 Group, same as /COPY/Group
diff --git a/tools/h5copy/testfiles/h5copytst.out.ls b/tools/h5copy/testfiles/h5copytst.out.ls
index 5ff1e90..af6cd8f 100644
--- a/tools/h5copy/testfiles/h5copytst.out.ls
+++ b/tools/h5copy/testfiles/h5copytst.out.ls
@@ -1,7 +1,7 @@
#############################
-Expected output for 'h5ls ../testfiles/h5copytst.out.h5'
+Expected output for 'h5ls ./testfiles/h5copytst.out.h5'
#############################
-Opened "../testfiles/h5copytst.out.h5" with sec2 driver.
+Opened "./testfiles/h5copytst.out.h5" with sec2 driver.
/ Group
Location: 1:96
Links: 1
diff --git a/tools/h5copy/testh5copy.sh b/tools/h5copy/testh5copy.sh
index 4f1d8cc..c94f26a 100644
--- a/tools/h5copy/testh5copy.sh
+++ b/tools/h5copy/testh5copy.sh
@@ -23,6 +23,10 @@ TESTNAME=h5copy
EXIT_SUCCESS=0
EXIT_FAILURE=1
+# Test files
+HDF_FILE1=h5copytst.h5
+HDF_FILE2=h5copy_ref.h5
+
H5COPY=h5copy # The tool name
H5COPY_BIN=`pwd`/$H5COPY # The path of the tool binary
H5DIFF=h5diff # The h5diff tool name
@@ -30,20 +34,19 @@ H5DIFF_BIN=`pwd`/../h5diff/$H5DIFF # The path of the h5diff tool binary
H5LS=h5ls # The h5ls tool name
H5LS_ARGS=-Svr # Arguments to the h5ls tool
H5LS_BIN=`pwd`/../h5ls/$H5LS # The path of the h5ls tool binary
+CMP='cmp -s'
+DIFF='diff -c'
nerrors=0
verbose=yes
-SRCFILE=h5copytst.h5
-INDIR=$srcdir/testfiles
-OUTDIR=../testfiles
-CMP='cmp -s'
-DIFF='diff -c'
-
# The build (current) directory might be different than the source directory.
if test -z "$srcdir"; then
srcdir=.
fi
+INDIR=$srcdir/testfiles
+OUTDIR=$srcdir/testfiles
+
test -d $OUTDIR || mkdir $OUTDIR
# Print a line-line message left justified in a field of 70 characters
@@ -242,10 +245,10 @@ H5LSTEST()
#
# Assumed arguments:
# <none>
-COPYOBJECTS()
+COPY_OBJECTS()
{
- TESTFILE="$INDIR/$SRCFILE"
- FILEOUT="$OUTDIR/`basename $SRCFILE .h5`.out.h5"
+ TESTFILE="$INDIR/$HDF_FILE1"
+ FILEOUT="$OUTDIR/`basename $HDF_FILE1 .h5`.out.h5"
# Remove any output file left over from previous test run
rm -f $FILEOUT
@@ -296,11 +299,39 @@ COPYOBJECTS()
fi
}
+# Copy references in various way.
+# adding to the destination file each time compare the result
+#
+# Assumed arguments:
+# <none>
+COPY_REFERENCES()
+{
+ TESTFILE="$INDIR/$HDF_FILE2"
+ FILEOUT="$OUTDIR/`basename $HDF_FILE2 .h5`.out.h5"
+
+ # Remove any output file left over from previous test run
+ 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
+ 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 ###
##############################################################################
-COPYOBJECTS
+COPY_OBJECTS
+COPY_REFERENCES
if test $nerrors -eq 0 ; then