| OLD | NEW |
| 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 <climits> | 7 #include <climits> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 | 308 |
| 309 TEST_F(HistogramTest, CorruptSampleCounts) { | 309 TEST_F(HistogramTest, CorruptSampleCounts) { |
| 310 Histogram* histogram = static_cast<Histogram*>( | 310 Histogram* histogram = static_cast<Histogram*>( |
| 311 Histogram::FactoryGet("Histogram", 1, 64, 8, HistogramBase::kNoFlags)); | 311 Histogram::FactoryGet("Histogram", 1, 64, 8, HistogramBase::kNoFlags)); |
| 312 | 312 |
| 313 // Add some samples. | 313 // Add some samples. |
| 314 histogram->Add(20); | 314 histogram->Add(20); |
| 315 histogram->Add(40); | 315 histogram->Add(40); |
| 316 | 316 |
| 317 scoped_ptr<SampleVector> snapshot = histogram->SnapshotSampleVector(); | 317 scoped_ptr<SampleVector> snapshot = histogram->SnapshotSampleVector(); |
| 318 EXPECT_EQ(Histogram::NO_INCONSISTENCIES, | 318 EXPECT_EQ(HistogramBase::NO_INCONSISTENCIES, |
| 319 histogram->FindCorruption(*snapshot)); | 319 histogram->FindCorruption(*snapshot)); |
| 320 EXPECT_EQ(2, snapshot->redundant_count()); | 320 EXPECT_EQ(2, snapshot->redundant_count()); |
| 321 EXPECT_EQ(2, snapshot->TotalCount()); | 321 EXPECT_EQ(2, snapshot->TotalCount()); |
| 322 | 322 |
| 323 snapshot->counts_[3] += 100; // Sample count won't match redundant count. | 323 snapshot->counts_[3] += 100; // Sample count won't match redundant count. |
| 324 EXPECT_EQ(Histogram::COUNT_LOW_ERROR, | 324 EXPECT_EQ(HistogramBase::COUNT_LOW_ERROR, |
| 325 histogram->FindCorruption(*snapshot)); | 325 histogram->FindCorruption(*snapshot)); |
| 326 snapshot->counts_[2] -= 200; | 326 snapshot->counts_[2] -= 200; |
| 327 EXPECT_EQ(Histogram::COUNT_HIGH_ERROR, | 327 EXPECT_EQ(HistogramBase::COUNT_HIGH_ERROR, |
| 328 histogram->FindCorruption(*snapshot)); | 328 histogram->FindCorruption(*snapshot)); |
| 329 | 329 |
| 330 // But we can't spot a corruption if it is compensated for. | 330 // But we can't spot a corruption if it is compensated for. |
| 331 snapshot->counts_[1] += 100; | 331 snapshot->counts_[1] += 100; |
| 332 EXPECT_EQ(Histogram::NO_INCONSISTENCIES, | 332 EXPECT_EQ(HistogramBase::NO_INCONSISTENCIES, |
| 333 histogram->FindCorruption(*snapshot)); | 333 histogram->FindCorruption(*snapshot)); |
| 334 } | 334 } |
| 335 | 335 |
| 336 TEST_F(HistogramTest, CorruptBucketBounds) { | 336 TEST_F(HistogramTest, CorruptBucketBounds) { |
| 337 Histogram* histogram = static_cast<Histogram*>( | 337 Histogram* histogram = static_cast<Histogram*>( |
| 338 Histogram::FactoryGet("Histogram", 1, 64, 8, HistogramBase::kNoFlags)); | 338 Histogram::FactoryGet("Histogram", 1, 64, 8, HistogramBase::kNoFlags)); |
| 339 | 339 |
| 340 scoped_ptr<SampleVector> snapshot = histogram->SnapshotSampleVector(); | 340 scoped_ptr<SampleVector> snapshot = histogram->SnapshotSampleVector(); |
| 341 EXPECT_EQ(Histogram::NO_INCONSISTENCIES, | 341 EXPECT_EQ(HistogramBase::NO_INCONSISTENCIES, |
| 342 histogram->FindCorruption(*snapshot)); | 342 histogram->FindCorruption(*snapshot)); |
| 343 | 343 |
| 344 BucketRanges* bucket_ranges = | 344 BucketRanges* bucket_ranges = |
| 345 const_cast<BucketRanges*>(histogram->bucket_ranges()); | 345 const_cast<BucketRanges*>(histogram->bucket_ranges()); |
| 346 HistogramBase::Sample tmp = bucket_ranges->range(1); | 346 HistogramBase::Sample tmp = bucket_ranges->range(1); |
| 347 bucket_ranges->set_range(1, bucket_ranges->range(2)); | 347 bucket_ranges->set_range(1, bucket_ranges->range(2)); |
| 348 bucket_ranges->set_range(2, tmp); | 348 bucket_ranges->set_range(2, tmp); |
| 349 EXPECT_EQ(Histogram::BUCKET_ORDER_ERROR | Histogram::RANGE_CHECKSUM_ERROR, | 349 EXPECT_EQ( |
| 350 histogram->FindCorruption(*snapshot)); | 350 HistogramBase::BUCKET_ORDER_ERROR | HistogramBase::RANGE_CHECKSUM_ERROR, |
| 351 histogram->FindCorruption(*snapshot)); |
| 351 | 352 |
| 352 bucket_ranges->set_range(2, bucket_ranges->range(1)); | 353 bucket_ranges->set_range(2, bucket_ranges->range(1)); |
| 353 bucket_ranges->set_range(1, tmp); | 354 bucket_ranges->set_range(1, tmp); |
| 354 EXPECT_EQ(0, histogram->FindCorruption(*snapshot)); | 355 EXPECT_EQ(0, histogram->FindCorruption(*snapshot)); |
| 355 | 356 |
| 356 // Show that two simple changes don't offset each other | 357 // Show that two simple changes don't offset each other |
| 357 bucket_ranges->set_range(3, bucket_ranges->range(3) + 1); | 358 bucket_ranges->set_range(3, bucket_ranges->range(3) + 1); |
| 358 EXPECT_EQ(Histogram::RANGE_CHECKSUM_ERROR, | 359 EXPECT_EQ(HistogramBase::RANGE_CHECKSUM_ERROR, |
| 359 histogram->FindCorruption(*snapshot)); | 360 histogram->FindCorruption(*snapshot)); |
| 360 | 361 |
| 361 bucket_ranges->set_range(4, bucket_ranges->range(4) - 1); | 362 bucket_ranges->set_range(4, bucket_ranges->range(4) - 1); |
| 362 EXPECT_EQ(Histogram::RANGE_CHECKSUM_ERROR, | 363 EXPECT_EQ(HistogramBase::RANGE_CHECKSUM_ERROR, |
| 363 histogram->FindCorruption(*snapshot)); | 364 histogram->FindCorruption(*snapshot)); |
| 364 | 365 |
| 365 // Repair histogram so that destructor won't DCHECK(). | 366 // Repair histogram so that destructor won't DCHECK(). |
| 366 bucket_ranges->set_range(3, bucket_ranges->range(3) - 1); | 367 bucket_ranges->set_range(3, bucket_ranges->range(3) - 1); |
| 367 bucket_ranges->set_range(4, bucket_ranges->range(4) + 1); | 368 bucket_ranges->set_range(4, bucket_ranges->range(4) + 1); |
| 368 } | 369 } |
| 369 | 370 |
| 370 TEST_F(HistogramTest, HistogramSerializeInfo) { | 371 TEST_F(HistogramTest, HistogramSerializeInfo) { |
| 371 Histogram* histogram = static_cast<Histogram*>( | 372 Histogram* histogram = static_cast<Histogram*>( |
| 372 Histogram::FactoryGet("Histogram", 1, 64, 8, | 373 Histogram::FactoryGet("Histogram", 1, 64, 8, |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 // CustomHistogram needs at least 1 valid range. | 484 // CustomHistogram needs at least 1 valid range. |
| 484 custom_ranges.clear(); | 485 custom_ranges.clear(); |
| 485 custom_ranges.push_back(0); | 486 custom_ranges.push_back(0); |
| 486 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, | 487 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, |
| 487 HistogramBase::kNoFlags), | 488 HistogramBase::kNoFlags), |
| 488 ""); | 489 ""); |
| 489 } | 490 } |
| 490 #endif | 491 #endif |
| 491 | 492 |
| 492 } // namespace base | 493 } // namespace base |
| OLD | NEW |