File: profiler_manager_gtest.cc

package info (click to toggle)
benchmark 1.9.5-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 1,820 kB
  • sloc: cpp: 14,339; python: 2,399; ansic: 38; sh: 28; makefile: 14
file content (42 lines) | stat: -rw-r--r-- 1,007 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <memory>

#include "benchmark/benchmark.h"
#include "gtest/gtest.h"

namespace {

class TestProfilerManager : public benchmark::ProfilerManager {
 public:
  void AfterSetupStart() override { ++start_called; }
  void BeforeTeardownStop() override { ++stop_called; }

  int start_called = 0;
  int stop_called = 0;
};

void BM_empty(benchmark::State& state) {
  for (auto _ : state) {
    auto iterations = state.iterations();
    benchmark::DoNotOptimize(iterations);
  }
}
BENCHMARK(BM_empty);

TEST(ProfilerManager, ReregisterManager) {
#if GTEST_HAS_DEATH_TEST
  // Tests only runnable in debug mode (when BM_CHECK is enabled).
#ifndef NDEBUG
#ifndef TEST_BENCHMARK_LIBRARY_HAS_NO_ASSERTIONS
  ASSERT_DEATH_IF_SUPPORTED(
      {
        std::unique_ptr<TestProfilerManager> pm(new TestProfilerManager());
        benchmark::RegisterProfilerManager(pm.get());
        benchmark::RegisterProfilerManager(pm.get());
      },
      "RegisterProfilerManager");
#endif
#endif
#endif
}

}  // namespace