OSDN Git Service

simpleperf: support building cts test.
[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 #include "get_test_data.h"
21 #include "test_util.h"
22
23
24 TEST(read_apk, IsValidApkPath) {
25   ASSERT_FALSE(IsValidApkPath("/dev/zero"));
26   ASSERT_FALSE(IsValidApkPath(GetTestData(ELF_FILE)));
27   ASSERT_TRUE(IsValidApkPath(GetTestData(APK_FILE)));
28 }
29
30 TEST(read_apk, FindElfInApkByOffset) {
31   ApkInspector inspector;
32   ASSERT_TRUE(inspector.FindElfInApkByOffset("/dev/null", 0) == nullptr);
33   ASSERT_TRUE(inspector.FindElfInApkByOffset(GetTestData(APK_FILE), 0) == nullptr);
34   EmbeddedElf* ee = inspector.FindElfInApkByOffset(GetTestData(APK_FILE), 0x9000);
35   ASSERT_TRUE(ee != nullptr);
36   ASSERT_EQ(ee->entry_name(), NATIVELIB_IN_APK);
37   ASSERT_EQ(NATIVELIB_OFFSET_IN_APK, ee->entry_offset());
38   ASSERT_EQ(NATIVELIB_SIZE_IN_APK, ee->entry_size());
39 }
40
41 TEST(read_apk, FindElfInApkByName) {
42   ASSERT_TRUE(ApkInspector::FindElfInApkByName("/dev/null", "") == nullptr);
43   ASSERT_TRUE(ApkInspector::FindElfInApkByName(GetTestData(APK_FILE), "") == nullptr);
44   auto ee = ApkInspector::FindElfInApkByName(GetTestData(APK_FILE), NATIVELIB_IN_APK);
45   ASSERT_TRUE(ee != nullptr);
46   ASSERT_EQ(NATIVELIB_OFFSET_IN_APK, ee->entry_offset());
47   ASSERT_EQ(NATIVELIB_SIZE_IN_APK, ee->entry_size());
48 }
49
50 TEST(read_apk, GetBuildIdFromApkFile) {
51   BuildId build_id;
52   ASSERT_TRUE(GetBuildIdFromApkFile(GetTestData(APK_FILE), NATIVELIB_IN_APK, &build_id));
53   ASSERT_EQ(build_id, native_lib_build_id);
54 }
55
56 TEST(read_apk, ParseSymbolsFromApkFile) {
57   std::map<std::string, ElfFileSymbol> symbols;
58   ASSERT_TRUE(ParseSymbolsFromApkFile(GetTestData(APK_FILE), NATIVELIB_IN_APK, native_lib_build_id,
59                                       std::bind(ParseSymbol, std::placeholders::_1, &symbols)));
60   CheckElfFileSymbols(symbols);
61 }