blob: ceae9e857b217bcbd67dcbec5fa79762bc176465 [file] [log] [blame]
Elliott Hugheseb02a122012-06-12 11:35:40 -07001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Ian Rogerse63db272014-07-15 15:36:11 -070017#include "common_runtime_test.h"
18
19#include <dirent.h>
20#include <dlfcn.h>
21#include <fcntl.h>
22#include <ScopedLocalRef.h>
Andreas Gampe369810a2015-01-14 19:53:31 -080023#include <stdlib.h>
Ian Rogerse63db272014-07-15 15:36:11 -070024
25#include "../../external/icu/icu4c/source/common/unicode/uvernum.h"
Andreas Gampe1fe5e5c2014-07-11 21:14:35 -070026#include "base/macros.h"
Elliott Hughes07ed66b2012-12-12 18:34:25 -080027#include "base/logging.h"
Ian Rogerse63db272014-07-15 15:36:11 -070028#include "base/stl_util.h"
29#include "base/stringprintf.h"
30#include "base/unix_file/fd_file.h"
31#include "class_linker.h"
32#include "compiler_callbacks.h"
33#include "dex_file.h"
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -070034#include "gc_root-inl.h"
Ian Rogerse63db272014-07-15 15:36:11 -070035#include "gc/heap.h"
Elliott Hugheseb02a122012-06-12 11:35:40 -070036#include "gtest/gtest.h"
Ian Rogerse63db272014-07-15 15:36:11 -070037#include "jni_internal.h"
38#include "mirror/class_loader.h"
Richard Uhler66d874d2015-01-15 09:37:19 -080039#include "mem_map.h"
Ian Rogerse63db272014-07-15 15:36:11 -070040#include "noop_compiler_callbacks.h"
41#include "os.h"
42#include "runtime-inl.h"
43#include "scoped_thread_state_change.h"
44#include "thread.h"
45#include "well_known_classes.h"
Elliott Hugheseb02a122012-06-12 11:35:40 -070046
47int main(int argc, char **argv) {
Andreas Gampe369810a2015-01-14 19:53:31 -080048 // Gtests can be very noisy. For example, an executable with multiple tests will trigger native
49 // bridge warnings. The following line reduces the minimum log severity to ERROR and suppresses
50 // everything else. In case you want to see all messages, comment out the line.
Richard Uhlerf45599d2015-03-10 08:38:31 -070051 // setenv("ANDROID_LOG_TAGS", "*:e", 1);
Andreas Gampe369810a2015-01-14 19:53:31 -080052
Elliott Hugheseb02a122012-06-12 11:35:40 -070053 art::InitLogging(argv);
Ian Rogersc7dd2952014-10-21 23:31:19 -070054 LOG(::art::INFO) << "Running main() from common_runtime_test.cc...";
Elliott Hugheseb02a122012-06-12 11:35:40 -070055 testing::InitGoogleTest(&argc, argv);
56 return RUN_ALL_TESTS();
57}
Ian Rogerse63db272014-07-15 15:36:11 -070058
59namespace art {
60
61ScratchFile::ScratchFile() {
62 // ANDROID_DATA needs to be set
63 CHECK_NE(static_cast<char*>(nullptr), getenv("ANDROID_DATA")) <<
64 "Are you subclassing RuntimeTest?";
65 filename_ = getenv("ANDROID_DATA");
66 filename_ += "/TmpFile-XXXXXX";
67 int fd = mkstemp(&filename_[0]);
68 CHECK_NE(-1, fd);
Andreas Gampe4303ba92014-11-06 01:00:46 -080069 file_.reset(new File(fd, GetFilename(), true));
Ian Rogerse63db272014-07-15 15:36:11 -070070}
71
72ScratchFile::ScratchFile(const ScratchFile& other, const char* suffix) {
73 filename_ = other.GetFilename();
74 filename_ += suffix;
75 int fd = open(filename_.c_str(), O_RDWR | O_CREAT, 0666);
76 CHECK_NE(-1, fd);
Andreas Gampe4303ba92014-11-06 01:00:46 -080077 file_.reset(new File(fd, GetFilename(), true));
Ian Rogerse63db272014-07-15 15:36:11 -070078}
79
80ScratchFile::ScratchFile(File* file) {
81 CHECK(file != NULL);
82 filename_ = file->GetPath();
83 file_.reset(file);
84}
85
86ScratchFile::~ScratchFile() {
87 Unlink();
88}
89
90int ScratchFile::GetFd() const {
91 return file_->Fd();
92}
93
Andreas Gampee21dc3d2014-12-08 16:59:43 -080094void ScratchFile::Close() {
Andreas Gampe4303ba92014-11-06 01:00:46 -080095 if (file_.get() != nullptr) {
96 if (file_->FlushCloseOrErase() != 0) {
97 PLOG(WARNING) << "Error closing scratch file.";
98 }
99 }
Andreas Gampee21dc3d2014-12-08 16:59:43 -0800100}
101
102void ScratchFile::Unlink() {
103 if (!OS::FileExists(filename_.c_str())) {
104 return;
105 }
106 Close();
Ian Rogerse63db272014-07-15 15:36:11 -0700107 int unlink_result = unlink(filename_.c_str());
108 CHECK_EQ(0, unlink_result);
109}
110
111CommonRuntimeTest::CommonRuntimeTest() {}
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800112CommonRuntimeTest::~CommonRuntimeTest() {
113 // Ensure the dex files are cleaned up before the runtime.
114 loaded_dex_files_.clear();
115 runtime_.reset();
116}
Ian Rogerse63db272014-07-15 15:36:11 -0700117
Andreas Gampe7747c8d2014-08-06 14:53:03 -0700118void CommonRuntimeTest::SetUpAndroidRoot() {
Ian Rogerse63db272014-07-15 15:36:11 -0700119 if (IsHost()) {
120 // $ANDROID_ROOT is set on the device, but not necessarily on the host.
121 // But it needs to be set so that icu4c can find its locale data.
122 const char* android_root_from_env = getenv("ANDROID_ROOT");
123 if (android_root_from_env == nullptr) {
124 // Use ANDROID_HOST_OUT for ANDROID_ROOT if it is set.
125 const char* android_host_out = getenv("ANDROID_HOST_OUT");
126 if (android_host_out != nullptr) {
127 setenv("ANDROID_ROOT", android_host_out, 1);
128 } else {
129 // Build it from ANDROID_BUILD_TOP or cwd
130 std::string root;
131 const char* android_build_top = getenv("ANDROID_BUILD_TOP");
132 if (android_build_top != nullptr) {
133 root += android_build_top;
134 } else {
135 // Not set by build server, so default to current directory
136 char* cwd = getcwd(nullptr, 0);
137 setenv("ANDROID_BUILD_TOP", cwd, 1);
138 root += cwd;
139 free(cwd);
140 }
141#if defined(__linux__)
142 root += "/out/host/linux-x86";
143#elif defined(__APPLE__)
144 root += "/out/host/darwin-x86";
145#else
146#error unsupported OS
147#endif
148 setenv("ANDROID_ROOT", root.c_str(), 1);
149 }
150 }
151 setenv("LD_LIBRARY_PATH", ":", 0); // Required by java.lang.System.<clinit>.
152
153 // Not set by build server, so default
154 if (getenv("ANDROID_HOST_OUT") == nullptr) {
155 setenv("ANDROID_HOST_OUT", getenv("ANDROID_ROOT"), 1);
156 }
157 }
Andreas Gampe7747c8d2014-08-06 14:53:03 -0700158}
Ian Rogerse63db272014-07-15 15:36:11 -0700159
Andreas Gampe7747c8d2014-08-06 14:53:03 -0700160void CommonRuntimeTest::SetUpAndroidData(std::string& android_data) {
Ian Rogerse63db272014-07-15 15:36:11 -0700161 // On target, Cannot use /mnt/sdcard because it is mounted noexec, so use subdir of dalvik-cache
Andreas Gampe5a79fde2014-08-06 13:12:26 -0700162 if (IsHost()) {
163 const char* tmpdir = getenv("TMPDIR");
164 if (tmpdir != nullptr && tmpdir[0] != 0) {
165 android_data = tmpdir;
166 } else {
167 android_data = "/tmp";
168 }
169 } else {
170 android_data = "/data/dalvik-cache";
171 }
172 android_data += "/art-data-XXXXXX";
Ian Rogerse63db272014-07-15 15:36:11 -0700173 if (mkdtemp(&android_data[0]) == nullptr) {
174 PLOG(FATAL) << "mkdtemp(\"" << &android_data[0] << "\") failed";
175 }
176 setenv("ANDROID_DATA", android_data.c_str(), 1);
177}
178
Andreas Gampe7747c8d2014-08-06 14:53:03 -0700179void CommonRuntimeTest::TearDownAndroidData(const std::string& android_data, bool fail_on_error) {
180 if (fail_on_error) {
181 ASSERT_EQ(rmdir(android_data.c_str()), 0);
182 } else {
183 rmdir(android_data.c_str());
184 }
185}
186
Igor Murashkin37743352014-11-13 14:38:00 -0800187std::string CommonRuntimeTest::GetCoreArtLocation() {
188 return GetCoreFileLocation("art");
189}
190
191std::string CommonRuntimeTest::GetCoreOatLocation() {
192 return GetCoreFileLocation("oat");
193}
Andreas Gampe7747c8d2014-08-06 14:53:03 -0700194
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800195std::unique_ptr<const DexFile> CommonRuntimeTest::LoadExpectSingleDexFile(const char* location) {
196 std::vector<std::unique_ptr<const DexFile>> dex_files;
Ian Rogerse63db272014-07-15 15:36:11 -0700197 std::string error_msg;
Richard Uhler66d874d2015-01-15 09:37:19 -0800198 MemMap::Init();
Ian Rogerse63db272014-07-15 15:36:11 -0700199 if (!DexFile::Open(location, location, &error_msg, &dex_files)) {
200 LOG(FATAL) << "Could not open .dex file '" << location << "': " << error_msg << "\n";
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800201 UNREACHABLE();
Ian Rogerse63db272014-07-15 15:36:11 -0700202 } else {
203 CHECK_EQ(1U, dex_files.size()) << "Expected only one dex file in " << location;
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800204 return std::move(dex_files[0]);
Ian Rogerse63db272014-07-15 15:36:11 -0700205 }
206}
207
208void CommonRuntimeTest::SetUp() {
Andreas Gampe7747c8d2014-08-06 14:53:03 -0700209 SetUpAndroidRoot();
210 SetUpAndroidData(android_data_);
Ian Rogerse63db272014-07-15 15:36:11 -0700211 dalvik_cache_.append(android_data_.c_str());
212 dalvik_cache_.append("/dalvik-cache");
213 int mkdir_result = mkdir(dalvik_cache_.c_str(), 0700);
214 ASSERT_EQ(mkdir_result, 0);
215
Ian Rogerse63db272014-07-15 15:36:11 -0700216 std::string min_heap_string(StringPrintf("-Xms%zdm", gc::Heap::kDefaultInitialSize / MB));
217 std::string max_heap_string(StringPrintf("-Xmx%zdm", gc::Heap::kDefaultMaximumSize / MB));
218
219 callbacks_.reset(new NoopCompilerCallbacks());
220
221 RuntimeOptions options;
Richard Uhlerc2752592015-01-02 13:28:22 -0800222 std::string boot_class_path_string = "-Xbootclasspath:" + GetLibCoreDexFileName();
223 options.push_back(std::make_pair(boot_class_path_string, nullptr));
Ian Rogerse63db272014-07-15 15:36:11 -0700224 options.push_back(std::make_pair("-Xcheck:jni", nullptr));
Richard Uhlerc2752592015-01-02 13:28:22 -0800225 options.push_back(std::make_pair(min_heap_string, nullptr));
226 options.push_back(std::make_pair(max_heap_string, nullptr));
Ian Rogerse63db272014-07-15 15:36:11 -0700227 options.push_back(std::make_pair("compilercallbacks", callbacks_.get()));
228 SetUpRuntimeOptions(&options);
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800229
Richard Uhler66d874d2015-01-15 09:37:19 -0800230 PreRuntimeCreate();
Ian Rogerse63db272014-07-15 15:36:11 -0700231 if (!Runtime::Create(options, false)) {
232 LOG(FATAL) << "Failed to create runtime";
233 return;
234 }
Richard Uhler66d874d2015-01-15 09:37:19 -0800235 PostRuntimeCreate();
Ian Rogerse63db272014-07-15 15:36:11 -0700236 runtime_.reset(Runtime::Current());
237 class_linker_ = runtime_->GetClassLinker();
238 class_linker_->FixupDexCaches(runtime_->GetResolutionMethod());
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700239
240 // Initialize maps for unstarted runtime. This needs to be here, as running clinits needs this
241 // set up.
242 interpreter::UnstartedRuntimeInitialize();
243
Ian Rogerse63db272014-07-15 15:36:11 -0700244 class_linker_->RunRootClinits();
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800245 boot_class_path_ = class_linker_->GetBootClassPath();
246 java_lang_dex_file_ = boot_class_path_[0];
247
Ian Rogerse63db272014-07-15 15:36:11 -0700248
249 // Runtime::Create acquired the mutator_lock_ that is normally given away when we
250 // Runtime::Start, give it away now and then switch to a more managable ScopedObjectAccess.
251 Thread::Current()->TransitionFromRunnableToSuspended(kNative);
252
253 // We're back in native, take the opportunity to initialize well known classes.
254 WellKnownClasses::Init(Thread::Current()->GetJniEnv());
255
256 // Create the heap thread pool so that the GC runs in parallel for tests. Normally, the thread
257 // pool is created by the runtime.
258 runtime_->GetHeap()->CreateThreadPool();
259 runtime_->GetHeap()->VerifyHeap(); // Check for heap corruption before the test
Richard Uhlerc2752592015-01-02 13:28:22 -0800260
261 // Get the boot class path from the runtime so it can be used in tests.
262 boot_class_path_ = class_linker_->GetBootClassPath();
263 ASSERT_FALSE(boot_class_path_.empty());
264 java_lang_dex_file_ = boot_class_path_[0];
Ian Rogerse63db272014-07-15 15:36:11 -0700265}
266
Alex Lighta59dd802014-07-02 16:28:08 -0700267void CommonRuntimeTest::ClearDirectory(const char* dirpath) {
268 ASSERT_TRUE(dirpath != nullptr);
269 DIR* dir = opendir(dirpath);
Ian Rogerse63db272014-07-15 15:36:11 -0700270 ASSERT_TRUE(dir != nullptr);
271 dirent* e;
Alex Lighta59dd802014-07-02 16:28:08 -0700272 struct stat s;
Ian Rogerse63db272014-07-15 15:36:11 -0700273 while ((e = readdir(dir)) != nullptr) {
274 if ((strcmp(e->d_name, ".") == 0) || (strcmp(e->d_name, "..") == 0)) {
275 continue;
276 }
Jeff Haof0a3f092014-07-24 16:26:09 -0700277 std::string filename(dirpath);
Ian Rogerse63db272014-07-15 15:36:11 -0700278 filename.push_back('/');
279 filename.append(e->d_name);
Alex Lighta59dd802014-07-02 16:28:08 -0700280 int stat_result = lstat(filename.c_str(), &s);
281 ASSERT_EQ(0, stat_result) << "unable to stat " << filename;
282 if (S_ISDIR(s.st_mode)) {
283 ClearDirectory(filename.c_str());
284 int rmdir_result = rmdir(filename.c_str());
285 ASSERT_EQ(0, rmdir_result) << filename;
286 } else {
287 int unlink_result = unlink(filename.c_str());
288 ASSERT_EQ(0, unlink_result) << filename;
289 }
Ian Rogerse63db272014-07-15 15:36:11 -0700290 }
291 closedir(dir);
Alex Lighta59dd802014-07-02 16:28:08 -0700292}
293
294void CommonRuntimeTest::TearDown() {
295 const char* android_data = getenv("ANDROID_DATA");
296 ASSERT_TRUE(android_data != nullptr);
297 ClearDirectory(dalvik_cache_.c_str());
Ian Rogerse63db272014-07-15 15:36:11 -0700298 int rmdir_cache_result = rmdir(dalvik_cache_.c_str());
299 ASSERT_EQ(0, rmdir_cache_result);
Andreas Gampe7747c8d2014-08-06 14:53:03 -0700300 TearDownAndroidData(android_data_, true);
Ian Rogerse63db272014-07-15 15:36:11 -0700301
302 // icu4c has a fixed 10-element array "gCommonICUDataArray".
303 // If we run > 10 tests, we fill that array and u_setCommonData fails.
304 // There's a function to clear the array, but it's not public...
305 typedef void (*IcuCleanupFn)();
306 void* sym = dlsym(RTLD_DEFAULT, "u_cleanup_" U_ICU_VERSION_SHORT);
307 CHECK(sym != nullptr) << dlerror();
308 IcuCleanupFn icu_cleanup_fn = reinterpret_cast<IcuCleanupFn>(sym);
309 (*icu_cleanup_fn)();
310
Ian Rogerse63db272014-07-15 15:36:11 -0700311 Runtime::Current()->GetHeap()->VerifyHeap(); // Check for heap corruption after the test
312}
313
314std::string CommonRuntimeTest::GetLibCoreDexFileName() {
315 return GetDexFileName("core-libart");
316}
317
318std::string CommonRuntimeTest::GetDexFileName(const std::string& jar_prefix) {
319 if (IsHost()) {
320 const char* host_dir = getenv("ANDROID_HOST_OUT");
321 CHECK(host_dir != nullptr);
322 return StringPrintf("%s/framework/%s-hostdex.jar", host_dir, jar_prefix.c_str());
323 }
324 return StringPrintf("%s/framework/%s.jar", GetAndroidRoot(), jar_prefix.c_str());
325}
326
327std::string CommonRuntimeTest::GetTestAndroidRoot() {
328 if (IsHost()) {
329 const char* host_dir = getenv("ANDROID_HOST_OUT");
330 CHECK(host_dir != nullptr);
331 return host_dir;
332 }
333 return GetAndroidRoot();
334}
335
Andreas Gampe1fe5e5c2014-07-11 21:14:35 -0700336// Check that for target builds we have ART_TARGET_NATIVETEST_DIR set.
337#ifdef ART_TARGET
338#ifndef ART_TARGET_NATIVETEST_DIR
339#error "ART_TARGET_NATIVETEST_DIR not set."
340#endif
341// Wrap it as a string literal.
342#define ART_TARGET_NATIVETEST_DIR_STRING STRINGIFY(ART_TARGET_NATIVETEST_DIR) "/"
343#else
344#define ART_TARGET_NATIVETEST_DIR_STRING ""
345#endif
346
Richard Uhler66d874d2015-01-15 09:37:19 -0800347std::string CommonRuntimeTest::GetTestDexFileName(const char* name) {
Ian Rogerse63db272014-07-15 15:36:11 -0700348 CHECK(name != nullptr);
349 std::string filename;
350 if (IsHost()) {
351 filename += getenv("ANDROID_HOST_OUT");
352 filename += "/framework/";
353 } else {
Andreas Gampe1fe5e5c2014-07-11 21:14:35 -0700354 filename += ART_TARGET_NATIVETEST_DIR_STRING;
Ian Rogerse63db272014-07-15 15:36:11 -0700355 }
356 filename += "art-gtest-";
357 filename += name;
358 filename += ".jar";
Richard Uhler66d874d2015-01-15 09:37:19 -0800359 return filename;
360}
361
362std::vector<std::unique_ptr<const DexFile>> CommonRuntimeTest::OpenTestDexFiles(const char* name) {
363 std::string filename = GetTestDexFileName(name);
Ian Rogerse63db272014-07-15 15:36:11 -0700364 std::string error_msg;
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800365 std::vector<std::unique_ptr<const DexFile>> dex_files;
Ian Rogerse63db272014-07-15 15:36:11 -0700366 bool success = DexFile::Open(filename.c_str(), filename.c_str(), &error_msg, &dex_files);
367 CHECK(success) << "Failed to open '" << filename << "': " << error_msg;
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800368 for (auto& dex_file : dex_files) {
Ian Rogerse63db272014-07-15 15:36:11 -0700369 CHECK_EQ(PROT_READ, dex_file->GetPermissions());
370 CHECK(dex_file->IsReadOnly());
371 }
Ian Rogerse63db272014-07-15 15:36:11 -0700372 return dex_files;
373}
374
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800375std::unique_ptr<const DexFile> CommonRuntimeTest::OpenTestDexFile(const char* name) {
376 std::vector<std::unique_ptr<const DexFile>> vector = OpenTestDexFiles(name);
Ian Rogerse63db272014-07-15 15:36:11 -0700377 EXPECT_EQ(1U, vector.size());
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800378 return std::move(vector[0]);
Ian Rogerse63db272014-07-15 15:36:11 -0700379}
380
381jobject CommonRuntimeTest::LoadDex(const char* dex_name) {
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800382 std::vector<std::unique_ptr<const DexFile>> dex_files = OpenTestDexFiles(dex_name);
383 std::vector<const DexFile*> class_path;
Ian Rogerse63db272014-07-15 15:36:11 -0700384 CHECK_NE(0U, dex_files.size());
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800385 for (auto& dex_file : dex_files) {
386 class_path.push_back(dex_file.get());
Ian Rogerse63db272014-07-15 15:36:11 -0700387 class_linker_->RegisterDexFile(*dex_file);
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800388 loaded_dex_files_.push_back(std::move(dex_file));
Ian Rogerse63db272014-07-15 15:36:11 -0700389 }
Ian Rogers68d8b422014-07-17 11:09:10 -0700390 Thread* self = Thread::Current();
391 JNIEnvExt* env = self->GetJniEnv();
392 ScopedLocalRef<jobject> class_loader_local(env,
393 env->AllocObject(WellKnownClasses::dalvik_system_PathClassLoader));
394 jobject class_loader = env->NewGlobalRef(class_loader_local.get());
395 self->SetClassLoaderOverride(class_loader_local.get());
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800396 Runtime::Current()->SetCompileTimeClassPath(class_loader, class_path);
Ian Rogerse63db272014-07-15 15:36:11 -0700397 return class_loader;
398}
399
Igor Murashkin37743352014-11-13 14:38:00 -0800400std::string CommonRuntimeTest::GetCoreFileLocation(const char* suffix) {
401 CHECK(suffix != nullptr);
402
403 std::string location;
404 if (IsHost()) {
405 const char* host_dir = getenv("ANDROID_HOST_OUT");
406 CHECK(host_dir != NULL);
407 location = StringPrintf("%s/framework/core.%s", host_dir, suffix);
408 } else {
409 location = StringPrintf("/data/art-test/core.%s", suffix);
410 }
411
412 return location;
413}
414
Ian Rogerse63db272014-07-15 15:36:11 -0700415CheckJniAbortCatcher::CheckJniAbortCatcher() : vm_(Runtime::Current()->GetJavaVM()) {
Ian Rogers68d8b422014-07-17 11:09:10 -0700416 vm_->SetCheckJniAbortHook(Hook, &actual_);
Ian Rogerse63db272014-07-15 15:36:11 -0700417}
418
419CheckJniAbortCatcher::~CheckJniAbortCatcher() {
Ian Rogers68d8b422014-07-17 11:09:10 -0700420 vm_->SetCheckJniAbortHook(nullptr, nullptr);
Ian Rogerse63db272014-07-15 15:36:11 -0700421 EXPECT_TRUE(actual_.empty()) << actual_;
422}
423
424void CheckJniAbortCatcher::Check(const char* expected_text) {
425 EXPECT_TRUE(actual_.find(expected_text) != std::string::npos) << "\n"
426 << "Expected to find: " << expected_text << "\n"
427 << "In the output : " << actual_;
428 actual_.clear();
429}
430
431void CheckJniAbortCatcher::Hook(void* data, const std::string& reason) {
432 // We use += because when we're hooking the aborts like this, multiple problems can be found.
433 *reinterpret_cast<std::string*>(data) += reason;
434}
435
436} // namespace art
437
438namespace std {
439
440template <typename T>
441std::ostream& operator<<(std::ostream& os, const std::vector<T>& rhs) {
442os << ::art::ToString(rhs);
443return os;
444}
445
446} // namespace std