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 #include "base/metrics/histogram.h" | 5 #include "base/metrics/histogram.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 // Add some samples. | 483 // Add some samples. |
484 histogram->Add(20); | 484 histogram->Add(20); |
485 histogram->Add(40); | 485 histogram->Add(40); |
486 | 486 |
487 std::unique_ptr<SampleVector> snapshot = histogram->SnapshotSampleVector(); | 487 std::unique_ptr<SampleVector> snapshot = histogram->SnapshotSampleVector(); |
488 EXPECT_EQ(HistogramBase::NO_INCONSISTENCIES, | 488 EXPECT_EQ(HistogramBase::NO_INCONSISTENCIES, |
489 histogram->FindCorruption(*snapshot)); | 489 histogram->FindCorruption(*snapshot)); |
490 EXPECT_EQ(2, snapshot->redundant_count()); | 490 EXPECT_EQ(2, snapshot->redundant_count()); |
491 EXPECT_EQ(2, snapshot->TotalCount()); | 491 EXPECT_EQ(2, snapshot->TotalCount()); |
492 | 492 |
493 snapshot->counts_[3] += 100; // Sample count won't match redundant count. | 493 snapshot->counts()[3] += 100; // Sample count won't match redundant count. |
494 EXPECT_EQ(HistogramBase::COUNT_LOW_ERROR, | 494 EXPECT_EQ(HistogramBase::COUNT_LOW_ERROR, |
495 histogram->FindCorruption(*snapshot)); | 495 histogram->FindCorruption(*snapshot)); |
496 snapshot->counts_[2] -= 200; | 496 snapshot->counts()[2] -= 200; |
497 EXPECT_EQ(HistogramBase::COUNT_HIGH_ERROR, | 497 EXPECT_EQ(HistogramBase::COUNT_HIGH_ERROR, |
498 histogram->FindCorruption(*snapshot)); | 498 histogram->FindCorruption(*snapshot)); |
499 | 499 |
500 // But we can't spot a corruption if it is compensated for. | 500 // But we can't spot a corruption if it is compensated for. |
501 snapshot->counts_[1] += 100; | 501 snapshot->counts()[1] += 100; |
502 EXPECT_EQ(HistogramBase::NO_INCONSISTENCIES, | 502 EXPECT_EQ(HistogramBase::NO_INCONSISTENCIES, |
503 histogram->FindCorruption(*snapshot)); | 503 histogram->FindCorruption(*snapshot)); |
504 } | 504 } |
505 | 505 |
506 TEST_P(HistogramTest, CorruptBucketBounds) { | 506 TEST_P(HistogramTest, CorruptBucketBounds) { |
507 Histogram* histogram = static_cast<Histogram*>( | 507 Histogram* histogram = static_cast<Histogram*>( |
508 Histogram::FactoryGet("Histogram", 1, 64, 8, HistogramBase::kNoFlags)); | 508 Histogram::FactoryGet("Histogram", 1, 64, 8, HistogramBase::kNoFlags)); |
509 | 509 |
510 std::unique_ptr<HistogramSamples> snapshot = histogram->SnapshotSamples(); | 510 std::unique_ptr<HistogramSamples> snapshot = histogram->SnapshotSamples(); |
511 EXPECT_EQ(HistogramBase::NO_INCONSISTENCIES, | 511 EXPECT_EQ(HistogramBase::NO_INCONSISTENCIES, |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 // CustomHistogram needs at least 1 valid range. | 743 // CustomHistogram needs at least 1 valid range. |
744 custom_ranges.clear(); | 744 custom_ranges.clear(); |
745 custom_ranges.push_back(0); | 745 custom_ranges.push_back(0); |
746 EXPECT_DEATH_IF_SUPPORTED( | 746 EXPECT_DEATH_IF_SUPPORTED( |
747 CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, | 747 CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, |
748 HistogramBase::kNoFlags), | 748 HistogramBase::kNoFlags), |
749 ""); | 749 ""); |
750 } | 750 } |
751 | 751 |
752 } // namespace base | 752 } // namespace base |
OLD | NEW |