Skip to content

Commit

Permalink
Merge branch 'main' into task/update-gtest-and-remove-warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
dmah42 authored Nov 4, 2024
2 parents 2e8a6c0 + d99cdd7 commit 8bd64d8
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test-min-cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

- uses: lukka/get-cmake@latest
with:
cmakeVersion: 3.10.0
cmakeVersion: 3.13.0

- name: create build environment
run: cmake -E make_directory ${{ runner.workspace }}/_build
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# 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)

Expand Down
10 changes: 5 additions & 5 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ module(
version = "1.9.0",
)

bazel_dep(name = "bazel_skylib", version = "1.5.0")
bazel_dep(name = "platforms", version = "0.0.8")
bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "rules_foreign_cc", version = "0.10.1")
bazel_dep(name = "rules_cc", version = "0.0.9")

bazel_dep(name = "rules_python", version = "0.31.0", dev_dependency = True)
bazel_dep(name = "googletest", version = "1.12.1", dev_dependency = True, repo_name = "com_google_googletest")
bazel_dep(name = "rules_python", version = "0.37.0", dev_dependency = True)
bazel_dep(name = "googletest", version = "1.14.0", dev_dependency = True, repo_name = "com_google_googletest")

bazel_dep(name = "libpfm", version = "4.11.0")

Expand Down Expand Up @@ -38,4 +38,4 @@ use_repo(pip, "tools_pip_deps")

# -- 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)
17 changes: 5 additions & 12 deletions bindings/python/google_benchmark/benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ NB_MODULE(_benchmark, m) {
using benchmark::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("kIsRate", Counter::Flags::kIsRate)
.value("kAvgThreads", Counter::Flags::kAvgThreads)
Expand All @@ -129,24 +129,17 @@ NB_MODULE(_benchmark, m) {
.value("kAvgIterations", Counter::Flags::kAvgIterations)
.value("kAvgIterationsRate", Counter::Flags::kAvgIterationsRate)
.value("kInvert", Counter::Flags::kInvert)
.export_values()
.def("__or__", [](Counter::Flags a, Counter::Flags b) {
return static_cast<int>(a) | static_cast<int>(b);
});
.export_values();

nb::enum_<Counter::OneK>(py_counter, "OneK")
.value("kIs1000", Counter::OneK::kIs1000)
.value("kIs1024", Counter::OneK::kIs1024)
.export_values();

py_counter
.def(
"__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("k") = Counter::kIs1000)
.def(nb::init<double, Counter::Flags, Counter::OneK>(),
nb::arg("value") = 0., nb::arg("flags") = Counter::kDefaults,
nb::arg("k") = Counter::kIs1000)
.def("__init__",
([](Counter* c, double value) { new (c) Counter(value); }))
.def_rw("value", &Counter::value)
Expand Down
2 changes: 1 addition & 1 deletion cmake/GoogleTest.cmake.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.10..3.22)
cmake_minimum_required (VERSION 3.13...3.22)

project(googletest-download NONE)

Expand Down
4 changes: 4 additions & 0 deletions src/benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,10 @@ void RegisterMemoryManager(MemoryManager* 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;
}

Expand Down
16 changes: 11 additions & 5 deletions src/colorprint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,25 @@ void ColorPrintf(std::ostream& out, LogColor color, const char* fmt,
// Gets the current text color.
CONSOLE_SCREEN_BUFFER_INFO 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
// SetConsoleTextAttribute call lest it affect the text that is already
// printed but has not yet reached the console.
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.flush();
// Restores the text color.
SetConsoleTextAttribute(stdout_handle, old_color_attrs);
// Restores the text and background color.
SetConsoleTextAttribute(stdout_handle, original_color_attrs);
#else
const char* color_code = GetPlatformColorCode(color);
if (color_code) out << FormatString("\033[0;3%sm", color_code);
Expand Down
2 changes: 1 addition & 1 deletion test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ platform(
TEST_COPTS = [
"-pedantic",
"-pedantic-errors",
"-std=c++11",
"-std=c++14",
"-Wall",
"-Wconversion",
"-Wextra",
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ if (BENCHMARK_ENABLE_GTEST_TESTS)
add_gtest(perf_counters_gtest)
add_gtest(time_unit_gtest)
add_gtest(min_time_parse_gtest)
add_gtest(profiler_manager_gtest)
endif(BENCHMARK_ENABLE_GTEST_TESTS)

###############################################################################
Expand Down
42 changes: 42 additions & 0 deletions test/profiler_manager_gtest.cc
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

0 comments on commit 8bd64d8

Please sign in to comment.