Bug 1050604 - Get IPDL tests passing again (r=bent)

This commit is contained in:
Bill McCloskey 2014-08-20 12:49:11 -07:00
Родитель be42be0ea4
Коммит 4cedc603cb
9 изменённых файлов: 77 добавлений и 41 удалений

Просмотреть файл

@ -163,6 +163,9 @@ PluginModuleChild::Init(const std::string& aPluginFilename,
true,
getter_AddRefs(localFile));
if (!localFile)
return false;
bool exists;
localFile->Exists(&exists);
NS_ASSERTION(exists, "plugin file ain't there");

Просмотреть файл

@ -17,15 +17,19 @@ using namespace IPC;
namespace mozilla {
namespace ipc {
#ifdef MOZ_IPDL_TESTS
bool IToplevelProtocol::sAllowNonMainThreadUse;
#endif
IToplevelProtocol::~IToplevelProtocol()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(NS_IsMainThread() || AllowNonMainThreadUse());
mOpenActors.clear();
}
void IToplevelProtocol::AddOpenedActor(IToplevelProtocol* aActor)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(NS_IsMainThread() || AllowNonMainThreadUse());
#ifdef DEBUG
for (const IToplevelProtocol* actor = mOpenActors.getFirst();
@ -62,6 +66,14 @@ IToplevelProtocol::CloneOpenedToplevels(IToplevelProtocol* aTemplate,
}
}
#ifdef MOZ_IPDL_TESTS
void
IToplevelProtocol::SetAllowNonMainThreadUse()
{
sAllowNonMainThreadUse = true;
}
#endif
class ChannelOpened : public IPC::Message
{
public:

Просмотреть файл

@ -188,7 +188,7 @@ protected:
: mProtocolId(aProtoId)
, mTrans(nullptr)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(NS_IsMainThread() || AllowNonMainThreadUse());
}
~IToplevelProtocol();
@ -214,12 +214,12 @@ public:
*/
IToplevelProtocol* GetFirstOpenedActors()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(NS_IsMainThread() || AllowNonMainThreadUse());
return mOpenActors.getFirst();
}
const IToplevelProtocol* GetFirstOpenedActors() const
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(NS_IsMainThread() || AllowNonMainThreadUse());
return mOpenActors.getFirst();
}
@ -233,11 +233,27 @@ public:
base::ProcessHandle aPeerProcess,
ProtocolCloneContext* aCtx);
#ifdef MOZ_IPDL_TESTS
static void SetAllowNonMainThreadUse();
#endif
static bool AllowNonMainThreadUse() {
#ifdef MOZ_IPDL_TESTS
return sAllowNonMainThreadUse;
#else
return false;
#endif
}
private:
LinkedList<IToplevelProtocol> mOpenActors; // All protocol actors opened by this.
ProtocolId mProtocolId;
Transport* mTrans;
#ifdef MOZ_IPDL_TESTS
static bool sAllowNonMainThreadUse;
#endif
};

Просмотреть файл

@ -38,6 +38,9 @@ MessageLoop *gParentMessageLoop;
bool gParentDone;
bool gChildDone;
void
DeleteChildActor();
//-----------------------------------------------------------------------------
// data/functions accessed by both parent and child processes
@ -135,6 +138,10 @@ IPDLUnitTestMain(void* aData)
{
char* testString = reinterpret_cast<char*>(aData);
// Some tests require this, and we don't care what thread we're on if we're
// not using Nuwa.
mozilla::ipc::IToplevelProtocol::SetAllowNonMainThreadUse();
// Check if we are to run the test using threads instead:
const char *prefix = "thread:";
const int prefixLen = strlen(prefix);
@ -321,6 +328,13 @@ QuitParent()
}
}
static void
ChildDie()
{
DeleteChildActor();
XRE_ShutdownChildProcess();
}
void
QuitChild()
{
@ -328,7 +342,8 @@ QuitChild()
gParentMessageLoop->PostTask(
FROM_HERE, NewRunnableFunction(ChildCompleted));
} else { // Process-mode test
XRE_ShutdownChildProcess();
MessageLoop::current()->PostTask(
FROM_HERE, NewRunnableFunction(ChildDie));
}
}
@ -362,8 +377,9 @@ IPDLUnitTestChildInit(IPC::Channel* transport,
base::ProcessHandle parent,
MessageLoop* worker)
{
if (atexit(DeleteChildActor))
fail("can't install atexit() handler");
// Some tests require this, and we don't care what thread we're on if we're
// not using Nuwa.
mozilla::ipc::IToplevelProtocol::SetAllowNonMainThreadUse();
switch (IPDLUnitTest()) {
//-----------------------------------------------------------------------------

Просмотреть файл

@ -13,7 +13,6 @@ child:
async Start();
rpc Reply1() returns (uint32_t result);
rpc Reply2() returns (uint32_t result);
rpc FinalTest_Hang();
};
} // namespace _ipdltest

