Bug 1428076 - Add a mochitest r=mstange
authorJulien Wajsberg <felash@gmail.com>
Wed, 24 Jan 2018 11:31:50 +0100
changeset 400738 167ef8dc0c60a49c9c7de5cdba48c276dec5d355
parent 400737 fcf73947d244a6e44652435ad1eb5993ceab4de6
child 400739 8bfa9cafcc0dc85df6197014dad2c5a3643760e1
push id33315
push userrgurzau@mozilla.com
push dateThu, 25 Jan 2018 17:00:51 +0000
treeherdermozilla-central@53c5a199232a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1428076
milestone60.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1428076 - Add a mochitest r=mstange MozReview-Commit-ID: EhNoJuMhrAS
tools/profiler/moz.build
tools/profiler/tests/chrome/.eslintrc.js
tools/profiler/tests/chrome/chrome.ini
tools/profiler/tests/chrome/test_profile_worker_bug_1428076.html
--- a/tools/profiler/moz.build
+++ b/tools/profiler/moz.build
@@ -136,16 +136,17 @@ if CONFIG['MOZ_TASK_TRACER']:
         'tasktracer/TracedTaskCommon.h',
     ]
     UNIFIED_SOURCES += [
         'tasktracer/GeckoTaskTracer.cpp',
         'tasktracer/TracedTaskCommon.cpp',
     ]
 
 XPCSHELL_TESTS_MANIFESTS += ['tests/xpcshell.ini']
+MOCHITEST_CHROME_MANIFESTS += ['tests/chrome/chrome.ini']
 
 if CONFIG['CC_TYPE'] in ('clang', 'gcc'):
     CXXFLAGS += [
         '-Wno-error=shadow',
         '-Wno-ignored-qualifiers', # due to use of breakpad headers
     ]
 
 with Files('**'):
new file mode 100644
--- /dev/null
+++ b/tools/profiler/tests/chrome/.eslintrc.js
@@ -0,0 +1,6 @@
+"use strict";
+
+module.exports = {
+  // Extend from the shared list of defined globals for mochitests.
+  "extends": "plugin:mozilla/chrome-test"
+};
new file mode 100644
--- /dev/null
+++ b/tools/profiler/tests/chrome/chrome.ini
@@ -0,0 +1,1 @@
+[test_profile_worker_bug_1428076.html]
new file mode 100644
--- /dev/null
+++ b/tools/profiler/tests/chrome/test_profile_worker_bug_1428076.html
@@ -0,0 +1,108 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1428076
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 1428076</title>
+  <link rel="stylesheet" type="text/css" href="chrome://global/skin"/>
+  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1428076">Mozilla Bug 1428076</a>
+
+<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+<script type="application/javascript">
+
+/** Test for Bug 1428076 **/
+"use strict";
+Components.utils.import("resource://gre/modules/Services.jsm");
+
+function startProfiler() {
+  const settings = {
+    entries: 1000000, // 9MB
+    interval: 1, // ms
+    features: ["js", "threads", "leaf", "stackwalk"],
+    threads: ["GeckoMain", "Compositor", "Worker"] // most common combination
+  };
+
+  Services.profiler.StartProfiler(
+    settings.entries,
+    settings.interval,
+    settings.features,
+    settings.features.length,
+    settings.threads,
+    settings.threads.length
+  );
+
+  info("Profiler has started");
+}
+
+function getProfile() {
+  const profile = Services.profiler.getProfileData();
+  info("We got a profile");
+
+  // Run the mochitest with `--keep-open true` to see the logged profile in the
+  // Web console.
+  console.log(profile);
+
+  return profile;
+}
+
+function stopProfiler() {
+  Services.profiler.StopProfiler();
+  info("Profiler has stopped");
+}
+
+function end(error) {
+  if (error) {
+    ok(false, `We got an error: ${error}`);
+  } else {
+    ok(true, "We ran the whole process");
+  }
+  SimpleTest.finish();
+}
+
+function workload() {
+  // We use a Blob for the worker content to avoid an external JS file, and data
+  // URLs seem to be blocked in a chrome environment.
+  const workerContent = new Blob(
+    [ "console.log('hello world!')" ],
+    { type: "application/javascript" }
+  );
+  const blobURL = URL.createObjectURL(workerContent);
+
+  // We start a worker and then terminate it right away to trigger our bug.
+  info("Starting the worker, and terminate it right away.");
+  const myWorker = new Worker(blobURL);
+  myWorker.terminate();
+
+  URL.revokeObjectURL(blobURL);
+
+  // We're deferring some little time so that the worker has the time to be
+  // properly cleaned up and the profiler actually saves the worker data.
+  return new Promise(resolve => {
+    setTimeout(resolve, 50);
+  });
+}
+
+SimpleTest.waitForExplicitFinish();
+(async function() {
+  try {
+    await startProfiler();
+    await workload();
+    await getProfile();
+    await stopProfiler();
+    await end();
+  } catch (e) {
+    // By catching and handling the error, we're being nice to mochitest
+    // runners: instead of waiting for the timeout, we fail right away.
+    await end(e);
+  }
+})();
+
+
+</script>
+</body>
+</html>