From f7212df0300f0d776b328fda05ef99947db59c0a Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Mon, 24 Feb 2020 12:45:22 -0600 Subject: HDFFV-11036 add file compare test process --- MANIFEST | 1 + config/cmake/fileCompareTest.cmake | 104 +++++++++++++++++++++++++++++++++++ config/cmake/userblockTest.cmake | 10 ++-- tools/test/h5repack/CMakeTests.cmake | 60 +++++++++++++++++--- 4 files changed, 162 insertions(+), 13 deletions(-) create mode 100644 config/cmake/fileCompareTest.cmake diff --git a/MANIFEST b/MANIFEST index 35d21ce..e746731 100644 --- a/MANIFEST +++ b/MANIFEST @@ -3348,6 +3348,7 @@ ./config/cmake/ConfigureChecks.cmake ./config/cmake/CPack.Info.plist.in ./config/cmake/CTestCustom.cmake +./config/cmake/fileCompareTest.cmake ./config/cmake/FindHDFS.cmake ./config/cmake/H5cxx_config.h.in ./config/cmake/H5pubconf.h.in diff --git a/config/cmake/fileCompareTest.cmake b/config/cmake/fileCompareTest.cmake new file mode 100644 index 0000000..d913da0 --- /dev/null +++ b/config/cmake/fileCompareTest.cmake @@ -0,0 +1,104 @@ +# +# 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 COPYING file, which can be found at the root of the source code +# distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. +# If you do not have access to either file, you may request a copy from +# help@hdfgroup.org. +# +# fileCompareTest.cmake compares two files. + +# arguments checking +if (NOT TEST_FOLDER) + message (FATAL_ERROR "Require TEST_FOLDER to be defined") +endif () +if (NOT TEST_ONEFILE) + message (FATAL_ERROR "Require TEST_ONEFILE the first file to be defined") +endif () +if (NOT TEST_TWOFILE) + message (FATAL_ERROR "Require TEST_TWOFILE the second file to be defined") +endif () +if (NOT TEST_FUNCTION) + message (FATAL_ERROR "Require TEST_FUNCTION (LT,LTEQ,EQ,GTEQ,GT) to be defined") +endif () +#if (NOT TEST_EXPECT) +# message (STATUS "Require TEST_EXPECT to be defined") +#endif () + +set (TEST_ONE_SIZE 0) +set (TEST_TWO_SIZE 0) +set (TEST_ONE_STRING 0) +set (TEST_TWO_STRING 0) +set (TEST_ONE_STRING_LEN 0) +set (TEST_TWO_STRING_LEN 0) + +if (TEST_STRINGS STREQUAL "YES") + # find the length of the first file + #s1=`cat $ufile | wc -c | sed -e 's/ //g'` + file (STRINGS ${TEST_FOLDER}/${TEST_ONEFILE} TEST_ONE_STRING) + string (LENGTH ${TEST_ONE_STRING} TEST_ONE_STRING_LEN) + + # Get the size of the second file. + file (STRINGS ${TEST_FOLDER}/${TEST_TWOFILE} TEST_TWO_STRING) + string (LENGTH ${TEST_TWO_STRING} TEST_TWO_STRING_LEN) + + math (EXPR TEST_STRING_SIZE "${TEST_ONE_STRING_LEN} - ${TEST_TWO_STRING_LEN}" ) + + # now compare the outputs + execute_process ( + COMMAND ${CMAKE_COMMAND} -E compare_files ${CMAKE_IGNORE_EOL} ${TEST_FOLDER}/${TEST_ONEFILE} ${TEST_FOLDER}/${TEST_TWOFILE} + RESULT_VARIABLE TEST_RESULT + ) + + message (STATUS "COMPARE Result: ${TEST_RESULT}: ${TEST_STRING_SIZE}=${TEST_U_STRING_LEN}-${TEST_O_STRING_LEN}") + # if the return value is !=${TEST_EXPECT} bail out + if (NOT TEST_RESULT EQUAL TEST_EXPECT) + message (FATAL_ERROR "Failed: The output of ${TEST_FOLDER}/${TEST_ONEFILE} did not match ${TEST_FOLDER}/${TEST_TWOFILE}.\n${TEST_ERROR}") + endif () +else () + if (CMAKE_VERSION VERSION_LESS "3.14.0") + message (FATAL_ERROR "CANNOT get file size, file command SIZE not supported") + else () + file (SIZE ${TEST_FOLDER}/${TEST_ONEFILE} TEST_ONE_SIZE) + file (SIZE ${TEST_FOLDER}/${TEST_TWOFILE} TEST_TWO_SIZE) + if (TEST_FUNCTION MATCHES "LT") + if (TEST_ONE_SIZE LESS TEST_TWO_SIZE) + message (STATUS "Passed: The size of ${TEST_FOLDER}/${TEST_ONEFILE} was less ${TEST_FOLDER}/${TEST_TWOFILE}") + else () + message (FATAL_ERROR "The size of ${TEST_FOLDER}/${TEST_ONEFILE} was NOT less ${TEST_FOLDER}/${TEST_TWOFILE}") + endif () + elseif (TEST_FUNCTION MATCHES "LTEQ") + if (TEST_ONE_SIZE LESS_EQUAL TEST_TWO_SIZE) + message (STATUS "Passed: The size of ${TEST_FOLDER}/${TEST_ONEFILE} was less or equal ${TEST_FOLDER}/${TEST_TWOFILE}") + else () + message (FATAL_ERROR "The size of ${TEST_FOLDER}/${TEST_ONEFILE} was NOT less or equal ${TEST_FOLDER}/${TEST_TWOFILE}") + endif () + elseif (TEST_FUNCTION MATCHES "EQ") + if (TEST_ONE_SIZE LESS_EQUAL TEST_TWO_SIZE) + message (STATUS "Passed: The size of ${TEST_FOLDER}/${TEST_ONEFILE} was equal ${TEST_FOLDER}/${TEST_TWOFILE}") + else () + message (FATAL_ERROR "The size of ${TEST_FOLDER}/${TEST_ONEFILE} was NOT equal ${TEST_FOLDER}/${TEST_TWOFILE}") + endif () + elseif (TEST_FUNCTION MATCHES "GTEQ") + if (TEST_ONE_SIZE LESS_EQUAL TEST_TWO_SIZE) + message (STATUS "Passed: The size of ${TEST_FOLDER}/${TEST_ONEFILE} was greater or equal ${TEST_FOLDER}/${TEST_TWOFILE}") + else () + message (FATAL_ERROR "The size of ${TEST_FOLDER}/${TEST_ONEFILE} was NOT greater or equal ${TEST_FOLDER}/${TEST_TWOFILE}") + endif () + elseif (TEST_FUNCTION MATCHES "GT") + if (TEST_ONE_SIZE LESS_EQUAL TEST_TWO_SIZE) + message (STATUS "Passed: The size of ${TEST_FOLDER}/${TEST_ONEFILE} was greater ${TEST_FOLDER}/${TEST_TWOFILE}") + else () + message (FATAL_ERROR "The size of ${TEST_FOLDER}/${TEST_ONEFILE} was NOT greater ${TEST_FOLDER}/${TEST_TWOFILE}") + endif () + else () + message (FATAL_ERROR "Failed: Incorrect test size compare command provided.\n${TEST_ERROR}") + endif () + endif () +endif () + +# everything went fine... + diff --git a/config/cmake/userblockTest.cmake b/config/cmake/userblockTest.cmake index d3806f1..c02669d 100644 --- a/config/cmake/userblockTest.cmake +++ b/config/cmake/userblockTest.cmake @@ -54,7 +54,7 @@ if (TEST_CHECKUB STREQUAL "YES") # 'tellub' calls H5Fget_user_block to get the size # of the user block #s2=`$JAM_BIN/tellub $origfile` - EXECUTE_PROCESS ( + execute_process ( COMMAND ${TEST_EMULATOR} ${TEST_PROGRAM} ${TEST_OFILE} WORKING_DIRECTORY ${TEST_FOLDER} RESULT_VARIABLE TEST_RESULT @@ -72,7 +72,7 @@ if (TEST_CHECKUB STREQUAL "YES") if (TEST_O_STRING_LEN) #$JAM_BIN/getub -c $s2 $origfile > $cmpfile - EXECUTE_PROCESS ( + execute_process ( COMMAND ${TEST_EMULATOR} ${TEST_GET_PROGRAM} -c ${TEST_O_STRING_LEN} ${TEST_OFILE} WORKING_DIRECTORY ${TEST_FOLDER} RESULT_VARIABLE TEST_RESULT @@ -90,7 +90,7 @@ if (TEST_CHECKUB STREQUAL "YES") endif () #$JAM_BIN/getub -c $size $hfile > $tfile - EXECUTE_PROCESS ( + execute_process ( COMMAND ${TEST_EMULATOR} ${TEST_GET_PROGRAM} -c ${TEST_STRING_SIZE} ${TEST_HFILE} WORKING_DIRECTORY ${TEST_FOLDER} RESULT_VARIABLE TEST_RESULT @@ -101,7 +101,7 @@ if (TEST_CHECKUB STREQUAL "YES") ) # now compare the outputs - EXECUTE_PROCESS ( + execute_process ( COMMAND ${CMAKE_COMMAND} -E compare_files ${CMAKE_IGNORE_EOL} ${TEST_HFILE}-ub.cmp ${TEST_HFILE}.cmp RESULT_VARIABLE TEST_RESULT ) @@ -114,7 +114,7 @@ if (TEST_CHECKUB STREQUAL "YES") else () # call 'ubsize' to get the size of the user block #ubsize=`$JAM_BIN/tellub $hfile` - EXECUTE_PROCESS ( + execute_process ( COMMAND ${TEST_EMULATOR} ${TEST_PROGRAM} ${TEST_HFILE} WORKING_DIRECTORY ${TEST_FOLDER} RESULT_VARIABLE TEST_H_STRING_LEN diff --git a/tools/test/h5repack/CMakeTests.cmake b/tools/test/h5repack/CMakeTests.cmake index e654bce..4823d07 100644 --- a/tools/test/h5repack/CMakeTests.cmake +++ b/tools/test/h5repack/CMakeTests.cmake @@ -638,12 +638,16 @@ macro (ADD_H5_TEST_META testname testfile) # Remove any output file left over from previous test run add_test ( - NAME H5REPACK_META-${testname}_N-clear-objects + NAME H5REPACK_META-${testname}-clear-objects COMMAND ${CMAKE_COMMAND} -E remove testfiles/out-${testname}_N.${testname}.h5 + testfiles/out-${testname}_N.${testname}.out + testfiles/out-${testname}_N.${testname}.out.err testfiles/out-${testname}_M.${testname}.h5 + testfiles/out-${testname}_M.${testname}.out + testfiles/out-${testname}_M.${testname}.out.err ) - set_tests_properties (H5REPACK_META-${testname}_N-clear-objects PROPERTIES + set_tests_properties (H5REPACK_META-${testname}-clear-objects PROPERTIES FIXTURES_REQUIRED clear_h5repack ) add_test ( @@ -651,21 +655,61 @@ COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $ ${PROJECT_BINARY_DIR}/testfiles/${testfile} ${PROJECT_BINARY_DIR}/testfiles/out-${testname}_N.${testname}.h5 ) set_tests_properties (H5REPACK_META-${testname}_N PROPERTIES - DEPENDS H5REPACK_META-${testname}_N-clear-objects + DEPENDS H5REPACK_META-${testname}-clear-objects + ) + add_test ( + NAME H5REPACK_META-${testname}_N_DFF + COMMAND "${CMAKE_COMMAND}" + -D "TEST_EMULATOR=${CMAKE_CROSSCOMPILING_EMULATOR}" + -D "TEST_PROGRAM=$" + -D "TEST_ARGS:STRING=-v;${testfile};out-${testname}_N.${testname}.h5" + -D "TEST_FOLDER=${PROJECT_BINARY_DIR}/testfiles" + -D "TEST_OUTPUT=out-${testname}_N.${testname}.out" + -D "TEST_EXPECT=0" + -D "TEST_REFERENCE=out-${testname}_N.${testname}.txt" + -P "${HDF_RESOURCES_EXT_DIR}/runTest.cmake" + ) + set_tests_properties (H5REPACK_META-${testname}_N_DFF PROPERTIES + DEPENDS H5REPACK_META-${testname}_N ) add_test ( NAME H5REPACK_META-${testname}_M COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $ ${ARGN} ${PROJECT_BINARY_DIR}/testfiles/${testfile} ${PROJECT_BINARY_DIR}/testfiles/out-${testname}_M.${testname}.h5 ) set_tests_properties (H5REPACK_META-${testname}_M PROPERTIES - DEPENDS H5REPACK_META-${testname}_N + DEPENDS H5REPACK_META-${testname}_N_DFF ) - - add_test (NAME H5REPACK_META-${testname} COMMAND ${CMAKE_COMMAND} -E compare_files ${CMAKE_IGNORE_EOL} ${PROJECT_BINARY_DIR}/testfiles/out-${testname}_N.${testname}.h5 ${PROJECT_BINARY_DIR}/testfiles/out-${testname}_M.${testname}.h5) - set_tests_properties (H5REPACK_META-${testname} PROPERTIES - WILL_FAIL "true" + add_test ( + NAME H5REPACK_META-${testname}_M_DFF + COMMAND "${CMAKE_COMMAND}" + -D "TEST_EMULATOR=${CMAKE_CROSSCOMPILING_EMULATOR}" + -D "TEST_PROGRAM=$" + -D "TEST_ARGS:STRING=-v;${testfile};out-${testname}_M.${testname}.h5" + -D "TEST_FOLDER=${PROJECT_BINARY_DIR}/testfiles" + -D "TEST_OUTPUT=out-${testname}_M.${testname}.out" + -D "TEST_EXPECT=0" + -D "TEST_REFERENCE=out-${testname}_M.${testname}.txt" + -P "${HDF_RESOURCES_EXT_DIR}/runTest.cmake" + ) + set_tests_properties (H5REPACK_META-${testname}_M_DFF PROPERTIES DEPENDS H5REPACK_META-${testname}_M ) + add_test (NAME H5REPACK_META-${testname} + COMMAND "${CMAKE_COMMAND}" + -D "TEST_FOLDER=${PROJECT_BINARY_DIR}/testfiles" + -D "TEST_ONEFILE=out-${testname}_N.${testname}.out" + -D "TEST_TWOFILE=out-${testname}_M.${testname}.h5" + -D "TEST_FUNCTION=LTEQ" + -P "${HDF_RESOURCES_DIR}/fileCompareTest.cmake" + ) + if (CMAKE_VERSION VERSION_LESS "3.14.0") + set_tests_properties (H5REPACK_META-${testname} PROPERTIES + DISABLED "true" + ) + endif () + set_tests_properties (H5REPACK_META-${testname} PROPERTIES + DEPENDS H5REPACK_META-${testname}_M_DFF + ) endmacro () macro (ADD_H5_UD_TEST testname resultcode resultfile) -- cgit v0.12