Index: base/metrics/histogram_unittest.cc |
diff --git a/base/metrics/histogram_unittest.cc b/base/metrics/histogram_unittest.cc |
index d89e7e93247d8b60896aa46b6bd4fa3dafe03b39..f234c7b8c0957838532c50e02c8b341bce0b3cf8 100644 |
--- a/base/metrics/histogram_unittest.cc |
+++ b/base/metrics/histogram_unittest.cc |
@@ -401,6 +401,24 @@ TEST_P(HistogramTest, AddCount_LargeValuesDontOverflow) { |
EXPECT_EQ(19400000000LL, samples2->sum()); |
} |
+// Make sure that counts returned by Histogram::SnapshotDelta do not overflow |
+// even when a total count (returned by Histogram::SnapshotSample) does. |
Ilya Sherman
2017/05/11 00:42:34
nit: I'd phrase this comment as something like:
"
altimin
2017/05/11 12:38:33
Done.
|
+TEST_P(HistogramTest, AddCount_LargeCountsDontOverflow) { |
+ const size_t kBucketCount = 10; |
+ Histogram* histogram = static_cast<Histogram*>(Histogram::FactoryGet( |
+ "AddCountHistogram", 10, 50, kBucketCount, HistogramBase::kNoFlags)); |
+ |
+ 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)); |
+ } |
+} |
+ |
// Make sure histogram handles out-of-bounds data gracefully. |
TEST_P(HistogramTest, BoundsTest) { |
const size_t kBucketCount = 50; |