blob: 7abd4baff284410224395d1a0b929ed85c478ab0 [file] [log] [blame]
Calin Juravle36eb3132017-01-13 16:32:38 -08001/*
2 * Copyright (C) 2017 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 <gtest/gtest.h>
18
Calin Juravle17374092021-06-08 13:45:09 -070019#include <string>
20
Calin Juravle36eb3132017-01-13 16:32:38 -080021#include "arch/instruction_set.h"
Eric Holkc7ac91b2021-02-04 21:44:01 +000022#include "base/compiler_filter.h"
Calin Juravle36eb3132017-01-13 16:32:38 -080023#include "dexopt_test.h"
Calin Juravle17374092021-06-08 13:45:09 -070024#include "dexoptanalyzer.h"
Calin Juravle36eb3132017-01-13 16:32:38 -080025
26namespace art {
Calin Juravle17374092021-06-08 13:45:09 -070027namespace dexoptanalyzer {
Calin Juravle36eb3132017-01-13 16:32:38 -080028
29class DexoptAnalyzerTest : public DexoptTest {
30 protected:
31 std::string GetDexoptAnalyzerCmd() {
Martin Stjernholme58624f2019-09-20 15:53:40 +010032 std::string file_path = GetArtBinDir() + "/dexoptanalyzer";
Calin Juravle36eb3132017-01-13 16:32:38 -080033 if (kIsDebugBuild) {
Roland Levillainfb6a5c02019-03-29 20:20:16 +000034 file_path += 'd';
Calin Juravle36eb3132017-01-13 16:32:38 -080035 }
36 EXPECT_TRUE(OS::FileExists(file_path.c_str())) << file_path << " should be a valid file path";
37 return file_path;
38 }
39
40 int Analyze(const std::string& dex_file,
41 CompilerFilter::Filter compiler_filter,
Calin Juravle17374092021-06-08 13:45:09 -070042 ProfileAnalysisResult profile_analysis_result,
43 const char* class_loader_context,
44 bool downgrade = false) {
Calin Juravle36eb3132017-01-13 16:32:38 -080045 std::string dexoptanalyzer_cmd = GetDexoptAnalyzerCmd();
46 std::vector<std::string> argv_str;
47 argv_str.push_back(dexoptanalyzer_cmd);
48 argv_str.push_back("--dex-file=" + dex_file);
49 argv_str.push_back("--isa=" + std::string(GetInstructionSetString(kRuntimeISA)));
50 argv_str.push_back("--compiler-filter=" + CompilerFilter::NameOfFilter(compiler_filter));
Calin Juravle17374092021-06-08 13:45:09 -070051 argv_str.push_back("--profile-analysis-result=" +
52 std::to_string(static_cast<int>(profile_analysis_result)));
53 if (downgrade) {
54 argv_str.push_back("--downgrade");
Calin Juravle36eb3132017-01-13 16:32:38 -080055 }
Calin Juravle17374092021-06-08 13:45:09 -070056
Vladimir Marko7a85e702018-12-03 18:47:23 +000057 argv_str.push_back("--runtime-arg");
58 argv_str.push_back(GetClassPathOption("-Xbootclasspath:", GetLibCoreDexFileNames()));
59 argv_str.push_back("--runtime-arg");
60 argv_str.push_back(GetClassPathOption("-Xbootclasspath-locations:", GetLibCoreDexLocations()));
Calin Juravle36eb3132017-01-13 16:32:38 -080061 argv_str.push_back("--image=" + GetImageLocation());
62 argv_str.push_back("--android-data=" + android_data_);
Calin Juravle0a5cad32020-02-14 20:29:26 +000063 if (class_loader_context != nullptr) {
64 argv_str.push_back("--class-loader-context=" + std::string(class_loader_context));
Nicolas Geoffray35de14b2019-01-10 13:10:36 +000065 }
Calin Juravle36eb3132017-01-13 16:32:38 -080066
67 std::string error;
68 return ExecAndReturnCode(argv_str, &error);
69 }
70
71 int DexoptanalyzerToOatFileAssistant(int dexoptanalyzerResult) {
72 switch (dexoptanalyzerResult) {
73 case 0: return OatFileAssistant::kNoDexOptNeeded;
74 case 1: return OatFileAssistant::kDex2OatFromScratch;
75 case 2: return OatFileAssistant::kDex2OatForBootImage;
76 case 3: return OatFileAssistant::kDex2OatForFilter;
Vladimir Markoe0669322018-09-03 15:44:54 +010077 case 4: return -OatFileAssistant::kDex2OatForBootImage;
78 case 5: return -OatFileAssistant::kDex2OatForFilter;
Calin Juravle36eb3132017-01-13 16:32:38 -080079 default: return dexoptanalyzerResult;
80 }
81 }
82
83 // Verify that the output of dexoptanalyzer for the given arguments is the same
84 // as the output of OatFileAssistant::GetDexOptNeeded.
85 void Verify(const std::string& dex_file,
86 CompilerFilter::Filter compiler_filter,
Calin Juravle17374092021-06-08 13:45:09 -070087 ProfileAnalysisResult profile_analysis_result =
88 ProfileAnalysisResult::kDontOptimizeSmallDelta,
Nicolas Geoffray35de14b2019-01-10 13:10:36 +000089 bool downgrade = false,
Calin Juravle0a5cad32020-02-14 20:29:26 +000090 const char* class_loader_context = "PCL[]") {
David Srbecky656fdcd2021-04-17 16:47:01 +000091 std::unique_ptr<ClassLoaderContext> context = class_loader_context == nullptr
92 ? nullptr
93 : ClassLoaderContext::Create(class_loader_context);
Nicolas Geoffray525fa422021-04-19 07:50:35 +000094 if (context != nullptr) {
95 std::vector<int> context_fds;
96 ASSERT_TRUE(context->OpenDexFiles("", context_fds, /*only_read_checksums*/ true));
97 }
David Srbecky656fdcd2021-04-17 16:47:01 +000098
Nicolas Geoffray525fa422021-04-19 07:50:35 +000099 int dexoptanalyzerResult = Analyze(
Calin Juravle17374092021-06-08 13:45:09 -0700100 dex_file, compiler_filter, profile_analysis_result, class_loader_context, downgrade);
Nicolas Geoffray525fa422021-04-19 07:50:35 +0000101 dexoptanalyzerResult = DexoptanalyzerToOatFileAssistant(dexoptanalyzerResult);
102 OatFileAssistant oat_file_assistant(dex_file.c_str(),
103 kRuntimeISA,
104 context.get(),
105 /*load_executable=*/ false);
Calin Juravle17374092021-06-08 13:45:09 -0700106 bool assume_profile_changed = profile_analysis_result == ProfileAnalysisResult::kOptimize;
Calin Juravle36eb3132017-01-13 16:32:38 -0800107 int assistantResult = oat_file_assistant.GetDexOptNeeded(
Nicolas Geoffray525fa422021-04-19 07:50:35 +0000108 compiler_filter, assume_profile_changed, downgrade);
Calin Juravle36eb3132017-01-13 16:32:38 -0800109 EXPECT_EQ(assistantResult, dexoptanalyzerResult);
110 }
111};
112
113// The tests below exercise the same test case from oat_file_assistant_test.cc.
114
Calin Juravle17374092021-06-08 13:45:09 -0700115// Case: We have a DEX file, but no ODEX file for it.
Calin Juravle36eb3132017-01-13 16:32:38 -0800116TEST_F(DexoptAnalyzerTest, DexNoOat) {
117 std::string dex_location = GetScratchDir() + "/DexNoOat.jar";
118 Copy(GetDexSrc1(), dex_location);
119
120 Verify(dex_location, CompilerFilter::kSpeed);
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100121 Verify(dex_location, CompilerFilter::kExtract);
Nicolas Geoffrayf50975a2020-10-15 13:34:55 +0000122 Verify(dex_location, CompilerFilter::kVerify);
Calin Juravle36eb3132017-01-13 16:32:38 -0800123 Verify(dex_location, CompilerFilter::kSpeedProfile);
Calin Juravle17374092021-06-08 13:45:09 -0700124 Verify(dex_location, CompilerFilter::kSpeed,
125 ProfileAnalysisResult::kDontOptimizeSmallDelta, false, nullptr);
Calin Juravle36eb3132017-01-13 16:32:38 -0800126}
127
Calin Juravle17374092021-06-08 13:45:09 -0700128// Case: We have a DEX file and up-to-date ODEX file for it.
Calin Juravle36eb3132017-01-13 16:32:38 -0800129TEST_F(DexoptAnalyzerTest, OatUpToDate) {
130 std::string dex_location = GetScratchDir() + "/OatUpToDate.jar";
Calin Juravle17374092021-06-08 13:45:09 -0700131 std::string odex_location = GetOdexDir() + "/OatUpToDate.odex";
Calin Juravle36eb3132017-01-13 16:32:38 -0800132 Copy(GetDexSrc1(), dex_location);
Calin Juravle17374092021-06-08 13:45:09 -0700133 GenerateOdexForTest(dex_location.c_str(), odex_location.c_str(), CompilerFilter::kSpeed);
Calin Juravle36eb3132017-01-13 16:32:38 -0800134
135 Verify(dex_location, CompilerFilter::kSpeed);
Nicolas Geoffrayf50975a2020-10-15 13:34:55 +0000136 Verify(dex_location, CompilerFilter::kVerify);
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100137 Verify(dex_location, CompilerFilter::kExtract);
Calin Juravle36eb3132017-01-13 16:32:38 -0800138 Verify(dex_location, CompilerFilter::kEverything);
Calin Juravle17374092021-06-08 13:45:09 -0700139 Verify(dex_location, CompilerFilter::kSpeed,
140 ProfileAnalysisResult::kDontOptimizeSmallDelta, false, nullptr);
Calin Juravle36eb3132017-01-13 16:32:38 -0800141}
142
Calin Juravle17374092021-06-08 13:45:09 -0700143// Case: We have a DEX file and speed-profile ODEX file for it.
Calin Juravle36eb3132017-01-13 16:32:38 -0800144TEST_F(DexoptAnalyzerTest, ProfileOatUpToDate) {
145 std::string dex_location = GetScratchDir() + "/ProfileOatUpToDate.jar";
Calin Juravle17374092021-06-08 13:45:09 -0700146 std::string odex_location = GetOdexDir() + "/ProfileOatUpToDate.odex";
Calin Juravle36eb3132017-01-13 16:32:38 -0800147 Copy(GetDexSrc1(), dex_location);
Calin Juravle17374092021-06-08 13:45:09 -0700148 GenerateOdexForTest(dex_location.c_str(), odex_location.c_str(), CompilerFilter::kSpeedProfile);
Calin Juravle36eb3132017-01-13 16:32:38 -0800149
Calin Juravle17374092021-06-08 13:45:09 -0700150 Verify(dex_location, CompilerFilter::kSpeedProfile,
151 ProfileAnalysisResult::kDontOptimizeSmallDelta);
152 Verify(dex_location, CompilerFilter::kVerify, ProfileAnalysisResult::kDontOptimizeSmallDelta);
153 Verify(dex_location, CompilerFilter::kSpeedProfile, ProfileAnalysisResult::kOptimize);
154 Verify(dex_location, CompilerFilter::kVerify, ProfileAnalysisResult::kOptimize);
155}
156
157// Case: We have a DEX file, verify odex file for it, and we ask if it's up to date
158// when the profiles are empty or full.
159TEST_F(DexoptAnalyzerTest, VerifyAndEmptyProfiles) {
160 std::string dex_location = GetScratchDir() + "/VerifyAndEmptyProfiles.jar";
161 std::string odex_location = GetOdexDir() + "/VerifyAndEmptyProfiles.odex";
162 Copy(GetDexSrc1(), dex_location);
163
164 GenerateOdexForTest(dex_location.c_str(), odex_location.c_str(), CompilerFilter::kVerify);
165
166 // If we want to speed-profile something that was verified, do it even if
167 // the profile analysis returns kDontOptimizeSmallDelta (it means that we do have profile data,
168 // so a transition verify -> speed-profile is still worth).
169 ASSERT_EQ(
170 static_cast<int>(ReturnCode::kDex2OatForFilterOdex),
171 Analyze(dex_location, CompilerFilter::kSpeedProfile,
172 ProfileAnalysisResult::kDontOptimizeSmallDelta, "PCL[]"));
173 // If we want to speed-profile something that was verified but the profiles are empty,
174 // don't do it - there will be no gain.
175 ASSERT_EQ(
176 static_cast<int>(ReturnCode::kNoDexOptNeeded),
177 Analyze(dex_location, CompilerFilter::kSpeedProfile,
178 ProfileAnalysisResult::kDontOptimizeEmptyProfiles, "PCL[]"));
179 // Standard case where we need to re-compile a speed-profile because of sufficient new
180 // information in the profile.
181 ASSERT_EQ(
182 static_cast<int>(ReturnCode::kDex2OatForFilterOdex),
183 Analyze(dex_location, CompilerFilter::kSpeedProfile,
184 ProfileAnalysisResult::kOptimize, "PCL[]"));
Calin Juravle36eb3132017-01-13 16:32:38 -0800185}
186
Shubham Ajmerae4e812a2017-05-25 20:09:58 -0700187TEST_F(DexoptAnalyzerTest, Downgrade) {
188 std::string dex_location = GetScratchDir() + "/Downgrade.jar";
Calin Juravle17374092021-06-08 13:45:09 -0700189 std::string odex_location = GetOdexDir() + "/Downgrade.odex";
Shubham Ajmerae4e812a2017-05-25 20:09:58 -0700190 Copy(GetDexSrc1(), dex_location);
Calin Juravle17374092021-06-08 13:45:09 -0700191 GenerateOdexForTest(dex_location.c_str(), odex_location.c_str(), CompilerFilter::kVerify);
Shubham Ajmerae4e812a2017-05-25 20:09:58 -0700192
Calin Juravle17374092021-06-08 13:45:09 -0700193 Verify(dex_location, CompilerFilter::kSpeedProfile,
194 ProfileAnalysisResult::kDontOptimizeSmallDelta, true);
195 Verify(dex_location, CompilerFilter::kVerify,
196 ProfileAnalysisResult::kDontOptimizeSmallDelta, true);
197 Verify(dex_location, CompilerFilter::kExtract,
198 ProfileAnalysisResult::kDontOptimizeSmallDelta, true);
Shubham Ajmerae4e812a2017-05-25 20:09:58 -0700199}
200
Calin Juravle17374092021-06-08 13:45:09 -0700201// Case: We have a MultiDEX file and up-to-date ODEX file for it.
Calin Juravle36eb3132017-01-13 16:32:38 -0800202TEST_F(DexoptAnalyzerTest, MultiDexOatUpToDate) {
203 std::string dex_location = GetScratchDir() + "/MultiDexOatUpToDate.jar";
Calin Juravle17374092021-06-08 13:45:09 -0700204 std::string odex_location = GetOdexDir() + "/MultiDexOatUpToDate.odex";
Calin Juravle36eb3132017-01-13 16:32:38 -0800205
Calin Juravle17374092021-06-08 13:45:09 -0700206 Copy(GetMultiDexSrc1(), dex_location);
207 GenerateOdexForTest(dex_location.c_str(), odex_location.c_str(), CompilerFilter::kSpeed);
208
209 Verify(dex_location, CompilerFilter::kSpeed, ProfileAnalysisResult::kDontOptimizeSmallDelta);
Calin Juravle36eb3132017-01-13 16:32:38 -0800210}
211
212// Case: We have a MultiDEX file where the secondary dex file is out of date.
213TEST_F(DexoptAnalyzerTest, MultiDexSecondaryOutOfDate) {
214 std::string dex_location = GetScratchDir() + "/MultiDexSecondaryOutOfDate.jar";
Calin Juravle17374092021-06-08 13:45:09 -0700215 std::string odex_location = GetOdexDir() + "/MultiDexSecondaryOutOfDate.odex";
Calin Juravle36eb3132017-01-13 16:32:38 -0800216
217 // Compile code for GetMultiDexSrc1.
218 Copy(GetMultiDexSrc1(), dex_location);
Calin Juravle17374092021-06-08 13:45:09 -0700219 GenerateOdexForTest(dex_location.c_str(), odex_location.c_str(), CompilerFilter::kSpeed);
Calin Juravle36eb3132017-01-13 16:32:38 -0800220
221 // Now overwrite the dex file with GetMultiDexSrc2 so the secondary checksum
222 // is out of date.
223 Copy(GetMultiDexSrc2(), dex_location);
224
Calin Juravle17374092021-06-08 13:45:09 -0700225 Verify(dex_location, CompilerFilter::kSpeed, ProfileAnalysisResult::kDontOptimizeSmallDelta);
Calin Juravle36eb3132017-01-13 16:32:38 -0800226}
227
Calin Juravle17374092021-06-08 13:45:09 -0700228// Case: We have a DEX file and an ODEX file out of date with respect to the
Calin Juravle36eb3132017-01-13 16:32:38 -0800229// dex checksum.
230TEST_F(DexoptAnalyzerTest, OatDexOutOfDate) {
231 std::string dex_location = GetScratchDir() + "/OatDexOutOfDate.jar";
Calin Juravle17374092021-06-08 13:45:09 -0700232 std::string odex_location = GetOdexDir() + "/OatDexOutOfDate.odex";
Calin Juravle36eb3132017-01-13 16:32:38 -0800233
234 // We create a dex, generate an oat for it, then overwrite the dex with a
235 // different dex to make the oat out of date.
236 Copy(GetDexSrc1(), dex_location);
Calin Juravle17374092021-06-08 13:45:09 -0700237 GenerateOdexForTest(dex_location.c_str(), odex_location.c_str(), CompilerFilter::kSpeed);
Calin Juravle36eb3132017-01-13 16:32:38 -0800238 Copy(GetDexSrc2(), dex_location);
239
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100240 Verify(dex_location, CompilerFilter::kExtract);
Calin Juravle36eb3132017-01-13 16:32:38 -0800241 Verify(dex_location, CompilerFilter::kSpeed);
242}
243
Calin Juravle17374092021-06-08 13:45:09 -0700244// Case: We have a DEX file and an ODEX file out of date with respect to the
Calin Juravle36eb3132017-01-13 16:32:38 -0800245// boot image.
246TEST_F(DexoptAnalyzerTest, OatImageOutOfDate) {
247 std::string dex_location = GetScratchDir() + "/OatImageOutOfDate.jar";
Calin Juravle17374092021-06-08 13:45:09 -0700248 std::string odex_location = GetOdexDir() + "/OatImageOutOfDate.odex";
Calin Juravle36eb3132017-01-13 16:32:38 -0800249
250 Copy(GetDexSrc1(), dex_location);
251 GenerateOatForTest(dex_location.c_str(),
Calin Juravle17374092021-06-08 13:45:09 -0700252 odex_location.c_str(),
Calin Juravle36eb3132017-01-13 16:32:38 -0800253 CompilerFilter::kSpeed,
Andreas Gampe9b031f72018-10-04 11:03:34 -0700254 /*with_alternate_image=*/true);
Calin Juravle36eb3132017-01-13 16:32:38 -0800255
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100256 Verify(dex_location, CompilerFilter::kExtract);
Nicolas Geoffrayf50975a2020-10-15 13:34:55 +0000257 Verify(dex_location, CompilerFilter::kVerify);
Calin Juravle36eb3132017-01-13 16:32:38 -0800258 Verify(dex_location, CompilerFilter::kSpeed);
259}
260
261// Case: We have a DEX file and a verify-at-runtime OAT file out of date with
262// respect to the boot image.
263// It shouldn't matter that the OAT file is out of date, because it is
264// verify-at-runtime.
265TEST_F(DexoptAnalyzerTest, OatVerifyAtRuntimeImageOutOfDate) {
266 std::string dex_location = GetScratchDir() + "/OatVerifyAtRuntimeImageOutOfDate.jar";
Calin Juravle17374092021-06-08 13:45:09 -0700267 std::string odex_location = GetOdexDir() + "/OatVerifyAtRuntimeImageOutOfDate.odex";
Calin Juravle36eb3132017-01-13 16:32:38 -0800268
269 Copy(GetDexSrc1(), dex_location);
270 GenerateOatForTest(dex_location.c_str(),
Calin Juravle17374092021-06-08 13:45:09 -0700271 odex_location.c_str(),
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100272 CompilerFilter::kExtract,
Andreas Gampe9b031f72018-10-04 11:03:34 -0700273 /*with_alternate_image=*/true);
Calin Juravle36eb3132017-01-13 16:32:38 -0800274
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100275 Verify(dex_location, CompilerFilter::kExtract);
Nicolas Geoffrayf50975a2020-10-15 13:34:55 +0000276 Verify(dex_location, CompilerFilter::kVerify);
Calin Juravle36eb3132017-01-13 16:32:38 -0800277}
278
279// Case: We have a DEX file and an ODEX file, but no OAT file.
280TEST_F(DexoptAnalyzerTest, DexOdexNoOat) {
281 std::string dex_location = GetScratchDir() + "/DexOdexNoOat.jar";
282 std::string odex_location = GetOdexDir() + "/DexOdexNoOat.odex";
283
284 Copy(GetDexSrc1(), dex_location);
285 GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed);
286
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100287 Verify(dex_location, CompilerFilter::kExtract);
Calin Juravle36eb3132017-01-13 16:32:38 -0800288 Verify(dex_location, CompilerFilter::kSpeed);
Vladimir Markoa2da9b92018-10-10 14:21:55 +0100289 Verify(dex_location, CompilerFilter::kEverything);
Calin Juravle36eb3132017-01-13 16:32:38 -0800290}
291
Calin Juravle36eb3132017-01-13 16:32:38 -0800292// Case: We have a stripped (or resource-only) DEX file, no ODEX file and no
293// OAT file. Expect: The status is kNoDexOptNeeded.
294TEST_F(DexoptAnalyzerTest, ResourceOnlyDex) {
295 std::string dex_location = GetScratchDir() + "/ResourceOnlyDex.jar";
296
Calin Juravle5ff23932020-12-11 18:26:14 -0800297 Copy(GetResourceOnlySrc1(), dex_location);
Calin Juravle36eb3132017-01-13 16:32:38 -0800298
299 Verify(dex_location, CompilerFilter::kSpeed);
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100300 Verify(dex_location, CompilerFilter::kExtract);
Nicolas Geoffrayf50975a2020-10-15 13:34:55 +0000301 Verify(dex_location, CompilerFilter::kVerify);
Calin Juravle36eb3132017-01-13 16:32:38 -0800302}
303
Vladimir Markoe0669322018-09-03 15:44:54 +0100304// Case: We have a DEX file, an ODEX file and an OAT file.
Calin Juravle36eb3132017-01-13 16:32:38 -0800305TEST_F(DexoptAnalyzerTest, OdexOatOverlap) {
306 std::string dex_location = GetScratchDir() + "/OdexOatOverlap.jar";
307 std::string odex_location = GetOdexDir() + "/OdexOatOverlap.odex";
308 std::string oat_location = GetOdexDir() + "/OdexOatOverlap.oat";
309
310 Copy(GetDexSrc1(), dex_location);
311 GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kSpeed);
312
313 // Create the oat file by copying the odex so they are located in the same
314 // place in memory.
315 Copy(odex_location, oat_location);
316
317 Verify(dex_location, CompilerFilter::kSpeed);
318}
319
Calin Juravle36eb3132017-01-13 16:32:38 -0800320// Case: We have a DEX file and a VerifyAtRuntime ODEX file, but no OAT file..
321TEST_F(DexoptAnalyzerTest, DexVerifyAtRuntimeOdexNoOat) {
322 std::string dex_location = GetScratchDir() + "/DexVerifyAtRuntimeOdexNoOat.jar";
323 std::string odex_location = GetOdexDir() + "/DexVerifyAtRuntimeOdexNoOat.odex";
324
325 Copy(GetDexSrc1(), dex_location);
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100326 GenerateOdexForTest(dex_location, odex_location, CompilerFilter::kExtract);
Calin Juravle36eb3132017-01-13 16:32:38 -0800327
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100328 Verify(dex_location, CompilerFilter::kExtract);
Calin Juravle36eb3132017-01-13 16:32:38 -0800329 Verify(dex_location, CompilerFilter::kSpeed);
330}
331
332// Case: Non-standard extension for dex file.
333TEST_F(DexoptAnalyzerTest, LongDexExtension) {
334 std::string dex_location = GetScratchDir() + "/LongDexExtension.jarx";
335 Copy(GetDexSrc1(), dex_location);
336
337 Verify(dex_location, CompilerFilter::kSpeed);
338}
339
340// Case: Very short, non-existent Dex location.
341TEST_F(DexoptAnalyzerTest, ShortDexLocation) {
342 std::string dex_location = "/xx";
343
344 Verify(dex_location, CompilerFilter::kSpeed);
345}
346
Nicolas Geoffray35de14b2019-01-10 13:10:36 +0000347// Case: We have a DEX file and up-to-date OAT file for it, and we check with
348// a class loader context.
349TEST_F(DexoptAnalyzerTest, ClassLoaderContext) {
350 std::string dex_location1 = GetScratchDir() + "/DexToAnalyze.jar";
351 std::string odex_location1 = GetOdexDir() + "/DexToAnalyze.odex";
352 std::string dex_location2 = GetScratchDir() + "/DexInContext.jar";
353 Copy(GetDexSrc1(), dex_location1);
354 Copy(GetDexSrc2(), dex_location2);
355
356 std::string class_loader_context = "PCL[" + dex_location2 + "]";
357 std::string class_loader_context_option = "--class-loader-context=PCL[" + dex_location2 + "]";
358
359 // Generate the odex to get the class loader context also open the dex files.
360 GenerateOdexForTest(dex_location1, odex_location1, CompilerFilter::kSpeed, /* compilation_reason= */ nullptr, /* extra_args= */ { class_loader_context_option });
361
Calin Juravle17374092021-06-08 13:45:09 -0700362 Verify(dex_location1, CompilerFilter::kSpeed, ProfileAnalysisResult::kDontOptimizeSmallDelta,
363 false, class_loader_context.c_str());
Nicolas Geoffray35de14b2019-01-10 13:10:36 +0000364}
Calin Juravle17374092021-06-08 13:45:09 -0700365
366} // namespace dexoptanalyzer
Calin Juravle36eb3132017-01-13 16:32:38 -0800367} // namespace art