-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit test for Pool Output/Source
This uses the new TestSourceProcessor and changes in TestProcessor to support OutputModules.
- Loading branch information
Showing
3 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
<test name="TestEdmFastMerge" command="TestEdmFastMerge.sh"/> | ||
<test name="TestEdmConfigDump" command="run_TestEdmConfigDump.sh"/> | ||
<test name="testIOPoolCommonLumiOverlap" command="test_overlap_lumi_fast_copy.sh"/> | ||
<bin file="test_catch2_*.cc" name="TestIOPoolCommonTP"> | ||
<use name="FWCore/TestProcessor"/> | ||
<use name="catch2"/> | ||
</bin> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#define CATCH_CONFIG_MAIN | ||
#include "catch.hpp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
#include "FWCore/TestProcessor/interface/TestProcessor.h" | ||
#include "FWCore/TestProcessor/interface/TestSourceProcessor.h" | ||
#include "FWCore/Utilities/interface/Exception.h" | ||
|
||
#include "DataFormats/TestObjects/interface/Thing.h" | ||
#include <vector> | ||
#include <filesystem> | ||
#include "catch.hpp" | ||
|
||
static constexpr auto s_tag = "[PoolOutputSource]"; | ||
|
||
namespace { | ||
std::string setOutputFile(std::string const& iConfig, std::string const& iFileName) { | ||
using namespace std::string_literals; | ||
return iConfig + "\nprocess.out.fileName = '"s + iFileName + "'\n"; | ||
} | ||
|
||
std::string setInputFile(std::string const& iConfig, std::string const& iFileName) { | ||
using namespace std::string_literals; | ||
return iConfig + "\nprocess.source.fileNames = ['file:"s + iFileName + "']\n"; | ||
} | ||
} // namespace | ||
TEST_CASE("Tests of PoolOuput -> PoolSource", s_tag) { | ||
const std::string baseOutConfig{ | ||
R"_(from FWCore.TestProcessor.TestProcess import * | ||
process = TestProcess() | ||
process.out = cms.OutputModule('PoolOutputModule', | ||
fileName = cms.untracked.string('') | ||
) | ||
process.add_(cms.Service("InitRootHandlers")) | ||
process.add_(cms.Service("JobReportService")) | ||
process.moduleToTest(process.out) | ||
)_"}; | ||
|
||
const std::string baseSourceConfig{ | ||
R"_(from FWCore.TestProcessor.TestSourceProcess import * | ||
process = TestSourceProcess() | ||
process.source = cms.Source("PoolSource", fileNames = cms.untracked.vstring('')) | ||
process.add_(cms.Service("InitRootHandlers")) | ||
process.add_(cms.Service("SiteLocalConfigService")) | ||
process.add_(cms.Service("JobReportService")) | ||
)_"}; | ||
|
||
SECTION("OneEmptyEvent") { | ||
const std::string fileName = "one_event.root"; | ||
{ | ||
auto configString = setOutputFile(baseOutConfig, fileName); | ||
|
||
edm::test::TestProcessor::Config config{configString}; | ||
|
||
edm::test::TestProcessor tester(config); | ||
tester.test(); | ||
} | ||
{ | ||
auto config = setInputFile(baseSourceConfig, fileName); | ||
edm::test::TestSourceProcessor tester(config); | ||
|
||
{ | ||
auto n = tester.findNextTransition(); | ||
REQUIRE(n == edm::InputSource::ItemType::IsFile); | ||
auto f = tester.openFile(); | ||
REQUIRE(bool(f)); | ||
} | ||
{ | ||
auto n = tester.findNextTransition(); | ||
REQUIRE(n.itemType() == edm::InputSource::ItemType::IsRun); | ||
auto r = tester.readRun(); | ||
REQUIRE(r.run() == 1); | ||
} | ||
{ | ||
auto n = tester.findNextTransition(); | ||
REQUIRE(n.itemType() == edm::InputSource::ItemType::IsLumi); | ||
auto r = tester.readLuminosityBlock(); | ||
REQUIRE(r.run() == 1); | ||
REQUIRE(r.luminosityBlock() == 1); | ||
} | ||
{ | ||
auto n = tester.findNextTransition(); | ||
REQUIRE(n.itemType() == edm::InputSource::ItemType::IsEvent); | ||
auto r = tester.readEvent(); | ||
REQUIRE(r.run() == 1); | ||
REQUIRE(r.luminosityBlock() == 1); | ||
REQUIRE(r.event() == 1); | ||
} | ||
{ | ||
auto n = tester.findNextTransition(); | ||
REQUIRE(n.itemType() == edm::InputSource::ItemType::IsStop); | ||
} | ||
} | ||
std::filesystem::remove(fileName); | ||
} | ||
|
||
SECTION("EventWithThing") { | ||
const std::string fileName = "thing.root"; | ||
{ | ||
auto configString = setOutputFile(baseOutConfig, fileName); | ||
|
||
edm::test::TestProcessor::Config config{configString}; | ||
auto thingToken = config.produces<std::vector<edmtest::Thing>>("thing"); | ||
|
||
edm::test::TestProcessor tester(config); | ||
tester.test(std::make_pair(thingToken, std::make_unique<std::vector<edmtest::Thing>>(1, edmtest::Thing{1}))); | ||
} | ||
{ | ||
auto config = setInputFile(baseSourceConfig, fileName); | ||
edm::test::TestSourceProcessor tester(config); | ||
|
||
{ | ||
auto n = tester.findNextTransition(); | ||
REQUIRE(n == edm::InputSource::ItemType::IsFile); | ||
auto f = tester.openFile(); | ||
REQUIRE(bool(f)); | ||
} | ||
{ | ||
auto n = tester.findNextTransition(); | ||
REQUIRE(n.itemType() == edm::InputSource::ItemType::IsRun); | ||
auto r = tester.readRun(); | ||
REQUIRE(r.run() == 1); | ||
} | ||
{ | ||
auto n = tester.findNextTransition(); | ||
REQUIRE(n.itemType() == edm::InputSource::ItemType::IsLumi); | ||
auto r = tester.readLuminosityBlock(); | ||
REQUIRE(r.run() == 1); | ||
REQUIRE(r.luminosityBlock() == 1); | ||
} | ||
{ | ||
auto n = tester.findNextTransition(); | ||
REQUIRE(n.itemType() == edm::InputSource::ItemType::IsEvent); | ||
auto r = tester.readEvent(); | ||
REQUIRE(r.run() == 1); | ||
REQUIRE(r.luminosityBlock() == 1); | ||
REQUIRE(r.event() == 1); | ||
auto v = r.get<std::vector<edmtest::Thing>>("thing", "", "TEST"); | ||
REQUIRE(v->size() == 1); | ||
REQUIRE((*v)[0].a == 1); | ||
} | ||
{ | ||
auto n = tester.findNextTransition(); | ||
REQUIRE(n.itemType() == edm::InputSource::ItemType::IsStop); | ||
} | ||
} | ||
std::filesystem::remove(fileName); | ||
} | ||
} |