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