Skip to content

Commit

Permalink
Merge 4db5fe3 into 8982e1e
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Feb 14, 2020
2 parents 8982e1e + 4db5fe3 commit 573818b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions include/benchmark/benchmark.h
Expand Up @@ -541,6 +541,9 @@ class State {
// responsibility to exit the scope as needed.
void SkipWithError(const char* msg);

// Returns true if an error has been reported with 'SkipWithError(...)'.
bool error_occurred() const { return error_occurred_; }

// REQUIRES: called exactly once per iteration of the benchmarking loop.
// Set the manually measured time for this benchmark iteration, which
// is used instead of automatically measured time if UseManualTime() was
Expand Down
2 changes: 1 addition & 1 deletion src/benchmark_runner.cc
Expand Up @@ -117,7 +117,7 @@ void RunInThread(const BenchmarkInstance* b, IterationCount iters,
? internal::ThreadTimer::CreateProcessCpuTime()
: internal::ThreadTimer::Create());
State st = b->Run(iters, thread_id, &timer, manager);
CHECK(st.iterations() >= st.max_iterations)
CHECK(st.error_occurred() || st.iterations() >= st.max_iterations)
<< "Benchmark returned before State::KeepRunning() returned false!";
{
MutexLock l(manager->GetBenchmarkMutex());
Expand Down
6 changes: 6 additions & 0 deletions test/skip_with_error_test.cc
Expand Up @@ -61,6 +61,12 @@ int AddCases(const char* base_name, std::initializer_list<TestCase> const& v) {

} // end namespace

void BM_error_no_running(benchmark::State& state) {
state.SkipWithError("error message");
}
BENCHMARK(BM_error_no_running);
ADD_CASES("BM_error_no_running", {{"", true, "error message"}});

void BM_error_before_running(benchmark::State& state) {
state.SkipWithError("error message");
while (state.KeepRunning()) {
Expand Down

0 comments on commit 573818b

Please sign in to comment.