Skip to content

Commit

Permalink
[CMake] Use CTest module and optionally submit to CDash
Browse files Browse the repository at this point in the history
  • Loading branch information
amadio committed Feb 22, 2024
1 parent fdeab66 commit 12d8bee
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ defaults:
shell: bash

env:
CDASH: ${{ vars.CDASH }}
CMAKE_VERBOSE_MAKEFILE: true
CTEST_OUTPUT_ON_FAILURE: true

Expand Down
10 changes: 4 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ configure_file(src/XrdVersion.hh.in src/XrdVersion.hh)

include_directories(BEFORE ${CMAKE_SOURCE_DIR}/src ${CMAKE_BINARY_DIR}/src)

add_subdirectory( src )
add_subdirectory( bindings )
include(CTest)

if( BUILD_TESTS )
ENABLE_TESTING()
add_subdirectory( tests )
endif()
add_subdirectory(src)
add_subdirectory(bindings)
add_subdirectory(tests)

add_subdirectory(docs)
add_subdirectory(utils)
Expand Down
2 changes: 2 additions & 0 deletions CTestConfig.cmake
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
set(CTEST_PROJECT_NAME "XRootD")
set(CTEST_NIGHTLY_START_TIME "00:00:00 UTC")
set(CTEST_DROP_SITE_CDASH TRUE)
set(CTEST_SUBMIT_URL https://my.cdash.org/submit.php?project=XRootD)
12 changes: 10 additions & 2 deletions test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.16)

set(ENV{LANG} "C")
set(ENV{LC_ALL} "C")
set(CTEST_USE_LAUNCHERS TRUE)

macro(section title)
if (DEFINED ENV{CI})
Expand Down Expand Up @@ -171,6 +172,9 @@ section("Build")
ctest_build(RETURN_VALUE BUILD_RESULT)

if(NOT ${BUILD_RESULT} EQUAL 0)
if(CDASH OR (DEFINED ENV{CDASH} AND "$ENV{CDASH}"))
ctest_submit()
endif()
message(FATAL_ERROR "Build failed")
endif()

Expand All @@ -184,7 +188,7 @@ section("Test")
ctest_test(PARALLEL_LEVEL $ENV{CTEST_PARALLEL_LEVEL} RETURN_VALUE TEST_RESULT)

if(NOT ${TEST_RESULT} EQUAL 0)
message(FATAL_ERROR "Tests failed")
message(SEND_ERROR "Tests failed")
endif()
endsection()

Expand All @@ -196,7 +200,7 @@ if(DEFINED CTEST_COVERAGE_COMMAND)
${GCOVR} -r ${CTEST_SOURCE_DIRECTORY}/src ${CTEST_BINARY_DIRECTORY}
--html-details ${CTEST_BINARY_DIRECTORY}/html/ ERROR_VARIABLE ERROR)
if(ERROR)
message(FATAL_ERROR "Failed to generate coverage report")
message(SEND_ERROR "Failed to generate coverage report")
endif()
endif()
ctest_coverage()
Expand All @@ -208,3 +212,7 @@ if(DEFINED CTEST_MEMORYCHECK_COMMAND)
ctest_memcheck()
endsection()
endif()

if(CDASH OR (DEFINED ENV{CDASH} AND "$ENV{CDASH}"))
ctest_submit()
endif()
4 changes: 4 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
if(NOT BUILD_TESTS)
return()
endif()

include(GoogleTest)
add_subdirectory( XrdCl )
add_subdirectory(XrdHttpTests)
Expand Down

0 comments on commit 12d8bee

Please sign in to comment.