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

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: Address comments. Created 5 years, 9 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 class NativeLibraryPrefetcherTest : public NativeLibraryPrefetcher {
14 FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest, TestParseLine32Bits);
pasko 2015/03/27 13:29:28 FRIEND_TEST_ALL_PREFIXES is typically used in the
Benoit L 2015/03/27 15:44:52 Done.
15 FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest, TestParseLine64Bits);
16 FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest, TestParseLineNoFile);
17 FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest,
18 TestMappingMatchesNoRange);
19 FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest,
20 TestMappingMatchesUnreadableRange);
21 FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest,
22 TestMappingMatchesSkipSharedRange);
23 FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest,
24 TestMappingMatchesLibchromeRange);
25 FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest,
26 TestMappingMatchesBaseApkRange);
27 };
28
29 TEST(NativeLibraryPrefetcherTest, TestParseLine32Bits) {
30 const std::string line(
31 "b6e62000-b6e64000 r-xp 00000000 b3:15 1204 /lib/libstdc++.so\n");
32 NativeLibraryPrefetcher::Mapping mapping;
33 ASSERT_TRUE(NativeLibraryPrefetcher::ParseMapping(line, &mapping));
34 EXPECT_EQ(mapping.start, 0xb6e62000ULL);
pasko 2015/03/27 13:29:28 it seems UINT64_C(0xb6e62000) would work and it is
Benoit L 2015/03/27 15:44:52 Done.
35 EXPECT_EQ(mapping.end, 0xb6e64000ULL);
36 EXPECT_EQ(mapping.flags, "r-xp");
37 EXPECT_EQ(mapping.offset, 0ULL);
38 EXPECT_EQ(mapping.device, "b3:15");
39 EXPECT_EQ(mapping.inode, 1204LL);
40 EXPECT_EQ(mapping.filename, "/lib/libstdc++.so");
41 }
42
43 TEST(NativeLibraryPrefetcherTest, TestParseLine64Bits) {
44 const std::string line(
45 "800000b6e62000-800000b6e64000 r-xp 00000000 b3:15 1204 libstdc++.so\n");
46 NativeLibraryPrefetcher::Mapping mapping;
47 ASSERT_TRUE(NativeLibraryPrefetcher::ParseMapping(line, &mapping));
48 EXPECT_EQ(mapping.start, 0x800000b6e62000ULL);
49 EXPECT_EQ(mapping.end, 0x800000b6e64000ULL);
50 EXPECT_EQ(mapping.flags, "r-xp");
51 EXPECT_EQ(mapping.offset, 0ULL);
52 EXPECT_EQ(mapping.device, "b3:15");
53 EXPECT_EQ(mapping.inode, 1204LL);
54 EXPECT_EQ(mapping.filename, "libstdc++.so");
55 }
56
57 TEST(NativeLibraryPrefetcherTest, TestParseLineNoFile) {
58 const std::string line("b6e62000-b6e64000 r-xp 00000000 b3:15 1204 \n");
59 NativeLibraryPrefetcher::Mapping mapping;
60 ASSERT_TRUE(NativeLibraryPrefetcher::ParseMapping(line, &mapping));
61 EXPECT_EQ(mapping.start, 0xb6e62000ULL);
62 EXPECT_EQ(mapping.end, 0xb6e64000ULL);
63 EXPECT_EQ(mapping.flags, "r-xp");
64 EXPECT_EQ(mapping.offset, 0ULL);
65 EXPECT_EQ(mapping.device, "b3:15");
66 EXPECT_EQ(mapping.inode, 1204LL);
67 EXPECT_EQ(mapping.filename, "");
68 }
69
70 TEST(NativeLibraryPrefetcherTest, TestMappingMatchesNoRange) {
71 const std::string lines[4] = {
72 "800000b6e62000-800000b6e64000 r-xp 00000000 b3:15 1204 \n",
73 "800000b6e62000-800000b6e64000 r-xp 00000000 b3:15 1204 foo\n",
74 "800000b6e62000-800000b6e64000 r-xp 00000000 b3:15 1204 foobar.apk\n",
75 "800000b6e62000-800000b6e64000 r-xp 00000000 b3:15 1204 "
76 "libchromium.so\n"};
77 for (int i = 0; i < 4; ++i) {
78 NativeLibraryPrefetcher::Mapping mapping;
79 ASSERT_TRUE(NativeLibraryPrefetcher::ParseMapping(lines[i], &mapping));
80 ASSERT_FALSE(NativeLibraryPrefetcher::MappingMatches(mapping));
81 }
82 }
83
84 TEST(NativeLibraryPrefetcherTest, TestMappingMatchesUnreadableRange) {
85 const std::string line(
86 "800000b6e62000-800000b6e64000 --xp 00000000 b3:15 1204 base.apk\n");
87 NativeLibraryPrefetcher::Mapping mapping;
88 ASSERT_TRUE(NativeLibraryPrefetcher::ParseMapping(line, &mapping));
89 ASSERT_FALSE(NativeLibraryPrefetcher::MappingMatches(mapping));
90 }
91
92 TEST(NativeLibraryPrefetcherTest, TestMappingMatchesSkipSharedRange) {
93 const std::string line(
94 "800000b6e62000-800000b6e64000 r-xs 00000000 b3:15 1204 base.apk\n");
95 NativeLibraryPrefetcher::Mapping mapping;
96 ASSERT_TRUE(NativeLibraryPrefetcher::ParseMapping(line, &mapping));
97 ASSERT_FALSE(NativeLibraryPrefetcher::MappingMatches(mapping));
98 }
99
100 TEST(NativeLibraryPrefetcherTest, TestMappingMatchesLibchromeRange) {
101 const std::string line("42-43 r-xp 00000000 b3:15 42 libchrome.so\n");
102 NativeLibraryPrefetcher::Mapping mapping;
103 ASSERT_TRUE(NativeLibraryPrefetcher::ParseMapping(line, &mapping));
104 ASSERT_TRUE(NativeLibraryPrefetcher::MappingMatches(mapping));
105 }
106
107 TEST(NativeLibraryPrefetcherTest, TestMappingMatchesBaseApkRange) {
108 const std::string line("42-43 rw-p 00000000 b3:15 1204 base.apk");
pasko 2015/03/27 13:29:28 should this also end with '\n'?
Benoit L 2015/03/27 15:44:52 Done.
pasko 2015/03/27 17:51:54 really done?
109 NativeLibraryPrefetcher::Mapping mapping;
110 ASSERT_TRUE(NativeLibraryPrefetcher::ParseMapping(line, &mapping));
111 ASSERT_TRUE(NativeLibraryPrefetcher::MappingMatches(mapping));
112 }
113
114 } // namespace android
115 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698