blob: 529143d93d118960480d6fd4638cf08b82637be0 [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"
Igor Murashkinaaebaa02015-01-26 10:55:53 -080025
26#define EXPECT_NULL(expected) EXPECT_EQ(reinterpret_cast<const void*>(expected), \
Mathieu Chartier2cebb242015-04-21 16:50:40 -070027 reinterpret_cast<void*>(nullptr));
Igor Murashkinaaebaa02015-01-26 10:55:53 -080028
29namespace art {
30 bool UsuallyEquals(double expected, double actual);
31
32 // This has a gtest dependency, which is why it's in the gtest only.
33 bool operator==(const TestProfilerOptions& lhs, const TestProfilerOptions& rhs) {
34 return lhs.enabled_ == rhs.enabled_ &&
35 lhs.output_file_name_ == rhs.output_file_name_ &&
36 lhs.period_s_ == rhs.period_s_ &&
37 lhs.duration_s_ == rhs.duration_s_ &&
38 lhs.interval_us_ == rhs.interval_us_ &&
39 UsuallyEquals(lhs.backoff_coefficient_, rhs.backoff_coefficient_) &&
40 UsuallyEquals(lhs.start_immediately_, rhs.start_immediately_) &&
41 UsuallyEquals(lhs.top_k_threshold_, rhs.top_k_threshold_) &&
42 UsuallyEquals(lhs.top_k_change_threshold_, rhs.top_k_change_threshold_) &&
43 lhs.profile_type_ == rhs.profile_type_ &&
44 lhs.max_stack_depth_ == rhs.max_stack_depth_;
45 }
46
47 bool UsuallyEquals(double expected, double actual) {
48 using FloatingPoint = ::testing::internal::FloatingPoint<double>;
49
50 FloatingPoint exp(expected);
51 FloatingPoint act(actual);
52
53 // Compare with ULPs instead of comparing with ==
54 return exp.AlmostEquals(act);
55 }
56
57 template <typename T>
58 bool UsuallyEquals(const T& expected, const T& actual,
59 typename std::enable_if<
60 detail::SupportsEqualityOperator<T>::value>::type* = 0) {
61 return expected == actual;
62 }
63
64 // Try to use memcmp to compare simple plain-old-data structs.
65 //
66 // This should *not* generate false positives, but it can generate false negatives.
67 // This will mostly work except for fields like float which can have different bit patterns
68 // that are nevertheless equal.
69 // If a test is failing because the structs aren't "equal" when they really are
70 // then it's recommended to implement operator== for it instead.
71 template <typename T, typename ... Ignore>
72 bool UsuallyEquals(const T& expected, const T& actual,
73 const Ignore& ... more ATTRIBUTE_UNUSED,
74 typename std::enable_if<std::is_pod<T>::value>::type* = 0,
75 typename std::enable_if<!detail::SupportsEqualityOperator<T>::value>::type* = 0
76 ) {
77 return memcmp(std::addressof(expected), std::addressof(actual), sizeof(T)) == 0;
78 }
79
80 bool UsuallyEquals(const XGcOption& expected, const XGcOption& actual) {
81 return memcmp(std::addressof(expected), std::addressof(actual), sizeof(expected)) == 0;
82 }
83
84 bool UsuallyEquals(const char* expected, std::string actual) {
85 return std::string(expected) == actual;
86 }
87
88 template <typename TMap, typename TKey, typename T>
89 ::testing::AssertionResult IsExpectedKeyValue(const T& expected,
90 const TMap& map,
91 const TKey& key) {
92 auto* actual = map.Get(key);
93 if (actual != nullptr) {
94 if (!UsuallyEquals(expected, *actual)) {
95 return ::testing::AssertionFailure()
96 << "expected " << detail::ToStringAny(expected) << " but got "
97 << detail::ToStringAny(*actual);
98 }
99 return ::testing::AssertionSuccess();
100 }
101
102 return ::testing::AssertionFailure() << "key was not in the map";
103 }
104
Igor Murashkin158f35c2015-06-10 15:55:30 -0700105 template <typename TMap, typename TKey, typename T>
106 ::testing::AssertionResult IsExpectedDefaultKeyValue(const T& expected,
107 const TMap& map,
108 const TKey& key) {
109 const T& actual = map.GetOrDefault(key);
110 if (!UsuallyEquals(expected, actual)) {
111 return ::testing::AssertionFailure()
112 << "expected " << detail::ToStringAny(expected) << " but got "
113 << detail::ToStringAny(actual);
114 }
115 return ::testing::AssertionSuccess();
116 }
117
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800118class CmdlineParserTest : public ::testing::Test {
119 public:
120 CmdlineParserTest() = default;
121 ~CmdlineParserTest() = default;
122
123 protected:
124 using M = RuntimeArgumentMap;
125 using RuntimeParser = ParsedOptions::RuntimeParser;
126
127 static void SetUpTestCase() {
128 art::InitLogging(nullptr); // argv = null
129 }
130
131 virtual void SetUp() {
132 parser_ = ParsedOptions::MakeParser(false); // do not ignore unrecognized options
133 }
134
135 static ::testing::AssertionResult IsResultSuccessful(CmdlineResult result) {
136 if (result.IsSuccess()) {
137 return ::testing::AssertionSuccess();
138 } else {
139 return ::testing::AssertionFailure()
140 << result.GetStatus() << " with: " << result.GetMessage();
141 }
142 }
143
144 static ::testing::AssertionResult IsResultFailure(CmdlineResult result,
145 CmdlineResult::Status failure_status) {
146 if (result.IsSuccess()) {
147 return ::testing::AssertionFailure() << " got success but expected failure: "
148 << failure_status;
149 } else if (result.GetStatus() == failure_status) {
150 return ::testing::AssertionSuccess();
151 }
152
153 return ::testing::AssertionFailure() << " expected failure " << failure_status
154 << " but got " << result.GetStatus();
155 }
156
157 std::unique_ptr<RuntimeParser> parser_;
158};
159
160#define EXPECT_KEY_EXISTS(map, key) EXPECT_TRUE((map).Exists(key))
161#define EXPECT_KEY_VALUE(map, key, expected) EXPECT_TRUE(IsExpectedKeyValue(expected, map, key))
Igor Murashkin158f35c2015-06-10 15:55:30 -0700162#define EXPECT_DEFAULT_KEY_VALUE(map, key, expected) EXPECT_TRUE(IsExpectedDefaultKeyValue(expected, map, key))
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800163
Igor Murashkin158f35c2015-06-10 15:55:30 -0700164#define _EXPECT_SINGLE_PARSE_EMPTY_SUCCESS(argv) \
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800165 do { \
166 EXPECT_TRUE(IsResultSuccessful(parser_->Parse(argv))); \
167 EXPECT_EQ(0u, parser_->GetArgumentsMap().Size()); \
Igor Murashkin158f35c2015-06-10 15:55:30 -0700168
169#define EXPECT_SINGLE_PARSE_EMPTY_SUCCESS(argv) \
170 _EXPECT_SINGLE_PARSE_EMPTY_SUCCESS(argv); \
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800171 } while (false)
172
Igor Murashkin158f35c2015-06-10 15:55:30 -0700173#define EXPECT_SINGLE_PARSE_DEFAULT_VALUE(expected, argv, key)\
174 _EXPECT_SINGLE_PARSE_EMPTY_SUCCESS(argv); \
175 RuntimeArgumentMap args = parser_->ReleaseArgumentsMap(); \
176 EXPECT_DEFAULT_KEY_VALUE(args, key, expected); \
177 } while (false) // NOLINT [readability/namespace] [5]
178
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800179#define _EXPECT_SINGLE_PARSE_EXISTS(argv, key) \
180 do { \
181 EXPECT_TRUE(IsResultSuccessful(parser_->Parse(argv))); \
182 RuntimeArgumentMap args = parser_->ReleaseArgumentsMap(); \
183 EXPECT_EQ(1u, args.Size()); \
184 EXPECT_KEY_EXISTS(args, key); \
185
186#define EXPECT_SINGLE_PARSE_EXISTS(argv, key) \
187 _EXPECT_SINGLE_PARSE_EXISTS(argv, key); \
188 } while (false)
189
190#define EXPECT_SINGLE_PARSE_VALUE(expected, argv, key) \
191 _EXPECT_SINGLE_PARSE_EXISTS(argv, key); \
192 EXPECT_KEY_VALUE(args, key, expected); \
193 } while (false) // NOLINT [readability/namespace] [5]
194
195#define EXPECT_SINGLE_PARSE_VALUE_STR(expected, argv, key) \
196 EXPECT_SINGLE_PARSE_VALUE(std::string(expected), argv, key)
197
198#define EXPECT_SINGLE_PARSE_FAIL(argv, failure_status) \
199 do { \
200 EXPECT_TRUE(IsResultFailure(parser_->Parse(argv), failure_status));\
201 RuntimeArgumentMap args = parser_->ReleaseArgumentsMap();\
202 EXPECT_EQ(0u, args.Size()); \
203 } while (false)
204
205TEST_F(CmdlineParserTest, TestSimpleSuccesses) {
206 auto& parser = *parser_;
207
208 EXPECT_LT(0u, parser.CountDefinedArguments());
209
210 {
211 // Test case 1: No command line arguments
212 EXPECT_TRUE(IsResultSuccessful(parser.Parse("")));
213 RuntimeArgumentMap args = parser.ReleaseArgumentsMap();
214 EXPECT_EQ(0u, args.Size());
215 }
216
217 EXPECT_SINGLE_PARSE_EXISTS("-Xzygote", M::Zygote);
218 EXPECT_SINGLE_PARSE_VALUE_STR("/hello/world", "-Xbootclasspath:/hello/world", M::BootClassPath);
219 EXPECT_SINGLE_PARSE_VALUE("/hello/world", "-Xbootclasspath:/hello/world", M::BootClassPath);
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800220 EXPECT_SINGLE_PARSE_VALUE(Memory<1>(234), "-Xss234", M::StackSize);
221 EXPECT_SINGLE_PARSE_VALUE(MemoryKiB(1234*MB), "-Xms1234m", M::MemoryInitialSize);
222 EXPECT_SINGLE_PARSE_VALUE(true, "-XX:EnableHSpaceCompactForOOM", M::EnableHSpaceCompactForOOM);
223 EXPECT_SINGLE_PARSE_VALUE(false, "-XX:DisableHSpaceCompactForOOM", M::EnableHSpaceCompactForOOM);
224 EXPECT_SINGLE_PARSE_VALUE(0.5, "-XX:HeapTargetUtilization=0.5", M::HeapTargetUtilization);
225 EXPECT_SINGLE_PARSE_VALUE(5u, "-XX:ParallelGCThreads=5", M::ParallelGCThreads);
Jean Christophe Beyler24e04aa2014-09-12 12:03:25 -0700226 EXPECT_SINGLE_PARSE_EXISTS("-Xno-dex-file-fallback", M::NoDexFileFallback);
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800227} // TEST_F
228
229TEST_F(CmdlineParserTest, TestSimpleFailures) {
230 // Test argument is unknown to the parser
231 EXPECT_SINGLE_PARSE_FAIL("abcdefg^%@#*(@#", CmdlineResult::kUnknown);
232 // Test value map substitution fails
233 EXPECT_SINGLE_PARSE_FAIL("-Xverify:whatever", CmdlineResult::kFailure);
234 // Test value type parsing failures
235 EXPECT_SINGLE_PARSE_FAIL("-Xsswhatever", CmdlineResult::kFailure); // invalid memory value
236 EXPECT_SINGLE_PARSE_FAIL("-Xms123", CmdlineResult::kFailure); // memory value too small
237 EXPECT_SINGLE_PARSE_FAIL("-XX:HeapTargetUtilization=0.0", CmdlineResult::kOutOfRange); // toosmal
238 EXPECT_SINGLE_PARSE_FAIL("-XX:HeapTargetUtilization=2.0", CmdlineResult::kOutOfRange); // toolarg
239 EXPECT_SINGLE_PARSE_FAIL("-XX:ParallelGCThreads=-5", CmdlineResult::kOutOfRange); // too small
240 EXPECT_SINGLE_PARSE_FAIL("-Xgc:blablabla", CmdlineResult::kUsage); // not a valid suboption
241} // TEST_F
242
243TEST_F(CmdlineParserTest, TestLogVerbosity) {
244 {
245 const char* log_args = "-verbose:"
246 "class,compiler,gc,heap,jdwp,jni,monitor,profiler,signals,startup,third-party-jni,"
247 "threads,verifier";
248
249 LogVerbosity log_verbosity = LogVerbosity();
250 log_verbosity.class_linker = true;
251 log_verbosity.compiler = true;
252 log_verbosity.gc = true;
253 log_verbosity.heap = true;
254 log_verbosity.jdwp = true;
255 log_verbosity.jni = true;
256 log_verbosity.monitor = true;
257 log_verbosity.profiler = true;
258 log_verbosity.signals = true;
259 log_verbosity.startup = true;
260 log_verbosity.third_party_jni = true;
261 log_verbosity.threads = true;
262 log_verbosity.verifier = true;
263
264 EXPECT_SINGLE_PARSE_VALUE(log_verbosity, log_args, M::Verbose);
265 }
266
267 {
268 const char* log_args = "-verbose:"
269 "class,compiler,gc,heap,jdwp,jni,monitor";
270
271 LogVerbosity log_verbosity = LogVerbosity();
272 log_verbosity.class_linker = true;
273 log_verbosity.compiler = true;
274 log_verbosity.gc = true;
275 log_verbosity.heap = true;
276 log_verbosity.jdwp = true;
277 log_verbosity.jni = true;
278 log_verbosity.monitor = true;
279
280 EXPECT_SINGLE_PARSE_VALUE(log_verbosity, log_args, M::Verbose);
281 }
282
283 EXPECT_SINGLE_PARSE_FAIL("-verbose:blablabla", CmdlineResult::kUsage); // invalid verbose opt
Richard Uhler66d874d2015-01-15 09:37:19 -0800284
285 {
Sebastien Hertzbba348e2015-06-01 08:28:18 +0200286 const char* log_args = "-verbose:deopt";
287 LogVerbosity log_verbosity = LogVerbosity();
288 log_verbosity.deopt = true;
289 EXPECT_SINGLE_PARSE_VALUE(log_verbosity, log_args, M::Verbose);
290 }
291
292 {
Richard Uhler66d874d2015-01-15 09:37:19 -0800293 const char* log_args = "-verbose:oat";
294 LogVerbosity log_verbosity = LogVerbosity();
295 log_verbosity.oat = true;
296 EXPECT_SINGLE_PARSE_VALUE(log_verbosity, log_args, M::Verbose);
297 }
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800298} // TEST_F
299
Nicolas Geoffray8f4ee5c2015-02-05 10:14:10 +0000300// TODO: Enable this b/19274810
301TEST_F(CmdlineParserTest, DISABLED_TestXGcOption) {
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800302 /*
303 * Test success
304 */
305 {
306 XGcOption option_all_true{}; // NOLINT [readability/braces] [4]
307 option_all_true.collector_type_ = gc::CollectorType::kCollectorTypeCMS;
308 option_all_true.verify_pre_gc_heap_ = true;
309 option_all_true.verify_pre_sweeping_heap_ = true;
310 option_all_true.verify_post_gc_heap_ = true;
311 option_all_true.verify_pre_gc_rosalloc_ = true;
312 option_all_true.verify_pre_sweeping_rosalloc_ = true;
313 option_all_true.verify_post_gc_rosalloc_ = true;
314
315 const char * xgc_args_all_true = "-Xgc:concurrent,"
316 "preverify,presweepingverify,postverify,"
317 "preverify_rosalloc,presweepingverify_rosalloc,"
318 "postverify_rosalloc,precise,"
319 "verifycardtable";
320
321 EXPECT_SINGLE_PARSE_VALUE(option_all_true, xgc_args_all_true, M::GcOption);
322
323 XGcOption option_all_false{}; // NOLINT [readability/braces] [4]
324 option_all_false.collector_type_ = gc::CollectorType::kCollectorTypeMS;
325 option_all_false.verify_pre_gc_heap_ = false;
326 option_all_false.verify_pre_sweeping_heap_ = false;
327 option_all_false.verify_post_gc_heap_ = false;
328 option_all_false.verify_pre_gc_rosalloc_ = false;
329 option_all_false.verify_pre_sweeping_rosalloc_ = false;
330 option_all_false.verify_post_gc_rosalloc_ = false;
331
332 const char* xgc_args_all_false = "-Xgc:nonconcurrent,"
333 "nopreverify,nopresweepingverify,nopostverify,nopreverify_rosalloc,"
334 "nopresweepingverify_rosalloc,nopostverify_rosalloc,noprecise,noverifycardtable";
335
336 EXPECT_SINGLE_PARSE_VALUE(option_all_false, xgc_args_all_false, M::GcOption);
337
338 XGcOption option_all_default{}; // NOLINT [readability/braces] [4]
339
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800340 const char* xgc_args_blank = "-Xgc:";
341 EXPECT_SINGLE_PARSE_VALUE(option_all_default, xgc_args_blank, M::GcOption);
342 }
343
344 /*
345 * Test failures
346 */
347 EXPECT_SINGLE_PARSE_FAIL("-Xgc:blablabla", CmdlineResult::kUsage); // invalid Xgc opt
348} // TEST_F
349
350/*
351 * {"-Xrunjdwp:_", "-agentlib:jdwp=_"}
352 */
353TEST_F(CmdlineParserTest, TestJdwpOptions) {
354 /*
355 * Test success
356 */
357 {
358 /*
359 * "Example: -Xrunjdwp:transport=dt_socket,address=8000,server=y\n"
360 */
361 JDWP::JdwpOptions opt = JDWP::JdwpOptions();
362 opt.transport = JDWP::JdwpTransportType::kJdwpTransportSocket;
363 opt.port = 8000;
364 opt.server = true;
365
366 const char *opt_args = "-Xrunjdwp:transport=dt_socket,address=8000,server=y";
367
368 EXPECT_SINGLE_PARSE_VALUE(opt, opt_args, M::JdwpOptions);
369 }
370
371 {
372 /*
373 * "Example: -agentlib:jdwp=transport=dt_socket,address=localhost:6500,server=n\n");
374 */
375 JDWP::JdwpOptions opt = JDWP::JdwpOptions();
376 opt.transport = JDWP::JdwpTransportType::kJdwpTransportSocket;
377 opt.host = "localhost";
378 opt.port = 6500;
379 opt.server = false;
380
381 const char *opt_args = "-agentlib:jdwp=transport=dt_socket,address=localhost:6500,server=n";
382
383 EXPECT_SINGLE_PARSE_VALUE(opt, opt_args, M::JdwpOptions);
384 }
385
386 /*
387 * Test failures
388 */
389 EXPECT_SINGLE_PARSE_FAIL("-Xrunjdwp:help", CmdlineResult::kUsage); // usage for help only
390 EXPECT_SINGLE_PARSE_FAIL("-Xrunjdwp:blabla", CmdlineResult::kFailure); // invalid subarg
391 EXPECT_SINGLE_PARSE_FAIL("-agentlib:jdwp=help", CmdlineResult::kUsage); // usage for help only
392 EXPECT_SINGLE_PARSE_FAIL("-agentlib:jdwp=blabla", CmdlineResult::kFailure); // invalid subarg
393} // TEST_F
394
395/*
396 * -D_ -D_ -D_ ...
397 */
398TEST_F(CmdlineParserTest, TestPropertiesList) {
399 /*
400 * Test successes
401 */
402 {
403 std::vector<std::string> opt = {"hello"};
404
405 EXPECT_SINGLE_PARSE_VALUE(opt, "-Dhello", M::PropertiesList);
406 }
407
408 {
409 std::vector<std::string> opt = {"hello", "world"};
410
411 EXPECT_SINGLE_PARSE_VALUE(opt, "-Dhello -Dworld", M::PropertiesList);
412 }
413
414 {
415 std::vector<std::string> opt = {"one", "two", "three"};
416
417 EXPECT_SINGLE_PARSE_VALUE(opt, "-Done -Dtwo -Dthree", M::PropertiesList);
418 }
419} // TEST_F
420
421/*
422* -Xcompiler-option foo -Xcompiler-option bar ...
423*/
424TEST_F(CmdlineParserTest, TestCompilerOption) {
425 /*
426 * Test successes
427 */
428 {
429 std::vector<std::string> opt = {"hello"};
430 EXPECT_SINGLE_PARSE_VALUE(opt, "-Xcompiler-option hello", M::CompilerOptions);
431 }
432
433 {
434 std::vector<std::string> opt = {"hello", "world"};
435 EXPECT_SINGLE_PARSE_VALUE(opt,
436 "-Xcompiler-option hello -Xcompiler-option world",
437 M::CompilerOptions);
438 }
439
440 {
441 std::vector<std::string> opt = {"one", "two", "three"};
442 EXPECT_SINGLE_PARSE_VALUE(opt,
443 "-Xcompiler-option one -Xcompiler-option two -Xcompiler-option three",
444 M::CompilerOptions);
445 }
446} // TEST_F
447
448/*
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800449* -Xjit, -Xnojit, -Xjitcodecachesize, Xjitcompilethreshold
450*/
451TEST_F(CmdlineParserTest, TestJitOptions) {
452 /*
453 * Test successes
454 */
455 {
Andreas Gampe26826992015-03-05 18:48:52 -0800456 EXPECT_SINGLE_PARSE_VALUE(true, "-Xusejit:true", M::UseJIT);
457 EXPECT_SINGLE_PARSE_VALUE(false, "-Xusejit:false", M::UseJIT);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800458 }
459 {
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000460 EXPECT_SINGLE_PARSE_VALUE(
Nicolas Geoffray295a5962015-11-19 18:17:41 +0000461 MemoryKiB(16 * KB), "-Xjitinitialsize:16K", M::JITCodeCacheInitialCapacity);
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000462 EXPECT_SINGLE_PARSE_VALUE(
Nicolas Geoffray295a5962015-11-19 18:17:41 +0000463 MemoryKiB(16 * MB), "-Xjitmaxsize:16M", M::JITCodeCacheMaxCapacity);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800464 }
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
Alex Lighteb7c1442015-08-31 13:17:42 -0700535/* -Xexperimental:_ */
536TEST_F(CmdlineParserTest, TestExperimentalFlags) {
Igor Murashkin158f35c2015-06-10 15:55:30 -0700537 // Off by default
Alex Lighteb7c1442015-08-31 13:17:42 -0700538 EXPECT_SINGLE_PARSE_DEFAULT_VALUE(ExperimentalFlags::kNone,
Igor Murashkin158f35c2015-06-10 15:55:30 -0700539 "",
Alex Lighteb7c1442015-08-31 13:17:42 -0700540 M::Experimental);
Igor Murashkin158f35c2015-06-10 15:55:30 -0700541
542 // Disabled explicitly
Alex Lighteb7c1442015-08-31 13:17:42 -0700543 EXPECT_SINGLE_PARSE_VALUE(ExperimentalFlags::kNone,
544 "-Xexperimental:none",
545 M::Experimental);
Igor Murashkin158f35c2015-06-10 15:55:30 -0700546
547 // Enabled explicitly
Alex Lighteb7c1442015-08-31 13:17:42 -0700548 EXPECT_SINGLE_PARSE_VALUE(ExperimentalFlags::kLambdas,
549 "-Xexperimental:lambdas",
550 M::Experimental);
551 // Enabled explicitly
552 EXPECT_SINGLE_PARSE_VALUE(ExperimentalFlags::kDefaultMethods,
553 "-Xexperimental:default-methods",
554 M::Experimental);
555
556 // Enabled both
557 EXPECT_SINGLE_PARSE_VALUE(ExperimentalFlags::kDefaultMethods | ExperimentalFlags::kLambdas,
558 "-Xexperimental:default-methods "
559 "-Xexperimental:lambdas",
560 M::Experimental);
Igor Murashkin158f35c2015-06-10 15:55:30 -0700561}
562
Igor Murashkin7617abd2015-07-10 18:27:47 -0700563// -Xverify:_
564TEST_F(CmdlineParserTest, TestVerify) {
565 EXPECT_SINGLE_PARSE_VALUE(verifier::VerifyMode::kNone, "-Xverify:none", M::Verify);
566 EXPECT_SINGLE_PARSE_VALUE(verifier::VerifyMode::kEnable, "-Xverify:remote", M::Verify);
567 EXPECT_SINGLE_PARSE_VALUE(verifier::VerifyMode::kEnable, "-Xverify:all", M::Verify);
568 EXPECT_SINGLE_PARSE_VALUE(verifier::VerifyMode::kSoftFail, "-Xverify:softfail", M::Verify);
569}
570
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800571TEST_F(CmdlineParserTest, TestIgnoreUnrecognized) {
572 RuntimeParser::Builder parserBuilder;
573
574 parserBuilder
575 .Define("-help")
576 .IntoKey(M::Help)
577 .IgnoreUnrecognized(true);
578
579 parser_.reset(new RuntimeParser(parserBuilder.Build()));
580
581 EXPECT_SINGLE_PARSE_EMPTY_SUCCESS("-non-existent-option");
582 EXPECT_SINGLE_PARSE_EMPTY_SUCCESS("-non-existent-option1 --non-existent-option-2");
583} // TEST_F
584
585TEST_F(CmdlineParserTest, TestIgnoredArguments) {
586 std::initializer_list<const char*> ignored_args = {
587 "-ea", "-da", "-enableassertions", "-disableassertions", "--runtime-arg", "-esa",
588 "-dsa", "-enablesystemassertions", "-disablesystemassertions", "-Xrs", "-Xint:abdef",
589 "-Xdexopt:foobar", "-Xnoquithandler", "-Xjnigreflimit:ixnay", "-Xgenregmap", "-Xnogenregmap",
590 "-Xverifyopt:never", "-Xcheckdexsum", "-Xincludeselectedop", "-Xjitop:noop",
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800591 "-Xincludeselectedmethod", "-Xjitblocking", "-Xjitmethod:_", "-Xjitclass:nosuchluck",
592 "-Xjitoffset:none", "-Xjitconfig:yes", "-Xjitcheckcg", "-Xjitverbose", "-Xjitprofile",
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800593 "-Xjitdisableopt", "-Xjitsuspendpoll", "-XX:mainThreadStackSize=1337"
594 };
595
596 // Check they are ignored when parsed one at a time
597 for (auto&& arg : ignored_args) {
598 SCOPED_TRACE(arg);
599 EXPECT_SINGLE_PARSE_EMPTY_SUCCESS(arg);
600 }
601
602 // Check they are ignored when we pass it all together at once
603 std::vector<const char*> argv = ignored_args;
604 EXPECT_SINGLE_PARSE_EMPTY_SUCCESS(argv);
605} // TEST_F
606
607TEST_F(CmdlineParserTest, MultipleArguments) {
608 EXPECT_TRUE(IsResultSuccessful(parser_->Parse(
609 "-help -XX:ForegroundHeapGrowthMultiplier=0.5 "
610 "-Xnodex2oat -Xmethod-trace -XX:LargeObjectSpace=map")));
611
612 auto&& map = parser_->ReleaseArgumentsMap();
613 EXPECT_EQ(5u, map.Size());
614 EXPECT_KEY_VALUE(map, M::Help, Unit{}); // NOLINT [whitespace/braces] [5]
615 EXPECT_KEY_VALUE(map, M::ForegroundHeapGrowthMultiplier, 0.5);
616 EXPECT_KEY_VALUE(map, M::Dex2Oat, false);
617 EXPECT_KEY_VALUE(map, M::MethodTrace, Unit{}); // NOLINT [whitespace/braces] [5]
618 EXPECT_KEY_VALUE(map, M::LargeObjectSpace, gc::space::LargeObjectSpaceType::kMap);
619} // TEST_F
620} // namespace art