def run(self, out_dir, test_name, iterations=10, 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 iterations: Run benchmak for this required number of iterations :type iterations: int :param collect: Specifies what to collect. Possible values: - 'systrace' - 'ftrace' :type collect: list(str) """ if 'energy' in collect: raise ValueError('UiBench workload does not support energy data collection') activity = '.' + test_name # Keep track of mandatory parameters self.out_dir = out_dir self.collect = collect # Filter out test overhead filter_prop = System.get_boolean_property(self._target, 'debug.hwui.filter_test_overhead') if not filter_prop: System.set_property( self._target, 'debug.hwui.filter_test_overhead', 'true', restart=True) # 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) # Force screen in PORTRAIT mode Screen.set_orientation(self._target, portrait=True) # 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) finish_logline = r'TestRunner: finished' UIBENCH_BENCHMARK_FINISH_RE = re.compile(finish_logline) self._log.debug("FINISH 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) command = "am instrument -e iterations {} -e class {}{} -w {}".format( iterations, self.test_package, activity, self.test_package) test_proc = 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!") match = UIBENCH_BENCHMARK_FINISH_RE.search(message) if match: self.tracingStop() self._log.debug("Benchmark finished!") test_proc.wait() break # Get frame stats self.db_file = os.path.join(out_dir, "framestats.txt") with open(self.db_file, 'w') as f: f.writelines(test_proc.stdout.readlines()) self.results = self.get_results(out_dir) # 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, iterations, collect=''): """ Run single system app jank test workload. Performance statistics are stored in self.results, and can be retrieved after the fact by calling SystemUi.get_results() :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 iterations: Run benchmark for this required number of iterations :type iterations: int :param collect: Specifies what to collect. Possible values: - 'systrace' - 'ftrace' - 'gfxinfo' - 'surfaceflinger' - any combination of the above :type collect: list(str) """ if "energy" in collect: raise ValueError('System app workload does not support energy data collection') activity = "." + test_name package = self._get_test_package(test_name) # Keep track of mandatory parameters self.out_dir = out_dir self.collect = collect # Filter out test overhead filter_prop = System.get_boolean_property(self._target, "debug.hwui.filter_test_overhead") if not filter_prop: System.set_property(self._target, "debug.hwui.filter_test_overhead", "true", restart=True) # Unlock device screen (assume no password required) Screen.unlock(self._target) # Close and clear application System.force_stop(self._target, package, clear=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) # Delete old test results self._target.remove("/sdcard/results.log") # Clear logcat self._target.execute("logcat -c") # Regexps for benchmark synchronization start_logline = r"TestRunner: started" SYSAPP_BENCHMARK_START_RE = re.compile(start_logline) self._log.debug("START string [%s]", start_logline) finish_logline = r"TestRunner: finished" SYSAPP_BENCHMARK_FINISH_RE = re.compile(finish_logline) self._log.debug("FINISH string [%s]", finish_logline) # Parse logcat output lines logcat_cmd = self._adb("logcat TestRunner:* System.out:I *:S BENCH:*") self._log.info("%s", logcat_cmd) command = "am instrument -e iterations {} -e class {}{} -w {}".format( iterations, self.test_package, activity, self.test_package) logcat = Popen(logcat_cmd, shell=True, stdout=PIPE) test_proc = self._target.background(command) while True: # read next logcat line (up to max 1024 chars) message = logcat.stdout.readline(1024) # Benchmark start match = SYSAPP_BENCHMARK_START_RE.search(message) if match: self.tracingStart() self._log.debug("Benchmark started!") # Benchmark finish match = SYSAPP_BENCHMARK_FINISH_RE.search(message) if match: self.tracingStop() self._log.debug("Benchmark finished!") test_proc.wait() break sleep(5) self._target.pull("/sdcard/results.log", os.path.join(out_dir, "results.log")) self.db_file = os.path.join(out_dir, "results.log") self.results = self.get_results(out_dir) # 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_orientation(self._target, auto=True) Screen.set_brightness(self._target, auto=True)