2016-05-23 21:27:43 +00:00
|
|
|
// Testing:
|
|
|
|
// State::PauseTiming()
|
|
|
|
// State::ResumeTiming()
|
|
|
|
// Test that CHECK's within these function diagnose when they are called
|
|
|
|
// outside of the KeepRunning() loop.
|
|
|
|
//
|
|
|
|
// NOTE: Users should NOT include or use src/check.h. This is only done in
|
|
|
|
// order to test library internals.
|
2016-05-23 21:05:55 +00:00
|
|
|
|
2016-05-23 21:38:30 +00:00
|
|
|
#include <cstdlib>
|
2016-10-07 18:04:50 +00:00
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
#include "../src/check.h"
|
|
|
|
#include "benchmark/benchmark_api.h"
|
2016-05-23 21:38:30 +00:00
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__EXCEPTIONS)
|
|
|
|
#define TEST_HAS_NO_EXCEPTIONS
|
|
|
|
#endif
|
2016-05-23 21:05:55 +00:00
|
|
|
|
2016-05-23 21:27:43 +00:00
|
|
|
void TestHandler() {
|
2016-05-23 21:38:30 +00:00
|
|
|
#ifndef TEST_HAS_NO_EXCEPTIONS
|
2016-05-23 21:05:55 +00:00
|
|
|
throw std::logic_error("");
|
2016-05-23 21:38:30 +00:00
|
|
|
#else
|
|
|
|
std::abort();
|
|
|
|
#endif
|
2016-05-23 21:05:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void try_invalid_pause_resume(benchmark::State& state) {
|
2016-05-23 21:38:30 +00:00
|
|
|
#if !defined(NDEBUG) && !defined(TEST_HAS_NO_EXCEPTIONS)
|
2016-05-23 21:05:55 +00:00
|
|
|
try {
|
|
|
|
state.PauseTiming();
|
|
|
|
std::abort();
|
2016-10-07 18:04:50 +00:00
|
|
|
} catch (std::logic_error const&) {
|
|
|
|
}
|
2016-05-23 21:05:55 +00:00
|
|
|
try {
|
|
|
|
state.ResumeTiming();
|
|
|
|
std::abort();
|
2016-10-07 18:04:50 +00:00
|
|
|
} catch (std::logic_error const&) {
|
|
|
|
}
|
2016-05-23 21:05:55 +00:00
|
|
|
#else
|
2016-10-07 18:04:50 +00:00
|
|
|
(void)state; // avoid unused warning
|
2016-05-23 21:05:55 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void BM_diagnostic_test(benchmark::State& state) {
|
|
|
|
static bool called_once = false;
|
|
|
|
|
|
|
|
if (called_once == false) try_invalid_pause_resume(state);
|
|
|
|
|
|
|
|
while (state.KeepRunning()) {
|
|
|
|
benchmark::DoNotOptimize(state.iterations());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (called_once == false) try_invalid_pause_resume(state);
|
|
|
|
|
|
|
|
called_once = true;
|
|
|
|
}
|
|
|
|
BENCHMARK(BM_diagnostic_test);
|
|
|
|
|
2016-10-07 18:04:50 +00:00
|
|
|
int main(int argc, char* argv[]) {
|
2016-05-23 21:27:43 +00:00
|
|
|
benchmark::internal::GetAbortHandler() = &TestHandler;
|
2016-05-23 21:05:55 +00:00
|
|
|
benchmark::Initialize(&argc, argv);
|
|
|
|
benchmark::RunSpecifiedBenchmarks();
|
2016-05-23 21:07:54 +00:00
|
|
|
}
|