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

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

Issue 10807083: Revert 148055 - Move CachedRanges out and add support for checksum. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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
« no previous file with comments | « base/metrics/histogram.cc ('k') | base/metrics/statistics_recorder.h » ('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) 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 // Test of Histogram class 5 // Test of Histogram class
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/metrics/bucket_ranges.h"
13 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
14 #include "base/metrics/statistics_recorder.h" 13 #include "base/metrics/statistics_recorder.h"
15 #include "base/time.h" 14 #include "base/time.h"
16 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
17 16
18 namespace base { 17 namespace base {
19 18
20 class HistogramTest : public testing::Test { 19 class HistogramTest : public testing::Test {
21 }; 20 };
22 21
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 375
377 TEST(HistogramTest, CorruptBucketBounds) { 376 TEST(HistogramTest, CorruptBucketBounds) {
378 Histogram* histogram(Histogram::FactoryGet( 377 Histogram* histogram(Histogram::FactoryGet(
379 "Histogram", 1, 64, 8, Histogram::kNoFlags)); // As per header file. 378 "Histogram", 1, 64, 8, Histogram::kNoFlags)); // As per header file.
380 379
381 Histogram::SampleSet snapshot; 380 Histogram::SampleSet snapshot;
382 histogram->SnapshotSample(&snapshot); 381 histogram->SnapshotSample(&snapshot);
383 EXPECT_EQ(Histogram::NO_INCONSISTENCIES, 0); 382 EXPECT_EQ(Histogram::NO_INCONSISTENCIES, 0);
384 EXPECT_EQ(0, histogram->FindCorruption(snapshot)); // No default corruption. 383 EXPECT_EQ(0, histogram->FindCorruption(snapshot)); // No default corruption.
385 384
386 BucketRanges* bucket_ranges = histogram->bucket_ranges(); 385 CachedRanges* cached_ranges = histogram->cached_ranges();
387 HistogramBase::Sample tmp = bucket_ranges->range(1); 386 std::swap(cached_ranges->ranges_[1], cached_ranges->ranges_[2]);
388 bucket_ranges->set_range(1, bucket_ranges->range(2));
389 bucket_ranges->set_range(2, tmp);
390 EXPECT_EQ(Histogram::BUCKET_ORDER_ERROR | Histogram::RANGE_CHECKSUM_ERROR, 387 EXPECT_EQ(Histogram::BUCKET_ORDER_ERROR | Histogram::RANGE_CHECKSUM_ERROR,
391 histogram->FindCorruption(snapshot)); 388 histogram->FindCorruption(snapshot));
392 389
393 bucket_ranges->set_range(2, bucket_ranges->range(1)); 390 std::swap(cached_ranges->ranges_[1], cached_ranges->ranges_[2]);
394 bucket_ranges->set_range(1, tmp);
395 EXPECT_EQ(0, histogram->FindCorruption(snapshot)); 391 EXPECT_EQ(0, histogram->FindCorruption(snapshot));
396 392
397 bucket_ranges->set_range(3, bucket_ranges->range(3) + 1); 393 ++cached_ranges->ranges_[3];
398 EXPECT_EQ(Histogram::RANGE_CHECKSUM_ERROR, 394 EXPECT_EQ(Histogram::RANGE_CHECKSUM_ERROR,
399 histogram->FindCorruption(snapshot)); 395 histogram->FindCorruption(snapshot));
400 396
401 // Show that two simple changes don't offset each other 397 // Show that two simple changes don't offset each other
402 bucket_ranges->set_range(4, bucket_ranges->range(4) - 1); 398 --cached_ranges->ranges_[4];
403 EXPECT_EQ(Histogram::RANGE_CHECKSUM_ERROR, 399 EXPECT_EQ(Histogram::RANGE_CHECKSUM_ERROR,
404 histogram->FindCorruption(snapshot)); 400 histogram->FindCorruption(snapshot));
405 401
406 // Repair histogram so that destructor won't DCHECK(). 402 // Repair histogram so that destructor won't DCHECK().
407 bucket_ranges->set_range(3, bucket_ranges->range(3) - 1); 403 --cached_ranges->ranges_[3];
408 bucket_ranges->set_range(4, bucket_ranges->range(4) + 1); 404 ++cached_ranges->ranges_[4];
409 } 405 }
410 406
411 // Table was generated similarly to sample code for CRC-32 given on: 407 // Table was generated similarly to sample code for CRC-32 given on:
412 // http://www.w3.org/TR/PNG/#D-CRCAppendix. 408 // http://www.w3.org/TR/PNG/#D-CRCAppendix.
413 TEST(HistogramTest, Crc32TableTest) { 409 TEST(HistogramTest, Crc32TableTest) {
414 for (int i = 0; i < 256; ++i) { 410 for (int i = 0; i < 256; ++i) {
415 uint32 checksum = i; 411 uint32 checksum = i;
416 for (int j = 0; j < 8; ++j) { 412 for (int j = 0; j < 8; ++j) {
417 const uint32 kReversedPolynomial = 0xedb88320L; 413 const uint32 kReversedPolynomial = 0xedb88320L;
418 if (checksum & 1) 414 if (checksum & 1)
419 checksum = kReversedPolynomial ^ (checksum >> 1); 415 checksum = kReversedPolynomial ^ (checksum >> 1);
420 else 416 else
421 checksum >>= 1; 417 checksum >>= 1;
422 } 418 }
423 EXPECT_EQ(Histogram::kCrcTable[i], checksum); 419 EXPECT_EQ(Histogram::kCrcTable[i], checksum);
424 } 420 }
425 } 421 }
426 422
427 // RangeTest, CustomRangeTest and CorruptBucketBounds test BucketRanges class. 423 // RangeTest, CustomRangeTest and CorruptBucketBounds test CachedRanges class.
428 // The following tests sharing of BucketRanges object. 424 // The following tests sharing of CachedRanges object.
429 TEST(HistogramTest, BucketRangesTest) { 425 TEST(HistogramTest, CachedRangesTest) {
430 StatisticsRecorder recorder; 426 StatisticsRecorder recorder;
431 StatisticsRecorder::Histograms histograms; 427 StatisticsRecorder::Histograms histograms;
432 428
433 recorder.GetHistograms(&histograms); 429 recorder.GetHistograms(&histograms);
434 EXPECT_EQ(0U, histograms.size()); 430 EXPECT_EQ(0U, histograms.size());
435 431
436 Histogram* histogram1(Histogram::FactoryGet( 432 Histogram* histogram1(Histogram::FactoryGet(
437 "Histogram", 1, 64, 8, Histogram::kNoFlags)); 433 "Histogram", 1, 64, 8, Histogram::kNoFlags));
438 434
439 Histogram* histogram2(Histogram::FactoryGet( 435 Histogram* histogram2(Histogram::FactoryGet(
440 "Histogram2", 1, 64, 8, Histogram::kNoFlags)); 436 "Histogram2", 1, 64, 8, Histogram::kNoFlags));
441 437
442 Histogram* histogram3(Histogram::FactoryGet( 438 Histogram* histogram3(Histogram::FactoryGet(
443 "Histogram3", 1, 64, 16, Histogram::kNoFlags)); 439 "Histogram3", 1, 64, 16, Histogram::kNoFlags));
444 440
445 BucketRanges* bucket_ranges1 = histogram1->bucket_ranges(); 441 CachedRanges* cached_ranges1 = histogram1->cached_ranges();
446 BucketRanges* bucket_ranges2 = histogram2->bucket_ranges(); 442 CachedRanges* cached_ranges2 = histogram2->cached_ranges();
447 BucketRanges* bucket_ranges3 = histogram3->bucket_ranges(); 443 CachedRanges* cached_ranges3 = histogram3->cached_ranges();
448 EXPECT_TRUE(bucket_ranges1->Equals(bucket_ranges2)); 444 EXPECT_TRUE(cached_ranges1->Equals(cached_ranges2));
449 EXPECT_FALSE(bucket_ranges1->Equals(bucket_ranges3)); 445 EXPECT_FALSE(cached_ranges1->Equals(cached_ranges3));
450 } 446 }
451 447
452 } // namespace base 448 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/histogram.cc ('k') | base/metrics/statistics_recorder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698