From 65402030cffe1dde4513b34ea9adf290c2f047d2 Mon Sep 17 00:00:00 2001 From: Valentin Schneider Date: Tue, 4 Apr 2017 13:29:09 +0100 Subject: [PATCH 1/2] libs/utils/android: Add tab, enter, dpad input methods Tab, Dpad and Enter can be used to select and activate buttons, just as with a keybord on a desktop computer. Dpad input behaves just like arrow key input. Signed-off-by: Valentin Schneider --- libs/utils/android/system.py | 54 ++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/libs/utils/android/system.py b/libs/utils/android/system.py index 42e8c4dec..6c1e7a1ae 100644 --- a/libs/utils/android/system.py +++ b/libs/utils/android/system.py @@ -254,6 +254,60 @@ class System(object): """ target.execute('input keyevent KEYCODE_BACK') + @staticmethod + def tab(target): + """ + Emulate TAB key keyboard input + :param target: instance of devlib Android target + :type target: devlib.target.AndroidTarget + """ + target.execute('input keyevent KEYCODE_TAB') + + @staticmethod + def enter(target): + """ + Emulate ENTER key keyboard input + :param target: instance of devlib Android target + :type target: devlib.target.AndroidTarget + """ + target.execute('input keyevent KEYCODE_ENTER') + + @staticmethod + def dpad_down(target): + """ + Emulate DPAD_DOWN input + :param target: instance of devlib Android target + :type target: devlib.target.AndroidTarget + """ + target.execute('input keyevent KEYCODE_DPAD_DOWN') + + @staticmethod + def dpad_up(target): + """ + Emulate DPAD_UP key input + :param target: instance of devlib Android target + :type target: devlib.target.AndroidTarget + """ + target.execute('input keyevent KEYCODE_DPAD_UP') + + @staticmethod + def dpad_left(target): + """ + Emulate DPAD_LEFT key input + :param target: instance of devlib Android target + :type target: devlib.target.AndroidTarget + """ + target.execute('input keyevent KEYCODE_DPAD_LEFT') + + @staticmethod + def dpad_right(target): + """ + Emulate DPAD_RIGHT key input + :param target: instance of devlib Android target + :type target: devlib.target.AndroidTarget + """ + target.execute('input keyevent KEYCODE_DPAD_RIGHT') + @staticmethod def gfxinfo_reset(target, apk_name): """ -- GitLab From a34590be59476645cd6cc4da02f876a98f112bbd Mon Sep 17 00:00:00 2001 From: Valentin Schneider Date: Tue, 4 Apr 2017 13:34:47 +0100 Subject: [PATCH 2/2] libs/utils/android/workloads: Add corporate geekbench Slightly different version from the vanilla geekbench. No EULA prompt, tweakable benchmarks and the data upload can be disabled. The workload code itself uses the Tab, Enter and Dpad keys in order to be "device neutral" - sometimes tapping at given coordinate percentages wouldn't work for all devices. Signed-off-by: Valentin Schneider --- .../android/workloads/geekbench_corporate.py | 181 ++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 libs/utils/android/workloads/geekbench_corporate.py diff --git a/libs/utils/android/workloads/geekbench_corporate.py b/libs/utils/android/workloads/geekbench_corporate.py new file mode 100644 index 000000000..1d5c501c1 --- /dev/null +++ b/libs/utils/android/workloads/geekbench_corporate.py @@ -0,0 +1,181 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# Copyright (C) 2015, ARM Limited and contributors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import re +import os +import logging +from time import sleep + +from subprocess import Popen, PIPE + +from android import Screen, Workload, System + +# Regexps for benchmark synchronization +GEEKBENCH_BENCHMARK_START_RE = re.compile( + r'ActivityManager: Start.* com.primatelabs.geekbench4.corporate' +) +GEEKBENCH_BENCHMARK_END_RE = re.compile( + r'GEEKBENCH_RESULT: (?P.+)' +) + +class GeekbenchCorporate(Workload): + """ + Android Geekbench Corporate workload + """ + + # Package required by this workload + package = 'com.primatelabs.geekbench4.corporate' + activity = 'com.primatelabs.geekbench.HomeActivity' + + def __init__(self, test_env): + super(GeekbenchCorporate, self).__init__(test_env) + self._log = logging.getLogger('GeekbenchCorporate') + self._log.debug('Workload created') + + def run(self, out_dir, test_name, collect=''): + """ + Run single Geekbench Corporate workload. + + :param out_dir: Path on host to experiment directory where + to store results. + :type out_dir: str + + :param test_name: Name of the test to run + :type test_name: str + + :param collect: Specifies what to collect. Possible values: + - 'energy' + - 'systrace' + - 'ftrace' + - any combination of the above in a space-separated string. + :type collect: list(str) + """ + + # Initialize energy meter results + self.out_dir = out_dir + self.collect = collect + + # Clear the stored data for the application + System.force_stop(self._target, self.package, clear=True) + + # Clear logcat from any previous runs + # do this on the target as then we don't need to build a string + self._target.clear_logcat() + + # Unlock device screen (assume no password required) + System.menu(self._target) + # Press Back button to be sure we run the benchmark from the start + System.back(self._target) + + # Set airplane mode + System.set_airplane_mode(self._target, on=True) + + # Force screen in PORTRAIT mode + Screen.set_orientation(self._target, portrait=True) + + # Set min brightness + Screen.set_brightness(self._target, auto=False, percent=0) + + # Start app on the target device + System.start_activity(self._target, self.package, self.activity) + # Allow the activity to start + sleep(2) + + # Parse logcat output lines to find beginning and end + logcat_cmd = self._adb( + 'logcat ActivityManager:* System.out:I *:S GEEKBENCH_RESULT:*'\ + .format(self._target.adb_name)) + self._log.info("%s", logcat_cmd) + logcat = Popen(logcat_cmd, shell=True, stdout=PIPE) + + # Selection won't work correctly if there is a scroll bar. + # Swiping changes focus, which can change the amount of + # actions to do depending on the device. + # DPAD DOWN is used to scroll to the bottom. + for i in range(0, 10): + System.dpad_down(self._target) + + # Select something. + # Options or 'CPU' may be selected. + System.tab(self._target) + + # Make sure Options is selected. + # That way we can follow the same actions for all devices. + System.dpad_up(self._target) + + # Move back to benchmark choice + System.dpad_down(self._target) + + if test_name.upper() == 'COMPUTE': + # CPU is selected, select COMPUTE and press ENTER + System.dpad_right(self._target); + System.enter(self._target); + + # Move through options to select "RUN ALL COMPUTE BENCHMARKS" + for i in range (0, 3): + System.dpad_down(self._target) + else: + # Move through options to select "RUN CPU BENCHMARK" + for i in range(0, 5): + System.dpad_down(self._target); + + # Press the 'RUN BENCHMARK' button + System.enter(self._target); + + while True: + + # read next logcat line (up to max 1024 chars) + message = logcat.stdout.readline(1024) + + # Benchmark start trigger + match = GEEKBENCH_BENCHMARK_START_RE.search(message) + if match: + # Start tracing + self.tracingStart() + self._log.debug("Benchmark started!") + + # Benchmark end trigger + match = GEEKBENCH_BENCHMARK_END_RE.search(message) + if match: + # Stop tracing + self.tracingStop() + remote_result_file = match.group('results_file') + self._log.debug("Benchmark finished! Results are in {}".format(remote_result_file)) + break + + # Get Geekbench Results file + target_result_file = self._target.path.basename(remote_result_file) + result_file = os.path.join(self.out_dir, target_result_file) + self._log.debug("result_file={}".format(result_file)) + self._target.pull(remote_result_file, result_file) + + # Close the app + System.force_stop(self._target, self.package, clear=False) + + # Go back to home screen + System.home(self._target) + + # Disable airplane mode + System.set_airplane_mode(self._target, on=False) + + # Switch back to screen auto rotation + Screen.set_orientation(self._target, auto=True) + + # Set brightness back to auto + Screen.set_brightness(self._target, auto=True) + +# vim :set tabstop=4 shiftwidth=4 expandtab -- GitLab