Debian Codegraph @

Modules/ThirdParty/HDF5/src/itkhdf5/config/cmake/vfdTest.cmake

raw
1 #
2 # Copyright by The HDF Group.
3 # All rights reserved.
4 #
5 # This file is part of HDF5. The full HDF5 copyright notice, including
6 # terms governing use, modification, and redistribution, is contained in
7 # the COPYING file, which can be found at the root of the source code
8 # distribution tree, or in https://www.hdfgroup.org/licenses.
9 # If you do not have access to either file, you may request a copy from
10 # [email protected].
11 #
12 # vfdTest.cmake executes a command and captures the output in a file. Command uses specified VFD.
13 # Exit status of command can also be compared.
14
15 # arguments checking
16 if (NOT TEST_PROGRAM)
17 message (FATAL_ERROR "Require TEST_PROGRAM to be defined")
18 endif ()
19 if (NOT TEST_FOLDER)
20 message (FATAL_ERROR "Require TEST_FOLDER to be defined")
21 endif ()
22 if (NOT TEST_VFD)
23 message (FATAL_ERROR "Require TEST_VFD to be defined")
24 endif ()
25
26 if (EXISTS "${TEST_FOLDER}/${TEST_OUTPUT}")
27 file (REMOVE ${TEST_FOLDER}/${TEST_OUTPUT})
28 endif ()
29
30 if (EXISTS "${TEST_FOLDER}/${TEST_OUTPUT}.err")
31 file (REMOVE ${TEST_FOLDER}/${TEST_OUTPUT}.err)
32 endif ()
33
34 # if there is not an error reference file add the error output to the stdout file
35 #if (NOT TEST_ERRREF)
36 # set (ERROR_APPEND 1)
37 #endif ()
38
39 message (STATUS "USING ${TEST_VFD} ON COMMAND: ${TEST_EMULATOR} ${TEST_PROGRAM} ${TEST_ARGS}")
40
41 set (ENV{HDF5_DRIVER} "${TEST_VFD}")
42
43 # run the test program, capture the stdout/stderr and the result var
44 execute_process (
45 COMMAND ${TEST_EMULATOR} ${TEST_PROGRAM} ${TEST_ARGS}
46 WORKING_DIRECTORY ${TEST_FOLDER}
47 RESULT_VARIABLE TEST_RESULT
48 OUTPUT_FILE ${TEST_OUTPUT}_${TEST_VFD}.out
49 ERROR_FILE ${TEST_OUTPUT}_${TEST_VFD}.err
50 OUTPUT_VARIABLE TEST_OUT
51 ERROR_VARIABLE TEST_ERROR
52 )
53
54 message (STATUS "COMMAND Result: ${TEST_RESULT}")
55
56 # if the .err file exists and ERRROR_APPEND is enabled
57 if (ERROR_APPEND AND EXISTS "${TEST_FOLDER}/${TEST_OUTPUT}_${TEST_VFD}.err")
58 file (READ ${TEST_FOLDER}/${TEST_OUTPUT}_${TEST_VFD}.err TEST_STREAM)
59 file (APPEND ${TEST_FOLDER}/${TEST_OUTPUT}_${TEST_VFD}.out "${TEST_STREAM}")
60 endif ()
61
62 # if the return value is !=${TEST_EXPECT} bail out
63 if (NOT TEST_RESULT EQUAL TEST_EXPECT)
64 if (NOT TEST_NOERRDISPLAY)
65 if (EXISTS "${TEST_FOLDER}/${TEST_OUTPUT}_${TEST_VFD}.out")
66 file (READ ${TEST_FOLDER}/${TEST_OUTPUT}_${TEST_VFD}.out TEST_STREAM)
67 message (STATUS "Output USING ${TEST_VFD}:\n${TEST_STREAM}")
68 endif ()
69 endif ()
70 message (FATAL_ERROR "Failed: Test program ${TEST_PROGRAM} exited != ${TEST_EXPECT}.\n${TEST_ERROR}")
71 endif ()
72
73 message (STATUS "COMMAND Error: ${TEST_ERROR}")
74
75 # everything went fine...
76 message (STATUS "Passed: The ${TEST_PROGRAM} program used vfd ${TEST_VFD}")