Skip to content

Commit

Permalink
Add unit test for global::OutputModule<ExternalWork>
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr15Jones committed Jul 21, 2021
1 parent 9199604 commit 796eba8
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
1 change: 1 addition & 0 deletions FWCore/Framework/test/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -395,3 +395,4 @@
<test name="testFWCoreFrameworkNonEventOrdering" command="test_non_event_ordering.sh"/>
<test name="testFWCoreFramework1ThreadESPrefetch" command="run_test_1_thread_es_prefetching.sh"/>
<test name="testFWCoreFrameworkModuleDeletion" command="run_module_delete_tests.sh"/>
<test name="testFWCoreFrameworkExternalWorkOutputModule" command="cmsRun ${LOCALTOP}/src/FWCore/Framework/test/testExternalWorkGlobalOutputModule_cfg.py"/>
63 changes: 63 additions & 0 deletions FWCore/Framework/test/stubs/TestFilterModule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/Framework/interface/one/EDFilter.h"
#include "FWCore/Framework/interface/one/OutputModule.h"
#include "FWCore/Framework/interface/global/OutputModule.h"
#include "FWCore/Framework/interface/global/EDAnalyzer.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"

Expand Down Expand Up @@ -88,6 +89,25 @@ namespace edmtest {
int total_;
};

class ExternalWorkSewerModule : public edm::global::OutputModule<edm::ExternalWork> {
public:
explicit ExternalWorkSewerModule(edm::ParameterSet const&);

static void fillDescriptions(ConfigurationDescriptions& descriptions);

private:
void write(edm::EventForOutput const& e) override;
void acquire(edm::StreamID, edm::EventForOutput const& e, edm::WaitingTaskWithArenaHolder) const override;
void writeLuminosityBlock(edm::LuminosityBlockForOutput const&) override {}
void writeRun(edm::RunForOutput const&) override {}
void endJob() override;

const std::string name_;
const int num_pass_;
mutable std::atomic<int> total_;
mutable std::atomic<int> totalAcquire_;
};

// -----------------------------------------------------------------

TestResultAnalyzer::TestResultAnalyzer(edm::ParameterSet const& ps)
Expand Down Expand Up @@ -202,8 +222,50 @@ namespace edmtest {
descriptions.add("sewerModule", desc);
}

// ---------

ExternalWorkSewerModule::ExternalWorkSewerModule(edm::ParameterSet const& ps)
: edm::global::OutputModuleBase::OutputModuleBase(ps),
edm::global::OutputModule<edm::ExternalWork>(ps),
name_(ps.getParameter<std::string>("name")),
num_pass_(ps.getParameter<int>("shouldPass")),
total_(0),
totalAcquire_(0) {}

void ExternalWorkSewerModule::acquire(edm::StreamID,
edm::EventForOutput const&,
WaitingTaskWithArenaHolder task) const {
++totalAcquire_;
}
void ExternalWorkSewerModule::write(edm::EventForOutput const&) { ++total_; }

void ExternalWorkSewerModule::endJob() {
std::cerr << "EXTERNALWORKSEWERMODULE " << name_ << ": should pass " << num_pass_ << ", did pass " << total_.load()
<< " with acquire " << totalAcquire_.load() << "\n";

if (total_.load() != num_pass_) {
std::cerr << "number passed should be " << num_pass_ << ", but got " << total_.load() << "\n";
abort();
}

if (total_.load() != totalAcquire_.load()) {
std::cerr << "write() called " << total_.load() << ", but acquire called " << totalAcquire_.load() << "\n";
abort();
}
}

void ExternalWorkSewerModule::fillDescriptions(ConfigurationDescriptions& descriptions) {
ParameterSetDescription desc;
desc.setComment("Tracks number of times the write and acquire methods are called.");
desc.add<std::string>("name")->setComment("name used in printout");
desc.add<int>("shouldPass")->setComment("number of times write/acquire should be called");
edm::one::OutputModule<>::fillDescription(desc, std::vector<std::string>(1U, std::string("drop *")));
descriptions.add("externalWorkSewerModule", desc);
}

} // namespace edmtest

using edmtest::ExternalWorkSewerModule;
using edmtest::SewerModule;
using edmtest::TestContextAnalyzer;
using edmtest::TestFilterModule;
Expand All @@ -212,4 +274,5 @@ using edmtest::TestResultAnalyzer;
DEFINE_FWK_MODULE(TestFilterModule);
DEFINE_FWK_MODULE(TestResultAnalyzer);
DEFINE_FWK_MODULE(SewerModule);
DEFINE_FWK_MODULE(ExternalWorkSewerModule);
DEFINE_FWK_MODULE(TestContextAnalyzer);
50 changes: 50 additions & 0 deletions FWCore/Framework/test/testExternalWorkGlobalOutputModule_cfg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import FWCore.ParameterSet.Config as cms

process = cms.Process("PROD")

import FWCore.Framework.test.cmsExceptionsFatalOption_cff
process.options = cms.untracked.PSet(
wantSummary = cms.untracked.bool(True),
Rethrow = FWCore.Framework.test.cmsExceptionsFatalOption_cff.Rethrow
)

process.maxEvents = cms.untracked.PSet(
input = cms.untracked.int32(99)
)

process.source = cms.Source("EmptySource")

process.f1 = cms.EDFilter("TestFilterModule",
acceptValue = cms.untracked.int32(30),
onlyOne = cms.untracked.bool(True)
)

process.outp = cms.OutputModule("ExternalWorkSewerModule",
shouldPass = cms.int32(3),
name = cms.string('for_p'),
SelectEvents = cms.untracked.PSet(
SelectEvents = cms.vstring('p')
)
)

process.outNone = cms.OutputModule("ExternalWorkSewerModule",
shouldPass = cms.int32(99),
name = cms.string('for_none')
)

process.outpempty = cms.OutputModule("ExternalWorkSewerModule",
shouldPass = cms.int32(99),
name = cms.string('pEmpty'),
SelectEvents = cms.untracked.PSet(
SelectEvents = cms.vstring('pEmpty')
)
)

process.pEmpty = cms.Path()
process.p = cms.Path(process.f1)

process.e1 = cms.EndPath(process.outp)
process.e2 = cms.EndPath(process.outNone)
process.e3 = cms.EndPath(process.outpempty)


0 comments on commit 796eba8

Please sign in to comment.