Bug 1168337: Kill the processes on startup of the Nuwa test case fix the abort in the preallocated process. r=khuey

This commit is contained in:
Cervantes Yu 2015-10-13 10:58:43 +08:00
parent 17762b53b7
commit 97b55066d9
3 changed files with 48 additions and 24 deletions

View File

@ -299,6 +299,43 @@ PreallocatedProcessManagerImpl::GetSpareProcess()
return process.forget();
}
static bool
TestCaseEnabled()
{
return Preferences::GetBool("dom.ipc.preallocatedProcessManager.testMode");
}
static void
SendTestOnlyNotification(const char* aMessage)
{
if (!TestCaseEnabled()) {
return;
}
AutoSafeJSContext cx;
nsString message;
message.AppendPrintf("%s", aMessage);
nsCOMPtr<nsIMessageBroadcaster> ppmm =
do_GetService("@mozilla.org/parentprocessmessagemanager;1");
mozilla::unused << ppmm->BroadcastAsyncMessage(
message, JS::NullHandleValue, JS::NullHandleValue, cx, 1);
}
static void
KillOrCloseProcess(ContentParent* aProcess)
{
if (TestCaseEnabled()) {
// KillHard() the process because we don't want the process to abort when we
// close the IPC channel while it's still running and creating actors.
aProcess->KillHard("Killed by test case.");
}
else {
aProcess->Close();
}
}
/**
* Publish a ContentParent to spare process list.
*/
@ -307,14 +344,7 @@ PreallocatedProcessManagerImpl::PublishSpareProcess(ContentParent* aContent)
{
MOZ_ASSERT(NS_IsMainThread());
if (Preferences::GetBool("dom.ipc.preallocatedProcessManager.testMode")) {
AutoJSContext cx;
nsCOMPtr<nsIMessageBroadcaster> ppmm =
do_GetService("@mozilla.org/parentprocessmessagemanager;1");
mozilla::unused << ppmm->BroadcastAsyncMessage(
NS_LITERAL_STRING("TEST-ONLY:nuwa-add-new-process"),
JS::NullHandleValue, JS::NullHandleValue, cx, 1);
}
SendTestOnlyNotification("TEST-ONLY:nuwa-add-new-process");
mSpareProcesses.AppendElement(aContent);
}
@ -333,7 +363,7 @@ PreallocatedProcessManagerImpl::MaybeForgetSpare(ContentParent* aContent)
mIsNuwaReady = false;
while (mSpareProcesses.Length() > 0) {
nsRefPtr<ContentParent> process = mSpareProcesses[mSpareProcesses.Length() - 1];
process->Close();
KillOrCloseProcess(aContent);
mSpareProcesses.RemoveElementAt(mSpareProcesses.Length() - 1);
}
ScheduleDelayedNuwaFork();
@ -353,14 +383,8 @@ PreallocatedProcessManagerImpl::OnNuwaReady()
ProcessPriorityManager::SetProcessPriority(mPreallocatedAppProcess,
hal::PROCESS_PRIORITY_MASTER);
mIsNuwaReady = true;
if (Preferences::GetBool("dom.ipc.preallocatedProcessManager.testMode")) {
AutoJSContext cx;
nsCOMPtr<nsIMessageBroadcaster> ppmm =
do_GetService("@mozilla.org/parentprocessmessagemanager;1");
mozilla::unused << ppmm->BroadcastAsyncMessage(
NS_LITERAL_STRING("TEST-ONLY:nuwa-ready"),
JS::NullHandleValue, JS::NullHandleValue, cx, 1);
}
SendTestOnlyNotification("TEST-ONLY:nuwa-ready");
NuwaFork();
}
@ -370,7 +394,6 @@ PreallocatedProcessManagerImpl::PreallocatedProcessReady()
return !mSpareProcesses.IsEmpty();
}
void
PreallocatedProcessManagerImpl::NuwaFork()
{
@ -399,7 +422,7 @@ PreallocatedProcessManagerImpl::Disable()
#ifdef MOZ_NUWA_PROCESS
while (mSpareProcesses.Length() > 0){
nsRefPtr<ContentParent> process = mSpareProcesses[0];
process->Close();
KillOrCloseProcess(process);
mSpareProcesses.RemoveElementAt(0);
}
mIsNuwaReady = false;

View File

@ -14,7 +14,7 @@ skip-if = buildapp == 'b2g' || buildapp == 'mulet' || e10s || toolkit == 'androi
[test_cpow_cookies.html]
skip-if = buildapp == 'b2g' || buildapp == 'mulet'
[test_NuwaProcessCreation.html]
skip-if = true # bug 1166923
skip-if = toolkit != 'gonk'
[test_NuwaProcessDeadlock.html]
skip-if = true # bug 1166923
[test_child_docshell.html]

View File

@ -14,6 +14,9 @@ Test if Nuwa process created successfully.
function runTest()
{
info("Shut down processes by disabling process prelaunch");
SpecialPowers.setBoolPref('dom.ipc.processPrelaunch.enabled', false);
info("Launch the Nuwa process");
let cpmm = SpecialPowers.Cc["@mozilla.org/childprocessmessagemanager;1"]
.getService(SpecialPowers.Ci.nsISyncMessageSender);
@ -22,12 +25,11 @@ function runTest()
receiveMessage: function receiveMessage(msg) {
msg = SpecialPowers.wrap(msg);
if (msg.name == 'TEST-ONLY:nuwa-ready') {
ok(true, "Got nuwa-ready");
is(seenNuwaReady, false, "Already received nuwa ready");
is(seenNuwaReady, false, "The Nuwa process is launched");
seenNuwaReady = true;
} else if (msg.name == 'TEST-ONLY:nuwa-add-new-process') {
ok(true, "Got nuwa-add-new-process");
is(seenNuwaReady, true, "Receive nuwa-add-new-process before nuwa-ready");
is(seenNuwaReady, true, "The preallocated process is launched from the Nuwa process");
shutdown();
}
}
@ -56,7 +58,6 @@ function setup()
SpecialPowers.pushPrefEnv({
'set': [
['dom.ipc.processPrelaunch.enabled', false],
['dom.ipc.preallocatedProcessManager.testMode', true]
]
}, runTest);