Bug 1779721 - Make sure utility process tests notifies test harness of SIGKILL r=mccr8

Differential Revision: https://phabricator.services.mozilla.com/D173520
This commit is contained in:
Alexandre Lissy 2023-03-24 16:37:25 +00:00
Родитель d31e4010ed
Коммит b5389d1492
5 изменённых файлов: 32 добавлений и 3 удалений

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

@ -50,4 +50,8 @@ add_task(async () => {
utilityPid,
`Should match the crashed PID ${utilityPid} with ${data}`
);
// Make sure the process is dead, otherwise there is a risk of race for
// writing leak logs
utilityProcessTest().noteIntentionalCrash(utilityPid);
});

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

@ -86,6 +86,10 @@ async function cleanUtilityProcessShutdown(actor, preferKill = false) {
`Should match the crashed PID ${utilityPid} with ${data}`
);
// Make sure the process is dead, otherwise there is a risk of race for
// writing leak logs
utilityProcessTest().noteIntentionalCrash(utilityPid);
ok(!subject.hasKey("dumpID"), "There should be no dumpID");
}
@ -357,6 +361,10 @@ async function crashSomeUtility(utilityPid, actorsCheck) {
"Subject needs to be a nsIPropertyBag2 to clean up properly"
);
// Make sure the process is dead, otherwise there is a risk of race for
// writing leak logs
utilityProcessTest().noteIntentionalCrash(utilityPid);
const dumpID = subject.getPropertyAsAString("dumpID");
ok(dumpID, "There should be a dumpID");

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

@ -9,6 +9,7 @@
# include "mozilla/ipc/UtilityProcessManager.h"
# include "mozilla/dom/Promise.h"
# include "mozilla/ProcInfo.h"
# include "mozilla/IntentionalCrash.h"
namespace mozilla::ipc {
@ -105,6 +106,12 @@ UtilityProcessTest::StartProcess(const nsTArray<nsCString>& aActorsToRegister,
return NS_OK;
}
NS_IMETHODIMP
UtilityProcessTest::NoteIntentionalCrash(uint32_t aPid) {
mozilla::NoteIntentionalCrash("utility", aPid);
return NS_OK;
}
NS_IMETHODIMP
UtilityProcessTest::StopProcess(const char* aActorName) {
using namespace mozilla::dom;

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

@ -20,6 +20,13 @@ interface nsIUtilityProcessTest : nsISupports
[implicit_jscontext]
Promise startProcess([optional] in Array<ACString> actorsToAdd);
/**
* ** Test-only Method **
*
* Note that we are going to manually crash a process
*/
void noteIntentionalCrash(in unsigned long pid);
/**
* ** Test-only Method **
*

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

@ -21,7 +21,7 @@
namespace mozilla {
inline void NoteIntentionalCrash(const char* aProcessType) {
inline void NoteIntentionalCrash(const char* aProcessType, uint32_t aPid = 0) {
// In opt builds we don't actually have the leak checking enabled, and the
// sandbox doesn't allow writing to this path, so we just disable this
// function's behaviour.
@ -33,6 +33,8 @@ inline void NoteIntentionalCrash(const char* aProcessType) {
fprintf(stderr, "XPCOM_MEM_BLOAT_LOG: %s\n", f);
uint32_t processPid = aPid == 0 ? getpid() : aPid;
std::ostringstream bloatName;
std::string processType(aProcessType);
if (!processType.compare("default")) {
@ -47,7 +49,7 @@ inline void NoteIntentionalCrash(const char* aProcessType) {
bloatLog.erase(bloatLog.size() - 4, 4);
}
bloatName << bloatLog << "_" << processType << "_pid" << getpid();
bloatName << bloatLog << "_" << processType << "_pid" << processPid;
if (hasExt) {
bloatName << ".log";
}
@ -57,7 +59,8 @@ inline void NoteIntentionalCrash(const char* aProcessType) {
FILE* processfd = fopen(bloatName.str().c_str(), "a");
if (processfd) {
fprintf(processfd, "==> process %d will purposefully crash\n", getpid());
fprintf(processfd, "\n==> process %d will purposefully crash\n",
processPid);
fclose(processfd);
}
#endif