OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/android/library_loader/library_prefetcher.h" | 5 #include "base/android/library_loader/library_prefetcher.h" |
6 | 6 |
7 #include <sys/mman.h> | 7 #include <sys/mman.h> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 #include "base/debug/proc_maps_linux.h" | 10 #include "base/debug/proc_maps_linux.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 regions.push_back( | 87 regions.push_back( |
88 base::debug::MappedMemoryRegion{0x3, 0x4, 0, kReadPrivate, "base.apk"}); | 88 base::debug::MappedMemoryRegion{0x3, 0x4, 0, kReadPrivate, "base.apk"}); |
89 std::vector<NativeLibraryPrefetcher::AddressRange> ranges; | 89 std::vector<NativeLibraryPrefetcher::AddressRange> ranges; |
90 NativeLibraryPrefetcher::FilterLibchromeRangesOnlyIfPossible(regions, | 90 NativeLibraryPrefetcher::FilterLibchromeRangesOnlyIfPossible(regions, |
91 &ranges); | 91 &ranges); |
92 EXPECT_EQ(ranges.size(), 1U); | 92 EXPECT_EQ(ranges.size(), 1U); |
93 EXPECT_EQ(ranges[0].first, 0x6U); | 93 EXPECT_EQ(ranges[0].first, 0x6U); |
94 EXPECT_EQ(ranges[0].second, 0x7U); | 94 EXPECT_EQ(ranges[0].second, 0x7U); |
95 } | 95 } |
96 | 96 |
97 TEST(NativeLibraryPrefetcherTest, TestPercentageOfResidentCode) { | 97 TEST(NativeLibraryPrefetcherTest, DISABLED_TestPercentageOfResidentCode) { |
98 size_t length = 4 * kPageSize; | 98 size_t length = 4 * kPageSize; |
99 base::SharedMemory shared_mem; | 99 base::SharedMemory shared_mem; |
100 ASSERT_TRUE(shared_mem.CreateAndMapAnonymous(length)); | 100 ASSERT_TRUE(shared_mem.CreateAndMapAnonymous(length)); |
101 void* address = shared_mem.memory(); | 101 void* address = shared_mem.memory(); |
102 | 102 |
103 std::vector<NativeLibraryPrefetcher::AddressRange> ranges = { | 103 std::vector<NativeLibraryPrefetcher::AddressRange> ranges = { |
104 {reinterpret_cast<uintptr_t>(address), | 104 {reinterpret_cast<uintptr_t>(address), |
105 reinterpret_cast<uintptr_t>(address) + length}}; | 105 reinterpret_cast<uintptr_t>(address) + length}}; |
106 | 106 |
107 // Remove everything. | 107 // Remove everything. |
108 ASSERT_EQ(0, madvise(address, length, MADV_DONTNEED)); | 108 ASSERT_EQ(0, madvise(address, length, MADV_DONTNEED)); |
109 // TODO(lizeb): If flaky, mock mincore(). | 109 // TODO(lizeb): If flaky, mock mincore(). |
110 EXPECT_EQ(0, NativeLibraryPrefetcher::PercentageOfResidentCode(ranges)); | 110 EXPECT_EQ(0, NativeLibraryPrefetcher::PercentageOfResidentCode(ranges)); |
111 | 111 |
112 // Get everything back. | 112 // Get everything back. |
113 ASSERT_EQ(0, mlock(address, length)); | 113 ASSERT_EQ(0, mlock(address, length)); |
114 EXPECT_EQ(100, NativeLibraryPrefetcher::PercentageOfResidentCode(ranges)); | 114 EXPECT_EQ(100, NativeLibraryPrefetcher::PercentageOfResidentCode(ranges)); |
115 munlock(address, length); | 115 munlock(address, length); |
116 } | 116 } |
117 | 117 |
118 TEST(NativeLibraryPrefetcherTest, TestPercentageOfResidentCodeTwoRegions) { | 118 TEST(NativeLibraryPrefetcherTest, |
| 119 DISABLED_TestPercentageOfResidentCodeTwoRegions) { |
119 size_t length = 4 * kPageSize; | 120 size_t length = 4 * kPageSize; |
120 base::SharedMemory shared_mem; | 121 base::SharedMemory shared_mem; |
121 ASSERT_TRUE(shared_mem.CreateAndMapAnonymous(length)); | 122 ASSERT_TRUE(shared_mem.CreateAndMapAnonymous(length)); |
122 void* address = shared_mem.memory(); | 123 void* address = shared_mem.memory(); |
123 | 124 |
124 size_t length2 = 8 * kPageSize; | 125 size_t length2 = 8 * kPageSize; |
125 base::SharedMemory shared_mem2; | 126 base::SharedMemory shared_mem2; |
126 ASSERT_TRUE(shared_mem2.CreateAndMapAnonymous(length2)); | 127 ASSERT_TRUE(shared_mem2.CreateAndMapAnonymous(length2)); |
127 void* address2 = shared_mem2.memory(); | 128 void* address2 = shared_mem2.memory(); |
128 | 129 |
(...skipping 14 matching lines...) Expand all Loading... |
143 EXPECT_EQ(33, NativeLibraryPrefetcher::PercentageOfResidentCode(ranges)); | 144 EXPECT_EQ(33, NativeLibraryPrefetcher::PercentageOfResidentCode(ranges)); |
144 // The second one. | 145 // The second one. |
145 ASSERT_EQ(0, mlock(address2, length2)); | 146 ASSERT_EQ(0, mlock(address2, length2)); |
146 EXPECT_EQ(100, NativeLibraryPrefetcher::PercentageOfResidentCode(ranges)); | 147 EXPECT_EQ(100, NativeLibraryPrefetcher::PercentageOfResidentCode(ranges)); |
147 munlock(address, length); | 148 munlock(address, length); |
148 munlock(address2, length); | 149 munlock(address2, length); |
149 } | 150 } |
150 | 151 |
151 } // namespace android | 152 } // namespace android |
152 } // namespace base | 153 } // namespace base |
OLD | NEW |