blob: 8873eb9c60bfc255da4d3189a5fb1e1cb72fc736 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
2 * Copyright (C) 2011 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 */
Carl Shapirofc322c72011-07-27 00:20:01 -070016
Brian Carlstrom491ca9e2014-03-02 18:24:38 -080017#include "parsed_options.h"
Elliott Hughes90a33692011-08-30 13:27:07 -070018
Ian Rogers700a4022014-05-19 16:49:03 -070019#include <memory>
20
Andreas Gampea00f0122015-12-16 16:54:35 -080021#include "arch/instruction_set.h"
Vladimir Markob9c29f62019-03-20 14:22:51 +000022#include "base/common_art_test.h"
Carl Shapirofc322c72011-07-27 00:20:01 -070023
24namespace art {
Carl Shapirofc322c72011-07-27 00:20:01 -070025
Vladimir Markob9c29f62019-03-20 14:22:51 +000026class ParsedOptionsTest : public CommonArtTest {
Igor Murashkineb6c7c22015-02-04 17:30:43 -080027 public:
28 static void SetUpTestCase() {
Vladimir Markob9c29f62019-03-20 14:22:51 +000029 CommonArtTest::SetUpAndroidRootEnvVars();
Igor Murashkineb6c7c22015-02-04 17:30:43 -080030 }
31};
Carl Shapirofc322c72011-07-27 00:20:01 -070032
Brian Carlstrom491ca9e2014-03-02 18:24:38 -080033TEST_F(ParsedOptionsTest, ParsedOptions) {
Brian Carlstromf734cf52011-08-17 16:28:14 -070034 void* test_vfprintf = reinterpret_cast<void*>(0xa);
35 void* test_abort = reinterpret_cast<void*>(0xb);
36 void* test_exit = reinterpret_cast<void*>(0xc);
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070037
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070038 std::string boot_class_path;
Przemyslaw Szczepaniak5b8e6e32015-09-30 14:40:33 +010039 std::string class_path;
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070040 boot_class_path += "-Xbootclasspath:";
Przemyslaw Szczepaniak5b8e6e32015-09-30 14:40:33 +010041
42 bool first_dex_file = true;
Vladimir Markob9c29f62019-03-20 14:22:51 +000043 for (const std::string& dex_file_name : GetLibCoreDexFileNames()) {
Przemyslaw Szczepaniak5b8e6e32015-09-30 14:40:33 +010044 if (!first_dex_file) {
45 class_path += ":";
46 } else {
47 first_dex_file = false;
48 }
49 class_path += dex_file_name;
50 }
51 boot_class_path += class_path;
Vladimir Marko91f10322018-12-07 18:04:10 +000052 std::vector<std::string> expected_boot_class_path;
53 Split(class_path, ':', &expected_boot_class_path);
Brian Carlstromf734cf52011-08-17 16:28:14 -070054
Ian Rogerse63db272014-07-15 15:36:11 -070055 RuntimeOptions options;
Mathieu Chartier2cebb242015-04-21 16:50:40 -070056 options.push_back(std::make_pair(boot_class_path.c_str(), nullptr));
57 options.push_back(std::make_pair("-classpath", nullptr));
Narayan Kamathd1ef4362015-11-12 11:49:06 +000058 options.push_back(std::make_pair(class_path.c_str(), nullptr));
Mathieu Chartier2cebb242015-04-21 16:50:40 -070059 options.push_back(std::make_pair("-cp", nullptr));
Narayan Kamathd1ef4362015-11-12 11:49:06 +000060 options.push_back(std::make_pair(class_path.c_str(), nullptr));
Mathieu Chartier2cebb242015-04-21 16:50:40 -070061 options.push_back(std::make_pair("-Ximage:boot_image", nullptr));
62 options.push_back(std::make_pair("-Xcheck:jni", nullptr));
63 options.push_back(std::make_pair("-Xms2048", nullptr));
64 options.push_back(std::make_pair("-Xmx4k", nullptr));
65 options.push_back(std::make_pair("-Xss1m", nullptr));
66 options.push_back(std::make_pair("-XX:HeapTargetUtilization=0.75", nullptr));
Hans Boehmbb2467b2019-03-29 22:55:06 -070067 options.push_back(std::make_pair("-XX:StopForNativeAllocs=200m", nullptr));
Mathieu Chartier2cebb242015-04-21 16:50:40 -070068 options.push_back(std::make_pair("-Dfoo=bar", nullptr));
69 options.push_back(std::make_pair("-Dbaz=qux", nullptr));
70 options.push_back(std::make_pair("-verbose:gc,class,jni", nullptr));
Brian Carlstromf734cf52011-08-17 16:28:14 -070071 options.push_back(std::make_pair("vfprintf", test_vfprintf));
72 options.push_back(std::make_pair("abort", test_abort));
73 options.push_back(std::make_pair("exit", test_exit));
Brian Carlstromf734cf52011-08-17 16:28:14 -070074
Igor Murashkinaaebaa02015-01-26 10:55:53 -080075 RuntimeArgumentMap map;
Vladimir Marko88b2b802015-12-04 14:19:04 +000076 bool parsed = ParsedOptions::Parse(options, false, &map);
77 ASSERT_TRUE(parsed);
Igor Murashkinaaebaa02015-01-26 10:55:53 -080078 ASSERT_NE(0u, map.Size());
79
80 using Opt = RuntimeArgumentMap;
81
82#define EXPECT_PARSED_EQ(expected, actual_key) EXPECT_EQ(expected, map.GetOrDefault(actual_key))
Vladimir Marko91f10322018-12-07 18:04:10 +000083#define EXPECT_PARSED_EQ_AS_STRING_VECTOR(expected, actual_key) \
84 EXPECT_EQ(expected, static_cast<std::vector<std::string>>(map.GetOrDefault(actual_key)))
Igor Murashkinaaebaa02015-01-26 10:55:53 -080085#define EXPECT_PARSED_EXISTS(actual_key) EXPECT_TRUE(map.Exists(actual_key))
86
Vladimir Marko91f10322018-12-07 18:04:10 +000087 EXPECT_PARSED_EQ_AS_STRING_VECTOR(expected_boot_class_path, Opt::BootClassPath);
Narayan Kamathd1ef4362015-11-12 11:49:06 +000088 EXPECT_PARSED_EQ(class_path, Opt::ClassPath);
Igor Murashkinaaebaa02015-01-26 10:55:53 -080089 EXPECT_PARSED_EQ(std::string("boot_image"), Opt::Image);
90 EXPECT_PARSED_EXISTS(Opt::CheckJni);
91 EXPECT_PARSED_EQ(2048U, Opt::MemoryInitialSize);
92 EXPECT_PARSED_EQ(4 * KB, Opt::MemoryMaximumSize);
93 EXPECT_PARSED_EQ(1 * MB, Opt::StackSize);
Hans Boehmbb2467b2019-03-29 22:55:06 -070094 EXPECT_PARSED_EQ(200 * MB, Opt::StopForNativeAllocs);
Igor Murashkinaaebaa02015-01-26 10:55:53 -080095 EXPECT_DOUBLE_EQ(0.75, map.GetOrDefault(Opt::HeapTargetUtilization));
96 EXPECT_TRUE(test_vfprintf == map.GetOrDefault(Opt::HookVfprintf));
97 EXPECT_TRUE(test_exit == map.GetOrDefault(Opt::HookExit));
98 EXPECT_TRUE(test_abort == map.GetOrDefault(Opt::HookAbort));
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -080099 EXPECT_TRUE(VLOG_IS_ON(class_linker));
100 EXPECT_FALSE(VLOG_IS_ON(compiler));
101 EXPECT_FALSE(VLOG_IS_ON(heap));
102 EXPECT_TRUE(VLOG_IS_ON(gc));
Mathieu Chartier765b2a02019-05-02 11:04:13 -0700103 EXPECT_FALSE(VLOG_IS_ON(interpreter));
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800104 EXPECT_FALSE(VLOG_IS_ON(jdwp));
105 EXPECT_TRUE(VLOG_IS_ON(jni));
106 EXPECT_FALSE(VLOG_IS_ON(monitor));
Phil Wang751beff2015-08-28 15:17:15 +0800107 EXPECT_FALSE(VLOG_IS_ON(signals));
108 EXPECT_FALSE(VLOG_IS_ON(simulator));
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800109 EXPECT_FALSE(VLOG_IS_ON(startup));
110 EXPECT_FALSE(VLOG_IS_ON(third_party_jni));
111 EXPECT_FALSE(VLOG_IS_ON(threads));
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800112
113 auto&& properties_list = map.GetOrDefault(Opt::PropertiesList);
114 ASSERT_EQ(2U, properties_list.size());
115 EXPECT_EQ("foo=bar", properties_list[0]);
116 EXPECT_EQ("baz=qux", properties_list[1]);
Brian Carlstromf734cf52011-08-17 16:28:14 -0700117}
118
Igor Murashkin2798da12015-02-06 17:59:39 -0800119TEST_F(ParsedOptionsTest, ParsedOptionsGc) {
120 RuntimeOptions options;
Mathieu Chartierf8e5d8c2018-04-06 13:35:37 -0700121 options.push_back(std::make_pair("-Xgc:SS", nullptr));
Igor Murashkin2798da12015-02-06 17:59:39 -0800122
123 RuntimeArgumentMap map;
Vladimir Marko88b2b802015-12-04 14:19:04 +0000124 bool parsed = ParsedOptions::Parse(options, false, &map);
125 ASSERT_TRUE(parsed);
Igor Murashkin2798da12015-02-06 17:59:39 -0800126 ASSERT_NE(0u, map.Size());
127
128 using Opt = RuntimeArgumentMap;
129
130 EXPECT_TRUE(map.Exists(Opt::GcOption));
131
132 XGcOption xgc = map.GetOrDefault(Opt::GcOption);
Mathieu Chartierf8e5d8c2018-04-06 13:35:37 -0700133 EXPECT_EQ(gc::kCollectorTypeSS, xgc.collector_type_);
Andreas Gampea00f0122015-12-16 16:54:35 -0800134}
135
Albert Mingkun Yang0b4d1462018-11-29 13:25:35 +0000136TEST_F(ParsedOptionsTest, ParsedOptionsGenerationalCC) {
137 RuntimeOptions options;
138 options.push_back(std::make_pair("-Xgc:generational_cc", nullptr));
139
140 RuntimeArgumentMap map;
141 bool parsed = ParsedOptions::Parse(options, false, &map);
142 ASSERT_TRUE(parsed);
143 ASSERT_NE(0u, map.Size());
144
145 using Opt = RuntimeArgumentMap;
146
147 EXPECT_TRUE(map.Exists(Opt::GcOption));
148
149 XGcOption xgc = map.GetOrDefault(Opt::GcOption);
150 ASSERT_TRUE(xgc.generational_cc);
151}
152
Andreas Gampea00f0122015-12-16 16:54:35 -0800153TEST_F(ParsedOptionsTest, ParsedOptionsInstructionSet) {
154 using Opt = RuntimeArgumentMap;
155
156 {
157 // Nothing set, should be kRuntimeISA.
158 RuntimeOptions options;
159 RuntimeArgumentMap map;
160 bool parsed = ParsedOptions::Parse(options, false, &map);
161 ASSERT_TRUE(parsed);
162 InstructionSet isa = map.GetOrDefault(Opt::ImageInstructionSet);
163 EXPECT_EQ(kRuntimeISA, isa);
164 }
165
Vladimir Marko41b605c2020-02-12 10:52:22 +0000166 const char* isa_strings[] = { "arm", "arm64", "x86", "x86_64" };
Andreas Gampea00f0122015-12-16 16:54:35 -0800167 InstructionSet ISAs[] = { InstructionSet::kArm,
168 InstructionSet::kArm64,
169 InstructionSet::kX86,
Vladimir Marko41b605c2020-02-12 10:52:22 +0000170 InstructionSet::kX86_64 };
Andreas Gampea00f0122015-12-16 16:54:35 -0800171 static_assert(arraysize(isa_strings) == arraysize(ISAs), "Need same amount.");
172
173 for (size_t i = 0; i < arraysize(isa_strings); ++i) {
174 RuntimeOptions options;
175 options.push_back(std::make_pair("imageinstructionset", isa_strings[i]));
176 RuntimeArgumentMap map;
177 bool parsed = ParsedOptions::Parse(options, false, &map);
178 ASSERT_TRUE(parsed);
179 InstructionSet isa = map.GetOrDefault(Opt::ImageInstructionSet);
180 EXPECT_EQ(ISAs[i], isa);
181 }
182}
Igor Murashkin2798da12015-02-06 17:59:39 -0800183
Brian Carlstromf734cf52011-08-17 16:28:14 -0700184} // namespace art