Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2934)

Unified Diff: base/trace_event/heap_profiler_allocation_register_unittest.cc

Issue 2037603002: tracing: Reduce memory usage of heap_profiler_allocation_register_unittest.cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/trace_event/heap_profiler_allocation_register_unittest.cc
diff --git a/base/trace_event/heap_profiler_allocation_register_unittest.cc b/base/trace_event/heap_profiler_allocation_register_unittest.cc
index b356aa7853bc7e0e1e52c72df82e77fc8f40cf9f..4668df31dd403514dc920ece26c30ab325d9878e 100644
--- a/base/trace_event/heap_profiler_allocation_register_unittest.cc
+++ b/base/trace_event/heap_profiler_allocation_register_unittest.cc
@@ -16,7 +16,10 @@ namespace trace_event {
class AllocationRegisterTest : public testing::Test {
public:
- static const uint32_t kNumBuckets = AllocationRegister::kNumBuckets;
+ // Use a lower number of cells for unittests to avoid reserving a virtual
+ // region which is too big.
+ static const uint32_t kNumCellsForTesting =
+ AllocationRegister::kNumBuckets + 100;
// Returns the number of cells that the |AllocationRegister| can store per
// system page.
@@ -56,7 +59,7 @@ size_t SumAllSizes(const AllocationRegister& reg) {
}
TEST_F(AllocationRegisterTest, InsertRemove) {
- AllocationRegister reg;
+ AllocationRegister reg(kNumCellsForTesting);
AllocationContext ctx;
// Zero-sized allocations should be discarded.
@@ -90,7 +93,7 @@ TEST_F(AllocationRegisterTest, InsertRemove) {
}
TEST_F(AllocationRegisterTest, DoubleFreeIsAllowed) {
- AllocationRegister reg;
+ AllocationRegister reg(kNumCellsForTesting);
AllocationContext ctx;
reg.Insert(reinterpret_cast<void*>(1), 1, ctx);
@@ -103,9 +106,7 @@ TEST_F(AllocationRegisterTest, DoubleFreeIsAllowed) {
}
TEST_F(AllocationRegisterTest, DoubleInsertOverwrites) {
- // TODO(ruuda): Although double insert happens in practice, it should not.
- // Find out the cause and ban double insert if possible.
- AllocationRegister reg;
+ AllocationRegister reg(kNumCellsForTesting);
AllocationContext ctx;
StackFrame frame1 = StackFrame::FromTraceEventName("Foo");
StackFrame frame2 = StackFrame::FromTraceEventName("Bar");
@@ -139,12 +140,12 @@ TEST_F(AllocationRegisterTest, DoubleInsertOverwrites) {
// register still behaves correctly.
TEST_F(AllocationRegisterTest, InsertRemoveCollisions) {
size_t expected_sum = 0;
- AllocationRegister reg;
+ AllocationRegister reg(kNumCellsForTesting);
AllocationContext ctx;
// By inserting 100 more entries than the number of buckets, there will be at
- // least 100 collisions.
- for (uintptr_t i = 1; i <= kNumBuckets + 100; i++) {
+ // least 100 collisions (100 = kNumCellsForTesting - kNumBuckets).
+ for (uintptr_t i = 1; i <= kNumCellsForTesting; i++) {
size_t size = i % 31;
expected_sum += size;
reg.Insert(reinterpret_cast<void*>(i), size, ctx);
@@ -156,7 +157,7 @@ TEST_F(AllocationRegisterTest, InsertRemoveCollisions) {
EXPECT_EQ(expected_sum, SumAllSizes(reg));
- for (uintptr_t i = 1; i <= kNumBuckets + 100; i++) {
+ for (uintptr_t i = 1; i <= kNumCellsForTesting; i++) {
size_t size = i % 31;
expected_sum -= size;
reg.Remove(reinterpret_cast<void*>(i));
@@ -176,7 +177,7 @@ TEST_F(AllocationRegisterTest, InsertRemoveCollisions) {
// free list is utilised properly.
TEST_F(AllocationRegisterTest, InsertRemoveRandomOrder) {
size_t expected_sum = 0;
- AllocationRegister reg;
+ AllocationRegister reg(kNumCellsForTesting);
AllocationContext ctx;
uintptr_t generator = 3;
@@ -217,7 +218,7 @@ TEST_F(AllocationRegisterTest, InsertRemoveRandomOrder) {
TEST_F(AllocationRegisterTest, ChangeContextAfterInsertion) {
using Allocation = AllocationRegister::Allocation;
const char kStdString[] = "std::string";
- AllocationRegister reg;
+ AllocationRegister reg(kNumCellsForTesting);
AllocationContext ctx;
reg.Insert(reinterpret_cast<void*>(17), 1, ctx);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698