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

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

Issue 6577013: Crash when we notice a corruption of the histogram range-vector... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 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 | Annotate | Revision Log
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 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 TEST(HistogramTest, CorruptBucketBounds) { 341 TEST(HistogramTest, CorruptBucketBounds) {
342 scoped_refptr<Histogram> histogram = Histogram::FactoryGet( 342 scoped_refptr<Histogram> histogram = Histogram::FactoryGet(
343 "Histogram", 1, 64, 8, Histogram::kNoFlags); // As per header file. 343 "Histogram", 1, 64, 8, Histogram::kNoFlags); // As per header file.
344 344
345 Histogram::SampleSet snapshot; 345 Histogram::SampleSet snapshot;
346 histogram->SnapshotSample(&snapshot); 346 histogram->SnapshotSample(&snapshot);
347 EXPECT_EQ(Histogram::NO_INCONSISTENCIES, 0); 347 EXPECT_EQ(Histogram::NO_INCONSISTENCIES, 0);
348 EXPECT_EQ(0, histogram->FindCorruption(snapshot)); // No default corruption. 348 EXPECT_EQ(0, histogram->FindCorruption(snapshot)); // No default corruption.
349 349
350 std::swap(histogram->ranges_[1], histogram->ranges_[2]); 350 std::swap(histogram->ranges_[1], histogram->ranges_[2]);
351 EXPECT_EQ(Histogram::BUCKET_ORDER_ERROR, histogram->FindCorruption(snapshot)); 351 EXPECT_EQ(Histogram::BUCKET_ORDER_ERROR | Histogram::RANGE_CHECKSUM_ERROR,
352 histogram->FindCorruption(snapshot));
352 353
353 std::swap(histogram->ranges_[1], histogram->ranges_[2]); 354 std::swap(histogram->ranges_[1], histogram->ranges_[2]);
354 EXPECT_EQ(0, histogram->FindCorruption(snapshot)); 355 EXPECT_EQ(0, histogram->FindCorruption(snapshot));
355 356
356 ++histogram->ranges_[3]; 357 ++histogram->ranges_[3];
357 EXPECT_EQ(Histogram::RANGE_CHECKSUM_ERROR, 358 EXPECT_EQ(Histogram::RANGE_CHECKSUM_ERROR,
358 histogram->FindCorruption(snapshot)); 359 histogram->FindCorruption(snapshot));
359 360
361 // Show that two simple changes don't offset each other
362 --histogram->ranges_[4];
363 EXPECT_EQ(Histogram::RANGE_CHECKSUM_ERROR,
364 histogram->FindCorruption(snapshot));
365
360 // Repair histogram so that destructor won't DCHECK(). 366 // Repair histogram so that destructor won't DCHECK().
361 --histogram->ranges_[3]; 367 --histogram->ranges_[3];
368 ++histogram->ranges_[4];
369 }
370
371 // Table was generated similarly to sample code for CRC-32 given on:
372 // http://www.w3.org/TR/PNG/#D-CRCAppendix.
373 TEST(HistogramTest, Crc32TableTest) {
374 for (int i = 0; i < 256; ++i) {
375 uint32 checksum = i;
376 for (int j = 0; j < 8; ++j) {
377 const uint32 kReversedPolynomial = 0xedb88320L;
378 if (checksum & 1)
379 checksum = kReversedPolynomial ^ (checksum >> 1);
380 else
381 checksum >>= 1;
382 }
383 EXPECT_EQ(Histogram::kCrcTable[i], checksum);
384 }
362 } 385 }
363 386
364 } // namespace base 387 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698