summaryrefslogtreecommitdiffstats
path: root/libbacktrace/backtrace_test.cpp
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2014-05-06 15:23:59 -0700
committerChristopher Ferris <cferris@google.com>2014-05-08 14:42:16 -0700
commita2efd3ac7abe223aa7a8ba8b5ba448216c4953b4 (patch)
tree4af24fc95846166c6891d4b23b7ca761aaa6b1b3 /libbacktrace/backtrace_test.cpp
parentb52a48affc77232047a599afa3e567c0a8c01b69 (diff)
downloadsystem_core-a2efd3ac7abe223aa7a8ba8b5ba448216c4953b4.tar.gz
system_core-a2efd3ac7abe223aa7a8ba8b5ba448216c4953b4.tar.bz2
system_core-a2efd3ac7abe223aa7a8ba8b5ba448216c4953b4.zip
Rewrite unwind thread handling.
This new version doesn't require any specialized thread implementation, it uses the Current implementation to do its job. In addition, it runs much faster when multiple threads are trying to unwind at the same time since the global signal lock is held for only a small amount of time. Even running through the threads one at a time should be faster since it no longer requires two passes through the unwound stacks. The new code now allows multiple simultaneous unwinds of the same thread. Finally, add the ability to unwind from a ucontext_t passed in. This functionality doesn't work for remote unwinds yet. Change-Id: I4d181d7ca5ffd2acfd1686e668e6d21e36b425cb
Diffstat (limited to 'libbacktrace/backtrace_test.cpp')
-rw-r--r--libbacktrace/backtrace_test.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/libbacktrace/backtrace_test.cpp b/libbacktrace/backtrace_test.cpp
index 9744922db..ed6b21112 100644
--- a/libbacktrace/backtrace_test.cpp
+++ b/libbacktrace/backtrace_test.cpp
@@ -615,6 +615,49 @@ TEST(libbacktrace, thread_multiple_dump) {
}
}
+TEST(libbacktrace, thread_multiple_dump_same_thread) {
+ pthread_attr_t attr;
+ pthread_attr_init(&attr);
+ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+ thread_t runner;
+ runner.tid = 0;
+ runner.state = 0;
+ ASSERT_TRUE(pthread_create(&runner.threadId, &attr, ThreadMaxRun, &runner) == 0);
+
+ // Wait for tids to be set.
+ ASSERT_TRUE(WaitForNonZero(&runner.state, 10));
+
+ // Start all of the dumpers at once, they will spin until they are signalled
+ // to begin their dump run.
+ int32_t dump_now = 0;
+ // Dump the same thread NUM_THREADS simultaneously.
+ std::vector<dump_thread_t> dumpers(NUM_THREADS);
+ for (size_t i = 0; i < NUM_THREADS; i++) {
+ dumpers[i].thread.tid = runner.tid;
+ dumpers[i].thread.state = 0;
+ dumpers[i].done = 0;
+ dumpers[i].now = &dump_now;
+
+ ASSERT_TRUE(pthread_create(&dumpers[i].thread.threadId, &attr, ThreadDump, &dumpers[i]) == 0);
+ }
+
+ // Start all of the dumpers going at once.
+ android_atomic_acquire_store(1, &dump_now);
+
+ for (size_t i = 0; i < NUM_THREADS; i++) {
+ ASSERT_TRUE(WaitForNonZero(&dumpers[i].done, 100));
+
+ ASSERT_TRUE(dumpers[i].backtrace != NULL);
+ VerifyMaxDump(dumpers[i].backtrace);
+
+ delete dumpers[i].backtrace;
+ dumpers[i].backtrace = NULL;
+ }
+
+ // Tell the runner thread to exit its infinite loop.
+ android_atomic_acquire_store(0, &runner.state);
+}
+
// This test is for UnwindMaps that should share the same map cursor when
// multiple maps are created for the current process at the same time.
TEST(libbacktrace, simultaneous_maps) {