• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 INSTANTIATE_TEST_SUITE_P(DynamicOrStatic,
24                          OatDumpTest,
25                          testing::Values(Flavor::kDynamic, Flavor::kStatic));
26 
27 // Disable tests on arm and arm64 as they are taking too long to run. b/27824283.
28 #define TEST_DISABLED_FOR_ARM_AND_ARM64() \
29   TEST_DISABLED_FOR_ARM();                \
30   TEST_DISABLED_FOR_ARM64();
31 
TEST_P(OatDumpTest,TestNoDumpVmap)32 TEST_P(OatDumpTest, TestNoDumpVmap) {
33   TEST_DISABLED_FOR_RISCV64();
34   TEST_DISABLED_FOR_ARM_AND_ARM64();
35   // TODO(b/334200225): Temporarily disable this test case for x86 and x86_64
36   // till the disassembler issue is fixed.
37   TEST_DISABLED_FOR_X86();
38   TEST_DISABLED_FOR_X86_64();
39   std::string error_msg;
40   ASSERT_TRUE(Exec(GetParam(),
41                    kArgImage | kArgBcp | kArgIsa,
42                    {"--no-dump:vmap"},
43                    kExpectImage | kExpectOat | kExpectCode));
44 }
45 
TEST_P(OatDumpTest,TestNoDisassemble)46 TEST_P(OatDumpTest, TestNoDisassemble) {
47   TEST_DISABLED_FOR_RISCV64();
48   TEST_DISABLED_FOR_ARM_AND_ARM64();
49   std::string error_msg;
50   ASSERT_TRUE(Exec(GetParam(),
51                    kArgImage | kArgBcp | kArgIsa,
52                    {"--no-disassemble"},
53                    kExpectImage | kExpectOat | kExpectCode));
54 }
55 
TEST_P(OatDumpTest,TestListClasses)56 TEST_P(OatDumpTest, TestListClasses) {
57   TEST_DISABLED_FOR_RISCV64();
58   TEST_DISABLED_FOR_ARM_AND_ARM64();
59   std::string error_msg;
60   ASSERT_TRUE(Exec(
61       GetParam(), kArgImage | kArgBcp | kArgIsa, {"--list-classes"}, kExpectImage | kExpectOat));
62 }
63 
TEST_P(OatDumpTest,TestListMethods)64 TEST_P(OatDumpTest, TestListMethods) {
65   TEST_DISABLED_FOR_RISCV64();
66   TEST_DISABLED_FOR_ARM_AND_ARM64();
67   std::string error_msg;
68   ASSERT_TRUE(Exec(
69       GetParam(), kArgImage | kArgBcp | kArgIsa, {"--list-methods"}, kExpectImage | kExpectOat));
70 }
71 
TEST_P(OatDumpTest,TestSymbolize)72 TEST_P(OatDumpTest, TestSymbolize) {
73   if (GetParam() == Flavor::kDynamic) {
74     TEST_DISABLED_FOR_TARGET();  // Can not write files inside the apex directory.
75   } else {
76     TEST_DISABLED_FOR_RISCV64();
77     TEST_DISABLED_FOR_ARM_AND_ARM64();
78   }
79   std::string error_msg;
80   ASSERT_TRUE(Exec(GetParam(), kArgSymbolize, {}, /*expects=*/0));
81 }
82 
TEST_P(OatDumpTest,TestExportDex)83 TEST_P(OatDumpTest, TestExportDex) {
84   if (GetParam() == Flavor::kStatic) {
85     TEST_DISABLED_FOR_RISCV64();
86     TEST_DISABLED_FOR_ARM_AND_ARM64();
87   }
88   std::string error_msg;
89   ASSERT_TRUE(GenerateAppOdexFile(GetParam()));
90   ASSERT_TRUE(Exec(GetParam(), kArgOatApp, {"--export-dex-to=" + tmp_dir_}, kExpectOat));
91   if (GetParam() == Flavor::kDynamic) {
92     const std::string dex_location =
93         tmp_dir_ + "/" + android::base::Basename(GetTestDexFileName(GetAppBaseName().c_str())) +
94         "_export.dex";
95     const std::string dexdump = GetExecutableFilePath("dexdump",
96                                                       /*is_debug=*/false,
97                                                       /*is_static=*/false,
98                                                       /*bitness=*/false);
99     std::string output;
100     auto post_fork_fn = []() { return true; };
101     ForkAndExecResult res = ForkAndExec({dexdump, "-d", dex_location}, post_fork_fn, &output);
102     ASSERT_TRUE(res.StandardSuccess());
103   }
104 }
105 
TEST_P(OatDumpTest,TestMethodAndOffsetOnly)106 TEST_P(OatDumpTest, TestMethodAndOffsetOnly) {
107   TEST_DISABLED_FOR_RISCV64();
108   TEST_DISABLED_FOR_ARM_AND_ARM64();
109   std::string error_msg;
110   ASSERT_TRUE(Exec(GetParam(),
111                    kArgOatBcp | kArgDexBcp | kArgMethodAndOffsetAsJson,
112                    {},
113                    kExpectMethodAndOffsetAsJson));
114 }
115 
116 }  // namespace art
117