RunCMakeTest.cmake 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. include(RunCMake)
  2. include(RunCTest)
  3. ###############################################################################
  4. # Test cthwalloc itself - we want to make sure it's not just rubber-stamping
  5. # the test results
  6. ###############################################################################
  7. function(cthwalloc_verify_log expected_contents)
  8. if(NOT EXISTS "${RunCMake_TEST_BINARY_DIR}/cthwalloc.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}/cthwalloc.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_cthwalloc_write_proc name proc)
  20. file(REMOVE "${RunCMake_BINARY_DIR}/${name}-build/cthwalloc.log")
  21. run_cthwalloc_write_proc_nodel("${name}" "${proc}" "${ARGN}")
  22. endfunction()
  23. function(run_cthwalloc_write_proc_nodel name proc)
  24. string(REPLACE ";" "\\;" proc "${proc}")
  25. run_cmake_command(${name} "${CMAKE_COMMAND}" -E env "${ARGN}" "${CTHWALLOC_COMMAND}" write "${RunCMake_BINARY_DIR}/${name}-build/cthwalloc.log" "${name}" 0 "${proc}")
  26. endfunction()
  27. function(run_cthwalloc_write_noproc name)
  28. run_cmake_command(${name} "${CMAKE_COMMAND}" -E env "${ARGN}" "${CTHWALLOC_COMMAND}" write "${RunCMake_BINARY_DIR}/${name}-build/cthwalloc.log" "${name}" 0)
  29. endfunction()
  30. function(run_cthwalloc_verify name tests)
  31. string(REPLACE ";" "\\;" tests "${tests}")
  32. run_cmake_command(${name} "${CTHWALLOC_COMMAND}" verify "${RunCMake_SOURCE_DIR}/${name}.log" "${CMAKE_CURRENT_LIST_DIR}/hwspec.json" "${tests}")
  33. endfunction()
  34. unset(ENV{CTEST_RESOURCE_GROUP_COUNT})
  35. set(RunCMake_TEST_NO_CLEAN 1)
  36. file(REMOVE_RECURSE "${RunCMake_BINARY_DIR}/cthwalloc-write-proc-good1-build")
  37. file(MAKE_DIRECTORY "${RunCMake_BINARY_DIR}/cthwalloc-write-proc-good1-build")
  38. file(WRITE "${RunCMake_BINARY_DIR}/cthwalloc-write-proc-good1-build/cthwalloc.log"
  39. [[begin test1
  40. alloc widgets 0 1
  41. dealloc widgets 0 1
  42. end test1
  43. ]])
  44. run_cthwalloc_write_proc_nodel(cthwalloc-write-proc-good1 "1,widgets:2,transmogrifiers:1;2,widgets:1,widgets:2"
  45. CTEST_RESOURCE_GROUP_COUNT=3
  46. CTEST_RESOURCE_GROUP_0=widgets,transmogrifiers
  47. CTEST_RESOURCE_GROUP_0_WIDGETS=id:0,slots:2
  48. CTEST_RESOURCE_GROUP_0_TRANSMOGRIFIERS=id:calvin,slots:1
  49. CTEST_RESOURCE_GROUP_1=widgets
  50. "CTEST_RESOURCE_GROUP_1_WIDGETS=id:0,slots:1\\;id:2,slots:2"
  51. CTEST_RESOURCE_GROUP_2=widgets
  52. "CTEST_RESOURCE_GROUP_2_WIDGETS=id:0,slots:1\\;id:2,slots:2"
  53. )
  54. set(RunCMake_TEST_NO_CLEAN 0)
  55. run_cthwalloc_write_proc(cthwalloc-write-proc-good2 "widgets:8"
  56. CTEST_RESOURCE_GROUP_COUNT=1
  57. CTEST_RESOURCE_GROUP_0=widgets
  58. CTEST_RESOURCE_GROUP_0_WIDGETS=id:3,slots:8
  59. )
  60. run_cthwalloc_write_proc(cthwalloc-write-proc-nocount "widgets:8")
  61. run_cthwalloc_write_proc(cthwalloc-write-proc-badcount "widgets:8"
  62. CTEST_RESOURCE_GROUP_COUNT=2
  63. )
  64. run_cthwalloc_write_proc(cthwalloc-write-proc-nores "widgets:8"
  65. CTEST_RESOURCE_GROUP_COUNT=1
  66. )
  67. run_cthwalloc_write_proc(cthwalloc-write-proc-badres "widgets:8"
  68. CTEST_RESOURCE_GROUP_COUNT=1
  69. CTEST_RESOURCE_GROUP_0=widgets,transmogrifiers
  70. )
  71. run_cthwalloc_write_proc(cthwalloc-write-proc-nowidgets "widgets:8"
  72. CTEST_RESOURCE_GROUP_COUNT=1
  73. CTEST_RESOURCE_GROUP_0=widgets
  74. )
  75. run_cthwalloc_write_proc(cthwalloc-write-proc-badwidgets1 "widgets:8"
  76. CTEST_RESOURCE_GROUP_COUNT=1
  77. CTEST_RESOURCE_GROUP_0=widgets
  78. CTEST_RESOURCE_GROUP_0_WIDGETS=
  79. )
  80. run_cthwalloc_write_proc(cthwalloc-write-proc-badwidgets2 "widgets:8"
  81. CTEST_RESOURCE_GROUP_COUNT=1
  82. CTEST_RESOURCE_GROUP_0=widgets
  83. "CTEST_RESOURCE_GROUP_0_WIDGETS=id:3,slots:8\\;id:0,slots:1"
  84. )
  85. run_cthwalloc_write_proc(cthwalloc-write-proc-badwidgets3 "widgets:8"
  86. CTEST_RESOURCE_GROUP_COUNT=1
  87. CTEST_RESOURCE_GROUP_0=widgets
  88. CTEST_RESOURCE_GROUP_0_WIDGETS=id:3,slots:7
  89. )
  90. run_cthwalloc_write_proc(cthwalloc-write-proc-badwidgets4 "widgets:8"
  91. CTEST_RESOURCE_GROUP_COUNT=1
  92. CTEST_RESOURCE_GROUP_0=widgets
  93. CTEST_RESOURCE_GROUP_0_WIDGETS=invalid
  94. )
  95. run_cthwalloc_write_proc(cthwalloc-write-proc-badwidgets5 "widgets:2,widgets:2"
  96. CTEST_RESOURCE_GROUP_COUNT=1
  97. CTEST_RESOURCE_GROUP_0=widgets
  98. "CTEST_RESOURCE_GROUP_0_WIDGETS=id:0,slots:2\\;id:0,slots:1"
  99. )
  100. run_cthwalloc_write_proc(cthwalloc-write-proc-badwidgets6 "widgets:2"
  101. CTEST_RESOURCE_GROUP_COUNT=1
  102. CTEST_RESOURCE_GROUP_0=widgets
  103. "CTEST_RESOURCE_GROUP_0_WIDGETS=id:0,slots:2\\;id:0,slots:1"
  104. )
  105. run_cthwalloc_write_proc(cthwalloc-write-proc-badwidgets7 "widgets:2,widgets:2"
  106. CTEST_RESOURCE_GROUP_COUNT=1
  107. CTEST_RESOURCE_GROUP_0=widgets
  108. CTEST_RESOURCE_GROUP_0_WIDGETS=id:0,slots:2
  109. )
  110. run_cthwalloc_write_noproc(cthwalloc-write-noproc-good1)
  111. run_cthwalloc_write_noproc(cthwalloc-write-noproc-count
  112. CTEST_RESOURCE_GROUP_COUNT=1
  113. )
  114. run_cthwalloc_verify(cthwalloc-verify-good1 "test1;test2")
  115. run_cthwalloc_verify(cthwalloc-verify-good2 "")
  116. run_cthwalloc_verify(cthwalloc-verify-nolog "")
  117. run_cthwalloc_verify(cthwalloc-verify-nores "")
  118. run_cthwalloc_verify(cthwalloc-verify-noid "")
  119. run_cthwalloc_verify(cthwalloc-verify-notenough "")
  120. run_cthwalloc_verify(cthwalloc-verify-baddealloc "")
  121. run_cthwalloc_verify(cthwalloc-verify-leak "")
  122. run_cthwalloc_verify(cthwalloc-verify-badtest1 "")
  123. run_cthwalloc_verify(cthwalloc-verify-badtest2 "test1")
  124. run_cthwalloc_verify(cthwalloc-verify-badtest3 "test1")
  125. run_cthwalloc_verify(cthwalloc-verify-badtest4 "test1")
  126. run_cthwalloc_verify(cthwalloc-verify-badtest5 "test1")
  127. run_cthwalloc_verify(cthwalloc-verify-nobegin "test1")
  128. run_cthwalloc_verify(cthwalloc-verify-noend "test1")
  129. ###############################################################################
  130. # Now test the hardware allocation feature of CTest
  131. ###############################################################################
  132. function(run_ctest_hardware name parallel random)
  133. run_ctest("${name}-ctest-s-hw" "-DCTEST_HARDWARE_ALLOC_ENABLED=1" "-DCTHWALLOC_COMMAND=${CTHWALLOC_COMMAND}" "-DCTEST_PARALLEL=${parallel}" "-DCTEST_RANDOM=${random}")
  134. run_ctest("${name}-ctest-s-nohw" "-DCTEST_HARDWARE_ALLOC_ENABLED=0" "-DCTHWALLOC_COMMAND=${CTHWALLOC_COMMAND}" "-DCTEST_PARALLEL=${parallel}" "-DCTEST_RANDOM=${random}")
  135. endfunction()
  136. function(verify_ctest_hardware)
  137. file(READ "${RunCMake_TEST_BINARY_DIR}/hwtests.txt" hwtests)
  138. execute_process(COMMAND "${CTHWALLOC_COMMAND}" verify "${RunCMake_TEST_BINARY_DIR}/cthwalloc.log" "${CMAKE_CURRENT_LIST_DIR}/hwspec.json" "${hwtests}"
  139. OUTPUT_VARIABLE output ERROR_QUIET RESULT_VARIABLE result)
  140. if(result)
  141. string(APPEND RunCMake_TEST_FAILED "${output}")
  142. set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}" PARENT_SCOPE)
  143. endif()
  144. endfunction()
  145. run_ctest_hardware(lotsoftests 10 1)
  146. run_ctest_hardware(checkfree1 2 0)
  147. run_ctest_hardware(checkfree2 1 0)
  148. run_ctest_hardware(notenough1 1 0)
  149. run_ctest_hardware(notenough2 1 0)
  150. run_ctest_hardware(ensure_parallel 2 0)
  151. set(ENV{CTEST_RESOURCE_GROUP_COUNT} 2)
  152. run_ctest_hardware(process_count 1 0)
  153. unset(ENV{CTEST_RESOURCE_GROUP_COUNT})