blob: aa4020e25f1b8c52fd298919ed7a1f0178171b0b [file] [log] [blame]
Andreas Gampeba26b512019-05-31 13:07:26 -07001/*
2 * Copyright (C) 2019 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
17#include "android-base/logging.h"
18#include "base/locks.h"
19#include "base/mutex.h"
20#include "common_runtime_test.h"
21#include "runtime.h"
22#include "thread-current-inl.h"
23
24namespace art {
25
26class RuntimeTest : public CommonRuntimeTest {};
27
28// Ensure that abort works with ThreadList locks held.
29
30TEST_F(RuntimeTest, AbortWithThreadListLockHeld) {
31 // This assumes the test is run single-threaded: do not start the runtime to avoid daemon threads.
32
33 constexpr const char* kDeathRegex = "Skipping all-threads dump as locks are held";
34 ASSERT_DEATH({
35 // The regex only works if we can ensure output goes to stderr.
36 android::base::SetLogger(android::base::StderrLogger);
37
38 MutexLock mu(Thread::Current(), *Locks::thread_list_lock_);
39 Runtime::Abort("Attempt to abort");
40 }, kDeathRegex);
41}
42
43} // namespace art