Home | History | Annotate | Download | only in workloads
      1 # SPDX-License-Identifier: Apache-2.0
      2 #
      3 # Copyright (C) 2015, ARM Limited 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 
     18 import re
     19 import os
     20 import logging
     21 
     22 from time import sleep
     23 
     24 from target_script import TargetScript
     25 from android import Screen, System
     26 from android.workload import Workload
     27 
     28 
     29 class GMaps(Workload):
     30     """
     31     Android GMaps workload
     32     """
     33 
     34     # Package required by this workload
     35     package = 'com.google.android.apps.maps'
     36     action = 'android.intent.action.VIEW'
     37 
     38     def __init__(self, test_env):
     39         super(GMaps, self).__init__(test_env)
     40         self._log = logging.getLogger('GMaps')
     41         self._log.debug('Workload created')
     42 
     43         # Set of output data reported by GMaps
     44         self.db_file = None
     45 
     46     def run(self, out_dir, location_search, swipe_count=5, collect=''):
     47         """
     48         Run single Gmaps workload.
     49 
     50         :param out_dir: Path to experiment directory where to store results.
     51         :type out_dir: str
     52 
     53         :param location_search: Search string to be used in GMaps
     54         :type location_search: str
     55 
     56         :param swipe_count: Number of sets of (left, right, up, down) swipes to do
     57         :type swipe_count: int
     58 
     59         :param collect: Specifies what to collect. Possible values:
     60             - 'energy'
     61             - 'systrace'
     62             - 'ftrace'
     63             - any combination of the above
     64         :type collect: list(str)
     65         """
     66 
     67         # Keep track of mandatory parameters
     68         self.out_dir = out_dir
     69         self.collect = collect
     70 
     71         # Set min brightness
     72         Screen.set_brightness(self._target, auto=False, percent=0)
     73         # Unlock device screen (assume no password required)
     74         Screen.unlock(self._target)
     75 
     76         # Use the monkey tool to start GMaps
     77         # This allows to subsequently set the screen orientation to LANDSCAPE
     78         # and to reset the frame statistics.
     79         System.monkey(self._target, self.package)
     80 
     81         # Force screen in PORTRAIT  mode
     82         Screen.set_orientation(self._target, portrait=True)
     83 
     84         System.gfxinfo_reset(self._target, self.package)
     85         sleep(1)
     86 
     87         # Start GMaps on the target device
     88         loc_url = 'geo:0,0?q='
     89         loc_url += '+'.join(location_search.split())
     90         System.start_action(self._target, self.action, loc_url)
     91         # Allow the activity to start
     92         sleep(1)
     93 
     94         script = TargetScript(self._te, "gmaps_swiper.sh")
     95         self._log.debug('Accumulating commands')
     96 
     97         for i in range(swipe_count):
     98             System.hswipe(script, 20, 80, 100, True)
     99             script.append('sleep 1')
    100             System.hswipe(script, 20, 80, 100, False)
    101             script.append('sleep 1')
    102             System.vswipe(script, 40, 60, 100, True)
    103             script.append('sleep 1')
    104             System.vswipe(script, 40, 60, 100, False)
    105             script.append('sleep 1')
    106 
    107         self._log.debug('Accumulation done')
    108 
    109         # Push script to the target
    110         script.push()
    111 
    112         self._log.info('Opening GMaps to [%s]', loc_url)
    113         # Let GMaps zoom in on the location
    114         sleep(2)
    115 
    116         self.tracingStart()
    117 
    118         self._log.info('Launching target script')
    119         script.run()
    120         self._log.info('Target script ended')
    121 
    122         self.tracingStop()
    123 
    124         # Get frame stats
    125         self.db_file = os.path.join(out_dir, "framestats.txt")
    126         System.gfxinfo_get(self._target, self.package, self.db_file)
    127 
    128         # Close the app without clearing the local data to
    129         # avoid the dialog to select the account at next start
    130         System.force_stop(self._target, self.package, clear=False)
    131 
    132         # Go back to home screen
    133         System.home(self._target)
    134 
    135         # Set brightness back to auto
    136         Screen.set_brightness(self._target, auto=True)
    137 
    138         # Switch back to screen auto rotation
    139         Screen.set_orientation(self._target, auto=True)
    140 
    141 # vim :set tabstop=4 shiftwidth=4 expandtab
    142