diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2eab2b0f0..045ea92ed 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,6 +8,9 @@ stages: # Basic checks to verify correctness of code - pre-build + # Build and run tests + - test + # Project compilation validation - build @@ -41,22 +44,16 @@ stages: before_script: - pwd - export USER="test" - # - export GIT_SSL_NO_VERIFY=1 - echo $CI_SERVER_HOST - echo $CRONJOB # We redefine the HOME - - export HOME=${CI_PROJECT_DIR}/install_latest/ - - if [ -d $HOME/.rest ]; then rm -Rf $HOME/.rest; fi - - if [ -f "/opt/root/install/bin/thisroot.sh" ]; then source /opt/root/install/bin/thisroot.sh; fi + - export HOME=${CI_PROJECT_DIR}/install/ + - rm -rf $HOME/.rest + # Check versions - root-config --version - - if [ -f "/opt/geant4/install/bin/geant4.sh" ]; then source /opt/geant4/install/bin/geant4.sh; fi - geant4-config --version - - if [ -d "/opt/garfieldpp/install" ]; then export GARFIELD_HOME=/opt/garfieldpp/install; fi - - if [ -d "/opt/garfieldpp/install" ]; then export HEED_DATABASE=$GARFIELD_HOME/Heed/heed++/database; fi - - if [ -d "/opt/garfieldpp/install" ]; then export LD_LIBRARY_PATH=$GARFIELD_HOME/lib:$LD_LIBRARY_PATH; fi - - ls $GARFIELD_HOME + - echo $GARFIELD_INSTALL - python3 --version - - apt update && apt install -y wget clang-format: stage: pre-build @@ -72,127 +69,78 @@ clang-format: - $CRONJOB - $CRONJOB == "YES" -validateCode: +Validate Code: stage: pre-build script: - cd ${CI_PROJECT_DIR}/ - python3 pull-submodules.py --force --dontask - python3 pipeline/validateProcesses.py source/libraries/ -#axionLib: -# stage: libraries -# script: -# - "curl -k -X POST -F token=bd53c38cdd1395ffeb14d297ebe202 -F ref=master https://lfna.unizar.es/api/v4/projects/31/trigger/pipeline" -# only: -# variables: -# - $CI_SERVER_HOST == "lfna.unizar.es" - -#modelLib: -# stage: libraries -# script: -# - "curl -k -X POST -F token=a244698329647e96d55908d75f3f0e -F ref=master https://lfna.unizar.es/api/v4/projects/11/trigger/pipeline" -# only: -# variables: -# - $CI_SERVER_HOST == "lfna.unizar.es" - -#build: -# type: build -# script: -# - cd ${CI_PROJECT_DIR}/ -# - python3 pull-submodules.py --force --dontask -# - if [ -d ${CI_PROJECT_DIR}/build ]; then rm -Rf ${CI_PROJECT_DIR}/build; fi -# - mkdir ${CI_PROJECT_DIR}/build && cd ${CI_PROJECT_DIR}/build/ -# - if [ -d ${CI_PROJECT_DIR}/install ]; then rm -Rf ${CI_PROJECT_DIR}/install; fi -# - cmake ${CI_PROJECT_DIR} -DREST_WELCOME=OFF -DREST_GARFIELD=ON -DREST_G4=ON -DRESTLIB_DETECTOR=ON -DRESTLIB_RAW=ON -DRESTLIB_TRACK=ON -DCMAKE_INSTALL_PREFIX=${CI_PROJECT_DIR}/install -# - make install -j2 -# # - . ${CI_PROJECT_DIR}/install/thisREST.sh -# except: -# variables: -# - $CRONJOB == "YES" -# artifacts: -# paths: -# - ${CI_PROJECT_DIR}/install -# expire_in: 1 day -# -build_latest: +Build and Test: + type: test + script: + - cd ${CI_PROJECT_DIR} + - python3 pull-submodules.py --force --dontask --latest:${CI_COMMIT_BRANCH} + - mkdir ${CI_PROJECT_DIR}/build && cd ${CI_PROJECT_DIR}/build + - cmake ${CI_PROJECT_DIR} + -DTEST=ON -DREST_GARFIELD=ON -DREST_G4=ON -DRESTLIB_DETECTOR=ON -DRESTLIB_RAW=ON -DRESTLIB_TRACK=ON + - make -j2 + - ctest --verbose -O ${CI_PROJECT_DIR}/build/Testing/summary.txt + + artifacts: + name: "Testing" + paths: + - ${CI_PROJECT_DIR}/build/Testing + expire_in: 1 day + +Build and Install: type: build script: - - cd ${CI_PROJECT_DIR}/ + - cd ${CI_PROJECT_DIR} - python3 pull-submodules.py --force --dontask --latest:${CI_COMMIT_BRANCH} - - if [ -d ${CI_PROJECT_DIR}/build_latest ]; then rm -Rf ${CI_PROJECT_DIR}/build_latest; fi - - mkdir ${CI_PROJECT_DIR}/build_latest && cd ${CI_PROJECT_DIR}/build_latest/ - - if [ -d ${CI_PROJECT_DIR}/install_latest ]; then rm -Rf ${CI_PROJECT_DIR}/install_latest; fi - - cmake ${CI_PROJECT_DIR} -DREST_WELCOME=OFF -DREST_GARFIELD=ON -DREST_G4=ON -DRESTLIB_DETECTOR=ON -DRESTLIB_RAW=ON -DRESTLIB_TRACK=ON -DCMAKE_INSTALL_PREFIX=${CI_PROJECT_DIR}/install_latest + - rm -rf ${CI_PROJECT_DIR}/build && mkdir ${CI_PROJECT_DIR}/build && cd ${CI_PROJECT_DIR}/build + - rm -rf ${CI_PROJECT_DIR}/install + - cmake ${CI_PROJECT_DIR} -DCMAKE_INSTALL_PREFIX=${CI_PROJECT_DIR}/install + -DREST_GARFIELD=ON -DREST_G4=ON -DRESTLIB_DETECTOR=ON -DRESTLIB_RAW=ON -DRESTLIB_TRACK=ON -DREST_WELCOME=OFF - make install -j2 - # - . ${CI_PROJECT_DIR}/install_latest/thisREST.sh + artifacts: + name: "Install" paths: - - ${CI_PROJECT_DIR}/install_latest + - ${CI_PROJECT_DIR}/install expire_in: 1 day - #build_latest_root622_geant4v1042: - # image: lobis/root-geant4-garfieldpp:cxx14_ROOTv6-22-08_Geant4v10.4.2 - # type: build - # script: - # - cd ${CI_PROJECT_DIR}/ - # - python3 pull-submodules.py --force --dontask --latest - # - if [ -d ${CI_PROJECT_DIR}/build_latest2 ]; then rm -Rf ${CI_PROJECT_DIR}/build_latest2; fi - # - mkdir ${CI_PROJECT_DIR}/build_latest2 && cd ${CI_PROJECT_DIR}/build_latest2/ - # - if [ -d ${CI_PROJECT_DIR}/install_latest2 ]; then rm -Rf ${CI_PROJECT_DIR}/install_latest2; fi - # - cmake ${CI_PROJECT_DIR} -DREST_WELCOME=OFF -DREST_GARFIELD=ON -DREST_G4=ON -DRESTLIB_DETECTOR=ON -DRESTLIB_RAW=ON -DRESTLIB_TRACK=ON -DCMAKE_INSTALL_PREFIX=${CI_PROJECT_DIR}/install_latest2 - # - make install -j2 - # - . ${CI_PROJECT_DIR}/install_latest2/thisREST.sh - # except: - # variables: - # - $CRONJOB == "YES" - - #build_nkx: - # image: nkx1231/root6-geant4-garfield:0.6 - # type: build - # script: - # - cd ${CI_PROJECT_DIR}/ - # - python3 pull-submodules.py --force --dontask - # - if [ -d ${CI_PROJECT_DIR}/build_nkx ]; then rm -Rf ${CI_PROJECT_DIR}/build_nkx; fi - # - mkdir ${CI_PROJECT_DIR}/build_nkx && cd ${CI_PROJECT_DIR}/build_nkx/ - # - if [ -d ${CI_PROJECT_DIR}/install_nkx]; then rm -Rf ${CI_PROJECT_DIR}/install_nkx; fi - # - cmake ${CI_PROJECT_DIR} -DREST_WELCOME=OFF -DREST_GARFIELD=ON -DREST_G4=ON -DRESTLIB_DETECTOR=ON -DRESTLIB_RAW=ON -DRESTLIB_TRACK=ON -DCMAKE_INSTALL_PREFIX=${CI_PROJECT_DIR}/install_nkx - # - make install -j2 - # - cat ${CI_PROJECT_DIR}/install_nkx/thisREST.sh -# - . ${CI_PROJECT_DIR}/install_nkx/thisREST.sh -# except: -# variables: -# - $CRONJOB == "YES" - -loadRESTLibs: +Load REST Libraries: type: install script: - - cat ${CI_PROJECT_DIR}/install_latest/thisREST.sh - - . ${CI_PROJECT_DIR}/install_latest/thisREST.sh + - echo ${CI_PROJECT_DIR}/install/thisREST.sh + - cat ${CI_PROJECT_DIR}/install/thisREST.sh + - source ${CI_PROJECT_DIR}/install/thisREST.sh - restRoot -b -q -listRESTMacros: +List REST Macros: type: install script: - - . ${CI_PROJECT_DIR}/install_latest/thisREST.sh + - source ${CI_PROJECT_DIR}/install/thisREST.sh - restManager ListMacros 01_NLDBD: type: restG4 script: - - . ${CI_PROJECT_DIR}/install_latest/thisREST.sh - - cd ${CI_PROJECT_DIR}/install_latest/examples/restG4/01.NLDBD/ + - source ${CI_PROJECT_DIR}/install/thisREST.sh + - cd ${CI_PROJECT_DIR}/install/examples/restG4/01.NLDBD/ - restG4 NLDBD.rml - geant4-config --version - restRoot -b -q Validate.C'("Run00001_NLDBD_Test.root")' artifacts: paths: - - ${CI_PROJECT_DIR}/install_latest/examples/restG4/01.NLDBD/Run00001_NLDBD_Test.root + - ${CI_PROJECT_DIR}/install/examples/restG4/01.NLDBD/Run00001_NLDBD_Test.root expire_in: 1 day 02_PandaXiiiMC: type: restG4 script: - - . ${CI_PROJECT_DIR}/install_latest/thisREST.sh + - source ${CI_PROJECT_DIR}/install/thisREST.sh - cd ${CI_PROJECT_DIR}/pipeline/pandaxiii_MC - restG4 Xe136bb0n.rml - restRoot -b -q ValidateG4.C'("Xe136bb0n_n2E06.root")' @@ -201,20 +149,20 @@ listRESTMacros: - ${CI_PROJECT_DIR}/pipeline/pandaxiii_MC/Xe136bb0n_n2E06.root expire_in: 1 day -LoadGas: +Load Gas: type: metadata script: - - . ${CI_PROJECT_DIR}/install_latest/thisREST.sh + - source ${CI_PROJECT_DIR}/install/thisREST.sh - cd ${CI_PROJECT_DIR}/pipeline/metadata/gas/ - restRoot -b -q LoadGasFromServerAndValidate.C only: variables: - $CI_SERVER_HOST == "lfna.unizar.es" -GenerateGas: +Generate Gas: type: metadata script: - - . ${CI_PROJECT_DIR}/install_latest/thisREST.sh + - source ${CI_PROJECT_DIR}/install/thisREST.sh - cd ${CI_PROJECT_DIR}/pipeline/metadata/gas/ - restRoot -b -q GenerateDummyGas.C only: @@ -224,24 +172,25 @@ GenerateGas: AnalysisTree: type: core script: - - . ${CI_PROJECT_DIR}/install_latest/thisREST.sh + - source ${CI_PROJECT_DIR}/install/thisREST.sh - cd ${CI_PROJECT_DIR}/pipeline/analysistree/ - restRoot -b -q simpleTree.cpp -GenerateReadout: +Generate Readout: type: metadata script: - - . ${CI_PROJECT_DIR}/install_latest/thisREST.sh + - source ${CI_PROJECT_DIR}/install/thisREST.sh - cd ${CI_PROJECT_DIR}/pipeline/metadata/readout/ - restManager --c generateReadout.rml --o readout.root - restRoot -b -q PrintReadout.C'("readout.root")' > /dev/null + # We need to introduce basic validation here # - diff validation.txt print.txt -BasicReadout: +Basic Readout: type: metadata script: - - . ${CI_PROJECT_DIR}/install_latest/thisREST.sh + - source ${CI_PROJECT_DIR}/install/thisREST.sh - cd ${CI_PROJECT_DIR}/projects/basic-readouts/ - ls - git status @@ -249,21 +198,21 @@ BasicReadout: - restRoot --m 1 -b -q GenerateReadouts.C'("basic.root")' - restRoot -b -q BasicValidation.C'("basic.root", "pixelDecoding")' -testMeta: +Test Metadata: type: restManager_generate script: - - . ${CI_PROJECT_DIR}/install_latest/thisREST.sh - - cd ${CI_PROJECT_DIR}/install_latest/examples + - source ${CI_PROJECT_DIR}/install/thisREST.sh + - cd ${CI_PROJECT_DIR}/install/examples - restManager --c saveMetadataFile.rml --o meta.root artifacts: paths: - - ${CI_PROJECT_DIR}/install_latest/examples/meta.root + - ${CI_PROJECT_DIR}/install/examples/meta.root expire_in: 1 day -trexDM_data_latest: +TREX-DM Latest Data: type: restManager_process script: - - . ${CI_PROJECT_DIR}/install_latest/thisREST.sh + - source ${CI_PROJECT_DIR}/install/thisREST.sh - cd ${CI_PROJECT_DIR}/pipeline/trex - wget https://sultan.unizar.es/trexdm-readouts/readouts_v2.3.root - restManager --c 01_raw.rml --f R01928_tagTest_Vm_250_Vd_160_Pr_6_Gain_0x0_Shape_0xF_Clock_0x4-068.aqs @@ -279,10 +228,10 @@ trexDM_data_latest: - ${CI_PROJECT_DIR}/pipeline/trex/Hits_01928.root expire_in: 1 day -pandaXIII_Topological: +PandaXIII Topological: type: restManager_process script: - - . ${CI_PROJECT_DIR}/install_latest/thisREST.sh + - source ${CI_PROJECT_DIR}/install/thisREST.sh - cd ${CI_PROJECT_DIR}/pipeline/pandaxiii_MC - restManager --c AllProcesses.rml --i testInput.root --o testOutput.root --j 1 --e 10 - restRoot -b -q ../MakeBasicTree.C'("testOutput.root")' @@ -293,10 +242,10 @@ pandaXIII_Topological: - ${CI_PROJECT_DIR}/pipeline/pandaxiii_MC/trackParameter.png expire_in: 1 week -pandaXIII_Topological_fromG4: +PandaXIII Topological from Geant4: type: restManager_process script: - - . ${CI_PROJECT_DIR}/install_latest/thisREST.sh + - source ${CI_PROJECT_DIR}/install/thisREST.sh - cd ${CI_PROJECT_DIR}/pipeline/pandaxiii_MC - echo "using just-generated g4 file" - restManager --c AllProcesses.rml --i Xe136bb0n_n2E06.root --o testOutput.root --j 1 --e 10 @@ -307,10 +256,10 @@ pandaXIII_Topological_fromG4: - ${CI_PROJECT_DIR}/pipeline/pandaxiii_MC/testOutput.root expire_in: 1 week -pandaXIII_data: +PandaXIII Data: type: restManager_process script: - - . ${CI_PROJECT_DIR}/install_latest/thisREST.sh + - source ${CI_PROJECT_DIR}/install/thisREST.sh - cd ${CI_PROJECT_DIR}/pipeline/pandaxiii_data - restManager --c P3AutoChain.rml --i CoBo_AsAd0_2019-03-15.graw --o testOutput.root --j 1 - restRoot -b -q ../MakeBasicTree.C'("testOutput.root")' @@ -320,12 +269,12 @@ pandaXIII_data: - ${CI_PROJECT_DIR}/pipeline/pandaxiii_data/TriggerRate.png expire_in: 1 week -EventSelection: +Event Selection: type: restManager_process script: - - . ${CI_PROJECT_DIR}/install_latest/thisREST.sh + - source ${CI_PROJECT_DIR}/install/thisREST.sh - cd ${CI_PROJECT_DIR}/pipeline/selection - - restManager --c g4Analysis.rml --f "${CI_PROJECT_DIR}/install_latest/examples/restG4/01.NLDBD/Run00001_NLDBD_Test.root" + - restManager --c g4Analysis.rml --f "${CI_PROJECT_DIR}/install/examples/restG4/01.NLDBD/Run00001_NLDBD_Test.root" - restManager --c g4OnSelection.rml --f Run00001_NLDBD_Test_g4Analysis.root - restRoot -b -q Validate.C'("Run00001_NLDBD_Test_EvSelection.root")' @@ -337,25 +286,25 @@ EventSelection: AnalysisPlot: type: postProcessing script: - - . ${CI_PROJECT_DIR}/install_latest/thisREST.sh + - source ${CI_PROJECT_DIR}/install/thisREST.sh - cd ${CI_PROJECT_DIR}/pipeline/analysisPlot/ - restManager --c summary.rml --f ${CI_PROJECT_DIR}/pipeline/trex/Hits_01928.root AnalysisPlot2: type: postProcessing script: - - . ${CI_PROJECT_DIR}/install_latest/thisREST.sh + - source ${CI_PROJECT_DIR}/install/thisREST.sh - cd ${CI_PROJECT_DIR}/pipeline/analysisPlot/ - restManager --batch --c classify.rml - restRoot -b -q ValidateClassify.C -deploy: +Deploy: type: deploy only: - tags script: - - . ${CI_PROJECT_DIR}/install_latest/thisREST.sh + - source ${CI_PROJECT_DIR}/install/thisREST.sh - rest-config --welcome artifacts: paths: - - ${CI_PROJECT_DIR}/install_latest + - ${CI_PROJECT_DIR}/install diff --git a/CMakeLists.txt b/CMakeLists.txt index 706e7a570..956b88d35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,7 @@ -PROJECT(REST) CMAKE_MINIMUM_REQUIRED(VERSION 3.5) +PROJECT(REST) + # Minimum compiler version if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") # require at least gcc 4.8 @@ -14,7 +15,6 @@ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") endif () endif () - if (CMAKE_SYSTEM_NAME MATCHES "Darwin") SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-stdlib=libc++") endif (CMAKE_SYSTEM_NAME MATCHES "Darwin") @@ -98,7 +98,7 @@ endif () set(external_include_dirs ${external_include_dirs} ${ROOT_INCLUDE_DIRS}) -# This is to enable linking of SQL libraries. I.e. for process TRestSQLToAnalysisProccess. +# This is to enable linking of SQL libraries. I.e. for process TRestSQLToAnalysisProcess. if (NOT DEFINED SQL) set(SQL OFF) endif () @@ -123,9 +123,13 @@ message(STATUS "external libraries to link: " ${external_libs}) # Gather some information string(TIMESTAMP date "%Y-%m-%d %H:%M") +# Enable testing (-DTEST=ON flag, it is OFF by default) +include(Testing) + # Start compile include(MacroRootDict) add_subdirectory(source) + message("") message(STATUS "rest Libraries: " ${rest_libraries_regular}) message(STATUS "rest executables: " ${rest_exes}) diff --git a/cmake/Testing.cmake b/cmake/Testing.cmake new file mode 100644 index 000000000..41fe65f74 --- /dev/null +++ b/cmake/Testing.cmake @@ -0,0 +1,57 @@ + +if (NOT DEFINED TEST OR NOT TEST) + set(TEST OFF) + message(STATUS "Testing disabled (Disabled by default, enabled via -DTEST=ON flag)") +endif () +if (TEST) + message(STATUS "Testing enabled (Disabled by default, enabled via -DTEST=ON flag)") + enable_testing() + add_compile_definitions(REST_TESTING_ENABLED) +endif () + +macro(ADD_TEST) + if (TEST) + message(STATUS "Adding tests at ${CMAKE_CURRENT_SOURCE_DIR}") + add_subdirectory(test) + endif () +endmacro() + +macro(ADD_LIBRARY_TEST) + if (TEST) + message(STATUS "Adding tests at ${CMAKE_CURRENT_SOURCE_DIR}") + set(TESTING_EXECUTABLE testRestGeant4) + + get_filename_component(DIR_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) + + string(SUBSTRING ${DIR_NAME} 0 1 FIRST_LETTER) + string(TOUPPER ${FIRST_LETTER} FIRST_LETTER) + string(REGEX REPLACE "^.(.*)" "${FIRST_LETTER}\\1" DIR_NAME_CAPITALIZED "${DIR_NAME}") + + set(LIBRARY_NAME "Rest${DIR_NAME_CAPITALIZED}") + + set(TESTING_EXECUTABLE "test${LIBRARY_NAME}") + + enable_testing() + + add_executable(${TESTING_EXECUTABLE}) + + FILE(GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/test/src/*.cxx) + target_sources( + ${TESTING_EXECUTABLE} PUBLIC + ${SOURCES} + ) + + target_link_libraries( + ${TESTING_EXECUTABLE} PUBLIC + ${LIBRARY_NAME} + gtest_main + RestFramework + stdc++fs # + ) + + include(GoogleTest) + + gtest_discover_tests(${TESTING_EXECUTABLE}) + + endif () +endmacro() diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 433ed717d..d487a9360 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -30,76 +30,76 @@ add_subdirectory(bin) # clear the cache first SUBDIRLIST(subdirs "${CMAKE_CURRENT_SOURCE_DIR}/libraries") -foreach(subdir ${subdirs}) - DIRNAME2LIBNAME(libname ${subdir}) - set("${libname}_COMPILED" "FALSE") -endforeach() +foreach (subdir ${subdirs}) + DIRNAME2LIBNAME(libname ${subdir}) + set("${libname}_COMPILED" "FALSE") +endforeach () # loop all the dirs and set the option set(dirs "libraries" "packages") -foreach(dir ${dirs}) - SUBDIRLIST(subdirs "${CMAKE_CURRENT_SOURCE_DIR}/${dir}") - foreach(subdir ${subdirs}) - set(fullname "${dir}/${subdir}") - DIRNAME2OPTION(option ${fullname}) - - file(GLOB ff "*/${subdir}/CMakeLists.txt") - if(ff) # if dir not empty, set the option to ON - if (NOT DEFINED ${option}) - IF(${REST_ALL_LIBS} MATCHES "ON") - set(${option} ON) - else() - set(${option} OFF) - endif() - endif() - message("Submodule found: ${fullname}. Option: ${option}=${${option}}") - else() - set(${option} OFF) - message("Empty submodule dir: ${fullname}. Option: ${option}=${${option}}") - endif() - endforeach() -endforeach() - -if( ${REST_G4} MATCHES ON ) - set( RESTLIB_GEANT4 ON ) -endif() - -if( ${RESTLIB_DETECTOR} MATCHES ON ) - if( ${RESTLIB_RAW} MATCHES ON) - set( RESTLIB_CONNECTORS ON ) - endif() -endif() +foreach (dir ${dirs}) + SUBDIRLIST(subdirs "${CMAKE_CURRENT_SOURCE_DIR}/${dir}") + foreach (subdir ${subdirs}) + set(fullname "${dir}/${subdir}") + DIRNAME2OPTION(option ${fullname}) + + file(GLOB ff "*/${subdir}/CMakeLists.txt") + if (ff) # if dir not empty, set the option to ON + if (NOT DEFINED ${option}) + IF (${REST_ALL_LIBS} MATCHES "ON") + set(${option} ON) + else () + set(${option} OFF) + endif () + endif () + message("Submodule found: ${fullname}. Option: ${option}=${${option}}") + else () + set(${option} OFF) + message("Empty submodule dir: ${fullname}. Option: ${option}=${${option}}") + endif () + endforeach () +endforeach () + +if (${REST_G4} MATCHES ON) + set(RESTLIB_GEANT4 ON) +endif () + +if (${RESTLIB_DETECTOR} MATCHES ON) + if (${RESTLIB_RAW} MATCHES ON) + set(RESTLIB_CONNECTORS ON) + endif () +endif () # loop all the dirs and compile if option is ON -foreach(dir ${dirs}) - SUBDIRLIST(subdirs "${CMAKE_CURRENT_SOURCE_DIR}/${dir}") - foreach(subdir ${subdirs}) - set(fullname "${dir}/${subdir}") - DIRNAME2OPTION(option ${fullname}) - - if(${${option}} MATCHES "ON") - add_subdirectory(${fullname}) - set(rest_include_dirs ${rest_include_dirs} ${dirs_included}) - set(rest_libraries ${rest_libraries} ${library_added}) - set(rest_packages ${rest_packages} ${package_added}) - set(rest_features ${rest_features} ${feature_added}) - endif() - endforeach() -endforeach() +foreach (dir ${dirs}) + SUBDIRLIST(subdirs "${CMAKE_CURRENT_SOURCE_DIR}/${dir}") + foreach (subdir ${subdirs}) + set(fullname "${dir}/${subdir}") + DIRNAME2OPTION(option ${fullname}) + + if (${${option}} MATCHES "ON") + add_subdirectory(${fullname}) + set(rest_include_dirs ${rest_include_dirs} ${dirs_included}) + set(rest_libraries ${rest_libraries} ${library_added}) + set(rest_packages ${rest_packages} ${package_added}) + set(rest_features ${rest_features} ${feature_added}) + endif () + endforeach () +endforeach () # remove duplicates -if(DEFINED rest_include_dirs) - list(REMOVE_DUPLICATES rest_include_dirs) -endif() -if(DEFINED rest_libraries) - list(REMOVE_DUPLICATES rest_libraries) -endif() -if(DEFINED rest_packages) - list(REMOVE_DUPLICATES rest_packages) -endif() -if(DEFINED rest_features) - list(REMOVE_DUPLICATES rest_features) -endif() +if (DEFINED rest_include_dirs) + list(REMOVE_DUPLICATES rest_include_dirs) +endif () +if (DEFINED rest_libraries) + list(REMOVE_DUPLICATES rest_libraries) +endif () +if (DEFINED rest_packages) + list(REMOVE_DUPLICATES rest_packages) +endif () +if (DEFINED rest_features) + list(REMOVE_DUPLICATES rest_features) +endif () # set REST compilation flags to main cmake set(rest_include_dirs ${rest_include_dirs} PARENT_SCOPE) @@ -108,16 +108,16 @@ set(rest_packages ${rest_packages} PARENT_SCOPE) set(rest_features ${rest_features} PARENT_SCOPE) set(rest_libraries_regular "-L${CMAKE_INSTALL_PREFIX}/lib ") -foreach(lib ${rest_libraries}) - set(rest_libraries_regular "${rest_libraries_regular} -l${lib} ") -endforeach(lib) +foreach (lib ${rest_libraries}) + set(rest_libraries_regular "${rest_libraries_regular} -l${lib} ") +endforeach (lib) set(rest_libraries_regular ${rest_libraries_regular} PARENT_SCOPE) set(rest_exes ${rest_exes} PARENT_SCOPE) set(rest_macros ${rest_macros} PARENT_SCOPE) # construct REST macros string(separate with blank) set(rest_macros_str) -foreach(mac ${rest_macros}) +foreach (mac ${rest_macros}) set(rest_macros_str "${rest_macros_str}${mac} ") -endforeach(mac ${rest_macros}) +endforeach (mac ${rest_macros}) set(rest_macros_str ${rest_macros_str} PARENT_SCOPE) diff --git a/source/bin/CMakeLists.txt b/source/bin/CMakeLists.txt index 721e135ac..ae3818d10 100644 --- a/source/bin/CMakeLists.txt +++ b/source/bin/CMakeLists.txt @@ -1,20 +1,21 @@ -#set(target_libraries ${rest_libraries} -lGui ${ROOT_LIBRARIES} -lEve -lGeom) + include_directories(${rest_include_dirs}) include_directories(${external_include_dirs}) set(rest_exes) set(files restManager.cxx restRoot.cxx) -foreach(file ${files}) -#get file name without extension -string(REGEX MATCH "[^/\\]*cxx" temp ${file}) -string(REPLACE ".cxx" "" name ${temp}) -ADD_EXECUTABLE(${name} ${file} ) -TARGET_LINK_LIBRARIES(${name} ${rest_libraries} ${external_libs} ) -install(TARGETS ${name} RUNTIME DESTINATION bin) -set(rest_exes "${rest_exes}${name} ") +foreach (file ${files}) + # Get file name without extension + string(REGEX MATCH "[^/\\]*cxx" temp ${file}) + string(REPLACE ".cxx" "" name ${temp}) + + ADD_EXECUTABLE(${name} ${file}) + TARGET_LINK_LIBRARIES(${name} ${rest_libraries} ${external_libs}) + install(TARGETS ${name} RUNTIME DESTINATION bin) + set(rest_exes "${rest_exes}${name} ") -endforeach(file) +endforeach (file) set(rest_exes ${rest_exes} PARENT_SCOPE) diff --git a/source/framework/CMakeLists.txt b/source/framework/CMakeLists.txt index 50f36a7bf..cec32bb4d 100644 --- a/source/framework/CMakeLists.txt +++ b/source/framework/CMakeLists.txt @@ -1,11 +1,15 @@ +add_subdirectory(external) + set(contents external/tinyxml tools core analysis) file(GLOB_RECURSE addon_src - "tiny*cpp" - "startup.cpp") + "tiny*cpp" + "startup.cpp") if (NOT ${REST_EVE} MATCHES "ON") - set( excludes TRestEveEventViewer) + set(excludes TRestEveEventViewer) endif (NOT ${REST_EVE} MATCHES "ON") COMPILEDIR(RestFramework) + +ADD_LIBRARY_TEST() diff --git a/source/framework/core/inc/TRestMetadata.h b/source/framework/core/inc/TRestMetadata.h index 752e9ea4a..e2587739f 100644 --- a/source/framework/core/inc/TRestMetadata.h +++ b/source/framework/core/inc/TRestMetadata.h @@ -24,6 +24,7 @@ #define RestCore_TRestMetadata #define TIXML_USE_STL + #include #include #include @@ -291,7 +292,7 @@ class TRestMetadata : public TNamed { /// returns the verboselevel in type of REST_Verbose_Level enumerator REST_Verbose_Level GetVerboseLevel() { return fVerboseLevel; } - /// returns the verboselevel in type of TString + /// returns the verbose level in type of TString TString GetVerboseLevelString(); /// Gets a string with the path used for data storage @@ -313,12 +314,12 @@ class TRestMetadata : public TNamed { void SetSectionName(std::string sName) { fSectionName = sName; } /// set config file path from external void SetConfigFile(std::string cfgFileName) { fConfigFileName = cfgFileName; } - /// Set the hoster manager for this class. + /// Set the host manager for this class. void SetHostmgr(TRestManager* m) { fHostmgr = m; } - /// sets the verboselevel + /// sets the verbose level void SetVerboseLevel(REST_Verbose_Level v) { fVerboseLevel = v; } /// overwriting the write() method with fStore considered - virtual Int_t Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0); + virtual Int_t Write(const char* name = nullptr, Int_t option = 0, Int_t bufsize = 0); ~TRestMetadata(); diff --git a/source/framework/core/src/startup.cpp b/source/framework/core/src/startup.cpp index c6976bee1..607a2c912 100644 --- a/source/framework/core/src/startup.cpp +++ b/source/framework/core/src/startup.cpp @@ -25,6 +25,10 @@ map RESTConverterMethodBase = {}; struct __REST_CONST_INIT { public: __REST_CONST_INIT() { +// TODO: fix to avoid this dirty fix +#ifdef REST_TESTING_ENABLED + return; +#endif REST_COMMIT = TRestTools::Execute("rest-config --commit"); char* _REST_PATH = getenv("REST_PATH"); diff --git a/source/framework/external/CMakeLists.txt b/source/framework/external/CMakeLists.txt new file mode 100644 index 000000000..fe25ae2b7 --- /dev/null +++ b/source/framework/external/CMakeLists.txt @@ -0,0 +1,17 @@ + +message(STATUS "External dependencies:") + +include(FetchContent) +set(FETCHCONTENT_QUIET ON) + +# Google Test +if (TEST) + # https://google.github.io/googletest/quickstart-cmake.html + message(STATUS "- Google Test") + FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip + ) + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) # Windows only + FetchContent_MakeAvailable(googletest) +endif () diff --git a/source/framework/test/files/TRestMetadataTest.rml b/source/framework/test/files/TRestMetadataTest.rml new file mode 100644 index 000000000..b4c1b8857 --- /dev/null +++ b/source/framework/test/files/TRestMetadataTest.rml @@ -0,0 +1 @@ + diff --git a/source/framework/test/files/TRestRunBasic.rml b/source/framework/test/files/TRestRunBasic.rml new file mode 100644 index 000000000..86185fa7b --- /dev/null +++ b/source/framework/test/files/TRestRunBasic.rml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/source/framework/test/src/FrameworkCore.cxx b/source/framework/test/src/FrameworkCore.cxx new file mode 100644 index 000000000..960663bba --- /dev/null +++ b/source/framework/test/src/FrameworkCore.cxx @@ -0,0 +1,60 @@ + +#include +#include +#include + +#include + +namespace fs = std::filesystem; + +using namespace std; + +#define FILES_PATH fs::path(__FILE__).parent_path().parent_path() / "files" +#define BASIC_TRESTRUN_RML FILES_PATH / "TRestRunBasic.rml" +#define BASIC_TRESTMETADATA_RML FILES_PATH / "TRestMetadataTest.rml" + +TEST(FrameworkCore, TestFiles) { + cout << "FrameworkCore test files path: " << FILES_PATH << endl; + + // Check dir exists and is a directory + EXPECT_TRUE(fs::is_directory(FILES_PATH)); + // Check it's not empty + EXPECT_TRUE(!fs::is_empty(FILES_PATH)); + // Check required files exist + EXPECT_TRUE(fs::exists(BASIC_TRESTRUN_RML)); + EXPECT_TRUE(fs::exists(BASIC_TRESTMETADATA_RML)); +} + +TEST(FrameworkCore, TRestRun) { + TRestRun run; + + run.LoadConfigFromFile(BASIC_TRESTRUN_RML); + + run.PrintAllMetadata(); + + EXPECT_TRUE(run.GetExperimentName() == "TRestRun Basic Test"); + EXPECT_TRUE(run.GetRunType() == "Test"); + EXPECT_TRUE(run.GetRunNumber() == 1); + EXPECT_TRUE(run.GetRunTag() == "Test"); + // EXPECT_TRUE(run.GetOutputFileName() == "Run[fRunNumber]_[fRunTag]_[fExperimentName].root"); + EXPECT_TRUE(run.GetRunDescription() == "This is a test for TRestRun"); + EXPECT_TRUE(run.GetVerboseLevelString() == "debug"); +} + +TEST(FrameworkCore, TRestMetadata) { + // Create new TRestMetadata class + class TRestMetadataTest : public TRestMetadata { + int fP1; + double fP2; + string fP3; + }; + + TRestMetadataTest restMetadataTest; + restMetadataTest.LoadConfigFromFile(BASIC_TRESTMETADATA_RML, "TRestMetadataTest"); + + restMetadataTest.PrintMetadata(); + + EXPECT_TRUE(restMetadataTest.GetParameter("p1") == "75"); + EXPECT_TRUE(restMetadataTest.GetParameter("p2") == "12.32"); + EXPECT_TRUE(restMetadataTest.GetParameter("p3") == "Aloha"); +} diff --git a/testing/dockerfiles/README.md b/testing/dockerfiles/README.md deleted file mode 100644 index cede7cf9a..000000000 --- a/testing/dockerfiles/README.md +++ /dev/null @@ -1,22 +0,0 @@ -# Introduction - -This section will contain everything necessary to build the docker containers used in the CI/CD pipeline. - -The base image for all other images is an ubuntu:18.04 image containing an installation of root and basic dependencies. All other images (e.g. REST image) will be built on top of this base image. - -This image's `Dockerfile` is under the *ROOT* directory. This image can be build with any version of ROOT via environment variable passing, to build this image run the following command (if no version is specified it defaults to ROOT version `6.16.00`): - -``` -ROOT_VERSION=6.16.00 -docker build -t root:${ROOT_VERSION} --build-arg ROOT_VERSION=${ROOT_VERSION} --build-arg MAKE_N_JOBS=3 . -``` - -Where the `-t` option is used to give the image a name (`root_v6.16.00` in this case) and `--build-arg ROOT_VERSION` is to assign a value to the `ROOT_VERSION` variable inside the `Dockerfile`. In this example we used an environment variable to keep the naming of the image consistent with the installed ROOT version. Remember you need to be on the directory of the `Dockerfile` (or use the `-f PATH_TO_DOCKERFILE` option) and have superuser privileges. - -# Container Registry - -In the near future we will use a feature called the GitLab container registry to upload our images built using the dockerfiles contained here. It is important to use this registry and not a public one (for example https://hub.docker.com/) because our images may contain sensitive information. - -For example the ROOT image could be public since it does not contain any sensitive information but in order to build the REST image one needs to pass a deployment key in order for the container to clone the REST repository. This is considered sensitive information therefor this image has to be kept private. - -We would pass the deployment key (and any other sensitive information) via `--build-arg` flag when building locally and then upload the image to the GitLab registry. it is important to mention that someone with access to the image still could recover this information unless we do a multi-stage build (and the sensitive information is not on the last stage). \ No newline at end of file diff --git a/testing/dockerfiles/REST/Dockerfile b/testing/dockerfiles/REST/Dockerfile deleted file mode 100644 index 989ff26ca..000000000 --- a/testing/dockerfiles/REST/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -# -# author: Luis Obis (lobis@unizar.es) -# - -# TODO: implement this image from the gitlab container registry root base image once its running - -FROM ubuntu:18.04 - -CMD ["/bin/bash"] \ No newline at end of file diff --git a/testing/dockerfiles/ROOT/Dockerfile b/testing/dockerfiles/ROOT/Dockerfile deleted file mode 100644 index 2520cb262..000000000 --- a/testing/dockerfiles/ROOT/Dockerfile +++ /dev/null @@ -1,41 +0,0 @@ -# -# author: Luis Obis (lobis@unizar.es) -# - -FROM ubuntu:18.04 - -RUN apt-get update -# root dependencies -RUN apt-get install -y git dpkg-dev cmake g++ gcc binutils libx11-dev libxpm-dev libxft-dev libxext-dev -RUN apt-get install -y gfortran libssl-dev libpcre3-dev \ - xlibmesa-glu-dev libglew1.5-dev libftgl-dev \ - libmysqlclient-dev libfftw3-dev libcfitsio-dev \ - graphviz-dev libavahi-compat-libdnssd-dev \ - libldap2-dev python-dev libxml2-dev libkrb5-dev \ - libgsl0-dev libqt4-dev -RUN apt-get install -y curl - -# download and build ROOT with provided options -ARG ROOT_VERSION="6.16.00" -RUN curl -o /tmp/root.tar.gz https://root.cern/download/root_v${ROOT_VERSION}.source.tar.gz -RUN tar xzfv /tmp/root.tar.gz -C /opt && rm -rf /tmp/root.tar.gz -WORKDIR /opt/root-${ROOT_VERSION}/build - -ARG ROOT_INSTALL_PREFIX=/opt/root -ARG MAKE_N_JOBS="" -# $((`nproc` + 1)) = number of cores + 1 for the fastest make -# MAKE_N_JOBS can be passed as argument in --build-arg -RUN if [ -z "$MAKE_N_JOBS" ]; then MAKE_N_JOBS=$((`nproc` + 1)); fi -RUN cmake -DCMAKE_INSTALL_PREFIX=$ROOT_INSTALL_PREFIX -DCXX17=ON -DGDML=ON .. -RUN make install -j$MAKE_N_JOBS -# remove downloaded sources - -WORKDIR / -RUN rm -rf /opt/root-${ROOT_VERSION}/ - -# set environment variables -ENV ROOTSYS "${ROOT_INSTALL_PREFIX}" -ENV PATH "${ROOTSYS}/bin:${PATH}" -ENV LD_LIBRARY_PATH "${ROOTSYS}/lib:${LD_LIBRARY_PATH}" - -CMD ["/bin/bash"] diff --git a/testing/tests/README.md b/testing/tests/README.md deleted file mode 100644 index 118f06fa8..000000000 --- a/testing/tests/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Introduction - -This section will contain all the unit tests and related files. \ No newline at end of file