diff options
author | 2018-04-27 14:12:03 -0700 | |
---|---|---|
committer | 2018-05-01 16:23:42 -0700 | |
commit | d5f8de8bc61160bb2cecdcc0f5aa54d151b6176a (patch) | |
tree | efecd6d3dffd3a1d768b87a111d9e60335d9108c | |
parent | 9417b6b81393253a56b1b9bb4c7d8a2a2966707e (diff) |
Add CommonArtTest
Add a test framework that does not start up a Runtime object.
Bug: 78651010
Test: make -j 40 test-art-host
Change-Id: I6c8af384af5fe1289c6cf137635e94934ac3795d
-rw-r--r-- | build/Android.gtest.mk | 1 | ||||
-rw-r--r-- | libartbase/Android.bp | 23 | ||||
-rw-r--r-- | libartbase/base/common_art_test.cc | 420 | ||||
-rw-r--r-- | libartbase/base/common_art_test.h | 234 | ||||
-rw-r--r-- | libartbase/base/mem_map_test.cc | 5 | ||||
-rw-r--r-- | libartbase/base/scoped_flock_test.cc | 4 | ||||
-rw-r--r-- | libartbase/base/unix_file/fd_file_test.cc | 2 | ||||
-rw-r--r-- | libartbase/base/unix_file/random_access_file_test.h | 6 | ||||
-rw-r--r-- | libartbase/base/zip_archive_test.cc | 4 | ||||
-rw-r--r-- | libdexfile/dex/type_lookup_table_test.cc | 6 | ||||
-rw-r--r-- | runtime/Android.bp | 1 | ||||
-rw-r--r-- | runtime/common_runtime_test.cc | 361 | ||||
-rw-r--r-- | runtime/common_runtime_test.h | 121 | ||||
-rw-r--r-- | runtime/dex/art_dex_file_loader_test.cc | 2 | ||||
-rw-r--r-- | test/Android.bp | 1 |
15 files changed, 696 insertions, 495 deletions
diff --git a/build/Android.gtest.mk b/build/Android.gtest.mk index a4a72f4ccc..b46f6771ea 100644 --- a/build/Android.gtest.mk +++ b/build/Android.gtest.mk @@ -370,6 +370,7 @@ ART_TEST_MODULES := \ art_imgdiag_tests \ art_libartbase_tests \ art_libdexfile_tests \ + art_libprofile_tests \ art_oatdump_tests \ art_patchoat_tests \ art_profman_tests \ diff --git a/libartbase/Android.bp b/libartbase/Android.bp index 8cf4d0376d..50abdd36af 100644 --- a/libartbase/Android.bp +++ b/libartbase/Android.bp @@ -116,9 +116,26 @@ art_cc_library { export_shared_lib_headers: ["libbase"], } -// For now many of these tests still use CommonRuntimeTest, almost universally because of -// ScratchFile and related. -// TODO: Remove CommonRuntimeTest dependency from these tests. +art_cc_library { + name: "libartbase-art-gtest", + defaults: ["libart-gtest-defaults"], + srcs: [ + "base/common_art_test.cc", + ], + shared_libs: [ + "libartbased", + "libdexfiled", + "libbase", + "libbacktrace", + ], + header_libs: [ + "libnativehelper_header_only", + ], + include_dirs: [ + "external/icu/icu4c/source/common", + ], +} + art_cc_test { name: "art_libartbase_tests", defaults: [ diff --git a/libartbase/base/common_art_test.cc b/libartbase/base/common_art_test.cc new file mode 100644 index 0000000000..0d798f37f7 --- /dev/null +++ b/libartbase/base/common_art_test.cc @@ -0,0 +1,420 @@ +/* + * Copyright (C) 2012 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 "common_art_test.h" + +#include <dirent.h> +#include <dlfcn.h> +#include <fcntl.h> +#include <stdlib.h> +#include <cstdio> +#include "nativehelper/scoped_local_ref.h" + +#include "android-base/stringprintf.h" +#include <unicode/uvernum.h> + +#include "art_field-inl.h" +#include "base/file_utils.h" +#include "base/logging.h" +#include "base/macros.h" +#include "base/mem_map.h" +#include "base/mutex.h" +#include "base/os.h" +#include "base/runtime_debug.h" +#include "base/stl_util.h" +#include "base/unix_file/fd_file.h" +#include "dex/art_dex_file_loader.h" +#include "dex/dex_file-inl.h" +#include "dex/dex_file_loader.h" +#include "dex/primitive.h" +#include "gtest/gtest.h" + +namespace art { + +using android::base::StringPrintf; + +ScratchFile::ScratchFile() { + // ANDROID_DATA needs to be set + CHECK_NE(static_cast<char*>(nullptr), getenv("ANDROID_DATA")) << + "Are you subclassing RuntimeTest?"; + filename_ = getenv("ANDROID_DATA"); + filename_ += "/TmpFile-XXXXXX"; + int fd = mkstemp(&filename_[0]); + CHECK_NE(-1, fd) << strerror(errno) << " for " << filename_; + file_.reset(new File(fd, GetFilename(), true)); +} + +ScratchFile::ScratchFile(const ScratchFile& other, const char* suffix) + : ScratchFile(other.GetFilename() + suffix) {} + +ScratchFile::ScratchFile(const std::string& filename) : filename_(filename) { + int fd = open(filename_.c_str(), O_RDWR | O_CREAT, 0666); + CHECK_NE(-1, fd); + file_.reset(new File(fd, GetFilename(), true)); +} + +ScratchFile::ScratchFile(File* file) { + CHECK(file != nullptr); + filename_ = file->GetPath(); + file_.reset(file); +} + +ScratchFile::ScratchFile(ScratchFile&& other) { + *this = std::move(other); +} + +ScratchFile& ScratchFile::operator=(ScratchFile&& other) { + if (GetFile() != other.GetFile()) { + std::swap(filename_, other.filename_); + std::swap(file_, other.file_); + } + return *this; +} + +ScratchFile::~ScratchFile() { + Unlink(); +} + +int ScratchFile::GetFd() const { + return file_->Fd(); +} + +void ScratchFile::Close() { + if (file_.get() != nullptr) { + if (file_->FlushCloseOrErase() != 0) { + PLOG(WARNING) << "Error closing scratch file."; + } + } +} + +void ScratchFile::Unlink() { + if (!OS::FileExists(filename_.c_str())) { + return; + } + Close(); + int unlink_result = unlink(filename_.c_str()); + CHECK_EQ(0, unlink_result); +} + +void CommonArtTestImpl::SetUpAndroidRoot() { + if (IsHost()) { + // $ANDROID_ROOT is set on the device, but not necessarily on the host. + // But it needs to be set so that icu4c can find its locale data. + const char* android_root_from_env = getenv("ANDROID_ROOT"); + if (android_root_from_env == nullptr) { + // Use ANDROID_HOST_OUT for ANDROID_ROOT if it is set. + const char* android_host_out = getenv("ANDROID_HOST_OUT"); + if (android_host_out != nullptr) { + setenv("ANDROID_ROOT", android_host_out, 1); + } else { + // Build it from ANDROID_BUILD_TOP or cwd + std::string root; + const char* android_build_top = getenv("ANDROID_BUILD_TOP"); + if (android_build_top != nullptr) { + root += android_build_top; + } else { + // Not set by build server, so default to current directory + char* cwd = getcwd(nullptr, 0); + setenv("ANDROID_BUILD_TOP", cwd, 1); + root += cwd; + free(cwd); + } +#if defined(__linux__) + root += "/out/host/linux-x86"; +#elif defined(__APPLE__) + root += "/out/host/darwin-x86"; +#else +#error unsupported OS +#endif + setenv("ANDROID_ROOT", root.c_str(), 1); + } + } + setenv("LD_LIBRARY_PATH", ":", 0); // Required by java.lang.System.<clinit>. + + // Not set by build server, so default + if (getenv("ANDROID_HOST_OUT") == nullptr) { + setenv("ANDROID_HOST_OUT", getenv("ANDROID_ROOT"), 1); + } + } +} + +void CommonArtTestImpl::SetUpAndroidData(std::string& android_data) { + // On target, Cannot use /mnt/sdcard because it is mounted noexec, so use subdir of dalvik-cache + if (IsHost()) { + const char* tmpdir = getenv("TMPDIR"); + if (tmpdir != nullptr && tmpdir[0] != 0) { + android_data = tmpdir; + } else { + android_data = "/tmp"; + } + } else { + android_data = "/data/dalvik-cache"; + } + android_data += "/art-data-XXXXXX"; + if (mkdtemp(&android_data[0]) == nullptr) { + PLOG(FATAL) << "mkdtemp(\"" << &android_data[0] << "\") failed"; + } + setenv("ANDROID_DATA", android_data.c_str(), 1); +} + +void CommonArtTestImpl::SetUp() { + SetUpAndroidRoot(); + SetUpAndroidData(android_data_); + dalvik_cache_.append(android_data_.c_str()); + dalvik_cache_.append("/dalvik-cache"); + int mkdir_result = mkdir(dalvik_cache_.c_str(), 0700); + ASSERT_EQ(mkdir_result, 0); +} + +void CommonArtTestImpl::TearDownAndroidData(const std::string& android_data, bool fail_on_error) { + if (fail_on_error) { + ASSERT_EQ(rmdir(android_data.c_str()), 0); + } else { + rmdir(android_data.c_str()); + } +} + +// Helper - find directory with the following format: +// ${ANDROID_BUILD_TOP}/${subdir1}/${subdir2}-${version}/${subdir3}/bin/ +std::string CommonArtTestImpl::GetAndroidToolsDir(const std::string& subdir1, + const std::string& subdir2, + const std::string& subdir3) { + std::string root; + const char* android_build_top = getenv("ANDROID_BUILD_TOP"); + if (android_build_top != nullptr) { + root = android_build_top; + } else { + // Not set by build server, so default to current directory + char* cwd = getcwd(nullptr, 0); + setenv("ANDROID_BUILD_TOP", cwd, 1); + root = cwd; + free(cwd); + } + + std::string toolsdir = root + "/" + subdir1; + std::string founddir; + DIR* dir; + if ((dir = opendir(toolsdir.c_str())) != nullptr) { + float maxversion = 0; + struct dirent* entry; + while ((entry = readdir(dir)) != nullptr) { + std::string format = subdir2 + "-%f"; + float version; + if (std::sscanf(entry->d_name, format.c_str(), &version) == 1) { + if (version > maxversion) { + maxversion = version; + founddir = toolsdir + "/" + entry->d_name + "/" + subdir3 + "/bin/"; + } + } + } + closedir(dir); + } + + if (founddir.empty()) { + ADD_FAILURE() << "Cannot find Android tools directory."; + } + return founddir; +} + +std::string CommonArtTestImpl::GetAndroidHostToolsDir() { + return GetAndroidToolsDir("prebuilts/gcc/linux-x86/host", + "x86_64-linux-glibc2.15", + "x86_64-linux"); +} + +std::string CommonArtTestImpl::GetCoreArtLocation() { + return GetCoreFileLocation("art"); +} + +std::string CommonArtTestImpl::GetCoreOatLocation() { + return GetCoreFileLocation("oat"); +} + +std::unique_ptr<const DexFile> CommonArtTestImpl::LoadExpectSingleDexFile(const char* location) { + std::vector<std::unique_ptr<const DexFile>> dex_files; + std::string error_msg; + MemMap::Init(); + static constexpr bool kVerifyChecksum = true; + const ArtDexFileLoader dex_file_loader; + if (!dex_file_loader.Open( + location, location, /* verify */ true, kVerifyChecksum, &error_msg, &dex_files)) { + LOG(FATAL) << "Could not open .dex file '" << location << "': " << error_msg << "\n"; + UNREACHABLE(); + } else { + CHECK_EQ(1U, dex_files.size()) << "Expected only one dex file in " << location; + return std::move(dex_files[0]); + } +} + +void CommonArtTestImpl::ClearDirectory(const char* dirpath, bool recursive) { + ASSERT_TRUE(dirpath != nullptr); + DIR* dir = opendir(dirpath); + ASSERT_TRUE(dir != nullptr); + dirent* e; + struct stat s; + while ((e = readdir(dir)) != nullptr) { + if ((strcmp(e->d_name, ".") == 0) || (strcmp(e->d_name, "..") == 0)) { + continue; + } + std::string filename(dirpath); + filename.push_back('/'); + filename.append(e->d_name); + int stat_result = lstat(filename.c_str(), &s); + ASSERT_EQ(0, stat_result) << "unable to stat " << filename; + if (S_ISDIR(s.st_mode)) { + if (recursive) { + ClearDirectory(filename.c_str()); + int rmdir_result = rmdir(filename.c_str()); + ASSERT_EQ(0, rmdir_result) << filename; + } + } else { + int unlink_result = unlink(filename.c_str()); + ASSERT_EQ(0, unlink_result) << filename; + } + } + closedir(dir); +} + +void CommonArtTestImpl::TearDown() { + const char* android_data = getenv("ANDROID_DATA"); + ASSERT_TRUE(android_data != nullptr); + ClearDirectory(dalvik_cache_.c_str()); + int rmdir_cache_result = rmdir(dalvik_cache_.c_str()); + ASSERT_EQ(0, rmdir_cache_result); + TearDownAndroidData(android_data_, true); + dalvik_cache_.clear(); +} + +static std::string GetDexFileName(const std::string& jar_prefix, bool host) { + std::string path; + if (host) { + const char* host_dir = getenv("ANDROID_HOST_OUT"); + CHECK(host_dir != nullptr); + path = host_dir; + } else { + path = GetAndroidRoot(); + } + + std::string suffix = host + ? "-hostdex" // The host version. + : "-testdex"; // The unstripped target version. + + return StringPrintf("%s/framework/%s%s.jar", path.c_str(), jar_prefix.c_str(), suffix.c_str()); +} + +std::vector<std::string> CommonArtTestImpl::GetLibCoreDexFileNames() { + return std::vector<std::string>({GetDexFileName("core-oj", IsHost()), + GetDexFileName("core-libart", IsHost())}); +} + +std::string CommonArtTestImpl::GetTestAndroidRoot() { + if (IsHost()) { + const char* host_dir = getenv("ANDROID_HOST_OUT"); + CHECK(host_dir != nullptr); + return host_dir; + } + return GetAndroidRoot(); +} + +// Check that for target builds we have ART_TARGET_NATIVETEST_DIR set. +#ifdef ART_TARGET +#ifndef ART_TARGET_NATIVETEST_DIR +#error "ART_TARGET_NATIVETEST_DIR not set." +#endif +// Wrap it as a string literal. +#define ART_TARGET_NATIVETEST_DIR_STRING STRINGIFY(ART_TARGET_NATIVETEST_DIR) "/" +#else +#define ART_TARGET_NATIVETEST_DIR_STRING "" +#endif + +std::string CommonArtTestImpl::GetTestDexFileName(const char* name) const { + CHECK(name != nullptr); + std::string filename; + if (IsHost()) { + filename += getenv("ANDROID_HOST_OUT"); + filename += "/framework/"; + } else { + filename += ART_TARGET_NATIVETEST_DIR_STRING; + } + filename += "art-gtest-"; + filename += name; + filename += ".jar"; + return filename; +} + +std::vector<std::unique_ptr<const DexFile>> CommonArtTestImpl::OpenTestDexFiles(const char* name) { + std::string filename = GetTestDexFileName(name); + 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, + kVerifyChecksum, + &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()); + CHECK(dex_file->IsReadOnly()); + } + return dex_files; +} + +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()); + return std::move(vector[0]); +} + +std::string CommonArtTestImpl::GetCoreFileLocation(const char* suffix) { + CHECK(suffix != nullptr); + + std::string location; + if (IsHost()) { + const char* host_dir = getenv("ANDROID_HOST_OUT"); + CHECK(host_dir != nullptr); + location = StringPrintf("%s/framework/core.%s", host_dir, suffix); + } else { + location = StringPrintf("/data/art-test/core.%s", suffix); + } + + return location; +} + +std::string CommonArtTestImpl::CreateClassPath( + const std::vector<std::unique_ptr<const DexFile>>& dex_files) { + CHECK(!dex_files.empty()); + std::string classpath = dex_files[0]->GetLocation(); + for (size_t i = 1; i < dex_files.size(); i++) { + classpath += ":" + dex_files[i]->GetLocation(); + } + return classpath; +} + +std::string CommonArtTestImpl::CreateClassPathWithChecksums( + const std::vector<std::unique_ptr<const DexFile>>& dex_files) { + CHECK(!dex_files.empty()); + std::string classpath = dex_files[0]->GetLocation() + "*" + + std::to_string(dex_files[0]->GetLocationChecksum()); + for (size_t i = 1; i < dex_files.size(); i++) { + classpath += ":" + dex_files[i]->GetLocation() + "*" + + std::to_string(dex_files[i]->GetLocationChecksum()); + } + return classpath; +} + +} // namespace art diff --git a/libartbase/base/common_art_test.h b/libartbase/base/common_art_test.h new file mode 100644 index 0000000000..a4764c275d --- /dev/null +++ b/libartbase/base/common_art_test.h @@ -0,0 +1,234 @@ +/* + * Copyright (C) 2018 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. + */ + +#ifndef ART_LIBARTBASE_BASE_COMMON_ART_TEST_H_ +#define ART_LIBARTBASE_BASE_COMMON_ART_TEST_H_ + +#include <gtest/gtest.h> + +#include <string> + +#include <android-base/logging.h> + +#include "base/globals.h" +#include "base/mutex.h" +#include "base/os.h" +#include "base/unix_file/fd_file.h" +#include "dex/art_dex_file_loader.h" +#include "dex/compact_dex_level.h" + +namespace art { + +using LogSeverity = android::base::LogSeverity; +using ScopedLogSeverity = android::base::ScopedLogSeverity; + +// OBJ pointer helpers to avoid needing .Decode everywhere. +#define EXPECT_OBJ_PTR_EQ(a, b) EXPECT_EQ(MakeObjPtr(a).Ptr(), MakeObjPtr(b).Ptr()); +#define ASSERT_OBJ_PTR_EQ(a, b) ASSERT_EQ(MakeObjPtr(a).Ptr(), MakeObjPtr(b).Ptr()); +#define EXPECT_OBJ_PTR_NE(a, b) EXPECT_NE(MakeObjPtr(a).Ptr(), MakeObjPtr(b).Ptr()); +#define ASSERT_OBJ_PTR_NE(a, b) ASSERT_NE(MakeObjPtr(a).Ptr(), MakeObjPtr(b).Ptr()); + +class DexFile; + +class ScratchFile { + public: + ScratchFile(); + + explicit ScratchFile(const std::string& filename); + + ScratchFile(const ScratchFile& other, const char* suffix); + + ScratchFile(ScratchFile&& other); + + ScratchFile& operator=(ScratchFile&& other); + + explicit ScratchFile(File* file); + + ~ScratchFile(); + + const std::string& GetFilename() const { + return filename_; + } + + File* GetFile() const { + return file_.get(); + } + + int GetFd() const; + + void Close(); + void Unlink(); + + private: + std::string filename_; + std::unique_ptr<File> file_; +}; + +class CommonArtTestImpl { + public: + CommonArtTestImpl() = default; + virtual ~CommonArtTestImpl() = default; + + static void SetUpAndroidRoot(); + + // Note: setting up ANDROID_DATA may create a temporary directory. If this is used in a + // non-derived class, be sure to also call the corresponding tear-down below. + static void SetUpAndroidData(std::string& android_data); + + static void TearDownAndroidData(const std::string& android_data, bool fail_on_error); + + // Gets the paths of the libcore dex files. + static std::vector<std::string> GetLibCoreDexFileNames(); + + // Returns bin directory which contains host's prebuild tools. + static std::string GetAndroidHostToolsDir(); + + // Retuerns the filename for a test dex (i.e. XandY or ManyMethods). + std::string GetTestDexFileName(const char* name) const; + + template <typename Mutator> + bool MutateDexFile(File* output_dex, const std::string& input_jar, const Mutator& mutator) { + std::vector<std::unique_ptr<const DexFile>> dex_files; + std::string error_msg; + const ArtDexFileLoader dex_file_loader; + CHECK(dex_file_loader.Open(input_jar.c_str(), + input_jar.c_str(), + /*verify*/ true, + /*verify_checksum*/ true, + &error_msg, + &dex_files)) << error_msg; + EXPECT_EQ(dex_files.size(), 1u) << "Only one input dex is supported"; + const std::unique_ptr<const DexFile>& dex = dex_files[0]; + CHECK(dex->EnableWrite()) << "Failed to enable write"; + DexFile* dex_file = const_cast<DexFile*>(dex.get()); + mutator(dex_file); + const_cast<DexFile::Header&>(dex_file->GetHeader()).checksum_ = dex_file->CalculateChecksum(); + if (!output_dex->WriteFully(dex->Begin(), dex->Size())) { + return false; + } + if (output_dex->Flush() != 0) { + PLOG(FATAL) << "Could not flush the output file."; + } + return true; + } + + protected: + static bool IsHost() { + return !kIsTargetBuild; + } + + // Helper - find directory with the following format: + // ${ANDROID_BUILD_TOP}/${subdir1}/${subdir2}-${version}/${subdir3}/bin/ + static std::string GetAndroidToolsDir(const std::string& subdir1, + const std::string& subdir2, + const std::string& subdir3); + + // File location to core.art, e.g. $ANDROID_HOST_OUT/system/framework/core.art + static std::string GetCoreArtLocation(); + + // File location to core.oat, e.g. $ANDROID_HOST_OUT/system/framework/core.oat + static std::string GetCoreOatLocation(); + + std::unique_ptr<const DexFile> LoadExpectSingleDexFile(const char* location); + + void ClearDirectory(const char* dirpath, bool recursive = true); + + std::string GetTestAndroidRoot(); + + std::vector<std::unique_ptr<const DexFile>> OpenTestDexFiles(const char* name); + + std::unique_ptr<const DexFile> OpenTestDexFile(const char* name); + + + std::string android_data_; + std::string dalvik_cache_; + + virtual void SetUp(); + + virtual void TearDown(); + + // Creates the class path string for the given dex files (the list of dex file locations + // separated by ':'). + std::string CreateClassPath(const std::vector<std::unique_ptr<const DexFile>>& dex_files); + // Same as CreateClassPath but add the dex file checksum after each location. The separator + // is '*'. + std::string CreateClassPathWithChecksums( + const std::vector<std::unique_ptr<const DexFile>>& dex_files); + + static std::string GetCoreFileLocation(const char* suffix); + + std::vector<std::unique_ptr<const DexFile>> loaded_dex_files_; +}; + +template <typename TestType> +class CommonArtTestBase : public TestType, public CommonArtTestImpl { + public: + CommonArtTestBase() {} + virtual ~CommonArtTestBase() {} + + protected: + virtual void SetUp() OVERRIDE { + CommonArtTestImpl::SetUp(); + } + + virtual void TearDown() OVERRIDE { + CommonArtTestImpl::TearDown(); + } +}; + +using CommonArtTest = CommonArtTestBase<testing::Test>; + +template <typename Param> +using CommonArtTestWithParam = CommonArtTestBase<testing::TestWithParam<Param>>; + +#define TEST_DISABLED_FOR_TARGET() \ + if (kIsTargetBuild) { \ + printf("WARNING: TEST DISABLED FOR TARGET\n"); \ + return; \ + } + +#define TEST_DISABLED_FOR_NON_STATIC_HOST_BUILDS() \ + if (!kHostStaticBuildEnabled) { \ + printf("WARNING: TEST DISABLED FOR NON-STATIC HOST BUILDS\n"); \ + return; \ + } + +#define TEST_DISABLED_FOR_MEMORY_TOOL() \ + if (RUNNING_ON_MEMORY_TOOL > 0) { \ + printf("WARNING: TEST DISABLED FOR MEMORY TOOL\n"); \ + return; \ + } + +#define TEST_DISABLED_FOR_MEMORY_TOOL_VALGRIND() \ + if (RUNNING_ON_MEMORY_TOOL > 0 && kMemoryToolIsValgrind) { \ + printf("WARNING: TEST DISABLED FOR MEMORY TOOL VALGRIND\n"); \ + return; \ + } + +#define TEST_DISABLED_FOR_MEMORY_TOOL_ASAN() \ + if (RUNNING_ON_MEMORY_TOOL > 0 && !kMemoryToolIsValgrind) { \ + printf("WARNING: TEST DISABLED FOR MEMORY TOOL ASAN\n"); \ + return; \ + } + +#define TEST_DISABLED_FOR_HEAP_POISONING() \ + if (kPoisonHeapReferences) { \ + printf("WARNING: TEST DISABLED FOR HEAP POISONING\n"); \ + return; \ + } +} // namespace art + +#endif // ART_LIBARTBASE_BASE_COMMON_ART_TEST_H_ diff --git a/libartbase/base/mem_map_test.cc b/libartbase/base/mem_map_test.cc index 4408f5502a..d956126df1 100644 --- a/libartbase/base/mem_map_test.cc +++ b/libartbase/base/mem_map_test.cc @@ -21,13 +21,14 @@ #include <memory> #include <random> -#include "common_runtime_test.h" +#include "base/common_art_test.h" +#include "common_runtime_test.h" // For TEST_DISABLED_FOR_MIPS #include "memory_tool.h" #include "unix_file/fd_file.h" namespace art { -class MemMapTest : public CommonRuntimeTest { +class MemMapTest : public CommonArtTest { public: static uint8_t* BaseBegin(MemMap* mem_map) { return reinterpret_cast<uint8_t*>(mem_map->base_begin_); diff --git a/libartbase/base/scoped_flock_test.cc b/libartbase/base/scoped_flock_test.cc index 1b6caaf747..f9ac1e0230 100644 --- a/libartbase/base/scoped_flock_test.cc +++ b/libartbase/base/scoped_flock_test.cc @@ -16,11 +16,11 @@ #include "scoped_flock.h" -#include "common_runtime_test.h" +#include "base/common_art_test.h" namespace art { -class ScopedFlockTest : public CommonRuntimeTest {}; +class ScopedFlockTest : public CommonArtTest {}; TEST_F(ScopedFlockTest, TestLocking) { ScratchFile scratch_file; diff --git a/libartbase/base/unix_file/fd_file_test.cc b/libartbase/base/unix_file/fd_file_test.cc index 7fc057b9e8..1f731a7a7b 100644 --- a/libartbase/base/unix_file/fd_file_test.cc +++ b/libartbase/base/unix_file/fd_file_test.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "common_runtime_test.h" // For ScratchFile +#include "base/common_art_test.h" // For ScratchFile #include "gtest/gtest.h" #include "fd_file.h" #include "random_access_file_test.h" diff --git a/libartbase/base/unix_file/random_access_file_test.h b/libartbase/base/unix_file/random_access_file_test.h index 1de5f7b72c..dbe6ca948f 100644 --- a/libartbase/base/unix_file/random_access_file_test.h +++ b/libartbase/base/unix_file/random_access_file_test.h @@ -21,7 +21,7 @@ #include <memory> #include <string> -#include "common_runtime_test.h" +#include "base/common_art_test.h" namespace unix_file { @@ -35,11 +35,11 @@ class RandomAccessFileTest : public testing::Test { virtual RandomAccessFile* MakeTestFile() = 0; virtual void SetUp() { - art::CommonRuntimeTest::SetUpAndroidData(android_data_); + art::CommonArtTest::SetUpAndroidData(android_data_); } virtual void TearDown() { - art::CommonRuntimeTest::TearDownAndroidData(android_data_, true); + art::CommonArtTest::TearDownAndroidData(android_data_, true); } std::string GetTmpPath(const std::string& name) { diff --git a/libartbase/base/zip_archive_test.cc b/libartbase/base/zip_archive_test.cc index 63743f754c..b99a471e04 100644 --- a/libartbase/base/zip_archive_test.cc +++ b/libartbase/base/zip_archive_test.cc @@ -22,13 +22,13 @@ #include <zlib.h> #include <memory> -#include "common_runtime_test.h" +#include "base/common_art_test.h" #include "os.h" #include "unix_file/fd_file.h" namespace art { -class ZipArchiveTest : public CommonRuntimeTest {}; +class ZipArchiveTest : public CommonArtTest {}; TEST_F(ZipArchiveTest, FindAndExtract) { std::string error_msg; diff --git a/libdexfile/dex/type_lookup_table_test.cc b/libdexfile/dex/type_lookup_table_test.cc index b6ab6da78c..6c3d291332 100644 --- a/libdexfile/dex/type_lookup_table_test.cc +++ b/libdexfile/dex/type_lookup_table_test.cc @@ -18,7 +18,7 @@ #include <memory> -#include "common_runtime_test.h" +#include "base/common_art_test.h" #include "dex/dex_file-inl.h" #include "dex/utf-inl.h" #include "scoped_thread_state_change-inl.h" @@ -26,10 +26,9 @@ namespace art { using DescriptorClassDefIdxPair = std::pair<const char*, uint32_t>; -class TypeLookupTableTest : public CommonRuntimeTestWithParam<DescriptorClassDefIdxPair> {}; +class TypeLookupTableTest : public CommonArtTestWithParam<DescriptorClassDefIdxPair> {}; TEST_F(TypeLookupTableTest, CreateLookupTable) { - ScopedObjectAccess soa(Thread::Current()); std::unique_ptr<const DexFile> dex_file(OpenTestDexFile("Lookup")); std::unique_ptr<TypeLookupTable> table(TypeLookupTable::Create(*dex_file)); ASSERT_NE(nullptr, table.get()); @@ -38,7 +37,6 @@ TEST_F(TypeLookupTableTest, CreateLookupTable) { } TEST_P(TypeLookupTableTest, Find) { - ScopedObjectAccess soa(Thread::Current()); std::unique_ptr<const DexFile> dex_file(OpenTestDexFile("Lookup")); std::unique_ptr<TypeLookupTable> table(TypeLookupTable::Create(*dex_file)); ASSERT_NE(nullptr, table.get()); diff --git a/runtime/Android.bp b/runtime/Android.bp index f39562313d..28bee3d67e 100644 --- a/runtime/Android.bp +++ b/runtime/Android.bp @@ -511,6 +511,7 @@ art_cc_library { ], shared_libs: [ "libartd", + "libartbase-art-gtest", "libbase", "libbacktrace", ], diff --git a/runtime/common_runtime_test.cc b/runtime/common_runtime_test.cc index f6a5efc547..f5b15ec239 100644 --- a/runtime/common_runtime_test.cc +++ b/runtime/common_runtime_test.cc @@ -67,6 +67,7 @@ int main(int argc, char **argv) { art::Locks::Init(); art::InitLogging(argv, art::Runtime::Abort); + art::MemMap::Init(); LOG(INFO) << "Running main() from common_runtime_test.cc..."; testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); @@ -76,69 +77,6 @@ namespace art { using android::base::StringPrintf; -ScratchFile::ScratchFile() { - // ANDROID_DATA needs to be set - CHECK_NE(static_cast<char*>(nullptr), getenv("ANDROID_DATA")) << - "Are you subclassing RuntimeTest?"; - filename_ = getenv("ANDROID_DATA"); - filename_ += "/TmpFile-XXXXXX"; - int fd = mkstemp(&filename_[0]); - CHECK_NE(-1, fd) << strerror(errno) << " for " << filename_; - file_.reset(new File(fd, GetFilename(), true)); -} - -ScratchFile::ScratchFile(const ScratchFile& other, const char* suffix) - : ScratchFile(other.GetFilename() + suffix) {} - -ScratchFile::ScratchFile(const std::string& filename) : filename_(filename) { - int fd = open(filename_.c_str(), O_RDWR | O_CREAT, 0666); - CHECK_NE(-1, fd); - file_.reset(new File(fd, GetFilename(), true)); -} - -ScratchFile::ScratchFile(File* file) { - CHECK(file != nullptr); - filename_ = file->GetPath(); - file_.reset(file); -} - -ScratchFile::ScratchFile(ScratchFile&& other) { - *this = std::move(other); -} - -ScratchFile& ScratchFile::operator=(ScratchFile&& other) { - if (GetFile() != other.GetFile()) { - std::swap(filename_, other.filename_); - std::swap(file_, other.file_); - } - return *this; -} - -ScratchFile::~ScratchFile() { - Unlink(); -} - -int ScratchFile::GetFd() const { - return file_->Fd(); -} - -void ScratchFile::Close() { - if (file_.get() != nullptr) { - if (file_->FlushCloseOrErase() != 0) { - PLOG(WARNING) << "Error closing scratch file."; - } - } -} - -void ScratchFile::Unlink() { - if (!OS::FileExists(filename_.c_str())) { - return; - } - Close(); - int unlink_result = unlink(filename_.c_str()); - CHECK_EQ(0, unlink_result); -} - static bool unstarted_initialized_ = false; CommonRuntimeTestImpl::CommonRuntimeTestImpl() @@ -151,124 +89,6 @@ CommonRuntimeTestImpl::~CommonRuntimeTestImpl() { runtime_.reset(); } -void CommonRuntimeTestImpl::SetUpAndroidRoot() { - if (IsHost()) { - // $ANDROID_ROOT is set on the device, but not necessarily on the host. - // But it needs to be set so that icu4c can find its locale data. - const char* android_root_from_env = getenv("ANDROID_ROOT"); - if (android_root_from_env == nullptr) { - // Use ANDROID_HOST_OUT for ANDROID_ROOT if it is set. - const char* android_host_out = getenv("ANDROID_HOST_OUT"); - if (android_host_out != nullptr) { - setenv("ANDROID_ROOT", android_host_out, 1); - } else { - // Build it from ANDROID_BUILD_TOP or cwd - std::string root; - const char* android_build_top = getenv("ANDROID_BUILD_TOP"); - if (android_build_top != nullptr) { - root += android_build_top; - } else { - // Not set by build server, so default to current directory - char* cwd = getcwd(nullptr, 0); - setenv("ANDROID_BUILD_TOP", cwd, 1); - root += cwd; - free(cwd); - } -#if defined(__linux__) - root += "/out/host/linux-x86"; -#elif defined(__APPLE__) - root += "/out/host/darwin-x86"; -#else -#error unsupported OS -#endif - setenv("ANDROID_ROOT", root.c_str(), 1); - } - } - setenv("LD_LIBRARY_PATH", ":", 0); // Required by java.lang.System.<clinit>. - - // Not set by build server, so default - if (getenv("ANDROID_HOST_OUT") == nullptr) { - setenv("ANDROID_HOST_OUT", getenv("ANDROID_ROOT"), 1); - } - } -} - -void CommonRuntimeTestImpl::SetUpAndroidData(std::string& android_data) { - // On target, Cannot use /mnt/sdcard because it is mounted noexec, so use subdir of dalvik-cache - if (IsHost()) { - const char* tmpdir = getenv("TMPDIR"); - if (tmpdir != nullptr && tmpdir[0] != 0) { - android_data = tmpdir; - } else { - android_data = "/tmp"; - } - } else { - android_data = "/data/dalvik-cache"; - } - android_data += "/art-data-XXXXXX"; - if (mkdtemp(&android_data[0]) == nullptr) { - PLOG(FATAL) << "mkdtemp(\"" << &android_data[0] << "\") failed"; - } - setenv("ANDROID_DATA", android_data.c_str(), 1); -} - -void CommonRuntimeTestImpl::TearDownAndroidData(const std::string& android_data, - bool fail_on_error) { - if (fail_on_error) { - ASSERT_EQ(rmdir(android_data.c_str()), 0); - } else { - rmdir(android_data.c_str()); - } -} - -// Helper - find directory with the following format: -// ${ANDROID_BUILD_TOP}/${subdir1}/${subdir2}-${version}/${subdir3}/bin/ -static std::string GetAndroidToolsDir(const std::string& subdir1, - const std::string& subdir2, - const std::string& subdir3) { - std::string root; - const char* android_build_top = getenv("ANDROID_BUILD_TOP"); - if (android_build_top != nullptr) { - root = android_build_top; - } else { - // Not set by build server, so default to current directory - char* cwd = getcwd(nullptr, 0); - setenv("ANDROID_BUILD_TOP", cwd, 1); - root = cwd; - free(cwd); - } - - std::string toolsdir = root + "/" + subdir1; - std::string founddir; - DIR* dir; - if ((dir = opendir(toolsdir.c_str())) != nullptr) { - float maxversion = 0; - struct dirent* entry; - while ((entry = readdir(dir)) != nullptr) { - std::string format = subdir2 + "-%f"; - float version; - if (std::sscanf(entry->d_name, format.c_str(), &version) == 1) { - if (version > maxversion) { - maxversion = version; - founddir = toolsdir + "/" + entry->d_name + "/" + subdir3 + "/bin/"; - } - } - } - closedir(dir); - } - - if (founddir.empty()) { - ADD_FAILURE() << "Cannot find Android tools directory."; - } - return founddir; -} - -std::string CommonRuntimeTestImpl::GetAndroidHostToolsDir() { - return GetAndroidToolsDir("prebuilts/gcc/linux-x86/host", - "x86_64-linux-glibc2.15", - "x86_64-linux"); -} - std::string CommonRuntimeTestImpl::GetAndroidTargetToolsDir(InstructionSet isa) { switch (isa) { case InstructionSet::kArm: @@ -297,38 +117,8 @@ std::string CommonRuntimeTestImpl::GetAndroidTargetToolsDir(InstructionSet isa) return ""; } -std::string CommonRuntimeTestImpl::GetCoreArtLocation() { - return GetCoreFileLocation("art"); -} - -std::string CommonRuntimeTestImpl::GetCoreOatLocation() { - return GetCoreFileLocation("oat"); -} - -std::unique_ptr<const DexFile> CommonRuntimeTestImpl::LoadExpectSingleDexFile( - const char* location) { - std::vector<std::unique_ptr<const DexFile>> dex_files; - std::string error_msg; - MemMap::Init(); - static constexpr bool kVerifyChecksum = true; - const ArtDexFileLoader dex_file_loader; - if (!dex_file_loader.Open( - location, location, /* verify */ true, kVerifyChecksum, &error_msg, &dex_files)) { - LOG(FATAL) << "Could not open .dex file '" << location << "': " << error_msg << "\n"; - UNREACHABLE(); - } else { - CHECK_EQ(1U, dex_files.size()) << "Expected only one dex file in " << location; - return std::move(dex_files[0]); - } -} - void CommonRuntimeTestImpl::SetUp() { - SetUpAndroidRoot(); - SetUpAndroidData(android_data_); - dalvik_cache_.append(android_data_.c_str()); - dalvik_cache_.append("/dalvik-cache"); - int mkdir_result = mkdir(dalvik_cache_.c_str(), 0700); - ASSERT_EQ(mkdir_result, 0); + CommonArtTestImpl::SetUp(); std::string min_heap_string(StringPrintf("-Xms%zdm", gc::Heap::kDefaultInitialSize / MB)); std::string max_heap_string(StringPrintf("-Xmx%zdm", gc::Heap::kDefaultMaximumSize / MB)); @@ -406,80 +196,13 @@ void CommonRuntimeTestImpl::FinalizeSetup() { runtime_->GetHeap()->SetMinIntervalHomogeneousSpaceCompactionByOom(0U); } -void CommonRuntimeTestImpl::ClearDirectory(const char* dirpath, bool recursive) { - ASSERT_TRUE(dirpath != nullptr); - DIR* dir = opendir(dirpath); - ASSERT_TRUE(dir != nullptr); - dirent* e; - struct stat s; - while ((e = readdir(dir)) != nullptr) { - if ((strcmp(e->d_name, ".") == 0) || (strcmp(e->d_name, "..") == 0)) { - continue; - } - std::string filename(dirpath); - filename.push_back('/'); - filename.append(e->d_name); - int stat_result = lstat(filename.c_str(), &s); - ASSERT_EQ(0, stat_result) << "unable to stat " << filename; - if (S_ISDIR(s.st_mode)) { - if (recursive) { - ClearDirectory(filename.c_str()); - int rmdir_result = rmdir(filename.c_str()); - ASSERT_EQ(0, rmdir_result) << filename; - } - } else { - int unlink_result = unlink(filename.c_str()); - ASSERT_EQ(0, unlink_result) << filename; - } - } - closedir(dir); -} - void CommonRuntimeTestImpl::TearDown() { - const char* android_data = getenv("ANDROID_DATA"); - ASSERT_TRUE(android_data != nullptr); - ClearDirectory(dalvik_cache_.c_str()); - int rmdir_cache_result = rmdir(dalvik_cache_.c_str()); - ASSERT_EQ(0, rmdir_cache_result); - TearDownAndroidData(android_data_, true); - dalvik_cache_.clear(); - + CommonArtTestImpl::TearDown(); if (runtime_ != nullptr) { runtime_->GetHeap()->VerifyHeap(); // Check for heap corruption after the test } } -static std::string GetDexFileName(const std::string& jar_prefix, bool host) { - std::string path; - if (host) { - const char* host_dir = getenv("ANDROID_HOST_OUT"); - CHECK(host_dir != nullptr); - path = host_dir; - } else { - path = GetAndroidRoot(); - } - - std::string suffix = host - ? "-hostdex" // The host version. - : "-testdex"; // The unstripped target version. - - return StringPrintf("%s/framework/%s%s.jar", path.c_str(), jar_prefix.c_str(), suffix.c_str()); -} - -std::vector<std::string> CommonRuntimeTestImpl::GetLibCoreDexFileNames() { - return std::vector<std::string>({GetDexFileName("core-oj", IsHost()), - GetDexFileName("core-libart", IsHost())}); -} - -std::string CommonRuntimeTestImpl::GetTestAndroidRoot() { - if (IsHost()) { - const char* host_dir = getenv("ANDROID_HOST_OUT"); - CHECK(host_dir != nullptr); - return host_dir; - } - return GetAndroidRoot(); -} - // Check that for target builds we have ART_TARGET_NATIVETEST_DIR set. #ifdef ART_TARGET #ifndef ART_TARGET_NATIVETEST_DIR @@ -491,47 +214,6 @@ std::string CommonRuntimeTestImpl::GetTestAndroidRoot() { #define ART_TARGET_NATIVETEST_DIR_STRING "" #endif -std::string CommonRuntimeTestImpl::GetTestDexFileName(const char* name) const { - CHECK(name != nullptr); - std::string filename; - if (IsHost()) { - filename += getenv("ANDROID_HOST_OUT"); - filename += "/framework/"; - } else { - filename += ART_TARGET_NATIVETEST_DIR_STRING; - } - filename += "art-gtest-"; - filename += name; - filename += ".jar"; - return filename; -} - -std::vector<std::unique_ptr<const DexFile>> CommonRuntimeTestImpl::OpenTestDexFiles( - const char* name) { - std::string filename = GetTestDexFileName(name); - 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, - kVerifyChecksum, - &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()); - CHECK(dex_file->IsReadOnly()); - } - return dex_files; -} - -std::unique_ptr<const DexFile> CommonRuntimeTestImpl::OpenTestDexFile(const char* name) { - std::vector<std::unique_ptr<const DexFile>> vector = OpenTestDexFiles(name); - EXPECT_EQ(1U, vector.size()); - return std::move(vector[0]); -} - std::vector<const DexFile*> CommonRuntimeTestImpl::GetDexFiles(jobject jclass_loader) { ScopedObjectAccess soa(Thread::Current()); @@ -658,43 +340,6 @@ jobject CommonRuntimeTestImpl::LoadDexInDelegateLastClassLoader(const std::strin parent_loader); } -std::string CommonRuntimeTestImpl::GetCoreFileLocation(const char* suffix) { - CHECK(suffix != nullptr); - - std::string location; - if (IsHost()) { - const char* host_dir = getenv("ANDROID_HOST_OUT"); - CHECK(host_dir != nullptr); - location = StringPrintf("%s/framework/core.%s", host_dir, suffix); - } else { - location = StringPrintf("/data/art-test/core.%s", suffix); - } - - return location; -} - -std::string CommonRuntimeTestImpl::CreateClassPath( - const std::vector<std::unique_ptr<const DexFile>>& dex_files) { - CHECK(!dex_files.empty()); - std::string classpath = dex_files[0]->GetLocation(); - for (size_t i = 1; i < dex_files.size(); i++) { - classpath += ":" + dex_files[i]->GetLocation(); - } - return classpath; -} - -std::string CommonRuntimeTestImpl::CreateClassPathWithChecksums( - const std::vector<std::unique_ptr<const DexFile>>& dex_files) { - CHECK(!dex_files.empty()); - std::string classpath = dex_files[0]->GetLocation() + "*" + - std::to_string(dex_files[0]->GetLocationChecksum()); - for (size_t i = 1; i < dex_files.size(); i++) { - classpath += ":" + dex_files[i]->GetLocation() + "*" + - std::to_string(dex_files[i]->GetLocationChecksum()); - } - return classpath; -} - void CommonRuntimeTestImpl::FillHeap(Thread* self, ClassLinker* class_linker, VariableSizedHandleScope* handle_scope) { diff --git a/runtime/common_runtime_test.h b/runtime/common_runtime_test.h index 186b1cd509..892abb4dbb 100644 --- a/runtime/common_runtime_test.h +++ b/runtime/common_runtime_test.h @@ -25,6 +25,7 @@ #include <android-base/logging.h> #include "arch/instruction_set.h" +#include "base/common_art_test.h" #include "base/globals.h" #include "base/mutex.h" #include "base/os.h" @@ -55,64 +56,13 @@ typedef std::vector<std::pair<std::string, const void*>> RuntimeOptions; class Thread; class VariableSizedHandleScope; -class ScratchFile { - public: - ScratchFile(); - - explicit ScratchFile(const std::string& filename); - - ScratchFile(const ScratchFile& other, const char* suffix); - - ScratchFile(ScratchFile&& other); - - ScratchFile& operator=(ScratchFile&& other); - - explicit ScratchFile(File* file); - - ~ScratchFile(); - - const std::string& GetFilename() const { - return filename_; - } - - File* GetFile() const { - return file_.get(); - } - - int GetFd() const; - - void Close(); - void Unlink(); - - private: - std::string filename_; - std::unique_ptr<File> file_; -}; - -class CommonRuntimeTestImpl { +class CommonRuntimeTestImpl : public CommonArtTestImpl { public: CommonRuntimeTestImpl(); virtual ~CommonRuntimeTestImpl(); - static void SetUpAndroidRoot(); - - // Note: setting up ANDROID_DATA may create a temporary directory. If this is used in a - // non-derived class, be sure to also call the corresponding tear-down below. - static void SetUpAndroidData(std::string& android_data); - - static void TearDownAndroidData(const std::string& android_data, bool fail_on_error); - - // Gets the paths of the libcore dex files. - static std::vector<std::string> GetLibCoreDexFileNames(); - // Returns bin directory which contains host's prebuild tools. - static std::string GetAndroidHostToolsDir(); - - // Returns bin directory which contains target's prebuild tools. static std::string GetAndroidTargetToolsDir(InstructionSet isa); - // Retuerns the filename for a test dex (i.e. XandY or ManyMethods). - std::string GetTestDexFileName(const char* name) const; - // A helper function to fill the heap. static void FillHeap(Thread* self, ClassLinker* class_linker, @@ -157,26 +107,6 @@ class CommonRuntimeTestImpl { // Called after the runtime is created. virtual void PostRuntimeCreate() {} - static bool IsHost() { - return !kIsTargetBuild; - } - - // File location to core.art, e.g. $ANDROID_HOST_OUT/system/framework/core.art - static std::string GetCoreArtLocation(); - - // File location to core.oat, e.g. $ANDROID_HOST_OUT/system/framework/core.oat - static std::string GetCoreOatLocation(); - - std::unique_ptr<const DexFile> LoadExpectSingleDexFile(const char* location); - - void ClearDirectory(const char* dirpath, bool recursive = true); - - std::string GetTestAndroidRoot(); - - std::vector<std::unique_ptr<const DexFile>> OpenTestDexFiles(const char* name); - - std::unique_ptr<const DexFile> OpenTestDexFile(const char* name); - // Loads the test dex file identified by the given dex_name into a PathClassLoader. // Returns the created class loader. jobject LoadDex(const char* dex_name) REQUIRES_SHARED(Locks::mutator_lock_); @@ -191,9 +121,6 @@ class CommonRuntimeTestImpl { jclass loader_class, jobject parent_loader); - std::string android_data_; - std::string dalvik_cache_; - std::unique_ptr<Runtime> runtime_; // The class_linker_, java_lang_dex_file_, and boot_class_path_ are all @@ -221,20 +148,6 @@ class CommonRuntimeTestImpl { // Called to finish up runtime creation and filling test fields. By default runs root // initializers, initialize well-known classes, and creates the heap thread pool. virtual void FinalizeSetup(); - - // Creates the class path string for the given dex files (the list of dex file locations - // separated by ':'). - std::string CreateClassPath( - const std::vector<std::unique_ptr<const DexFile>>& dex_files); - // Same as CreateClassPath but add the dex file checksum after each location. The separator - // is '*'. - std::string CreateClassPathWithChecksums( - const std::vector<std::unique_ptr<const DexFile>>& dex_files); - - private: - static std::string GetCoreFileLocation(const char* suffix); - - std::vector<std::unique_ptr<const DexFile>> loaded_dex_files_; }; template <typename TestType> @@ -278,12 +191,6 @@ class CheckJniAbortCatcher { DISALLOW_COPY_AND_ASSIGN(CheckJniAbortCatcher); }; -#define TEST_DISABLED_FOR_TARGET() \ - if (kIsTargetBuild) { \ - printf("WARNING: TEST DISABLED FOR TARGET\n"); \ - return; \ - } - #define TEST_DISABLED_FOR_MIPS() \ if (kRuntimeISA == InstructionSet::kMips) { \ printf("WARNING: TEST DISABLED FOR MIPS\n"); \ @@ -308,30 +215,6 @@ class CheckJniAbortCatcher { return; \ } -#define TEST_DISABLED_FOR_NON_STATIC_HOST_BUILDS() \ - if (!kHostStaticBuildEnabled) { \ - printf("WARNING: TEST DISABLED FOR NON-STATIC HOST BUILDS\n"); \ - return; \ - } - -#define TEST_DISABLED_FOR_MEMORY_TOOL() \ - if (RUNNING_ON_MEMORY_TOOL > 0) { \ - printf("WARNING: TEST DISABLED FOR MEMORY TOOL\n"); \ - return; \ - } - -#define TEST_DISABLED_FOR_MEMORY_TOOL_VALGRIND() \ - if (RUNNING_ON_MEMORY_TOOL > 0 && kMemoryToolIsValgrind) { \ - printf("WARNING: TEST DISABLED FOR MEMORY TOOL VALGRIND\n"); \ - return; \ - } - -#define TEST_DISABLED_FOR_MEMORY_TOOL_ASAN() \ - if (RUNNING_ON_MEMORY_TOOL > 0 && !kMemoryToolIsValgrind) { \ - printf("WARNING: TEST DISABLED FOR MEMORY TOOL ASAN\n"); \ - return; \ - } - #define TEST_DISABLED_FOR_HEAP_POISONING() \ if (kPoisonHeapReferences) { \ printf("WARNING: TEST DISABLED FOR HEAP POISONING\n"); \ diff --git a/runtime/dex/art_dex_file_loader_test.cc b/runtime/dex/art_dex_file_loader_test.cc index afc2599ea0..aee397b65b 100644 --- a/runtime/dex/art_dex_file_loader_test.cc +++ b/runtime/dex/art_dex_file_loader_test.cc @@ -353,7 +353,7 @@ TEST_F(ArtDexFileLoaderTest, IsPlatformDexFile) { /* verify_checksum */ false, &error_msg, &dex_files); - ASSERT_TRUE(success); + ASSERT_TRUE(success) << error_msg; ASSERT_GE(dex_files.size(), 1u); for (std::unique_ptr<const DexFile>& dex_file : dex_files) { ASSERT_FALSE(dex_file->IsPlatformDexFile()); diff --git a/test/Android.bp b/test/Android.bp index 16d14cdf30..0c6b449877 100644 --- a/test/Android.bp +++ b/test/Android.bp @@ -148,6 +148,7 @@ art_cc_library { whole_static_libs: [ "libart-compiler-gtest", "libart-runtime-gtest", + "libartbase-art-gtest", "libgtest", ], shared_libs: [ |