common_runtime_test.cc revision c7d4a5889085de271130c1ebeb83f96881195124
1eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughes/* 2eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughes * Copyright (C) 2012 The Android Open Source Project 3eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughes * 4eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughes * Licensed under the Apache License, Version 2.0 (the "License"); 5eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughes * you may not use this file except in compliance with the License. 6eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughes * You may obtain a copy of the License at 7eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughes * 8eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughes * http://www.apache.org/licenses/LICENSE-2.0 9eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughes * 10eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughes * Unless required by applicable law or agreed to in writing, software 11eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughes * distributed under the License is distributed on an "AS IS" BASIS, 12eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughes * See the License for the specific language governing permissions and 14eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughes * limitations under the License. 15eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughes */ 16eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughes 17e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "common_runtime_test.h" 18e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 193e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky#include <cstdio> 20e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include <dirent.h> 21e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include <dlfcn.h> 22e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include <fcntl.h> 23e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include <ScopedLocalRef.h> 24369810a98e6394b6dd162f5349e38a1f597b3bc7Andreas Gampe#include <stdlib.h> 25e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 26e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "../../external/icu/icu4c/source/common/unicode/uvernum.h" 27e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier#include "art_field-inl.h" 281fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe#include "base/macros.h" 2907ed66b5ae659c452cbe1ab20c3dbf1d6f546461Elliott Hughes#include "base/logging.h" 30e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "base/stl_util.h" 31e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "base/stringprintf.h" 32e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "base/unix_file/fd_file.h" 33e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "class_linker.h" 34e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "compiler_callbacks.h" 35e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier#include "dex_file-inl.h" 3694f7b49578b6aaa80de8ffed230648d601393905Hiroshi Yamauchi#include "gc_root-inl.h" 37e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "gc/heap.h" 38eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughes#include "gtest/gtest.h" 3981c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe#include "handle_scope-inl.h" 409b5cba401aae6d34450112bdcf9bab5e19da90f2Andreas Gampe#include "interpreter/unstarted_runtime.h" 41e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "jni_internal.h" 42e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier#include "mirror/class-inl.h" 43e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "mirror/class_loader.h" 4466d874d96d5699bb090c59f47a5a528956ca053eRichard Uhler#include "mem_map.h" 45e58991b3b2282b5761f1a6023a16c803e1c4eb45Mathieu Chartier#include "native/dalvik_system_DexFile.h" 46e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "noop_compiler_callbacks.h" 47e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "os.h" 48e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier#include "primitive.h" 49e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "runtime-inl.h" 50e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "scoped_thread_state_change.h" 51e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "thread.h" 52e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "well_known_classes.h" 53eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughes 54eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughesint main(int argc, char **argv) { 55369810a98e6394b6dd162f5349e38a1f597b3bc7Andreas Gampe // Gtests can be very noisy. For example, an executable with multiple tests will trigger native 56369810a98e6394b6dd162f5349e38a1f597b3bc7Andreas Gampe // bridge warnings. The following line reduces the minimum log severity to ERROR and suppresses 57369810a98e6394b6dd162f5349e38a1f597b3bc7Andreas Gampe // everything else. In case you want to see all messages, comment out the line. 58a7a4759946d9f11c88dc108b2b6a9518ce9c1e18Nicolas Geoffray setenv("ANDROID_LOG_TAGS", "*:e", 1); 59369810a98e6394b6dd162f5349e38a1f597b3bc7Andreas Gampe 60eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughes art::InitLogging(argv); 61c7dd295a4e0cc1d15c0c96088e55a85389bade74Ian Rogers LOG(::art::INFO) << "Running main() from common_runtime_test.cc..."; 62eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughes testing::InitGoogleTest(&argc, argv); 63eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughes return RUN_ALL_TESTS(); 64eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughes} 65e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 66e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersnamespace art { 67e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 68e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian RogersScratchFile::ScratchFile() { 69e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // ANDROID_DATA needs to be set 70e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK_NE(static_cast<char*>(nullptr), getenv("ANDROID_DATA")) << 71e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers "Are you subclassing RuntimeTest?"; 72e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename_ = getenv("ANDROID_DATA"); 73e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename_ += "/TmpFile-XXXXXX"; 74e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers int fd = mkstemp(&filename_[0]); 75e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK_NE(-1, fd); 764303ba97313458491e038d78efa041d41cf7bb43Andreas Gampe file_.reset(new File(fd, GetFilename(), true)); 77e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 78e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 79e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian RogersScratchFile::ScratchFile(const ScratchFile& other, const char* suffix) { 80e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename_ = other.GetFilename(); 81e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename_ += suffix; 82e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers int fd = open(filename_.c_str(), O_RDWR | O_CREAT, 0666); 83e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK_NE(-1, fd); 844303ba97313458491e038d78efa041d41cf7bb43Andreas Gampe file_.reset(new File(fd, GetFilename(), true)); 85e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 86e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 87e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian RogersScratchFile::ScratchFile(File* file) { 882cebb24bfc3247d3e9be138a3350106737455918Mathieu Chartier CHECK(file != nullptr); 89e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename_ = file->GetPath(); 90e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers file_.reset(file); 91e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 92e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 93e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian RogersScratchFile::~ScratchFile() { 94e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers Unlink(); 95e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 96e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 97e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersint ScratchFile::GetFd() const { 98e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers return file_->Fd(); 99e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 100e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 101e21dc3db191df04c100620965bee4617b3b24397Andreas Gampevoid ScratchFile::Close() { 1024303ba97313458491e038d78efa041d41cf7bb43Andreas Gampe if (file_.get() != nullptr) { 1034303ba97313458491e038d78efa041d41cf7bb43Andreas Gampe if (file_->FlushCloseOrErase() != 0) { 1044303ba97313458491e038d78efa041d41cf7bb43Andreas Gampe PLOG(WARNING) << "Error closing scratch file."; 1054303ba97313458491e038d78efa041d41cf7bb43Andreas Gampe } 1064303ba97313458491e038d78efa041d41cf7bb43Andreas Gampe } 107e21dc3db191df04c100620965bee4617b3b24397Andreas Gampe} 108e21dc3db191df04c100620965bee4617b3b24397Andreas Gampe 109e21dc3db191df04c100620965bee4617b3b24397Andreas Gampevoid ScratchFile::Unlink() { 110e21dc3db191df04c100620965bee4617b3b24397Andreas Gampe if (!OS::FileExists(filename_.c_str())) { 111e21dc3db191df04c100620965bee4617b3b24397Andreas Gampe return; 112e21dc3db191df04c100620965bee4617b3b24397Andreas Gampe } 113e21dc3db191df04c100620965bee4617b3b24397Andreas Gampe Close(); 114e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers int unlink_result = unlink(filename_.c_str()); 115e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK_EQ(0, unlink_result); 116e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 117e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 1189b5cba401aae6d34450112bdcf9bab5e19da90f2Andreas Gampestatic bool unstarted_initialized_ = false; 1199b5cba401aae6d34450112bdcf9bab5e19da90f2Andreas Gampe 120e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian RogersCommonRuntimeTest::CommonRuntimeTest() {} 121fbef44de596d298dc6430f482dffc933a046dd28Richard UhlerCommonRuntimeTest::~CommonRuntimeTest() { 122fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler // Ensure the dex files are cleaned up before the runtime. 123fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler loaded_dex_files_.clear(); 124fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler runtime_.reset(); 125fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler} 126e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 1277747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampevoid CommonRuntimeTest::SetUpAndroidRoot() { 128e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers if (IsHost()) { 129e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // $ANDROID_ROOT is set on the device, but not necessarily on the host. 130e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // But it needs to be set so that icu4c can find its locale data. 131e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers const char* android_root_from_env = getenv("ANDROID_ROOT"); 132e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers if (android_root_from_env == nullptr) { 133e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // Use ANDROID_HOST_OUT for ANDROID_ROOT if it is set. 134e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers const char* android_host_out = getenv("ANDROID_HOST_OUT"); 135e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers if (android_host_out != nullptr) { 136e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers setenv("ANDROID_ROOT", android_host_out, 1); 137e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } else { 138e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // Build it from ANDROID_BUILD_TOP or cwd 139e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers std::string root; 140e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers const char* android_build_top = getenv("ANDROID_BUILD_TOP"); 141e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers if (android_build_top != nullptr) { 142e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers root += android_build_top; 143e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } else { 144e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // Not set by build server, so default to current directory 145e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers char* cwd = getcwd(nullptr, 0); 146e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers setenv("ANDROID_BUILD_TOP", cwd, 1); 147e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers root += cwd; 148e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers free(cwd); 149e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 150e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#if defined(__linux__) 151e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers root += "/out/host/linux-x86"; 152e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#elif defined(__APPLE__) 153e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers root += "/out/host/darwin-x86"; 154e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#else 155e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#error unsupported OS 156e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#endif 157e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers setenv("ANDROID_ROOT", root.c_str(), 1); 158e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 159e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 160e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers setenv("LD_LIBRARY_PATH", ":", 0); // Required by java.lang.System.<clinit>. 161e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 162e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // Not set by build server, so default 163e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers if (getenv("ANDROID_HOST_OUT") == nullptr) { 164e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers setenv("ANDROID_HOST_OUT", getenv("ANDROID_ROOT"), 1); 165e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 166e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 1677747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe} 168e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 1697747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampevoid CommonRuntimeTest::SetUpAndroidData(std::string& android_data) { 170e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // On target, Cannot use /mnt/sdcard because it is mounted noexec, so use subdir of dalvik-cache 1715a79fdecffbea657ebecd4cf19078925239eb1c3Andreas Gampe if (IsHost()) { 1725a79fdecffbea657ebecd4cf19078925239eb1c3Andreas Gampe const char* tmpdir = getenv("TMPDIR"); 1735a79fdecffbea657ebecd4cf19078925239eb1c3Andreas Gampe if (tmpdir != nullptr && tmpdir[0] != 0) { 1745a79fdecffbea657ebecd4cf19078925239eb1c3Andreas Gampe android_data = tmpdir; 1755a79fdecffbea657ebecd4cf19078925239eb1c3Andreas Gampe } else { 1765a79fdecffbea657ebecd4cf19078925239eb1c3Andreas Gampe android_data = "/tmp"; 1775a79fdecffbea657ebecd4cf19078925239eb1c3Andreas Gampe } 1785a79fdecffbea657ebecd4cf19078925239eb1c3Andreas Gampe } else { 1795a79fdecffbea657ebecd4cf19078925239eb1c3Andreas Gampe android_data = "/data/dalvik-cache"; 1805a79fdecffbea657ebecd4cf19078925239eb1c3Andreas Gampe } 1815a79fdecffbea657ebecd4cf19078925239eb1c3Andreas Gampe android_data += "/art-data-XXXXXX"; 182e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers if (mkdtemp(&android_data[0]) == nullptr) { 183e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers PLOG(FATAL) << "mkdtemp(\"" << &android_data[0] << "\") failed"; 184e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 185e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers setenv("ANDROID_DATA", android_data.c_str(), 1); 186e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 187e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 1887747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampevoid CommonRuntimeTest::TearDownAndroidData(const std::string& android_data, bool fail_on_error) { 1897747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe if (fail_on_error) { 1907747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe ASSERT_EQ(rmdir(android_data.c_str()), 0); 1917747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe } else { 1927747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe rmdir(android_data.c_str()); 1937747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe } 1947747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe} 1957747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe 1963e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky// Helper - find directory with the following format: 1973e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky// ${ANDROID_BUILD_TOP}/${subdir1}/${subdir2}-${version}/${subdir3}/bin/ 1983e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbeckystatic std::string GetAndroidToolsDir(const std::string& subdir1, 1993e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky const std::string& subdir2, 2003e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky const std::string& subdir3) { 2013e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky std::string root; 2023e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky const char* android_build_top = getenv("ANDROID_BUILD_TOP"); 2033e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky if (android_build_top != nullptr) { 2043e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky root = android_build_top; 2053e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky } else { 2063e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky // Not set by build server, so default to current directory 2073e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky char* cwd = getcwd(nullptr, 0); 2083e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky setenv("ANDROID_BUILD_TOP", cwd, 1); 2093e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky root = cwd; 2103e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky free(cwd); 2113e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky } 2123e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky 2133e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky std::string toolsdir = root + "/" + subdir1; 2143e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky std::string founddir; 2153e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky DIR* dir; 2163e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky if ((dir = opendir(toolsdir.c_str())) != nullptr) { 2173e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky float maxversion = 0; 2183e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky struct dirent* entry; 2193e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky while ((entry = readdir(dir)) != nullptr) { 2203e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky std::string format = subdir2 + "-%f"; 2213e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky float version; 2223e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky if (std::sscanf(entry->d_name, format.c_str(), &version) == 1) { 2233e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky if (version > maxversion) { 2243e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky maxversion = version; 2253e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky founddir = toolsdir + "/" + entry->d_name + "/" + subdir3 + "/bin/"; 2263e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky } 2273e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky } 2283e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky } 2293e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky closedir(dir); 2303e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky } 2313e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky 2323e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky if (founddir.empty()) { 2333e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky ADD_FAILURE() << "Can not find Android tools directory."; 2343e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky } 2353e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky return founddir; 2363e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky} 2373e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky 2383e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbeckystd::string CommonRuntimeTest::GetAndroidHostToolsDir() { 2393e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky return GetAndroidToolsDir("prebuilts/gcc/linux-x86/host", 2403e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky "x86_64-linux-glibc2.15", 2413e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky "x86_64-linux"); 2423e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky} 2433e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky 2443e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbeckystd::string CommonRuntimeTest::GetAndroidTargetToolsDir(InstructionSet isa) { 2453e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky switch (isa) { 2463e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky case kArm: 2473e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky case kThumb2: 2483e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky return GetAndroidToolsDir("prebuilts/gcc/linux-x86/arm", 2493e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky "arm-linux-androideabi", 2503e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky "arm-linux-androideabi"); 2513e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky case kArm64: 2523e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky return GetAndroidToolsDir("prebuilts/gcc/linux-x86/aarch64", 2533e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky "aarch64-linux-android", 2543e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky "aarch64-linux-android"); 2553e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky case kX86: 2563e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky case kX86_64: 2573e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky return GetAndroidToolsDir("prebuilts/gcc/linux-x86/x86", 2583e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky "x86_64-linux-android", 2593e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky "x86_64-linux-android"); 2603e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky case kMips: 2613e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky case kMips64: 2623e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky return GetAndroidToolsDir("prebuilts/gcc/linux-x86/mips", 2633e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky "mips64el-linux-android", 2643e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky "mips64el-linux-android"); 2653e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky case kNone: 2663e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky break; 2673e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky } 2683e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky ADD_FAILURE() << "Invalid isa " << isa; 2693e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky return ""; 2703e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky} 2713e52aa4d406fe802dabee2a2e7ba8764cc13aaaaDavid Srbecky 2723774335b08076117d6950cd472cdd59a167470b5Igor Murashkinstd::string CommonRuntimeTest::GetCoreArtLocation() { 2733774335b08076117d6950cd472cdd59a167470b5Igor Murashkin return GetCoreFileLocation("art"); 2743774335b08076117d6950cd472cdd59a167470b5Igor Murashkin} 2753774335b08076117d6950cd472cdd59a167470b5Igor Murashkin 2763774335b08076117d6950cd472cdd59a167470b5Igor Murashkinstd::string CommonRuntimeTest::GetCoreOatLocation() { 2773774335b08076117d6950cd472cdd59a167470b5Igor Murashkin return GetCoreFileLocation("oat"); 2783774335b08076117d6950cd472cdd59a167470b5Igor Murashkin} 2797747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe 280fbef44de596d298dc6430f482dffc933a046dd28Richard Uhlerstd::unique_ptr<const DexFile> CommonRuntimeTest::LoadExpectSingleDexFile(const char* location) { 281fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler std::vector<std::unique_ptr<const DexFile>> dex_files; 282e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers std::string error_msg; 28366d874d96d5699bb090c59f47a5a528956ca053eRichard Uhler MemMap::Init(); 284e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers if (!DexFile::Open(location, location, &error_msg, &dex_files)) { 285e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers LOG(FATAL) << "Could not open .dex file '" << location << "': " << error_msg << "\n"; 286fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler UNREACHABLE(); 287e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } else { 288e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK_EQ(1U, dex_files.size()) << "Expected only one dex file in " << location; 289fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler return std::move(dex_files[0]); 290e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 291e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 292e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 293e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersvoid CommonRuntimeTest::SetUp() { 2947747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe SetUpAndroidRoot(); 2957747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe SetUpAndroidData(android_data_); 296e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers dalvik_cache_.append(android_data_.c_str()); 297e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers dalvik_cache_.append("/dalvik-cache"); 298e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers int mkdir_result = mkdir(dalvik_cache_.c_str(), 0700); 299e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers ASSERT_EQ(mkdir_result, 0); 300e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 301e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers std::string min_heap_string(StringPrintf("-Xms%zdm", gc::Heap::kDefaultInitialSize / MB)); 302e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers std::string max_heap_string(StringPrintf("-Xmx%zdm", gc::Heap::kDefaultMaximumSize / MB)); 303e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 304e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 305e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers RuntimeOptions options; 306d1ef4362bf799f9f5d50e5edef8433664b503051Narayan Kamath std::string boot_class_path_string = "-Xbootclasspath"; 3075b8e6e36e96d6d1921dd356fa46191d1e6a18082Przemyslaw Szczepaniak for (const std::string &core_dex_file_name : GetLibCoreDexFileNames()) { 308d1ef4362bf799f9f5d50e5edef8433664b503051Narayan Kamath boot_class_path_string += ":"; 309d1ef4362bf799f9f5d50e5edef8433664b503051Narayan Kamath boot_class_path_string += core_dex_file_name; 3105b8e6e36e96d6d1921dd356fa46191d1e6a18082Przemyslaw Szczepaniak } 311e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 312c275259449ec57987e52d3ab1eda3272b994488fRichard Uhler options.push_back(std::make_pair(boot_class_path_string, nullptr)); 313e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers options.push_back(std::make_pair("-Xcheck:jni", nullptr)); 314c275259449ec57987e52d3ab1eda3272b994488fRichard Uhler options.push_back(std::make_pair(min_heap_string, nullptr)); 315c275259449ec57987e52d3ab1eda3272b994488fRichard Uhler options.push_back(std::make_pair(max_heap_string, nullptr)); 316bb9c6b1c55e9e2308b4f5892a398a8837231fdbdAndreas Gampe 317bb9c6b1c55e9e2308b4f5892a398a8837231fdbdAndreas Gampe callbacks_.reset(new NoopCompilerCallbacks()); 318bb9c6b1c55e9e2308b4f5892a398a8837231fdbdAndreas Gampe 319e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers SetUpRuntimeOptions(&options); 320aaebaa0121be3b9d9f13630585304482cbcaeb4bIgor Murashkin 321bb9c6b1c55e9e2308b4f5892a398a8837231fdbdAndreas Gampe // Install compiler-callbacks if SetupRuntimeOptions hasn't deleted them. 322bb9c6b1c55e9e2308b4f5892a398a8837231fdbdAndreas Gampe if (callbacks_.get() != nullptr) { 323bb9c6b1c55e9e2308b4f5892a398a8837231fdbdAndreas Gampe options.push_back(std::make_pair("compilercallbacks", callbacks_.get())); 324bb9c6b1c55e9e2308b4f5892a398a8837231fdbdAndreas Gampe } 325bb9c6b1c55e9e2308b4f5892a398a8837231fdbdAndreas Gampe 32666d874d96d5699bb090c59f47a5a528956ca053eRichard Uhler PreRuntimeCreate(); 327e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers if (!Runtime::Create(options, false)) { 328e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers LOG(FATAL) << "Failed to create runtime"; 329e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers return; 330e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 33166d874d96d5699bb090c59f47a5a528956ca053eRichard Uhler PostRuntimeCreate(); 332e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers runtime_.reset(Runtime::Current()); 333e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers class_linker_ = runtime_->GetClassLinker(); 334e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers class_linker_->FixupDexCaches(runtime_->GetResolutionMethod()); 3352969bcdcd80624e4a4fef696b54c2c76b44b6853Andreas Gampe 336a00f012660e9a4baa34c0ab96042f7146e9a6017Andreas Gampe // Runtime::Create acquired the mutator_lock_ that is normally given away when we 337a00f012660e9a4baa34c0ab96042f7146e9a6017Andreas Gampe // Runtime::Start, give it away now and then switch to a more managable ScopedObjectAccess. 338a00f012660e9a4baa34c0ab96042f7146e9a6017Andreas Gampe Thread::Current()->TransitionFromRunnableToSuspended(kNative); 339a00f012660e9a4baa34c0ab96042f7146e9a6017Andreas Gampe 340a00f012660e9a4baa34c0ab96042f7146e9a6017Andreas Gampe // Get the boot class path from the runtime so it can be used in tests. 341a00f012660e9a4baa34c0ab96042f7146e9a6017Andreas Gampe boot_class_path_ = class_linker_->GetBootClassPath(); 342a00f012660e9a4baa34c0ab96042f7146e9a6017Andreas Gampe ASSERT_FALSE(boot_class_path_.empty()); 343a00f012660e9a4baa34c0ab96042f7146e9a6017Andreas Gampe java_lang_dex_file_ = boot_class_path_[0]; 344a00f012660e9a4baa34c0ab96042f7146e9a6017Andreas Gampe 345a00f012660e9a4baa34c0ab96042f7146e9a6017Andreas Gampe FinalizeSetup(); 346a00f012660e9a4baa34c0ab96042f7146e9a6017Andreas Gampe} 347a00f012660e9a4baa34c0ab96042f7146e9a6017Andreas Gampe 348a00f012660e9a4baa34c0ab96042f7146e9a6017Andreas Gampevoid CommonRuntimeTest::FinalizeSetup() { 3492969bcdcd80624e4a4fef696b54c2c76b44b6853Andreas Gampe // Initialize maps for unstarted runtime. This needs to be here, as running clinits needs this 3502969bcdcd80624e4a4fef696b54c2c76b44b6853Andreas Gampe // set up. 3519b5cba401aae6d34450112bdcf9bab5e19da90f2Andreas Gampe if (!unstarted_initialized_) { 352799681b176ad25437ce2849639f54f610dcbf684Andreas Gampe interpreter::UnstartedRuntime::Initialize(); 3539b5cba401aae6d34450112bdcf9bab5e19da90f2Andreas Gampe unstarted_initialized_ = true; 3549b5cba401aae6d34450112bdcf9bab5e19da90f2Andreas Gampe } 3552969bcdcd80624e4a4fef696b54c2c76b44b6853Andreas Gampe 356a00f012660e9a4baa34c0ab96042f7146e9a6017Andreas Gampe { 357a00f012660e9a4baa34c0ab96042f7146e9a6017Andreas Gampe ScopedObjectAccess soa(Thread::Current()); 358a00f012660e9a4baa34c0ab96042f7146e9a6017Andreas Gampe class_linker_->RunRootClinits(); 359a00f012660e9a4baa34c0ab96042f7146e9a6017Andreas Gampe } 360e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 361e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // We're back in native, take the opportunity to initialize well known classes. 362e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers WellKnownClasses::Init(Thread::Current()->GetJniEnv()); 363e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 364e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // Create the heap thread pool so that the GC runs in parallel for tests. Normally, the thread 365e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // pool is created by the runtime. 366e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers runtime_->GetHeap()->CreateThreadPool(); 367e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers runtime_->GetHeap()->VerifyHeap(); // Check for heap corruption before the test 3684460a84be92b5a94ecfb5c650aef4945ab849c93Hiroshi Yamauchi // Reduce timinig-dependent flakiness in OOME behavior (eg StubTest.AllocObject). 3694460a84be92b5a94ecfb5c650aef4945ab849c93Hiroshi Yamauchi runtime_->GetHeap()->SetMinIntervalHomogeneousSpaceCompactionByOom(0U); 370e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 371e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 372a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Lightvoid CommonRuntimeTest::ClearDirectory(const char* dirpath) { 373a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light ASSERT_TRUE(dirpath != nullptr); 374a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light DIR* dir = opendir(dirpath); 375e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers ASSERT_TRUE(dir != nullptr); 376e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers dirent* e; 377a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light struct stat s; 378e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers while ((e = readdir(dir)) != nullptr) { 379e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers if ((strcmp(e->d_name, ".") == 0) || (strcmp(e->d_name, "..") == 0)) { 380e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers continue; 381e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 382f0a3f09c3d54646166a55c05a6b39c7dd504129cJeff Hao std::string filename(dirpath); 383e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename.push_back('/'); 384e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename.append(e->d_name); 385a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light int stat_result = lstat(filename.c_str(), &s); 386a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light ASSERT_EQ(0, stat_result) << "unable to stat " << filename; 387a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light if (S_ISDIR(s.st_mode)) { 388a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light ClearDirectory(filename.c_str()); 389a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light int rmdir_result = rmdir(filename.c_str()); 390a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light ASSERT_EQ(0, rmdir_result) << filename; 391a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light } else { 392a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light int unlink_result = unlink(filename.c_str()); 393a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light ASSERT_EQ(0, unlink_result) << filename; 394a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light } 395e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 396e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers closedir(dir); 397a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light} 398a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light 399a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Lightvoid CommonRuntimeTest::TearDown() { 400a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light const char* android_data = getenv("ANDROID_DATA"); 401a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light ASSERT_TRUE(android_data != nullptr); 402a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light ClearDirectory(dalvik_cache_.c_str()); 403e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers int rmdir_cache_result = rmdir(dalvik_cache_.c_str()); 404e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers ASSERT_EQ(0, rmdir_cache_result); 4057747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe TearDownAndroidData(android_data_, true); 406e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 407e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // icu4c has a fixed 10-element array "gCommonICUDataArray". 408e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // If we run > 10 tests, we fill that array and u_setCommonData fails. 409e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // There's a function to clear the array, but it's not public... 410e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers typedef void (*IcuCleanupFn)(); 411e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers void* sym = dlsym(RTLD_DEFAULT, "u_cleanup_" U_ICU_VERSION_SHORT); 412e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK(sym != nullptr) << dlerror(); 413e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers IcuCleanupFn icu_cleanup_fn = reinterpret_cast<IcuCleanupFn>(sym); 414e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers (*icu_cleanup_fn)(); 415e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 416e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers Runtime::Current()->GetHeap()->VerifyHeap(); // Check for heap corruption after the test 417b8bce05ec116183bb72768039a0899a772439025Yi Kong 418b8bce05ec116183bb72768039a0899a772439025Yi Kong // Manually closing the JNI libraries. 419b8bce05ec116183bb72768039a0899a772439025Yi Kong // Runtime does not support repeatedly doing JNI->CreateVM, thus we need to manually clean up the 420b8bce05ec116183bb72768039a0899a772439025Yi Kong // dynamic linking loader so that gtests would not fail. 421b8bce05ec116183bb72768039a0899a772439025Yi Kong // Bug: 25785594 422b8bce05ec116183bb72768039a0899a772439025Yi Kong if (runtime_->IsStarted()) { 423b8bce05ec116183bb72768039a0899a772439025Yi Kong { 424b8bce05ec116183bb72768039a0899a772439025Yi Kong // We retrieve the handle by calling dlopen on the library. To close it, we need to call 425b8bce05ec116183bb72768039a0899a772439025Yi Kong // dlclose twice, the first time to undo our dlopen and the second time to actually unload it. 426b8bce05ec116183bb72768039a0899a772439025Yi Kong // See man dlopen. 427b8bce05ec116183bb72768039a0899a772439025Yi Kong void* handle = dlopen("libjavacore.so", RTLD_LAZY); 428b8bce05ec116183bb72768039a0899a772439025Yi Kong dlclose(handle); 429b8bce05ec116183bb72768039a0899a772439025Yi Kong CHECK_EQ(0, dlclose(handle)); 430b8bce05ec116183bb72768039a0899a772439025Yi Kong } 431b8bce05ec116183bb72768039a0899a772439025Yi Kong { 432b8bce05ec116183bb72768039a0899a772439025Yi Kong void* handle = dlopen("libopenjdk.so", RTLD_LAZY); 433b8bce05ec116183bb72768039a0899a772439025Yi Kong dlclose(handle); 434b8bce05ec116183bb72768039a0899a772439025Yi Kong CHECK_EQ(0, dlclose(handle)); 435b8bce05ec116183bb72768039a0899a772439025Yi Kong } 436b8bce05ec116183bb72768039a0899a772439025Yi Kong } 437e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 438e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 439c7d4a5889085de271130c1ebeb83f96881195124Andreas Gampestatic std::string GetDexFileName(const std::string& jar_prefix, bool host) { 440c7d4a5889085de271130c1ebeb83f96881195124Andreas Gampe std::string path; 441c7d4a5889085de271130c1ebeb83f96881195124Andreas Gampe if (host) { 442e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers const char* host_dir = getenv("ANDROID_HOST_OUT"); 443e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK(host_dir != nullptr); 444c7d4a5889085de271130c1ebeb83f96881195124Andreas Gampe path = host_dir; 445c7d4a5889085de271130c1ebeb83f96881195124Andreas Gampe } else { 446c7d4a5889085de271130c1ebeb83f96881195124Andreas Gampe path = GetAndroidRoot(); 447e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 448c7d4a5889085de271130c1ebeb83f96881195124Andreas Gampe 449c7d4a5889085de271130c1ebeb83f96881195124Andreas Gampe std::string suffix = host 450c7d4a5889085de271130c1ebeb83f96881195124Andreas Gampe ? "-hostdex" // The host version. 451c7d4a5889085de271130c1ebeb83f96881195124Andreas Gampe : "-testdex"; // The unstripped target version. 452c7d4a5889085de271130c1ebeb83f96881195124Andreas Gampe 453c7d4a5889085de271130c1ebeb83f96881195124Andreas Gampe return StringPrintf("%s/framework/%s%s.jar", path.c_str(), jar_prefix.c_str(), suffix.c_str()); 454c7d4a5889085de271130c1ebeb83f96881195124Andreas Gampe} 455c7d4a5889085de271130c1ebeb83f96881195124Andreas Gampe 456c7d4a5889085de271130c1ebeb83f96881195124Andreas Gampestd::vector<std::string> CommonRuntimeTest::GetLibCoreDexFileNames() { 457c7d4a5889085de271130c1ebeb83f96881195124Andreas Gampe return std::vector<std::string>({GetDexFileName("core-oj", IsHost()), 458c7d4a5889085de271130c1ebeb83f96881195124Andreas Gampe GetDexFileName("core-libart", IsHost())}); 459e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 460e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 461e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersstd::string CommonRuntimeTest::GetTestAndroidRoot() { 462e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers if (IsHost()) { 463e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers const char* host_dir = getenv("ANDROID_HOST_OUT"); 464e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK(host_dir != nullptr); 465e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers return host_dir; 466e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 467e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers return GetAndroidRoot(); 468e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 469e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 4701fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe// Check that for target builds we have ART_TARGET_NATIVETEST_DIR set. 4711fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe#ifdef ART_TARGET 4721fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe#ifndef ART_TARGET_NATIVETEST_DIR 4731fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe#error "ART_TARGET_NATIVETEST_DIR not set." 4741fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe#endif 4751fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe// Wrap it as a string literal. 4761fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe#define ART_TARGET_NATIVETEST_DIR_STRING STRINGIFY(ART_TARGET_NATIVETEST_DIR) "/" 4771fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe#else 4781fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe#define ART_TARGET_NATIVETEST_DIR_STRING "" 4791fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe#endif 4801fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe 48166d874d96d5699bb090c59f47a5a528956ca053eRichard Uhlerstd::string CommonRuntimeTest::GetTestDexFileName(const char* name) { 482e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK(name != nullptr); 483e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers std::string filename; 484e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers if (IsHost()) { 485e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename += getenv("ANDROID_HOST_OUT"); 486e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename += "/framework/"; 487e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } else { 4881fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe filename += ART_TARGET_NATIVETEST_DIR_STRING; 489e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 490e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename += "art-gtest-"; 491e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename += name; 492e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename += ".jar"; 49366d874d96d5699bb090c59f47a5a528956ca053eRichard Uhler return filename; 49466d874d96d5699bb090c59f47a5a528956ca053eRichard Uhler} 49566d874d96d5699bb090c59f47a5a528956ca053eRichard Uhler 49666d874d96d5699bb090c59f47a5a528956ca053eRichard Uhlerstd::vector<std::unique_ptr<const DexFile>> CommonRuntimeTest::OpenTestDexFiles(const char* name) { 49766d874d96d5699bb090c59f47a5a528956ca053eRichard Uhler std::string filename = GetTestDexFileName(name); 498e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers std::string error_msg; 499fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler std::vector<std::unique_ptr<const DexFile>> dex_files; 500e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers bool success = DexFile::Open(filename.c_str(), filename.c_str(), &error_msg, &dex_files); 501e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK(success) << "Failed to open '" << filename << "': " << error_msg; 502fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler for (auto& dex_file : dex_files) { 503e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK_EQ(PROT_READ, dex_file->GetPermissions()); 504e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK(dex_file->IsReadOnly()); 505e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 506e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers return dex_files; 507e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 508e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 509fbef44de596d298dc6430f482dffc933a046dd28Richard Uhlerstd::unique_ptr<const DexFile> CommonRuntimeTest::OpenTestDexFile(const char* name) { 510fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler std::vector<std::unique_ptr<const DexFile>> vector = OpenTestDexFiles(name); 511e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers EXPECT_EQ(1U, vector.size()); 512fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler return std::move(vector[0]); 513e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 514e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 51581c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampestd::vector<const DexFile*> CommonRuntimeTest::GetDexFiles(jobject jclass_loader) { 51681c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe std::vector<const DexFile*> ret; 51781c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe 51881c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe ScopedObjectAccess soa(Thread::Current()); 51981c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe 520c785344b87221f5e4e6473e5b762e4e61fe65dcfMathieu Chartier StackHandleScope<2> hs(soa.Self()); 52181c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe Handle<mirror::ClassLoader> class_loader = hs.NewHandle( 52281c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe soa.Decode<mirror::ClassLoader*>(jclass_loader)); 52381c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe 52481c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe DCHECK_EQ(class_loader->GetClass(), 52581c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe soa.Decode<mirror::Class*>(WellKnownClasses::dalvik_system_PathClassLoader)); 52681c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe DCHECK_EQ(class_loader->GetParent()->GetClass(), 52781c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe soa.Decode<mirror::Class*>(WellKnownClasses::java_lang_BootClassLoader)); 52881c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe 52981c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe // The class loader is a PathClassLoader which inherits from BaseDexClassLoader. 53081c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe // We need to get the DexPathList and loop through it. 531c785344b87221f5e4e6473e5b762e4e61fe65dcfMathieu Chartier ArtField* cookie_field = soa.DecodeField(WellKnownClasses::dalvik_system_DexFile_cookie); 532c785344b87221f5e4e6473e5b762e4e61fe65dcfMathieu Chartier ArtField* dex_file_field = 533c785344b87221f5e4e6473e5b762e4e61fe65dcfMathieu Chartier soa.DecodeField(WellKnownClasses::dalvik_system_DexPathList__Element_dexFile); 53481c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe mirror::Object* dex_path_list = 53581c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe soa.DecodeField(WellKnownClasses::dalvik_system_PathClassLoader_pathList)-> 53681c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe GetObject(class_loader.Get()); 537c785344b87221f5e4e6473e5b762e4e61fe65dcfMathieu Chartier if (dex_path_list != nullptr && dex_file_field!= nullptr && cookie_field != nullptr) { 53881c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe // DexPathList has an array dexElements of Elements[] which each contain a dex file. 53981c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe mirror::Object* dex_elements_obj = 54081c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe soa.DecodeField(WellKnownClasses::dalvik_system_DexPathList_dexElements)-> 54181c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe GetObject(dex_path_list); 54281c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe // Loop through each dalvik.system.DexPathList$Element's dalvik.system.DexFile and look 54381c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe // at the mCookie which is a DexFile vector. 54481c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe if (dex_elements_obj != nullptr) { 54581c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe Handle<mirror::ObjectArray<mirror::Object>> dex_elements = 54681c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe hs.NewHandle(dex_elements_obj->AsObjectArray<mirror::Object>()); 54781c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe for (int32_t i = 0; i < dex_elements->GetLength(); ++i) { 54881c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe mirror::Object* element = dex_elements->GetWithoutChecks(i); 54981c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe if (element == nullptr) { 55081c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe // Should never happen, fall back to java code to throw a NPE. 55181c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe break; 55281c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe } 55381c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe mirror::Object* dex_file = dex_file_field->GetObject(element); 55481c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe if (dex_file != nullptr) { 55581c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe mirror::LongArray* long_array = cookie_field->GetObject(dex_file)->AsLongArray(); 55681c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe DCHECK(long_array != nullptr); 55781c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe int32_t long_array_size = long_array->GetLength(); 558e58991b3b2282b5761f1a6023a16c803e1c4eb45Mathieu Chartier for (int32_t j = kDexFileIndexStart; j < long_array_size; ++j) { 55981c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe const DexFile* cp_dex_file = reinterpret_cast<const DexFile*>(static_cast<uintptr_t>( 56081c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe long_array->GetWithoutChecks(j))); 56181c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe if (cp_dex_file == nullptr) { 56281c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe LOG(WARNING) << "Null DexFile"; 56381c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe continue; 56481c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe } 56581c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe ret.push_back(cp_dex_file); 56681c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe } 56781c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe } 56881c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe } 56981c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe } 57081c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe } 57181c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe 57281c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe return ret; 57381c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe} 57481c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe 57581c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampeconst DexFile* CommonRuntimeTest::GetFirstDexFile(jobject jclass_loader) { 57681c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe std::vector<const DexFile*> tmp(GetDexFiles(jclass_loader)); 57781c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe DCHECK(!tmp.empty()); 57881c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe const DexFile* ret = tmp[0]; 57981c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe DCHECK(ret != nullptr); 58081c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe return ret; 58181c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe} 58281c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe 583e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersjobject CommonRuntimeTest::LoadDex(const char* dex_name) { 584fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler std::vector<std::unique_ptr<const DexFile>> dex_files = OpenTestDexFiles(dex_name); 585fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler std::vector<const DexFile*> class_path; 586e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK_NE(0U, dex_files.size()); 587fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler for (auto& dex_file : dex_files) { 588fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler class_path.push_back(dex_file.get()); 589fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler loaded_dex_files_.push_back(std::move(dex_file)); 590e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 59181c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe 59268d8b42ddec39ec0174162d90d4abaa004d1983eIan Rogers Thread* self = Thread::Current(); 593673ed3d8aedc5462a47ded827c99f35d46525457Mathieu Chartier jobject class_loader = Runtime::Current()->GetClassLinker()->CreatePathClassLoader(self, 594d37d364c27e74a7b49970a8c970482e273aa7b1aMathieu Chartier class_path, 595d37d364c27e74a7b49970a8c970482e273aa7b1aMathieu Chartier nullptr); 59681c6f8db12b203878a7d72444ead2bc7cf5c47adAndreas Gampe self->SetClassLoaderOverride(class_loader); 597e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers return class_loader; 598e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 599e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 6003774335b08076117d6950cd472cdd59a167470b5Igor Murashkinstd::string CommonRuntimeTest::GetCoreFileLocation(const char* suffix) { 6013774335b08076117d6950cd472cdd59a167470b5Igor Murashkin CHECK(suffix != nullptr); 6023774335b08076117d6950cd472cdd59a167470b5Igor Murashkin 6033774335b08076117d6950cd472cdd59a167470b5Igor Murashkin std::string location; 6043774335b08076117d6950cd472cdd59a167470b5Igor Murashkin if (IsHost()) { 6053774335b08076117d6950cd472cdd59a167470b5Igor Murashkin const char* host_dir = getenv("ANDROID_HOST_OUT"); 6062cebb24bfc3247d3e9be138a3350106737455918Mathieu Chartier CHECK(host_dir != nullptr); 6073774335b08076117d6950cd472cdd59a167470b5Igor Murashkin location = StringPrintf("%s/framework/core.%s", host_dir, suffix); 6083774335b08076117d6950cd472cdd59a167470b5Igor Murashkin } else { 6093774335b08076117d6950cd472cdd59a167470b5Igor Murashkin location = StringPrintf("/data/art-test/core.%s", suffix); 6103774335b08076117d6950cd472cdd59a167470b5Igor Murashkin } 6113774335b08076117d6950cd472cdd59a167470b5Igor Murashkin 6123774335b08076117d6950cd472cdd59a167470b5Igor Murashkin return location; 6133774335b08076117d6950cd472cdd59a167470b5Igor Murashkin} 6143774335b08076117d6950cd472cdd59a167470b5Igor Murashkin 615e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian RogersCheckJniAbortCatcher::CheckJniAbortCatcher() : vm_(Runtime::Current()->GetJavaVM()) { 61668d8b42ddec39ec0174162d90d4abaa004d1983eIan Rogers vm_->SetCheckJniAbortHook(Hook, &actual_); 617e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 618e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 619e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian RogersCheckJniAbortCatcher::~CheckJniAbortCatcher() { 62068d8b42ddec39ec0174162d90d4abaa004d1983eIan Rogers vm_->SetCheckJniAbortHook(nullptr, nullptr); 621e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers EXPECT_TRUE(actual_.empty()) << actual_; 622e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 623e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 624e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersvoid CheckJniAbortCatcher::Check(const char* expected_text) { 625e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers EXPECT_TRUE(actual_.find(expected_text) != std::string::npos) << "\n" 626e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers << "Expected to find: " << expected_text << "\n" 627e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers << "In the output : " << actual_; 628e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers actual_.clear(); 629e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 630e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 631e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersvoid CheckJniAbortCatcher::Hook(void* data, const std::string& reason) { 632e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // We use += because when we're hooking the aborts like this, multiple problems can be found. 633e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers *reinterpret_cast<std::string*>(data) += reason; 634e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 635e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 636e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} // namespace art 637e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 638e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersnamespace std { 639e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 640e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogerstemplate <typename T> 641e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersstd::ostream& operator<<(std::ostream& os, const std::vector<T>& rhs) { 642e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersos << ::art::ToString(rhs); 643e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersreturn os; 644e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 645e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 646e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} // namespace std 647