Chromium Code Reviews| Index: components/metrics/leak_detector/leak_detector_impl_unittest.cc |
| diff --git a/components/metrics/leak_detector/leak_detector_impl_unittest.cc b/components/metrics/leak_detector/leak_detector_impl_unittest.cc |
| index 7a7e30a4413a07ef3629b885bff9ab48e7690dbe..5d10eca29f7854f5329b7a7352021b53edbe2512 100644 |
| --- a/components/metrics/leak_detector/leak_detector_impl_unittest.cc |
| +++ b/components/metrics/leak_detector/leak_detector_impl_unittest.cc |
| @@ -21,10 +21,6 @@ |
| namespace metrics { |
| namespace leak_detector { |
| -using InternalLeakReport = LeakDetectorImpl::LeakReport; |
| -template <typename T> |
| -using InternalVector = LeakDetectorImpl::InternalVector<T>; |
| - |
| namespace { |
| // Makes working with complex numbers easier. |
| @@ -139,6 +135,11 @@ class LeakDetectorImplTest : public ::testing::Test { |
| } |
| protected: |
| + using InternalLeakReport = LeakDetectorImpl::LeakReport; |
| + template <typename T> |
| + using InternalVector = LeakDetectorImpl::InternalVector<T>; |
| + using AllocationBreakdown = LeakDetectorImpl::LeakReport::AllocationBreakdown; |
| + |
| // Alloc and free functions that allocate and free heap memory and |
| // automatically pass alloc/free info to |detector_|. They emulate the |
| // alloc/free hook functions that would call into LeakDetectorImpl in |
| @@ -532,28 +533,35 @@ TEST_F(LeakDetectorImplTest, SimpleLeakyFunctionWithLeak) { |
| // There should have been one leak analysis per outer loop iteration, for a |
| // total of 20 history records (|kNumOuterIterations|) per report. |
| - const auto& report1_size_history = report1.size_breakdown_history(); |
| - EXPECT_EQ(20U, report1_size_history.size()); |
| + const auto& report1_history = report1.alloc_breakdown_history(); |
| + EXPECT_EQ(20U, report1_history.size()); |
| size_t index = 0; |
| - for (const InternalVector<uint32_t>& entry : report1_size_history) { |
| - ASSERT_GT(entry.size(), SizeToIndex(48)); |
| + for (const AllocationBreakdown& entry : report1_history) { |
| + const InternalVector<uint32_t>& counts_by_size = entry.counts_by_size; |
| + ASSERT_GT(counts_by_size.size(), SizeToIndex(48)); |
| // Check the two leaky sizes, 32 and 48. |
| - EXPECT_EQ((index + 1) * 32 + 2, entry[SizeToIndex(32)]); |
| - EXPECT_EQ((index + 1) * 32 + 2, entry[SizeToIndex(48)]); |
| + EXPECT_EQ((index + 1) * 32 + 2, counts_by_size[SizeToIndex(32)]); |
| + EXPECT_EQ((index + 1) * 32 + 2, counts_by_size[SizeToIndex(48)]); |
| // Not related to the leaks, but there should be a dangling 16-byte |
| // allocation during each leak analysis, because it hasn't yet been freed. |
| - EXPECT_EQ(1U, entry[SizeToIndex(16)]); |
| + EXPECT_EQ(1U, counts_by_size[SizeToIndex(16)]); |
| ++index; |
| } |
|
Simon Que
2016/04/09 00:15:58
Still need to check the call stack breakdown.
Simon Que
2016/04/09 01:04:32
Done.
|
| - // |report2| should have the same size history as |report1|. |
| - const auto& report2_size_history = report2.size_breakdown_history(); |
| - EXPECT_TRUE(std::equal(report1_size_history.begin(), |
| - report1_size_history.end(), |
| - report2_size_history.begin())); |
| + // |report2| should have the same size history and call stack history as |
| + // |report1|. |
| + const auto& report2_history = report2.alloc_breakdown_history(); |
| + auto compare_history_func = |
| + [](AllocationBreakdown a, AllocationBreakdown b) -> bool { |
| + return std::equal(a.counts_by_size.begin(), a.counts_by_size.end(), |
| + b.counts_by_size.begin()) && |
| + a.count_for_call_stack == b.count_for_call_stack; |
| + }; |
| + EXPECT_TRUE(std::equal(report1_history.begin(), report1_history.end(), |
| + report2_history.begin(), compare_history_func)); |
| } |
| TEST_F(LeakDetectorImplTest, JuliaSetNoLeak) { |
| @@ -598,31 +606,37 @@ TEST_F(LeakDetectorImplTest, JuliaSetWithLeak) { |
| } |
| // Check |report1|'s historical data. |
| - const auto& report1_size_history = report1.size_breakdown_history(); |
| + const auto& report1_history = report1.alloc_breakdown_history(); |
| // Computing the exact number of leak analyses is not trivial, but we know it |
| // must be at least |kSizeSuspicionThreshold + kCallStackSuspicionThreshold| |
| // in order to have generated a report. |
| - EXPECT_GT(report1_size_history.size(), |
| + EXPECT_GT(report1_history.size(), |
| kSizeSuspicionThreshold + kCallStackSuspicionThreshold); |
| // Make sure that the final allocation counts for the leaky sizes are larger |
| // than that of the non-leaky size by at least an order of magnitude. |
| - const InternalVector<uint32_t>& final_entry = *report1_size_history.rbegin(); |
| + const AllocationBreakdown& final_entry = *report1_history.rbegin(); |
| + const InternalVector<uint32_t>& counts_by_size = final_entry.counts_by_size; |
| uint32_t size_0_index = SizeToIndex(sizeof(Complex) + 24); |
| uint32_t size_1_index = SizeToIndex(sizeof(Complex) + 40); |
| uint32_t size_2_index = SizeToIndex(sizeof(Complex) + 52); |
| - ASSERT_LT(size_0_index, final_entry.size()); |
| - ASSERT_LT(size_1_index, final_entry.size()); |
| - ASSERT_LT(size_2_index, final_entry.size()); |
| - |
| - EXPECT_GT(final_entry[size_1_index], final_entry[size_0_index] * 10); |
| - EXPECT_GT(final_entry[size_2_index], final_entry[size_0_index] * 10); |
| - |
| - // |report2| should have the same size history as |report1|. |
| - const auto& report2_size_history = report2.size_breakdown_history(); |
| - EXPECT_TRUE(std::equal(report1_size_history.begin(), |
| - report1_size_history.end(), |
| - report2_size_history.begin())); |
| + ASSERT_LT(size_0_index, counts_by_size.size()); |
| + ASSERT_LT(size_1_index, counts_by_size.size()); |
| + ASSERT_LT(size_2_index, counts_by_size.size()); |
| + |
| + EXPECT_GT(counts_by_size[size_1_index], counts_by_size[size_0_index] * 10); |
| + EXPECT_GT(counts_by_size[size_2_index], counts_by_size[size_0_index] * 10); |
| + |
| + // |report2| should have the same size history as |report1|, but not the same |
| + // call stack history. |
| + const auto& report2_history = report2.alloc_breakdown_history(); |
| + auto compare_size_history_func = |
| + [](AllocationBreakdown a, AllocationBreakdown b) -> bool { |
| + return std::equal(a.counts_by_size.begin(), a.counts_by_size.end(), |
| + b.counts_by_size.begin()); |
| + }; |
| + EXPECT_TRUE(std::equal(report1_history.begin(), report1_history.end(), |
| + report2_history.begin(), compare_size_history_func)); |
| } |
| } // namespace leak_detector |