OLD | NEW |
---|---|
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. |
11 | 11 |
12 #include "base/at_exit.h" | 12 #include "base/at_exit.h" |
13 #include "base/base_paths.h" | 13 #include "base/base_paths.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/debug_on_start.h" | 15 #include "base/debug_on_start.h" |
16 #include "base/debug_util.h" | |
16 #include "base/file_path.h" | 17 #include "base/file_path.h" |
17 #include "base/icu_util.h" | 18 #include "base/icu_util.h" |
18 #include "base/logging.h" | 19 #include "base/logging.h" |
19 #include "base/multiprocess_test.h" | 20 #include "base/multiprocess_test.h" |
20 #include "base/scoped_nsautorelease_pool.h" | 21 #include "base/scoped_nsautorelease_pool.h" |
21 #include "base/time.h" | 22 #include "base/time.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
23 #include "testing/multiprocess_func_list.h" | 24 #include "testing/multiprocess_func_list.h" |
24 | 25 |
25 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
26 #include <windows.h> | 27 #include <windows.h> |
27 #endif | 28 #endif |
28 | 29 |
29 #if defined(OS_POSIX) | 30 #if defined(OS_POSIX) |
30 #include <signal.h> | 31 #include <signal.h> |
31 #endif | 32 #endif |
32 | 33 |
33 #if defined(OS_LINUX) | 34 #if defined(OS_LINUX) |
34 #include <gtk/gtk.h> | 35 #include <gtk/gtk.h> |
35 #endif | 36 #endif |
36 | 37 |
38 #if defined(OS_POSIX) | |
39 static void TestSuiteCrashHandler(int signal) { | |
40 StackTrace().PrintBacktrace(); | |
agl
2009/09/03 17:36:33
Note that, if the crash happens at certain points,
| |
41 _exit(1); | |
42 } | |
43 #endif | |
44 | |
37 class TestSuite { | 45 class TestSuite { |
38 public: | 46 public: |
39 TestSuite(int argc, char** argv) { | 47 TestSuite(int argc, char** argv) { |
40 base::EnableTerminationOnHeapCorruption(); | 48 base::EnableTerminationOnHeapCorruption(); |
41 CommandLine::Init(argc, argv); | 49 CommandLine::Init(argc, argv); |
42 testing::InitGoogleTest(&argc, argv); | 50 testing::InitGoogleTest(&argc, argv); |
43 #if defined(OS_LINUX) | 51 #if defined(OS_LINUX) |
44 g_thread_init(NULL); | 52 g_thread_init(NULL); |
45 gtk_init_check(&argc, &argv); | 53 gtk_init_check(&argc, &argv); |
46 #endif | 54 #endif |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 | 125 |
118 #if defined(OS_POSIX) | 126 #if defined(OS_POSIX) |
119 // When running in an application, our code typically expects SIGPIPE | 127 // When running in an application, our code typically expects SIGPIPE |
120 // to be ignored. Therefore, when testing that same code, it should run | 128 // to be ignored. Therefore, when testing that same code, it should run |
121 // with SIGPIPE ignored as well. | 129 // with SIGPIPE ignored as well. |
122 struct sigaction action; | 130 struct sigaction action; |
123 action.sa_handler = SIG_IGN; | 131 action.sa_handler = SIG_IGN; |
124 action.sa_flags = 0; | 132 action.sa_flags = 0; |
125 sigemptyset(&action.sa_mask); | 133 sigemptyset(&action.sa_mask); |
126 CHECK(sigaction(SIGPIPE, &action, NULL) == 0); | 134 CHECK(sigaction(SIGPIPE, &action, NULL) == 0); |
135 | |
136 // TODO(phajdan.jr): Catch other crashy signals, like SIGABRT. | |
137 CHECK(signal(SIGSEGV, &TestSuiteCrashHandler) != SIG_ERR); | |
138 CHECK(signal(SIGILL, &TestSuiteCrashHandler) != SIG_ERR); | |
139 CHECK(signal(SIGBUS, &TestSuiteCrashHandler) != SIG_ERR); | |
agl
2009/09/03 17:36:33
SIGFPE is probably good too.
| |
127 #endif // OS_POSIX | 140 #endif // OS_POSIX |
128 | 141 |
129 #if defined(OS_WIN) | 142 #if defined(OS_WIN) |
130 // For unit tests we turn on the high resolution timer and disable | 143 // For unit tests we turn on the high resolution timer and disable |
131 // base::Time's use of SystemMonitor. Tests create and destroy the message | 144 // base::Time's use of SystemMonitor. Tests create and destroy the message |
132 // loop, which causes a crash with SystemMonitor (http://crbug.com/12187). | 145 // loop, which causes a crash with SystemMonitor (http://crbug.com/12187). |
133 base::Time::EnableHiResClockForTests(); | 146 base::Time::EnableHiResClockForTests(); |
134 | 147 |
135 // In some cases, we do not want to see standard error dialogs. | 148 // In some cases, we do not want to see standard error dialogs. |
136 if (!IsDebuggerPresent() && | 149 if (!IsDebuggerPresent() && |
(...skipping 12 matching lines...) Expand all Loading... | |
149 | 162 |
150 virtual void Shutdown() { | 163 virtual void Shutdown() { |
151 } | 164 } |
152 | 165 |
153 // Make sure that we setup an AtExitManager so Singleton objects will be | 166 // Make sure that we setup an AtExitManager so Singleton objects will be |
154 // destroyed. | 167 // destroyed. |
155 base::AtExitManager at_exit_manager_; | 168 base::AtExitManager at_exit_manager_; |
156 }; | 169 }; |
157 | 170 |
158 #endif // BASE_TEST_SUITE_H_ | 171 #endif // BASE_TEST_SUITE_H_ |
OLD | NEW |