Chromium Code Reviews| 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 size_t frames_found = 0; | 20 size_t frames_found = 0; |
| 21 trace.Addresses(&frames_found); | 21 trace.Addresses(&frames_found); |
| 22 if (frames_found == 0) { | 22 ASSERT_GE(frames_found, 5u) << |
|
awong
2009/08/21 20:52:20
Did you mean to make these more strict? I remembe
| |
| 23 LOG(ERROR) << "No stack frames found. Skipping rest of test."; | 23 "No stack frames found. Skipping rest of test."; |
| 24 return; | |
| 25 } | |
| 26 | 24 |
| 27 // Check if the output has symbol initialization warning. If it does, fail. | 25 // Check if the output has symbol initialization warning. If it does, fail. |
| 28 if (backtrace_message.find("Dumping unresolved backtrace") != | 26 ASSERT_EQ(backtrace_message.find("Dumping unresolved backtrace"), |
| 29 std::string::npos) { | 27 std::string::npos) << |
| 30 LOG(ERROR) << "Unable to resolve symbols. Skipping rest of test."; | 28 "Unable to resolve symbols. Skipping rest of test."; |
| 31 return; | |
| 32 } | |
| 33 | 29 |
| 34 #if 0 | 30 #if 0 |
| 35 //TODO(ajwong): Disabling checking of symbol resolution since it depends | 31 //TODO(ajwong): Disabling checking of symbol resolution since it depends |
| 36 // on whether or not symbols are present, and there are too many | 32 // on whether or not symbols are present, and there are too many |
| 37 // configurations to reliably ensure that symbols are findable. | 33 // configurations to reliably ensure that symbols are findable. |
| 38 #if defined(OS_MACOSX) | 34 #if defined(OS_MACOSX) |
| 39 | 35 |
| 40 // Symbol resolution via the backtrace_symbol funciton does not work well | 36 // Symbol resolution via the backtrace_symbol funciton does not work well |
| 41 // in OsX. | 37 // in OsX. |
| 42 // See this thread: | 38 // See this thread: |
| 43 // | 39 // |
| 44 // http://lists.apple.com/archives/darwin-dev/2009/Mar/msg00111.html | 40 // http://lists.apple.com/archives/darwin-dev/2009/Mar/msg00111.html |
| 45 // | 41 // |
| 46 // Just check instead that we find our way back to the "start" symbol | 42 // Just check instead that we find our way back to the "start" symbol |
| 47 // which should be the first symbol in the trace. | 43 // which should be the first symbol in the trace. |
| 48 // | 44 // |
| 49 // TODO(port): Find a more reliable way to resolve symbols. | 45 // TODO(port): Find a more reliable way to resolve symbols. |
| 50 | 46 |
| 51 // Expect to at least find main. | 47 // Expect to at least find main. |
| 52 EXPECT_TRUE(backtrace_message.find("start") != std::string::npos) | 48 EXPECT_TRUE(backtrace_message.find("start") != std::string::npos) |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 68 | 64 |
| 69 // Expect to find this function as well. | 65 // Expect to find this function as well. |
| 70 // Note: This will fail if not linked with -rdynamic (aka -export_dynamic) | 66 // Note: This will fail if not linked with -rdynamic (aka -export_dynamic) |
| 71 EXPECT_TRUE(backtrace_message.find(__func__) != std::string::npos) | 67 EXPECT_TRUE(backtrace_message.find(__func__) != std::string::npos) |
| 72 << "Expected to find " << __func__ << " in backtrace:\n" | 68 << "Expected to find " << __func__ << " in backtrace:\n" |
| 73 << backtrace_message; | 69 << backtrace_message; |
| 74 | 70 |
| 75 #endif // define(OS_MACOSX) | 71 #endif // define(OS_MACOSX) |
| 76 #endif | 72 #endif |
| 77 } | 73 } |
| OLD | NEW |