summaryrefslogtreecommitdiff
path: root/runtime/runtime_test.cc
diff options
context:
space:
mode:
author Andreas Gampe <agampe@google.com> 2019-06-12 10:00:57 -0700
committer Treehugger Robot <treehugger-gerrit@google.com> 2019-06-14 17:58:19 +0000
commit3e2446bbe9326786a970c88bbfac80b8ed8e5cdd (patch)
tree3495f831cb926030c57901152a939718ff12886e /runtime/runtime_test.cc
parent1adb04fd1ab7a44b5bf0e0d8deb522b68849a2f6 (diff)
ART: Correctly handle an abort from an unattached thread
Libbase may be shared with other platform components. In that case, if the aborting thread is attached to the runtime, ART will print its usual dump to be helpful. If the thread is unattached, this must not be done as it would violate mutex invariants. Bug: 135056249 Test: m test-art-host-gtest-runtime_test Change-Id: I61c3df5fdbc8ddaf279f39dc653738016986dcd9
Diffstat (limited to 'runtime/runtime_test.cc')
-rw-r--r--runtime/runtime_test.cc23
1 files changed, 22 insertions, 1 deletions
diff --git a/runtime/runtime_test.cc b/runtime/runtime_test.cc
index 282e43071e..3fe281bd5f 100644
--- a/runtime/runtime_test.cc
+++ b/runtime/runtime_test.cc
@@ -14,10 +14,13 @@
* limitations under the License.
*/
+#include "common_runtime_test.h"
+
+#include <thread>
+
#include "android-base/logging.h"
#include "base/locks.h"
#include "base/mutex.h"
-#include "common_runtime_test.h"
#include "runtime.h"
#include "thread-current-inl.h"
@@ -54,4 +57,22 @@ TEST_F(RuntimeTest, AbortWithThreadSuspendCountLockHeld) {
}, kDeathRegex);
}
+TEST_F(RuntimeTest, AbortFromUnattachedThread) {
+ // This assumes the test is run single-threaded: do not start the runtime to avoid daemon threads.
+
+ constexpr const char* kDeathRegex = "Going down";
+ ASSERT_EXIT({
+ // The regex only works if we can ensure output goes to stderr.
+ android::base::SetLogger(android::base::StderrLogger);
+
+ Thread::Current()->TransitionFromSuspendedToRunnable();
+ runtime_->Start();
+
+ std::thread t([]() {
+ LOG(FATAL) << "Going down";
+ });
+ t.join();
+ }, ::testing::KilledBySignal(SIGABRT), kDeathRegex);
+}
+
} // namespace art