Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | */ |
Carl Shapiro | fc322c7 | 2011-07-27 00:20:01 -0700 | [diff] [blame] | 16 | |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 17 | #include "parsed_options.h" |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 18 | |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 19 | #include <memory> |
| 20 | |
Andreas Gampe | a00f012 | 2015-12-16 16:54:35 -0800 | [diff] [blame] | 21 | #include "arch/instruction_set.h" |
Vladimir Marko | b9c29f6 | 2019-03-20 14:22:51 +0000 | [diff] [blame] | 22 | #include "base/common_art_test.h" |
Carl Shapiro | fc322c7 | 2011-07-27 00:20:01 -0700 | [diff] [blame] | 23 | |
| 24 | namespace art { |
Carl Shapiro | fc322c7 | 2011-07-27 00:20:01 -0700 | [diff] [blame] | 25 | |
Vladimir Marko | b9c29f6 | 2019-03-20 14:22:51 +0000 | [diff] [blame] | 26 | class ParsedOptionsTest : public CommonArtTest { |
Igor Murashkin | eb6c7c2 | 2015-02-04 17:30:43 -0800 | [diff] [blame] | 27 | public: |
| 28 | static void SetUpTestCase() { |
Vladimir Marko | b9c29f6 | 2019-03-20 14:22:51 +0000 | [diff] [blame] | 29 | CommonArtTest::SetUpAndroidRootEnvVars(); |
Igor Murashkin | eb6c7c2 | 2015-02-04 17:30:43 -0800 | [diff] [blame] | 30 | } |
| 31 | }; |
Carl Shapiro | fc322c7 | 2011-07-27 00:20:01 -0700 | [diff] [blame] | 32 | |
Peter Collingbourne | 2931057 | 2022-03-10 16:14:04 -0800 | [diff] [blame] | 33 | static int test_vfprintf(FILE*, const char*, va_list) { return 0; } |
| 34 | static void test_abort() {} |
| 35 | static void test_exit(jint) {} |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 36 | |
Peter Collingbourne | 2931057 | 2022-03-10 16:14:04 -0800 | [diff] [blame] | 37 | TEST_F(ParsedOptionsTest, ParsedOptions) { |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 38 | std::string boot_class_path; |
Przemyslaw Szczepaniak | 5b8e6e3 | 2015-09-30 14:40:33 +0100 | [diff] [blame] | 39 | std::string class_path; |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 40 | boot_class_path += "-Xbootclasspath:"; |
Przemyslaw Szczepaniak | 5b8e6e3 | 2015-09-30 14:40:33 +0100 | [diff] [blame] | 41 | |
| 42 | bool first_dex_file = true; |
Vladimir Marko | b9c29f6 | 2019-03-20 14:22:51 +0000 | [diff] [blame] | 43 | for (const std::string& dex_file_name : GetLibCoreDexFileNames()) { |
Przemyslaw Szczepaniak | 5b8e6e3 | 2015-09-30 14:40:33 +0100 | [diff] [blame] | 44 | if (!first_dex_file) { |
| 45 | class_path += ":"; |
| 46 | } else { |
| 47 | first_dex_file = false; |
| 48 | } |
| 49 | class_path += dex_file_name; |
| 50 | } |
| 51 | boot_class_path += class_path; |
Vladimir Marko | 91f1032 | 2018-12-07 18:04:10 +0000 | [diff] [blame] | 52 | std::vector<std::string> expected_boot_class_path; |
| 53 | Split(class_path, ':', &expected_boot_class_path); |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 54 | |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 55 | RuntimeOptions options; |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 56 | options.push_back(std::make_pair(boot_class_path.c_str(), nullptr)); |
| 57 | options.push_back(std::make_pair("-classpath", nullptr)); |
Narayan Kamath | d1ef436 | 2015-11-12 11:49:06 +0000 | [diff] [blame] | 58 | options.push_back(std::make_pair(class_path.c_str(), nullptr)); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 59 | options.push_back(std::make_pair("-cp", nullptr)); |
Narayan Kamath | d1ef436 | 2015-11-12 11:49:06 +0000 | [diff] [blame] | 60 | options.push_back(std::make_pair(class_path.c_str(), nullptr)); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 61 | options.push_back(std::make_pair("-Ximage:boot_image", nullptr)); |
| 62 | options.push_back(std::make_pair("-Xcheck:jni", nullptr)); |
| 63 | options.push_back(std::make_pair("-Xms2048", nullptr)); |
| 64 | options.push_back(std::make_pair("-Xmx4k", nullptr)); |
| 65 | options.push_back(std::make_pair("-Xss1m", nullptr)); |
| 66 | options.push_back(std::make_pair("-XX:HeapTargetUtilization=0.75", nullptr)); |
Hans Boehm | bb2467b | 2019-03-29 22:55:06 -0700 | [diff] [blame] | 67 | options.push_back(std::make_pair("-XX:StopForNativeAllocs=200m", nullptr)); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 68 | options.push_back(std::make_pair("-Dfoo=bar", nullptr)); |
| 69 | options.push_back(std::make_pair("-Dbaz=qux", nullptr)); |
| 70 | options.push_back(std::make_pair("-verbose:gc,class,jni", nullptr)); |
Peter Collingbourne | 2931057 | 2022-03-10 16:14:04 -0800 | [diff] [blame] | 71 | options.push_back(std::make_pair("vfprintf", reinterpret_cast<void*>(test_vfprintf))); |
| 72 | options.push_back(std::make_pair("abort", reinterpret_cast<void*>(test_abort))); |
| 73 | options.push_back(std::make_pair("exit", reinterpret_cast<void*>(test_exit))); |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 74 | |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 75 | RuntimeArgumentMap map; |
Vladimir Marko | 88b2b80 | 2015-12-04 14:19:04 +0000 | [diff] [blame] | 76 | bool parsed = ParsedOptions::Parse(options, false, &map); |
| 77 | ASSERT_TRUE(parsed); |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 78 | ASSERT_NE(0u, map.Size()); |
| 79 | |
| 80 | using Opt = RuntimeArgumentMap; |
| 81 | |
| 82 | #define EXPECT_PARSED_EQ(expected, actual_key) EXPECT_EQ(expected, map.GetOrDefault(actual_key)) |
Vladimir Marko | 91f1032 | 2018-12-07 18:04:10 +0000 | [diff] [blame] | 83 | #define EXPECT_PARSED_EQ_AS_STRING_VECTOR(expected, actual_key) \ |
| 84 | EXPECT_EQ(expected, static_cast<std::vector<std::string>>(map.GetOrDefault(actual_key))) |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 85 | #define EXPECT_PARSED_EXISTS(actual_key) EXPECT_TRUE(map.Exists(actual_key)) |
| 86 | |
Vladimir Marko | 91f1032 | 2018-12-07 18:04:10 +0000 | [diff] [blame] | 87 | EXPECT_PARSED_EQ_AS_STRING_VECTOR(expected_boot_class_path, Opt::BootClassPath); |
Narayan Kamath | d1ef436 | 2015-11-12 11:49:06 +0000 | [diff] [blame] | 88 | EXPECT_PARSED_EQ(class_path, Opt::ClassPath); |
Victor Hsieh | 61ffd04 | 2021-05-20 15:14:25 -0700 | [diff] [blame] | 89 | std::vector<std::string> boot_images = map.GetOrDefault(Opt::Image); |
| 90 | ASSERT_EQ(1U, boot_images.size()); |
| 91 | EXPECT_EQ(std::string("boot_image"), boot_images[0]); |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 92 | EXPECT_PARSED_EXISTS(Opt::CheckJni); |
| 93 | EXPECT_PARSED_EQ(2048U, Opt::MemoryInitialSize); |
| 94 | EXPECT_PARSED_EQ(4 * KB, Opt::MemoryMaximumSize); |
| 95 | EXPECT_PARSED_EQ(1 * MB, Opt::StackSize); |
Hans Boehm | bb2467b | 2019-03-29 22:55:06 -0700 | [diff] [blame] | 96 | EXPECT_PARSED_EQ(200 * MB, Opt::StopForNativeAllocs); |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 97 | EXPECT_DOUBLE_EQ(0.75, map.GetOrDefault(Opt::HeapTargetUtilization)); |
Peter Collingbourne | 2931057 | 2022-03-10 16:14:04 -0800 | [diff] [blame] | 98 | EXPECT_TRUE(reinterpret_cast<void*>(test_vfprintf) == map.GetOrDefault(Opt::HookVfprintf)); |
| 99 | EXPECT_TRUE(reinterpret_cast<void*>(test_exit) == map.GetOrDefault(Opt::HookExit)); |
| 100 | EXPECT_TRUE(reinterpret_cast<void*>(test_abort) == map.GetOrDefault(Opt::HookAbort)); |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 101 | EXPECT_TRUE(VLOG_IS_ON(class_linker)); |
| 102 | EXPECT_FALSE(VLOG_IS_ON(compiler)); |
| 103 | EXPECT_FALSE(VLOG_IS_ON(heap)); |
| 104 | EXPECT_TRUE(VLOG_IS_ON(gc)); |
Mathieu Chartier | 765b2a0 | 2019-05-02 11:04:13 -0700 | [diff] [blame] | 105 | EXPECT_FALSE(VLOG_IS_ON(interpreter)); |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 106 | EXPECT_FALSE(VLOG_IS_ON(jdwp)); |
| 107 | EXPECT_TRUE(VLOG_IS_ON(jni)); |
| 108 | EXPECT_FALSE(VLOG_IS_ON(monitor)); |
Phil Wang | 751beff | 2015-08-28 15:17:15 +0800 | [diff] [blame] | 109 | EXPECT_FALSE(VLOG_IS_ON(signals)); |
| 110 | EXPECT_FALSE(VLOG_IS_ON(simulator)); |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 111 | EXPECT_FALSE(VLOG_IS_ON(startup)); |
| 112 | EXPECT_FALSE(VLOG_IS_ON(third_party_jni)); |
| 113 | EXPECT_FALSE(VLOG_IS_ON(threads)); |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 114 | |
| 115 | auto&& properties_list = map.GetOrDefault(Opt::PropertiesList); |
| 116 | ASSERT_EQ(2U, properties_list.size()); |
| 117 | EXPECT_EQ("foo=bar", properties_list[0]); |
| 118 | EXPECT_EQ("baz=qux", properties_list[1]); |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Igor Murashkin | 2798da1 | 2015-02-06 17:59:39 -0800 | [diff] [blame] | 121 | TEST_F(ParsedOptionsTest, ParsedOptionsGc) { |
| 122 | RuntimeOptions options; |
Mathieu Chartier | f8e5d8c | 2018-04-06 13:35:37 -0700 | [diff] [blame] | 123 | options.push_back(std::make_pair("-Xgc:SS", nullptr)); |
Igor Murashkin | 2798da1 | 2015-02-06 17:59:39 -0800 | [diff] [blame] | 124 | |
| 125 | RuntimeArgumentMap map; |
Vladimir Marko | 88b2b80 | 2015-12-04 14:19:04 +0000 | [diff] [blame] | 126 | bool parsed = ParsedOptions::Parse(options, false, &map); |
| 127 | ASSERT_TRUE(parsed); |
Igor Murashkin | 2798da1 | 2015-02-06 17:59:39 -0800 | [diff] [blame] | 128 | ASSERT_NE(0u, map.Size()); |
| 129 | |
| 130 | using Opt = RuntimeArgumentMap; |
| 131 | |
| 132 | EXPECT_TRUE(map.Exists(Opt::GcOption)); |
| 133 | |
| 134 | XGcOption xgc = map.GetOrDefault(Opt::GcOption); |
Mathieu Chartier | f8e5d8c | 2018-04-06 13:35:37 -0700 | [diff] [blame] | 135 | EXPECT_EQ(gc::kCollectorTypeSS, xgc.collector_type_); |
Andreas Gampe | a00f012 | 2015-12-16 16:54:35 -0800 | [diff] [blame] | 136 | } |
| 137 | |
Albert Mingkun Yang | 0b4d146 | 2018-11-29 13:25:35 +0000 | [diff] [blame] | 138 | TEST_F(ParsedOptionsTest, ParsedOptionsGenerationalCC) { |
| 139 | RuntimeOptions options; |
| 140 | options.push_back(std::make_pair("-Xgc:generational_cc", nullptr)); |
| 141 | |
| 142 | RuntimeArgumentMap map; |
| 143 | bool parsed = ParsedOptions::Parse(options, false, &map); |
| 144 | ASSERT_TRUE(parsed); |
| 145 | ASSERT_NE(0u, map.Size()); |
| 146 | |
| 147 | using Opt = RuntimeArgumentMap; |
| 148 | |
| 149 | EXPECT_TRUE(map.Exists(Opt::GcOption)); |
| 150 | |
| 151 | XGcOption xgc = map.GetOrDefault(Opt::GcOption); |
| 152 | ASSERT_TRUE(xgc.generational_cc); |
| 153 | } |
| 154 | |
Andreas Gampe | a00f012 | 2015-12-16 16:54:35 -0800 | [diff] [blame] | 155 | TEST_F(ParsedOptionsTest, ParsedOptionsInstructionSet) { |
| 156 | using Opt = RuntimeArgumentMap; |
| 157 | |
| 158 | { |
| 159 | // Nothing set, should be kRuntimeISA. |
| 160 | RuntimeOptions options; |
| 161 | RuntimeArgumentMap map; |
| 162 | bool parsed = ParsedOptions::Parse(options, false, &map); |
| 163 | ASSERT_TRUE(parsed); |
| 164 | InstructionSet isa = map.GetOrDefault(Opt::ImageInstructionSet); |
| 165 | EXPECT_EQ(kRuntimeISA, isa); |
| 166 | } |
| 167 | |
Vladimir Marko | 41b605c | 2020-02-12 10:52:22 +0000 | [diff] [blame] | 168 | const char* isa_strings[] = { "arm", "arm64", "x86", "x86_64" }; |
Andreas Gampe | a00f012 | 2015-12-16 16:54:35 -0800 | [diff] [blame] | 169 | InstructionSet ISAs[] = { InstructionSet::kArm, |
| 170 | InstructionSet::kArm64, |
| 171 | InstructionSet::kX86, |
Vladimir Marko | 41b605c | 2020-02-12 10:52:22 +0000 | [diff] [blame] | 172 | InstructionSet::kX86_64 }; |
Andreas Gampe | a00f012 | 2015-12-16 16:54:35 -0800 | [diff] [blame] | 173 | static_assert(arraysize(isa_strings) == arraysize(ISAs), "Need same amount."); |
| 174 | |
| 175 | for (size_t i = 0; i < arraysize(isa_strings); ++i) { |
| 176 | RuntimeOptions options; |
| 177 | options.push_back(std::make_pair("imageinstructionset", isa_strings[i])); |
| 178 | RuntimeArgumentMap map; |
| 179 | bool parsed = ParsedOptions::Parse(options, false, &map); |
| 180 | ASSERT_TRUE(parsed); |
| 181 | InstructionSet isa = map.GetOrDefault(Opt::ImageInstructionSet); |
| 182 | EXPECT_EQ(ISAs[i], isa); |
| 183 | } |
| 184 | } |
Igor Murashkin | 2798da1 | 2015-02-06 17:59:39 -0800 | [diff] [blame] | 185 | |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 186 | } // namespace art |