Mathieu Chartier | 19510f0 | 2015-05-26 14:44:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 <string> |
| 18 | #include <vector> |
| 19 | #include <sstream> |
| 20 | |
| 21 | #include "common_runtime_test.h" |
| 22 | |
| 23 | #include "base/stringprintf.h" |
| 24 | #include "runtime/arch/instruction_set.h" |
| 25 | #include "runtime/gc/heap.h" |
| 26 | #include "runtime/gc/space/image_space.h" |
| 27 | #include "runtime/os.h" |
| 28 | #include "runtime/utils.h" |
| 29 | #include "utils.h" |
| 30 | |
| 31 | #include <sys/types.h> |
| 32 | #include <unistd.h> |
| 33 | |
| 34 | namespace art { |
| 35 | |
| 36 | class OatDumpTest : public CommonRuntimeTest { |
| 37 | protected: |
| 38 | virtual void SetUp() { |
| 39 | CommonRuntimeTest::SetUp(); |
| 40 | core_art_location_ = GetCoreArtLocation(); |
| 41 | core_oat_location_ = GetSystemImageFilename(GetCoreOatLocation().c_str(), kRuntimeISA); |
| 42 | } |
| 43 | |
| 44 | // Returns path to the oatdump binary. |
| 45 | std::string GetOatDumpFilePath() { |
| 46 | std::string root = GetTestAndroidRoot(); |
| 47 | root += "/bin/oatdump"; |
| 48 | if (kIsDebugBuild) { |
| 49 | root += "d"; |
| 50 | } |
| 51 | return root; |
| 52 | } |
| 53 | |
| 54 | enum Mode { |
| 55 | kModeOat, |
| 56 | kModeArt, |
| 57 | kModeSymbolize, |
| 58 | }; |
| 59 | |
| 60 | // Run the test with custom arguments. |
| 61 | bool Exec(Mode mode, const std::vector<std::string>& args, std::string* error_msg) { |
| 62 | std::string file_path = GetOatDumpFilePath(); |
| 63 | |
| 64 | EXPECT_TRUE(OS::FileExists(file_path.c_str())) << file_path << " should be a valid file path"; |
| 65 | |
| 66 | std::vector<std::string> exec_argv = { file_path }; |
| 67 | if (mode == kModeSymbolize) { |
| 68 | exec_argv.push_back("--symbolize=" + core_oat_location_); |
| 69 | exec_argv.push_back("--output=" + core_oat_location_ + ".symbolize"); |
| 70 | } else if (mode == kModeArt) { |
| 71 | exec_argv.push_back("--image=" + core_art_location_); |
| 72 | exec_argv.push_back("--output=/dev/null"); |
| 73 | } else { |
| 74 | CHECK_EQ(static_cast<size_t>(mode), static_cast<size_t>(kModeOat)); |
| 75 | exec_argv.push_back("--oat-file=" + core_oat_location_); |
| 76 | exec_argv.push_back("--output=/dev/null"); |
| 77 | } |
| 78 | exec_argv.insert(exec_argv.end(), args.begin(), args.end()); |
| 79 | return ::art::Exec(exec_argv, error_msg); |
| 80 | } |
| 81 | |
| 82 | private: |
| 83 | std::string core_art_location_; |
| 84 | std::string core_oat_location_; |
| 85 | }; |
| 86 | |
| 87 | TEST_F(OatDumpTest, TestImage) { |
| 88 | std::string error_msg; |
| 89 | ASSERT_TRUE(Exec(kModeArt, {}, &error_msg)) << error_msg; |
| 90 | } |
| 91 | |
| 92 | TEST_F(OatDumpTest, TestOatImage) { |
| 93 | std::string error_msg; |
| 94 | ASSERT_TRUE(Exec(kModeOat, {}, &error_msg)) << error_msg; |
| 95 | } |
| 96 | |
| 97 | TEST_F(OatDumpTest, TestDumpRawMappingTable) { |
| 98 | std::string error_msg; |
| 99 | ASSERT_TRUE(Exec(kModeArt, {"--dump:raw_mapping_table"}, &error_msg)) << error_msg; |
| 100 | } |
| 101 | |
| 102 | TEST_F(OatDumpTest, TestDumpRawGcMap) { |
| 103 | std::string error_msg; |
| 104 | ASSERT_TRUE(Exec(kModeArt, {"--dump:raw_gc_map"}, &error_msg)) << error_msg; |
| 105 | } |
| 106 | |
| 107 | TEST_F(OatDumpTest, TestNoDumpVmap) { |
| 108 | std::string error_msg; |
| 109 | ASSERT_TRUE(Exec(kModeArt, {"--no-dump:vmap"}, &error_msg)) << error_msg; |
| 110 | } |
| 111 | |
| 112 | TEST_F(OatDumpTest, TestNoDisassemble) { |
| 113 | std::string error_msg; |
| 114 | ASSERT_TRUE(Exec(kModeArt, {"--no-disassemble"}, &error_msg)) << error_msg; |
| 115 | } |
| 116 | |
| 117 | TEST_F(OatDumpTest, TestListClasses) { |
| 118 | std::string error_msg; |
| 119 | ASSERT_TRUE(Exec(kModeArt, {"--list-classes"}, &error_msg)) << error_msg; |
| 120 | } |
| 121 | |
| 122 | TEST_F(OatDumpTest, TestListMethods) { |
| 123 | std::string error_msg; |
| 124 | ASSERT_TRUE(Exec(kModeArt, {"--list-methods"}, &error_msg)) << error_msg; |
| 125 | } |
| 126 | |
| 127 | TEST_F(OatDumpTest, TestSymbolize) { |
| 128 | std::string error_msg; |
| 129 | ASSERT_TRUE(Exec(kModeSymbolize, {}, &error_msg)) << error_msg; |
| 130 | } |
| 131 | |
| 132 | } // namespace art |