OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <sstream> | 8 #include <sstream> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
231 EXPECT_EQ("00001", itoa_r_wrapper(1, 128, 10, 5)); | 231 EXPECT_EQ("00001", itoa_r_wrapper(1, 128, 10, 5)); |
232 EXPECT_EQ("688", itoa_r_wrapper(0x688, 128, 16, 0)); | 232 EXPECT_EQ("688", itoa_r_wrapper(0x688, 128, 16, 0)); |
233 EXPECT_EQ("688", itoa_r_wrapper(0x688, 128, 16, 1)); | 233 EXPECT_EQ("688", itoa_r_wrapper(0x688, 128, 16, 1)); |
234 EXPECT_EQ("688", itoa_r_wrapper(0x688, 128, 16, 2)); | 234 EXPECT_EQ("688", itoa_r_wrapper(0x688, 128, 16, 2)); |
235 EXPECT_EQ("688", itoa_r_wrapper(0x688, 128, 16, 3)); | 235 EXPECT_EQ("688", itoa_r_wrapper(0x688, 128, 16, 3)); |
236 EXPECT_EQ("0688", itoa_r_wrapper(0x688, 128, 16, 4)); | 236 EXPECT_EQ("0688", itoa_r_wrapper(0x688, 128, 16, 4)); |
237 EXPECT_EQ("00688", itoa_r_wrapper(0x688, 128, 16, 5)); | 237 EXPECT_EQ("00688", itoa_r_wrapper(0x688, 128, 16, 5)); |
238 } | 238 } |
239 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) | 239 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) |
240 | 240 |
241 #if HAVE_TRACE_STACK_FRAME_POINTERS | |
242 | |
243 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.
| |
244 const void* fp_frames[10]; | |
245 size_t fp_frame_count = | |
246 TraceStackFramePointers(fp_frames, arraysize(fp_frames), 0); | |
247 | |
248 // We expect to fill the whole frame array | |
249 ASSERT_EQ(arraysize(fp_frames), fp_frame_count); | |
250 | |
251 // Compare against StackTrace | |
252 | |
253 StackTrace stack_trace; | |
254 size_t frame_count = 0; | |
255 const void* const* frames = stack_trace.Addresses(&frame_count); | |
256 | |
257 // Find offsets into both frame arrays that have matching frames | |
258 size_t fp_frames_offset = 0; | |
259 size_t frames_offset = 0; | |
260 bool found_matching_frame = false; | |
261 for (;fp_frames_offset != fp_frame_count; ++fp_frames_offset) { | |
262 const void* frame = fp_frames[fp_frames_offset]; | |
263 for (frames_offset = 0; frames_offset != frame_count; ++frames_offset) { | |
264 if (frames[frames_offset] == frame) { | |
265 found_matching_frame = true; | |
266 break; | |
267 } | |
268 } | |
269 if (found_matching_frame) { | |
270 break; | |
271 } | |
272 } | |
273 | |
274 ASSERT_TRUE(found_matching_frame) << | |
275 "StackTrace class and TraceStackFramePointers function produced " << | |
276 "completely different traces."; | |
277 | |
278 // fp_frames[0] points somewhere inside this function and differs from | |
279 // location reported by StackFrame (since invocations are on different | |
280 // lines). However fp_frames[1] points to the caller function, and should | |
281 // be in both frame arrays. | |
282 ASSERT_EQ(fp_frames_offset, 1u); | |
283 | |
284 size_t check_depth = std::min(fp_frame_count - fp_frames_offset, | |
285 frame_count - frames_offset); | |
286 for (size_t i = 0; i != check_depth; ++i) { | |
287 size_t fp_frame_index = i + fp_frames_offset; | |
288 size_t frame_index = i + frames_offset; | |
289 EXPECT_EQ(frames[frame_index], fp_frames[fp_frame_index]) << | |
290 "Where frame_index = " << frame_index << ", " << | |
291 "fp_frame_index = " << fp_frame_index; | |
292 } | |
293 } | |
294 | |
295 #endif // HAVE_TRACE_STACK_FRAME_POINTERS | |
296 | |
241 } // namespace debug | 297 } // namespace debug |
242 } // namespace base | 298 } // namespace base |
OLD | NEW |