OSDN Git Service

Merge "Support profiling of shared libs embedded in APKs."
[android-x86/system-extras.git] / simpleperf / read_apk_test.cpp
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "read_apk.h"
18
19 #include <gtest/gtest.h>
20
21 static const std::string fibjar = "fibonacci.jar";
22 static const std::string jniapk = "has_embedded_native_libs.apk";
23
24 TEST(read_apk, IsValidJarOrApkPath) {
25   ASSERT_FALSE(IsValidJarOrApkPath("/dev/zero"));
26   ASSERT_FALSE(IsValidJarOrApkPath("/proc/self/exe"));
27   ASSERT_TRUE(IsValidJarOrApkPath(fibjar));
28 }
29
30 TEST(read_apk, CollectEmbeddedElfInfoFromApk) {
31   ApkInspector inspector;
32   ASSERT_TRUE(inspector.FindElfInApkByMmapOffset("/dev/null", 0) == nullptr);
33   ASSERT_TRUE(inspector.FindElfInApkByMmapOffset(fibjar, 0) == nullptr);
34   ASSERT_TRUE(inspector.FindElfInApkByMmapOffset(jniapk, 0) == nullptr);
35   EmbeddedElf *ee1 = inspector.FindElfInApkByMmapOffset(jniapk, 0x91000);
36   ASSERT_TRUE(ee1 != nullptr);
37   ASSERT_EQ(ee1->entry_name(), "lib/armeabi-v7a/libframeworks_coretests_jni.so");
38   ASSERT_TRUE(ee1->entry_offset() == 593920);
39   ASSERT_TRUE(ee1->entry_size() == 13904);
40 }