Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(400)

Side by Side Diff: base/android/library_loader/library_prefetcher_unittest.cc

Issue 1001343002: Prefetch the native library from native code by parsing /proc/pid/maps. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Re-use existing /proc/maps parsing code. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/android/library_loader/library_prefetcher.h"
6
7 #include <string>
8 #include <vector>
9 #include "base/debug/proc_maps_linux.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace base {
13 namespace android {
14
15 namespace {
16 const uint8 kRead = base::debug::MappedMemoryRegion::READ;
17 const uint8 kReadPrivate = base::debug::MappedMemoryRegion::READ |
18 base::debug::MappedMemoryRegion::PRIVATE;
19 const uint8 kExecutePrivate = base::debug::MappedMemoryRegion::EXECUTE |
20 base::debug::MappedMemoryRegion::PRIVATE;
21 } // namespace
22
23 TEST(NativeLibraryPrefetcherTest, TestIsGoodToPrefetchNoRange) {
24 const base::debug::MappedMemoryRegion regions[4] = {
25 base::debug::MappedMemoryRegion{0x4000, 0x5000, 10, kReadPrivate, ""},
26 base::debug::MappedMemoryRegion{0x4000, 0x5000, 10, kReadPrivate, "foo"},
27 base::debug::MappedMemoryRegion{
28 0x4000, 0x5000, 10, kReadPrivate, "foobar.apk"},
29 base::debug::MappedMemoryRegion{
30 0x4000, 0x5000, 10, kReadPrivate, "libchromium.so"}};
31 for (int i = 0; i < 4; ++i) {
32 ASSERT_FALSE(NativeLibraryPrefetcher::IsGoodToPrefetch(regions[i]));
33 }
34 }
35
36 TEST(NativeLibraryPrefetcherTest, TestIsGoodToPrefetchUnreadableRange) {
37 const base::debug::MappedMemoryRegion region = {
38 0x4000, 0x5000, 10, kExecutePrivate, "base.apk"};
39 ASSERT_FALSE(NativeLibraryPrefetcher::IsGoodToPrefetch(region));
40 }
41
42 TEST(NativeLibraryPrefetcherTest, TestIsGoodToPrefetchSkipSharedRange) {
43 const base::debug::MappedMemoryRegion region = {
44 0x4000, 0x5000, 10, kRead, "base.apk"};
45 ASSERT_FALSE(NativeLibraryPrefetcher::IsGoodToPrefetch(region));
46 }
47
48 TEST(NativeLibraryPrefetcherTest, TestIsGoodToPrefetchLibchromeRange) {
49 const base::debug::MappedMemoryRegion region = {
50 0x4000, 0x5000, 10, kReadPrivate, "libchrome.so"};
51 ASSERT_TRUE(NativeLibraryPrefetcher::IsGoodToPrefetch(region));
52 }
53
54 TEST(NativeLibraryPrefetcherTest, TestIsGoodToPrefetchBaseApkRange) {
55 const base::debug::MappedMemoryRegion region = {
56 0x4000, 0x5000, 10, kReadPrivate, "base.apk"};
57 ASSERT_TRUE(NativeLibraryPrefetcher::IsGoodToPrefetch(region));
58 }
59
60 TEST(NativeLibraryPrefetcherTest,
61 TestTakeOnlyLibchromeRangesIfPossibleNoLibchrome) {
62 std::vector<base::debug::MappedMemoryRegion> regions;
63 regions.push_back(
64 base::debug::MappedMemoryRegion{0x1, 0x2, 0, kReadPrivate, "base.apk"});
65 regions.push_back(
66 base::debug::MappedMemoryRegion{0x3, 0x4, 0, kReadPrivate, "base.apk"});
67 std::vector<std::pair<uintptr_t, uintptr_t>> ranges;
68 NativeLibraryPrefetcher::TakeOnlyLibchromeRangesIfPossible(regions, &ranges);
69 EXPECT_EQ(ranges.size(), 2U);
70 EXPECT_EQ(ranges[0].first, 0x1U);
71 EXPECT_EQ(ranges[0].second, 0x2U);
72 EXPECT_EQ(ranges[1].first, 0x3U);
73 EXPECT_EQ(ranges[1].second, 0x4U);
74 }
75
76 TEST(NativeLibraryPrefetcherTest,
77 TestTakeOnlyLibchromeRangesIfPossibleHasLibchrome) {
78 std::vector<base::debug::MappedMemoryRegion> regions;
79 regions.push_back(
80 base::debug::MappedMemoryRegion{0x1, 0x2, 0, kReadPrivate, "base.apk"});
81 regions.push_back(base::debug::MappedMemoryRegion{
82 0x6, 0x7, 0, kReadPrivate, "libchrome.so"});
83 regions.push_back(
84 base::debug::MappedMemoryRegion{0x3, 0x4, 0, kReadPrivate, "base.apk"});
85 std::vector<std::pair<uintptr_t, uintptr_t>> ranges;
86 NativeLibraryPrefetcher::TakeOnlyLibchromeRangesIfPossible(regions, &ranges);
87 EXPECT_EQ(ranges.size(), 1U);
88 EXPECT_EQ(ranges[0].first, 0x6U);
89 EXPECT_EQ(ranges[0].second, 0x7U);
90 }
91
92 } // namespace android
93 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698