From 18b4ff1c435096d859a2bc0844fe4241039e7281 Mon Sep 17 00:00:00 2001 From: Michael McGeagh Date: Fri, 10 Mar 2017 14:11:48 +0000 Subject: [PATCH 1/3] uibench: Added parameter to allow action(s) By default when running uibench, no user action is performed during the tests. This adds an optional parameter called 'action' and performs the actions as input events. This parameter can take the form of a list and allows you to perform multiple actions in a set order too. E.g. When performing ActivityTransition test, action=['tap', 'tap'] will perform two taps in the centre of the screen which will maximise a thumbnail then minimise the resulting fullscreen image. --- libs/utils/android/workloads/uibench.py | 33 ++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/libs/utils/android/workloads/uibench.py b/libs/utils/android/workloads/uibench.py index bdba69fa8..4fc05ec23 100755 --- a/libs/utils/android/workloads/uibench.py +++ b/libs/utils/android/workloads/uibench.py @@ -20,7 +20,7 @@ import os import logging from subprocess import Popen, PIPE -from time import sleep +from time import time, sleep from android import Screen, System, Workload @@ -58,7 +58,7 @@ class UiBench(Workload): # Set of output data reported by UiBench self.db_file = None - def run(self, out_dir, test_name, duration_s, collect=''): + def run(self, out_dir, test_name, duration_s, collect='', action=''): """ Run single UiBench workload. @@ -77,6 +77,12 @@ class UiBench(Workload): - 'ftrace' - any combination of the above :type collect: list(str) + + :param action: Perform user interactions during the test. Possible values: + - 'vswipe' + - 'tap' + - any combination of the above in execution order + :type action: list(str) """ activity = '.' + test_name @@ -142,7 +148,17 @@ class UiBench(Workload): # Run the workload for the required time self._log.info('Benchmark [%s] started, waiting %d [s]', activity, duration_s) - sleep(duration_s) + + start = time() + + if action: + # Format actions as a list if it is just a single string item + actions = [action] if isinstance(action, basestring) else action + for a in actions: + self._perform_action(a) + + while (time() - start) < duration_s: + sleep(1) self._log.debug("Benchmark done!") self.tracingStop() @@ -162,4 +178,15 @@ class UiBench(Workload): System.set_airplane_mode(self._target, on=False) Screen.set_brightness(self._target, auto=True) + def _perform_action(self, action, delay_s=0): + if action == 'vswipe': + # Action: A fast Swipe Up/Scroll Down + System.vswipe(self._target, 20, 80, 50) + + if action == 'tap': + # Action: Tap in the centre of the screen + System.tap(self._target, 50, 50) + + sleep(delay_s) + # vim :set tabstop=4 shiftwidth=4 expandtab -- GitLab From 5946769323a637c0a4d94ac49dd48ef49b2c8874 Mon Sep 17 00:00:00 2001 From: Michael McGeagh Date: Mon, 10 Apr 2017 13:13:03 +0100 Subject: [PATCH 2/3] uibench: default actions added as a dictionary Default actions for every activity has been added as a dictionary. The test_name activity is used to look up the default actions to be performed and performs them during the test. uibench: delay default and position changed The delay between actions now occurs before the action, not after The default delay has changed from 0 to 1 --- libs/utils/android/workloads/uibench.py | 67 ++++++++++++++----------- 1 file changed, 39 insertions(+), 28 deletions(-) diff --git a/libs/utils/android/workloads/uibench.py b/libs/utils/android/workloads/uibench.py index 4fc05ec23..efa9707ca 100755 --- a/libs/utils/android/workloads/uibench.py +++ b/libs/utils/android/workloads/uibench.py @@ -34,21 +34,33 @@ class UiBench(Workload): # Supported activities list, obtained via: # adb shell dumpsys package | grep -i uibench | grep Activity - test_BitmapUpload = 'BitmapUploadActivity' - test_DialogList = 'DialogListActivity' - test_EditTextType = 'EditTextTypeActivity' - test_FullscreenOverdraw = 'FullscreenOverdrawActivity' - test_GlTextureView = 'GlTextureViewActivity' - test_InflatingList = 'InflatingListActivity' - test_Invalidate = 'InvalidateActivity' - test_ShadowGrid = 'ShadowGridActivity' - test_TextCacheHighHitrate = 'TextCacheHighHitrateActivity' - test_TextCacheLowHitrate = 'TextCacheLowHitrateActivity' - test_Transition = 'ActivityTransition' - test_TransitionDetails = 'ActivityTransitionDetails' - test_TrivialAnimation = 'TrivialAnimationActivity' - test_TrivialList = 'TrivialListActivity' - test_TrivialRecyclerView = 'TrivialRecyclerViewActivity' + # + # test_actions is a dictonary of standard actions to perform for each activity in uibench + # Possible actions are as follows, or None if no action is to be performed: + # - 'vswipe' + # - 'tap' + # - A list with any combination of the above, in execution order + test_actions = { + # General + 'DialogListActivity': 'vswipe', + 'FullscreenOverdrawActivity': None, + 'GlTextureViewActivity': None, + 'InvalidateActivity': None, + 'TrivialAnimationActivity': None, + 'TrivialListActivity': 'vswipe', + 'TrivialRecyclerViewActivity': 'vswipe', + # Inflation + 'InflatingListActivity': 'vswipe', + # Rendering + 'BitmapUploadActivity': None, + 'ShadowGridActivity': ['tap', 'vswipe'], + # Text + 'EditTextTypeActivity': None, + 'TextCacheHighHitrateActivity': 'vswipe', + 'TextCacheLowHitrateActivity': 'vswipe', + # Transitions + 'ActivityTransition': ['tap', 'tap'], + } def __init__(self, test_env): super(UiBench, self).__init__(test_env) @@ -58,7 +70,7 @@ class UiBench(Workload): # Set of output data reported by UiBench self.db_file = None - def run(self, out_dir, test_name, duration_s, collect='', action=''): + def run(self, out_dir, test_name, duration_s, collect=''): """ Run single UiBench workload. @@ -77,16 +89,16 @@ class UiBench(Workload): - 'ftrace' - any combination of the above :type collect: list(str) - - :param action: Perform user interactions during the test. Possible values: - - 'vswipe' - - 'tap' - - any combination of the above in execution order - :type action: list(str) """ activity = '.' + test_name + action = None + if test_name in self.test_actions: + action = self.test_actions[test_name] + # Format actions as a list if it is just a single string item + action = [action] if isinstance(action, basestring) else action + # Keep track of mandatory parameters self.out_dir = out_dir self.collect = collect @@ -152,9 +164,7 @@ class UiBench(Workload): start = time() if action: - # Format actions as a list if it is just a single string item - actions = [action] if isinstance(action, basestring) else action - for a in actions: + for a in action: self._perform_action(a) while (time() - start) < duration_s: @@ -178,7 +188,10 @@ class UiBench(Workload): System.set_airplane_mode(self._target, on=False) Screen.set_brightness(self._target, auto=True) - def _perform_action(self, action, delay_s=0): + def _perform_action(self, action, delay_s=1.0): + # Delay before performing action + sleep(delay_s) + if action == 'vswipe': # Action: A fast Swipe Up/Scroll Down System.vswipe(self._target, 20, 80, 50) @@ -187,6 +200,4 @@ class UiBench(Workload): # Action: Tap in the centre of the screen System.tap(self._target, 50, 50) - sleep(delay_s) - # vim :set tabstop=4 shiftwidth=4 expandtab -- GitLab From a0d5b468dd9b11dd6899612a1895a82861fd95e4 Mon Sep 17 00:00:00 2001 From: Michael McGeagh Date: Tue, 11 Apr 2017 10:57:59 +0100 Subject: [PATCH 3/3] uibench: Default actions can be overridden Added new parameter, actions, which is defaulted to be 'default'. This means it will use the default actions defined in the test_actions dictionary. Use this parameter to ignore the default actions and define your own. None means perform no action. --- libs/utils/android/workloads/uibench.py | 29 +++++++++++++++++-------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/libs/utils/android/workloads/uibench.py b/libs/utils/android/workloads/uibench.py index efa9707ca..8308f6982 100755 --- a/libs/utils/android/workloads/uibench.py +++ b/libs/utils/android/workloads/uibench.py @@ -70,7 +70,7 @@ class UiBench(Workload): # Set of output data reported by UiBench self.db_file = None - def run(self, out_dir, test_name, duration_s, collect=''): + def run(self, out_dir, test_name, duration_s, collect='', actions='default'): """ Run single UiBench workload. @@ -89,15 +89,27 @@ class UiBench(Workload): - 'ftrace' - any combination of the above :type collect: list(str) + + :param actions: Specifies what actions to perform. Possible values: + - None : Perform no action + - 'default' : Use the predefined default actions from the `test_actions` dict + - 'vswipe' : Perform a vertical swipe + - 'tap' : Perform a centre tap + - A list with any combination of vswipe and tap, in execution order + :type actions: list(str) """ activity = '.' + test_name - action = None - if test_name in self.test_actions: - action = self.test_actions[test_name] - # Format actions as a list if it is just a single string item - action = [action] if isinstance(action, basestring) else action + # If default, get the default actions from test_actions + # If this is an undefined test, no action will be the default + if actions == 'default': + actions = None + if test_name in self.test_actions: + actions = self.test_actions[test_name] + # Format actions as a list if it is just a single string item, + # or an empty list if it is None + actions = [actions] if isinstance(actions, basestring) else actions if actions else [] # Keep track of mandatory parameters self.out_dir = out_dir @@ -163,9 +175,8 @@ class UiBench(Workload): start = time() - if action: - for a in action: - self._perform_action(a) + for action in actions: + self._perform_action(action) while (time() - start) < duration_s: sleep(1) -- GitLab