blob: d957869a7616a439cc5f33e41c02dcc0ff7a1587 [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"
18#include "runtime/runtime_options.h"
19#include "runtime/parsed_options.h"
20
21#include "utils.h"
22#include <numeric>
23#include "gtest/gtest.h"
Alex Lighteb7c1442015-08-31 13:17:42 -070024#include "runtime/experimental_flags.h"
Andreas Gamped482e732017-04-24 17:59:09 -070025#include "runtime/runtime.h"
Igor Murashkinaaebaa02015-01-26 10:55:53 -080026
27#define EXPECT_NULL(expected) EXPECT_EQ(reinterpret_cast<const void*>(expected), \
Mathieu Chartier2cebb242015-04-21 16:50:40 -070028 reinterpret_cast<void*>(nullptr));
Igor Murashkinaaebaa02015-01-26 10:55:53 -080029
30namespace art {
31 bool UsuallyEquals(double expected, double actual);
32
33 // This has a gtest dependency, which is why it's in the gtest only.
Calin Juravle138dbff2016-06-28 19:36:58 +010034 bool operator==(const ProfileSaverOptions& lhs, const ProfileSaverOptions& rhs) {
Igor Murashkinaaebaa02015-01-26 10:55:53 -080035 return lhs.enabled_ == rhs.enabled_ &&
Calin Juravle138dbff2016-06-28 19:36:58 +010036 lhs.min_save_period_ms_ == rhs.min_save_period_ms_ &&
37 lhs.save_resolved_classes_delay_ms_ == rhs.save_resolved_classes_delay_ms_ &&
Mathieu Chartier7b135c82017-06-05 12:54:01 -070038 lhs.hot_startup_method_samples_ == rhs.hot_startup_method_samples_ &&
Calin Juravle138dbff2016-06-28 19:36:58 +010039 lhs.min_methods_to_save_ == rhs.min_methods_to_save_ &&
40 lhs.min_classes_to_save_ == rhs.min_classes_to_save_ &&
41 lhs.min_notification_before_wake_ == rhs.min_notification_before_wake_ &&
42 lhs.max_notification_before_wake_ == rhs.max_notification_before_wake_;
Igor Murashkinaaebaa02015-01-26 10:55:53 -080043 }
44
45 bool UsuallyEquals(double expected, double actual) {
46 using FloatingPoint = ::testing::internal::FloatingPoint<double>;
47
48 FloatingPoint exp(expected);
49 FloatingPoint act(actual);
50
51 // Compare with ULPs instead of comparing with ==
52 return exp.AlmostEquals(act);
53 }
54
55 template <typename T>
56 bool UsuallyEquals(const T& expected, const T& actual,
57 typename std::enable_if<
58 detail::SupportsEqualityOperator<T>::value>::type* = 0) {
59 return expected == actual;
60 }
61
62 // Try to use memcmp to compare simple plain-old-data structs.
63 //
64 // This should *not* generate false positives, but it can generate false negatives.
65 // This will mostly work except for fields like float which can have different bit patterns
66 // that are nevertheless equal.
67 // If a test is failing because the structs aren't "equal" when they really are
68 // then it's recommended to implement operator== for it instead.
69 template <typename T, typename ... Ignore>
70 bool UsuallyEquals(const T& expected, const T& actual,
71 const Ignore& ... more ATTRIBUTE_UNUSED,
72 typename std::enable_if<std::is_pod<T>::value>::type* = 0,
73 typename std::enable_if<!detail::SupportsEqualityOperator<T>::value>::type* = 0
74 ) {
75 return memcmp(std::addressof(expected), std::addressof(actual), sizeof(T)) == 0;
76 }
77
78 bool UsuallyEquals(const XGcOption& expected, const XGcOption& actual) {
79 return memcmp(std::addressof(expected), std::addressof(actual), sizeof(expected)) == 0;
80 }
81
Andreas Gampeca620d72016-11-08 08:09:33 -080082 bool UsuallyEquals(const char* expected, const std::string& actual) {
Igor Murashkinaaebaa02015-01-26 10:55:53 -080083 return std::string(expected) == actual;
84 }
85
86 template <typename TMap, typename TKey, typename T>
87 ::testing::AssertionResult IsExpectedKeyValue(const T& expected,
88 const TMap& map,
89 const TKey& key) {
90 auto* actual = map.Get(key);
91 if (actual != nullptr) {
92 if (!UsuallyEquals(expected, *actual)) {
93 return ::testing::AssertionFailure()
94 << "expected " << detail::ToStringAny(expected) << " but got "
95 << detail::ToStringAny(*actual);
96 }
97 return ::testing::AssertionSuccess();
98 }
99
100 return ::testing::AssertionFailure() << "key was not in the map";
101 }
102
Igor Murashkin158f35c2015-06-10 15:55:30 -0700103 template <typename TMap, typename TKey, typename T>
104 ::testing::AssertionResult IsExpectedDefaultKeyValue(const T& expected,
105 const TMap& map,
106 const TKey& key) {
107 const T& actual = map.GetOrDefault(key);
108 if (!UsuallyEquals(expected, actual)) {
109 return ::testing::AssertionFailure()
110 << "expected " << detail::ToStringAny(expected) << " but got "
111 << detail::ToStringAny(actual);
112 }
113 return ::testing::AssertionSuccess();
114 }
115
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800116class CmdlineParserTest : public ::testing::Test {
117 public:
118 CmdlineParserTest() = default;
119 ~CmdlineParserTest() = default;
120
121 protected:
122 using M = RuntimeArgumentMap;
123 using RuntimeParser = ParsedOptions::RuntimeParser;
124
125 static void SetUpTestCase() {
Andreas Gampe51d80cc2017-06-21 21:05:13 -0700126 art::InitLogging(nullptr, art::Runtime::Abort); // argv = null
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800127 }
128
129 virtual void SetUp() {
130 parser_ = ParsedOptions::MakeParser(false); // do not ignore unrecognized options
131 }
132
Andreas Gampeca620d72016-11-08 08:09:33 -0800133 static ::testing::AssertionResult IsResultSuccessful(const CmdlineResult& result) {
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800134 if (result.IsSuccess()) {
135 return ::testing::AssertionSuccess();
136 } else {
137 return ::testing::AssertionFailure()
138 << result.GetStatus() << " with: " << result.GetMessage();
139 }
140 }
141
Andreas Gampeca620d72016-11-08 08:09:33 -0800142 static ::testing::AssertionResult IsResultFailure(const CmdlineResult& result,
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800143 CmdlineResult::Status failure_status) {
144 if (result.IsSuccess()) {
145 return ::testing::AssertionFailure() << " got success but expected failure: "
146 << failure_status;
147 } else if (result.GetStatus() == failure_status) {
148 return ::testing::AssertionSuccess();
149 }
150
151 return ::testing::AssertionFailure() << " expected failure " << failure_status
152 << " but got " << result.GetStatus();
153 }
154
155 std::unique_ptr<RuntimeParser> parser_;
156};
157
158#define EXPECT_KEY_EXISTS(map, key) EXPECT_TRUE((map).Exists(key))
159#define EXPECT_KEY_VALUE(map, key, expected) EXPECT_TRUE(IsExpectedKeyValue(expected, map, key))
Igor Murashkin158f35c2015-06-10 15:55:30 -0700160#define EXPECT_DEFAULT_KEY_VALUE(map, key, expected) EXPECT_TRUE(IsExpectedDefaultKeyValue(expected, map, key))
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800161
Igor Murashkin158f35c2015-06-10 15:55:30 -0700162#define _EXPECT_SINGLE_PARSE_EMPTY_SUCCESS(argv) \
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800163 do { \
164 EXPECT_TRUE(IsResultSuccessful(parser_->Parse(argv))); \
165 EXPECT_EQ(0u, parser_->GetArgumentsMap().Size()); \
Igor Murashkin158f35c2015-06-10 15:55:30 -0700166
167#define EXPECT_SINGLE_PARSE_EMPTY_SUCCESS(argv) \
168 _EXPECT_SINGLE_PARSE_EMPTY_SUCCESS(argv); \
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800169 } while (false)
170
Igor Murashkin158f35c2015-06-10 15:55:30 -0700171#define EXPECT_SINGLE_PARSE_DEFAULT_VALUE(expected, argv, key)\
172 _EXPECT_SINGLE_PARSE_EMPTY_SUCCESS(argv); \
173 RuntimeArgumentMap args = parser_->ReleaseArgumentsMap(); \
174 EXPECT_DEFAULT_KEY_VALUE(args, key, expected); \
175 } while (false) // NOLINT [readability/namespace] [5]
176
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800177#define _EXPECT_SINGLE_PARSE_EXISTS(argv, key) \
178 do { \
179 EXPECT_TRUE(IsResultSuccessful(parser_->Parse(argv))); \
180 RuntimeArgumentMap args = parser_->ReleaseArgumentsMap(); \
181 EXPECT_EQ(1u, args.Size()); \
182 EXPECT_KEY_EXISTS(args, key); \
183
184#define EXPECT_SINGLE_PARSE_EXISTS(argv, key) \
185 _EXPECT_SINGLE_PARSE_EXISTS(argv, key); \
186 } while (false)
187
188#define EXPECT_SINGLE_PARSE_VALUE(expected, argv, key) \
189 _EXPECT_SINGLE_PARSE_EXISTS(argv, key); \
190 EXPECT_KEY_VALUE(args, key, expected); \
191 } while (false) // NOLINT [readability/namespace] [5]
192
193#define EXPECT_SINGLE_PARSE_VALUE_STR(expected, argv, key) \
194 EXPECT_SINGLE_PARSE_VALUE(std::string(expected), argv, key)
195
196#define EXPECT_SINGLE_PARSE_FAIL(argv, failure_status) \
197 do { \
198 EXPECT_TRUE(IsResultFailure(parser_->Parse(argv), failure_status));\
199 RuntimeArgumentMap args = parser_->ReleaseArgumentsMap();\
200 EXPECT_EQ(0u, args.Size()); \
201 } while (false)
202
203TEST_F(CmdlineParserTest, TestSimpleSuccesses) {
204 auto& parser = *parser_;
205
206 EXPECT_LT(0u, parser.CountDefinedArguments());
207
208 {
209 // Test case 1: No command line arguments
210 EXPECT_TRUE(IsResultSuccessful(parser.Parse("")));
211 RuntimeArgumentMap args = parser.ReleaseArgumentsMap();
212 EXPECT_EQ(0u, args.Size());
213 }
214
215 EXPECT_SINGLE_PARSE_EXISTS("-Xzygote", M::Zygote);
216 EXPECT_SINGLE_PARSE_VALUE_STR("/hello/world", "-Xbootclasspath:/hello/world", M::BootClassPath);
217 EXPECT_SINGLE_PARSE_VALUE("/hello/world", "-Xbootclasspath:/hello/world", M::BootClassPath);
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800218 EXPECT_SINGLE_PARSE_VALUE(Memory<1>(234), "-Xss234", M::StackSize);
219 EXPECT_SINGLE_PARSE_VALUE(MemoryKiB(1234*MB), "-Xms1234m", M::MemoryInitialSize);
220 EXPECT_SINGLE_PARSE_VALUE(true, "-XX:EnableHSpaceCompactForOOM", M::EnableHSpaceCompactForOOM);
221 EXPECT_SINGLE_PARSE_VALUE(false, "-XX:DisableHSpaceCompactForOOM", M::EnableHSpaceCompactForOOM);
222 EXPECT_SINGLE_PARSE_VALUE(0.5, "-XX:HeapTargetUtilization=0.5", M::HeapTargetUtilization);
223 EXPECT_SINGLE_PARSE_VALUE(5u, "-XX:ParallelGCThreads=5", M::ParallelGCThreads);
Jean Christophe Beyler24e04aa2014-09-12 12:03:25 -0700224 EXPECT_SINGLE_PARSE_EXISTS("-Xno-dex-file-fallback", M::NoDexFileFallback);
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800225} // TEST_F
226
227TEST_F(CmdlineParserTest, TestSimpleFailures) {
228 // Test argument is unknown to the parser
229 EXPECT_SINGLE_PARSE_FAIL("abcdefg^%@#*(@#", CmdlineResult::kUnknown);
230 // Test value map substitution fails
231 EXPECT_SINGLE_PARSE_FAIL("-Xverify:whatever", CmdlineResult::kFailure);
232 // Test value type parsing failures
233 EXPECT_SINGLE_PARSE_FAIL("-Xsswhatever", CmdlineResult::kFailure); // invalid memory value
234 EXPECT_SINGLE_PARSE_FAIL("-Xms123", CmdlineResult::kFailure); // memory value too small
235 EXPECT_SINGLE_PARSE_FAIL("-XX:HeapTargetUtilization=0.0", CmdlineResult::kOutOfRange); // toosmal
236 EXPECT_SINGLE_PARSE_FAIL("-XX:HeapTargetUtilization=2.0", CmdlineResult::kOutOfRange); // toolarg
237 EXPECT_SINGLE_PARSE_FAIL("-XX:ParallelGCThreads=-5", CmdlineResult::kOutOfRange); // too small
238 EXPECT_SINGLE_PARSE_FAIL("-Xgc:blablabla", CmdlineResult::kUsage); // not a valid suboption
239} // TEST_F
240
241TEST_F(CmdlineParserTest, TestLogVerbosity) {
242 {
243 const char* log_args = "-verbose:"
Phil Wang751beff2015-08-28 15:17:15 +0800244 "class,compiler,gc,heap,jdwp,jni,monitor,profiler,signals,simulator,startup,"
245 "third-party-jni,threads,verifier";
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800246
247 LogVerbosity log_verbosity = LogVerbosity();
248 log_verbosity.class_linker = true;
249 log_verbosity.compiler = true;
250 log_verbosity.gc = true;
251 log_verbosity.heap = true;
252 log_verbosity.jdwp = true;
253 log_verbosity.jni = true;
254 log_verbosity.monitor = true;
255 log_verbosity.profiler = true;
256 log_verbosity.signals = true;
Phil Wang751beff2015-08-28 15:17:15 +0800257 log_verbosity.simulator = true;
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800258 log_verbosity.startup = true;
259 log_verbosity.third_party_jni = true;
260 log_verbosity.threads = true;
261 log_verbosity.verifier = true;
262
263 EXPECT_SINGLE_PARSE_VALUE(log_verbosity, log_args, M::Verbose);
264 }
265
266 {
267 const char* log_args = "-verbose:"
268 "class,compiler,gc,heap,jdwp,jni,monitor";
269
270 LogVerbosity log_verbosity = LogVerbosity();
271 log_verbosity.class_linker = true;
272 log_verbosity.compiler = true;
273 log_verbosity.gc = true;
274 log_verbosity.heap = true;
275 log_verbosity.jdwp = true;
276 log_verbosity.jni = true;
277 log_verbosity.monitor = true;
278
279 EXPECT_SINGLE_PARSE_VALUE(log_verbosity, log_args, M::Verbose);
280 }
281
282 EXPECT_SINGLE_PARSE_FAIL("-verbose:blablabla", CmdlineResult::kUsage); // invalid verbose opt
Richard Uhler66d874d2015-01-15 09:37:19 -0800283
284 {
Sebastien Hertzbba348e2015-06-01 08:28:18 +0200285 const char* log_args = "-verbose:deopt";
286 LogVerbosity log_verbosity = LogVerbosity();
287 log_verbosity.deopt = true;
288 EXPECT_SINGLE_PARSE_VALUE(log_verbosity, log_args, M::Verbose);
289 }
290
291 {
Mathieu Chartier66a55392016-02-19 10:25:39 -0800292 const char* log_args = "-verbose:collector";
293 LogVerbosity log_verbosity = LogVerbosity();
294 log_verbosity.collector = true;
295 EXPECT_SINGLE_PARSE_VALUE(log_verbosity, log_args, M::Verbose);
296 }
297
298 {
Richard Uhler66d874d2015-01-15 09:37:19 -0800299 const char* log_args = "-verbose:oat";
300 LogVerbosity log_verbosity = LogVerbosity();
301 log_verbosity.oat = true;
302 EXPECT_SINGLE_PARSE_VALUE(log_verbosity, log_args, M::Verbose);
303 }
Andreas Gampebec07a02017-04-11 13:48:37 -0700304
305 {
306 const char* log_args = "-verbose:dex";
307 LogVerbosity log_verbosity = LogVerbosity();
308 log_verbosity.dex = true;
309 EXPECT_SINGLE_PARSE_VALUE(log_verbosity, log_args, M::Verbose);
310 }
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800311} // TEST_F
312
Nicolas Geoffray8f4ee5c2015-02-05 10:14:10 +0000313// TODO: Enable this b/19274810
314TEST_F(CmdlineParserTest, DISABLED_TestXGcOption) {
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800315 /*
316 * Test success
317 */
318 {
319 XGcOption option_all_true{}; // NOLINT [readability/braces] [4]
320 option_all_true.collector_type_ = gc::CollectorType::kCollectorTypeCMS;
321 option_all_true.verify_pre_gc_heap_ = true;
322 option_all_true.verify_pre_sweeping_heap_ = true;
323 option_all_true.verify_post_gc_heap_ = true;
324 option_all_true.verify_pre_gc_rosalloc_ = true;
325 option_all_true.verify_pre_sweeping_rosalloc_ = true;
326 option_all_true.verify_post_gc_rosalloc_ = true;
327
328 const char * xgc_args_all_true = "-Xgc:concurrent,"
329 "preverify,presweepingverify,postverify,"
330 "preverify_rosalloc,presweepingverify_rosalloc,"
331 "postverify_rosalloc,precise,"
332 "verifycardtable";
333
334 EXPECT_SINGLE_PARSE_VALUE(option_all_true, xgc_args_all_true, M::GcOption);
335
336 XGcOption option_all_false{}; // NOLINT [readability/braces] [4]
337 option_all_false.collector_type_ = gc::CollectorType::kCollectorTypeMS;
338 option_all_false.verify_pre_gc_heap_ = false;
339 option_all_false.verify_pre_sweeping_heap_ = false;
340 option_all_false.verify_post_gc_heap_ = false;
341 option_all_false.verify_pre_gc_rosalloc_ = false;
342 option_all_false.verify_pre_sweeping_rosalloc_ = false;
343 option_all_false.verify_post_gc_rosalloc_ = false;
344
345 const char* xgc_args_all_false = "-Xgc:nonconcurrent,"
346 "nopreverify,nopresweepingverify,nopostverify,nopreverify_rosalloc,"
347 "nopresweepingverify_rosalloc,nopostverify_rosalloc,noprecise,noverifycardtable";
348
349 EXPECT_SINGLE_PARSE_VALUE(option_all_false, xgc_args_all_false, M::GcOption);
350
351 XGcOption option_all_default{}; // NOLINT [readability/braces] [4]
352
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800353 const char* xgc_args_blank = "-Xgc:";
354 EXPECT_SINGLE_PARSE_VALUE(option_all_default, xgc_args_blank, M::GcOption);
355 }
356
357 /*
358 * Test failures
359 */
360 EXPECT_SINGLE_PARSE_FAIL("-Xgc:blablabla", CmdlineResult::kUsage); // invalid Xgc opt
361} // TEST_F
362
363/*
364 * {"-Xrunjdwp:_", "-agentlib:jdwp=_"}
365 */
366TEST_F(CmdlineParserTest, TestJdwpOptions) {
367 /*
368 * Test success
369 */
370 {
371 /*
372 * "Example: -Xrunjdwp:transport=dt_socket,address=8000,server=y\n"
373 */
374 JDWP::JdwpOptions opt = JDWP::JdwpOptions();
375 opt.transport = JDWP::JdwpTransportType::kJdwpTransportSocket;
376 opt.port = 8000;
377 opt.server = true;
378
379 const char *opt_args = "-Xrunjdwp:transport=dt_socket,address=8000,server=y";
380
381 EXPECT_SINGLE_PARSE_VALUE(opt, opt_args, M::JdwpOptions);
382 }
383
384 {
385 /*
386 * "Example: -agentlib:jdwp=transport=dt_socket,address=localhost:6500,server=n\n");
387 */
388 JDWP::JdwpOptions opt = JDWP::JdwpOptions();
389 opt.transport = JDWP::JdwpTransportType::kJdwpTransportSocket;
390 opt.host = "localhost";
391 opt.port = 6500;
392 opt.server = false;
393
394 const char *opt_args = "-agentlib:jdwp=transport=dt_socket,address=localhost:6500,server=n";
395
396 EXPECT_SINGLE_PARSE_VALUE(opt, opt_args, M::JdwpOptions);
397 }
398
399 /*
400 * Test failures
401 */
402 EXPECT_SINGLE_PARSE_FAIL("-Xrunjdwp:help", CmdlineResult::kUsage); // usage for help only
403 EXPECT_SINGLE_PARSE_FAIL("-Xrunjdwp:blabla", CmdlineResult::kFailure); // invalid subarg
404 EXPECT_SINGLE_PARSE_FAIL("-agentlib:jdwp=help", CmdlineResult::kUsage); // usage for help only
405 EXPECT_SINGLE_PARSE_FAIL("-agentlib:jdwp=blabla", CmdlineResult::kFailure); // invalid subarg
406} // TEST_F
407
408/*
409 * -D_ -D_ -D_ ...
410 */
411TEST_F(CmdlineParserTest, TestPropertiesList) {
412 /*
413 * Test successes
414 */
415 {
416 std::vector<std::string> opt = {"hello"};
417
418 EXPECT_SINGLE_PARSE_VALUE(opt, "-Dhello", M::PropertiesList);
419 }
420
421 {
422 std::vector<std::string> opt = {"hello", "world"};
423
424 EXPECT_SINGLE_PARSE_VALUE(opt, "-Dhello -Dworld", M::PropertiesList);
425 }
426
427 {
428 std::vector<std::string> opt = {"one", "two", "three"};
429
430 EXPECT_SINGLE_PARSE_VALUE(opt, "-Done -Dtwo -Dthree", M::PropertiesList);
431 }
432} // TEST_F
433
434/*
435* -Xcompiler-option foo -Xcompiler-option bar ...
436*/
437TEST_F(CmdlineParserTest, TestCompilerOption) {
438 /*
439 * Test successes
440 */
441 {
442 std::vector<std::string> opt = {"hello"};
443 EXPECT_SINGLE_PARSE_VALUE(opt, "-Xcompiler-option hello", M::CompilerOptions);
444 }
445
446 {
447 std::vector<std::string> opt = {"hello", "world"};
448 EXPECT_SINGLE_PARSE_VALUE(opt,
449 "-Xcompiler-option hello -Xcompiler-option world",
450 M::CompilerOptions);
451 }
452
453 {
454 std::vector<std::string> opt = {"one", "two", "three"};
455 EXPECT_SINGLE_PARSE_VALUE(opt,
456 "-Xcompiler-option one -Xcompiler-option two -Xcompiler-option three",
457 M::CompilerOptions);
458 }
459} // TEST_F
460
461/*
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800462* -Xjit, -Xnojit, -Xjitcodecachesize, Xjitcompilethreshold
463*/
464TEST_F(CmdlineParserTest, TestJitOptions) {
465 /*
466 * Test successes
467 */
468 {
Calin Juravleffc87072016-04-20 14:22:09 +0100469 EXPECT_SINGLE_PARSE_VALUE(true, "-Xusejit:true", M::UseJitCompilation);
470 EXPECT_SINGLE_PARSE_VALUE(false, "-Xusejit:false", M::UseJitCompilation);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800471 }
472 {
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000473 EXPECT_SINGLE_PARSE_VALUE(
Nicolas Geoffray295a5962015-11-19 18:17:41 +0000474 MemoryKiB(16 * KB), "-Xjitinitialsize:16K", M::JITCodeCacheInitialCapacity);
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000475 EXPECT_SINGLE_PARSE_VALUE(
Nicolas Geoffray295a5962015-11-19 18:17:41 +0000476 MemoryKiB(16 * MB), "-Xjitmaxsize:16M", M::JITCodeCacheMaxCapacity);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800477 }
478 {
479 EXPECT_SINGLE_PARSE_VALUE(12345u, "-Xjitthreshold:12345", M::JITCompileThreshold);
480 }
481} // TEST_F
482
483/*
Calin Juravle138dbff2016-06-28 19:36:58 +0100484* -Xps-*
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800485*/
Calin Juravle138dbff2016-06-28 19:36:58 +0100486TEST_F(CmdlineParserTest, ProfileSaverOptions) {
Mathieu Chartier885a7132017-06-10 14:35:11 -0700487 ProfileSaverOptions opt = ProfileSaverOptions(true, 1, 2, 3, 4, 5, 6, 7, "abc", true);
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800488
Calin Juravle138dbff2016-06-28 19:36:58 +0100489 EXPECT_SINGLE_PARSE_VALUE(opt,
490 "-Xjitsaveprofilinginfo "
491 "-Xps-min-save-period-ms:1 "
492 "-Xps-save-resolved-classes-delay-ms:2 "
Mathieu Chartier7b135c82017-06-05 12:54:01 -0700493 "-Xps-hot-startup-method-samples:3 "
Calin Juravle138dbff2016-06-28 19:36:58 +0100494 "-Xps-min-methods-to-save:4 "
495 "-Xps-min-classes-to-save:5 "
496 "-Xps-min-notification-before-wake:6 "
Calin Juravle9545f6d2017-03-16 19:05:09 -0700497 "-Xps-max-notification-before-wake:7 "
Mathieu Chartier885a7132017-06-10 14:35:11 -0700498 "-Xps-profile-path:abc "
499 "-Xps-profile-boot-class-path",
Calin Juravle138dbff2016-06-28 19:36:58 +0100500 M::ProfileSaverOpts);
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800501} // TEST_F
502
Alex Lighteb7c1442015-08-31 13:17:42 -0700503/* -Xexperimental:_ */
504TEST_F(CmdlineParserTest, TestExperimentalFlags) {
Neil Fuller9724c632016-01-07 15:42:47 +0000505 // Default
Alex Lighteb7c1442015-08-31 13:17:42 -0700506 EXPECT_SINGLE_PARSE_DEFAULT_VALUE(ExperimentalFlags::kNone,
Igor Murashkin158f35c2015-06-10 15:55:30 -0700507 "",
Alex Lighteb7c1442015-08-31 13:17:42 -0700508 M::Experimental);
Igor Murashkin158f35c2015-06-10 15:55:30 -0700509
510 // Disabled explicitly
Alex Lighteb7c1442015-08-31 13:17:42 -0700511 EXPECT_SINGLE_PARSE_VALUE(ExperimentalFlags::kNone,
512 "-Xexperimental:none",
513 M::Experimental);
Igor Murashkin158f35c2015-06-10 15:55:30 -0700514}
515
Igor Murashkin7617abd2015-07-10 18:27:47 -0700516// -Xverify:_
517TEST_F(CmdlineParserTest, TestVerify) {
518 EXPECT_SINGLE_PARSE_VALUE(verifier::VerifyMode::kNone, "-Xverify:none", M::Verify);
519 EXPECT_SINGLE_PARSE_VALUE(verifier::VerifyMode::kEnable, "-Xverify:remote", M::Verify);
520 EXPECT_SINGLE_PARSE_VALUE(verifier::VerifyMode::kEnable, "-Xverify:all", M::Verify);
521 EXPECT_SINGLE_PARSE_VALUE(verifier::VerifyMode::kSoftFail, "-Xverify:softfail", M::Verify);
522}
523
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800524TEST_F(CmdlineParserTest, TestIgnoreUnrecognized) {
525 RuntimeParser::Builder parserBuilder;
526
527 parserBuilder
528 .Define("-help")
529 .IntoKey(M::Help)
530 .IgnoreUnrecognized(true);
531
532 parser_.reset(new RuntimeParser(parserBuilder.Build()));
533
534 EXPECT_SINGLE_PARSE_EMPTY_SUCCESS("-non-existent-option");
535 EXPECT_SINGLE_PARSE_EMPTY_SUCCESS("-non-existent-option1 --non-existent-option-2");
536} // TEST_F
537
538TEST_F(CmdlineParserTest, TestIgnoredArguments) {
539 std::initializer_list<const char*> ignored_args = {
540 "-ea", "-da", "-enableassertions", "-disableassertions", "--runtime-arg", "-esa",
541 "-dsa", "-enablesystemassertions", "-disablesystemassertions", "-Xrs", "-Xint:abdef",
542 "-Xdexopt:foobar", "-Xnoquithandler", "-Xjnigreflimit:ixnay", "-Xgenregmap", "-Xnogenregmap",
543 "-Xverifyopt:never", "-Xcheckdexsum", "-Xincludeselectedop", "-Xjitop:noop",
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800544 "-Xincludeselectedmethod", "-Xjitblocking", "-Xjitmethod:_", "-Xjitclass:nosuchluck",
545 "-Xjitoffset:none", "-Xjitconfig:yes", "-Xjitcheckcg", "-Xjitverbose", "-Xjitprofile",
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800546 "-Xjitdisableopt", "-Xjitsuspendpoll", "-XX:mainThreadStackSize=1337"
547 };
548
549 // Check they are ignored when parsed one at a time
550 for (auto&& arg : ignored_args) {
551 SCOPED_TRACE(arg);
552 EXPECT_SINGLE_PARSE_EMPTY_SUCCESS(arg);
553 }
554
555 // Check they are ignored when we pass it all together at once
556 std::vector<const char*> argv = ignored_args;
557 EXPECT_SINGLE_PARSE_EMPTY_SUCCESS(argv);
558} // TEST_F
559
560TEST_F(CmdlineParserTest, MultipleArguments) {
561 EXPECT_TRUE(IsResultSuccessful(parser_->Parse(
562 "-help -XX:ForegroundHeapGrowthMultiplier=0.5 "
563 "-Xnodex2oat -Xmethod-trace -XX:LargeObjectSpace=map")));
564
565 auto&& map = parser_->ReleaseArgumentsMap();
566 EXPECT_EQ(5u, map.Size());
567 EXPECT_KEY_VALUE(map, M::Help, Unit{}); // NOLINT [whitespace/braces] [5]
568 EXPECT_KEY_VALUE(map, M::ForegroundHeapGrowthMultiplier, 0.5);
569 EXPECT_KEY_VALUE(map, M::Dex2Oat, false);
570 EXPECT_KEY_VALUE(map, M::MethodTrace, Unit{}); // NOLINT [whitespace/braces] [5]
571 EXPECT_KEY_VALUE(map, M::LargeObjectSpace, gc::space::LargeObjectSpaceType::kMap);
572} // TEST_F
573} // namespace art