Esempio 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)
Esempio n. 2
0
 def result(self):
     if self._status != self.FinishedStatus:
         self._finished_timestamp = time.time()
         self._status = self.FinishedStatus
     if True == self._print:
         print_msg(
             'DeviceCommand-%s: Finished - Standby = %ss' %
             (self._command_id,
              round(self._finished_timestamp - self._standby_timestamp, 3)))
     return self._result
Esempio n. 3
0
 def discard(self, _error='CommandDiscard'):
     self._discard_timestamp = time.time()
     self._status = self.DiscardStatus
     self._result = self.__get_result_struct__(_error=_error)
     self._executed_event.set()
     if True == self._print:
         print_msg(
             'DeviceCommand-%s: Discarded - Standby = %ss' %
             (self._command_id,
              round(self._discard_timestamp - self._standby_timestamp, 3)))
Esempio n. 4
0
 def command(self):
     self._execute_timestamp = time.time()
     self._status = self.ExecuteStatus
     self._execute_event.set()
     if True == self._print:
         print_msg(
             'DeviceCommand-%s: Execute - Standby = %ss' %
             (self._command_id,
              round(self._execute_timestamp - self._standby_timestamp, 3)))
     return self._command
Esempio n. 5
0
 def exec_command(self, i):
     _cmd = deviceCommandDelegator.get_next_command(udid)
     if _cmd:
         print_msg('Driver - %s <<< cmd : %s' % (i, _cmd))
         _rst = {
             "id": _cmd['id'],
             "result": "%s" % _cmd['method'],
             "error": _cmd['method']
         }
         deviceCommandDelegator.set_command_result(udid, _rst)
         print_msg('Driver - %s >>> rst : %s' % (i, _rst))
     else:
         import sys
         sys.stderr.write('%s\n' % '无命令')
Esempio n. 6
0
 def result(self, _result={}):
     if False == isinstance(_result, dict):
         raise Exception(
             "__DeviceCommand__.result = _result: The _result is not an instance of the <dict>."
         )
     self._executed_timestamp = time.time()
     self._status = self.ExecutedStatus
     self._result = self.__get_result_struct__()
     self._result.update(_result)
     self._executed_event.set()
     if True == self._print:
         print_msg(
             'DeviceCommand-%s: Executed - Execute = %ss' %
             (self._command_id,
              round(self._executed_timestamp - self._execute_timestamp, 3)))
Esempio n. 7
0
 def run(self):
     _exec_command_times = list()
     for i in xrange(self._cmds):
         _cmd = {"method": "%s" % i, "params": ["%s" % i]}
         print_msg('-' * 60)
         print_msg('Case   - %s cmd --> : %s' % (i, _cmd))
         _start_timestamp = time.time()
         _rst = deviceCommandDelegator.exec_command(udid, _cmd)
         _exec_command_times.append(time.time() - _start_timestamp)
         print_msg('Case   - %s rst <-- : %s' % (i, _rst))
     print_msg('-' * 60)
     _all_exec_command_time = 0
     for item in _exec_command_times:
         _all_exec_command_time += item
     print_msg('执行命令开销: %s\n' %
               (_all_exec_command_time / len(_exec_command_times)))
