Commit 9b4fafb9 authored by David Teller's avatar David Teller
Browse files

Bug 1635494 - Test that nsIProcessToolsService::kill doesn't cause crash reports;r=gsvelto

nsIProcessToolsService::kill is designed to kill without causing crash reports.
Let's make sure it does not cause crash reports.

Depends on D82552

Differential Revision: https://phabricator.services.mozilla.com/D82553
parent d76fedbf
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -205,10 +205,14 @@ async function do_content_crash(setup, callback) {
  do_get_profile();
  await makeFakeAppDir();
  await sendCommandAsync('load("' + headfile.path.replace(/\\/g, "/") + '");');
  if (setup) {
    await sendCommandAsync(setup);
  }
  await sendCommandAsync('load("' + tailfile.path.replace(/\\/g, "/") + '");');
  await spinEventLoop();
  let id = getMinidump().leafName.slice(0, -4);

  let minidump = getMinidump();
  let id = minidump.leafName.slice(0, -4);
  await Services.crashmanager.ensureCrashIsPresent(id);
  try {
    await handleMinidump(callback);
+44 −0
Original line number Diff line number Diff line
// Test that calling Services.processtools.kill doesn't create a crash report.
add_task(async function run_test() {
  if (!("@mozilla.org/toolkit/crash-reporter;1" in Cc)) {
    dump(
      "INFO | test_kill.js | Can't test crashreporter in a non-libxul build.\n"
    );
    return;
  }

  // Let's launch a child process and kill it (from within, it's simpler).

  do_load_child_test_harness();

  // Setting the minidump path won't work in the child, so we need to do
  // that here.
  let crashReporter = Cc["@mozilla.org/toolkit/crash-reporter;1"].getService(
    Ci.nsICrashReporter
  );
  crashReporter.minidumpPath = do_get_tempdir();
  let headfile = do_get_file("../unit/crasher_subprocess_head.js");
  const CRASH_THEN_WAIT =
    "const ProcessTools = Cc['@mozilla.org/processtools-service;1'].getService(Ci.nsIProcessToolsService);\
     console.log('Child process commiting ritual self-sacrifice');\
     ProcessTools.kill(ProcessTools.pid);\
     console.error('Oops, I should be dead');\
     while (true) {} ;";
  do_get_profile();
  await makeFakeAppDir();
  await sendCommandAsync('load("' + headfile.path.replace(/\\/g, "/") + '");');
  await sendCommandAsync(CRASH_THEN_WAIT);

  // Let's wait a little to give the child process a chance to create a minidump.
  let { setTimeout } = ChromeUtils.import("resource://gre/modules/Timer.jsm");
  // eslint-disable-next-line mozilla/no-arbitrary-setTimeout
  await new Promise(resolve => setTimeout(resolve, 100));

  // Now make sure that we have no minidump.
  let minidump = getMinidump();
  Assert.equal(
    minidump,
    null,
    `There should be no minidump ${minidump == null ? "null" : minidump.path}`
  );
});
+1 −2
Original line number Diff line number Diff line
@@ -62,7 +62,6 @@ add_task(async function run_test() {
          Assert.ok(Number(extra[label]) >= 0);
        }
      }
    },
    true
    }
  );
});
+2 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ support-files =
[test_crash_after_js_large_allocation_failure_reporting.js]
[test_crash_oom.js]
[test_oom_annotation.js]
[test_kill.js]

[test_crash_abort.js]
skip-if = os == 'win'
@@ -109,3 +110,4 @@ head = head_crashreporter.js head_win64cfi.js
skip-if = !(os == 'win' && bits == 64 && processor == 'x86_64')
reason = Windows test specific to the x86-64 architecture
support-files = test_crash_win64cfi_not_a_pe.exe