Skip to content

Commit

Permalink
WIP: Add TRIBITS_READ_CTEST_TAG_FILE() and TribitsGetCTestTestXmlDir.…
Browse files Browse the repository at this point in the history
…cmake (TriBITSPub#278, TriBITSPub#154)

This is needed to be able to read XML files out of the
<bulid>/Testing/<buildstarttime>/ directory needed for (TriBITSPub#278)

This will also make it easy to generate a CDash URL without knowing the build
ID.
  • Loading branch information
bartlettroscoe committed Feb 18, 2019
1 parent d46448c commit 4e82eb3
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 10 deletions.
28 changes: 28 additions & 0 deletions test/ctest_driver/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
89 changes: 89 additions & 0 deletions test/ctest_driver/CTestDriverUnitTests.cmake
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions test/ctest_driver/data/dummy_build_dir/Testing/TAG
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
20101015-1112
My CDash Track
10 changes: 0 additions & 10 deletions tribits/ctest_driver/TribitsCTestDriverCoreHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -390,7 +388,6 @@ ENDMACRO()
#
# Select only packages that are modified or failed in the last CI iteration
#

MACRO(ENABLE_ONLY_MODIFIED_PACKAGES)

#
Expand Down Expand Up @@ -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} ...")
Expand Down Expand Up @@ -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})
Expand All @@ -621,7 +616,6 @@ ENDMACRO()
#
# Select the default generator.
#

MACRO(SELECT_DEFAULT_GENERATOR)
# When the build tree is known and exists, use
# its generator.
Expand All @@ -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()
Expand All @@ -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}")
Expand All @@ -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.")
Expand All @@ -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
Expand Down
41 changes: 41 additions & 0 deletions tribits/ctest_driver/TribitsGetCTestTestXmlDir.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#
# cmake -P script to get the CTest testing XML directory
# <build>/Testing/<buildstarttime> given jus the <bulid> directory path.
#
# Usage:
#
# cmake \
# -DPROJECT_NAME=<projectName> \
# -D${PROJECT_NAME}_TRIBITS_DIR=<tribits-dir> \
# -DCTEST_BUILD_DIR=<build-dir> \
# -P <tribits-dir>/ctest_driver/TribitsGetCTestTestXmlDir.cmake
#
# This script reads in the <build-dir>/Testing/TAG to get <bulidstarttime> and
# then prints the directory <build>/Testing/<buildstarttime> 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}")
16 changes: 16 additions & 0 deletions tribits/ctest_driver/TribitsReadTagFile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
INCLUDE(TribitsCMakePolicies)
INCLUDE(Split)


#
# Read in the <build>/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()

0 comments on commit 4e82eb3

Please sign in to comment.