OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <sstream> |
| 6 #include <string> |
| 7 |
| 8 #include "base/debug_util.h" |
| 9 #include "base/logging.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 TEST(StackTrace, OutputToStream) { |
| 13 StackTrace trace; |
| 14 |
| 15 // Dump the trace into a string. |
| 16 std::ostringstream os; |
| 17 trace.OutputToStream(&os); |
| 18 std::string backtrace_message = os.str(); |
| 19 |
| 20 size_t frames_found = 0; |
| 21 trace.Addresses(&frames_found); |
| 22 if (frames_found == 0) { |
| 23 LOG(ERROR) << "No stack frames found. Skipping rest of test."; |
| 24 return; |
| 25 } |
| 26 |
| 27 // Check if the output has symbol initialization warning. If it does, fail. |
| 28 if (backtrace_message.find("Dumping unresolved backtrace") != |
| 29 std::string::npos) { |
| 30 LOG(ERROR) << "Unable to resolve symbols. Skipping rest of test."; |
| 31 return; |
| 32 } |
| 33 |
| 34 #if defined(OS_MACOSX) |
| 35 |
| 36 // Symbol resolution via the backtrace_symbol funciton does not work well |
| 37 // in OsX. |
| 38 // See this thread: |
| 39 // |
| 40 // http://lists.apple.com/archives/darwin-dev/2009/Mar/msg00111.html |
| 41 // |
| 42 // Just check instead that we find our way back to the "start" symbol |
| 43 // which should be the first symbol in the trace. |
| 44 // |
| 45 // TODO(port): Find a more reliable way to resolve symbols. |
| 46 |
| 47 // Expect to at least find main. |
| 48 EXPECT_TRUE(backtrace_message.find("start") != std::string::npos) |
| 49 << "Expected to find start in backtrace:\n" |
| 50 << backtrace_message; |
| 51 |
| 52 #else // defined(OS_MACOSX) |
| 53 |
| 54 // Expect to at least find main. |
| 55 EXPECT_TRUE(backtrace_message.find("main") != std::string::npos) |
| 56 << "Expected to find main in backtrace:\n" |
| 57 << backtrace_message; |
| 58 |
| 59 #if defined(OS_WIN) |
| 60 // MSVC doesn't allow the use of C99's __func__ within C++, so we fake it with |
| 61 // MSVC's __FUNCTION__ macro. |
| 62 #define __func__ __FUNCTION__ |
| 63 #endif |
| 64 |
| 65 // Expect to find this function as well. |
| 66 // Note: This will fail if not linked with -rdynamic (aka -export_dynamic) |
| 67 EXPECT_TRUE(backtrace_message.find(__func__) != std::string::npos) |
| 68 << "Expected to find " << __func__ << " in backtrace:\n" |
| 69 << backtrace_message; |
| 70 |
| 71 #endif // define(OS_MACOSX) |
| 72 } |
OLD | NEW |