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