Bug 1319910 - Crash child, not parent, on FatalError in TestActorPunning and TestBadActor. r=billm

The parent process crashes if it gets a bad message from the child,
but that makes it hard to test. This patch overrides the fatal error
handling method and uses the old behavior, that kills the child.

I copied the code to kill the child from TestHangs.

MozReview-Commit-ID: 3YgqaCgHGI0

--HG--
extra : rebase_source : cbecee2742014e969c641b89833cff5f46b99a33
This commit is contained in:
Andrew McCreight 2016-11-23 13:40:04 -08:00
parent 1cb2f34ca9
commit ced5e33c0a
4 changed files with 53 additions and 1 deletions

View File

@ -25,6 +25,30 @@ TestActorPunningParent::RecvPun(PTestActorPunningSubParent* a, const Bad& bad)
return IPC_OK();
}
// 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");
}
}
}
PTestActorPunningPunnedParent*
TestActorPunningParent::AllocPTestActorPunningPunnedParent()
{

View File

@ -35,10 +35,12 @@ protected:
virtual void ActorDestroy(ActorDestroyReason why) override
{
if (NormalShutdown == why)
fail("should have died from error!");
fail("should have died from error!");
passed("ok");
QuitParent();
}
virtual void HandleFatalError(const char* aProtocolName, const char* aErrorMsg) const override;
};
class TestActorPunningPunnedParent :

View File

@ -19,6 +19,30 @@ TestBadActorParent::Main()
Unused << child->Call__delete__(child);
}
// 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
TestBadActorParent::HandleFatalError(const char* aProtocolName, const char* aErrorMsg) const
{
if (!!strcmp(aProtocolName, "PTestBadActorSubParent")) {
fail("wrong protocol hit a fatal error");
}
if (!!strcmp(aErrorMsg, "incoming message racing with actor deletion")) {
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");
}
}
}
PTestBadActorSubParent*
TestBadActorParent::AllocPTestBadActorSubParent()
{

View File

@ -33,6 +33,8 @@ protected:
QuitParent();
}
virtual void HandleFatalError(const char* aProtocolName, const char* aErrorMsg) const override;
virtual PTestBadActorSubParent*
AllocPTestBadActorSubParent() override;