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

Side by Side Diff: base/metrics/histogram_unittest.cc

Issue 4349002: Revert 64687 - Try to detect internal corruption of histogram instances.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « base/metrics/histogram.cc ('k') | chrome/common/metrics_helpers.cc » ('j') | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 // Test of Histogram class 5 // Test of Histogram class
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/time.h" 8 #include "base/time.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 301
302 // Check to see that the bucket counts reflect our additions. 302 // Check to see that the bucket counts reflect our additions.
303 Histogram::SampleSet sample; 303 Histogram::SampleSet sample;
304 histogram->SnapshotSample(&sample); 304 histogram->SnapshotSample(&sample);
305 EXPECT_EQ(INT_MAX, histogram->ranges(8)); 305 EXPECT_EQ(INT_MAX, histogram->ranges(8));
306 for (int i = 0; i < 8; i++) 306 for (int i = 0; i < 8; i++)
307 EXPECT_EQ(i + 1, sample.counts(i)); 307 EXPECT_EQ(i + 1, sample.counts(i));
308 } 308 }
309 309
310 } // namespace 310 } // namespace
311
312 //------------------------------------------------------------------------------
313 // We can't be an an anonymous namespace while being friends, so we pop back
314 // out to the base namespace here. We need to be friends to corrupt the
315 // internals of the histogram and/or sampleset.
316 TEST(HistogramTest, CorruptSampleCounts) {
317 scoped_refptr<Histogram> histogram = Histogram::FactoryGet(
318 "Histogram", 1, 64, 8, Histogram::kNoFlags); // As per header file.
319
320 EXPECT_EQ(0, histogram->sample_.redundant_count());
321 histogram->Add(20); // Add some samples.
322 histogram->Add(40);
323 EXPECT_EQ(2, histogram->sample_.redundant_count());
324
325 Histogram::SampleSet snapshot;
326 histogram->SnapshotSample(&snapshot);
327 EXPECT_EQ(Histogram::NO_INCONSISTENCIES, 0);
328 EXPECT_EQ(0, histogram->FindCorruption(snapshot)); // No default corruption.
329 EXPECT_EQ(2, snapshot.redundant_count());
330
331 snapshot.counts_[3] += 100; // Sample count won't match redundant count.
332 EXPECT_EQ(Histogram::COUNT_LOW_ERROR, histogram->FindCorruption(snapshot));
333 snapshot.counts_[2] -= 200;
334 EXPECT_EQ(Histogram::COUNT_HIGH_ERROR, histogram->FindCorruption(snapshot));
335
336 // But we can't spot a corruption if it is compensated for.
337 snapshot.counts_[1] += 100;
338 EXPECT_EQ(0, histogram->FindCorruption(snapshot));
339 }
340
341 TEST(HistogramTest, CorruptBucketBounds) {
342 scoped_refptr<Histogram> histogram = Histogram::FactoryGet(
343 "Histogram", 1, 64, 8, Histogram::kNoFlags); // As per header file.
344
345 Histogram::SampleSet snapshot;
346 histogram->SnapshotSample(&snapshot);
347 EXPECT_EQ(Histogram::NO_INCONSISTENCIES, 0);
348 EXPECT_EQ(0, histogram->FindCorruption(snapshot)); // No default corruption.
349
350 std::swap(histogram->ranges_[1], histogram->ranges_[2]);
351 EXPECT_EQ(Histogram::BUCKET_ORDER_ERROR, histogram->FindCorruption(snapshot));
352
353 std::swap(histogram->ranges_[1], histogram->ranges_[2]);
354 EXPECT_EQ(0, histogram->FindCorruption(snapshot));
355
356 ++histogram->ranges_[3];
357 EXPECT_EQ(Histogram::RANGE_CHECKSUM_ERROR,
358 histogram->FindCorruption(snapshot));
359
360 // Repair histogram so that destructor won't DCHECK().
361 --histogram->ranges_[3];
362 }
363
364 } // namespace base 311 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/histogram.cc ('k') | chrome/common/metrics_helpers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698