CTestUpdateCommon.cmake 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. if(NOT "${UPDATE_XML_ENTRIES}" MATCHES "<FullName>${f}</FullName>")
  38. list(APPEND MISSING ${f})
  39. endif()
  40. endforeach(f)
  41. # Report the result
  42. if(MISSING)
  43. # List the missing entries
  44. set(MSG "Update.xml is missing an entry for:\n")
  45. foreach(f ${MISSING})
  46. set(MSG "${MSG} ${f}\n")
  47. endforeach(f)
  48. # Provide the log file
  49. file(GLOB UPDATE_LOG_FILE
  50. ${TOP}/${build}/Testing/Temporary/LastUpdate*.log)
  51. if(UPDATE_LOG_FILE)
  52. file(READ ${UPDATE_LOG_FILE} UPDATE_LOG LIMIT 4096)
  53. string(REGEX REPLACE "\n" "\n " UPDATE_LOG "${UPDATE_LOG}")
  54. set(MSG "${MSG}Update log:\n ${UPDATE_LOG}")
  55. else(UPDATE_LOG_FILE)
  56. set(MSG "${MSG}No update log found!")
  57. endif(UPDATE_LOG_FILE)
  58. # Display the error message
  59. message(FATAL_ERROR "${MSG}")
  60. else(MISSING)
  61. # Success
  62. message(" no entries missing from Update.xml")
  63. endif(MISSING)
  64. endfunction(check_updates)
  65. #-----------------------------------------------------------------------------
  66. # Function to create initial content.
  67. function(create_content dir)
  68. file(MAKE_DIRECTORY ${TOP}/${dir})
  69. # An example CTest project configuration file.
  70. file(WRITE ${TOP}/${dir}/CTestConfig.cmake
  71. "# CTest Configuration File
  72. set(CTEST_PROJECT_NAME TestProject)
  73. set(CTEST_NIGHTLY_START_TIME \"21:00:00 EDT\")
  74. ")
  75. # Some other files.
  76. file(WRITE ${TOP}/${dir}/foo.txt "foo\n")
  77. file(WRITE ${TOP}/${dir}/bar.txt "bar\n")
  78. endfunction(create_content)
  79. #-----------------------------------------------------------------------------
  80. # Function to update content.
  81. function(update_content dir added_var removed_var)
  82. file(APPEND ${TOP}/${dir}/foo.txt "foo line 2\n")
  83. file(WRITE ${TOP}/${dir}/zot.txt "zot\n")
  84. file(REMOVE ${TOP}/${dir}/bar.txt)
  85. set(${added_var} zot.txt PARENT_SCOPE)
  86. set(${removed_var} bar.txt PARENT_SCOPE)
  87. endfunction(update_content)
  88. #-----------------------------------------------------------------------------
  89. # Function to write CTestConfiguration.ini content.
  90. function(create_build_tree src_dir bin_dir)
  91. file(MAKE_DIRECTORY ${TOP}/${bin_dir})
  92. file(WRITE ${TOP}/${bin_dir}/CTestConfiguration.ini
  93. "# CTest Configuration File
  94. SourceDirectory: ${TOP}/${src_dir}
  95. BuildDirectory: ${TOP}/${bin_dir}
  96. Site: test.site
  97. BuildName: user-test
  98. ")
  99. endfunction(create_build_tree)
  100. #-----------------------------------------------------------------------------
  101. # Function to write the dashboard test script.
  102. function(create_dashboard_script name custom_text)
  103. # Write the dashboard script.
  104. file(WRITE ${TOP}/dashboard.cmake
  105. "# CTest Dashboard Script
  106. set(CTEST_DASHBOARD_ROOT \"${TOP}\")
  107. set(CTEST_SITE test.site)
  108. set(CTEST_BUILD_NAME dash-test)
  109. set(CTEST_SOURCE_DIRECTORY \${CTEST_DASHBOARD_ROOT}/dash-source)
  110. set(CTEST_BINARY_DIRECTORY \${CTEST_DASHBOARD_ROOT}/dash-binary)
  111. ${custom_text}
  112. # Start a dashboard and run the update step
  113. ctest_start(Experimental)
  114. ctest_update(SOURCE \${CTEST_SOURCE_DIRECTORY})
  115. ")
  116. endfunction(create_dashboard_script)
  117. #-----------------------------------------------------------------------------
  118. # Function to run the dashboard through the command line
  119. function(run_dashboard_command_line bin_dir)
  120. run_child(
  121. WORKING_DIRECTORY ${TOP}/${bin_dir}
  122. COMMAND ${CMAKE_CTEST_COMMAND} -M Experimental -T Start -T Update
  123. )
  124. # Verify the updates reported by CTest.
  125. check_updates(${bin_dir} foo.txt bar.txt zot.txt)
  126. endfunction(run_dashboard_command_line)
  127. #-----------------------------------------------------------------------------
  128. # Function to run the dashboard through a script
  129. function(run_dashboard_script name)
  130. run_child(
  131. WORKING_DIRECTORY ${TOP}
  132. COMMAND ${CMAKE_CTEST_COMMAND} -S ${name} -V
  133. )
  134. # Verify the updates reported by CTest.
  135. check_updates(dash-binary foo.txt bar.txt zot.txt)
  136. endfunction(run_dashboard_script)
  137. #-----------------------------------------------------------------------------
  138. # Function to initialize the testing directory.
  139. function(init_testing)
  140. file(REMOVE_RECURSE ${TOP})
  141. file(MAKE_DIRECTORY ${TOP})
  142. endfunction(init_testing)