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

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: . 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 "testing/gtest/include/gtest/gtest.h"
9
10 namespace base {
11 namespace android {
12
13 TEST(NativeLibraryPrefetcherTest, TestParseLine32Bits) {
14 const std::string line(
15 "b6e62000-b6e64000 r-xp 00000000 b3:15 1204 /lib/libstdc++.so\n");
16 NativeLibraryPrefetcher::Mapping mapping;
17 ASSERT_TRUE(NativeLibraryPrefetcher::ParseMapping(line, &mapping));
18 EXPECT_EQ(mapping.start, UINT64_C(0xb6e62000));
19 EXPECT_EQ(mapping.end, UINT64_C(0xb6e64000));
20 EXPECT_EQ(mapping.flags, "r-xp");
21 EXPECT_EQ(mapping.filename, "/lib/libstdc++.so");
22 }
23
24 TEST(NativeLibraryPrefetcherTest, TestParseLine64Bits) {
25 const std::string line(
26 "800000b6e62000-800000b6e64000 r-xp 00000000 b3:15 1204 libstdc++.so\n");
27 NativeLibraryPrefetcher::Mapping mapping;
28 ASSERT_TRUE(NativeLibraryPrefetcher::ParseMapping(line, &mapping));
29 EXPECT_EQ(mapping.start, UINT64_C(0x800000b6e62000));
30 EXPECT_EQ(mapping.end, UINT64_C(0x800000b6e64000));
31 EXPECT_EQ(mapping.flags, "r-xp");
32 EXPECT_EQ(mapping.filename, "libstdc++.so");
33 }
34
35 TEST(NativeLibraryPrefetcherTest, TestParseLineNoFile) {
36 const std::string line("b6e62000-b6e64000 r-xp 00000000 b3:15 1204 \n");
37 NativeLibraryPrefetcher::Mapping mapping;
38 ASSERT_TRUE(NativeLibraryPrefetcher::ParseMapping(line, &mapping));
39 EXPECT_EQ(mapping.start, UINT64_C(0xb6e62000));
40 EXPECT_EQ(mapping.end, UINT64_C(0xb6e64000));
41 EXPECT_EQ(mapping.flags, "r-xp");
42 EXPECT_EQ(mapping.filename, "");
43 }
44
45 TEST(NativeLibraryPrefetcherTest, TestIsGoodToPrefetchNoRange) {
46 const std::string lines[4] = {
47 "800000b6e62000-800000b6e64000 r-xp 00000000 b3:15 1204 \n",
48 "800000b6e62000-800000b6e64000 r-xp 00000000 b3:15 1204 foo\n",
49 "800000b6e62000-800000b6e64000 r-xp 00000000 b3:15 1204 foobar.apk\n",
50 "800000b6e62000-800000b6e64000 r-xp 00000000 b3:15 1204 \n"
51 "libchromium.so\n"};
52 for (int i = 0; i < 4; ++i) {
53 NativeLibraryPrefetcher::Mapping mapping;
54 ASSERT_TRUE(NativeLibraryPrefetcher::ParseMapping(lines[i], &mapping));
55 ASSERT_FALSE(NativeLibraryPrefetcher::IsGoodToPrefetch(mapping));
56 }
57 }
58
59 TEST(NativeLibraryPrefetcherTest, TestIsGoodToPrefetchUnreadableRange) {
60 const std::string line(
61 "800000b6e62000-800000b6e64000 --xp 00000000 b3:15 1204 base.apk\n");
62 NativeLibraryPrefetcher::Mapping mapping;
63 ASSERT_TRUE(NativeLibraryPrefetcher::ParseMapping(line, &mapping));
64 ASSERT_FALSE(NativeLibraryPrefetcher::IsGoodToPrefetch(mapping));
65 }
66
67 TEST(NativeLibraryPrefetcherTest, TestIsGoodToPrefetchSkipSharedRange) {
68 const std::string line(
69 "800000b6e62000-800000b6e64000 r-xs 00000000 b3:15 1204 base.apk\n");
70 NativeLibraryPrefetcher::Mapping mapping;
71 ASSERT_TRUE(NativeLibraryPrefetcher::ParseMapping(line, &mapping));
72 ASSERT_FALSE(NativeLibraryPrefetcher::IsGoodToPrefetch(mapping));
73 }
74
75 TEST(NativeLibraryPrefetcherTest, TestIsGoodToPrefetchLibchromeRange) {
76 const std::string line("42-43 r-xp 00000000 b3:15 42 libchrome.so\n");
77 NativeLibraryPrefetcher::Mapping mapping;
78 ASSERT_TRUE(NativeLibraryPrefetcher::ParseMapping(line, &mapping));
79 ASSERT_TRUE(NativeLibraryPrefetcher::IsGoodToPrefetch(mapping));
80 }
81
82 TEST(NativeLibraryPrefetcherTest, TestIsGoodToPrefetchBaseApkRange) {
83 const std::string line("42-43 rw-p 00000000 b3:15 1204 base.apk\n");
84 NativeLibraryPrefetcher::Mapping mapping;
85 ASSERT_TRUE(NativeLibraryPrefetcher::ParseMapping(line, &mapping));
86 ASSERT_TRUE(NativeLibraryPrefetcher::IsGoodToPrefetch(mapping));
87 }
88
89 } // namespace android
90 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698