Mojo: Add leak detection to mojo::embedder::test::Shutdown().

Don't hook up Init()/Shutdown() to our test harnesses yet, because
things blow up (we currently have singletons that will hold handles
across tests).

R=sky@chromium.org

Review URL: https://codereview.chromium.org/136793026

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@245605 0039d316-1c4b-4281-b951-d872f2087c98
parent d2965c49
...@@ -14,12 +14,17 @@ ...@@ -14,12 +14,17 @@
#include "mojo/system/system_impl_export.h" #include "mojo/system/system_impl_export.h"
namespace mojo { namespace mojo {
namespace system { namespace system {
class CoreImpl; class CoreImpl;
class Dispatcher; class Dispatcher;
// Test-only function (defined/used in embedder/test_embedder.cc). Declared here
// so it can be friended.
namespace internal {
bool ShutdownCheckNoLeaks(CoreImpl*);
}
// |CoreImpl| is a singleton object that implements the Mojo system calls. All // |CoreImpl| is a singleton object that implements the Mojo system calls. All
// public methods are thread-safe. // public methods are thread-safe.
class MOJO_SYSTEM_IMPL_EXPORT CoreImpl : public Core { class MOJO_SYSTEM_IMPL_EXPORT CoreImpl : public Core {
...@@ -80,6 +85,8 @@ class MOJO_SYSTEM_IMPL_EXPORT CoreImpl : public Core { ...@@ -80,6 +85,8 @@ class MOJO_SYSTEM_IMPL_EXPORT CoreImpl : public Core {
uint32_t num_bytes_read) OVERRIDE; uint32_t num_bytes_read) OVERRIDE;
private: private:
friend bool internal::ShutdownCheckNoLeaks(CoreImpl*);
// The |busy| member is used only to deal with functions (in particular // The |busy| member is used only to deal with functions (in particular
// |WriteMessage()|) that want to hold on to a dispatcher and later remove it // |WriteMessage()|) that want to hold on to a dispatcher and later remove it
// from the handle table, without holding on to the handle table lock. // from the handle table, without holding on to the handle table lock.
...@@ -145,7 +152,6 @@ class MOJO_SYSTEM_IMPL_EXPORT CoreImpl : public Core { ...@@ -145,7 +152,6 @@ class MOJO_SYSTEM_IMPL_EXPORT CoreImpl : public Core {
}; };
} // namespace system } // namespace system
} // namespace mojo } // namespace mojo
#endif // MOJO_SYSTEM_CORE_IMPL_H_ #endif // MOJO_SYSTEM_CORE_IMPL_H_
...@@ -91,7 +91,7 @@ TEST_F(EmbedderTest, ChannelsBasic) { ...@@ -91,7 +91,7 @@ TEST_F(EmbedderTest, ChannelsBasic) {
client_channel_info)); client_channel_info));
#endif // !defined(OS_WIN) #endif // !defined(OS_WIN)
test::Shutdown(); EXPECT_TRUE(test::Shutdown());
} }
// TODO(vtl): Test immediate write & close. // TODO(vtl): Test immediate write & close.
......
...@@ -5,22 +5,45 @@ ...@@ -5,22 +5,45 @@
#include "mojo/system/embedder/test_embedder.h" #include "mojo/system/embedder/test_embedder.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/macros.h"
#include "mojo/system/core_impl.h" #include "mojo/system/core_impl.h"
namespace mojo { namespace mojo {
namespace system {
namespace internal {
bool ShutdownCheckNoLeaks(CoreImpl* core_impl) {
// No point in taking the lock.
if (core_impl->handle_table_.empty())
return true;
for (CoreImpl::HandleTableMap::const_iterator it =
core_impl->handle_table_.begin();
it != core_impl->handle_table_.end();
++it) {
LOG(ERROR) << "Mojo embedder shutdown: Leaking handle " << (*it).first;
}
return false;
}
} // namespace internal
} // namespace system
namespace embedder { namespace embedder {
namespace test { namespace test {
void Shutdown() { bool Shutdown() {
system::CoreImpl* core_impl = static_cast<system::CoreImpl*>(Core::Get()); system::CoreImpl* core_impl = static_cast<system::CoreImpl*>(Core::Get());
CHECK(core_impl); CHECK(core_impl);
Core::Reset(); Core::Reset();
// TODO(vtl): Check for leaks, etc. bool rv = system::internal::ShutdownCheckNoLeaks(core_impl);
delete core_impl; delete core_impl;
return rv;
} }
} // namespace test } // namespace test
} // namespace embedder } // namespace embedder
} // namespace mojo } // namespace mojo
...@@ -13,8 +13,10 @@ namespace test { ...@@ -13,8 +13,10 @@ namespace test {
// This shuts down the global, singleton instance. (Note: "Real" embedders are // This shuts down the global, singleton instance. (Note: "Real" embedders are
// not expected to ever shut down this instance. This |Shutdown()| function will // not expected to ever shut down this instance. This |Shutdown()| function will
// do more work to ensure that tests don't leak, etc.) // do more work to ensure that tests don't leak, etc.) Returns true if there
MOJO_SYSTEM_IMPL_EXPORT void Shutdown(); // were no problems, false if there were leaks -- i.e., handles still open -- or
// any other problems.
MOJO_SYSTEM_IMPL_EXPORT bool Shutdown();
} // namespace test } // namespace test
} // namespace embedder } // namespace embedder
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment