Index: base/metrics/sparse_histogram_unittest.cc |
diff --git a/base/metrics/sparse_histogram_unittest.cc b/base/metrics/sparse_histogram_unittest.cc |
index 40e6fbf644bdf4ac8024259534fed9b01126c70d..a6fb3efea730797c050bce0a1864f8b138ff4f2d 100644 |
--- a/base/metrics/sparse_histogram_unittest.cc |
+++ b/base/metrics/sparse_histogram_unittest.cc |
@@ -149,6 +149,25 @@ TEST_P(SparseHistogramTest, AddCount_LargeValuesDontOverflow) { |
EXPECT_EQ(55250000000LL, snapshot2->sum()); |
} |
+// Make sure that counts returned by Histogram::SnapshotDelta do not overflow |
+// even when a total count (returned by Histogram::SnapshotSample) does. |
+TEST_P(SparseHistogramTest, AddCount_LargeCountsDontOverflow) { |
+ std::unique_ptr<SparseHistogram> histogram(NewSparseHistogram("Sparse")); |
+ std::unique_ptr<HistogramSamples> snapshot(histogram->SnapshotSamples()); |
+ EXPECT_EQ(0, snapshot->TotalCount()); |
+ EXPECT_EQ(0, snapshot->sum()); |
+ |
+ const int count = (1 << 30) - 1; |
+ |
+ // Repeat N times to make sure that there is no internal value overflow. |
+ for (int i = 0; i < 10; ++i) { |
+ histogram->AddCount(42, count); |
+ std::unique_ptr<HistogramSamples> samples = histogram->SnapshotDelta(); |
+ EXPECT_EQ(count, samples->TotalCount()); |
+ EXPECT_EQ(count, samples->GetCount(42)); |
+ } |
+} |
+ |
TEST_P(SparseHistogramTest, MacroBasicTest) { |
UMA_HISTOGRAM_SPARSE_SLOWLY("Sparse", 100); |
UMA_HISTOGRAM_SPARSE_SLOWLY("Sparse", 200); |