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_); |
Andreas Gampe | 71f2e80 | 2016-03-24 18:57:48 -0700 | [diff] [blame] | 72 | exec_argv.push_back("--instruction-set=" + std::string(GetInstructionSetString(kRuntimeISA))); |
Mathieu Chartier | 19510f0 | 2015-05-26 14:44:35 -0700 | [diff] [blame] | 73 | exec_argv.push_back("--output=/dev/null"); |
| 74 | } else { |
| 75 | CHECK_EQ(static_cast<size_t>(mode), static_cast<size_t>(kModeOat)); |
| 76 | exec_argv.push_back("--oat-file=" + core_oat_location_); |
| 77 | exec_argv.push_back("--output=/dev/null"); |
| 78 | } |
| 79 | exec_argv.insert(exec_argv.end(), args.begin(), args.end()); |
| 80 | return ::art::Exec(exec_argv, error_msg); |
| 81 | } |
| 82 | |
| 83 | private: |
| 84 | std::string core_art_location_; |
| 85 | std::string core_oat_location_; |
| 86 | }; |
| 87 | |
Vladimir Marko | 7da3170 | 2016-03-29 18:42:21 +0100 | [diff] [blame] | 88 | // Disable tests on arm and mips as they are taking too long to run. b/27824283. |
| 89 | #if !defined(__arm__) && !defined(__mips__) |
Mathieu Chartier | 19510f0 | 2015-05-26 14:44:35 -0700 | [diff] [blame] | 90 | TEST_F(OatDumpTest, TestImage) { |
| 91 | std::string error_msg; |
| 92 | ASSERT_TRUE(Exec(kModeArt, {}, &error_msg)) << error_msg; |
| 93 | } |
| 94 | |
| 95 | TEST_F(OatDumpTest, TestOatImage) { |
| 96 | std::string error_msg; |
| 97 | ASSERT_TRUE(Exec(kModeOat, {}, &error_msg)) << error_msg; |
| 98 | } |
| 99 | |
Mathieu Chartier | 19510f0 | 2015-05-26 14:44:35 -0700 | [diff] [blame] | 100 | TEST_F(OatDumpTest, TestNoDumpVmap) { |
| 101 | std::string error_msg; |
| 102 | ASSERT_TRUE(Exec(kModeArt, {"--no-dump:vmap"}, &error_msg)) << error_msg; |
| 103 | } |
| 104 | |
| 105 | TEST_F(OatDumpTest, TestNoDisassemble) { |
| 106 | std::string error_msg; |
| 107 | ASSERT_TRUE(Exec(kModeArt, {"--no-disassemble"}, &error_msg)) << error_msg; |
| 108 | } |
| 109 | |
| 110 | TEST_F(OatDumpTest, TestListClasses) { |
| 111 | std::string error_msg; |
| 112 | ASSERT_TRUE(Exec(kModeArt, {"--list-classes"}, &error_msg)) << error_msg; |
| 113 | } |
| 114 | |
| 115 | TEST_F(OatDumpTest, TestListMethods) { |
| 116 | std::string error_msg; |
| 117 | ASSERT_TRUE(Exec(kModeArt, {"--list-methods"}, &error_msg)) << error_msg; |
| 118 | } |
| 119 | |
| 120 | TEST_F(OatDumpTest, TestSymbolize) { |
| 121 | std::string error_msg; |
| 122 | ASSERT_TRUE(Exec(kModeSymbolize, {}, &error_msg)) << error_msg; |
| 123 | } |
Nicolas Geoffray | 973ce7c | 2016-03-24 09:23:04 +0000 | [diff] [blame] | 124 | #endif |
Mathieu Chartier | 19510f0 | 2015-05-26 14:44:35 -0700 | [diff] [blame] | 125 | } // namespace art |