From: Mathieu Chartier Date: Tue, 26 May 2015 21:44:35 +0000 (-0700) Subject: Add oatdump test X-Git-Tag: android-x86-7.1-r1~889^2~1173^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=19510f02b011e545665f6219e6144c8e47aed5f0;p=android-x86%2Fart.git Add oatdump test Bug: 18000316 Change-Id: Ic22d63dc64a9b7a492b5e6bfbd4c75f30c35dfd5 --- diff --git a/build/Android.gtest.mk b/build/Android.gtest.mk index ccea540e2..77753894a 100644 --- a/build/Android.gtest.mk +++ b/build/Android.gtest.mk @@ -111,6 +111,7 @@ LOCAL_PATH := art RUNTIME_GTEST_COMMON_SRC_FILES := \ cmdline/cmdline_parser_test.cc \ imgdiag/imgdiag_test.cc \ + oatdump/oatdump_test.cc \ runtime/arch/arch_test.cc \ runtime/arch/instruction_set_test.cc \ runtime/arch/instruction_set_features_test.cc \ diff --git a/oatdump/oatdump.cc b/oatdump/oatdump.cc index 949c2cbcc..a67ef8f0b 100644 --- a/oatdump/oatdump.cc +++ b/oatdump/oatdump.cc @@ -2302,7 +2302,7 @@ struct OatdumpArgs : public CmdlineArgs { " --dump:raw_mapping_table enables dumping of the mapping table.\n" " Example: --dump:raw_mapping_table\n" "\n" - " --dump:raw_mapping_table enables dumping of the GC map.\n" + " --dump:raw_gc_map enables dumping of the GC map.\n" " Example: --dump:raw_gc_map\n" "\n" " --no-dump:vmap may be used to disable vmap dumping.\n" diff --git a/oatdump/oatdump_test.cc b/oatdump/oatdump_test.cc new file mode 100644 index 000000000..b34bc84ec --- /dev/null +++ b/oatdump/oatdump_test.cc @@ -0,0 +1,132 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "common_runtime_test.h" + +#include "base/stringprintf.h" +#include "runtime/arch/instruction_set.h" +#include "runtime/gc/heap.h" +#include "runtime/gc/space/image_space.h" +#include "runtime/os.h" +#include "runtime/utils.h" +#include "utils.h" + +#include +#include + +namespace art { + +class OatDumpTest : public CommonRuntimeTest { + protected: + virtual void SetUp() { + CommonRuntimeTest::SetUp(); + core_art_location_ = GetCoreArtLocation(); + core_oat_location_ = GetSystemImageFilename(GetCoreOatLocation().c_str(), kRuntimeISA); + } + + // Returns path to the oatdump binary. + std::string GetOatDumpFilePath() { + std::string root = GetTestAndroidRoot(); + root += "/bin/oatdump"; + if (kIsDebugBuild) { + root += "d"; + } + return root; + } + + enum Mode { + kModeOat, + kModeArt, + kModeSymbolize, + }; + + // Run the test with custom arguments. + bool Exec(Mode mode, const std::vector& args, std::string* error_msg) { + std::string file_path = GetOatDumpFilePath(); + + EXPECT_TRUE(OS::FileExists(file_path.c_str())) << file_path << " should be a valid file path"; + + std::vector exec_argv = { file_path }; + if (mode == kModeSymbolize) { + exec_argv.push_back("--symbolize=" + core_oat_location_); + exec_argv.push_back("--output=" + core_oat_location_ + ".symbolize"); + } else if (mode == kModeArt) { + exec_argv.push_back("--image=" + core_art_location_); + exec_argv.push_back("--output=/dev/null"); + } else { + CHECK_EQ(static_cast(mode), static_cast(kModeOat)); + exec_argv.push_back("--oat-file=" + core_oat_location_); + exec_argv.push_back("--output=/dev/null"); + } + exec_argv.insert(exec_argv.end(), args.begin(), args.end()); + return ::art::Exec(exec_argv, error_msg); + } + + private: + std::string core_art_location_; + std::string core_oat_location_; +}; + +TEST_F(OatDumpTest, TestImage) { + std::string error_msg; + ASSERT_TRUE(Exec(kModeArt, {}, &error_msg)) << error_msg; +} + +TEST_F(OatDumpTest, TestOatImage) { + std::string error_msg; + ASSERT_TRUE(Exec(kModeOat, {}, &error_msg)) << error_msg; +} + +TEST_F(OatDumpTest, TestDumpRawMappingTable) { + std::string error_msg; + ASSERT_TRUE(Exec(kModeArt, {"--dump:raw_mapping_table"}, &error_msg)) << error_msg; +} + +TEST_F(OatDumpTest, TestDumpRawGcMap) { + std::string error_msg; + ASSERT_TRUE(Exec(kModeArt, {"--dump:raw_gc_map"}, &error_msg)) << error_msg; +} + +TEST_F(OatDumpTest, TestNoDumpVmap) { + std::string error_msg; + ASSERT_TRUE(Exec(kModeArt, {"--no-dump:vmap"}, &error_msg)) << error_msg; +} + +TEST_F(OatDumpTest, TestNoDisassemble) { + std::string error_msg; + ASSERT_TRUE(Exec(kModeArt, {"--no-disassemble"}, &error_msg)) << error_msg; +} + +TEST_F(OatDumpTest, TestListClasses) { + std::string error_msg; + ASSERT_TRUE(Exec(kModeArt, {"--list-classes"}, &error_msg)) << error_msg; +} + +TEST_F(OatDumpTest, TestListMethods) { + std::string error_msg; + ASSERT_TRUE(Exec(kModeArt, {"--list-methods"}, &error_msg)) << error_msg; +} + +TEST_F(OatDumpTest, TestSymbolize) { + std::string error_msg; + ASSERT_TRUE(Exec(kModeSymbolize, {}, &error_msg)) << error_msg; +} + +} // namespace art