Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 } | 62 } |
| 63 | 63 |
| 64 private: | 64 private: |
| 65 CommandLine old_command_line_; | 65 CommandLine old_command_line_; |
| 66 | 66 |
| 67 DISALLOW_COPY_AND_ASSIGN(TestClientInitializer); | 67 DISALLOW_COPY_AND_ASSIGN(TestClientInitializer); |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 } // namespace | 70 } // namespace |
| 71 | 71 |
| 72 namespace base { | |
| 73 | |
| 74 class TestWatchAtExitManager : public testing::EmptyTestEventListener { | |
| 75 public: | |
| 76 TestWatchAtExitManager() { } | |
| 77 ~TestWatchAtExitManager() { } | |
| 78 | |
| 79 virtual void OnTestStart(const testing::TestInfo& test_info) OVERRIDE { | |
| 80 initial_top_manager_ = AtExitManager::CurrentAtExitManager(); | |
| 81 at_exit_stack_size_ = AtExitManager::CurrentAtExitCallbackStackSize(); | |
| 82 } | |
| 83 | |
| 84 virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE { | |
| 85 void* new_top_manager = AtExitManager::CurrentAtExitManager(); | |
| 86 size_t new_stack_size = AtExitManager::CurrentAtExitCallbackStackSize(); | |
| 87 | |
| 88 if (initial_top_manager_ != new_top_manager) { | |
| 89 LOG(ERROR) << "AtExitManager: stack changed depth across test " << | |
|
Paweł Hajdan Jr.
2012/06/21 08:45:24
This should also have a TODO above.
The error mes
Scott Byer
2012/06/21 21:35:01
Made it an error (doesn't currently occur anywhere
| |
| 90 test_info.test_case_name() << "." << test_info.name(); | |
| 91 } else if (new_stack_size != at_exit_stack_size_) { | |
| 92 // TODO(scottbyer): clean up all the errors that result from this and | |
| 93 // turn this into a test failure with | |
| 94 // ADD_FAILURE(). http://crbug.com/133403 | |
| 95 LOG(WARNING) << | |
| 96 "AtExitManager: items added to the callback list by " << | |
| 97 test_info.test_case_name() << "." << test_info.name() << | |
| 98 ". Test should be surrounded by a ShadowingAtExitManager."; | |
|
Paweł Hajdan Jr.
2012/06/21 08:45:24
ShadowingAtExitManager is not always the right sol
Scott Byer
2012/06/21 21:35:01
New wording, but I'm still trying to think through
| |
| 99 } | |
| 100 } | |
| 101 | |
| 102 private: | |
| 103 void* initial_top_manager_; | |
| 104 size_t at_exit_stack_size_; | |
| 105 | |
| 106 DISALLOW_COPY_AND_ASSIGN(TestWatchAtExitManager); | |
| 107 }; | |
| 108 | |
| 109 } // namespace base | |
| 110 | |
| 72 const char TestSuite::kStrictFailureHandling[] = "strict_failure_handling"; | 111 const char TestSuite::kStrictFailureHandling[] = "strict_failure_handling"; |
| 73 | 112 |
| 74 TestSuite::TestSuite(int argc, char** argv) : initialized_command_line_(false) { | 113 TestSuite::TestSuite(int argc, char** argv) : initialized_command_line_(false) { |
| 75 PreInitialize(argc, argv, true); | 114 PreInitialize(argc, argv, true); |
| 76 } | 115 } |
| 77 | 116 |
| 78 TestSuite::TestSuite(int argc, char** argv, bool create_at_exit_manager) | 117 TestSuite::TestSuite(int argc, char** argv, bool create_at_exit_manager) |
| 79 : initialized_command_line_(false) { | 118 : initialized_command_line_(false) { |
| 80 PreInitialize(argc, argv, create_at_exit_manager); | 119 PreInitialize(argc, argv, create_at_exit_manager); |
| 81 } | 120 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 testing::UnitTest::GetInstance()->listeners(); | 202 testing::UnitTest::GetInstance()->listeners(); |
| 164 listeners.Append(new MaybeTestDisabler); | 203 listeners.Append(new MaybeTestDisabler); |
| 165 } | 204 } |
| 166 | 205 |
| 167 void TestSuite::ResetCommandLine() { | 206 void TestSuite::ResetCommandLine() { |
| 168 testing::TestEventListeners& listeners = | 207 testing::TestEventListeners& listeners = |
| 169 testing::UnitTest::GetInstance()->listeners(); | 208 testing::UnitTest::GetInstance()->listeners(); |
| 170 listeners.Append(new TestClientInitializer); | 209 listeners.Append(new TestClientInitializer); |
| 171 } | 210 } |
| 172 | 211 |
| 212 void TestSuite::WatchAtExitManager() { | |
| 213 testing::TestEventListeners& listeners = | |
| 214 testing::UnitTest::GetInstance()->listeners(); | |
| 215 listeners.Append(new TestWatchAtExitManager); | |
| 216 } | |
| 217 | |
| 173 // Don't add additional code to this method. Instead add it to | 218 // Don't add additional code to this method. Instead add it to |
| 174 // Initialize(). See bug 6436. | 219 // Initialize(). See bug 6436. |
| 175 int TestSuite::Run() { | 220 int TestSuite::Run() { |
| 176 #if defined(OS_MACOSX) | 221 #if defined(OS_MACOSX) |
| 177 base::mac::ScopedNSAutoreleasePool scoped_pool; | 222 base::mac::ScopedNSAutoreleasePool scoped_pool; |
| 178 #endif | 223 #endif |
| 179 | 224 |
| 180 Initialize(); | 225 Initialize(); |
| 181 std::string client_func = | 226 std::string client_func = |
| 182 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 227 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 SuppressErrorDialogs(); | 325 SuppressErrorDialogs(); |
| 281 base::debug::SetSuppressDebugUI(true); | 326 base::debug::SetSuppressDebugUI(true); |
| 282 logging::SetLogAssertHandler(UnitTestAssertHandler); | 327 logging::SetLogAssertHandler(UnitTestAssertHandler); |
| 283 } | 328 } |
| 284 | 329 |
| 285 icu_util::Initialize(); | 330 icu_util::Initialize(); |
| 286 | 331 |
| 287 CatchMaybeTests(); | 332 CatchMaybeTests(); |
| 288 ResetCommandLine(); | 333 ResetCommandLine(); |
| 289 | 334 |
| 335 // Don't watch for AtExit items being added if we're running as a child | |
| 336 // process (e.g., browser_tests or interactive_ui_tests). | |
| 337 if (!CommandLine::ForCurrentProcess()->HasSwitch("single_process") && | |
|
Paweł Hajdan Jr.
2012/06/21 08:45:24
Don't hardcode command-line flags this way, we alw
Scott Byer
2012/06/21 21:35:01
Done.
| |
| 338 !CommandLine::ForCurrentProcess()->HasSwitch("single-process")) { | |
| 339 WatchAtExitManager(); | |
| 340 } | |
| 341 | |
| 290 TestTimeouts::Initialize(); | 342 TestTimeouts::Initialize(); |
| 291 } | 343 } |
| 292 | 344 |
| 293 void TestSuite::Shutdown() { | 345 void TestSuite::Shutdown() { |
| 294 } | 346 } |
| OLD | NEW |