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 c5df85c8f0
commit 0b11cb2e5b
3 changed files with 48 additions and 24 deletions

View File

@@ -299,6 +299,43 @@ PreallocatedProcessManagerImpl::GetSpareProcess()
return process.forget(); 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. * Publish a ContentParent to spare process list.
*/ */
@@ -307,14 +344,7 @@ PreallocatedProcessManagerImpl::PublishSpareProcess(ContentParent* aContent)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
if (Preferences::GetBool("dom.ipc.preallocatedProcessManager.testMode")) { SendTestOnlyNotification("TEST-ONLY:nuwa-add-new-process");
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);
}
mSpareProcesses.AppendElement(aContent); mSpareProcesses.AppendElement(aContent);
} }
@@ -333,7 +363,7 @@ PreallocatedProcessManagerImpl::MaybeForgetSpare(ContentParent* aContent)
mIsNuwaReady = false; mIsNuwaReady = false;
while (mSpareProcesses.Length() > 0) { while (mSpareProcesses.Length() > 0) {
nsRefPtr<ContentParent> process = mSpareProcesses[mSpareProcesses.Length() - 1]; nsRefPtr<ContentParent> process = mSpareProcesses[mSpareProcesses.Length() - 1];
process->Close(); KillOrCloseProcess(aContent);
mSpareProcesses.RemoveElementAt(mSpareProcesses.Length() - 1); mSpareProcesses.RemoveElementAt(mSpareProcesses.Length() - 1);
} }
ScheduleDelayedNuwaFork(); ScheduleDelayedNuwaFork();
@@ -353,14 +383,8 @@ PreallocatedProcessManagerImpl::OnNuwaReady()
ProcessPriorityManager::SetProcessPriority(mPreallocatedAppProcess, ProcessPriorityManager::SetProcessPriority(mPreallocatedAppProcess,
hal::PROCESS_PRIORITY_MASTER); hal::PROCESS_PRIORITY_MASTER);
mIsNuwaReady = true; mIsNuwaReady = true;
if (Preferences::GetBool("dom.ipc.preallocatedProcessManager.testMode")) { SendTestOnlyNotification("TEST-ONLY:nuwa-ready");
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);
}
NuwaFork(); NuwaFork();
} }
@@ -370,7 +394,6 @@ PreallocatedProcessManagerImpl::PreallocatedProcessReady()
return !mSpareProcesses.IsEmpty(); return !mSpareProcesses.IsEmpty();
} }
void void
PreallocatedProcessManagerImpl::NuwaFork() PreallocatedProcessManagerImpl::NuwaFork()
{ {
@@ -399,7 +422,7 @@ PreallocatedProcessManagerImpl::Disable()
#ifdef MOZ_NUWA_PROCESS #ifdef MOZ_NUWA_PROCESS
while (mSpareProcesses.Length() > 0){ while (mSpareProcesses.Length() > 0){
nsRefPtr<ContentParent> process = mSpareProcesses[0]; nsRefPtr<ContentParent> process = mSpareProcesses[0];
process->Close(); KillOrCloseProcess(process);
mSpareProcesses.RemoveElementAt(0); mSpareProcesses.RemoveElementAt(0);
} }
mIsNuwaReady = false; mIsNuwaReady = false;

View File

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

View File

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