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 19 matching lines...) Expand all Loading... |
30 // Test parameter indicates if a persistent memory allocator should be used | 30 // Test parameter indicates if a persistent memory allocator should be used |
31 // for histogram allocation. False will allocate histograms from the process | 31 // for histogram allocation. False will allocate histograms from the process |
32 // heap. | 32 // heap. |
33 class HistogramTest : public testing::TestWithParam<bool> { | 33 class HistogramTest : public testing::TestWithParam<bool> { |
34 protected: | 34 protected: |
35 const int32_t kAllocatorMemorySize = 8 << 20; // 8 MiB | 35 const int32_t kAllocatorMemorySize = 8 << 20; // 8 MiB |
36 | 36 |
37 HistogramTest() : use_persistent_histogram_allocator_(GetParam()) {} | 37 HistogramTest() : use_persistent_histogram_allocator_(GetParam()) {} |
38 | 38 |
39 void SetUp() override { | 39 void SetUp() override { |
| 40 if (use_persistent_histogram_allocator_) |
| 41 CreatePersistentMemoryAllocator(); |
| 42 |
40 // Each test will have a clean state (no Histogram / BucketRanges | 43 // Each test will have a clean state (no Histogram / BucketRanges |
41 // registered). | 44 // registered). |
42 InitializeStatisticsRecorder(); | 45 InitializeStatisticsRecorder(); |
43 if (use_persistent_histogram_allocator_) | |
44 CreatePersistentMemoryAllocator(); | |
45 } | 46 } |
46 | 47 |
47 void TearDown() override { | 48 void TearDown() override { |
48 if (allocator_) { | 49 if (allocator_) { |
49 ASSERT_FALSE(allocator_->IsFull()); | 50 ASSERT_FALSE(allocator_->IsFull()); |
50 ASSERT_FALSE(allocator_->IsCorrupt()); | 51 ASSERT_FALSE(allocator_->IsCorrupt()); |
51 } | 52 } |
52 UninitializeStatisticsRecorder(); | 53 UninitializeStatisticsRecorder(); |
53 DestroyPersistentMemoryAllocator(); | 54 DestroyPersistentMemoryAllocator(); |
54 } | 55 } |
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
797 // CustomHistogram needs at least 1 valid range. | 798 // CustomHistogram needs at least 1 valid range. |
798 custom_ranges.clear(); | 799 custom_ranges.clear(); |
799 custom_ranges.push_back(0); | 800 custom_ranges.push_back(0); |
800 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, | 801 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, |
801 HistogramBase::kNoFlags), | 802 HistogramBase::kNoFlags), |
802 ""); | 803 ""); |
803 } | 804 } |
804 #endif | 805 #endif |
805 | 806 |
806 } // namespace base | 807 } // namespace base |
OLD | NEW |