Chromium Code Reviews| Index: base/debug/stack_trace_unittest.cc |
| diff --git a/base/debug/stack_trace_unittest.cc b/base/debug/stack_trace_unittest.cc |
| index 9abedba6bafd91160989fb718cebc78b4fafbdf6..af53a147766cad1969b0ac8cf52b8ec3dc621e17 100644 |
| --- a/base/debug/stack_trace_unittest.cc |
| +++ b/base/debug/stack_trace_unittest.cc |
| @@ -238,5 +238,61 @@ TEST_F(StackTraceTest, itoa_r) { |
| } |
| #endif // defined(OS_POSIX) && !defined(OS_ANDROID) |
| +#if HAVE_TRACE_STACK_FRAME_POINTERS |
| + |
| +TEST_F(StackTraceTest, TraceStackFramePointers) { |
|
Primiano Tucci (use gerrit)
2016/04/18 20:18:08
I wouldn't base this test on comparing unwinding
Dmitry Skiba
2016/04/20 16:32:56
Done.
|
| + const void* fp_frames[10]; |
| + size_t fp_frame_count = |
| + TraceStackFramePointers(fp_frames, arraysize(fp_frames), 0); |
| + |
| + // We expect to fill the whole frame array |
| + ASSERT_EQ(arraysize(fp_frames), fp_frame_count); |
| + |
| + // Compare against StackTrace |
| + |
| + StackTrace stack_trace; |
| + size_t frame_count = 0; |
| + const void* const* frames = stack_trace.Addresses(&frame_count); |
| + |
| + // Find offsets into both frame arrays that have matching frames |
| + size_t fp_frames_offset = 0; |
| + size_t frames_offset = 0; |
| + bool found_matching_frame = false; |
| + for (;fp_frames_offset != fp_frame_count; ++fp_frames_offset) { |
| + const void* frame = fp_frames[fp_frames_offset]; |
| + for (frames_offset = 0; frames_offset != frame_count; ++frames_offset) { |
| + if (frames[frames_offset] == frame) { |
| + found_matching_frame = true; |
| + break; |
| + } |
| + } |
| + if (found_matching_frame) { |
| + break; |
| + } |
| + } |
| + |
| + ASSERT_TRUE(found_matching_frame) << |
| + "StackTrace class and TraceStackFramePointers function produced " << |
| + "completely different traces."; |
| + |
| + // fp_frames[0] points somewhere inside this function and differs from |
| + // location reported by StackFrame (since invocations are on different |
| + // lines). However fp_frames[1] points to the caller function, and should |
| + // be in both frame arrays. |
| + ASSERT_EQ(fp_frames_offset, 1u); |
| + |
| + size_t check_depth = std::min(fp_frame_count - fp_frames_offset, |
| + frame_count - frames_offset); |
| + for (size_t i = 0; i != check_depth; ++i) { |
| + size_t fp_frame_index = i + fp_frames_offset; |
| + size_t frame_index = i + frames_offset; |
| + EXPECT_EQ(frames[frame_index], fp_frames[fp_frame_index]) << |
| + "Where frame_index = " << frame_index << ", " << |
| + "fp_frame_index = " << fp_frame_index; |
| + } |
| +} |
| + |
| +#endif // HAVE_TRACE_STACK_FRAME_POINTERS |
| + |
| } // namespace debug |
| } // namespace base |