From 0dc1e1e99a7ee095c04255ae8a4cf68b8fde12c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Fri, 31 Jul 2020 03:42:01 +0200 Subject: [PATCH] perf: Add basic run tests While the performance framework was originally written to collect performance metrics, driving the shell by an automated script is also useful to ensure that basic functionality is working. Add such a basic test, initially checking top bar menus, notifications and the overview. Eventually it would be nice to separate the automatic scripting from gathering performance metrics, but IMHO that can wait until we switch from gjs' custom imports system to ES modules. https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1396 --- js/js-resources.gresource.xml | 1 + js/perf/basic.js | 146 ++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 js/perf/basic.js diff --git a/js/js-resources.gresource.xml b/js/js-resources.gresource.xml index 07e134353..26878daf8 100644 --- a/js/js-resources.gresource.xml +++ b/js/js-resources.gresource.xml @@ -32,6 +32,7 @@ misc/util.js misc/weather.js + perf/basic.js perf/core.js perf/hwtest.js diff --git a/js/perf/basic.js b/js/perf/basic.js new file mode 100644 index 000000000..718532f28 --- /dev/null +++ b/js/perf/basic.js @@ -0,0 +1,146 @@ +// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*- +/* exported run, finish, script_topBarNavDone, script_notificationShowDone, + script_notificationCloseDone, script_overviewShowDone, + script_applicationsShowStart, script_applicationsShowDone, METRICS, +*/ +/* eslint camelcase: ["error", { properties: "never", allow: ["^script_"] }] */ + +const { St } = imports.gi; + +const Main = imports.ui.main; +const MessageTray = imports.ui.messageTray; +const Scripting = imports.ui.scripting; + +// This script tests the most important (basic) functionality of the shell. + +var METRICS = {}; + +async function run() { + /* eslint-disable no-await-in-loop */ + Scripting.defineScriptEvent('topBarNavStart', 'Starting to navigate the top bar'); + Scripting.defineScriptEvent('topBarNavDone', 'Done navigating the top bar'); + Scripting.defineScriptEvent('notificationShowStart', 'Showing a notification'); + Scripting.defineScriptEvent('notificationShowDone', 'Done showing a notification'); + Scripting.defineScriptEvent('notificationCloseStart', 'Closing a notification'); + Scripting.defineScriptEvent('notificationCloseDone', 'Done closing a notification'); + 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'); + + Main.overview.connect('shown', + () => Scripting.scriptEvent('overviewShowDone')); + + await Scripting.sleep(1000); + + // navigate through top bar + Scripting.scriptEvent('topBarNavStart'); + Main.panel.statusArea.aggregateMenu.menu.open(); + await Scripting.sleep(400); + + const { menuManager } = Main.panel; + while (menuManager.activeMenu && + Main.panel.navigate_focus(menuManager.activeMenu.sourceActor, + St.DirectionType.TAB_BACKWARD, false)) + await Scripting.sleep(400); + Scripting.scriptEvent('topBarNavDone'); + + await Scripting.sleep(1000); + + // notification + const source = new MessageTray.SystemNotificationSource(); + Main.messageTray.add(source); + + Scripting.scriptEvent('notificationShowStart'); + source.connect('notification-show', + () => Scripting.scriptEvent('notificationShowDone')); + + const notification = new MessageTray.Notification(source, + 'A test notification'); + source.showNotification(notification); + await Scripting.sleep(400); + + Main.panel.statusArea.dateMenu.menu.open(); + await Scripting.sleep(400); + + Scripting.scriptEvent('notificationCloseStart'); + notification.connect('destroy', + () => Scripting.scriptEvent('notificationCloseDone')); + + notification.destroy(); + await Scripting.sleep(400); + + Main.panel.statusArea.dateMenu.menu.close(); + await Scripting.waitLeisure(); + + await Scripting.sleep(1000); + + // overview (window picker) + Scripting.scriptEvent('overviewShowStart'); + Main.overview.show(); + await Scripting.waitLeisure(); + Main.overview.hide(); + await Scripting.waitLeisure(); + + await Scripting.sleep(1000); + + // overview (app picker) + Main.overview.show(); + await Scripting.waitLeisure(); + + Scripting.scriptEvent('applicationsShowStart'); + // eslint-disable-next-line require-atomic-updates + Main.overview.dash.showAppsButton.checked = true; + await Scripting.waitLeisure(); + Scripting.scriptEvent('applicationsShowDone'); + // eslint-disable-next-line require-atomic-updates + Main.overview.dash.showAppsButton.checked = false; + await Scripting.waitLeisure(); + + Main.overview.hide(); + await Scripting.waitLeisure(); + /* eslint-enable no-await-in-loop */ +} + +let topBarNav = false; +let notificationShown = false; +let notificationClosed = false; +let windowPickerShown = false; +let appPickerShown = false; + +function script_topBarNavDone() { + topBarNav = true; +} + +function script_notificationShowDone() { + notificationShown = true; +} + +function script_notificationCloseDone() { + notificationClosed = true; +} + +function script_overviewShowDone() { + windowPickerShown = true; +} + +function script_applicationsShowDone() { + appPickerShown = true; +} + +function finish() { + if (!topBarNav) + throw new Error('Failed to navigate top bar'); + + if (!notificationShown) + throw new Error('Failed to show notification'); + + if (!notificationClosed) + throw new Error('Failed to close notification'); + + if (!windowPickerShown) + throw new Error('Failed to show window picker'); + + if (!appPickerShown) + throw new Error('Failed to show app picker'); +}