From 26e018206d0c6984559772d7bbcc94d2cd2ea90f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Thu, 13 Jul 2023 21:29:13 +0200 Subject: [PATCH] tests/shell: Fix remaining ESlint errors All tests are currently excluded from linting, so errors can sneak in more easily. We should change that, so quickly fix up any remaining errors. Part-of: --- .eslintrc.yml | 1 + lint/eslintrc-shell.yml | 4 +- tests/shell/basic.js | 9 +++- tests/shell/core.js | 65 ++++++++++++++++++----- tests/shell/hwtest.js | 115 +++++++++++++++++++++++++++++++++------- 5 files changed, 161 insertions(+), 33 deletions(-) diff --git a/.eslintrc.yml b/.eslintrc.yml index 9289caa25..95be3a07c 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -8,5 +8,6 @@ overrides: - js/portalHelper/** - subprojects/extensions-app/** - subprojects/extensions-tool/** + - tests/shell/** parserOptions: sourceType: module diff --git a/lint/eslintrc-shell.yml b/lint/eslintrc-shell.yml index e4bf009bc..da9c26af1 100644 --- a/lint/eslintrc-shell.yml +++ b/lint/eslintrc-shell.yml @@ -16,7 +16,9 @@ rules: jsdoc/require-param-description: off overrides: - - files: js/** + - files: + - js/** + - tests/shell/** excludedFiles: - js/portalHelper/* - js/misc/extensionUtils.js diff --git a/tests/shell/basic.js b/tests/shell/basic.js index 588123fd8..04c3f8711 100644 --- a/tests/shell/basic.js +++ b/tests/shell/basic.js @@ -11,6 +11,7 @@ const Scripting = imports.ui.scripting; export var METRICS = {}; +/** @returns {void} */ export async function run() { console.debug('Running basic perf test'); @@ -38,7 +39,7 @@ export async function run() { Main.panel.statusArea.quickSettings.menu.open(); await Scripting.sleep(400); - const { menuManager } = Main.panel; + const {menuManager} = Main.panel; while (menuManager.activeMenu && Main.panel.navigate_focus(menuManager.activeMenu.sourceActor, St.DirectionType.TAB_BACKWARD, false)) @@ -118,26 +119,32 @@ let notificationClosed = false; let windowPickerShown = false; let appPickerShown = false; +/** @returns {void} */ export function script_topBarNavDone() { topBarNav = true; } +/** @returns {void} */ export function script_notificationShowDone() { notificationShown = true; } +/** @returns {void} */ export function script_notificationCloseDone() { notificationClosed = true; } +/** @returns {void} */ export function script_overviewShowDone() { windowPickerShown = true; } +/** @returns {void} */ export function script_applicationsShowDone() { appPickerShown = true; } +/** @returns {void} */ export function finish() { if (!topBarNav) throw new Error('Failed to navigate top bar'); diff --git a/tests/shell/core.js b/tests/shell/core.js index 933960104..12d9cb060 100644 --- a/tests/shell/core.js +++ b/tests/shell/core.js @@ -93,13 +93,14 @@ const WINDOW_CONFIGS = [{ alpha: true, maximized: false, count: 10, metric: 'overviewFps10Alpha', }]; +/** @returns {void} */ export async function run() { /* eslint-disable no-await-in-loop */ - Scripting.defineScriptEvent("overviewShowStart", "Starting to show the overview"); - Scripting.defineScriptEvent("overviewShowDone", "Overview finished showing"); - Scripting.defineScriptEvent("afterShowHide", "After a show/hide cycle for the overview"); - Scripting.defineScriptEvent("applicationsShowStart", "Starting to switch to applications view"); - Scripting.defineScriptEvent("applicationsShowDone", "Done switching to applications view"); + Scripting.defineScriptEvent('overviewShowStart', 'Starting to show the overview'); + Scripting.defineScriptEvent('overviewShowDone', 'Overview finished showing'); + Scripting.defineScriptEvent('afterShowHide', 'After a show/hide cycle for the overview'); + Scripting.defineScriptEvent('applicationsShowStart', 'Starting to switch to applications view'); + Scripting.defineScriptEvent('applicationsShowDone', 'Done switching to applications view'); // Enable recording of timestamps for different points in the frame cycle global.frame_timestamps = true; @@ -114,7 +115,7 @@ export async function run() { // We go to the overview twice for each configuration; the first time // to calculate the mipmaps for the windows, the second time to get // a clean set of numbers. - if ((i % 2) == 0) { + if ((i % 2) === 0) { let config = WINDOW_CONFIGS[i / 2]; await Scripting.destroyTestWindows(); @@ -175,6 +176,10 @@ let haveSwapComplete = false; let applicationsShowStart; let applicationsShowCount = 0; +/** + * @param {number} time - event timestamp + * @returns {void} + */ export function script_overviewShowStart(time) { showingOverview = true; finishedShowingOverview = false; @@ -182,6 +187,10 @@ export function script_overviewShowStart(time) { overviewFrames = 0; } +/** + * @param {number} _time - event timestamp + * @returns {void} + */ export function script_overviewShowDone(_time) { // We've set up the state at the end of the zoom out, but we // need to wait for one more frame to paint before we count @@ -189,32 +198,55 @@ export function script_overviewShowDone(_time) { finishedShowingOverview = true; } +/** + * @param {number} time - event timestamp + * @returns {void} + */ export function script_applicationsShowStart(time) { applicationsShowStart = time; } +/** @returns {void} */ +/** + * @param {number} time - event timestamp + * @returns {void} + */ export function script_applicationsShowDone(time) { applicationsShowCount++; - if (applicationsShowCount == 1) + if (applicationsShowCount === 1) METRICS.applicationsShowTimeFirst.value = time - applicationsShowStart; else METRICS.applicationsShowTimeSubsequent.value = time - applicationsShowStart; } +/** @returns {void} */ +/** + * @param {number} _time - event timestamp + * @returns {void} + */ export function script_afterShowHide(_time) { - if (overviewShowCount == 1) + if (overviewShowCount === 1) METRICS.usedAfterOverview.value = mallocUsedSize; else METRICS.leakedAfterOverview.value = mallocUsedSize - METRICS.usedAfterOverview.value; } +/** + * @param {number} time - event timestamp + * @param {number} bytes - event data + * @returns {void} + */ export function malloc_usedSize(time, bytes) { mallocUsedSize = bytes; } +/** + * @param {number} time - event timestamp + * @returns {void} + */ function _frameDone(time) { if (showingOverview) { - if (overviewFrames == 0) + if (overviewFrames === 0) overviewLatency = time - overviewShowStart; overviewFrames++; @@ -231,28 +263,37 @@ function _frameDone(time) { // be 1 frame for a FPS computation, hence the '- 1' let fps = (overviewFrames - 1) / dt; - if (overviewShowCount == 1) { + if (overviewShowCount === 1) { METRICS.overviewLatencyFirst.value = overviewLatency; METRICS.overviewFpsFirst.value = fps; - } else if (overviewShowCount == 2) { + } else if (overviewShowCount === 2) { METRICS.overviewLatencySubsequent.value = overviewLatency; } // Other than overviewFpsFirst, we collect FPS metrics the second // we show each window configuration. overviewShowCount is 1,2,3... - if (overviewShowCount % 2 == 0) { + if (overviewShowCount % 2 === 0) { let config = WINDOW_CONFIGS[(overviewShowCount / 2) - 1]; METRICS[config.metric].value = fps; } } } +/** + * @param {number} time - event timestamp + * @param {number} swapTime - event data + * @returns {void} + */ export function glx_swapComplete(time, swapTime) { haveSwapComplete = true; _frameDone(swapTime); } +/** + * @param {number} time - event timestamp + * @returns {void} + */ export function clutter_stagePaintDone(time) { // If we aren't receiving GLXBufferSwapComplete events, then we approximate // the time the user sees a frame with the time we finished doing drawing diff --git a/tests/shell/hwtest.js b/tests/shell/hwtest.js index 5d9bfdb54..6e7267614 100644 --- a/tests/shell/hwtest.js +++ b/tests/shell/hwtest.js @@ -42,10 +42,14 @@ export var METRICS = { }, }; +/** + * @param {number} milliseconds - time to wait + * @returns {callback} + */ function waitAndDraw(milliseconds) { let cb; - let timeline = new Clutter.Timeline({ duration: milliseconds }); + let timeline = new Clutter.Timeline({duration: milliseconds}); timeline.start(); timeline.connect('new-frame', (_timeline, _frame) => { @@ -61,6 +65,11 @@ function waitAndDraw(milliseconds) { return callback => (cb = callback); } +/** + * @param {object} object - emitter object + * @param {string} signal - signal name + * @returns {callback} + */ function waitSignal(object, signal) { let cb; @@ -73,6 +82,9 @@ function waitSignal(object, signal) { return callback => (cb = callback); } +/** + * @returns {number} + */ function extractBootTimestamp() { const sp = Gio.Subprocess.new([ 'journalctl', '-b', @@ -96,22 +108,23 @@ function extractBootTimestamp() { return result; } +/** @returns {void} */ export async function run() { /* eslint-disable no-await-in-loop */ - Scripting.defineScriptEvent("desktopShown", "Finished initial animation"); - Scripting.defineScriptEvent("overviewShowStart", "Starting to show the overview"); - Scripting.defineScriptEvent("overviewShowDone", "Overview finished showing"); - Scripting.defineScriptEvent("applicationsShowStart", "Starting to switch to applications view"); - Scripting.defineScriptEvent("applicationsShowDone", "Done switching to applications view"); - Scripting.defineScriptEvent("mainViewDrawStart", "Drawing main view"); - Scripting.defineScriptEvent("mainViewDrawDone", "Ending timing main view drawing"); - Scripting.defineScriptEvent("overviewDrawStart", "Drawing overview"); - Scripting.defineScriptEvent("overviewDrawDone", "Ending timing overview drawing"); - Scripting.defineScriptEvent("redrawTestStart", "Drawing application window"); - Scripting.defineScriptEvent("redrawTestDone", "Ending timing application window drawing"); - Scripting.defineScriptEvent("collectTimings", "Accumulate frame timings from redraw tests"); - Scripting.defineScriptEvent("geditLaunch", "gedit application launch"); - Scripting.defineScriptEvent("geditFirstFrame", "first frame of gedit window drawn"); + Scripting.defineScriptEvent('desktopShown', 'Finished initial animation'); + Scripting.defineScriptEvent('overviewShowStart', 'Starting to show the overview'); + Scripting.defineScriptEvent('overviewShowDone', 'Overview finished showing'); + Scripting.defineScriptEvent('applicationsShowStart', 'Starting to switch to applications view'); + Scripting.defineScriptEvent('applicationsShowDone', 'Done switching to applications view'); + Scripting.defineScriptEvent('mainViewDrawStart', 'Drawing main view'); + Scripting.defineScriptEvent('mainViewDrawDone', 'Ending timing main view drawing'); + Scripting.defineScriptEvent('overviewDrawStart', 'Drawing overview'); + Scripting.defineScriptEvent('overviewDrawDone', 'Ending timing overview drawing'); + Scripting.defineScriptEvent('redrawTestStart', 'Drawing application window'); + Scripting.defineScriptEvent('redrawTestDone', 'Ending timing application window drawing'); + Scripting.defineScriptEvent('collectTimings', 'Accumulate frame timings from redraw tests'); + Scripting.defineScriptEvent('geditLaunch', 'gedit application launch'); + Scripting.defineScriptEvent('geditFirstFrame', 'first frame of gedit window drawn'); await Scripting.waitLeisure(); Scripting.scriptEvent('desktopShown'); @@ -148,7 +161,7 @@ export async function run() { global.frame_finish_timestamp = true; for (let k = 0; k < 5; k++) - await Scripting.createTestWindow({ maximized: true }); + await Scripting.createTestWindow({maximized: true}); await Scripting.waitTestWindows(); await Scripting.sleep(1000); @@ -201,7 +214,7 @@ export async function run() { if (windows.length > 0) throw new Error('gedit was already running'); - while (windows.length == 0) { + while (windows.length === 0) { await waitSignal(global.display, 'window-created'); windows = app.get_windows(); } @@ -227,51 +240,99 @@ let redrawTiming; let redrawTimes = {}; let geditLaunchTime; +/** + * @param {number} time - event timestamp + * @returns {void} + */ export function script_desktopShown(time) { let bootTimestamp = extractBootTimestamp(); METRICS.timeToDesktop.value = time - bootTimestamp; } +/** + * @param {number} time - event timestamp + * @returns {void} + */ export function script_overviewShowStart(time) { overviewShowStart = time; } +/** + * @param {number} time - event timestamp + * @returns {void} + */ export function script_overviewShowDone(time) { METRICS.overviewShowTime.value = time - overviewShowStart; } +/** + * @param {number} time - event timestamp + * @returns {void} + */ export function script_applicationsShowStart(time) { applicationsShowStart = time; } +/** + * @param {number} time - event timestamp + * @returns {void} + */ export function script_applicationsShowDone(time) { METRICS.applicationsShowTime.value = time - applicationsShowStart; } +/** + * @param {number} _time - event timestamp + * @returns {void} + */ export function script_mainViewDrawStart(_time) { redrawTiming = 'mainView'; } +/** + * @param {number} _time - event timestamp + * @returns {void} + */ export function script_mainViewDrawDone(_time) { redrawTiming = null; } +/** + * @param {number} _time - event timestamp + * @returns {void} + */ export function script_overviewDrawStart(_time) { redrawTiming = 'overview'; } +/** + * @param {number} _time - event timestamp + * @returns {void} + */ export function script_overviewDrawDone(_time) { redrawTiming = null; } +/** + * @param {number} _time - event timestamp + * @returns {void} + */ export function script_redrawTestStart(_time) { redrawTiming = 'application'; } +/** + * @param {number} _time - event timestamp + * @returns {void} + */ export function script_redrawTestDone(_time) { redrawTiming = null; } +/** + * @param {number} _time - event timestamp + * @returns {void} + */ export function script_collectTimings(_time) { for (let timing in redrawTimes) { let times = redrawTimes[timing]; @@ -280,9 +341,9 @@ export function script_collectTimings(_time) { let len = times.length; let median; - if (len == 0) + if (len === 0) median = -1; - else if (len % 2 == 1) + else if (len % 2 === 1) median = times[(len - 1) / 2]; else median = Math.round((times[len / 2 - 1] + times[len / 2]) / 2); @@ -291,18 +352,34 @@ export function script_collectTimings(_time) { } } +/** + * @param {number} time - event timestamp + * @returns {void} + */ export function script_geditLaunch(time) { geditLaunchTime = time; } +/** + * @param {number} time - event timestamp + * @returns {void} + */ export function script_geditFirstFrame(time) { METRICS.geditStartTime.value = time - geditLaunchTime; } +/** + * @param {number} time - event timestamp + * @returns {void} + */ export function clutter_stagePaintStart(time) { stagePaintStart = time; } +/** + * @param {number} time - event timestamp + * @returns {void} + */ export function clutter_paintCompletedTimestamp(time) { if (redrawTiming != null && stagePaintStart != null) { if (!(redrawTiming in redrawTimes))