Skip to content

Commit d43e705

Browse files
committed
some fixes
1 parent e1eaa52 commit d43e705

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

test/memory_results_gtest.cc

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
#include "benchmark/benchmark.h"
55
#include "gtest/gtest.h"
66

7-
#define N_REPETITIONS 100
8-
#define N_ITERATIONS 1
7+
namespace {
98

109
using benchmark::ClearRegisteredBenchmarks;
1110
using benchmark::ConsoleReporter;
@@ -15,31 +14,32 @@ using benchmark::RunSpecifiedBenchmarks;
1514
using benchmark::State;
1615
using benchmark::internal::Benchmark;
1716

18-
namespace counts {
17+
constexpr int N_REPETITIONS = 100;
18+
constexpr int N_ITERATIONS = 1;
19+
1920
int num_allocs = 0;
2021
int max_bytes_used = 0;
2122
int total_allocated_bytes = 0;
2223
int net_heap_growth = 0;
24+
2325
void reset() {
2426
num_allocs = 0;
2527
max_bytes_used = 0;
2628
total_allocated_bytes = 0;
2729
net_heap_growth = 0;
2830
}
29-
} // namespace counts
30-
3131
class TestMemoryManager : public MemoryManager {
3232
void Start() override {}
3333
void Stop(Result& result) override {
34-
result.num_allocs = counts::num_allocs;
35-
result.net_heap_growth = counts::net_heap_growth;
36-
result.max_bytes_used = counts::max_bytes_used;
37-
result.total_allocated_bytes = counts::total_allocated_bytes;
38-
39-
counts::num_allocs += 1;
40-
counts::max_bytes_used += 2;
41-
counts::net_heap_growth += 4;
42-
counts::total_allocated_bytes += 10;
34+
result.num_allocs = num_allocs;
35+
result.net_heap_growth = net_heap_growth;
36+
result.max_bytes_used = max_bytes_used;
37+
result.total_allocated_bytes = total_allocated_bytes;
38+
39+
num_allocs += 1;
40+
max_bytes_used += 2;
41+
net_heap_growth += 4;
42+
total_allocated_bytes += 10;
4343
}
4444
};
4545

@@ -73,6 +73,7 @@ class MemoryResultsTest : public testing::Test {
7373
});
7474
bm->Repetitions(N_REPETITIONS);
7575
bm->Iterations(N_ITERATIONS);
76+
reset();
7677
}
7778
void TearDown() override { ClearRegisteredBenchmarks(); }
7879
};
@@ -83,9 +84,8 @@ TEST_F(MemoryResultsTest, NoMMTest) {
8384
}
8485

8586
TEST_F(MemoryResultsTest, ResultsTest) {
86-
counts::reset();
87-
MemoryManager* mm = new TestMemoryManager;
88-
RegisterMemoryManager(mm);
87+
auto mm = std::make_unique<TestMemoryManager>();
88+
RegisterMemoryManager(mm.get());
8989

9090
RunSpecifiedBenchmarks(&reporter);
9191
EXPECT_EQ(reporter.store.size(), N_REPETITIONS);
@@ -97,6 +97,6 @@ TEST_F(MemoryResultsTest, ResultsTest) {
9797
EXPECT_EQ(reporter.store[i].total_allocated_bytes,
9898
static_cast<int64_t>(i) * 10);
9999
}
100-
101-
delete mm;
102100
}
101+
102+
} // namespace

0 commit comments

Comments
 (0)