OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/persistent_histogram_allocator.h" | 5 #include "base/metrics/persistent_histogram_allocator.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/metrics/bucket_ranges.h" | 9 #include "base/metrics/bucket_ranges.h" |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
11 #include "base/metrics/persistent_memory_allocator.h" | 11 #include "base/metrics/persistent_memory_allocator.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 namespace base { | 14 namespace base { |
15 | 15 |
16 class PersistentHistogramAllocatorTest : public testing::Test { | 16 class PersistentHistogramAllocatorTest : public testing::Test { |
17 protected: | 17 protected: |
18 const int32_t kAllocatorMemorySize = 64 << 10; // 64 KiB | 18 const int32_t kAllocatorMemorySize = 64 << 10; // 64 KiB |
19 | 19 |
20 PersistentHistogramAllocatorTest() { CreatePersistentHistogramAllocator(); } | 20 PersistentHistogramAllocatorTest() { CreatePersistentHistogramAllocator(); } |
21 ~PersistentHistogramAllocatorTest() override { | 21 ~PersistentHistogramAllocatorTest() override { |
22 DestroyPersistentHistogramAllocator(); | 22 DestroyPersistentHistogramAllocator(); |
23 } | 23 } |
24 | 24 |
25 void CreatePersistentHistogramAllocator() { | 25 void CreatePersistentHistogramAllocator() { |
26 allocator_memory_.reset(new char[kAllocatorMemorySize]); | 26 allocator_memory_.reset(new char[kAllocatorMemorySize]); |
27 | 27 |
28 PersistentHistogramAllocator::ReleaseGlobalAllocatorForTesting(); | 28 GlobalHistogramAllocator::ReleaseForTesting(); |
29 memset(allocator_memory_.get(), 0, kAllocatorMemorySize); | 29 memset(allocator_memory_.get(), 0, kAllocatorMemorySize); |
30 PersistentHistogramAllocator::GetCreateHistogramResultHistogram(); | 30 GlobalHistogramAllocator::GetCreateHistogramResultHistogram(); |
31 PersistentHistogramAllocator::CreateGlobalAllocatorOnPersistentMemory( | 31 GlobalHistogramAllocator::CreateWithPersistentMemory( |
32 allocator_memory_.get(), kAllocatorMemorySize, 0, 0, | 32 allocator_memory_.get(), kAllocatorMemorySize, 0, 0, |
33 "PersistentHistogramAllocatorTest"); | 33 "PersistentHistogramAllocatorTest"); |
34 allocator_ = | 34 allocator_ = GlobalHistogramAllocator::Get()->memory_allocator(); |
35 PersistentHistogramAllocator::GetGlobalAllocator()->memory_allocator(); | |
36 } | 35 } |
37 | 36 |
38 void DestroyPersistentHistogramAllocator() { | 37 void DestroyPersistentHistogramAllocator() { |
39 allocator_ = nullptr; | 38 allocator_ = nullptr; |
40 PersistentHistogramAllocator::ReleaseGlobalAllocatorForTesting(); | 39 GlobalHistogramAllocator::ReleaseForTesting(); |
41 } | 40 } |
42 | 41 |
43 std::unique_ptr<char[]> allocator_memory_; | 42 std::unique_ptr<char[]> allocator_memory_; |
44 PersistentMemoryAllocator* allocator_ = nullptr; | 43 PersistentMemoryAllocator* allocator_ = nullptr; |
45 | 44 |
46 private: | 45 private: |
47 DISALLOW_COPY_AND_ASSIGN(PersistentHistogramAllocatorTest); | 46 DISALLOW_COPY_AND_ASSIGN(PersistentHistogramAllocatorTest); |
48 }; | 47 }; |
49 | 48 |
50 TEST_F(PersistentHistogramAllocatorTest, CreateAndIterateTest) { | 49 TEST_F(PersistentHistogramAllocatorTest, CreateAndIterateTest) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 | 117 |
119 recovered = recovery.GetNextHistogram(&histogram_iter); | 118 recovered = recovery.GetNextHistogram(&histogram_iter); |
120 ASSERT_TRUE(recovered); | 119 ASSERT_TRUE(recovered); |
121 recovered->CheckName("TestCustomHistogram"); | 120 recovered->CheckName("TestCustomHistogram"); |
122 | 121 |
123 recovered = recovery.GetNextHistogram(&histogram_iter); | 122 recovered = recovery.GetNextHistogram(&histogram_iter); |
124 EXPECT_FALSE(recovered); | 123 EXPECT_FALSE(recovered); |
125 } | 124 } |
126 | 125 |
127 } // namespace base | 126 } // namespace base |
OLD | NEW |