-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Verify RegisterProfilerManager doesn't overwrite an existing registra…
…tion (#1837) * Verify RegisterProfilerManager doesn't overwrite an existing registration Tested: Add a second registration to test/profiler_manager_test.cc and verify the test crashes as expected. * Verify RegisterProfilerManager doesn't overwrite an existing registration Tested: Configure with: cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DBENCHMARK_DOWNLOAD_DEPENDENCIES=on Then run: ctest -R profiler_manager_gtest Before change test fails (expected), after change test passes (expected) --------- Co-authored-by: dominic <[email protected]>
- Loading branch information
Showing
3 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |