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

Side by Side Diff: base/test_suite.h

Issue 201050: Print stack trace on exception in unit tests on Windows.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 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
« base/debug_util_win.cc ('K') | « base/debug_util_win.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #ifndef BASE_TEST_SUITE_H_ 5 #ifndef BASE_TEST_SUITE_H_
6 #define BASE_TEST_SUITE_H_ 6 #define BASE_TEST_SUITE_H_
7 7
8 // Defines a basic test suite framework for running gtest based tests. You can 8 // Defines a basic test suite framework for running gtest based tests. You can
9 // instantiate this class in your main function and call its Run method to run 9 // instantiate this class in your main function and call its Run method to run
10 // any gtest based tests that are linked into your executable. 10 // any gtest based tests that are linked into your executable.
(...skipping 22 matching lines...) Expand all
33 33
34 #if defined(OS_LINUX) 34 #if defined(OS_LINUX)
35 #include <gtk/gtk.h> 35 #include <gtk/gtk.h>
36 #endif 36 #endif
37 37
38 #if defined(OS_POSIX) 38 #if defined(OS_POSIX)
39 static void TestSuiteCrashHandler(int signal) { 39 static void TestSuiteCrashHandler(int signal) {
40 StackTrace().PrintBacktrace(); 40 StackTrace().PrintBacktrace();
41 _exit(1); 41 _exit(1);
42 } 42 }
43 #endif 43 #endif // OS_POSIX
44
45 #if defined(OS_WIN)
46 // Previous unhandled filter. Will be called if not NULL when we intercept an
47 // exception.
48 __declspec(selectany) LPTOP_LEVEL_EXCEPTION_FILTER g_previous_filter = NULL;
49
50 // Prints the exception call stack.
51 // This is the unit tests exception filter.
52 inline long WINAPI UnitTestExceptionFilter(EXCEPTION_POINTERS* info) {
53 StackTrace(info).PrintBacktrace();
54 if (g_previous_filter)
55 return g_previous_filter(info);
56 return EXCEPTION_EXECUTE_HANDLER;
57 }
58 #endif // OS_WIN
44 59
45 class TestSuite { 60 class TestSuite {
46 public: 61 public:
47 TestSuite(int argc, char** argv) { 62 TestSuite(int argc, char** argv) {
48 base::EnableTerminationOnHeapCorruption(); 63 base::EnableTerminationOnHeapCorruption();
49 CommandLine::Init(argc, argv); 64 CommandLine::Init(argc, argv);
50 testing::InitGoogleTest(&argc, argv); 65 testing::InitGoogleTest(&argc, argv);
51 #if defined(OS_LINUX) 66 #if defined(OS_LINUX)
52 g_thread_init(NULL); 67 g_thread_init(NULL);
53 gtk_init_check(&argc, &argv); 68 gtk_init_check(&argc, &argv);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 163
149 // In some cases, we do not want to see standard error dialogs. 164 // In some cases, we do not want to see standard error dialogs.
150 if (!IsDebuggerPresent() && 165 if (!IsDebuggerPresent() &&
151 !CommandLine::ForCurrentProcess()->HasSwitch(L"show-error-dialogs")) { 166 !CommandLine::ForCurrentProcess()->HasSwitch(L"show-error-dialogs")) {
152 SuppressErrorDialogs(); 167 SuppressErrorDialogs();
153 #if !defined(PURIFY) 168 #if !defined(PURIFY)
154 // When the code in this file moved around, bug 6436 resurfaced. 169 // When the code in this file moved around, bug 6436 resurfaced.
155 // As a hack workaround, just #ifdef out this code for Purify builds. 170 // As a hack workaround, just #ifdef out this code for Purify builds.
156 logging::SetLogAssertHandler(UnitTestAssertHandler); 171 logging::SetLogAssertHandler(UnitTestAssertHandler);
157 #endif // !defined(PURIFY) 172 #endif // !defined(PURIFY)
173 // Add stack dumping support on exception on windows. Similar to OS_POSIX
174 // signal() handling above.
175 g_previous_filter = SetUnhandledExceptionFilter(&UnitTestExceptionFilter);
158 } 176 }
159 #endif // defined(OS_WIN) 177 #endif // defined(OS_WIN)
160 178
161 icu_util::Initialize(); 179 icu_util::Initialize();
162 } 180 }
163 181
164 virtual void Shutdown() { 182 virtual void Shutdown() {
165 } 183 }
166 184
167 // Make sure that we setup an AtExitManager so Singleton objects will be 185 // Make sure that we setup an AtExitManager so Singleton objects will be
168 // destroyed. 186 // destroyed.
169 base::AtExitManager at_exit_manager_; 187 base::AtExitManager at_exit_manager_;
170 }; 188 };
171 189
172 #endif // BASE_TEST_SUITE_H_ 190 #endif // BASE_TEST_SUITE_H_
OLDNEW
« base/debug_util_win.cc ('K') | « base/debug_util_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698