diff options
author | Allen Byrne <byrn@hdfgroup.org> | 2017-01-18 18:51:56 (GMT) |
---|---|---|
committer | Allen Byrne <byrn@hdfgroup.org> | 2017-01-18 18:51:56 (GMT) |
commit | 95242bbd5ce97f48e94bab11e8f736a60c0f509b (patch) | |
tree | b285919a49150c86a2e04838176d481df32d8461 /tools | |
parent | 509b6c24a7793b8fddd15a6abb6f9573f7adae3e (diff) | |
parent | e4b314c47c1c50b326c5f72254a662c284a26b97 (diff) | |
download | hdf5-95242bbd5ce97f48e94bab11e8f736a60c0f509b.zip hdf5-95242bbd5ce97f48e94bab11e8f736a60c0f509b.tar.gz hdf5-95242bbd5ce97f48e94bab11e8f736a60c0f509b.tar.bz2 |
Merge pull request #253 in HDFFV/hdf5 from ~BYRN/hdf5_adb:develop to develop
* commit 'e4b314c47c1c50b326c5f72254a662c284a26b97':
Fix indentation
Fix script varnames
Chnage test dir to avoid parallel test collisions
Add autotools version of plugin tests for UD filters
HDFFV-9994 add h5ls reference file to copy
HDFFV-9994 - correct reference file
HDFFV-9994 add UD tests for tools
Add goto error for dataset read failure. Fixed comments
Diffstat (limited to 'tools')
26 files changed, 1641 insertions, 87 deletions
diff --git a/tools/lib/h5diff.c b/tools/lib/h5diff.c index 79dc51f..e6ff7e0 100644 --- a/tools/lib/h5diff.c +++ b/tools/lib/h5diff.c @@ -47,7 +47,7 @@ void do_print_objname (const char *OBJ, const char *path1, const char *path2, di { /* if verbose level is higher than 0, put space line before * displaying any object or symbolic links. This improves - * readability of the output. + * readability of the output. */ if (opts->m_verbose_level >= 1) parallel_print("\n"); @@ -71,7 +71,7 @@ do_print_attrname (const char *attr, const char *path1, const char *path2) * Function: print_warn * * Purpose: check print warning condition. - * Return: + * Return: * 1 if verbose mode * 0 if not verbos mode * Programmer: Jonathan Kim @@ -146,7 +146,7 @@ static void print_incoming_data(void) * * Purpose: check if options are valid * - * Return: + * Return: * 1 : Valid * 0 : Not valid * @@ -189,10 +189,10 @@ out: * * Purpose: check if 'paths' are part of exclude path list * - * Return: + * Return: * 1 - excluded path * 0 - not excluded path - * + * * Programmer: Jonathan Kim * Date: Aug 23, 2010 *------------------------------------------------------------------------*/ @@ -221,11 +221,11 @@ static int is_exclude_path (char * path, h5trav_type_t type, diff_opt_t *options { size_t len_grp; - /* check if given path belong to an excluding group, if so + /* 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. - */ + * not under “/grp1xxx/” group. + */ len_grp = HDstrlen(exclude_path_ptr->obj_path); if (path[len_grp] == '/') { @@ -236,15 +236,15 @@ static int is_exclude_path (char * path, h5trav_type_t type, diff_opt_t *options } } /* exclude target is not group, just exclude the object */ - else + else { ret_cmp = HDstrcmp(exclude_path_ptr->obj_path, path); if (ret_cmp == 0) /* found matching object */ { /* excluded non-group object */ ret = 1; - /* remember the type of this maching object. - * if it's group, it can be used for excluding its member + /* remember the type of this maching object. + * if it's group, it can be used for excluding its member * objects in this while() loop */ exclude_path_ptr->obj_type = type; break; /* while */ @@ -339,7 +339,7 @@ static void build_match_list (const char *objname1, trav_info_t *info1, const ch path2_lp = (info2->paths[curr2].path) + path2_offset; type1_l = info1->paths[curr1].type; type2_l = info2->paths[curr2].type; - + /* criteria is string compare */ cmp = HDstrcmp(path1_lp, path2_lp); @@ -410,7 +410,7 @@ static void build_match_list (const char *objname1, trav_info_t *info1, const ch if (!is_exclude_path(path2_lp, type2_l, options)) { trav_table_addflags(infile, path2_lp, info2->paths[curr2].type, table); - } + } curr2++; } /* end while */ @@ -424,8 +424,8 @@ static void build_match_list (const char *objname1, trav_info_t *info1, const ch /*------------------------------------------------------------------------- * Function: trav_grp_objs * - * Purpose: - * Call back function from h5trav_visit(). + * Purpose: + * Call back function from h5trav_visit(). * * Programmer: Jonathan Kim * @@ -437,22 +437,22 @@ static herr_t trav_grp_objs(const char *path, const H5O_info_t *oinfo, trav_info_visit_obj(path, oinfo, already_visited, udata); return 0; -} +} /*------------------------------------------------------------------------- * Function: trav_grp_symlinks * - * Purpose: - * Call back function from h5trav_visit(). + * Purpose: + * Call back function from h5trav_visit(). * Track and extra checkings while visiting all symbolic-links. * * Programmer: Jonathan Kim * * Date: Aug 16, 2010 *------------------------------------------------------------------------*/ -static herr_t trav_grp_symlinks(const char *path, const H5L_info_t *linfo, +static herr_t trav_grp_symlinks(const char *path, const H5L_info_t *linfo, void *udata) -{ +{ trav_info_t *tinfo = (trav_info_t *)udata; diff_opt_t *opts = (diff_opt_t *)tinfo->opts; int ret; @@ -482,18 +482,18 @@ static herr_t trav_grp_symlinks(const char *path, const H5L_info_t *linfo, tinfo->symlink_visited.dangle_link = TRUE; trav_info_visit_lnk(path, linfo, tinfo); if (opts->no_dangle_links) - opts->err_stat = 1; /* make dgangling link is error */ + opts->err_stat = 1; /* make dangling link is error */ goto done; } - /* check if already visit the target object */ - if(symlink_is_visited( &(tinfo->symlink_visited), linfo->type, NULL, lnk_info.trg_path)) + /* check if already visit the target object */ + if(symlink_is_visited( &(tinfo->symlink_visited), linfo->type, NULL, lnk_info.trg_path)) goto done; /* add this link as visited link */ - if(symlink_visit_add( &(tinfo->symlink_visited), linfo->type, NULL, lnk_info.trg_path) < 0) + if(symlink_visit_add( &(tinfo->symlink_visited), linfo->type, NULL, lnk_info.trg_path) < 0) goto done; - + if(h5trav_visit(tinfo->fid, path, TRUE, TRUE, trav_grp_objs,trav_grp_symlinks, tinfo) < 0) { @@ -502,8 +502,8 @@ static herr_t trav_grp_symlinks(const char *path, const H5L_info_t *linfo, goto done; } break; - - case H5L_TYPE_EXTERNAL: + + case H5L_TYPE_EXTERNAL: ret = H5tools_get_symlink_info(tinfo->fid, path, &lnk_info, opts->follow_links); /* error */ if (ret < 0) @@ -514,21 +514,21 @@ static herr_t trav_grp_symlinks(const char *path, const H5L_info_t *linfo, tinfo->symlink_visited.dangle_link = TRUE; trav_info_visit_lnk(path, linfo, tinfo); if (opts->no_dangle_links) - opts->err_stat = 1; /* make dgangling link is error */ + opts->err_stat = 1; /* make dangling link is error */ goto done; } - if(H5Lunpack_elink_val(lnk_info.trg_path, linfo->u.val_size, NULL, &ext_fname, &ext_path) < 0) + if(H5Lunpack_elink_val(lnk_info.trg_path, linfo->u.val_size, NULL, &ext_fname, &ext_path) < 0) goto done; - /* check if already visit the target object */ - if(symlink_is_visited( &(tinfo->symlink_visited), linfo->type, ext_fname, ext_path)) + /* check if already visit the target object */ + if(symlink_is_visited( &(tinfo->symlink_visited), linfo->type, ext_fname, ext_path)) goto done; /* add this link as visited link */ - if(symlink_visit_add( &(tinfo->symlink_visited), linfo->type, ext_fname, ext_path) < 0) + if(symlink_visit_add( &(tinfo->symlink_visited), linfo->type, ext_fname, ext_path) < 0) goto done; - + if(h5trav_visit(tinfo->fid, path, TRUE, TRUE, trav_grp_objs,trav_grp_symlinks, tinfo) < 0) { @@ -548,11 +548,11 @@ static herr_t trav_grp_symlinks(const char *path, const H5L_info_t *linfo, break; } /* end of switch */ -done: +done: if (lnk_info.trg_path) HDfree(lnk_info.trg_path); return 0; -} +} /*------------------------------------------------------------------------- @@ -630,7 +630,7 @@ hsize_t h5diff(const char *fname1, H5E_BEGIN_TRY { /* 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, NULL, NULL, (size_t)0)) < 0) { parallel_print("h5diff: <%s>: unable to open file\n", fname1); options->err_stat = 1; @@ -639,7 +639,7 @@ hsize_t h5diff(const char *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, NULL, NULL, (size_t)0)) < 0) { parallel_print("h5diff: <%s>: unable to open file\n", fname2); options->err_stat = 1; @@ -704,14 +704,14 @@ hsize_t h5diff(const char *fname1, else { /* check if link itself exist */ - if(H5Lexists(file1_id, obj1fullname, H5P_DEFAULT) <= 0) + if(H5Lexists(file1_id, obj1fullname, H5P_DEFAULT) <= 0) { parallel_print ("Object <%s> could not be found in <%s>\n", obj1fullname, fname1); options->err_stat = 1; goto out; } /* get info from link */ - if(H5Lget_info(file1_id, obj1fullname, &src_linfo1, H5P_DEFAULT) < 0) + if(H5Lget_info(file1_id, obj1fullname, &src_linfo1, H5P_DEFAULT) < 0) { parallel_print("Unable to get link info from <%s>\n", obj1fullname); goto out; @@ -719,7 +719,7 @@ hsize_t h5diff(const char *fname1, info1_lp = info1_obj; - /* + /* * check the type of specified path for hard and symbolic links */ if(src_linfo1.type == H5L_TYPE_HARD) @@ -764,14 +764,14 @@ hsize_t h5diff(const char *fname1, else { /* check if link itself exist */ - if(H5Lexists(file2_id, obj2fullname, H5P_DEFAULT) <= 0) + if(H5Lexists(file2_id, obj2fullname, H5P_DEFAULT) <= 0) { parallel_print ("Object <%s> could not be found in <%s>\n", obj2fullname, fname2); options->err_stat = 1; goto out; } /* get info from link */ - if(H5Lget_info(file2_id, obj2fullname, &src_linfo2, H5P_DEFAULT) < 0) + if(H5Lget_info(file2_id, obj2fullname, &src_linfo2, H5P_DEFAULT) < 0) { parallel_print("Unable to get link info from <%s>\n", obj2fullname); goto out; @@ -779,7 +779,7 @@ hsize_t h5diff(const char *fname1, info2_lp = info2_obj; - /* + /* * check the type of specified path for hard and symbolic links */ if(src_linfo2.type == H5L_TYPE_HARD) @@ -811,7 +811,7 @@ hsize_t h5diff(const char *fname1, obj2type = H5TRAV_TYPE_UDLINK; trav_info_add(info2_obj, obj2fullname, obj2type); } - } + } } /* if no object specified */ else @@ -830,7 +830,7 @@ hsize_t h5diff(const char *fname1, l_ret2 = H5tools_get_symlink_info(file2_id, obj2fullname, &trg_linfo2, options->follow_links); /*--------------------------------------------- - * check for following symlinks + * check for following symlinks */ if (options->follow_links) { @@ -915,7 +915,7 @@ hsize_t h5diff(const char *fname1, } } } - else if(l_ret2 < 0) /* fail */ + else if(l_ret2 < 0) /* fail */ { parallel_print ("Object <%s> could not be found in <%s>\n", obj2fullname, fname2); options->err_stat = 1; @@ -936,11 +936,11 @@ hsize_t h5diff(const char *fname1, } } /* end of if follow symlinks */ - /* + /* * If verbose options is not used, don't need to traverse through the list * of objects in the group to display objects information, - * So use h5tools_is_obj_same() to improve performance by skipping - * comparing details of same objects. + * So use h5tools_is_obj_same() to improve performance by skipping + * comparing details of same objects. */ if(!(options->m_verbose || options->m_report)) @@ -1087,10 +1087,10 @@ out: /*------------------------------------------------------------------------- * Function: diff_match * - * Purpose: - * Compare common objects in given groups according to table structure. - * The table structure has flags which can be used to find common objects - * and will be compared. + * Purpose: + * Compare common objects in given groups according to table structure. + * The table structure has flags which can be used to find common objects + * and will be compared. * Common object means same name (absolute path) objects in both location. * * Return: Number of differences found @@ -1126,7 +1126,7 @@ hsize_t diff_match(hid_t file1_id, const char *grp1, trav_info_t *info1, h5difftrace("diff_match start\n"); - /* + /* * if not root, prepare object name to be pre-appended to group path to * make full path */ @@ -1141,8 +1141,8 @@ hsize_t diff_match(hid_t file1_id, const char *grp1, trav_info_t *info1, * 2) the graph must match, i.e same names (absolute path) * 3) objects with the same name must be of the same type *------------------------------------------------------------------------- - */ - + */ + /* not valid compare used when --exclude-path option is used */ if (!options->exclude_path) { @@ -1152,7 +1152,7 @@ hsize_t diff_match(hid_t file1_id, const char *grp1, trav_info_t *info1, options->contents = 0; } } - + /* objects in one file and not the other */ for( i = 0; i < table->nobjs; i++) { @@ -1209,7 +1209,7 @@ hsize_t diff_match(hid_t file1_id, const char *grp1, trav_info_t *info1, #endif /* H5_HAVE_ASPRINTF */ /* get index to figure out type of the object in file1 */ - while(info1->paths[idx1].path && + while(info1->paths[idx1].path && (HDstrcmp(obj1_fullpath, info1->paths[idx1].path) != 0)) idx1++; /* get index to figure out type of the object in file2 */ @@ -1226,7 +1226,7 @@ hsize_t diff_match(hid_t file1_id, const char *grp1, trav_info_t *info1, if(!g_Parallel) { nfound += diff(file1_id, obj1_fullpath, - file2_id, obj2_fullpath, + file2_id, obj2_fullpath, options, &argdata); } /* end if */ #ifdef H5_HAVE_PARALLEL @@ -1244,7 +1244,7 @@ hsize_t diff_match(hid_t file1_id, const char *grp1, trav_info_t *info1, */ /*Set up args to pass to worker task. */ - if(HDstrlen(obj1_fullpath) > 255 || + if(HDstrlen(obj1_fullpath) > 255 || HDstrlen(obj2_fullpath) > 255) { printf("The parallel diff only supports object names up to 255 characters\n"); @@ -1401,7 +1401,7 @@ hsize_t diff_match(hid_t file1_id, const char *grp1, trav_info_t *info1, #endif /* H5_HAVE_PARALLEL */ if(obj1_fullpath) HDfree(obj1_fullpath); - if(obj2_fullpath) + if(obj2_fullpath) HDfree(obj2_fullpath); } /* end if */ } /* end for */ @@ -1568,14 +1568,14 @@ hsize_t diff(hid_t file1_id, if(print_warn(options)) linkinfo1.opt.msg_mode = linkinfo2.opt.msg_mode = 1; - /* for symbolic links, take care follow symlink and no dangling link + /* for symbolic links, take care follow symlink and no dangling link * options */ - if (argdata->type[0] == H5TRAV_TYPE_LINK || + if (argdata->type[0] == H5TRAV_TYPE_LINK || argdata->type[0] == H5TRAV_TYPE_UDLINK || - argdata->type[1] == H5TRAV_TYPE_LINK || + argdata->type[1] == H5TRAV_TYPE_LINK || argdata->type[1] == H5TRAV_TYPE_UDLINK ) { - /* + /* * check dangling links for path1 and path2 */ @@ -1586,7 +1586,7 @@ hsize_t diff(hid_t file1_id, { if (options->no_dangle_links) { - /* gangling link is error */ + /* dangling link is error */ if(options->m_verbose) parallel_print("Warning: <%s> is a dangling link.\n", path1); goto out; @@ -1604,7 +1604,7 @@ hsize_t diff(hid_t file1_id, { if (options->no_dangle_links) { - /* gangling link is error */ + /* dangling link is error */ if(options->m_verbose) parallel_print("Warning: <%s> is a dangling link.\n", path2); goto out; @@ -1614,7 +1614,7 @@ hsize_t diff(hid_t file1_id, } else if (ret < 0) goto out; - + /* found dangling link */ if (is_dangle_link1 || is_dangle_link2) goto out2; @@ -1637,7 +1637,7 @@ hsize_t diff(hid_t file1_id, if (options->m_verbose||options->m_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]), + path1, get_type(argdata->type[0]), path2, get_type(argdata->type[1])); } options->not_cmp=1; @@ -1648,11 +1648,11 @@ hsize_t diff(hid_t file1_id, } else /* now both object types are same */ object_type = argdata->type[0]; - - /* + + /* * If both points to the same target object, skip comparing details inside * of the objects to improve performance. - * Always check for the hard links, otherwise if follow symlink option is + * Always check for the hard links, otherwise if follow symlink option is * specified. * * Perform this to match the outputs as bypassing. @@ -1672,7 +1672,7 @@ hsize_t diff(hid_t file1_id, { case H5TRAV_TYPE_DATASET: do_print_objname("dataset", path1, path2, options); - break; + break; case H5TRAV_TYPE_NAMED_DATATYPE: do_print_objname("datatype", path1, path2, options); break; @@ -1687,7 +1687,7 @@ hsize_t diff(hid_t file1_id, do_print_objname("external link", path1, path2, options); else do_print_objname ("user defined link", path1, path2, options); - break; + break; case H5TRAV_TYPE_UNKNOWN: default: parallel_print("Comparison not supported: <%s> and <%s> are of type %s\n", @@ -1735,14 +1735,14 @@ hsize_t diff(hid_t file1_id, if (nfound) { do_print_objname("dataset", path1, path2, options); - print_found(nfound); + print_found(nfound); } } /*--------------------------------------------------------- * compare attributes - * if condition refers to cases when the dataset is a + * if condition refers to cases when the dataset is a * referenced object *--------------------------------------------------------- */ @@ -1781,7 +1781,7 @@ hsize_t diff(hid_t file1_id, /*----------------------------------------------------------------- * compare attributes - * the if condition refers to cases when the dataset is a + * the if condition refers to cases when the dataset is a * referenced object *----------------------------------------------------------------- */ @@ -1813,7 +1813,7 @@ hsize_t diff(hid_t file1_id, /*----------------------------------------------------------------- * compare attributes - * the if condition refers to cases when the dataset is a + * the if condition refers to cases when the dataset is a * referenced object *----------------------------------------------------------------- */ @@ -1855,10 +1855,10 @@ hsize_t diff(hid_t file1_id, case H5TRAV_TYPE_UDLINK: { /* Only external links will have a query function registered */ - if(linkinfo1.linfo.type == H5L_TYPE_EXTERNAL && linkinfo2.linfo.type == H5L_TYPE_EXTERNAL) + if(linkinfo1.linfo.type == H5L_TYPE_EXTERNAL && linkinfo2.linfo.type == H5L_TYPE_EXTERNAL) { /* If the buffers are the same size, compare them */ - if(linkinfo1.linfo.u.val_size == linkinfo2.linfo.u.val_size) + if(linkinfo1.linfo.u.val_size == linkinfo2.linfo.u.val_size) { ret = HDmemcmp(linkinfo1.trg_path, linkinfo2.trg_path, linkinfo1.linfo.u.val_size); } @@ -1866,7 +1866,7 @@ hsize_t diff(hid_t file1_id, ret = 1; /* if "linkinfo1.trg_path" != "linkinfo2.trg_path" then the links - * are "different" extlinkinfo#.path is combination string of + * are "different" extlinkinfo#.path is combination string of * file_name and obj_name */ nfound = (ret != 0) ? 1 : 0; @@ -1875,7 +1875,7 @@ hsize_t diff(hid_t file1_id, do_print_objname("external link", path1, path2, options); } /* end if */ - else + else { /* If one or both of these links isn't an external link, we can only * compare information from H5Lget_info since we don't have a query @@ -1884,7 +1884,7 @@ hsize_t diff(hid_t file1_id, * If the link classes or the buffer length are not the * same, the links are "different" */ - if((linkinfo1.linfo.type != linkinfo2.linfo.type) || + if((linkinfo1.linfo.type != linkinfo2.linfo.type) || (linkinfo1.linfo.u.val_size != linkinfo2.linfo.u.val_size)) nfound = 1; else @@ -1922,7 +1922,7 @@ out: out2: /*----------------------------------- - * handle dangling link(s) + * handle dangling link(s) */ /* both path1 and path2 are dangling links */ if(is_dangle_link1 && is_dangle_link2) diff --git a/tools/lib/h5diff_dset.c b/tools/lib/h5diff_dset.c index 63f1483..aca8d02 100644 --- a/tools/lib/h5diff_dset.c +++ b/tools/lib/h5diff_dset.c @@ -89,6 +89,9 @@ hsize_t diff_dataset( hid_t file1_id, obj2_name, options); } + else + goto error; + /*------------------------------------------------------------------------- * close *------------------------------------------------------------------------- diff --git a/tools/test/h5diff/CMakeLists.txt b/tools/test/h5diff/CMakeLists.txt index 1d13e14..f6951a3 100644 --- a/tools/test/h5diff/CMakeLists.txt +++ b/tools/test/h5diff/CMakeLists.txt @@ -19,4 +19,32 @@ INCLUDE_DIRECTORIES (${HDF5_TOOLS_DIR}/lib) #add_test (NAME h5diffgentest COMMAND $<TARGET_FILE:h5diffgentest>) endif () + #----------------------------------------------------------------------------- + # If plugin library tests can be tested + #----------------------------------------------------------------------------- + set (HDF5_TOOL_PLUGIN_LIB_CORENAME "dynlibdiff") + set (HDF5_TOOL_PLUGIN_LIB_NAME "${HDF5_EXTERNAL_LIB_PREFIX}${HDF5_TOOL_PLUGIN_LIB_CORENAME}") + set (HDF5_TOOL_PLUGIN_LIB_TARGET ${HDF5_TOOL_PLUGIN_LIB_CORENAME}) + add_definitions (${HDF_EXTRA_C_FLAGS}) + INCLUDE_DIRECTORIES (${HDF5_SRC_DIR}) + + add_library (${HDF5_TOOL_PLUGIN_LIB_TARGET} SHARED dynlib_diff.c) + TARGET_C_PROPERTIES (${HDF5_TOOL_PLUGIN_LIB_TARGET} SHARED " " " ") + target_link_libraries (${HDF5_TOOL_PLUGIN_LIB_TARGET} ${HDF5_TEST_LIB_TARGET}) + H5_SET_LIB_OPTIONS (${HDF5_TOOL_PLUGIN_LIB_TARGET} ${HDF5_TOOL_PLUGIN_LIB_NAME} SHARED ${HDF5_PACKAGE_SOVERSION}) + + # make plugins dir + file (MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/plugins") + #----------------------------------------------------------------------------- + # Copy plugin library to a plugins folder + #----------------------------------------------------------------------------- + add_custom_command ( + TARGET ${HDF5_TOOL_PLUGIN_LIB_TARGET} + POST_BUILD + COMMAND ${CMAKE_COMMAND} + ARGS -E copy_if_different + "$<TARGET_FILE:${HDF5_TOOL_PLUGIN_LIB_TARGET}>" + "${CMAKE_BINARY_DIR}/plugins/$<TARGET_FILE_NAME:${HDF5_TOOL_PLUGIN_LIB_TARGET}>" + ) + include (CMakeTests.cmake) diff --git a/tools/test/h5diff/CMakeTests.cmake b/tools/test/h5diff/CMakeTests.cmake index 8a2781e..d098746 100644 --- a/tools/test/h5diff/CMakeTests.cmake +++ b/tools/test/h5diff/CMakeTests.cmake @@ -55,6 +55,8 @@ ${HDF5_TOOLS_TEST_H5DIFF_SOURCE_DIR}/testfiles/tmptest2.he5 ${HDF5_TOOLS_TEST_H5DIFF_SOURCE_DIR}/testfiles/tmpSingleSiteBethe.reference.h5 ${HDF5_TOOLS_TEST_H5DIFF_SOURCE_DIR}/testfiles/tmpSingleSiteBethe.output.h5 + ${HDF5_TOOLS_TEST_H5DIFF_SOURCE_DIR}/testfiles/tudfilter.h5 + ${HDF5_TOOLS_TEST_H5DIFF_SOURCE_DIR}/testfiles/tudfilter2.h5 # tools/testfiles/vds ${HDF5_TOOLS_DIR}/testfiles/vds/1_a.h5 ${HDF5_TOOLS_DIR}/testfiles/vds/1_b.h5 @@ -259,6 +261,8 @@ ${HDF5_TOOLS_TEST_H5DIFF_SOURCE_DIR}/testfiles/h5diff_90.txt ${HDF5_TOOLS_TEST_H5DIFF_SOURCE_DIR}/testfiles/h5diff_tmp1.txt ${HDF5_TOOLS_TEST_H5DIFF_SOURCE_DIR}/testfiles/h5diff_tmp2.txt + ${HDF5_TOOLS_TEST_H5DIFF_SOURCE_DIR}/testfiles/h5diff_ud.txt + ${HDF5_TOOLS_TEST_H5DIFF_SOURCE_DIR}/testfiles/h5diff_udfail.txt ${HDF5_TOOLS_TEST_H5DIFF_SOURCE_DIR}/testfiles/h5diff_v1.txt ${HDF5_TOOLS_TEST_H5DIFF_SOURCE_DIR}/testfiles/h5diff_v2.txt ${HDF5_TOOLS_TEST_H5DIFF_SOURCE_DIR}/testfiles/h5diff_v3.txt @@ -376,6 +380,51 @@ endif () ENDMACRO () + MACRO (ADD_H5_UD_TEST testname resultcode resultfile) + if (NOT HDF5_ENABLE_USING_MEMCHECKER) + # Remove any output file left over from previous test run + add_test ( + NAME H5DIFF_UD-${testname}-clearall-objects + COMMAND ${CMAKE_COMMAND} + -E remove + testfiles/${resultfile}.out + testfiles/${resultfile}.out.err + ) + if (${resultcode} STREQUAL "2") + add_test ( + NAME H5DIFF_UD-${testname} + COMMAND "${CMAKE_COMMAND}" + -D "TEST_PROGRAM=$<TARGET_FILE:h5diff>" + -D "TEST_ARGS:STRING=${ARGN}" + -D "TEST_FOLDER=${PROJECT_BINARY_DIR}/testfiles" + -D "TEST_OUTPUT=${resultfile}.out" + -D "TEST_EXPECT=${resultcode}" + -D "TEST_REFERENCE=${resultfile}.txt" + -D "TEST_APPEND=EXIT CODE:" + -D "TEST_ENV_VAR=HDF5_PLUGIN_PATH" + -D "TEST_ENV_VALUE=${CMAKE_BINARY_DIR}" + -P "${HDF_RESOURCES_EXT_DIR}/runTest.cmake" + ) + else () + add_test ( + NAME H5DIFF_UD-${testname} + COMMAND "${CMAKE_COMMAND}" + -D "TEST_PROGRAM=$<TARGET_FILE:h5diff>" + -D "TEST_ARGS:STRING=${ARGN}" + -D "TEST_FOLDER=${PROJECT_BINARY_DIR}/testfiles" + -D "TEST_OUTPUT=${resultfile}.out" + -D "TEST_EXPECT=${resultcode}" + -D "TEST_REFERENCE=${resultfile}.txt" + -D "TEST_APPEND=EXIT CODE:" + -D "TEST_ENV_VAR=HDF5_PLUGIN_PATH" + -D "TEST_ENV_VALUE=${CMAKE_BINARY_DIR}/plugins" + -P "${HDF_RESOURCES_EXT_DIR}/runTest.cmake" + ) + endif () + set_tests_properties (H5DIFF_UD-${testname} PROPERTIES DEPENDS H5DIFF_UD-${testname}-clearall-objects) + endif () + ENDMACRO () + ############################################################################## ############################################################################## ### T H E T E S T S ### @@ -1393,3 +1442,8 @@ ADD_H5_TEST (h5diff_v1 0 -v ${FILEV1} ${FILEV2}) ADD_H5_TEST (h5diff_v2 0 -r ${FILEV1} ${FILEV2}) ADD_H5_TEST (h5diff_v3 0 -c ${FILEV1} ${FILEV2}) +############################################################################## +### P L U G I N T E S T S +############################################################################## +ADD_H5_UD_TEST (h5diff_plugin_test 0 h5diff_ud -v tudfilter.h5 tudfilter2.h5) +ADD_H5_UD_TEST (h5diff_plugin_fail 2 h5diff_udfail -v tudfilter.h5 tudfilter2.h5) diff --git a/tools/test/h5diff/Makefile.am b/tools/test/h5diff/Makefile.am index c366199..1d700ea 100644 --- a/tools/test/h5diff/Makefile.am +++ b/tools/test/h5diff/Makefile.am @@ -38,6 +38,11 @@ check_PROGRAMS=$(TEST_PROG) check_SCRIPTS=$(TEST_SCRIPT) $(TEST_SCRIPT_PARA) # The parallel test script testph5diff.sh actually depends on testh5diff.sh. SCRIPT_DEPEND=../../src/h5diff/h5diff$(EXEEXT) $(H5PDIFF) ../../src/h5diff/testh5diff.sh +if HAVE_SHARED_CONDITIONAL +if USE_PLUGINS_CONDITIONAL + TEST_SCRIPT += h5diff_plugin.sh +endif +endif # Source files for the program h5diffgentest_SOURCES=h5diffgentest.c @@ -45,9 +50,20 @@ h5diffgentest_SOURCES=h5diffgentest.c # Programs depend on the main HDF5 library and tools library LDADD=$(LIBH5TOOLS) $(LIBHDF5) +if HAVE_SHARED_CONDITIONAL + # Build it as shared library if configure is enabled for shared library. + lib_LTLIBRARIES=libdynlibdiff.la + libdynlibdiff_la_SOURCES=dynlib_diff.c + +install-exec-hook: + $(RM) $(DESTDIR)$(libdir)/*dynlib* +endif + # Temporary files. *.h5 are generated by h5diff. They should # be copied to the testfiles/ directory if update is required CHECK_CLEANFILES+=*.h5 expect_sorted actual_sorted +DISTCLEANFILES=h5diff_plugin.sh + include $(top_srcdir)/config/conclude.am diff --git a/tools/test/h5diff/dynlib_diff.c b/tools/test/h5diff/dynlib_diff.c new file mode 100644 index 0000000..0d8be2b --- /dev/null +++ b/tools/test/h5diff/dynlib_diff.c @@ -0,0 +1,94 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic document set and is * + * linked from the top-level documents page. It can also be found at * + * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have access * + * to either file, you may request a copy from help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* + * Programmer: Raymond Lu + * 13 February 2013 + * + * Purpose: Tests the plugin module (H5PL) + */ + +#include <stdlib.h> +#include <stdio.h> +#include "H5PLextern.h" + +#define H5Z_FILTER_DYNLIB2 258 +#define MULTIPLIER 3 + +static size_t H5Z_filter_dynlib2(unsigned int flags, size_t cd_nelmts, + const unsigned int *cd_values, size_t nbytes, size_t *buf_size, void **buf); + +/* This message derives from H5Z */ +const H5Z_class2_t H5Z_DYNLIB2[1] = {{ + H5Z_CLASS_T_VERS, /* H5Z_class_t version */ + H5Z_FILTER_DYNLIB2, /* Filter id number */ + 1, 1, /* Encoding and decoding enabled */ + "dynlib2", /* Filter name for debugging */ + NULL, /* The "can apply" callback */ + NULL, /* The "set local" callback */ + (H5Z_func_t)H5Z_filter_dynlib2, /* The actual filter function */ +}}; + +H5PL_type_t H5PLget_plugin_type(void) {return H5PL_TYPE_FILTER;} +const void *H5PLget_plugin_info(void) {return H5Z_DYNLIB2;} + +/*------------------------------------------------------------------------- + * Function: H5Z_filter_dynlib2 + * + * Purpose: A dynlib2 filter method that multiplies the original value + * during write and divide the original value during read. It + * will be built as a shared library. plugin.c test will load + * and use this filter library. + * + * Return: Success: Data chunk size + * + * Failure: 0 + * + * Programmer: Raymond Lu + * 29 March 2013 + * + *------------------------------------------------------------------------- + */ +static size_t +H5Z_filter_dynlib2(unsigned int flags, size_t cd_nelmts, + const unsigned int *cd_values, size_t nbytes, + size_t *buf_size, void **buf) +{ + int *int_ptr = (int *)*buf; /* Pointer to the data values */ + size_t buf_left = *buf_size; /* Amount of data buffer left to process */ + + /* Check for the correct number of parameters */ + if(cd_nelmts > 0) + return(0); + + /* Assignment to eliminate unused parameter warning. */ + cd_values = cd_values; + + if(flags & H5Z_FLAG_REVERSE) { /*read*/ + /* Divide the original value with MULTIPLIER */ + while(buf_left > 0) { + *int_ptr++ /= MULTIPLIER; + buf_left -= sizeof(int); + } /* end while */ + } /* end if */ + else { /*write*/ + /* Multiply the original value with MULTIPLIER */ + while(buf_left > 0) { + *int_ptr++ *= MULTIPLIER; + buf_left -= sizeof(int); + } /* end while */ + } /* end else */ + + return nbytes; +} /* end H5Z_filter_dynlib2() */ + diff --git a/tools/test/h5diff/h5diff_plugin.sh.in b/tools/test/h5diff/h5diff_plugin.sh.in new file mode 100644 index 0000000..ffd2ea1 --- /dev/null +++ b/tools/test/h5diff/h5diff_plugin.sh.in @@ -0,0 +1,315 @@ +#! /bin/sh +# +# Copyright by The HDF Group. +# All rights reserved. +# +# This file is part of HDF5. The full HDF5 copyright notice, including +# terms governing use, modification, and redistribution, is contained in +# the files COPYING and Copyright.html. COPYING can be found at the root +# of the source code distribution tree; Copyright.html can be found at the +# root level of an installed copy of the electronic document set and is +# linked from the top-level documents page. It can also be found at +# http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have access +# to either file, you may request a copy from help@hdfgroup.org. +# +srcdir=@srcdir@ +TOP_BUILDDIR=@top_builddir@ + +# Determine backward compatibility options enabled +DEPRECATED_SYMBOLS="@DEPRECATED_SYMBOLS@" + +EXIT_SUCCESS=0 +EXIT_FAILURE=1 + +H5DIFF=../../src/h5diff/h5diff # The tool name +H5DIFF_BIN=`pwd`/$H5DIFF # The path of the tool binary + +nerrors=0 +verbose=yes +h5haveexitcode=yes # default is yes + +TEST_NAME=ud_plugin +FROM_DIR=`pwd`/.libs +PLUGIN_LIB="$FROM_DIR/libdynlibdiff.*" +PLUGIN_LIBDIR=testdir3 +RM='rm -rf' + +RM='rm -rf' +CMP='cmp -s' +DIFF='diff -c' +CP='cp' +DIRNAME='dirname' +LS='ls' +AWK='awk' + +# source dirs +SRC_TOOLS="$srcdir/../.." + +# testfiles source dirs for tools +SRC_H5DIFF_TESTFILES="$SRC_TOOLS/test/h5diff/testfiles" + +TESTDIR=./testplug +test -d $TESTDIR || mkdir $TESTDIR + +###################################################################### +# test files +# -------------------------------------------------------------------- +# All the test files copy from source directory to test directory +# NOTE: Keep this framework to add/remove test files. +# Any test files from other tools can be used in this framework. +# This list are also used for checking exist. +# Comment '#' without space can be used. +# -------------------------------------------------------------------- +LIST_HDF5_TEST_FILES=" +$SRC_H5DIFF_TESTFILES/tudfilter.h5 +$SRC_H5DIFF_TESTFILES/tudfilter2.h5 +$SRC_H5DIFF_TESTFILES/h5diff_ud.txt +$SRC_H5DIFF_TESTFILES/h5diff_udfail.txt +" + +# Main Body +# Create test directories if not exists yet. +test -d $PLUGIN_LIBDIR || mkdir -p $PLUGIN_LIBDIR +if [ $? != 0 ]; then + echo "Failed to create test directory($PLUGIN_LIBDIR)" + exit $EXIT_FAILURE +fi + +# copy plugin library for test +$CP $PLUGIN_LIB $PLUGIN_LIBDIR +if [ $? != 0 ]; then + echo "Failed to copy plugin library ($PLUGIN_LIB) for test." + exit $EXIT_FAILURE +fi + +# setup plugin path +ENVCMD="env HDF5_PLUGIN_PATH=../${PLUGIN_LIBDIR}" + +# +# copy test files and expected output files from source dirs to test dir +# +COPY_TESTFILES="$LIST_HDF5_TEST_FILES" + +COPY_TESTFILES_TO_TESTDIR() +{ + # copy test files. Used -f to make sure get a new copy + for tstfile in $COPY_TESTFILES + do + # ignore '#' comment + echo $tstfile | tr -d ' ' | grep '^#' > /dev/null + RET=$? + if [ $RET -eq 1 ]; then + # skip cp if srcdir is same as destdir + # this occurs when build/test performed in source dir and + # make cp fail + SDIR=`$DIRNAME $tstfile` + INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'` + INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'` + if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then + $CP -f $tstfile $TESTDIR + if [ $? -ne 0 ]; then + echo "Error: FAILED to copy $tstfile ." + + # Comment out this to CREATE expected file + exit $EXIT_FAILURE + fi + fi + fi + done +} + +CLEAN_TESTFILES_AND_TESTDIR() +{ + # skip rm if srcdir is same as destdir + # this occurs when build/test performed in source dir and + # make cp fail + SDIR=$SRC_H5DIFF_TESTFILES + INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'` + INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'` + if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then + $RM $TESTDIR + fi +} + +# Parse option +# -p run ph5diff tests +# -h print help page +while [ $# -gt 0 ]; do + case "$1" in + -p) # reset the tool name and bin to run ph5diff tests + TESTNAME=ph5diff + H5DIFF=../../src/h5diff/ph5diff # The tool name + H5DIFF_BIN=`pwd`/$H5DIFF # The path of the tool binary + pmode=yes + shift + ;; + -h) # print help page + echo "$0 [-p] [-h]" + echo " -p run ph5diff tests" + echo " -h print help page" + shift + exit 0 + ;; + *) # unknown option + echo "$0: Unknown option ($1)" + exit 1 + ;; + esac +done + +# RUNSERIAL is used. Check if it can return exit code from executalbe correctly. +if [ -n "$RUNSERIAL_NOEXITCODE" ]; then + echo "***Warning*** Serial Exit Code is not passed back to shell corretly." + echo "***Warning*** Exit code checking is skipped." + h5haveexitcode=no +fi + + +# Print a $* message left justified in a field of 70 characters +# +MESSAGE() { + SPACES=" " + echo "$* $SPACES" | cut -c1-70 | tr -d '\012' +} + +# Print a line-line message left justified in a field of 70 characters +# beginning with the word "Testing". +# +TESTING() { + SPACES=" " + echo "Testing $* $SPACES" | cut -c1-70 | tr -d '\012' +} + +# Print a line-line message left justified in a field of 70 characters +# beginning with the word "Verifying". +# +VERIFY() { + MESSAGE "Verifying $*" +} + +# Source in the output filter function definitions. +. $srcdir/../../../bin/output_filter.sh + +# Run a test and print PASS or *FAIL*. If a test fails then increment +# the `nerrors' global variable and (if $verbose is set) display the +# difference between the actual output and the expected output. The +# expected output is given as the first argument to this function and +# the actual output file is calculated by replacing the `.ddl' with +# `.out'. The actual output is not removed if $HDF5_NOCLEANUP has a +# non-zero value. +# +# Need eval before the RUNCMD command because some machines like +# AIX, has RUNPARALLEL in the style as +# MP_PROCS=3 MP_TASKS_PER_NODE=3 poe ./a.out +# that throws the shell script off. +# +TOOLTEST() { + expect="$TESTDIR/$1" + actual="$TESTDIR/`basename $1 .txt`.out" + actual_err="$TESTDIR/`basename $1 .txt`.err" + actual_sav=${actual}-sav + actual_err_sav=${actual_err}-sav + shift + if test -n "$pmode"; then + RUNCMD=$RUNPARALLEL + else + RUNCMD=$RUNSERIAL + fi + + # Run test. + TESTING $H5DIFF $@ + ( + #echo "#############################" + #echo "Expected output for '$H5DIFF $@'" + #echo "#############################" + cd $TESTDIR + eval $ENVCMD $RUNCMD $H5DIFF_BIN "$@" + ) >$actual 2>$actual_err + EXIT_CODE=$? + # save actual and actual_err in case they are needed later. + cp $actual $actual_sav + STDOUT_FILTER $actual + cp $actual_err $actual_err_sav + STDERR_FILTER $actual_err + cat $actual_err >> $actual + # don't add exit code check in pmode, as it causes failure. (exit code + # is from mpirun not tool) + # if any problem occurs relate to an exit code, it will be caught in + # serial mode, so the test is fullfilled. + if test $h5haveexitcode = 'yes' -a -z "$pmode"; then + echo "EXIT CODE: $EXIT_CODE" >> $actual + fi + + if [ ! -f $expect ]; then + # Create the expect file if it doesn't yet exist. + echo " CREATED" + cp $actual $expect + elif $CMP $expect $actual; then + echo " PASSED" + elif test $h5haveexitcode = 'yes' -a -z "$pmode"; then + echo "*FAILED*" + echo " Expected result ($expect) differs from actual result ($actual)" + nerrors="`expr $nerrors + 1`" + test yes = "$verbose" && $DIFF $expect $actual |sed 's/^/ /' + else + # parallel mode output are often of different ordering from serial + # output. If the sorted expected and actual files compare the same, + # it is safe to assume the actual output match the expected file. + expect_sorted=expect_sorted + actual_sorted=actual_sorted + sort $expect -o $expect_sorted + sort $actual -o $actual_sorted + # remove "EXIT CODE:" line from expect file. test for exit code + # is done by serial mode. + grep -v "EXIT CODE:" $expect_sorted > $expect_sorted.noexit + mv $expect_sorted.noexit $expect_sorted + if $CMP $expect_sorted $actual_sorted; then + echo " PASSED" + else + echo "*FAILED*" + nerrors="`expr $nerrors + 1`" + if test yes = "$verbose"; then + echo "====Expected result ($expect_sorted) differs from actual result ($actual_sorted)" + $DIFF $expect_sorted $actual_sorted |sed 's/^/ /' + echo "====The actual output ($actual_sav)" + sed 's/^/ /' < $actual_sav + echo "====The actual stderr ($actual_err_sav)" + sed 's/^/ /' < $actual_err_sav + echo "====End of actual stderr ($actual_err_sav)" + echo "" + fi + fi + fi + + # Clean up output file + if test -z "$HDF5_NOCLEANUP"; then + rm -f $actual $actual_err $actual_sav $actual_err_sav + rm -f $actual_sorted $expect_sorted + fi +} + +############################################################################## +### T H E T E S T S +############################################################################## +# prepare for test +COPY_TESTFILES_TO_TESTDIR + +# Run the test +TOOLTEST h5diff_ud.txt -v tudfilter.h5 tudfilter2.h5 + +# print results +if test $nerrors -ne 0 ; then + echo "$nerrors errors encountered" + exit_code=$EXIT_FAILURE +else + echo "All Plugin API tests passed." + exit_code=$EXIT_SUCCESS +fi + +# Clean up temporary files/directories +CLEAN_TESTFILES_AND_TESTDIR + +# Clean up temporary files/directories and leave +$RM $PLUGIN_LIBDIR + +exit $exit_code diff --git a/tools/test/h5diff/testfiles/h5diff_ud.txt b/tools/test/h5diff/testfiles/h5diff_ud.txt new file mode 100644 index 0000000..7c9bb5e --- /dev/null +++ b/tools/test/h5diff/testfiles/h5diff_ud.txt @@ -0,0 +1,11 @@ + +file1 file2 +--------------------------------------- + x x / + x x /dynlib2 + +group : </> and </> +0 differences found +dataset: </dynlib2> and </dynlib2> +0 differences found +EXIT CODE: 0 diff --git a/tools/test/h5diff/testfiles/h5diff_udfail.txt b/tools/test/h5diff/testfiles/h5diff_udfail.txt new file mode 100644 index 0000000..7eb1155 --- /dev/null +++ b/tools/test/h5diff/testfiles/h5diff_udfail.txt @@ -0,0 +1,12 @@ + +file1 file2 +--------------------------------------- + x x / + x x /dynlib2 + +group : </> and </> +0 differences found +dataset: </dynlib2> and </dynlib2> +0 differences found +warning: dataset </dynlib2> cannot be read, user defined filter is not available +EXIT CODE: 2 diff --git a/tools/test/h5diff/testfiles/tudfilter.h5 b/tools/test/h5diff/testfiles/tudfilter.h5 Binary files differnew file mode 100644 index 0000000..eaf6a43 --- /dev/null +++ b/tools/test/h5diff/testfiles/tudfilter.h5 diff --git a/tools/test/h5diff/testfiles/tudfilter2.h5 b/tools/test/h5diff/testfiles/tudfilter2.h5 Binary files differnew file mode 100644 index 0000000..eaf6a43 --- /dev/null +++ b/tools/test/h5diff/testfiles/tudfilter2.h5 diff --git a/tools/test/h5dump/CMakeLists.txt b/tools/test/h5dump/CMakeLists.txt index cc399d1..89c7534 100644 --- a/tools/test/h5dump/CMakeLists.txt +++ b/tools/test/h5dump/CMakeLists.txt @@ -6,6 +6,34 @@ PROJECT (HDF5_TOOLS_TEST_H5DUMP) #----------------------------------------------------------------------------- INCLUDE_DIRECTORIES (${HDF5_TOOLS_DIR}/lib) + #----------------------------------------------------------------------------- + # If plugin library tests can be tested + #----------------------------------------------------------------------------- + set (HDF5_TOOL_PLUGIN_LIB_CORENAME "dynlibdump") + set (HDF5_TOOL_PLUGIN_LIB_NAME "${HDF5_EXTERNAL_LIB_PREFIX}${HDF5_TOOL_PLUGIN_LIB_CORENAME}") + set (HDF5_TOOL_PLUGIN_LIB_TARGET ${HDF5_TOOL_PLUGIN_LIB_CORENAME}) + add_definitions (${HDF_EXTRA_C_FLAGS}) + INCLUDE_DIRECTORIES (${HDF5_SRC_DIR}) + + add_library (${HDF5_TOOL_PLUGIN_LIB_TARGET} SHARED dynlib_dump.c) + TARGET_C_PROPERTIES (${HDF5_TOOL_PLUGIN_LIB_TARGET} SHARED " " " ") + target_link_libraries (${HDF5_TOOL_PLUGIN_LIB_TARGET} ${HDF5_TEST_LIB_TARGET}) + H5_SET_LIB_OPTIONS (${HDF5_TOOL_PLUGIN_LIB_TARGET} ${HDF5_TOOL_PLUGIN_LIB_NAME} SHARED ${HDF5_PACKAGE_SOVERSION}) + + # make plugins dir + file (MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/plugins") + #----------------------------------------------------------------------------- + # Copy plugin library to a plugins folder + #----------------------------------------------------------------------------- + add_custom_command ( + TARGET ${HDF5_TOOL_PLUGIN_LIB_TARGET} + POST_BUILD + COMMAND ${CMAKE_COMMAND} + ARGS -E copy_if_different + "$<TARGET_FILE:${HDF5_TOOL_PLUGIN_LIB_TARGET}>" + "${CMAKE_BINARY_DIR}/plugins/$<TARGET_FILE_NAME:${HDF5_TOOL_PLUGIN_LIB_TARGET}>" + ) + # -------------------------------------------------------------------- # Add the h5dump test executable # -------------------------------------------------------------------- diff --git a/tools/test/h5dump/CMakeTests.cmake b/tools/test/h5dump/CMakeTests.cmake index ddfbfbc..1a335b2 100644 --- a/tools/test/h5dump/CMakeTests.cmake +++ b/tools/test/h5dump/CMakeTests.cmake @@ -166,6 +166,7 @@ ${HDF5_TOOLS_DIR}/testfiles/tstring2.ddl ${HDF5_TOOLS_DIR}/testfiles/tstringe.ddl ${HDF5_TOOLS_DIR}/testfiles/tszip.ddl + ${HDF5_TOOLS_DIR}/testfiles/tudfilter.ddl ${HDF5_TOOLS_DIR}/testfiles/tudlink-1.ddl ${HDF5_TOOLS_DIR}/testfiles/tudlink-2.ddl ${HDF5_TOOLS_DIR}/testfiles/tuserfilter.ddl @@ -291,6 +292,7 @@ ${HDF5_TOOLS_DIR}/testfiles/tstr.h5 ${HDF5_TOOLS_DIR}/testfiles/tstr2.h5 ${HDF5_TOOLS_DIR}/testfiles/tstr3.h5 + ${HDF5_TOOLS_DIR}/testfiles/tudfilter.h5 ${HDF5_TOOLS_DIR}/testfiles/tudlink.h5 ${HDF5_TOOLS_DIR}/testfiles/tvldtypes1.h5 ${HDF5_TOOLS_DIR}/testfiles/tvldtypes2.h5 @@ -680,9 +682,36 @@ endif () ENDMACRO () + MACRO (ADD_H5_UD_TEST testname resultcode resultfile) + if (NOT HDF5_ENABLE_USING_MEMCHECKER) + # Remove any output file left over from previous test run + add_test ( + NAME H5DUMP_UD-${testname}-clearall-objects + COMMAND ${CMAKE_COMMAND} + -E remove + testfiles/std/${resultfile}.out + testfiles/std/${resultfile}.out.err + ) + add_test ( + NAME H5DUMP_UD-${testname} + COMMAND "${CMAKE_COMMAND}" + -D "TEST_PROGRAM=$<TARGET_FILE:h5dump>" + -D "TEST_ARGS:STRING=${ARGN}" + -D "TEST_FOLDER=${PROJECT_BINARY_DIR}/testfiles/std" + -D "TEST_OUTPUT=${resultfile}.out" + -D "TEST_EXPECT=${resultcode}" + -D "TEST_REFERENCE=${resultfile}.ddl" + -D "TEST_ENV_VAR=HDF5_PLUGIN_PATH" + -D "TEST_ENV_VALUE=${CMAKE_BINARY_DIR}/plugins" + -P "${HDF_RESOURCES_EXT_DIR}/runTest.cmake" + ) + set_tests_properties (H5DUMP_UD-${testname} PROPERTIES DEPENDS H5DUMP_UD-${testname}-clearall-objects) + endif () + ENDMACRO () + ############################################################################## ############################################################################## -### T H E T E S T S HDF5_ENABLE_USING_MEMCHECKER ### +### T H E T E S T S ### ############################################################################## ############################################################################## @@ -1421,3 +1450,8 @@ # test for non-existing file ADD_H5_TEST (non_existing 1 --enable-error-stack tgroup.h5 non_existing.h5) + +############################################################################## +### P L U G I N T E S T S +############################################################################## +ADD_H5_UD_TEST (h5dump_plugin_test 0 tudfilter --enable-error-stack tudfilter.h5) diff --git a/tools/test/h5dump/Makefile.am b/tools/test/h5dump/Makefile.am index aed34ec..a3d1df7 100644 --- a/tools/test/h5dump/Makefile.am +++ b/tools/test/h5dump/Makefile.am @@ -30,13 +30,27 @@ TEST_SCRIPT=testh5dump.sh testh5dumppbits.sh testh5dumpvds.sh testh5dumpxml.sh check_PROGRAMS=$(TEST_PROG) binread check_SCRIPTS=$(TEST_SCRIPT) SCRIPT_DEPEND=../../src/h5dump/h5dump$(EXEEXT) +if HAVE_SHARED_CONDITIONAL +if USE_PLUGINS_CONDITIONAL + TEST_SCRIPT += h5dump_plugin.sh +endif +endif # All the programs depend on the hdf5 and h5tools libraries LDADD=$(LIBH5TOOLS) $(LIBHDF5) +if HAVE_SHARED_CONDITIONAL + # Build it as shared library if configure is enabled for shared library. + lib_LTLIBRARIES=libdynlibdump.la + libdynlibdump_la_SOURCES=dynlib_dump.c + +install-exec-hook: + $(RM) $(DESTDIR)$(libdir)/*dynlib* +endif + # Temporary files. *.h5 are generated by h5dumpgentest. They should # copied to the testfiles/ directory if update is required. CHECK_CLEANFILES+=*.h5 *.bin -DISTCLEANFILES=testh5dump.sh testh5dumppbits.sh testh5dumpxml.sh +DISTCLEANFILES=testh5dump.sh testh5dumppbits.sh testh5dumpxml.sh h5dump_plugin.sh include $(top_srcdir)/config/conclude.am diff --git a/tools/test/h5dump/dynlib_dump.c b/tools/test/h5dump/dynlib_dump.c new file mode 100644 index 0000000..0d8be2b --- /dev/null +++ b/tools/test/h5dump/dynlib_dump.c @@ -0,0 +1,94 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic document set and is * + * linked from the top-level documents page. It can also be found at * + * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have access * + * to either file, you may request a copy from help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* + * Programmer: Raymond Lu + * 13 February 2013 + * + * Purpose: Tests the plugin module (H5PL) + */ + +#include <stdlib.h> +#include <stdio.h> +#include "H5PLextern.h" + +#define H5Z_FILTER_DYNLIB2 258 +#define MULTIPLIER 3 + +static size_t H5Z_filter_dynlib2(unsigned int flags, size_t cd_nelmts, + const unsigned int *cd_values, size_t nbytes, size_t *buf_size, void **buf); + +/* This message derives from H5Z */ +const H5Z_class2_t H5Z_DYNLIB2[1] = {{ + H5Z_CLASS_T_VERS, /* H5Z_class_t version */ + H5Z_FILTER_DYNLIB2, /* Filter id number */ + 1, 1, /* Encoding and decoding enabled */ + "dynlib2", /* Filter name for debugging */ + NULL, /* The "can apply" callback */ + NULL, /* The "set local" callback */ + (H5Z_func_t)H5Z_filter_dynlib2, /* The actual filter function */ +}}; + +H5PL_type_t H5PLget_plugin_type(void) {return H5PL_TYPE_FILTER;} +const void *H5PLget_plugin_info(void) {return H5Z_DYNLIB2;} + +/*------------------------------------------------------------------------- + * Function: H5Z_filter_dynlib2 + * + * Purpose: A dynlib2 filter method that multiplies the original value + * during write and divide the original value during read. It + * will be built as a shared library. plugin.c test will load + * and use this filter library. + * + * Return: Success: Data chunk size + * + * Failure: 0 + * + * Programmer: Raymond Lu + * 29 March 2013 + * + *------------------------------------------------------------------------- + */ +static size_t +H5Z_filter_dynlib2(unsigned int flags, size_t cd_nelmts, + const unsigned int *cd_values, size_t nbytes, + size_t *buf_size, void **buf) +{ + int *int_ptr = (int *)*buf; /* Pointer to the data values */ + size_t buf_left = *buf_size; /* Amount of data buffer left to process */ + + /* Check for the correct number of parameters */ + if(cd_nelmts > 0) + return(0); + + /* Assignment to eliminate unused parameter warning. */ + cd_values = cd_values; + + if(flags & H5Z_FLAG_REVERSE) { /*read*/ + /* Divide the original value with MULTIPLIER */ + while(buf_left > 0) { + *int_ptr++ /= MULTIPLIER; + buf_left -= sizeof(int); + } /* end while */ + } /* end if */ + else { /*write*/ + /* Multiply the original value with MULTIPLIER */ + while(buf_left > 0) { + *int_ptr++ *= MULTIPLIER; + buf_left -= sizeof(int); + } /* end while */ + } /* end else */ + + return nbytes; +} /* end H5Z_filter_dynlib2() */ + diff --git a/tools/test/h5dump/h5dump_plugin.sh.in b/tools/test/h5dump/h5dump_plugin.sh.in new file mode 100644 index 0000000..d19981e --- /dev/null +++ b/tools/test/h5dump/h5dump_plugin.sh.in @@ -0,0 +1,241 @@ +#! /bin/sh +# +# Copyright by The HDF Group. +# All rights reserved. +# +# This file is part of HDF5. The full HDF5 copyright notice, including +# terms governing use, modification, and redistribution, is contained in +# the files COPYING and Copyright.html. COPYING can be found at the root +# of the source code distribution tree; Copyright.html can be found at the +# root level of an installed copy of the electronic document set and is +# linked from the top-level documents page. It can also be found at +# http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have access +# to either file, you may request a copy from help@hdfgroup.org. +# +srcdir=@srcdir@ +TOP_BUILDDIR=@top_builddir@ + +# Determine backward compatibility options enabled +DEPRECATED_SYMBOLS="@DEPRECATED_SYMBOLS@" + +EXIT_SUCCESS=0 +EXIT_FAILURE=1 + +H5DUMP=../../src/h5dump/h5dump # The h5dump tool name +H5DUMP_BIN=`pwd`/$H5DUMP # The path of the h5dump tool binary + +nerrors=0 +verbose=yes +h5haveexitcode=yes # default is yes + +TEST_NAME=ud_plugin +FROM_DIR=`pwd`/.libs +PLUGIN_LIB="$FROM_DIR/libdynlibdump.*" +PLUGIN_LIBDIR=testdir3 +RM='rm -rf' + +RM='rm -rf' +GREP='grep' +CMP='cmp' +DIFF='diff -c' +CP='cp' +DIRNAME='dirname' +LS='ls' +AWK='awk' + +# source dirs +SRC_TOOLS="$srcdir/../.." + +# testfiles source dirs for tools +SRC_TOOLS_TESTFILES="$SRC_TOOLS/testfiles" +SRC_H5DUMP_TESTFILES="$SRC_TOOLS_TESTFILES" + +TESTDIR=./testplug +test -d $TESTDIR || mkdir $TESTDIR + +###################################################################### +# test files +# -------------------------------------------------------------------- +# All the test files copy from source directory to test directory +# NOTE: Keep this framework to add/remove test files. +# Any test files from other tools can be used in this framework. +# This list are also used for checking exist. +# Comment '#' without space can be used. +# -------------------------------------------------------------------- +LIST_HDF5_TEST_FILES=" +$SRC_H5DUMP_TESTFILES/tudfilter.h5 +$SRC_H5DUMP_TESTFILES/tudfilter.ddl +" + +# RUNSERIAL is used. Check if it can return exit code from executable correctly. +if [ -n "$RUNSERIAL_NOEXITCODE" ]; then + echo "***Warning*** Serial Exit Code is not passed back to shell correctly." + echo "***Warning*** Exit code checking is skipped." + h5haveexitcode=no +fi + +# Main Body +# Create test directories if not exists yet. +test -d $PLUGIN_LIBDIR || mkdir -p $PLUGIN_LIBDIR +if [ $? != 0 ]; then + echo "Failed to create test directory($PLUGIN_LIBDIR)" + exit $EXIT_FAILURE +fi + +# copy plugin library for test +$CP $PLUGIN_LIB $PLUGIN_LIBDIR +if [ $? != 0 ]; then + echo "Failed to copy plugin library ($PLUGIN_LIB) for test." + exit $EXIT_FAILURE +fi + +# setup plugin path +ENVCMD="env HDF5_PLUGIN_PATH=../${PLUGIN_LIBDIR}" + +# +# copy test files and expected output files from source dirs to test dir +# +COPY_TESTFILES="$LIST_HDF5_TEST_FILES" + +COPY_TESTFILES_TO_TESTDIR() +{ + # copy test files. Used -f to make sure get a new copy + for tstfile in $COPY_TESTFILES + do + # ignore '#' comment + echo $tstfile | tr -d ' ' | grep '^#' > /dev/null + RET=$? + if [ $RET -eq 1 ]; then + # skip cp if srcdir is same as destdir + # this occurs when build/test performed in source dir and + # make cp fail + SDIR=`$DIRNAME $tstfile` + INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'` + INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'` + if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then + $CP -f $tstfile $TESTDIR + if [ $? -ne 0 ]; then + echo "Error: FAILED to copy $tstfile ." + + # Comment out this to CREATE expected file + exit $EXIT_FAILURE + fi + fi + fi + done +} + +CLEAN_TESTFILES_AND_TESTDIR() +{ + # skip rm if srcdir is same as destdir + # this occurs when build/test performed in source dir and + # make cp fail + SDIR=$SRC_H5DUMP_TESTFILES + INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'` + INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'` + if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then + $RM $TESTDIR + fi +} + +# Print a $* message left justified in a field of 70 characters +# +MESSAGE() { + SPACES=" " + echo "$* $SPACES" | cut -c1-70 | tr -d '\012' +} + +# Print a line-line message left justified in a field of 70 characters +# beginning with the word "Testing". +# +TESTING() { + SPACES=" " + echo "Testing $* $SPACES" | cut -c1-70 | tr -d '\012' +} + +# Print a line-line message left justified in a field of 70 characters +# beginning with the word "Verifying". +# +VERIFY() { + MESSAGE "Verifying $*" +} + +# Source in the output filter function definitions. +. $srcdir/../../../bin/output_filter.sh + +# Run a test and print PASS or *FAIL*. If a test fails then increment +# the `nerrors' global variable and (if $verbose is set) display the +# difference between the actual output and the expected output. The +# expected output is given as the first argument to this function and +# the actual output file is calculated by replacing the `.ddl' with +# `.out'. The actual output is not removed if $HDF5_NOCLEANUP has a +# non-zero value. +# If $1 == ignorecase then do caseless CMP and DIFF. +# ADD_H5_TEST +TOOLTEST() { + expect="$TESTDIR/$1" + actual="$TESTDIR/`basename $1 .ddl`.out" + actual_err="$TESTDIR/`basename $1 .ddl`.err" + actual_sav=${actual}-sav + actual_err_sav=${actual_err}-sav + shift + + # Run test. + TESTING $H5DUMP $@ + ( + cd $TESTDIR + $ENVCMD $RUNSERIAL $H5DUMP_BIN "$@" + ) >$actual 2>$actual_err + + # save actual and actual_err in case they are needed later. + cp $actual $actual_sav + STDOUT_FILTER $actual + cp $actual_err $actual_err_sav + STDERR_FILTER $actual_err + cat $actual_err >> $actual + + if [ ! -f $expect ]; then + # Create the expect file if it doesn't yet exist. + echo " CREATED" + cp $actual $expect + elif $CMP $expect $actual > /dev/null 2>&1 ; then + echo " PASSED" + else + echo "*FAILED*" + echo " Expected result (*.ddl) differs from actual result (*.out)" + nerrors="`expr $nerrors + 1`" + test yes = "$verbose" && $DIFF $caseless $expect $actual |sed 's/^/ /' + fi + + # Clean up output file + if test -z "$HDF5_NOCLEANUP"; then + rm -f $actual $actual_err $actual_sav $actual_err_sav $actual_ext + fi + +} + +############################################################################## +### T H E T E S T S +############################################################################## +# prepare for test +COPY_TESTFILES_TO_TESTDIR + +# Run the test +TOOLTEST tudfilter.ddl --enable-error-stack tudfilter.h5 + +# print results +if test $nerrors -ne 0 ; then + echo "$nerrors errors encountered" + exit_code=$EXIT_FAILURE +else + echo "All Plugin API tests passed." + exit_code=$EXIT_SUCCESS +fi + +# Clean up temporary files/directories +CLEAN_TESTFILES_AND_TESTDIR + +# Clean up temporary files/directories and leave +$RM $PLUGIN_LIBDIR + +exit $exit_code diff --git a/tools/test/h5dump/h5dumpgentest.c b/tools/test/h5dump/h5dumpgentest.c index 335eafa..7df9cbb 100644 --- a/tools/test/h5dump/h5dumpgentest.c +++ b/tools/test/h5dump/h5dumpgentest.c @@ -114,6 +114,7 @@ #define FILE81 "tints4dims.h5" #define FILE82 "tcompound_complex2.h5" #define FILE83 "tvlenstr_array.h5" +#define FILE84 "tudfilter.h5" /*------------------------------------------------------------------------- * prototypes @@ -153,6 +154,23 @@ const H5Z_class2_t H5Z_MYFILTER[1] = {{ myfilter, /* The actual filter function */ }}; +#define H5Z_FILTER_DYNLIB2 258 +#define MULTIPLIER 3 + +static size_t H5Z_filter_dynlib2(unsigned int flags, size_t cd_nelmts, + const unsigned int *cd_values, size_t nbytes, size_t *buf_size, void **buf); + +/* This message derives from H5Z */ +const H5Z_class2_t H5Z_DYNLIB2[1] = {{ + H5Z_CLASS_T_VERS, /* H5Z_class_t version */ + H5Z_FILTER_DYNLIB2, /* Filter id number */ + 1, 1, /* Encoding and decoding enabled */ + "dynlib2", /* Filter name for debugging */ + NULL, /* The "can apply" callback */ + NULL, /* The "set local" callback */ + (H5Z_func_t)H5Z_filter_dynlib2, /* The actual filter function */ +}}; + /* A UD link traversal function. Shouldn't actually be called. */ static hid_t UD_traverse(H5_ATTR_UNUSED const char * link_name, H5_ATTR_UNUSED hid_t cur_group, @@ -10286,6 +10304,118 @@ static void gent_vlenstr_array(void) H5Fclose(file); } +/*------------------------------------------------------------------------- + * Function: gent_udfilter + * + * Purpose: Generate a file to be used in testing user defined filter plugin3. + *------------------------------------------------------------------------- + */ +static void gent_udfilter(void) +{ + hid_t fid; /* file id */ + hid_t dcpl; /* dataset creation property list */ + hid_t sid; /* dataspace ID */ + hid_t tid; /* datatype ID */ + + hsize_t dims1[RANK] = {DIM1,DIM2}; + hsize_t chunk_dims[RANK] = {CDIM1,CDIM2}; + int buf1[DIM1][DIM2]; + int i, j, n, ret; + + for(i=n=0; i<DIM1; i++){ + for(j=0; j<DIM2; j++){ + buf1[i][j]=n++; + } + } + + /* create a file */ + fid = H5Fcreate(FILE84, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + HDassert(fid>=0); + + /* create a space */ + sid = H5Screate_simple(SPACE2_RANK, dims1, NULL); + + dcpl = H5Pcreate(H5P_DATASET_CREATE); + HDassert(dcpl>=0); + + ret = H5Pset_layout(dcpl, H5D_CHUNKED); + HDassert(ret >= 0); + + ret = H5Pset_chunk(dcpl, SPACE2_RANK, chunk_dims); + HDassert(ret >= 0); + + ret = H5Zregister (H5Z_DYNLIB2); + HDassert(ret >= 0); + + ret = H5Pset_filter (dcpl, H5Z_FILTER_DYNLIB2, H5Z_FLAG_MANDATORY, 0, NULL); + HDassert(ret >= 0); + + ret=make_dset(fid, "dynlib2", sid, H5T_NATIVE_INT, dcpl, buf1); + HDassert(ret >= 0); + + /* remove the filters from the dcpl */ + ret = H5Premove_filter(dcpl, H5Z_FILTER_ALL); + HDassert(ret >= 0); + + /*------------------------------------------------------------------------- + * close + *------------------------------------------------------------------------- + */ + ret = H5Sclose(sid); + HDassert(ret >= 0); + + ret = H5Pclose(dcpl); + HDassert(ret >= 0); + + ret = H5Fclose(fid); + HDassert(ret >= 0); +} + +/*------------------------------------------------------------------------- + * Function: H5Z_filter_dynlib2 + * + * Purpose: A dynlib2 filter method that multiplies the original value + * during write and divide the original value during read. It + * will be built as a shared library. tools tests will load + * and use this filter as a plugin library. + * + * Return: Success: Data chunk size + * + * Failure: 0 + *------------------------------------------------------------------------- + */ +static size_t +H5Z_filter_dynlib2(unsigned int flags, size_t cd_nelmts, + const unsigned int *cd_values, size_t nbytes, + size_t *buf_size, void **buf) +{ + int *int_ptr = (int *)*buf; /* Pointer to the data values */ + size_t buf_left = *buf_size; /* Amount of data buffer left to process */ + + /* Check for the correct number of parameters */ + if(cd_nelmts > 0) + return(0); + + /* Assignment to eliminate unused parameter warning. */ + cd_values = cd_values; + + if(flags & H5Z_FLAG_REVERSE) { /*read*/ + /* Divide the original value with MULTIPLIER */ + while(buf_left > 0) { + *int_ptr++ /= MULTIPLIER; + buf_left -= sizeof(int); + } /* end while */ + } /* end if */ + else { /*write*/ + /* Multiply the original value with MULTIPLIER */ + while(buf_left > 0) { + *int_ptr++ *= MULTIPLIER; + buf_left -= sizeof(int); + } /* end while */ + } /* end else */ + + return nbytes; +} /* end H5Z_filter_dynlib2() */ /*------------------------------------------------------------------------- * Function: main @@ -10383,6 +10513,8 @@ int main(void) gent_intsfourdims(); + gent_udfilter(); + return 0; } diff --git a/tools/test/h5ls/CMakeLists.txt b/tools/test/h5ls/CMakeLists.txt index 3280f7f..c21ca92 100644 --- a/tools/test/h5ls/CMakeLists.txt +++ b/tools/test/h5ls/CMakeLists.txt @@ -6,6 +6,34 @@ PROJECT (HDF5_TOOLS_TEST_H5LS) #----------------------------------------------------------------------------- INCLUDE_DIRECTORIES (${HDF5_TOOLS_DIR}/lib) + #----------------------------------------------------------------------------- + # If plugin library tests can be tested + #----------------------------------------------------------------------------- + set (HDF5_TOOL_PLUGIN_LIB_CORENAME "dynlibls") + set (HDF5_TOOL_PLUGIN_LIB_NAME "${HDF5_EXTERNAL_LIB_PREFIX}${HDF5_TOOL_PLUGIN_LIB_CORENAME}") + set (HDF5_TOOL_PLUGIN_LIB_TARGET ${HDF5_TOOL_PLUGIN_LIB_CORENAME}) + add_definitions (${HDF_EXTRA_C_FLAGS}) + INCLUDE_DIRECTORIES (${HDF5_SRC_DIR}) + + add_library (${HDF5_TOOL_PLUGIN_LIB_TARGET} SHARED dynlib_ls.c) + TARGET_C_PROPERTIES (${HDF5_TOOL_PLUGIN_LIB_TARGET} SHARED " " " ") + target_link_libraries (${HDF5_TOOL_PLUGIN_LIB_TARGET} ${HDF5_TEST_LIB_TARGET}) + H5_SET_LIB_OPTIONS (${HDF5_TOOL_PLUGIN_LIB_TARGET} ${HDF5_TOOL_PLUGIN_LIB_NAME} SHARED ${HDF5_PACKAGE_SOVERSION}) + + # make plugins dir + file (MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/plugins") + #----------------------------------------------------------------------------- + # Copy plugin library to a plugins folder + #----------------------------------------------------------------------------- + add_custom_command ( + TARGET ${HDF5_TOOL_PLUGIN_LIB_TARGET} + POST_BUILD + COMMAND ${CMAKE_COMMAND} + ARGS -E copy_if_different + "$<TARGET_FILE:${HDF5_TOOL_PLUGIN_LIB_TARGET}>" + "${CMAKE_BINARY_DIR}/plugins/$<TARGET_FILE_NAME:${HDF5_TOOL_PLUGIN_LIB_TARGET}>" + ) + include (CMakeTests.cmake) include (CMakeTestsVDS.cmake) diff --git a/tools/test/h5ls/CMakeTests.cmake b/tools/test/h5ls/CMakeTests.cmake index 936f025..fc15986 100644 --- a/tools/test/h5ls/CMakeTests.cmake +++ b/tools/test/h5ls/CMakeTests.cmake @@ -29,6 +29,7 @@ ${HDF5_TOOLS_DIR}/testfiles/tslink.h5 ${HDF5_TOOLS_DIR}/testfiles/tsoftlinks.h5 ${HDF5_TOOLS_DIR}/testfiles/tstr.h5 + ${HDF5_TOOLS_DIR}/testfiles/tudfilter.h5 ${HDF5_TOOLS_DIR}/testfiles/tudlink.h5 ${HDF5_TOOLS_DIR}/testfiles/tvldtypes1.h5 ${HDF5_TOOLS_DIR}/testfiles/tdset_idx.h5 @@ -87,6 +88,7 @@ ${HDF5_TOOLS_DIR}/testfiles/tsaf.ls ${HDF5_TOOLS_DIR}/testfiles/tslink-1.ls ${HDF5_TOOLS_DIR}/testfiles/tstr-1.ls + ${HDF5_TOOLS_DIR}/testfiles/tudfilter.ls ${HDF5_TOOLS_DIR}/testfiles/tudlink-1.ls ${HDF5_TOOLS_DIR}/testfiles/tvldtypes1.ls ${HDF5_TOOLS_DIR}/testfiles/tvldtypes2le.ls @@ -135,6 +137,33 @@ endif () ENDMACRO () + MACRO (ADD_H5_UD_TEST testname resultcode resultfile) + if (NOT HDF5_ENABLE_USING_MEMCHECKER) + # Remove any output file left over from previous test run + add_test ( + NAME H5LS_UD-${testname}-clearall-objects + COMMAND ${CMAKE_COMMAND} + -E remove + testfiles/${resultfile}.out + testfiles/${resultfile}.out.err + ) + add_test ( + NAME H5LS_UD-${testname} + COMMAND "${CMAKE_COMMAND}" + -D "TEST_PROGRAM=$<TARGET_FILE:h5ls>" + -D "TEST_ARGS=${ARGN}" + -D "TEST_FOLDER=${PROJECT_BINARY_DIR}/testfiles" + -D "TEST_OUTPUT=${resultfile}.out" + -D "TEST_EXPECT=${resultcode}" + -D "TEST_REFERENCE=${resultfile}.ls" + -D "TEST_ENV_VAR=HDF5_PLUGIN_PATH" + -D "TEST_ENV_VALUE=${CMAKE_BINARY_DIR}/plugins" + -P "${HDF_RESOURCES_EXT_DIR}/runTest.cmake" + ) + set_tests_properties (H5LS_UD-${testname} PROPERTIES DEPENDS H5LS_UD-${testname}-clearall-objects) + endif () + ENDMACRO () + ############################################################################## ############################################################################## ### T H E T E S T S ### @@ -410,3 +439,8 @@ ADD_H5_TEST (tdset_idx 0 -w80 -d tdset_idx.h5) endif (USE_FILTER_DEFLATE) + +############################################################################## +### P L U G I N T E S T S +############################################################################## +ADD_H5_UD_TEST (h5ls_plugin_test 0 tudfilter -w80 -v -d tudfilter.h5) diff --git a/tools/test/h5ls/Makefile.am b/tools/test/h5ls/Makefile.am index 6f3d3dd..170aa63 100644 --- a/tools/test/h5ls/Makefile.am +++ b/tools/test/h5ls/Makefile.am @@ -27,8 +27,24 @@ AM_CPPFLAGS+=-I$(top_srcdir)/src -I$(top_srcdir)/tools/lib TEST_SCRIPT=testh5ls.sh testh5lsvds.sh check_SCRIPTS=$(TEST_SCRIPT) SCRIPT_DEPEND=../../src/h5ls/h5ls$(EXEEXT) +if HAVE_SHARED_CONDITIONAL +if USE_PLUGINS_CONDITIONAL + TEST_SCRIPT += h5ls_plugin.sh +endif +endif # All programs depend on the hdf5 and h5tools libraries LDADD=$(LIBH5TOOLS) $(LIBHDF5) +if HAVE_SHARED_CONDITIONAL + # Build it as shared library if configure is enabled for shared library. + lib_LTLIBRARIES=libdynlibls.la + libdynlibls_la_SOURCES=dynlib_ls.c + +install-exec-hook: + $(RM) $(DESTDIR)$(libdir)/*dynlib* +endif + +DISTCLEANFILES=h5ls_plugin.sh + include $(top_srcdir)/config/conclude.am diff --git a/tools/test/h5ls/dynlib_ls.c b/tools/test/h5ls/dynlib_ls.c new file mode 100644 index 0000000..0d8be2b --- /dev/null +++ b/tools/test/h5ls/dynlib_ls.c @@ -0,0 +1,94 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic document set and is * + * linked from the top-level documents page. It can also be found at * + * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have access * + * to either file, you may request a copy from help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* + * Programmer: Raymond Lu + * 13 February 2013 + * + * Purpose: Tests the plugin module (H5PL) + */ + +#include <stdlib.h> +#include <stdio.h> +#include "H5PLextern.h" + +#define H5Z_FILTER_DYNLIB2 258 +#define MULTIPLIER 3 + +static size_t H5Z_filter_dynlib2(unsigned int flags, size_t cd_nelmts, + const unsigned int *cd_values, size_t nbytes, size_t *buf_size, void **buf); + +/* This message derives from H5Z */ +const H5Z_class2_t H5Z_DYNLIB2[1] = {{ + H5Z_CLASS_T_VERS, /* H5Z_class_t version */ + H5Z_FILTER_DYNLIB2, /* Filter id number */ + 1, 1, /* Encoding and decoding enabled */ + "dynlib2", /* Filter name for debugging */ + NULL, /* The "can apply" callback */ + NULL, /* The "set local" callback */ + (H5Z_func_t)H5Z_filter_dynlib2, /* The actual filter function */ +}}; + +H5PL_type_t H5PLget_plugin_type(void) {return H5PL_TYPE_FILTER;} +const void *H5PLget_plugin_info(void) {return H5Z_DYNLIB2;} + +/*------------------------------------------------------------------------- + * Function: H5Z_filter_dynlib2 + * + * Purpose: A dynlib2 filter method that multiplies the original value + * during write and divide the original value during read. It + * will be built as a shared library. plugin.c test will load + * and use this filter library. + * + * Return: Success: Data chunk size + * + * Failure: 0 + * + * Programmer: Raymond Lu + * 29 March 2013 + * + *------------------------------------------------------------------------- + */ +static size_t +H5Z_filter_dynlib2(unsigned int flags, size_t cd_nelmts, + const unsigned int *cd_values, size_t nbytes, + size_t *buf_size, void **buf) +{ + int *int_ptr = (int *)*buf; /* Pointer to the data values */ + size_t buf_left = *buf_size; /* Amount of data buffer left to process */ + + /* Check for the correct number of parameters */ + if(cd_nelmts > 0) + return(0); + + /* Assignment to eliminate unused parameter warning. */ + cd_values = cd_values; + + if(flags & H5Z_FLAG_REVERSE) { /*read*/ + /* Divide the original value with MULTIPLIER */ + while(buf_left > 0) { + *int_ptr++ /= MULTIPLIER; + buf_left -= sizeof(int); + } /* end while */ + } /* end if */ + else { /*write*/ + /* Multiply the original value with MULTIPLIER */ + while(buf_left > 0) { + *int_ptr++ *= MULTIPLIER; + buf_left -= sizeof(int); + } /* end while */ + } /* end else */ + + return nbytes; +} /* end H5Z_filter_dynlib2() */ + diff --git a/tools/test/h5ls/h5ls_plugin.sh.in b/tools/test/h5ls/h5ls_plugin.sh.in new file mode 100644 index 0000000..3436071 --- /dev/null +++ b/tools/test/h5ls/h5ls_plugin.sh.in @@ -0,0 +1,253 @@ +#! /bin/sh +# +# Copyright by The HDF Group. +# All rights reserved. +# +# This file is part of HDF5. The full HDF5 copyright notice, including +# terms governing use, modification, and redistribution, is contained in +# the files COPYING and Copyright.html. COPYING can be found at the root +# of the source code distribution tree; Copyright.html can be found at the +# root level of an installed copy of the electronic document set and is +# linked from the top-level documents page. It can also be found at +# http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have access +# to either file, you may request a copy from help@hdfgroup.org. +# +srcdir=@srcdir@ +TOP_BUILDDIR=@top_builddir@ + +# Determine backward compatibility options enabled +DEPRECATED_SYMBOLS="@DEPRECATED_SYMBOLS@" + +EXIT_SUCCESS=0 +EXIT_FAILURE=1 + +H5LS=../../src/h5ls/h5ls # The tool name +H5LS_BIN=`pwd`/$H5LS # The path of the tool binary + +nerrors=0 +verbose=yes +h5haveexitcode=yes # default is yes + +TEST_NAME=ud_plugin +FROM_DIR=`pwd`/.libs +PLUGIN_LIB="$FROM_DIR/libdynlibls.*" +PLUGIN_LIBDIR=testdir3 +RM='rm -rf' + +RM='rm -rf' +GREP='grep' +CMP='cmp -s' +DIFF='diff -c' +CP='cp' +DIRNAME='dirname' +LS='ls' +AWK='awk' + +# source dirs +SRC_TOOLS="$srcdir/../.." + +# testfiles source dirs for tools +SRC_TOOLS_TESTFILES="$SRC_TOOLS/testfiles" +SRC_H5LS_TESTFILES="$SRC_TOOLS_TESTFILES" + +TESTDIR=./testplug +test -d $TESTDIR || mkdir $TESTDIR + +###################################################################### +# test files +# -------------------------------------------------------------------- +# All the test files copy from source directory to test directory +# NOTE: Keep this framework to add/remove test files. +# Any test files from other tools can be used in this framework. +# This list are also used for checking exist. +# Comment '#' without space can be used. +# -------------------------------------------------------------------- +LIST_HDF5_TEST_FILES=" +$SRC_TOOLS_TESTFILES/tudfilter.h5 +$SRC_TOOLS_TESTFILES/tudfilter.ls +" + +# RUNSERIAL is used. Check if it can return exit code from executable correctly. +if [ -n "$RUNSERIAL_NOEXITCODE" ]; then + echo "***Warning*** Serial Exit Code is not passed back to shell correctly." + echo "***Warning*** Exit code checking is skipped." + h5haveexitcode=no +fi + +# Main Body +# Create test directories if not exists yet. +test -d $PLUGIN_LIBDIR || mkdir -p $PLUGIN_LIBDIR +if [ $? != 0 ]; then + echo "Failed to create test directory($PLUGIN_LIBDIR)" + exit $EXIT_FAILURE +fi + +# copy plugin library for test +$CP $PLUGIN_LIB $PLUGIN_LIBDIR +if [ $? != 0 ]; then + echo "Failed to copy plugin library ($PLUGIN_LIB) for test." + exit $EXIT_FAILURE +fi + +# setup plugin path +ENVCMD="env HDF5_PLUGIN_PATH=../${PLUGIN_LIBDIR}" + +# +# copy test files and expected output files from source dirs to test dir +# +COPY_TESTFILES="$LIST_HDF5_TEST_FILES" + +COPY_TESTFILES_TO_TESTDIR() +{ + # copy test files. Used -f to make sure get a new copy + for tstfile in $COPY_TESTFILES + do + # ignore '#' comment + echo $tstfile | tr -d ' ' | grep '^#' > /dev/null + RET=$? + if [ $RET -eq 1 ]; then + # skip cp if srcdir is same as destdir + # this occurs when build/test performed in source dir and + # make cp fail + SDIR=`$DIRNAME $tstfile` + INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'` + INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'` + if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then + $CP -f $tstfile $TESTDIR + if [ $? -ne 0 ]; then + echo "Error: FAILED to copy $tstfile ." + + # Comment out this to CREATE expected file + exit $EXIT_FAILURE + fi + fi + fi + done +} + +CLEAN_TESTFILES_AND_TESTDIR() +{ + # skip rm if srcdir is same as destdir + # this occurs when build/test performed in source dir and + # make cp fail + SDIR=$SRC_H5LS_TESTFILES + INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'` + INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'` + if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then + $RM $TESTDIR + fi +} + +# Print a $* message left justified in a field of 70 characters +# +MESSAGE() { + SPACES=" " + echo "$* $SPACES" | cut -c1-70 | tr -d '\012' +} + +# Print a line-line message left justified in a field of 70 characters +# beginning with the word "Testing". +# +TESTING() { + SPACES=" " + echo "Testing $* $SPACES" | cut -c1-70 | tr -d '\012' +} + +# Print a line-line message left justified in a field of 70 characters +# beginning with the word "Verifying". +# +VERIFY() { + MESSAGE "Verifying $*" +} + +# Source in the output filter function definitions. +. $srcdir/../../../bin/output_filter.sh + +# Run a test and print PASS or *FAIL*. For now, if h5ls can complete +# with exit status 0, consider it pass. If a test fails then increment +# the `nerrors' global variable and (if $verbose is set) display up to $NLINS +# lines of the actual output from the tool test. The actual output is not +# removed if $HDF5_NOCLEANUP has a non-zero value. +# Arguemnts: +# $1 -- actual output filename to use +# $2 and on -- argument for the h5ls tool +TOOLTEST() { + expect="$TESTDIR/$1" + actual="$TESTDIR/`basename $1 .ls`.out" + actual_err="$TESTDIR/`basename $1 .ls`.err" + actual_sav=${actual}-sav + actual_err_sav=${actual_err}-sav + shift + retvalexpect=$1 + shift + + # Run test. + # Stderr is included in stdout so that the diff can detect + # any unexpected output from that stream too. + TESTING $H5LS $@ + ( + cd $TESTDIR + $ENVCMD $RUNSERIAL $H5LS_BIN "$@" + ) >$actual 2>$actual_err + + exitcode=$? + # save actual and actual_err in case they are needed later. + cp $actual $actual_sav + STDOUT_FILTER $actual + cp $actual_err $actual_err_sav + STDERR_FILTER $actual_err + cat $actual_err >> $actual + if [ $h5haveexitcode = 'yes' -a $exitcode -ne $retvalexpect ]; then + echo "*FAILED*" + nerrors="`expr $nerrors + 1`" + if [ yes = "$verbose" ]; then + echo "test returned with exit code $exitcode" + echo "test output: (up to $NLINES lines)" + head -$NLINES $actual + echo "***end of test output***" + echo "" + fi + elif [ ! -f $expect ]; then + # Create the expect file if it doesn't yet exist. + echo " CREATED" + cp $actual $expect + elif $CMP $expect $actual; then + echo " PASSED" + else + echo "*FAILED*" + echo " Expected result differs from actual result" + nerrors="`expr $nerrors + 1`" + test yes = "$verbose" && $DIFF $expect $actual |sed 's/^/ /' + fi + + # Clean up output file + if test -z "$HDF5_NOCLEANUP"; then + rm -f $actual $actual_err $actual_sav $actual_err_sav + fi +} + +############################################################################## +### T H E T E S T S +############################################################################## +# prepare for test +COPY_TESTFILES_TO_TESTDIR + +# Run the test +TOOLTEST tudfilter.ls 0 -w80 -v -d tudfilter.h5 + +# print results +if test $nerrors -ne 0 ; then + echo "$nerrors errors encountered" + exit_code=$EXIT_FAILURE +else + echo "All Plugin API tests passed." + exit_code=$EXIT_SUCCESS +fi + +# Clean up temporary files/directories +CLEAN_TESTFILES_AND_TESTDIR + +# Clean up temporary files/directories and leave +$RM $PLUGIN_LIBDIR + +exit $exit_code diff --git a/tools/test/h5repack/CMakeTests.cmake b/tools/test/h5repack/CMakeTests.cmake index b610d23..ccd8d88 100644 --- a/tools/test/h5repack/CMakeTests.cmake +++ b/tools/test/h5repack/CMakeTests.cmake @@ -1151,7 +1151,7 @@ set (TESTRETVAL 255) if (WIN32) set (TESTRETVAL -1) - endif() + endif () ADD_H5_CMP_TEST (plugin_zero "" "TEST" ${TESTRETVAL} h5repack_layout.h5 -v -f UD=250,0) if (HDF5_TEST_VFD) diff --git a/tools/testfiles/tudfilter.ddl b/tools/testfiles/tudfilter.ddl new file mode 100644 index 0000000..5bdceec --- /dev/null +++ b/tools/testfiles/tudfilter.ddl @@ -0,0 +1,30 @@ +HDF5 "tudfilter.h5" { +GROUP "/" { + DATASET "dynlib2" { + DATATYPE H5T_STD_I32LE + DATASPACE SIMPLE { ( 20, 10 ) / ( 20, 10 ) } + DATA { + (0,0): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + (1,0): 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + (2,0): 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + (3,0): 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, + (4,0): 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, + (5,0): 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, + (6,0): 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + (7,0): 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, + (8,0): 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, + (9,0): 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, + (10,0): 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, + (11,0): 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, + (12,0): 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, + (13,0): 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, + (14,0): 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, + (15,0): 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, + (16,0): 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, + (17,0): 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, + (18,0): 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, + (19,0): 190, 191, 192, 193, 194, 195, 196, 197, 198, 199 + } + } +} +} diff --git a/tools/testfiles/tudfilter.h5 b/tools/testfiles/tudfilter.h5 Binary files differnew file mode 100644 index 0000000..eaf6a43 --- /dev/null +++ b/tools/testfiles/tudfilter.h5 diff --git a/tools/testfiles/tudfilter.ls b/tools/testfiles/tudfilter.ls new file mode 100644 index 0000000..7ca8682 --- /dev/null +++ b/tools/testfiles/tudfilter.ls @@ -0,0 +1,23 @@ +Opened "tudfilter.h5" with sec2 driver. +dynlib2 Dataset {20/20, 10/10} + Location: 1:800 + Links: 1 + Chunks: {10, 5} 200 bytes + Storage: 800 logical bytes, 800 allocated bytes, 100.00% utilization + Filter-0: dynlib2-258 {} + Type: native int + Data: + (0,0) 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, + (1,9) 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, + (3,5) 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, + (5,1) 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, + (6,7) 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, + (8,3) 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, + (9,9) 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, + (11,2) 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, + (12,5) 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, + (13,8) 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, + (15,1) 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, + (16,4) 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, + (17,7) 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, + (19,0) 190, 191, 192, 193, 194, 195, 196, 197, 198, 199 |