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