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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: base/metrics/histogram_unittest.cc
===================================================================
--- base/metrics/histogram_unittest.cc (revision 76117)
+++ base/metrics/histogram_unittest.cc (working copy)
@@ -348,7 +348,8 @@
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));
+ EXPECT_EQ(Histogram::BUCKET_ORDER_ERROR | Histogram::RANGE_CHECKSUM_ERROR,
+ histogram->FindCorruption(snapshot));
std::swap(histogram->ranges_[1], histogram->ranges_[2]);
EXPECT_EQ(0, histogram->FindCorruption(snapshot));
@@ -357,8 +358,30 @@
EXPECT_EQ(Histogram::RANGE_CHECKSUM_ERROR,
histogram->FindCorruption(snapshot));
+ // Show that two simple changes don't offset each other
+ --histogram->ranges_[4];
+ EXPECT_EQ(Histogram::RANGE_CHECKSUM_ERROR,
+ histogram->FindCorruption(snapshot));
+
// Repair histogram so that destructor won't DCHECK().
--histogram->ranges_[3];
+ ++histogram->ranges_[4];
}
+// Table was generated similarly to sample code for CRC-32 given on:
+// http://www.w3.org/TR/PNG/#D-CRCAppendix.
+TEST(HistogramTest, Crc32TableTest) {
+ for (int i = 0; i < 256; ++i) {
+ uint32 checksum = i;
+ for (int j = 0; j < 8; ++j) {
+ const uint32 kReversedPolynomial = 0xedb88320L;
+ if (checksum & 1)
+ checksum = kReversedPolynomial ^ (checksum >> 1);
+ else
+ checksum >>= 1;
+ }
+ EXPECT_EQ(Histogram::kCrcTable[i], checksum);
+ }
+}
+
} // namespace base

Powered by Google App Engine
This is Rietveld 408576698