summaryrefslogtreecommitdiffstats
path: root/base/metrics/histogram_unittest.cc
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2010-11-18 18:32:45 +0000
committerBen Murdoch <benm@google.com>2010-11-18 18:38:07 +0000
commit513209b27ff55e2841eac0e4120199c23acce758 (patch)
treeaeba30bb08c5f47c57003544e378a377c297eee6 /base/metrics/histogram_unittest.cc
parent164f7496de0fbee436b385a79ead9e3cb81a50c1 (diff)
downloadexternal_chromium-513209b27ff55e2841eac0e4120199c23acce758.zip
external_chromium-513209b27ff55e2841eac0e4120199c23acce758.tar.gz
external_chromium-513209b27ff55e2841eac0e4120199c23acce758.tar.bz2
Merge Chromium at r65505: Initial merge by git.
Change-Id: I31d8f1d8cd33caaf7f47ffa7350aef42d5fbdb45
Diffstat (limited to 'base/metrics/histogram_unittest.cc')
-rw-r--r--base/metrics/histogram_unittest.cc53
1 files changed, 53 insertions, 0 deletions
diff --git a/base/metrics/histogram_unittest.cc b/base/metrics/histogram_unittest.cc
index e7e3983..b9c51ad 100644
--- a/base/metrics/histogram_unittest.cc
+++ b/base/metrics/histogram_unittest.cc
@@ -308,4 +308,57 @@ TEST(HistogramTest, BucketPlacementTest) {
}
} // namespace
+
+//------------------------------------------------------------------------------
+// We can't be an an anonymous namespace while being friends, so we pop back
+// out to the base namespace here. We need to be friends to corrupt the
+// internals of the histogram and/or sampleset.
+TEST(HistogramTest, CorruptSampleCounts) {
+ scoped_refptr<Histogram> histogram = Histogram::FactoryGet(
+ "Histogram", 1, 64, 8, Histogram::kNoFlags); // As per header file.
+
+ EXPECT_EQ(0, histogram->sample_.redundant_count());
+ histogram->Add(20); // Add some samples.
+ histogram->Add(40);
+ EXPECT_EQ(2, histogram->sample_.redundant_count());
+
+ Histogram::SampleSet snapshot;
+ histogram->SnapshotSample(&snapshot);
+ EXPECT_EQ(Histogram::NO_INCONSISTENCIES, 0);
+ EXPECT_EQ(0, histogram->FindCorruption(snapshot)); // No default corruption.
+ EXPECT_EQ(2, snapshot.redundant_count());
+
+ snapshot.counts_[3] += 100; // Sample count won't match redundant count.
+ EXPECT_EQ(Histogram::COUNT_LOW_ERROR, histogram->FindCorruption(snapshot));
+ snapshot.counts_[2] -= 200;
+ EXPECT_EQ(Histogram::COUNT_HIGH_ERROR, histogram->FindCorruption(snapshot));
+
+ // But we can't spot a corruption if it is compensated for.
+ snapshot.counts_[1] += 100;
+ EXPECT_EQ(0, histogram->FindCorruption(snapshot));
+}
+
+TEST(HistogramTest, CorruptBucketBounds) {
+ scoped_refptr<Histogram> histogram = Histogram::FactoryGet(
+ "Histogram", 1, 64, 8, Histogram::kNoFlags); // As per header file.
+
+ Histogram::SampleSet snapshot;
+ histogram->SnapshotSample(&snapshot);
+ EXPECT_EQ(Histogram::NO_INCONSISTENCIES, 0);
+ EXPECT_EQ(0, histogram->FindCorruption(snapshot)); // No default corruption.
+
+ std::swap(histogram->ranges_[1], histogram->ranges_[2]);
+ EXPECT_EQ(Histogram::BUCKET_ORDER_ERROR, histogram->FindCorruption(snapshot));
+
+ std::swap(histogram->ranges_[1], histogram->ranges_[2]);
+ EXPECT_EQ(0, histogram->FindCorruption(snapshot));
+
+ ++histogram->ranges_[3];
+ EXPECT_EQ(Histogram::RANGE_CHECKSUM_ERROR,
+ histogram->FindCorruption(snapshot));
+
+ // Repair histogram so that destructor won't DCHECK().
+ --histogram->ranges_[3];
+}
+
} // namespace base