1# SPDX-License-Identifier: Apache-2.0 2# 3# Copyright (C) 2017, ARM Limited, Google and contributors. 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); you may 6# not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16# 17 18import re 19import os 20import logging 21 22from subprocess import Popen, PIPE 23from time import sleep 24 25from android import Screen, System, Workload 26 27class SystemUi(Workload): 28 """ 29 Android SystemUi jank test workload 30 """ 31 32 package = 'com.android.systemui' 33 34 # Instrumentation required to run tests 35 test_package = 'android.platform.systemui.tests.jank' 36 37 testOpenAllAppsContainer = "LauncherJankTests#testOpenAllAppsContainer" 38 testAllAppsContainerSwipe = "LauncherJankTests#testAllAppsContainerSwipe" 39 testHomeScreenSwipe = "LauncherJankTests#testHomeScreenSwipe" 40 testWidgetsContainerFling = "LauncherJankTests#testWidgetsContainerFling" 41 testSettingsFling = "SettingsJankTests#testSettingsFling" 42 testRecentAppsFling = "SystemUiJankTests#testRecentAppsFling" 43 testRecentAppsDismiss = "SystemUiJankTests#testRecentAppsDismiss" 44 testNotificationListPull = "SystemUiJankTests#testNotificationListPull" 45 testNotificationListPull_manyNotifications = "SystemUiJankTests#testNotificationListPull_manyNotifications" 46 testQuickSettingsPull = "SystemUiJankTests#testQuickSettingsPull" 47 testUnlock = "SystemUiJankTests#testUnlock" 48 testExpandGroup = "SystemUiJankTests#testExpandGroup" 49 testClearAll = "SystemUiJankTests#testClearAll" 50 testChangeBrightness = "SystemUiJankTests#testChangeBrightness" 51 testNotificationAppear = "SystemUiJankTests#testNotificationAppear" 52 testCameraFromLockscreen = "SystemUiJankTests#testCameraFromLockscreen" 53 testAmbientWakeUp = "SystemUiJankTests#testAmbientWakeUp" 54 testGoToFullShade = "SystemUiJankTests#testGoToFullShade" 55 testInlineReply = "SystemUiJankTests#testInlineReply" 56 testPinAppearance = "SystemUiJankTests#testPinAppearance" 57 testLaunchSettings = "SystemUiJankTests#testLaunchSettings" 58 59 def __init__(self, test_env): 60 super(SystemUi, self).__init__(test_env) 61 self._log = logging.getLogger('SystemUi') 62 self._log.debug('Workload created') 63 64 # Set of output data reported by SystemUi 65 self.db_file = None 66 67 def run(self, out_dir, test_name, iterations, collect='gfxinfo'): 68 """ 69 Run single SystemUi jank test workload. 70 71 :param out_dir: Path to experiment directory where to store results. 72 :type out_dir: str 73 74 :param test_name: Name of the test to run 75 :type test_name: str 76 77 :param iterations: Run benchmark for this required number of iterations 78 :type iterations: int 79 80 :param collect: Specifies what to collect. Possible values: 81 - 'systrace' 82 - 'ftrace' 83 - 'gfxinfo' 84 - 'surfaceflinger' 85 - any combination of the above 86 :type collect: list(str) 87 """ 88 if 'energy' in collect: 89 raise ValueError('SystemUi workload does not support energy data collection') 90 91 activity = '.' + test_name 92 93 # Keep track of mandatory parameters 94 self.out_dir = out_dir 95 self.collect = collect 96 97 # Unlock device screen (assume no password required) 98 Screen.unlock(self._target) 99 100 # Close and clear application 101 System.force_stop(self._target, self.package, clear=True) 102 103 # Set airplane mode 104 System.set_airplane_mode(self._target, on=True) 105 106 # Set min brightness 107 Screen.set_brightness(self._target, auto=False, percent=0) 108 109 # Force screen in PORTRAIT mode 110 Screen.set_orientation(self._target, portrait=True) 111 112 # Reset frame statistics 113 System.gfxinfo_reset(self._target, self.package) 114 sleep(1) 115 116 # Clear logcat 117 os.system(self._adb('logcat -c')); 118 119 # Regexps for benchmark synchronization 120 start_logline = r'TestRunner: started' 121 SYSTEMUI_BENCHMARK_START_RE = re.compile(start_logline) 122 self._log.debug("START string [%s]", start_logline) 123 124 finish_logline = r'TestRunner: finished' 125 SYSTEMUI_BENCHMARK_FINISH_RE = re.compile(finish_logline) 126 self._log.debug("FINISH string [%s]", finish_logline) 127 128 # Parse logcat output lines 129 logcat_cmd = self._adb( 130 'logcat TestRunner:* System.out:I *:S BENCH:*'\ 131 .format(self._target.adb_name)) 132 self._log.info("%s", logcat_cmd) 133 134 command = "nohup am instrument -e iterations {} -e class {}{} -w {}".format( 135 iterations, self.test_package, activity, self.test_package) 136 self._target.background(command) 137 138 logcat = Popen(logcat_cmd, shell=True, stdout=PIPE) 139 while True: 140 # read next logcat line (up to max 1024 chars) 141 message = logcat.stdout.readline(1024) 142 143 # Benchmark start trigger 144 match = SYSTEMUI_BENCHMARK_START_RE.search(message) 145 if match: 146 self.tracingStart() 147 self._log.debug("Benchmark started!") 148 149 match = SYSTEMUI_BENCHMARK_FINISH_RE.search(message) 150 if match: 151 self.tracingStop() 152 self._log.debug("Benchmark finished!") 153 break 154 155 sleep(5) 156 157 # Go back to home screen 158 System.home(self._target) 159 160 # Switch back to original settings 161 Screen.set_orientation(self._target, auto=True) 162 System.set_airplane_mode(self._target, on=False) 163 Screen.set_brightness(self._target, auto=True) 164