Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a simple test that only reads partial frames to check proper cleanup #713

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions cmake/podioTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function(PODIO_SET_TEST_ENV test)
ENABLE_SIO=${ENABLE_SIO}
PODIO_BUILD_BASE=${PROJECT_BINARY_DIR}
LSAN_OPTIONS=suppressions=${PROJECT_SOURCE_DIR}/tests/root_io/leak_sanitizer_suppressions.txt
TSAN_OPTIONS=suppressions=${PROJECT_SOURCE_DIR}/tests/root_io/thread_sanitizer_suppressions.txt
)
set_property(TEST ${test}
PROPERTY ENVIRONMENT "${test_environment}"
Expand Down
2 changes: 2 additions & 0 deletions tests/CTestCustom.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ if ((NOT "@FORCE_RUN_ALL_TESTS@" STREQUAL "ON") AND (NOT "@USE_SANITIZER@" STREQ
write_python_frame_root
read_python_frame_root
read_and_write_frame_root
read_partial_root

param_reading_rdataframe

Expand Down Expand Up @@ -107,6 +108,7 @@ if ((NOT "@FORCE_RUN_ALL_TESTS@" STREQUAL "ON") AND (NOT "@USE_SANITIZER@" STREQ
read_rntuple
write_interface_rntuple
read_interface_rntuple
read_partial_rntuple
)

endif()
Expand Down
39 changes: 39 additions & 0 deletions tests/read_partial.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef PODIO_TESTS_READ_PARTIAL_H // NOLINT(llvm-header-guard): folder structure not suitable
#define PODIO_TESTS_READ_PARTIAL_H // NOLINT(llvm-header-guard): folder structure not suitable

#include "podio/Frame.h"

#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>

void read_partial_collections(const podio::Frame& event, const std::vector<std::string>& collsToRead) {
for (const auto& name : collsToRead) {
event.get(name);
}
}

/**
* This is a test case that will always work in normal builds and will only fail
* in builds with sanitizers enabled, where they will start to fail in case of
* e.g. memory leaks.
*/
template <typename ReaderT>
int read_partial_frames(const std::string& filename) {
auto reader = ReaderT();
try {
reader.openFile(filename);
} catch (const std::runtime_error& e) {
std::cerr << "File " << filename << " could not be opened. aborting." << std::endl;
return 1;
}

for (auto i = 0u; i < reader.getEntries(podio::Category::Event); ++i) {
const auto event = podio::Frame(reader.readEntry(podio::Category::Event, i));
read_partial_collections(event, {"mcparticles", "info", "hits", "clusters"});
}

return 0;
}
#endif // PODIO_TESTS_READ_PARTIAL_H
11 changes: 10 additions & 1 deletion tests/root_io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set(root_dependent_tests
read_and_write_frame_root.cpp
write_interface_root.cpp
read_interface_root.cpp
read_partial_root.cpp
)
if(ENABLE_RNTUPLE)
set(root_dependent_tests
Expand All @@ -17,6 +18,7 @@ if(ENABLE_RNTUPLE)
read_python_frame_rntuple.cpp
write_interface_rntuple.cpp
read_interface_rntuple.cpp
read_partial_rntuple.cpp
)
endif()
if(ENABLE_DATASOURCE)
Expand All @@ -39,13 +41,20 @@ set_tests_properties(
read_frame_root
read_frame_root_multiple
read_and_write_frame_root
read_partial_root

PROPERTIES
DEPENDS write_frame_root
)

if(ENABLE_RNTUPLE)
set_property(TEST read_rntuple PROPERTY DEPENDS write_rntuple)
set_tests_properties(
read_rntuple
read_partial_rntuple

PROPERTIES
DEPENDS write_rntuple
)
set_property(TEST read_interface_rntuple PROPERTY DEPENDS write_interface_rntuple)
endif()

Expand Down
7 changes: 7 additions & 0 deletions tests/root_io/read_partial_rntuple.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "read_partial.h"

#include "podio/RNTupleReader.h"

int main() {
return read_partial_frames<podio::RNTupleReader>("example_rntuple.root");
}
7 changes: 7 additions & 0 deletions tests/root_io/read_partial_root.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "read_partial.h"

#include "podio/ROOTReader.h"

int main() {
return read_partial_frames<podio::ROOTReader>("example_frame.root");
}
2 changes: 2 additions & 0 deletions tests/root_io/thread_sanitizer_suppressions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Ignore race conditions in libROOTNTuple
race:ROOTNTuple
3 changes: 3 additions & 0 deletions tests/sio_io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ set(sio_dependent_tests
read_python_frame_sio.cpp
write_interface_sio.cpp
read_interface_sio.cpp
read_partial_sio.cpp
)

set(sio_libs podio::podioSioIO podio::podioIO)
foreach( sourcefile ${sio_dependent_tests} )
CREATE_PODIO_TEST(${sourcefile} "${sio_libs}")
Expand All @@ -14,6 +16,7 @@ endforeach()
set_tests_properties(
read_frame_sio
read_and_write_frame_sio
read_partial_sio

PROPERTIES
DEPENDS
Expand Down
7 changes: 7 additions & 0 deletions tests/sio_io/read_partial_sio.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "read_partial.h"

#include "podio/SIOReader.h"

int main() {
return read_partial_frames<podio::SIOReader>("example_frame.sio");
}