Merge branch 'main' into task/update-gtest-and-remove-warnings

This commit is contained in:
dominic 2024-11-04 20:00:19 +00:00 committed by GitHub
commit 8bd64d8edd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 72 additions and 26 deletions

View file

@ -20,7 +20,7 @@ jobs:
- uses: lukka/get-cmake@latest - uses: lukka/get-cmake@latest
with: with:
cmakeVersion: 3.10.0 cmakeVersion: 3.13.0
- name: create build environment - name: create build environment
run: cmake -E make_directory ${{ runner.workspace }}/_build run: cmake -E make_directory ${{ runner.workspace }}/_build

View file

@ -1,5 +1,5 @@
# Require CMake 3.10. If available, use the policies up to CMake 3.22. # Require CMake 3.10. If available, use the policies up to CMake 3.22.
cmake_minimum_required (VERSION 3.10...3.22) cmake_minimum_required (VERSION 3.13...3.22)
project (benchmark VERSION 1.9.0 LANGUAGES CXX) project (benchmark VERSION 1.9.0 LANGUAGES CXX)

View file

@ -3,13 +3,13 @@ module(
version = "1.9.0", version = "1.9.0",
) )
bazel_dep(name = "bazel_skylib", version = "1.5.0") bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "platforms", version = "0.0.8") bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "rules_foreign_cc", version = "0.10.1") bazel_dep(name = "rules_foreign_cc", version = "0.10.1")
bazel_dep(name = "rules_cc", version = "0.0.9") bazel_dep(name = "rules_cc", version = "0.0.9")
bazel_dep(name = "rules_python", version = "0.31.0", dev_dependency = True) bazel_dep(name = "rules_python", version = "0.37.0", dev_dependency = True)
bazel_dep(name = "googletest", version = "1.12.1", dev_dependency = True, repo_name = "com_google_googletest") bazel_dep(name = "googletest", version = "1.14.0", dev_dependency = True, repo_name = "com_google_googletest")
bazel_dep(name = "libpfm", version = "4.11.0") bazel_dep(name = "libpfm", version = "4.11.0")
@ -38,4 +38,4 @@ use_repo(pip, "tools_pip_deps")
# -- bazel_dep definitions -- # # -- bazel_dep definitions -- #
bazel_dep(name = "nanobind_bazel", version = "2.1.0", dev_dependency = True) bazel_dep(name = "nanobind_bazel", version = "2.2.0", dev_dependency = True)

View file

