summaryrefslogtreecommitdiffstats
path: root/tools/lib/h5diff.c
diff options
context:
space:
mode:
authorAllen Byrne <50328838+byrnHDF@users.noreply.github.com>2021-02-22 04:05:43 (GMT)
committerGitHub <noreply@github.com>2021-02-22 04:05:43 (GMT)
commitdf1a4af96126682ea4a05c2b26bf6b7c916579ff (patch)
tree993205ed1edde76001a811532f91997138b46744 /tools/lib/h5diff.c
parent88960489604861813b3676bc234f49ca8ee937d3 (diff)
downloadhdf5-df1a4af96126682ea4a05c2b26bf6b7c916579ff.zip
hdf5-df1a4af96126682ea4a05c2b26bf6b7c916579ff.tar.gz
hdf5-df1a4af96126682ea4a05c2b26bf6b7c916579ff.tar.bz2
HDF5 1 8 merge of recent changes and tools (#353)
* Update supported platforms * Merge PR#3 changes from develop * # WARNING: head commit changed in the meantime Merge gcc 10 diagnostics option from develop Merge CMake changes from develop Merge warnings from develop Merge #318 OSX changes from develop Merge tools changes from develop Merge test macros from develop * Format updates * Fix missing semicolon and format fix * Format update * Correct actions, remove java option * Update autotools build files * Add testfiles * Fix configure issue with make flags * Init fapls to default * Update generated files and fix h5repack id closure * update format
Diffstat (limited to 'tools/lib/h5diff.c')
-rw-r--r--tools/lib/h5diff.c164
1 files changed, 131 insertions, 33 deletions
diff --git a/tools/lib/h5diff.c b/tools/lib/h5diff.c
index 42154bc..1b11672 100644
--- a/tools/lib/h5diff.c
+++ b/tools/lib/h5diff.c
@@ -28,7 +28,7 @@
int
print_objname(diff_opt_t *opts, hsize_t nfound)
{
- return ((opts->m_verbose || nfound) && !opts->m_quiet) ? 1 : 0;
+ return ((opts->mode_verbose || nfound) && !opts->mode_quiet) ? 1 : 0;
}
/*-------------------------------------------------------------------------
@@ -44,7 +44,7 @@ do_print_objname(const char *OBJ, const char *path1, const char *path2, diff_opt
* displaying any object or symbolic links. This improves
* readability of the output.
*/
- if (opts->m_verbose_level >= 1)
+ if (opts->mode_verbose_level >= 1)
parallel_print("\n");
parallel_print("%-7s: <%s> and <%s>\n", OBJ, path1, path2);
}
@@ -73,7 +73,7 @@ do_print_attrname(const char *attr, const char *path1, const char *path2)
static int
print_warn(diff_opt_t *opts)
{
- return ((opts->m_verbose)) ? 1 : 0;
+ return ((opts->mode_verbose)) ? 1 : 0;
}
#ifdef H5_HAVE_PARALLEL
@@ -139,7 +139,7 @@ is_valid_options(diff_opt_t *opts)
/*-----------------------------------------------
* no -q(quiet) with -v (verbose) or -r (report) */
- if (opts->m_quiet && (opts->m_verbose || opts->m_report)) {
+ if (opts->mode_quiet && (opts->mode_verbose || opts->mode_report)) {
parallel_print("Error: -q (quiet mode) cannot be added to verbose or report modes\n");
opts->err_stat = H5DIFF_ERR;
H5TOOLS_GOTO_DONE(0);
@@ -207,7 +207,7 @@ is_exclude_path(char *path, h5trav_type_t type, diff_opt_t *opts)
if (ret_cmp == 0) { /* found matching object */
/* excluded non-group object */
ret_value = 1;
- /* remember the type of this maching object.
+ /* remember the type of this matching object.
* if it's group, it can be used for excluding its member
* objects in this while() loop */
exclude_path_ptr->obj_type = type;
@@ -222,6 +222,70 @@ done:
}
/*-------------------------------------------------------------------------
+ * Function: is_exclude_attr
+ *
+ * Purpose: check if 'paths' are part of exclude path list
+ *
+ * Return:
+ * 1 - excluded path
+ * 0 - not excluded path
+ *------------------------------------------------------------------------*/
+static int
+is_exclude_attr(const char *path, h5trav_type_t type, diff_opt_t *opts)
+{
+ struct exclude_path_list *exclude_ptr;
+ int ret_cmp;
+ int ret_value = 0;
+
+ /* check if exclude attr option is given */
+ if (!opts->exclude_attr_path)
+ H5TOOLS_GOTO_DONE(0);
+
+ /* assign to local exclude list pointer */
+ exclude_ptr = opts->exclude_attr;
+
+ /* search objects in exclude list */
+ while (NULL != exclude_ptr) {
+ /* if exclude path is is group, exclude its members as well */
+ if (exclude_ptr->obj_type == H5TRAV_TYPE_GROUP) {
+ ret_cmp = HDstrncmp(exclude_ptr->obj_path, path, HDstrlen(exclude_ptr->obj_path));
+ if (ret_cmp == 0) { /* found matching members */
+ size_t len_grp;
+
+ /* check if given path belong to an excluding group, if so
+ * exclude it as well.
+ * This verifies if “/grp1/dset1” is only under “/grp1”, but
+ * not under “/grp1xxx/” group.
+ */
+ len_grp = HDstrlen(exclude_ptr->obj_path);
+ if (path[len_grp] == '/') {
+ /* belong to excluded group! */
+ ret_value = 1;
+ break; /* while */
+ }
+ }
+ }
+ /* exclude target is not group, just exclude the object */
+ else {
+ ret_cmp = HDstrcmp(exclude_ptr->obj_path, path);
+ if (ret_cmp == 0) { /* found matching object */
+ /* excluded non-group object */
+ ret_value = 1;
+ /* remember the type of this matching object.
+ * if it's group, it can be used for excluding its member
+ * objects in this while() loop */
+ exclude_ptr->obj_type = type;
+ break; /* while */
+ }
+ }
+ exclude_ptr = exclude_ptr->next;
+ }
+
+done:
+ return ret_value;
+}
+
+/*-------------------------------------------------------------------------
* Function: free_exclude_path_list
*
* Purpose: free exclude object list from diff options
@@ -240,6 +304,24 @@ free_exclude_path_list(diff_opt_t *opts)
}
/*-------------------------------------------------------------------------
+ * Function: free_exclude_attr_list
+ *
+ * Purpose: free exclude object attribute list from diff options
+ *------------------------------------------------------------------------*/
+static void
+free_exclude_attr_list(diff_opt_t *opts)
+{
+ struct exclude_path_list *curr = opts->exclude_attr;
+ struct exclude_path_list *next;
+
+ while (NULL != curr) {
+ next = curr->next;
+ HDfree(curr);
+ curr = next;
+ }
+}
+
+/*-------------------------------------------------------------------------
* Function: build_match_list
*
* Purpose: get list of matching path_name from info1 and info2
@@ -284,6 +366,7 @@ build_match_list(const char *objname1, trav_info_t *info1, const char *objname2,
* All the objects belong to given groups are the candidates.
* So prepare to compare paths without the group names.
*/
+ H5TOOLS_DEBUG("objname1 = %s objname2 = %s ", objname1, objname2);
/* if obj1 is not root */
if (HDstrcmp(objname1, "/") != 0)
@@ -551,17 +634,17 @@ h5diff(const char *fname1, const char *fname2, const char *objname1, const char
*-------------------------------------------------------------------------
*/
/* open file 1 */
- if ((file1_id = h5tools_fopen(fname1, H5F_ACC_RDONLY, H5P_DEFAULT, NULL, NULL, (size_t)0)) < 0) {
+ if ((file1_id = h5tools_fopen(fname1, H5F_ACC_RDONLY, H5P_DEFAULT, FALSE, NULL, (size_t)0)) < 0) {
parallel_print("h5diff: <%s>: unable to open file\n", fname1);
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "<%s>: unable to open file\n", fname1);
- } /* end if */
+ }
H5TOOLS_DEBUG("file1_id = %s", fname1);
/* open file 2 */
- if ((file2_id = h5tools_fopen(fname2, H5F_ACC_RDONLY, H5P_DEFAULT, NULL, NULL, (size_t)0)) < 0) {
+ if ((file2_id = h5tools_fopen(fname2, H5F_ACC_RDONLY, H5P_DEFAULT, FALSE, NULL, (size_t)0)) < 0) {
parallel_print("h5diff: <%s>: unable to open file\n", fname2);
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "<%s>: unable to open file\n", fname2);
- } /* end if */
+ }
H5TOOLS_DEBUG("file2_id = %s", fname2);
/*-------------------------------------------------------------------------
@@ -591,6 +674,7 @@ h5diff(const char *fname1, const char *fname2, const char *objname1, const char
}
else
obj1fullname = HDstrdup(objname1);
+ H5TOOLS_DEBUG("obj1fullname = %s", obj1fullname);
/* make the given object2 fullpath, start with "/" */
if (HDstrncmp(objname2, "/", 1)) {
@@ -608,6 +692,7 @@ h5diff(const char *fname1, const char *fname2, const char *objname1, const char
}
else
obj2fullname = HDstrdup(objname2);
+ H5TOOLS_DEBUG("obj2fullname = %s", obj2fullname);
/*----------------------------------------------------------
* check if obj1 is root, group, single object or symlink
@@ -741,12 +826,12 @@ h5diff(const char *fname1, const char *fname2, const char *objname1, const char
H5TOOLS_DEBUG("h5diff ... dangling link");
if (opts->no_dangle_links) {
/* treat dangling link as error */
- if (opts->m_verbose)
+ if (opts->mode_verbose)
parallel_print("Warning: <%s> is a dangling link.\n", obj1fullname);
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "treat dangling link as error");
}
else {
- if (opts->m_verbose)
+ if (opts->mode_verbose)
parallel_print("obj1 <%s> is a dangling link.\n", obj1fullname);
if (l_ret1 != 0 || l_ret2 != 0) {
nfound++;
@@ -782,12 +867,12 @@ h5diff(const char *fname1, const char *fname2, const char *objname1, const char
H5TOOLS_DEBUG("h5diff ... dangling link");
if (opts->no_dangle_links) {
/* treat dangling link as error */
- if (opts->m_verbose)
+ if (opts->mode_verbose)
parallel_print("Warning: <%s> is a dangling link.\n", obj2fullname);
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "treat dangling link as error");
}
else {
- if (opts->m_verbose)
+ if (opts->mode_verbose)
parallel_print("obj2 <%s> is a dangling link.\n", obj2fullname);
if (l_ret1 != 0 || l_ret2 != 0) {
nfound++;
@@ -821,8 +906,8 @@ h5diff(const char *fname1, const char *fname2, const char *objname1, const char
* comparing details of same objects.
*/
- if (!(opts->m_verbose || opts->m_report)) {
- H5TOOLS_DEBUG("h5diff NOT (opts->m_verbose || opts->m_report)");
+ if (!(opts->mode_verbose || opts->mode_report)) {
+ H5TOOLS_DEBUG("h5diff NOT (opts->mode_verbose || opts->mode_report)");
/* if no danglink links */
if (l_ret1 > 0 && l_ret2 > 0)
if (h5tools_is_obj_same(file1_id, obj1fullname, file2_id, obj2fullname) != 0)
@@ -889,9 +974,14 @@ h5diff(const char *fname1, const char *fname2, const char *objname1, const char
/*------------------------------------------------------
* print the list
*/
- if (opts->m_verbose) {
+ if (opts->mode_verbose) {
unsigned u;
+ if (opts->mode_verbose_level > 2) {
+ parallel_print("file1: %s\n", fname1);
+ parallel_print("file2: %s\n", fname2);
+ }
+
parallel_print("\n");
/* if given objects is group under root */
if (HDstrcmp(obj1fullname, "/") || HDstrcmp(obj2fullname, "/"))
@@ -910,6 +1000,7 @@ h5diff(const char *fname1, const char *fname2, const char *objname1, const char
}
H5TOOLS_DEBUG("diff_match next - errstat:%d", opts->err_stat);
nfound = diff_match(file1_id, obj1fullname, info1_lp, file2_id, obj2fullname, info2_lp, match_list, opts);
+ H5TOOLS_DEBUG("diff_match nfound: %d - errstat:%d", nfound, opts->err_stat);
done:
opts->err_stat = opts->err_stat | ret_value;
@@ -1004,12 +1095,14 @@ diff_match(hid_t file1_id, const char *grp1, trav_info_t *info1, hid_t file2_id,
*-------------------------------------------------------------------------
*/
+ H5TOOLS_DEBUG("exclude_path opts->contents:%d", opts->contents);
/* not valid compare used when --exclude-path option is used */
if (!opts->exclude_path) {
/* number of different objects */
if (info1->nused != info2->nused) {
opts->contents = 0;
}
+ H5TOOLS_DEBUG("opts->exclude_path opts->contents:%d", opts->contents);
}
/* objects in one file and not the other */
@@ -1018,6 +1111,7 @@ diff_match(hid_t file1_id, const char *grp1, trav_info_t *info1, hid_t file2_id,
opts->contents = 0;
break;
}
+ H5TOOLS_DEBUG("table->nobjs[%d] opts->contents:%d", i, opts->contents);
}
/*-------------------------------------------------------------------------
@@ -1361,6 +1455,8 @@ diff_match(hid_t file1_id, const char *grp1, trav_info_t *info1, hid_t file2_id,
opts->err_stat = opts->err_stat | ret_value;
+ free_exclude_attr_list(opts);
+
/* free table */
if (table)
trav_table_free(table);
@@ -1432,7 +1528,7 @@ diff(hid_t file1_id, const char *path1, hid_t file2_id, const char *path2, diff_
if (status == 0) {
if (opts->no_dangle_links) {
/* dangling link is error */
- if (opts->m_verbose)
+ if (opts->mode_verbose)
parallel_print("Warning: <%s> is a dangling link.\n", path1);
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "dangling link is error");
}
@@ -1447,7 +1543,7 @@ diff(hid_t file1_id, const char *path1, hid_t file2_id, const char *path2, diff_
if (status == 0) {
if (opts->no_dangle_links) {
/* dangling link is error */
- if (opts->m_verbose)
+ if (opts->mode_verbose)
parallel_print("Warning: <%s> is a dangling link.\n", path2);
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "dangling link is error");
}
@@ -1472,10 +1568,11 @@ diff(hid_t file1_id, const char *path1, hid_t file2_id, const char *path2, diff_
/* if objects are not the same type */
if (argdata->type[0] != argdata->type[1]) {
H5TOOLS_DEBUG("diff objects are not the same");
- if (opts->m_verbose || opts->m_list_not_cmp) {
+ if (opts->mode_verbose || opts->mode_list_not_cmp) {
parallel_print("Not comparable: <%s> is of type %s and <%s> is of type %s\n", path1,
get_type(argdata->type[0]), path2, get_type(argdata->type[1]));
}
+
opts->not_cmp = 1;
/* TODO: will need to update non-comparable is different
* opts->contents = 0;
@@ -1499,7 +1596,7 @@ diff(hid_t file1_id, const char *path1, hid_t file2_id, const char *path2, diff_
object_type == H5TRAV_TYPE_GROUP);
if (opts->follow_links || is_hard_link) {
/* print information is only verbose option is used */
- if (opts->m_verbose || opts->m_report) {
+ if (opts->mode_verbose || opts->mode_report) {
switch (object_type) {
case H5TRAV_TYPE_DATASET:
do_print_objname("dataset", path1, path2, opts);
@@ -1529,7 +1626,7 @@ diff(hid_t file1_id, const char *path1, hid_t file2_id, const char *path2, diff_
} /* switch(type)*/
print_found(nfound);
- } /* if(opts->m_verbose || opts->m_report) */
+ } /* if(opts->mode_verbose || opts->mode_report) */
/* exact same, so comparison is done */
H5TOOLS_GOTO_DONE(H5DIFF_NO_ERR);
@@ -1547,15 +1644,16 @@ diff(hid_t file1_id, const char *path1, hid_t file2_id, const char *path2, diff_
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Dopen2 failed");
if ((dset2_id = H5Dopen2(file2_id, path2, H5P_DEFAULT)) < 0)
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Dopen2 failed");
+ H5TOOLS_DEBUG("paths: %s - %s", path1, path2);
/* verbose (-v) and report (-r) mode */
- if (opts->m_verbose || opts->m_report) {
+ if (opts->mode_verbose || opts->mode_report) {
do_print_objname("dataset", path1, path2, opts);
H5TOOLS_DEBUG("call diff_dataset 1:%s 2:%s ", path1, path2);
nfound = diff_dataset(file1_id, file2_id, path1, path2, opts);
print_found(nfound);
}
/* quiet mode (-q), just count differences */
- else if (opts->m_quiet) {
+ else if (opts->mode_quiet) {
nfound = diff_dataset(file1_id, file2_id, path1, path2, opts);
}
/* the rest (-c, none, ...) */
@@ -1575,7 +1673,7 @@ diff(hid_t file1_id, const char *path1, hid_t file2_id, const char *path2, diff_
* referenced object
*---------------------------------------------------------
*/
- if (path1) {
+ if (path1 && !is_exclude_attr(path1, object_type, opts)) {
H5TOOLS_DEBUG("call diff_attr 1:%s 2:%s ", path1, path2);
nfound += diff_attr(dset1_id, dset2_id, path1, path2, opts);
}
@@ -1607,7 +1705,7 @@ diff(hid_t file1_id, const char *path1, hid_t file2_id, const char *path2, diff_
do_print_objname("datatype", path1, path2, opts);
/* always print the number of differences found in verbose mode */
- if (opts->m_verbose)
+ if (opts->mode_verbose)
print_found(nfound);
/*-----------------------------------------------------------------
@@ -1616,7 +1714,7 @@ diff(hid_t file1_id, const char *path1, hid_t file2_id, const char *path2, diff_
* referenced object
*-----------------------------------------------------------------
*/
- if (path1) {
+ if (path1 && !is_exclude_attr(path1, object_type, opts)) {
H5TOOLS_DEBUG("call diff_attr 1:%s 2:%s ", path1, path2);
nfound += diff_attr(type1_id, type2_id, path1, path2, opts);
}
@@ -1637,7 +1735,7 @@ diff(hid_t file1_id, const char *path1, hid_t file2_id, const char *path2, diff_
do_print_objname("group", path1, path2, opts);
/* always print the number of differences found in verbose mode */
- if (opts->m_verbose)
+ if (opts->mode_verbose)
print_found(nfound);
if ((grp1_id = H5Gopen2(file1_id, path1, H5P_DEFAULT)) < 0)
@@ -1651,7 +1749,7 @@ diff(hid_t file1_id, const char *path1, hid_t file2_id, const char *path2, diff_
* referenced object
*-----------------------------------------------------------------
*/
- if (path1) {
+ if (path1 && !is_exclude_attr(path1, object_type, opts)) {
H5TOOLS_DEBUG("call diff_attr 1:%s 2:%s ", path1, path2);
nfound += diff_attr(grp1_id, grp2_id, path1, path2, opts);
}
@@ -1677,7 +1775,7 @@ diff(hid_t file1_id, const char *path1, hid_t file2_id, const char *path2, diff_
do_print_objname("link", path1, path2, opts);
/* always print the number of differences found in verbose mode */
- if (opts->m_verbose)
+ if (opts->mode_verbose)
print_found(nfound);
} break;
@@ -1725,13 +1823,13 @@ diff(hid_t file1_id, const char *path1, hid_t file2_id, const char *path2, diff_
} /* end else */
/* always print the number of differences found in verbose mode */
- if (opts->m_verbose)
+ if (opts->mode_verbose)
print_found(nfound);
} break;
case H5TRAV_TYPE_UNKNOWN:
default:
- if (opts->m_verbose)
+ if (opts->mode_verbose)
parallel_print("Comparison not supported: <%s> and <%s> are of type %s\n", path1, path2,
get_type(object_type));
opts->not_cmp = 1;
@@ -1753,7 +1851,7 @@ done:
}
/* path1 is dangling link */
else if (is_dangle_link1) {
- if (opts->m_verbose)
+ if (opts->mode_verbose)
parallel_print("obj1 <%s> is a dangling link.\n", path1);
nfound++;
if (print_objname(opts, nfound))
@@ -1761,7 +1859,7 @@ done:
}
/* path2 is dangling link */
else if (is_dangle_link2) {
- if (opts->m_verbose)
+ if (opts->mode_verbose)
parallel_print("obj2 <%s> is a dangling link.\n", path2);
nfound++;
if (print_objname(opts, nfound))