Просмотреть файл

@ -120,6 +120,19 @@ TestOpensOpenedParent::AnswerHelloRpc()
return CallHiRpc();
}
static void
ShutdownTestOpensOpenedParent(TestOpensOpenedParent* parent,
Transport* transport)
{
delete parent;
// Now delete the transport, which has to happen after the
// top-level actor is deleted.
XRE_GetIOMessageLoop()->PostTask(
FROM_HERE,
new DeleteTask<Transport>(transport));
}
void
TestOpensOpenedParent::ActorDestroy(ActorDestroyReason why)
{
@ -131,12 +144,10 @@ TestOpensOpenedParent::ActorDestroy(ActorDestroyReason why)
// ActorDestroy() is just a callback from IPDL-generated code,
// which needs the top-level actor (this) to stay alive a little
// longer so other things can be cleaned up.
MessageLoop::current()->PostTask(
gMainThread->PostTask(
FROM_HERE,
new DeleteTask<TestOpensOpenedParent>(this));
XRE_GetIOMessageLoop()->PostTask(
FROM_HERE,
new DeleteTask<Transport>(mTransport));
NewRunnableFunction(ShutdownTestOpensOpenedParent,
this, mTransport));
}
//-----------------------------------------------------------------------------
@ -270,7 +281,7 @@ TestOpensOpenedChild::ActorDestroy(ActorDestroyReason why)
// which needs the top-level actor (this) to stay alive a little
// longer so other things can be cleaned up. Defer shutdown to
// let cleanup finish.
MessageLoop::current()->PostTask(
gMainThread->PostTask(
FROM_HERE,
NewRunnableFunction(ShutdownTestOpensOpenedChild,
this, mTransport));

Просмотреть файл

@ -18,7 +18,7 @@ public:
virtual ~TestRPCParent();
static bool RunTestInProcesses() { return true; }
static bool RunTestInThreads() { return true; }
static bool RunTestInThreads() { return false; }
void Main();

Просмотреть файл

@ -80,16 +80,7 @@ TestUrgencyParent::RecvTest3(uint32_t *value)
bool
TestUrgencyParent::RecvFinalTest_Begin()
{
SetReplyTimeoutMs(2000);
if (CallFinalTest_Hang())
fail("should have failed due to timeout");
if (!GetIPCChannel()->Unsound_IsClosed())
fail("channel should have closed");
MessageLoop::current()->PostTask(
FROM_HERE,
NewRunnableMethod(this, &TestUrgencyParent::Close));
return false;
return true;
}
//-----------------------------------------------------------------------------
@ -130,9 +121,8 @@ TestUrgencyChild::RecvStart()
if (result != 1000)
fail("wrong value from test3");
// This must be the last test, since the child process may die.
if (SendFinalTest_Begin())
fail("Final test should not have succeeded");
if (!SendFinalTest_Begin())
fail("Final test should have succeeded");
Close();
@ -164,13 +154,6 @@ TestUrgencyChild::AnswerReply2(uint32_t *reply)
return true;
}
bool
TestUrgencyChild::AnswerFinalTest_Hang()
{
Sleep(10);
return true;
}
TestUrgencyChild::TestUrgencyChild()
: test_(0)
{

Просмотреть файл

@ -18,7 +18,7 @@ public:
virtual ~TestUrgencyParent();
static bool RunTestInProcesses() { return true; }
static bool RunTestInThreads() { return true; }
static bool RunTestInThreads() { return false; }
void Main();
@ -35,8 +35,6 @@ public:
}
virtual void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE
{
if (AbnormalShutdown != why)
fail("unexpected destruction!");
passed("ok");
QuitParent();
}
@ -61,8 +59,6 @@ public:
virtual void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE
{
if (AbnormalShutdown != why)
fail("unexpected destruction!");
QuitChild();
}