diff options
-rw-r--r-- | dexdump/Android.bp | 4 | ||||
-rw-r--r-- | libartbase/base/common_art_test.cc | 18 | ||||
-rw-r--r-- | libartbase/base/common_art_test.h | 3 | ||||
-rw-r--r-- | libartbase/base/file_utils_test.cc | 8 | ||||
-rw-r--r-- | libdexfile/dex/art_dex_file_loader_test.cc | 31 |
5 files changed, 37 insertions, 27 deletions
diff --git a/dexdump/Android.bp b/dexdump/Android.bp index 2f0962c19a..ac9a9a2932 100644 --- a/dexdump/Android.bp +++ b/dexdump/Android.bp @@ -23,10 +23,6 @@ cc_defaults { "dexdump.cc", ], cflags: ["-Wall", "-Werror"], - // TODO: fix b/72216369 and remove the need for this. - include_dirs: [ - "art/runtime" // dex utils. - ], } art_cc_binary { diff --git a/libartbase/base/common_art_test.cc b/libartbase/base/common_art_test.cc index 0d798f37f7..67413eb85c 100644 --- a/libartbase/base/common_art_test.cc +++ b/libartbase/base/common_art_test.cc @@ -355,17 +355,18 @@ std::string CommonArtTestImpl::GetTestDexFileName(const char* name) const { return filename; } -std::vector<std::unique_ptr<const DexFile>> CommonArtTestImpl::OpenTestDexFiles(const char* name) { - std::string filename = GetTestDexFileName(name); +std::vector<std::unique_ptr<const DexFile>> CommonArtTestImpl::OpenDexFiles(const char* filename) { + static constexpr bool kVerify = true; static constexpr bool kVerifyChecksum = true; std::string error_msg; const ArtDexFileLoader dex_file_loader; std::vector<std::unique_ptr<const DexFile>> dex_files; - bool success = dex_file_loader.Open(filename.c_str(), - filename.c_str(), - /* verify */ true, + bool success = dex_file_loader.Open(filename, + filename, + kVerify, kVerifyChecksum, - &error_msg, &dex_files); + &error_msg, + &dex_files); CHECK(success) << "Failed to open '" << filename << "': " << error_msg; for (auto& dex_file : dex_files) { CHECK_EQ(PROT_READ, dex_file->GetPermissions()); @@ -374,6 +375,11 @@ std::vector<std::unique_ptr<const DexFile>> CommonArtTestImpl::OpenTestDexFiles( return dex_files; } +std::vector<std::unique_ptr<const DexFile>> CommonArtTestImpl::OpenTestDexFiles( + const char* name) { + return OpenDexFiles(GetTestDexFileName(name).c_str()); +} + std::unique_ptr<const DexFile> CommonArtTestImpl::OpenTestDexFile(const char* name) { std::vector<std::unique_ptr<const DexFile>> vector = OpenTestDexFiles(name); EXPECT_EQ(1U, vector.size()); diff --git a/libartbase/base/common_art_test.h b/libartbase/base/common_art_test.h index a4764c275d..3998be516d 100644 --- a/libartbase/base/common_art_test.h +++ b/libartbase/base/common_art_test.h @@ -148,6 +148,9 @@ class CommonArtTestImpl { std::string GetTestAndroidRoot(); + // Open a file (allows reading of framework jars). + std::vector<std::unique_ptr<const DexFile>> OpenDexFiles(const char* filename); + // Open a test file (art-gtest-*.jar). std::vector<std::unique_ptr<const DexFile>> OpenTestDexFiles(const char* name); std::unique_ptr<const DexFile> OpenTestDexFile(const char* name); diff --git a/libartbase/base/file_utils_test.cc b/libartbase/base/file_utils_test.cc index e74dfe5e64..56d1c44fc0 100644 --- a/libartbase/base/file_utils_test.cc +++ b/libartbase/base/file_utils_test.cc @@ -20,11 +20,11 @@ #include <stdlib.h> #include "base/stl_util.h" -#include "common_runtime_test.h" +#include "common_art_test.h" namespace art { -class FileUtilsTest : public CommonRuntimeTest {}; +class FileUtilsTest : public CommonArtTest {}; TEST_F(FileUtilsTest, GetDalvikCacheFilename) { std::string name; @@ -63,7 +63,7 @@ TEST_F(FileUtilsTest, GetAndroidRootSafe) { // We don't expect null returns for most cases, so don't check and let std::string crash. - // CommonRuntimeTest sets ANDROID_ROOT, so expect this to be the same. + // CommonArtTest sets ANDROID_ROOT, so expect this to be the same. std::string android_root = GetAndroidRootSafe(&error_msg); std::string android_root_env = getenv("ANDROID_ROOT"); EXPECT_EQ(android_root, android_root_env); @@ -78,7 +78,7 @@ TEST_F(FileUtilsTest, GetAndroidRootSafe) { // Set a bogus value for ANDROID_ROOT. This should be an error. ASSERT_EQ(0, setenv("ANDROID_ROOT", "/this/is/obviously/bogus", 1 /* overwrite */)); - EXPECT_TRUE(GetAndroidRootSafe(&error_msg) == nullptr); + EXPECT_EQ(GetAndroidRootSafe(&error_msg), ""); // Unset ANDROID_ROOT and see that it still returns something (as libart code is running). ASSERT_EQ(0, unsetenv("ANDROID_ROOT")); diff --git a/libdexfile/dex/art_dex_file_loader_test.cc b/libdexfile/dex/art_dex_file_loader_test.cc index d353c26b35..5f3fc0266f 100644 --- a/libdexfile/dex/art_dex_file_loader_test.cc +++ b/libdexfile/dex/art_dex_file_loader_test.cc @@ -14,26 +14,25 @@ * limitations under the License. */ +#include "art_dex_file_loader.h" + #include <sys/mman.h> #include <fstream> #include <memory> -#include "art_dex_file_loader.h" +#include "base/common_art_test.h" #include "base/file_utils.h" #include "base/mem_map.h" #include "base/os.h" #include "base/stl_util.h" #include "base/unix_file/fd_file.h" -#include "common_runtime_test.h" #include "dex/base64_test_util.h" #include "dex/code_item_accessors-inl.h" #include "dex/descriptors_names.h" #include "dex/dex_file.h" #include "dex/dex_file-inl.h" #include "dex/dex_file_loader.h" -#include "scoped_thread_state_change-inl.h" -#include "thread-current-inl.h" namespace art { @@ -43,26 +42,35 @@ static void Copy(const std::string& src, const std::string& dst) { dst_stream << src_stream.rdbuf(); } -class ArtDexFileLoaderTest : public CommonRuntimeTest {}; +class ArtDexFileLoaderTest : public CommonArtTest { + void SetUp() OVERRIDE { + CommonArtTest::SetUp(); + // Open a jar file from the boot classpath for use in basic tests of dex accessors. + std::vector<std::string> lib_core_dex_file_names = GetLibCoreDexFileNames(); + CHECK_NE(lib_core_dex_file_names.size(), 0U); + dex_files_ = OpenDexFiles(lib_core_dex_file_names[0].c_str()); + CHECK_NE(dex_files_.size(), 0U); + // Save a dex file for use by tests. + java_lang_dex_file_ = dex_files_[0].get(); + } -// TODO: Port OpenTestDexFile(s) need to be ported to use non-ART utilities, and -// the tests that depend upon them should be moved to dex_file_loader_test.cc + protected: + std::vector<std::unique_ptr<const DexFile>> dex_files_; + const DexFile* java_lang_dex_file_; +}; TEST_F(ArtDexFileLoaderTest, Open) { - ScopedObjectAccess soa(Thread::Current()); std::unique_ptr<const DexFile> dex(OpenTestDexFile("Nested")); ASSERT_TRUE(dex.get() != nullptr); } TEST_F(ArtDexFileLoaderTest, GetLocationChecksum) { - ScopedObjectAccess soa(Thread::Current()); std::unique_ptr<const DexFile> raw(OpenTestDexFile("Main")); EXPECT_NE(raw->GetHeader().checksum_, raw->GetLocationChecksum()); } TEST_F(ArtDexFileLoaderTest, GetChecksum) { std::vector<uint32_t> checksums; - ScopedObjectAccess soa(Thread::Current()); std::string error_msg; const ArtDexFileLoader dex_file_loader; EXPECT_TRUE(dex_file_loader.GetMultiDexChecksums(GetLibCoreDexFileNames()[0].c_str(), @@ -94,7 +102,6 @@ TEST_F(ArtDexFileLoaderTest, GetMultiDexChecksums) { } TEST_F(ArtDexFileLoaderTest, ClassDefs) { - ScopedObjectAccess soa(Thread::Current()); std::unique_ptr<const DexFile> raw(OpenTestDexFile("Nested")); ASSERT_TRUE(raw.get() != nullptr); EXPECT_EQ(3U, raw->NumClassDefs()); @@ -110,7 +117,6 @@ TEST_F(ArtDexFileLoaderTest, ClassDefs) { } TEST_F(ArtDexFileLoaderTest, GetMethodSignature) { - ScopedObjectAccess soa(Thread::Current()); std::unique_ptr<const DexFile> raw(OpenTestDexFile("GetMethodSignature")); ASSERT_TRUE(raw.get() != nullptr); EXPECT_EQ(1U, raw->NumClassDefs()); @@ -215,7 +221,6 @@ TEST_F(ArtDexFileLoaderTest, GetMethodSignature) { } TEST_F(ArtDexFileLoaderTest, FindStringId) { - ScopedObjectAccess soa(Thread::Current()); std::unique_ptr<const DexFile> raw(OpenTestDexFile("GetMethodSignature")); ASSERT_TRUE(raw.get() != nullptr); EXPECT_EQ(1U, raw->NumClassDefs()); |