blob: a52e16328acbf898035e74fb5f4df7791d80aa22 [file] [log] [blame]
Igor Murashkinaaebaa02015-01-26 10:55:53 -08001/*
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 "cmdline_parser.h"
Igor Murashkinaaebaa02015-01-26 10:55:53 -080018
Igor Murashkinaaebaa02015-01-26 10:55:53 -080019#include <numeric>
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070020
Igor Murashkinaaebaa02015-01-26 10:55:53 -080021#include "gtest/gtest.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070022
David Sehrc431b9d2018-03-02 12:01:51 -080023#include "base/mutex.h"
24#include "base/utils.h"
Alex Light40320712017-12-14 11:52:04 -080025#include "jdwp_provider.h"
Andreas Gampe2c30e4a2017-08-23 11:31:32 -070026#include "experimental_flags.h"
27#include "parsed_options.h"
28#include "runtime.h"
29#include "runtime_options.h"
Igor Murashkinaaebaa02015-01-26 10:55:53 -080030
31#define EXPECT_NULL(expected) EXPECT_EQ(reinterpret_cast<const void*>(expected), \
Mathieu Chartier2cebb242015-04-21 16:50:40 -070032 reinterpret_cast<void*>(nullptr));
Igor Murashkinaaebaa02015-01-26 10:55:53 -080033
34namespace art {
35 bool UsuallyEquals(double expected, double actual);
36
37 // This has a gtest dependency, which is why it's in the gtest only.
Calin Juravle138dbff2016-06-28 19:36:58 +010038 bool operator==(const ProfileSaverOptions& lhs, const ProfileSaverOptions& rhs) {
Igor Murashkinaaebaa02015-01-26 10:55:53 -080039 return lhs.enabled_ == rhs.enabled_ &&
Calin Juravle138dbff2016-06-28 19:36:58 +010040 lhs.min_save_period_ms_ == rhs.min_save_period_ms_ &&
41 lhs.save_resolved_classes_delay_ms_ == rhs.save_resolved_classes_delay_ms_ &&
Mathieu Chartier7b135c82017-06-05 12:54:01 -070042 lhs.hot_startup_method_samples_ == rhs.hot_startup_method_samples_ &&
Calin Juravle138dbff2016-06-28 19:36:58 +010043 lhs.min_methods_to_save_ == rhs.min_methods_to_save_ &&
44 lhs.min_classes_to_save_ == rhs.min_classes_to_save_ &&
45 lhs.min_notification_before_wake_ == rhs.min_notification_before_wake_ &&
46 lhs.max_notification_before_wake_ == rhs.max_notification_before_wake_;
Igor Murashkinaaebaa02015-01-26 10:55:53 -080047 }
48
49 bool UsuallyEquals(double expected, double actual) {
50 using FloatingPoint = ::testing::internal::FloatingPoint<double>;
51
52 FloatingPoint exp(expected);
53 FloatingPoint act(actual);
54
55 // Compare with ULPs instead of comparing with ==
56 return exp.AlmostEquals(act);
57 }
58
59 template <typename T>
60 bool UsuallyEquals(const T& expected, const T& actual,
61 typename std::enable_if<
62 detail::SupportsEqualityOperator<T>::value>::type* = 0) {
63 return expected == actual;
64 }
65
66 // Try to use memcmp to compare simple plain-old-data structs.
67 //
68 // This should *not* generate false positives, but it can generate false negatives.
69 // This will mostly work except for fields like float which can have different bit patterns
70 // that are nevertheless equal.
71 // If a test is failing because the structs aren't "equal" when they really are
72 // then it's recommended to implement operator== for it instead.
73 template <typename T, typename ... Ignore>
74 bool UsuallyEquals(const T& expected, const T& actual,
75 const Ignore& ... more ATTRIBUTE_UNUSED,
76 typename std::enable_if<std::is_pod<T>::value>::type* = 0,
77 typename std::enable_if<!detail::SupportsEqualityOperator<T>::value>::type* = 0
78 ) {
79 return memcmp(std::addressof(expected), std::addressof(actual), sizeof(T)) == 0;
80 }
81
82 bool UsuallyEquals(const XGcOption& expected, const XGcOption& actual) {
83 return memcmp(std::addressof(expected), std::addressof(actual), sizeof(expected)) == 0;
84 }
85
Andreas Gampeca620d72016-11-08 08:09:33 -080086 bool UsuallyEquals(const char* expected, const std::string& actual) {
Igor Murashkinaaebaa02015-01-26 10:55:53 -080087 return std::string(expected) == actual;
88 }
89
90 template <typename TMap, typename TKey, typename T>
91 ::testing::AssertionResult IsExpectedKeyValue(const T& expected,
92 const TMap& map,
93 const TKey& key) {
94 auto* actual = map.Get(key);
95 if (actual != nullptr) {
96 if (!UsuallyEquals(expected, *actual)) {
97 return ::testing::AssertionFailure()
98 << "expected " << detail::ToStringAny(expected) << " but got "
99 << detail::ToStringAny(*actual);
100 }
101 return ::testing::AssertionSuccess();
102 }
103
104 return ::testing::AssertionFailure() << "key was not in the map";
105 }
106
Igor Murashkin158f35c2015-06-10 15:55:30 -0700107 template <typename TMap, typename TKey, typename T>
108 ::testing::AssertionResult IsExpectedDefaultKeyValue(const T& expected,
109 const TMap& map,
110 const TKey& key) {
111 const T& actual = map.GetOrDefault(key);
112 if (!UsuallyEquals(expected, actual)) {
113 return ::testing::AssertionFailure()
114 << "expected " << detail::ToStringAny(expected) << " but got "
115 << detail::ToStringAny(actual);
116 }
117 return ::testing::AssertionSuccess();
118 }
119
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800120class CmdlineParserTest : public ::testing::Test {
121 public:
122 CmdlineParserTest() = default;
123 ~CmdlineParserTest() = default;
124
125 protected:
126 using M = RuntimeArgumentMap;
127 using RuntimeParser = ParsedOptions::RuntimeParser;
128
129 static void SetUpTestCase() {
David Sehrc431b9d2018-03-02 12:01:51 -0800130 art::Locks::Init();
Andreas Gampe51d80cc2017-06-21 21:05:13 -0700131 art::InitLogging(nullptr, art::Runtime::Abort); // argv = null
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800132 }
133
134 virtual void SetUp() {
135 parser_ = ParsedOptions::MakeParser(false); // do not ignore unrecognized options
136 }
137
Andreas Gampeca620d72016-11-08 08:09:33 -0800138 static ::testing::AssertionResult IsResultSuccessful(const CmdlineResult& result) {
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800139 if (result.IsSuccess()) {
140 return ::testing::AssertionSuccess();
141 } else {
142 return ::testing::AssertionFailure()
143 << result.GetStatus() << " with: " << result.GetMessage();
144 }
145 }
146
Andreas Gampeca620d72016-11-08 08:09:33 -0800147 static ::testing::AssertionResult IsResultFailure(const CmdlineResult& result,
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800148 CmdlineResult::Status failure_status) {
149 if (result.IsSuccess()) {
150 return ::testing::AssertionFailure() << " got success but expected failure: "
151 << failure_status;
152 } else if (result.GetStatus() == failure_status) {
153 return ::testing::AssertionSuccess();
154 }
155
156 return ::testing::AssertionFailure() << " expected failure " << failure_status
157 << " but got " << result.GetStatus();
158 }
159
160 std::unique_ptr<RuntimeParser> parser_;
161};
162
163#define EXPECT_KEY_EXISTS(map, key) EXPECT_TRUE((map).Exists(key))
164#define EXPECT_KEY_VALUE(map, key, expected) EXPECT_TRUE(IsExpectedKeyValue(expected, map, key))
Igor Murashkin158f35c2015-06-10 15:55:30 -0700165#define EXPECT_DEFAULT_KEY_VALUE(map, key, expected) EXPECT_TRUE(IsExpectedDefaultKeyValue(expected, map, key))
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800166
Igor Murashkin158f35c2015-06-10 15:55:30 -0700167#define _EXPECT_SINGLE_PARSE_EMPTY_SUCCESS(argv) \
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800168 do { \
169 EXPECT_TRUE(IsResultSuccessful(parser_->Parse(argv))); \
170 EXPECT_EQ(0u, parser_->GetArgumentsMap().Size()); \
Igor Murashkin158f35c2015-06-10 15:55:30 -0700171
172#define EXPECT_SINGLE_PARSE_EMPTY_SUCCESS(argv) \
173 _EXPECT_SINGLE_PARSE_EMPTY_SUCCESS(argv); \
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800174 } while (false)
175
Igor Murashkin158f35c2015-06-10 15:55:30 -0700176#define EXPECT_SINGLE_PARSE_DEFAULT_VALUE(expected, argv, key)\
177 _EXPECT_SINGLE_PARSE_EMPTY_SUCCESS(argv); \
178 RuntimeArgumentMap args = parser_->ReleaseArgumentsMap(); \
179 EXPECT_DEFAULT_KEY_VALUE(args, key, expected); \
180 } while (false) // NOLINT [readability/namespace] [5]
181
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800182#define _EXPECT_SINGLE_PARSE_EXISTS(argv, key) \
183 do { \
184 EXPECT_TRUE(IsResultSuccessful(parser_->Parse(argv))); \
185 RuntimeArgumentMap args = parser_->ReleaseArgumentsMap(); \
186 EXPECT_EQ(1u, args.Size()); \
187 EXPECT_KEY_EXISTS(args, key); \
188
189#define EXPECT_SINGLE_PARSE_EXISTS(argv, key) \
190 _EXPECT_SINGLE_PARSE_EXISTS(argv, key); \
191 } while (false)
192
193#define EXPECT_SINGLE_PARSE_VALUE(expected, argv, key) \
194 _EXPECT_SINGLE_PARSE_EXISTS(argv, key); \
195 EXPECT_KEY_VALUE(args, key, expected); \
Igor Murashkin5573c372017-11-16 13:34:30 -0800196 } while (false)
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800197
198#define EXPECT_SINGLE_PARSE_VALUE_STR(expected, argv, key) \
199 EXPECT_SINGLE_PARSE_VALUE(std::string(expected), argv, key)
200
201#define EXPECT_SINGLE_PARSE_FAIL(argv, failure_status) \
202 do { \
203 EXPECT_TRUE(IsResultFailure(parser_->Parse(argv), failure_status));\
204 RuntimeArgumentMap args = parser_->ReleaseArgumentsMap();\
205 EXPECT_EQ(0u, args.Size()); \
206 } while (false)
207
208TEST_F(CmdlineParserTest, TestSimpleSuccesses) {
209 auto& parser = *parser_;
210
211 EXPECT_LT(0u, parser.CountDefinedArguments());
212
213 {
214 // Test case 1: No command line arguments
215 EXPECT_TRUE(IsResultSuccessful(parser.Parse("")));
216 RuntimeArgumentMap args = parser.ReleaseArgumentsMap();
217 EXPECT_EQ(0u, args.Size());
218 }
219
220 EXPECT_SINGLE_PARSE_EXISTS("-Xzygote", M::Zygote);
221 EXPECT_SINGLE_PARSE_VALUE_STR("/hello/world", "-Xbootclasspath:/hello/world", M::BootClassPath);
222 EXPECT_SINGLE_PARSE_VALUE("/hello/world", "-Xbootclasspath:/hello/world", M::BootClassPath);
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800223 EXPECT_SINGLE_PARSE_VALUE(Memory<1>(234), "-Xss234", M::StackSize);
224 EXPECT_SINGLE_PARSE_VALUE(MemoryKiB(1234*MB), "-Xms1234m", M::MemoryInitialSize);
225 EXPECT_SINGLE_PARSE_VALUE(true, "-XX:EnableHSpaceCompactForOOM", M::EnableHSpaceCompactForOOM);
226 EXPECT_SINGLE_PARSE_VALUE(false, "-XX:DisableHSpaceCompactForOOM", M::EnableHSpaceCompactForOOM);
227 EXPECT_SINGLE_PARSE_VALUE(0.5, "-XX:HeapTargetUtilization=0.5", M::HeapTargetUtilization);
228 EXPECT_SINGLE_PARSE_VALUE(5u, "-XX:ParallelGCThreads=5", M::ParallelGCThreads);
Jean Christophe Beyler24e04aa2014-09-12 12:03:25 -0700229 EXPECT_SINGLE_PARSE_EXISTS("-Xno-dex-file-fallback", M::NoDexFileFallback);
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800230} // TEST_F
231
232TEST_F(CmdlineParserTest, TestSimpleFailures) {
233 // Test argument is unknown to the parser
234 EXPECT_SINGLE_PARSE_FAIL("abcdefg^%@#*(@#", CmdlineResult::kUnknown);
235 // Test value map substitution fails
236 EXPECT_SINGLE_PARSE_FAIL("-Xverify:whatever", CmdlineResult::kFailure);
237 // Test value type parsing failures
238 EXPECT_SINGLE_PARSE_FAIL("-Xsswhatever", CmdlineResult::kFailure); // invalid memory value
239 EXPECT_SINGLE_PARSE_FAIL("-Xms123", CmdlineResult::kFailure); // memory value too small
240 EXPECT_SINGLE_PARSE_FAIL("-XX:HeapTargetUtilization=0.0", CmdlineResult::kOutOfRange); // toosmal
241 EXPECT_SINGLE_PARSE_FAIL("-XX:HeapTargetUtilization=2.0", CmdlineResult::kOutOfRange); // toolarg
242 EXPECT_SINGLE_PARSE_FAIL("-XX:ParallelGCThreads=-5", CmdlineResult::kOutOfRange); // too small
243 EXPECT_SINGLE_PARSE_FAIL("-Xgc:blablabla", CmdlineResult::kUsage); // not a valid suboption
244} // TEST_F
245
246TEST_F(CmdlineParserTest, TestLogVerbosity) {
247 {
248 const char* log_args = "-verbose:"
Phil Wang751beff2015-08-28 15:17:15 +0800249 "class,compiler,gc,heap,jdwp,jni,monitor,profiler,signals,simulator,startup,"
Andreas Gampe92d77202017-12-06 20:49:00 -0800250 "third-party-jni,threads,verifier,verifier-debug";
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800251
252 LogVerbosity log_verbosity = LogVerbosity();
253 log_verbosity.class_linker = true;
254 log_verbosity.compiler = true;
255 log_verbosity.gc = true;
256 log_verbosity.heap = true;
257 log_verbosity.jdwp = true;
258 log_verbosity.jni = true;
259 log_verbosity.monitor = true;
260 log_verbosity.profiler = true;
261 log_verbosity.signals = true;
Phil Wang751beff2015-08-28 15:17:15 +0800262 log_verbosity.simulator = true;
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800263 log_verbosity.startup = true;
264 log_verbosity.third_party_jni = true;
265 log_verbosity.threads = true;
266 log_verbosity.verifier = true;
Andreas Gampe92d77202017-12-06 20:49:00 -0800267 log_verbosity.verifier_debug = true;
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800268
269 EXPECT_SINGLE_PARSE_VALUE(log_verbosity, log_args, M::Verbose);
270 }
271
272 {
273 const char* log_args = "-verbose:"
274 "class,compiler,gc,heap,jdwp,jni,monitor";
275
276 LogVerbosity log_verbosity = LogVerbosity();
277 log_verbosity.class_linker = true;
278 log_verbosity.compiler = true;
279 log_verbosity.gc = true;
280 log_verbosity.heap = true;
281 log_verbosity.jdwp = true;
282 log_verbosity.jni = true;
283 log_verbosity.monitor = true;
284
285 EXPECT_SINGLE_PARSE_VALUE(log_verbosity, log_args, M::Verbose);
286 }
287
288 EXPECT_SINGLE_PARSE_FAIL("-verbose:blablabla", CmdlineResult::kUsage); // invalid verbose opt
Richard Uhler66d874d2015-01-15 09:37:19 -0800289
290 {
Sebastien Hertzbba348e2015-06-01 08:28:18 +0200291 const char* log_args = "-verbose:deopt";
292 LogVerbosity log_verbosity = LogVerbosity();
293 log_verbosity.deopt = true;
294 EXPECT_SINGLE_PARSE_VALUE(log_verbosity, log_args, M::Verbose);
295 }
296
297 {
Mathieu Chartier66a55392016-02-19 10:25:39 -0800298 const char* log_args = "-verbose:collector";
299 LogVerbosity log_verbosity = LogVerbosity();
300 log_verbosity.collector = true;
301 EXPECT_SINGLE_PARSE_VALUE(log_verbosity, log_args, M::Verbose);
302 }
303
304 {
Richard Uhler66d874d2015-01-15 09:37:19 -0800305 const char* log_args = "-verbose:oat";
306 LogVerbosity log_verbosity = LogVerbosity();
307 log_verbosity.oat = true;
308 EXPECT_SINGLE_PARSE_VALUE(log_verbosity, log_args, M::Verbose);
309 }
Andreas Gampebec07a02017-04-11 13:48:37 -0700310
311 {
312 const char* log_args = "-verbose:dex";
313 LogVerbosity log_verbosity = LogVerbosity();
314 log_verbosity.dex = true;
315 EXPECT_SINGLE_PARSE_VALUE(log_verbosity, log_args, M::Verbose);
316 }
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800317} // TEST_F
318
Nicolas Geoffray8f4ee5c2015-02-05 10:14:10 +0000319// TODO: Enable this b/19274810
320TEST_F(CmdlineParserTest, DISABLED_TestXGcOption) {
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800321 /*
322 * Test success
323 */
324 {
Igor Murashkin5573c372017-11-16 13:34:30 -0800325 XGcOption option_all_true{};
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800326 option_all_true.collector_type_ = gc::CollectorType::kCollectorTypeCMS;
327 option_all_true.verify_pre_gc_heap_ = true;
328 option_all_true.verify_pre_sweeping_heap_ = true;
329 option_all_true.verify_post_gc_heap_ = true;
330 option_all_true.verify_pre_gc_rosalloc_ = true;
331 option_all_true.verify_pre_sweeping_rosalloc_ = true;
332 option_all_true.verify_post_gc_rosalloc_ = true;
333
334 const char * xgc_args_all_true = "-Xgc:concurrent,"
335 "preverify,presweepingverify,postverify,"
336 "preverify_rosalloc,presweepingverify_rosalloc,"
337 "postverify_rosalloc,precise,"
338 "verifycardtable";
339
340 EXPECT_SINGLE_PARSE_VALUE(option_all_true, xgc_args_all_true, M::GcOption);
341
Igor Murashkin5573c372017-11-16 13:34:30 -0800342 XGcOption option_all_false{};
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800343 option_all_false.collector_type_ = gc::CollectorType::kCollectorTypeMS;
344 option_all_false.verify_pre_gc_heap_ = false;
345 option_all_false.verify_pre_sweeping_heap_ = false;
346 option_all_false.verify_post_gc_heap_ = false;
347 option_all_false.verify_pre_gc_rosalloc_ = false;
348 option_all_false.verify_pre_sweeping_rosalloc_ = false;
349 option_all_false.verify_post_gc_rosalloc_ = false;
350
351 const char* xgc_args_all_false = "-Xgc:nonconcurrent,"
352 "nopreverify,nopresweepingverify,nopostverify,nopreverify_rosalloc,"
353 "nopresweepingverify_rosalloc,nopostverify_rosalloc,noprecise,noverifycardtable";
354
355 EXPECT_SINGLE_PARSE_VALUE(option_all_false, xgc_args_all_false, M::GcOption);
356
Igor Murashkin5573c372017-11-16 13:34:30 -0800357 XGcOption option_all_default{};
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800358
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800359 const char* xgc_args_blank = "-Xgc:";
360 EXPECT_SINGLE_PARSE_VALUE(option_all_default, xgc_args_blank, M::GcOption);
361 }
362
363 /*
364 * Test failures
365 */
366 EXPECT_SINGLE_PARSE_FAIL("-Xgc:blablabla", CmdlineResult::kUsage); // invalid Xgc opt
367} // TEST_F
368
369/*
Alex Light40320712017-12-14 11:52:04 -0800370 * { "-XjdwpProvider:_" }
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800371 */
Alex Light40320712017-12-14 11:52:04 -0800372TEST_F(CmdlineParserTest, TestJdwpProviderEmpty) {
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800373 {
Alex Lightbaac7e42018-06-08 15:30:11 +0000374 EXPECT_SINGLE_PARSE_DEFAULT_VALUE(JdwpProvider::kUnset, "", M::JdwpProvider);
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800375 }
Alex Light40320712017-12-14 11:52:04 -0800376} // TEST_F
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800377
Alex Light40320712017-12-14 11:52:04 -0800378TEST_F(CmdlineParserTest, TestJdwpProviderDefault) {
379 const char* opt_args = "-XjdwpProvider:default";
Alex Light2183d4d2018-01-26 14:24:54 -0800380 EXPECT_SINGLE_PARSE_VALUE(JdwpProvider::kDefaultJdwpProvider, opt_args, M::JdwpProvider);
Alex Light40320712017-12-14 11:52:04 -0800381} // TEST_F
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800382
Alex Light40320712017-12-14 11:52:04 -0800383TEST_F(CmdlineParserTest, TestJdwpProviderInternal) {
384 const char* opt_args = "-XjdwpProvider:internal";
385 EXPECT_SINGLE_PARSE_VALUE(JdwpProvider::kInternal, opt_args, M::JdwpProvider);
386} // TEST_F
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800387
Alex Light40320712017-12-14 11:52:04 -0800388TEST_F(CmdlineParserTest, TestJdwpProviderNone) {
389 const char* opt_args = "-XjdwpProvider:none";
390 EXPECT_SINGLE_PARSE_VALUE(JdwpProvider::kNone, opt_args, M::JdwpProvider);
391} // TEST_F
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800392
Alex Lightfbf96702017-12-14 13:27:13 -0800393TEST_F(CmdlineParserTest, TestJdwpProviderAdbconnection) {
394 const char* opt_args = "-XjdwpProvider:adbconnection";
395 EXPECT_SINGLE_PARSE_VALUE(JdwpProvider::kAdbConnection, opt_args, M::JdwpProvider);
396} // TEST_F
397
Alex Light40320712017-12-14 11:52:04 -0800398TEST_F(CmdlineParserTest, TestJdwpProviderHelp) {
399 EXPECT_SINGLE_PARSE_FAIL("-XjdwpProvider:help", CmdlineResult::kUsage);
400} // TEST_F
401
402TEST_F(CmdlineParserTest, TestJdwpProviderFail) {
403 EXPECT_SINGLE_PARSE_FAIL("-XjdwpProvider:blablabla", CmdlineResult::kFailure);
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800404} // TEST_F
405
406/*
407 * -D_ -D_ -D_ ...
408 */
409TEST_F(CmdlineParserTest, TestPropertiesList) {
410 /*
411 * Test successes
412 */
413 {
414 std::vector<std::string> opt = {"hello"};
415
416 EXPECT_SINGLE_PARSE_VALUE(opt, "-Dhello", M::PropertiesList);
417 }
418
419 {
420 std::vector<std::string> opt = {"hello", "world"};
421
422 EXPECT_SINGLE_PARSE_VALUE(opt, "-Dhello -Dworld", M::PropertiesList);
423 }
424
425 {
426 std::vector<std::string> opt = {"one", "two", "three"};
427
428 EXPECT_SINGLE_PARSE_VALUE(opt, "-Done -Dtwo -Dthree", M::PropertiesList);
429 }
430} // TEST_F
431
432/*
433* -Xcompiler-option foo -Xcompiler-option bar ...
434*/
435TEST_F(CmdlineParserTest, TestCompilerOption) {
436 /*
437 * Test successes
438 */
439 {
440 std::vector<std::string> opt = {"hello"};
441 EXPECT_SINGLE_PARSE_VALUE(opt, "-Xcompiler-option hello", M::CompilerOptions);
442 }
443
444 {
445 std::vector<std::string> opt = {"hello", "world"};
446 EXPECT_SINGLE_PARSE_VALUE(opt,
447 "-Xcompiler-option hello -Xcompiler-option world",
448 M::CompilerOptions);
449 }
450
451 {
452 std::vector<std::string> opt = {"one", "two", "three"};
453 EXPECT_SINGLE_PARSE_VALUE(opt,
454 "-Xcompiler-option one -Xcompiler-option two -Xcompiler-option three",
455 M::CompilerOptions);
456 }
457} // TEST_F
458
459/*
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800460* -Xjit, -Xnojit, -Xjitcodecachesize, Xjitcompilethreshold
461*/
462TEST_F(CmdlineParserTest, TestJitOptions) {
463 /*
464 * Test successes
465 */
466 {
Calin Juravleffc87072016-04-20 14:22:09 +0100467 EXPECT_SINGLE_PARSE_VALUE(true, "-Xusejit:true", M::UseJitCompilation);
468 EXPECT_SINGLE_PARSE_VALUE(false, "-Xusejit:false", M::UseJitCompilation);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800469 }
470 {
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000471 EXPECT_SINGLE_PARSE_VALUE(
Nicolas Geoffray295a5962015-11-19 18:17:41 +0000472 MemoryKiB(16 * KB), "-Xjitinitialsize:16K", M::JITCodeCacheInitialCapacity);
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000473 EXPECT_SINGLE_PARSE_VALUE(
Nicolas Geoffray295a5962015-11-19 18:17:41 +0000474 MemoryKiB(16 * MB), "-Xjitmaxsize:16M", M::JITCodeCacheMaxCapacity);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800475 }
476 {
477 EXPECT_SINGLE_PARSE_VALUE(12345u, "-Xjitthreshold:12345", M::JITCompileThreshold);
478 }
479} // TEST_F
480
481/*
Calin Juravle138dbff2016-06-28 19:36:58 +0100482* -Xps-*
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800483*/
Calin Juravle138dbff2016-06-28 19:36:58 +0100484TEST_F(CmdlineParserTest, ProfileSaverOptions) {
Mathieu Chartier885a7132017-06-10 14:35:11 -0700485 ProfileSaverOptions opt = ProfileSaverOptions(true, 1, 2, 3, 4, 5, 6, 7, "abc", true);
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800486
Calin Juravle138dbff2016-06-28 19:36:58 +0100487 EXPECT_SINGLE_PARSE_VALUE(opt,
488 "-Xjitsaveprofilinginfo "
489 "-Xps-min-save-period-ms:1 "
490 "-Xps-save-resolved-classes-delay-ms:2 "
Mathieu Chartier7b135c82017-06-05 12:54:01 -0700491 "-Xps-hot-startup-method-samples:3 "
Calin Juravle138dbff2016-06-28 19:36:58 +0100492 "-Xps-min-methods-to-save:4 "
493 "-Xps-min-classes-to-save:5 "
494 "-Xps-min-notification-before-wake:6 "
Calin Juravle9545f6d2017-03-16 19:05:09 -0700495 "-Xps-max-notification-before-wake:7 "
Mathieu Chartier885a7132017-06-10 14:35:11 -0700496 "-Xps-profile-path:abc "
497 "-Xps-profile-boot-class-path",
Calin Juravle138dbff2016-06-28 19:36:58 +0100498 M::ProfileSaverOpts);
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800499} // TEST_F
500
Alex Lighteb7c1442015-08-31 13:17:42 -0700501/* -Xexperimental:_ */
502TEST_F(CmdlineParserTest, TestExperimentalFlags) {
Neil Fuller9724c632016-01-07 15:42:47 +0000503 // Default
Alex Lighteb7c1442015-08-31 13:17:42 -0700504 EXPECT_SINGLE_PARSE_DEFAULT_VALUE(ExperimentalFlags::kNone,
Igor Murashkin158f35c2015-06-10 15:55:30 -0700505 "",
Alex Lighteb7c1442015-08-31 13:17:42 -0700506 M::Experimental);
Igor Murashkin158f35c2015-06-10 15:55:30 -0700507
508 // Disabled explicitly
Alex Lighteb7c1442015-08-31 13:17:42 -0700509 EXPECT_SINGLE_PARSE_VALUE(ExperimentalFlags::kNone,
510 "-Xexperimental:none",
511 M::Experimental);
Igor Murashkin158f35c2015-06-10 15:55:30 -0700512}
513
Igor Murashkin7617abd2015-07-10 18:27:47 -0700514// -Xverify:_
515TEST_F(CmdlineParserTest, TestVerify) {
516 EXPECT_SINGLE_PARSE_VALUE(verifier::VerifyMode::kNone, "-Xverify:none", M::Verify);
517 EXPECT_SINGLE_PARSE_VALUE(verifier::VerifyMode::kEnable, "-Xverify:remote", M::Verify);
518 EXPECT_SINGLE_PARSE_VALUE(verifier::VerifyMode::kEnable, "-Xverify:all", M::Verify);
519 EXPECT_SINGLE_PARSE_VALUE(verifier::VerifyMode::kSoftFail, "-Xverify:softfail", M::Verify);
520}
521
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800522TEST_F(CmdlineParserTest, TestIgnoreUnrecognized) {
523 RuntimeParser::Builder parserBuilder;
524
525 parserBuilder
526 .Define("-help")
527 .IntoKey(M::Help)
528 .IgnoreUnrecognized(true);
529
530 parser_.reset(new RuntimeParser(parserBuilder.Build()));
531
532 EXPECT_SINGLE_PARSE_EMPTY_SUCCESS("-non-existent-option");
533 EXPECT_SINGLE_PARSE_EMPTY_SUCCESS("-non-existent-option1 --non-existent-option-2");
534} // TEST_F
535
536TEST_F(CmdlineParserTest, TestIgnoredArguments) {
537 std::initializer_list<const char*> ignored_args = {
538 "-ea", "-da", "-enableassertions", "-disableassertions", "--runtime-arg", "-esa",
539 "-dsa", "-enablesystemassertions", "-disablesystemassertions", "-Xrs", "-Xint:abdef",
540 "-Xdexopt:foobar", "-Xnoquithandler", "-Xjnigreflimit:ixnay", "-Xgenregmap", "-Xnogenregmap",
541 "-Xverifyopt:never", "-Xcheckdexsum", "-Xincludeselectedop", "-Xjitop:noop",
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800542 "-Xincludeselectedmethod", "-Xjitblocking", "-Xjitmethod:_", "-Xjitclass:nosuchluck",
543 "-Xjitoffset:none", "-Xjitconfig:yes", "-Xjitcheckcg", "-Xjitverbose", "-Xjitprofile",
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800544 "-Xjitdisableopt", "-Xjitsuspendpoll", "-XX:mainThreadStackSize=1337"
545 };
546
547 // Check they are ignored when parsed one at a time
548 for (auto&& arg : ignored_args) {
549 SCOPED_TRACE(arg);
550 EXPECT_SINGLE_PARSE_EMPTY_SUCCESS(arg);
551 }
552
553 // Check they are ignored when we pass it all together at once
554 std::vector<const char*> argv = ignored_args;
555 EXPECT_SINGLE_PARSE_EMPTY_SUCCESS(argv);
556} // TEST_F
557
558TEST_F(CmdlineParserTest, MultipleArguments) {
559 EXPECT_TRUE(IsResultSuccessful(parser_->Parse(
560 "-help -XX:ForegroundHeapGrowthMultiplier=0.5 "
561 "-Xnodex2oat -Xmethod-trace -XX:LargeObjectSpace=map")));
562
563 auto&& map = parser_->ReleaseArgumentsMap();
564 EXPECT_EQ(5u, map.Size());
Igor Murashkin5573c372017-11-16 13:34:30 -0800565 EXPECT_KEY_VALUE(map, M::Help, Unit{});
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800566 EXPECT_KEY_VALUE(map, M::ForegroundHeapGrowthMultiplier, 0.5);
567 EXPECT_KEY_VALUE(map, M::Dex2Oat, false);
Igor Murashkin5573c372017-11-16 13:34:30 -0800568 EXPECT_KEY_VALUE(map, M::MethodTrace, Unit{});
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800569 EXPECT_KEY_VALUE(map, M::LargeObjectSpace, gc::space::LargeObjectSpaceType::kMap);
570} // TEST_F
571} // namespace art