Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2331)

Unified Diff: base/metrics/histogram_unittest.cc

Issue 1618423004: Fix overflow bug in histogram sample data structures (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/metrics/histogram.h ('k') | base/metrics/sample_map.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/histogram_unittest.cc
diff --git a/base/metrics/histogram_unittest.cc b/base/metrics/histogram_unittest.cc
index 2fadc304415e4fc96b5478bdad712cc2e2a30e21..e03f5aaf95ec3b7567dce74ed6d68aacd8bf3f2a 100644
--- a/base/metrics/histogram_unittest.cc
+++ b/base/metrics/histogram_unittest.cc
@@ -245,7 +245,7 @@ TEST_F(HistogramTest, AddCountTest) {
histogram->AddCount(20, 15);
histogram->AddCount(30, 14);
- scoped_ptr<SampleVector> samples = histogram->SnapshotSampleVector();
+ scoped_ptr<HistogramSamples> samples = histogram->SnapshotSamples();
EXPECT_EQ(29, samples->TotalCount());
EXPECT_EQ(15, samples->GetCount(20));
EXPECT_EQ(14, samples->GetCount(30));
@@ -253,12 +253,37 @@ TEST_F(HistogramTest, AddCountTest) {
histogram->AddCount(20, 25);
histogram->AddCount(30, 24);
- scoped_ptr<SampleVector> samples2 = histogram->SnapshotSampleVector();
+ scoped_ptr<HistogramSamples> samples2 = histogram->SnapshotSamples();
EXPECT_EQ(78, samples2->TotalCount());
EXPECT_EQ(40, samples2->GetCount(20));
EXPECT_EQ(38, samples2->GetCount(30));
}
+// Test the AddCount function with large sample values.
+TEST_F(HistogramTest, AddCountLargeTest) {
Alexei Svitkine (slow) 2016/01/22 22:33:03 Nit: Maybe AddCount_LargeValuesDontOverflow And s
bcf 2016/01/22 22:46:14 Done.
+ const size_t kBucketCount = 50;
+ Histogram* histogram = static_cast<Histogram*>(
+ Histogram::FactoryGet("AddCountHistogram", 10, 1000000000, kBucketCount,
+ HistogramBase::kNoFlags));
+
+ histogram->AddCount(200000000, 15);
+ histogram->AddCount(300000000, 14);
+
+ scoped_ptr<HistogramSamples> samples = histogram->SnapshotSamples();
+ EXPECT_EQ(29, samples->TotalCount());
+ EXPECT_EQ(15, samples->GetCount(200000000));
+ EXPECT_EQ(14, samples->GetCount(300000000));
+
+ histogram->AddCount(200000000, 25);
+ histogram->AddCount(300000000, 24);
+
+ scoped_ptr<HistogramSamples> samples2 = histogram->SnapshotSamples();
+ EXPECT_EQ(78, samples2->TotalCount());
+ EXPECT_EQ(40, samples2->GetCount(200000000));
+ EXPECT_EQ(38, samples2->GetCount(300000000));
+ EXPECT_EQ(19400000000LL, samples2->sum());
+}
+
// Make sure histogram handles out-of-bounds data gracefully.
TEST_F(HistogramTest, BoundsTest) {
const size_t kBucketCount = 50;
@@ -358,7 +383,7 @@ TEST_F(HistogramTest, CorruptBucketBounds) {
Histogram* histogram = static_cast<Histogram*>(
Histogram::FactoryGet("Histogram", 1, 64, 8, HistogramBase::kNoFlags));
- scoped_ptr<SampleVector> snapshot = histogram->SnapshotSampleVector();
+ scoped_ptr<HistogramSamples> snapshot = histogram->SnapshotSamples();
EXPECT_EQ(HistogramBase::NO_INCONSISTENCIES,
histogram->FindCorruption(*snapshot));
« no previous file with comments | « base/metrics/histogram.h ('k') | base/metrics/sample_map.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698