blob: 130eed2807a2a7545d0bcb34dcfcf3b3da9dee2c [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), \
26 reinterpret_cast<void*>(NULL));
27
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
104class CmdlineParserTest : public ::testing::Test {
105 public:
106 CmdlineParserTest() = default;
107 ~CmdlineParserTest() = default;
108
109 protected:
110 using M = RuntimeArgumentMap;
111 using RuntimeParser = ParsedOptions::RuntimeParser;
112
113 static void SetUpTestCase() {
114 art::InitLogging(nullptr); // argv = null
115 }
116
117 virtual void SetUp() {
118 parser_ = ParsedOptions::MakeParser(false); // do not ignore unrecognized options
119 }
120
121 static ::testing::AssertionResult IsResultSuccessful(CmdlineResult result) {
122 if (result.IsSuccess()) {
123 return ::testing::AssertionSuccess();
124 } else {
125 return ::testing::AssertionFailure()
126 << result.GetStatus() << " with: " << result.GetMessage();
127 }
128 }
129
130 static ::testing::AssertionResult IsResultFailure(CmdlineResult result,
131 CmdlineResult::Status failure_status) {
132 if (result.IsSuccess()) {
133 return ::testing::AssertionFailure() << " got success but expected failure: "
134 << failure_status;
135 } else if (result.GetStatus() == failure_status) {
136 return ::testing::AssertionSuccess();
137 }
138
139 return ::testing::AssertionFailure() << " expected failure " << failure_status
140 << " but got " << result.GetStatus();
141 }
142
143 std::unique_ptr<RuntimeParser> parser_;
144};
145
146#define EXPECT_KEY_EXISTS(map, key) EXPECT_TRUE((map).Exists(key))
147#define EXPECT_KEY_VALUE(map, key, expected) EXPECT_TRUE(IsExpectedKeyValue(expected, map, key))
148
149#define EXPECT_SINGLE_PARSE_EMPTY_SUCCESS(argv) \
150 do { \
151 EXPECT_TRUE(IsResultSuccessful(parser_->Parse(argv))); \
152 EXPECT_EQ(0u, parser_->GetArgumentsMap().Size()); \
153 } while (false)
154
155#define _EXPECT_SINGLE_PARSE_EXISTS(argv, key) \
156 do { \
157 EXPECT_TRUE(IsResultSuccessful(parser_->Parse(argv))); \
158 RuntimeArgumentMap args = parser_->ReleaseArgumentsMap(); \
159 EXPECT_EQ(1u, args.Size()); \
160 EXPECT_KEY_EXISTS(args, key); \
161
162#define EXPECT_SINGLE_PARSE_EXISTS(argv, key) \
163 _EXPECT_SINGLE_PARSE_EXISTS(argv, key); \
164 } while (false)
165
166#define EXPECT_SINGLE_PARSE_VALUE(expected, argv, key) \
167 _EXPECT_SINGLE_PARSE_EXISTS(argv, key); \
168 EXPECT_KEY_VALUE(args, key, expected); \
169 } while (false) // NOLINT [readability/namespace] [5]
170
171#define EXPECT_SINGLE_PARSE_VALUE_STR(expected, argv, key) \
172 EXPECT_SINGLE_PARSE_VALUE(std::string(expected), argv, key)
173
174#define EXPECT_SINGLE_PARSE_FAIL(argv, failure_status) \
175 do { \
176 EXPECT_TRUE(IsResultFailure(parser_->Parse(argv), failure_status));\
177 RuntimeArgumentMap args = parser_->ReleaseArgumentsMap();\
178 EXPECT_EQ(0u, args.Size()); \
179 } while (false)
180
181TEST_F(CmdlineParserTest, TestSimpleSuccesses) {
182 auto& parser = *parser_;
183
184 EXPECT_LT(0u, parser.CountDefinedArguments());
185
186 {
187 // Test case 1: No command line arguments
188 EXPECT_TRUE(IsResultSuccessful(parser.Parse("")));
189 RuntimeArgumentMap args = parser.ReleaseArgumentsMap();
190 EXPECT_EQ(0u, args.Size());
191 }
192
193 EXPECT_SINGLE_PARSE_EXISTS("-Xzygote", M::Zygote);
194 EXPECT_SINGLE_PARSE_VALUE_STR("/hello/world", "-Xbootclasspath:/hello/world", M::BootClassPath);
195 EXPECT_SINGLE_PARSE_VALUE("/hello/world", "-Xbootclasspath:/hello/world", M::BootClassPath);
196 EXPECT_SINGLE_PARSE_VALUE(false, "-Xverify:none", M::Verify);
197 EXPECT_SINGLE_PARSE_VALUE(true, "-Xverify:remote", M::Verify);
198 EXPECT_SINGLE_PARSE_VALUE(true, "-Xverify:all", M::Verify);
199 EXPECT_SINGLE_PARSE_VALUE(Memory<1>(234), "-Xss234", M::StackSize);
200 EXPECT_SINGLE_PARSE_VALUE(MemoryKiB(1234*MB), "-Xms1234m", M::MemoryInitialSize);
201 EXPECT_SINGLE_PARSE_VALUE(true, "-XX:EnableHSpaceCompactForOOM", M::EnableHSpaceCompactForOOM);
202 EXPECT_SINGLE_PARSE_VALUE(false, "-XX:DisableHSpaceCompactForOOM", M::EnableHSpaceCompactForOOM);
203 EXPECT_SINGLE_PARSE_VALUE(0.5, "-XX:HeapTargetUtilization=0.5", M::HeapTargetUtilization);
204 EXPECT_SINGLE_PARSE_VALUE(5u, "-XX:ParallelGCThreads=5", M::ParallelGCThreads);
Jean Christophe Beyler24e04aa2014-09-12 12:03:25 -0700205 EXPECT_SINGLE_PARSE_EXISTS("-Xno-dex-file-fallback", M::NoDexFileFallback);
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800206} // TEST_F
207
208TEST_F(CmdlineParserTest, TestSimpleFailures) {
209 // Test argument is unknown to the parser
210 EXPECT_SINGLE_PARSE_FAIL("abcdefg^%@#*(@#", CmdlineResult::kUnknown);
211 // Test value map substitution fails
212 EXPECT_SINGLE_PARSE_FAIL("-Xverify:whatever", CmdlineResult::kFailure);
213 // Test value type parsing failures
214 EXPECT_SINGLE_PARSE_FAIL("-Xsswhatever", CmdlineResult::kFailure); // invalid memory value
215 EXPECT_SINGLE_PARSE_FAIL("-Xms123", CmdlineResult::kFailure); // memory value too small
216 EXPECT_SINGLE_PARSE_FAIL("-XX:HeapTargetUtilization=0.0", CmdlineResult::kOutOfRange); // toosmal
217 EXPECT_SINGLE_PARSE_FAIL("-XX:HeapTargetUtilization=2.0", CmdlineResult::kOutOfRange); // toolarg
218 EXPECT_SINGLE_PARSE_FAIL("-XX:ParallelGCThreads=-5", CmdlineResult::kOutOfRange); // too small
219 EXPECT_SINGLE_PARSE_FAIL("-Xgc:blablabla", CmdlineResult::kUsage); // not a valid suboption
220} // TEST_F
221
222TEST_F(CmdlineParserTest, TestLogVerbosity) {
223 {
224 const char* log_args = "-verbose:"
225 "class,compiler,gc,heap,jdwp,jni,monitor,profiler,signals,startup,third-party-jni,"
226 "threads,verifier";
227
228 LogVerbosity log_verbosity = LogVerbosity();
229 log_verbosity.class_linker = true;
230 log_verbosity.compiler = true;
231 log_verbosity.gc = true;
232 log_verbosity.heap = true;
233 log_verbosity.jdwp = true;
234 log_verbosity.jni = true;
235 log_verbosity.monitor = true;
236 log_verbosity.profiler = true;
237 log_verbosity.signals = true;
238 log_verbosity.startup = true;
239 log_verbosity.third_party_jni = true;
240 log_verbosity.threads = true;
241 log_verbosity.verifier = true;
242
243 EXPECT_SINGLE_PARSE_VALUE(log_verbosity, log_args, M::Verbose);
244 }
245
246 {
247 const char* log_args = "-verbose:"
248 "class,compiler,gc,heap,jdwp,jni,monitor";
249
250 LogVerbosity log_verbosity = LogVerbosity();
251 log_verbosity.class_linker = true;
252 log_verbosity.compiler = true;
253 log_verbosity.gc = true;
254 log_verbosity.heap = true;
255 log_verbosity.jdwp = true;
256 log_verbosity.jni = true;
257 log_verbosity.monitor = true;
258
259 EXPECT_SINGLE_PARSE_VALUE(log_verbosity, log_args, M::Verbose);
260 }
261
262 EXPECT_SINGLE_PARSE_FAIL("-verbose:blablabla", CmdlineResult::kUsage); // invalid verbose opt
263} // TEST_F
264
Nicolas Geoffray8f4ee5c2015-02-05 10:14:10 +0000265// TODO: Enable this b/19274810
266TEST_F(CmdlineParserTest, DISABLED_TestXGcOption) {
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800267 /*
268 * Test success
269 */
270 {
271 XGcOption option_all_true{}; // NOLINT [readability/braces] [4]
272 option_all_true.collector_type_ = gc::CollectorType::kCollectorTypeCMS;
273 option_all_true.verify_pre_gc_heap_ = true;
274 option_all_true.verify_pre_sweeping_heap_ = true;
275 option_all_true.verify_post_gc_heap_ = true;
276 option_all_true.verify_pre_gc_rosalloc_ = true;
277 option_all_true.verify_pre_sweeping_rosalloc_ = true;
278 option_all_true.verify_post_gc_rosalloc_ = true;
279
280 const char * xgc_args_all_true = "-Xgc:concurrent,"
281 "preverify,presweepingverify,postverify,"
282 "preverify_rosalloc,presweepingverify_rosalloc,"
283 "postverify_rosalloc,precise,"
284 "verifycardtable";
285
286 EXPECT_SINGLE_PARSE_VALUE(option_all_true, xgc_args_all_true, M::GcOption);
287
288 XGcOption option_all_false{}; // NOLINT [readability/braces] [4]
289 option_all_false.collector_type_ = gc::CollectorType::kCollectorTypeMS;
290 option_all_false.verify_pre_gc_heap_ = false;
291 option_all_false.verify_pre_sweeping_heap_ = false;
292 option_all_false.verify_post_gc_heap_ = false;
293 option_all_false.verify_pre_gc_rosalloc_ = false;
294 option_all_false.verify_pre_sweeping_rosalloc_ = false;
295 option_all_false.verify_post_gc_rosalloc_ = false;
296
297 const char* xgc_args_all_false = "-Xgc:nonconcurrent,"
298 "nopreverify,nopresweepingverify,nopostverify,nopreverify_rosalloc,"
299 "nopresweepingverify_rosalloc,nopostverify_rosalloc,noprecise,noverifycardtable";
300
301 EXPECT_SINGLE_PARSE_VALUE(option_all_false, xgc_args_all_false, M::GcOption);
302
303 XGcOption option_all_default{}; // NOLINT [readability/braces] [4]
304
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800305 const char* xgc_args_blank = "-Xgc:";
306 EXPECT_SINGLE_PARSE_VALUE(option_all_default, xgc_args_blank, M::GcOption);
307 }
308
309 /*
310 * Test failures
311 */
312 EXPECT_SINGLE_PARSE_FAIL("-Xgc:blablabla", CmdlineResult::kUsage); // invalid Xgc opt
313} // TEST_F
314
315/*
316 * {"-Xrunjdwp:_", "-agentlib:jdwp=_"}
317 */
318TEST_F(CmdlineParserTest, TestJdwpOptions) {
319 /*
320 * Test success
321 */
322 {
323 /*
324 * "Example: -Xrunjdwp:transport=dt_socket,address=8000,server=y\n"
325 */
326 JDWP::JdwpOptions opt = JDWP::JdwpOptions();
327 opt.transport = JDWP::JdwpTransportType::kJdwpTransportSocket;
328 opt.port = 8000;
329 opt.server = true;
330
331 const char *opt_args = "-Xrunjdwp:transport=dt_socket,address=8000,server=y";
332
333 EXPECT_SINGLE_PARSE_VALUE(opt, opt_args, M::JdwpOptions);
334 }
335
336 {
337 /*
338 * "Example: -agentlib:jdwp=transport=dt_socket,address=localhost:6500,server=n\n");
339 */
340 JDWP::JdwpOptions opt = JDWP::JdwpOptions();
341 opt.transport = JDWP::JdwpTransportType::kJdwpTransportSocket;
342 opt.host = "localhost";
343 opt.port = 6500;
344 opt.server = false;
345
346 const char *opt_args = "-agentlib:jdwp=transport=dt_socket,address=localhost:6500,server=n";
347
348 EXPECT_SINGLE_PARSE_VALUE(opt, opt_args, M::JdwpOptions);
349 }
350
351 /*
352 * Test failures
353 */
354 EXPECT_SINGLE_PARSE_FAIL("-Xrunjdwp:help", CmdlineResult::kUsage); // usage for help only
355 EXPECT_SINGLE_PARSE_FAIL("-Xrunjdwp:blabla", CmdlineResult::kFailure); // invalid subarg
356 EXPECT_SINGLE_PARSE_FAIL("-agentlib:jdwp=help", CmdlineResult::kUsage); // usage for help only
357 EXPECT_SINGLE_PARSE_FAIL("-agentlib:jdwp=blabla", CmdlineResult::kFailure); // invalid subarg
358} // TEST_F
359
360/*
361 * -D_ -D_ -D_ ...
362 */
363TEST_F(CmdlineParserTest, TestPropertiesList) {
364 /*
365 * Test successes
366 */
367 {
368 std::vector<std::string> opt = {"hello"};
369
370 EXPECT_SINGLE_PARSE_VALUE(opt, "-Dhello", M::PropertiesList);
371 }
372
373 {
374 std::vector<std::string> opt = {"hello", "world"};
375
376 EXPECT_SINGLE_PARSE_VALUE(opt, "-Dhello -Dworld", M::PropertiesList);
377 }
378
379 {
380 std::vector<std::string> opt = {"one", "two", "three"};
381
382 EXPECT_SINGLE_PARSE_VALUE(opt, "-Done -Dtwo -Dthree", M::PropertiesList);
383 }
384} // TEST_F
385
386/*
387* -Xcompiler-option foo -Xcompiler-option bar ...
388*/
389TEST_F(CmdlineParserTest, TestCompilerOption) {
390 /*
391 * Test successes
392 */
393 {
394 std::vector<std::string> opt = {"hello"};
395 EXPECT_SINGLE_PARSE_VALUE(opt, "-Xcompiler-option hello", M::CompilerOptions);
396 }
397
398 {
399 std::vector<std::string> opt = {"hello", "world"};
400 EXPECT_SINGLE_PARSE_VALUE(opt,
401 "-Xcompiler-option hello -Xcompiler-option world",
402 M::CompilerOptions);
403 }
404
405 {
406 std::vector<std::string> opt = {"one", "two", "three"};
407 EXPECT_SINGLE_PARSE_VALUE(opt,
408 "-Xcompiler-option one -Xcompiler-option two -Xcompiler-option three",
409 M::CompilerOptions);
410 }
411} // TEST_F
412
413/*
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800414* -Xjit, -Xnojit, -Xjitcodecachesize, Xjitcompilethreshold
415*/
416TEST_F(CmdlineParserTest, TestJitOptions) {
417 /*
418 * Test successes
419 */
420 {
Andreas Gampe26826992015-03-05 18:48:52 -0800421 EXPECT_SINGLE_PARSE_VALUE(true, "-Xusejit:true", M::UseJIT);
422 EXPECT_SINGLE_PARSE_VALUE(false, "-Xusejit:false", M::UseJIT);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800423 }
424 {
425 EXPECT_SINGLE_PARSE_VALUE(MemoryKiB(16 * KB), "-Xjitcodecachesize:16K", M::JITCodeCacheCapacity);
426 EXPECT_SINGLE_PARSE_VALUE(MemoryKiB(16 * MB), "-Xjitcodecachesize:16M", M::JITCodeCacheCapacity);
427 }
428 {
429 EXPECT_SINGLE_PARSE_VALUE(12345u, "-Xjitthreshold:12345", M::JITCompileThreshold);
430 }
431} // TEST_F
432
433/*
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800434* -X-profile-*
435*/
436TEST_F(CmdlineParserTest, TestProfilerOptions) {
437 /*
438 * Test successes
439 */
440
441 {
442 TestProfilerOptions opt;
443 opt.enabled_ = true;
444
445 EXPECT_SINGLE_PARSE_VALUE(opt,
446 "-Xenable-profiler",
447 M::ProfilerOpts);
448 }
449
450 {
451 TestProfilerOptions opt;
452 // also need to test 'enabled'
453 opt.output_file_name_ = "hello_world.txt";
454
455 EXPECT_SINGLE_PARSE_VALUE(opt,
456 "-Xprofile-filename:hello_world.txt ",
457 M::ProfilerOpts);
458 }
459
460 {
461 TestProfilerOptions opt = TestProfilerOptions();
462 // also need to test 'enabled'
463 opt.output_file_name_ = "output.txt";
464 opt.period_s_ = 123u;
465 opt.duration_s_ = 456u;
466 opt.interval_us_ = 789u;
467 opt.backoff_coefficient_ = 2.0;
468 opt.start_immediately_ = true;
469 opt.top_k_threshold_ = 50.0;
470 opt.top_k_change_threshold_ = 60.0;
471 opt.profile_type_ = kProfilerMethod;
472 opt.max_stack_depth_ = 1337u;
473
474 EXPECT_SINGLE_PARSE_VALUE(opt,
475 "-Xprofile-filename:output.txt "
476 "-Xprofile-period:123 "
477 "-Xprofile-duration:456 "
478 "-Xprofile-interval:789 "
479 "-Xprofile-backoff:2.0 "
480 "-Xprofile-start-immediately "
481 "-Xprofile-top-k-threshold:50.0 "
482 "-Xprofile-top-k-change-threshold:60.0 "
483 "-Xprofile-type:method "
484 "-Xprofile-max-stack-depth:1337",
485 M::ProfilerOpts);
486 }
487
488 {
489 TestProfilerOptions opt = TestProfilerOptions();
490 opt.profile_type_ = kProfilerBoundedStack;
491
492 EXPECT_SINGLE_PARSE_VALUE(opt,
493 "-Xprofile-type:stack",
494 M::ProfilerOpts);
495 }
496} // TEST_F
497
498TEST_F(CmdlineParserTest, TestIgnoreUnrecognized) {
499 RuntimeParser::Builder parserBuilder;
500
501 parserBuilder
502 .Define("-help")
503 .IntoKey(M::Help)
504 .IgnoreUnrecognized(true);
505
506 parser_.reset(new RuntimeParser(parserBuilder.Build()));
507
508 EXPECT_SINGLE_PARSE_EMPTY_SUCCESS("-non-existent-option");
509 EXPECT_SINGLE_PARSE_EMPTY_SUCCESS("-non-existent-option1 --non-existent-option-2");
510} // TEST_F
511
512TEST_F(CmdlineParserTest, TestIgnoredArguments) {
513 std::initializer_list<const char*> ignored_args = {
514 "-ea", "-da", "-enableassertions", "-disableassertions", "--runtime-arg", "-esa",
515 "-dsa", "-enablesystemassertions", "-disablesystemassertions", "-Xrs", "-Xint:abdef",
516 "-Xdexopt:foobar", "-Xnoquithandler", "-Xjnigreflimit:ixnay", "-Xgenregmap", "-Xnogenregmap",
517 "-Xverifyopt:never", "-Xcheckdexsum", "-Xincludeselectedop", "-Xjitop:noop",
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800518 "-Xincludeselectedmethod", "-Xjitblocking", "-Xjitmethod:_", "-Xjitclass:nosuchluck",
519 "-Xjitoffset:none", "-Xjitconfig:yes", "-Xjitcheckcg", "-Xjitverbose", "-Xjitprofile",
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800520 "-Xjitdisableopt", "-Xjitsuspendpoll", "-XX:mainThreadStackSize=1337"
521 };
522
523 // Check they are ignored when parsed one at a time
524 for (auto&& arg : ignored_args) {
525 SCOPED_TRACE(arg);
526 EXPECT_SINGLE_PARSE_EMPTY_SUCCESS(arg);
527 }
528
529 // Check they are ignored when we pass it all together at once
530 std::vector<const char*> argv = ignored_args;
531 EXPECT_SINGLE_PARSE_EMPTY_SUCCESS(argv);
532} // TEST_F
533
534TEST_F(CmdlineParserTest, MultipleArguments) {
535 EXPECT_TRUE(IsResultSuccessful(parser_->Parse(
536 "-help -XX:ForegroundHeapGrowthMultiplier=0.5 "
537 "-Xnodex2oat -Xmethod-trace -XX:LargeObjectSpace=map")));
538
539 auto&& map = parser_->ReleaseArgumentsMap();
540 EXPECT_EQ(5u, map.Size());
541 EXPECT_KEY_VALUE(map, M::Help, Unit{}); // NOLINT [whitespace/braces] [5]
542 EXPECT_KEY_VALUE(map, M::ForegroundHeapGrowthMultiplier, 0.5);
543 EXPECT_KEY_VALUE(map, M::Dex2Oat, false);
544 EXPECT_KEY_VALUE(map, M::MethodTrace, Unit{}); // NOLINT [whitespace/braces] [5]
545 EXPECT_KEY_VALUE(map, M::LargeObjectSpace, gc::space::LargeObjectSpaceType::kMap);
546} // TEST_F
547} // namespace art