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 22 matching lines...) Expand all Loading... |
33 HistogramTest() {} | 33 HistogramTest() {} |
34 ~HistogramTest() override {} | 34 ~HistogramTest() override {} |
35 | 35 |
36 protected: | 36 protected: |
37 const int32_t kAllocatorMemorySize = 64 << 10; // 64 KiB | 37 const int32_t kAllocatorMemorySize = 64 << 10; // 64 KiB |
38 | 38 |
39 void SetUp() override { | 39 void SetUp() override { |
40 // Each test will have a clean state (no Histogram / BucketRanges | 40 // Each test will have a clean state (no Histogram / BucketRanges |
41 // registered). | 41 // registered). |
42 InitializeStatisticsRecorder(); | 42 InitializeStatisticsRecorder(); |
43 // By getting the results-histogram before any persistent allocator | |
44 // is attached, that histogram is guaranteed not to be stored in | |
45 // any persistent memory segment (which simplifies some tests). | |
46 GetCreateHistogramResultHistogram(); | |
47 } | 43 } |
48 | 44 |
49 void TearDown() override { | 45 void TearDown() override { |
50 UninitializeStatisticsRecorder(); | 46 UninitializeStatisticsRecorder(); |
51 DestroyPersistentMemoryAllocator(); | 47 DestroyPersistentMemoryAllocator(); |
52 } | 48 } |
53 | 49 |
54 void InitializeStatisticsRecorder() { | 50 void InitializeStatisticsRecorder() { |
55 StatisticsRecorder::ResetForTesting(); | 51 StatisticsRecorder::ResetForTesting(); |
56 statistics_recorder_ = new StatisticsRecorder(); | 52 statistics_recorder_ = new StatisticsRecorder(); |
57 } | 53 } |
58 | 54 |
59 void UninitializeStatisticsRecorder() { | 55 void UninitializeStatisticsRecorder() { |
60 delete statistics_recorder_; | 56 delete statistics_recorder_; |
61 statistics_recorder_ = NULL; | 57 statistics_recorder_ = NULL; |
62 } | 58 } |
63 | 59 |
64 void CreatePersistentMemoryAllocator() { | 60 void CreatePersistentMemoryAllocator() { |
| 61 // By getting the results-histogram before any persistent allocator |
| 62 // is attached, that histogram is guaranteed not to be stored in |
| 63 // any persistent memory segment (which simplifies some tests). |
| 64 GetCreateHistogramResultHistogram(); |
| 65 |
65 if (!allocator_memory_) | 66 if (!allocator_memory_) |
66 allocator_memory_.reset(new char[kAllocatorMemorySize]); | 67 allocator_memory_.reset(new char[kAllocatorMemorySize]); |
67 | 68 |
68 SetPersistentHistogramMemoryAllocator(nullptr); | |
69 memset(allocator_memory_.get(), 0, kAllocatorMemorySize); | 69 memset(allocator_memory_.get(), 0, kAllocatorMemorySize); |
70 SetPersistentHistogramMemoryAllocator( | 70 SetPersistentHistogramMemoryAllocator( |
71 new PersistentMemoryAllocator( | 71 new PersistentMemoryAllocator( |
72 allocator_memory_.get(), kAllocatorMemorySize, 0, | 72 allocator_memory_.get(), kAllocatorMemorySize, 0, |
73 0, "HistogramAllocatorTest", false)); | 73 0, "HistogramAllocatorTest", false)); |
74 allocator_ = GetPersistentHistogramMemoryAllocator(); | 74 allocator_ = GetPersistentHistogramMemoryAllocator(); |
75 } | 75 } |
76 | 76 |
77 void DestroyPersistentMemoryAllocator() { | 77 void DestroyPersistentMemoryAllocator() { |
78 allocator_ = nullptr; | 78 allocator_ = nullptr; |
79 SetPersistentHistogramMemoryAllocator(nullptr); | 79 delete ReleasePersistentHistogramMemoryAllocatorForTesting(); |
80 } | 80 } |
81 | 81 |
82 StatisticsRecorder* statistics_recorder_; | 82 StatisticsRecorder* statistics_recorder_; |
83 scoped_ptr<char[]> allocator_memory_; | 83 scoped_ptr<char[]> allocator_memory_; |
84 PersistentMemoryAllocator* allocator_; | 84 PersistentMemoryAllocator* allocator_; |
85 | 85 |
86 private: | 86 private: |
87 DISALLOW_COPY_AND_ASSIGN(HistogramTest); | 87 DISALLOW_COPY_AND_ASSIGN(HistogramTest); |
88 }; | 88 }; |
89 | 89 |
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 // CustomHistogram needs at least 1 valid range. | 771 // CustomHistogram needs at least 1 valid range. |
772 custom_ranges.clear(); | 772 custom_ranges.clear(); |
773 custom_ranges.push_back(0); | 773 custom_ranges.push_back(0); |
774 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, | 774 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, |
775 HistogramBase::kNoFlags), | 775 HistogramBase::kNoFlags), |
776 ""); | 776 ""); |
777 } | 777 } |
778 #endif | 778 #endif |
779 | 779 |
780 } // namespace base | 780 } // namespace base |
OLD | NEW |