diff options
Diffstat (limited to 'tools/profiler/tests/chrome')
4 files changed, 195 insertions, 0 deletions
diff --git a/tools/profiler/tests/chrome/chrome.ini b/tools/profiler/tests/chrome/chrome.ini new file mode 100644 index 0000000000..76c0b2eaf1 --- /dev/null +++ b/tools/profiler/tests/chrome/chrome.ini @@ -0,0 +1,7 @@ +[DEFAULT] +support-files=profiler_test_utils.js + +[test_profile_worker_bug_1428076.html] +skip-if = os == 'android' && processor == 'arm' # Bug 1541291 +[test_profile_worker.html] +skip-if = os == 'android' && processor == 'arm' # Bug 1541291 diff --git a/tools/profiler/tests/chrome/profiler_test_utils.js b/tools/profiler/tests/chrome/profiler_test_utils.js new file mode 100644 index 0000000000..b89a25995a --- /dev/null +++ b/tools/profiler/tests/chrome/profiler_test_utils.js @@ -0,0 +1,64 @@ +"use strict"; + +(function() { + const { Services } = ChromeUtils.import( + "resource://gre/modules/Services.jsm" + ); + + function startProfiler(settings) { + Services.profiler.StartProfiler( + settings.entries, + settings.interval, + settings.features, + settings.threads, + 0, + settings.duration + ); + + 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." + ); + + // 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(); + } + + async function runTest(settings, workload) { + SimpleTest.waitForExplicitFinish(); + try { + await startProfiler(settings); + 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); + } + } + + window.runTest = runTest; +})(); diff --git a/tools/profiler/tests/chrome/test_profile_worker.html b/tools/profiler/tests/chrome/test_profile_worker.html new file mode 100644 index 0000000000..d32d36bb41 --- /dev/null +++ b/tools/profiler/tests/chrome/test_profile_worker.html @@ -0,0 +1,66 @@ +<!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 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> +<script type="application/javascript" src="profiler_test_utils.js"></script> +<script type="application/javascript"> +/* globals runTest */ + +"use strict"; + +const settings = { + entries: 1000000, // 9MB + interval: 1, // ms + features: ["js", "threads", "leaf", "stackwalk"], + threads: ["GeckoMain", "Compositor", "Worker"], // most common combination +}; + +const workerCode = ` + console.log('hello world'); + setTimeout(() => postMessage('message from worker'), 50); +`; + +function startWorker() { + // 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( + [ workerCode ], + { 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..."); + const myWorker = new Worker(blobURL); + return { worker: myWorker, url: blobURL }; +} + +function workload() { + const { worker, url } = startWorker(); + + return new Promise(resolve => { + worker.onmessage = () => { + info("Got a message, terminating the worker."); + worker.terminate(); + URL.revokeObjectURL(url); + resolve(); + }; + }); +} + +runTest(settings, workload); + +</script> +</body> +</html> diff --git a/tools/profiler/tests/chrome/test_profile_worker_bug_1428076.html b/tools/profiler/tests/chrome/test_profile_worker_bug_1428076.html new file mode 100644 index 0000000000..30245b5b46 --- /dev/null +++ b/tools/profiler/tests/chrome/test_profile_worker_bug_1428076.html @@ -0,0 +1,58 @@ +<!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 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> +<script type="application/javascript" src="profiler_test_utils.js"></script> +<script type="application/javascript"> +/** Test for Bug 1428076 **/ + +/* globals runTest */ + +"use strict"; + +const settings = { + entries: 1000000, // 9MB + interval: 1, // ms + features: ["js", "threads", "leaf", "stackwalk"], + threads: ["GeckoMain", "Compositor", "Worker"], // most common combination +}; + +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); + }); +} + +runTest(settings, workload); + +</script> +</body> +</html> |