summaryrefslogtreecommitdiffstats
path: root/tools/test/h5jam
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2016-10-27 15:06:00 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2016-10-27 15:06:00 (GMT)
commit2c6dbbf2129c4997606be4b130346d42fe12eae3 (patch)
treedb8430aa5757b32f3bd46928798cc2b686a72bfb /tools/test/h5jam
parent5b562d9ce9b2945d0378b9c03e01f42923da80f4 (diff)
downloadhdf5-2c6dbbf2129c4997606be4b130346d42fe12eae3.zip
hdf5-2c6dbbf2129c4997606be4b130346d42fe12eae3.tar.gz
hdf5-2c6dbbf2129c4997606be4b130346d42fe12eae3.tar.bz2
Split tools into src and test - add folders
Diffstat (limited to 'tools/test/h5jam')
-rw-r--r--tools/test/h5jam/CMakeLists.txt34
-rw-r--r--tools/test/h5jam/CMakeTests.cmake384
-rw-r--r--tools/test/h5jam/Makefile.am40
-rw-r--r--tools/test/h5jam/getub.c157
-rw-r--r--tools/test/h5jam/h5jamgentest.c389
-rw-r--r--tools/test/h5jam/tellub.c196
-rw-r--r--tools/test/h5jam/testfiles/h5jam-help.txt24
-rw-r--r--tools/test/h5jam/testfiles/h5jam-ub-nohdf5.txt2
-rw-r--r--tools/test/h5jam/testfiles/h5unjam-help.txt27
-rw-r--r--tools/test/h5jam/testfiles/tall.h5bin0 -> 9968 bytes
-rw-r--r--tools/test/h5jam/testfiles/twithub.h5bin0 -> 10592 bytes
-rw-r--r--tools/test/h5jam/testfiles/twithub513.h5bin0 -> 11056 bytes
-rw-r--r--tools/test/h5jam/testfiles/u10.txt1
-rw-r--r--tools/test/h5jam/testfiles/u511.txt1
-rw-r--r--tools/test/h5jam/testfiles/u512.txt1
-rw-r--r--tools/test/h5jam/testfiles/u513.txt1
-rw-r--r--tools/test/h5jam/testh5jam.sh.in699
17 files changed, 1956 insertions, 0 deletions
diff --git a/tools/test/h5jam/CMakeLists.txt b/tools/test/h5jam/CMakeLists.txt
new file mode 100644
index 0000000..d3980c4
--- /dev/null
+++ b/tools/test/h5jam/CMakeLists.txt
@@ -0,0 +1,34 @@
+cmake_minimum_required (VERSION 3.1.0)
+PROJECT (HDF5_TOOLS_TEST_H5JAM)
+
+#-----------------------------------------------------------------------------
+# Setup include Directories
+#-----------------------------------------------------------------------------
+INCLUDE_DIRECTORIES (${HDF5_TOOLS_DIR}/lib)
+
+ # --------------------------------------------------------------------
+ # Add the h5jam test executables
+ # --------------------------------------------------------------------
+ if (HDF5_BUILD_GENERATORS)
+ add_executable (h5jamgentest ${HDF5_TOOLS_TEST_H5JAM_SOURCE_DIR}/h5jamgentest.c)
+ TARGET_NAMING (h5jamgentest STATIC)
+ TARGET_C_PROPERTIES (testhdf5 STATIC " " " ")
+ target_link_libraries (h5jamgentest ${HDF5_LIB_TARGET})
+ set_target_properties (h5jamgentest PROPERTIES FOLDER generator/tools)
+
+ #add_test (NAME h5jamgentest COMMAND $<TARGET_FILE:h5jamgentest>)
+ endif (HDF5_BUILD_GENERATORS)
+
+add_executable (getub ${HDF5_TOOLS_TEST_H5JAM_SOURCE_DIR}/getub.c)
+TARGET_NAMING (getub STATIC)
+TARGET_C_PROPERTIES (getub STATIC " " " ")
+target_link_libraries (getub ${HDF5_TOOLS_LIB_TARGET} ${HDF5_LIB_TARGET})
+set_target_properties (getub PROPERTIES FOLDER tools)
+
+add_executable (tellub ${HDF5_TOOLS_TEST_H5JAM_SOURCE_DIR}/tellub.c)
+TARGET_NAMING (tellub STATIC)
+TARGET_C_PROPERTIES (tellub STATIC " " " ")
+target_link_libraries (tellub ${HDF5_TOOLS_LIB_TARGET} ${HDF5_LIB_TARGET})
+set_target_properties (tellub PROPERTIES FOLDER tools)
+
+ include (CMakeTests.cmake)
diff --git a/tools/test/h5jam/CMakeTests.cmake b/tools/test/h5jam/CMakeTests.cmake
new file mode 100644
index 0000000..9ed2015
--- /dev/null
+++ b/tools/test/h5jam/CMakeTests.cmake
@@ -0,0 +1,384 @@
+
+##############################################################################
+##############################################################################
+### T E S T I N G ###
+##############################################################################
+##############################################################################
+
+ set (HDF5_REFERENCE_TXT_FILES
+ u10.txt
+ u511.txt
+ u512.txt
+ u513.txt
+ h5jam-help.txt
+ h5unjam-help.txt
+ h5jam-ub-nohdf5.txt
+ )
+ set (HDF5_REFERENCE_TEST_FILES
+ tall.h5
+ twithub.h5
+ twithub513.h5
+ )
+
+ file (MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/testfiles")
+ foreach (h5_file ${HDF5_REFERENCE_TEST_FILES})
+ HDFTEST_COPY_FILE("${HDF5_TOOLS_TEST_H5JAM_SOURCE_DIR}/testfiles/${h5_file}" "${PROJECT_BINARY_DIR}/testfiles/${h5_file}" "h5jam_files")
+ endforeach (h5_file ${HDF5_REFERENCE_TEST_FILES})
+
+ foreach (txt_file ${HDF5_REFERENCE_TXT_FILES})
+ HDFTEST_COPY_FILE("${HDF5_TOOLS_TEST_H5JAM_SOURCE_DIR}/testfiles/${txt_file}" "${PROJECT_BINARY_DIR}/testfiles/${txt_file}" "h5jam_files")
+ endforeach (txt_file ${HDF5_REFERENCE_TXT_FILES})
+ add_custom_target(h5jam_files ALL COMMENT "Copying files needed by h5jam tests" DEPENDS ${h5jam_files_list})
+
+##############################################################################
+##############################################################################
+### T H E T E S T S M A C R O S ###
+##############################################################################
+##############################################################################
+
+ # ============================================================
+ # TEST_H5JAM_OUTPUT
+ # For the purpose to verify only output & exitcode from h5jam
+ #
+ MACRO (TEST_H5JAM_OUTPUT expectfile resultcode)
+ # If using memchecker add tests without using scripts
+ if (HDF5_ENABLE_USING_MEMCHECKER)
+ add_test (NAME H5JAM-${expectfile} COMMAND $<TARGET_FILE:h5jam> ${ARGN})
+ if (NOT "${resultcode}" STREQUAL "0")
+ set_tests_properties (H5JAM-${expectfile} PROPERTIES WILL_FAIL "true")
+ endif (NOT "${resultcode}" STREQUAL "0")
+ else (HDF5_ENABLE_USING_MEMCHECKER)
+ add_test (
+ NAME H5JAM-${expectfile}
+ COMMAND "${CMAKE_COMMAND}"
+ -D "TEST_PROGRAM=$<TARGET_FILE:h5jam>"
+ -D "TEST_ARGS:STRING=${ARGN}"
+ -D "TEST_FOLDER=${PROJECT_BINARY_DIR}"
+ -D "TEST_OUTPUT=${expectfile}.out"
+ -D "TEST_EXPECT=${resultcode}"
+ -D "TEST_REFERENCE=testfiles/${expectfile}.txt"
+ -P "${HDF_RESOURCES_EXT_DIR}/runTest.cmake"
+ )
+ endif (HDF5_ENABLE_USING_MEMCHECKER)
+ ENDMACRO (TEST_H5JAM_OUTPUT)
+
+ # ============================================================
+ # TEST_H5UNJAM_OUTPUT
+ # For the purpose to verify only output & exitcode from h5unjam
+ #
+ MACRO (TEST_H5UNJAM_OUTPUT expectfile resultcode)
+ # If using memchecker add tests without using scripts
+ if (HDF5_ENABLE_USING_MEMCHECKER)
+ add_test (NAME H5JAM-UNJAM-${expectfile} COMMAND $<TARGET_FILE:h5unjam> ${ARGN})
+ if (NOT "${resultcode}" STREQUAL "0")
+ set_tests_properties (H5JAM-UNJAM-${expectfile} PROPERTIES WILL_FAIL "true")
+ endif (NOT "${resultcode}" STREQUAL "0")
+ else (HDF5_ENABLE_USING_MEMCHECKER)
+ add_test (
+ NAME H5JAM-UNJAM-${expectfile}
+ COMMAND "${CMAKE_COMMAND}"
+ -D "TEST_PROGRAM=$<TARGET_FILE:h5unjam>"
+ -D "TEST_ARGS=${ARGN}"
+ -D "TEST_FOLDER=${PROJECT_BINARY_DIR}"
+ -D "TEST_OUTPUT=${expectfile}.out"
+ -D "TEST_EXPECT=${resultcode}"
+ -D "TEST_REFERENCE=testfiles/${expectfile}.txt"
+ -P "${HDF_RESOURCES_EXT_DIR}/runTest.cmake"
+ )
+ endif (HDF5_ENABLE_USING_MEMCHECKER)
+ ENDMACRO (TEST_H5UNJAM_OUTPUT)
+
+ MACRO (CHECKFILE testname testdepends expected actual)
+ # If using memchecker add tests without using scripts
+ if (NOT HDF5_ENABLE_USING_MEMCHECKER)
+ add_test (
+ NAME H5JAM-${testname}-CHECKFILE-H5DMP
+ COMMAND "${CMAKE_COMMAND}"
+ -D "TEST_PROGRAM=$<TARGET_FILE:h5dump>"
+ -D "TEST_ARGS:STRING=testfiles/${expected}"
+ -D "TEST_FOLDER=${PROJECT_BINARY_DIR}"
+ -D "TEST_OUTPUT=${actual}.new"
+ -D "TEST_EXPECT=0"
+ -D "TEST_FILTER=(^(HDF5)[^\n]*)"
+ -D "TEST_SKIP_COMPARE=TRUE"
+ -P "${HDF_RESOURCES_EXT_DIR}/runTest.cmake"
+ )
+ set_tests_properties (H5JAM-${testname}-CHECKFILE-H5DMP PROPERTIES DEPENDS ${testdepends})
+ add_test (
+ NAME H5JAM-${testname}-CHECKFILE-H5DMP_CMP
+ COMMAND "${CMAKE_COMMAND}"
+ -D "TEST_PROGRAM=$<TARGET_FILE:h5dump>"
+ -D "TEST_ARGS:STRING=${actual}"
+ -D "TEST_FOLDER=${PROJECT_BINARY_DIR}"
+ -D "TEST_OUTPUT=${actual}.out"
+ -D "TEST_EXPECT=0"
+ -D "TEST_FILTER=(^(HDF5)[^\n]*)"
+ -D "TEST_REFERENCE=${actual}.new"
+ -P "${HDF_RESOURCES_EXT_DIR}/runTest.cmake"
+ )
+ set_tests_properties (H5JAM-${testname}-CHECKFILE-H5DMP_CMP PROPERTIES DEPENDS H5JAM-${testname}-CHECKFILE-H5DMP)
+ endif (NOT HDF5_ENABLE_USING_MEMCHECKER)
+ ENDMACRO(CHECKFILE testname testdepends expected actual)
+
+ MACRO (UNJAMTEST testname setfile infile ufile chkfile outfile)
+ if (NOT HDF5_ENABLE_USING_MEMCHECKER)
+ add_test (
+ NAME H5JAM-${testname}-UNJAM-SETUP-clear-objects
+ COMMAND ${CMAKE_COMMAND} -E remove ${infile}
+ )
+ add_test (
+ NAME H5JAM-${testname}-UNJAM-SETUP
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${HDF5_TOOLS_TEST_H5JAM_SOURCE_DIR}/testfiles/${setfile} ${PROJECT_BINARY_DIR}/${infile}
+ )
+ set_tests_properties (H5JAM-${testname}-UNJAM-SETUP PROPERTIES DEPENDS H5JAM-${testname}-UNJAM-SETUP-clear-objects)
+ add_test (
+ NAME H5JAM-${testname}-UNJAM-clear-objects
+ COMMAND ${CMAKE_COMMAND} -E remove ${outfile}
+ )
+ set_tests_properties (H5JAM-${testname}-UNJAM-clear-objects PROPERTIES DEPENDS H5JAM-${testname}-UNJAM-SETUP)
+ if (NOT "${ufile}" STREQUAL "NONE")
+ add_test (
+ NAME H5JAM-${testname}-UNJAM_D-clear-objects
+ COMMAND ${CMAKE_COMMAND} -E remove ${ufile}
+ )
+ set_tests_properties (H5JAM-${testname}-UNJAM_D-clear-objects PROPERTIES DEPENDS H5JAM-${testname}-UNJAM-clear-objects)
+ add_test (NAME H5JAM-${testname}-UNJAM COMMAND $<TARGET_FILE:h5unjam> -i ${infile} -u ${ufile} -o ${outfile})
+ set_tests_properties (H5JAM-${testname}-UNJAM PROPERTIES DEPENDS H5JAM-${testname}-UNJAM_D-clear-objects)
+ set (compare_test ${ufile})
+ else (NOT "${ufile}" STREQUAL "NONE")
+ if (NOT "${ARGN}" STREQUAL "--delete")
+ add_test (
+ NAME H5JAM-${testname}-UNJAM
+ COMMAND "${CMAKE_COMMAND}"
+ -D "TEST_PROGRAM=$<TARGET_FILE:h5unjam>"
+ -D "TEST_ARGS:STRING=-i;${infile};-o;${outfile}"
+ -D "TEST_FOLDER=${PROJECT_BINARY_DIR}"
+ -D "TEST_OUTPUT=${outfile}.ufile.txt"
+ -D "TEST_EXPECT=0"
+ -D "TEST_SKIP_COMPARE=TRUE"
+ -P "${HDF_RESOURCES_EXT_DIR}/runTest.cmake"
+ )
+ set_tests_properties (H5JAM-${testname}-UNJAM PROPERTIES DEPENDS H5JAM-${testname}-UNJAM-clear-objects)
+ set (compare_test "${outfile}.ufile.txt")
+ else (NOT "${ARGN}" STREQUAL "--delete")
+ add_test (NAME H5JAM-${testname}-UNJAM COMMAND $<TARGET_FILE:h5unjam> -i ${infile} -o ${outfile})
+ set_tests_properties (H5JAM-${testname}-UNJAM PROPERTIES DEPENDS H5JAM-${testname}-UNJAM-clear-objects)
+ set (compare_test "")
+ endif (NOT "${ARGN}" STREQUAL "--delete")
+ endif (NOT "${ufile}" STREQUAL "NONE")
+ if (NOT "${compare_test}" STREQUAL "")
+ add_test (
+ NAME H5JAM-${testname}-UNJAM-CHECK_UB_1-clear-objects
+ COMMAND ${CMAKE_COMMAND}
+ -E remove
+ ${infile}.len.txt
+ ${infile}.cmp
+ ${infile}-ub.cmp
+ )
+ set_tests_properties (H5JAM-${testname}-UNJAM-CHECK_UB_1-clear-objects PROPERTIES DEPENDS "H5JAM-${testname}-UNJAM")
+ add_test (
+ NAME H5JAM-${testname}-UNJAM-CHECK_UB_1
+ COMMAND "${CMAKE_COMMAND}"
+ -D "TEST_PROGRAM=$<TARGET_FILE:tellub>"
+ -D "TEST_GET_PROGRAM=$<TARGET_FILE:getub>"
+ -D "TEST_CHECKUB=YES"
+ -D "TEST_FOLDER=${PROJECT_BINARY_DIR}"
+ -D "TEST_HFILE=${infile}"
+ -D "TEST_UFILE=${compare_test}"
+ -D "TEST_EXPECT=0"
+ -D "TEST_OFILE="
+ -P "${HDF_RESOURCES_DIR}/userblockTest.cmake"
+ )
+ set_tests_properties (H5JAM-${testname}-UNJAM-CHECK_UB_1 PROPERTIES DEPENDS H5JAM-${testname}-UNJAM-CHECK_UB_1-clear-objects)
+ endif (NOT "${compare_test}" STREQUAL "")
+
+ add_test (
+ NAME H5JAM-${testname}-UNJAM-CHECK_NOUB
+ COMMAND "${CMAKE_COMMAND}"
+ -D "TEST_PROGRAM=$<TARGET_FILE:tellub>"
+ -D "TEST_GET_PROGRAM=$<TARGET_FILE:getub>"
+ -D "TEST_CHECKUB=NO"
+ -D "TEST_FOLDER=${PROJECT_BINARY_DIR}"
+ -D "TEST_HFILE=${outfile}"
+ -D "TEST_EXPECT=0"
+ -D "TEST_UFILE=NULL"
+ -D "TEST_OFILE=NULL"
+ -P "${HDF_RESOURCES_DIR}/userblockTest.cmake"
+ )
+ if (NOT "${compare_test}" STREQUAL "")
+ set_tests_properties (H5JAM-${testname}-UNJAM-CHECK_NOUB PROPERTIES DEPENDS H5JAM-${testname}-UNJAM-CHECK_UB_1)
+ else (NOT "${compare_test}" STREQUAL "")
+ set_tests_properties (H5JAM-${testname}-UNJAM-CHECK_NOUB PROPERTIES DEPENDS H5JAM-${testname}-UNJAM)
+ endif (NOT "${compare_test}" STREQUAL "")
+
+ CHECKFILE (${testname} "H5JAM-${testname}-UNJAM-CHECK_NOUB" ${chkfile} ${outfile})
+ endif (NOT HDF5_ENABLE_USING_MEMCHECKER)
+ ENDMACRO(UNJAMTEST testname infile ufile outfile)
+
+ MACRO (JAMTEST testname jamfile infile chkfile outfile)
+ if (NOT HDF5_ENABLE_USING_MEMCHECKER)
+ add_test (
+ NAME H5JAM-${testname}-clear-objects
+ COMMAND ${CMAKE_COMMAND} -E remove ${outfile} ${infile}.cpy.h5
+ )
+ endif (NOT HDF5_ENABLE_USING_MEMCHECKER)
+ add_test (NAME H5JAM-${testname} COMMAND $<TARGET_FILE:h5jam> -u testfiles/${jamfile} -i testfiles/${infile} -o ${outfile} ${ARGN})
+ if (NOT HDF5_ENABLE_USING_MEMCHECKER)
+ set_tests_properties (H5JAM-${testname} PROPERTIES DEPENDS H5JAM-${testname}-clear-objects)
+ set (compare_test ${outfile})
+ set (compare_orig testfiles/${infile})
+ if ("${ARGN}" STREQUAL "--clobber")
+ set (compare_orig "")
+ endif ("${ARGN}" STREQUAL "--clobber")
+
+ add_test (
+ NAME H5JAM-${testname}-CHECK_UB_1-clear-objects
+ COMMAND ${CMAKE_COMMAND}
+ -E remove
+ ${compare_test}.len.txt
+ ${compare_test}.cmp
+ ${compare_test}-ub.cmp
+ )
+ set_tests_properties (H5JAM-${testname}-CHECK_UB_1-clear-objects PROPERTIES DEPENDS "H5JAM-${testname}")
+ add_test (
+ NAME H5JAM-${testname}-CHECK_UB_1
+ COMMAND "${CMAKE_COMMAND}"
+ -D "TEST_PROGRAM=$<TARGET_FILE:tellub>"
+ -D "TEST_GET_PROGRAM=$<TARGET_FILE:getub>"
+ -D "TEST_CHECKUB=YES"
+ -D "TEST_FOLDER=${PROJECT_BINARY_DIR}"
+ -D "TEST_HFILE=${compare_test}"
+ -D "TEST_UFILE=testfiles/${jamfile}"
+ -D "TEST_EXPECT=0"
+ -D "TEST_OFILE=${compare_orig}"
+ -P "${HDF_RESOURCES_DIR}/userblockTest.cmake"
+ )
+ set_tests_properties (H5JAM-${testname}-CHECK_UB_1 PROPERTIES DEPENDS H5JAM-${testname}-CHECK_UB_1-clear-objects)
+ CHECKFILE (${testname} "H5JAM-${testname}-CHECK_UB_1" ${chkfile} ${outfile})
+ endif (NOT HDF5_ENABLE_USING_MEMCHECKER)
+ ENDMACRO (JAMTEST testname jamfile infile outfile)
+
+ MACRO (JAMTEST_NONE testname jamfile infile setfile chkfile)
+ if (NOT HDF5_ENABLE_USING_MEMCHECKER)
+ add_test (
+ NAME H5JAM-${testname}_NONE-clear-objects
+ COMMAND ${CMAKE_COMMAND} -E remove
+ ${chkfile} ${chkfile}.cpy.h5
+ )
+ add_test (
+ NAME H5JAM-${testname}_NONE-SETUP
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different testfiles/${setfile} ${chkfile}
+ )
+ set_tests_properties (H5JAM-${testname}_NONE-SETUP PROPERTIES DEPENDS H5JAM-${testname}_NONE-clear-objects)
+
+ add_test (
+ NAME H5JAM-${testname}_NONE_COPY
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${chkfile} ${chkfile}.cpy.h5
+ )
+ set_tests_properties (H5JAM-${testname}_NONE_COPY PROPERTIES DEPENDS H5JAM-${testname}_NONE-SETUP)
+
+ add_test (NAME H5JAM-${testname}_NONE COMMAND $<TARGET_FILE:h5jam> -u testfiles/${jamfile} -i ${chkfile} ${ARGN})
+ set_tests_properties (H5JAM-${testname}_NONE PROPERTIES DEPENDS H5JAM-${testname}_NONE_COPY)
+
+ set (compare_test ${chkfile})
+ set (compare_orig ${chkfile}.cpy.h5)
+ if ("${ARGN}" STREQUAL "--clobber")
+ set (compare_orig "")
+ endif ("${ARGN}" STREQUAL "--clobber")
+
+ add_test (
+ NAME H5JAM-${testname}_NONE-CHECK_UB_1-clear-objects
+ COMMAND ${CMAKE_COMMAND}
+ -E remove
+ ${compare_test}.len.txt
+ ${compare_test}.cmp
+ ${compare_test}-ub.cmp
+ )
+ set_tests_properties (H5JAM-${testname}_NONE-CHECK_UB_1-clear-objects PROPERTIES DEPENDS "H5JAM-${testname}_NONE")
+ add_test (
+ NAME H5JAM-${testname}_NONE-CHECK_UB_1
+ COMMAND "${CMAKE_COMMAND}"
+ -D "TEST_PROGRAM=$<TARGET_FILE:tellub>"
+ -D "TEST_GET_PROGRAM=$<TARGET_FILE:getub>"
+ -D "TEST_CHECKUB=YES"
+ -D "TEST_FOLDER=${PROJECT_BINARY_DIR}"
+ -D "TEST_HFILE=${compare_test}"
+ -D "TEST_UFILE=testfiles/${jamfile}"
+ -D "TEST_EXPECT=0"
+ -D "TEST_OFILE=${compare_orig}"
+ -P "${HDF_RESOURCES_DIR}/userblockTest.cmake"
+ )
+ set_tests_properties (H5JAM-${testname}_NONE-CHECK_UB_1 PROPERTIES DEPENDS H5JAM-${testname}_NONE-CHECK_UB_1-clear-objects)
+ CHECKFILE (${testname} "H5JAM-${testname}_NONE-CHECK_UB_1" ${infile} ${chkfile})
+ endif (NOT HDF5_ENABLE_USING_MEMCHECKER)
+ ENDMACRO (JAMTEST_NONE testname jamfile infile setfile chkfile)
+
+##############################################################################
+##############################################################################
+### T H E T E S T S ###
+##############################################################################
+##############################################################################
+
+#-------------------------------
+# Testing h5jam
+#-------------------------------
+ # help page
+ TEST_H5JAM_OUTPUT(h5jam-help 0 -h)
+
+ # don't allow HDF5 format file as an user block file
+ TEST_H5JAM_OUTPUT(h5jam-ub-nohdf5 1 -i testfiles/tall.h5 -u testfiles/tall.h5 -o tall-tmp.h5)
+
+ JAMTEST (tall_u10 u10.txt tall.h5 tall.h5 ta2.h5)
+ JAMTEST (tall_u511 u511.txt tall.h5 tall.h5 ta3.h5)
+ JAMTEST (tall_u512 u512.txt tall.h5 tall.h5 ta4.h5)
+ JAMTEST (tall_u513 u513.txt tall.h5 tall.h5 ta5.h5)
+
+ JAMTEST_NONE (N_ta_u10 u10.txt tall.h5 tall.h5 ta6.h5)
+ JAMTEST_NONE (N_ta_u511 u511.txt tall.h5 tall.h5 ta7.h5)
+ JAMTEST_NONE (N_ta_u512 u512.txt tall.h5 tall.h5 ta8.h5)
+ JAMTEST_NONE (N_ta_u513 u513.txt tall.h5 tall.h5 ta9.h5)
+
+ JAMTEST (twithub_u10 u10.txt twithub.h5 tall.h5 tax2.h5)
+ JAMTEST (twithub_u511 u511.txt twithub.h5 tall.h5 tax3.h5)
+ JAMTEST (twithub_u512 u512.txt twithub.h5 tall.h5 tax4.h5)
+ JAMTEST (twithub_u513 u513.txt twithub.h5 tall.h5 tax5.h5)
+
+ JAMTEST (twithub513_u10 u10.txt twithub513.h5 tall.h5 tax6.h5)
+ JAMTEST (twithub513_u511 u511.txt twithub513.h5 tall.h5 tax7.h5)
+ JAMTEST (twithub513_u512 u512.txt twithub513.h5 tall.h5 tax8.h5)
+ JAMTEST (twithub513_u513 u513.txt twithub513.h5 tall.h5 tax9.h5)
+
+ JAMTEST (twithub_u10_c u10.txt twithub.h5 tall.h5 taz2.h5 --clobber)
+ JAMTEST (twithub_u511_c u511.txt twithub.h5 tall.h5 taz3.h5 --clobber)
+ JAMTEST (twithub_u512_c u512.txt twithub.h5 tall.h5 taz4.h5 --clobber)
+ JAMTEST (twithub_u513_c u513.txt twithub.h5 tall.h5 taz5.h5 --clobber)
+
+ JAMTEST (twithub513_u10_c u10.txt twithub513.h5 tall.h5 taz6.h5 --clobber)
+ JAMTEST (twithub513_u511_c u511.txt twithub513.h5 tall.h5 taz7.h5 --clobber)
+ JAMTEST (twithub513_u512_c u512.txt twithub513.h5 tall.h5 taz8.h5 --clobber)
+ JAMTEST (twithub513_u513_c u513.txt twithub513.h5 tall.h5 taz9.h5 --clobber)
+
+ JAMTEST_NONE (N_twithub_u10_c u10.txt tall.h5 twithub.h5 tay2.h5 --clobber)
+ JAMTEST_NONE (N_twithub_u511_c u511.txt tall.h5 twithub.h5 tay3.h5 --clobber)
+ JAMTEST_NONE (N_twithub_u512_c u512.txt tall.h5 twithub.h5 tay4.h5 --clobber)
+ JAMTEST_NONE (N_twithub_u513_c u513.txt tall.h5 twithub.h5 tay5.h5 --clobber)
+
+ JAMTEST_NONE (N_twithub513_u10_c u10.txt tall.h5 twithub513.h5 tay6.h5 --clobber)
+ JAMTEST_NONE (N_twithub513_u511_c u511.txt tall.h5 twithub513.h5 tay7.h5 --clobber)
+ JAMTEST_NONE (N_twithub513_u512_c u512.txt tall.h5 twithub513.h5 tay8.h5 --clobber)
+ JAMTEST_NONE (N_twithub513_u513_c u513.txt tall.h5 twithub513.h5 tay9.h5 --clobber)
+
+#-------------------------------
+# Testing h5unjam
+#-------------------------------
+ # help page
+ TEST_H5UNJAM_OUTPUT(h5unjam-help 0 -h)
+
+ UNJAMTEST (twithub_tall twithub.h5 tai1.h5 o10.txt tall.h5 taa1.h5)
+ UNJAMTEST (twithub513_tall twithub513.h5 tai2.h5 o512.txt tall.h5 taa2.h5)
+
+ UNJAMTEST (N_twithub_tall twithub.h5 tai3.h5 NONE tall.h5 taa3.h5)
+ UNJAMTEST (N_twithub513_tall twithub513.h5 tai4.h5 NONE tall.h5 taa4.h5)
+
+ UNJAMTEST (D_twithub_tall twithub.h5 taj2.h5 NONE tall.h5 tac2.h5 --delete)
+ UNJAMTEST (D_twithub513_tall twithub513.h5 taj3.h5 NONE tall.h5 tac3.h5 --delete)
diff --git a/tools/test/h5jam/Makefile.am b/tools/test/h5jam/Makefile.am
new file mode 100644
index 0000000..068f437
--- /dev/null
+++ b/tools/test/h5jam/Makefile.am
@@ -0,0 +1,40 @@
+#
+# Copyright by The HDF Group.
+# Copyright by the Board of Trustees of the University of Illinois.
+# 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 HDF5 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.
+##
+## Makefile.am
+## Run automake to generate a Makefile.in from this file.
+#
+# HDF5 Library Makefile(.in)
+#
+
+include $(top_srcdir)/config/commence.am
+
+# Include src and tools/lib directories
+AM_CPPFLAGS+=-I$(top_srcdir)/src -I$(top_srcdir)/tools/lib
+
+check_PROGRAMS=tellub h5jamgentest getub
+TEST_SCRIPT=testh5jam.sh
+
+check_SCRIPTS=$(TEST_SCRIPT)
+SCRIPT_DEPEND=../../src/h5jam/h5jam$(EXEEXT) ../../src/h5jam/h5unjam$(EXEEXT)
+
+# Link against the main HDF5 library and tools library
+LDADD=$(LIBH5TOOLS) $(LIBHDF5)
+
+# Temporary files. *.h5 are generated by jamgentest. They should
+# copied to the testfiles/ directory if update is required.
+CHECK_CLEANFILES+=*.h5 testfiles/h5jam-*-sav testfiles/h5unjam-*-sav
+DISTCLEANFILES=testh5jam.sh
+
+include $(top_srcdir)/config/conclude.am
diff --git a/tools/test/h5jam/getub.c b/tools/test/h5jam/getub.c
new file mode 100644
index 0000000..4e02e6b
--- /dev/null
+++ b/tools/test/h5jam/getub.c
@@ -0,0 +1,157 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * Copyright by The HDF Group. *
+ * Copyright by the Board of Trustees of the University of Illinois. *
+ * 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 HDF5 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. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+#include "H5private.h"
+#include "h5tools.h"
+#include "h5tools_utils.h"
+
+void parse_command_line(int argc, const char *argv[]);
+
+/* Name of tool */
+#define PROGRAM_NAME "getub"
+char *nbytes = NULL;
+
+static const char *s_opts = "c:"; /* add more later ? */
+static struct long_options l_opts[] = {
+ {"c", require_arg, 'c'}, /* input file */
+ {NULL, 0, '\0'}
+};
+
+/*-------------------------------------------------------------------------
+ * Function: usage
+ *
+ * Purpose: Print the usage message
+ *
+ * Return: void
+ *-------------------------------------------------------------------------
+ */
+static void
+usage (const char *prog)
+{
+ HDfflush(stdout);
+ HDfprintf(stdout, "usage: %s -c nb file] \n", prog);
+ HDfprintf(stdout, " print first 'nb' byts of file to stdoug.\n");
+}
+
+/*-------------------------------------------------------------------------
+ * Function: parse_command_line
+ *
+ * Purpose: Parse the command line for the h5dumper.
+ *
+ * Return: Success:
+ *
+ * Failure: Exits program with EXIT_FAILURE value.
+ *-------------------------------------------------------------------------
+ */
+void
+parse_command_line(int argc, const char *argv[])
+{
+ int opt;
+
+ /* parse command line options */
+ while((opt = get_option (argc, argv, s_opts, l_opts)) != EOF) {
+ switch((char) opt) {
+ case 'c':
+ nbytes = HDstrdup(opt_arg);
+ break;
+ case '?':
+ default:
+ usage(h5tools_getprogname());
+ HDexit(EXIT_FAILURE);
+ } /* end switch */
+ } /* end while */
+
+ if(argc <= opt_ind) {
+ error_msg("missing file name\n");
+ usage(h5tools_getprogname());
+ HDexit(EXIT_FAILURE);
+ } /* end if */
+} /* end parse_command_line() */
+
+int
+main(int argc, const char *argv[])
+{
+ int fd = -1;
+ unsigned size;
+ char *filename = NULL;
+ long res;
+ char *buf = NULL;
+
+ h5tools_setprogname(PROGRAM_NAME);
+ h5tools_setstatus(EXIT_SUCCESS);
+
+ /* Initialize h5tools lib */
+ h5tools_init();
+
+ parse_command_line(argc, argv);
+
+ if(NULL == nbytes) {
+ /* missing arg */
+ error_msg("missing size\n");
+ usage(h5tools_getprogname());
+ goto error;
+ } /* end if */
+
+ if(argc <= (opt_ind)) {
+ error_msg("missing file name\n");
+ usage(h5tools_getprogname());
+ goto error;
+ } /* end if */
+
+ filename = HDstrdup(argv[opt_ind]);
+
+ size = 0;
+ if(EOF == (res = sscanf(nbytes, "%u", &size))) {
+ /* fail */
+ error_msg("missing file name\n");
+ usage(h5tools_getprogname());
+ goto error;
+ } /* end if */
+
+ if((fd = HDopen(filename, O_RDONLY, 0)) < 0) {
+ error_msg("can't open file %s\n", filename);
+ goto error;
+ } /* end if */
+
+ if(NULL == (buf = (char *)HDmalloc((unsigned)(size + 1)))) {
+ error_msg("can't allocate buffer \n");
+ goto error;
+ } /* end if */
+
+ res = HDread(fd, buf, (unsigned)size);
+ if(res < (long)size) {
+ error_msg("Bad read \n");
+ goto error;
+ } /* end if */
+
+ if(HDwrite(1, buf, (unsigned)size) < 0) {
+ error_msg("Bad write \n");
+ goto error;
+ } /* end if */
+
+ /* close things and exit */
+ HDfree(buf);
+ HDclose(fd);
+
+ return EXIT_SUCCESS;
+
+error:
+ if(buf)
+ HDfree(buf);
+ if(fd > -1)
+ HDclose(fd);
+ return EXIT_FAILURE;
+} /* end main() */
+
diff --git a/tools/test/h5jam/h5jamgentest.c b/tools/test/h5jam/h5jamgentest.c
new file mode 100644
index 0000000..a12b17a
--- /dev/null
+++ b/tools/test/h5jam/h5jamgentest.c
@@ -0,0 +1,389 @@
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * Copyright by The HDF Group. *
+ * Copyright by the Board of Trustees of the University of Illinois. *
+ * 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 HDF5 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. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/*
+ * Generate the binary hdf5 files and user block data for the jam/unjam tests.
+ * Usage: just execute the program without any arguments will
+ * generate all the files in the local directory.
+ *
+ * If you regenerate the test files (e.g., changing some code,
+ * trying it on a new platform, ...), you need to verify the correctness
+ * of the expected output and update the corresponding *.ddl files.
+ */
+#include <assert.h>
+#include <limits.h>
+
+#include "hdf5.h"
+#include "H5private.h"
+
+/* not used yet
+#define UBTXT1 "u0.txt"
+*/
+#define UBTXT2 "u10.txt"
+#define UBTXT3 "u511.txt"
+#define UBTXT4 "u512.txt"
+#define UBTXT5 "u513.txt"
+/* not used yet
+#define UBTXT6 "u1023.txt"
+#define UBTXT7 "u1024.txt"
+#define UBTXT8 "u1025.txt"
+#define UBTXT9 "u2047.txt"
+#define UBTXT10 "u2048.txt"
+#define UBTXT11 "u2049.txt"
+#define UBBIN1 "u0.dat"
+#define UBBIN2 "u10.dat"
+#define UBBIN3 "u511.dat"
+#define UBBIN4 "u512.dat"
+#define UBBIN5 "u513.dat"
+*/
+
+/* not used yet
+#define FILE1 "tnull.h5"
+#define FILE2 "tnullwithub.h5"
+*/
+/* tall is same as dumper test */
+#define FILE7 "tall.h5"
+#define FILE8 "twithub.h5"
+#define FILE9 "twithub513.h5"
+
+/*
+ * This pattern is used to fill text files
+ */
+char pattern[11] = "abcdefghij";
+
+/*-------------------------------------------------------------------------
+ * prototypes
+ *-------------------------------------------------------------------------
+ */
+
+
+#define BUF_SIZE 1024
+
+/* Element selection information */
+
+typedef enum{
+ RED,
+ GREEN,
+ BLUE,
+ WHITE,
+ BLACK
+} enumtype;
+
+/* Compound datatype */
+typedef struct s1_t {
+ unsigned int a;
+ unsigned int b;
+ float c;
+} s1_t;
+
+
+/* A UD link traversal function. Shouldn't actually be called. */
+static hid_t UD_traverse(const char H5_ATTR_UNUSED * link_name, hid_t H5_ATTR_UNUSED cur_group,
+ const void H5_ATTR_UNUSED * udata, size_t H5_ATTR_UNUSED udata_size, hid_t H5_ATTR_UNUSED lapl_id)
+{
+ return -1;
+}
+
+#define MY_LINKCLASS 187
+const H5L_class_t UD_link_class[1] = {{
+ H5L_LINK_CLASS_T_VERS, /* H5L_class_t version */
+ (H5L_type_t)MY_LINKCLASS, /* Link type id number */
+ "UD link class", /* name for debugging */
+ NULL, /* Creation callback */
+ NULL, /* Move/rename callback */
+ NULL, /* Copy callback */
+ UD_traverse, /* The actual traversal function */
+ NULL, /* Deletion callback */
+ NULL /* Query callback */
+}};
+
+
+
+/* gent_ub
+ with no ub, identical to gent_all from h5dumpgentest.c
+
+ FILENAME is the name of the file to create
+ UB_SIZE is the size the buffer should be
+ UB_FILL characters will be set to the PATTERN array,
+ the rest of the user block will be NULL.
+
+/ : g1 g2 attr1 attr2
+g1 : g1.1 g1.2
+g1.1 : dset1.1.1(attr1, attr2) dset1.1.2
+g1.2 : g1.2.1 extlink
+g1.2.1 : slink
+g2 : dset2.1 dset2.2 udlink
+
+*/
+
+static void
+gent_ub(const char * filename, size_t ub_size, size_t ub_fill)
+{
+ hid_t fid, group, attr, dataset, space;
+ hid_t create_plist;
+ hsize_t dims[2];
+ int data[2][2], dset1[10][10], dset2[20];
+ char buf[BUF_SIZE];
+ int i, j;
+ size_t u;
+ float dset2_1[10], dset2_2[3][5];
+ int fd;
+ char *bp;
+
+ if(ub_size > 0)
+ {
+ create_plist = H5Pcreate(H5P_FILE_CREATE);
+ H5Pset_userblock(create_plist, (hsize_t)ub_size);
+ fid = H5Fcreate(filename, H5F_ACC_TRUNC, create_plist, H5P_DEFAULT);
+ }
+ else
+ {
+ fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ }
+
+ /* create groups */
+ group = H5Gcreate2(fid, "/g1", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ H5Gclose(group);
+
+ group = H5Gcreate2(fid, "/g2", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ H5Gclose(group);
+
+ group = H5Gcreate2(fid, "/g1/g1.1", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ H5Gclose(group);
+
+ group = H5Gcreate2(fid, "/g1/g1.2", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ H5Gclose(group);
+
+ group = H5Gcreate2(fid, "/g1/g1.2/g1.2.1", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ H5Gclose(group);
+
+ /* root attributes */
+ group = H5Gopen2(fid, "/", H5P_DEFAULT);
+
+ dims[0] = 10;
+ space = H5Screate_simple(1, dims, NULL);
+ attr = H5Acreate2(group, "attr1", H5T_STD_I8BE, space, H5P_DEFAULT, H5P_DEFAULT);
+ sprintf(buf, "abcdefghi");
+ H5Awrite(attr, H5T_NATIVE_SCHAR, buf);
+ H5Sclose(space);
+ H5Aclose(attr);
+
+ dims[0] = 2; dims[1] = 2;
+ space = H5Screate_simple(2, dims, NULL);
+ attr = H5Acreate2(group, "attr2", H5T_STD_I32BE, space, H5P_DEFAULT, H5P_DEFAULT);
+ data[0][0] = 0; data[0][1] = 1; data[1][0] = 2; data[1][1] = 3;
+ H5Awrite(attr, H5T_NATIVE_INT, data);
+ H5Sclose(space);
+ H5Aclose(attr);
+
+ H5Gclose(group);
+
+ group = H5Gopen2(fid, "/g1/g1.1", H5P_DEFAULT);
+
+ /* dset1.1.1 */
+ dims[0] = 10; dims[1] = 10;
+ space = H5Screate_simple(2, dims, NULL);
+ dataset = H5Dcreate2(group, "dset1.1.1", H5T_STD_I32BE, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ for (i = 0; i < 10; i++)
+ for (j = 0; j < 10; j++)
+ dset1[i][j] = j*i;
+ H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset1);
+ H5Sclose(space);
+
+ /* attributes of dset1.1.1 */
+ dims[0] = 27;
+ space = H5Screate_simple(1, dims, NULL);
+ attr = H5Acreate2(dataset, "attr1", H5T_STD_I8BE, space, H5P_DEFAULT, H5P_DEFAULT);
+ sprintf(buf, "1st attribute of dset1.1.1");
+ H5Awrite(attr, H5T_NATIVE_SCHAR, buf);
+ H5Sclose(space);
+ H5Aclose(attr);
+
+ dims[0] = 27;
+ space = H5Screate_simple(1, dims, NULL);
+ attr = H5Acreate2(dataset, "attr2", H5T_STD_I8BE, space, H5P_DEFAULT, H5P_DEFAULT);
+ sprintf(buf, "2nd attribute of dset1.1.1");
+ H5Awrite(attr, H5T_NATIVE_SCHAR, buf);
+ H5Sclose(space);
+ H5Aclose(attr);
+
+ H5Dclose(dataset);
+
+ /* dset1.1.2 */
+ dims[0] = 20;
+ space = H5Screate_simple(1, dims, NULL);
+ dataset = H5Dcreate2(group, "dset1.1.2", H5T_STD_I32BE, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ for (i = 0; i < 20; i++)
+ dset2[i] = i;
+ H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset2);
+ H5Sclose(space);
+ H5Dclose(dataset);
+
+ H5Gclose(group);
+
+ /* external link */
+ H5Lcreate_external("somefile", "somepath", fid, "/g1/g1.2/extlink", H5P_DEFAULT, H5P_DEFAULT);
+
+ /* soft link */
+ group = H5Gopen2(fid, "/g1/g1.2/g1.2.1", H5P_DEFAULT);
+ H5Lcreate_soft("somevalue", group, "slink", H5P_DEFAULT, H5P_DEFAULT);
+ H5Gclose(group);
+
+ group = H5Gopen2(fid, "/g2", H5P_DEFAULT);
+
+ /* dset2.1 */
+ dims[0] = 10;
+ space = H5Screate_simple(1, dims, NULL);
+ dataset = H5Dcreate2(group, "dset2.1", H5T_IEEE_F32BE, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ for (i = 0; i < 10; i++)
+ dset2_1[i] = (float)((float)i * 0.1F + 1.0F);
+ H5Dwrite(dataset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset2_1);
+ H5Sclose(space);
+ H5Dclose(dataset);
+
+ /* dset2.2 */
+ dims[0] = 3; dims[1] = 5;
+ space = H5Screate_simple(2, dims, NULL);
+ dataset = H5Dcreate2(group, "dset2.2", H5T_IEEE_F32BE, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ for (i = 0; i < 3; i++)
+ for (j = 0; j < 5; j++)
+ dset2_2[i][j] = (float)(((float)i + 1.0F) * (float)j * 0.1F);
+ H5Dwrite(dataset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset2_2);
+ H5Sclose(space);
+ H5Dclose(dataset);
+
+ H5Gclose(group);
+
+ /* user-defined link */
+ H5Lregister(UD_link_class);
+ H5Lcreate_ud(fid, "/g2/udlink", (H5L_type_t)MY_LINKCLASS, NULL, (size_t)0, H5P_DEFAULT, H5P_DEFAULT);
+
+ H5Fclose(fid);
+
+ /* If a user block is being used, write to it here */
+ if(ub_size > 0)
+ {
+ ssize_t nbytes;
+
+ HDassert(ub_size <= BUF_SIZE);
+
+ fd = HDopen(filename, O_RDWR, 0);
+ HDassert(fd >= 0);
+
+ /* fill buf with pattern */
+ HDmemset(buf, '\0', ub_size);
+ bp = buf;
+ for (u = 0; u < ub_fill; u++)
+ *bp++ = pattern[u % 10];
+
+ nbytes = HDwrite(fd, buf, ub_size);
+ HDassert(nbytes >= 0);
+
+ HDclose(fd);
+ }
+}
+
+static void
+create_textfile(const char *name, size_t size)
+{
+ char *buf;
+ int fd;
+ size_t i;
+ char *bp;
+ ssize_t nbytes;
+
+ fd = HDcreat(name,0777);
+ HDassert(fd >= 0);
+ buf = (char *)HDcalloc(size, (size_t)1);
+ HDassert(buf);
+
+ /* fill buf with pattern */
+ bp = buf;
+ for(i = 0; i < size; i++)
+ *bp++ = pattern[i % 10];
+
+ nbytes = HDwrite(fd, buf, size);
+ HDassert(nbytes >= 0);
+
+ HDfree(buf);
+
+ HDclose(fd);
+}
+
+#ifdef notdef
+/* not used yet */
+void
+create_binfile(char *name, off_t size)
+{
+ char *buf;
+ int fd;
+ int i;
+ char *bp;
+
+ fd = creat(name,0777);
+ HDassert(fd >= 0);
+
+ buf = HDcalloc(size,1);
+ HDassert(buf);
+
+ /* fill buf with pattern */
+ bp = buf;
+ for (i = 0; i < size; i++)
+ *bp++ = (char) i & 0xff;
+
+ HDwrite(fd,buf,size);
+
+ HDclose(fd);
+}
+#endif
+
+/*-------------------------------------------------------------------------
+ * Function: main
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+int main(void)
+{
+
+/*
+create_textfile(UBTXT1, (size_t)0);
+*/
+create_textfile(UBTXT2, (size_t)10);
+create_textfile(UBTXT3, (size_t)511);
+create_textfile(UBTXT4, (size_t)512);
+create_textfile(UBTXT5, (size_t)513);
+/*
+create_textfile(UBTXT6, (size_t)1023);
+create_textfile(UBTXT7, (size_t)1024);
+create_textfile(UBTXT8, (size_t)1025);
+create_textfile(UBTXT9, (size_t)2047);
+create_textfile(UBTXT10, (size_t)2048);
+create_textfile(UBTXT11, (size_t)2049);
+
+create_binfile(UBBIN1, (off_t)0);
+create_binfile(UBBIN2, (off_t)10);
+create_binfile(UBBIN3, (off_t)511);
+create_binfile(UBBIN4, (off_t)512);
+create_binfile(UBBIN5, (off_t)513);
+
+*/
+ gent_ub(FILE7, (size_t)0, (size_t)0);
+ gent_ub(FILE8, (size_t)512, HDstrlen(pattern));
+ gent_ub(FILE9, (size_t)1024, (size_t)513);
+
+ return 0;
+}
diff --git a/tools/test/h5jam/tellub.c b/tools/test/h5jam/tellub.c
new file mode 100644
index 0000000..b4f87af
--- /dev/null
+++ b/tools/test/h5jam/tellub.c
@@ -0,0 +1,196 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * Copyright by The HDF Group. *
+ * Copyright by the Board of Trustees of the University of Illinois. *
+ * 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 HDF5 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. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+#include <stdio.h>
+
+#ifdef H5_HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include "hdf5.h"
+#include "H5private.h"
+#include "h5tools.h"
+#include "h5tools_utils.h"
+
+/* Name of tool */
+#define PROGRAMNAME "tellub"
+
+/*
+ * Command-line options: The user can specify short or long-named
+ * parameters. The long-named ones can be partially spelled. When
+ * adding more, make sure that they don't clash with each other.
+ */
+static const char *s_opts = "h";
+static struct long_options l_opts[] = {
+ {"help", no_arg, 'h'},
+ {"hel", no_arg, 'h'},
+ {NULL, 0, '\0'}
+};
+
+/*-------------------------------------------------------------------------
+ * Function: usage
+ *
+ * Purpose: Print the usage message
+ *
+ * Return: void
+ *
+ * Programmer:
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static void
+usage (const char *prog)
+{
+ fflush (stdout);
+ fprintf (stdout, "usage: %s h5_file\n", prog);
+ fprintf (stdout,
+ " Check that h5_fil is HDF5 file and print size of user block \n");
+ fprintf (stdout, " %s -h\n", prog);
+ fprintf (stdout, " Print a usage message and exit\n");
+}
+
+/*-------------------------------------------------------------------------
+ * Function: parse_command_line
+ *
+ * Purpose: Parse the command line for the h5dumper.
+ *
+ * Return: Success:
+ *
+ * Failure: Exits program with EXIT_FAILURE value.
+ *
+ * Programmer:
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+static void
+parse_command_line (int argc, const char *argv[])
+{
+ int opt;
+
+ /* parse command line options */
+ while ((opt = get_option (argc, argv, s_opts, l_opts)) != EOF)
+ {
+ switch ((char) opt)
+ {
+ case 'h':
+ usage (h5tools_getprogname());
+ exit (EXIT_SUCCESS);
+ case '?':
+ default:
+ usage (h5tools_getprogname());
+ exit (EXIT_FAILURE);
+ }
+ }
+
+ /* check for file name to be processed */
+ if (argc <= opt_ind)
+ {
+ error_msg("missing file name\n");
+ usage (h5tools_getprogname());
+ exit (EXIT_FAILURE);
+ }
+}
+
+/*-------------------------------------------------------------------------
+ * Function: main
+ *
+ * Purpose: HDF5 user block unjammer
+ *
+ * Return: Success: 0
+ * Failure: 1
+ *
+ * Programmer:
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+int
+main (int argc, const char *argv[])
+{
+ char *ifname;
+ void *edata;
+ H5E_auto2_t func;
+ hid_t ifile;
+ hsize_t usize;
+ htri_t testval;
+ herr_t status;
+ hid_t plist;
+
+ h5tools_setprogname(PROGRAMNAME);
+ h5tools_setstatus(EXIT_SUCCESS);
+
+ /* Initialize h5tools lib */
+ h5tools_init();
+
+ /* Disable error reporting */
+ H5Eget_auto2(H5E_DEFAULT, &func, &edata);
+ H5Eset_auto2(H5E_DEFAULT, NULL, NULL);
+
+ parse_command_line (argc, argv);
+
+ if (argc <= (opt_ind))
+ {
+ error_msg("missing file name\n");
+ usage (h5tools_getprogname());
+ return (EXIT_FAILURE);
+ }
+
+ ifname = HDstrdup (argv[opt_ind]);
+
+ testval = H5Fis_hdf5 (ifname);
+
+ if (testval <= 0)
+ {
+ error_msg("Input HDF5 file is not HDF \"%s\"\n", ifname);
+ return (EXIT_FAILURE);
+ }
+
+ ifile = H5Fopen (ifname, H5F_ACC_RDONLY, H5P_DEFAULT);
+
+ if (ifile < 0)
+ {
+ error_msg("Can't open input HDF5 file \"%s\"\n", ifname);
+ return (EXIT_FAILURE);
+ }
+
+ plist = H5Fget_create_plist (ifile);
+ if (plist < 0)
+ {
+ error_msg("Can't get file creation plist for file \"%s\"\n",
+ ifname);
+ return (EXIT_FAILURE);
+ }
+
+ status = H5Pget_userblock (plist, &usize);
+ if (status < 0)
+ {
+ error_msg("Can't get user block for file \"%s\"\n", ifname);
+ return (EXIT_FAILURE);
+ }
+
+ printf ("%ld\n", (long) usize);
+
+ H5Pclose (plist);
+ H5Fclose (ifile);
+
+ return (EXIT_SUCCESS);
+}
+
diff --git a/tools/test/h5jam/testfiles/h5jam-help.txt b/tools/test/h5jam/testfiles/h5jam-help.txt
new file mode 100644
index 0000000..ce97c22
--- /dev/null
+++ b/tools/test/h5jam/testfiles/h5jam-help.txt
@@ -0,0 +1,24 @@
+usage: h5jam -i <in_file.h5> -u <in_user_file> [-o <out_file.h5>] [--clobber]
+
+Adds user block to front of an HDF5 file and creates a new concatenated file.
+
+OPTIONS
+ -i in_file.h5 Specifies the input HDF5 file.
+ -u in_user_file Specifies the file to be inserted into the user block.
+ Can be any file format except an HDF5 format.
+ -o out_file.h5 Specifies the output HDF5 file.
+ If not specified, the user block will be concatenated in
+ place to the input HDF5 file.
+ --clobber Wipes out any existing user block before concatenating
+ the given user block.
+ The size of the new user block will be the larger of;
+ - the size of existing user block in the input HDF5 file
+ - the size of user block required by new input user file
+ (size = 512 x 2N, N is positive integer.)
+
+ -h Prints a usage message and exits.
+ -V Prints the HDF5 library version and exits.
+
+Exit Status:
+ 0 Succeeded.
+ >0 An error occurred.
diff --git a/tools/test/h5jam/testfiles/h5jam-ub-nohdf5.txt b/tools/test/h5jam/testfiles/h5jam-ub-nohdf5.txt
new file mode 100644
index 0000000..72c0b17
--- /dev/null
+++ b/tools/test/h5jam/testfiles/h5jam-ub-nohdf5.txt
@@ -0,0 +1,2 @@
+h5jam error: -u <user_file> cannot be HDF5 file, but it appears to be an HDF5 file.
+Try '-h' or '--help' for more information or see the <h5jam> entry in the 'HDF5 Reference Manual'.
diff --git a/tools/test/h5jam/testfiles/h5unjam-help.txt b/tools/test/h5jam/testfiles/h5unjam-help.txt
new file mode 100644
index 0000000..f0d92e9
--- /dev/null
+++ b/tools/test/h5jam/testfiles/h5unjam-help.txt
@@ -0,0 +1,27 @@
+usage: h5unjam -i <in_file.h5> [-o <out_file.h5> ] [-u <out_user_file> | --delete]
+
+Splits user file and HDF5 file into two files: user block data and HDF5 data.
+
+OPTIONS
+ -i in_file.h5 Specifies the HDF5 as input. If the input HDF5 file
+ contains no user block, exit with an error message.
+ -o out_file.h5 Specifies output HDF5 file without a user block.
+ If not specified, the user block will be removed from the
+ input HDF5 file.
+ -u out_user_file
+ Specifies the output file containing the data from the
+ user block.
+ Cannot be used with --delete option.
+ --delete Remove the user block from the input HDF5 file. The content
+ of the user block is discarded.
+ Cannot be used with the -u option.
+
+ -h Prints a usage message and exits.
+ -V Prints the HDF5 library version and exits.
+
+ If neither --delete nor -u is specified, the user block from the input file
+ will be displayed to stdout.
+
+Exit Status:
+ 0 Succeeded.
+ >0 An error occurred.
diff --git a/tools/test/h5jam/testfiles/tall.h5 b/tools/test/h5jam/testfiles/tall.h5
new file mode 100644
index 0000000..918aeee
--- /dev/null
+++ b/tools/test/h5jam/testfiles/tall.h5
Binary files differ
diff --git a/tools/test/h5jam/testfiles/twithub.h5 b/tools/test/h5jam/testfiles/twithub.h5
new file mode 100644
index 0000000..4bc1833
--- /dev/null
+++ b/tools/test/h5jam/testfiles/twithub.h5
Binary files differ
diff --git a/tools/test/h5jam/testfiles/twithub513.h5 b/tools/test/h5jam/testfiles/twithub513.h5
new file mode 100644
index 0000000..0eac208
--- /dev/null
+++ b/tools/test/h5jam/testfiles/twithub513.h5
Binary files differ
diff --git a/tools/test/h5jam/testfiles/u10.txt b/tools/test/h5jam/testfiles/u10.txt
new file mode 100644
index 0000000..c76a964
--- /dev/null
+++ b/tools/test/h5jam/testfiles/u10.txt
@@ -0,0 +1 @@
+abcdefghij \ No newline at end of file
diff --git a/tools/test/h5jam/testfiles/u511.txt b/tools/test/h5jam/testfiles/u511.txt
new file mode 100644
index 0000000..bff1736
--- /dev/null
+++ b/tools/test/h5jam/testfiles/u511.txt
@@ -0,0 +1 @@
+abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghija \ No newline at end of file
diff --git a/tools/test/h5jam/testfiles/u512.txt b/tools/test/h5jam/testfiles/u512.txt
new file mode 100644
index 0000000..33a36c9
--- /dev/null
+++ b/tools/test/h5jam/testfiles/u512.txt
@@ -0,0 +1 @@
+abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijab \ No newline at end of file
diff --git a/tools/test/h5jam/testfiles/u513.txt b/tools/test/h5jam/testfiles/u513.txt
new file mode 100644
index 0000000..6b46ebf
--- /dev/null
+++ b/tools/test/h5jam/testfiles/u513.txt
@@ -0,0 +1 @@
+abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabc \ No newline at end of file
diff --git a/tools/test/h5jam/testh5jam.sh.in b/tools/test/h5jam/testh5jam.sh.in
new file mode 100644
index 0000000..fb6d9e2
--- /dev/null
+++ b/tools/test/h5jam/testh5jam.sh.in
@@ -0,0 +1,699 @@
+#! /bin/sh
+#
+# Copyright by The HDF Group.
+# Copyright by the Board of Trustees of the University of Illinois.
+# 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 HDF5 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.
+#
+# Tests for the h5jam/h5unjam tools
+
+srcdir=@srcdir@
+
+# Determine which filters are available
+USE_FILTER_SZIP="@USE_FILTER_SZIP@"
+USE_FILTER_DEFLATE="@USE_FILTER_DEFLATE@"
+
+TESTNAME=../../src/h5jam/h5unjam
+EXIT_SUCCESS=0
+EXIT_FAILURE=1
+
+DUMPER=../../src/h5dump/h5dump # The dumper to use
+DUMPER_BIN=`pwd`/../$DUMPER # The path of the dumper binary
+JAM=../../src/h5jam/h5jam # Tool to test
+UNJAM=../../src/h5jam/h5unjam # Tool to test
+JAM_BIN="$RUNSERIAL "`pwd` # The path of the jam binary
+UNJAM_BIN=`pwd` # The path of the jam binary
+
+RM='rm -rf'
+CMP='cmp -s'
+DIFF='diff -c'
+AWK='awk'
+CP='cp'
+DIRNAME='dirname'
+LS='ls'
+AWK='awk'
+
+nerrors=0
+verbose=yes
+
+# source dirs
+SRC_TOOLS="$srcdir/../.."
+SRC_TOOLS_TESTFILES="$SRC_TOOLS/testfiles"
+
+# testfiles source dirs for tools
+SRC_H5LS_TESTFILES="$SRC_TOOLS_TESTFILES"
+SRC_H5DUMP_TESTFILES="$SRC_TOOLS_TESTFILES"
+SRC_H5DIFF_TESTFILES="$SRC_TOOLS/test/h5diff/testfiles"
+SRC_H5COPY_TESTFILES="$SRC_TOOLS/test/h5copy/testfiles"
+SRC_H5REPACK_TESTFILES="$SRC_TOOLS/test/h5repack/testfiles"
+SRC_H5JAM_TESTFILES="$SRC_TOOLS/test/h5jam/testfiles"
+SRC_H5STAT_TESTFILES="$SRC_TOOLS/test/h5stat/testfiles"
+SRC_H5IMPORT_TESTFILES="$SRC_TOOLS/test/h5import/testfiles"
+
+TESTDIR=./testfiles
+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_H5JAM_TESTFILES/tall.h5
+$SRC_H5JAM_TESTFILES/twithub.h5
+$SRC_H5JAM_TESTFILES/twithub513.h5
+"
+LIST_OTHER_TEST_FILES="
+$SRC_H5JAM_TESTFILES/u10.txt
+$SRC_H5JAM_TESTFILES/u511.txt
+$SRC_H5JAM_TESTFILES/u512.txt
+$SRC_H5JAM_TESTFILES/u513.txt
+$SRC_H5JAM_TESTFILES/h5jam-help.txt
+$SRC_H5JAM_TESTFILES/h5unjam-help.txt
+$SRC_H5JAM_TESTFILES/h5jam-ub-nohdf5.txt
+"
+
+# Source in the output filter function definitions.
+. $srcdir/../../../bin/output_filter.sh
+
+#
+# copy test files and expected output files from source dirs to test dir
+#
+COPY_TESTFILES="$LIST_HDF5_TEST_FILES $LIST_OTHER_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_H5JAM_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 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 "Compare".
+#
+COMPARE() {
+ SPACES=" "
+ echo "Compare $* $SPACES" | cut -c1-70 | tr -d '\012'
+}
+
+# Print a "SKIP" message
+SKIP() {
+ TESTING $JAM $@
+ echo " -SKIP-"
+}
+
+#
+# COMPARE_FILES a.h5 b.h5
+# Compare two files, skipping the first line. This is used to
+# compare the output of the dumper, skipping the file name which
+# is different.
+# The result is stored in 'compval'.
+#
+cmpval=0;
+COMPARE_FILES() {
+ $AWK 'NR > 1' $1 > $1.cmp
+ $AWK 'NR > 1' $2 > $2.cmp
+ $CMP $1.cmp $2.cmp
+ cmpval=$?
+ rm -f $1.cmp $2.cmp
+}
+
+# CLEANUP files
+# Clean up named files.
+CLEANUP() {
+ if test -z "$HDF5_NOCLEANUP"; then
+ for i in $*
+ do
+ rm -f $i
+ done
+ fi
+}
+
+# SETUP file tocopy
+# Clone a standard input file in the test directory
+# Modification:
+# Was using "cp" command which means file $2 will inherit the permission
+# setting of file $1. If $1 is read-only, so will $2. That will cause
+# failure when the test attempts to write it later on. Changed to use
+# the "cat" command.
+#
+SETUP() {
+ cat < $1 > $2
+}
+
+#
+# CHECKFILE orig.h5 compar.h5
+# Check that the test file is the same as an original.
+# The two files are dumped with the dumper, and the output
+# compared with COMPARE_FILES.
+# If the files are the same, the test reports " PASSED",
+# otherwise, it reports "*FAILED*"
+CHECKFILE() {
+ expected="`dirname $2`/`basename $2 .h5`.out"
+ expected_err="`dirname $2`/`basename $2 .h5`.err"
+ actual="`basename $1 .h5`.out"
+ actual_err="`basename $1 .h5`.err"
+
+ $RUNSERIAL $DUMPER_BIN/$DUMPER $1 >$expected 2>$expected_err
+ cat $expected_err >> $expected
+
+ # dump the test file
+ COMPARE $2 to $1
+ $RUNSERIAL $DUMPER_BIN/$DUMPER $2 >$actual 2>$actual_err
+ cat $actual_err >> $actual
+
+ # compare the two files (ignore line 1)
+ COMPARE_FILES $actual $expected
+ if [ "$cmpval" = 0 ] ; then
+ echo " PASSED"
+ else
+ echo "*FAILED*"
+ echo " Expected result (*.ddl) differs from actual result (*.out)"
+ nerrors="`expr $nerrors + 1`"
+ test yes = "$verbose" && $DIFF $expected $actual |sed 's/^/ /'
+ fi
+
+ # Clean up output files
+ if test -z "$HDF5_NOCLEANUP"; then
+ rm -f $actual $actual_err
+ rm -f $expected $expected_err
+ fi
+}
+
+#
+# CHECK_UB file.h5 user_block_file origfile.h5
+#
+# Check the user block in 'file.h5' is the same as
+# 'user_block' (allowing for padding).
+#
+# If the original file had a user block before the test
+# then 'compare.h5' is passed. The user block must be extracted
+# and the test file compared to:
+# cat compare_ub user_block_file.
+#
+# This test uses './getub' to extract the user block from
+# 'file.h5', which is compared to the file described above.
+#
+# The result is set in variable 'result1'.
+#
+result1=0;
+CHECK_UB_1() {
+ hfile="$1"
+ ufile="$2"
+
+ # check for third argument (the original file)
+ origfile="";
+ if [ -n "$3" ];
+ then
+ origfile="$3"
+ fi
+
+ # find the length of the user block to check
+ s1=`cat $ufile | wc -c | sed -e 's/ //g'`
+ if [ "$s1" = "0" ];
+ then
+ echo "File "$ufile" is empty"
+ result1=1;
+ fi
+
+ # Get the size of the original user block, if any.
+ if [ -n "$origfile" ];
+ then
+ # 'tellub' calls H5Fget_user_block to get the size
+ # of the user block
+ s2=`$JAM_BIN/tellub $origfile`
+ if [ "$s2" = "0" ];
+ then
+ size=$s1;
+ cmpfile=$ufile
+ else
+ cmpfile="tt2"
+ size=`expr $s2 + $s1`
+ $JAM_BIN/getub -c $s2 $origfile > $cmpfile
+ cat $ufile >> $cmpfile
+ fi
+ else
+ # assume no user block
+ s2="0"
+ size=$s1;
+ cmpfile=$ufile
+ fi
+
+ # Extract 'size' bytes from the front of 'hfile'
+ # Compare to 'cmpfile', result is set in result1
+ tfile="tt1"
+ $JAM_BIN/getub -c $size $hfile > $tfile
+ res=`cmp $cmpfile $tfile`
+ if [ "$?" != "0" ];
+ then
+ echo $res
+ result1=1;
+ else
+ result1=0;
+ fi
+
+ # clean up
+ rm -f $tfile
+ if [ "$s2" != "0" ] ;
+ then
+ rm -f $cmpfile
+ fi
+}
+
+
+# CHECK_NOUB file.h5
+#
+# Check that 'file.h5' has no user block.
+# Setst result2 to 1 if there is a user block (fail), 0 if none (pass)
+
+result2=0;
+
+CHECK_NOUB() {
+ hfile="$1"
+
+ # call 'ubsize' to get the size of the user block
+ ubsize=`$JAM_BIN/tellub $hfile`
+
+ if [ "$?" != "0" ];
+ then
+ # error
+ result2=1;
+ else
+ if [ "$ubsize" = "0" ];
+ then
+ # pass
+ result2=0;
+ else
+ # fail
+ result2=1;
+ fi
+ fi
+}
+
+# JAMTEST user_block file.h5 [--clobber] [ofile.h5]
+#
+# Test the 'jam' tool:
+# 1. figure out the input and output, and the comparision
+# that will be done.
+# 2. call 'jam' with the appropriate arguments
+# 3. check the user block is correct in the output (Check_UB)
+# If the user block is correct, print "PASSED", else "*FAILED*"
+JAMTEST() {
+ ufile="$1"
+ ifile="$2"
+ compare_test="" # the file to test
+ compare_orig="" # the comparison to test against
+ cleanup=""
+
+ # sort out the arguments for the test and the check
+ do_clobber="no"
+ if [ "$3" = "--clobber" ];
+ then
+ # clobber overwrites any existing user block
+ do_clobber="yes"
+ clobber="--clobber"
+ compare_orig=""
+ if [ -z "$4" ];
+ then
+ # output goes to infile, compare ubfile to infile
+ ofile=""
+ compare_test="$ifile"
+ else
+ # output goes to $4, compare ofile to ubfile
+ ofile="$4"
+ compare_test="$ofile"
+ fi
+ else
+ clobber=""
+ # add user block to existing ub, if any
+ if [ -z "$3" ];
+ then
+ # output goes to infile, compare ubfile to infile
+ ofile=""
+ compare_test="$ifile"
+ cp $ifile xxofile.h5
+ compare_orig="xxofile.h5"
+ cleanup="$cleanup $compare_orig"
+ else
+ # output goes to $3, compare ofile to ubfile
+ ofile="$3"
+ compare_test="$ofile"
+ compare_orig="$ifile"
+ fi
+ fi
+
+ # call 'jam' with the appropriate arguments
+ if [ -n "$ofile" ];
+ then
+ TESTING h5jam -u `basename $ufile` -i `basename $ifile` -o `basename $ofile` $clobber
+ $JAM_BIN/$JAM -u $ufile -i $ifile -o $ofile $clobber
+ else
+ TESTING jam -u `basename $ufile` -i `basename $ifile` $clobber
+ $JAM_BIN/$JAM -u $ufile -i $ifile $clobber
+ fi
+
+ #echo "CHECK_UB_1 $compare_test $ufile $compare_orig"
+ CHECK_UB_1 $compare_test $ufile $compare_orig
+
+ if [ "$result1" = "0" ] ;
+ then
+ echo " PASSED"
+ else
+ echo " *FAILED*"
+ nerrors="`expr $nerrors + 1`"
+ fi
+ CLEANUP $cleanup
+}
+
+# UNJAMTEST file.h5 [- | --delete] ofile
+#
+# Test the 'unjam' tool
+#
+###fix the working directory here and in jamtest
+UNJAMTEST () {
+ infile="$1"
+ ofile="$3"
+ if [ "$2" = "-" ];
+ then
+ uofile="uofile"
+ TESTING h5unjam -i `basename $infile` -o `basename $ofile` "> "`basename $uofile`
+ $JAM_BIN/$UNJAM -i $infile -o $ofile > $uofile
+ else
+ if [ "$2" = "--delete" ];
+ then
+ uofile="none"
+ TESTING h5unjam -i `basename $infile` -o `basename $ofile` --delete
+ $JAM_BIN/$UNJAM -i $infile -o $ofile --delete
+
+ else
+ uofile="$2"
+ TESTING h5unjam -i `basename $infile` -u `basename $uofile` -o `basename $ofile`
+ $JAM_BIN/$UNJAM -i $infile -u $uofile -o $ofile
+ fi
+ fi
+
+ result1=0
+ result2=0
+ cleanup=""
+ if [ "$uofile" != "none" ];
+ then
+ # sets result1
+ CHECK_UB_1 $infile $uofile
+ CLEANUP $uofile
+ fi
+
+ # sets result2
+ CHECK_NOUB $ofile
+
+ if [ "$result1" = "0" -a "$result2" = "0" ];
+ then
+ echo " PASSED"
+ else
+ echo " *FAILED*"
+ nerrors="`expr $nerrors + 1`"
+ fi
+}
+
+
+#
+# TOOLTEST_OUTPUT < JAM | UNJAM > expect-output.txt exit-code options
+#
+# Only verify stdout/stderr output from h5jam and j5unjam
+#
+
+TOOLTEST_OUTPUT() {
+ if [ "$1" == "JAM" ]; then
+ TOOLCMD=$JAM_BIN/$JAM
+ elif [ "$1" == "UNJAM" ]; then
+ TOOLCMD=$JAM_BIN/$UNJAM
+ fi
+ shift
+ 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
+
+ TESTING h5jam $@
+ (
+ cd $TESTDIR
+ $TOOLCMD "$@"
+ ) >$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
+ # combine stderr to stdout for output compare
+ cat $actual_err >> $actual
+
+ if [ ! -f $expect ]; then
+ # Create the expect file if it doesn't yet exist.
+ echo " CREATED"
+ cp $actual $expect
+ rm -f $actual $actual_sav $actual_err $actual_err_sav
+ elif $CMP $expect $actual; then
+ echo " PASSED"
+ rm -f $actual $actual_sav $actual_err $actual_err_sav
+ else
+ echo "*FAILED*"
+ echo " Expected result differs from actual result"
+ nerrors="`expr $nerrors + 1`"
+ test yes = "$verbose" && $DIFF $expect $actual |sed 's/^/ /'
+ fi
+}
+
+##############################################################################
+##############################################################################
+### T H E T E S T S ###
+##############################################################################
+##############################################################################
+# prepare for test
+COPY_TESTFILES_TO_TESTDIR
+
+#-------------------------------
+# Testing h5jam
+#-------------------------------
+# help page
+TOOLTEST_OUTPUT JAM h5jam-help.txt 0 -h
+
+# don't allow HDF5 format file as an user block file
+TOOLTEST_OUTPUT JAM h5jam-ub-nohdf5.txt 1 -i tall.h5 -u tall.h5 -o tall-tmp.h5
+
+JAMTEST $TESTDIR/u10.txt $TESTDIR/tall.h5 ta2.h5
+CHECKFILE $TESTDIR/tall.h5 ta2.h5
+CLEANUP ta2.h5
+JAMTEST $TESTDIR/u511.txt $TESTDIR/tall.h5 ta3.h5
+CHECKFILE $TESTDIR/tall.h5 ta3.h5
+CLEANUP ta3.h5
+JAMTEST $TESTDIR/u512.txt $TESTDIR/tall.h5 ta4.h5
+CHECKFILE $TESTDIR/tall.h5 ta4.h5
+CLEANUP ta4.h5
+JAMTEST $TESTDIR/u513.txt $TESTDIR/tall.h5 ta5.h5
+CHECKFILE $TESTDIR/tall.h5 ta5.h5
+CLEANUP ta5.h5
+
+SETUP $TESTDIR/tall.h5 ta6.h5
+JAMTEST $TESTDIR/u10.txt ta6.h5
+CHECKFILE $TESTDIR/tall.h5 ta6.h5
+CLEANUP ta6.h5
+SETUP $TESTDIR/tall.h5 ta7.h5
+JAMTEST $TESTDIR/u511.txt ta7.h5
+CHECKFILE $TESTDIR/tall.h5 ta7.h5
+CLEANUP ta7.h5
+SETUP $TESTDIR/tall.h5 ta8.h5
+JAMTEST $TESTDIR/u512.txt ta8.h5
+CHECKFILE $TESTDIR/tall.h5 ta8.h5
+CLEANUP ta8.h5
+SETUP $TESTDIR/tall.h5 ta9.h5
+JAMTEST $TESTDIR/u513.txt ta9.h5
+CHECKFILE $TESTDIR/tall.h5 ta9.h5
+CLEANUP ta9.h5
+
+JAMTEST $TESTDIR/u10.txt $TESTDIR/twithub.h5 tax2.h5
+CHECKFILE $TESTDIR/tall.h5 tax2.h5
+CLEANUP tax2.h5
+JAMTEST $TESTDIR/u511.txt $TESTDIR/twithub.h5 tax3.h5
+CHECKFILE $TESTDIR/tall.h5 tax3.h5
+CLEANUP tax3.h5
+JAMTEST $TESTDIR/u512.txt $TESTDIR/twithub.h5 tax4.h5
+CHECKFILE $TESTDIR/tall.h5 tax4.h5
+CLEANUP tax4.h5
+JAMTEST $TESTDIR/u513.txt $TESTDIR/twithub.h5 tax5.h5
+CHECKFILE $TESTDIR/tall.h5 tax5.h5
+CLEANUP tax5.h5
+
+JAMTEST $TESTDIR/u10.txt $TESTDIR/twithub513.h5 tax6.h5
+CHECKFILE $TESTDIR/tall.h5 tax6.h5
+CLEANUP tax6.h5
+JAMTEST $TESTDIR/u511.txt $TESTDIR/twithub513.h5 tax7.h5
+CHECKFILE $TESTDIR/tall.h5 tax7.h5
+CLEANUP tax7.h5
+JAMTEST $TESTDIR/u512.txt $TESTDIR/twithub513.h5 tax8.h5
+CHECKFILE $TESTDIR/tall.h5 tax8.h5
+CLEANUP tax8.h5
+JAMTEST $TESTDIR/u513.txt $TESTDIR/twithub513.h5 tax9.h5
+CHECKFILE $TESTDIR/tall.h5 tax9.h5
+CLEANUP tax9.h5
+
+JAMTEST $TESTDIR/u10.txt $TESTDIR/twithub.h5 --clobber taz2.h5
+CHECKFILE $TESTDIR/tall.h5 taz2.h5
+CLEANUP taz2.h5
+JAMTEST $TESTDIR/u511.txt $TESTDIR/twithub.h5 --clobber taz3.h5
+CHECKFILE $TESTDIR/tall.h5 taz3.h5
+CLEANUP taz3.h5
+JAMTEST $TESTDIR/u512.txt $TESTDIR/twithub.h5 --clobber taz4.h5
+CHECKFILE $TESTDIR/tall.h5 taz4.h5
+CLEANUP taz4.h5
+JAMTEST $TESTDIR/u513.txt $TESTDIR/twithub.h5 --clobber taz5.h5
+CHECKFILE $TESTDIR/tall.h5 taz5.h5
+CLEANUP taz5.h5
+
+JAMTEST $TESTDIR/u10.txt $TESTDIR/twithub513.h5 --clobber taz6.h5
+CHECKFILE $TESTDIR/tall.h5 taz6.h5
+CLEANUP taz6.h5
+JAMTEST $TESTDIR/u511.txt $TESTDIR/twithub513.h5 --clobber taz7.h5
+CHECKFILE $TESTDIR/tall.h5 taz7.h5
+CLEANUP taz7.h5
+JAMTEST $TESTDIR/u512.txt $TESTDIR/twithub513.h5 --clobber taz8.h5
+CHECKFILE $TESTDIR/tall.h5 taz8.h5
+CLEANUP taz8.h5
+JAMTEST $TESTDIR/u513.txt $TESTDIR/twithub513.h5 --clobber taz9.h5
+CHECKFILE $TESTDIR/tall.h5 taz9.h5
+CLEANUP taz9.h5
+
+SETUP $TESTDIR/twithub.h5 tay2.h5
+JAMTEST $TESTDIR/u10.txt tay2.h5 --clobber
+CHECKFILE $TESTDIR/tall.h5 tay2.h5
+CLEANUP tay2.h5
+SETUP $TESTDIR/twithub.h5 tay3.h5
+JAMTEST $TESTDIR/u511.txt tay3.h5 --clobber
+CHECKFILE $TESTDIR/tall.h5 tay3.h5
+CLEANUP tay3.h5
+SETUP $TESTDIR/twithub.h5 tay4.h5
+JAMTEST $TESTDIR/u512.txt tay4.h5 --clobber
+CHECKFILE $TESTDIR/tall.h5 tay4.h5
+CLEANUP tay4.h5
+SETUP $TESTDIR/twithub.h5 tay5.h5
+JAMTEST $TESTDIR/u513.txt tay5.h5 --clobber
+CHECKFILE $TESTDIR/tall.h5 tay5.h5
+CLEANUP tay5.h5
+
+SETUP $TESTDIR/twithub513.h5 tay6.h5
+JAMTEST $TESTDIR/u10.txt tay6.h5 --clobber
+CHECKFILE $TESTDIR/tall.h5 tay6.h5
+CLEANUP tay6.h5
+SETUP $TESTDIR/twithub513.h5 tay7.h5
+JAMTEST $TESTDIR/u511.txt tay7.h5 --clobber
+CHECKFILE $TESTDIR/tall.h5 tay7.h5
+CLEANUP tay7.h5
+SETUP $TESTDIR/twithub513.h5 tay8.h5
+JAMTEST $TESTDIR/u512.txt tay8.h5 --clobber
+CHECKFILE $TESTDIR/tall.h5 tay8.h5
+CLEANUP tay8.h5
+SETUP $TESTDIR/twithub513.h5 tay9.h5
+JAMTEST $TESTDIR/u513.txt tay9.h5 --clobber
+CHECKFILE $TESTDIR/tall.h5 tay9.h5
+CLEANUP tay9.h5
+
+#---------------------------------
+# Testing h5unjam
+#---------------------------------
+# help page
+TOOLTEST_OUTPUT UNJAM h5unjam-help.txt 0 -h
+
+SETUP $TESTDIR/twithub.h5 tai1.h5
+UNJAMTEST tai1.h5 o10.txt taa1.h5
+CHECKFILE $TESTDIR/tall.h5 taa1.h5
+CLEANUP taa1.h5 tai1.h5 o10.txt
+SETUP $TESTDIR/twithub513.h5 tai2.h5
+UNJAMTEST tai2.h5 o512.txt taa2.h5
+CHECKFILE $TESTDIR/tall.h5 taa2.h5
+CLEANUP taa2.h5 tai2.h5 o512.txt
+
+SETUP $TESTDIR/twithub.h5 tai3.h5
+UNJAMTEST tai3.h5 - taa3.h5
+CHECKFILE $TESTDIR/tall.h5 taa3.h5
+CLEANUP taa3.h5 tai3.h5
+SETUP $TESTDIR/twithub513.h5 tai4.h5
+UNJAMTEST tai4.h5 - taa4.h5
+CHECKFILE $TESTDIR/tall.h5 taa4.h5
+CLEANUP taa4.h5 tai4.h5
+
+SETUP $TESTDIR/twithub.h5 taj2.h5
+UNJAMTEST taj2.h5 --delete tac2.h5
+CHECKFILE $TESTDIR/tall.h5 tac2.h5
+CLEANUP tac2.h5 taj2.h5
+SETUP $TESTDIR/twithub513.h5 taj3.h5
+UNJAMTEST taj3.h5 --delete tac3.h5
+CHECKFILE $TESTDIR/tall.h5 tac3.h5
+CLEANUP tac3.h5 taj3.h5
+
+# Clean up temporary files/directories
+CLEAN_TESTFILES_AND_TESTDIR
+
+if test $nerrors -eq 0 ; then
+ echo "All $TESTNAME tests passed."
+ exit $EXIT_SUCCESS
+else
+ echo "$TESTNAME tests failed with $nerrors errors."
+ exit $EXIT_FAILURE
+fi