parsed_options_test.cc revision 5b8e6e36e96d6d1921dd356fa46191d1e6a18082
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 23namespace art { 24 25class ParsedOptionsTest : public CommonRuntimeTest {}; 26 27TEST_F(ParsedOptionsTest, ParsedOptions) { 28 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); 32 33 std::string boot_class_path; 34 std::string class_path; 35 boot_class_path += "-Xbootclasspath:"; 36 37 bool first_dex_file = true; 38 for (const std::string &dex_file_name : GetLibCoreDexFileNames()) { 39 if (!first_dex_file) { 40 class_path += ":"; 41 } else { 42 first_dex_file = false; 43 } 44 class_path += dex_file_name; 45 } 46 boot_class_path += class_path; 47 48 RuntimeOptions options; 49 options.push_back(std::make_pair(boot_class_path.c_str(), null)); 50 options.push_back(std::make_pair("-classpath", null)); 51 options.push_back(std::make_pair(class_path.c_str(), null)); 52 options.push_back(std::make_pair("-cp", null)); 53 options.push_back(std::make_pair(class_path.c_str(), null)); 54 options.push_back(std::make_pair("-Ximage:boot_image", null)); 55 options.push_back(std::make_pair("-Xcheck:jni", null)); 56 options.push_back(std::make_pair("-Xms2048", null)); 57 options.push_back(std::make_pair("-Xmx4k", null)); 58 options.push_back(std::make_pair("-Xss1m", null)); 59 options.push_back(std::make_pair("-XX:HeapTargetUtilization=0.75", null)); 60 options.push_back(std::make_pair("-Dfoo=bar", null)); 61 options.push_back(std::make_pair("-Dbaz=qux", null)); 62 options.push_back(std::make_pair("-verbose:gc,class,jni", null)); 63 options.push_back(std::make_pair("vfprintf", test_vfprintf)); 64 options.push_back(std::make_pair("abort", test_abort)); 65 options.push_back(std::make_pair("exit", test_exit)); 66 std::unique_ptr<ParsedOptions> parsed(ParsedOptions::Create(options, false)); 67 ASSERT_TRUE(parsed.get() != NULL); 68 69 EXPECT_EQ(class_path, parsed->boot_class_path_string_); 70 EXPECT_EQ(class_path, parsed->class_path_string_); 71 EXPECT_EQ(std::string("boot_image"), parsed->image_); 72 EXPECT_EQ(true, parsed->check_jni_); 73 EXPECT_EQ(2048U, parsed->heap_initial_size_); 74 EXPECT_EQ(4 * KB, parsed->heap_maximum_size_); 75 EXPECT_EQ(1 * MB, parsed->stack_size_); 76 EXPECT_EQ(0.75, parsed->heap_target_utilization_); 77 EXPECT_TRUE(test_vfprintf == parsed->hook_vfprintf_); 78 EXPECT_TRUE(test_exit == parsed->hook_exit_); 79 EXPECT_TRUE(test_abort == parsed->hook_abort_); 80 EXPECT_TRUE(VLOG_IS_ON(class_linker)); 81 EXPECT_FALSE(VLOG_IS_ON(compiler)); 82 EXPECT_FALSE(VLOG_IS_ON(heap)); 83 EXPECT_TRUE(VLOG_IS_ON(gc)); 84 EXPECT_FALSE(VLOG_IS_ON(jdwp)); 85 EXPECT_TRUE(VLOG_IS_ON(jni)); 86 EXPECT_FALSE(VLOG_IS_ON(monitor)); 87 EXPECT_FALSE(VLOG_IS_ON(startup)); 88 EXPECT_FALSE(VLOG_IS_ON(third_party_jni)); 89 EXPECT_FALSE(VLOG_IS_ON(threads)); 90 ASSERT_EQ(2U, parsed->properties_.size()); 91 EXPECT_EQ("foo=bar", parsed->properties_[0]); 92 EXPECT_EQ("baz=qux", parsed->properties_[1]); 93} 94 95} // namespace art 96