File: AddTestsPython.cmake

package info (click to toggle)
xdmf 3.0%2Bgit20160803-3
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 35,388 kB
  • ctags: 36,627
  • sloc: ansic: 265,382; cpp: 162,889; python: 10,976; f90: 1,378; yacc: 687; fortran: 464; xml: 200; java: 187; lex: 125; makefile: 82; sh: 28
file content (247 lines) | stat: -rw-r--r-- 8,197 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
INCLUDE(TestingSetup)

# Variables that are set externally
SET(python_binary_dir ${CMAKE_CURRENT_BINARY_DIR})
SET(python_source_dir ${CMAKE_CURRENT_SOURCE_DIR})

# Python Add Dependencies Macro
# Author: Brian Panneton
# Description: This macro adds the python test dependencies.
#        Note: The tests already depend on their own file
# Parameters:         
#              dependencies         = any dependencies needed for python tests
MACRO(ADD_TEST_PYTHON_DEPENDENCIES dependencies)
	IF(NOT ("${dependencies}" STREQUAL ""))
	        SET_PROPERTY(GLOBAL APPEND PROPERTY PYTHON_TEST_DEPENDENCIES 
        	        "${dependencies}"
	        )
	ENDIF()
ENDMACRO()

# Python Add Dependencies Macro
# Author: Brian Panneton
# Description: This macro adds the python test dependencies.
#        Note: The tests already depend on their own file
# Parameters:         
#              dependencies         = any dependencies needed for python tests
MACRO(ADD_TEST_PYTHON_FILE_DEPENDENCIES dependencies)
	IF(NOT ("${dependencies}" STREQUAL ""))
	        SET_PROPERTY(GLOBAL APPEND PROPERTY PYTHON_TEST_FILE_DEPENDENCIES 
        	        "${dependencies}"
	        )
	ENDIF()
ENDMACRO()

# Python Add PythonPath Macro
# Author: Brian Panneton
# Description: This macro adds the python test pythonpaths.
# Parameters:         
#              pyp         = any pythonpaths needed for python tests
MACRO(ADD_TEST_PYTHON_PYTHONPATH pyp)
        GET_PROPERTY(pythonpath GLOBAL PROPERTY PYTHON_TEST_PYTHONPATH)
        IF(NOT ("${pyp}" STREQUAL ""))
                SET_PROPERTY(GLOBAL PROPERTY PYTHON_TEST_PYTHONPATH 
                        "${pythonpath}${sep}${pyp}" 
                )
        ENDIF()
ENDMACRO()

# Python Add LDPath  Macro
# Author: Brian Panneton
# Description: This macro adds the python test ldpaths.
# Parameters:         
#               ld  = any ldpaths needed for python tests
MACRO(ADD_TEST_PYTHON_LDPATH ld)
    GET_PROPERTY(ldpath GLOBAL PROPERTY PYTHON_TEST_LDPATH)
    IF("${ld}" STRGREATER "")
        SET_PROPERTY(GLOBAL PROPERTY PYTHON_TEST_LDPATH 
                "${ldpath}${sep}${ld}" 
        )
    ENDIF()
ENDMACRO()

# Python Add Path Macro
# Author: Brian Panneton
# Description: This macro adds the python test paths.
# Parameters:         
#               p = any paths needed for python tests
MACRO(ADD_TEST_PYTHON_PATH p)
    GET_PROPERTY(path GLOBAL PROPERTY PYTHON_TEST_PATH)
    IF("${p}" STRGREATER "")
        SET_PROPERTY(GLOBAL PROPERTY PYTHON_TEST_PATH 
                "${path}${sep}${p}" 
        )
    ENDIF()
ENDMACRO()

# Add Python Test Macro
# Author: Brian Panneton
# Description:	This macro compiles and adds the python test in one shot. There is
#		no need to build a test separately, because there isn't a case 
#		that you don't want to run it.
# Parameters: 
#		executable 	= executable name 
#		${ARGN}		= any arguments for the executable
#
MACRO(ADD_TEST_PYTHON executable)
	
	PARSE_TEST_ARGS("${ARGN}")

	GET_PROPERTY(python_file_dependencies GLOBAL 
			PROPERTY PYTHON_TEST_FILE_DEPENDENCIES)
	GET_PROPERTY(python_pythonpath GLOBAL PROPERTY PYTHON_TEST_PYTHONPATH)
    GET_PROPERTY(python_ldpath GLOBAL PROPERTY PYTHON_TEST_LDPATH)
    GET_PROPERTY(python_path GLOBAL PROPERTY PYTHON_TEST_PATH)
	
	ADD_CUSTOM_COMMAND(
		OUTPUT ${python_binary_dir}/${executable}.pyc
		WORKING_DIRECTORY ${python_binary_dir} 
		COMMAND ${CMAKE_COMMAND}
		ARGS 	-E copy
			${python_source_dir}/${executable}.py
			${python_binary_dir}/${executable}.py
		COMMAND ${PYTHON_EXECUTABLE} 
		ARGS	-mpy_compile
			${python_binary_dir}/${executable}.py
		DEPENDS ${python_source_dir}/${executable}.py
			${python_file_dependencies}
	)
	
	SET_PROPERTY(GLOBAL APPEND PROPERTY PYTHON_TEST_TARGETS "${python_binary_dir}/${executable}.pyc")

    # Dlls need to be in the path dir for java
    IF(WIN32)
        IF("${python_path}" STREQUAL "")
            SET(python_path ${java_ldpath})
        ENDIF()
    ENDIF()

	SET_CORE("${python_binary_dir}")
    ADD_TEST(Python${is_core}_${executable}${dup} ${CMAKE_COMMAND}
            -D "EXECUTABLE=${executable}"
            -D "ARGUMENTS=${arguments}"
            -D "PYTHONPATH=${python_pythonpath}"
            -D "LDPATH=${python_ldpath}"
            -D "PATH=${python_path}"
            -D "SEPARATOR=${sep}"
            -P "${python_binary_dir}/TestDriverPython.cmake"
    )
    IF(NOT "${tdep}" STREQUAL "")
        SET_TESTS_PROPERTIES(Python${is_core}_${executable}${dup}
            PROPERTIES DEPENDS ${tdep})
    ENDIF()

