def start(self, results): """ Grab stage: starts log reader, make sync w/ flashlight pipeline: if uplug_type is manual: remind user to start flashlight app if unplug_type is auto: start async logcat reader start lightning flashes Args: results (queue-like object): Phone should put there dataframes, format: ['sys_uts', 'message'] """ self.phone_q = results #if self.unplug_type == 'manual': # logger.info("It's time to start flashlight app!") # return #if self.unplug_type == 'auto': self.__start_async_logcat() # start flashes app execute( "adb -s {device_id} shell am start -n {package}/{runner}.MainActivity".format( device_id=self.source, package=self.lightning_apk_class, runner=self.lightning_apk_class ) ) logger.info('Waiting 15 seconds till flashlight app end its work...') time.sleep(15) return
def end(self): """ Stop test and grabbers """ if self.test_performer: self.test_performer.close() self.logcat_reader_stdout.close() self.logcat_reader_stderr.close() self.logcat_process.kill() self.drain_logcat_stdout.close() self.drain_logcat_stderr.close() # apps cleanup for apk in self.cleanup_apps: execute("adb -s {device_id} uninstall {app}".format(device_id=self.source, app=apk)) return
def execute(self, cmd): """ Execute and check exit code """ self.log.info("Executing: %s", cmd) retcode = execute( cmd, shell=True, poll_period=0.1, catch_out=self.catch_out)[0] if retcode: raise RuntimeError("Subprocess returned %s" % retcode) return retcode
def is_test_finished(self): if self.poll: self.log.info("Executing: %s", self.poll) retcode = execute(self.poll, shell=True, poll_period=0.1, catch_out=self.catch_out)[0] if retcode: self.log.warn("Non-zero exit code, interrupting test: %s", retcode) return retcode return -1
def start(self, results): """ Grab stage: starts log reader, make sync w/ flashlight pipeline: if unplug_type is manual: remind user to start flashlight app if unplug_type is auto: start async logcat reader start lightning flashes Args: results (queue-like object): Phone should put there dataframes, format: ['sys_uts', 'message'] """ self.phone_q = results self.__start_async_logcat() # start flashes app execute( "adb -s {device_id} shell am startservice -a BLINK --ei DELAY 10000 -n com.yandex.pmu_blinker/.PmuIntentService" .format(device_id=self.source, )) return
def prepare_test(self): try: retcode, stdout, stderr = execute([ self.get_option("phantom_path"), 'check', self.phantom.config_file ], catch_out=True) except OSError: logger.debug("Phantom I/O engine is not installed!", exc_info=True) raise OSError( "Phantom I/O engine not found. \nMore information: {doc_url}". format( doc_url= 'http://yandextank.readthedocs.io/en/latest/install.html')) else: if retcode or stderr: raise RuntimeError( "Config check failed. Subprocess returned code %s. Stderr: %s" % (retcode, stderr)) logger.debug( "Linking sample reader to aggregator." " Reading samples from %s", self.phantom.phout_file) logger.debug( "Linking stats reader to aggregator." " Reading stats from %s", self.phantom.stat_log) self.core.job.aggregator.add_result_listener(self) # stepping inside get_info() self.core.job.phantom_info = self.phantom.get_info() try: console = self.core.get_plugin_of_type(ConsolePlugin) except KeyError: logger.debug("Console not found: %s", exc_info=True) else: widget1 = PhantomProgressBarWidget(self) console.add_info_widget(widget1) self.core.job.aggregator.add_result_listener(widget1) widget2 = PhantomInfoWidget(self) console.add_info_widget(widget2) self.core.job.aggregator.add_result_listener(widget2)
def __setup_taskset(self, affinity, pid=None, args=None): """ if pid specified: set process w/ pid `pid` CPU affinity to specified `affinity` core(s) if args specified: modify list of args for Popen to start w/ taskset w/ affinity `affinity` """ self.taskset_path = self.get_option(self.SECTION, 'taskset_path') if args: return [self.taskset_path, '-c', affinity] + args if pid: args = "%s -pc %s %s" % (self.taskset_path, affinity, pid) retcode, stdout, stderr = execute(args, shell=True, poll_period=0.1, catch_out=True) logger.debug('taskset for pid %s stdout: %s', pid, stdout) if retcode == 0: logger.info("Enabled taskset for pid %s with affinity %s", str(pid), affinity) else: logger.debug('Taskset setup failed w/ retcode :%s', retcode) raise KeyError(stderr)
def __check_disk(self): ''' raise exception on disk space exceeded ''' cmd = "sh -c \"df --no-sync -m -P -l -x fuse -x tmpfs -x devtmpfs -x davfs -x nfs " cmd += self.core.artifacts_base_dir cmd += " | tail -n 1 | awk '{print \$4}' \"" res = execute(cmd, True, 0.1, True) logging.debug("Result: %s", res) if not len(res[1]): self.log.debug("No disk usage info: %s", res[2]) return disk_free = res[1] self.log.debug("Disk free space: %s/%s", disk_free.strip(), self.disk_limit) if int(disk_free.strip()) < self.disk_limit: raise RuntimeError( "Not enough local resources: disk space less than %sMB in %s: %sMB" % (self.disk_limit, self.core.artifacts_base_dir, int(disk_free.strip())))
def __setup_taskset(self, affinity, pid=None, args=None): """ if pid specified: set process w/ pid `pid` CPU affinity to specified `affinity` core(s) if args specified: modify list of args for Popen to start w/ taskset w/ affinity `affinity` """ self.taskset_path = self.get_option(self.SECTION, 'taskset_path') if args: return [self.taskset_path, '-c', affinity] + args if pid: args = "%s -pc %s %s" % (self.taskset_path, affinity, pid) retcode, stdout, stderr = execute(args, shell=True, poll_period=0.1, catch_out=True) logger.debug('taskset for pid %s stdout: %s', pid, stdout) if retcode == 0: logger.info("Enabled taskset for pid %s with affinity %s", str(pid), affinity) else: logger.debug('Taskset setup failed w/ retcode :%s', retcode) raise KeyError(stderr)
def __check_disk(self): ''' raise exception on disk space exceeded ''' cmd = "sh -c \"df --no-sync -m -P -l -x fuse -x tmpfs -x devtmpfs -x davfs -x nfs " cmd += self.core.artifacts_base_dir cmd += " | tail -n 1 | awk '{print \$4}' \"" res = execute(cmd, True, 0.1, True) logging.debug("Result: %s", res) if not len(res[1]): self.log.debug("No disk usage info: %s", res[2]) return disk_free = res[1] self.log.debug( "Disk free space: %s/%s", disk_free.strip(), self.disk_limit) if int(disk_free.strip()) < self.disk_limit: raise RuntimeError( "Not enough local resources: disk space less than %sMB in %s: %sMB" % ( self.disk_limit, self.core.artifacts_base_dir, int(disk_free.strip())))
def prepare(self): """ Phone preparements stage: install apps etc pipeline: install lightning install apks clean log """ # apps cleanup for apk in self.cleanup_apps: execute("adb -s {device_id} uninstall {app}".format(device_id=self.source, app=apk)) # install lightning self.lightning_apk_fname = resource.get_opener(self.lightning_apk_path).get_filename logger.info('Installing lightning apk...') execute("adb -s {device_id} install -r -d -t {apk}".format(device_id=self.source, apk=self.lightning_apk_fname)) # install apks for apk in self.test_apps: apk_fname = resource.get_opener(apk).get_filename execute("adb -s {device_id} install -r -d -t {apk}".format(device_id=self.source, apk=apk_fname)) # clean logcat execute("adb -s {device_id} logcat -c".format(device_id=self.source))
def prepare_test(self): try: retcode, stdout, stderr = execute( [self.get_option("phantom_path"), 'check', self.phantom.config_file], catch_out=True ) except OSError: logger.debug("Phantom I/O engine is not installed!", exc_info=True) raise OSError("Phantom I/O engine not found. \nMore information: {doc_url}".format( doc_url='http://yandextank.readthedocs.io/en/latest/install.html') ) else: if retcode or stderr: raise RuntimeError("Config check failed. Subprocess returned code %s. Stderr: %s" % (retcode, stderr)) logger.debug( "Linking sample reader to aggregator." " Reading samples from %s", self.phantom.phout_file) logger.debug( "Linking stats reader to aggregator." " Reading stats from %s", self.phantom.stat_log) self.core.job.aggregator.add_result_listener(self) self.core.job.phantom_info = self.phantom.get_info() try: console = self.core.get_plugin_of_type(ConsolePlugin) except KeyError: logger.debug("Console not found: %s", exc_info=True) else: widget1 = PhantomProgressBarWidget(self) console.add_info_widget(widget1) self.core.job.aggregator.add_result_listener(widget1) widget2 = PhantomInfoWidget(self) console.add_info_widget(widget2) self.core.job.aggregator.add_result_listener(widget2)