Bug 1561435 - Format memory/, a=automatic-formatting

# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D35912

--HG--
extra : source : ae1388f34f73a8628d46d49ca0de9577a20bf650
This commit is contained in:
Victor Porof 2019-07-05 10:51:11 +02:00
parent 379161a602
commit feaa92296b
3 changed files with 49 additions and 45 deletions

View file

@ -45,7 +45,6 @@ module.exports = {
"overrides": [{
"files": [
"devtools/**",
"memory/**",
"mfbt/**",
"mobile/**",
"modules/**",

View file

@ -40,7 +40,6 @@ toolkit/components/telemetry/datareporting-prefs.js
toolkit/components/telemetry/healthreport-prefs.js
# Ignore all top-level directories for now.
memory/**
mfbt/**
mobile/**
modules/**

View file

@ -6,12 +6,15 @@
"use strict";
const {FileUtils} = ChromeUtils.import("resource://gre/modules/FileUtils.jsm");
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { FileUtils } = ChromeUtils.import(
"resource://gre/modules/FileUtils.jsm"
);
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
// The xpcshell test harness sets PYTHON so we can read it here.
var gEnv = Cc["@mozilla.org/process/environment;1"]
.getService(Ci.nsIEnvironment);
var gEnv = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
var gPythonName = gEnv.get("PYTHON");
// If we're testing locally, the executable file is in "CurProcD". Otherwise,
@ -37,10 +40,12 @@ var gDmdScriptFile = getExecutable("dmd.py");
var gScanTestFile = FileUtils.getFile("CurWorkD", ["scan-test.py"]);
function readFile(aFile) {
let fstream = Cc["@mozilla.org/network/file-input-stream;1"]
.createInstance(Ci.nsIFileInputStream);
let cstream = Cc["@mozilla.org/intl/converter-input-stream;1"]
.createInstance(Ci.nsIConverterInputStream);
let fstream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(
Ci.nsIFileInputStream
);
let cstream = Cc["@mozilla.org/intl/converter-input-stream;1"].createInstance(
Ci.nsIConverterInputStream
);
fstream.init(aFile, -1, 0, 0);
cstream.init(fstream, "UTF-8", 0, 0);
@ -58,10 +63,9 @@ function readFile(aFile) {
}
function runProcess(aExeFile, aArgs) {
let process = Cc["@mozilla.org/process/util;1"]
.createInstance(Ci.nsIProcess);
let process = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
process.init(aExeFile);
process.run(/* blocking = */true, aArgs, aArgs.length);
process.run(/* blocking = */ true, aArgs, aArgs.length);
return process.exitValue;
}
@ -69,14 +73,15 @@ function test(aPrefix, aArgs) {
// DMD writes the JSON files to CurWorkD, so we do likewise here with
// |actualFile| for consistency. It is removed once we've finished.
let expectedFile = FileUtils.getFile("CurWorkD", [aPrefix + "-expected.txt"]);
let actualFile = FileUtils.getFile("CurWorkD", [aPrefix + "-actual.txt"]);
let actualFile = FileUtils.getFile("CurWorkD", [aPrefix + "-actual.txt"]);
// Run dmd.py on the JSON file, producing |actualFile|.
let args = [
gDmdScriptFile.path,
"--filter-stacks-for-testing",
"-o", actualFile.path,
"-o",
actualFile.path,
].concat(aArgs);
runProcess(new FileUtils.File(gPythonName), args);
@ -88,12 +93,15 @@ function test(aPrefix, aArgs) {
let success;
try {
let rv = runProcess(new FileUtils.File("/usr/bin/diff"),
["-u", expectedFile.path, actualFile.path]);
let rv = runProcess(new FileUtils.File("/usr/bin/diff"), [
"-u",
expectedFile.path,
actualFile.path,
]);
success = rv == 0;
} catch (e) {
let expectedData = readFile(expectedFile);
let actualData = readFile(actualFile);
let actualData = readFile(actualFile);
success = expectedData === actualData;
if (!success) {
expectedData = expectedData.split("\n");
@ -114,10 +122,7 @@ function test(aPrefix, aArgs) {
// Run scan-test.py on the JSON file and see if it succeeds.
function scanTest(aJsonFilePath, aExtraArgs) {
let args = [
gScanTestFile.path,
aJsonFilePath,
].concat(aExtraArgs);
let args = [gScanTestFile.path, aJsonFilePath].concat(aExtraArgs);
return runProcess(new FileUtils.File(gPythonName), args) == 0;
}
@ -165,7 +170,10 @@ function run_test() {
let is64Bit = Services.appinfo.is64Bit;
let basicScanFileName = "basic-scan-" + (is64Bit ? "64" : "32");
test(basicScanFileName, ["--clamp-contents", jsonFile.path]);
ok(scanTest(jsonFile.path, ["--clamp-contents"]), "Scan with address clamping");
ok(
scanTest(jsonFile.path, ["--clamp-contents"]),
"Scan with address clamping"
);
// Run the generic test a second time to ensure that the first time produced
// valid JSON output. "--clamp-contents" is passed in so we don't have to have
@ -182,41 +190,39 @@ function run_test() {
// appropriately. The number of records in the output is different for each
// of the tested values.
jsonFile = FileUtils.getFile("CurWorkD", ["script-max-frames.json"]);
test("script-max-frames-8",
[jsonFile.path]); // --max-frames=8 is the default
test("script-max-frames-3",
["--max-frames=3", "--no-fix-stacks", jsonFile.path]);
test("script-max-frames-1",
["--max-frames=1", jsonFile.path]);
test("script-max-frames-8", [jsonFile.path]); // --max-frames=8 is the default
test("script-max-frames-3", [
"--max-frames=3",
"--no-fix-stacks",
jsonFile.path,
]);
test("script-max-frames-1", ["--max-frames=1", jsonFile.path]);
// This file has three records that are shown in a different order for each
// of the different sort values. It also tests the handling of gzipped JSON
// files.
jsonFile = FileUtils.getFile("CurWorkD", ["script-sort-by.json.gz"]);
test("script-sort-by-usable",
["--sort-by=usable", jsonFile.path]);
test("script-sort-by-req",
["--sort-by=req", "--no-fix-stacks", jsonFile.path]);
test("script-sort-by-slop",
["--sort-by=slop", jsonFile.path]);
test("script-sort-by-num-blocks",
["--sort-by=num-blocks", jsonFile.path]);
test("script-sort-by-usable", ["--sort-by=usable", jsonFile.path]);
test("script-sort-by-req", [
"--sort-by=req",
"--no-fix-stacks",
jsonFile.path,
]);
test("script-sort-by-slop", ["--sort-by=slop", jsonFile.path]);
test("script-sort-by-num-blocks", ["--sort-by=num-blocks", jsonFile.path]);
// This file has several real stack traces taken from Firefox execution, each
// of which tests a different allocator function (or functions).
jsonFile = FileUtils.getFile("CurWorkD", ["script-ignore-alloc-fns.json"]);
test("script-ignore-alloc-fns",
["--ignore-alloc-fns", jsonFile.path]);
test("script-ignore-alloc-fns", ["--ignore-alloc-fns", jsonFile.path]);
// This tests "live"-mode diffs.
jsonFile = FileUtils.getFile("CurWorkD", ["script-diff-live1.json"]);
jsonFile = FileUtils.getFile("CurWorkD", ["script-diff-live1.json"]);
jsonFile2 = FileUtils.getFile("CurWorkD", ["script-diff-live2.json"]);
test("script-diff-live",
[jsonFile.path, jsonFile2.path]);
test("script-diff-live", [jsonFile.path, jsonFile2.path]);
// This tests "dark-matter"-mode diffs.
jsonFile = FileUtils.getFile("CurWorkD", ["script-diff-dark-matter1.json"]);
jsonFile = FileUtils.getFile("CurWorkD", ["script-diff-dark-matter1.json"]);
jsonFile2 = FileUtils.getFile("CurWorkD", ["script-diff-dark-matter2.json"]);
test("script-diff-dark-matter",
[jsonFile.path, jsonFile2.path]);
test("script-diff-dark-matter", [jsonFile.path, jsonFile2.path]);
}