Hi Ted,
On 2016-06-30 14:37, TS wrote:
> [snip]
> Is it possible to have a ctest which involves preprocessing as well as
> postprocessing. The code to test is myCode.exe, which writes an output file.
> PASS or FAIL is the result of comparison of output against reference data.
AFAIK, there is currently no direct language support for this in
cmake/ctest. However, you can achieve the desired result by using a
custom script which does the preprocessing, the target execution, and
the postprocessing.
I attached you an example for such a "wrapper" cmake script, which I
once used for direct file comparison. I presume that your comparison is
slightly different but it should get you started. The `add_test` looks
then something like that:
```
add_test(NAME test
COMMAND ${CMAKE_COMMAND}
-D "PROGRAM:STRING=$<TARGET_FILE:target>;infile;outfile"
-D "PRE_DELETE_OUTPUT_FILES:BOOL=true"
-D "REFERENCE_FILES:STRING=reffile"
-D "OUTPUT_FILES:STRING=outfile"
-P "${CMAKE_SOURCE_DIR}/path-to-script/run_and_compare.cmake" )
```
> [snip]
> but because rm is not build by cmake, it complains that cannot find it.
>
>
Kind of unrelated to your original question but you can use either
`file(REMOVE ...)` within a cmake script, or call `cmake -E remove ...`
to delete files in a platform independent way.
Regards,
Mario
# Executes a program and compares result files
#
# The following variables have to be defined to run this script:
# PROGRAM.............................The program and the parameters which should be executed
# PRE_DELETE_OUTPUT_FILES.............Delete the output files before executing the program
# OUTPUT_FILES........................List of output files
# REFERENCE_FILES.....................List of reference files
#
# Example for adding a target using this script:
# ADD_CUSTOM_TARGET( coverage COMMAND "${CMAKE_COMMAND}"
# -D "PROGRAM:STRING=${PROGRAM}"
# -D "OUTPUT_FILES:STRING=${OUTPUT_FILES}"
# -D "REFERENCE_FILES:STRING=${REFERENCE_FILES}"
# -P "${PROJECT_SOURCE_DIR}/cmake/scripts/run_and_compare.cmake" )
IF(NOT PROGRAM OR NOT OUTPUT_FILES OR NOT REFERENCE_FILES)
MESSAGE(STATUS "The following variables have to be defined (-D) to run this script:")
MESSAGE(STATUS " PROGRAM.............................The program and the parameters which should be executed")
MESSAGE(STATUS " OUTPUT_FILES........................List of output files")
MESSAGE(STATUS " REFERENCE_FILES.....................List of reference files")
MESSAGE(SEND_ERROR "Invalid/insufficient parameters specified!")
ENDIF()
# validate that there are as many reference as output files
LIST(LENGTH OUTPUT_FILES OUTPUT_FILES_LENGTH)
LIST(LENGTH REFERENCE_FILES REFERENCE_FILES_LENGTH)
IF( NOT OUTPUT_FILES_LENGTH EQUAL REFERENCE_FILES_LENGTH )
MESSAGE(SEND_ERROR "Output file count does not match reference file count!")
ENDIF()
IF( PRE_DELETE_OUTPUT_FILES )
FOREACH(OUT_FILE ${OUTPUT_FILES})
MESSAGE(STATUS "Deleting \"${OUT_FILE}\" before starting program")
FILE(REMOVE ${OUT_FILE})
ENDFOREACH()
ENDIF()
# execute the program
MESSAGE(STATUS "Executing \"${PROGRAM}\"" )
EXECUTE_PROCESS(COMMAND ${PROGRAM}
RESULT_VARIABLE error)
# compare all result files
FOREACH(i RANGE 1 ${OUTPUT_FILES_LENGTH})
MATH(EXPR idx "${i}-1")
LIST(GET OUTPUT_FILES ${idx} OUT_FILE)
LIST(GET REFERENCE_FILES ${idx} REF_FILE)
MESSAGE(STATUS "Comparing \"${OUT_FILE}\" with \"${REF_FILE}\"")
EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E compare_files ${REF_FILE} ${OUT_FILE}
RESULT_VARIABLE result)
# capture the first error
IF(NOT error AND result )
SET(error ${result})
ENDIF()
ENDFOREACH()
IF(error)
MESSAGE(SEND_ERROR "Terminated with non-zero error code.")
ENDIF()
--
Powered by www.kitware.com
Please keep messages on-topic and check the CMake FAQ at:
http://www.cmake.org/Wiki/CMake_FAQ
Kitware offers various services to support the CMake community. For more
information on each offering, please visit:
CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake