Skip to content

Commit d08336b

Browse files
committed
Add unit test for Pool Output/Source
This uses the new TestSourceProcessor and changes in TestProcessor to support OutputModules.
1 parent 8b9b9fa commit d08336b

File tree

3 files changed

+152
-0
lines changed

3 files changed

+152
-0
lines changed

IOPool/Common/test/BuildFile.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
<test name="TestEdmFastMerge" command="TestEdmFastMerge.sh"/>
22
<test name="TestEdmConfigDump" command="run_TestEdmConfigDump.sh"/>
33
<test name="testIOPoolCommonLumiOverlap" command="test_overlap_lumi_fast_copy.sh"/>
4+
<bin file="test_catch2_*.cc" name="TestIOPoolCommonTP">
5+
<use name="FWCore/TestProcessor"/>
6+
<use name="catch2"/>
7+
</bin>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#define CATCH_CONFIG_MAIN
2+
#include "catch.hpp"
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
#include "FWCore/TestProcessor/interface/TestProcessor.h"
2+
#include "FWCore/TestProcessor/interface/TestSourceProcessor.h"
3+
#include "FWCore/Utilities/interface/Exception.h"
4+
5+
#include "DataFormats/TestObjects/interface/Thing.h"
6+
#include <vector>
7+
#include <filesystem>
8+
#include "catch.hpp"
9+
10+
static constexpr auto s_tag = "[PoolOutputSource]";
11+
12+
namespace {
13+
std::string setOutputFile(std::string const& iConfig, std::string const& iFileName) {
14+
using namespace std::string_literals;
15+
return iConfig + "\nprocess.out.fileName = '"s + iFileName + "'\n";
16+
}
17+
18+
std::string setInputFile(std::string const& iConfig, std::string const& iFileName) {
19+
using namespace std::string_literals;
20+
return iConfig + "\nprocess.source.fileNames = ['file:"s + iFileName + "']\n";
21+
}
22+
} // namespace
23+
TEST_CASE("Tests of PoolOuput -> PoolSource", s_tag) {
24+
const std::string baseOutConfig{
25+
R"_(from FWCore.TestProcessor.TestProcess import *
26+
process = TestProcess()
27+
process.out = cms.OutputModule('PoolOutputModule',
28+
fileName = cms.untracked.string('')
29+
)
30+
process.add_(cms.Service("InitRootHandlers"))
31+
process.add_(cms.Service("JobReportService"))
32+
33+
process.moduleToTest(process.out)
34+
)_"};
35+
36+
const std::string baseSourceConfig{
37+
R"_(from FWCore.TestProcessor.TestSourceProcess import *
38+
process = TestSourceProcess()
39+
process.source = cms.Source("PoolSource", fileNames = cms.untracked.vstring(''))
40+
process.add_(cms.Service("InitRootHandlers"))
41+
process.add_(cms.Service("SiteLocalConfigService"))
42+
process.add_(cms.Service("JobReportService"))
43+
)_"};
44+
45+
SECTION("OneEmptyEvent") {
46+
const std::string fileName = "one_event.root";
47+
{
48+
auto configString = setOutputFile(baseOutConfig, fileName);
49+
50+
edm::test::TestProcessor::Config config{configString};
51+
52+
edm::test::TestProcessor tester(config);
53+
tester.test();
54+
}
55+
{
56+
auto config = setInputFile(baseSourceConfig, fileName);
57+
edm::test::TestSourceProcessor tester(config);
58+
59+
{
60+
auto n = tester.findNextTransition();
61+
REQUIRE(n == edm::InputSource::ItemType::IsFile);
62+
auto f = tester.openFile();
63+
REQUIRE(bool(f));
64+
}
65+
{
66+
auto n = tester.findNextTransition();
67+
REQUIRE(n.itemType() == edm::InputSource::ItemType::IsRun);
68+
auto r = tester.readRun();
69+
REQUIRE(r.run() == 1);
70+
}
71+
{
72+
auto n = tester.findNextTransition();
73+
REQUIRE(n.itemType() == edm::InputSource::ItemType::IsLumi);
74+
auto r = tester.readLuminosityBlock();
75+
REQUIRE(r.run() == 1);
76+
REQUIRE(r.luminosityBlock() == 1);
77+
}
78+
{
79+
auto n = tester.findNextTransition();
80+
REQUIRE(n.itemType() == edm::InputSource::ItemType::IsEvent);
81+
auto r = tester.readEvent();
82+
REQUIRE(r.run() == 1);
83+
REQUIRE(r.luminosityBlock() == 1);
84+
REQUIRE(r.event() == 1);
85+
}
86+
{
87+
auto n = tester.findNextTransition();
88+
REQUIRE(n.itemType() == edm::InputSource::ItemType::IsStop);
89+
}
90+
}
91+
std::filesystem::remove(fileName);
92+
}
93+
94+
SECTION("EventWithThing") {
95+
const std::string fileName = "thing.root";
96+
{
97+
auto configString = setOutputFile(baseOutConfig, fileName);
98+
99+
edm::test::TestProcessor::Config config{configString};
100+
auto thingToken = config.produces<std::vector<edmtest::Thing>>("thing");
101+
102+
edm::test::TestProcessor tester(config);
103+
tester.test(std::make_pair(thingToken, std::make_unique<std::vector<edmtest::Thing>>(1, edmtest::Thing{1})));
104+
}
105+
{
106+
auto config = setInputFile(baseSourceConfig, fileName);
107+
edm::test::TestSourceProcessor tester(config);
108+
109+
{
110+
auto n = tester.findNextTransition();
111+
REQUIRE(n == edm::InputSource::ItemType::IsFile);
112+
auto f = tester.openFile();
113+
REQUIRE(bool(f));
114+
}
115+
{
116+
auto n = tester.findNextTransition();
117+
REQUIRE(n.itemType() == edm::InputSource::ItemType::IsRun);
118+
auto r = tester.readRun();
119+
REQUIRE(r.run() == 1);
120+
}
121+
{
122+
auto n = tester.findNextTransition();
123+
REQUIRE(n.itemType() == edm::InputSource::ItemType::IsLumi);
124+
auto r = tester.readLuminosityBlock();
125+
REQUIRE(r.run() == 1);
126+
REQUIRE(r.luminosityBlock() == 1);
127+
}
128+
{
129+
auto n = tester.findNextTransition();
130+
REQUIRE(n.itemType() == edm::InputSource::ItemType::IsEvent);
131+
auto r = tester.readEvent();
132+
REQUIRE(r.run() == 1);
133+
REQUIRE(r.luminosityBlock() == 1);
134+
REQUIRE(r.event() == 1);
135+
auto v = r.get<std::vector<edmtest::Thing>>("thing", "", "TEST");
136+
REQUIRE(v->size() == 1);
137+
REQUIRE((*v)[0].a == 1);
138+
}
139+
{
140+
auto n = tester.findNextTransition();
141+
REQUIRE(n.itemType() == edm::InputSource::ItemType::IsStop);
142+
}
143+
}
144+
std::filesystem::remove(fileName);
145+
}
146+
}

0 commit comments

Comments
 (0)