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