2012-09-20 23:30:53 +04:00
|
|
|
#include "TestActorPunning.h"
|
|
|
|
|
|
|
|
#include "IPDLUnitTests.h" // fail etc.
|
2016-08-23 07:09:32 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2012-09-20 23:30:53 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace _ipdltest {
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// parent
|
|
|
|
|
|
|
|
void
|
|
|
|
TestActorPunningParent::Main()
|
|
|
|
{
|
|
|
|
if (!SendStart())
|
|
|
|
fail("sending Start");
|
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2012-09-20 23:30:53 +04:00
|
|
|
TestActorPunningParent::RecvPun(PTestActorPunningSubParent* a, const Bad& bad)
|
|
|
|
{
|
|
|
|
if (a->SendBad())
|
|
|
|
fail("bad!");
|
|
|
|
fail("shouldn't have received this message in the first place");
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2012-09-20 23:30:53 +04:00
|
|
|
}
|
|
|
|
|
2016-11-24 00:40:04 +03:00
|
|
|
// By default, fatal errors kill the parent process, but this makes it
|
|
|
|
// hard to test, so instead we use the previous behavior and kill the
|
|
|
|
// child process.
|
|
|
|
void
|
|
|
|
TestActorPunningParent::HandleFatalError(const char* aProtocolName, const char* aErrorMsg) const
|
|
|
|
{
|
|
|
|
if (!!strcmp(aProtocolName, "PTestActorPunningParent")) {
|
|
|
|
fail("wrong protocol hit a fatal error");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!!strcmp(aErrorMsg, "Error deserializing 'PTestActorPunningSubParent'")) {
|
|
|
|
fail("wrong fatal error");
|
|
|
|
}
|
|
|
|
|
|
|
|
ipc::ScopedProcessHandle otherProcessHandle;
|
|
|
|
if (!base::OpenProcessHandle(OtherPid(), &otherProcessHandle.rwget())) {
|
|
|
|
fail("couldn't open child process");
|
|
|
|
} else {
|
|
|
|
if (!base::KillProcess(otherProcessHandle, 0, false)) {
|
|
|
|
fail("terminating child process");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-20 23:30:53 +04:00
|
|
|
PTestActorPunningPunnedParent*
|
2013-07-08 19:48:40 +04:00
|
|
|
TestActorPunningParent::AllocPTestActorPunningPunnedParent()
|
2012-09-20 23:30:53 +04:00
|
|
|
{
|
|
|
|
return new TestActorPunningPunnedParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-07-08 19:48:40 +04:00
|
|
|
TestActorPunningParent::DeallocPTestActorPunningPunnedParent(PTestActorPunningPunnedParent* a)
|
2012-09-20 23:30:53 +04:00
|
|
|
{
|
|
|
|
delete a;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
PTestActorPunningSubParent*
|
2013-07-08 19:48:40 +04:00
|
|
|
TestActorPunningParent::AllocPTestActorPunningSubParent()
|
2012-09-20 23:30:53 +04:00
|
|
|
{
|
|
|
|
return new TestActorPunningSubParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-07-08 19:48:40 +04:00
|
|
|
TestActorPunningParent::DeallocPTestActorPunningSubParent(PTestActorPunningSubParent* a)
|
2012-09-20 23:30:53 +04:00
|
|
|
{
|
|
|
|
delete a;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// child
|
|
|
|
|
|
|
|
PTestActorPunningPunnedChild*
|
2013-07-08 19:48:40 +04:00
|
|
|
TestActorPunningChild::AllocPTestActorPunningPunnedChild()
|
2012-09-20 23:30:53 +04:00
|
|
|
{
|
|
|
|
return new TestActorPunningPunnedChild();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-07-08 19:48:40 +04:00
|
|
|
TestActorPunningChild::DeallocPTestActorPunningPunnedChild(PTestActorPunningPunnedChild*)
|
2012-09-20 23:30:53 +04:00
|
|
|
{
|
|
|
|
fail("should have died by now");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
PTestActorPunningSubChild*
|
2013-07-08 19:48:40 +04:00
|
|
|
TestActorPunningChild::AllocPTestActorPunningSubChild()
|
2012-09-20 23:30:53 +04:00
|
|
|
{
|
|
|
|
return new TestActorPunningSubChild();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-07-08 19:48:40 +04:00
|
|
|
TestActorPunningChild::DeallocPTestActorPunningSubChild(PTestActorPunningSubChild*)
|
2012-09-20 23:30:53 +04:00
|
|
|
{
|
|
|
|
fail("should have died by now");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2012-09-20 23:30:53 +04:00
|
|
|
TestActorPunningChild::RecvStart()
|
|
|
|
{
|
|
|
|
SendPTestActorPunningSubConstructor();
|
|
|
|
SendPTestActorPunningPunnedConstructor();
|
|
|
|
PTestActorPunningSubChild* a = SendPTestActorPunningSubConstructor();
|
|
|
|
// We can't assert whether this succeeds or fails, due to race
|
|
|
|
// conditions.
|
|
|
|
SendPun(a, Bad());
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2012-09-20 23:30:53 +04:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2012-09-20 23:30:53 +04:00
|
|
|
TestActorPunningSubChild::RecvBad()
|
|
|
|
{
|
|
|
|
fail("things are going really badly right now");
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2012-09-20 23:30:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace _ipdltest
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
namespace IPC {
|
|
|
|
using namespace mozilla::_ipdltest;
|
|
|
|
using namespace mozilla::ipc;
|
|
|
|
|
|
|
|
/*static*/ void
|
|
|
|
ParamTraits<Bad>::Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
2016-05-17 01:09:51 +03:00
|
|
|
// Skip past the sentinel for the actor as well as the actor.
|
|
|
|
int32_t* ptr = aMsg->GetInt32PtrForTest(2 * sizeof(int32_t));
|
2012-09-20 23:30:53 +04:00
|
|
|
ActorHandle* ah = reinterpret_cast<ActorHandle*>(ptr);
|
|
|
|
if (ah->mId != -3)
|
|
|
|
fail("guessed wrong offset (value is %d, should be -3)", ah->mId);
|
|
|
|
ah->mId = -2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ bool
|
2016-04-21 07:09:15 +03:00
|
|
|
ParamTraits<Bad>::Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
|
2012-09-20 23:30:53 +04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace IPC
|
|
|
|
|