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