From 6f2aa6ca6cdae0ff0d5d708d433b32a65191ca49 Mon Sep 17 00:00:00 2001
From: Ralf Ulrich <ralf.ulrich@kit.edu>
Date: Mon, 27 May 2019 23:12:04 +0200
Subject: [PATCH] CI

---
 .gitlab-ci.yml                               | 189 ++++++++++++++++---
 CMakeLists.txt                               |  17 +-
 CMakeModules/CorsikaUtilities.cmake          |   2 +-
 Environment/BaseExponential.h                |   3 +-
 Environment/SlidingPlanarExponential.h       |   3 +-
 Framework/ProcessSequence/ProcessSequence.h  |   6 +-
 Framework/Utilities/sgn.h                    |  11 ++
 Processes/CMakeLists.txt                     |   1 -
 Processes/Pythia/testPythia.cc               |   4 +-
 Processes/SwitchProcess/SwitchProcess.h      |   2 +-
 Processes/SwitchProcess/testSwitchProcess.cc |   2 +-
 Processes/UrQMD/UrQMD.cc                     |   2 +-
 Processes/UrQMD/UrQMD.h                      |   2 +-
 Processes/UrQMD/testUrQMD.cc                 |   3 +-
 14 files changed, 200 insertions(+), 47 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 438378738..818e8e242 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,5 +1,3 @@
-image: corsika/devel:u-18.04
-
 variables:
   GIT_SSL_NO_VERIFY: "1"
   ## Runtime options for sanitizers
@@ -9,60 +7,201 @@ variables:
   LSAN_OPTIONS: "log_threads=1"
   ASAN_OPTIONS: "detect_leaks=0:detect_stack_use_after_return=1"
 
-build: # normal pipeline for each commit, except for commits to the master
-  stage: build
+# normal multi-step pipeline for each commit
+stages:
+  - config
+  - build
+  - test
+  - release
+  - optional
+
+# job/stage to just prepare cmake
+config-u-18_04:
+  image: corsika/devel:u-18.04
+  stage: config
+  tags:
+    - corsika
+  script:
+    - mkdir build
+    - cd build
+    - cmake .. -DCMAKE_BUILD_TYPE=Debug -DWITH_PYTHIA=ON
+  artifacts:
+    expire_in: 1 day
+    paths:
+       - build
+  except:
+    - master
+
+# job/stage to just prepare cmake
+config-clang-8:
+  image: corsika/devel:clang-8
+  stage: config
   tags:
     - corsika
   script:
     - mkdir build
     - cd build
-    - cmake .. -DCMAKE_BUILD_TYPE=Debug
+    - cmake .. -DCMAKE_BUILD_TYPE=Debug -DWITH_PYTHIA=ON
+  artifacts:
+    expire_in: 1 day
+    paths:
+       - build
+  except:
+    - master
+
+# normal pipeline for each commit
+build-u-18_04: 
+  image: corsika/devel:u-18.04
+  dependencies:
+    - config-u-18_04
+  stage: build
+  tags:
+    - corsika
+  script:
+    - cd build
     - cmake --build . -- -j4
-    - ctest -j4 -V >& test.log || gzip -v -9 -S .gz test.log
   artifacts:
-    expire_in: 1 year
+    expire_in: 1 day
+    paths:
+       - build
+
+# normal pipeline for each commit
+build-clang-8: 
+  image: corsika/devel:clang-8
+  dependencies:
+    - config-clang-8
+  stage: build
+  tags:
+    - corsika
+  script:
+    - cd build
+    - cmake --build . -- -j4
+  artifacts:
+    expire_in: 1 day
+    paths:
+       - build
+
+test-u-18_04: 
+  image: corsika/devel:u-18.04
+  dependencies:
+    - build-u-18_04
+  stage: test
+  tags:
+    - corsika
+  script:
+    - set -o pipefail
+    - cd build
+    - ctest -VV | gzip -v -9 > test.log.gz 
+  artifacts:
+    expire_in: 3 months
+    reports:
+      junit:
+        - build/test_outputs/junit*.xml
     paths:
       - build/test.log.gz
+
+test-clang-8: 
+  image: corsika/devel:clang-8
+  dependencies:
+    - build-clang-8
+  stage: test
+  tags:
+    - corsika
+  script:
+    - set -o pipefail
+    - cd build
+    - ctest -VV | gzip -v -9 > test.log.gz 
+  artifacts:
+    expire_in: 3 months
     reports:
       junit:
         - build/test_outputs/junit*.xml
