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

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

Issue 10834010: Revert 144488 - For unit tests, track additions to AtExitManager and warn. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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/test/test_suite.h ('k') | base/test/test_switches.h » ('j') | 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 "base/at_exit.h" 7 #include "base/at_exit.h"
8 #include "base/base_paths.h" 8 #include "base/base_paths.h"
9 #include "base/base_switches.h" 9 #include "base/base_switches.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/debug/debug_on_start_win.h" 11 #include "base/debug/debug_on_start_win.h"
12 #include "base/debug/debugger.h" 12 #include "base/debug/debugger.h"
13 #include "base/file_path.h" 13 #include "base/file_path.h"
14 #include "base/i18n/icu_util.h" 14 #include "base/i18n/icu_util.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
17 #include "base/path_service.h" 17 #include "base/path_service.h"
18 #include "base/process_util.h" 18 #include "base/process_util.h"
19 #include "base/test/multiprocess_test.h" 19 #include "base/test/multiprocess_test.h"
20 #include "base/test/test_switches.h"
21 #include "base/test/test_timeouts.h" 20 #include "base/test/test_timeouts.h"
22 #include "base/time.h" 21 #include "base/time.h"
23 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
24 #include "testing/multiprocess_func_list.h" 23 #include "testing/multiprocess_func_list.h"
25 24
26 #if defined(OS_MACOSX) 25 #if defined(OS_MACOSX)
27 #include "base/mac/scoped_nsautorelease_pool.h" 26 #include "base/mac/scoped_nsautorelease_pool.h"
28 #if defined(OS_IOS) 27 #if defined(OS_IOS)
29 #include "base/test/test_listener_ios.h" 28 #include "base/test/test_listener_ios.h"
30 #else 29 #else
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 } 70 }
72 71
73 private: 72 private:
74 CommandLine old_command_line_; 73 CommandLine old_command_line_;
75 74
76 DISALLOW_COPY_AND_ASSIGN(TestClientInitializer); 75 DISALLOW_COPY_AND_ASSIGN(TestClientInitializer);
77 }; 76 };
78 77
79 } // namespace 78 } // namespace
80 79
81 namespace base {
82
83 class TestWatchAtExitManager : public testing::EmptyTestEventListener {
84 public:
85 TestWatchAtExitManager() { }
86 ~TestWatchAtExitManager() { }
87
88 virtual void OnTestStart(const testing::TestInfo& test_info) OVERRIDE {
89 initial_top_manager_ = AtExitManager::current();
90 at_exit_stack_size_ = initial_top_manager_->CallbackStackSize();
91 }
92
93 virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE {
94 AtExitManager* new_top_manager = AtExitManager::current();
95 size_t new_stack_size = new_top_manager->CallbackStackSize();
96
97 if (initial_top_manager_ != new_top_manager) {
98 ADD_FAILURE() << "The current AtExitManager has changed across the "
99 "test " << test_info.test_case_name() << "." << test_info.name() <<
100 " most likely because one was created without being destroyed.";
101 } else if (new_stack_size != at_exit_stack_size_) {
102 // TODO(scottbyer): clean up all the errors that result from this and
103 // turn this into a test failure with
104 // ADD_FAILURE(). http://crbug.com/133403
105 LOG(WARNING) <<
106 "AtExitManager: items were added to the callback list by " <<
107 test_info.test_case_name() << "." << test_info.name() <<
108 ". Global state should be cleaned up before a test exits.";
109 }
110 }
111
112 private:
113 AtExitManager* initial_top_manager_;
114 size_t at_exit_stack_size_;
115
116 DISALLOW_COPY_AND_ASSIGN(TestWatchAtExitManager);
117 };
118
119 } // namespace base
120
121 const char TestSuite::kStrictFailureHandling[] = "strict_failure_handling"; 80 const char TestSuite::kStrictFailureHandling[] = "strict_failure_handling";
122 81
123 TestSuite::TestSuite(int argc, char** argv) : initialized_command_line_(false) { 82 TestSuite::TestSuite(int argc, char** argv) : initialized_command_line_(false) {
124 PreInitialize(argc, argv, true); 83 PreInitialize(argc, argv, true);
125 } 84 }
126 85
127 TestSuite::TestSuite(int argc, char** argv, bool create_at_exit_manager) 86 TestSuite::TestSuite(int argc, char** argv, bool create_at_exit_manager)
128 : initialized_command_line_(false) { 87 : initialized_command_line_(false) {
129 PreInitialize(argc, argv, create_at_exit_manager); 88 PreInitialize(argc, argv, create_at_exit_manager);
130 } 89 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 testing::UnitTest::GetInstance()->listeners(); 171 testing::UnitTest::GetInstance()->listeners();
213 listeners.Append(new MaybeTestDisabler); 172 listeners.Append(new MaybeTestDisabler);
214 } 173 }
215 174
216 void TestSuite::ResetCommandLine() { 175 void TestSuite::ResetCommandLine() {
217 testing::TestEventListeners& listeners = 176 testing::TestEventListeners& listeners =
218 testing::UnitTest::GetInstance()->listeners(); 177 testing::UnitTest::GetInstance()->listeners();
219 listeners.Append(new TestClientInitializer); 178 listeners.Append(new TestClientInitializer);
220 } 179 }
221 180
222 void TestSuite::WatchAtExitManager() {
223 testing::TestEventListeners& listeners =
224 testing::UnitTest::GetInstance()->listeners();
225 listeners.Append(new TestWatchAtExitManager);
226 }
227
228 // Don't add additional code to this method. Instead add it to 181 // Don't add additional code to this method. Instead add it to
229 // Initialize(). See bug 6436. 182 // Initialize(). See bug 6436.
230 int TestSuite::Run() { 183 int TestSuite::Run() {
231 #if defined(OS_MACOSX) 184 #if defined(OS_MACOSX)
232 base::mac::ScopedNSAutoreleasePool scoped_pool; 185 base::mac::ScopedNSAutoreleasePool scoped_pool;
233 #endif 186 #endif
234 187
235 Initialize(); 188 Initialize();
236 std::string client_func = 189 std::string client_func =
237 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 190 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 SuppressErrorDialogs(); 295 SuppressErrorDialogs();
343 base::debug::SetSuppressDebugUI(true); 296 base::debug::SetSuppressDebugUI(true);
344 logging::SetLogAssertHandler(UnitTestAssertHandler); 297 logging::SetLogAssertHandler(UnitTestAssertHandler);
345 } 298 }
346 299
347 icu_util::Initialize(); 300 icu_util::Initialize();
348 301
349 CatchMaybeTests(); 302 CatchMaybeTests();
350 ResetCommandLine(); 303 ResetCommandLine();
351 304
352 // Don't watch for AtExit items being added if we're running as a child
353 // process (e.g., browser_tests or interactive_ui_tests).
354 if (!CommandLine::ForCurrentProcess()->HasSwitch(
355 switches::kSingleProcessTestsFlag) &&
356 !CommandLine::ForCurrentProcess()->HasSwitch(
357 switches::kSingleProcessChromeFlag)) {
358 WatchAtExitManager();
359 }
360
361 TestTimeouts::Initialize(); 305 TestTimeouts::Initialize();
362 } 306 }
363 307
364 void TestSuite::Shutdown() { 308 void TestSuite::Shutdown() {
365 } 309 }
OLDNEW
« no previous file with comments | « base/test/test_suite.h ('k') | base/test/test_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698