Skip to content

Commit

Permalink
more nolint and some global fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dmah42 committed Feb 17, 2025
1 parent 0255fb3 commit 3172799
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 13 deletions.
6 changes: 5 additions & 1 deletion src/benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,17 @@ BM_DEFINE_int32(v, 0);

namespace internal {

// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
std::map<std::string, std::string>* global_context = nullptr;

BENCHMARK_EXPORT std::map<std::string, std::string>*& GetGlobalContext() {
return global_context;
}

static void const volatile* volatile global_force_escape_pointer;
namespace {
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
void const volatile* volatile global_force_escape_pointer;
} // namespace

// FIXME: Verify if LTO still messes this up?
void UseCharPointer(char const volatile* const v) {
Expand Down
5 changes: 4 additions & 1 deletion src/check.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
namespace benchmark {
namespace internal {

static AbortHandlerT* handler = &std::abort;
namespace {
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
AbortHandlerT* handler = &std::abort;
} // namespace

BENCHMARK_EXPORT AbortHandlerT*& GetAbortHandler() { return handler; }

Expand Down
19 changes: 9 additions & 10 deletions src/commandlineflags.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,32 @@
#define FLAG(name) FLAGS_##name

// Macros for declaring flags.
// NOLINTBEGIN
// NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables)
#define BM_DECLARE_bool(name) BENCHMARK_EXPORT extern bool FLAG(name)
#define BM_DECLARE_int32(name) BENCHMARK_EXPORT extern int32_t FLAG(name)
#define BM_DECLARE_double(name) BENCHMARK_EXPORT extern double FLAG(name)
#define BM_DECLARE_string(name) BENCHMARK_EXPORT extern std::string FLAG(name)
#define BM_DECLARE_kvpairs(name) \
BENCHMARK_EXPORT extern std::map<std::string, std::string> FLAG(name)
// NOLINTEND
// NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables)

// Macros for defining flags.
// NOLINTBEGIN
// NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables)
#define BM_DEFINE_bool(name, default_val) \
BENCHMARK_EXPORT bool FLAG(name) = \
benchmark::BoolFromEnv(#name, default_val) // NOLINT
BENCHMARK_EXPORT bool FLAG(name) = benchmark::BoolFromEnv(#name, default_val)
#define BM_DEFINE_int32(name, default_val) \
BENCHMARK_EXPORT int32_t FLAG(name) = \
benchmark::Int32FromEnv(#name, default_val) // NOLINT
benchmark::Int32FromEnv(#name, default_val)
#define BM_DEFINE_double(name, default_val) \
BENCHMARK_EXPORT double FLAG(name) = \
benchmark::DoubleFromEnv(#name, default_val) // NOLINT
benchmark::DoubleFromEnv(#name, default_val)
#define BM_DEFINE_string(name, default_val) \
BENCHMARK_EXPORT std::string FLAG(name) = \
benchmark::StringFromEnv(#name, default_val) // NOLINT
benchmark::StringFromEnv(#name, default_val)
#define BM_DEFINE_kvpairs(name, default_val) \
BENCHMARK_EXPORT std::map<std::string, std::string> FLAG(name) = \
benchmark::KvPairsFromEnv(#name, default_val) // NOLINT
// NOLINTEND
benchmark::KvPairsFromEnv(#name, default_val)
// NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables)

namespace benchmark {

Expand Down
3 changes: 2 additions & 1 deletion test/benchmark_random_interleaving_gtest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class EventQueue : public std::queue<std::string> {
}
};

EventQueue* const queue = new EventQueue(); // NOLINT
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
EventQueue* const queue = new EventQueue();

class NullReporter : public BenchmarkReporter {
public:
Expand Down
6 changes: 6 additions & 0 deletions test/benchmark_setup_teardown_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@

// Test that Setup() and Teardown() are called exactly once
// for each benchmark run (single-threaded).
namespace {
namespace singlethreaded {
static int setup_call = 0;
static int teardown_call = 0;
} // namespace singlethreaded
} // namespace
static void DoSetup1(const benchmark::State& state) {
++singlethreaded::setup_call;

Expand All @@ -40,11 +42,13 @@ BENCHMARK(BM_with_setup)
->Teardown(DoTeardown1);

// Test that Setup() and Teardown() are called once for each group of threads.
namespace {
namespace concurrent {
static std::atomic<int> setup_call(0);
static std::atomic<int> teardown_call(0);
static std::atomic<int> func_call(0);
} // namespace concurrent
} // namespace

static void DoSetup2(const benchmark::State& state) {
concurrent::setup_call.fetch_add(1, std::memory_order_acquire);
Expand All @@ -71,10 +75,12 @@ BENCHMARK(BM_concurrent)
->Threads(15);

// Testing interaction with Fixture::Setup/Teardown
namespace {
namespace fixture_interaction {
int setup = 0;
int fixture_setup = 0;
} // namespace fixture_interaction
} // namespace

#define FIXTURE_BECHMARK_NAME MyFixture

Expand Down
2 changes: 2 additions & 0 deletions test/benchmark_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ std::set<int64_t> ConstructRandomSet(int64_t size) {
return s;
}

// NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables)
std::mutex test_vector_mu;
std::vector<int>* test_vector = nullptr;
// NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables)

} // end namespace

Expand Down
1 change: 1 addition & 0 deletions test/skip_with_error_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct TestCase {
}
};

// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
std::vector<TestCase> ExpectedResults;

int AddCases(const std::string& base_name,
Expand Down

0 comments on commit 3172799

Please sign in to comment.