blob: 5407d3a199f991f03a848284d266beb07fd20489 [file] [log] [blame]
Mathieu Chartier19510f02015-05-26 14:44:35 -07001/*
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
34namespace art {
35
36class 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
Vladimir Marko7da31702016-03-29 18:42:21 +010087// Disable tests on arm and mips as they are taking too long to run. b/27824283.
88#if !defined(__arm__) && !defined(__mips__)
Mathieu Chartier19510f02015-05-26 14:44:35 -070089TEST_F(OatDumpTest, TestImage) {
90 std::string error_msg;
91 ASSERT_TRUE(Exec(kModeArt, {}, &error_msg)) << error_msg;
92}
93
94TEST_F(OatDumpTest, TestOatImage) {
95 std::string error_msg;
96 ASSERT_TRUE(Exec(kModeOat, {}, &error_msg)) << error_msg;
97}
98
99TEST_F(OatDumpTest, TestDumpRawMappingTable) {
100 std::string error_msg;
101 ASSERT_TRUE(Exec(kModeArt, {"--dump:raw_mapping_table"}, &error_msg)) << error_msg;
102}
103
104TEST_F(OatDumpTest, TestDumpRawGcMap) {
105 std::string error_msg;
106 ASSERT_TRUE(Exec(kModeArt, {"--dump:raw_gc_map"}, &error_msg)) << error_msg;
107}
108
109TEST_F(OatDumpTest, TestNoDumpVmap) {
110 std::string error_msg;
111 ASSERT_TRUE(Exec(kModeArt, {"--no-dump:vmap"}, &error_msg)) << error_msg;
112}
113
114TEST_F(OatDumpTest, TestNoDisassemble) {
115 std::string error_msg;
116 ASSERT_TRUE(Exec(kModeArt, {"--no-disassemble"}, &error_msg)) << error_msg;
117}
118
119TEST_F(OatDumpTest, TestListClasses) {
120 std::string error_msg;
121 ASSERT_TRUE(Exec(kModeArt, {"--list-classes"}, &error_msg)) << error_msg;
122}
123
124TEST_F(OatDumpTest, TestListMethods) {
125 std::string error_msg;
126 ASSERT_TRUE(Exec(kModeArt, {"--list-methods"}, &error_msg)) << error_msg;
127}
128
129TEST_F(OatDumpTest, TestSymbolize) {
130 std::string error_msg;
131 ASSERT_TRUE(Exec(kModeSymbolize, {}, &error_msg)) << error_msg;
132}
Nicolas Geoffray973ce7c2016-03-24 09:23:04 +0000133#endif
Mathieu Chartier19510f02015-05-26 14:44:35 -0700134} // namespace art