From d28adb49fde76dcde757d48ad0f9f77f1c1c63a3 Mon Sep 17 00:00:00 2001
From: Florian Uhlig <f.uhlig@gsi.de>
Date: Tue, 2 Nov 2021 17:34:44 +0100
Subject: [PATCH] Use different test cases with CMake variable

Before the change it was necessary to define an environment variable to switch
between different test suites like for example the Experimental or Nightly
tests. Now the test suites are chosen by the CMake command line parameter
CBM_TEST_MODEL. These are Experimental, Nightly and Weekly which differ by the
number of executed tests.
---
 CMakeLists.txt              |  6 +++
 CbmRoot_test.cmake          | 73 +++++++++++++------------------------
 Dart.sh                     |  6 ++-
 macro/C2F/CMakeLists.txt    | 11 ++++--
 macro/CMakeLists.txt        |  9 ++---
 macro/dimuon/CMakeLists.txt |  4 +-
 macro/mcbm/CMakeLists.txt   |  6 +--
 macro/run/CMakeLists.txt    |  4 +-
 8 files changed, 53 insertions(+), 66 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index ec7201d313..40da32e7cb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -394,6 +394,12 @@ add_subdirectory (analysis)
 add_subdirectory (mvd)
 
 ### Others
+Option(LARGE_TEST_STATISTIC "Run the test suite with large statistic (100 events)" OFF)
+
+if(NOT CBM_TEST_MODEL)
+  set(CBM_TEST_MODEL Experimental)
+endif()
+
 add_subdirectory (macro)
 add_subdirectory(fles)
 If(FAIRMQ_FOUND)
diff --git a/CbmRoot_test.cmake b/CbmRoot_test.cmake
index 77819779a2..4565b64457 100644
--- a/CbmRoot_test.cmake
+++ b/CbmRoot_test.cmake
@@ -6,6 +6,10 @@ Set(CTEST_CMAKE_GENERATOR "Unix Makefiles")
 Set(CTEST_PROJECT_NAME "CBMROOT")
 Set(EXTRA_FLAGS $ENV{EXTRA_FLAGS})
 
+if(NOT CBM_TEST_MODEL)
+  set(CBM_TEST_MODEL NIGHTLY)
+endif()
+
 include(${CTEST_SOURCE_DIRECTORY}/CTestConfig.cmake)
 Ctest_Read_Custom_Files("${CTEST_SOURCE_DIRECTORY}")
 
@@ -27,21 +31,26 @@ Else()
   Set(CTEST_USE_LAUNCHERS 1)
 EndIf()
 
-If($ENV{ctest_model} MATCHES Weekly)
-  Set(_Model PROFILE)
-ElseIf($ENV{ctest_model} MATCHES MergeRequest)
-  Set(_Model CONTINUOUS)
+
+If(${CBM_TEST_MODEL} MATCHES MergeRequest OR ${CBM_TEST_MODEL} MATCHES Continuous)
+  Set(_BuildType NIGHTLY)
+  Set(_CMakeModel Continuous)
+elseIf(${CBM_TEST_MODEL} MATCHES Weekly OR ${CBM_TEST_MODEL} MATCHES Profile)
+  Set(_BuildType PROFILE)
+  Set(_CMakeModel Nightly)
 Else()
-  String(TOUPPER $ENV{ctest_model} _Model)
+  String(TOUPPER ${CBM_TEST_MODEL} _BuildType)
+  set(_CMakeModel ${CBM_TEST_MODEL})
 EndIf()
 
 If(EXTRA_FLAGS)
-  Set(CTEST_CONFIGURE_COMMAND " \"${CMAKE_EXECUTABLE_NAME}\" \"-G${CTEST_CMAKE_GENERATOR}\" \"-DCMAKE_BUILD_TYPE=${_Model}\" \"-DCTEST_USE_LAUNCHERS=${CTEST_USE_LAUNCHERS}\" \"${EXTRA_FLAGS}\" \"${CTEST_SOURCE_DIRECTORY}\" ")
+  Set(CTEST_CONFIGURE_COMMAND " \"${CMAKE_EXECUTABLE_NAME}\" \"-G${CTEST_CMAKE_GENERATOR}\" \"-DCMAKE_BUILD_TYPE=${_BuildType}\" \"-DCTEST_USE_LAUNCHERS=${CTEST_USE_LAUNCHERS}\" \"${EXTRA_FLAGS}\" \"${CTEST_SOURCE_DIRECTORY}\" ")
 Else()
