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