summaryrefslogtreecommitdiffstats
path: root/tools/test/h5dump
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2017-01-17 19:46:11 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2017-01-17 19:46:11 (GMT)
commit406db26f51ce4536931ce7cbe7a2eb5775c7a9d8 (patch)
tree5be7b4bfbcc75a47ca0f5bf9af6cddcf9f297bb7 /tools/test/h5dump
parentbe260bbf75e965e80808adf8c8d2b35dd7f9470b (diff)
downloadhdf5-406db26f51ce4536931ce7cbe7a2eb5775c7a9d8.zip
hdf5-406db26f51ce4536931ce7cbe7a2eb5775c7a9d8.tar.gz
hdf5-406db26f51ce4536931ce7cbe7a2eb5775c7a9d8.tar.bz2
HDFFV-9994 add UD tests for tools
Diffstat (limited to 'tools/test/h5dump')
-rw-r--r--tools/test/h5dump/CMakeLists.txt28
-rw-r--r--tools/test/h5dump/CMakeTests.cmake36
-rw-r--r--tools/test/h5dump/dynlib_dump.c94
-rw-r--r--tools/test/h5dump/h5dumpgentest.c132
4 files changed, 289 insertions, 1 deletions
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/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/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;
}