diff options
-rw-r--r-- | build/Android.gtest.mk | 7 | ||||
-rw-r--r-- | dexlayout/Android.bp | 22 | ||||
-rw-r--r-- | dexlayout/dexdiag.cc | 23 | ||||
-rw-r--r-- | dexlayout/dexdiag_test.cc | 155 |
4 files changed, 11 insertions, 196 deletions
diff --git a/build/Android.gtest.mk b/build/Android.gtest.mk index f27db0eed9..ed34a8df5f 100644 --- a/build/Android.gtest.mk +++ b/build/Android.gtest.mk @@ -170,12 +170,6 @@ ART_GTEST_dex2oat_test_TARGET_DEPS := \ # TODO: document why this is needed. ART_GTEST_proxy_test_HOST_DEPS := $(HOST_CORE_IMAGE_DEFAULT_64) $(HOST_CORE_IMAGE_DEFAULT_32) -# The dexdiag test requires the dexdiag utility. -ART_GTEST_dexdiag_test_HOST_DEPS := \ - $(HOST_OUT_EXECUTABLES)/dexdiag -ART_GTEST_dexdiag_test_TARGET_DEPS := \ - dexdiag - # The dexdump test requires an image and the dexdump utility. # TODO: rename into dexdump when migration completes ART_GTEST_dexdump_test_HOST_DEPS := \ @@ -247,7 +241,6 @@ ART_TEST_MODULES := \ art_compiler_tests \ art_compiler_host_tests \ art_dex2oat_tests \ - art_dexdiag_tests \ art_dexdump_tests \ art_dexlayout_tests \ art_dexlist_tests \ diff --git a/dexlayout/Android.bp b/dexlayout/Android.bp index 16e6809f4a..4b65c5299a 100644 --- a/dexlayout/Android.bp +++ b/dexlayout/Android.bp @@ -20,7 +20,7 @@ art_cc_defaults { "dexlayout.cc", "dex_ir.cc", "dex_ir_builder.cc", - "dex_verify.cc", + "dex_verify.cc", "dex_visualize.cc", "dex_writer.cc", ], @@ -43,7 +43,6 @@ art_cc_library { art_cc_binary { name: "dexlayout", - defaults: ["art_defaults"], host_supported: true, srcs: ["dexlayout_main.cc"], cflags: ["-Wall"], @@ -61,28 +60,13 @@ art_cc_test { art_cc_binary { name: "dexdiag", - defaults: ["art_defaults"], - host_supported: true, + host_supported: false, srcs: ["dexdiag.cc"], cflags: ["-Wall"], shared_libs: [ "libart", "libart-dexlayout", + "libpagemap", ], - target: { - android: { - shared_libs: [ - "libpagemap", - ] - }, - } } -art_cc_test { - name: "art_dexdiag_tests", - host_supported: true, - defaults: [ - "art_gtest_defaults", - ], - srcs: ["dexdiag_test.cc"], -} diff --git a/dexlayout/dexdiag.cc b/dexlayout/dexdiag.cc index bc56bbfa81..688201b6b8 100644 --- a/dexlayout/dexdiag.cc +++ b/dexlayout/dexdiag.cc @@ -15,7 +15,6 @@ */ #include <errno.h> -#include <inttypes.h> #include <stdint.h> #include <stdlib.h> #include <string.h> @@ -31,9 +30,7 @@ #include "dex_file.h" #include "dex_ir.h" #include "dex_ir_builder.h" -#ifdef ART_TARGET_ANDROID #include "pagemap/pagemap.h" -#endif #include "runtime.h" #include "vdex_file.h" @@ -41,6 +38,8 @@ namespace art { using android::base::StringPrintf; +static constexpr size_t kLineLength = 32; + static bool g_verbose = false; // The width needed to print a file page offset (32-bit). @@ -165,7 +164,6 @@ static void PrintLetterKey() { std::cout << ". (Mapped page not resident)" << std::endl; } -#ifdef ART_TARGET_ANDROID static char PageTypeChar(uint16_t type) { if (kDexSectionInfoMap.find(type) == kDexSectionInfoMap.end()) { return '-'; @@ -196,7 +194,6 @@ static void ProcessPageMap(uint64_t* pagemap, size_t end, const std::vector<dex_ir::DexFileSection>& sections, PageCount* page_counts) { - static constexpr size_t kLineLength = 32; for (size_t page = start; page < end; ++page) { char type_char = '.'; if (PM_PAGEMAP_PRESENT(pagemap[page])) { @@ -271,7 +268,7 @@ static void ProcessOneDexMapping(uint64_t* pagemap, std::cerr << "Dex file start offset for " << dex_file->GetLocation().c_str() << " is incorrect: map start " - << StringPrintf("%" PRIx64 " > dex start %" PRIx64 "\n", map_start, dex_file_start) + << StringPrintf("%zx > dex start %zx\n", map_start, dex_file_start) << std::endl; return; } @@ -280,7 +277,7 @@ static void ProcessOneDexMapping(uint64_t* pagemap, uint64_t end_page = RoundUp(start_address + dex_file_size, kPageSize) / kPageSize; std::cout << "DEX " << dex_file->GetLocation().c_str() - << StringPrintf(": %" PRIx64 "-%" PRIx64, + << StringPrintf(": %zx-%zx", map_start + start_page * kPageSize, map_start + end_page * kPageSize) << std::endl; @@ -344,7 +341,7 @@ static bool DisplayMappingIfFromVdexFile(pm_map_t* map, Printer* printer) { // Process the dex files. std::cout << "MAPPING " << pm_map_name(map) - << StringPrintf(": %" PRIx64 "-%" PRIx64, pm_map_start(map), pm_map_end(map)) + << StringPrintf(": %zx-%zx", pm_map_start(map), pm_map_end(map)) << std::endl; for (const auto& dex_file : dex_files) { ProcessOneDexMapping(pagemap, @@ -358,7 +355,6 @@ static bool DisplayMappingIfFromVdexFile(pm_map_t* map, Printer* printer) { } static void ProcessOneOatMapping(uint64_t* pagemap, size_t size, Printer* printer) { - static constexpr size_t kLineLength = 32; size_t resident_page_count = 0; for (size_t page = 0; page < size; ++page) { char type_char = '.'; @@ -409,7 +405,7 @@ static bool DisplayMappingIfFromOatFile(pm_map_t* map, Printer* printer) { // Process the dex files. std::cout << "MAPPING " << pm_map_name(map) - << StringPrintf(": %" PRIx64 "-%" PRIx64, pm_map_start(map), pm_map_end(map)) + << StringPrintf(": %zx-%zx", pm_map_start(map), pm_map_end(map)) << std::endl; ProcessOneOatMapping(pagemap, len, printer); free(pagemap); @@ -429,10 +425,9 @@ static bool FilterByNameContains(const std::string& mapped_file_name, } return false; } -#endif static void Usage(const char* cmd) { - std::cout << "Usage: " << cmd << " [options] pid" << std::endl + std::cerr << "Usage: " << cmd << " [options] pid" << std::endl << " --contains=<string>: Display sections containing string." << std::endl << " --help: Shows this message." << std::endl << " --verbose: Makes displays verbose." << std::endl; @@ -467,7 +462,6 @@ static int DexDiagMain(int argc, char* argv[]) { InitLogging(argv, Runtime::Aborter); MemMap::Init(); -#ifdef ART_TARGET_ANDROID pid_t pid; char* endptr; pid = (pid_t)strtol(argv[argc - 1], &endptr, 10); @@ -501,7 +495,7 @@ static int DexDiagMain(int argc, char* argv[]) { return EXIT_FAILURE; } - // Process the mappings that are due to vdex or oat files. + // Process the mappings that are due to DEX files. Printer printer; for (size_t i = 0; i < num_maps; ++i) { std::string mapped_file_name = pm_map_name(maps[i]); @@ -515,7 +509,6 @@ static int DexDiagMain(int argc, char* argv[]) { return EXIT_FAILURE; } } -#endif return EXIT_SUCCESS; } diff --git a/dexlayout/dexdiag_test.cc b/dexlayout/dexdiag_test.cc deleted file mode 100644 index dfe42b20fe..0000000000 --- a/dexlayout/dexdiag_test.cc +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (C) 2017 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 <string> -#include <vector> - -#include "common_runtime_test.h" - -#include "runtime/exec_utils.h" -#include "runtime/oat_file.h" -#include "runtime/os.h" - -namespace art { - -static const char* kDexDiagContains = "--contains=boot.vdex"; -static const char* kDexDiagContainsFails = "--contains=anything_other_than_boot.vdex"; -static const char* kDexDiagHelp = "--help"; -static const char* kDexDiagVerbose = "--verbose"; -static const char* kDexDiagBinaryName = "dexdiag"; - -class DexDiagTest : public CommonRuntimeTest { - protected: - virtual void SetUp() { - CommonRuntimeTest::SetUp(); - } - - // Path to the dexdiag(d?)[32|64] binary. - std::string GetDexDiagFilePath() { - std::string root = GetTestAndroidRoot(); - - root += "/bin/"; - root += kDexDiagBinaryName; - - std::string root32 = root + "32"; - // If we have both a 32-bit and a 64-bit build, the 32-bit file will have a 32 suffix. - if (OS::FileExists(root32.c_str()) && !Is64BitInstructionSet(kRuntimeISA)) { - return root32; - } else { - // This is a 64-bit build or only a single build exists. - return root; - } - } - - void OpenOatAndVdexFiles() { - // Open the boot.oat file. - // This is a little convoluted because we have to - // get the location of the default boot image (/system/framework/boot.art), - // find it in the right architecture subdirectory (/system/framework/arm/boot.art), - // find the oat file next to the image (/system/framework/arm/boot.oat). - // Then, opening the oat file has the side-effect of opening the corresponding - // vdex file (/system/framework/arm/boot.vdex). - std::string error_msg; - const std::string default_location = GetDefaultBootImageLocation(&error_msg); - EXPECT_TRUE(!default_location.empty()) << error_msg; - std::string oat_location = GetSystemImageFilename(default_location.c_str(), kRuntimeISA); - EXPECT_TRUE(!oat_location.empty()); - const std::string kImageFileSuffix = ".art"; - size_t suffix_pos = oat_location.rfind(kImageFileSuffix); - EXPECT_TRUE(suffix_pos != std::string::npos); - const std::string kOatFileSuffix = ".oat"; - oat_location = oat_location.replace(suffix_pos, kImageFileSuffix.length(), kOatFileSuffix); - std::unique_ptr<OatFile> oat(OatFile::Open(oat_location.c_str(), - oat_location.c_str(), - nullptr, - nullptr, - false, - /*low_4gb*/false, - nullptr, - &error_msg)); - EXPECT_TRUE(oat != nullptr) << error_msg; - } - - // Run dexdiag with a custom boot image location. - bool Exec(pid_t this_pid, const std::vector<std::string>& args, std::string* error_msg) { - // Invoke 'dexdiag' against the current process. - // This should succeed because we have a runtime and so it should - // be able to map in the boot.art and do a diff for it. - std::vector<std::string> exec_argv; - - // Build the command line "dexdiag <args> this_pid". - std::string executable_path = GetDexDiagFilePath(); - EXPECT_TRUE(OS::FileExists(executable_path.c_str())) << executable_path - << " should be a valid file path"; - exec_argv.push_back(executable_path); - for (const auto& arg : args) { - exec_argv.push_back(arg); - } - exec_argv.push_back(std::to_string(this_pid)); - - return ::art::Exec(exec_argv, error_msg); - } -}; - -// We can't run these tests on the host, as they will fail when trying to open -// /proc/pid/pagemap. -// On the target, we invoke 'dexdiag' against the current process. -// This should succeed because we have a runtime and so dexdiag should -// be able to find the map for, e.g., boot.vdex and friends. -TEST_F(DexDiagTest, DexDiagHelpTest) { - // TODO: test the resulting output. - std::string error_msg; - ASSERT_TRUE(Exec(getpid(), { kDexDiagHelp }, &error_msg)) << "Failed to execute -- because: " - << error_msg; -} - -#if defined (ART_TARGET) -TEST_F(DexDiagTest, DexDiagContainsTest) { -#else -TEST_F(DexDiagTest, DISABLED_DexDiagContainsTest) { -#endif - OpenOatAndVdexFiles(); - // TODO: test the resulting output. - std::string error_msg; - ASSERT_TRUE(Exec(getpid(), { kDexDiagContains }, &error_msg)) << "Failed to execute -- because: " - << error_msg; -} - -#if defined (ART_TARGET) -TEST_F(DexDiagTest, DexDiagContainsFailsTest) { -#else -TEST_F(DexDiagTest, DISABLED_DexDiagContainsFailsTest) { -#endif - OpenOatAndVdexFiles(); - // TODO: test the resulting output. - std::string error_msg; - ASSERT_TRUE(Exec(getpid(), { kDexDiagContainsFails }, &error_msg)) - << "Failed to execute -- because: " - << error_msg; -} - -#if defined (ART_TARGET) -TEST_F(DexDiagTest, DexDiagVerboseTest) { -#else -TEST_F(DexDiagTest, DISABLED_DexDiagVerboseTest) { -#endif - // TODO: test the resulting output. - std::string error_msg; - ASSERT_TRUE(Exec(getpid(), { kDexDiagVerbose }, &error_msg)) << "Failed to execute -- because: " - << error_msg; -} - -} // namespace art |