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..3ad2bc86801c05111c2354224bef2100eabaffc1 100644 |
--- a/base/metrics/sparse_histogram_unittest.cc |
+++ b/base/metrics/sparse_histogram_unittest.cc |
@@ -10,6 +10,7 @@ |
#include "base/metrics/histogram_base.h" |
#include "base/metrics/histogram_macros.h" |
#include "base/metrics/histogram_samples.h" |
+#include "base/metrics/metrics_hashes.h" |
#include "base/metrics/persistent_histogram_allocator.h" |
#include "base/metrics/persistent_memory_allocator.h" |
#include "base/metrics/sample_map.h" |
@@ -149,6 +150,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); |
@@ -364,4 +384,11 @@ TEST_P(SparseHistogramTest, ExtremeValues) { |
} |
} |
+TEST_P(SparseHistogramTest, HistogramNameHash) { |
+ const char kName[] = "TestName"; |
+ HistogramBase* histogram = SparseHistogram::FactoryGet( |
+ kName, HistogramBase::kUmaTargetedHistogramFlag); |
+ EXPECT_EQ(histogram->name_hash(), HashMetricName(kName)); |
+} |
+ |
} // namespace base |