-  Set(CTEST_CONFIGURE_COMMAND " \"${CMAKE_EXECUTABLE_NAME}\" \"-G${CTEST_CMAKE_GENERATOR}\" \"-DCMAKE_BUILD_TYPE=${_Model}\" \"-DCTEST_USE_LAUNCHERS=${CTEST_USE_LAUNCHERS}\" \"${CTEST_SOURCE_DIRECTORY}\" ")
+  Set(CTEST_CONFIGURE_COMMAND " \"${CMAKE_EXECUTABLE_NAME}\" \"-G${CTEST_CMAKE_GENERATOR}\" \"-DCMAKE_BUILD_TYPE=${_BuildType}\" \"-DCTEST_USE_LAUNCHERS=${CTEST_USE_LAUNCHERS}\" \"${CTEST_SOURCE_DIRECTORY}\" ")
 EndIf()
 
-If($ENV{ctest_model} MATCHES Nightly OR $ENV{ctest_model} MATCHES Weekly OR $ENV{ctest_model} MATCHES Profile)
+#If(${CBM_TEST_MODEL} MATCHES Nightly OR ${CBM_TEST_MODEL} MATCHES Weekly OR ${CBM_TEST_MODEL} MATCHES Profile)
+If(NOT ${_BuildType} MATCHES Experimental)
 
   Find_Program(GCOV_COMMAND gcov)
   If(GCOV_COMMAND)
@@ -49,61 +58,31 @@ If($ENV{ctest_model} MATCHES Nightly OR $ENV{ctest_model} MATCHES Weekly OR $ENV
     Set(CTEST_COVERAGE_COMMAND ${GCOV_COMMAND})
   EndIf(GCOV_COMMAND)
 
-  If(NOT $ENV{ctest_model} MATCHES Weekly)
-    Set(ENV{ctest_model} Nightly)
-  EndIf()
-
-  # get the information about conflicting or localy modified files
-  # from svn, extract the relavant information about the file name
-  # and put the result in the output variable
-  If(EXISTS ${CTEST_SOURCE_DIRECTORY}/.svn)
-    Execute_Process(COMMAND svn stat -u
-                    COMMAND grep ^[CM]
-                    COMMAND cut -c21-
-                    OUTPUT_VARIABLE FILELIST
-                    )
-
-    # create out of the output a cmake list. This step is done to convert the
-    # stream into seperated filenames.
-    # The trick is to exchange an "\n" by an ";" which is the separartor in
-    # a list created by cmake
-    String(REGEX REPLACE "\n" ";" _result "${FILELIST}")
-
-    ForEach(_file ${_result})
-      String(STRIP "${_file}" _file1)
-      Set(CTEST_NOTES_FILES ${CTEST_NOTES_FILES} "${CTEST_SOURCE_DIRECTORY}/${_file1}")
-    EndForEach(_file ${_result})
-  EndIf()
-
   CTEST_EMPTY_BINARY_DIRECTORY(${CTEST_BINARY_DIRECTORY})
 
 EndIf()
 
-If($ENV{ctest_model} MATCHES MergeRequest)
-  set(ENV{ctest_model} Continuous)
-EndIf()
-
-Ctest_Start($ENV{ctest_model})
+Ctest_Start(${_CMakeModel})
 
 unset(repeat)
-If($ENV{ctest_model} MATCHES Continuous)
+If(${CBM_TEST_MODEL} MATCHES MergeRequest OR ${CBM_TEST_MODEL} MATCHES Continuous)
   if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.17)
     set(repeat REPEAT UNTIL_PASS:2)
-  endif()
-  set(ENV{ctest_model} Nightly)
+  endif()        
 EndIf()
 
 
-If(NOT $ENV{ctest_model} MATCHES Experimental)
+If(NOT ${_BuildType} MATCHES Experimental)
   Ctest_Update(SOURCE "${CTEST_SOURCE_DIRECTORY}")
 EndIf()
 
 Ctest_Configure(BUILD "${CTEST_BINARY_DIRECTORY}"
                 RETURN_VALUE _RETVAL
 )
+
 If(NOT _RETVAL)
   Ctest_Build(BUILD "${CTEST_BINARY_DIRECTORY}")
-  If($ENV{ctest_model} MATCHES Continuous)
+  If(${_CMakeModel} MATCHES Continuous)
     If(${CMAKE_VERSION} VERSION_LESS 3.14.0)
       CTest_Submit(PARTS Update Configure Build)
     Else()
@@ -119,7 +98,7 @@ If(NOT _RETVAL)
              RETURN_VALUE _ctest_test_ret_val
             )
 
