Skip to content

Commit

Permalink
Merge pull request #23194 from Dr15Jones/testHarness
Browse files Browse the repository at this point in the history
Added the TestProcessor system
  • Loading branch information
cmsbuild committed May 14, 2018
2 parents d75c484 + 37e4cbc commit 1b8e196
Show file tree
Hide file tree
Showing 25 changed files with 2,459 additions and 78 deletions.
2 changes: 1 addition & 1 deletion DataFormats/TrackReco/interface/HitPattern.h
Expand Up @@ -479,7 +479,7 @@ class HitPattern
uint8_t beginOuter;
uint8_t endOuter;

friend int test::TestHitPattern::test();
friend int ::test::TestHitPattern::test();

template<int N>
friend struct PatternSet;
Expand Down
24 changes: 15 additions & 9 deletions FWCore/Framework/src/Principal.cc
Expand Up @@ -241,17 +241,23 @@ namespace edm {
}
}
//Need to know if the product from this processes is added at end of transition
bool productMadeAtEnd = false;
for(unsigned int i=0; i< matchingHolders.size();++i) {
if( (not ambiguous[i]) and
ProductResolverIndexInvalid != matchingHolders[i] and
productResolvers_[matchingHolders[i]]->branchDescription().availableOnlyAtEndTransition()) {
productMadeAtEnd = true;
break;
if ((numberOfMatches == 1) and
(lastMatchIndex != ProductResolverIndexAmbiguous)) {
//only one choice so use a special resolver
productResolvers_.at(productResolverIndex) = std::make_shared<SingleChoiceNoProcessProductResolver>(lastMatchIndex);
} else {
bool productMadeAtEnd = false;
for(unsigned int i=0; i< matchingHolders.size();++i) {
if( (not ambiguous[i]) and
ProductResolverIndexInvalid != matchingHolders[i] and
productResolvers_[matchingHolders[i]]->branchDescription().availableOnlyAtEndTransition()) {
productMadeAtEnd = true;
break;
}
}
std::shared_ptr<ProductResolverBase> newHolder = std::make_shared<NoProcessProductResolver>(matchingHolders, ambiguous, productMadeAtEnd);
productResolvers_.at(productResolverIndex) = newHolder;
}
std::shared_ptr<ProductResolverBase> newHolder = std::make_shared<NoProcessProductResolver>(matchingHolders, ambiguous, productMadeAtEnd);
productResolvers_.at(productResolverIndex) = newHolder;
}
}

Expand Down
28 changes: 26 additions & 2 deletions FWCore/Integration/test/ESTestAnalyzers.cc
Expand Up @@ -8,6 +8,8 @@
#include "FWCore/Integration/interface/ESTestRecords.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"

#include <algorithm>
#include <vector>
Expand All @@ -19,23 +21,45 @@ namespace edmtest {
explicit ESTestAnalyzerA(edm::ParameterSet const&);
virtual void analyze(const edm::Event&, const edm::EventSetup&);

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
private:
std::vector<int> runsToGetDataFor_;
std::vector<int> expectedValues_;
};

