blob: f68b6329c4fb7b045e5a91485cc6efae85135ad8 [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 Murashkinaaebaa02015-01-26 10:55:53 -080025class ParsedOptionsTest : public ::testing::Test {};
Carl Shapirofc322c72011-07-27 00:20:01 -070026
Brian Carlstrom491ca9e2014-03-02 18:24:38 -080027TEST_F(ParsedOptionsTest, ParsedOptions) {
Brian Carlstromf734cf52011-08-17 16:28:14 -070028 void* test_vfprintf = reinterpret_cast<void*>(0xa);
29 void* test_abort = reinterpret_cast<void*>(0xb);
30 void* test_exit = reinterpret_cast<void*>(0xc);
31 void* null = reinterpret_cast<void*>(NULL);
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070032
Igor Murashkinaaebaa02015-01-26 10:55:53 -080033 std::string lib_core(CommonRuntimeTest::GetLibCoreDexFileName());
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070034
35 std::string boot_class_path;
36 boot_class_path += "-Xbootclasspath:";
37 boot_class_path += lib_core;
Brian Carlstromf734cf52011-08-17 16:28:14 -070038
Ian Rogerse63db272014-07-15 15:36:11 -070039 RuntimeOptions options;
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070040 options.push_back(std::make_pair(boot_class_path.c_str(), null));
41 options.push_back(std::make_pair("-classpath", null));
42 options.push_back(std::make_pair(lib_core.c_str(), null));
43 options.push_back(std::make_pair("-cp", null));
44 options.push_back(std::make_pair(lib_core.c_str(), null));
Brian Carlstrom58ae9412011-10-04 00:56:06 -070045 options.push_back(std::make_pair("-Ximage:boot_image", null));
Brian Carlstromf734cf52011-08-17 16:28:14 -070046 options.push_back(std::make_pair("-Xcheck:jni", null));
47 options.push_back(std::make_pair("-Xms2048", null));
48 options.push_back(std::make_pair("-Xmx4k", null));
49 options.push_back(std::make_pair("-Xss1m", null));
Brian Carlstrombd86bcc2013-03-10 20:26:16 -070050 options.push_back(std::make_pair("-XX:HeapTargetUtilization=0.75", null));
Brian Carlstromf734cf52011-08-17 16:28:14 -070051 options.push_back(std::make_pair("-Dfoo=bar", null));
52 options.push_back(std::make_pair("-Dbaz=qux", null));
53 options.push_back(std::make_pair("-verbose:gc,class,jni", null));
54 options.push_back(std::make_pair("vfprintf", test_vfprintf));
55 options.push_back(std::make_pair("abort", test_abort));
56 options.push_back(std::make_pair("exit", test_exit));
Brian Carlstromf734cf52011-08-17 16:28:14 -070057
Igor Murashkinaaebaa02015-01-26 10:55:53 -080058 RuntimeArgumentMap map;
59 std::unique_ptr<ParsedOptions> parsed(ParsedOptions::Create(options, false, &map));
60 ASSERT_TRUE(parsed.get() != NULL);
61 ASSERT_NE(0u, map.Size());
62
63 using Opt = RuntimeArgumentMap;
64
65#define EXPECT_PARSED_EQ(expected, actual_key) EXPECT_EQ(expected, map.GetOrDefault(actual_key))
66#define EXPECT_PARSED_EXISTS(actual_key) EXPECT_TRUE(map.Exists(actual_key))
67
68 EXPECT_PARSED_EQ(lib_core, Opt::BootClassPath);
69 EXPECT_PARSED_EQ(lib_core, Opt::ClassPath);
70 EXPECT_PARSED_EQ(std::string("boot_image"), Opt::Image);
71 EXPECT_PARSED_EXISTS(Opt::CheckJni);
72 EXPECT_PARSED_EQ(2048U, Opt::MemoryInitialSize);
73 EXPECT_PARSED_EQ(4 * KB, Opt::MemoryMaximumSize);
74 EXPECT_PARSED_EQ(1 * MB, Opt::StackSize);
75 EXPECT_DOUBLE_EQ(0.75, map.GetOrDefault(Opt::HeapTargetUtilization));
76 EXPECT_TRUE(test_vfprintf == map.GetOrDefault(Opt::HookVfprintf));
77 EXPECT_TRUE(test_exit == map.GetOrDefault(Opt::HookExit));
78 EXPECT_TRUE(test_abort == map.GetOrDefault(Opt::HookAbort));
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -080079 EXPECT_TRUE(VLOG_IS_ON(class_linker));
80 EXPECT_FALSE(VLOG_IS_ON(compiler));
81 EXPECT_FALSE(VLOG_IS_ON(heap));
82 EXPECT_TRUE(VLOG_IS_ON(gc));
83 EXPECT_FALSE(VLOG_IS_ON(jdwp));
84 EXPECT_TRUE(VLOG_IS_ON(jni));
85 EXPECT_FALSE(VLOG_IS_ON(monitor));
86 EXPECT_FALSE(VLOG_IS_ON(startup));
87 EXPECT_FALSE(VLOG_IS_ON(third_party_jni));
88 EXPECT_FALSE(VLOG_IS_ON(threads));
Igor Murashkinaaebaa02015-01-26 10:55:53 -080089
90 auto&& properties_list = map.GetOrDefault(Opt::PropertiesList);
91 ASSERT_EQ(2U, properties_list.size());
92 EXPECT_EQ("foo=bar", properties_list[0]);
93 EXPECT_EQ("baz=qux", properties_list[1]);
Brian Carlstromf734cf52011-08-17 16:28:14 -070094}
95
96} // namespace art