summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDana Robinson <derobins@hdfgroup.org>2011-05-04 20:07:38 (GMT)
committerDana Robinson <derobins@hdfgroup.org>2011-05-04 20:07:38 (GMT)
commitfbba9db9559924c5fab5ad969884e86ca0cc1418 (patch)
treed48ee2a7907a23ec50415eb568cb863bdf3e0b37
parent2ee184118709356cfada5dd510d26148183b9259 (diff)
downloadhdf5-fbba9db9559924c5fab5ad969884e86ca0cc1418.zip
hdf5-fbba9db9559924c5fab5ad969884e86ca0cc1418.tar.gz
hdf5-fbba9db9559924c5fab5ad969884e86ca0cc1418.tar.bz2
[svn-r20724] Purpose: Fix a bug in h5diff when enum values are compared that do
not represent a valid enum value. Description: The h5diff code compares enum values by converting them to strings and then comparing them. When the enum value is out of range and can't be converted to an enum string representation, the comparison was skipped. The code now flags differences when one of the two enum values is out of range (two out of range values are compared in memory). A test has been added to the tools test script. This fixes JIRA HDFFV-7527 Tested on: jam, koala, heiwa (h5committest)
-rw-r--r--MANIFEST2
-rw-r--r--tools/h5diff/h5diffgentest.c81
-rw-r--r--tools/h5diff/testfiles/h5diff_30.txt10
-rwxr-xr-xtools/h5diff/testfiles/h5diff_enum_invalid_values.h5bin0 -> 2192 bytes
-rwxr-xr-xtools/h5diff/testh5diff.sh12
-rw-r--r--tools/lib/h5diff_array.c35
6 files changed, 138 insertions, 2 deletions
diff --git a/MANIFEST b/MANIFEST
index 4711773..547e593 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -1596,6 +1596,7 @@
./tools/h5diff/testfiles/h5diff_26.txt
./tools/h5diff/testfiles/h5diff_27.txt
./tools/h5diff/testfiles/h5diff_28.txt
+./tools/h5diff/testfiles/h5diff_30.txt
./tools/h5diff/testfiles/h5diff_50.txt
./tools/h5diff/testfiles/h5diff_51.txt
./tools/h5diff/testfiles/h5diff_52.txt
@@ -1763,6 +1764,7 @@
./tools/h5diff/testfiles/h5diff_comp_vl_strs.h5
./tools/h5diff/testfiles/h5diff_dset_zero_dim_size1.h5
./tools/h5diff/testfiles/h5diff_dset_zero_dim_size2.h5
+./tools/h5diff/testfiles/h5diff_enum_invalid_values.h5
#test files for h5repack
./tools/h5repack/testfiles/h5repack_fill.h5
diff --git a/tools/h5diff/h5diffgentest.c b/tools/h5diff/h5diffgentest.c
index 3ef01a0..43b1a37 100644
--- a/tools/h5diff/h5diffgentest.c
+++ b/tools/h5diff/h5diffgentest.c
@@ -75,6 +75,8 @@
/* attribute compre with verbose level */
#define ATTR_VERBOSE_LEVEL_FILE1 "h5diff_attr_v_level1.h5"
#define ATTR_VERBOSE_LEVEL_FILE2 "h5diff_attr_v_level2.h5"
+/* file containing valid/invalid enum value mix */
+#define ENUM_INVALID_VALUES "h5diff_enum_invalid_values.h5"
#define UIMAX 4294967295u /*Maximum value for a variable of type unsigned int */
#define STR_SIZE 3
@@ -131,6 +133,7 @@ static int test_exclude_obj1(const char *fname1, const char *fname2);
static int test_exclude_obj2(const char *fname1, const char *fname2);
static int test_comp_vlen_strings(const char *fname1, const char *grp_name, int is_file_new);
static int test_attributes_verbose_level(const char *fname1, const char *fname2);
+static int test_enums(const char *fname);
/* called by test_attributes() and test_datasets() */
static void write_attr_in(hid_t loc_id,const char* dset_name,hid_t fid,int make_diffs);
@@ -197,6 +200,13 @@ int main(void)
test_comp_vlen_strings(COMP_VL_STRS_FILE, "group", 1);
test_comp_vlen_strings(COMP_VL_STRS_FILE, "group_copy", 0);
+ /* diff when invalid enum values are present.
+ * This will probably grow to involve more extensive testing of
+ * enums so it has been given its own test file and test (apart
+ * from the basic type testing).
+ */
+ test_enums(ENUM_INVALID_VALUES);
+
return 0;
}
@@ -4021,6 +4031,77 @@ out:
return status;
}
+
+/*-------------------------------------------------------------------------
+*
+* Purpose: Test diffs of enum values which may include invalid values.
+*
+* Programmer: Dana Robinson
+*
+*-------------------------------------------------------------------------*/
+
+static int
+test_enums(const char *fname)
+{
+ hid_t fid = -1;
+
+ hid_t tid = -1;
+ int enum_val = -1;
+
+ /* The data in the two arrays cover the following cases:
+ *
+ * V = valid enum value, I = invalid enum value
+ *
+ * 0: I-I (same value)
+ * 1: V-I
+ * 2: I-V
+ * 3: V-V (same value)
+ * 4: I-I (different values)
+ * 5: V-V (different values)
+ */
+ int data1[6] = {9, 0, 9, 0, 8, 0};
+ int data2[6] = {9, 9, 0, 0, 9, 1};
+
+ hsize_t dims = 6;
+
+ herr_t status = SUCCEED;
+
+ /*-----------------------------------------------------------------------
+ * Create the file
+ *---------------------------------------------------------------------*/
+
+ fid = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+
+ /*-----------------------------------------------------------------------
+ * Create enum types
+ *---------------------------------------------------------------------*/
+
+ tid = H5Tenum_create(H5T_NATIVE_INT);
+ enum_val = 0;
+ status = H5Tenum_insert(tid, "YIN", &enum_val);
+ enum_val = 1;
+ status = H5Tenum_insert(tid, "YANG", &enum_val);
+
+ /*-----------------------------------------------------------------------
+ * Create datasets containing enum data.
+ *---------------------------------------------------------------------*/
+
+ status = write_dset(fid, 1, &dims, "dset1", tid, data1);
+ status = write_dset(fid, 1, &dims, "dset2", tid, data2);
+
+out:
+ /*-----------------------------------------------------------------------
+ * Close
+ *---------------------------------------------------------------------*/
+ if(fid)
+ H5Fclose(fid);
+ if(tid)
+ H5Tclose(tid);
+
+ return status;
+}
+
+
/*-------------------------------------------------------------------------
* Function: write_attr_in
*
diff --git a/tools/h5diff/testfiles/h5diff_30.txt b/tools/h5diff/testfiles/h5diff_30.txt
new file mode 100644
index 0000000..cd5b3f9
--- /dev/null
+++ b/tools/h5diff/testfiles/h5diff_30.txt
@@ -0,0 +1,10 @@
+dataset: </dset1> and </dset2>
+size: [6] [6]
+position dset1 dset2 difference
+------------------------------------------------------------
+[ 1 ] YIN **INVALID VALUE**
+[ 2 ] **INVALID VALUE** YIN
+[ 4 ] **INVALID VALUE** **INVALID VALUE**
+[ 5 ] YIN YANG
+4 differences found
+EXIT CODE: 1
diff --git a/tools/h5diff/testfiles/h5diff_enum_invalid_values.h5 b/tools/h5diff/testfiles/h5diff_enum_invalid_values.h5
new file mode 100755
index 0000000..9dc55f7
--- /dev/null
+++ b/tools/h5diff/testfiles/h5diff_enum_invalid_values.h5
Binary files differ
diff --git a/tools/h5diff/testh5diff.sh b/tools/h5diff/testh5diff.sh
index 5087350..48dc6a9 100755
--- a/tools/h5diff/testh5diff.sh
+++ b/tools/h5diff/testh5diff.sh
@@ -76,6 +76,9 @@ COMP_VL_STRS_FILE=h5diff_comp_vl_strs.h5
ATTR_VERBOSE_LEVEL_FILE1=h5diff_attr_v_level1.h5
ATTR_VERBOSE_LEVEL_FILE2=h5diff_attr_v_level2.h5
+# test enum types which may have invalid values
+ENUM_INVALID_VALUES=h5diff_enum_invalid_values.h5
+
TESTNAME=h5diff
EXIT_SUCCESS=0
EXIT_FAILURE=1
@@ -413,6 +416,15 @@ TOOLTEST h5diff_27.txt -v $FILE3 $FILE3 t1 t2
TOOLTEST h5diff_28.txt -v $FILE3 $FILE3 l1 l2
+# ##############################################################################
+# # Enum value tests (may become more comprehensive in the future)
+# ##############################################################################
+
+# 3.0
+TOOLTEST h5diff_30.txt -v $ENUM_INVALID_VALUES $ENUM_INVALID_VALUES dset1 dset2
+
+
+
# ##############################################################################
# # Dataset datatypes
diff --git a/tools/lib/h5diff_array.c b/tools/lib/h5diff_array.c
index c4c8dbf..6c5744f 100644
--- a/tools/lib/h5diff_array.c
+++ b/tools/lib/h5diff_array.c
@@ -621,12 +621,43 @@ hsize_t diff_datum(void *_mem1,
char enum_name1[1024];
char enum_name2[1024];
+ herr_t err1;
+ herr_t err2;
+
/* disable error reporting */
H5E_BEGIN_TRY {
- if ((H5Tenum_nameof(m_type, mem1, enum_name1, sizeof enum_name1) >= 0) &&
- (H5Tenum_nameof(m_type, mem2, enum_name2, sizeof enum_name2) >= 0))
+ /* If the enum value cannot be converted to a string
+ * it is set to an error string for later output.
+ */
+ err1 = H5Tenum_nameof(m_type, mem1, enum_name1, sizeof enum_name1);
+ if(err1 < 0)
+ strcpy(enum_name1, "**INVALID VALUE**");
+
+ err2 = H5Tenum_nameof(m_type, mem2, enum_name2, sizeof enum_name2);
+ if(err2 < 0)
+ strcpy(enum_name2, "**INVALID VALUE**");
+
+ if(err1 < 0 || err2 < 0)
{
+ /* One or more bad enum values */
+
+ /* If the two values cannot be converted to a string
+ * (probably due to them being invalid enum values),
+ * don't attempt to convert them - just report errors.
+ */
+ nfound += 1;
+ if ( print_data(options) )
+ {
+ print_pos(ph,0,i,acc,pos,rank,dims,obj1,obj2);
+ parallel_print(SPACES);
+ parallel_print(S_FORMAT,enum_name1,enum_name2);
+ }
+ }
+ else
+ {
+ /* Both enum values were valid */
+
if (HDstrcmp(enum_name1,enum_name2)!=0)
{
nfound=1;