testcase.prf 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. have_target {
  2. # qt_build_config.prf disables execptions for all Qt modules which don't
  3. # explicitly turn it on again, while the qmake default is to build with
  4. # exceptions. As we want tests to be built like 3rd party applications,
  5. # qt_build_config tells us to re-enable exceptions here.
  6. testcase_exceptions: CONFIG += exceptions
  7. benchmark: type = benchmark
  8. else: type = check
  9. $${type}.files =
  10. $${type}.path = .
  11. # Add environment for non-installed builds. Do this first, so the
  12. # 'make' variable expansions don't end up in a batch file/script.
  13. QT_TOOL_NAME = target
  14. qtAddTargetEnv($${type}.commands, QT)
  15. # If the test ends up in a different directory, we should cd to that directory.
  16. TESTRUN_CWD = $$DESTDIR
  17. debug_and_release:debug_and_release_target {
  18. # But in debug-and-release-target mode we don't want to cd into the debug/release
  19. # directory (e.g. if the test goes to foo/release/tst_thing.exe, we want to do
  20. # 'cd foo && release/tst_thing.exe', not 'cd foo/release && tst_thing.exe').
  21. TESTRUN_CWD ~= s/(release|debug)$//
  22. TEST_TARGET_DIR = $$relative_path($$absolute_path($$DESTDIR, $$OUT_PWD), $$absolute_path($$TESTRUN_CWD, $$OUT_PWD))
  23. }
  24. # Allow for a custom test runner script
  25. $${type}.commands += $(TESTRUNNER)
  26. unix {
  27. isEmpty(TEST_TARGET_DIR): TEST_TARGET_DIR = .
  28. app_bundle: \
  29. $${type}.commands += $${TEST_TARGET_DIR}/$(QMAKE_TARGET).app/Contents/MacOS/$(QMAKE_TARGET)
  30. else: \
  31. $${type}.commands += $${TEST_TARGET_DIR}/$(QMAKE_TARGET)
  32. } else {
  33. # Windows
  34. !isEmpty(TEST_TARGET_DIR): TEST_TARGET_DIR = $${TEST_TARGET_DIR}$${QMAKE_DIR_SEP}
  35. $${type}.commands += $${TEST_TARGET_DIR}$(TARGET)
  36. }
  37. # Allow for custom arguments to tests
  38. $${type}.commands += $(TESTARGS)
  39. !isEmpty(TESTRUN_CWD):!contains(TESTRUN_CWD, ^\\./?): \
  40. $${type}.commands = cd $$shell_path($$TESTRUN_CWD) && $$eval($${type}.commands)
  41. # If the test is marked as insignificant, discard the exit code
  42. insignificant_test: $${type}.commands = -$$eval($${type}.commands)
  43. QMAKE_EXTRA_TARGETS *= $${type}
  44. isEmpty(BUILDS)|build_pass {
  45. $${type}.depends = first
  46. } else {
  47. # For exclusive builds, only run the test once.
  48. $${type}.CONFIG = recursive
  49. $${type}.target = $${type}_all
  50. $${type}.recurse_target = $${type}
  51. $${type}.commands =
  52. $${type}_first.depends = $$eval($$first(BUILDS).target)-$${type}
  53. $${type}_first.target = $${type}
  54. QMAKE_EXTRA_TARGETS += $${type}_first
  55. }
  56. !no_testcase_installs:!contains(INSTALLS, target) {
  57. # Install tests unless no_testcase_installs is set, or there is already
  58. # a `target' in INSTALLS.
  59. #
  60. # Tests are installed under a directory named after the target so that each
  61. # test has its own directory for testdata etc.
  62. #
  63. load(resolve_target)
  64. TARGET_BASENAME = $$basename(QMAKE_RESOLVED_TARGET)
  65. target.path = $$[QT_INSTALL_TESTS]/$$TARGET_BASENAME
  66. INSTALLS += target
  67. }
  68. !builtin_testdata:contains(INSTALLS, target) {
  69. # Install testdata and helpers as well, but only if we're actually installing the test.
  70. #
  71. # Testdata is installed relative to the directory containing the testcase
  72. # binary itself, e.g. this:
  73. #
  74. # CONFIG += testcase
  75. # TARGET = tst_qxmlreader
  76. #
  77. # TESTDATA += testdata/test1.xml testdata/test2.xml
  78. #
  79. # ... will result in:
  80. #
  81. # /usr/lib/qt5/tests/tst_qxmlreader/tst_qxmlreader
  82. # /usr/lib/qt5/tests/tst_qxmlreader/testdata/test1.xml
  83. # /usr/lib/qt5/tests/tst_qxmlreader/testdata/test2.xml
  84. # ...
  85. #
  86. for(file, TESTDATA) {
  87. tnam = $$file
  88. tnam ~= s,\\.\\.,dotdot,
  89. tnam ~= s,[?*],wildcard,
  90. tnam ~= s,[^A-Za-z0-9],_,
  91. tdi = testdata_$$tnam
  92. # TESTDATA consists of the files to install (source)...
  93. $${tdi}.files = $$file
  94. # ... and the destination preserves the relative path.
  95. # Strip any leading ../ from the testdata, so that installation does not escape
  96. # the test's directory in the case of e.g.
  97. #
  98. # TARGET = ../tst_qprocess
  99. # TESTDATA = ../thing1 ../thing2
  100. #
  101. # The testdata should end up at $$[QT_INSTALL_TESTS]/tst_qprocess/thing1,
  102. # rather than $$[QT_INSTALL_TESTS]/tst_qprocess/../thing1.
  103. #
  104. # Note that this does not guarantee the same relative path between test binary
  105. # and testdata in the build and install tree, but should cover most cases.
  106. #
  107. file = $$replace(file, ^(\\.\\./)+, )
  108. $${tdi}.path = $${target.path}/$$dirname(file)
  109. INSTALLS += $$tdi
  110. }
  111. # Install GENERATED_TESTDATA.
  112. # Logic is copied from the TESTDATA installation, only difference being that
  113. # INSTALL target is added with CONFIG = no_check_exist
  114. for(file, GENERATED_TESTDATA) {
  115. tnam = $$file
  116. tnam ~= s,\\.\\.,dotdot,
  117. tnam ~= s,[?*],wildcard,
  118. tnam ~= s,[^A-Za-z0-9],_,
  119. tdi = testdata_$$tnam
  120. $${tdi}.files = $$file
  121. $${tdi}.CONFIG = no_check_exist
  122. file = $$replace(file, ^(\\.\\./)+, )
  123. $${tdi}.path = $${target.path}/$$dirname(file)
  124. INSTALLS += $$tdi
  125. }
  126. # TEST_HELPER_INSTALLS specifies additional test helper executables for installation.
  127. #
  128. # Typical usage is:
  129. #
  130. # TEST_HELPER_INSTALLS += ../some/helper1 ../some/helper2
  131. #
  132. # Resulting in the test helpers being installed to:
  133. #
  134. # $$[QT_INSTALL_TESTS]/$$TARGET/some/helper1
  135. # $$[QT_INSTALL_TESTS]/$$TARGET/some/helper2
  136. #
  137. win32: extension = .exe
  138. for(test_helper, TEST_HELPER_INSTALLS) {
  139. test_helper_dir = $$dirname(test_helper)
  140. output = $$basename(test_helper_dir)
  141. target = $$basename(test_helper)
  142. targetName = $$replace(target, ' ', '_') # handle spaces in name
  143. subTarget = $${targetName}.target
  144. subInstall = $${targetName}_install
  145. subConfig = $${subInstall}.CONFIG
  146. subFiles = $${subInstall}.files
  147. subPath = $${subInstall}.path
  148. $$subTarget = $${output}/$${target}$${extension}
  149. $$subFiles = $${OUT_PWD}/$${test_helper}$${extension}
  150. $$subPath = $${target.path}/$${output}
  151. $$subConfig += no_check_exist executable
  152. INSTALLS += $${subInstall}
  153. }
  154. }
  155. builtin_testdata {
  156. ALL_TESTDATA = $$TESTDATA $$GENERATED_TESTDATA
  157. # RESOURCES does not support wildcards (for good reasons)
  158. for(td, ALL_TESTDATA): \
  159. testdata.files += $$files($$absolute_path($$td, $$_PRO_FILE_PWD_))
  160. !isEmpty(testdata.files) {
  161. testdata.base = $$_PRO_FILE_PWD_
  162. RESOURCES += testdata
  163. }
  164. !isEmpty(TEST_HELPER_INSTALLS): \
  165. error("This platform does not support tests which require helpers.")
  166. }
  167. macx-xcode:bundle:isEmpty(QMAKE_BUNDLE_EXTENSION) {
  168. QMAKE_PBX_PRODUCT_TYPE = com.apple.product-type.bundle.unit-test
  169. QMAKE_PBX_BUNDLE_TYPE = wrapper.cfbundle
  170. QMAKE_BUNDLE_EXTENSION = .xctest
  171. }
  172. } # have_target