Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: base/debug/stack_trace_unittest.cc

Issue 11362048: GTTF: Make Linux stack dump signal handler async-signal safe. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <sstream> 6 #include <sstream>
6 #include <string> 7 #include <string>
7 8
8 #include "base/debug/stack_trace.h" 9 #include "base/debug/stack_trace.h"
9 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/process_util.h"
12 #include "base/test/multiprocess_test.h"
13 #include "base/test/test_timeouts.h"
10 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "testing/multiprocess_func_list.h"
11 16
12 namespace base { 17 namespace base {
13 namespace debug { 18 namespace debug {
14 19
20 typedef MultiProcessTest StackTraceTest;
21
15 // Note: On Linux, this test currently only fully works on Debug builds. 22 // Note: On Linux, this test currently only fully works on Debug builds.
16 // See comments in the #ifdef soup if you intend to change this. 23 // See comments in the #ifdef soup if you intend to change this.
17 #if defined(OS_WIN) 24 #if defined(OS_WIN)
18 // Always fails on Windows: crbug.com/32070 25 // Always fails on Windows: crbug.com/32070
19 #define MAYBE_OutputToStream DISABLED_OutputToStream 26 #define MAYBE_OutputToStream DISABLED_OutputToStream
20 #else 27 #else
21 #define MAYBE_OutputToStream OutputToStream 28 #define MAYBE_OutputToStream OutputToStream
22 #endif 29 #endif
23 TEST(StackTrace, MAYBE_OutputToStream) { 30 TEST_F(StackTraceTest, MAYBE_OutputToStream) {
24 StackTrace trace; 31 StackTrace trace;
25 32
26 // Dump the trace into a string. 33 // Dump the trace into a string.
27 std::ostringstream os; 34 std::ostringstream os;
28 trace.OutputToStream(&os); 35 trace.OutputToStream(&os);
29 std::string backtrace_message = os.str(); 36 std::string backtrace_message = os.str();
30 37
31 // ToString() should produce the same output. 38 // ToString() should produce the same output.
32 EXPECT_EQ(backtrace_message, trace.ToString()); 39 EXPECT_EQ(backtrace_message, trace.ToString());
33 40
(...skipping 28 matching lines...) Expand all
62 // which should be the first symbol in the trace. 69 // which should be the first symbol in the trace.
63 // 70 //
64 // TODO(port): Find a more reliable way to resolve symbols. 71 // TODO(port): Find a more reliable way to resolve symbols.
65 72
66 // Expect to at least find main. 73 // Expect to at least find main.
67 EXPECT_TRUE(backtrace_message.find("start") != std::string::npos) 74 EXPECT_TRUE(backtrace_message.find("start") != std::string::npos)
68 << "Expected to find start in backtrace:\n" 75 << "Expected to find start in backtrace:\n"
69 << backtrace_message; 76 << backtrace_message;
70 77
71 #endif 78 #endif
72 #elif defined(__GLIBCXX__) 79 #elif defined(USE_SYMBOLIZE)
73 // This branch is for gcc-compiled code, but not Mac due to the 80 // This branch is for gcc-compiled code, but not Mac due to the
74 // above #if. 81 // above #if.
75 // Expect a demangled symbol. 82 // Expect a demangled symbol.
76 EXPECT_TRUE(backtrace_message.find("testing::Test::Run()") != 83 EXPECT_TRUE(backtrace_message.find("testing::Test::Run()") !=
77 std::string::npos) 84 std::string::npos)
78 << "Expected a demangled symbol in backtrace:\n" 85 << "Expected a demangled symbol in backtrace:\n"
79 << backtrace_message; 86 << backtrace_message;
80 87
81 #elif 0 88 #elif 0
82 // This is the fall-through case; it used to cover Windows. 89 // This is the fall-through case; it used to cover Windows.
(...skipping 13 matching lines...) Expand all
96 103
97 // Expect to find this function as well. 104 // Expect to find this function as well.
98 // Note: This will fail if not linked with -rdynamic (aka -export_dynamic) 105 // Note: This will fail if not linked with -rdynamic (aka -export_dynamic)
99 EXPECT_TRUE(backtrace_message.find(__func__) != std::string::npos) 106 EXPECT_TRUE(backtrace_message.find(__func__) != std::string::npos)
100 << "Expected to find " << __func__ << " in backtrace:\n" 107 << "Expected to find " << __func__ << " in backtrace:\n"
101 << backtrace_message; 108 << backtrace_message;
102 109
103 #endif // define(OS_MACOSX) 110 #endif // define(OS_MACOSX)
104 } 111 }
105 112
113 MULTIPROCESS_TEST_MAIN(MismatchedMallocChildProcess) {
114 char* pointer = new char[10];
115 delete pointer;
116 return 2;
117 }
118
119 // Regression test for StackDumpingSignalHandler async-signal unsafety.
120 // Combined with tcmalloc's debugallocation, that signal handler
121 // and e.g. mismatched new[]/delete would cause a hang because
122 // of re-entering malloc.
123 TEST_F(StackTraceTest, AsyncSignalUnsafeSignalHandlerHang) {
124 ProcessHandle child = this->SpawnChild("MismatchedMallocChildProcess", false);
125 ASSERT_NE(kNullProcessHandle, child);
126 ASSERT_TRUE(WaitForSingleProcess(child, TestTimeouts::action_timeout()));
127 }
128
106 // The test is used for manual testing, e.g., to see the raw output. 129 // The test is used for manual testing, e.g., to see the raw output.
107 TEST(StackTrace, DebugOutputToStream) { 130 TEST_F(StackTraceTest, DebugOutputToStream) {
108 StackTrace trace; 131 StackTrace trace;
109 std::ostringstream os; 132 std::ostringstream os;
110 trace.OutputToStream(&os); 133 trace.OutputToStream(&os);
111 VLOG(1) << os.str(); 134 VLOG(1) << os.str();
112 } 135 }
113 136
114 // The test is used for manual testing, e.g., to see the raw output. 137 // The test is used for manual testing, e.g., to see the raw output.
115 TEST(StackTrace, DebugPrintBacktrace) { 138 TEST_F(StackTraceTest, DebugPrintBacktrace) {
116 StackTrace().PrintBacktrace(); 139 StackTrace().PrintBacktrace();
117 } 140 }
118 141
142 namespace {
143
144 std::string itoa_r_wrapper(intptr_t i, size_t sz, int base) {
145 char buffer[1024];
146 CHECK_LE(sz, sizeof(buffer));
147
148 char* result = internal::itoa_r(i, buffer, sz, base);
149 EXPECT_TRUE(result);
150 return std::string(buffer);
151 }
152
153 } // namespace
154
155 #if defined(OS_POSIX)
156 TEST_F(StackTraceTest, itoa_r) {
157 EXPECT_EQ("0", itoa_r_wrapper(0, 128, 10));
158 EXPECT_EQ("-1", itoa_r_wrapper(-1, 128, 10));
jar (doing other things) 2012/11/07 00:32:07 You should do this base 16, and get (on your 64 bi
159
160 // Test edge cases.
161 EXPECT_EQ("-9223372036854775808",
jar (doing other things) 2012/11/07 00:32:07 On a 32 bit machine, this will give a different an
Paweł Hajdan Jr. 2012/11/07 00:52:28 Do we have any 32-bit machines we test on? In case
Scott Hess - ex-Googler 2012/11/07 01:02:26 OSX still builds 32-bit.
162 itoa_r_wrapper(std::numeric_limits<intptr_t>::min(), 128, 10));
163 EXPECT_EQ("9223372036854775807",
164 itoa_r_wrapper(std::numeric_limits<intptr_t>::max(), 128, 10));
jar (doing other things) 2012/11/07 00:32:07 Also do this verification, base 16. The results s
165
166 // Test hex output.
167 EXPECT_EQ("688", itoa_r_wrapper(0x688, 128, 16));
168 EXPECT_EQ("deadbeef", itoa_r_wrapper(0xdeadbeef, 128, 16));
169
170 // Check that itoa_r respects passed buffer size limit.
171 char buffer[1024];
172 EXPECT_TRUE(internal::itoa_r(0xdeadbeef, buffer, 10, 16));
173 EXPECT_TRUE(internal::itoa_r(0xdeadbeef, buffer, 9, 16));
174 EXPECT_FALSE(internal::itoa_r(0xdeadbeef, buffer, 8, 16));
175 EXPECT_FALSE(internal::itoa_r(0xdeadbeef, buffer, 7, 16));
176 }
177 #endif // defined(OS_POSIX)
178
119 } // namespace debug 179 } // namespace debug
120 } // namespace base 180 } // namespace base
OLDNEW
« base/debug/stack_trace_posix.cc ('K') | « base/debug/stack_trace_posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698