summaryrefslogtreecommitdiff
path: root/oatdump/oatdump_app_test.cc
blob: d4dee4f2f6ba3e76e9e126c6d29d37d8cc2e5c99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "oatdump_test.h"

namespace art {

// Oat file compiled with a boot image. oatdump invoked with a boot image.
TEST_P(OatDumpTest, TestDumpOatWithRuntimeWithBootImage) {
  ASSERT_TRUE(GenerateAppOdexFile(GetParam()));
  ASSERT_TRUE(Exec(GetParam(),
                   kArgOatApp | kArgBootImage | kArgBcp | kArgIsa,
                   {},
                   kExpectOat | kExpectCode | kExpectBssMappingsForBcp));
}

// Oat file compiled without a boot image. oatdump invoked without a boot image.
TEST_P(OatDumpTest, TestDumpOatWithRuntimeWithNoBootImage) {
  TEST_DISABLED_FOR_DEBUG_BUILD();  // DCHECK failed.
  ASSERT_TRUE(GenerateAppOdexFile(GetParam(), {"--boot-image=/nonx/boot.art"}));
  ASSERT_TRUE(Exec(GetParam(),
                   kArgOatApp | kArgBcp | kArgIsa,
                   {"--boot-image=/nonx/boot.art"},
                   kExpectOat | kExpectCode | kExpectBssMappingsForBcp));
}

// Dex code cannot be found in the vdex file, and no --dex-file is specified. Dump header only.
TEST_P(OatDumpTest, TestDumpOatTryWithRuntimeDexNotFound) {
  ASSERT_TRUE(
      GenerateAppOdexFile(GetParam(), {"--dex-location=/nonx/app.jar", "--copy-dex-files=false"}));
  ASSERT_TRUE(Exec(GetParam(), kArgOatApp | kArgBootImage | kArgBcp | kArgIsa, {}, kExpectOat));
}

// Dex code cannot be found in the vdex file, but can be found in the specified dex file.
TEST_P(OatDumpTest, TestDumpOatWithRuntimeDexSpecified) {
  ASSERT_TRUE(
      GenerateAppOdexFile(GetParam(), {"--dex-location=/nonx/app.jar", "--copy-dex-files=false"}));
  ASSERT_TRUE(Exec(GetParam(),
                   kArgOatApp | kArgDexApp | kArgBootImage | kArgBcp | kArgIsa,
                   {},
                   kExpectOat | kExpectCode | kExpectBssMappingsForBcp));
}

// Oat file compiled with a boot image. oatdump invoked without a boot image.
TEST_P(OatDumpTest, TestDumpOatWithoutRuntimeBcpMismatch) {
  ASSERT_TRUE(GenerateAppOdexFile(GetParam()));
  ASSERT_TRUE(Exec(GetParam(),
                   kArgOatApp | kArgBcp | kArgIsa,
                   {"--boot-image=/nonx/boot.art"},
                   kExpectOat | kExpectCode | kExpectBssOffsetsForBcp));
}

// Bootclasspath not specified.
TEST_P(OatDumpTest, TestDumpOatWithoutRuntimeNoBcp) {
  ASSERT_TRUE(GenerateAppOdexFile(GetParam()));
  ASSERT_TRUE(Exec(GetParam(), kArgOatApp, {}, kExpectOat | kExpectCode | kExpectBssOffsetsForBcp));
}

// Dex code cannot be found in the vdex file, and no --dex-file is specified. Dump header only.
TEST_P(OatDumpTest, TestDumpOatWithoutRuntimeDexNotFound) {
  ASSERT_TRUE(
      GenerateAppOdexFile(GetParam(), {"--dex-location=/nonx/app.jar", "--copy-dex-files=false"}));
  ASSERT_TRUE(Exec(GetParam(), kArgOatApp, {}, kExpectOat));
}

// Dex code cannot be found in the vdex file, but can be found in the specified dex file.
TEST_P(OatDumpTest, TestDumpOatWithoutRuntimeDexSpecified) {
  ASSERT_TRUE(
      GenerateAppOdexFile(GetParam(), {"--dex-location=/nonx/app.jar", "--copy-dex-files=false"}));
  ASSERT_TRUE(Exec(
      GetParam(), kArgOatApp | kArgDexApp, {}, kExpectOat | kExpectCode | kExpectBssOffsetsForBcp));
}

TEST_P(OatDumpTest, TestDumpAppImageWithBootImage) {
  TEST_DISABLED_WITHOUT_BAKER_READ_BARRIERS();  // GC bug, b/126305867
  const std::string app_image_arg = "--app-image-file=" + GetAppImageName();
  ASSERT_TRUE(GenerateAppOdexFile(GetParam(), {app_image_arg}));
  ASSERT_TRUE(Exec(GetParam(),
                   kArgAppImage | kArgOatApp | kArgBootImage | kArgBcp | kArgIsa,
                   {},
                   kExpectImage | kExpectOat | kExpectCode | kExpectBssMappingsForBcp));
}

// Deprecated usage, but checked for compatibility.
TEST_P(OatDumpTest, TestDumpAppImageWithBootImageLegacy) {
  TEST_DISABLED_WITHOUT_BAKER_READ_BARRIERS();  // GC bug, b/126305867
  const std::string app_image_arg = "--app-image-file=" + GetAppImageName();
  ASSERT_TRUE(GenerateAppOdexFile(GetParam(), {app_image_arg}));
  ASSERT_TRUE(Exec(GetParam(),
                   kArgAppImage | kArgImage | kArgBcp | kArgIsa,
                   {"--app-oat=" + GetAppOdexName()},
                   kExpectImage | kExpectOat | kExpectCode | kExpectBssMappingsForBcp));
}

TEST_P(OatDumpTest, TestDumpAppImageInvalidPath) {
  TEST_DISABLED_WITHOUT_BAKER_READ_BARRIERS();  // GC bug, b/126305867
  const std::string app_image_arg = "--app-image-file=" + GetAppImageName();
  ASSERT_TRUE(GenerateAppOdexFile(GetParam(), {app_image_arg}));
  ASSERT_TRUE(Exec(GetParam(),
                   kArgOatApp | kArgBootImage | kArgBcp | kArgIsa,
                   {"--app-image=missing_app_image.art"},
                   /*expects=*/0,
                   /*expect_failure=*/true));
}

// The runtime can start, but the boot image check should fail.
TEST_P(OatDumpTest, TestDumpAppImageWithWrongBootImage) {
  TEST_DISABLED_WITHOUT_BAKER_READ_BARRIERS();  // GC bug, b/126305867
  const std::string app_image_arg = "--app-image-file=" + GetAppImageName();
  ASSERT_TRUE(GenerateAppOdexFile(GetParam(), {app_image_arg}));
  ASSERT_TRUE(Exec(GetParam(),
                   kArgAppImage | kArgOatApp | kArgBcp | kArgIsa,
                   {"--boot-image=/nonx/boot.art"},
                   /*expects=*/0,
                   /*expect_failure=*/true));
}

// Not possible.
TEST_P(OatDumpTest, TestDumpAppImageWithoutRuntime) {
  TEST_DISABLED_WITHOUT_BAKER_READ_BARRIERS();  // GC bug, b/126305867
  const std::string app_image_arg = "--app-image-file=" + GetAppImageName();
  ASSERT_TRUE(GenerateAppOdexFile(GetParam(), {app_image_arg}));
  ASSERT_TRUE(Exec(GetParam(),
                   kArgAppImage | kArgOatApp,
                   {},
                   /*expects=*/0,
                   /*expect_failure=*/true));
}

// Dex code cannot be found in the vdex file, and no --dex-file is specified. Cannot dump app image.
TEST_P(OatDumpTest, TestDumpAppImageDexNotFound) {
  TEST_DISABLED_WITHOUT_BAKER_READ_BARRIERS();  // GC bug, b/126305867
  const std::string app_image_arg = "--app-image-file=" + GetAppImageName();
  ASSERT_TRUE(GenerateAppOdexFile(
      GetParam(), {app_image_arg, "--dex-location=/nonx/app.jar", "--copy-dex-files=false"}));
  ASSERT_TRUE(Exec(GetParam(),
                   kArgAppImage | kArgOatApp | kArgBootImage | kArgBcp | kArgIsa,
                   {},
                   /*expects=*/0,
                   /*expect_failure=*/true));
}

// Dex code cannot be found in the vdex file, but can be found in the specified dex file.
TEST_P(OatDumpTest, TestDumpAppImageDexSpecified) {
  TEST_DISABLED_WITHOUT_BAKER_READ_BARRIERS();  // GC bug, b/126305867
  const std::string app_image_arg = "--app-image-file=" + GetAppImageName();
  ASSERT_TRUE(GenerateAppOdexFile(
      GetParam(), {app_image_arg, "--dex-location=/nonx/app.jar", "--copy-dex-files=false"}));
  ASSERT_TRUE(Exec(GetParam(),
                   kArgAppImage | kArgOatApp | kArgDexApp | kArgBootImage | kArgBcp | kArgIsa,
                   {},
                   kExpectImage | kExpectOat | kExpectCode | kExpectBssMappingsForBcp));
}

}  // namespace art