common_runtime_test.cc revision aaebaa0121be3b9d9f13630585304482cbcaeb4b
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" 37e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "jni_internal.h" 38e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "mirror/class_loader.h" 39e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "noop_compiler_callbacks.h" 40e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "os.h" 41e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "runtime-inl.h" 42e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "scoped_thread_state_change.h" 43e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "thread.h" 44e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "well_known_classes.h" 45eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughes 46eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughesint main(int argc, char **argv) { 47369810a98e6394b6dd162f5349e38a1f597b3bc7Andreas Gampe // Gtests can be very noisy. For example, an executable with multiple tests will trigger native 48369810a98e6394b6dd162f5349e38a1f597b3bc7Andreas Gampe // bridge warnings. The following line reduces the minimum log severity to ERROR and suppresses 49369810a98e6394b6dd162f5349e38a1f597b3bc7Andreas Gampe // everything else. In case you want to see all messages, comment out the line. 50369810a98e6394b6dd162f5349e38a1f597b3bc7Andreas Gampe setenv("ANDROID_LOG_TAGS", "*:e", 1); 51369810a98e6394b6dd162f5349e38a1f597b3bc7Andreas Gampe 52eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughes art::InitLogging(argv); 53c7dd295a4e0cc1d15c0c96088e55a85389bade74Ian Rogers LOG(::art::INFO) << "Running main() from common_runtime_test.cc..."; 54eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughes testing::InitGoogleTest(&argc, argv); 55eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughes return RUN_ALL_TESTS(); 56eb02a124afcd6869ada475712bca8cbe0de20222Elliott Hughes} 57e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 58e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersnamespace art { 59e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 60e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian RogersScratchFile::ScratchFile() { 61e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // ANDROID_DATA needs to be set 62e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK_NE(static_cast<char*>(nullptr), getenv("ANDROID_DATA")) << 63e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers "Are you subclassing RuntimeTest?"; 64e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename_ = getenv("ANDROID_DATA"); 65e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename_ += "/TmpFile-XXXXXX"; 66e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers int fd = mkstemp(&filename_[0]); 67e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK_NE(-1, fd); 684303ba97313458491e038d78efa041d41cf7bb43Andreas Gampe file_.reset(new File(fd, GetFilename(), true)); 69e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 70e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 71e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian RogersScratchFile::ScratchFile(const ScratchFile& other, const char* suffix) { 72e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename_ = other.GetFilename(); 73e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename_ += suffix; 74e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers int fd = open(filename_.c_str(), O_RDWR | O_CREAT, 0666); 75e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK_NE(-1, fd); 764303ba97313458491e038d78efa041d41cf7bb43Andreas Gampe file_.reset(new File(fd, GetFilename(), true)); 77e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 78e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 79e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian RogersScratchFile::ScratchFile(File* file) { 80e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK(file != NULL); 81e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename_ = file->GetPath(); 82e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers file_.reset(file); 83e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 84e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 85e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian RogersScratchFile::~ScratchFile() { 86e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers Unlink(); 87e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 88e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 89e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersint ScratchFile::GetFd() const { 90e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers return file_->Fd(); 91e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 92e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 93e21dc3db191df04c100620965bee4617b3b24397Andreas Gampevoid ScratchFile::Close() { 944303ba97313458491e038d78efa041d41cf7bb43Andreas Gampe if (file_.get() != nullptr) { 954303ba97313458491e038d78efa041d41cf7bb43Andreas Gampe if (file_->FlushCloseOrErase() != 0) { 964303ba97313458491e038d78efa041d41cf7bb43Andreas Gampe PLOG(WARNING) << "Error closing scratch file."; 974303ba97313458491e038d78efa041d41cf7bb43Andreas Gampe } 984303ba97313458491e038d78efa041d41cf7bb43Andreas Gampe } 99e21dc3db191df04c100620965bee4617b3b24397Andreas Gampe} 100e21dc3db191df04c100620965bee4617b3b24397Andreas Gampe 101e21dc3db191df04c100620965bee4617b3b24397Andreas Gampevoid ScratchFile::Unlink() { 102e21dc3db191df04c100620965bee4617b3b24397Andreas Gampe if (!OS::FileExists(filename_.c_str())) { 103e21dc3db191df04c100620965bee4617b3b24397Andreas Gampe return; 104e21dc3db191df04c100620965bee4617b3b24397Andreas Gampe } 105e21dc3db191df04c100620965bee4617b3b24397Andreas Gampe Close(); 106e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers int unlink_result = unlink(filename_.c_str()); 107e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK_EQ(0, unlink_result); 108e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 109e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 110e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian RogersCommonRuntimeTest::CommonRuntimeTest() {} 111fbef44de596d298dc6430f482dffc933a046dd28Richard UhlerCommonRuntimeTest::~CommonRuntimeTest() { 112fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler // Ensure the dex files are cleaned up before the runtime. 113fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler loaded_dex_files_.clear(); 114fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler runtime_.reset(); 115fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler} 116e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 1177747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampevoid CommonRuntimeTest::SetUpAndroidRoot() { 118e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers if (IsHost()) { 119e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // $ANDROID_ROOT is set on the device, but not necessarily on the host. 120e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // But it needs to be set so that icu4c can find its locale data. 121e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers const char* android_root_from_env = getenv("ANDROID_ROOT"); 122e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers if (android_root_from_env == nullptr) { 123e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // Use ANDROID_HOST_OUT for ANDROID_ROOT if it is set. 124e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers const char* android_host_out = getenv("ANDROID_HOST_OUT"); 125e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers if (android_host_out != nullptr) { 126e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers setenv("ANDROID_ROOT", android_host_out, 1); 127e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } else { 128e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // Build it from ANDROID_BUILD_TOP or cwd 129e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers std::string root; 130e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers const char* android_build_top = getenv("ANDROID_BUILD_TOP"); 131e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers if (android_build_top != nullptr) { 132e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers root += android_build_top; 133e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } else { 134e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // Not set by build server, so default to current directory 135e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers char* cwd = getcwd(nullptr, 0); 136e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers setenv("ANDROID_BUILD_TOP", cwd, 1); 137e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers root += cwd; 138e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers free(cwd); 139e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 140e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#if defined(__linux__) 141e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers root += "/out/host/linux-x86"; 142e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#elif defined(__APPLE__) 143e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers root += "/out/host/darwin-x86"; 144e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#else 145e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#error unsupported OS 146e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#endif 147e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers setenv("ANDROID_ROOT", root.c_str(), 1); 148e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 149e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 150e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers setenv("LD_LIBRARY_PATH", ":", 0); // Required by java.lang.System.<clinit>. 151e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 152e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // Not set by build server, so default 153e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers if (getenv("ANDROID_HOST_OUT") == nullptr) { 154e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers setenv("ANDROID_HOST_OUT", getenv("ANDROID_ROOT"), 1); 155e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 156e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 1577747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe} 158e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 1597747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampevoid CommonRuntimeTest::SetUpAndroidData(std::string& android_data) { 160e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // On target, Cannot use /mnt/sdcard because it is mounted noexec, so use subdir of dalvik-cache 1615a79fdecffbea657ebecd4cf19078925239eb1c3Andreas Gampe if (IsHost()) { 1625a79fdecffbea657ebecd4cf19078925239eb1c3Andreas Gampe const char* tmpdir = getenv("TMPDIR"); 1635a79fdecffbea657ebecd4cf19078925239eb1c3Andreas Gampe if (tmpdir != nullptr && tmpdir[0] != 0) { 1645a79fdecffbea657ebecd4cf19078925239eb1c3Andreas Gampe android_data = tmpdir; 1655a79fdecffbea657ebecd4cf19078925239eb1c3Andreas Gampe } else { 1665a79fdecffbea657ebecd4cf19078925239eb1c3Andreas Gampe android_data = "/tmp"; 1675a79fdecffbea657ebecd4cf19078925239eb1c3Andreas Gampe } 1685a79fdecffbea657ebecd4cf19078925239eb1c3Andreas Gampe } else { 1695a79fdecffbea657ebecd4cf19078925239eb1c3Andreas Gampe android_data = "/data/dalvik-cache"; 1705a79fdecffbea657ebecd4cf19078925239eb1c3Andreas Gampe } 1715a79fdecffbea657ebecd4cf19078925239eb1c3Andreas Gampe android_data += "/art-data-XXXXXX"; 172e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers if (mkdtemp(&android_data[0]) == nullptr) { 173e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers PLOG(FATAL) << "mkdtemp(\"" << &android_data[0] << "\") failed"; 174e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 175e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers setenv("ANDROID_DATA", android_data.c_str(), 1); 176e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 177e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 1787747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampevoid CommonRuntimeTest::TearDownAndroidData(const std::string& android_data, bool fail_on_error) { 1797747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe if (fail_on_error) { 1807747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe ASSERT_EQ(rmdir(android_data.c_str()), 0); 1817747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe } else { 1827747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe rmdir(android_data.c_str()); 1837747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe } 1847747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe} 1857747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe 1863774335b08076117d6950cd472cdd59a167470b5Igor Murashkinstd::string CommonRuntimeTest::GetCoreArtLocation() { 1873774335b08076117d6950cd472cdd59a167470b5Igor Murashkin return GetCoreFileLocation("art"); 1883774335b08076117d6950cd472cdd59a167470b5Igor Murashkin} 1893774335b08076117d6950cd472cdd59a167470b5Igor Murashkin 1903774335b08076117d6950cd472cdd59a167470b5Igor Murashkinstd::string CommonRuntimeTest::GetCoreOatLocation() { 1913774335b08076117d6950cd472cdd59a167470b5Igor Murashkin return GetCoreFileLocation("oat"); 1923774335b08076117d6950cd472cdd59a167470b5Igor Murashkin} 1937747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe 194fbef44de596d298dc6430f482dffc933a046dd28Richard Uhlerstd::unique_ptr<const DexFile> CommonRuntimeTest::LoadExpectSingleDexFile(const char* location) { 195fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler std::vector<std::unique_ptr<const DexFile>> dex_files; 196e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers std::string error_msg; 197e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers if (!DexFile::Open(location, location, &error_msg, &dex_files)) { 198e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers LOG(FATAL) << "Could not open .dex file '" << location << "': " << error_msg << "\n"; 199fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler UNREACHABLE(); 200e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } else { 201e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK_EQ(1U, dex_files.size()) << "Expected only one dex file in " << location; 202fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler return std::move(dex_files[0]); 203e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 204e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 205e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 206e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersvoid CommonRuntimeTest::SetUp() { 2077747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe SetUpAndroidRoot(); 2087747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe SetUpAndroidData(android_data_); 209e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers dalvik_cache_.append(android_data_.c_str()); 210e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers dalvik_cache_.append("/dalvik-cache"); 211e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers int mkdir_result = mkdir(dalvik_cache_.c_str(), 0700); 212e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers ASSERT_EQ(mkdir_result, 0); 213e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 214e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers std::string min_heap_string(StringPrintf("-Xms%zdm", gc::Heap::kDefaultInitialSize / MB)); 215e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers std::string max_heap_string(StringPrintf("-Xmx%zdm", gc::Heap::kDefaultMaximumSize / MB)); 216e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 217e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers callbacks_.reset(new NoopCompilerCallbacks()); 218e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 219e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers RuntimeOptions options; 220c275259449ec57987e52d3ab1eda3272b994488fRichard Uhler std::string boot_class_path_string = "-Xbootclasspath:" + GetLibCoreDexFileName(); 221c275259449ec57987e52d3ab1eda3272b994488fRichard Uhler options.push_back(std::make_pair(boot_class_path_string, nullptr)); 222e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers options.push_back(std::make_pair("-Xcheck:jni", nullptr)); 223c275259449ec57987e52d3ab1eda3272b994488fRichard Uhler options.push_back(std::make_pair(min_heap_string, nullptr)); 224c275259449ec57987e52d3ab1eda3272b994488fRichard Uhler options.push_back(std::make_pair(max_heap_string, nullptr)); 225e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers options.push_back(std::make_pair("compilercallbacks", callbacks_.get())); 226e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers SetUpRuntimeOptions(&options); 227aaebaa0121be3b9d9f13630585304482cbcaeb4bIgor Murashkin 228e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers if (!Runtime::Create(options, false)) { 229e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers LOG(FATAL) << "Failed to create runtime"; 230e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers return; 231e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 232e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers runtime_.reset(Runtime::Current()); 233e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers class_linker_ = runtime_->GetClassLinker(); 234e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers class_linker_->FixupDexCaches(runtime_->GetResolutionMethod()); 235e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers class_linker_->RunRootClinits(); 236fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler boot_class_path_ = class_linker_->GetBootClassPath(); 237fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler java_lang_dex_file_ = boot_class_path_[0]; 238fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler 239e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 240e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // Runtime::Create acquired the mutator_lock_ that is normally given away when we 241e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // Runtime::Start, give it away now and then switch to a more managable ScopedObjectAccess. 242e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers Thread::Current()->TransitionFromRunnableToSuspended(kNative); 243e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 244e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // We're back in native, take the opportunity to initialize well known classes. 245e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers WellKnownClasses::Init(Thread::Current()->GetJniEnv()); 246e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 247e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // Create the heap thread pool so that the GC runs in parallel for tests. Normally, the thread 248e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // pool is created by the runtime. 249e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers runtime_->GetHeap()->CreateThreadPool(); 250e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers runtime_->GetHeap()->VerifyHeap(); // Check for heap corruption before the test 251c275259449ec57987e52d3ab1eda3272b994488fRichard Uhler 252c275259449ec57987e52d3ab1eda3272b994488fRichard Uhler // Get the boot class path from the runtime so it can be used in tests. 253c275259449ec57987e52d3ab1eda3272b994488fRichard Uhler boot_class_path_ = class_linker_->GetBootClassPath(); 254c275259449ec57987e52d3ab1eda3272b994488fRichard Uhler ASSERT_FALSE(boot_class_path_.empty()); 255c275259449ec57987e52d3ab1eda3272b994488fRichard Uhler java_lang_dex_file_ = boot_class_path_[0]; 256e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 257e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 258a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Lightvoid CommonRuntimeTest::ClearDirectory(const char* dirpath) { 259a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light ASSERT_TRUE(dirpath != nullptr); 260a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light DIR* dir = opendir(dirpath); 261e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers ASSERT_TRUE(dir != nullptr); 262e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers dirent* e; 263a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light struct stat s; 264e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers while ((e = readdir(dir)) != nullptr) { 265e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers if ((strcmp(e->d_name, ".") == 0) || (strcmp(e->d_name, "..") == 0)) { 266e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers continue; 267e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 268f0a3f09c3d54646166a55c05a6b39c7dd504129cJeff Hao std::string filename(dirpath); 269e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename.push_back('/'); 270e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename.append(e->d_name); 271a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light int stat_result = lstat(filename.c_str(), &s); 272a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light ASSERT_EQ(0, stat_result) << "unable to stat " << filename; 273a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light if (S_ISDIR(s.st_mode)) { 274a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light ClearDirectory(filename.c_str()); 275a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light int rmdir_result = rmdir(filename.c_str()); 276a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light ASSERT_EQ(0, rmdir_result) << filename; 277a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light } else { 278a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light int unlink_result = unlink(filename.c_str()); 279a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light ASSERT_EQ(0, unlink_result) << filename; 280a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light } 281e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 282e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers closedir(dir); 283a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light} 284a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light 285a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Lightvoid CommonRuntimeTest::TearDown() { 286a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light const char* android_data = getenv("ANDROID_DATA"); 287a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light ASSERT_TRUE(android_data != nullptr); 288a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light ClearDirectory(dalvik_cache_.c_str()); 289e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers int rmdir_cache_result = rmdir(dalvik_cache_.c_str()); 290e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers ASSERT_EQ(0, rmdir_cache_result); 2917747c8de402f64e3009ca3bcccebddbb70f617eeAndreas Gampe TearDownAndroidData(android_data_, true); 292e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 293e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // icu4c has a fixed 10-element array "gCommonICUDataArray". 294e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // If we run > 10 tests, we fill that array and u_setCommonData fails. 295e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // There's a function to clear the array, but it's not public... 296e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers typedef void (*IcuCleanupFn)(); 297e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers void* sym = dlsym(RTLD_DEFAULT, "u_cleanup_" U_ICU_VERSION_SHORT); 298e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK(sym != nullptr) << dlerror(); 299e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers IcuCleanupFn icu_cleanup_fn = reinterpret_cast<IcuCleanupFn>(sym); 300e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers (*icu_cleanup_fn)(); 301e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 302e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers Runtime::Current()->GetHeap()->VerifyHeap(); // Check for heap corruption after the test 303e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 304e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 305e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersstd::string CommonRuntimeTest::GetLibCoreDexFileName() { 306e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers return GetDexFileName("core-libart"); 307e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 308e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 309e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersstd::string CommonRuntimeTest::GetDexFileName(const std::string& jar_prefix) { 310e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers if (IsHost()) { 311e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers const char* host_dir = getenv("ANDROID_HOST_OUT"); 312e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK(host_dir != nullptr); 313e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers return StringPrintf("%s/framework/%s-hostdex.jar", host_dir, jar_prefix.c_str()); 314e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 315e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers return StringPrintf("%s/framework/%s.jar", GetAndroidRoot(), jar_prefix.c_str()); 316e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 317e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 318e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersstd::string CommonRuntimeTest::GetTestAndroidRoot() { 319e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers if (IsHost()) { 320e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers const char* host_dir = getenv("ANDROID_HOST_OUT"); 321e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK(host_dir != nullptr); 322e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers return host_dir; 323e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 324e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers return GetAndroidRoot(); 325e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 326e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 3271fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe// Check that for target builds we have ART_TARGET_NATIVETEST_DIR set. 3281fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe#ifdef ART_TARGET 3291fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe#ifndef ART_TARGET_NATIVETEST_DIR 3301fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe#error "ART_TARGET_NATIVETEST_DIR not set." 3311fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe#endif 3321fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe// Wrap it as a string literal. 3331fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe#define ART_TARGET_NATIVETEST_DIR_STRING STRINGIFY(ART_TARGET_NATIVETEST_DIR) "/" 3341fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe#else 3351fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe#define ART_TARGET_NATIVETEST_DIR_STRING "" 3361fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe#endif 3371fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe 338fbef44de596d298dc6430f482dffc933a046dd28Richard Uhlerstd::vector<std::unique_ptr<const DexFile>> CommonRuntimeTest::OpenTestDexFiles(const char* name) { 339e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK(name != nullptr); 340e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers std::string filename; 341e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers if (IsHost()) { 342e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename += getenv("ANDROID_HOST_OUT"); 343e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename += "/framework/"; 344e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } else { 3451fe5e5cce85a3cdc64a8d226a8ef4e6134c2b9ebAndreas Gampe filename += ART_TARGET_NATIVETEST_DIR_STRING; 346e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 347e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename += "art-gtest-"; 348e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename += name; 349e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers filename += ".jar"; 350e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers std::string error_msg; 351fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler std::vector<std::unique_ptr<const DexFile>> dex_files; 352e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers bool success = DexFile::Open(filename.c_str(), filename.c_str(), &error_msg, &dex_files); 353e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK(success) << "Failed to open '" << filename << "': " << error_msg; 354fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler for (auto& dex_file : dex_files) { 355e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK_EQ(PROT_READ, dex_file->GetPermissions()); 356e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK(dex_file->IsReadOnly()); 357e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 358e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers return dex_files; 359e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 360e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 361fbef44de596d298dc6430f482dffc933a046dd28Richard Uhlerstd::unique_ptr<const DexFile> CommonRuntimeTest::OpenTestDexFile(const char* name) { 362fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler std::vector<std::unique_ptr<const DexFile>> vector = OpenTestDexFiles(name); 363e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers EXPECT_EQ(1U, vector.size()); 364fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler return std::move(vector[0]); 365e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 366e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 367e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersjobject CommonRuntimeTest::LoadDex(const char* dex_name) { 368fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler std::vector<std::unique_ptr<const DexFile>> dex_files = OpenTestDexFiles(dex_name); 369fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler std::vector<const DexFile*> class_path; 370e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers CHECK_NE(0U, dex_files.size()); 371fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler for (auto& dex_file : dex_files) { 372fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler class_path.push_back(dex_file.get()); 373e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers class_linker_->RegisterDexFile(*dex_file); 374fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler loaded_dex_files_.push_back(std::move(dex_file)); 375e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers } 37668d8b42ddec39ec0174162d90d4abaa004d1983eIan Rogers Thread* self = Thread::Current(); 37768d8b42ddec39ec0174162d90d4abaa004d1983eIan Rogers JNIEnvExt* env = self->GetJniEnv(); 37868d8b42ddec39ec0174162d90d4abaa004d1983eIan Rogers ScopedLocalRef<jobject> class_loader_local(env, 37968d8b42ddec39ec0174162d90d4abaa004d1983eIan Rogers env->AllocObject(WellKnownClasses::dalvik_system_PathClassLoader)); 38068d8b42ddec39ec0174162d90d4abaa004d1983eIan Rogers jobject class_loader = env->NewGlobalRef(class_loader_local.get()); 38168d8b42ddec39ec0174162d90d4abaa004d1983eIan Rogers self->SetClassLoaderOverride(class_loader_local.get()); 382fbef44de596d298dc6430f482dffc933a046dd28Richard Uhler Runtime::Current()->SetCompileTimeClassPath(class_loader, class_path); 383e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers return class_loader; 384e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 385e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 3863774335b08076117d6950cd472cdd59a167470b5Igor Murashkinstd::string CommonRuntimeTest::GetCoreFileLocation(const char* suffix) { 3873774335b08076117d6950cd472cdd59a167470b5Igor Murashkin CHECK(suffix != nullptr); 3883774335b08076117d6950cd472cdd59a167470b5Igor Murashkin 3893774335b08076117d6950cd472cdd59a167470b5Igor Murashkin std::string location; 3903774335b08076117d6950cd472cdd59a167470b5Igor Murashkin if (IsHost()) { 3913774335b08076117d6950cd472cdd59a167470b5Igor Murashkin const char* host_dir = getenv("ANDROID_HOST_OUT"); 3923774335b08076117d6950cd472cdd59a167470b5Igor Murashkin CHECK(host_dir != NULL); 3933774335b08076117d6950cd472cdd59a167470b5Igor Murashkin location = StringPrintf("%s/framework/core.%s", host_dir, suffix); 3943774335b08076117d6950cd472cdd59a167470b5Igor Murashkin } else { 3953774335b08076117d6950cd472cdd59a167470b5Igor Murashkin location = StringPrintf("/data/art-test/core.%s", suffix); 3963774335b08076117d6950cd472cdd59a167470b5Igor Murashkin } 3973774335b08076117d6950cd472cdd59a167470b5Igor Murashkin 3983774335b08076117d6950cd472cdd59a167470b5Igor Murashkin return location; 3993774335b08076117d6950cd472cdd59a167470b5Igor Murashkin} 4003774335b08076117d6950cd472cdd59a167470b5Igor Murashkin 401e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian RogersCheckJniAbortCatcher::CheckJniAbortCatcher() : vm_(Runtime::Current()->GetJavaVM()) { 40268d8b42ddec39ec0174162d90d4abaa004d1983eIan Rogers vm_->SetCheckJniAbortHook(Hook, &actual_); 403e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 404e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 405e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian RogersCheckJniAbortCatcher::~CheckJniAbortCatcher() { 40668d8b42ddec39ec0174162d90d4abaa004d1983eIan Rogers vm_->SetCheckJniAbortHook(nullptr, nullptr); 407e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers EXPECT_TRUE(actual_.empty()) << actual_; 408e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 409e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 410e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersvoid CheckJniAbortCatcher::Check(const char* expected_text) { 411e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers EXPECT_TRUE(actual_.find(expected_text) != std::string::npos) << "\n" 412e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers << "Expected to find: " << expected_text << "\n" 413e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers << "In the output : " << actual_; 414e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers actual_.clear(); 415e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 416e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 417e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersvoid CheckJniAbortCatcher::Hook(void* data, const std::string& reason) { 418e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers // We use += because when we're hooking the aborts like this, multiple problems can be found. 419e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers *reinterpret_cast<std::string*>(data) += reason; 420e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 421e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 422e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} // namespace art 423e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 424e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersnamespace std { 425e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 426e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogerstemplate <typename T> 427e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersstd::ostream& operator<<(std::ostream& os, const std::vector<T>& rhs) { 428e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersos << ::art::ToString(rhs); 429e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogersreturn os; 430e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} 431e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers 432e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers} // namespace std 433