blob: 98fd327f029900ef861ed57f49dff39ab047d73b [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"
24
25#define EXPECT_NULL(expected) EXPECT_EQ(reinterpret_cast<const void*>(expected), \
Mathieu Chartier2cebb242015-04-21 16:50:40 -070026 reinterpret_cast<void*>(nullptr));
Igor Murashkinaaebaa02015-01-26 10:55:53 -080027
28namespace art {
29 bool UsuallyEquals(double expected, double actual);
30
31 // This has a gtest dependency, which is why it's in the gtest only.
32 bool operator==(const TestProfilerOptions& lhs, const TestProfilerOptions& rhs) {
33 return lhs.enabled_ == rhs.enabled_ &&
34 lhs.output_file_name_ == rhs.output_file_name_ &&
35 lhs.period_s_ == rhs.period_s_ &&
36 lhs.duration_s_ == rhs.duration_s_ &&
37 lhs.interval_us_ == rhs.interval_us_ &&
38 UsuallyEquals(lhs.backoff_coefficient_, rhs.backoff_coefficient_) &&
39 UsuallyEquals(lhs.start_immediately_, rhs.start_immediately_) &&
40 UsuallyEquals(lhs.top_k_threshold_, rhs.top_k_threshold_) &&
41 UsuallyEquals(lhs.top_k_change_threshold_, rhs.top_k_change_threshold_) &&
42 lhs.profile_type_ == rhs.profile_type_ &&
43 lhs.max_stack_depth_ == rhs.max_stack_depth_;
44 }
45
46 bool UsuallyEquals(double expected, double actual) {
47 using FloatingPoint = ::testing::internal::FloatingPoint<double>;
48
49 FloatingPoint exp(expected);
50 FloatingPoint act(actual);
51
52 // Compare with ULPs instead of comparing with ==
53 return exp.AlmostEquals(act);
54 }
55
56 template <typename T>
57 bool UsuallyEquals(const T& expected, const T& actual,
58 typename std::enable_if<
59 detail::SupportsEqualityOperator<T>::value>::type* = 0) {
60 return expected == actual;
61 }
62
63 // Try to use memcmp to compare simple plain-old-data structs.
64 //
65 // This should *not* generate false positives, but it can generate false negatives.
66 // This will mostly work except for fields like float which can have different bit patterns
67 // that are nevertheless equal.
68 // If a test is failing because the structs aren't "equal" when they really are
69 // then it's recommended to implement operator== for it instead.
70 template <typename T, typename ... Ignore>
71 bool UsuallyEquals(const T& expected, const T& actual,
72 const Ignore& ... more ATTRIBUTE_UNUSED,
73 typename std::enable_if<std::is_pod<T>::value>::type* = 0,
74 typename std::enable_if<!detail::SupportsEqualityOperator<T>::value>::type* = 0
75 ) {
76 return memcmp(std::addressof(expected), std::addressof(actual), sizeof(T)) == 0;
77 }
78
79 bool UsuallyEquals(const XGcOption& expected, const XGcOption& actual) {
80 return memcmp(std::addressof(expected), std::addressof(actual), sizeof(expected)) == 0;
81 }
82
83 bool UsuallyEquals(const char* expected, std::string actual) {
84 return std::string(expected) == actual;
85 }
86
87 template <typename TMap, typename TKey, typename T>
88 ::testing::AssertionResult IsExpectedKeyValue(const T& expected,
89 const TMap& map,
90 const TKey& key) {
91 auto* actual = map.Get(key);
92 if (actual != nullptr) {
93 if (!UsuallyEquals(expected, *actual)) {
94 return ::testing::AssertionFailure()
95 << "expected " << detail::ToStringAny(expected) << " but got "
96 << detail::ToStringAny(*actual);
97 }
98 return ::testing::AssertionSuccess();
99 }
100
101 return ::testing::AssertionFailure() << "key was not in the map";
102 }
103
Igor Murashkin158f35c2015-06-10 15:55:30 -0700104 template <typename TMap, typename TKey, typename T>
105 ::testing::AssertionResult IsExpectedDefaultKeyValue(const T& expected,
106 const TMap& map,
107 const TKey& key) {
108 const T& actual = map.GetOrDefault(key);
109 if (!UsuallyEquals(expected, actual)) {
110 return ::testing::AssertionFailure()
111 << "expected " << detail::ToStringAny(expected) << " but got "
112 << detail::ToStringAny(actual);
113 }
114 return ::testing::AssertionSuccess();
115 }
116
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800117class CmdlineParserTest : public ::testing::Test {
118 public:
119 CmdlineParserTest() = default;
120 ~CmdlineParserTest() = default;
121
122 protected:
123 using M = RuntimeArgumentMap;
124 using RuntimeParser = ParsedOptions::RuntimeParser;
125
126 static void SetUpTestCase() {
127 art::InitLogging(nullptr); // argv = null
128 }
129
130 virtual void SetUp() {
131 parser_ = ParsedOptions::MakeParser(false); // do not ignore unrecognized options
132 }
133
134 static ::testing::AssertionResult IsResultSuccessful(CmdlineResult result) {
135 if (result.IsSuccess()) {
136 return ::testing::AssertionSuccess();
137 } else {
138 return ::testing::AssertionFailure()
139 << result.GetStatus() << " with: " << result.GetMessage();
140 }
141 }
142
143 static ::testing::AssertionResult IsResultFailure(CmdlineResult result,
144 CmdlineResult::Status failure_status) {
145 if (result.IsSuccess()) {
146 return ::testing::AssertionFailure() << " got success but expected failure: "
147 << failure_status;
148 } else if (result.GetStatus() == failure_status) {
149 return ::testing::AssertionSuccess();
150 }
151
152 return ::testing::AssertionFailure() << " expected failure " << failure_status
153 << " but got " << result.GetStatus();
154 }
155
156 std::unique_ptr<RuntimeParser> parser_;
157};
158
159#define EXPECT_KEY_EXISTS(map, key) EXPECT_TRUE((map).Exists(key))
160#define EXPECT_KEY_VALUE(map, key, expected) EXPECT_TRUE(IsExpectedKeyValue(expected, map, key))
Igor Murashkin158f35c2015-06-10 15:55:30 -0700161#define EXPECT_DEFAULT_KEY_VALUE(map, key, expected) EXPECT_TRUE(IsExpectedDefaultKeyValue(expected, map, key))
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800162
Igor Murashkin158f35c2015-06-10 15:55:30 -0700163#define _EXPECT_SINGLE_PARSE_EMPTY_SUCCESS(argv) \
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800164 do { \
165 EXPECT_TRUE(IsResultSuccessful(parser_->Parse(argv))); \
166 EXPECT_EQ(0u, parser_->GetArgumentsMap().Size()); \
Igor Murashkin158f35c2015-06-10 15:55:30 -0700167
168#define EXPECT_SINGLE_PARSE_EMPTY_SUCCESS(argv) \
169 _EXPECT_SINGLE_PARSE_EMPTY_SUCCESS(argv); \
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800170 } while (false)
171
Igor Murashkin158f35c2015-06-10 15:55:30 -0700172#define EXPECT_SINGLE_PARSE_DEFAULT_VALUE(expected, argv, key)\
173 _EXPECT_SINGLE_PARSE_EMPTY_SUCCESS(argv); \
174 RuntimeArgumentMap args = parser_->ReleaseArgumentsMap(); \
175 EXPECT_DEFAULT_KEY_VALUE(args, key, expected); \
176 } while (false) // NOLINT [readability/namespace] [5]
177
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800178#define _EXPECT_SINGLE_PARSE_EXISTS(argv, key) \
179 do { \
180 EXPECT_TRUE(IsResultSuccessful(parser_->Parse(argv))); \
181 RuntimeArgumentMap args = parser_->ReleaseArgumentsMap(); \
182 EXPECT_EQ(1u, args.Size()); \
183 EXPECT_KEY_EXISTS(args, key); \
184
185#define EXPECT_SINGLE_PARSE_EXISTS(argv, key) \
186 _EXPECT_SINGLE_PARSE_EXISTS(argv, key); \
187 } while (false)
188
189#define EXPECT_SINGLE_PARSE_VALUE(expected, argv, key) \
190 _EXPECT_SINGLE_PARSE_EXISTS(argv, key); \
191 EXPECT_KEY_VALUE(args, key, expected); \
192 } while (false) // NOLINT [readability/namespace] [5]
193
194#define EXPECT_SINGLE_PARSE_VALUE_STR(expected, argv, key) \
195 EXPECT_SINGLE_PARSE_VALUE(std::string(expected), argv, key)
196
197#define EXPECT_SINGLE_PARSE_FAIL(argv, failure_status) \
198 do { \
199 EXPECT_TRUE(IsResultFailure(parser_->Parse(argv), failure_status));\
200 RuntimeArgumentMap args = parser_->ReleaseArgumentsMap();\
201 EXPECT_EQ(0u, args.Size()); \
202 } while (false)
203
204TEST_F(CmdlineParserTest, TestSimpleSuccesses) {
205 auto& parser = *parser_;
206
207 EXPECT_LT(0u, parser.CountDefinedArguments());
208
209 {
210 // Test case 1: No command line arguments
211 EXPECT_TRUE(IsResultSuccessful(parser.Parse("")));
212 RuntimeArgumentMap args = parser.ReleaseArgumentsMap();
213 EXPECT_EQ(0u, args.Size());
214 }
215
216 EXPECT_SINGLE_PARSE_EXISTS("-Xzygote", M::Zygote);
217 EXPECT_SINGLE_PARSE_VALUE_STR("/hello/world", "-Xbootclasspath:/hello/world", M::BootClassPath);
218 EXPECT_SINGLE_PARSE_VALUE("/hello/world", "-Xbootclasspath:/hello/world", M::BootClassPath);
219 EXPECT_SINGLE_PARSE_VALUE(false, "-Xverify:none", M::Verify);
220 EXPECT_SINGLE_PARSE_VALUE(true, "-Xverify:remote", M::Verify);
221 EXPECT_SINGLE_PARSE_VALUE(true, "-Xverify:all", M::Verify);
222 EXPECT_SINGLE_PARSE_VALUE(Memory<1>(234), "-Xss234", M::StackSize);
223 EXPECT_SINGLE_PARSE_VALUE(MemoryKiB(1234*MB), "-Xms1234m", M::MemoryInitialSize);
224 EXPECT_SINGLE_PARSE_VALUE(true, "-XX:EnableHSpaceCompactForOOM", M::EnableHSpaceCompactForOOM);
225 EXPECT_SINGLE_PARSE_VALUE(false, "-XX:DisableHSpaceCompactForOOM", M::EnableHSpaceCompactForOOM);
226 EXPECT_SINGLE_PARSE_VALUE(0.5, "-XX:HeapTargetUtilization=0.5", M::HeapTargetUtilization);
227 EXPECT_SINGLE_PARSE_VALUE(5u, "-XX:ParallelGCThreads=5", M::ParallelGCThreads);
Jean Christophe Beyler24e04aa2014-09-12 12:03:25 -0700228 EXPECT_SINGLE_PARSE_EXISTS("-Xno-dex-file-fallback", M::NoDexFileFallback);
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800229} // TEST_F
230
231TEST_F(CmdlineParserTest, TestSimpleFailures) {
232 // Test argument is unknown to the parser
233 EXPECT_SINGLE_PARSE_FAIL("abcdefg^%@#*(@#", CmdlineResult::kUnknown);
234 // Test value map substitution fails
235 EXPECT_SINGLE_PARSE_FAIL("-Xverify:whatever", CmdlineResult::kFailure);
236 // Test value type parsing failures
237 EXPECT_SINGLE_PARSE_FAIL("-Xsswhatever", CmdlineResult::kFailure); // invalid memory value
238 EXPECT_SINGLE_PARSE_FAIL("-Xms123", CmdlineResult::kFailure); // memory value too small
239 EXPECT_SINGLE_PARSE_FAIL("-XX:HeapTargetUtilization=0.0", CmdlineResult::kOutOfRange); // toosmal
240 EXPECT_SINGLE_PARSE_FAIL("-XX:HeapTargetUtilization=2.0", CmdlineResult::kOutOfRange); // toolarg
241 EXPECT_SINGLE_PARSE_FAIL("-XX:ParallelGCThreads=-5", CmdlineResult::kOutOfRange); // too small
242 EXPECT_SINGLE_PARSE_FAIL("-Xgc:blablabla", CmdlineResult::kUsage); // not a valid suboption
243} // TEST_F
244
245TEST_F(CmdlineParserTest, TestLogVerbosity) {
246 {
247 const char* log_args = "-verbose:"
248 "class,compiler,gc,heap,jdwp,jni,monitor,profiler,signals,startup,third-party-jni,"
249 "threads,verifier";
250
251 LogVerbosity log_verbosity = LogVerbosity();
252 log_verbosity.class_linker = true;
253 log_verbosity.compiler = true;
254 log_verbosity.gc = true;
255 log_verbosity.heap = true;
256 log_verbosity.jdwp = true;
257 log_verbosity.jni = true;
258 log_verbosity.monitor = true;
259 log_verbosity.profiler = true;
260 log_verbosity.signals = true;
261 log_verbosity.startup = true;
262 log_verbosity.third_party_jni = true;
263 log_verbosity.threads = true;
264 log_verbosity.verifier = true;
265
266 EXPECT_SINGLE_PARSE_VALUE(log_verbosity, log_args, M::Verbose);
267 }
268
269 {
270 const char* log_args = "-verbose:"
271 "class,compiler,gc,heap,jdwp,jni,monitor";
272
273 LogVerbosity log_verbosity = LogVerbosity();
274 log_verbosity.class_linker = true;
275 log_verbosity.compiler = true;
276 log_verbosity.gc = true;
277 log_verbosity.heap = true;
278 log_verbosity.jdwp = true;
279 log_verbosity.jni = true;
280 log_verbosity.monitor = true;
281
282 EXPECT_SINGLE_PARSE_VALUE(log_verbosity, log_args, M::Verbose);
283 }
284
285 EXPECT_SINGLE_PARSE_FAIL("-verbose:blablabla", CmdlineResult::kUsage); // invalid verbose opt
Richard Uhler66d874d2015-01-15 09:37:19 -0800286
287 {
Sebastien Hertzbba348e2015-06-01 08:28:18 +0200288 const char* log_args = "-verbose:deopt";
289 LogVerbosity log_verbosity = LogVerbosity();
290 log_verbosity.deopt = true;
291 EXPECT_SINGLE_PARSE_VALUE(log_verbosity, log_args, M::Verbose);
292 }
293
294 {
Richard Uhler66d874d2015-01-15 09:37:19 -0800295 const char* log_args = "-verbose:oat";
296 LogVerbosity log_verbosity = LogVerbosity();
297 log_verbosity.oat = true;
298 EXPECT_SINGLE_PARSE_VALUE(log_verbosity, log_args, M::Verbose);
299 }
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800300} // TEST_F
301
Nicolas Geoffray8f4ee5c2015-02-05 10:14:10 +0000302// TODO: Enable this b/19274810
303TEST_F(CmdlineParserTest, DISABLED_TestXGcOption) {
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800304 /*
305 * Test success
306 */
307 {
308 XGcOption option_all_true{}; // NOLINT [readability/braces] [4]
309 option_all_true.collector_type_ = gc::CollectorType::kCollectorTypeCMS;
310 option_all_true.verify_pre_gc_heap_ = true;
311 option_all_true.verify_pre_sweeping_heap_ = true;
312 option_all_true.verify_post_gc_heap_ = true;
313 option_all_true.verify_pre_gc_rosalloc_ = true;
314 option_all_true.verify_pre_sweeping_rosalloc_ = true;
315 option_all_true.verify_post_gc_rosalloc_ = true;
316
317 const char * xgc_args_all_true = "-Xgc:concurrent,"
318 "preverify,presweepingverify,postverify,"
319 "preverify_rosalloc,presweepingverify_rosalloc,"
320 "postverify_rosalloc,precise,"
321 "verifycardtable";
322
323 EXPECT_SINGLE_PARSE_VALUE(option_all_true, xgc_args_all_true, M::GcOption);
324
325 XGcOption option_all_false{}; // NOLINT [readability/braces] [4]
326 option_all_false.collector_type_ = gc::CollectorType::kCollectorTypeMS;
327 option_all_false.verify_pre_gc_heap_ = false;
328 option_all_false.verify_pre_sweeping_heap_ = false;
329 option_all_false.verify_post_gc_heap_ = false;
330 option_all_false.verify_pre_gc_rosalloc_ = false;
331 option_all_false.verify_pre_sweeping_rosalloc_ = false;
332 option_all_false.verify_post_gc_rosalloc_ = false;
333
334 const char* xgc_args_all_false = "-Xgc:nonconcurrent,"
335 "nopreverify,nopresweepingverify,nopostverify,nopreverify_rosalloc,"
336 "nopresweepingverify_rosalloc,nopostverify_rosalloc,noprecise,noverifycardtable";
337
338 EXPECT_SINGLE_PARSE_VALUE(option_all_false, xgc_args_all_false, M::GcOption);
339
340 XGcOption option_all_default{}; // NOLINT [readability/braces] [4]
341
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800342 const char* xgc_args_blank = "-Xgc:";
343 EXPECT_SINGLE_PARSE_VALUE(option_all_default, xgc_args_blank, M::GcOption);
344 }
345
346 /*
347 * Test failures
348 */
349 EXPECT_SINGLE_PARSE_FAIL("-Xgc:blablabla", CmdlineResult::kUsage); // invalid Xgc opt
350} // TEST_F
351
352/*
353 * {"-Xrunjdwp:_", "-agentlib:jdwp=_"}
354 */
355TEST_F(CmdlineParserTest, TestJdwpOptions) {
356 /*
357 * Test success
358 */
359 {
360 /*
361 * "Example: -Xrunjdwp:transport=dt_socket,address=8000,server=y\n"
362 */
363 JDWP::JdwpOptions opt = JDWP::JdwpOptions();
364 opt.transport = JDWP::JdwpTransportType::kJdwpTransportSocket;
365 opt.port = 8000;
366 opt.server = true;
367
368 const char *opt_args = "-Xrunjdwp:transport=dt_socket,address=8000,server=y";
369
370 EXPECT_SINGLE_PARSE_VALUE(opt, opt_args, M::JdwpOptions);
371 }
372
373 {
374 /*
375 * "Example: -agentlib:jdwp=transport=dt_socket,address=localhost:6500,server=n\n");
376 */
377 JDWP::JdwpOptions opt = JDWP::JdwpOptions();
378 opt.transport = JDWP::JdwpTransportType::kJdwpTransportSocket;
379 opt.host = "localhost";
380 opt.port = 6500;
381 opt.server = false;
382
383 const char *opt_args = "-agentlib:jdwp=transport=dt_socket,address=localhost:6500,server=n";
384
385 EXPECT_SINGLE_PARSE_VALUE(opt, opt_args, M::JdwpOptions);
386 }
387
388 /*
389 * Test failures
390 */
391 EXPECT_SINGLE_PARSE_FAIL("-Xrunjdwp:help", CmdlineResult::kUsage); // usage for help only
392 EXPECT_SINGLE_PARSE_FAIL("-Xrunjdwp:blabla", CmdlineResult::kFailure); // invalid subarg
393 EXPECT_SINGLE_PARSE_FAIL("-agentlib:jdwp=help", CmdlineResult::kUsage); // usage for help only
394 EXPECT_SINGLE_PARSE_FAIL("-agentlib:jdwp=blabla", CmdlineResult::kFailure); // invalid subarg
395} // TEST_F
396
397/*
398 * -D_ -D_ -D_ ...
399 */
400TEST_F(CmdlineParserTest, TestPropertiesList) {
401 /*
402 * Test successes
403 */
404 {
405 std::vector<std::string> opt = {"hello"};
406
407 EXPECT_SINGLE_PARSE_VALUE(opt, "-Dhello", M::PropertiesList);
408 }
409
410 {
411 std::vector<std::string> opt = {"hello", "world"};
412
413 EXPECT_SINGLE_PARSE_VALUE(opt, "-Dhello -Dworld", M::PropertiesList);
414 }
415
416 {
417 std::vector<std::string> opt = {"one", "two", "three"};
418
419 EXPECT_SINGLE_PARSE_VALUE(opt, "-Done -Dtwo -Dthree", M::PropertiesList);
420 }
421} // TEST_F
422
423/*
424* -Xcompiler-option foo -Xcompiler-option bar ...
425*/
426TEST_F(CmdlineParserTest, TestCompilerOption) {
427 /*
428 * Test successes
429 */
430 {
431 std::vector<std::string> opt = {"hello"};
432 EXPECT_SINGLE_PARSE_VALUE(opt, "-Xcompiler-option hello", M::CompilerOptions);
433 }
434
435 {
436 std::vector<std::string> opt = {"hello", "world"};
437 EXPECT_SINGLE_PARSE_VALUE(opt,
438 "-Xcompiler-option hello -Xcompiler-option world",
439 M::CompilerOptions);
440 }
441
442 {
443 std::vector<std::string> opt = {"one", "two", "three"};
444 EXPECT_SINGLE_PARSE_VALUE(opt,
445 "-Xcompiler-option one -Xcompiler-option two -Xcompiler-option three",
446 M::CompilerOptions);
447 }
448} // TEST_F
449
450/*
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800451* -Xjit, -Xnojit, -Xjitcodecachesize, Xjitcompilethreshold
452*/
453TEST_F(CmdlineParserTest, TestJitOptions) {
454 /*
455 * Test successes
456 */
457 {
Andreas Gampe26826992015-03-05 18:48:52 -0800458 EXPECT_SINGLE_PARSE_VALUE(true, "-Xusejit:true", M::UseJIT);
459 EXPECT_SINGLE_PARSE_VALUE(false, "-Xusejit:false", M::UseJIT);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800460 }
461 {
462 EXPECT_SINGLE_PARSE_VALUE(MemoryKiB(16 * KB), "-Xjitcodecachesize:16K", M::JITCodeCacheCapacity);
463 EXPECT_SINGLE_PARSE_VALUE(MemoryKiB(16 * MB), "-Xjitcodecachesize:16M", M::JITCodeCacheCapacity);
464 }
465 {
466 EXPECT_SINGLE_PARSE_VALUE(12345u, "-Xjitthreshold:12345", M::JITCompileThreshold);
467 }
468} // TEST_F
469
470/*
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800471* -X-profile-*
472*/
473TEST_F(CmdlineParserTest, TestProfilerOptions) {
474 /*
475 * Test successes
476 */
477
478 {
479 TestProfilerOptions opt;
480 opt.enabled_ = true;
481
482 EXPECT_SINGLE_PARSE_VALUE(opt,
483 "-Xenable-profiler",
484 M::ProfilerOpts);
485 }
486
487 {
488 TestProfilerOptions opt;
489 // also need to test 'enabled'
490 opt.output_file_name_ = "hello_world.txt";
491
492 EXPECT_SINGLE_PARSE_VALUE(opt,
493 "-Xprofile-filename:hello_world.txt ",
494 M::ProfilerOpts);
495 }
496
497 {
498 TestProfilerOptions opt = TestProfilerOptions();
499 // also need to test 'enabled'
500 opt.output_file_name_ = "output.txt";
501 opt.period_s_ = 123u;
502 opt.duration_s_ = 456u;
503 opt.interval_us_ = 789u;
504 opt.backoff_coefficient_ = 2.0;
505 opt.start_immediately_ = true;
506 opt.top_k_threshold_ = 50.0;
507 opt.top_k_change_threshold_ = 60.0;
508 opt.profile_type_ = kProfilerMethod;
509 opt.max_stack_depth_ = 1337u;
510
511 EXPECT_SINGLE_PARSE_VALUE(opt,
512 "-Xprofile-filename:output.txt "
513 "-Xprofile-period:123 "
514 "-Xprofile-duration:456 "
515 "-Xprofile-interval:789 "
516 "-Xprofile-backoff:2.0 "
517 "-Xprofile-start-immediately "
518 "-Xprofile-top-k-threshold:50.0 "
519 "-Xprofile-top-k-change-threshold:60.0 "
520 "-Xprofile-type:method "
521 "-Xprofile-max-stack-depth:1337",
522 M::ProfilerOpts);
523 }
524
525 {
526 TestProfilerOptions opt = TestProfilerOptions();
527 opt.profile_type_ = kProfilerBoundedStack;
528
529 EXPECT_SINGLE_PARSE_VALUE(opt,
530 "-Xprofile-type:stack",
531 M::ProfilerOpts);
532 }
533} // TEST_F
534
Igor Murashkin158f35c2015-06-10 15:55:30 -0700535/* -X[no]experimental-lambdas */
536TEST_F(CmdlineParserTest, TestExperimentalLambdas) {
537 // Off by default
538 EXPECT_SINGLE_PARSE_DEFAULT_VALUE(false,
539 "",
540 M::ExperimentalLambdas);
541
542 // Disabled explicitly
543 EXPECT_SINGLE_PARSE_VALUE(false,
544 "-Xnoexperimental-lambdas",
545 M::ExperimentalLambdas);
546
547 // Enabled explicitly
548 EXPECT_SINGLE_PARSE_VALUE(true,
549 "-Xexperimental-lambdas",
550 M::ExperimentalLambdas);
551}
552
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800553TEST_F(CmdlineParserTest, TestIgnoreUnrecognized) {
554 RuntimeParser::Builder parserBuilder;
555
556 parserBuilder
557 .Define("-help")
558 .IntoKey(M::Help)
559 .IgnoreUnrecognized(true);
560
561 parser_.reset(new RuntimeParser(parserBuilder.Build()));
562
563 EXPECT_SINGLE_PARSE_EMPTY_SUCCESS("-non-existent-option");
564 EXPECT_SINGLE_PARSE_EMPTY_SUCCESS("-non-existent-option1 --non-existent-option-2");
565} // TEST_F
566
567TEST_F(CmdlineParserTest, TestIgnoredArguments) {
568 std::initializer_list<const char*> ignored_args = {
569 "-ea", "-da", "-enableassertions", "-disableassertions", "--runtime-arg", "-esa",
570 "-dsa", "-enablesystemassertions", "-disablesystemassertions", "-Xrs", "-Xint:abdef",
571 "-Xdexopt:foobar", "-Xnoquithandler", "-Xjnigreflimit:ixnay", "-Xgenregmap", "-Xnogenregmap",
572 "-Xverifyopt:never", "-Xcheckdexsum", "-Xincludeselectedop", "-Xjitop:noop",
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800573 "-Xincludeselectedmethod", "-Xjitblocking", "-Xjitmethod:_", "-Xjitclass:nosuchluck",
574 "-Xjitoffset:none", "-Xjitconfig:yes", "-Xjitcheckcg", "-Xjitverbose", "-Xjitprofile",
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800575 "-Xjitdisableopt", "-Xjitsuspendpoll", "-XX:mainThreadStackSize=1337"
576 };
577
578 // Check they are ignored when parsed one at a time
579 for (auto&& arg : ignored_args) {
580 SCOPED_TRACE(arg);
581 EXPECT_SINGLE_PARSE_EMPTY_SUCCESS(arg);
582 }
583
584 // Check they are ignored when we pass it all together at once
585 std::vector<const char*> argv = ignored_args;
586 EXPECT_SINGLE_PARSE_EMPTY_SUCCESS(argv);
587} // TEST_F
588
589TEST_F(CmdlineParserTest, MultipleArguments) {
590 EXPECT_TRUE(IsResultSuccessful(parser_->Parse(
591 "-help -XX:ForegroundHeapGrowthMultiplier=0.5 "
592 "-Xnodex2oat -Xmethod-trace -XX:LargeObjectSpace=map")));
593
594 auto&& map = parser_->ReleaseArgumentsMap();
595 EXPECT_EQ(5u, map.Size());
596 EXPECT_KEY_VALUE(map, M::Help, Unit{}); // NOLINT [whitespace/braces] [5]
597 EXPECT_KEY_VALUE(map, M::ForegroundHeapGrowthMultiplier, 0.5);
598 EXPECT_KEY_VALUE(map, M::Dex2Oat, false);
599 EXPECT_KEY_VALUE(map, M::MethodTrace, Unit{}); // NOLINT [whitespace/braces] [5]
600 EXPECT_KEY_VALUE(map, M::LargeObjectSpace, gc::space::LargeObjectSpaceType::kMap);
601} // TEST_F
602} // namespace art