diff options
author | Christopher Ferris <cferris@google.com> | 2015-03-26 19:18:36 -0700 |
---|---|---|
committer | Christopher Ferris <cferris@google.com> | 2015-03-31 10:51:44 -0700 |
commit | 2c43cff01d1271be451671567955158629b23670 (patch) | |
tree | b08d199b9cc4d0b665d7dc844cadedf883d0590c /libbacktrace/backtrace_test.cpp | |
parent | e29744d94df787fa83307572d90a954b1592f69b (diff) | |
download | system_core-2c43cff01d1271be451671567955158629b23670.tar.gz system_core-2c43cff01d1271be451671567955158629b23670.tar.bz2 system_core-2c43cff01d1271be451671567955158629b23670.zip |
Refactor the code.
The object hierarchy was confusing and convoluted. This removes
a lot of unnecessary code, and consolidates the BacktraceCurrent
and BacktraceThread code into BacktraceCurrent.
Change-Id: I01c8407d493712a48169df49dd3ff46db4a7c3ae
Diffstat (limited to 'libbacktrace/backtrace_test.cpp')
-rw-r--r-- | libbacktrace/backtrace_test.cpp | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/libbacktrace/backtrace_test.cpp b/libbacktrace/backtrace_test.cpp index b1e34bdaa..d40885647 100644 --- a/libbacktrace/backtrace_test.cpp +++ b/libbacktrace/backtrace_test.cpp @@ -33,13 +33,14 @@ #include <backtrace/BacktraceMap.h> // For the THREAD_SIGNAL definition. -#include "BacktraceThread.h" +#include "BacktraceCurrent.h" #include <cutils/atomic.h> #include <gtest/gtest.h> #include <algorithm> #include <memory> +#include <string> #include <vector> #include "thread_utils.h" @@ -83,15 +84,16 @@ uint64_t NanoTime() { return static_cast<uint64_t>(t.tv_sec * NS_PER_SEC + t.tv_nsec); } -void DumpFrames(Backtrace* backtrace) { +std::string DumpFrames(Backtrace* backtrace) { if (backtrace->NumFrames() == 0) { - printf(" No frames to dump\n"); - return; + return " No frames to dump\n"; } + std::string frame; for (size_t i = 0; i < backtrace->NumFrames(); i++) { - printf(" %s\n", backtrace->FormatFrameData(i).c_str()); + frame += " " + backtrace->FormatFrameData(i) + '\n'; } + return frame; } void WaitForStop(pid_t pid) { @@ -133,8 +135,8 @@ void VerifyLevelDump(Backtrace* backtrace) { break; } } - ASSERT_LT(static_cast<size_t>(0), frame_num); - ASSERT_LE(static_cast<size_t>(3), frame_num); + ASSERT_LT(static_cast<size_t>(0), frame_num) << DumpFrames(backtrace); + ASSERT_LE(static_cast<size_t>(3), frame_num) << DumpFrames(backtrace); ASSERT_EQ(backtrace->GetFrame(frame_num)->func_name, "test_level_one"); ASSERT_EQ(backtrace->GetFrame(frame_num-1)->func_name, "test_level_two"); @@ -490,9 +492,13 @@ TEST(libbacktrace, thread_level_trace) { // The SA_RESTORER flag gets set behind our back, so a direct comparison // doesn't work unless we mask the value off. Mips doesn't have this // flag, so skip this on that platform. -#ifdef SA_RESTORER +#if defined(SA_RESTORER) cur_action.sa_flags &= ~SA_RESTORER; new_action.sa_flags &= ~SA_RESTORER; +#elif defined(__GLIBC__) + // Our host compiler doesn't appear to define this flag for some reason. + cur_action.sa_flags &= ~0x04000000; + new_action.sa_flags &= ~0x04000000; #endif EXPECT_EQ(cur_action.sa_flags, new_action.sa_flags); } @@ -858,10 +864,15 @@ void* ThreadReadTest(void* data) { // Tell the caller it's okay to start reading memory. android_atomic_acquire_store(1, &thread_data->state); - // Loop waiting for everything + // Loop waiting for the caller to finish reading the memory. while (thread_data->state) { } + // Re-enable read-write on the page so that we don't crash if we try + // and access data on this page when freeing the memory. + if (mprotect(&memory[pagesize], pagesize, PROT_READ | PROT_WRITE) != 0) { + return reinterpret_cast<void*>(-1); + } free(memory); android_atomic_acquire_store(1, &thread_data->state); @@ -1005,6 +1016,7 @@ void CheckForLeak(pid_t pid, pid_t tid) { delete backtrace; } size_t stable_pss = GetPssBytes(); + ASSERT_TRUE(stable_pss != 0); // Loop enough that even a small leak should be detectable. for (size_t i = 0; i < 4096; i++) { @@ -1014,6 +1026,7 @@ void CheckForLeak(pid_t pid, pid_t tid) { delete backtrace; } size_t new_pss = GetPssBytes(); + ASSERT_TRUE(new_pss != 0); size_t abs_diff = (new_pss > stable_pss) ? new_pss - stable_pss : stable_pss - new_pss; // As long as the new pss is within a certain amount, consider everything okay. ASSERT_LE(abs_diff, MAX_LEAK_BYTES); |