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

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

Issue 12207058: Connect SparseHistogram with the rest of stats system (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix and add tests Created 7 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 unified diff | Download patch | Annotate | Revision Log
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 <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
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(NO_INCONSISTENCIES, histogram->FindCorruption(*snapshot));
319 histogram->FindCorruption(*snapshot));
320 EXPECT_EQ(2, snapshot->redundant_count()); 319 EXPECT_EQ(2, snapshot->redundant_count());
321 EXPECT_EQ(2, snapshot->TotalCount()); 320 EXPECT_EQ(2, snapshot->TotalCount());
322 321
323 snapshot->counts_[3] += 100; // Sample count won't match redundant count. 322 snapshot->counts_[3] += 100; // Sample count won't match redundant count.
324 EXPECT_EQ(Histogram::COUNT_LOW_ERROR, 323 EXPECT_EQ(COUNT_LOW_ERROR, histogram->FindCorruption(*snapshot));
325 histogram->FindCorruption(*snapshot));
326 snapshot->counts_[2] -= 200; 324 snapshot->counts_[2] -= 200;
327 EXPECT_EQ(Histogram::COUNT_HIGH_ERROR, 325 EXPECT_EQ(COUNT_HIGH_ERROR, histogram->FindCorruption(*snapshot));
328 histogram->FindCorruption(*snapshot));
329 326
330 // But we can't spot a corruption if it is compensated for. 327 // But we can't spot a corruption if it is compensated for.
331 snapshot->counts_[1] += 100; 328 snapshot->counts_[1] += 100;
332 EXPECT_EQ(Histogram::NO_INCONSISTENCIES, 329 EXPECT_EQ(NO_INCONSISTENCIES, histogram->FindCorruption(*snapshot));
333 histogram->FindCorruption(*snapshot));
334 } 330 }
335 331
336 TEST_F(HistogramTest, CorruptBucketBounds) { 332 TEST_F(HistogramTest, CorruptBucketBounds) {
337 Histogram* histogram = static_cast<Histogram*>( 333 Histogram* histogram = static_cast<Histogram*>(
338 Histogram::FactoryGet("Histogram", 1, 64, 8, HistogramBase::kNoFlags)); 334 Histogram::FactoryGet("Histogram", 1, 64, 8, HistogramBase::kNoFlags));
339 335
340 scoped_ptr<SampleVector> snapshot = histogram->SnapshotSampleVector(); 336 scoped_ptr<SampleVector> snapshot = histogram->SnapshotSampleVector();
341 EXPECT_EQ(Histogram::NO_INCONSISTENCIES, 337 EXPECT_EQ(NO_INCONSISTENCIES, histogram->FindCorruption(*snapshot));
342 histogram->FindCorruption(*snapshot));
343 338
344 BucketRanges* bucket_ranges = 339 BucketRanges* bucket_ranges =
345 const_cast<BucketRanges*>(histogram->bucket_ranges()); 340 const_cast<BucketRanges*>(histogram->bucket_ranges());
346 HistogramBase::Sample tmp = bucket_ranges->range(1); 341 HistogramBase::Sample tmp = bucket_ranges->range(1);
347 bucket_ranges->set_range(1, bucket_ranges->range(2)); 342 bucket_ranges->set_range(1, bucket_ranges->range(2));
348 bucket_ranges->set_range(2, tmp); 343 bucket_ranges->set_range(2, tmp);
349 EXPECT_EQ(Histogram::BUCKET_ORDER_ERROR | Histogram::RANGE_CHECKSUM_ERROR, 344 EXPECT_EQ(BUCKET_ORDER_ERROR | RANGE_CHECKSUM_ERROR,
350 histogram->FindCorruption(*snapshot)); 345 histogram->FindCorruption(*snapshot));
351 346
352 bucket_ranges->set_range(2, bucket_ranges->range(1)); 347 bucket_ranges->set_range(2, bucket_ranges->range(1));
353 bucket_ranges->set_range(1, tmp); 348 bucket_ranges->set_range(1, tmp);
354 EXPECT_EQ(0, histogram->FindCorruption(*snapshot)); 349 EXPECT_EQ(0, histogram->FindCorruption(*snapshot));
355 350
356 // Show that two simple changes don't offset each other 351 // Show that two simple changes don't offset each other
357 bucket_ranges->set_range(3, bucket_ranges->range(3) + 1); 352 bucket_ranges->set_range(3, bucket_ranges->range(3) + 1);
358 EXPECT_EQ(Histogram::RANGE_CHECKSUM_ERROR, 353 EXPECT_EQ(RANGE_CHECKSUM_ERROR, histogram->FindCorruption(*snapshot));
359 histogram->FindCorruption(*snapshot));
360 354
361 bucket_ranges->set_range(4, bucket_ranges->range(4) - 1); 355 bucket_ranges->set_range(4, bucket_ranges->range(4) - 1);
362 EXPECT_EQ(Histogram::RANGE_CHECKSUM_ERROR, 356 EXPECT_EQ(RANGE_CHECKSUM_ERROR, histogram->FindCorruption(*snapshot));
363 histogram->FindCorruption(*snapshot));
364 357
365 // Repair histogram so that destructor won't DCHECK(). 358 // Repair histogram so that destructor won't DCHECK().
366 bucket_ranges->set_range(3, bucket_ranges->range(3) - 1); 359 bucket_ranges->set_range(3, bucket_ranges->range(3) - 1);
367 bucket_ranges->set_range(4, bucket_ranges->range(4) + 1); 360 bucket_ranges->set_range(4, bucket_ranges->range(4) + 1);
368 } 361 }
369 362
370 TEST_F(HistogramTest, HistogramSerializeInfo) { 363 TEST_F(HistogramTest, HistogramSerializeInfo) {
371 Histogram* histogram = static_cast<Histogram*>( 364 Histogram* histogram = static_cast<Histogram*>(
372 Histogram::FactoryGet("Histogram", 1, 64, 8, 365 Histogram::FactoryGet("Histogram", 1, 64, 8,
373 HistogramBase::kIPCSerializationSourceFlag)); 366 HistogramBase::kIPCSerializationSourceFlag));
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 // CustomHistogram needs at least 1 valid range. 476 // CustomHistogram needs at least 1 valid range.
484 custom_ranges.clear(); 477 custom_ranges.clear();
485 custom_ranges.push_back(0); 478 custom_ranges.push_back(0);
486 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, 479 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges,
487 HistogramBase::kNoFlags), 480 HistogramBase::kNoFlags),
488 ""); 481 "");
489 } 482 }
490 #endif 483 #endif
491 484
492 } // namespace base 485 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698