@@ -55,6 +55,55 @@ function(add_qml_test PATH COMPONENT_NAME)
55endfunction()
55endfunction()
58+# add_qml_test_data(path component_name
62+# Install file called ${component_name} (or ${component_name}.qml) under
65+function(add_qml_test_data PATH COMPONENT_NAME)
66+ cmake_parse_arguments(TEST "" "DESTINATION" "" ${ARGN})
68+ set(filename "${CMAKE_CURRENT_SOURCE_DIR}/${PATH}/${COMPONENT_NAME}")
70+ if (IS_DIRECTORY "${filename}")
71+ # As a convenience, allow specifying a directory and we will install
72+ # all files in the dir. We do it this way rather than passing
73+ # DIRECTORY to install() because we want to process any qml files.
74+ file(GLOB subfiles RELATIVE "${filename}" "${filename}/*")
75+ foreach(subfile ${subfiles})
76+ add_qml_test_data("${PATH}/${COMPONENT_NAME}" "${subfile}")
81+ if (NOT EXISTS "${filename}")
82+ set(filename "${filename}.qml")
83+ set(COMPONENT_NAME "${COMPONENT_NAME}.qml")
86+ if ("${filename}" MATCHES "\\.qml$")
87+ file(READ "${filename}" contents)
88+ string(REGEX REPLACE "(\"[./]*)/qml(/|\")" "\\1\\2" contents "${contents}")
89+ # this is for (at least) cardcreatortest which pulls in an architecture-specific
90+ # import into the plugins directory (which is a 'qml' once installed).
91+ string(REGEX REPLACE "(import \"[./]*)/plugins(/|\")" "\\1/qml\\2" contents "${contents}")
92+ set(filename "${CMAKE_CURRENT_BINARY_DIR}/${PATH}/${COMPONENT_NAME}")
93+ file(WRITE "${filename}" "${contents}")
96+ if (TEST_DESTINATION)
97+ set(DESTINATION "${TEST_DESTINATION}")
99+ file(RELATIVE_PATH relcurpath "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}")
100+ set(DESTINATION "${SHELL_APP_DIR}/${relcurpath}/${PATH}")
103+ install(FILES "${filename}" DESTINATION "${DESTINATION}")
58# add_qml_unittest(path component_name
107# add_qml_unittest(path component_name
@@ -71,6 +120,10 @@ function(add_qml_unittest PATH COMPONENT_NAME)
72 ARGS -input ${CMAKE_CURRENT_SOURCE_DIR}/${PATH}/tst_${COMPONENT_NAME}.qml ${QMLTEST_ARGS}
121 ARGS -input ${CMAKE_CURRENT_SOURCE_DIR}/${PATH}/tst_${COMPONENT_NAME}.qml ${QMLTEST_ARGS}
124+ if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${PATH}/tst_${COMPONENT_NAME}.qml")
125+ add_qml_test_data("${PATH}" "tst_${COMPONENT_NAME}.qml")
74endfunction()
127endfunction()
@@ -91,6 +144,10 @@ function(add_manual_qml_test PATH COMPONENT_NAME)
92 ARGS ${CMAKE_CURRENT_SOURCE_DIR}/${PATH}/tst_${COMPONENT_NAME}.qml ${QMLTEST_ARGS}
145 ARGS ${CMAKE_CURRENT_SOURCE_DIR}/${PATH}/tst_${COMPONENT_NAME}.qml ${QMLTEST_ARGS}
148+ if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${PATH}/tst_${COMPONENT_NAME}.qml")
149+ add_qml_test_data("${PATH}" "tst_${COMPONENT_NAME}.qml")
94endfunction()
151endfunction()
@@ -108,8 +165,7 @@ endfunction()
109# Logging options in the standard form of "-o filename,format"
166# Logging options in the standard form of "-o filename,format"
110# will be appended to the arguments list, prefixed with ARG_PREFIX.
167# will be appended to the arguments list, prefixed with ARG_PREFIX.
111−# XUnitXML files will be stored in current binary dir or under
168+# XUnitXML files will be stored in current binary dir.
112−# ARTIFACTS_DIR, if set.
114# Three targets will be created:
170# Three targets will be created:
115# - test${component_name} - Runs the test
171# - test${component_name} - Runs the test
@@ -122,14 +178,8 @@ function(add_executable_test COMPONENT_NAME TARGET)
122 cmake_parse_arguments(QMLTEST "${QMLTEST_OPTIONS}" "${QMLTEST_SINGLE}" "${QMLTEST_MULTI}" ${ARGN})
178 cmake_parse_arguments(QMLTEST "${QMLTEST_OPTIONS}" "${QMLTEST_SINGLE}" "${QMLTEST_MULTI}" ${ARGN})
123 mangle_arguments()
179 mangle_arguments()
125− if(ARTIFACTS_DIR)
181+ file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
126− file(RELATIVE_PATH path ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
127− file(MAKE_DIRECTORY ${ARTIFACTS_DIR}/${path})
128− set(file_logger -o ${ARTIFACTS_DIR}/${path}/test${COMPONENT_NAME}.xml,xunitxml)
130− file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
131− set(file_logger -o ${CMAKE_CURRENT_BINARY_DIR}/test${COMPONENT_NAME}.xml,xunitxml)
182+ set(file_logger -o ${CMAKE_CURRENT_BINARY_DIR}/test${COMPONENT_NAME}.xml,xunitxml)
134 bake_arguments("${QMLTEST_ARG_PREFIX}" args ${iterations} ${file_logger} ${STDOUT_LOGGER})
184 bake_arguments("${QMLTEST_ARG_PREFIX}" args ${iterations} ${file_logger} ${STDOUT_LOGGER})
@@ -207,8 +257,124 @@ function(add_manual_test COMPONENT_NAME TARGET)
207endfunction()
257endfunction()
260+# add_meta_test(target)
262+# Adds a test target that will run one of our "meta" test targets, like
263+# xvfbuitests. This script will run the specified suite of tests on an
266+function(add_meta_test TARGET_NAME)
267+ cmake_parse_arguments(TEST "" "" "DEPENDS" ${ARGN})
269+ add_custom_target(${TARGET_NAME})
271+ set(filename "${CMAKE_BINARY_DIR}/tests/scripts/${TARGET_NAME}.sh")
272+ file(WRITE "${filename}" "#!/usr/bin/parallel --shebang --no-notice\n\n")
274+ add_meta_dependencies(${TARGET_NAME} DEPENDS ${TEST_DEPENDS})
275+ # else we will write the rest of the script as we add cmake targets
277+ install(FILES "${filename}"
278+ PERMISSIONS OWNER_EXECUTE OWNER_READ OWNER_WRITE
279+ GROUP_EXECUTE GROUP_READ
280+ WORLD_EXECUTE WORLD_READ
281+ DESTINATION "${SHELL_PRIVATE_LIBDIR}/tests/scripts"
210################### INTERNAL ####################
286################### INTERNAL ####################
288+function(install_test_script TARGET_NAME)
289+ cmake_parse_arguments(TEST "" "" "COMMAND;ENVIRONMENT" ${ARGN})
291+ # Now write the above test into a shell script that we can run on an
293+ set(script "#!/bin/sh\n\nset -x\n\n")
294+ foreach(ONE_ENV ${TEST_ENVIRONMENT})
295+ set(script "${script}export ${ONE_ENV}\n")
297+ set(script "${script}export UNITY_TESTING_DATADIR=\"${CMAKE_INSTALL_PREFIX}/${SHELL_APP_DIR}\"\n")
298+ set(script "${script}export UNITY_TESTING_LIBDIR=\"${CMAKE_INSTALL_PREFIX}/${SHELL_PRIVATE_LIBDIR}\"\n")
299+ set(script "${script}\n")
300+ set(script "${script}XML_ARGS=\n")
301+ set(script "${script}if [ -n \"\$ARTIFACTS_DIR\" ]; then\n")
302+ set(script "${script} XML_ARGS=\"@XML_ARGS@\"\n")
303+ set(script "${script} mkdir -p \"@XML_DIR@\"\n")
304+ set(script "${script} touch \"@XML_FILE@\"\n")
305+ set(script "${script}fi\n")
306+ set(script "${script}\n")
307+ foreach(ONE_CMD ${TEST_COMMAND})
308+ set(script "${script}'${ONE_CMD}' ")
311+ set(filename "${CMAKE_BINARY_DIR}/tests/scripts/${TARGET_NAME}.sh")
313+ # Generate script to file then read it back to resolve any generator
314+ # expressions before we try to replace paths.
316+ OUTPUT "${filename}"
320+ # Do replacement at install time to save needless work and to make sure
321+ # we are modifying file after generate step above (which doesn't happen
322+ # immediately). We can't use a custom-defined function or macro here...
323+ # So instead we use a giant ugly code block.
325+ # START OF CODE BLOCK --------------------------------------------------
327+ file(READ \"${filename}\" replacestr)
329+ # Now some replacements...
330+ # tests like to write xml output to our builddir; we don't need that, but we do want them in ARTIFACTS_DIR
331+ string(REGEX MATCH \"( '--parameter')? '-o'( '--parameter')? '[^']*,xunitxml' \" xmlargs \"\${replacestr}\")
332+ string(REGEX REPLACE \"( '--parameter')? '-o'( '--parameter')? '[^']*,xunitxml' \" \" \\\$XML_ARGS \" replacestr \"\${replacestr}\")
333+ string(REGEX REPLACE \"'[^']*/tests/\" \"'\\\$ARTIFACTS_DIR/tests/\" xmlargs \"\${xmlargs}\")
334+ string(REGEX REPLACE \".*'([^']*),xunitxml'.*\" \"\\\\1\" xmlfile \"\${xmlargs}\")
335+ string(REGEX REPLACE \"(.*)/[^/]*\" \"\\\\1\" xmldir \"\${xmlfile}\")
336+ string(REGEX REPLACE \"'\" \"\" xmlargs \"\${xmlargs}\") # strip single quotes
337+ string(REGEX REPLACE \"@XML_ARGS@\" \"\${xmlargs}\" replacestr \"\${replacestr}\")
338+ string(REGEX REPLACE \"@XML_DIR@\" \"\${xmldir}\" replacestr \"\${replacestr}\")
339+ string(REGEX REPLACE \"@XML_FILE@\" \"\${xmlfile}\" replacestr \"\${replacestr}\")
340+ # replace build/source roots with their install paths
341+ string(REPLACE \"${CMAKE_BINARY_DIR}/libs\" \"${CMAKE_INSTALL_PREFIX}/${SHELL_PRIVATE_LIBDIR}\" replacestr \"\${replacestr}\")
342+ string(REPLACE \"${CMAKE_BINARY_DIR}/plugins\" \"${CMAKE_INSTALL_PREFIX}/${SHELL_INSTALL_QML}\" replacestr \"\${replacestr}\")
343+ string(REPLACE \"${CMAKE_BINARY_DIR}/tests/libs\" \"${CMAKE_INSTALL_PREFIX}/${SHELL_PRIVATE_LIBDIR}/tests/libs\" replacestr \"\${replacestr}\")
344+ string(REPLACE \"${CMAKE_BINARY_DIR}/tests/mocks\" \"${CMAKE_INSTALL_PREFIX}/${SHELL_INSTALL_QML}/mocks\" replacestr \"\${replacestr}\")
345+ string(REPLACE \"${CMAKE_BINARY_DIR}/tests/plugins\" \"${CMAKE_INSTALL_PREFIX}/${SHELL_PRIVATE_LIBDIR}/tests/plugins\" replacestr \"\${replacestr}\")
346+ string(REPLACE \"${CMAKE_BINARY_DIR}/tests/qmltests\" \"${CMAKE_INSTALL_PREFIX}/${SHELL_PRIVATE_LIBDIR}/tests/qmltests\" replacestr \"\${replacestr}\")
347+ string(REPLACE \"${CMAKE_BINARY_DIR}/tests/uqmlscene\" \"${CMAKE_INSTALL_PREFIX}/${SHELL_PRIVATE_LIBDIR}\" replacestr \"\${replacestr}\")
348+ string(REPLACE \"${CMAKE_BINARY_DIR}/tests/utils/modules\" \"${CMAKE_INSTALL_PREFIX}/${SHELL_INSTALL_QML}/utils\" replacestr \"\${replacestr}\")
349+ string(REPLACE \"${CMAKE_SOURCE_DIR}/tests/plugins\" \"${CMAKE_INSTALL_PREFIX}/${SHELL_APP_DIR}/tests/plugins\" replacestr \"\${replacestr}\")
350+ string(REPLACE \"${CMAKE_SOURCE_DIR}/tests/qmltests\" \"${CMAKE_INSTALL_PREFIX}/${SHELL_APP_DIR}/tests/qmltests\" replacestr \"\${replacestr}\")
352+ file(WRITE \"${filename}\" \"\${replacestr}\")
354+ # END OF CODE BLOCK --------------------------------------------------
356+ install(FILES "${filename}"
357+ PERMISSIONS OWNER_EXECUTE OWNER_READ OWNER_WRITE
358+ GROUP_EXECUTE GROUP_READ
359+ WORLD_EXECUTE WORLD_READ
360+ DESTINATION "${SHELL_PRIVATE_LIBDIR}/tests/scripts"
364+function(add_meta_dependencies UPSTREAM_TARGET)
365+ cmake_parse_arguments(TEST "" "" "DEPENDS" ${ARGN})
367+ foreach(depend ${TEST_DEPENDS})
368+ add_dependencies(${UPSTREAM_TARGET} ${depend})
370+ # add depend to the meta test script that we will install on system
371+ set(filename "${CMAKE_BINARY_DIR}/tests/scripts/${UPSTREAM_TARGET}.sh")
372+ if (EXISTS "${filename}")
373+ file(APPEND "${filename}" "${CMAKE_INSTALL_PREFIX}/${SHELL_PRIVATE_LIBDIR}/tests/scripts/${depend}.sh\n")
212# add_qmltest_target(target_name target
378# add_qmltest_target(target_name target
213# COMMAND test_exe [arg1 [...]] # execute this test with arguments
379# COMMAND test_exe [arg1 [...]] # execute this test with arguments
214# [...] # see above for available arguments:
380# [...] # see above for available arguments:
@@ -231,6 +397,11 @@ function(add_qmltest_target TARGET_NAME TARGET)
231 DEPENDS ${TARGET} ${QMLTEST_DEPENDS}
397 DEPENDS ${TARGET} ${QMLTEST_DEPENDS}
400+ install_test_script(${TARGET_NAME}
401+ ENVIRONMENT ${QMLTEST_ENVIRONMENT}
402+ COMMAND ${QMLTEST_COMMAND}
234 if(QMLTEST_ADD_TEST)
405 if(QMLTEST_ADD_TEST)
235 add_test(
406 add_test(
236 NAME ${TARGET_NAME}
407 NAME ${TARGET_NAME}
@@ -248,7 +419,7 @@ function(add_qmltest_target TARGET_NAME TARGET)
250 foreach(UPSTREAM_TARGET ${QMLTEST_TARGETS})
421 foreach(UPSTREAM_TARGET ${QMLTEST_TARGETS})
251− add_dependencies(${UPSTREAM_TARGET} ${TARGET_NAME})
422+ add_meta_dependencies(${UPSTREAM_TARGET} DEPENDS ${TARGET_NAME})
252 endforeach()
423 endforeach()
253endfunction()
424endfunction()