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

Unified Diff: base/test/test_suite.cc

Issue 10582012: For unit tests, track additions to AtExitManager and warn. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Back off to a warning. Created 8 years, 6 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 side-by-side diff with in-line comments
Download patch
« base/at_exit.h ('K') | « base/test/test_suite.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
}
« base/at_exit.h ('K') | « base/test/test_suite.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698