blob: 8fdf8aa0cd9fe45280e39059e51e1c51b5f35eee [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>
Andreas Gampe369810a2015-01-14 19:53:31 -080022#include <stdlib.h>
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070023#include <cstdio>
Andreas Gampe373a9b52017-10-18 09:01:57 -070024#include "nativehelper/scoped_local_ref.h"
Ian Rogerse63db272014-07-15 15:36:11 -070025
Andreas Gampe46ee31b2016-12-14 10:11:49 -080026#include "android-base/stringprintf.h"
Andreas Gampefdb7a612017-11-01 15:11:13 -070027#include <unicode/uvernum.h>
Andreas Gampe46ee31b2016-12-14 10:11:49 -080028
Mathieu Chartiere401d142015-04-22 13:56:20 -070029#include "art_field-inl.h"
David Sehr891a50e2017-10-27 17:01:07 -070030#include "base/file_utils.h"
Elliott Hughes07ed66b2012-12-12 18:34:25 -080031#include "base/logging.h"
Steven Morelande431e272017-07-18 16:53:49 -070032#include "base/macros.h"
David Sehr79e26072018-04-06 17:58:50 -070033#include "base/mem_map.h"
David Sehrc431b9d2018-03-02 12:01:51 -080034#include "base/mutex.h"
35#include "base/os.h"
Andreas Gampedcc528d2017-12-07 13:37:10 -080036#include "base/runtime_debug.h"
Ian Rogerse63db272014-07-15 15:36:11 -070037#include "base/stl_util.h"
Ian Rogerse63db272014-07-15 15:36:11 -070038#include "base/unix_file/fd_file.h"
39#include "class_linker.h"
Andreas Gampeb8e7c372018-02-20 18:24:55 -080040#include "class_loader_utils.h"
Ian Rogerse63db272014-07-15 15:36:11 -070041#include "compiler_callbacks.h"
David Sehr013fd802018-01-11 22:55:24 -080042#include "dex/art_dex_file_loader.h"
David Sehr9e734c72018-01-04 17:56:19 -080043#include "dex/dex_file-inl.h"
44#include "dex/dex_file_loader.h"
David Sehr67bf42e2018-02-26 16:43:04 -080045#include "dex/primitive.h"
Ian Rogerse63db272014-07-15 15:36:11 -070046#include "gc/heap.h"
Steven Morelande431e272017-07-18 16:53:49 -070047#include "gc_root-inl.h"
Elliott Hugheseb02a122012-06-12 11:35:40 -070048#include "gtest/gtest.h"
Andreas Gampe81c6f8d2015-03-25 17:19:53 -070049#include "handle_scope-inl.h"
Andreas Gampe9b5cba42015-03-11 09:53:50 -070050#include "interpreter/unstarted_runtime.h"
Vladimir Markoa3ad0cd2018-05-04 10:06:38 +010051#include "jni/java_vm_ext.h"
52#include "jni/jni_internal.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070053#include "mirror/class-inl.h"
Ian Rogerse63db272014-07-15 15:36:11 -070054#include "mirror/class_loader.h"
Andreas Gampe52ecb652018-10-24 15:18:21 -070055#include "mirror/object_array-alloc-inl.h"
Mathieu Chartiere58991b2015-10-13 07:59:34 -070056#include "native/dalvik_system_DexFile.h"
Ian Rogerse63db272014-07-15 15:36:11 -070057#include "noop_compiler_callbacks.h"
Ian Rogerse63db272014-07-15 15:36:11 -070058#include "runtime-inl.h"
Mathieu Chartier0795f232016-09-27 18:43:30 -070059#include "scoped_thread_state_change-inl.h"
Ian Rogerse63db272014-07-15 15:36:11 -070060#include "thread.h"
61#include "well_known_classes.h"
Elliott Hugheseb02a122012-06-12 11:35:40 -070062
Ian Rogerse63db272014-07-15 15:36:11 -070063namespace art {
64
Andreas Gampe46ee31b2016-12-14 10:11:49 -080065using android::base::StringPrintf;
66
Andreas Gampe9b5cba42015-03-11 09:53:50 -070067static bool unstarted_initialized_ = false;
68
Andreas Gampe48864112017-01-19 17:23:17 -080069CommonRuntimeTestImpl::CommonRuntimeTestImpl()
70 : class_linker_(nullptr), java_lang_dex_file_(nullptr) {
71}
Mathieu Chartier91c91162016-01-15 09:48:15 -080072
73CommonRuntimeTestImpl::~CommonRuntimeTestImpl() {
Richard Uhlerfbef44d2014-12-23 09:48:51 -080074 // Ensure the dex files are cleaned up before the runtime.
75 loaded_dex_files_.clear();
76 runtime_.reset();
77}
Ian Rogerse63db272014-07-15 15:36:11 -070078
Mathieu Chartier91c91162016-01-15 09:48:15 -080079std::string CommonRuntimeTestImpl::GetAndroidTargetToolsDir(InstructionSet isa) {
David Srbecky3e52aa42015-04-12 07:45:18 +010080 switch (isa) {
Vladimir Marko33bff252017-11-01 14:35:42 +000081 case InstructionSet::kArm:
82 case InstructionSet::kThumb2:
David Srbecky3e52aa42015-04-12 07:45:18 +010083 return GetAndroidToolsDir("prebuilts/gcc/linux-x86/arm",
84 "arm-linux-androideabi",
85 "arm-linux-androideabi");
Vladimir Marko33bff252017-11-01 14:35:42 +000086 case InstructionSet::kArm64:
David Srbecky3e52aa42015-04-12 07:45:18 +010087 return GetAndroidToolsDir("prebuilts/gcc/linux-x86/aarch64",
88 "aarch64-linux-android",
89 "aarch64-linux-android");
Vladimir Marko33bff252017-11-01 14:35:42 +000090 case InstructionSet::kX86:
91 case InstructionSet::kX86_64:
David Srbecky3e52aa42015-04-12 07:45:18 +010092 return GetAndroidToolsDir("prebuilts/gcc/linux-x86/x86",
93 "x86_64-linux-android",
94 "x86_64-linux-android");
Vladimir Marko33bff252017-11-01 14:35:42 +000095 case InstructionSet::kMips:
96 case InstructionSet::kMips64:
David Srbecky3e52aa42015-04-12 07:45:18 +010097 return GetAndroidToolsDir("prebuilts/gcc/linux-x86/mips",
98 "mips64el-linux-android",
99 "mips64el-linux-android");
Vladimir Marko33bff252017-11-01 14:35:42 +0000100 case InstructionSet::kNone:
David Srbecky3e52aa42015-04-12 07:45:18 +0100101 break;
102 }
103 ADD_FAILURE() << "Invalid isa " << isa;
104 return "";
105}
106
Mathieu Chartier91c91162016-01-15 09:48:15 -0800107void CommonRuntimeTestImpl::SetUp() {
David Sehrd5f8de82018-04-27 14:12:03 -0700108 CommonArtTestImpl::SetUp();
Ian Rogerse63db272014-07-15 15:36:11 -0700109
Ian Rogerse63db272014-07-15 15:36:11 -0700110 std::string min_heap_string(StringPrintf("-Xms%zdm", gc::Heap::kDefaultInitialSize / MB));
111 std::string max_heap_string(StringPrintf("-Xmx%zdm", gc::Heap::kDefaultMaximumSize / MB));
112
Ian Rogerse63db272014-07-15 15:36:11 -0700113
114 RuntimeOptions options;
Narayan Kamathd1ef4362015-11-12 11:49:06 +0000115 std::string boot_class_path_string = "-Xbootclasspath";
116 for (const std::string &core_dex_file_name : GetLibCoreDexFileNames()) {
117 boot_class_path_string += ":";
118 boot_class_path_string += core_dex_file_name;
119 }
120
Richard Uhlerc2752592015-01-02 13:28:22 -0800121 options.push_back(std::make_pair(boot_class_path_string, nullptr));
Ian Rogerse63db272014-07-15 15:36:11 -0700122 options.push_back(std::make_pair("-Xcheck:jni", nullptr));
Richard Uhlerc2752592015-01-02 13:28:22 -0800123 options.push_back(std::make_pair(min_heap_string, nullptr));
124 options.push_back(std::make_pair(max_heap_string, nullptr));
Andreas Gampe1c5b42f2017-06-15 18:20:45 -0700125 options.push_back(std::make_pair("-XX:SlowDebug=true", nullptr));
Andreas Gampe46c4c852017-06-21 19:49:08 -0700126 static bool gSlowDebugTestFlag = false;
127 RegisterRuntimeDebugFlag(&gSlowDebugTestFlag);
Andreas Gampebb9c6b12015-03-29 13:56:36 -0700128
129 callbacks_.reset(new NoopCompilerCallbacks());
130
Ian Rogerse63db272014-07-15 15:36:11 -0700131 SetUpRuntimeOptions(&options);
Igor Murashkinaaebaa02015-01-26 10:55:53 -0800132
Andreas Gampebb9c6b12015-03-29 13:56:36 -0700133 // Install compiler-callbacks if SetupRuntimeOptions hasn't deleted them.
134 if (callbacks_.get() != nullptr) {
135 options.push_back(std::make_pair("compilercallbacks", callbacks_.get()));
136 }
137
Richard Uhler66d874d2015-01-15 09:37:19 -0800138 PreRuntimeCreate();
Ian Rogerse63db272014-07-15 15:36:11 -0700139 if (!Runtime::Create(options, false)) {
140 LOG(FATAL) << "Failed to create runtime";
141 return;
142 }
Richard Uhler66d874d2015-01-15 09:37:19 -0800143 PostRuntimeCreate();
Ian Rogerse63db272014-07-15 15:36:11 -0700144 runtime_.reset(Runtime::Current());
145 class_linker_ = runtime_->GetClassLinker();
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700146
Andreas Gampea00f0122015-12-16 16:54:35 -0800147 // Runtime::Create acquired the mutator_lock_ that is normally given away when we
148 // Runtime::Start, give it away now and then switch to a more managable ScopedObjectAccess.
149 Thread::Current()->TransitionFromRunnableToSuspended(kNative);
150
151 // Get the boot class path from the runtime so it can be used in tests.
152 boot_class_path_ = class_linker_->GetBootClassPath();
153 ASSERT_FALSE(boot_class_path_.empty());
154 java_lang_dex_file_ = boot_class_path_[0];
155
156 FinalizeSetup();
Andreas Gampe46c4c852017-06-21 19:49:08 -0700157
158 // Ensure that we're really running with debug checks enabled.
159 CHECK(gSlowDebugTestFlag);
Andreas Gampea00f0122015-12-16 16:54:35 -0800160}
161
Mathieu Chartier91c91162016-01-15 09:48:15 -0800162void CommonRuntimeTestImpl::FinalizeSetup() {
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700163 // Initialize maps for unstarted runtime. This needs to be here, as running clinits needs this
164 // set up.
Andreas Gampe9b5cba42015-03-11 09:53:50 -0700165 if (!unstarted_initialized_) {
Andreas Gampe799681b2015-05-15 19:24:12 -0700166 interpreter::UnstartedRuntime::Initialize();
Andreas Gampe9b5cba42015-03-11 09:53:50 -0700167 unstarted_initialized_ = true;
168 }
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700169
Andreas Gampea00f0122015-12-16 16:54:35 -0800170 {
171 ScopedObjectAccess soa(Thread::Current());
Vladimir Markodcfcce42018-06-27 10:00:28 +0000172 runtime_->RunRootClinits(soa.Self());
Andreas Gampea00f0122015-12-16 16:54:35 -0800173 }
Ian Rogerse63db272014-07-15 15:36:11 -0700174
175 // We're back in native, take the opportunity to initialize well known classes.
176 WellKnownClasses::Init(Thread::Current()->GetJniEnv());
177
178 // Create the heap thread pool so that the GC runs in parallel for tests. Normally, the thread
179 // pool is created by the runtime.
180 runtime_->GetHeap()->CreateThreadPool();
181 runtime_->GetHeap()->VerifyHeap(); // Check for heap corruption before the test
Hiroshi Yamauchi4460a842015-03-09 11:57:48 -0700182 // Reduce timinig-dependent flakiness in OOME behavior (eg StubTest.AllocObject).
183 runtime_->GetHeap()->SetMinIntervalHomogeneousSpaceCompactionByOom(0U);
Ian Rogerse63db272014-07-15 15:36:11 -0700184}
185
Mathieu Chartier91c91162016-01-15 09:48:15 -0800186void CommonRuntimeTestImpl::TearDown() {
David Sehrd5f8de82018-04-27 14:12:03 -0700187 CommonArtTestImpl::TearDown();
Andreas Gampe48864112017-01-19 17:23:17 -0800188 if (runtime_ != nullptr) {
189 runtime_->GetHeap()->VerifyHeap(); // Check for heap corruption after the test
190 }
Ian Rogerse63db272014-07-15 15:36:11 -0700191}
192
Andreas Gampe1fe5e5c2014-07-11 21:14:35 -0700193// Check that for target builds we have ART_TARGET_NATIVETEST_DIR set.
194#ifdef ART_TARGET
195#ifndef ART_TARGET_NATIVETEST_DIR
196#error "ART_TARGET_NATIVETEST_DIR not set."
197#endif
198// Wrap it as a string literal.
199#define ART_TARGET_NATIVETEST_DIR_STRING STRINGIFY(ART_TARGET_NATIVETEST_DIR) "/"
200#else
201#define ART_TARGET_NATIVETEST_DIR_STRING ""
202#endif
203
Mathieu Chartier91c91162016-01-15 09:48:15 -0800204std::vector<const DexFile*> CommonRuntimeTestImpl::GetDexFiles(jobject jclass_loader) {
Andreas Gampe81c6f8d2015-03-25 17:19:53 -0700205 ScopedObjectAccess soa(Thread::Current());
206
Calin Juravlec79470d2017-07-12 17:37:42 -0700207 StackHandleScope<1> hs(soa.Self());
Andreas Gampe81c6f8d2015-03-25 17:19:53 -0700208 Handle<mirror::ClassLoader> class_loader = hs.NewHandle(
Mathieu Chartier0795f232016-09-27 18:43:30 -0700209 soa.Decode<mirror::ClassLoader>(jclass_loader));
Calin Juravlec79470d2017-07-12 17:37:42 -0700210 return GetDexFiles(soa, class_loader);
211}
Andreas Gampe81c6f8d2015-03-25 17:19:53 -0700212
Calin Juravlec79470d2017-07-12 17:37:42 -0700213std::vector<const DexFile*> CommonRuntimeTestImpl::GetDexFiles(
214 ScopedObjectAccess& soa,
215 Handle<mirror::ClassLoader> class_loader) {
Calin Juravlec79470d2017-07-12 17:37:42 -0700216 DCHECK(
217 (class_loader->GetClass() ==
218 soa.Decode<mirror::Class>(WellKnownClasses::dalvik_system_PathClassLoader)) ||
219 (class_loader->GetClass() ==
220 soa.Decode<mirror::Class>(WellKnownClasses::dalvik_system_DelegateLastClassLoader)));
Andreas Gampe81c6f8d2015-03-25 17:19:53 -0700221
Andreas Gampeb8e7c372018-02-20 18:24:55 -0800222 std::vector<const DexFile*> ret;
223 VisitClassLoaderDexFiles(soa,
224 class_loader,
225 [&](const DexFile* cp_dex_file) {
226 if (cp_dex_file == nullptr) {
227 LOG(WARNING) << "Null DexFile";
228 } else {
229 ret.push_back(cp_dex_file);
230 }
231 return true;
232 });
Andreas Gampe81c6f8d2015-03-25 17:19:53 -0700233 return ret;
234}
235
Mathieu Chartier91c91162016-01-15 09:48:15 -0800236const DexFile* CommonRuntimeTestImpl::GetFirstDexFile(jobject jclass_loader) {
Andreas Gampe81c6f8d2015-03-25 17:19:53 -0700237 std::vector<const DexFile*> tmp(GetDexFiles(jclass_loader));
238 DCHECK(!tmp.empty());
239 const DexFile* ret = tmp[0];
240 DCHECK(ret != nullptr);
241 return ret;
242}
243
Nicolas Geoffrayd01f60c2016-10-28 14:45:48 +0100244jobject CommonRuntimeTestImpl::LoadMultiDex(const char* first_dex_name,
245 const char* second_dex_name) {
246 std::vector<std::unique_ptr<const DexFile>> first_dex_files = OpenTestDexFiles(first_dex_name);
247 std::vector<std::unique_ptr<const DexFile>> second_dex_files = OpenTestDexFiles(second_dex_name);
248 std::vector<const DexFile*> class_path;
249 CHECK_NE(0U, first_dex_files.size());
250 CHECK_NE(0U, second_dex_files.size());
251 for (auto& dex_file : first_dex_files) {
252 class_path.push_back(dex_file.get());
253 loaded_dex_files_.push_back(std::move(dex_file));
254 }
255 for (auto& dex_file : second_dex_files) {
256 class_path.push_back(dex_file.get());
257 loaded_dex_files_.push_back(std::move(dex_file));
258 }
259
260 Thread* self = Thread::Current();
261 jobject class_loader = Runtime::Current()->GetClassLinker()->CreatePathClassLoader(self,
262 class_path);
263 self->SetClassLoaderOverride(class_loader);
264 return class_loader;
265}
266
Mathieu Chartier91c91162016-01-15 09:48:15 -0800267jobject CommonRuntimeTestImpl::LoadDex(const char* dex_name) {
Calin Juravle7865ac72017-06-28 11:03:12 -0700268 jobject class_loader = LoadDexInPathClassLoader(dex_name, nullptr);
269 Thread::Current()->SetClassLoaderOverride(class_loader);
270 return class_loader;
271}
272
273jobject CommonRuntimeTestImpl::LoadDexInWellKnownClassLoader(const std::string& dex_name,
274 jclass loader_class,
275 jobject parent_loader) {
276 std::vector<std::unique_ptr<const DexFile>> dex_files = OpenTestDexFiles(dex_name.c_str());
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800277 std::vector<const DexFile*> class_path;
Ian Rogerse63db272014-07-15 15:36:11 -0700278 CHECK_NE(0U, dex_files.size());
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800279 for (auto& dex_file : dex_files) {
280 class_path.push_back(dex_file.get());
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800281 loaded_dex_files_.push_back(std::move(dex_file));
Ian Rogerse63db272014-07-15 15:36:11 -0700282 }
Ian Rogers68d8b422014-07-17 11:09:10 -0700283 Thread* self = Thread::Current();
Calin Juravle7865ac72017-06-28 11:03:12 -0700284 ScopedObjectAccess soa(self);
285
286 jobject result = Runtime::Current()->GetClassLinker()->CreateWellKnownClassLoader(
287 self,
288 class_path,
289 loader_class,
290 parent_loader);
291
292 {
293 // Verify we build the correct chain.
294
295 ObjPtr<mirror::ClassLoader> actual_class_loader = soa.Decode<mirror::ClassLoader>(result);
296 // Verify that the result has the correct class.
297 CHECK_EQ(soa.Decode<mirror::Class>(loader_class), actual_class_loader->GetClass());
298 // Verify that the parent is not null. The boot class loader will be set up as a
299 // proper object.
300 ObjPtr<mirror::ClassLoader> actual_parent(actual_class_loader->GetParent());
301 CHECK(actual_parent != nullptr);
302
303 if (parent_loader != nullptr) {
304 // We were given a parent. Verify that it's what we expect.
305 ObjPtr<mirror::ClassLoader> expected_parent = soa.Decode<mirror::ClassLoader>(parent_loader);
306 CHECK_EQ(expected_parent, actual_parent);
307 } else {
308 // No parent given. The parent must be the BootClassLoader.
309 CHECK(Runtime::Current()->GetClassLinker()->IsBootClassLoader(soa, actual_parent));
310 }
311 }
312
313 return result;
314}
315
316jobject CommonRuntimeTestImpl::LoadDexInPathClassLoader(const std::string& dex_name,
317 jobject parent_loader) {
318 return LoadDexInWellKnownClassLoader(dex_name,
319 WellKnownClasses::dalvik_system_PathClassLoader,
320 parent_loader);
321}
322
323jobject CommonRuntimeTestImpl::LoadDexInDelegateLastClassLoader(const std::string& dex_name,
324 jobject parent_loader) {
325 return LoadDexInWellKnownClassLoader(dex_name,
326 WellKnownClasses::dalvik_system_DelegateLastClassLoader,
327 parent_loader);
Ian Rogerse63db272014-07-15 15:36:11 -0700328}
329
Andreas Gampe26761f72017-07-20 18:00:39 -0700330void CommonRuntimeTestImpl::FillHeap(Thread* self,
331 ClassLinker* class_linker,
332 VariableSizedHandleScope* handle_scope) {
333 DCHECK(handle_scope != nullptr);
334
335 Runtime::Current()->GetHeap()->SetIdealFootprint(1 * GB);
336
337 // Class java.lang.Object.
338 Handle<mirror::Class> c(handle_scope->NewHandle(
339 class_linker->FindSystemClass(self, "Ljava/lang/Object;")));
340 // Array helps to fill memory faster.
341 Handle<mirror::Class> ca(handle_scope->NewHandle(
342 class_linker->FindSystemClass(self, "[Ljava/lang/Object;")));
343
344 // Start allocating with ~128K
345 size_t length = 128 * KB;
346 while (length > 40) {
347 const int32_t array_length = length / 4; // Object[] has elements of size 4.
348 MutableHandle<mirror::Object> h(handle_scope->NewHandle<mirror::Object>(
349 mirror::ObjectArray<mirror::Object>::Alloc(self, ca.Get(), array_length)));
350 if (self->IsExceptionPending() || h == nullptr) {
351 self->ClearException();
352
353 // Try a smaller length
354 length = length / 2;
355 // Use at most a quarter the reported free space.
356 size_t mem = Runtime::Current()->GetHeap()->GetFreeMemory();
357 if (length * 4 > mem) {
358 length = mem / 4;
359 }
360 }
361 }
362
363 // Allocate simple objects till it fails.
364 while (!self->IsExceptionPending()) {
365 handle_scope->NewHandle<mirror::Object>(c->AllocObject(self));
366 }
367 self->ClearException();
368}
369
370void CommonRuntimeTestImpl::SetUpRuntimeOptionsForFillHeap(RuntimeOptions *options) {
371 // Use a smaller heap
372 bool found = false;
373 for (std::pair<std::string, const void*>& pair : *options) {
374 if (pair.first.find("-Xmx") == 0) {
375 pair.first = "-Xmx4M"; // Smallest we can go.
376 found = true;
377 }
378 }
379 if (!found) {
380 options->emplace_back("-Xmx4M", nullptr);
381 }
382}
383
Ian Rogerse63db272014-07-15 15:36:11 -0700384CheckJniAbortCatcher::CheckJniAbortCatcher() : vm_(Runtime::Current()->GetJavaVM()) {
Ian Rogers68d8b422014-07-17 11:09:10 -0700385 vm_->SetCheckJniAbortHook(Hook, &actual_);
Ian Rogerse63db272014-07-15 15:36:11 -0700386}
387
388CheckJniAbortCatcher::~CheckJniAbortCatcher() {
Ian Rogers68d8b422014-07-17 11:09:10 -0700389 vm_->SetCheckJniAbortHook(nullptr, nullptr);
Ian Rogerse63db272014-07-15 15:36:11 -0700390 EXPECT_TRUE(actual_.empty()) << actual_;
391}
392
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700393void CheckJniAbortCatcher::Check(const std::string& expected_text) {
394 Check(expected_text.c_str());
395}
396
Ian Rogerse63db272014-07-15 15:36:11 -0700397void CheckJniAbortCatcher::Check(const char* expected_text) {
398 EXPECT_TRUE(actual_.find(expected_text) != std::string::npos) << "\n"
399 << "Expected to find: " << expected_text << "\n"
400 << "In the output : " << actual_;
401 actual_.clear();
402}
403
404void CheckJniAbortCatcher::Hook(void* data, const std::string& reason) {
405 // We use += because when we're hooking the aborts like this, multiple problems can be found.
406 *reinterpret_cast<std::string*>(data) += reason;
407}
408
409} // namespace art
Andreas Gampec857f4a2018-10-25 13:12:37 -0700410
411// Allow other test code to run global initialization/configuration before
412// gtest infra takes over.
413extern "C"
414__attribute__((visibility("default"))) __attribute__((weak))
415void ArtTestGlobalInit() {
416 LOG(ERROR) << "ArtTestGlobalInit in common_runtime_test";
417}
418
419int main(int argc, char **argv) {
420 // Gtests can be very noisy. For example, an executable with multiple tests will trigger native
421 // bridge warnings. The following line reduces the minimum log severity to ERROR and suppresses
422 // everything else. In case you want to see all messages, comment out the line.
423 setenv("ANDROID_LOG_TAGS", "*:e", 1);
424
425 art::Locks::Init();
426 art::InitLogging(argv, art::Runtime::Abort);
427 art::MemMap::Init();
428 LOG(INFO) << "Running main() from common_runtime_test.cc...";
429 testing::InitGoogleTest(&argc, argv);
430 ArtTestGlobalInit();
431 return RUN_ALL_TESTS();
432}