Bug 1749809 - Basic profiler test for UtilityProcess r=florian

Differential Revision: https://phabricator.services.mozilla.com/D137752
This commit is contained in:
Alexandre Lissy 2022-02-04 21:05:49 +00:00
parent ef1c1d2562
commit f9a5917710
5 changed files with 101 additions and 2 deletions

View File

@ -1,4 +1,7 @@
[DEFAULT]
support-files =
../../../../tools/profiler/tests/shared-head.js
[browser_utility.js]
[browser_utility_profiler.js]
skip-if = tsan # from tools/profiler/tests/browser/browser.ini, timing out on profiler tests?
[browser_utility_start.js]

View File

@ -0,0 +1,72 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/* import-globals-from /tools/profiler/tests/shared-head.js */
Services.scriptloader.loadSubScript(
"chrome://mochitests/content/browser/tools/profiler/tests/browser/shared-head.js",
this
);
var utilityPid = undefined;
const utilityProcessTest = Cc[
"@mozilla.org/utility-process-test;1"
].createInstance(Ci.nsIUtilityProcessTest);
add_task(async () => {
await utilityProcessTest
.startProcess()
.then(async pid => {
utilityPid = pid;
ok(true, "Could start Utility process: " + pid);
})
.catch(async () => {
ok(false, "Cannot start Utility process?");
});
});
add_task(async () => {
info("Start the profiler");
startProfiler();
let profile;
await TestUtils.waitForCondition(async () => {
profile = await Services.profiler.getProfileDataAsync();
return (
profile.processes.filter(ps => ps.threads[0].processType === "utility")
.length === 1
);
}, "Give time for the profiler to start and collect some samples");
info(`Check that the utility process ${utilityPid} is present.`);
let utilityProcessIndex = profile.processes.findIndex(
p => p.threads[0].pid == utilityPid
);
Assert.notEqual(utilityProcessIndex, -1, "Could find index of utility");
Assert.equal(
profile.processes[utilityProcessIndex].threads[0].processType,
"utility",
"Profile has processType utility"
);
Assert.greater(
profile.processes[utilityProcessIndex].threads.length,
0,
"The utility process should have threads"
);
Assert.equal(
profile.threads.length,
1,
"The parent process should have only one thread"
);
Services.profiler.StopProfiler();
});
add_task(async () => {
info("Stop Utility Process");
utilityProcessTest.stopProcess();
});

View File

@ -34,7 +34,10 @@ UtilityProcessTest::StartProcess(JSContext* aCx,
utilityProc->LaunchProcess(SandboxingKind::GENERIC_UTILITY)
->Then(
GetCurrentSerialEventTarget(), __func__,
[promise]() { promise->MaybeResolveWithUndefined(); },
[promise, utilityProc]() {
Maybe<int32_t> utilityPid = utilityProc->ProcessPid();
promise->MaybeResolve(*utilityPid);
},
[promise](nsresult aError) {
MOZ_ASSERT_UNREACHABLE(
"UtilityProcessTest; failure to get Utility process");
@ -45,6 +48,20 @@ UtilityProcessTest::StartProcess(JSContext* aCx,
return NS_OK;
}
NS_IMETHODIMP
UtilityProcessTest::StopProcess() {
RefPtr<UtilityProcessManager> utilityProc =
UtilityProcessManager::GetSingleton();
MOZ_ASSERT(utilityProc, "No UtilityprocessManager?");
utilityProc->CleanShutdown();
Maybe<int32_t> utilityPid = utilityProc->ProcessPid();
MOZ_RELEASE_ASSERT(utilityPid.isNothing(),
"Should not have a utility process PID anymore");
return NS_OK;
}
NS_IMPL_ISUPPORTS(UtilityProcessTest, nsIUtilityProcessTest)
} // namespace mozilla::ipc

View File

@ -15,4 +15,11 @@ interface nsIUtilityProcessTest : nsISupports
*/
[implicit_jscontext]
Promise startProcess();
/**
* ** Test-only Method **
*
* Allowing to stop Utility Process from JS code.
*/
void stopProcess();
};