Esempio n. 8
0
 def __init__(self, **args):
     self.logger = Logger(os.path.join('/tmp', 'instruments.log'))
     self.args = args
     if self.args.get('device_udid') is None: raise Exception('device_udid is None.')
     if self.args.get('device_udid') is None: raise Exception('bundle_id is None.')
     self.device_udid = self.args['device_udid']
     self.environment = {'device_udid'                 : self.args['device_udid'],
                         'device_simulator'            : self.args['device_simulator'],
                         'bundle_id'                   : self.args['bundle_id'],
                         'trace_template'              : self.args.get('trace_template'),
                         'trace_output'                : self.args.get('trace_output'),
                         'uia_script'                  : os.path.abspath(self.args.get('uia_script', os.path.join(self.CurrentDirectoryPath, '_bootstrap.js'))),
                         'uia_results_path'            : os.path.join('/tmp', '_uiaresults'),
                         'screen_shot_path'            : os.path.join('/tmp', '_screenshot'),
                         'cwd'                         : self.CurrentDirectoryPath,
                         'timeout'                     : self.args.get('timeout', 20 * 60),
                         'xmlrpc_uri'                  : self.args.get('xmlrpc_uri', 'http://0.0.0.0:11516'),
                         'cmd_fetch_delegate'          : os.path.join(self.CurrentDirectoryPath, '_cmd_fetch_delegate.py'),
                         'cmd_fetch_delegate_timeout'  : self.args.get('cmd_fetch_delegate_timeout', 10),
                         'ignore_cmd_error'            : self.args.get('ignore_cmd_error', True),
                         'python_path'                 : self.PythonPath}
     self.environment.update(eval(urllib.unquote(self.args.get('environment'))))
     self.args.update(self.environment)
     self.args.update({'started_callback': self.__started_callback__, 'stdout_line_callback': self.__stdout_line_callback__, 'stderr_line_callback': self.__stderr_line_callback__, 'return_code_callback': self.__return_code_callback__})
     self._clean_instrumentscli_n_trace(self.environment.get('trace_output'))
     self._renew_output_path()
     self._update_environment_file()
     self.out = list()
     self.err = list()
     self.rpc = xmlrpclib.ServerProxy(self.environment.get('xmlrpc_uri'), allow_none=True)
     self.instruments = Xcode().start_instruments(**self.args)
     print_msg(self.instruments.command)
     self.instruments_uia_result_path = None
     self.instruments_timeout_daemon = ThreadTimer(timeout=self.environment.get('timeout'), callback=self.__timeout_kill_instruments__)
     self.instruments_pid = self.instruments.pid
     self.instruments_trace_complete = False
     self.instruments.wait()
Esempio n. 9
0
 def run(self):
     if True == self._print:
         print_msg('DeviceCommand-%s: %s' % (self._command_id, '-' * 60))
         print_msg('DeviceCommand-%s: Command  = %s' %
                   (self._command_id, self._command))
     if self._standby_timeout > 0:
         self._execute_event.wait(self._standby_timeout)
     if self._execute_timeout > 0:
         self._executed_event.wait(self._execute_timeout)
     if self._execute_timeout > 0 and self._status not in [
             self.ExecutedStatus, self.DiscardStatus, self.FinishedStatus
     ]:
         self._timeout_timestamp = time.time()
         self._status = self.TimeoutStatus
         self._result = self.__get_result_struct__(_error="CommandTimeout")
     if self._status == self.ExecutedStatus:
         self._finished_timestamp = time.time()
         self._status = self.FinishedStatus
     if True == self._print:
         print_msg('DeviceCommand-%s: Result   = %s' %
                   (self._command_id, self._result))
         print_msg('DeviceCommand-%s: Duration = %ss' %
                   (self._command_id,
                    round(time.time() - self._standby_timestamp, 3)))
Esempio n. 10
0
                print_msg('Case   - %s cmd --> : %s' % (i, _cmd))
                _start_timestamp = time.time()
                _rst = deviceCommandDelegator.exec_command(udid, _cmd)
                _exec_command_times.append(time.time() - _start_timestamp)
                print_msg('Case   - %s rst <-- : %s' % (i, _rst))
            print_msg('-' * 60)
            _all_exec_command_time = 0
            for item in _exec_command_times:
                _all_exec_command_time += item
            print_msg('执行命令开销: %s\n' %
                      (_all_exec_command_time / len(_exec_command_times)))

    for i in xrange(6):
        case1 = Case()
        driver1 = Driver()
        driver2 = Driver()
        case2 = Case()

    while threading.active_count() > 3:
        time.sleep(1)
        print_msg('Waitting... [count: %s]' % threading.active_count())

    for item in threading.enumerate():
        print_msg(item)

    while len(deviceCommandDelegator._command_list) > 0:
        print_msg('命令队列残留: %s' % len(deviceCommandDelegator._command_list))
        time.sleep(1)
    print_msg('命令队列残留: %s' % len(deviceCommandDelegator._command_list))
    print_msg('Finished...')
Esempio n. 11
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))