From 8c9b42fcf3d5077414e860e701d53bf61d0d99cd Mon Sep 17 00:00:00 2001 From: Jonathan Kim Date: Thu, 18 Mar 2010 16:38:09 -0500 Subject: [svn-r18425] Purpose: Fix for bug1814 - NPOESS: h5repack doesn't handle references to the groups as an element of a dataset Description: handles object reference to named-datatype as well. Add test cases. Tested: jam, amani, linew --- MANIFEST | 2 +- tools/h5repack/h5repack.sh.in | 4 + tools/h5repack/h5repack_refs.c | 16 +- tools/h5repack/h5repacktst.c | 323 ++++++++++++++++++++++++++++++ tools/h5repack/testfiles/h5repack_refs.h5 | Bin 0 -> 9280 bytes tools/lib/h5diff_array.c | 3 +- 6 files changed, 342 insertions(+), 6 deletions(-) create mode 100644 tools/h5repack/testfiles/h5repack_refs.h5 diff --git a/MANIFEST b/MANIFEST index d13e1ea..9ab9509 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1609,7 +1609,7 @@ ./tools/h5repack/testfiles/h5repack_ext.h5 ./tools/h5repack/testfiles/ublock.bin ./tools/h5repack/testfiles/h5repack_named_dtypes.h5 - +./tools/h5repack/testfiles/h5repack_refs.h5 # jam utility and tests ./tools/h5jam/h5jam.c diff --git a/tools/h5repack/h5repack.sh.in b/tools/h5repack/h5repack.sh.in index 32622a0..35fc5fd 100755 --- a/tools/h5repack/h5repack.sh.in +++ b/tools/h5repack/h5repack.sh.in @@ -59,6 +59,7 @@ FILE14=h5repack_layouto.h5 # A file with an older version of the layout mes # (copy of test/tlayouto.h5) FILE15=h5repack_named_dtypes.h5 FILE16=tfamily%05d.h5 # located in common testfiles folder +FILE_REF=h5repack_refs.h5 nerrors=0 @@ -531,6 +532,9 @@ TOOLTEST $FILE15 # tests family driver (file is located in common testfiles folder, uses TOOLTEST1 TOOLTEST1 $FILE16 +# test various references (bug 1814) +TOOLTEST $FILE_REF + if test $nerrors -eq 0 ; then echo "All $TESTNAME tests passed." exit $EXIT_SUCCESS diff --git a/tools/h5repack/h5repack_refs.c b/tools/h5repack/h5repack_refs.c index fddcf0e..9945f49 100644 --- a/tools/h5repack/h5repack_refs.c +++ b/tools/h5repack/h5repack_refs.c @@ -690,23 +690,31 @@ static const char* MapIdToName(hid_t refobj_id, trav_table_t *travt) { unsigned int i; + const char* ret = NULL; + H5O_info_t ref_oinfo; /* Stat for the refobj id */ /* linear search */ for(i = 0; i < travt->nobjs; i++) { - if(travt->objs[i].type == H5O_TYPE_DATASET) + if(travt->objs[i].type == H5O_TYPE_DATASET || + travt->objs[i].type == H5O_TYPE_GROUP || + travt->objs[i].type == H5O_TYPE_NAMED_DATATYPE) { H5O_info_t ref_oinfo; /* Stat for the refobj id */ /* obtain information to identify the referenced object uniquely */ if(H5Oget_info(refobj_id, &ref_oinfo) < 0) - return NULL; + goto out; if(ref_oinfo.addr == travt->objs[i].objno) - return(travt->objs[i].name); + { + ret = travt->objs[i].name; + goto out; + } } /* end if */ } /* i */ - return NULL; +out: + return ret; } diff --git a/tools/h5repack/h5repacktst.c b/tools/h5repack/h5repacktst.c index 17ece99..d4cd347 100644 --- a/tools/h5repack/h5repacktst.c +++ b/tools/h5repack/h5repacktst.c @@ -78,6 +78,8 @@ #define FNAME_UB "ublock.bin" +/* obj and region references */ +#define FNAME_REF "h5repack_refs.h5" const char *H5REPACK_FILENAMES[] = { "h5repack_big_out", @@ -100,6 +102,13 @@ int d_status = EXIT_SUCCESS; /* Size of userblock (for userblock test) */ #define USERBLOCK_SIZE 2048 +/* obj and region references */ +#define NAME_OBJ_DS "Dset1" +#define NAME_OBJ_GRP "Group" +#define NAME_OBJ_NDTYPE "NamedDatatype" +#define REG_REF_DS1 "Dset_REGREF" +#define REG_REF_DS2 "Dset2" + /*------------------------------------------------------------------------- * prototypes *------------------------------------------------------------------------- @@ -132,6 +141,7 @@ static int make_userblock(void); static int verify_userblock( const char* filename); static int make_userblock_file(void); static int make_named_dtype(hid_t loc_id); +static int make_references(hid_t loc_id); /*------------------------------------------------------------------------- @@ -1763,6 +1773,16 @@ int make_testfiles(void) if(H5Fclose(fid) < 0) return -1; + /*------------------------------------------------------------------------- + * create a file with obj and region references + *-------------------------------------------------------------------------*/ + if((fid = H5Fcreate(FNAME_REF,H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT)) < 0) + return -1; + if (make_references(fid) < 0) + goto out; + if(H5Fclose(fid) < 0) + return -1; + return 0; out: @@ -5583,3 +5603,306 @@ out: return -1; } /* end make_named_dtype() */ +/*------------------------------------------------------------------------- + * Function: gen_obj_ref + * + * Purpose: + * Generate object references to objects (dataset,group and named datatype) + * + * Note: + * copied from h5copygentest.c and upate to create named datatype + * + * Programmer: Jonathan Kim (March 18, 2010) + *------------------------------------------------------------------------*/ +static herr_t gen_obj_ref(hid_t loc_id) +{ + hid_t sid=0, oid=0, tid=0; + hsize_t dims1[1]={3}; + hsize_t dims2[1]={3}; + 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", FUNC, __LINE__); + ret = FAIL; + goto out; + } + + oid = H5Dcreate2 (loc_id, NAME_OBJ_DS, H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + if (oid < 0) + { + fprintf(stderr, "Error: %s %d> H5Dcreate2 failed.\n", FUNC, __LINE__); + ret = FAIL; + goto out; + } + + status = H5Dwrite(oid, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data); + if (status < 0) + { + fprintf(stderr, "Error: %s %d> H5Dwrite failed.\n", FUNC, __LINE__); + ret = FAIL; + goto out; + } + + H5Dclose(oid); + H5Sclose(sid); + + /*-------------- + * add group */ + oid = H5Gcreate2 (loc_id, NAME_OBJ_GRP, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + if (oid < 0) + { + fprintf(stderr, "Error: %s %d> H5Gcreate2 failed.\n", FUNC, __LINE__); + ret = FAIL; + goto out; + } + H5Gclose(oid); + + /*---------------------- + * add named datatype + */ + tid = H5Tcopy(H5T_NATIVE_INT); + status = H5Tcommit2(loc_id, NAME_OBJ_NDTYPE, tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + if (status < 0) + { + fprintf(stderr, "Error: %s %d> H5Tcommit2 failed.\n", FUNC, __LINE__); + ret = FAIL; + goto out; + } + + /*--------------------------------------------------------- + * create obj references to the previously created objects. + * Passing -1 as reference is an object.*/ + hobj_ref_t objref_buf[3]; /* write buffer for */ + + /* obj ref to dataset */ + status = H5Rcreate (&objref_buf[0], loc_id, NAME_OBJ_DS, H5R_OBJECT, -1); + if (status < 0) + { + fprintf(stderr, "Error: %s %d> H5Rcreate failed.\n", FUNC, __LINE__); + ret = FAIL; + goto out; + } + + /* obj ref to group */ + status = H5Rcreate (&objref_buf[1], loc_id, NAME_OBJ_GRP, H5R_OBJECT, -1); + if (status < 0) + { + fprintf(stderr, "Error: %s %d> H5Rcreate failed.\n", FUNC, __LINE__); + ret = FAIL; + goto out; + } + + /* obj ref to named-datatype */ + status = H5Rcreate (&objref_buf[2], loc_id, NAME_OBJ_NDTYPE, H5R_OBJECT, -1); + if (status < 0) + { + fprintf(stderr, "Error: %s %d> H5Rcreate failed.\n", FUNC, __LINE__); + ret = FAIL; + goto out; + } + + /*--------------------------------------------------------- + * create dataset contain references + */ + sid = H5Screate_simple (1, dims2, NULL); + if (sid < 0) + { + fprintf(stderr, "Error: %s %d> H5Screate_simple failed.\n", FUNC, __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", FUNC, __LINE__); + ret = FAIL; + goto out; + } + + status = H5Dwrite(oid, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, objref_buf); + if (status < 0) + { + fprintf(stderr, "Error: %s %d> H5Dwrite failed.\n", FUNC, __LINE__); + ret = FAIL; + goto out; + } + +out: + if(oid > 0) + H5Dclose(oid); + if(tid > 0) + H5Tclose(tid); + if(sid > 0) + H5Sclose(sid); + + return ret; +} + + +/*------------------------------------------------------------------------- + * Function: gen_region_ref + * + * Purpose: Generate dataset region references + * + * Note: + * copied from h5copygentest.c + * + * Programmer: Jonathan Kim (March 18, 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", FUNC, __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", FUNC, __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", FUNC, __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", FUNC, __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", FUNC, __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", FUNC, __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", FUNC, __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", FUNC, __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", FUNC, __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", FUNC, __LINE__); + ret = FAIL; + goto out; + } + +out: + if (oid1 > 0) + H5Dclose (oid1); + if (oid2 > 0) + H5Dclose (oid2); + if (sid > 0) + H5Sclose (sid); + + return ret; +} + +/*------------------------------------------------------------------------- +* Function: make_references +* +* Purpose: create a file with obj and region references +* +* Programmer: Jonathan Kim (March 18, 2010) +*------------------------------------------------------------------------- +*/ +static herr_t make_references(hid_t loc_id) +{ + herr_t ret = SUCCEED; + herr_t status; + + /* add object reference */ + status = gen_obj_ref(loc_id); + if (status == FAIL) + { + fprintf(stderr, "Failed to generate object reference.\n"); + ret = FAIL; + } + + /* add region reference */ + status = gen_region_ref(loc_id); + if (status == FAIL) + { + fprintf(stderr, "Failed to generate region reference.\n"); + ret = FAIL; + } + + return ret; +} + diff --git a/tools/h5repack/testfiles/h5repack_refs.h5 b/tools/h5repack/testfiles/h5repack_refs.h5 new file mode 100644 index 0000000..23d53e6 Binary files /dev/null and b/tools/h5repack/testfiles/h5repack_refs.h5 differ diff --git a/tools/lib/h5diff_array.c b/tools/lib/h5diff_array.c index 6572594..48e08a5 100644 --- a/tools/lib/h5diff_array.c +++ b/tools/lib/h5diff_array.c @@ -747,7 +747,8 @@ hsize_t diff_datum(void *_mem1, NULL, options); else { - parallel_print("Warning: Comparison not possible of object types referenced: <%s> and <%s>", + if(options->m_verbose) + parallel_print("Warning: Comparison not possible of object types referenced: <%s> and <%s>\n", obj1, obj2); options->not_cmp = 1; } -- cgit v0.12