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