| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 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 | 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 <sstream> | 5 #include <sstream> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/debug_util.h" | 8 #include "base/debug_util.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 11 |
| 12 TEST(StackTrace, OutputToStream) { | 12 TEST(StackTrace, OutputToStream) { |
| 13 StackTrace trace; | 13 StackTrace trace; |
| 14 | 14 |
| 15 // Dump the trace into a string. | 15 // Dump the trace into a string. |
| 16 std::ostringstream os; | 16 std::ostringstream os; |
| 17 trace.OutputToStream(&os); | 17 trace.OutputToStream(&os); |
| 18 std::string backtrace_message = os.str(); | 18 std::string backtrace_message = os.str(); |
| 19 | 19 |
| 20 #if defined(OS_LINUX) && NDEBUG |
| 21 // Stack traces require an extra data table that bloats our binaries, |
| 22 // so they're turned off for release builds. We stop the test here, |
| 23 // at least letting us verify that the calls don't crash. |
| 24 return; |
| 25 #endif // defined(OS_LINUX) && NDEBUG |
| 26 |
| 20 size_t frames_found = 0; | 27 size_t frames_found = 0; |
| 21 trace.Addresses(&frames_found); | 28 trace.Addresses(&frames_found); |
| 22 ASSERT_GE(frames_found, 5u) << | 29 ASSERT_GE(frames_found, 5u) << |
| 23 "No stack frames found. Skipping rest of test."; | 30 "No stack frames found. Skipping rest of test."; |
| 24 | 31 |
| 25 // Check if the output has symbol initialization warning. If it does, fail. | 32 // Check if the output has symbol initialization warning. If it does, fail. |
| 26 ASSERT_EQ(backtrace_message.find("Dumping unresolved backtrace"), | 33 ASSERT_EQ(backtrace_message.find("Dumping unresolved backtrace"), |
| 27 std::string::npos) << | 34 std::string::npos) << |
| 28 "Unable to resolve symbols. Skipping rest of test."; | 35 "Unable to resolve symbols. Skipping rest of test."; |
| 29 | 36 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 78 |
| 72 // Expect to find this function as well. | 79 // Expect to find this function as well. |
| 73 // Note: This will fail if not linked with -rdynamic (aka -export_dynamic) | 80 // Note: This will fail if not linked with -rdynamic (aka -export_dynamic) |
| 74 EXPECT_TRUE(backtrace_message.find(__func__) != std::string::npos) | 81 EXPECT_TRUE(backtrace_message.find(__func__) != std::string::npos) |
| 75 << "Expected to find " << __func__ << " in backtrace:\n" | 82 << "Expected to find " << __func__ << " in backtrace:\n" |
| 76 << backtrace_message; | 83 << backtrace_message; |
| 77 | 84 |
| 78 #endif // define(OS_MACOSX) | 85 #endif // define(OS_MACOSX) |
| 79 #endif | 86 #endif |
| 80 } | 87 } |
| OLD | NEW |