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 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 start(self, results): """ Grab stage: starts log reader, make sync w/ flashlight 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 start -n {package}/{runner}.MainActivity" .format(device_id=self.source, package=self.lightning_apk_class, runner=self.lightning_apk_class)) 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 end(self): """ Stop test and grabbers pipeline: if uplug_type is manual: ask user to plug device in get logcat dump from device if unplug_type is auto: stop async logcat process, readers and queues """ if self.unplug_type == 'manual': logger.warning( "Plug the phone in and press `enter` to continue...") # TODO make API and remove this raw_input() _, stdout, stderr = execute( "adb -s {device_id} logcat -d".format(device_id=self.source), catch_out=True) logger.debug('Recieved %d logcat data', len(stdout)) self.phone_q.put(chunk_to_df(stdout, android_logevent_re)) return if self.unplug_type == 'auto': self.logcat_reader_stdout.close() self.logcat_reader_stderr.close() self.logcat_process.kill() self.drain_logcat_stdout.close() self.drain_logcat_stderr.close() return
def run_test(self): """ App stage: run app/phone tests, pipeline: if unplug_type is auto: run test if unplug_type is manual: skip """ if self.unplug_type == 'manual': return if self.unplug_type == 'auto': execute( "adb shell am instrument -w -e class {test_class} {test_package}/{test_runner}" .format(test_class=self.test_class, test_package=self.test_package, test_runner=self.test_runner)) return
def prepare(self): """ Phone preparements stage: install apps etc pipeline: install lightning install apks clean log """ # 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)) # unplug device or start logcat if self.unplug_type == 'manual': logger.info( 'Detach the phone %s from USB and press enter to continue...', self.source) # TODO make API and remove this raw_input()
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(self): """ Phone preparements stage: install apps etc pipeline: install lightning install apks clean log """ rcode, stdout, stderr = execute( "adb -s {device_id} get-state".format(device_id=self.source)) if stdout: if stdout.strip('\n') == 'unknown': raise RuntimeError( 'Phone "%s" has an unknown state. Please check device authorization and current state' % self.source) else: logger.debug( 'Unknown adb get-state command stdout, continue without phone check...' ) # 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))