Index: base/metrics/histogram_unittest.cc |
diff --git a/base/metrics/histogram_unittest.cc b/base/metrics/histogram_unittest.cc |
index 09f9106d09758837ce79ac15453bb5c198a3b9d8..c1202aa4732752c60b52be770ba9de6719ace331 100644 |
--- a/base/metrics/histogram_unittest.cc |
+++ b/base/metrics/histogram_unittest.cc |
@@ -29,11 +29,13 @@ |
namespace base { |
class HistogramTest : public testing::Test { |
+ public: |
+ HistogramTest() {} |
+ ~HistogramTest() override {} |
+ |
protected: |
const int32_t kAllocatorMemorySize = 64 << 10; // 64 KiB |
- HistogramTest() {} |
- |
void SetUp() override { |
// Each test will have a clean state (no Histogram / BucketRanges |
// registered). |
@@ -50,6 +52,7 @@ class HistogramTest : public testing::Test { |
} |
void InitializeStatisticsRecorder() { |
+ StatisticsRecorder::ResetForTesting(); |
statistics_recorder_ = new StatisticsRecorder(); |
} |
@@ -84,6 +87,21 @@ class HistogramTest : public testing::Test { |
DISALLOW_COPY_AND_ASSIGN(HistogramTest); |
}; |
+class AllocatorHistogramTest : public HistogramTest, |
+ public testing::WithParamInterface<bool> { |
+ public: |
+ AllocatorHistogramTest() { |
+ if (GetParam()) |
+ CreatePersistentMemoryAllocator(); |
+ } |
+ ~AllocatorHistogramTest() override {} |
+}; |
+ |
+// Run all AllocatorHistogramTest cases with both heap and persistent memory. |
+INSTANTIATE_TEST_CASE_P(HeapAndPersistent, AllocatorHistogramTest, |
+ testing::Values(false, true)); |
+ |
+ |
// Check for basic syntax and use. |
TEST_F(HistogramTest, BasicTest) { |
// Try basic construction |
@@ -208,6 +226,35 @@ TEST_F(HistogramTest, NameMatchTest) { |
EXPECT_EQ(2, samples->GetCount(10)); |
} |
+// Check that delta calculations work correct. |
+TEST_P(AllocatorHistogramTest, DeltaTest) { |
+ HistogramBase* histogram = |
+ Histogram::FactoryGet("DeltaHistogram", 1, 64, 8, |
+ HistogramBase::kNoFlags); |
+ histogram->Add(1); |
+ histogram->Add(10); |
+ histogram->Add(50); |
+ |
+ scoped_ptr<HistogramSamples> samples = histogram->SnapshotDelta(); |
+ EXPECT_EQ(3, samples->TotalCount()); |
+ EXPECT_EQ(1, samples->GetCount(1)); |
+ EXPECT_EQ(1, samples->GetCount(10)); |
+ EXPECT_EQ(1, samples->GetCount(50)); |
+ EXPECT_EQ(samples->TotalCount(), samples->redundant_count()); |
+ |
+ samples = histogram->SnapshotDelta(); |
+ EXPECT_EQ(0, samples->TotalCount()); |
+ |
+ histogram->Add(10); |
+ histogram->Add(10); |
+ samples = histogram->SnapshotDelta(); |
+ EXPECT_EQ(2, samples->TotalCount()); |
+ EXPECT_EQ(2, samples->GetCount(10)); |
+ |
+ samples = histogram->SnapshotDelta(); |
+ EXPECT_EQ(0, samples->TotalCount()); |
+} |
+ |
TEST_F(HistogramTest, ExponentialRangesTest) { |
// Check that we got a nice exponential when there was enough room. |
BucketRanges ranges(9); |
@@ -520,7 +567,7 @@ TEST_F(HistogramTest, CorruptBucketBounds) { |
bucket_ranges->set_range(2, bucket_ranges->range(1)); |
bucket_ranges->set_range(1, tmp); |
- EXPECT_EQ(0, histogram->FindCorruption(*snapshot)); |
+ EXPECT_EQ(0U, histogram->FindCorruption(*snapshot)); |
// Show that two simple changes don't offset each other |
bucket_ranges->set_range(3, bucket_ranges->range(3) + 1); |