Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
${CMAKE_SOURCE_DIR}/cmake)

option(MCStepLogger_BUILD_TESTS "Control whether tests are built" OFF)

include(CTest)

# Install directories
SET(INSTALL_BIN_DIR ${CMAKE_INSTALL_PREFIX}/bin)
SET(INSTALL_MACRO_DIR ${CMAKE_INSTALL_PREFIX}/macro)
Expand Down Expand Up @@ -224,3 +228,12 @@ configure_file(
install(FILES
"${PROJECT_BINARY_DIR}/MCStepLoggerConfig.cmake"
DESTINATION ${INSTALL_CMAKE_DIR})

###############
# Build tests #
###############
if(NOT MCStepLogger_BUILD_TESTS)
message(WARNING "No tests are built.")
else()
add_subdirectory(test)
endif(NOT MCStepLogger_BUILD_TESTS)
23 changes: 23 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Build tests

set(REPO_NAME_TEST MCStepLoggerTestData)

# Could potentially use CMake's FetchContent module but seems to be overhead since we only need this single line
execute_process(COMMAND git clone https://gitlab.cern.ch/bvolkel/${REPO_NAME_TEST}.git WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} RESULT_VARIABLE res)

if(NOT res EQUAL "0")
message(WARNING "Test data could not be fetched")
return()
endif(NOT res EQUAL "0")

# Find boost unit tests dependencies
find_package(Boost REQUIRED COMPONENTS unit_test_framework)
include_directories(${Boost_INCLUDE_DIR})

# The basic test only checks core functionality without any backend.
set(CORE_TARGET analysis)
set(TEST_CORE "test${CORE_TARGET}")
set(STEP_TEST_FILE MCStepLoggerOutput.root)
add_executable(${CORE_TARGET} "${CORE_TARGET}.cxx")
target_link_libraries(${CORE_TARGET} MCStepLoggerCore MCStepLoggerAnalysis ${Boost_LIBRARIES})
add_test(NAME ${TEST_CORE} COMMAND ${CORE_TARGET} -- ${REPO_NAME_TEST}/${CORE_TARGET}/${STEP_TEST_FILE} "./")
53 changes: 53 additions & 0 deletions test/analysis.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Test analysis functionality

#define BOOST_TEST_MAIN
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE MCStepLoggerAnalysisCoreTest

#include <fstream>

#include <boost/test/unit_test.hpp>
#include <boost/test/results_collector.hpp>

#include "MCStepLogger/MCAnalysisManager.h"
#include "MCStepLogger/MCAnalysisFileWrapper.h"
#include "MCStepLogger/SimpleStepAnalysis.h"
#include "MCStepLogger/MCAnalysisFileWrapper.h"

using namespace o2::mcstepanalysis;

// checking meta info and whether there is a value container the analysis can be conpared with
BOOST_AUTO_TEST_CASE(testAnalysis)
{

// require input and output path
BOOST_REQUIRE(boost::unit_test::framework::master_test_suite().argc == 3);

new SimpleStepAnalysis();
auto& anamgr = MCAnalysisManager::Instance();
anamgr.setLabel("testLabel");
anamgr.setInputFilepath(boost::unit_test::framework::master_test_suite().argv[1]);

// everything loaded and ready to run?
BOOST_REQUIRE(anamgr.checkReadiness());

// runs all events found and should produce an output file
anamgr.run();

// write output
std::string outputDir(boost::unit_test::framework::master_test_suite().argv[2]);
std::string analysisFilepath = outputDir + "/SimpleStepAnalysis/Analysis.root";
anamgr.write(outputDir);

// Now check if the analysis file was produced properly
std::ifstream file(analysisFilepath);
BOOST_REQUIRE(file);

MCAnalysisFileWrapper anaFile;
anaFile.read(analysisFilepath);
BOOST_REQUIRE(anaFile.isSane());

// one last check for meta information
auto& anaMetaInfo = anaFile.getAnalysisMetaInfo();
BOOST_REQUIRE(anaMetaInfo.analysisName.compare("SimpleStepAnalysis") == 0);
}