blob: c32d76c715a81c364b35153159014d7529012254 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
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 Shapirofc322c72011-07-27 00:20:01 -070016
Brian Carlstrom491ca9e2014-03-02 18:24:38 -080017#include "parsed_options.h"
Elliott Hughes90a33692011-08-30 13:27:07 -070018
Ian Rogers700a4022014-05-19 16:49:03 -070019#include <memory>
20
Andreas Gampea00f0122015-12-16 16:54:35 -080021#include "arch/instruction_set.h"
22#include "base/stringprintf.h"
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080023#include "common_runtime_test.h"
Carl Shapirofc322c72011-07-27 00:20:01 -070024
25namespace art {
Carl Shapirofc322c72011-07-27 00:20:01 -070026
Igor Murashkineb6c7c22015-02-04 17:30:43 -080027class ParsedOptionsTest : public ::testing::Test {
28 public:
29 static void SetUpTestCase() {
30 CommonRuntimeTest::SetUpAndroidRoot();
31 }
32};
Carl Shapirofc322c72011-07-27 00:20:01 -070033
Brian Carlstrom491ca9e2014-03-02 18:24:38 -080034TEST_F(ParsedOptionsTest, ParsedOptions) {
Brian Carlstromf734cf52011-08-17 16:28:14 -070035 void* test_vfprintf = reinterpret_cast<void*>(0xa);
36 void* test_abort = reinterpret_cast<void*>(0xb);
37 void* test_exit = reinterpret_cast<void*>(0xc);
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070038
Igor Murashkinaaebaa02015-01-26 10:55:53 -080039 std::string lib_core(CommonRuntimeTest::GetLibCoreDexFileName());
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070040
41 std::string boot_class_path;
42 boot_class_path += "-Xbootclasspath:";
43 boot_class_path += lib_core;
Brian Carlstromf734cf52011-08-17 16:28:14 -070044
Ian Rogerse63db272014-07-15 15:36:11 -070045 RuntimeOptions options;
Mathieu Chartier2cebb242015-04-21 16:50:40 -070046 options.push_back(std::make_pair(boot_class_path.c_str(), nullptr));
47 options.push_back(std::make_pair("-classpath", nullptr));
48 options.push_back(std::make_pair(lib_core.c_str(), nullptr));
49 options.push_back(std::make_pair("-cp", nullptr));
50 options.push_back(std::make_pair(lib_core.c_str(), nullptr));
51 options.push_back(std::make_pair("-Ximage:boot_image", nullptr));
52 options.push_back(std::make_pair("-Xcheck:jni", nullptr));
53 options.push_back(std::make_pair("-Xms2048", nullptr));
54 options.push_back(std::make_pair("-Xmx4k", nullptr));
55 options.push_back(std::make_pair("-Xss1m", nullptr));
56 options.push_back(std::make_pair("-XX:HeapTargetUtilization=0.75", nullptr));
57 options.push_back(std::make_pair("-Dfoo=bar", nullptr));
58 options.push_back(std::make_pair("-Dbaz=qux", nullptr));
59 options.push_back(std::make_pair("-verbose:gc,class,jni", nullptr));
Brian Carlstromf734cf52011-08-17 16:28:14 -070060 options.push_back(std::make_pair("vfprintf", test_vfprintf));
61 options.push_back(std::make_pair("abort", test_abort));
62 options.push_back(std::make_pair("exit", test_exit));
Brian Carlstromf734cf52011-08-17 16:28:14 -070063
Igor Murashkinaaebaa02015-01-26 10:55:53 -080064 RuntimeArgumentMap map;
Vladimir Marko88b2b802015-12-04 14:19:04 +000065 bool parsed = ParsedOptions::Parse(options, false, &map);
66 ASSERT_TRUE(parsed);
Igor Murashkinaaebaa02015-01-26 10:55:53 -080067 ASSERT_NE(0u, map.Size());
68
69 using Opt = RuntimeArgumentMap;
70
71#define EXPECT_PARSED_EQ(expected, actual_key) EXPECT_EQ(expected, map.GetOrDefault(actual_key))
72#define EXPECT_PARSED_EXISTS(actual_key) EXPECT_TRUE(map.Exists(actual_key))
73
74 EXPECT_PARSED_EQ(lib_core, Opt::BootClassPath);
75 EXPECT_PARSED_EQ(lib_core, Opt::ClassPath);
76 EXPECT_PARSED_EQ(std::string("boot_image"), Opt::Image);
77 EXPECT_PARSED_EXISTS(Opt::CheckJni);
78 EXPECT_PARSED_EQ(2048U, Opt::MemoryInitialSize);
79 EXPECT_PARSED_EQ(4 * KB, Opt::MemoryMaximumSize);
80 EXPECT_PARSED_EQ(1 * MB, Opt::StackSize);
81 EXPECT_DOUBLE_EQ(0.75, map.GetOrDefault(Opt::HeapTargetUtilization));
82 EXPECT_TRUE(test_vfprintf == map.GetOrDefault(Opt::HookVfprintf));
83 EXPECT_TRUE(test_exit == map.GetOrDefault(Opt::HookExit));
84 EXPECT_TRUE(test_abort == map.GetOrDefault(Opt::HookAbort));
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -080085 EXPECT_TRUE(VLOG_IS_ON(class_linker));
86 EXPECT_FALSE(VLOG_IS_ON(compiler));
87 EXPECT_FALSE(VLOG_IS_ON(heap));
88 EXPECT_TRUE(VLOG_IS_ON(gc));
89 EXPECT_FALSE(VLOG_IS_ON(jdwp));
90 EXPECT_TRUE(VLOG_IS_ON(jni));
91 EXPECT_FALSE(VLOG_IS_ON(monitor));
Phil Wang751beff2015-08-28 15:17:15 +080092 EXPECT_FALSE(VLOG_IS_ON(signals));
93 EXPECT_FALSE(VLOG_IS_ON(simulator));
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -080094 EXPECT_FALSE(VLOG_IS_ON(startup));
95 EXPECT_FALSE(VLOG_IS_ON(third_party_jni));
96 EXPECT_FALSE(VLOG_IS_ON(threads));
Igor Murashkinaaebaa02015-01-26 10:55:53 -080097
98 auto&& properties_list = map.GetOrDefault(Opt::PropertiesList);
99 ASSERT_EQ(2U, properties_list.size());
100 EXPECT_EQ("foo=bar", properties_list[0]);
101 EXPECT_EQ("baz=qux", properties_list[1]);
Brian Carlstromf734cf52011-08-17 16:28:14 -0700102}
103
Igor Murashkin2798da12015-02-06 17:59:39 -0800104TEST_F(ParsedOptionsTest, ParsedOptionsGc) {
105 RuntimeOptions options;
106 options.push_back(std::make_pair("-Xgc:MC", nullptr));
107
108 RuntimeArgumentMap map;
Vladimir Marko88b2b802015-12-04 14:19:04 +0000109 bool parsed = ParsedOptions::Parse(options, false, &map);
110 ASSERT_TRUE(parsed);
Igor Murashkin2798da12015-02-06 17:59:39 -0800111 ASSERT_NE(0u, map.Size());
112
113 using Opt = RuntimeArgumentMap;
114
115 EXPECT_TRUE(map.Exists(Opt::GcOption));
116
117 XGcOption xgc = map.GetOrDefault(Opt::GcOption);
Andreas Gampea00f0122015-12-16 16:54:35 -0800118 EXPECT_EQ(gc::kCollectorTypeMC, xgc.collector_type_);
119}
120
121TEST_F(ParsedOptionsTest, ParsedOptionsInstructionSet) {
122 using Opt = RuntimeArgumentMap;
123
124 {
125 // Nothing set, should be kRuntimeISA.
126 RuntimeOptions options;
127 RuntimeArgumentMap map;
128 bool parsed = ParsedOptions::Parse(options, false, &map);
129 ASSERT_TRUE(parsed);
130 InstructionSet isa = map.GetOrDefault(Opt::ImageInstructionSet);
131 EXPECT_EQ(kRuntimeISA, isa);
132 }
133
134 const char* isa_strings[] = { "arm", "arm64", "x86", "x86_64", "mips", "mips64" };
135 InstructionSet ISAs[] = { InstructionSet::kArm,
136 InstructionSet::kArm64,
137 InstructionSet::kX86,
138 InstructionSet::kX86_64,
139 InstructionSet::kMips,
140 InstructionSet::kMips64 };
141 static_assert(arraysize(isa_strings) == arraysize(ISAs), "Need same amount.");
142
143 for (size_t i = 0; i < arraysize(isa_strings); ++i) {
144 RuntimeOptions options;
145 options.push_back(std::make_pair("imageinstructionset", isa_strings[i]));
146 RuntimeArgumentMap map;
147 bool parsed = ParsedOptions::Parse(options, false, &map);
148 ASSERT_TRUE(parsed);
149 InstructionSet isa = map.GetOrDefault(Opt::ImageInstructionSet);
150 EXPECT_EQ(ISAs[i], isa);
151 }
152}
Igor Murashkin2798da12015-02-06 17:59:39 -0800153
Brian Carlstromf734cf52011-08-17 16:28:14 -0700154} // namespace art