@ -118,7 +118,7 @@ NB_MODULE(_benchmark, m) {
using benchmark::Counter; using benchmark::Counter;
nb::class_<Counter> py_counter(m, "Counter"); nb::class_<Counter> py_counter(m, "Counter");
nb::enum_<Counter::Flags>(py_counter, "Flags", nb::is_arithmetic()) nb::enum_<Counter::Flags>(py_counter, "Flags", nb::is_arithmetic(), nb::is_flag())
.value("kDefaults", Counter::Flags::kDefaults) .value("kDefaults", Counter::Flags::kDefaults)
.value("kIsRate", Counter::Flags::kIsRate) .value("kIsRate", Counter::Flags::kIsRate)
.value("kAvgThreads", Counter::Flags::kAvgThreads) .value("kAvgThreads", Counter::Flags::kAvgThreads)
@ -129,10 +129,7 @@ NB_MODULE(_benchmark, m) {
.value("kAvgIterations", Counter::Flags::kAvgIterations) .value("kAvgIterations", Counter::Flags::kAvgIterations)
.value("kAvgIterationsRate", Counter::Flags::kAvgIterationsRate) .value("kAvgIterationsRate", Counter::Flags::kAvgIterationsRate)
.value("kInvert", Counter::Flags::kInvert) .value("kInvert", Counter::Flags::kInvert)
.export_values() .export_values();
.def("__or__", [](Counter::Flags a, Counter::Flags b) {
return static_cast<int>(a) | static_cast<int>(b);
});
nb::enum_<Counter::OneK>(py_counter, "OneK") nb::enum_<Counter::OneK>(py_counter, "OneK")
.value("kIs1000", Counter::OneK::kIs1000) .value("kIs1000", Counter::OneK::kIs1000)
@ -140,11 +137,7 @@ NB_MODULE(_benchmark, m) {
.export_values(); .export_values();
py_counter py_counter
.def( .def(nb::init<double, Counter::Flags, Counter::OneK>(),
"__init__",
[](Counter* c, double value, int flags, Counter::OneK oneK) {
new (c) Counter(value, static_cast<Counter::Flags>(flags), oneK);
},
nb::arg("value") = 0., nb::arg("flags") = Counter::kDefaults, nb::arg("value") = 0., nb::arg("flags") = Counter::kDefaults,
nb::arg("k") = Counter::kIs1000) nb::arg("k") = Counter::kIs1000)
.def("__init__", .def("__init__",

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.10..3.22) cmake_minimum_required (VERSION 3.13...3.22)
project(googletest-download NONE) project(googletest-download NONE)

View file

@ -668,6 +668,10 @@ void RegisterMemoryManager(MemoryManager* manager) {
} }
void RegisterProfilerManager(ProfilerManager* manager) { void RegisterProfilerManager(ProfilerManager* manager) {
// Don't allow overwriting an existing manager.
if (manager != nullptr) {
BM_CHECK_EQ(internal::profiler_manager, nullptr);
}
internal::profiler_manager = manager; internal::profiler_manager = manager;
} }

View file

@ -135,19 +135,25 @@ void ColorPrintf(std::ostream& out, LogColor color, const char* fmt,
// Gets the current text color. // Gets the current text color.
CONSOLE_SCREEN_BUFFER_INFO buffer_info; CONSOLE_SCREEN_BUFFER_INFO buffer_info;
GetConsoleScreenBufferInfo(stdout_handle, &buffer_info); GetConsoleScreenBufferInfo(stdout_handle, &buffer_info);
const WORD old_color_attrs = buffer_info.wAttributes; const WORD original_color_attrs = buffer_info.wAttributes;
// We need to flush the stream buffers into the console before each // We need to flush the stream buffers into the console before each
// SetConsoleTextAttribute call lest it affect the text that is already // SetConsoleTextAttribute call lest it affect the text that is already
// printed but has not yet reached the console. // printed but has not yet reached the console.
out.flush(); out.flush();
SetConsoleTextAttribute(stdout_handle,
GetPlatformColorCode(color) | FOREGROUND_INTENSITY); const WORD original_background_attrs =
original_color_attrs & (BACKGROUND_RED | BACKGROUND_GREEN |
BACKGROUND_BLUE | BACKGROUND_INTENSITY);
SetConsoleTextAttribute(stdout_handle, GetPlatformColorCode(color) |
FOREGROUND_INTENSITY |
original_background_attrs);
out << FormatString(fmt, args); out << FormatString(fmt, args);
out.flush(); out.flush();
// Restores the text color. // Restores the text and background color.
SetConsoleTextAttribute(stdout_handle, old_color_attrs); SetConsoleTextAttribute(stdout_handle, original_color_attrs);
#else #else
const char* color_code = GetPlatformColorCode(color); const char* color_code = GetPlatformColorCode(color);
if (color_code) out << FormatString("\033[0;3%sm", color_code); if (color_code) out << FormatString("\033[0;3%sm", color_code);

View file

@ -10,7 +10,7 @@ platform(
TEST_COPTS = [ TEST_COPTS = [
"-pedantic", "-pedantic",
"-pedantic-errors", "-pedantic-errors",
"-std=c++11", "-std=c++14",
"-Wall", "-Wall",
"-Wconversion", "-Wconversion",
"-Wextra", "-Wextra",

View file

@ -254,6 +254,7 @@ if (BENCHMARK_ENABLE_GTEST_TESTS)
add_gtest(perf_counters_gtest) add_gtest(perf_counters_gtest)
add_gtest(time_unit_gtest) add_gtest(time_unit_gtest)
add_gtest(min_time_parse_gtest) add_gtest(min_time_parse_gtest)
add_gtest(profiler_manager_gtest)
endif(BENCHMARK_ENABLE_GTEST_TESTS) endif(BENCHMARK_ENABLE_GTEST_TESTS)
############################################################################### ###############################################################################

View file

@ -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