-  except:
-    - master
+    paths:
+      - build/test.log.gz
 
-coverage: # special pipeline for master with coverage report
-  stage: build
+# normal pipeline for each commit
+release-u-18_04: 
+  image: corsika/devel:u-18.04
+  dependencies:
+    - config-u-18_04
+  stage: optional
   tags:
     - corsika
   script:
-    - mkdir -p build
     - cd build
-    - cmake .. -DCMAKE_BUILD_TYPE=Coverage
+    - cmake .. -DCMAKE_BUILD_TYPE=Release
     - cmake --build . -- -j4
     - ctest -j4 
-    - cmake --build . --target coverage && tar czf coverage-report.tar.gz coverage-report
+  when: manual    
+
+# normal pipeline for each commit
+release-clang-8: 
+  image: corsika/devel:clang-8
+  dependencies:
+    - config-clang-8
+  stage: optional
+  tags:
+    - corsika
+  script:
+    - cd build
+    - cmake .. -DCMAKE_BUILD_TYPE=Release
+    - cmake --build . -- -j4
+    - ctest -j4 
+  when: manual    
+
+coverage: # special manual job to run after normal pipeline finished 
+  image: corsika/devel:u-18.04
+  dependencies:
+    - config-u-18_04
+  stage: optional
+  tags:
+    - corsika
+  script:
+    - cd build
+    - cmake .. -DCMAKE_BUILD_TYPE=Coverage
+    - cmake --build . -- -j4
+    - ctest -j4 -V > test.log 
+    - cmake --build . --target coverage
+    - tar czf coverage-report.tar.gz coverage-report
+  coverage: '/functions.*\s+(\d+\%)\s/'
   artifacts:
     expire_in: 1 year
     paths:
       - build/coverage-report.tar.gz
-  only:
-    - master
+  when: manual    
+  allow_failure: true
 
-pages:
-  stage: build
+documentation:
+  image: corsika/devel:u-18.04
+  dependencies:
+    - build-u-18_04
+  stage: optional
   tags:
     - corsika
   script:
-    - mkdir build
     - cd build
-    - cmake ..
-    - cmake --build . --target doxygen
+    - cmake --build . --target doxygen -- -j4
     - mkdir .public
     - cp -r Documentation/Doxygen/html .public/
     - mv .public ../public
   artifacts:
+    expire_in: 3 months
     paths:
       - public
-  only:
-    - tags
-    - triggers
-    - schedules
+  when: manual
+  allow_failure: true
+
+sanity:
+  image: corsika/devel:u-18.04
+  dependencies:
+    - config-u-18_04
+  stage: optional
+  tags:
+    - corsika
+  script:
+    - cd build
+    - cmake .. -DWITH_CORSIKA_SANITIZERS_ENABLED=ON
+    - cmake --build . -- -j4
+  when: manual
+  allow_failure: true
+
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ade8b5911..cf20efb46 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -18,12 +18,14 @@ project (
 # as long as there still are modules using it:
 enable_language (Fortran)
 
+# TEMPORARY: this should be removed, the sanitizers should be always enabled
+option (WITH_CORSIKA_SANITIZERS_ENABLED "temporary way to globally disable sanitizers until the currently failing tests are fixed" OFF)
+option (WITH_PYTHIA "flag to switch on/off pythia support" OFF)
+option (WITH_COAST "flag to switch on/off COAST (reverse) interface" OFF)
+
 # ignore many irrelevant Up-to-date messages during install
 set (CMAKE_INSTALL_MESSAGE LAZY)
 
-# TEMPORARY: this should be removed, the sanitizers should be always enabled
-option(CORSIKA_SANITIZERS_ENABLED "temporary way to globally disable sanitizers until the currently failing tests are fixed" OFF)
-
 # directory for local cmake modules
 set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules)
 include (CorsikaUtilities) # a few cmake function
@@ -105,7 +107,7 @@ if (CMAKE_BUILD_TYPE STREQUAL Coverage)
     COMMAND ${LCOV_BIN_DIR}/genhtml coverage.info -o coverage-report
     DEPENDS coverage.info
     )
-  add_custom_target(coverage DEPENDS coverage-report)
+  add_custom_target (coverage DEPENDS coverage-report)
 endif ()
 
 # add call to ./do-copyright.py to run as unit-test-case
