Chromium Code Reviews| 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 3ec4580be5047e83336e1799e5749d1c03849bd3..8e61649b12b89261a8fb911b3f368ba18bba9021 100644 |
| --- a/base/trace_event/heap_profiler_allocation_register_unittest.cc |
| +++ b/base/trace_event/heap_profiler_allocation_register_unittest.cc |
| @@ -55,21 +55,30 @@ size_t SumAllSizes(const AllocationRegister& reg) { |
| return sum; |
| } |
| +TEST_F(AllocationRegisterTest, NoZeroSizeInsert) { |
| + AllocationRegister reg; |
| + AllocationContext ctx = AllocationContext::Empty(); |
| + |
| + reg.Insert(reinterpret_cast<void*>(1), 0, ctx); |
|
Primiano Tucci (use gerrit)
2016/04/06 08:20:44
I think this (and line 64) can be moved to the Ins
|
| + |
| + EXPECT_EQ(0u, OrAllAddresses(reg)); |
| +} |
| + |
| TEST_F(AllocationRegisterTest, InsertRemove) { |
| AllocationRegister reg; |
| AllocationContext ctx = AllocationContext::Empty(); |
| EXPECT_EQ(0u, OrAllAddresses(reg)); |
| - reg.Insert(reinterpret_cast<void*>(1), 0, ctx); |
| + reg.Insert(reinterpret_cast<void*>(1), 1, ctx); |
| EXPECT_EQ(1u, OrAllAddresses(reg)); |
| - reg.Insert(reinterpret_cast<void*>(2), 0, ctx); |
| + reg.Insert(reinterpret_cast<void*>(2), 1, ctx); |
| EXPECT_EQ(3u, OrAllAddresses(reg)); |
| - reg.Insert(reinterpret_cast<void*>(4), 0, ctx); |
| + reg.Insert(reinterpret_cast<void*>(4), 1, ctx); |
| EXPECT_EQ(7u, OrAllAddresses(reg)); |
| @@ -90,8 +99,8 @@ TEST_F(AllocationRegisterTest, DoubleFreeIsAllowed) { |
| AllocationRegister reg; |
| AllocationContext ctx = AllocationContext::Empty(); |
| - reg.Insert(reinterpret_cast<void*>(1), 0, ctx); |
| - reg.Insert(reinterpret_cast<void*>(2), 0, ctx); |
| + reg.Insert(reinterpret_cast<void*>(1), 1, ctx); |
| + reg.Insert(reinterpret_cast<void*>(2), 1, ctx); |
| reg.Remove(reinterpret_cast<void*>(1)); |
| reg.Remove(reinterpret_cast<void*>(1)); // Remove for the second time. |
| reg.Remove(reinterpret_cast<void*>(4)); // Remove never inserted address. |
| @@ -179,7 +188,7 @@ TEST_F(AllocationRegisterTest, InsertRemoveRandomOrder) { |
| uint32_t initial_water_mark = GetHighWaterMark(reg); |
| for (uintptr_t i = 2; i < prime; i++) { |
| - size_t size = i % 31; |
| + size_t size = i % 31 + 1; |
| expected_sum += size; |
| reg.Insert(reinterpret_cast<void*>(i), size, ctx); |
| } |
| @@ -189,7 +198,7 @@ TEST_F(AllocationRegisterTest, InsertRemoveRandomOrder) { |
| // Iterate the numbers 2, 3, ..., prime - 1 in pseudorandom order. |
| for (uintptr_t i = generator; i != 1; i = (i * generator) % prime) { |
| - size_t size = i % 31; |
| + size_t size = i % 31 + 1; |
| expected_sum -= size; |
| reg.Remove(reinterpret_cast<void*>(i)); |
| EXPECT_EQ(expected_sum, SumAllSizes(reg)); |
| @@ -200,12 +209,12 @@ TEST_F(AllocationRegisterTest, InsertRemoveRandomOrder) { |
| // Insert |prime - 2| entries again. This should use cells from the free list, |
| // so the |next_unused_cell_| index should not change. |
| for (uintptr_t i = 2; i < prime; i++) |
| - reg.Insert(reinterpret_cast<void*>(i), 0, ctx); |
| + reg.Insert(reinterpret_cast<void*>(i), 1, ctx); |
| ASSERT_EQ(prime - 2, GetHighWaterMark(reg) - initial_water_mark); |
| // Inserting one more entry should use a fresh cell again. |
| - reg.Insert(reinterpret_cast<void*>(prime), 0, ctx); |
| + reg.Insert(reinterpret_cast<void*>(prime), 1, ctx); |
| ASSERT_EQ(prime - 1, GetHighWaterMark(reg) - initial_water_mark); |
| } |
| @@ -268,7 +277,7 @@ TEST_F(AllocationRegisterTest, OverflowDeathTest) { |
| // minus 1 elements are inserted, because cell 0 is unused, so this should |
| // fill up the available cells exactly. |
| for (i = 1; i < GetNumCells(reg); i++) { |
| - reg.Insert(reinterpret_cast<void*>(i), 0, ctx); |
| + reg.Insert(reinterpret_cast<void*>(i), 1, ctx); |
| } |
| // Adding just one extra element might still work because the allocated memory |
| @@ -277,7 +286,7 @@ TEST_F(AllocationRegisterTest, OverflowDeathTest) { |
| const size_t cells_per_page = GetNumCellsPerPage(); |
| ASSERT_DEATH(for (size_t j = 0; j < cells_per_page; j++) { |
| - reg.Insert(reinterpret_cast<void*>(i + j), 0, ctx); |
| + reg.Insert(reinterpret_cast<void*>(i + j), 1, ctx); |
| }, ""); |
| } |
| #endif |