def run(self, exp_dir, video_url, video_duration_s, collect=''): # Initialize energy meter results nrg_report = None # Unlock device screen (assume no password required) System.menu(self.target) # Press Back button to be sure we run the video from the start System.back(self.target) # Use the monkey tool to start YouTube without playing any video. # This allows to subsequently set the screen orientation to LANDSCAPE # and to reset the frame statistics. System.monkey(self.target, self.package) # Force screen in LANDSCAPE mode Screen.set_orientation(self.target, portrait=False) System.gfxinfo_reset(self.target, self.package) sleep(1) # Start YouTube video on the target device System.start_action(self.target, self.action, video_url) # Allow the activity to start sleep(1) # Start energy collection if 'energy' in collect and self.te.emeter: self.te.emeter.reset() # Wait until the end of the video self.logger.info("Play video for %d [s]", video_duration_s) sleep(video_duration_s) # Stop energy collection if 'energy' in collect and self.te.emeter: nrg_report = self.te.emeter.report(exp_dir) # Get frame stats db_file = os.path.join(exp_dir, "framestats.txt") System.gfxinfo_get(self.target, self.package, db_file) # Close the app without clearing the local data to # avoid the dialog to select the account at next start System.force_stop(self.target, self.package, clear=False) # Go back to home screen System.home(self.target) # Switch back to screen auto rotation Screen.set_orientation(self.target, auto=True) return db_file, nrg_report
def run(self, exp_dir, video_url, video_duration_s, collect=''): # Initialize energy meter results nrg_report = None # Unlock device screen (assume no password required) System.menu(self.target) # Press Back button to be sure we run the video from the start System.back(self.target) # Use the monkey tool to start YouTube without playing any video. # This allows to subsequently set the screen orientation to LANDSCAPE # and to reset the frame statistics. System.monkey(self.target, self.package) # Force screen in LANDSCAPE mode Screen.set_orientation(self.target, portrait=False) System.gfxinfo_reset(self.target, self.package) sleep(1) # Start YouTube video on the target device System.start_action(self.target, self.action, video_url) # Allow the activity to start sleep(1) # Start energy collection if 'energy' in collect and self.te.emeter: self.te.emeter.reset() # Wait until the end of the video self.logger.info("Play video for %d [s]", video_duration_s) sleep(video_duration_s) # Stop energy collection if 'energy' in collect and self.te.emeter: nrg_report = self.te.emeter.report(exp_dir) # Get frame stats db_file = os.path.join(exp_dir, "framestats.txt") System.gfxinfo_get(self.target, self.package, db_file) # Close the app without clearing the local data to # avoid the dialog to select the account at next start System.force_stop(self.target, self.package, clear=False) # Go back to home screen System.home(self.target) # Switch back to screen auto rotation Screen.set_orientation(self.target, auto=True) return db_file, nrg_report
def run(self, out_dir, location_search, swipe_count=5, collect=''): """ Run single Gmaps workload. :param out_dir: Path to experiment directory where to store results. :type out_dir: str :param location_search: Search string to be used in GMaps :type location_search: str :param swipe_count: Number of sets of (left, right, up, down) swipes to do :type swipe_count: int :param collect: Specifies what to collect. Possible values: - 'energy' - 'systrace' - 'ftrace' - any combination of the above :type collect: list(str) """ # Keep track of mandatory parameters self.out_dir = out_dir self.collect = collect # Set min brightness Screen.set_brightness(self._target, auto=False, percent=0) # Unlock device screen (assume no password required) Screen.unlock(self._target) # Use the monkey tool to start GMaps # This allows to subsequently set the screen orientation to LANDSCAPE # and to reset the frame statistics. System.monkey(self._target, self.package) # Force screen in PORTRAIT mode Screen.set_orientation(self._target, portrait=True) System.gfxinfo_reset(self._target, self.package) sleep(1) # Start GMaps on the target device loc_url = 'geo:0,0?q=' loc_url += '+'.join(location_search.split()) System.start_action(self._target, self.action, loc_url) # Allow the activity to start sleep(1) script = TargetScript(self._te, "gmaps_swiper.sh") self._log.debug('Accumulating commands') for i in range(swipe_count): System.hswipe(script, 20, 80, 100, True) script.append('sleep 1') System.hswipe(script, 20, 80, 100, False) script.append('sleep 1') System.vswipe(script, 40, 60, 100, True) script.append('sleep 1') System.vswipe(script, 40, 60, 100, False) script.append('sleep 1') self._log.debug('Accumulation done') # Push script to the target script.push() self._log.info('Opening GMaps to [%s]', loc_url) # Let GMaps zoom in on the location sleep(2) self.tracingStart() self._log.info('Launching target script') script.run() self._log.info('Target script ended') self.tracingStop() # Get frame stats self.db_file = os.path.join(out_dir, "framestats.txt") System.gfxinfo_get(self._target, self.package, self.db_file) # Close the app without clearing the local data to # avoid the dialog to select the account at next start System.force_stop(self._target, self.package, clear=False) # Go back to home screen System.home(self._target) # Set brightness back to auto Screen.set_brightness(self._target, auto=True) # Switch back to screen auto rotation Screen.set_orientation(self._target, auto=True)
def run(self, out_dir, video_url, video_duration_s, collect=''): """ Run single YouTube workload. :param out_dir: Path to experiment directory where to store results. :type out_dir: str :param video_url: Video URL to be played :type video_url: str :param video_duration_s: Play video for this required number of seconds :type video_duration_s: int :param collect: Specifies what to collect. Possible values: - 'energy' - 'systrace' - 'ftrace' - any combination of the above :type collect: list(str) """ # Keep track of mandatory parameters self.out_dir = out_dir self.collect = collect # Unlock device screen (assume no password required) Screen.unlock(self._target) # Stop youtube if already running System.force_stop(self._target, self.package) # Use the monkey tool to start YouTube without playing any video. # This allows to subsequently set the screen orientation to LANDSCAPE # and to reset the frame statistics. System.monkey(self._target, self.package) # Force screen in LANDSCAPE mode Screen.set_orientation(self._target, portrait=False) # Set min brightness Screen.set_brightness(self._target, auto=False, percent=0) System.gfxinfo_reset(self._target, self.package) sleep(1) # Start YouTube video on the target device System.start_action(self._target, self.action, video_url) # Allow the activity to start sleep(1) # Wait until the end of the video self.tracingStart() self._log.info('Play video for %d [s]', video_duration_s) sleep(video_duration_s) self.tracingStop() # Get frame stats self.db_file = os.path.join(out_dir, "framestats.txt") System.gfxinfo_get(self._target, self.package, self.db_file) # Close the app without clearing the local data to # avoid the dialog to select the account at next start System.force_stop(self._target, self.package, clear=False) # Go back to home screen System.home(self._target) # 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)
def run(self, out_dir, duration_s=10, collect='surfaceflinger'): """ Run a camera startup workload :param out_dir: Path to experiment directory where to store results. :type out_dir: str :param duration_s: Duration of test :type duration_s: int :param collect: Specifies what to collect. Possible values: - 'energy' - 'systrace' - 'ftrace' - any combination of the above :type collect: list(str) """ self._log.info( "Running CameraStartup for {}s and collecting {}".format( duration_s, collect)) # Keep track of mandatory parameters self.out_dir = out_dir self.collect = collect # Unlock device screen (assume no password required) Screen.unlock(self._target) # Set airplane mode System.set_airplane_mode(self._target, on=True) # Set min brightness Screen.set_brightness(self._target, auto=False, percent=0) # Force screen in PORTRAIT mode Screen.set_orientation(self._target, portrait=True) sleep(1) self.tracingStart() # Wait for a few seconds so that you can clear see start of trace and start of camera app sleep(3) # Use the monkey tool to start CameraStartup System.monkey(self._target, self.package) sleep(duration_s) self.tracingStop() # Close the app without clearing the local data to # avoid the dialog to select the account at next start System.force_stop(self._target, self.package, clear=False) # Go back to home screen System.home(self._target) # Set brightness back to auto Screen.set_brightness(self._target, auto=True) # Switch back to screen auto rotation Screen.set_orientation(self._target, auto=True) # Switch off airplane mode System.set_airplane_mode(self._target, on=False)
def run(self, out_dir, video_url, video_duration_s, collect=''): """ Run single YouTube workload. :param out_dir: Path to experiment directory where to store results. :type out_dir: str :param video_url: Video URL to be played :type video_url: str :param video_duration_s: Play video for this required number of seconds :type video_duration_s: int :param collect: Specifies what to collect. Possible values: - 'energy' - 'systrace' - 'ftrace' - any combination of the above :type collect: list(str) """ # Keep track of mandatory parameters self.out_dir = out_dir self.collect = collect # Unlock device screen (assume no password required) Screen.unlock(self._target) # Stop youtube if already running System.force_stop(self._target, self.package) # Use the monkey tool to start YouTube without playing any video. # This allows to subsequently set the screen orientation to LANDSCAPE # and to reset the frame statistics. System.monkey(self._target, self.package) # Force screen in LANDSCAPE mode Screen.set_orientation(self._target, portrait=False) # Set min brightness Screen.set_brightness(self._target, auto=False, percent=0) System.gfxinfo_reset(self._target, self.package) sleep(1) # Start YouTube video on the target device System.start_action(self._target, self.action, video_url) # Allow the activity to start sleep(1) # Wait until the end of the video self.tracingStart() self._log.info('Play video for %d [s]', video_duration_s) sleep(video_duration_s) self.tracingStop() # Get frame stats self.db_file = os.path.join(out_dir, "framestats.txt") System.gfxinfo_get(self._target, self.package, self.db_file) # Close the app without clearing the local data to # avoid the dialog to select the account at next start System.force_stop(self._target, self.package, clear=False) # Go back to home screen System.home(self._target) # 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)
def run(self, out_dir, test_name, duration_s, collect='', actions='default'): """ Run single UiBench workload. :param out_dir: Path 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 duration_s: Run benchmak for this required number of seconds :type duration_s: int :param collect: Specifies what to collect. Possible values: - 'energy' - 'systrace' - '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 # 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 self.collect = collect # Unlock device screen (assume no password required) Screen.unlock(self._target) # Close and clear application System.force_stop(self._target, self.package, clear=True) # Set airplane mode System.set_airplane_mode(self._target, on=True) # Set min brightness Screen.set_brightness(self._target, auto=False, percent=0) # Start the main view of the app which must be running # to reset the frame statistics. System.monkey(self._target, self.package) # Force screen in PORTRAIT mode Screen.set_orientation(self._target, portrait=True) # Reset frame statistics System.gfxinfo_reset(self._target, self.package) sleep(1) # Clear logcat os.system(self._adb('logcat -c')); # Regexps for benchmark synchronization start_logline = r'ActivityManager: START.*'\ 'cmp=com.android.test.uibench/{}'.format(activity) UIBENCH_BENCHMARK_START_RE = re.compile(start_logline) self._log.debug("START string [%s]", start_logline) # Parse logcat output lines logcat_cmd = self._adb( 'logcat ActivityManager:* System.out:I *:S BENCH:*'\ .format(self._target.adb_name)) self._log.info("%s", logcat_cmd) # Prepare user-input commands on the device if actions: script = TargetScript(self._te, "uibench.sh") for action in actions: self._perform_action(script, action) script.push() # Start the activity System.start_activity(self._target, self.package, activity) logcat = Popen(logcat_cmd, shell=True, stdout=PIPE) while True: # read next logcat line (up to max 1024 chars) message = logcat.stdout.readline(1024) # Benchmark start trigger match = UIBENCH_BENCHMARK_START_RE.search(message) if match: self.tracingStart() self._log.debug("Benchmark started!") break # Run the workload for the required time self._log.info('Benchmark [%s] started, waiting %d [s]', activity, duration_s) start = time() if actions: script.run() while (time() - start) < duration_s: sleep(1) self._log.debug("Benchmark done!") self.tracingStop() # Get frame stats self.db_file = os.path.join(out_dir, "framestats.txt") System.gfxinfo_get(self._target, self.package, self.db_file) # Close and clear application System.force_stop(self._target, self.package, clear=True) # Go back to home screen System.home(self._target) # Switch back to original settings Screen.set_orientation(self._target, auto=True) System.set_airplane_mode(self._target, on=False) Screen.set_brightness(self._target, auto=True)
def run(self, out_dir, package, permissions, duration_s, collect=''): """ Run single AppStartup workload. :param out_dir: Path to experiment directory where to store results. :type out_dir: str :param package: Name of the apk package :type package: str :param permissions: List of permissions the app requires :type permissions: list of str :param duration_s: Run benchmak for this required number of seconds :type duration_s: int :param collect: Specifies what to collect. Possible values: - 'energy' - 'time_in_state' - 'systrace' - 'ftrace' - any combination of the above :type collect: list(str) """ # Keep track of mandatory parameters self.out_dir = out_dir self.collect = collect # Check if the package exists on the device if not System.contains_package(self._target, package): raise RuntimeError('System does not contain the requried package') # Unlock device screen (assume no password required) Screen.unlock(self._target) # Close and clear application System.force_stop(self._target, package, clear=True) sleep(3) # Grant permissions for permission in permissions: System.grant_permission(self._target, package, permission) sleep(3) # Set min brightness Screen.set_brightness(self._target, auto=False, percent=100) # Set screen timeout Screen.set_timeout(self._target, seconds=duration_s + 60) # Force screen in PORTRAIT mode Screen.set_orientation(self._target, portrait=True) # Start the main view of the app System.monkey(self._target, package) # Start tracing self.tracingStart() # Sleep for duration sleep(duration_s) # Stop tracing self.tracingStop() # Reset permissions System.reset_permissions(self._target, package) # Close and clear application System.force_stop(self._target, package, clear=True) # Go back to home screen System.home(self._target) # Switch back to original settings Screen.set_defaults(self._target)
def run(self, out_dir, test_name, duration_s, collect=''): """ Run single UiBench workload. :param out_dir: Path 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 duration_s: Run benchmak for this required number of seconds :type duration_s: int :param collect: Specifies what to collect. Possible values: - 'energy' - 'systrace' - 'ftrace' - any combination of the above :type collect: list(str) """ activity = '.' + test_name # Keep track of mandatory parameters self.out_dir = out_dir self.collect = collect # Unlock device screen (assume no password required) Screen.unlock(self._target) # Close and clear application System.force_stop(self._target, self.package, clear=True) # Set airplane mode System.set_airplane_mode(self._target, on=True) # Set min brightness Screen.set_brightness(self._target, auto=False, percent=0) # Start the main view of the app which must be running # to reset the frame statistics. System.monkey(self._target, self.package) # Force screen in PORTRAIT mode Screen.set_orientation(self._target, portrait=True) # Reset frame statistics System.gfxinfo_reset(self._target, self.package) sleep(1) # Clear logcat os.system(self._adb('logcat -c')) # Regexps for benchmark synchronization start_logline = r'TestRunner: started' UIBENCH_BENCHMARK_START_RE = re.compile(start_logline) self._log.debug("START string [%s]", start_logline) # Parse logcat output lines logcat_cmd = self._adb( 'logcat TestRunner:* System.out:I *:S BENCH:*'\ .format(self._target.adb_name)) self._log.info("%s", logcat_cmd) # Run benchmark with a lot of iterations to avoid finishing before duration_s elapses command = "nohup am instrument -e iterations 1000000 -e class {}{} -w {}".format( self.test_package, activity, self.test_package) self._target.background(command) logcat = Popen(logcat_cmd, shell=True, stdout=PIPE) while True: # read next logcat line (up to max 1024 chars) message = logcat.stdout.readline(1024) # Benchmark start trigger match = UIBENCH_BENCHMARK_START_RE.search(message) if match: self.tracingStart() self._log.debug("Benchmark started!") break # Run the workload for the required time self._log.info('Benchmark [%s] started, waiting %d [s]', activity, duration_s) sleep(duration_s) self._log.debug("Benchmark done!") self.tracingStop() # Get frame stats self.db_file = os.path.join(out_dir, "framestats.txt") System.gfxinfo_get(self._target, self.package, self.db_file) # Close and clear application System.force_stop(self._target, self.package, clear=True) # Go back to home screen System.home(self._target) # Switch back to original settings Screen.set_orientation(self._target, auto=True) System.set_airplane_mode(self._target, on=False) Screen.set_brightness(self._target, auto=True)
def run(self, out_dir, test_name, duration_s, collect=''): """ Run single UiBench workload. :param out_dir: Path 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 duration_s: Run benchmak for this required number of seconds :type duration_s: int :param collect: Specifies what to collect. Possible values: - 'energy' - 'systrace' - 'ftrace' - any combination of the above :type collect: list(str) """ activity = '.' + test_name # Keep track of mandatory parameters self.out_dir = out_dir self.collect = collect # Unlock device screen (assume no password required) Screen.unlock(self._target) # Close and clear application System.force_stop(self._target, self.package, clear=True) # Set airplane mode System.set_airplane_mode(self._target, on=True) # Set min brightness Screen.set_brightness(self._target, auto=False, percent=0) # Start the main view of the app which must be running # to reset the frame statistics. System.monkey(self._target, self.package) # Force screen in PORTRAIT mode Screen.set_orientation(self._target, portrait=True) # Reset frame statistics System.gfxinfo_reset(self._target, self.package) sleep(1) # Clear logcat os.system(self._adb('logcat -c')); # Regexps for benchmark synchronization start_logline = r'ActivityManager: START.*'\ 'cmp=com.android.test.uibench/{}'.format(activity) UIBENCH_BENCHMARK_START_RE = re.compile(start_logline) self._log.debug("START string [%s]", start_logline) # Parse logcat output lines logcat_cmd = self._adb( 'logcat ActivityManager:* System.out:I *:S BENCH:*'\ .format(self._target.adb_name)) self._log.info("%s", logcat_cmd) # Start the activity System.start_activity(self._target, self.package, activity) logcat = Popen(logcat_cmd, shell=True, stdout=PIPE) while True: # read next logcat line (up to max 1024 chars) message = logcat.stdout.readline(1024) # Benchmark start trigger match = UIBENCH_BENCHMARK_START_RE.search(message) if match: self.tracingStart() self._log.debug("Benchmark started!") break # Run the workload for the required time self._log.info('Benchmark [%s] started, waiting %d [s]', activity, duration_s) sleep(duration_s) self._log.debug("Benchmark done!") self.tracingStop() # Get frame stats self.db_file = os.path.join(out_dir, "framestats.txt") System.gfxinfo_get(self._target, self.package, self.db_file) # Close and clear application System.force_stop(self._target, self.package, clear=True) # Go back to home screen System.home(self._target) # Switch back to original settings Screen.set_orientation(self._target, auto=True) System.set_airplane_mode(self._target, on=False) Screen.set_brightness(self._target, auto=True)
def run(self, out_dir, location_search, swipe_count=5, collect=''): """ Run single Gmaps workload. :param out_dir: Path to experiment directory where to store results. :type out_dir: str :param location_search: Search string to be used in GMaps :type location_search: str :param swipe_count: Number of sets of (left, right, up, down) swipes to do :type swipe_count: int :param collect: Specifies what to collect. Possible values: - 'energy' - 'systrace' - 'ftrace' - any combination of the above :type collect: list(str) """ # Keep track of mandatory parameters self.out_dir = out_dir self.collect = collect # Set min brightness Screen.set_brightness(self._target, auto=False, percent=0) # Unlock device screen (assume no password required) Screen.unlock(self._target) # Use the monkey tool to start GMaps # This allows to subsequently set the screen orientation to LANDSCAPE # and to reset the frame statistics. System.monkey(self._target, self.package) # Force screen in PORTRAIT mode Screen.set_orientation(self._target, portrait=True) System.gfxinfo_reset(self._target, self.package) sleep(1) # Start GMaps on the target device loc_url = 'geo:0,0?q=' loc_url += '+'.join(location_search.split()) System.start_action(self._target, self.action, loc_url) # Allow the activity to start sleep(1) script = TargetScript(self._te, "gmaps_swiper.sh") self._log.debug('Accumulating commands') for i in range(swipe_count): System.hswipe(script, 20, 80, 100, True) script.append('sleep 1') System.hswipe(script, 20, 80, 100, False) script.append('sleep 1') System.vswipe(script, 40, 60, 100, True) script.append('sleep 1') System.vswipe(script, 40, 60, 100, False) script.append('sleep 1') self._log.debug('Accumulation done') # Push script to the target script.push() self._log.info('Opening GMaps to [%s]', loc_url) # Let GMaps zoom in on the location sleep(2) self.tracingStart() self._log.info('Launching target script') script.run() self._log.info('Target script ended') self.tracingStop() # Get frame stats self.db_file = os.path.join(out_dir, "framestats.txt") System.gfxinfo_get(self._target, self.package, self.db_file) # Close the app without clearing the local data to # avoid the dialog to select the account at next start System.force_stop(self._target, self.package, clear=False) # Go back to home screen System.home(self._target) # Set brightness back to auto Screen.set_brightness(self._target, auto=True) # Switch back to screen auto rotation Screen.set_orientation(self._target, auto=True)
def run(self, out_dir, duration_s=30, collect='systrace'): """ Run a camera preview workload :param out_dir: Path to experiment directory where to store results. :type out_dir: str :param duration_s: Duration of test :type duration_s: int :param collect: Specifies what to collect. Possible values: - 'energy' - 'systrace' - 'ftrace' - any combination of the above :type collect: list(str) """ self._log.info("Running CameraPreview for {}s and collecting {}".format(duration_s, collect)) # Keep track of mandatory parameters self.out_dir = out_dir self.collect = collect # Unlock device screen (assume no password required) Screen.unlock(self._target) # Set airplane mode System.set_airplane_mode(self._target, on=True) # Set min brightness Screen.set_brightness(self._target, auto=False, percent=0) # Use the monkey tool to start CameraPreview # This allows to subsequently set the screen orientation to LANDSCAPE # and to reset the frame statistics. System.monkey(self._target, self.package) # Force screen in PORTRAIT mode Screen.set_orientation(self._target, portrait=True) sleep(2) self.tracingStart() sleep(duration_s) self.tracingStop() # Close the app without clearing the local data to # avoid the dialog to select the account at next start System.force_stop(self._target, self.package, clear=False) # Go back to home screen System.home(self._target) # Set brightness back to auto Screen.set_brightness(self._target, auto=True) # Switch back to screen auto rotation Screen.set_orientation(self._target, auto=True) # Switch off airplane mode System.set_airplane_mode(self._target, on=False)