@@ -114,12 +116,13 @@ add_test (NAME copyright_notices COMMAND ./do-copyright.py WORKING_DIRECTORY ${C
 # add call to do-clang-format.sh checking to run as unit-test-case
 add_test (NAME clang_format COMMAND ./do-clang-format.sh check WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
 
-find_package (Pythia8) # optional
+if (WITH_PYTHIA)
+  find_package (Pythia8) # optional
+endif (WITH_PYTHIA)
 find_package (Eigen3 REQUIRED)
 
 # order of subdirectories
 add_subdirectory (ThirdParty)
-#add_subdirectory (Utilities)
 add_subdirectory (Framework)
 add_subdirectory (Environment)
 add_subdirectory (Stack)
@@ -130,4 +133,4 @@ add_subdirectory (Main)
 add_subdirectory (Tools)
 if (WITH_COAST)
   add_subdirectory (COAST)
-endif()
+endif ()
diff --git a/CMakeModules/CorsikaUtilities.cmake b/CMakeModules/CorsikaUtilities.cmake
index ad853b8d1..abe8e4a76 100644
--- a/CMakeModules/CorsikaUtilities.cmake
+++ b/CMakeModules/CorsikaUtilities.cmake
@@ -151,5 +151,5 @@ function (CORSIKA_ADD_TEST)
     target_compile_options(${name} PRIVATE -O1 -fno-omit-frame-pointer -fsanitize=${sanitize} -fno-sanitize-recover=all)
     set_target_properties(${name} PROPERTIES LINK_FLAGS "-fsanitize=${sanitize}")
   endif()
-  add_test (NAME ${name} COMMAND ${name} -o ${PROJECT_BINARY_DIR}/test_outputs/junit-${name}.xml -r junit)
+  add_test (NAME ${name} COMMAND ${name} -o ${PROJECT_BINARY_DIR}/test_outputs/junit-${name}.xml -s -r junit)
 endfunction (CORSIKA_ADD_TEST)
diff --git a/Environment/BaseExponential.h b/Environment/BaseExponential.h
index 15585b6af..462c73c26 100644
--- a/Environment/BaseExponential.h
+++ b/Environment/BaseExponential.h
@@ -1,5 +1,6 @@
+
 /*
- * (c) Copyright 2019 CORSIKA Project, corsika-project@lists.kit.edu
+ * (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu
  *
  * See file AUTHORS for a list of contributors.
  *
diff --git a/Environment/SlidingPlanarExponential.h b/Environment/SlidingPlanarExponential.h
index 3cffa3afb..71f8e27d9 100644
--- a/Environment/SlidingPlanarExponential.h
+++ b/Environment/SlidingPlanarExponential.h
@@ -1,5 +1,6 @@
+
 /*
- * (c) Copyright 2019 CORSIKA Project, corsika-project@lists.kit.edu
+ * (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu
  *
  * See file AUTHORS for a list of contributors.
  *
diff --git a/Framework/ProcessSequence/ProcessSequence.h b/Framework/ProcessSequence/ProcessSequence.h
index bb8bb061f..8116966d1 100644
--- a/Framework/ProcessSequence/ProcessSequence.h
+++ b/Framework/ProcessSequence/ProcessSequence.h
@@ -60,12 +60,12 @@ namespace corsika::process {
   template <typename T>
   struct is_switch_process : std::false_type {};
 
-  template <typename A, typename B>
-  struct is_switch_process<switch_process::SwitchProcess<A, B>> : std::true_type {};
-
   template <typename T>
   bool constexpr is_switch_process_v = is_switch_process<T>::value;
 
+  template <typename A, typename B>
+  struct is_process_sequence<switch_process::SwitchProcess<A, B>> : std::true_type {};
+
   /**
      T1 and T2 are both references if possible (lvalue), otherwise
      (rvalue) they are just classes. This allows us to handle both,
diff --git a/Framework/Utilities/sgn.h b/Framework/Utilities/sgn.h
index 43d9a9fad..b0084ee04 100644
--- a/Framework/Utilities/sgn.h
+++ b/Framework/Utilities/sgn.h
@@ -1,3 +1,14 @@
+
+/*
+ * (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu
+ *
+ * See file AUTHORS for a list of contributors.
+ *
+ * This software is distributed under the terms of the GNU General Public
+ * Licence version 3 (GPL Version 3). See file LICENSE for a full version of
+ * the license.
+ */
+
 #ifndef _utilities_sgn_h
 #define _utilities_sgn_h
 
diff --git a/Processes/CMakeLists.txt b/Processes/CMakeLists.txt
index a9e52d9e8..e3057e2db 100644
--- a/Processes/CMakeLists.txt
+++ b/Processes/CMakeLists.txt
@@ -12,7 +12,6 @@ add_subdirectory (UrQMD)
 add_subdirectory (SwitchProcess)
 add_subdirectory (ParticleCut)
 
-#add_custom_target(CORSIKAprocesses)
 add_library (CORSIKAprocesses INTERFACE)
 add_dependencies(CORSIKAprocesses ProcessNullModel)
 add_dependencies(CORSIKAprocesses ProcessSibyll)
diff --git a/Processes/Pythia/testPythia.cc b/Processes/Pythia/testPythia.cc
index caeb19328..6e35b89df 100644
--- a/Processes/Pythia/testPythia.cc
+++ b/Processes/Pythia/testPythia.cc
@@ -98,7 +98,6 @@ TEST_CASE("pythia process") {
 
   // setup environment, geometry
   environment::Environment<environment::IMediumModel> env;
-  auto& universe = *(env.GetUniverse());
 
   geometry::CoordinateSystem const& cs = env.GetCoordinateSystem();
 
@@ -115,7 +114,6 @@ TEST_CASE("pythia process") {
           std::vector<float>{1.}));
 
   auto const* nodePtr = theMedium.get(); // save the medium for later use before moving it
-  universe.AddChild(std::move(theMedium));
 
   SECTION("pythia decay") {
 
@@ -141,7 +139,7 @@ TEST_CASE("pythia process") {
 
     process::pythia::Decay model(particleList);
     model.Init();
-    /*[[maybe_unused]] const process::EProcessReturn ret =*/model.DoDecay(projectile);
+    model.DoDecay(projectile);
     [[maybe_unused]] const TimeType time = model.GetLifetime(particle);
   }
 
diff --git a/Processes/SwitchProcess/SwitchProcess.h b/Processes/SwitchProcess/SwitchProcess.h
index 4a251b360..b217af0a5 100644
--- a/Processes/SwitchProcess/SwitchProcess.h
+++ b/Processes/SwitchProcess/SwitchProcess.h
@@ -1,5 +1,5 @@
 /*
- * (c) Copyright 2019 CORSIKA Project, corsika-project@lists.kit.edu
+ * (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu
  *
  * See file AUTHORS for a list of contributors.
  *
diff --git a/Processes/SwitchProcess/testSwitchProcess.cc b/Processes/SwitchProcess/testSwitchProcess.cc
index be3ced44f..b66b90bb5 100644
--- a/Processes/SwitchProcess/testSwitchProcess.cc
+++ b/Processes/SwitchProcess/testSwitchProcess.cc
@@ -1,5 +1,5 @@
 /*
- * (c) Copyright 2019 CORSIKA Project, corsika-project@lists.kit.edu
+ * (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu
  *
  * See file AUTHORS for a list of contributors.
  *
diff --git a/Processes/UrQMD/UrQMD.cc b/Processes/UrQMD/UrQMD.cc
index fba5dc183..1258c2632 100644
--- a/Processes/UrQMD/UrQMD.cc
+++ b/Processes/UrQMD/UrQMD.cc
@@ -1,5 +1,5 @@
 /*
- * (c) Copyright 2019 CORSIKA Project, corsika-project@lists.kit.edu
+ * (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu
  *
  * See file AUTHORS for a list of contributors.
  *
diff --git a/Processes/UrQMD/UrQMD.h b/Processes/UrQMD/UrQMD.h
index bdbca146e..ea2526b91 100644
--- a/Processes/UrQMD/UrQMD.h
+++ b/Processes/UrQMD/UrQMD.h
@@ -1,5 +1,5 @@
 /*
- * (c) Copyright 2019 CORSIKA Project, corsika-project@lists.kit.edu
+ * (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu
  *
  * See file AUTHORS for a list of contributors.
  *
diff --git a/Processes/UrQMD/testUrQMD.cc b/Processes/UrQMD/testUrQMD.cc
index 81b421547..13c17f6d2 100644
--- a/Processes/UrQMD/testUrQMD.cc
+++ b/Processes/UrQMD/testUrQMD.cc
@@ -1,5 +1,6 @@
+
 /*
- * (c) Copyright 2019 CORSIKA Project, corsika-project@lists.kit.edu
+ * (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu
  *
  * See file AUTHORS for a list of contributors.
  *
-- 
GitLab