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 | |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 21 | #include "common_runtime_test.h" |
Carl Shapiro | fc322c7 | 2011-07-27 00:20:01 -0700 | [diff] [blame] | 22 | |
| 23 | namespace art { |
Carl Shapiro | fc322c7 | 2011-07-27 00:20:01 -0700 | [diff] [blame] | 24 | |
Igor Murashkin | eb6c7c2 | 2015-02-04 17:30:43 -0800 | [diff] [blame] | 25 | class ParsedOptionsTest : public ::testing::Test { |
| 26 | public: |
| 27 | static void SetUpTestCase() { |
| 28 | CommonRuntimeTest::SetUpAndroidRoot(); |
| 29 | } |
| 30 | }; |
Carl Shapiro | fc322c7 | 2011-07-27 00:20:01 -0700 | [diff] [blame] | 31 | |
Brian Carlstrom | 491ca9e | 2014-03-02 18:24:38 -0800 | [diff] [blame] | 32 | TEST_F(ParsedOptionsTest, ParsedOptions) { |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 33 | void* test_vfprintf = reinterpret_cast<void*>(0xa); |
| 34 | void* test_abort = reinterpret_cast<void*>(0xb); |
| 35 | void* test_exit = reinterpret_cast<void*>(0xc); |
| 36 | void* null = reinterpret_cast<void*>(NULL); |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 37 | |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 38 | std::string lib_core(CommonRuntimeTest::GetLibCoreDexFileName()); |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 39 | |
| 40 | std::string boot_class_path; |
| 41 | boot_class_path += "-Xbootclasspath:"; |
| 42 | boot_class_path += lib_core; |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 43 | |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 44 | RuntimeOptions options; |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 45 | options.push_back(std::make_pair(boot_class_path.c_str(), null)); |
| 46 | options.push_back(std::make_pair("-classpath", null)); |
| 47 | options.push_back(std::make_pair(lib_core.c_str(), null)); |
| 48 | options.push_back(std::make_pair("-cp", null)); |
| 49 | options.push_back(std::make_pair(lib_core.c_str(), null)); |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 50 | options.push_back(std::make_pair("-Ximage:boot_image", null)); |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 51 | options.push_back(std::make_pair("-Xcheck:jni", null)); |
| 52 | options.push_back(std::make_pair("-Xms2048", null)); |
| 53 | options.push_back(std::make_pair("-Xmx4k", null)); |
| 54 | options.push_back(std::make_pair("-Xss1m", null)); |
Brian Carlstrom | bd86bcc | 2013-03-10 20:26:16 -0700 | [diff] [blame] | 55 | options.push_back(std::make_pair("-XX:HeapTargetUtilization=0.75", null)); |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 56 | options.push_back(std::make_pair("-Dfoo=bar", null)); |
| 57 | options.push_back(std::make_pair("-Dbaz=qux", null)); |
| 58 | options.push_back(std::make_pair("-verbose:gc,class,jni", null)); |
| 59 | options.push_back(std::make_pair("vfprintf", test_vfprintf)); |
| 60 | options.push_back(std::make_pair("abort", test_abort)); |
| 61 | options.push_back(std::make_pair("exit", test_exit)); |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 62 | |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 63 | RuntimeArgumentMap map; |
| 64 | std::unique_ptr<ParsedOptions> parsed(ParsedOptions::Create(options, false, &map)); |
| 65 | ASSERT_TRUE(parsed.get() != NULL); |
| 66 | ASSERT_NE(0u, map.Size()); |
| 67 | |
| 68 | using Opt = RuntimeArgumentMap; |
| 69 | |
| 70 | #define EXPECT_PARSED_EQ(expected, actual_key) EXPECT_EQ(expected, map.GetOrDefault(actual_key)) |
| 71 | #define EXPECT_PARSED_EXISTS(actual_key) EXPECT_TRUE(map.Exists(actual_key)) |
| 72 | |
| 73 | EXPECT_PARSED_EQ(lib_core, Opt::BootClassPath); |
| 74 | EXPECT_PARSED_EQ(lib_core, Opt::ClassPath); |
| 75 | EXPECT_PARSED_EQ(std::string("boot_image"), Opt::Image); |
| 76 | EXPECT_PARSED_EXISTS(Opt::CheckJni); |
| 77 | EXPECT_PARSED_EQ(2048U, Opt::MemoryInitialSize); |
| 78 | EXPECT_PARSED_EQ(4 * KB, Opt::MemoryMaximumSize); |
| 79 | EXPECT_PARSED_EQ(1 * MB, Opt::StackSize); |
| 80 | EXPECT_DOUBLE_EQ(0.75, map.GetOrDefault(Opt::HeapTargetUtilization)); |
| 81 | EXPECT_TRUE(test_vfprintf == map.GetOrDefault(Opt::HookVfprintf)); |
| 82 | EXPECT_TRUE(test_exit == map.GetOrDefault(Opt::HookExit)); |
| 83 | EXPECT_TRUE(test_abort == map.GetOrDefault(Opt::HookAbort)); |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 84 | EXPECT_TRUE(VLOG_IS_ON(class_linker)); |
| 85 | EXPECT_FALSE(VLOG_IS_ON(compiler)); |
| 86 | EXPECT_FALSE(VLOG_IS_ON(heap)); |
| 87 | EXPECT_TRUE(VLOG_IS_ON(gc)); |
| 88 | EXPECT_FALSE(VLOG_IS_ON(jdwp)); |
| 89 | EXPECT_TRUE(VLOG_IS_ON(jni)); |
| 90 | EXPECT_FALSE(VLOG_IS_ON(monitor)); |
| 91 | EXPECT_FALSE(VLOG_IS_ON(startup)); |
| 92 | EXPECT_FALSE(VLOG_IS_ON(third_party_jni)); |
| 93 | EXPECT_FALSE(VLOG_IS_ON(threads)); |
Igor Murashkin | aaebaa0 | 2015-01-26 10:55:53 -0800 | [diff] [blame] | 94 | |
| 95 | auto&& properties_list = map.GetOrDefault(Opt::PropertiesList); |
| 96 | ASSERT_EQ(2U, properties_list.size()); |
| 97 | EXPECT_EQ("foo=bar", properties_list[0]); |
| 98 | EXPECT_EQ("baz=qux", properties_list[1]); |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Igor Murashkin | 2798da1 | 2015-02-06 17:59:39 -0800 | [diff] [blame] | 101 | TEST_F(ParsedOptionsTest, ParsedOptionsGc) { |
| 102 | RuntimeOptions options; |
| 103 | options.push_back(std::make_pair("-Xgc:MC", nullptr)); |
| 104 | |
| 105 | RuntimeArgumentMap map; |
| 106 | std::unique_ptr<ParsedOptions> parsed(ParsedOptions::Create(options, false, &map)); |
| 107 | ASSERT_TRUE(parsed.get() != NULL); |
| 108 | ASSERT_NE(0u, map.Size()); |
| 109 | |
| 110 | using Opt = RuntimeArgumentMap; |
| 111 | |
| 112 | EXPECT_TRUE(map.Exists(Opt::GcOption)); |
| 113 | |
| 114 | XGcOption xgc = map.GetOrDefault(Opt::GcOption); |
| 115 | EXPECT_EQ(gc::kCollectorTypeMC, xgc.collector_type_);} |
| 116 | |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 117 | } // namespace art |