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