blob: 7c53e01c475c45f14c71854c49913cb2a5c0fdeb [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:"
Phil Wang751beff2015-08-28 15:17:15 +0800246 "class,compiler,gc,heap,jdwp,jni,monitor,profiler,signals,simulator,startup,"
247 "third-party-jni,threads,verifier";
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800248
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;
Phil Wang751beff2015-08-28 15:17:15 +0800259 log_verbosity.simulator = true;
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800260 log_verbosity.startup = true;
261 log_verbosity.third_party_jni = true;
262 log_verbosity.threads = true;
263 log_verbosity.verifier = true;
264
265 EXPECT_SINGLE_PARSE_VALUE(log_verbosity, log_args, M::Verbose);
266 }
267
268 {
269 const char* log_args = "-verbose:"
270 "class,compiler,gc,heap,jdwp,jni,monitor";
271
272 LogVerbosity log_verbosity = LogVerbosity();
273 log_verbosity.class_linker = true;
274 log_verbosity.compiler = true;
275 log_verbosity.gc = true;
276 log_verbosity.heap = true;
277 log_verbosity.jdwp = true;
278 log_verbosity.jni = true;
279 log_verbosity.monitor = true;
280
281 EXPECT_SINGLE_PARSE_VALUE(log_verbosity, log_args, M::Verbose);
282 }
283
284 EXPECT_SINGLE_PARSE_FAIL("-verbose:blablabla", CmdlineResult::kUsage); // invalid verbose opt
Richard Uhler66d874d2015-01-15 09:37:19 -0800285
286 {
Sebastien Hertzbba348e2015-06-01 08:28:18 +0200287 const char* log_args = "-verbose:deopt";
288 LogVerbosity log_verbosity = LogVerbosity();
289 log_verbosity.deopt = true;
290 EXPECT_SINGLE_PARSE_VALUE(log_verbosity, log_args, M::Verbose);
291 }
292
293 {
Mathieu Chartiera6e1c122016-02-19 10:25:39 -0800294 const char* log_args = "-verbose:collector";
295 LogVerbosity log_verbosity = LogVerbosity();
296 log_verbosity.collector = true;
297 EXPECT_SINGLE_PARSE_VALUE(log_verbosity, log_args, M::Verbose);
298 }
299
300 {
Richard Uhler66d874d2015-01-15 09:37:19 -0800301 const char* log_args = "-verbose:oat";
302 LogVerbosity log_verbosity = LogVerbosity();
303 log_verbosity.oat = true;
304 EXPECT_SINGLE_PARSE_VALUE(log_verbosity, log_args, M::Verbose);
305 }
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800306} // TEST_F
307
Nicolas Geoffray8f4ee5c2015-02-05 10:14:10 +0000308// TODO: Enable this b/19274810
309TEST_F(CmdlineParserTest, DISABLED_TestXGcOption) {
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800310 /*
311 * Test success
312 */
313 {
314 XGcOption option_all_true{}; // NOLINT [readability/braces] [4]
315 option_all_true.collector_type_ = gc::CollectorType::kCollectorTypeCMS;
316 option_all_true.verify_pre_gc_heap_ = true;
317 option_all_true.verify_pre_sweeping_heap_ = true;
318 option_all_true.verify_post_gc_heap_ = true;
319 option_all_true.verify_pre_gc_rosalloc_ = true;
320 option_all_true.verify_pre_sweeping_rosalloc_ = true;
321 option_all_true.verify_post_gc_rosalloc_ = true;
322
323 const char * xgc_args_all_true = "-Xgc:concurrent,"
324 "preverify,presweepingverify,postverify,"
325 "preverify_rosalloc,presweepingverify_rosalloc,"
326 "postverify_rosalloc,precise,"
327 "verifycardtable";
328
329 EXPECT_SINGLE_PARSE_VALUE(option_all_true, xgc_args_all_true, M::GcOption);
330
331 XGcOption option_all_false{}; // NOLINT [readability/braces] [4]
332 option_all_false.collector_type_ = gc::CollectorType::kCollectorTypeMS;
333 option_all_false.verify_pre_gc_heap_ = false;
334 option_all_false.verify_pre_sweeping_heap_ = false;
335 option_all_false.verify_post_gc_heap_ = false;
336 option_all_false.verify_pre_gc_rosalloc_ = false;
337 option_all_false.verify_pre_sweeping_rosalloc_ = false;
338 option_all_false.verify_post_gc_rosalloc_ = false;
339
340 const char* xgc_args_all_false = "-Xgc:nonconcurrent,"
341 "nopreverify,nopresweepingverify,nopostverify,nopreverify_rosalloc,"
342 "nopresweepingverify_rosalloc,nopostverify_rosalloc,noprecise,noverifycardtable";
343
344 EXPECT_SINGLE_PARSE_VALUE(option_all_false, xgc_args_all_false, M::GcOption);
345
346 XGcOption option_all_default{}; // NOLINT [readability/braces] [4]
347
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800348 const char* xgc_args_blank = "-Xgc:";
349 EXPECT_SINGLE_PARSE_VALUE(option_all_default, xgc_args_blank, M::GcOption);
350 }
351
352 /*
353 * Test failures
354 */
355 EXPECT_SINGLE_PARSE_FAIL("-Xgc:blablabla", CmdlineResult::kUsage); // invalid Xgc opt
356} // TEST_F
357
358/*
359 * {"-Xrunjdwp:_", "-agentlib:jdwp=_"}
360 */
361TEST_F(CmdlineParserTest, TestJdwpOptions) {
362 /*
363 * Test success
364 */
365 {
366 /*
367 * "Example: -Xrunjdwp:transport=dt_socket,address=8000,server=y\n"
368 */
369 JDWP::JdwpOptions opt = JDWP::JdwpOptions();
370 opt.transport = JDWP::JdwpTransportType::kJdwpTransportSocket;
371 opt.port = 8000;
372 opt.server = true;
373
374 const char *opt_args = "-Xrunjdwp:transport=dt_socket,address=8000,server=y";
375
376 EXPECT_SINGLE_PARSE_VALUE(opt, opt_args, M::JdwpOptions);
377 }
378
379 {
380 /*
381 * "Example: -agentlib:jdwp=transport=dt_socket,address=localhost:6500,server=n\n");
382 */
383 JDWP::JdwpOptions opt = JDWP::JdwpOptions();
384 opt.transport = JDWP::JdwpTransportType::kJdwpTransportSocket;
385 opt.host = "localhost";
386 opt.port = 6500;
387 opt.server = false;
388
389 const char *opt_args = "-agentlib:jdwp=transport=dt_socket,address=localhost:6500,server=n";
390
391 EXPECT_SINGLE_PARSE_VALUE(opt, opt_args, M::JdwpOptions);
392 }
393
394 /*
395 * Test failures
396 */
397 EXPECT_SINGLE_PARSE_FAIL("-Xrunjdwp:help", CmdlineResult::kUsage); // usage for help only
398 EXPECT_SINGLE_PARSE_FAIL("-Xrunjdwp:blabla", CmdlineResult::kFailure); // invalid subarg
399 EXPECT_SINGLE_PARSE_FAIL("-agentlib:jdwp=help", CmdlineResult::kUsage); // usage for help only
400 EXPECT_SINGLE_PARSE_FAIL("-agentlib:jdwp=blabla", CmdlineResult::kFailure); // invalid subarg
401} // TEST_F
402
403/*
404 * -D_ -D_ -D_ ...
405 */
406TEST_F(CmdlineParserTest, TestPropertiesList) {
407 /*
408 * Test successes
409 */
410 {
411 std::vector<std::string> opt = {"hello"};
412
413 EXPECT_SINGLE_PARSE_VALUE(opt, "-Dhello", M::PropertiesList);
414 }
415
416 {
417 std::vector<std::string> opt = {"hello", "world"};
418
419 EXPECT_SINGLE_PARSE_VALUE(opt, "-Dhello -Dworld", M::PropertiesList);
420 }
421
422 {
423 std::vector<std::string> opt = {"one", "two", "three"};
424
425 EXPECT_SINGLE_PARSE_VALUE(opt, "-Done -Dtwo -Dthree", M::PropertiesList);
426 }
427} // TEST_F
428
429/*
430* -Xcompiler-option foo -Xcompiler-option bar ...
431*/
432TEST_F(CmdlineParserTest, TestCompilerOption) {
433 /*
434 * Test successes
435 */
436 {
437 std::vector<std::string> opt = {"hello"};
438 EXPECT_SINGLE_PARSE_VALUE(opt, "-Xcompiler-option hello", M::CompilerOptions);
439 }
440
441 {
442 std::vector<std::string> opt = {"hello", "world"};
443 EXPECT_SINGLE_PARSE_VALUE(opt,
444 "-Xcompiler-option hello -Xcompiler-option world",
445 M::CompilerOptions);
446 }
447
448 {
449 std::vector<std::string> opt = {"one", "two", "three"};
450 EXPECT_SINGLE_PARSE_VALUE(opt,
451 "-Xcompiler-option one -Xcompiler-option two -Xcompiler-option three",
452 M::CompilerOptions);
453 }
454} // TEST_F
455
456/*
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800457* -Xjit, -Xnojit, -Xjitcodecachesize, Xjitcompilethreshold
458*/
459TEST_F(CmdlineParserTest, TestJitOptions) {
460 /*
461 * Test successes
462 */
463 {
Calin Juravlee5de54c2016-04-20 14:22:09 +0100464 EXPECT_SINGLE_PARSE_VALUE(true, "-Xusejit:true", M::UseJitCompilation);
465 EXPECT_SINGLE_PARSE_VALUE(false, "-Xusejit:false", M::UseJitCompilation);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800466 }
467 {
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000468 EXPECT_SINGLE_PARSE_VALUE(
Nicolas Geoffray295a5962015-11-19 18:17:41 +0000469 MemoryKiB(16 * KB), "-Xjitinitialsize:16K", M::JITCodeCacheInitialCapacity);
Nicolas Geoffray0a3be162015-11-18 11:15:22 +0000470 EXPECT_SINGLE_PARSE_VALUE(
Nicolas Geoffray295a5962015-11-19 18:17:41 +0000471 MemoryKiB(16 * MB), "-Xjitmaxsize:16M", M::JITCodeCacheMaxCapacity);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800472 }
473 {
474 EXPECT_SINGLE_PARSE_VALUE(12345u, "-Xjitthreshold:12345", M::JITCompileThreshold);
475 }
476} // TEST_F
477
478/*
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800479* -X-profile-*
480*/
481TEST_F(CmdlineParserTest, TestProfilerOptions) {
482 /*
483 * Test successes
484 */
485
486 {
487 TestProfilerOptions opt;
488 opt.enabled_ = true;
489
490 EXPECT_SINGLE_PARSE_VALUE(opt,
491 "-Xenable-profiler",
492 M::ProfilerOpts);
493 }
494
495 {
496 TestProfilerOptions opt;
497 // also need to test 'enabled'
498 opt.output_file_name_ = "hello_world.txt";
499
500 EXPECT_SINGLE_PARSE_VALUE(opt,
501 "-Xprofile-filename:hello_world.txt ",
502 M::ProfilerOpts);
503 }
504
505 {
506 TestProfilerOptions opt = TestProfilerOptions();
507 // also need to test 'enabled'
508 opt.output_file_name_ = "output.txt";
509 opt.period_s_ = 123u;
510 opt.duration_s_ = 456u;
511 opt.interval_us_ = 789u;
512 opt.backoff_coefficient_ = 2.0;
513 opt.start_immediately_ = true;
514 opt.top_k_threshold_ = 50.0;
515 opt.top_k_change_threshold_ = 60.0;
516 opt.profile_type_ = kProfilerMethod;
517 opt.max_stack_depth_ = 1337u;
518
519 EXPECT_SINGLE_PARSE_VALUE(opt,
520 "-Xprofile-filename:output.txt "
521 "-Xprofile-period:123 "
522 "-Xprofile-duration:456 "
523 "-Xprofile-interval:789 "
524 "-Xprofile-backoff:2.0 "
525 "-Xprofile-start-immediately "
526 "-Xprofile-top-k-threshold:50.0 "
527 "-Xprofile-top-k-change-threshold:60.0 "
528 "-Xprofile-type:method "
529 "-Xprofile-max-stack-depth:1337",
530 M::ProfilerOpts);
531 }
532
533 {
534 TestProfilerOptions opt = TestProfilerOptions();
535 opt.profile_type_ = kProfilerBoundedStack;
536
537 EXPECT_SINGLE_PARSE_VALUE(opt,
538 "-Xprofile-type:stack",
539 M::ProfilerOpts);
540 }
541} // TEST_F
542
Alex Lighteb7c1442015-08-31 13:17:42 -0700543/* -Xexperimental:_ */
544TEST_F(CmdlineParserTest, TestExperimentalFlags) {
Neil Fuller9724c632016-01-07 15:42:47 +0000545 // Default
Alex Lighteb7c1442015-08-31 13:17:42 -0700546 EXPECT_SINGLE_PARSE_DEFAULT_VALUE(ExperimentalFlags::kNone,
Igor Murashkin158f35c2015-06-10 15:55:30 -0700547 "",
Alex Lighteb7c1442015-08-31 13:17:42 -0700548 M::Experimental);
Igor Murashkin158f35c2015-06-10 15:55:30 -0700549
550 // Disabled explicitly
Alex Lighteb7c1442015-08-31 13:17:42 -0700551 EXPECT_SINGLE_PARSE_VALUE(ExperimentalFlags::kNone,
552 "-Xexperimental:none",
553 M::Experimental);
Igor Murashkin158f35c2015-06-10 15:55:30 -0700554
555 // Enabled explicitly
Alex Lighteb7c1442015-08-31 13:17:42 -0700556 EXPECT_SINGLE_PARSE_VALUE(ExperimentalFlags::kLambdas,
557 "-Xexperimental:lambdas",
558 M::Experimental);
Igor Murashkin158f35c2015-06-10 15:55:30 -0700559}
560
Igor Murashkin7617abd2015-07-10 18:27:47 -0700561// -Xverify:_
562TEST_F(CmdlineParserTest, TestVerify) {
563 EXPECT_SINGLE_PARSE_VALUE(verifier::VerifyMode::kNone, "-Xverify:none", M::Verify);
564 EXPECT_SINGLE_PARSE_VALUE(verifier::VerifyMode::kEnable, "-Xverify:remote", M::Verify);
565 EXPECT_SINGLE_PARSE_VALUE(verifier::VerifyMode::kEnable, "-Xverify:all", M::Verify);
566 EXPECT_SINGLE_PARSE_VALUE(verifier::VerifyMode::kSoftFail, "-Xverify:softfail", M::Verify);
567}
568
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800569TEST_F(CmdlineParserTest, TestIgnoreUnrecognized) {
570 RuntimeParser::Builder parserBuilder;
571
572 parserBuilder
573 .Define("-help")
574 .IntoKey(M::Help)
575 .IgnoreUnrecognized(true);
576
577 parser_.reset(new RuntimeParser(parserBuilder.Build()));
578
579 EXPECT_SINGLE_PARSE_EMPTY_SUCCESS("-non-existent-option");
580 EXPECT_SINGLE_PARSE_EMPTY_SUCCESS("-non-existent-option1 --non-existent-option-2");
581} // TEST_F
582
583TEST_F(CmdlineParserTest, TestIgnoredArguments) {
584 std::initializer_list<const char*> ignored_args = {
585 "-ea", "-da", "-enableassertions", "-disableassertions", "--runtime-arg", "-esa",
586 "-dsa", "-enablesystemassertions", "-disablesystemassertions", "-Xrs", "-Xint:abdef",
587 "-Xdexopt:foobar", "-Xnoquithandler", "-Xjnigreflimit:ixnay", "-Xgenregmap", "-Xnogenregmap",
588 "-Xverifyopt:never", "-Xcheckdexsum", "-Xincludeselectedop", "-Xjitop:noop",
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800589 "-Xincludeselectedmethod", "-Xjitblocking", "-Xjitmethod:_", "-Xjitclass:nosuchluck",
590 "-Xjitoffset:none", "-Xjitconfig:yes", "-Xjitcheckcg", "-Xjitverbose", "-Xjitprofile",
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800591 "-Xjitdisableopt", "-Xjitsuspendpoll", "-XX:mainThreadStackSize=1337"
592 };
593
594 // Check they are ignored when parsed one at a time
595 for (auto&& arg : ignored_args) {
596 SCOPED_TRACE(arg);
597 EXPECT_SINGLE_PARSE_EMPTY_SUCCESS(arg);
598 }
599
600 // Check they are ignored when we pass it all together at once
601 std::vector<const char*> argv = ignored_args;
602 EXPECT_SINGLE_PARSE_EMPTY_SUCCESS(argv);
603} // TEST_F
604
605TEST_F(CmdlineParserTest, MultipleArguments) {
606 EXPECT_TRUE(IsResultSuccessful(parser_->Parse(
607 "-help -XX:ForegroundHeapGrowthMultiplier=0.5 "
608 "-Xnodex2oat -Xmethod-trace -XX:LargeObjectSpace=map")));
609
610 auto&& map = parser_->ReleaseArgumentsMap();
611 EXPECT_EQ(5u, map.Size());
612 EXPECT_KEY_VALUE(map, M::Help, Unit{}); // NOLINT [whitespace/braces] [5]
613 EXPECT_KEY_VALUE(map, M::ForegroundHeapGrowthMultiplier, 0.5);
614 EXPECT_KEY_VALUE(map, M::Dex2Oat, false);
615 EXPECT_KEY_VALUE(map, M::MethodTrace, Unit{}); // NOLINT [whitespace/braces] [5]
616 EXPECT_KEY_VALUE(map, M::LargeObjectSpace, gc::space::LargeObjectSpaceType::kMap);
617} // TEST_F
618} // namespace art