| 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..48c2a86d04da3f6de905d5544ab3fefb42648768
|
| --- /dev/null
|
| +++ b/base/android/library_loader/library_prefetcher_unittest.cc
|
| @@ -0,0 +1,90 @@
|
| +// 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 {
|
| +
|
| +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, UINT64_C(0xb6e62000));
|
| + EXPECT_EQ(mapping.end, UINT64_C(0xb6e64000));
|
| + EXPECT_EQ(mapping.flags, "r-xp");
|
| + 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, UINT64_C(0x800000b6e62000));
|
| + EXPECT_EQ(mapping.end, UINT64_C(0x800000b6e64000));
|
| + EXPECT_EQ(mapping.flags, "r-xp");
|
| + 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, UINT64_C(0xb6e62000));
|
| + EXPECT_EQ(mapping.end, UINT64_C(0xb6e64000));
|
| + EXPECT_EQ(mapping.flags, "r-xp");
|
| + EXPECT_EQ(mapping.filename, "");
|
| +}
|
| +
|
| +TEST(NativeLibraryPrefetcherTest, TestIsGoodToPrefetchNoRange) {
|
| + 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 \n"
|
| + "libchromium.so\n"};
|
| + for (int i = 0; i < 4; ++i) {
|
| + NativeLibraryPrefetcher::Mapping mapping;
|
| + ASSERT_TRUE(NativeLibraryPrefetcher::ParseMapping(lines[i], &mapping));
|
| + ASSERT_FALSE(NativeLibraryPrefetcher::IsGoodToPrefetch(mapping));
|
| + }
|
| +}
|
| +
|
| +TEST(NativeLibraryPrefetcherTest, TestIsGoodToPrefetchUnreadableRange) {
|
| + 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::IsGoodToPrefetch(mapping));
|
| +}
|
| +
|
| +TEST(NativeLibraryPrefetcherTest, TestIsGoodToPrefetchSkipSharedRange) {
|
| + 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::IsGoodToPrefetch(mapping));
|
| +}
|
| +
|
| +TEST(NativeLibraryPrefetcherTest, TestIsGoodToPrefetchLibchromeRange) {
|
| + 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::IsGoodToPrefetch(mapping));
|
| +}
|
| +
|
| +TEST(NativeLibraryPrefetcherTest, TestIsGoodToPrefetchBaseApkRange) {
|
| + const std::string line("42-43 rw-p 00000000 b3:15 1204 base.apk\n");
|
| + NativeLibraryPrefetcher::Mapping mapping;
|
| + ASSERT_TRUE(NativeLibraryPrefetcher::ParseMapping(line, &mapping));
|
| + ASSERT_TRUE(NativeLibraryPrefetcher::IsGoodToPrefetch(mapping));
|
| +}
|
| +
|
| +} // namespace android
|
| +} // namespace base
|
|
|