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: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2822>
This commit is contained in:
Florian Müllner 2023-07-13 21:29:13 +02:00 committed by Evan Welsh
parent 9e84891240
commit 26e018206d
5 changed files with 161 additions and 33 deletions

View File

@ -8,5 +8,6 @@ overrides:
- js/portalHelper/** - js/portalHelper/**
- subprojects/extensions-app/** - subprojects/extensions-app/**
- subprojects/extensions-tool/** - subprojects/extensions-tool/**
- tests/shell/**
parserOptions: parserOptions:
sourceType: module sourceType: module

View File

@ -16,7 +16,9 @@ rules:
jsdoc/require-param-description: off jsdoc/require-param-description: off
overrides: overrides:
- files: js/** - files:
- js/**
- tests/shell/**
excludedFiles: excludedFiles:
- js/portalHelper/* - js/portalHelper/*
- js/misc/extensionUtils.js - js/misc/extensionUtils.js

View File

@ -11,6 +11,7 @@ const Scripting = imports.ui.scripting;
export var METRICS = {}; export var METRICS = {};
/** @returns {void} */
export async function run() { export async function run() {
console.debug('Running basic perf test'); console.debug('Running basic perf test');
@ -118,26 +119,32 @@ let notificationClosed = false;
let windowPickerShown = false; let windowPickerShown = false;
let appPickerShown = false; let appPickerShown = false;
/** @returns {void} */
export function script_topBarNavDone() { export function script_topBarNavDone() {
topBarNav = true; topBarNav = true;
} }
/** @returns {void} */
export function script_notificationShowDone() { export function script_notificationShowDone() {
notificationShown = true; notificationShown = true;
} }
/** @returns {void} */
export function script_notificationCloseDone() { export function script_notificationCloseDone() {
notificationClosed = true; notificationClosed = true;
} }
/** @returns {void} */
export function script_overviewShowDone() { export function script_overviewShowDone() {
windowPickerShown = true; windowPickerShown = true;
} }
/** @returns {void} */
export function script_applicationsShowDone() { export function script_applicationsShowDone() {
appPickerShown = true; appPickerShown = true;
} }
/** @returns {void} */
export function finish() { export function finish() {
if (!topBarNav) if (!topBarNav)
throw new Error('Failed to navigate top bar'); throw new Error('Failed to navigate top bar');

View File

@ -93,13 +93,14 @@ const WINDOW_CONFIGS = [{
alpha: true, maximized: false, count: 10, metric: 'overviewFps10Alpha', alpha: true, maximized: false, count: 10, metric: 'overviewFps10Alpha',
}]; }];
/** @returns {void} */
export async function run() { export async function run() {
/* eslint-disable no-await-in-loop */ /* eslint-disable no-await-in-loop */
Scripting.defineScriptEvent("overviewShowStart", "Starting to show the overview"); Scripting.defineScriptEvent('overviewShowStart', 'Starting to show the overview');
Scripting.defineScriptEvent("overviewShowDone", "Overview finished showing"); Scripting.defineScriptEvent('overviewShowDone', 'Overview finished showing');
Scripting.defineScriptEvent("afterShowHide", "After a show/hide cycle for the overview"); Scripting.defineScriptEvent('afterShowHide', 'After a show/hide cycle for the overview');
Scripting.defineScriptEvent("applicationsShowStart", "Starting to switch to applications view"); Scripting.defineScriptEvent('applicationsShowStart', 'Starting to switch to applications view');
Scripting.defineScriptEvent("applicationsShowDone", "Done switching to applications view"); Scripting.defineScriptEvent('applicationsShowDone', 'Done switching to applications view');
// Enable recording of timestamps for different points in the frame cycle // Enable recording of timestamps for different points in the frame cycle
global.frame_timestamps = true; global.frame_timestamps = true;
@ -114,7 +115,7 @@ export async function run() {
// We go to the overview twice for each configuration; the first time // We go to the overview twice for each configuration; the first time
// to calculate the mipmaps for the windows, the second time to get // to calculate the mipmaps for the windows, the second time to get
// a clean set of numbers. // a clean set of numbers.
if ((i % 2) == 0) { if ((i % 2) === 0) {
let config = WINDOW_CONFIGS[i / 2]; let config = WINDOW_CONFIGS[i / 2];
await Scripting.destroyTestWindows(); await Scripting.destroyTestWindows();
@ -175,6 +176,10 @@ let haveSwapComplete = false;
let applicationsShowStart; let applicationsShowStart;
let applicationsShowCount = 0; let applicationsShowCount = 0;
/**
* @param {number} time - event timestamp
* @returns {void}
*/
export function script_overviewShowStart(time) { export function script_overviewShowStart(time) {
showingOverview = true; showingOverview = true;
finishedShowingOverview = false; finishedShowingOverview = false;
@ -182,6 +187,10 @@ export function script_overviewShowStart(time) {
overviewFrames = 0; overviewFrames = 0;
} }
/**
* @param {number} _time - event timestamp
* @returns {void}
*/
export function script_overviewShowDone(_time) { export function script_overviewShowDone(_time) {
// We've set up the state at the end of the zoom out, but we // 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 // need to wait for one more frame to paint before we count
@ -189,32 +198,55 @@ export function script_overviewShowDone(_time) {
finishedShowingOverview = true; finishedShowingOverview = true;
} }
/**
* @param {number} time - event timestamp
* @returns {void}
*/
export function script_applicationsShowStart(time) { export function script_applicationsShowStart(time) {
applicationsShowStart = time; applicationsShowStart = time;
} }
/** @returns {void} */
/**
* @param {number} time - event timestamp
* @returns {void}
*/
export function script_applicationsShowDone(time) { export function script_applicationsShowDone(time) {
applicationsShowCount++; applicationsShowCount++;
if (applicationsShowCount == 1) if (applicationsShowCount === 1)
METRICS.applicationsShowTimeFirst.value = time - applicationsShowStart; METRICS.applicationsShowTimeFirst.value = time - applicationsShowStart;
else else
METRICS.applicationsShowTimeSubsequent.value = time - applicationsShowStart; METRICS.applicationsShowTimeSubsequent.value = time - applicationsShowStart;
} }
/** @returns {void} */
/**
* @param {number} _time - event timestamp
* @returns {void}
*/
export function script_afterShowHide(_time) { export function script_afterShowHide(_time) {
if (overviewShowCount == 1) if (overviewShowCount === 1)
METRICS.usedAfterOverview.value = mallocUsedSize; METRICS.usedAfterOverview.value = mallocUsedSize;
else else
METRICS.leakedAfterOverview.value = mallocUsedSize - METRICS.usedAfterOverview.value; 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) { export function malloc_usedSize(time, bytes) {
mallocUsedSize = bytes; mallocUsedSize = bytes;
} }
/**
* @param {number} time - event timestamp
* @returns {void}
*/
function _frameDone(time) { function _frameDone(time) {
if (showingOverview) { if (showingOverview) {
if (overviewFrames == 0) if (overviewFrames === 0)
overviewLatency = time - overviewShowStart; overviewLatency = time - overviewShowStart;
overviewFrames++; overviewFrames++;
@ -231,28 +263,37 @@ function _frameDone(time) {
// be 1 frame for a FPS computation, hence the '- 1' // be 1 frame for a FPS computation, hence the '- 1'
let fps = (overviewFrames - 1) / dt; let fps = (overviewFrames - 1) / dt;
if (overviewShowCount == 1) { if (overviewShowCount === 1) {
METRICS.overviewLatencyFirst.value = overviewLatency; METRICS.overviewLatencyFirst.value = overviewLatency;
METRICS.overviewFpsFirst.value = fps; METRICS.overviewFpsFirst.value = fps;
} else if (overviewShowCount == 2) { } else if (overviewShowCount === 2) {
METRICS.overviewLatencySubsequent.value = overviewLatency; METRICS.overviewLatencySubsequent.value = overviewLatency;
} }
// Other than overviewFpsFirst, we collect FPS metrics the second // Other than overviewFpsFirst, we collect FPS metrics the second
// we show each window configuration. overviewShowCount is 1,2,3... // 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]; let config = WINDOW_CONFIGS[(overviewShowCount / 2) - 1];
METRICS[config.metric].value = fps; METRICS[config.metric].value = fps;
} }
} }
} }
/**
* @param {number} time - event timestamp
* @param {number} swapTime - event data
* @returns {void}
*/
export function glx_swapComplete(time, swapTime) { export function glx_swapComplete(time, swapTime) {
haveSwapComplete = true; haveSwapComplete = true;
_frameDone(swapTime); _frameDone(swapTime);
} }
/**
* @param {number} time - event timestamp
* @returns {void}
*/
export function clutter_stagePaintDone(time) { export function clutter_stagePaintDone(time) {
// If we aren't receiving GLXBufferSwapComplete events, then we approximate // If we aren't receiving GLXBufferSwapComplete events, then we approximate
// the time the user sees a frame with the time we finished doing drawing // the time the user sees a frame with the time we finished doing drawing

View File

@ -42,6 +42,10 @@ export var METRICS = {
}, },
}; };
/**
* @param {number} milliseconds - time to wait
* @returns {callback}
*/
function waitAndDraw(milliseconds) { function waitAndDraw(milliseconds) {
let cb; let cb;
@ -61,6 +65,11 @@ function waitAndDraw(milliseconds) {
return callback => (cb = callback); return callback => (cb = callback);
} }
/**
* @param {object} object - emitter object
* @param {string} signal - signal name
* @returns {callback}
*/
function waitSignal(object, signal) { function waitSignal(object, signal) {
let cb; let cb;
@ -73,6 +82,9 @@ function waitSignal(object, signal) {
return callback => (cb = callback); return callback => (cb = callback);
} }
/**
* @returns {number}
*/
function extractBootTimestamp() { function extractBootTimestamp() {
const sp = Gio.Subprocess.new([ const sp = Gio.Subprocess.new([
'journalctl', '-b', 'journalctl', '-b',
@ -96,22 +108,23 @@ function extractBootTimestamp() {
return result; return result;
} }
/** @returns {void} */
export async function run() { export async function run() {
/* eslint-disable no-await-in-loop */ /* eslint-disable no-await-in-loop */
Scripting.defineScriptEvent("desktopShown", "Finished initial animation"); Scripting.defineScriptEvent('desktopShown', 'Finished initial animation');
Scripting.defineScriptEvent("overviewShowStart", "Starting to show the overview"); Scripting.defineScriptEvent('overviewShowStart', 'Starting to show the overview');
Scripting.defineScriptEvent("overviewShowDone", "Overview finished showing"); Scripting.defineScriptEvent('overviewShowDone', 'Overview finished showing');
Scripting.defineScriptEvent("applicationsShowStart", "Starting to switch to applications view"); Scripting.defineScriptEvent('applicationsShowStart', 'Starting to switch to applications view');
Scripting.defineScriptEvent("applicationsShowDone", "Done switching to applications view"); Scripting.defineScriptEvent('applicationsShowDone', 'Done switching to applications view');
Scripting.defineScriptEvent("mainViewDrawStart", "Drawing main view"); Scripting.defineScriptEvent('mainViewDrawStart', 'Drawing main view');
Scripting.defineScriptEvent("mainViewDrawDone", "Ending timing main view drawing"); Scripting.defineScriptEvent('mainViewDrawDone', 'Ending timing main view drawing');
Scripting.defineScriptEvent("overviewDrawStart", "Drawing overview"); Scripting.defineScriptEvent('overviewDrawStart', 'Drawing overview');
Scripting.defineScriptEvent("overviewDrawDone", "Ending timing overview drawing"); Scripting.defineScriptEvent('overviewDrawDone', 'Ending timing overview drawing');
Scripting.defineScriptEvent("redrawTestStart", "Drawing application window"); Scripting.defineScriptEvent('redrawTestStart', 'Drawing application window');
Scripting.defineScriptEvent("redrawTestDone", "Ending timing application window drawing"); Scripting.defineScriptEvent('redrawTestDone', 'Ending timing application window drawing');
Scripting.defineScriptEvent("collectTimings", "Accumulate frame timings from redraw tests"); Scripting.defineScriptEvent('collectTimings', 'Accumulate frame timings from redraw tests');
Scripting.defineScriptEvent("geditLaunch", "gedit application launch"); Scripting.defineScriptEvent('geditLaunch', 'gedit application launch');
Scripting.defineScriptEvent("geditFirstFrame", "first frame of gedit window drawn"); Scripting.defineScriptEvent('geditFirstFrame', 'first frame of gedit window drawn');
await Scripting.waitLeisure(); await Scripting.waitLeisure();
Scripting.scriptEvent('desktopShown'); Scripting.scriptEvent('desktopShown');
@ -201,7 +214,7 @@ export async function run() {
if (windows.length > 0) if (windows.length > 0)
throw new Error('gedit was already running'); throw new Error('gedit was already running');
while (windows.length == 0) { while (windows.length === 0) {
await waitSignal(global.display, 'window-created'); await waitSignal(global.display, 'window-created');
windows = app.get_windows(); windows = app.get_windows();
} }
@ -227,51 +240,99 @@ let redrawTiming;
let redrawTimes = {}; let redrawTimes = {};
let geditLaunchTime; let geditLaunchTime;
/**
* @param {number} time - event timestamp
* @returns {void}
*/
export function script_desktopShown(time) { export function script_desktopShown(time) {
let bootTimestamp = extractBootTimestamp(); let bootTimestamp = extractBootTimestamp();
METRICS.timeToDesktop.value = time - bootTimestamp; METRICS.timeToDesktop.value = time - bootTimestamp;
} }
/**
* @param {number} time - event timestamp
* @returns {void}
*/
export function script_overviewShowStart(time) { export function script_overviewShowStart(time) {
overviewShowStart = time; overviewShowStart = time;
} }
/**
* @param {number} time - event timestamp
* @returns {void}
*/
export function script_overviewShowDone(time) { export function script_overviewShowDone(time) {
METRICS.overviewShowTime.value = time - overviewShowStart; METRICS.overviewShowTime.value = time - overviewShowStart;
} }
/**
* @param {number} time - event timestamp
* @returns {void}
*/
export function script_applicationsShowStart(time) { export function script_applicationsShowStart(time) {
applicationsShowStart = time; applicationsShowStart = time;
} }
/**
* @param {number} time - event timestamp
* @returns {void}
*/
export function script_applicationsShowDone(time) { export function script_applicationsShowDone(time) {
METRICS.applicationsShowTime.value = time - applicationsShowStart; METRICS.applicationsShowTime.value = time - applicationsShowStart;
} }
/**
* @param {number} _time - event timestamp
* @returns {void}
*/
export function script_mainViewDrawStart(_time) { export function script_mainViewDrawStart(_time) {
redrawTiming = 'mainView'; redrawTiming = 'mainView';
} }
/**
* @param {number} _time - event timestamp
* @returns {void}
*/
export function script_mainViewDrawDone(_time) { export function script_mainViewDrawDone(_time) {
redrawTiming = null; redrawTiming = null;
} }
/**
* @param {number} _time - event timestamp
* @returns {void}
*/
export function script_overviewDrawStart(_time) { export function script_overviewDrawStart(_time) {
redrawTiming = 'overview'; redrawTiming = 'overview';
} }
/**
* @param {number} _time - event timestamp
* @returns {void}
*/
export function script_overviewDrawDone(_time) { export function script_overviewDrawDone(_time) {
redrawTiming = null; redrawTiming = null;
} }
/**
* @param {number} _time - event timestamp
* @returns {void}
*/
export function script_redrawTestStart(_time) { export function script_redrawTestStart(_time) {
redrawTiming = 'application'; redrawTiming = 'application';
} }
/**
* @param {number} _time - event timestamp
* @returns {void}
*/
export function script_redrawTestDone(_time) { export function script_redrawTestDone(_time) {
redrawTiming = null; redrawTiming = null;
} }
/**
* @param {number} _time - event timestamp
* @returns {void}
*/
export function script_collectTimings(_time) { export function script_collectTimings(_time) {
for (let timing in redrawTimes) { for (let timing in redrawTimes) {
let times = redrawTimes[timing]; let times = redrawTimes[timing];
@ -280,9 +341,9 @@ export function script_collectTimings(_time) {
let len = times.length; let len = times.length;
let median; let median;
if (len == 0) if (len === 0)
median = -1; median = -1;
else if (len % 2 == 1) else if (len % 2 === 1)
median = times[(len - 1) / 2]; median = times[(len - 1) / 2];
else else
median = Math.round((times[len / 2 - 1] + times[len / 2]) / 2); 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) { export function script_geditLaunch(time) {
geditLaunchTime = time; geditLaunchTime = time;
} }
/**
* @param {number} time - event timestamp
* @returns {void}
*/
export function script_geditFirstFrame(time) { export function script_geditFirstFrame(time) {
METRICS.geditStartTime.value = time - geditLaunchTime; METRICS.geditStartTime.value = time - geditLaunchTime;
} }
/**
* @param {number} time - event timestamp
* @returns {void}
*/
export function clutter_stagePaintStart(time) { export function clutter_stagePaintStart(time) {
stagePaintStart = time; stagePaintStart = time;
} }
/**
* @param {number} time - event timestamp
* @returns {void}
*/
export function clutter_paintCompletedTimestamp(time) { export function clutter_paintCompletedTimestamp(time) {
if (redrawTiming != null && stagePaintStart != null) { if (redrawTiming != null && stagePaintStart != null) {
if (!(redrawTiming in redrawTimes)) if (!(redrawTiming in redrawTimes))