From ff689ffe19660f5181b2dde2875a7f524c65bb62 Mon Sep 17 00:00:00 2001 From: David Teller Date: Tue, 10 Dec 2019 08:44:26 +0000 Subject: [PATCH] Bug 1587722 - Tests for memory statistics on crashes;r=gsvelto Depends on D55457 Differential Revision: https://phabricator.services.mozilla.com/D55933 --HG-- rename : toolkit/crashreporter/test/unit/test_oom_annotation_windows.js => toolkit/crashreporter/test/unit/test_oom_annotation.js extra : moz-landing-system : lando --- .../test/unit/test_oom_annotation.js | 68 +++++++++++++++++++ .../test/unit/test_oom_annotation_windows.js | 28 -------- toolkit/crashreporter/test/unit/xpcshell.ini | 3 +- 3 files changed, 69 insertions(+), 30 deletions(-) create mode 100644 toolkit/crashreporter/test/unit/test_oom_annotation.js delete mode 100644 toolkit/crashreporter/test/unit/test_oom_annotation_windows.js diff --git a/toolkit/crashreporter/test/unit/test_oom_annotation.js b/toolkit/crashreporter/test/unit/test_oom_annotation.js new file mode 100644 index 000000000000..ead89d69166c --- /dev/null +++ b/toolkit/crashreporter/test/unit/test_oom_annotation.js @@ -0,0 +1,68 @@ +add_task(async function run_test() { + if (!("@mozilla.org/toolkit/crash-reporter;1" in Cc)) { + dump( + "INFO | test_crash_oom.js | Can't test crashreporter in a non-libxul build.\n" + ); + return; + } + + await do_crash( + function() { + crashType = CrashTestUtils.CRASH_OOM; + crashReporter.annotateCrashReport("TestKey", "Yes"); + }, + function(mdump, extra) { + ChromeUtils.import("resource://gre/modules/AppConstants.jsm", this); + Assert.equal(extra.TestKey, "Yes"); + + // A list of pairs [annotation name, must be > 0] + let annotations; + switch (AppConstants.platform) { + case "win": + annotations = [ + ["OOMAllocationSize", true], + ["SystemMemoryUsePercentage", false], + ["TotalVirtualMemory", true], + ["AvailableVirtualMemory", false], + ["TotalPageFile", false], + ["AvailablePageFile", false], + ["TotalPhysicalMemory", true], + ["AvailablePhysicalMemory", false], + ]; + break; + case "linux": + annotations = [ + ["AvailablePageFile", false], + ["AvailablePhysicalMemory", false], + ["AvailableSwapMemory", false], + ["AvailableVirtualMemory", false], + ["TotalPageFile", false], + ["TotalPhysicalMemory", true], + ]; + break; + case "macosx": + annotations = [ + ["AvailablePhysicalMemory", false], + ["AvailableSwapMemory", false], + ["PurgeablePhysicalMemory", false], + ["TotalPhysicalMemory", true], + ]; + break; + default: + annotations = []; + } + for (let [label, shouldBeGreaterThanZero] of annotations) { + Assert.ok(label in extra, `Annotation ${label} is present`); + + // All these annotations should represent non-negative numbers. + // A few of them (e.g. physical memory) are guaranteed to be positive. + if (shouldBeGreaterThanZero) { + Assert.ok(Number(extra[label]) > 0); + } else { + Assert.ok(Number(extra[label]) >= 0); + } + } + }, + true + ); +}); diff --git a/toolkit/crashreporter/test/unit/test_oom_annotation_windows.js b/toolkit/crashreporter/test/unit/test_oom_annotation_windows.js deleted file mode 100644 index dbc638d33d34..000000000000 --- a/toolkit/crashreporter/test/unit/test_oom_annotation_windows.js +++ /dev/null @@ -1,28 +0,0 @@ -add_task(async function run_test() { - if (!("@mozilla.org/toolkit/crash-reporter;1" in Cc)) { - dump( - "INFO | test_crash_oom.js | Can't test crashreporter in a non-libxul build.\n" - ); - return; - } - - await do_crash( - function() { - crashType = CrashTestUtils.CRASH_OOM; - crashReporter.annotateCrashReport("TestKey", "Yes"); - }, - function(mdump, extra) { - Assert.equal(extra.TestKey, "Yes"); - Assert.ok("OOMAllocationSize" in extra); - Assert.ok(Number(extra.OOMAllocationSize) > 0); - Assert.ok("SystemMemoryUsePercentage" in extra); - Assert.ok("TotalVirtualMemory" in extra); - Assert.ok("AvailableVirtualMemory" in extra); - Assert.ok("TotalPageFile" in extra); - Assert.ok("AvailablePageFile" in extra); - Assert.ok("TotalPhysicalMemory" in extra); - Assert.ok("AvailablePhysicalMemory" in extra); - }, - true - ); -}); diff --git a/toolkit/crashreporter/test/unit/xpcshell.ini b/toolkit/crashreporter/test/unit/xpcshell.ini index 2622aa63ece5..0236d582a8a4 100644 --- a/toolkit/crashreporter/test/unit/xpcshell.ini +++ b/toolkit/crashreporter/test/unit/xpcshell.ini @@ -15,8 +15,7 @@ support-files = [test_crash_after_js_large_allocation_failure.js] [test_crash_after_js_large_allocation_failure_reporting.js] [test_crash_oom.js] -[test_oom_annotation_windows.js] -skip-if = os != 'win' +[test_oom_annotation.js] [test_crash_abort.js] skip-if = os == 'win'