ESTestAnalyzerA::ESTestAnalyzerA(edm::ParameterSet const& pset) :
runsToGetDataFor_(pset.getParameter<std::vector<int> >("runsToGetDataFor")) {
runsToGetDataFor_(pset.getParameter<std::vector<int> >("runsToGetDataFor")),
expectedValues_(pset.getUntrackedParameter<std::vector<int>>("expectedValues")){
assert( expectedValues_.empty() or expectedValues_.size() == runsToGetDataFor_.size());
}

void ESTestAnalyzerA::analyze(edm::Event const& ev, edm::EventSetup const& es) {
if (std::find(runsToGetDataFor_.begin(), runsToGetDataFor_.end(), ev.run()) != runsToGetDataFor_.end()) {
auto found = std::find(runsToGetDataFor_.begin(), runsToGetDataFor_.end(), ev.run());
if ( found != runsToGetDataFor_.end()) {
ESTestRecordA const& rec = es.get<ESTestRecordA>();
edm::ESHandle<ESTestDataA> dataA;
rec.get(dataA);
edm::LogAbsolute("ESTestAnalyzerA") << "ESTestAnalyzerA: process = " << moduleDescription().processName() << ": Data value = " << dataA->value();
if(not expectedValues_.empty()) {
if(expectedValues_[found-runsToGetDataFor_.begin()] != dataA->value()) {
throw cms::Exception("TestError")<<"Exptected value "<<expectedValues_[found-runsToGetDataFor_.begin()]<<" but saw "<<dataA->value();
}
}
}
}

void ESTestAnalyzerA::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
//The following says we do not know what parameters are allowed so do no validation
// Please change this to state exactly what you do use, even if it is no parameters
edm::ParameterSetDescription desc;
desc.setComment("Test module for the EventSetup");
desc.add<std::vector<int>>("runsToGetDataFor")
->setComment("ID number for each Run for which we should get EventSetup data.");
desc.addUntracked<std::vector<int>>("expectedValues",std::vector<int>())
->setComment("EventSetup value expected for each Run. If empty, no values compared.");
descriptions.addDefault(desc);
}



class ESTestAnalyzerB : public edm::EDAnalyzer {
Expand Down
132 changes: 66 additions & 66 deletions FWCore/Modules/src/LogErrorFilter.cc
Expand Up @@ -111,85 +111,85 @@ LogErrorFilter::filter(edm::Event& iEvent, edm::EventSetup const&) {
unsigned int errorsBelowThreshold = 0;
unsigned int warningsBelowThreshold = 0;
// update counters here
for(unsigned int iE = 0; iE != errorsAndWarnings->size(); ++iE) {
const edm::ErrorSummaryEntry& iSummary = (*errorsAndWarnings)[iE];
if (std::find(avoidCategories_.begin(),avoidCategories_.end(), iSummary.category) != avoidCategories_.end() )
continue;
std::string kind= iSummary.category + ":" + iSummary.module;
int iSeverity = iSummary.severity.getLevel();
if (iSeverity == edm::ELseverityLevel::ELsev_error){
unsigned int& iCount = errorCounts_[kind];
iCount++;
if (iCount <= maxErrorKindsPerLumi_) errorsBelowThreshold++;
}
if (iSeverity == edm::ELseverityLevel::ELsev_warning){
unsigned int& iCount = warningCounts_[kind];
iCount++;
if (iCount <= maxWarningKindsPerLumi_) warningsBelowThreshold++;
}
for(auto const& summary : *errorsAndWarnings) {
if (std::find(avoidCategories_.begin(),avoidCategories_.end(), summary.category) != avoidCategories_.end() )
continue;
std::string kind= summary.category + ":" + summary.module;
int iSeverity = summary.severity.getLevel();
if (iSeverity == edm::ELseverityLevel::ELsev_error){
unsigned int& iCount = errorCounts_[kind];
iCount++;
if (iCount <= maxErrorKindsPerLumi_) errorsBelowThreshold++;
} else if (iSeverity == edm::ELseverityLevel::ELsev_warning){
unsigned int& iCount = warningCounts_[kind];
iCount++;
if (iCount <= maxWarningKindsPerLumi_) warningsBelowThreshold++;
}

}
return ( (atLeastOneEntry_ && (errorsBelowThreshold > 0 || warningsBelowThreshold > 0))
|| (atLeastOneError_ && errorsBelowThreshold > 0)
|| (atLeastOneWarning_ && warningsBelowThreshold > 0));
|| (atLeastOneError_ && errorsBelowThreshold > 0)
|| (atLeastOneWarning_ && warningsBelowThreshold > 0));
} else {
//no separation by kind, just count any errors/warnings
if(atLeastOneEntry_) {
if(!avoidCategories_.empty()) {
for(unsigned int iE = 0; iE != errorsAndWarnings->size(); ++iE) {
//veto categories from user input.
if(std::find(avoidCategories_.begin(),avoidCategories_.end(), ((*errorsAndWarnings)[iE]).category) != avoidCategories_.end()) {
continue;
} else {
return true;
}
}
return false;
} else {
return (!errorsAndWarnings->empty());
}
for(auto const& summary: *errorsAndWarnings) {
edm::ELseverityLevel const& severity = summary.severity;
if(severity.getLevel() != edm::ELseverityLevel::ELsev_error and
severity.getLevel() != edm::ELseverityLevel::ELsev_warning) {
continue;
}
if(!avoidCategories_.empty()) {
//veto categories from user input.
if(std::find(avoidCategories_.begin(),avoidCategories_.end(),summary.category) != avoidCategories_.end()) {
continue;
}
}
return true;
}
return false;
} else {
if(atLeastOneError_ || atLeastOneWarning_) {
unsigned int nError = 0;
unsigned int nWarning = 0;
for(unsigned int iE = 0; iE != errorsAndWarnings->size(); ++iE) {
//veto categories from user input.
if(!avoidCategories_.empty()) {
if(std::find(avoidCategories_.begin(),avoidCategories_.end(), ((*errorsAndWarnings)[iE]).category) != avoidCategories_.end()) {
continue;
}
}
edm::ELseverityLevel const& severity = ((*errorsAndWarnings)[iE]).severity;
//count errors
if(severity.getLevel() == edm::ELseverityLevel::ELsev_error) {
++nError;
}
//count warnings
if(severity.getLevel() == edm::ELseverityLevel::ELsev_warning) {
++nWarning;
}
}
if(atLeastOneError_ && nError != 0) {
return (true);
}
if(atLeastOneWarning_ && nWarning != 0) {
return (true);
}
}
if(atLeastOneError_ || atLeastOneWarning_) {
unsigned int nError = 0;
unsigned int nWarning = 0;
for(auto const& summary: *errorsAndWarnings) {
//veto categories from user input.
if(!avoidCategories_.empty()) {
if(std::find(avoidCategories_.begin(),avoidCategories_.end(), summary.category) != avoidCategories_.end()) {
continue;
}
}
edm::ELseverityLevel const& severity = summary.severity;
//count errors
if(severity.getLevel() == edm::ELseverityLevel::ELsev_error) {
++nError;
}
//count warnings
if(severity.getLevel() == edm::ELseverityLevel::ELsev_warning) {
++nWarning;
}
}
if(atLeastOneError_ && nError != 0) {
return (true);
}
if(atLeastOneWarning_ && nWarning != 0) {
return (true);
}
}
}
}
}
return (false);
}

void LogErrorFilter::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&){
if (useThresholdsPerKind_){
typedef std::map<std::string, unsigned int>::iterator msIter;
msIter errorMI = errorCounts_.begin();
msIter errorMIEnd = errorCounts_.end();
for (;errorMI != errorMIEnd; ++errorMI) errorMI->second = 0;
msIter warningMI = warningCounts_.begin();
msIter warningMIEnd = warningCounts_.end();
for (;warningMI != warningMIEnd; ++warningMI) warningMI->second = 0;
if (useThresholdsPerKind_) {
for(auto& err: errorCounts_) {
err.second = 0;
}
for(auto& err: warningCounts_) {
err.second = 0;
}
}

return;
Expand Down
4 changes: 4 additions & 0 deletions FWCore/Modules/test/BuildFile.xml
Expand Up @@ -3,4 +3,8 @@
<flags TEST_RUNNER_ARGS=" /bin/bash FWCore/Modules/test FWCoreModulesTest.sh"/>
<use name="FWCore/Utilities"/>
</bin>
<bin file="test_catch2_*.cc" name="TestFWCoreModulesTP">
<use name="FWCore/TestProcessor"/>
<use name="catch2"/>
</bin>
</environment>

0 comments on commit 1b8e196

Please sign in to comment.