1 /*
2  * Copyright (C) 2015 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 <android-base/file.h>
18 
19 #include "oatdump_test.h"
20 
21 namespace art {
22 
23 // Disable tests on arm and arm64 as they are taking too long to run. b/27824283.
24 #define TEST_DISABLED_FOR_ARM_AND_ARM64() \
25     TEST_DISABLED_FOR_ARM(); \
26     TEST_DISABLED_FOR_ARM64(); \
27 
TEST_F(OatDumpTest,TestNoDumpVmap)28 TEST_F(OatDumpTest, TestNoDumpVmap) {
29   TEST_DISABLED_FOR_ARM_AND_ARM64();
30   std::string error_msg;
31   ASSERT_TRUE(Exec(kDynamic, kModeArt, {"--no-dump:vmap"}, kListAndCode));
32 }
TEST_F(OatDumpTest,TestNoDumpVmapStatic)33 TEST_F(OatDumpTest, TestNoDumpVmapStatic) {
34   TEST_DISABLED_FOR_ARM_AND_ARM64();
35   TEST_DISABLED_FOR_NON_STATIC_HOST_BUILDS();
36   std::string error_msg;
37   ASSERT_TRUE(Exec(kStatic, kModeArt, {"--no-dump:vmap"}, kListAndCode));
38 }
39 
TEST_F(OatDumpTest,TestNoDisassemble)40 TEST_F(OatDumpTest, TestNoDisassemble) {
41   TEST_DISABLED_FOR_ARM_AND_ARM64();
42   std::string error_msg;
43   ASSERT_TRUE(Exec(kDynamic, kModeArt, {"--no-disassemble"}, kListAndCode));
44 }
TEST_F(OatDumpTest,TestNoDisassembleStatic)45 TEST_F(OatDumpTest, TestNoDisassembleStatic) {
46   TEST_DISABLED_FOR_ARM_AND_ARM64();
47   TEST_DISABLED_FOR_NON_STATIC_HOST_BUILDS();
48   std::string error_msg;
49   ASSERT_TRUE(Exec(kStatic, kModeArt, {"--no-disassemble"}, kListAndCode));
50 }
51 
TEST_F(OatDumpTest,TestListClasses)52 TEST_F(OatDumpTest, TestListClasses) {
53   TEST_DISABLED_FOR_ARM_AND_ARM64();
54   std::string error_msg;
55   ASSERT_TRUE(Exec(kDynamic, kModeArt, {"--list-classes"}, kListOnly));
56 }
TEST_F(OatDumpTest,TestListClassesStatic)57 TEST_F(OatDumpTest, TestListClassesStatic) {
58   TEST_DISABLED_FOR_ARM_AND_ARM64();
59   TEST_DISABLED_FOR_NON_STATIC_HOST_BUILDS();
60   std::string error_msg;
61   ASSERT_TRUE(Exec(kStatic, kModeArt, {"--list-classes"}, kListOnly));
62 }
63 
TEST_F(OatDumpTest,TestListMethods)64 TEST_F(OatDumpTest, TestListMethods) {
65   TEST_DISABLED_FOR_ARM_AND_ARM64();
66   std::string error_msg;
67   ASSERT_TRUE(Exec(kDynamic, kModeArt, {"--list-methods"}, kListOnly));
68 }
TEST_F(OatDumpTest,TestListMethodsStatic)69 TEST_F(OatDumpTest, TestListMethodsStatic) {
70   TEST_DISABLED_FOR_ARM_AND_ARM64();
71   TEST_DISABLED_FOR_NON_STATIC_HOST_BUILDS();
72   std::string error_msg;
73   ASSERT_TRUE(Exec(kStatic, kModeArt, {"--list-methods"}, kListOnly));
74 }
75 
TEST_F(OatDumpTest,TestSymbolize)76 TEST_F(OatDumpTest, TestSymbolize) {
77   TEST_DISABLED_FOR_TARGET();  // Can not write files inside the apex directory.
78   std::string error_msg;
79   ASSERT_TRUE(Exec(kDynamic, kModeSymbolize, {}, kListOnly));
80 }
TEST_F(OatDumpTest,TestSymbolizeStatic)81 TEST_F(OatDumpTest, TestSymbolizeStatic) {
82   TEST_DISABLED_FOR_ARM_AND_ARM64();
83   TEST_DISABLED_FOR_NON_STATIC_HOST_BUILDS();
84   std::string error_msg;
85   ASSERT_TRUE(Exec(kStatic, kModeSymbolize, {}, kListOnly));
86 }
87 
TEST_F(OatDumpTest,TestExportDex)88 TEST_F(OatDumpTest, TestExportDex) {
89   TEST_DISABLED_FOR_ARM_AND_ARM64();
90   // Test is failing on target, b/77469384.
91   TEST_DISABLED_FOR_TARGET();
92   std::string error_msg;
93   ASSERT_TRUE(GenerateAppOdexFile(kDynamic, {"--runtime-arg", "-Xmx64M"}));
94   ASSERT_TRUE(Exec(kDynamic, kModeOat, {"--export-dex-to=" + tmp_dir_}, kListOnly));
95   const std::string dex_location =
96       tmp_dir_+ "/" + android::base::Basename(GetTestDexFileName(GetAppBaseName().c_str())) +
97       "_export.dex";
98   const std::string dexdump = GetExecutableFilePath("dexdump",
99                                                     /*is_debug=*/false,
100                                                     /*is_static=*/false,
101                                                     /*bitness=*/false);
102   std::string output;
103   auto post_fork_fn = []() { return true; };
104   ForkAndExecResult res = ForkAndExec({dexdump, "-d", dex_location}, post_fork_fn, &output);
105   ASSERT_TRUE(res.StandardSuccess());
106 }
TEST_F(OatDumpTest,TestExportDexStatic)107 TEST_F(OatDumpTest, TestExportDexStatic) {
108   TEST_DISABLED_FOR_ARM_AND_ARM64();
109   TEST_DISABLED_FOR_NON_STATIC_HOST_BUILDS();
110   std::string error_msg;
111   ASSERT_TRUE(GenerateAppOdexFile(kStatic, {"--runtime-arg", "-Xmx64M"}));
112   ASSERT_TRUE(Exec(kStatic, kModeOat, {"--export-dex-to=" + tmp_dir_}, kListOnly));
113 }
114 
115 }  // namespace art
116