| 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 <limits> | 5 #include <limits> |
| 6 #include <sstream> | 6 #include <sstream> |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/debug/stack_trace.h" | 9 #include "base/debug/stack_trace.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/process/kill.h" | 11 #include "base/process/kill.h" |
| 12 #include "base/process/process_handle.h" | 12 #include "base/process/process_handle.h" |
| 13 #include "base/test/test_timeouts.h" | 13 #include "base/test/test_timeouts.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "testing/multiprocess_func_list.h" | 15 #include "testing/multiprocess_func_list.h" |
| 16 | 16 |
| 17 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_IOS) | 17 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_IOS) |
| 18 #include "base/test/multiprocess_test.h" | 18 #include "base/test/multiprocess_test.h" |
| 19 #endif | 19 #endif |
| 20 | 20 |
| 21 namespace base { | 21 namespace base { |
| 22 namespace debug { | 22 namespace debug { |
| 23 | 23 |
| 24 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_IOS) | 24 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_IOS) |
| 25 typedef MultiProcessTest StackTraceTest; | 25 typedef MultiProcessTest StackTraceTest; |
| 26 #else | 26 #else |
| 27 typedef testing::Test StackTraceTest; | 27 typedef testing::Test StackTraceTest; |
| 28 #endif | 28 #endif |
| 29 | 29 |
| 30 // Note: On Linux, this test currently only fully works on Debug builds. | 30 #if defined(__UCLIBC__) || defined(FNL_MUSL) |
| 31 // See comments in the #ifdef soup if you intend to change this. | |
| 32 #if defined(OS_WIN) | |
| 33 // Always fails on Windows: crbug.com/32070 | |
| 34 #define MAYBE_OutputToStream DISABLED_OutputToStream | 31 #define MAYBE_OutputToStream DISABLED_OutputToStream |
| 35 #else | 32 #else |
| 36 #define MAYBE_OutputToStream OutputToStream | 33 #define MAYBE_OutputToStream OutputToStream |
| 37 #endif | 34 #endif |
| 38 #if !defined(__UCLIBC__) && !defined(FNL_MUSL) | |
| 39 TEST_F(StackTraceTest, MAYBE_OutputToStream) { | 35 TEST_F(StackTraceTest, MAYBE_OutputToStream) { |
| 40 StackTrace trace; | 36 StackTrace trace; |
| 41 | 37 |
| 42 // Dump the trace into a string. | 38 // Dump the trace into a string. |
| 43 std::ostringstream os; | 39 std::ostringstream os; |
| 44 trace.OutputToStream(&os); | 40 trace.OutputToStream(&os); |
| 45 std::string backtrace_message = os.str(); | 41 std::string backtrace_message = os.str(); |
| 46 | 42 |
| 47 // ToString() should produce the same output. | 43 // ToString() should produce the same output. |
| 48 EXPECT_EQ(backtrace_message, trace.ToString()); | 44 EXPECT_EQ(backtrace_message, trace.ToString()); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 #elif 0 | 93 #elif 0 |
| 98 // This is the fall-through case; it used to cover Windows. | 94 // This is the fall-through case; it used to cover Windows. |
| 99 // But it's disabled because of varying buildbot configs; | 95 // But it's disabled because of varying buildbot configs; |
| 100 // some lack symbols. | 96 // some lack symbols. |
| 101 | 97 |
| 102 // Expect to at least find main. | 98 // Expect to at least find main. |
| 103 EXPECT_TRUE(backtrace_message.find("main") != std::string::npos) | 99 EXPECT_TRUE(backtrace_message.find("main") != std::string::npos) |
| 104 << "Expected to find main in backtrace:\n" | 100 << "Expected to find main in backtrace:\n" |
| 105 << backtrace_message; | 101 << backtrace_message; |
| 106 | 102 |
| 107 #if defined(OS_WIN) | |
| 108 // MSVC doesn't allow the use of C99's __func__ within C++, so we fake it with | |
| 109 // MSVC's __FUNCTION__ macro. | |
| 110 #define __func__ __FUNCTION__ | |
| 111 #endif | |
| 112 | |
| 113 // Expect to find this function as well. | 103 // Expect to find this function as well. |
| 114 // Note: This will fail if not linked with -rdynamic (aka -export_dynamic) | 104 // Note: This will fail if not linked with -rdynamic (aka -export_dynamic) |
| 115 EXPECT_TRUE(backtrace_message.find(__func__) != std::string::npos) | 105 EXPECT_TRUE(backtrace_message.find(__func__) != std::string::npos) |
| 116 << "Expected to find " << __func__ << " in backtrace:\n" | 106 << "Expected to find " << __func__ << " in backtrace:\n" |
| 117 << backtrace_message; | 107 << backtrace_message; |
| 118 | 108 |
| 119 #endif // define(OS_MACOSX) | 109 #endif // define(OS_MACOSX) |
| 120 } | 110 } |
| 121 | 111 |
| 122 // The test is used for manual testing, e.g., to see the raw output. | 112 // The test is used for manual testing, e.g., to see the raw output. |
| 123 TEST_F(StackTraceTest, DebugOutputToStream) { | 113 TEST_F(StackTraceTest, DebugOutputToStream) { |
| 124 StackTrace trace; | 114 StackTrace trace; |
| 125 std::ostringstream os; | 115 std::ostringstream os; |
| 126 trace.OutputToStream(&os); | 116 trace.OutputToStream(&os); |
| 127 VLOG(1) << os.str(); | 117 VLOG(1) << os.str(); |
| 128 } | 118 } |
| 129 | 119 |
| 130 // The test is used for manual testing, e.g., to see the raw output. | 120 // The test is used for manual testing, e.g., to see the raw output. |
| 131 TEST_F(StackTraceTest, DebugPrintBacktrace) { | 121 TEST_F(StackTraceTest, DebugPrintBacktrace) { |
| 132 StackTrace().Print(); | 122 StackTrace().Print(); |
| 133 } | 123 } |
| 134 #endif // !defined(__UCLIBC__) | |
| 135 | 124 |
| 136 #if defined(OS_POSIX) && !defined(OS_ANDROID) | 125 #if defined(OS_POSIX) && !defined(OS_ANDROID) |
| 137 #if !defined(OS_IOS) | 126 #if !defined(OS_IOS) |
| 138 static char* newArray() { | 127 static char* newArray() { |
| 139 // Clang warns about the mismatched new[]/delete if they occur in the same | 128 // Clang warns about the mismatched new[]/delete if they occur in the same |
| 140 // function. | 129 // function. |
| 141 return new char[10]; | 130 return new char[10]; |
| 142 } | 131 } |
| 143 | 132 |
| 144 MULTIPROCESS_TEST_MAIN(MismatchedMallocChildProcess) { | 133 MULTIPROCESS_TEST_MAIN(MismatchedMallocChildProcess) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 EXPECT_EQ("688", itoa_r_wrapper(0x688, 128, 16, 1)); | 219 EXPECT_EQ("688", itoa_r_wrapper(0x688, 128, 16, 1)); |
| 231 EXPECT_EQ("688", itoa_r_wrapper(0x688, 128, 16, 2)); | 220 EXPECT_EQ("688", itoa_r_wrapper(0x688, 128, 16, 2)); |
| 232 EXPECT_EQ("688", itoa_r_wrapper(0x688, 128, 16, 3)); | 221 EXPECT_EQ("688", itoa_r_wrapper(0x688, 128, 16, 3)); |
| 233 EXPECT_EQ("0688", itoa_r_wrapper(0x688, 128, 16, 4)); | 222 EXPECT_EQ("0688", itoa_r_wrapper(0x688, 128, 16, 4)); |
| 234 EXPECT_EQ("00688", itoa_r_wrapper(0x688, 128, 16, 5)); | 223 EXPECT_EQ("00688", itoa_r_wrapper(0x688, 128, 16, 5)); |
| 235 } | 224 } |
| 236 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) | 225 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) |
| 237 | 226 |
| 238 } // namespace debug | 227 } // namespace debug |
| 239 } // namespace base | 228 } // namespace base |
| OLD | NEW |