common_runtime_test.cc revision 4460a84be92b5a94ecfb5c650aef4945ab849c93
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 19e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include <dirent.h> 20e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include <dlfcn.h> 21e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include <fcntl.h> 22e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include <ScopedLocalRef.h> 23369810a98e6394b6dd162f5349e38a1f597b3bc7Andreas Gampe#include <stdlib.h> 24e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 25e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "../../external/icu/icu4c/source/common/unicode/uvernum.h" 261fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe#include "base/macros.h" 2707ed66b5ae659c452cbe1ab20c3dbf1d6f546461Elliott Hughes#include "base/logging.h" 28e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "base/stl_util.h" 29e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "base/stringprintf.h" 30e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "base/unix_file/fd_file.h" 31e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "class_linker.h" 32e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "compiler_callbacks.h" 33e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "dex_file.h" 3494f7b49578b6aaa80de8ffed230648d601393905Hiroshi Yamauchi#include "gc_root-inl.h" 35e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "gc/heap.h" 36eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughes#include "gtest/gtest.h" 379b5cba401aae6d34450112bdcf9bab5e19da90f2Andreas Gampe#include "interpreter/unstarted_runtime.h" 38e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "jni_internal.h" 39e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "mirror/class_loader.h" 4066d874d96d5699bb090c59f47a5a528956ca053eRichard Uhler#include "mem_map.h" 41e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "noop_compiler_callbacks.h" 42e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "os.h" 43e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "runtime-inl.h" 44e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "scoped_thread_state_change.h" 45e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "thread.h" 46e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "well_known_classes.h" 47eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughes 48eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughesint main(int argc, char **argv) { 49369810a98e6394b6dd162f5349e38a1f597b3bc7Andreas Gampe // Gtests can be very noisy. For example, an executable with multiple tests will trigger native 50369810a98e6394b6dd162f5349e38a1f597b3bc7Andreas Gampe // bridge warnings. The following line reduces the minimum log severity to ERROR and suppresses 51369810a98e6394b6dd162f5349e38a1f597b3bc7Andreas Gampe // everything else. In case you want to see all messages, comment out the line. 52892fc96694b51ac7a896dacd75af5b235f955825Richard Uhler setenv("ANDROID_LOG_TAGS", "*:e", 1); 53369810a98e6394b6dd162f5349e38a1f597b3bc7Andreas Gampe 54eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughes art::InitLogging(argv); 55c7dd295a4e0cc1d15c0c96088e55a85389bade74Ian Rogers LOG(::art::INFO) << "Running main() from common_runtime_test.cc..."; 56eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughes testing::InitGoogleTest(&argc, argv); 57eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughes return RUN_ALL_TESTS(); 58eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughes} 59e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 60e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersnamespace art { 61e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 62e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian RogersScratchFile::ScratchFile() { 63e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // ANDROID_DATA needs to be set 64e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK_NE(static_cast<char*>(nullptr), getenv("ANDROID_DATA")) << 65e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers "Are you subclassing RuntimeTest?"; 66e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename_ = getenv("ANDROID_DATA"); 67e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename_ += "/TmpFile-XXXXXX"; 68e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers int fd = mkstemp(&filename_[0]); 69e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK_NE(-1, fd); 704303ba97313458491e038d78efa041d41cf7bb43Andreas Gampe file_.reset(new File(fd, GetFilename(), true)); 71e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 72e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 73e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian RogersScratchFile::ScratchFile(const ScratchFile& other, const char* suffix) { 74e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename_ = other.GetFilename(); 75e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename_ += suffix; 76e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers int fd = open(filename_.c_str(), O_RDWR | O_CREAT, 0666); 77e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK_NE(-1, fd); 784303ba97313458491e038d78efa041d41cf7bb43Andreas Gampe file_.reset(new File(fd, GetFilename(), true)); 79e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 80e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 81e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian RogersScratchFile::ScratchFile(File* file) { 82e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK(file != NULL); 83e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename_ = file->GetPath(); 84e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers file_.reset(file); 85e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 86e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 87e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian RogersScratchFile::~ScratchFile() { 88e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers Unlink(); 89e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 90e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 91e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersint ScratchFile::GetFd() const { 92e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers return file_->Fd(); 93e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 94e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 95e21dc3db191df04c100620965bee4617b3b24397Andreas Gampevoid ScratchFile::Close() { 964303ba97313458491e038d78efa041d41cf7bb43Andreas Gampe if (file_.get() != nullptr) { 974303ba97313458491e038d78efa041d41cf7bb43Andreas Gampe if (file_->FlushCloseOrErase() != 0) { 984303ba97313458491e038d78efa041d41cf7bb43Andreas Gampe PLOG(WARNING) << "Error closing scratch file."; 994303ba97313458491e038d78efa041d41cf7bb43Andreas Gampe } 1004303ba97313458491e038d78efa041d41cf7bb43Andreas Gampe } 101e21dc3db191df04c100620965bee4617b3b24397Andreas Gampe} 102e21dc3db191df04c100620965bee4617b3b24397Andreas Gampe 103e21dc3db191df04c100620965bee4617b3b24397Andreas Gampevoid ScratchFile::Unlink() { 104e21dc3db191df04c100620965bee4617b3b24397Andreas Gampe if (!OS::FileExists(filename_.c_str())) { 105e21dc3db191df04c100620965bee4617b3b24397Andreas Gampe return; 106e21dc3db191df04c100620965bee4617b3b24397Andreas Gampe } 107e21dc3db191df04c100620965bee4617b3b24397Andreas Gampe Close(); 108e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers int unlink_result = unlink(filename_.c_str()); 109e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK_EQ(0, unlink_result); 110e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 111e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 1129b5cba401aae6d34450112bdcf9bab5e19da90f2Andreas Gampestatic bool unstarted_initialized_ = false; 1139b5cba401aae6d34450112bdcf9bab5e19da90f2Andreas Gampe 114e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian RogersCommonRuntimeTest::CommonRuntimeTest() {} 115fbef44de596d298dc6430f482dffc933a046dd28Richard UhlerCommonRuntimeTest::~CommonRuntimeTest() { 116fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler // Ensure the dex files are cleaned up before the runtime. 117fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler loaded_dex_files_.clear(); 118fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler runtime_.reset(); 119fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler} 120e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 1217747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampevoid CommonRuntimeTest::SetUpAndroidRoot() { 122e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers if (IsHost()) { 123e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // $ANDROID_ROOT is set on the device, but not necessarily on the host. 124e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // But it needs to be set so that icu4c can find its locale data. 125e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers const char* android_root_from_env = getenv("ANDROID_ROOT"); 126e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers if (android_root_from_env == nullptr) { 127e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // Use ANDROID_HOST_OUT for ANDROID_ROOT if it is set. 128e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers const char* android_host_out = getenv("ANDROID_HOST_OUT"); 129e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers if (android_host_out != nullptr) { 130e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers setenv("ANDROID_ROOT", android_host_out, 1); 131e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } else { 132e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // Build it from ANDROID_BUILD_TOP or cwd 133e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers std::string root; 134e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers const char* android_build_top = getenv("ANDROID_BUILD_TOP"); 135e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers if (android_build_top != nullptr) { 136e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers root += android_build_top; 137e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } else { 138e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // Not set by build server, so default to current directory 139e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers char* cwd = getcwd(nullptr, 0); 140e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers setenv("ANDROID_BUILD_TOP", cwd, 1); 141e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers root += cwd; 142e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers free(cwd); 143e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 144e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#if defined(__linux__) 145e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers root += "/out/host/linux-x86"; 146e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#elif defined(__APPLE__) 147e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers root += "/out/host/darwin-x86"; 148e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#else 149e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#error unsupported OS 150e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#endif 151e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers setenv("ANDROID_ROOT", root.c_str(), 1); 152e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 153e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 154e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers setenv("LD_LIBRARY_PATH", ":", 0); // Required by java.lang.System.<clinit>. 155e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 156e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // Not set by build server, so default 157e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers if (getenv("ANDROID_HOST_OUT") == nullptr) { 158e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers setenv("ANDROID_HOST_OUT", getenv("ANDROID_ROOT"), 1); 159e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 160e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 1617747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe} 162e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 1637747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampevoid CommonRuntimeTest::SetUpAndroidData(std::string& android_data) { 164e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // On target, Cannot use /mnt/sdcard because it is mounted noexec, so use subdir of dalvik-cache 1655a79fdecffbea657ebecd4cf19078925239eb1c3Andreas Gampe if (IsHost()) { 1665a79fdecffbea657ebecd4cf19078925239eb1c3Andreas Gampe const char* tmpdir = getenv("TMPDIR"); 1675a79fdecffbea657ebecd4cf19078925239eb1c3Andreas Gampe if (tmpdir != nullptr && tmpdir[0] != 0) { 1685a79fdecffbea657ebecd4cf19078925239eb1c3Andreas Gampe android_data = tmpdir; 1695a79fdecffbea657ebecd4cf19078925239eb1c3Andreas Gampe } else { 1705a79fdecffbea657ebecd4cf19078925239eb1c3Andreas Gampe android_data = "/tmp"; 1715a79fdecffbea657ebecd4cf19078925239eb1c3Andreas Gampe } 1725a79fdecffbea657ebecd4cf19078925239eb1c3Andreas Gampe } else { 1735a79fdecffbea657ebecd4cf19078925239eb1c3Andreas Gampe android_data = "/data/dalvik-cache"; 1745a79fdecffbea657ebecd4cf19078925239eb1c3Andreas Gampe } 1755a79fdecffbea657ebecd4cf19078925239eb1c3Andreas Gampe android_data += "/art-data-XXXXXX"; 176e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers if (mkdtemp(&android_data[0]) == nullptr) { 177e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers PLOG(FATAL) << "mkdtemp(\"" << &android_data[0] << "\") failed"; 178e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 179e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers setenv("ANDROID_DATA", android_data.c_str(), 1); 180e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 181e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 1827747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampevoid CommonRuntimeTest::TearDownAndroidData(const std::string& android_data, bool fail_on_error) { 1837747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe if (fail_on_error) { 1847747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe ASSERT_EQ(rmdir(android_data.c_str()), 0); 1857747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe } else { 1867747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe rmdir(android_data.c_str()); 1877747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe } 1887747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe} 1897747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe 1903774335b08076117d6950cd472cdd59a167470b5Igor Murashkinstd::string CommonRuntimeTest::GetCoreArtLocation() { 1913774335b08076117d6950cd472cdd59a167470b5Igor Murashkin return GetCoreFileLocation("art"); 1923774335b08076117d6950cd472cdd59a167470b5Igor Murashkin} 1933774335b08076117d6950cd472cdd59a167470b5Igor Murashkin 1943774335b08076117d6950cd472cdd59a167470b5Igor Murashkinstd::string CommonRuntimeTest::GetCoreOatLocation() { 1953774335b08076117d6950cd472cdd59a167470b5Igor Murashkin return GetCoreFileLocation("oat"); 1963774335b08076117d6950cd472cdd59a167470b5Igor Murashkin} 1977747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe 198fbef44de596d298dc6430f482dffc933a046dd28Richard Uhlerstd::unique_ptr<const DexFile> CommonRuntimeTest::LoadExpectSingleDexFile(const char* location) { 199fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler std::vector<std::unique_ptr<const DexFile>> dex_files; 200e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers std::string error_msg; 20166d874d96d5699bb090c59f47a5a528956ca053eRichard Uhler MemMap::Init(); 202e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers if (!DexFile::Open(location, location, &error_msg, &dex_files)) { 203e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers LOG(FATAL) << "Could not open .dex file '" << location << "': " << error_msg << "\n"; 204fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler UNREACHABLE(); 205e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } else { 206e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK_EQ(1U, dex_files.size()) << "Expected only one dex file in " << location; 207fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler return std::move(dex_files[0]); 208e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 209e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 210e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 211e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersvoid CommonRuntimeTest::SetUp() { 2127747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe SetUpAndroidRoot(); 2137747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe SetUpAndroidData(android_data_); 214e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers dalvik_cache_.append(android_data_.c_str()); 215e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers dalvik_cache_.append("/dalvik-cache"); 216e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers int mkdir_result = mkdir(dalvik_cache_.c_str(), 0700); 217e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers ASSERT_EQ(mkdir_result, 0); 218e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 219e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers std::string min_heap_string(StringPrintf("-Xms%zdm", gc::Heap::kDefaultInitialSize / MB)); 220e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers std::string max_heap_string(StringPrintf("-Xmx%zdm", gc::Heap::kDefaultMaximumSize / MB)); 221e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 222e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers callbacks_.reset(new NoopCompilerCallbacks()); 223e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 224e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers RuntimeOptions options; 225c275259449ec57987e52d3ab1eda3272b994488fRichard Uhler std::string boot_class_path_string = "-Xbootclasspath:" + GetLibCoreDexFileName(); 226c275259449ec57987e52d3ab1eda3272b994488fRichard Uhler options.push_back(std::make_pair(boot_class_path_string, nullptr)); 227e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers options.push_back(std::make_pair("-Xcheck:jni", nullptr)); 228c275259449ec57987e52d3ab1eda3272b994488fRichard Uhler options.push_back(std::make_pair(min_heap_string, nullptr)); 229c275259449ec57987e52d3ab1eda3272b994488fRichard Uhler options.push_back(std::make_pair(max_heap_string, nullptr)); 230e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers options.push_back(std::make_pair("compilercallbacks", callbacks_.get())); 231e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers SetUpRuntimeOptions(&options); 232aaebaa0121be3b9d9f13630585304482cbcaeb4bIgor Murashkin 23366d874d96d5699bb090c59f47a5a528956ca053eRichard Uhler PreRuntimeCreate(); 234e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers if (!Runtime::Create(options, false)) { 235e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers LOG(FATAL) << "Failed to create runtime"; 236e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers return; 237e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 23866d874d96d5699bb090c59f47a5a528956ca053eRichard Uhler PostRuntimeCreate(); 239e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers runtime_.reset(Runtime::Current()); 240e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers class_linker_ = runtime_->GetClassLinker(); 241e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers class_linker_->FixupDexCaches(runtime_->GetResolutionMethod()); 2422969bcdcd80624e4a4fef696b54c2c76b44b6853Andreas Gampe 2432969bcdcd80624e4a4fef696b54c2c76b44b6853Andreas Gampe // Initialize maps for unstarted runtime. This needs to be here, as running clinits needs this 2442969bcdcd80624e4a4fef696b54c2c76b44b6853Andreas Gampe // set up. 2459b5cba401aae6d34450112bdcf9bab5e19da90f2Andreas Gampe if (!unstarted_initialized_) { 2469b5cba401aae6d34450112bdcf9bab5e19da90f2Andreas Gampe interpreter::UnstartedRuntimeInitialize(); 2479b5cba401aae6d34450112bdcf9bab5e19da90f2Andreas Gampe unstarted_initialized_ = true; 2489b5cba401aae6d34450112bdcf9bab5e19da90f2Andreas Gampe } 2492969bcdcd80624e4a4fef696b54c2c76b44b6853Andreas Gampe 250e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers class_linker_->RunRootClinits(); 251fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler boot_class_path_ = class_linker_->GetBootClassPath(); 252fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler java_lang_dex_file_ = boot_class_path_[0]; 253fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler 254e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 255e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // Runtime::Create acquired the mutator_lock_ that is normally given away when we 256e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // Runtime::Start, give it away now and then switch to a more managable ScopedObjectAccess. 257e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers Thread::Current()->TransitionFromRunnableToSuspended(kNative); 258e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 259e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // We're back in native, take the opportunity to initialize well known classes. 260e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers WellKnownClasses::Init(Thread::Current()->GetJniEnv()); 261e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 262e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // Create the heap thread pool so that the GC runs in parallel for tests. Normally, the thread 263e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // pool is created by the runtime. 264e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers runtime_->GetHeap()->CreateThreadPool(); 265e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers runtime_->GetHeap()->VerifyHeap(); // Check for heap corruption before the test 2664460a84be92b5a94ecfb5c650aef4945ab849c93Hiroshi Yamauchi // Reduce timinig-dependent flakiness in OOME behavior (eg StubTest.AllocObject). 2674460a84be92b5a94ecfb5c650aef4945ab849c93Hiroshi Yamauchi runtime_->GetHeap()->SetMinIntervalHomogeneousSpaceCompactionByOom(0U); 268c275259449ec57987e52d3ab1eda3272b994488fRichard Uhler 269c275259449ec57987e52d3ab1eda3272b994488fRichard Uhler // Get the boot class path from the runtime so it can be used in tests. 270c275259449ec57987e52d3ab1eda3272b994488fRichard Uhler boot_class_path_ = class_linker_->GetBootClassPath(); 271c275259449ec57987e52d3ab1eda3272b994488fRichard Uhler ASSERT_FALSE(boot_class_path_.empty()); 272c275259449ec57987e52d3ab1eda3272b994488fRichard Uhler java_lang_dex_file_ = boot_class_path_[0]; 273e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 274e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 275a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Lightvoid CommonRuntimeTest::ClearDirectory(const char* dirpath) { 276a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light ASSERT_TRUE(dirpath != nullptr); 277a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light DIR* dir = opendir(dirpath); 278e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers ASSERT_TRUE(dir != nullptr); 279e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers dirent* e; 280a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light struct stat s; 281e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers while ((e = readdir(dir)) != nullptr) { 282e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers if ((strcmp(e->d_name, ".") == 0) || (strcmp(e->d_name, "..") == 0)) { 283e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers continue; 284e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 285f0a3f09c3d54646166a55c05a6b39c7dd504129cJeff Hao std::string filename(dirpath); 286e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename.push_back('/'); 287e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename.append(e->d_name); 288a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light int stat_result = lstat(filename.c_str(), &s); 289a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light ASSERT_EQ(0, stat_result) << "unable to stat " << filename; 290a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light if (S_ISDIR(s.st_mode)) { 291a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light ClearDirectory(filename.c_str()); 292a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light int rmdir_result = rmdir(filename.c_str()); 293a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light ASSERT_EQ(0, rmdir_result) << filename; 294a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light } else { 295a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light int unlink_result = unlink(filename.c_str()); 296a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light ASSERT_EQ(0, unlink_result) << filename; 297a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light } 298e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 299e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers closedir(dir); 300a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light} 301a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light 302a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Lightvoid CommonRuntimeTest::TearDown() { 303a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light const char* android_data = getenv("ANDROID_DATA"); 304a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light ASSERT_TRUE(android_data != nullptr); 305a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light ClearDirectory(dalvik_cache_.c_str()); 306e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers int rmdir_cache_result = rmdir(dalvik_cache_.c_str()); 307e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers ASSERT_EQ(0, rmdir_cache_result); 3087747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe TearDownAndroidData(android_data_, true); 309e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 310e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // icu4c has a fixed 10-element array "gCommonICUDataArray". 311e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // If we run > 10 tests, we fill that array and u_setCommonData fails. 312e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // There's a function to clear the array, but it's not public... 313e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers typedef void (*IcuCleanupFn)(); 314e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers void* sym = dlsym(RTLD_DEFAULT, "u_cleanup_" U_ICU_VERSION_SHORT); 315e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK(sym != nullptr) << dlerror(); 316e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers IcuCleanupFn icu_cleanup_fn = reinterpret_cast<IcuCleanupFn>(sym); 317e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers (*icu_cleanup_fn)(); 318e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 319e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers Runtime::Current()->GetHeap()->VerifyHeap(); // Check for heap corruption after the test 320e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 321e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 322e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersstd::string CommonRuntimeTest::GetLibCoreDexFileName() { 323e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers return GetDexFileName("core-libart"); 324e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 325e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 326e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersstd::string CommonRuntimeTest::GetDexFileName(const std::string& jar_prefix) { 327e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers if (IsHost()) { 328e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers const char* host_dir = getenv("ANDROID_HOST_OUT"); 329e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK(host_dir != nullptr); 330e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers return StringPrintf("%s/framework/%s-hostdex.jar", host_dir, jar_prefix.c_str()); 331e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 332e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers return StringPrintf("%s/framework/%s.jar", GetAndroidRoot(), jar_prefix.c_str()); 333e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 334e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 335e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersstd::string CommonRuntimeTest::GetTestAndroidRoot() { 336e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers if (IsHost()) { 337e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers const char* host_dir = getenv("ANDROID_HOST_OUT"); 338e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK(host_dir != nullptr); 339e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers return host_dir; 340e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 341e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers return GetAndroidRoot(); 342e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 343e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 3441fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe// Check that for target builds we have ART_TARGET_NATIVETEST_DIR set. 3451fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe#ifdef ART_TARGET 3461fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe#ifndef ART_TARGET_NATIVETEST_DIR 3471fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe#error "ART_TARGET_NATIVETEST_DIR not set." 3481fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe#endif 3491fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe// Wrap it as a string literal. 3501fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe#define ART_TARGET_NATIVETEST_DIR_STRING STRINGIFY(ART_TARGET_NATIVETEST_DIR) "/" 3511fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe#else 3521fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe#define ART_TARGET_NATIVETEST_DIR_STRING "" 3531fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe#endif 3541fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe 35566d874d96d5699bb090c59f47a5a528956ca053eRichard Uhlerstd::string CommonRuntimeTest::GetTestDexFileName(const char* name) { 356e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK(name != nullptr); 357e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers std::string filename; 358e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers if (IsHost()) { 359e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename += getenv("ANDROID_HOST_OUT"); 360e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename += "/framework/"; 361e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } else { 3621fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe filename += ART_TARGET_NATIVETEST_DIR_STRING; 363e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 364e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename += "art-gtest-"; 365e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename += name; 366e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename += ".jar"; 36766d874d96d5699bb090c59f47a5a528956ca053eRichard Uhler return filename; 36866d874d96d5699bb090c59f47a5a528956ca053eRichard Uhler} 36966d874d96d5699bb090c59f47a5a528956ca053eRichard Uhler 37066d874d96d5699bb090c59f47a5a528956ca053eRichard Uhlerstd::vector<std::unique_ptr<const DexFile>> CommonRuntimeTest::OpenTestDexFiles(const char* name) { 37166d874d96d5699bb090c59f47a5a528956ca053eRichard Uhler std::string filename = GetTestDexFileName(name); 372e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers std::string error_msg; 373fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler std::vector<std::unique_ptr<const DexFile>> dex_files; 374e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers bool success = DexFile::Open(filename.c_str(), filename.c_str(), &error_msg, &dex_files); 375e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK(success) << "Failed to open '" << filename << "': " << error_msg; 376fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler for (auto& dex_file : dex_files) { 377e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK_EQ(PROT_READ, dex_file->GetPermissions()); 378e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK(dex_file->IsReadOnly()); 379e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 380e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers return dex_files; 381e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 382e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 383fbef44de596d298dc6430f482dffc933a046dd28Richard Uhlerstd::unique_ptr<const DexFile> CommonRuntimeTest::OpenTestDexFile(const char* name) { 384fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler std::vector<std::unique_ptr<const DexFile>> vector = OpenTestDexFiles(name); 385e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers EXPECT_EQ(1U, vector.size()); 386fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler return std::move(vector[0]); 387e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 388e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 389e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersjobject CommonRuntimeTest::LoadDex(const char* dex_name) { 390fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler std::vector<std::unique_ptr<const DexFile>> dex_files = OpenTestDexFiles(dex_name); 391fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler std::vector<const DexFile*> class_path; 392e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK_NE(0U, dex_files.size()); 393fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler for (auto& dex_file : dex_files) { 394fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler class_path.push_back(dex_file.get()); 395e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers class_linker_->RegisterDexFile(*dex_file); 396fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler loaded_dex_files_.push_back(std::move(dex_file)); 397e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 39868d8b42ddec39ec0174162d90d4abaa004d1983eIan Rogers Thread* self = Thread::Current(); 39968d8b42ddec39ec0174162d90d4abaa004d1983eIan Rogers JNIEnvExt* env = self->GetJniEnv(); 40068d8b42ddec39ec0174162d90d4abaa004d1983eIan Rogers ScopedLocalRef<jobject> class_loader_local(env, 40168d8b42ddec39ec0174162d90d4abaa004d1983eIan Rogers env->AllocObject(WellKnownClasses::dalvik_system_PathClassLoader)); 40268d8b42ddec39ec0174162d90d4abaa004d1983eIan Rogers jobject class_loader = env->NewGlobalRef(class_loader_local.get()); 40368d8b42ddec39ec0174162d90d4abaa004d1983eIan Rogers self->SetClassLoaderOverride(class_loader_local.get()); 404fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler Runtime::Current()->SetCompileTimeClassPath(class_loader, class_path); 405e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers return class_loader; 406e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 407e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 4083774335b08076117d6950cd472cdd59a167470b5Igor Murashkinstd::string CommonRuntimeTest::GetCoreFileLocation(const char* suffix) { 4093774335b08076117d6950cd472cdd59a167470b5Igor Murashkin CHECK(suffix != nullptr); 4103774335b08076117d6950cd472cdd59a167470b5Igor Murashkin 4113774335b08076117d6950cd472cdd59a167470b5Igor Murashkin std::string location; 4123774335b08076117d6950cd472cdd59a167470b5Igor Murashkin if (IsHost()) { 4133774335b08076117d6950cd472cdd59a167470b5Igor Murashkin const char* host_dir = getenv("ANDROID_HOST_OUT"); 4143774335b08076117d6950cd472cdd59a167470b5Igor Murashkin CHECK(host_dir != NULL); 4153774335b08076117d6950cd472cdd59a167470b5Igor Murashkin location = StringPrintf("%s/framework/core.%s", host_dir, suffix); 4163774335b08076117d6950cd472cdd59a167470b5Igor Murashkin } else { 4173774335b08076117d6950cd472cdd59a167470b5Igor Murashkin location = StringPrintf("/data/art-test/core.%s", suffix); 4183774335b08076117d6950cd472cdd59a167470b5Igor Murashkin } 4193774335b08076117d6950cd472cdd59a167470b5Igor Murashkin 4203774335b08076117d6950cd472cdd59a167470b5Igor Murashkin return location; 4213774335b08076117d6950cd472cdd59a167470b5Igor Murashkin} 4223774335b08076117d6950cd472cdd59a167470b5Igor Murashkin 423e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian RogersCheckJniAbortCatcher::CheckJniAbortCatcher() : vm_(Runtime::Current()->GetJavaVM()) { 42468d8b42ddec39ec0174162d90d4abaa004d1983eIan Rogers vm_->SetCheckJniAbortHook(Hook, &actual_); 425e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 426e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 427e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian RogersCheckJniAbortCatcher::~CheckJniAbortCatcher() { 42868d8b42ddec39ec0174162d90d4abaa004d1983eIan Rogers vm_->SetCheckJniAbortHook(nullptr, nullptr); 429e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers EXPECT_TRUE(actual_.empty()) << actual_; 430e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 431e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 432e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersvoid CheckJniAbortCatcher::Check(const char* expected_text) { 433e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers EXPECT_TRUE(actual_.find(expected_text) != std::string::npos) << "\n" 434e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers << "Expected to find: " << expected_text << "\n" 435e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers << "In the output : " << actual_; 436e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers actual_.clear(); 437e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 438e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 439e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersvoid CheckJniAbortCatcher::Hook(void* data, const std::string& reason) { 440e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // We use += because when we're hooking the aborts like this, multiple problems can be found. 441e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers *reinterpret_cast<std::string*>(data) += reason; 442e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 443e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 444e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} // namespace art 445e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 446e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersnamespace std { 447e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 448e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogerstemplate <typename T> 449e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersstd::ostream& operator<<(std::ostream& os, const std::vector<T>& rhs) { 450e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersos << ::art::ToString(rhs); 451e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersreturn os; 452e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 453e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 454e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} // namespace std 455