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

Side by Side Diff: base/test/test_suite.cc

Issue 2638763004: Report CHECK/DCHECK to test launcher summary output. (Closed)
Patch Set: Add stack trace marker. Created 3 years, 11 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
« base/logging.cc ('K') | « base/test/test_suite.h ('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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/test/test_suite.h" 5 #include "base/test/test_suite.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/at_exit.h" 9 #include "base/at_exit.h"
10 #include "base/base_paths.h" 10 #include "base/base_paths.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 #endif 58 #endif
59 59
60 #if defined(OS_IOS) 60 #if defined(OS_IOS)
61 #include "base/test/test_support_ios.h" 61 #include "base/test/test_support_ios.h"
62 #endif 62 #endif
63 63
64 namespace base { 64 namespace base {
65 65
66 namespace { 66 namespace {
67 67
68 TestSuite* g_test_suite = nullptr;
69
68 class MaybeTestDisabler : public testing::EmptyTestEventListener { 70 class MaybeTestDisabler : public testing::EmptyTestEventListener {
69 public: 71 public:
70 void OnTestStart(const testing::TestInfo& test_info) override { 72 void OnTestStart(const testing::TestInfo& test_info) override {
71 ASSERT_FALSE(TestSuite::IsMarkedMaybe(test_info)) 73 ASSERT_FALSE(TestSuite::IsMarkedMaybe(test_info))
72 << "Probably the OS #ifdefs don't include all of the necessary " 74 << "Probably the OS #ifdefs don't include all of the necessary "
73 "platforms.\nPlease ensure that no tests have the MAYBE_ prefix " 75 "platforms.\nPlease ensure that no tests have the MAYBE_ prefix "
74 "after the code is preprocessed."; 76 "after the code is preprocessed.";
75 } 77 }
76 }; 78 };
77 79
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 InitializeFromCommandLine(argc, argv); 153 InitializeFromCommandLine(argc, argv);
152 // Logging must be initialized before any thread has a chance to call logging 154 // Logging must be initialized before any thread has a chance to call logging
153 // functions. 155 // functions.
154 InitializeLogging(); 156 InitializeLogging();
155 } 157 }
156 #endif // defined(OS_WIN) 158 #endif // defined(OS_WIN)
157 159
158 TestSuite::~TestSuite() { 160 TestSuite::~TestSuite() {
159 if (initialized_command_line_) 161 if (initialized_command_line_)
160 CommandLine::Reset(); 162 CommandLine::Reset();
163
164 g_test_suite = nullptr;
161 } 165 }
162 166
163 void TestSuite::InitializeFromCommandLine(int argc, char** argv) { 167 void TestSuite::InitializeFromCommandLine(int argc, char** argv) {
164 initialized_command_line_ = CommandLine::Init(argc, argv); 168 initialized_command_line_ = CommandLine::Init(argc, argv);
165 testing::InitGoogleTest(&argc, argv); 169 testing::InitGoogleTest(&argc, argv);
166 testing::InitGoogleMock(&argc, argv); 170 testing::InitGoogleMock(&argc, argv);
167 171
168 #if defined(OS_IOS) 172 #if defined(OS_IOS)
169 InitIOSRunHook(this, argc, argv); 173 InitIOSRunHook(this, argc, argv);
170 #endif 174 #endif
171 } 175 }
172 176
173 #if defined(OS_WIN) 177 #if defined(OS_WIN)
174 void TestSuite::InitializeFromCommandLine(int argc, wchar_t** argv) { 178 void TestSuite::InitializeFromCommandLine(int argc, wchar_t** argv) {
175 // Windows CommandLine::Init ignores argv anyway. 179 // Windows CommandLine::Init ignores argv anyway.
176 initialized_command_line_ = CommandLine::Init(argc, NULL); 180 initialized_command_line_ = CommandLine::Init(argc, NULL);
177 testing::InitGoogleTest(&argc, argv); 181 testing::InitGoogleTest(&argc, argv);
178 testing::InitGoogleMock(&argc, argv); 182 testing::InitGoogleMock(&argc, argv);
179 } 183 }
180 #endif // defined(OS_WIN) 184 #endif // defined(OS_WIN)
181 185
182 void TestSuite::PreInitialize() { 186 void TestSuite::PreInitialize() {
187 g_test_suite = this;
183 #if defined(OS_WIN) 188 #if defined(OS_WIN)
184 testing::GTEST_FLAG(catch_exceptions) = false; 189 testing::GTEST_FLAG(catch_exceptions) = false;
185 #endif 190 #endif
186 EnableTerminationOnHeapCorruption(); 191 EnableTerminationOnHeapCorruption();
187 #if defined(OS_LINUX) && defined(USE_AURA) 192 #if defined(OS_LINUX) && defined(USE_AURA)
188 // When calling native char conversion functions (e.g wrctomb) we need to 193 // When calling native char conversion functions (e.g wrctomb) we need to
189 // have the locale set. In the absence of such a call the "C" locale is the 194 // have the locale set. In the absence of such a call the "C" locale is the
190 // default. In the gtk code (below) gtk_init() implicitly sets a locale. 195 // default. In the gtk code (below) gtk_init() implicitly sets a locale.
191 setlocale(LC_ALL, ""); 196 setlocale(LC_ALL, "");
192 #endif // defined(OS_LINUX) && defined(USE_AURA) 197 #endif // defined(OS_LINUX) && defined(USE_AURA)
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 236
232 // Do not add the result printer if output path already exists. It's an 237 // Do not add the result printer if output path already exists. It's an
233 // indicator there is a process printing to that file, and we're likely 238 // indicator there is a process printing to that file, and we're likely
234 // its child. Do not clobber the results in that case. 239 // its child. Do not clobber the results in that case.
235 if (PathExists(output_path)) { 240 if (PathExists(output_path)) {
236 LOG(WARNING) << "Test launcher output path " << output_path.AsUTF8Unsafe() 241 LOG(WARNING) << "Test launcher output path " << output_path.AsUTF8Unsafe()
237 << " exists. Not adding test launcher result printer."; 242 << " exists. Not adding test launcher result printer.";
238 return; 243 return;
239 } 244 }
240 245
241 XmlUnitTestResultPrinter* printer = new XmlUnitTestResultPrinter; 246 printer_ = new XmlUnitTestResultPrinter;
242 CHECK(printer->Initialize(output_path)); 247 CHECK(printer_->Initialize(output_path));
243 testing::TestEventListeners& listeners = 248 testing::TestEventListeners& listeners =
244 testing::UnitTest::GetInstance()->listeners(); 249 testing::UnitTest::GetInstance()->listeners();
245 listeners.Append(printer); 250 listeners.Append(printer_);
251
252 logging::SetLogMessageHandler(UnitTestLogMessageHandler);
Paweł Hajdan Jr. 2017/01/23 16:55:06 Is this composable with any other possibly install
alex-ac 2017/01/27 12:55:45 I've changed the way of setting LogAssertMessageHa
246 } 253 }
247 254
248 // Don't add additional code to this method. Instead add it to 255 // Don't add additional code to this method. Instead add it to
249 // Initialize(). See bug 6436. 256 // Initialize(). See bug 6436.
250 int TestSuite::Run() { 257 int TestSuite::Run() {
251 #if defined(OS_IOS) 258 #if defined(OS_IOS)
252 RunTestsFromIOSApp(); 259 RunTestsFromIOSApp();
253 #endif 260 #endif
254 261
255 #if defined(OS_MACOSX) 262 #if defined(OS_MACOSX)
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 << test_info->name(); 303 << test_info->name();
297 fflush(stderr); 304 fflush(stderr);
298 } 305 }
299 #endif // defined(OS_ANDROID) 306 #endif // defined(OS_ANDROID)
300 307
301 // The logging system actually prints the message before calling the assert 308 // The logging system actually prints the message before calling the assert
302 // handler. Just exit now to avoid printing too many stack traces. 309 // handler. Just exit now to avoid printing too many stack traces.
303 _exit(1); 310 _exit(1);
304 } 311 }
305 312
313 // static
314 bool TestSuite::UnitTestLogMessageHandler(int severity,
315 const char* file,
316 int line,
317 size_t message_start,
318 const std::string& str) {
319 if (severity == logging::LOG_FATAL && g_test_suite &&
320 g_test_suite->printer_) {
321 std::string message = str.substr(message_start);
322 std::string summary;
323
324 size_t marker_pos = message.find(logging::kStackTraceMarker);
325 if (marker_pos == std::string::npos) {
326 summary = message;
327 } else {
328 summary = message.substr(0, marker_pos);
329 }
330 g_test_suite->printer_->OnAssert(file, line, summary, message);
Paweł Hajdan Jr. 2017/01/23 16:55:06 This entire thing seems hacky. We use globals, and
alex-ac 2017/01/27 12:55:45 I've changed logging handler API to use base::Call
331 }
332 return false;
333 }
334
306 void TestSuite::SuppressErrorDialogs() { 335 void TestSuite::SuppressErrorDialogs() {
307 #if defined(OS_WIN) 336 #if defined(OS_WIN)
308 UINT new_flags = SEM_FAILCRITICALERRORS | 337 UINT new_flags = SEM_FAILCRITICALERRORS |
309 SEM_NOGPFAULTERRORBOX | 338 SEM_NOGPFAULTERRORBOX |
310 SEM_NOOPENFILEERRORBOX; 339 SEM_NOOPENFILEERRORBOX;
311 340
312 // Preserve existing error mode, as discussed at 341 // Preserve existing error mode, as discussed at
313 // http://blogs.msdn.com/oldnewthing/archive/2004/07/27/198410.aspx 342 // http://blogs.msdn.com/oldnewthing/archive/2004/07/27/198410.aspx
314 UINT existing_flags = SetErrorMode(new_flags); 343 UINT existing_flags = SetErrorMode(new_flags);
315 SetErrorMode(existing_flags | new_flags); 344 SetErrorMode(existing_flags | new_flags);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 428
400 void TestSuite::Shutdown() { 429 void TestSuite::Shutdown() {
401 base::debug::StopProfiling(); 430 base::debug::StopProfiling();
402 431
403 // Clear the FeatureList that was created by Initialize(). 432 // Clear the FeatureList that was created by Initialize().
404 if (created_feature_list_) 433 if (created_feature_list_)
405 FeatureList::ClearInstanceForTesting(); 434 FeatureList::ClearInstanceForTesting();
406 } 435 }
407 436
408 } // namespace base 437 } // namespace base
OLDNEW
« base/logging.cc ('K') | « base/test/test_suite.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698