Index: mojo/edk/test/mojo_test_base.cc |
diff --git a/mojo/edk/test/mojo_test_base.cc b/mojo/edk/test/mojo_test_base.cc |
index 7ec067aeae6742fe27c8f3ee33341536270d99bf..f6dea48dc3ffb64d4365ddaccf9b859662735376 100644 |
--- a/mojo/edk/test/mojo_test_base.cc |
+++ b/mojo/edk/test/mojo_test_base.cc |
@@ -13,11 +13,29 @@ |
#include "mojo/public/c/system/functions.h" |
#include "testing/gtest/include/gtest/gtest.h" |
+#if defined(OS_MACOSX) && !defined(OS_IOS) |
+#include "base/mac/mach_port_broker.h" |
+#endif |
+ |
namespace mojo { |
namespace edk { |
namespace test { |
+ |
+#if defined(OS_MACOSX) && !defined(OS_IOS) |
+namespace { |
+base::MachPortBroker* g_mach_broker = nullptr; |
+} |
+#endif |
+ |
MojoTestBase::MojoTestBase() { |
+#if defined(OS_MACOSX) && !defined(OS_IOS) |
+ if (!g_mach_broker) { |
+ g_mach_broker = new base::MachPortBroker("mojo_test"); |
+ CHECK(g_mach_broker->Init()); |
+ SetMachPortProviderIfNeeded(g_mach_broker); |
+ } |
+#endif |
} |
MojoTestBase::~MojoTestBase() {} |
@@ -31,12 +49,16 @@ MojoTestBase::ClientController& MojoTestBase::StartClient( |
MojoTestBase::ClientController::ClientController(const std::string& client_name, |
MojoTestBase* test) |
- : test_(test) |
+ : test_(test) { |
#if !defined(OS_IOS) |
- , |
- pipe_(helper_.StartChild(client_name)) |
+#if defined(OS_MACOSX) |
+ base::AutoLock lock(g_mach_broker->GetLock()); |
Ken Rockot(use gerrit already)
2016/03/09 08:34:31
nit: please document why you have to acquire this
Anand Mistry (off Chromium)
2016/03/11 07:44:18
Done.
|
+#endif |
+ pipe_ = helper_.StartChild(client_name); |
+#if defined(OS_MACOSX) |
+ g_mach_broker->AddPlaceholderForPid(helper_.test_child().Handle()); |
+#endif |
#endif |
-{ |
} |
MojoTestBase::ClientController::~ClientController() { |
@@ -47,7 +69,12 @@ MojoTestBase::ClientController::~ClientController() { |
int MojoTestBase::ClientController::WaitForShutdown() { |
was_shutdown_ = true; |
#if !defined(OS_IOS) |
- return helper_.WaitForChildShutdown(); |
+ int retval = helper_.WaitForChildShutdown(); |
+#if defined(OS_MACOSX) |
+ base::AutoLock lock(g_mach_broker->GetLock()); |
+ g_mach_broker->InvalidatePid(helper_.test_child().Handle()); |
+#endif |
+ return retval; |
#else |
NOTREACHED(); |
return 1; |