CTestUpdateCommon.cmake 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #-----------------------------------------------------------------------------
  2. # Function to run a child process and report output only on error.
  3. function(run_child)
  4. execute_process(${ARGN}
  5. RESULT_VARIABLE FAILED
  6. OUTPUT_VARIABLE OUTPUT
  7. ERROR_VARIABLE OUTPUT
  8. OUTPUT_STRIP_TRAILING_WHITESPACE
  9. ERROR_STRIP_TRAILING_WHITESPACE
  10. )
  11. if(FAILED)
  12. string(REGEX REPLACE "\n" "\n " OUTPUT "${OUTPUT}")
  13. message(FATAL_ERROR "Child failed (${FAILED}), output is\n ${OUTPUT}\n")
  14. endif(FAILED)
  15. endfunction(run_child)
  16. #-----------------------------------------------------------------------------
  17. # Function to find the Update.xml file and check for expected entries.
  18. function(check_updates build)
  19. # Find the Update.xml file for the given build tree
  20. set(PATTERN ${TOP}/${build}/Testing/*/Update.xml)
  21. file(GLOB UPDATE_XML_FILE RELATIVE ${TOP} ${PATTERN})
  22. string(REGEX REPLACE "//Update.xml$" "/Update.xml"
  23. UPDATE_XML_FILE "${UPDATE_XML_FILE}"
  24. )
  25. if(NOT UPDATE_XML_FILE)
  26. message(FATAL_ERROR "Cannot find Update.xml with pattern\n ${PATTERN}")
  27. endif(NOT UPDATE_XML_FILE)
  28. message(" found ${UPDATE_XML_FILE}")
  29. # Read entries from the Update.xml file
  30. file(STRINGS ${TOP}/${UPDATE_XML_FILE} UPDATE_XML_ENTRIES
  31. REGEX "FullName"
  32. LIMIT_INPUT 4096
  33. )
  34. # Verify that expected entries exist
  35. set(MISSING)
  36. foreach(f ${ARGN})
  37. string(REPLACE "/" "[/\\\\]" regex "${f}")
  38. string(REPLACE "." "\\." regex "${regex}")
  39. if(NOT "${UPDATE_XML_ENTRIES}" MATCHES "<FullName>${regex}</FullName>")
  40. list(APPEND MISSING ${f})
  41. endif()
  42. endforeach(f)
  43. # Report the result
  44. if(MISSING)
  45. # List the missing entries
  46. set(MSG "Update.xml is missing an entry for:\n")
  47. foreach(f ${MISSING})
  48. set(MSG "${MSG} ${f}\n")
  49. endforeach(f)
  50. # Provide the log file
  51. file(GLOB UPDATE_LOG_FILE
  52. ${TOP}/${build}/Testing/Temporary/LastUpdate*.log)
  53. if(UPDATE_LOG_FILE)
  54. file(READ ${UPDATE_LOG_FILE} UPDATE_LOG LIMIT 4096)
  55. string(REGEX REPLACE "\n" "\n " UPDATE_LOG "${UPDATE_LOG}")
  56. set(MSG "${MSG}Update log:\n ${UPDATE_LOG}")
  57. else(UPDATE_LOG_FILE)
  58. set(MSG "${MSG}No update log found!")
  59. endif(UPDATE_LOG_FILE)
  60. # Display the error message
  61. message(FATAL_ERROR "${MSG}")
  62. else(MISSING)
  63. # Success
  64. message(" no entries missing from Update.xml")
  65. endif(MISSING)
  66. endfunction(check_updates)
  67. #-----------------------------------------------------------------------------
  68. # Function to create initial content.
  69. function(create_content dir)
  70. file(MAKE_DIRECTORY ${TOP}/${dir})
  71. # An example CTest project configuration file.
  72. file(WRITE ${TOP}/${dir}/CTestConfig.cmake
  73. "# CTest Configuration File
  74. set(CTEST_PROJECT_NAME TestProject)
  75. set(CTEST_NIGHTLY_START_TIME \"21:00:00 EDT\")
  76. ")
  77. # Some other files.
  78. file(WRITE ${TOP}/${dir}/foo.txt "foo\n")
  79. file(WRITE ${TOP}/${dir}/bar.txt "bar\n")
  80. endfunction(create_content)
  81. #-----------------------------------------------------------------------------
  82. # Function to update content.
  83. function(update_content dir added_var removed_var dirs_var)
  84. file(APPEND ${TOP}/${dir}/foo.txt "foo line 2\n")
  85. file(WRITE ${TOP}/${dir}/zot.txt "zot\n")
  86. file(REMOVE ${TOP}/${dir}/bar.txt)
  87. file(MAKE_DIRECTORY ${TOP}/${dir}/subdir)
  88. file(WRITE ${TOP}/${dir}/subdir/foo.txt "foo\n")
  89. file(WRITE ${TOP}/${dir}/subdir/bar.txt "bar\n")
  90. set(${dirs_var} subdir PARENT_SCOPE)
  91. set(${added_var} zot.txt subdir/foo.txt subdir/bar.txt PARENT_SCOPE)
  92. set(${removed_var} bar.txt PARENT_SCOPE)
  93. endfunction(update_content)
  94. #-----------------------------------------------------------------------------
  95. # Function to change existing files
  96. function(change_content dir)
  97. file(APPEND ${TOP}/${dir}/foo.txt "foo line 3\n")
  98. file(APPEND ${TOP}/${dir}/subdir/foo.txt "foo line 2\n")
  99. endfunction(change_content)
  100. #-----------------------------------------------------------------------------
  101. # Function to create local modifications before update
  102. function(modify_content dir)
  103. file(APPEND ${TOP}/${dir}/CTestConfig.cmake "# local modification\n")
  104. endfunction(modify_content)
  105. #-----------------------------------------------------------------------------
  106. # Function to write CTestConfiguration.ini content.
  107. function(create_build_tree src_dir bin_dir)
  108. file(MAKE_DIRECTORY ${TOP}/${bin_dir})
  109. file(WRITE ${TOP}/${bin_dir}/CTestConfiguration.ini
  110. "# CTest Configuration File
  111. SourceDirectory: ${TOP}/${src_dir}
  112. BuildDirectory: ${TOP}/${bin_dir}
  113. Site: test.site
  114. BuildName: user-test
  115. ")
  116. endfunction(create_build_tree)
  117. #-----------------------------------------------------------------------------
  118. # Function to write the dashboard test script.
  119. function(create_dashboard_script name custom_text)
  120. # Write the dashboard script.
  121. file(WRITE ${TOP}/dashboard.cmake
  122. "# CTest Dashboard Script
  123. set(CTEST_DASHBOARD_ROOT \"${TOP}\")
  124. set(CTEST_SITE test.site)
  125. set(CTEST_BUILD_NAME dash-test)
  126. set(CTEST_SOURCE_DIRECTORY \${CTEST_DASHBOARD_ROOT}/dash-source)
  127. set(CTEST_BINARY_DIRECTORY \${CTEST_DASHBOARD_ROOT}/dash-binary)
  128. ${custom_text}
  129. # Start a dashboard and run the update step
  130. ctest_start(Experimental)
  131. ctest_update(SOURCE \${CTEST_SOURCE_DIRECTORY})
  132. ")
  133. endfunction(create_dashboard_script)
  134. #-----------------------------------------------------------------------------
  135. # Function to run the dashboard through the command line
  136. function(run_dashboard_command_line bin_dir)
  137. run_child(
  138. WORKING_DIRECTORY ${TOP}/${bin_dir}
  139. COMMAND ${CMAKE_CTEST_COMMAND} -M Experimental -T Start -T Update
  140. )
  141. # Verify the updates reported by CTest.
  142. check_updates(${bin_dir} foo.txt bar.txt zot.txt CTestConfig.cmake
  143. subdir/foo.txt subdir/bar.txt)
  144. endfunction(run_dashboard_command_line)
  145. #-----------------------------------------------------------------------------
  146. # Function to run the dashboard through a script
  147. function(run_dashboard_script name)
  148. run_child(
  149. WORKING_DIRECTORY ${TOP}
  150. COMMAND ${CMAKE_CTEST_COMMAND} -S ${name} -V
  151. )
  152. # Verify the updates reported by CTest.
  153. check_updates(dash-binary foo.txt bar.txt zot.txt
  154. subdir/foo.txt subdir/bar.txt)
  155. endfunction(run_dashboard_script)
  156. #-----------------------------------------------------------------------------
  157. # Function to initialize the testing directory.
  158. function(init_testing)
  159. file(REMOVE_RECURSE ${TOP})
  160. file(MAKE_DIRECTORY ${TOP})
  161. endfunction(init_testing)