ENDMACRO()



# PYTHON MPI Test Macro
# Author: Andrew Burns
# Description: This macro builds and adds a script to execute MPI tests.
# Parameters:
#               executable      = script name
#               files           = code to be compiled and executed by the script
#               tdep            = test dependency (Full Test Name with Prefix)
#               ${ARGN}         = any arguments for the executable
MACRO(ADD_MPI_TEST_PYTHON script files)
    PARSE_TEST_ARGS("${ARGN}")

    GET_PROPERTY(python_file_dependencies GLOBAL
                 PROPERTY PYTHON_TEST_FILE_DEPENDENCIES)
    GET_PROPERTY(python_pythonpath GLOBAL PROPERTY PYTHON_TEST_PYTHONPATH)
    GET_PROPERTY(python_ldpath GLOBAL PROPERTY PYTHON_TEST_LDPATH)
    GET_PROPERTY(python_path GLOBAL PROPERTY PYTHON_TEST_PATH)

    IF(WIN32)
        IF("${python_path}" STREQUAL "")
            SET(python_path ${python_ldpath})
        ENDIF()
    ENDIF()

    set(tempfiles ${files})

    WHILE(NOT "${tempfiles}" STREQUAL "")
        # ${executable}
        STRING(REGEX MATCH "([^ ,])+,|([^ ,])+" executable "${tempfiles}")
        STRING(REGEX REPLACE "," "" executable "${executable}")
        STRING(REGEX REPLACE "${executable},|${executable}" "" trimmed "${tempfiles}")

        set(tempfiles ${trimmed})

        IF(EXISTS ${python_source_dir}/${executable}.py)
                file(COPY
                    ${python_source_dir}/${executable}.py
                    DESTINATION ${python_binary_dir}/
                )
        ENDIF()

    ENDWHILE()

    SET_CORE("${python_binary_dir}")
    ADD_TEST(Python${is_core}_${script} ${CMAKE_COMMAND}
            -D "EXECUTABLE='./${script}'"
            -D "ARGUMENTS=${arguments}"
            -D "PYTHONPATH=${python_pythonpath}"
            -D "LDPATH=${python_ldpath}"
            -D "PATH=${python_path}"
            -D "SEPARATOR=${sep}"
            -P "${python_binary_dir}/TestDriverPythonScript.cmake"
    )
    IF(NOT "${tdep}" STREQUAL "")
        SET_TESTS_PROPERTIES(Python${is_core}_${script}}
            PROPERTIES DEPENDS ${tdep})
    ENDIF()
    file(COPY
        ${python_source_dir}/${script}
        DESTINATION ${python_binary_dir}/
    )
ENDMACRO()




# Python Clean Macro
# Author: Brian Panneton
# Description: This macro sets up the python test for a make clean.
# Parameters:         
#              executable      = executable name
#              ${ARGN}         = files that the executable created
MACRO(CLEAN_TEST_PYTHON executable)
	set_property(DIRECTORY APPEND PROPERTY
		ADDITIONAL_MAKE_CLEAN_FILES ${ARGN}
		${executable}.py
	)
ENDMACRO()


# Python Create Target Macro
# Author: Brian Panneton
# Description: This macro sets up the python test target
# Parameters:	none
MACRO(CREATE_TARGET_TEST_PYTHON)
	IF(EXISTS PythonCore_ALLTEST)
        	SET(PythonCore_ALLTEST PythonCore_ALLTEST)
	ENDIF()

    GET_PROPERTY(python_dependencies GLOBAL PROPERTY PYTHON_TEST_DEPENDENCIES)	

	SET_CORE("${python_binary_dir}")
	GET_PROPERTY(targets GLOBAL PROPERTY PYTHON_TEST_TARGETS)
	ADD_CUSTOM_TARGET(Python${is_core}_ALLTEST ALL DEPENDS 
		${PythonCore_ALLTEST} ${targets})

    IF(NOT ("${python_dependencies}" STREQUAL ""))
        ADD_DEPENDENCIES(Python${is_core}_ALLTEST ${python_dependencies})
	ENDIF()

	IF(NOT ("${is_core}" STREQUAL ""))
		SET_PROPERTY(GLOBAL PROPERTY PYTHON_TEST_TARGETS "")
	ENDIF()

ENDMACRO()


# Configure the python 'driver' file
CONFIGURE_FILE(${TESTING_SUITE_DIR}/TestingSuite/TestDriverPython.cmake.in ${python_binary_dir}/TestDriverPython.cmake @ONLY)
CONFIGURE_FILE(${TESTING_SUITE_DIR}/TestingSuite/TestDriverPythonScript.cmake.in ${python_binary_dir}/TestDriverPythonScript.cmake @ONLY)