-  If($ENV{ctest_model} MATCHES Continuous)
+  If(${_CMakeModel} MATCHES Continuous)
     If(${CMAKE_VERSION} VERSION_LESS 3.14.0)
       CTest_Submit(PARTS Test)
     Else()
@@ -131,7 +110,7 @@ If(NOT _RETVAL)
 
   If(GCOV_COMMAND)
     Ctest_Coverage(BUILD "${CTEST_BINARY_DIRECTORY}")
-    If($ENV{ctest_model} MATCHES Continuous)
+    If(${_CMakeModel} MATCHES Continuous)
       If(${CMAKE_VERSION} VERSION_LESS 3.14.0)
         CTest_Submit(PARTS Coverage)
       Else()
@@ -143,7 +122,7 @@ If(NOT _RETVAL)
   EndIf()
 
   Ctest_Upload(FILES ${CTEST_NOTES_FILES})
-  If(NOT $ENV{ctest_model} MATCHES Continuous)
+  If(NOT ${_CMakeModel} MATCHES Continuous)
     If(${CMAKE_VERSION} VERSION_LESS 3.14.0)
       Ctest_Submit()
     Else()
diff --git a/Dart.sh b/Dart.sh
index 0bda08a973..4af49c69bc 100755
--- a/Dart.sh
+++ b/Dart.sh
@@ -65,7 +65,8 @@ else
 fi
 
 # set the ctest model to command line parameter
-export ctest_model=$1
+#export ctest_model=$1
+ctest_model=$1
 
 # test for architecture
 arch=$(uname -s | tr '[A-Z]' '[a-z]')
@@ -128,4 +129,5 @@ echo "************************"
 
 cd $SOURCEDIR
 
