From daabf196f6aecc6898d72fdf64309592e8763870 Mon Sep 17 00:00:00 2001 From: Ulan Degenbaev Date: Fri, 19 Oct 2018 10:46:37 +0200 Subject: [PATCH] Support automated runs in the web version. (#63) --- src/bootstrap.js | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/bootstrap.js b/src/bootstrap.js index 1426e957..fe65824b 100644 --- a/src/bootstrap.js +++ b/src/bootstrap.js @@ -46,8 +46,12 @@ function reset() { } else { const benchmark = benchmarks[index]; text += ``; - text += `${benchmark.name}`; - text += `—`; + text += `${benchmark.name}`; + text += `—`; } } text += ""; @@ -82,6 +86,16 @@ window.onerror = () => { }; window.onload = initialize; +// Helpers for automated runs in Telemetry/Catapult. +window.automated = { + // Set to true when the whole suite is completed. + completed: false, + // The result array of {name, score} pairs. + results: [], + // The function that starts the run. + start +}; + suite.forEach(benchmark => { benchmark.on("start", event => { if (suite.aborted) return; @@ -114,8 +128,13 @@ suite.forEach(benchmark => { }); suite.on("complete", event => { + window.automated.completed = true; if (suite.aborted) return; const hz = gmean(suite.map(benchmark => benchmark.hz)); + window.automated.results = suite.map(benchmark => { + return { name: benchmark.name, score: benchmark.hz }; + }); + window.automated.results.push({ name: "total", score: hz }); displayResultMessage("geomean", `${hz.toFixed(2)}`, "highlighted-result"); const statusDiv = document.getElementById("status"); @@ -129,10 +148,13 @@ suite.on("complete", event => { }); suite.on("error", event => { + window.automated.completed = true; const benchmark = event.target; const error = benchmark.error; const name = benchmark.name; - document.body.innerHTML = `

ERROR

Encountered errors during execution of ${name} test. Refusing to run a partial benchmark suite.

${error.stack}
`; + document.body.innerHTML = `

ERROR

Encountered errors during execution of ${name} test. Refusing to run a partial benchmark suite.

${
+    error.stack
+  }
`; console.error(error); suite.abort(); });