blob: 304ba7b04ff3df69db1a813c4f04adf30dd5c8dd [file] [log] [blame]
Victor Hsiehc9821f12020-08-07 11:32:29 -07001/*
2 * Copyright (C) 2020 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 <map>
18#include <memory>
19#include <string>
20
21#include <android-base/logging.h>
22
23#include <gtest/gtest.h>
24
25#include "execv_helper.h"
26#include "run_dex2oat.h"
Victor Hsiehcb35a062020-08-13 16:11:13 -070027#include "unique_file.h"
Victor Hsiehc9821f12020-08-07 11:32:29 -070028
29namespace android {
30namespace installd {
31
32class RunDex2OatTest : public testing::Test {
33 public:
34 static constexpr const char* INPUT_PATH = "/dir/input/basename.apk";
35 static constexpr const char* OUTPUT_PATH = "/dir/output/basename.oat";
36 static constexpr const char* FLAG_UNUSED = "{{FLAG_UNUSED}}";
37
Victor Hsiehcb35a062020-08-13 16:11:13 -070038 // UniqueFile closes FD. Avoid using standard I/O since the test is expected to print gtest
39 // results. Alternatively, mock out UniqueFile to avoid the side effect of close(2).
40 static constexpr int ZIP_FD = 3;
41 static constexpr int OAT_FD = 4;
42 static constexpr int INPUT_VDEX_FD = 5;
43 static constexpr int OUTPUT_VDEX_FD = 6;
44 static constexpr int IMAGE_FD = 7;
45 static constexpr int PROFILE_FD = 8;
46 static constexpr int DEX_METADATA_FD = 9;
47 static constexpr int SWAP_FD = 10;
Victor Hsiehc9821f12020-08-07 11:32:29 -070048
49 using FakeSystemProperties = std::map<std::string, std::string>;
50
51 // A fake RunDex2Oat that allows to override (fake) system properties and starts with none.
52 class FakeRunDex2Oat : public RunDex2Oat {
53 private:
54 static constexpr const char* TRUE_STR = "true";
55 static constexpr const char* FALSE_STR = "false";
56
57 public:
58 FakeRunDex2Oat(ExecVHelper* execv_helper, FakeSystemProperties* properties)
59 : RunDex2Oat("/dir/bin/dex2oat", execv_helper), properties_(properties) { }
60
61 virtual ~FakeRunDex2Oat() {}
62
63 virtual std::string GetProperty(const std::string& key,
64 const std::string& default_value) override {
65 if (!properties_) {
66 return default_value;
67 }
68 auto iter = properties_->find(key);
69 if (iter == properties_->end()) {
70 return default_value;
71 }
72 return iter->second;
73 }
74
75 virtual bool GetBoolProperty(const std::string& key, bool default_value) override {
76 std::string value = GetProperty(key, "");
77 if (value == "") {
78 return default_value;
79 }
80 return value == TRUE_STR;
81 }
82
83 private:
84 FakeSystemProperties* properties_;
85 };
86
87 struct RunDex2OatArgs {
88 static std::unique_ptr<RunDex2OatArgs> MakeDefaultTestArgs() {
89 auto args = std::make_unique<RunDex2OatArgs>();
Victor Hsiehcb35a062020-08-13 16:11:13 -070090 args->input_dex.reset(ZIP_FD, INPUT_PATH);
91 args->output_oat.reset(OAT_FD, OUTPUT_PATH);
92 args->input_vdex.reset(INPUT_VDEX_FD, "UNUSED_PATH");
93 args->output_vdex.reset(OUTPUT_VDEX_FD, "UNUSED_PATH");
Victor Hsiehc9821f12020-08-07 11:32:29 -070094 args->instruction_set = "arm64";
95 args->compilation_reason = "rundex2oattest";
96 return args;
97 }
98
Victor Hsiehcb35a062020-08-13 16:11:13 -070099 UniqueFile output_oat;
100 UniqueFile output_vdex;
101 UniqueFile output_image;
102 UniqueFile input_dex;
103 UniqueFile input_vdex;
104 UniqueFile dex_metadata;
105 UniqueFile profile;
Victor Hsiehc9821f12020-08-07 11:32:29 -0700106 int swap_fd = -1;
107 const char* instruction_set = nullptr;
108 const char* compiler_filter = "extract";
109 bool debuggable = false;
110 bool post_bootcomplete = false;
111 bool for_restore = false;
Victor Hsiehc9821f12020-08-07 11:32:29 -0700112 const char* class_loader_context = nullptr;
113 std::string class_loader_context_fds;
114 int target_sdk_version = 0;
115 bool enable_hidden_api_checks = false;
116 bool generate_compact_dex = true;
Jiakai Zhang202524b2021-12-22 16:40:52 +0000117 bool use_jitzygote = false;
Martin Stjernholm02570a72022-11-01 13:56:46 +0000118 bool background_job_compile = false;
Victor Hsiehc9821f12020-08-07 11:32:29 -0700119 const char* compilation_reason = nullptr;
120 };
121
122 class FakeExecVHelper : public ExecVHelper {
123 public:
124 bool HasArg(const std::string& arg) const {
125 auto end = argv_.end() - 1; // To exclude the terminating nullptr
126 return find(argv_.begin(), end, arg) != end;
127 }
128
129 bool FlagNotUsed(const std::string& flag) const {
130 auto has_prefix = [flag](const char* arg) {
131 return strncmp(arg, flag.c_str(), flag.size()) == 0;
132 };
133 auto end = argv_.end() - 1; // To exclude the terminating nullptr
134 return find_if(argv_.begin(), end, has_prefix) == end;
135 }
136
137 virtual void Exec(int exit_code) override {
138 std::string cmd;
139 for (auto arg : argv_) {
140 if (arg == nullptr) {
141 continue;
142 }
143 cmd += arg;
144 cmd += " ";
145 }
Victor Hsiehcb35a062020-08-13 16:11:13 -0700146 LOG(DEBUG) << "FakeExecVHelper exit_code: " << exit_code << " cmd: " << cmd << "\n";
Victor Hsiehc9821f12020-08-07 11:32:29 -0700147 }
148 };
149
150 virtual void SetUp() override {
151 execv_helper_.reset(new FakeExecVHelper());
152 system_properties_.clear();
153 initializeDefaultExpectedFlags();
154 }
155
156 // Initializes the default flags expected to a run. It currently matches to the expected flags
157 // with RunDex2OatArgs::MakeDefaultTestArgs.
158 //
159 // default_expected_flags_ defines a mapping of <flag_name, expected_value>, where flag_name is
160 // something like "--flag-name", and expected_value can be "=value" or ":value" (depending on
161 // its delimiter), "" (if no value is needed), or a special value of FLAG_UNUSED to indicates
162 // that it should not be used.
163 void initializeDefaultExpectedFlags() {
164 default_expected_flags_.clear();
165
166 // Files
167 default_expected_flags_["--zip-fd"] = "=" + std::to_string(ZIP_FD);
168 default_expected_flags_["--zip-location"] = "=basename.apk";
169 default_expected_flags_["--oat-fd"] = "=" + std::to_string(OAT_FD);
170 default_expected_flags_["--oat-location"] = "=" + std::string(OUTPUT_PATH);
171 default_expected_flags_["--input-vdex-fd"] = "=" + std::to_string(INPUT_VDEX_FD);
172 default_expected_flags_["--output-vdex-fd"] = "=" + std::to_string(OUTPUT_VDEX_FD);
173 default_expected_flags_["--classpath-dir"] = "=/dir/input";
174 default_expected_flags_["--app-image-fd"] = FLAG_UNUSED;
175 default_expected_flags_["--profile-file-fd"] = FLAG_UNUSED;
176 default_expected_flags_["--swap-fd"] = FLAG_UNUSED;
177 default_expected_flags_["--class-loader-context"] = FLAG_UNUSED;
178 default_expected_flags_["--class-loader-context-fds"] = FLAG_UNUSED;
Jiakai Zhang202524b2021-12-22 16:40:52 +0000179 default_expected_flags_["--boot-image"] = FLAG_UNUSED;
Victor Hsiehc9821f12020-08-07 11:32:29 -0700180
181 // Arch
182 default_expected_flags_["--instruction-set"] = "=arm64";
183 default_expected_flags_["--instruction-set-features"] = FLAG_UNUSED;
184 default_expected_flags_["--instruction-set-variant"] = FLAG_UNUSED;
185 default_expected_flags_["--cpu-set"] = FLAG_UNUSED;
186
187 // Misc
188 default_expected_flags_["--compiler-filter"] = "=extract";
189 default_expected_flags_["--compilation-reason"] = "=rundex2oattest";
190 default_expected_flags_["--compact-dex-level"] = FLAG_UNUSED;
191 default_expected_flags_["-j"] = FLAG_UNUSED;
192 default_expected_flags_["--max-image-block-size"] = FLAG_UNUSED;
193 default_expected_flags_["--very-large-app-threshold"] = FLAG_UNUSED;
194 default_expected_flags_["--resolve-startup-const-strings"] = FLAG_UNUSED;
Jiakai Zhang202524b2021-12-22 16:40:52 +0000195 default_expected_flags_["--force-jit-zygote"] = FLAG_UNUSED;
Victor Hsiehc9821f12020-08-07 11:32:29 -0700196
197 // Debug
198 default_expected_flags_["--debuggable"] = FLAG_UNUSED;
199 default_expected_flags_["--generate-debug-info"] = FLAG_UNUSED;
200 default_expected_flags_["--generate-mini-debug-info"] = FLAG_UNUSED;
201
202 // Runtime
203 // TODO(victorhsieh): Check if the previous flag is actually --runtime-arg.
204 default_expected_flags_["-Xms"] = FLAG_UNUSED;
205 default_expected_flags_["-Xmx"] = FLAG_UNUSED;
206 default_expected_flags_["-Xbootclasspath"] = FLAG_UNUSED;
207 default_expected_flags_["-Xtarget-sdk-version"] = FLAG_UNUSED;
208 default_expected_flags_["-Xhidden-api-policy"] = FLAG_UNUSED;
209 default_expected_flags_["-Xnorelocate"] = FLAG_UNUSED;
210
211 // Test only
212 default_expected_flags_["--foo"] = FLAG_UNUSED;
213 default_expected_flags_["--bar"] = FLAG_UNUSED;
214 default_expected_flags_["--baz"] = FLAG_UNUSED;
215 }
216
217 void SetExpectedFlagUsed(const std::string& flag, const std::string& value) {
218 auto iter = default_expected_flags_.find(flag);
219 ASSERT_NE(iter, default_expected_flags_.end()) << "Must define the default value";
220 iter->second = value;
221 }
222
223 void VerifyExpectedFlags() {
224 for (auto const& [flag, value] : default_expected_flags_) {
225 if (value == FLAG_UNUSED) {
226 EXPECT_TRUE(execv_helper_->FlagNotUsed(flag))
227 << "Flag " << flag << " should be unused, but got the value " << value;
228 } else if (value == "") {
229 EXPECT_TRUE(execv_helper_->HasArg(flag))
230 << "Flag " << flag << " should be specified without value, but got " << value;
231 } else {
232 EXPECT_TRUE(execv_helper_->HasArg(flag + value))
Victor Hsiehcb35a062020-08-13 16:11:13 -0700233 << "Flag " << flag << value << " is not specificed";
Victor Hsiehc9821f12020-08-07 11:32:29 -0700234 }
235 }
236 }
237
238 void setSystemProperty(const std::string& key, const std::string& value) {
239 system_properties_[key] = value;
240 }
241
242 void CallRunDex2Oat(std::unique_ptr<RunDex2OatArgs> args) {
243 FakeRunDex2Oat runner(execv_helper_.get(), &system_properties_);
Victor Hsiehcb35a062020-08-13 16:11:13 -0700244 runner.Initialize(args->output_oat,
245 args->output_vdex,
246 args->output_image,
247 args->input_dex,
248 args->input_vdex,
249 args->dex_metadata,
250 args->profile,
251 args->class_loader_context,
252 args->class_loader_context_fds,
Victor Hsiehc9821f12020-08-07 11:32:29 -0700253 args->swap_fd,
254 args->instruction_set,
255 args->compiler_filter,
256 args->debuggable,
257 args->post_bootcomplete,
258 args->for_restore,
Victor Hsiehc9821f12020-08-07 11:32:29 -0700259 args->target_sdk_version,
260 args->enable_hidden_api_checks,
261 args->generate_compact_dex,
Jiakai Zhang202524b2021-12-22 16:40:52 +0000262 args->use_jitzygote,
Martin Stjernholm02570a72022-11-01 13:56:46 +0000263 args->background_job_compile,
Victor Hsiehc9821f12020-08-07 11:32:29 -0700264 args->compilation_reason);
265 runner.Exec(/*exit_code=*/ 0);
266 }
267
268 private:
269 std::unique_ptr<FakeExecVHelper> execv_helper_;
270 std::map<std::string, std::string> default_expected_flags_;
271 FakeSystemProperties system_properties_;
272};
273
274TEST_F(RunDex2OatTest, BasicInputOutput) {
275 auto execv_helper = std::make_unique<FakeExecVHelper>();
276 CallRunDex2Oat(RunDex2OatArgs::MakeDefaultTestArgs());
277
278 VerifyExpectedFlags();
279}
280
281TEST_F(RunDex2OatTest, WithAllOtherInputFds) {
282 auto args = RunDex2OatArgs::MakeDefaultTestArgs();
Victor Hsiehcb35a062020-08-13 16:11:13 -0700283 args->output_image.reset(IMAGE_FD, "UNUSED_PATH");
284 args->profile.reset(PROFILE_FD, "UNUSED_PATH");
Victor Hsiehc9821f12020-08-07 11:32:29 -0700285 args->swap_fd = SWAP_FD;
286 CallRunDex2Oat(std::move(args));
287
288 SetExpectedFlagUsed("--app-image-fd", "=" + std::to_string(IMAGE_FD));
289 SetExpectedFlagUsed("--profile-file-fd", "=" + std::to_string(PROFILE_FD));
290 SetExpectedFlagUsed("--swap-fd", "=" + std::to_string(SWAP_FD));
291 VerifyExpectedFlags();
292}
293
294TEST_F(RunDex2OatTest, WithClassLoaderContext) {
295 auto args = RunDex2OatArgs::MakeDefaultTestArgs();
296 args->class_loader_context = "CLASS_LOADER_CONTEXT";
297 CallRunDex2Oat(std::move(args));
298
299 SetExpectedFlagUsed("--class-loader-context", "=CLASS_LOADER_CONTEXT");
300 SetExpectedFlagUsed("--class-loader-context-fds", FLAG_UNUSED);
301 VerifyExpectedFlags();
302}
303
304TEST_F(RunDex2OatTest, WithClassLoaderContextAndFds) {
305 auto args = RunDex2OatArgs::MakeDefaultTestArgs();
306 args->class_loader_context = "CLASS_LOADER_CONTEXT";
307 args->class_loader_context_fds = "CLASS_LOADER_CONTEXT_FDS";
308 CallRunDex2Oat(std::move(args));
309
310 SetExpectedFlagUsed("--class-loader-context", "=CLASS_LOADER_CONTEXT");
311 SetExpectedFlagUsed("--class-loader-context-fds", "=CLASS_LOADER_CONTEXT_FDS");
312 VerifyExpectedFlags();
313}
314
315TEST_F(RunDex2OatTest, WithOnlyClassLoaderContextFds) {
316 auto args = RunDex2OatArgs::MakeDefaultTestArgs();
317 args->class_loader_context_fds = "CLASS_LOADER_CONTEXT_FDS";
318 CallRunDex2Oat(std::move(args));
319
320 SetExpectedFlagUsed("--class-loader-context", FLAG_UNUSED);
321 SetExpectedFlagUsed("--class-loader-context-fds", FLAG_UNUSED);
322 VerifyExpectedFlags();
323}
324
Victor Hsiehc9821f12020-08-07 11:32:29 -0700325TEST_F(RunDex2OatTest, DoNotGenerateCompactDex) {
326 auto args = RunDex2OatArgs::MakeDefaultTestArgs();
327 args->generate_compact_dex = false;
328 CallRunDex2Oat(std::move(args));
329
330 SetExpectedFlagUsed("--compact-dex-level", "=none");
331 VerifyExpectedFlags();
332}
333
334TEST_F(RunDex2OatTest, DoNotGenerateCompactDexWithVdexInPlaceUpdate) {
335 auto args = RunDex2OatArgs::MakeDefaultTestArgs();
336 args->generate_compact_dex = true;
Victor Hsiehcb35a062020-08-13 16:11:13 -0700337 args->input_vdex.reset(INPUT_VDEX_FD, "UNUSED_PATH");
338 args->output_vdex.reset(INPUT_VDEX_FD, "UNUSED_PATH");
Victor Hsiehc9821f12020-08-07 11:32:29 -0700339 CallRunDex2Oat(std::move(args));
340
341 SetExpectedFlagUsed("--compact-dex-level", "=none");
342 SetExpectedFlagUsed("--output-vdex-fd", "=" + std::to_string(INPUT_VDEX_FD));
343 VerifyExpectedFlags();
344}
345
346TEST_F(RunDex2OatTest, ISA) {
347 setSystemProperty("dalvik.vm.isa.x86.features", "a-x86-feature");
348 setSystemProperty("dalvik.vm.isa.x86.variant", "a-x86-variant");
349 auto args = RunDex2OatArgs::MakeDefaultTestArgs();
350 args->instruction_set = "x86";
351 CallRunDex2Oat(std::move(args));
352
353 SetExpectedFlagUsed("--instruction-set", "=x86");
354 SetExpectedFlagUsed("--instruction-set-features", "=a-x86-feature");
355 SetExpectedFlagUsed("--instruction-set-variant", "=a-x86-variant");
356 VerifyExpectedFlags();
357}
358
359TEST_F(RunDex2OatTest, CpuSetPreBootComplete) {
360 setSystemProperty("dalvik.vm.boot-dex2oat-cpu-set", "1,2");
361 auto args = RunDex2OatArgs::MakeDefaultTestArgs();
362 args->post_bootcomplete = false;
363 CallRunDex2Oat(std::move(args));
364
365 SetExpectedFlagUsed("--cpu-set", "=1,2");
366 VerifyExpectedFlags();
367}
368
369TEST_F(RunDex2OatTest, CpuSetPostBootCompleteNotForRestore) {
370 setSystemProperty("dalvik.vm.dex2oat-cpu-set", "1,2");
371 auto args = RunDex2OatArgs::MakeDefaultTestArgs();
372 args->post_bootcomplete = true;
373 args->for_restore = false;
374 CallRunDex2Oat(std::move(args));
375
376 SetExpectedFlagUsed("--cpu-set", "=1,2");
377 VerifyExpectedFlags();
378}
379
Martin Stjernholm02570a72022-11-01 13:56:46 +0000380TEST_F(RunDex2OatTest, CpuSetPostBootCompleteBackground) {
381 setSystemProperty("dalvik.vm.background-dex2oat-cpu-set", "1,3");
382 setSystemProperty("dalvik.vm.dex2oat-cpu-set", "1,2");
383 auto args = RunDex2OatArgs::MakeDefaultTestArgs();
384 args->post_bootcomplete = true;
385 args->background_job_compile = true;
386 CallRunDex2Oat(std::move(args));
387
388 SetExpectedFlagUsed("--cpu-set", "=1,3");
389 VerifyExpectedFlags();
390}
391
392TEST_F(RunDex2OatTest, CpuSetPostBootCompleteBackground_Backup) {
393 setSystemProperty("dalvik.vm.background-dex2oat-cpu-set", "");
394 setSystemProperty("dalvik.vm.dex2oat-cpu-set", "1,2");
395 auto args = RunDex2OatArgs::MakeDefaultTestArgs();
396 args->post_bootcomplete = true;
397 args->background_job_compile = true;
398 CallRunDex2Oat(std::move(args));
399
400 SetExpectedFlagUsed("--cpu-set", "=1,2");
401 VerifyExpectedFlags();
402}
403
Victor Hsiehc9821f12020-08-07 11:32:29 -0700404TEST_F(RunDex2OatTest, CpuSetPostBootCompleteForRestore) {
405 setSystemProperty("dalvik.vm.restore-dex2oat-cpu-set", "1,2");
406 setSystemProperty("dalvik.vm.dex2oat-cpu-set", "2,3");
407 auto args = RunDex2OatArgs::MakeDefaultTestArgs();
408 args->post_bootcomplete = true;
409 args->for_restore = true;
410 CallRunDex2Oat(std::move(args));
411
412 SetExpectedFlagUsed("--cpu-set", "=1,2");
413 VerifyExpectedFlags();
414}
415
416TEST_F(RunDex2OatTest, CpuSetPostBootCompleteForRestore_Backup) {
417 setSystemProperty("dalvik.vm.restore-dex2oat-cpu-set", "");
418 setSystemProperty("dalvik.vm.dex2oat-cpu-set", "1,2");
419 auto args = RunDex2OatArgs::MakeDefaultTestArgs();
420 args->post_bootcomplete = true;
421 args->for_restore = true;
422 CallRunDex2Oat(std::move(args));
423
424 SetExpectedFlagUsed("--cpu-set", "=1,2");
425 VerifyExpectedFlags();
426}
427
428TEST_F(RunDex2OatTest, Runtime) {
429 setSystemProperty("dalvik.vm.dex2oat-Xms", "1234m");
430 setSystemProperty("dalvik.vm.dex2oat-Xmx", "5678m");
431 auto args = RunDex2OatArgs::MakeDefaultTestArgs();
432 args->target_sdk_version = 30;
433 args->enable_hidden_api_checks = true;
434 CallRunDex2Oat(std::move(args));
435
436 SetExpectedFlagUsed("-Xms", "1234m");
437 SetExpectedFlagUsed("-Xmx", "5678m");
438 SetExpectedFlagUsed("-Xtarget-sdk-version", ":30");
439 SetExpectedFlagUsed("-Xhidden-api-policy", ":enabled");
440 SetExpectedFlagUsed("-Xnorelocate", FLAG_UNUSED);
441 VerifyExpectedFlags();
442}
443
444TEST_F(RunDex2OatTest, SkipRelocationInMinFramework) {
445 setSystemProperty("vold.decrypt", "trigger_restart_min_framework");
446 CallRunDex2Oat(RunDex2OatArgs::MakeDefaultTestArgs());
447
448 SetExpectedFlagUsed("--compiler-filter", "=extract");
449 SetExpectedFlagUsed("-Xnorelocate", "");
450 VerifyExpectedFlags();
451}
452
453TEST_F(RunDex2OatTest, SkipRelocationIfDecryptedWithFullDiskEncryption) {
454 setSystemProperty("vold.decrypt", "1");
455 CallRunDex2Oat(RunDex2OatArgs::MakeDefaultTestArgs());
456
457 SetExpectedFlagUsed("--compiler-filter", "=extract");
458 SetExpectedFlagUsed("-Xnorelocate", "");
459 VerifyExpectedFlags();
460}
461
462TEST_F(RunDex2OatTest, DalvikVmDex2oatFilter) {
463 setSystemProperty("dalvik.vm.dex2oat-filter", "speed");
464 auto args = RunDex2OatArgs::MakeDefaultTestArgs();
465 args->compiler_filter = nullptr;
466 CallRunDex2Oat(std::move(args));
467
468 SetExpectedFlagUsed("--compiler-filter", "=speed");
469 VerifyExpectedFlags();
470}
471
472TEST_F(RunDex2OatTest, ResolveStartupStartings) {
473 setSystemProperty("dalvik.vm.dex2oat-resolve-startup-strings", "false");
474 CallRunDex2Oat(RunDex2OatArgs::MakeDefaultTestArgs());
475
476 SetExpectedFlagUsed("--resolve-startup-const-strings", "=false");
477 VerifyExpectedFlags();
478}
479
480TEST_F(RunDex2OatTest, ResolveStartupStartingsOverride) {
481 setSystemProperty("dalvik.vm.dex2oat-resolve-startup-strings", "false");
482 setSystemProperty("persist.device_config.runtime.dex2oat_resolve_startup_strings", "true");
483 CallRunDex2Oat(RunDex2OatArgs::MakeDefaultTestArgs());
484
485 SetExpectedFlagUsed("--resolve-startup-const-strings", "=true");
486 VerifyExpectedFlags();
487}
488
489TEST_F(RunDex2OatTest, ThreadsPreBootComplete) {
490 setSystemProperty("dalvik.vm.boot-dex2oat-threads", "2");
491 auto args = RunDex2OatArgs::MakeDefaultTestArgs();
492 args->post_bootcomplete = false;
493 CallRunDex2Oat(std::move(args));
494
495 SetExpectedFlagUsed("-j", "2");
496 VerifyExpectedFlags();
497}
498
499TEST_F(RunDex2OatTest, ThreadsPostBootCompleteNotForRestore) {
500 setSystemProperty("dalvik.vm.dex2oat-threads", "3");
501 auto args = RunDex2OatArgs::MakeDefaultTestArgs();
502 args->post_bootcomplete = true;
503 args->for_restore = false;
504 CallRunDex2Oat(std::move(args));
505
506 SetExpectedFlagUsed("-j", "3");
507 VerifyExpectedFlags();
508}
509
Martin Stjernholm02570a72022-11-01 13:56:46 +0000510TEST_F(RunDex2OatTest, ThreadsPostBootCompleteBackground) {
511 setSystemProperty("dalvik.vm.background-dex2oat-threads", "2");
512 setSystemProperty("dalvik.vm.dex2oat-threads", "3");
513 auto args = RunDex2OatArgs::MakeDefaultTestArgs();
514 args->post_bootcomplete = true;
515 args->background_job_compile = true;
516 CallRunDex2Oat(std::move(args));
517
518 SetExpectedFlagUsed("-j", "2");
519 VerifyExpectedFlags();
520}
521
522TEST_F(RunDex2OatTest, ThreadsPostBootCompleteBackground_Backup) {
523 setSystemProperty("dalvik.vm.background-dex2oat-threads", "");
524 setSystemProperty("dalvik.vm.dex2oat-threads", "3");
525 auto args = RunDex2OatArgs::MakeDefaultTestArgs();
526 args->post_bootcomplete = true;
527 args->background_job_compile = true;
528 CallRunDex2Oat(std::move(args));
529
530 SetExpectedFlagUsed("-j", "3");
531 VerifyExpectedFlags();
532}
533
Victor Hsiehc9821f12020-08-07 11:32:29 -0700534TEST_F(RunDex2OatTest, ThreadsPostBootCompleteForRestore) {
535 setSystemProperty("dalvik.vm.restore-dex2oat-threads", "4");
536 setSystemProperty("dalvik.vm.dex2oat-threads", "5");
537 auto args = RunDex2OatArgs::MakeDefaultTestArgs();
538 args->post_bootcomplete = true;
539 args->for_restore = true;
540 CallRunDex2Oat(std::move(args));
541
542 SetExpectedFlagUsed("-j", "4");
543 VerifyExpectedFlags();
544}
545
546TEST_F(RunDex2OatTest, ThreadsPostBootCompleteForRestore_Backup) {
547 setSystemProperty("dalvik.vm.restore-dex2oat-threads", "");
548 setSystemProperty("dalvik.vm.dex2oat-threads", "5");
549 auto args = RunDex2OatArgs::MakeDefaultTestArgs();
550 args->post_bootcomplete = true;
551 args->for_restore = true;
552 CallRunDex2Oat(std::move(args));
553
554 SetExpectedFlagUsed("-j", "5");
555 VerifyExpectedFlags();
556}
557
558TEST_F(RunDex2OatTest, Debuggable) {
559 auto args = RunDex2OatArgs::MakeDefaultTestArgs();
560 args->debuggable = true;
561 CallRunDex2Oat(std::move(args));
562
563 SetExpectedFlagUsed("--debuggable", "");
564 VerifyExpectedFlags();
565}
566
567TEST_F(RunDex2OatTest, AlwaysDebuggable) {
568 setSystemProperty("dalvik.vm.always_debuggable", "1");
569 CallRunDex2Oat(RunDex2OatArgs::MakeDefaultTestArgs());
570
571 SetExpectedFlagUsed("--debuggable", "");
572 VerifyExpectedFlags();
573}
574
575TEST_F(RunDex2OatTest, GenerateDebugInfo) {
576 setSystemProperty("debug.generate-debug-info", "true");
577 CallRunDex2Oat(RunDex2OatArgs::MakeDefaultTestArgs());
578
579 SetExpectedFlagUsed("--generate-debug-info", "");
580 VerifyExpectedFlags();
581}
582
583TEST_F(RunDex2OatTest, HiddenApiCheck) {
584 auto args = RunDex2OatArgs::MakeDefaultTestArgs();
585 args->enable_hidden_api_checks = true;
586 CallRunDex2Oat(std::move(args));
587
588 SetExpectedFlagUsed("-Xhidden-api-policy", ":enabled");
589 VerifyExpectedFlags();
590}
591
592TEST_F(RunDex2OatTest, Misc) {
593 setSystemProperty("dalvik.vm.dex2oat-max-image-block-size", "524288");
594 setSystemProperty("dalvik.vm.dex2oat-very-large", "100000");
595 CallRunDex2Oat(RunDex2OatArgs::MakeDefaultTestArgs());
596
597 SetExpectedFlagUsed("--max-image-block-size", "=524288");
598 SetExpectedFlagUsed("--very-large-app-threshold", "=100000");
599 VerifyExpectedFlags();
600}
601
602TEST_F(RunDex2OatTest, ExtraFlags) {
603 setSystemProperty("dalvik.vm.dex2oat-flags", "--foo=123 --bar:456 --baz");
604 CallRunDex2Oat(RunDex2OatArgs::MakeDefaultTestArgs());
605
606 SetExpectedFlagUsed("--foo", "=123");
607 SetExpectedFlagUsed("--bar", ":456");
608 SetExpectedFlagUsed("--baz", "");
609 VerifyExpectedFlags();
610}
611
Jiakai Zhang202524b2021-12-22 16:40:52 +0000612TEST_F(RunDex2OatTest, UseJitZygoteImage) {
613 auto args = RunDex2OatArgs::MakeDefaultTestArgs();
614 args->use_jitzygote = true;
615 CallRunDex2Oat(std::move(args));
616
617 SetExpectedFlagUsed("--force-jit-zygote", "");
618 VerifyExpectedFlags();
619}
620
621TEST_F(RunDex2OatTest, BootImage) {
622 setSystemProperty("dalvik.vm.boot-image", "foo.art:bar.art");
623 CallRunDex2Oat(RunDex2OatArgs::MakeDefaultTestArgs());
624
625 SetExpectedFlagUsed("--boot-image", "=foo.art:bar.art");
626 VerifyExpectedFlags();
627}
628
Victor Hsiehc9821f12020-08-07 11:32:29 -0700629} // namespace installd
630} // namespace android