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

Side by Side Diff: base/debug_util_unittest.cc

Issue 3945002: Move debug-related stuff from base to the base/debug directory and use the... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 2 months 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
« no previous file with comments | « base/debug_util_posix.cc ('k') | base/debug_util_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <sstream>
6 #include <string>
7
8 #include "base/debug_util.h"
9 #include "base/logging.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 // Note: On Linux, this test currently only fully works on Debug builds.
13 // See comments in the #ifdef soup if you intend to change this.
14 // Flaky, crbug.com/32070.
15 TEST(StackTrace, FLAKY_OutputToStream) {
16 StackTrace trace;
17
18 // Dump the trace into a string.
19 std::ostringstream os;
20 trace.OutputToStream(&os);
21 std::string backtrace_message = os.str();
22
23 #if defined(OS_POSIX) && !defined(OS_MACOSX) && NDEBUG
24 // Stack traces require an extra data table that bloats our binaries,
25 // so they're turned off for release builds. We stop the test here,
26 // at least letting us verify that the calls don't crash.
27 return;
28 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) && NDEBUG
29
30 size_t frames_found = 0;
31 trace.Addresses(&frames_found);
32 ASSERT_GE(frames_found, 5u) <<
33 "No stack frames found. Skipping rest of test.";
34
35 // Check if the output has symbol initialization warning. If it does, fail.
36 ASSERT_EQ(backtrace_message.find("Dumping unresolved backtrace"),
37 std::string::npos) <<
38 "Unable to resolve symbols. Skipping rest of test.";
39
40 #if defined(OS_MACOSX)
41 #if 0
42 // Disabled due to -fvisibility=hidden in build config.
43
44 // Symbol resolution via the backtrace_symbol function does not work well
45 // in OS X.
46 // See this thread:
47 //
48 // http://lists.apple.com/archives/darwin-dev/2009/Mar/msg00111.html
49 //
50 // Just check instead that we find our way back to the "start" symbol
51 // which should be the first symbol in the trace.
52 //
53 // TODO(port): Find a more reliable way to resolve symbols.
54
55 // Expect to at least find main.
56 EXPECT_TRUE(backtrace_message.find("start") != std::string::npos)
57 << "Expected to find start in backtrace:\n"
58 << backtrace_message;
59
60 #endif
61 #elif defined(__GLIBCXX__)
62 // This branch is for gcc-compiled code, but not Mac due to the
63 // above #if.
64 // Expect a demangled symbol.
65 EXPECT_TRUE(backtrace_message.find("testing::Test::Run()") !=
66 std::string::npos)
67 << "Expected a demangled symbol in backtrace:\n"
68 << backtrace_message;
69
70 #elif 0
71 // This is the fall-through case; it used to cover Windows.
72 // But it's disabled because of varying buildbot configs;
73 // some lack symbols.
74
75 // Expect to at least find main.
76 EXPECT_TRUE(backtrace_message.find("main") != std::string::npos)
77 << "Expected to find main in backtrace:\n"
78 << backtrace_message;
79
80 #if defined(OS_WIN)
81 // MSVC doesn't allow the use of C99's __func__ within C++, so we fake it with
82 // MSVC's __FUNCTION__ macro.
83 #define __func__ __FUNCTION__
84 #endif
85
86 // Expect to find this function as well.
87 // Note: This will fail if not linked with -rdynamic (aka -export_dynamic)
88 EXPECT_TRUE(backtrace_message.find(__func__) != std::string::npos)
89 << "Expected to find " << __func__ << " in backtrace:\n"
90 << backtrace_message;
91
92 #endif // define(OS_MACOSX)
93 }
94
95 // The test is used for manual testing, e.g., to see the raw output.
96 TEST(StackTrace, DebugOutputToStream) {
97 StackTrace trace;
98 std::ostringstream os;
99 trace.OutputToStream(&os);
100 VLOG(1) << os.str();
101 }
102
103 // The test is used for manual testing, e.g., to see the raw output.
104 TEST(StackTrace, DebugPrintBacktrace) {
105 StackTrace().PrintBacktrace();
106 }
OLDNEW
« no previous file with comments | « base/debug_util_posix.cc ('k') | base/debug_util_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698