Exemplo n.º 1
0
 def notify(self, _json_data):
     _dict = Json().loads(_json_data)
     _method = _dict['method']
     _params = _dict['params']
     _device_udid = _params[0]['environment']['device_udid']
     _instruments_pid = _params[0]['pid']
     # -*- -*- -*-
     if _method == 'InstrumentsStarted': print_msg(_method)
     # -*- -*- -*-
     if _method in [
             'TraceTemplateInvalid', 'TargetAppBundleIDInvalid',
             'DeviceIsCurrentlyLockedWithAPasscode',
             'TheAppMustBeSignedWithADevelopmentIdentity',
             'TargetAppIsNotFrontmost', 'TargetAppDied', 'DeviceDisabled',
             'InstrumentsError', 'InstrumentsTimeout'
     ]:
         if _method == 'TargetAppDied':
             self.crash_flag = True
         self.DeviceCommandDelegator.clean_all(_device_udid, _method)
         self.TasksLastError.update({_device_udid: _method})
         self._dispatch_started_events(_device_udid)
         Process().kill_process_tree_by_pid(_instruments_pid)
         print_err(_method)
     # -*- -*- -*-
     if _method == 'InstrumentsTerminated':
         self.DeviceCommandDelegator.clean_all(_device_udid, _method)
         self.TasksEnvironment.pop(_device_udid, None)
         self.TasksBootstrapStandBy.pop(_device_udid, None)
         self.TasksPID.pop(_device_udid, None)
         self.LastExecCommandDeviceUdid = None
         self._dispatch_stopped_events(_device_udid)
         print_msg(_method)
Exemplo n.º 2
0
 def __excavate__(self, line):
     if self.instruments_trace_complete == False and re.match('^ScreenshotCaptured:.+$', line):
         if self.instruments_uia_result_path is None:
             self.instruments_uia_result_path = self._find_instruments_uia_result_path()
         if self.instruments_uia_result_path is not None:
             data = Json().loads(re.sub('^ScreenshotCaptured:', '', line))
             src = os.path.join(self.instruments_uia_result_path, data['name'])
             dst = data['path']
             start_time = time.time()
             while time.time() - start_time < 10:
                 if os.path.exists(src):
                     FileManager(src).force_copy_to(dst)
                     if os.path.exists(dst): return
                 time.sleep(0.03)
             print_err('Warning: screenshot failed [ %s ]' % src)
             return
     if self.instruments_trace_complete == False and re.match('^TORPC:.+$', line):
         try: self.rpc.ins.send_result(self.device_udid, re.sub('^TORPC:', '', line))
         except Exception, e: print_err(str(e))
         return
     if self.instruments_trace_complete == False and re.match('^Instruments Usage Error : The specified template .+$', line, re.I):
         self.__notify__('TraceTemplateInvalid')
         self.instruments_trace_complete = True
         return
     if self.instruments_trace_complete == False and re.match('^Instruments Usage Error : Specified target process is invalid: .+$', line, re.I):
         self.__notify__('TargetAppBundleIDInvalid')
         self.instruments_trace_complete = True
         return
     if self.instruments_trace_complete == False and re.match('^Instruments Trace Error : Target failed to run: Device is currently locked with a passcode.  Please unlock the device and try again.$', line, re.I):
         self.__notify__('DeviceIsCurrentlyLockedWithAPasscode')
         self.instruments_trace_complete = True
         return
     if self.instruments_trace_complete == False and re.match('^Instruments Trace Error : Target failed to run: Permission to debug com.tencent.qq.dailybuild.test.gn was denied.  The app must be signed with a development identity \(e.g. iOS Developer\).$', line, re.I):
         self.__notify__('TheAppMustBeSignedWithADevelopmentIdentity')
         self.instruments_trace_complete = True
         return
     if self.instruments_trace_complete == False and re.match('^Could not start script, target application is not frontmost.$', line, re.I):
         self.__notify__('TargetAppIsNotFrontmost')
         self.instruments_trace_complete = True
         return
     if self.instruments_trace_complete == False and re.match('^The target application appears to have died$', line, re.I):
         self.__notify__('TargetAppDied')
         self.instruments_trace_complete = True
         return
     if self.instruments_trace_complete == False and re.match('^.+WebKit Threading Violation - initial use of WebKit from a secondary thread.$', line, re.I):
         self.__notify__('DeviceDisabled')
         return
     if self.instruments_trace_complete == False and re.match('^Instruments Usage Error :.+$', line, re.I):
         self.__notify__('InstrumentsError')
         self.instruments_trace_complete = True
         return
     if self.instruments_trace_complete == False and re.match('^Instruments Trace Complete.+$', line, re.I):
         self.instruments.keep_running = False
         self.instruments_trace_complete = True
         return
Exemplo n.º 3
0
 def start(self,
           _device_udid,
           _device_simulator,
           _bundle_id,
           app_params,
           _trace_template=None,
           _trace_output=None,
           _retry=3,
           _timeout=55,
           _instruments_timeout=20 * 60,
           _cmd_fetch_delegate_timeout=10,
           _force_release=True):
     _device = DT().get_device_by_udid(_device_udid)
     if _device is None:
         raise Exception('The device_udid is invalid: %s' % _device_udid)
     if _timeout < 10:
         raise Exception(
             'The _timeout value must be greater than 10 seconds')
     if _force_release and self.is_working(_device_udid):
         self.release(_device_udid)
     if self.is_working(_device_udid): raise Exception('The app is working')
     params = ''
     if app_params:
         params_list = []
         for k in app_params:
             params_list.append("-%s" % k)
             params_list.append("%s" % app_params[k])
         params = ' '.join(params_list)
     for i in xrange(_retry):
         _task = ThreadTask(' '.join([
             self.PythonPath,
             '"%s"' % self.InstrumentsDriverPath,
             '-device_udid "%s"' % _device_udid,
             '-device_simulator %s' % _device_simulator,
             '-bundle_id "%s"' % _bundle_id,
             '-params "%s"' % params if params else '',
             '-trace_template "%s"' % _trace_template,
             '-trace_output "%s"' % _trace_output,
             '-xmlrpc_uri "http://%s:%s"' %
             (self._server.address, self._server.port),
             '-timeout %s' % _instruments_timeout,
             '-cmd_fetch_delegate_timeout %s' % _cmd_fetch_delegate_timeout,
             '-environment "%s"' % urllib.quote(
                 "%s" % self.TasksEnvironment.get(_device_udid, {}))
         ]))
         if self.wait_for_started(_device_udid, _timeout):
             self.TasksPID.update({_device_udid: _task.pid})
             return True
         print_err('ins.start -> retry [%s]' % (i + 1))
         Process().kill_child_processes_by_ppid(_task.pid)
         time.sleep(3)
     _error = self.TasksLastError.pop(_device_udid, None)
     if _error: raise Exception('%s' % _error)
     return False
Exemplo n.º 4
0
 def _find_instruments_uia_result_path(self):
     if os.path.exists(self.environment.get('uia_results_path')):
         items = FileManager(path=self.environment.get('uia_results_path')).get_children(sort_by_ctime=True)
         if len(items) > 0 : return items[-1]
         else:print_err('Warning: instruments_uia_result_path not found.')
Exemplo n.º 5
0
 def __notify__(self, method):
     print_msg(method)
     try: self.rpc.ins.notify(Json().dumps({"method": "%s" % method, "params": [{'pid': self.instruments_pid, 'environment': self.environment, 'error': self._get_err()}]}))
     except Exception, e: print_err(str(e))