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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: base/android/library_loader/library_prefetcher_unittest.cc
diff --git a/base/android/library_loader/library_prefetcher_unittest.cc b/base/android/library_loader/library_prefetcher_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e2643f39c154a3ec2d9ecc93c1878e95bdd51315
--- /dev/null
+++ b/base/android/library_loader/library_prefetcher_unittest.cc
@@ -0,0 +1,115 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/android/library_loader/library_prefetcher.h"
+
+#include <string>
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace base {
+namespace android {
+
+class NativeLibraryPrefetcherTest : public NativeLibraryPrefetcher {
+ 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.
+ FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest, TestParseLine64Bits);
+ FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest, TestParseLineNoFile);
+ FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest,
+ TestMappingMatchesNoRange);
+ FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest,
+ TestMappingMatchesUnreadableRange);
+ FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest,
+ TestMappingMatchesSkipSharedRange);
+ FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest,
+ TestMappingMatchesLibchromeRange);
+ FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest,
+ TestMappingMatchesBaseApkRange);
+};
+
+TEST(NativeLibraryPrefetcherTest, TestParseLine32Bits) {
+ const std::string line(
+ "b6e62000-b6e64000 r-xp 00000000 b3:15 1204 /lib/libstdc++.so\n");
+ NativeLibraryPrefetcher::Mapping mapping;
+ ASSERT_TRUE(NativeLibraryPrefetcher::ParseMapping(line, &mapping));
+ 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.
+ EXPECT_EQ(mapping.end, 0xb6e64000ULL);
+ EXPECT_EQ(mapping.flags, "r-xp");
+ EXPECT_EQ(mapping.offset, 0ULL);
+ EXPECT_EQ(mapping.device, "b3:15");
+ EXPECT_EQ(mapping.inode, 1204LL);
+ EXPECT_EQ(mapping.filename, "/lib/libstdc++.so");
+}
+
+TEST(NativeLibraryPrefetcherTest, TestParseLine64Bits) {
+ const std::string line(
+ "800000b6e62000-800000b6e64000 r-xp 00000000 b3:15 1204 libstdc++.so\n");
+ NativeLibraryPrefetcher::Mapping mapping;
+ ASSERT_TRUE(NativeLibraryPrefetcher::ParseMapping(line, &mapping));
+ EXPECT_EQ(mapping.start, 0x800000b6e62000ULL);
+ EXPECT_EQ(mapping.end, 0x800000b6e64000ULL);
+ EXPECT_EQ(mapping.flags, "r-xp");
+ EXPECT_EQ(mapping.offset, 0ULL);
+ EXPECT_EQ(mapping.device, "b3:15");
+ EXPECT_EQ(mapping.inode, 1204LL);
+ EXPECT_EQ(mapping.filename, "libstdc++.so");
+}
+
+TEST(NativeLibraryPrefetcherTest, TestParseLineNoFile) {
+ const std::string line("b6e62000-b6e64000 r-xp 00000000 b3:15 1204 \n");
+ NativeLibraryPrefetcher::Mapping mapping;
+ ASSERT_TRUE(NativeLibraryPrefetcher::ParseMapping(line, &mapping));
+ EXPECT_EQ(mapping.start, 0xb6e62000ULL);
+ EXPECT_EQ(mapping.end, 0xb6e64000ULL);
+ EXPECT_EQ(mapping.flags, "r-xp");
+ EXPECT_EQ(mapping.offset, 0ULL);
+ EXPECT_EQ(mapping.device, "b3:15");
+ EXPECT_EQ(mapping.inode, 1204LL);
+ EXPECT_EQ(mapping.filename, "");
+}
+
+TEST(NativeLibraryPrefetcherTest, TestMappingMatchesNoRange) {
+ const std::string lines[4] = {
+ "800000b6e62000-800000b6e64000 r-xp 00000000 b3:15 1204 \n",
+ "800000b6e62000-800000b6e64000 r-xp 00000000 b3:15 1204 foo\n",
+ "800000b6e62000-800000b6e64000 r-xp 00000000 b3:15 1204 foobar.apk\n",
+ "800000b6e62000-800000b6e64000 r-xp 00000000 b3:15 1204 "
+ "libchromium.so\n"};
+ for (int i = 0; i < 4; ++i) {
+ NativeLibraryPrefetcher::Mapping mapping;
+ ASSERT_TRUE(NativeLibraryPrefetcher::ParseMapping(lines[i], &mapping));
+ ASSERT_FALSE(NativeLibraryPrefetcher::MappingMatches(mapping));
+ }
+}
+
+TEST(NativeLibraryPrefetcherTest, TestMappingMatchesUnreadableRange) {
+ const std::string line(
+ "800000b6e62000-800000b6e64000 --xp 00000000 b3:15 1204 base.apk\n");
+ NativeLibraryPrefetcher::Mapping mapping;
+ ASSERT_TRUE(NativeLibraryPrefetcher::ParseMapping(line, &mapping));
+ ASSERT_FALSE(NativeLibraryPrefetcher::MappingMatches(mapping));
+}
+
+TEST(NativeLibraryPrefetcherTest, TestMappingMatchesSkipSharedRange) {
+ const std::string line(
+ "800000b6e62000-800000b6e64000 r-xs 00000000 b3:15 1204 base.apk\n");
+ NativeLibraryPrefetcher::Mapping mapping;
+ ASSERT_TRUE(NativeLibraryPrefetcher::ParseMapping(line, &mapping));
+ ASSERT_FALSE(NativeLibraryPrefetcher::MappingMatches(mapping));
+}
+
+TEST(NativeLibraryPrefetcherTest, TestMappingMatchesLibchromeRange) {
+ const std::string line("42-43 r-xp 00000000 b3:15 42 libchrome.so\n");
+ NativeLibraryPrefetcher::Mapping mapping;
+ ASSERT_TRUE(NativeLibraryPrefetcher::ParseMapping(line, &mapping));
+ ASSERT_TRUE(NativeLibraryPrefetcher::MappingMatches(mapping));
+}
+
+TEST(NativeLibraryPrefetcherTest, TestMappingMatchesBaseApkRange) {
+ 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?
+ NativeLibraryPrefetcher::Mapping mapping;
+ ASSERT_TRUE(NativeLibraryPrefetcher::ParseMapping(line, &mapping));
+ ASSERT_TRUE(NativeLibraryPrefetcher::MappingMatches(mapping));
+}
+
+} // namespace android
+} // namespace base

Powered by Google App Engine
This is Rietveld 408576698