Chromium Code Reviews| Index: base/test/test_suite.cc |
| diff --git a/base/test/test_suite.cc b/base/test/test_suite.cc |
| index fb0070fc9de11b596c806a965270f6e708a77e4b..36e738686924fe2f7eddcc69fed5e761f7d512a5 100644 |
| --- a/base/test/test_suite.cc |
| +++ b/base/test/test_suite.cc |
| @@ -69,6 +69,45 @@ class TestClientInitializer : public testing::EmptyTestEventListener { |
| } // namespace |
| +namespace base { |
| + |
| +class TestWatchAtExitManager : public testing::EmptyTestEventListener { |
| + public: |
| + TestWatchAtExitManager() { } |
| + ~TestWatchAtExitManager() { } |
| + |
| + virtual void OnTestStart(const testing::TestInfo& test_info) OVERRIDE { |
| + initial_top_manager_ = AtExitManager::CurrentAtExitManager(); |
| + at_exit_stack_size_ = AtExitManager::CurrentAtExitCallbackStackSize(); |
| + } |
| + |
| + virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE { |
| + void* new_top_manager = AtExitManager::CurrentAtExitManager(); |
| + size_t new_stack_size = AtExitManager::CurrentAtExitCallbackStackSize(); |
| + |
| + if (initial_top_manager_ != new_top_manager) { |
| + 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
|
| + test_info.test_case_name() << "." << test_info.name(); |
| + } else if (new_stack_size != at_exit_stack_size_) { |
| + // TODO(scottbyer): clean up all the errors that result from this and |
| + // turn this into a test failure with |
| + // ADD_FAILURE(). http://crbug.com/133403 |
| + LOG(WARNING) << |
| + "AtExitManager: items added to the callback list by " << |
| + test_info.test_case_name() << "." << test_info.name() << |
| + ". 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
|
| + } |
| + } |
| + |
| + private: |
| + void* initial_top_manager_; |
| + size_t at_exit_stack_size_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TestWatchAtExitManager); |
| +}; |
| + |
| +} // namespace base |
| + |
| const char TestSuite::kStrictFailureHandling[] = "strict_failure_handling"; |
| TestSuite::TestSuite(int argc, char** argv) : initialized_command_line_(false) { |
| @@ -170,6 +209,12 @@ void TestSuite::ResetCommandLine() { |
| listeners.Append(new TestClientInitializer); |
| } |
| +void TestSuite::WatchAtExitManager() { |
| + testing::TestEventListeners& listeners = |
| + testing::UnitTest::GetInstance()->listeners(); |
| + listeners.Append(new TestWatchAtExitManager); |
| +} |
| + |
| // Don't add additional code to this method. Instead add it to |
| // Initialize(). See bug 6436. |
| int TestSuite::Run() { |
| @@ -287,6 +332,13 @@ void TestSuite::Initialize() { |
| CatchMaybeTests(); |
| ResetCommandLine(); |
| + // Don't watch for AtExit items being added if we're running as a child |
| + // process (e.g., browser_tests or interactive_ui_tests). |
| + 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.
|
| + !CommandLine::ForCurrentProcess()->HasSwitch("single-process")) { |
| + WatchAtExitManager(); |
| + } |
| + |
| TestTimeouts::Initialize(); |
| } |