blob: eee491018224ec83d5119734250930b4f783a5d2 [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
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080021#include "common_runtime_test.h"
Carl Shapirofc322c72011-07-27 00:20:01 -070022
23namespace art {
Carl Shapirofc322c72011-07-27 00:20:01 -070024
Igor Murashkineb6c7c22015-02-04 17:30:43 -080025class ParsedOptionsTest : public ::testing::Test {
26 public:
27 static void SetUpTestCase() {
28 CommonRuntimeTest::SetUpAndroidRoot();
29 }
30};
Carl Shapirofc322c72011-07-27 00:20:01 -070031
Brian Carlstrom491ca9e2014-03-02 18:24:38 -080032TEST_F(ParsedOptionsTest, ParsedOptions) {
Brian Carlstromf734cf52011-08-17 16:28:14 -070033 void* test_vfprintf = reinterpret_cast<void*>(0xa);
34 void* test_abort = reinterpret_cast<void*>(0xb);
35 void* test_exit = reinterpret_cast<void*>(0xc);
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070036
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070037 std::string boot_class_path;
Przemyslaw Szczepaniak5b8e6e32015-09-30 14:40:33 +010038 std::string class_path;
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070039 boot_class_path += "-Xbootclasspath:";
Przemyslaw Szczepaniak5b8e6e32015-09-30 14:40:33 +010040
41 bool first_dex_file = true;
Narayan Kamathd1ef4362015-11-12 11:49:06 +000042 for (const std::string &dex_file_name :
43 CommonRuntimeTest::GetLibCoreDexFileNames()) {
Przemyslaw Szczepaniak5b8e6e32015-09-30 14:40:33 +010044 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;
Brian Carlstromf734cf52011-08-17 16:28:14 -070052
Ian Rogerse63db272014-07-15 15:36:11 -070053 RuntimeOptions options;
Mathieu Chartier2cebb242015-04-21 16:50:40 -070054 options.push_back(std::make_pair(boot_class_path.c_str(), nullptr));
55 options.push_back(std::make_pair("-classpath", nullptr));
Narayan Kamathd1ef4362015-11-12 11:49:06 +000056 options.push_back(std::make_pair(class_path.c_str(), nullptr));
Mathieu Chartier2cebb242015-04-21 16:50:40 -070057 options.push_back(std::make_pair("-cp", nullptr));
Narayan Kamathd1ef4362015-11-12 11:49:06 +000058 options.push_back(std::make_pair(class_path.c_str(), nullptr));
Mathieu Chartier2cebb242015-04-21 16:50:40 -070059 options.push_back(std::make_pair("-Ximage:boot_image", nullptr));
60 options.push_back(std::make_pair("-Xcheck:jni", nullptr));
61 options.push_back(std::make_pair("-Xms2048", nullptr));
62 options.push_back(std::make_pair("-Xmx4k", nullptr));
63 options.push_back(std::make_pair("-Xss1m", nullptr));
64 options.push_back(std::make_pair("-XX:HeapTargetUtilization=0.75", nullptr));
65 options.push_back(std::make_pair("-Dfoo=bar", nullptr));
66 options.push_back(std::make_pair("-Dbaz=qux", nullptr));
67 options.push_back(std::make_pair("-verbose:gc,class,jni", nullptr));
Brian Carlstromf734cf52011-08-17 16:28:14 -070068 options.push_back(std::make_pair("vfprintf", test_vfprintf));
69 options.push_back(std::make_pair("abort", test_abort));
70 options.push_back(std::make_pair("exit", test_exit));
Brian Carlstromf734cf52011-08-17 16:28:14 -070071
Igor Murashkinaaebaa02015-01-26 10:55:53 -080072 RuntimeArgumentMap map;
73 std::unique_ptr<ParsedOptions> parsed(ParsedOptions::Create(options, false, &map));
Mathieu Chartier2cebb242015-04-21 16:50:40 -070074 ASSERT_TRUE(parsed.get() != nullptr);
Igor Murashkinaaebaa02015-01-26 10:55:53 -080075 ASSERT_NE(0u, map.Size());
76
77 using Opt = RuntimeArgumentMap;
78
79#define EXPECT_PARSED_EQ(expected, actual_key) EXPECT_EQ(expected, map.GetOrDefault(actual_key))
80#define EXPECT_PARSED_EXISTS(actual_key) EXPECT_TRUE(map.Exists(actual_key))
81
Narayan Kamathd1ef4362015-11-12 11:49:06 +000082 EXPECT_PARSED_EQ(class_path, Opt::BootClassPath);
83 EXPECT_PARSED_EQ(class_path, Opt::ClassPath);
Igor Murashkinaaebaa02015-01-26 10:55:53 -080084 EXPECT_PARSED_EQ(std::string("boot_image"), Opt::Image);
85 EXPECT_PARSED_EXISTS(Opt::CheckJni);
86 EXPECT_PARSED_EQ(2048U, Opt::MemoryInitialSize);
87 EXPECT_PARSED_EQ(4 * KB, Opt::MemoryMaximumSize);
88 EXPECT_PARSED_EQ(1 * MB, Opt::StackSize);
89 EXPECT_DOUBLE_EQ(0.75, map.GetOrDefault(Opt::HeapTargetUtilization));
90 EXPECT_TRUE(test_vfprintf == map.GetOrDefault(Opt::HookVfprintf));
91 EXPECT_TRUE(test_exit == map.GetOrDefault(Opt::HookExit));
92 EXPECT_TRUE(test_abort == map.GetOrDefault(Opt::HookAbort));
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -080093 EXPECT_TRUE(VLOG_IS_ON(class_linker));
94 EXPECT_FALSE(VLOG_IS_ON(compiler));
95 EXPECT_FALSE(VLOG_IS_ON(heap));
96 EXPECT_TRUE(VLOG_IS_ON(gc));
97 EXPECT_FALSE(VLOG_IS_ON(jdwp));
98 EXPECT_TRUE(VLOG_IS_ON(jni));
99 EXPECT_FALSE(VLOG_IS_ON(monitor));
100 EXPECT_FALSE(VLOG_IS_ON(startup));
101 EXPECT_FALSE(VLOG_IS_ON(third_party_jni));
102 EXPECT_FALSE(VLOG_IS_ON(threads));
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800103
104 auto&& properties_list = map.GetOrDefault(Opt::PropertiesList);
105 ASSERT_EQ(2U, properties_list.size());
106 EXPECT_EQ("foo=bar", properties_list[0]);
107 EXPECT_EQ("baz=qux", properties_list[1]);
Brian Carlstromf734cf52011-08-17 16:28:14 -0700108}
109
Igor Murashkin2798da12015-02-06 17:59:39 -0800110TEST_F(ParsedOptionsTest, ParsedOptionsGc) {
111 RuntimeOptions options;
112 options.push_back(std::make_pair("-Xgc:MC", nullptr));
113
114 RuntimeArgumentMap map;
115 std::unique_ptr<ParsedOptions> parsed(ParsedOptions::Create(options, false, &map));
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700116 ASSERT_TRUE(parsed.get() != nullptr);
Igor Murashkin2798da12015-02-06 17:59:39 -0800117 ASSERT_NE(0u, map.Size());
118
119 using Opt = RuntimeArgumentMap;
120
121 EXPECT_TRUE(map.Exists(Opt::GcOption));
122
123 XGcOption xgc = map.GetOrDefault(Opt::GcOption);
124 EXPECT_EQ(gc::kCollectorTypeMC, xgc.collector_type_);}
125
Brian Carlstromf734cf52011-08-17 16:28:14 -0700126} // namespace art