-ctest -S $SOURCEDIR/CbmRoot_test.cmake -V --VV 
+ctest -S $SOURCEDIR/CbmRoot_test.cmake -V --VV -DCBM_TEST_MODEL=${ctest_model}
+#ctest -S $SOURCEDIR/CbmRoot_test.cmake -V --VV
diff --git a/macro/C2F/CMakeLists.txt b/macro/C2F/CMakeLists.txt
index 0f60dbcd39..8801c61f22 100644
--- a/macro/C2F/CMakeLists.txt
+++ b/macro/C2F/CMakeLists.txt
@@ -12,14 +12,17 @@ GENERATE_CBM_TEST_SCRIPT(${CBMROOT_SOURCE_DIR}/macro/analysis/common/qa/run_anal
 File(COPY ${CBMROOT_SOURCE_DIR}/macro/include/.rootrc DESTINATION ${MACRO_DIR})
 File(COPY ${CBMROOT_SOURCE_DIR}/macro/C2F/sis100_electron.tree.list DESTINATION ${MACRO_DIR})
 
-
 # Define the number of events to run
-Set(NumEvents 20)
+if(LARGE_TEST_STATISTIC)
+  Set(NumEvents 100)
+else()
+  Set(NumEvents 20)
+endif()
 
 # Define the different setups to be tested
-If( ($ENV{ctest_model} MATCHES Nightly) OR ($ENV{ctest_model} MATCHES Weekly) )
+#If( ${CBM_TEST_MODEL} MATCHES Nightly OR ${CBM_TEST_MODEL} MATCHES Weekly )
   List(APPEND cbm_setup sis100_electron)
-EndIf()
+#EndIf()
 
   ForEach(setup IN LISTS cbm_setup)
 
diff --git a/macro/CMakeLists.txt b/macro/CMakeLists.txt
index 0660b39888..c6815af251 100644
--- a/macro/CMakeLists.txt
+++ b/macro/CMakeLists.txt
@@ -7,19 +7,16 @@ add_subdirectory(include)
 
 
 #--- Additional tests for nightly builds
-If($ENV{ctest_model} MATCHES Nightly)
+If(NOT ${CBM_TEST_MODEL} MATCHES Experimental)
   add_subdirectory(field)
   add_subdirectory(C2F)
   add_subdirectory(dimuon)
   Message("Additional Nightly tests")
-EndIf($ENV{ctest_model}  MATCHES Nightly)
+EndIf()
 
 #--- Additional tests for weekly builds
-If($ENV{ctest_model} MATCHES Weekly)
+If(${CBM_TEST_MODEL} MATCHES Weekly)
   add_subdirectory(KF)
-  add_subdirectory(field)
-  add_subdirectory(C2F)
-  add_subdirectory(dimuon)
   Message("Additional long running Weekly tests")
 EndIf()
 
diff --git a/macro/dimuon/CMakeLists.txt b/macro/dimuon/CMakeLists.txt
index 5b4763debd..68f6934170 100644
--- a/macro/dimuon/CMakeLists.txt
+++ b/macro/dimuon/CMakeLists.txt
@@ -15,7 +15,7 @@ File(COPY ${CBMROOT_SOURCE_DIR}/parameters/much/TOF8gev_fitParam_sigma2.sis100_m
 Set(NumEvents 1000)
 
 # Define the different setups to be tested
-If( ($ENV{ctest_model} MATCHES Nightly) OR ($ENV{ctest_model} MATCHES Weekly) )
+#If( ($ENV{ctest_model} MATCHES Nightly) OR ($ENV{ctest_model} MATCHES Weekly) )
   List(APPEND cbm_setup sis100_muon_lmvm)
 
   ForEach(setup IN LISTS cbm_setup)
@@ -70,7 +70,7 @@ If( ($ENV{ctest_model} MATCHES Nightly) OR ($ENV{ctest_model} MATCHES Weekly) )
   
   EndForEach(setup IN LISTS cbm_setup)
   # end of test CBM setups from geometry/setup
-EndIf()
+#EndIf()
 
 # Installation of macros is done in macro/CMakeLists.txt to install the
 # macros even if the tests are not executed
diff --git a/macro/mcbm/CMakeLists.txt b/macro/mcbm/CMakeLists.txt
index 1f6090530f..0729662a3b 100644
--- a/macro/mcbm/CMakeLists.txt
+++ b/macro/mcbm/CMakeLists.txt
@@ -27,7 +27,7 @@ Set(BeamAngle 25)
 # additional ones for current/future setups should also be added to the CI tests
 # Old ones may be tested in addition for nightly/weekly to ensure backward compatibility
 # Nightly if for now not different from CI so the "extras" are used only in Weekly
-If( ($ENV{ctest_model} MATCHES Weekly) )
+If(${CBM_TEST_MODEL} MATCHES Weekly)
   List(APPEND cbm_setup mcbm_beam_2021_07_surveyed) # Default
   List(APPEND cbm_setup mcbm_beam_2022_02 mcbm_beam_2022_03 mcbm_beam_2022_04 mcbm_beam_2022_05) # Non-default current/future setups
   List(APPEND cbm_setup mcbm_beam_2020_03 mcbm_beam_2021_03) # Legacy
@@ -113,13 +113,13 @@ ForEach(setup IN LISTS cbm_setup)
   Set(fixture_overlap fixture_overlap_${setup})
   set_tests_properties(${testname} PROPERTIES FIXTURES_SETUP ${fixture_overlap})
 
-  If( ($ENV{ctest_model} MATCHES Nightly) OR ($ENV{ctest_model} MATCHES Weekly) )
+#  If( ($ENV{ctest_model} MATCHES Nightly) OR ($ENV{ctest_model} MATCHES Weekly) )
     Set(testname mcbm_check_media_${setup})
     Add_Test(${testname} ${CBMROOT_BINARY_DIR}/macro/mcbm/check_media.sh \"data/${setup}_test\")
     Set_Tests_Properties(${testname} PROPERTIES TIMEOUT "60")
     Set_Tests_Properties(${testname} PROPERTIES PASS_REGULAR_EXPRESSION "Test Passed;All ok")
     set_tests_properties(${testname} PROPERTIES FIXTURES_REQUIRED ${fixture_overlap})
-  EndIf()
+#  EndIf()
 
 EndForEach(setup IN LISTS cbm_setup)
 
diff --git a/macro/run/CMakeLists.txt b/macro/run/CMakeLists.txt
index 6bdbdbec37..f5ad10da58 100644
--- a/macro/run/CMakeLists.txt
+++ b/macro/run/CMakeLists.txt
@@ -17,7 +17,7 @@ file(COPY ${CBMROOT_SOURCE_DIR}/macro/include/.rootrc
 
 
 # =====   Define variables for tests   =======================================
-if($ENV{ctest_model} MATCHES Weekly)
+if(${CBM_TEST_MODEL} MATCHES Weekly)
   Set(nEvents 100)
   Set(uploadHistJPG 1)
   Set(pullDevAllowed .2)
@@ -35,7 +35,7 @@ math(EXPR nBeam "${nEvents} * 3")
 
 
 # =====   Define the different setups to be tested with   ====================
-if(($ENV{ctest_model} MATCHES Nightly) OR ($ENV{ctest_model} MATCHES Weekly))
+if(NOT ${CBM_TEST_MODEL} MATCHES Experimental )
   List(APPEND cbm_setup sis100_hadron sis100_electron sis100_muon_lmvm
   	sis100_muon_jpsi sis300_electron)
 else()
-- 
GitLab