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 15:17:26 +00:00
Родитель 47a2d4ff4b
Коммит 9761993a72
5 изменённых файлов: 101 добавлений и 2 удалений

Просмотреть файл

@ -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]

Просмотреть файл

@ -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();
});

Просмотреть файл

@ -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

Просмотреть файл

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