Update V8 to version 4.5.86.
[chromium-blink-merge.git] / base / android / library_loader / library_prefetcher_unittest.cc
blob7b7296f5f61d96baec74917cba7a89e97c4e3f89
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.
5 #include "base/android/library_loader/library_prefetcher.h"
7 #include <string>
8 #include <vector>
9 #include "base/debug/proc_maps_linux.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace base {
13 namespace android {
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
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]));
36 TEST(NativeLibraryPrefetcherTest, TestIsGoodToPrefetchUnreadableRange) {
37 const base::debug::MappedMemoryRegion region = {
38 0x4000, 0x5000, 10, kExecutePrivate, "base.apk"};
39 ASSERT_FALSE(NativeLibraryPrefetcher::IsGoodToPrefetch(region));
42 TEST(NativeLibraryPrefetcherTest, TestIsGoodToPrefetchSkipSharedRange) {
43 const base::debug::MappedMemoryRegion region = {
44 0x4000, 0x5000, 10, kRead, "base.apk"};
45 ASSERT_FALSE(NativeLibraryPrefetcher::IsGoodToPrefetch(region));
48 TEST(NativeLibraryPrefetcherTest, TestIsGoodToPrefetchLibchromeRange) {
49 const base::debug::MappedMemoryRegion region = {
50 0x4000, 0x5000, 10, kReadPrivate, "libchrome.so"};
51 ASSERT_TRUE(NativeLibraryPrefetcher::IsGoodToPrefetch(region));
54 TEST(NativeLibraryPrefetcherTest, TestIsGoodToPrefetchBaseApkRange) {
55 const base::debug::MappedMemoryRegion region = {
56 0x4000, 0x5000, 10, kReadPrivate, "base.apk"};
57 ASSERT_TRUE(NativeLibraryPrefetcher::IsGoodToPrefetch(region));
60 TEST(NativeLibraryPrefetcherTest,
61 TestFilterLibchromeRangesOnlyIfPossibleNoLibchrome) {
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<NativeLibraryPrefetcher::AddressRange> ranges;
68 NativeLibraryPrefetcher::FilterLibchromeRangesOnlyIfPossible(regions,
69 &ranges);
70 EXPECT_EQ(ranges.size(), 2U);
71 EXPECT_EQ(ranges[0].first, 0x1U);
72 EXPECT_EQ(ranges[0].second, 0x2U);
73 EXPECT_EQ(ranges[1].first, 0x3U);
74 EXPECT_EQ(ranges[1].second, 0x4U);
77 TEST(NativeLibraryPrefetcherTest,
78 TestFilterLibchromeRangesOnlyIfPossibleHasLibchrome) {
79 std::vector<base::debug::MappedMemoryRegion> regions;
80 regions.push_back(
81 base::debug::MappedMemoryRegion{0x1, 0x2, 0, kReadPrivate, "base.apk"});
82 regions.push_back(base::debug::MappedMemoryRegion{
83 0x6, 0x7, 0, kReadPrivate, "libchrome.so"});
84 regions.push_back(
85 base::debug::MappedMemoryRegion{0x3, 0x4, 0, kReadPrivate, "base.apk"});
86 std::vector<NativeLibraryPrefetcher::AddressRange> ranges;
87 NativeLibraryPrefetcher::FilterLibchromeRangesOnlyIfPossible(regions,
88 &ranges);
89 EXPECT_EQ(ranges.size(), 1U);
90 EXPECT_EQ(ranges[0].first, 0x6U);
91 EXPECT_EQ(ranges[0].second, 0x7U);
94 } // namespace android
95 } // namespace base