Skip to content

Commit

Permalink
Merge pull request #19633 from Dr15Jones/addExceptionTests
Browse files Browse the repository at this point in the history
Extend state machine test to include exceptions
  • Loading branch information
cmsbuild committed Jul 10, 2017
2 parents 0d534b8 + d21de95 commit 22055b5
Show file tree
Hide file tree
Showing 12 changed files with 432 additions and 4 deletions.
20 changes: 19 additions & 1 deletion FWCore/Framework/test/MockEventProcessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "FWCore/Framework/interface/InputSource.h"
#include <cassert>
#include <sstream>
#include <exception>

namespace {
// As each data item is read from the mock data it is
Expand Down Expand Up @@ -42,7 +43,8 @@ namespace edm {
shouldWeEndLoop_(true),
shouldWeStop_(false),
eventProcessed_(false),
reachedEndOfInput_(false)
reachedEndOfInput_(false),
shouldThrow_(false)
{
}

Expand Down Expand Up @@ -92,6 +94,10 @@ namespace edm {
output_ << " *** nextItemType: Restart " << t.value << " ***\n";
shouldWeEndLoop_ = t.value;
return InputSource::IsStop;
} else if(ch == 't') {
output_ << " *** nextItemType: Throw " << t.value << " ***\n";
shouldThrow_ = true;
return nextTransitionType();
}
return InputSource::IsInvalid;
}
Expand Down Expand Up @@ -150,6 +156,7 @@ namespace edm {

void MockEventProcessor::readFile() {
output_ << " \treadFile\n";
throwIfNeeded();
}

void MockEventProcessor::closeInputFile(bool /*cleaningUpAfterException*/) {
Expand Down Expand Up @@ -200,6 +207,7 @@ namespace edm {

void MockEventProcessor::beginRun(ProcessHistoryID const& phid, RunNumber_t run) {
output_ << "\tbeginRun " << run << "\n";
throwIfNeeded();
}

void MockEventProcessor::endRun(ProcessHistoryID const& phid, RunNumber_t run, bool /*cleaningUpAfterException*/ ) {
Expand All @@ -208,6 +216,7 @@ namespace edm {

void MockEventProcessor::beginLumi(ProcessHistoryID const&, RunNumber_t run, LuminosityBlockNumber_t lumi) {
output_ << "\tbeginLumi " << run << "/" << lumi << "\n";
throwIfNeeded();
}

void MockEventProcessor::endLumi(ProcessHistoryID const&, RunNumber_t run, LuminosityBlockNumber_t lumi, bool /*cleaningUpAfterException*/) {
Expand Down Expand Up @@ -254,13 +263,22 @@ namespace edm {
output_ << "\treadEvent\n";
output_ << "\tprocessEvent\n";
eventProcessed_ = true;
throwIfNeeded();
}

bool MockEventProcessor::shouldWeStop() const {
output_ << "\tshouldWeStop\n";
return eventProcessed_ and shouldWeStop_;
}

void MockEventProcessor::throwIfNeeded() {
if(shouldThrow_) {
shouldThrow_ = false;
output_ <<"\tthrowing\n";
throw TestException();
}
}

void MockEventProcessor::setExceptionMessageFiles(std::string&) {}
void MockEventProcessor::setExceptionMessageRuns(std::string&) {}
void MockEventProcessor::setExceptionMessageLumis(std::string&) {}
Expand Down
10 changes: 9 additions & 1 deletion FWCore/Framework/test/MockEventProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ Original Authors: W. David Dagenhart, Marc Paterno
#include <iostream>
#include <string>
#include <sstream>
#include <exception>

namespace edm {
class MockEventProcessor {
public:

class TestException : public std::exception {
public:
TestException() noexcept
:std::exception() {}
};

MockEventProcessor(std::string const& mockData,
std::ostream& output,
bool iDoNotMerge);
Expand Down Expand Up @@ -72,6 +78,7 @@ namespace edm {

private:
void readAndProcessEvent();
void throwIfNeeded();

std::string mockData_;
std::ostream & output_;
Expand All @@ -86,6 +93,7 @@ namespace edm {
bool shouldWeStop_;
bool eventProcessed_;
bool reachedEndOfInput_;
bool shouldThrow_;
};
}

Expand Down
9 changes: 9 additions & 0 deletions FWCore/Framework/test/run_statemachine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ pushd ${LOCAL_TMP_DIR}

done

#testing exceptions
for i in 20 21 22 23
do

${exe} -i ${input}${i}.txt -o ${output}${i}.txt || die "TestFWCoreFrameworkStatemachine with input ${i}" $?
diff ${reference_output}${i}.txt ${output}${i}.txt || die "comparing ${output}${i}.txt" $?

done

popd

exit 0
7 changes: 5 additions & 2 deletions FWCore/Framework/test/statemachine_t.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,11 @@ int main(int argc, char* argv[]) try {
edm::MockEventProcessor mockEventProcessor(mockData,
output,
mode);

mockEventProcessor.runToCompletion();
try {
mockEventProcessor.runToCompletion();
} catch(edm::MockEventProcessor::TestException const& e) {
output <<"caught test exception\n";
}
}
return 0;
} catch(std::exception const& e) {
Expand Down
9 changes: 9 additions & 0 deletions FWCore/Framework/test/unit_test_outputs/statemachine_20.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
f 1
r 1
l 1
e 1
f 0
r 2
l 1
t 1
e 1
9 changes: 9 additions & 0 deletions FWCore/Framework/test/unit_test_outputs/statemachine_21.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
f 1
r 1
l 1
e 1
f 0
r 2
t 1
l 1

9 changes: 9 additions & 0 deletions FWCore/Framework/test/unit_test_outputs/statemachine_22.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
f 1
r 1
l 1
e 1
f 0
t 1
r 2


8 changes: 8 additions & 0 deletions FWCore/Framework/test/unit_test_outputs/statemachine_23.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
f 1
r 1
l 1
e 1
t 1
f 0


103 changes: 103 additions & 0 deletions FWCore/Framework/test/unit_test_outputs/statemachine_output_20.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@

Machine parameters: mode = NOMERGE
startingNewLoop
*** nextItemType: File 1 ***
readFile
respondToOpenInputFile
openOutputFiles
*** nextItemType: Run 1 ***
readRun 1
beginRun 1
*** nextItemType: Lumi 1 ***
readLuminosityBlock 1
beginLumi 1/1
*** nextItemType: Event ***
readEvent
processEvent
shouldWeStop
*** nextItemType: File 0 ***
shouldWeStop
endLumi 1/1
writeLumi 1/1
deleteLumiFromCache 1/1
endRun 1
writeRun 1
deleteRunFromCache 1
respondToCloseInputFile
closeInputFile
closeOutputFiles
readFile
respondToOpenInputFile
openOutputFiles
*** nextItemType: Run 2 ***
readRun 2
beginRun 2
*** nextItemType: Lumi 1 ***
readLuminosityBlock 1
beginLumi 2/1
*** nextItemType: Throw 1 ***
*** nextItemType: Event ***
readEvent
processEvent
throwing
endLumi 2/1
writeLumi 2/1
deleteLumiFromCache 2/1
endRun 2
writeRun 2
deleteRunFromCache 2
respondToCloseInputFile
closeInputFile
closeOutputFiles
caught test exception

Machine parameters: mode = FULLMERGE
startingNewLoop
*** nextItemType: File 1 ***
readFile
respondToOpenInputFile
openOutputFiles
*** nextItemType: Run 1 ***
readRun 1
beginRun 1
*** nextItemType: Lumi 1 ***
readLuminosityBlock 1
beginLumi 1/1
*** nextItemType: Event ***
readEvent
processEvent
shouldWeStop
*** nextItemType: File 0 ***
shouldWeStop
shouldWeCloseOutput
respondToCloseInputFile
closeInputFile
readFile
respondToOpenInputFile
*** nextItemType: Run 2 ***
endLumi 1/1
writeLumi 1/1
deleteLumiFromCache 1/1
endRun 1
writeRun 1
deleteRunFromCache 1
readRun 2
beginRun 2
*** nextItemType: Lumi 1 ***
readLuminosityBlock 1
beginLumi 2/1
*** nextItemType: Throw 1 ***
*** nextItemType: Event ***
readEvent
processEvent
throwing
endLumi 2/1
writeLumi 2/1
deleteLumiFromCache 2/1
endRun 2
writeRun 2
deleteRunFromCache 2
respondToCloseInputFile
closeInputFile
closeOutputFiles
caught test exception
97 changes: 97 additions & 0 deletions FWCore/Framework/test/unit_test_outputs/statemachine_output_21.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@

Machine parameters: mode = NOMERGE
startingNewLoop
*** nextItemType: File 1 ***
readFile
respondToOpenInputFile
openOutputFiles
*** nextItemType: Run 1 ***
readRun 1
beginRun 1
*** nextItemType: Lumi 1 ***
readLuminosityBlock 1
beginLumi 1/1
*** nextItemType: Event ***
readEvent
processEvent
shouldWeStop
*** nextItemType: File 0 ***
shouldWeStop
endLumi 1/1
writeLumi 1/1
deleteLumiFromCache 1/1
endRun 1
writeRun 1
deleteRunFromCache 1
respondToCloseInputFile
closeInputFile
closeOutputFiles
readFile
respondToOpenInputFile
openOutputFiles
*** nextItemType: Run 2 ***
readRun 2
beginRun 2
*** nextItemType: Throw 1 ***
*** nextItemType: Lumi 1 ***
readLuminosityBlock 1
beginLumi 2/1
throwing
endLumi 2/1
writeLumi 2/1
deleteLumiFromCache 2/1
endRun 2
writeRun 2
deleteRunFromCache 2
respondToCloseInputFile
closeInputFile
closeOutputFiles
caught test exception

Machine parameters: mode = FULLMERGE
startingNewLoop
*** nextItemType: File 1 ***
readFile
respondToOpenInputFile
openOutputFiles
*** nextItemType: Run 1 ***
readRun 1
beginRun 1
*** nextItemType: Lumi 1 ***
readLuminosityBlock 1
beginLumi 1/1
*** nextItemType: Event ***
readEvent
processEvent
shouldWeStop
*** nextItemType: File 0 ***
shouldWeStop
shouldWeCloseOutput
respondToCloseInputFile
closeInputFile
readFile
respondToOpenInputFile
*** nextItemType: Run 2 ***
endLumi 1/1
writeLumi 1/1
deleteLumiFromCache 1/1
endRun 1
writeRun 1
deleteRunFromCache 1
readRun 2
beginRun 2
*** nextItemType: Throw 1 ***
*** nextItemType: Lumi 1 ***
readLuminosityBlock 1
beginLumi 2/1
throwing
endLumi 2/1
writeLumi 2/1
deleteLumiFromCache 2/1
endRun 2
writeRun 2
deleteRunFromCache 2
respondToCloseInputFile
closeInputFile
closeOutputFiles
caught test exception

0 comments on commit 22055b5

Please sign in to comment.