RunCMakeTest.cmake 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. include(RunCMake)
  2. include(RunCTest)
  3. ###############################################################################
  4. # Test ctresalloc itself - we want to make sure it's not just rubber-stamping
  5. # the test results
  6. ###############################################################################
  7. function(ctresalloc_verify_log expected_contents)
  8. if(NOT EXISTS "${RunCMake_TEST_BINARY_DIR}/ctresalloc.log")
  9. string(APPEND RunCMake_TEST_FAILED "Log file was not written\n")
  10. set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}" PARENT_SCOPE)
  11. return()
  12. endif()
  13. file(READ "${RunCMake_TEST_BINARY_DIR}/ctresalloc.log" actual_contents)
  14. if(NOT actual_contents STREQUAL expected_contents)
  15. string(APPEND RunCMake_TEST_FAILED "Actual log did not match expected log\n")
  16. set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}" PARENT_SCOPE)
  17. endif()
  18. endfunction()
  19. function(run_ctresalloc_write_proc name proc)
  20. file(REMOVE "${RunCMake_BINARY_DIR}/${name}-build/ctresalloc.log")
  21. run_ctresalloc_write_proc_nodel("${name}" "${proc}" "${ARGN}")
  22. endfunction()
  23. function(run_ctresalloc_write_proc_nodel name proc)
  24. string(REPLACE ";" "\\;" proc "${proc}")
  25. run_cmake_command(${name} "${CMAKE_COMMAND}" -E env "${ARGN}" "${CTRESALLOC_COMMAND}" write "${RunCMake_BINARY_DIR}/${name}-build/ctresalloc.log" "${name}" 0 "${proc}")
  26. endfunction()
  27. function(run_ctresalloc_write_noproc name)
  28. run_cmake_command(${name} "${CMAKE_COMMAND}" -E env "${ARGN}" "${CTRESALLOC_COMMAND}" write "${RunCMake_BINARY_DIR}/${name}-build/ctresalloc.log" "${name}" 0)
  29. endfunction()
  30. function(run_ctresalloc_verify name tests)
  31. string(REPLACE ";" "\\;" tests "${tests}")
  32. run_cmake_command(${name} "${CTRESALLOC_COMMAND}" verify "${RunCMake_SOURCE_DIR}/${name}.log" "${CMAKE_CURRENT_LIST_DIR}/resspec.json" "${tests}")
  33. endfunction()
  34. function(read_testing_file filename variable)
  35. file(READ "${RunCMake_TEST_BINARY_DIR}/Testing/TAG" _tag)
  36. string(REGEX REPLACE "^([^\n]*)\n.*$" "\\1" _date "${_tag}")
  37. file(READ "${RunCMake_TEST_BINARY_DIR}/Testing/${_date}/${filename}" _contents)
  38. set("${variable}" "${_contents}" PARENT_SCOPE)
  39. endfunction()
  40. unset(ENV{CTEST_RESOURCE_GROUP_COUNT})
  41. set(RunCMake_TEST_NO_CLEAN 1)
  42. file(REMOVE_RECURSE "${RunCMake_BINARY_DIR}/ctresalloc-write-proc-good1-build")
  43. file(MAKE_DIRECTORY "${RunCMake_BINARY_DIR}/ctresalloc-write-proc-good1-build")
  44. file(WRITE "${RunCMake_BINARY_DIR}/ctresalloc-write-proc-good1-build/ctresalloc.log"
  45. [[begin test1
  46. alloc widgets 0 1
  47. dealloc widgets 0 1
  48. end test1
  49. ]])
  50. run_ctresalloc_write_proc_nodel(ctresalloc-write-proc-good1 "1,widgets:2,transmogrifiers:1;2,widgets:1,widgets:2"
  51. CTEST_RESOURCE_GROUP_COUNT=3
  52. CTEST_RESOURCE_GROUP_0=widgets,transmogrifiers
  53. CTEST_RESOURCE_GROUP_0_WIDGETS=id:0,slots:2
  54. CTEST_RESOURCE_GROUP_0_TRANSMOGRIFIERS=id:calvin,slots:1
  55. CTEST_RESOURCE_GROUP_1=widgets
  56. "CTEST_RESOURCE_GROUP_1_WIDGETS=id:0,slots:1\\;id:2,slots:2"
  57. CTEST_RESOURCE_GROUP_2=widgets
  58. "CTEST_RESOURCE_GROUP_2_WIDGETS=id:0,slots:1\\;id:2,slots:2"
  59. )
  60. set(RunCMake_TEST_NO_CLEAN 0)
  61. run_ctresalloc_write_proc(ctresalloc-write-proc-good2 "widgets:8"
  62. CTEST_RESOURCE_GROUP_COUNT=1
  63. CTEST_RESOURCE_GROUP_0=widgets
  64. CTEST_RESOURCE_GROUP_0_WIDGETS=id:3,slots:8
  65. )
  66. run_ctresalloc_write_proc(ctresalloc-write-proc-nocount "widgets:8")
  67. run_ctresalloc_write_proc(ctresalloc-write-proc-badcount "widgets:8"
  68. CTEST_RESOURCE_GROUP_COUNT=2
  69. )
  70. run_ctresalloc_write_proc(ctresalloc-write-proc-nores "widgets:8"
  71. CTEST_RESOURCE_GROUP_COUNT=1
  72. )
  73. run_ctresalloc_write_proc(ctresalloc-write-proc-badres "widgets:8"
  74. CTEST_RESOURCE_GROUP_COUNT=1
  75. CTEST_RESOURCE_GROUP_0=widgets,transmogrifiers
  76. )
  77. run_ctresalloc_write_proc(ctresalloc-write-proc-nowidgets "widgets:8"
  78. CTEST_RESOURCE_GROUP_COUNT=1
  79. CTEST_RESOURCE_GROUP_0=widgets
  80. )
  81. run_ctresalloc_write_proc(ctresalloc-write-proc-badwidgets1 "widgets:8"
  82. CTEST_RESOURCE_GROUP_COUNT=1
  83. CTEST_RESOURCE_GROUP_0=widgets
  84. CTEST_RESOURCE_GROUP_0_WIDGETS=
  85. )
  86. run_ctresalloc_write_proc(ctresalloc-write-proc-badwidgets2 "widgets:8"
  87. CTEST_RESOURCE_GROUP_COUNT=1
  88. CTEST_RESOURCE_GROUP_0=widgets
  89. "CTEST_RESOURCE_GROUP_0_WIDGETS=id:3,slots:8\\;id:0,slots:1"
  90. )
  91. run_ctresalloc_write_proc(ctresalloc-write-proc-badwidgets3 "widgets:8"
  92. CTEST_RESOURCE_GROUP_COUNT=1
  93. CTEST_RESOURCE_GROUP_0=widgets
  94. CTEST_RESOURCE_GROUP_0_WIDGETS=id:3,slots:7
  95. )
  96. run_ctresalloc_write_proc(ctresalloc-write-proc-badwidgets4 "widgets:8"
  97. CTEST_RESOURCE_GROUP_COUNT=1
  98. CTEST_RESOURCE_GROUP_0=widgets
  99. CTEST_RESOURCE_GROUP_0_WIDGETS=invalid
  100. )
  101. run_ctresalloc_write_proc(ctresalloc-write-proc-badwidgets5 "widgets:2,widgets:2"
  102. CTEST_RESOURCE_GROUP_COUNT=1
  103. CTEST_RESOURCE_GROUP_0=widgets
  104. "CTEST_RESOURCE_GROUP_0_WIDGETS=id:0,slots:2\\;id:0,slots:1"
  105. )
  106. run_ctresalloc_write_proc(ctresalloc-write-proc-badwidgets6 "widgets:2"
  107. CTEST_RESOURCE_GROUP_COUNT=1
  108. CTEST_RESOURCE_GROUP_0=widgets
  109. "CTEST_RESOURCE_GROUP_0_WIDGETS=id:0,slots:2\\;id:0,slots:1"
  110. )
  111. run_ctresalloc_write_proc(ctresalloc-write-proc-badwidgets7 "widgets:2,widgets:2"
  112. CTEST_RESOURCE_GROUP_COUNT=1
  113. CTEST_RESOURCE_GROUP_0=widgets
  114. CTEST_RESOURCE_GROUP_0_WIDGETS=id:0,slots:2
  115. )
  116. run_ctresalloc_write_noproc(ctresalloc-write-noproc-good1)
  117. run_ctresalloc_write_noproc(ctresalloc-write-noproc-count
  118. CTEST_RESOURCE_GROUP_COUNT=1
  119. )
  120. run_ctresalloc_verify(ctresalloc-verify-good1 "test1;test2")
  121. run_ctresalloc_verify(ctresalloc-verify-good2 "")
  122. run_ctresalloc_verify(ctresalloc-verify-nolog "")
  123. run_ctresalloc_verify(ctresalloc-verify-nores "")
  124. run_ctresalloc_verify(ctresalloc-verify-noid "")
  125. run_ctresalloc_verify(ctresalloc-verify-notenough "")
  126. run_ctresalloc_verify(ctresalloc-verify-baddealloc "")
  127. run_ctresalloc_verify(ctresalloc-verify-leak "")
  128. run_ctresalloc_verify(ctresalloc-verify-badtest1 "")
  129. run_ctresalloc_verify(ctresalloc-verify-badtest2 "test1")
  130. run_ctresalloc_verify(ctresalloc-verify-badtest3 "test1")
  131. run_ctresalloc_verify(ctresalloc-verify-badtest4 "test1")
  132. run_ctresalloc_verify(ctresalloc-verify-badtest5 "test1")
  133. run_ctresalloc_verify(ctresalloc-verify-nobegin "test1")
  134. run_ctresalloc_verify(ctresalloc-verify-noend "test1")
  135. ###############################################################################
  136. # Now test the resource allocation feature of CTest
  137. ###############################################################################
  138. function(run_ctest_resource name parallel random extra)
  139. run_ctest("${name}-ctest-s-res" "-DCTEST_RESOURCE_ALLOC_ENABLED=1" "-DCTEST_RESOURCE_SPEC_SOURCE=ARG" "-DCTRESALLOC_COMMAND=${CTRESALLOC_COMMAND}" "-DCTEST_PARALLEL=${parallel}" "-DCTEST_RANDOM=${random}")
  140. run_ctest("${name}-ctest-s-nores" "-DCTEST_RESOURCE_ALLOC_ENABLED=0" "-DCTEST_RESOURCE_SPEC_SOURCE=NONE" "-DCTRESALLOC_COMMAND=${CTRESALLOC_COMMAND}" "-DCTEST_PARALLEL=${parallel}" "-DCTEST_RANDOM=${random}")
  141. if(extra)
  142. run_ctest("${name}-ctest-s-res-variable" "-DCTEST_RESOURCE_ALLOC_ENABLED=1" "-DCTEST_RESOURCE_SPEC_SOURCE=VARIABLE" "-DCTRESALLOC_COMMAND=${CTRESALLOC_COMMAND}" "-DCTEST_PARALLEL=${parallel}" "-DCTEST_RANDOM=${random}")
  143. run_ctest("${name}-ctest-s-res-cache" "-DCTEST_RESOURCE_ALLOC_ENABLED=1" "-DCTEST_RESOURCE_SPEC_SOURCE=CACHE" "-DCTRESALLOC_COMMAND=${CTRESALLOC_COMMAND}" "-DCTEST_PARALLEL=${parallel}" "-DCTEST_RANDOM=${random}")
  144. run_ctest("${name}-ctest-s-res-cmdline" "-DCTEST_RESOURCE_ALLOC_ENABLED=1" "-DCTEST_RESOURCE_SPEC_SOURCE=CMDLINE" "-DCTRESALLOC_COMMAND=${CTRESALLOC_COMMAND}" "-DCTEST_PARALLEL=${parallel}" "-DCTEST_RANDOM=${random}" --resource-spec-file "${RunCMake_SOURCE_DIR}/resspec.json")
  145. endif()
  146. endfunction()
  147. function(verify_ctest_resources)
  148. file(READ "${RunCMake_TEST_BINARY_DIR}/restests.txt" restests)
  149. execute_process(COMMAND "${CTRESALLOC_COMMAND}" verify "${RunCMake_TEST_BINARY_DIR}/ctresalloc.log" "${CMAKE_CURRENT_LIST_DIR}/resspec.json" "${restests}"
  150. OUTPUT_VARIABLE output ERROR_QUIET RESULT_VARIABLE result)
  151. if(result)
  152. string(APPEND RunCMake_TEST_FAILED "${output}")
  153. set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}" PARENT_SCOPE)
  154. endif()
  155. endfunction()
  156. run_ctest_resource(lotsoftests 10 1 0)
  157. run_ctest_resource(checkfree1 2 0 1)
  158. run_ctest_resource(checkfree2 1 0 0)
  159. run_ctest_resource(notenough1 1 0 1)
  160. run_ctest_resource(notenough2 1 0 0)
  161. run_ctest_resource(notenough3 1 0 0)
  162. run_ctest_resource(combine 1 0 0)
  163. run_ctest_resource(ensure_parallel 2 0 0)
  164. set(ENV{CTEST_RESOURCE_GROUP_COUNT} 2)
  165. run_ctest_resource(process_count 1 0 0)
  166. unset(ENV{CTEST_RESOURCE_GROUP_COUNT})