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

Side by Side Diff: base/metrics/sparse_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: Rename tests, remove redundant comments. 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 unified diff | Download patch
« no previous file with comments | « base/metrics/sample_vector_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/metrics/sparse_histogram.h" 5 #include "base/metrics/sparse_histogram.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/metrics/histogram_base.h" 10 #include "base/metrics/histogram_base.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 EXPECT_EQ(15, snapshot1->GetCount(100)); 74 EXPECT_EQ(15, snapshot1->GetCount(100));
75 75
76 histogram->AddCount(100, 15); 76 histogram->AddCount(100, 15);
77 histogram->AddCount(101, 25); 77 histogram->AddCount(101, 25);
78 scoped_ptr<HistogramSamples> snapshot2(histogram->SnapshotSamples()); 78 scoped_ptr<HistogramSamples> snapshot2(histogram->SnapshotSamples());
79 EXPECT_EQ(55, snapshot2->TotalCount()); 79 EXPECT_EQ(55, snapshot2->TotalCount());
80 EXPECT_EQ(30, snapshot2->GetCount(100)); 80 EXPECT_EQ(30, snapshot2->GetCount(100));
81 EXPECT_EQ(25, snapshot2->GetCount(101)); 81 EXPECT_EQ(25, snapshot2->GetCount(101));
82 } 82 }
83 83
84 TEST_F(SparseHistogramTest, AddCount_LargeValuesDontOverflow) {
85 scoped_ptr<SparseHistogram> histogram(NewSparseHistogram("Sparse"));
86 scoped_ptr<HistogramSamples> snapshot(histogram->SnapshotSamples());
87 EXPECT_EQ(0, snapshot->TotalCount());
88 EXPECT_EQ(0, snapshot->sum());
89
90 histogram->AddCount(1000000000, 15);
91 scoped_ptr<HistogramSamples> snapshot1(histogram->SnapshotSamples());
92 EXPECT_EQ(15, snapshot1->TotalCount());
93 EXPECT_EQ(15, snapshot1->GetCount(1000000000));
94
95 histogram->AddCount(1000000000, 15);
96 histogram->AddCount(1010000000, 25);
97 scoped_ptr<HistogramSamples> snapshot2(histogram->SnapshotSamples());
98 EXPECT_EQ(55, snapshot2->TotalCount());
99 EXPECT_EQ(30, snapshot2->GetCount(1000000000));
100 EXPECT_EQ(25, snapshot2->GetCount(1010000000));
101 EXPECT_EQ(55250000000LL, snapshot2->sum());
102 }
103
84 TEST_F(SparseHistogramTest, MacroBasicTest) { 104 TEST_F(SparseHistogramTest, MacroBasicTest) {
85 UMA_HISTOGRAM_SPARSE_SLOWLY("Sparse", 100); 105 UMA_HISTOGRAM_SPARSE_SLOWLY("Sparse", 100);
86 UMA_HISTOGRAM_SPARSE_SLOWLY("Sparse", 200); 106 UMA_HISTOGRAM_SPARSE_SLOWLY("Sparse", 200);
87 UMA_HISTOGRAM_SPARSE_SLOWLY("Sparse", 100); 107 UMA_HISTOGRAM_SPARSE_SLOWLY("Sparse", 100);
88 108
89 StatisticsRecorder::Histograms histograms; 109 StatisticsRecorder::Histograms histograms;
90 StatisticsRecorder::GetHistograms(&histograms); 110 StatisticsRecorder::GetHistograms(&histograms);
91 111
92 ASSERT_EQ(1U, histograms.size()); 112 ASSERT_EQ(1U, histograms.size());
93 HistogramBase* sparse_histogram = histograms[0]; 113 HistogramBase* sparse_histogram = histograms[0];
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 160
141 int flag; 161 int flag;
142 EXPECT_TRUE(iter.ReadInt(&flag)); 162 EXPECT_TRUE(iter.ReadInt(&flag));
143 EXPECT_EQ(HistogramBase::kIPCSerializationSourceFlag, flag); 163 EXPECT_EQ(HistogramBase::kIPCSerializationSourceFlag, flag);
144 164
145 // No more data in the pickle. 165 // No more data in the pickle.
146 EXPECT_FALSE(iter.SkipBytes(1)); 166 EXPECT_FALSE(iter.SkipBytes(1));
147 } 167 }
148 168
149 } // namespace base 169 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/sample_vector_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698