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

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: trybot debugging ios & android 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/test_timeouts.h"
10 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "testing/multiprocess_func_list.h"
15
16 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_IOS)
17 #include "base/test/multiprocess_test.h"
18 #endif
11 19
12 namespace base { 20 namespace base {
13 namespace debug { 21 namespace debug {
14 22
23 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_IOS)
24 typedef MultiProcessTest StackTraceTest;
25 #else
26 typedef testing::Test StackTraceTest;
27 #endif
28
15 // Note: On Linux, this test currently only fully works on Debug builds. 29 // 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. 30 // See comments in the #ifdef soup if you intend to change this.
17 #if defined(OS_WIN) 31 #if defined(OS_WIN)
18 // Always fails on Windows: crbug.com/32070 32 // Always fails on Windows: crbug.com/32070
19 #define MAYBE_OutputToStream DISABLED_OutputToStream 33 #define MAYBE_OutputToStream DISABLED_OutputToStream
20 #else 34 #else
21 #define MAYBE_OutputToStream OutputToStream 35 #define MAYBE_OutputToStream OutputToStream
22 #endif 36 #endif
23 TEST(StackTrace, MAYBE_OutputToStream) { 37 TEST_F(StackTraceTest, MAYBE_OutputToStream) {
24 StackTrace trace; 38 StackTrace trace;
25 39
26 // Dump the trace into a string. 40 // Dump the trace into a string.
27 std::ostringstream os; 41 std::ostringstream os;
28 trace.OutputToStream(&os); 42 trace.OutputToStream(&os);
29 std::string backtrace_message = os.str(); 43 std::string backtrace_message = os.str();
30 44
31 // ToString() should produce the same output. 45 // ToString() should produce the same output.
32 EXPECT_EQ(backtrace_message, trace.ToString()); 46 EXPECT_EQ(backtrace_message, trace.ToString());
33 47
(...skipping 28 matching lines...) Expand all
62 // which should be the first symbol in the trace. 76 // which should be the first symbol in the trace.
63 // 77 //
64 // TODO(port): Find a more reliable way to resolve symbols. 78 // TODO(port): Find a more reliable way to resolve symbols.
65 79
66 // Expect to at least find main. 80 // Expect to at least find main.
67 EXPECT_TRUE(backtrace_message.find("start") != std::string::npos) 81 EXPECT_TRUE(backtrace_message.find("start") != std::string::npos)
68 << "Expected to find start in backtrace:\n" 82 << "Expected to find start in backtrace:\n"
69 << backtrace_message; 83 << backtrace_message;
70 84
71 #endif 85 #endif
72 #elif defined(__GLIBCXX__) 86 #elif defined(USE_SYMBOLIZE)
73 // This branch is for gcc-compiled code, but not Mac due to the 87 // This branch is for gcc-compiled code, but not Mac due to the
74 // above #if. 88 // above #if.
75 // Expect a demangled symbol. 89 // Expect a demangled symbol.
76 EXPECT_TRUE(backtrace_message.find("testing::Test::Run()") != 90 EXPECT_TRUE(backtrace_message.find("testing::Test::Run()") !=
77 std::string::npos) 91 std::string::npos)
78 << "Expected a demangled symbol in backtrace:\n" 92 << "Expected a demangled symbol in backtrace:\n"
79 << backtrace_message; 93 << backtrace_message;
80 94
81 #elif 0 95 #elif 0
82 // This is the fall-through case; it used to cover Windows. 96 // This is the fall-through case; it used to cover Windows.
(...skipping 14 matching lines...) Expand all
97 // Expect to find this function as well. 111 // Expect to find this function as well.
98 // Note: This will fail if not linked with -rdynamic (aka -export_dynamic) 112 // Note: This will fail if not linked with -rdynamic (aka -export_dynamic)
99 EXPECT_TRUE(backtrace_message.find(__func__) != std::string::npos) 113 EXPECT_TRUE(backtrace_message.find(__func__) != std::string::npos)
100 << "Expected to find " << __func__ << " in backtrace:\n" 114 << "Expected to find " << __func__ << " in backtrace:\n"
101 << backtrace_message; 115 << backtrace_message;
102 116
103 #endif // define(OS_MACOSX) 117 #endif // define(OS_MACOSX)
104 } 118 }
105 119
106 // 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.
107 TEST(StackTrace, DebugOutputToStream) { 121 TEST_F(StackTraceTest, DebugOutputToStream) {
108 StackTrace trace; 122 StackTrace trace;
109 std::ostringstream os; 123 std::ostringstream os;
110 trace.OutputToStream(&os); 124 trace.OutputToStream(&os);
111 VLOG(1) << os.str(); 125 VLOG(1) << os.str();
112 } 126 }
113 127
114 // The test is used for manual testing, e.g., to see the raw output. 128 // The test is used for manual testing, e.g., to see the raw output.
115 TEST(StackTrace, DebugPrintBacktrace) { 129 TEST_F(StackTraceTest, DebugPrintBacktrace) {
116 StackTrace().PrintBacktrace(); 130 StackTrace().PrintBacktrace();
117 } 131 }
118 132
133 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_IOS)
134 MULTIPROCESS_TEST_MAIN(MismatchedMallocChildProcess) {
135 char* pointer = new char[10];
136 delete pointer;
137 return 2;
138 }
139
140 // Regression test for StackDumpingSignalHandler async-signal unsafety.
141 // Combined with tcmalloc's debugallocation, that signal handler
142 // and e.g. mismatched new[]/delete would cause a hang because
143 // of re-entering malloc.
144 TEST_F(StackTraceTest, AsyncSignalUnsafeSignalHandlerHang) {
145 ProcessHandle child = this->SpawnChild("MismatchedMallocChildProcess", false);
146 ASSERT_NE(kNullProcessHandle, child);
147 ASSERT_TRUE(WaitForSingleProcess(child, TestTimeouts::action_timeout()));
148 }
149
150 namespace {
151
152 std::string itoa_r_wrapper(intptr_t i, size_t sz, int base) {
153 char buffer[1024];
154 CHECK_LE(sz, sizeof(buffer));
155
156 char* result = internal::itoa_r(i, buffer, sz, base);
157 EXPECT_TRUE(result);
158 return std::string(buffer);
159 }
160
161 } // namespace
162
163 TEST_F(StackTraceTest, itoa_r) {
164 EXPECT_EQ("0", itoa_r_wrapper(0, 128, 10));
165 EXPECT_EQ("-1", itoa_r_wrapper(-1, 128, 10));
166
167 // Test edge cases.
168 if (sizeof(intptr_t) == 4) {
169 EXPECT_EQ("ffffffff", itoa_r_wrapper(-1, 128, 16));
170 EXPECT_EQ("-2147483648",
171 itoa_r_wrapper(std::numeric_limits<intptr_t>::min(), 128, 10));
172 EXPECT_EQ("2147483647",
173 itoa_r_wrapper(std::numeric_limits<intptr_t>::max(), 128, 10));
174
175 EXPECT_EQ("80000000",
176 itoa_r_wrapper(std::numeric_limits<intptr_t>::min(), 128, 16));
177 EXPECT_EQ("7fffffff",
178 itoa_r_wrapper(std::numeric_limits<intptr_t>::max(), 128, 16));
179 } else if (sizeof(intptr_t) == 8) {
180 EXPECT_EQ("ffffffffffffffff", itoa_r_wrapper(-1, 128, 16));
181 EXPECT_EQ("-9223372036854775808",
182 itoa_r_wrapper(std::numeric_limits<intptr_t>::min(), 128, 10));
183 EXPECT_EQ("9223372036854775807",
184 itoa_r_wrapper(std::numeric_limits<intptr_t>::max(), 128, 10));
185
186 EXPECT_EQ("8000000000000000",
187 itoa_r_wrapper(std::numeric_limits<intptr_t>::min(), 128, 16));
188 EXPECT_EQ("7fffffffffffffff",
189 itoa_r_wrapper(std::numeric_limits<intptr_t>::max(), 128, 16));
190 } else {
191 ADD_FAILURE() << "Missing test case for your size of intptr_t ("
192 << sizeof(intptr_t) << ")";
193 }
194
195 // Test hex output.
196 EXPECT_EQ("688", itoa_r_wrapper(0x688, 128, 16));
197 EXPECT_EQ("deadbeef", itoa_r_wrapper(0xdeadbeef, 128, 16));
198
199 // Check that itoa_r respects passed buffer size limit.
200 char buffer[1024];
201 EXPECT_TRUE(internal::itoa_r(0xdeadbeef, buffer, 10, 16));
202 EXPECT_TRUE(internal::itoa_r(0xdeadbeef, buffer, 9, 16));
203 EXPECT_FALSE(internal::itoa_r(0xdeadbeef, buffer, 8, 16));
204 EXPECT_FALSE(internal::itoa_r(0xdeadbeef, buffer, 7, 16));
205 }
206 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_IOS)
207
119 } // namespace debug 208 } // namespace debug
120 } // namespace base 209 } // 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