From 4e82eb3b74bb841f0923e882fae2cb983610bab5 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Mon, 18 Feb 2019 09:59:42 -0700 Subject: [PATCH] WIP: Add TRIBITS_READ_CTEST_TAG_FILE() and TribitsGetCTestTestXmlDir.cmake (#278, #154) This is needed to be able to read XML files out of the /Testing// directory needed for (#278) This will also make it easy to generate a CDash URL without knowing the build ID. --- test/ctest_driver/CMakeLists.txt | 28 ++++++ test/ctest_driver/CTestDriverUnitTests.cmake | 89 +++++++++++++++++++ .../data/dummy_build_dir/Testing/TAG | 2 + .../TribitsCTestDriverCoreHelpers.cmake | 10 --- .../TribitsGetCTestTestXmlDir.cmake | 41 +++++++++ tribits/ctest_driver/TribitsReadTagFile.cmake | 16 ++++ 6 files changed, 176 insertions(+), 10 deletions(-) create mode 100644 test/ctest_driver/CTestDriverUnitTests.cmake create mode 100644 test/ctest_driver/data/dummy_build_dir/Testing/TAG create mode 100644 tribits/ctest_driver/TribitsGetCTestTestXmlDir.cmake create mode 100644 tribits/ctest_driver/TribitsReadTagFile.cmake diff --git a/test/ctest_driver/CMakeLists.txt b/test/ctest_driver/CMakeLists.txt index 2f8a42846..eb208066a 100644 --- a/test/ctest_driver/CMakeLists.txt +++ b/test/ctest_driver/CMakeLists.txt @@ -1,5 +1,33 @@ +TRIBITS_ADD_ADVANCED_TEST( CTestDriverUnitTests + OVERALL_WORKING_DIRECTORY TEST_NAME + TEST_0 CMND ${CMAKE_COMMAND} + ARGS + -DPROJECT_NAME=${PROJECT_NAME} + -D${PROJECT_NAME}_TRIBITS_DIR=${${PROJECT_NAME}_TRIBITS_DIR} + -P "${CMAKE_CURRENT_SOURCE_DIR}/CTestDriverUnitTests.cmake" + PASS_REGULAR_EXPRESSION_ALL + "Final UnitTests Result: num_run = 2" + "Final UnitTests Result: PASSED" + ) + + +TRIBITS_ADD_ADVANCED_TEST( TribitsGetCTestTestXmlDir + OVERALL_WORKING_DIRECTORY TEST_NAME + + TEST_0 CMND ${CMAKE_COMMAND} + ARGS + -DPROJECT_NAME=${PROJECT_NAME} + -D${PROJECT_NAME}_TRIBITS_DIR=${${PROJECT_NAME}_TRIBITS_DIR} + -DCTEST_BUILD_DIR="${CMAKE_CURRENT_LIST_DIR}/data/dummy_build_dir" + -P "${${PROJECT_NAME}_TRIBITS_DIR}/ctest_driver/TribitsGetCTestTestXmlDir.cmake" + PASS_REGULAR_EXPRESSION_ALL + "${CMAKE_CURRENT_LIST_DIR}/data/dummy_build_dir/Testing/20101015-1112" + ) + + ADD_SUBDIRECTORY(MockCTestDriver) + IF (CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") ADD_SUBDIRECTORY(TribitsExampleProject) ENDIF() diff --git a/test/ctest_driver/CTestDriverUnitTests.cmake b/test/ctest_driver/CTestDriverUnitTests.cmake new file mode 100644 index 000000000..237dc8230 --- /dev/null +++ b/test/ctest_driver/CTestDriverUnitTests.cmake @@ -0,0 +1,89 @@ +# @HEADER +# ************************************************************************ +# +# TriBITS: Tribal Build, Integrate, and Test System +# Copyright 2013 Sandia Corporation +# +# Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, +# the U.S. Government retains certain rights in this software. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# 3. Neither the name of the Corporation nor the names of the +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY +# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# ************************************************************************ +# @HEADER + +MESSAGE("PROJECT_NAME = ${PROJECT_NAME}") +MESSAGE("${PROJECT_NAME}_TRIBITS_DIR = ${${PROJECT_NAME}_TRIBITS_DIR}") + +SET( CMAKE_MODULE_PATH + "${${PROJECT_NAME}_TRIBITS_DIR}/core/utils" + "${${PROJECT_NAME}_TRIBITS_DIR}/core/package_arch" + "${${PROJECT_NAME}_TRIBITS_DIR}/ctest_driver" + ) + +INCLUDE(GlobalSet) +INCLUDE(TribitsReadTagFile) +INCLUDE(UnitTestHelpers) + + +FUNCTION(UNITTEST_READ_CTEST_TAG_FILE) + + MESSAGE("\n***") + MESSAGE("*** Testing tribits_read_ctest_tag_file()") + MESSAGE("***\n") + + SET(TAG_FILE_IN "${CMAKE_CURRENT_LIST_DIR}/data/dummy_build_dir/Testing/TAG") + + TRIBITS_READ_CTEST_TAG_FILE(${TAG_FILE_IN} BUILD_START_TIME_OUT CDASH_TRACK_OUT) + + UNITTEST_COMPARE_CONST(BUILD_START_TIME_OUT + "20101015-1112") + + UNITTEST_COMPARE_CONST(CDASH_TRACK_OUT + "My CDash Track") # NOTE: Spaces are important to test here! + +ENDFUNCTION() + +# +# Execute the unit tests +# + +# Assume that all unit tests will pass by default +GLOBAL_SET(UNITTEST_OVERALL_PASS TRUE) +GLOBAL_SET(UNITTEST_OVERALL_NUMPASSED 0) +GLOBAL_SET(UNITTEST_OVERALL_NUMRUN 0) + +# Run the unit test functions +UNITTEST_READ_CTEST_TAG_FILE() + +MESSAGE("\n***") +MESSAGE("*** Determine final result of all unit tests") +MESSAGE("***\n") + +# Pass in the number of expected tests that must pass! +UNITTEST_FINAL_RESULT(2) diff --git a/test/ctest_driver/data/dummy_build_dir/Testing/TAG b/test/ctest_driver/data/dummy_build_dir/Testing/TAG new file mode 100644 index 000000000..b0df6bdb8 --- /dev/null +++ b/test/ctest_driver/data/dummy_build_dir/Testing/TAG @@ -0,0 +1,2 @@ +20101015-1112 +My CDash Track diff --git a/tribits/ctest_driver/TribitsCTestDriverCoreHelpers.cmake b/tribits/ctest_driver/TribitsCTestDriverCoreHelpers.cmake index 0238e5ee5..24319a4ac 100644 --- a/tribits/ctest_driver/TribitsCTestDriverCoreHelpers.cmake +++ b/tribits/ctest_driver/TribitsCTestDriverCoreHelpers.cmake @@ -273,7 +273,6 @@ ENDMACRO() # NOTE: This macro is used to clean up the main TRIBITS_CTEST_DRIVER() # macro. # - MACRO(TRIBITS_SETUP_PACKAGES) # Here, we must point into the source tree just cloned (or updated) @@ -342,7 +341,6 @@ ENDMACRO() # # Select packages set by the input # - MACRO(ENABLE_USER_SELECTED_PACKAGES) # 1) Set the enables for packages already set with @@ -390,7 +388,6 @@ ENDMACRO() # # Select only packages that are modified or failed in the last CI iteration # - MACRO(ENABLE_ONLY_MODIFIED_PACKAGES) # @@ -559,7 +556,6 @@ ENDMACRO() # NOTE: These disables need to dominate over the above enables so this code is # after all the enable code has run # - MACRO(DISABLE_EXCLUDED_PACKAGES) FOREACH(TRIBITS_PACKAGE ${${PROJECT_NAME}_EXCLUDE_PACKAGES}) MESSAGE("Disabling excluded package ${TRIBITS_PACKAGE} ...") @@ -609,7 +605,6 @@ ENDMACRO() # locally. When run locally, ctest will just report aggregated times for # subprojects that have 1 or more tests. Not true for CDash. # - MACRO(TRIBITS_CTEST_DRIVER_SET_LABELS_TO_SUBPROJECTS_MAPPING) SET(CTEST_LABELS_FOR_SUBPROJECTS) FOREACH(TRIBITS_PACKAGE ${${PROJECT_NAME}_PACKAGES_TO_DIRECTLY_TEST}) @@ -621,7 +616,6 @@ ENDMACRO() # # Select the default generator. # - MACRO(SELECT_DEFAULT_GENERATOR) # When the build tree is known and exists, use # its generator. @@ -641,7 +635,6 @@ ENDMACRO() # # Call INITIALIZE_ERROR_QUEUE once at the top of TRIBITS_CTEST_DRIVER # - MACRO(INITIALIZE_ERROR_QUEUE) SET(TRIBITS_CTEST_DRIVER_ERROR_QUEUE "") ENDMACRO() @@ -658,7 +651,6 @@ ENDMACRO() # When adding more callers of QUEUE_ERROR, just make sure that it does not # duplicate an existing/reported dashboard failure. # - MACRO(QUEUE_ERROR err_msg) SET(TRIBITS_CTEST_DRIVER_ERROR_QUEUE ${TRIBITS_CTEST_DRIVER_ERROR_QUEUE} "${err_msg}") @@ -668,7 +660,6 @@ ENDMACRO() # # Call REPORT_QUEUED_ERRORS() once at the bottom of TRIBITS_CTEST_DRIVER() # - MACRO(REPORT_QUEUED_ERRORS) IF ("${TRIBITS_CTEST_DRIVER_ERROR_QUEUE}" STREQUAL "") MESSAGE("TRIBITS_CTEST_DRIVER_ERROR_QUEUE is empty. All is well.") @@ -685,7 +676,6 @@ ENDMACRO() # Override CTEST_SUBMIT to drive multiple submits and to detect failed # submissions and track them as queued errors. # - MACRO(TRIBITS_CTEST_SUBMIT) # Cache the original CTEST_DROP_SITE and CTEST_DROP_LOCATION diff --git a/tribits/ctest_driver/TribitsGetCTestTestXmlDir.cmake b/tribits/ctest_driver/TribitsGetCTestTestXmlDir.cmake new file mode 100644 index 000000000..edfab6d51 --- /dev/null +++ b/tribits/ctest_driver/TribitsGetCTestTestXmlDir.cmake @@ -0,0 +1,41 @@ +# +# cmake -P script to get the CTest testing XML directory +# /Testing/ given jus the directory path. +# +# Usage: +# +# cmake \ +# -DPROJECT_NAME= \ +# -D${PROJECT_NAME}_TRIBITS_DIR= \ +# -DCTEST_BUILD_DIR= \ +# -P /ctest_driver/TribitsGetCTestTestXmlDir.cmake +# +# This script reads in the /Testing/TAG to get and +# then prints the directory /Testing/ to STDOUT. +# + +IF ("${PROJECT_NAME}" STREQUAL "") + MESSAGE(FATAL_ERROR "Error, PROJECT_NAME must be set!") +ENDIF() + +IF ("${${PROJECT_NAME}_TRIBITS_DIR}" STREQUAL "") + MESSAGE(FATAL_ERROR "Error, ${PROJECT_NAME}_TRIBITS_DIR must be set!") +ENDIF() + +IF ("${CTEST_BUILD_DIR}" STREQUAL "") + MESSAGE(FATAL_ERROR "Error, CTEST_BUILD_DIR must be set!") +ENDIF() + +SET( CMAKE_MODULE_PATH + "${${PROJECT_NAME}_TRIBITS_DIR}/core/utils" + "${${PROJECT_NAME}_TRIBITS_DIR}/core/package_arch" + "${${PROJECT_NAME}_TRIBITS_DIR}/ctest_driver" + ) + +INCLUDE(TribitsReadTagFile) + +SET(TAG_FILE "${CTEST_BUILD_DIR}/Testing/TAG") + +TRIBITS_READ_CTEST_TAG_FILE("${TAG_FILE}" BUILD_START_TIME CDASH_TRACK) + +MESSAGE("${CTEST_BUILD_DIR}/Testing/${BUILD_START_TIME}") diff --git a/tribits/ctest_driver/TribitsReadTagFile.cmake b/tribits/ctest_driver/TribitsReadTagFile.cmake new file mode 100644 index 000000000..673d23ef1 --- /dev/null +++ b/tribits/ctest_driver/TribitsReadTagFile.cmake @@ -0,0 +1,16 @@ +INCLUDE(TribitsCMakePolicies) +INCLUDE(Split) + + +# +# Read in the /Testing/TAG file contents +# +# +FUNCTION(TRIBITS_READ_CTEST_TAG_FILE TAG_FILE_IN BUILD_START_TIME_OUT CDASH_TRACK_OUT) + FILE(READ "${TAG_FILE_IN}" TAG_FILE_STR) + SPLIT("${TAG_FILE_STR}" "\n" TAG_FILE_STR_LIST) + LIST(GET TAG_FILE_STR_LIST 0 BUILD_START_TIME) + LIST(GET TAG_FILE_STR_LIST 1 CDASH_TRACK) + SET(${BUILD_START_TIME_OUT} "${BUILD_START_TIME}" PARENT_SCOPE) + SET(${CDASH_TRACK_OUT} "${CDASH_TRACK}" PARENT_SCOPE) +ENDFUNCTION()