diff --git a/CbmRoot_test.cmake b/CbmRoot_test.cmake index 39eaa03d571f2de44caa86587421a0a5e9ac6a4e..2bf9c186d78e84888be00e0915ab8f7aa9b62e7e 100644 --- a/CbmRoot_test.cmake +++ b/CbmRoot_test.cmake @@ -73,9 +73,18 @@ unset(repeat) if(${_CMakeModel} MATCHES Continuous) if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.17) set(repeat REPEAT UNTIL_PASS:2) - endif() + endif() EndIf() +# The stop time should be a date compatible string without day nor timezone +# Examples: +# => CTEST_END_TIME_LIMIT=`date -d "${END_TIME}CET -5minutes" +"%H:%M:%S"` +# => CTEST_END_TIME_LIMIT=`date -d "now +25minutes" +"%H:%M:%S"` +unset(stop_time) +If(DEFINED ENV{CTEST_END_TIME_LIMIT}) + set(stop_time STOP_TIME "$ENV{CTEST_END_TIME_LIMIT}") + message(STATUS " End time for the ctest test runs set to ${stop_time}") +EndIf() If(NOT ${_BuildType} MATCHES Experimental) Ctest_Update(SOURCE "${CTEST_SOURCE_DIRECTORY}") @@ -113,6 +122,7 @@ If(NOT _RETVAL) Ctest_Test(BUILD "${CTEST_BINARY_DIRECTORY}" PARALLEL_LEVEL $ENV{number_of_processors} ${repeat} + ${stop_time} RETURN_VALUE _ctest_test_ret_val ) diff --git a/scripts/find_slurm_ctest_stop_time.sh b/scripts/find_slurm_ctest_stop_time.sh new file mode 100755 index 0000000000000000000000000000000000000000..c450f17a1aa68f247bbb7a279b57616a9df84ef3 --- /dev/null +++ b/scripts/find_slurm_ctest_stop_time.sh @@ -0,0 +1,47 @@ +#!/bin/bash +# Copyright (C) 2024 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt +# SPDX-License-Identifier: GPL-3.0-only +# First commited by Pierre-Alain Loizeau + +# Script used to compute a "safe" end time for the ctest test stage of a Dart/Cdash chain in order +# to have enough time to upload the CDASH results before a job is killed on a SLURM cluster (e.g. Virgo @ GSI) +# +# Usage: +# - with a full/relative/absolute path to an output Dart.cfg file as parameter, where the export will be added +# - without any parameter, then setting an export +# +# => Typical use case would be calling it in your sbatch script after setting up the other parts of the +# Dart.cfg gile and before the call to Dart.sh +#>> echo "export NCPU=10" >> ${DART_CFG} +#>> [...] +#>> ./scripts/find_slurm_ctest_stop_time.sh ${DART_CFG} +#>> [...] +#>> ./Dart.sh Weekly ./${DART_CFG} &> ${OUT_DIR}/Dart_weekly.log + +# SLURM end time +END_TIME=`squeue -j ${SLURM_JOB_ID} -h --Format EndTime` +echo "SLURM Job end time ${END_TIME}" + +# Ctest end time = SLURM -5 minutes (should be enough for coverage and uploads) +# => Not working as ctest expects the "time point in hours-minutes-seconds within current day" +# + hardcode the day/year/month to the current day... +# https://gitlab.kitware.com/cmake/cmake/-/blob/master/Help/manual/ctest.1.rst#L440 +# https://gitlab.kitware.com/cmake/cmake/-/blob/master/Source/cmCTest.cxx#L1991 +# https://gitlab.kitware.com/cmake/cmake/-/blob/master/Source/cmCTest.cxx#L3012 +# https://gitlab.kitware.com/cmake/cmake/-/blob/master/Source/CTest/cmCTestRunTest.cxx#L811 +# => Does not work for long running tests close to end of the day +# CTEST_END_TIME_LIMIT=`date -d "${END_TIME}CET -5minutes" +"%Y-%m-%d %H:%M:%S %z"` +# => But following should be ok for weeklies starting early in the morning +# => Does not work at least with cmake 3.22 and 3.24, seesm that timezone is breaking decoding +# (tried all timezone options of date, with and without space between time and timezone) +#CTEST_END_TIME_LIMIT=`date -d "${END_TIME}CET -5minutes" +"%H:%M:%S %z"` +# => Working! but probably unsafe on day of Summer time swaps + if tests run close to midnight... +CTEST_END_TIME_LIMIT=`date -d "${END_TIME}CET -5minutes" +"%H:%M:%S"` +echo "Setting the job time limit for ctest to ${CTEST_END_TIME_LIMIT} to make sure CDASH data is uploaded" + +if [[ $# -eq 1 ]]; then + # Set the export in the chosen Dart.cfg file + echo "export CTEST_END_TIME_LIMIT=\"${CTEST_END_TIME_LIMIT}\"" >> $1 +else + export CTEST_END_TIME_LIMIT=\"${CTEST_END_TIME_LIMIT}\" +fi