コード例 #1
0
ファイル: ins.py プロジェクト: sungj521/QT4i
 def release(self, timeout=CommandTimeout):
     '''释放某个设备的instrument
     
     :param timeout: 等待超时 (秒)
     :type timeout: int
     :returns : boolean -- True if release successfully, False if not
     '''
     _begin_time = time.time()
     if self.is_working():
         self.device_command_delegator.clean_all(self.udid,
                                                 "InstrumentsRelease")
         self.device_command_delegator.send_command(
             self.udid, {"method": "release"},
             timeout - (time.time() - _begin_time))
         if not self.wait_for_stop(timeout - (time.time() - _begin_time)):
             Process().kill_child_processes_by_ppid(
                 self.TasksPID.get(self.udid))
         if self.is_working():
             Process().kill_process_by_name("_fetch_cmd_delegate.py")
             Process().kill_process_by_name("instruments.py")
             os.system('killall -9 "instruments" "Instruments"')
             self.TasksBoostrapStandBy.pop(self.udid, None)
             self.instances.pop(self.udid)
     time.sleep(3)
     return self.is_working() == False
コード例 #2
0
    def start(self, is_daemon=True):
        '''启动driver
        '''
        # Check for a pidfile to see if the daemon already runs
        pid = self.get_pid()

        if pid:
            process = Process().get_process_by_pid(pid, 'driverserver.py')
            if process:
                args = process['CMD'].split(' ')
                if len(args) > 3:
                    args = main_parser.parse_args(args[2:])
                    logger.info('Driverserver info:%s' % args)
                    if int(args.agent_port) == self._agent_port and int(
                            args.port) == self._driver_port:
                        return
                Process().kill_process_by_pid(pid)
                logger.warning('Kill old driver server process %d' % pid)
                logger.warning('old_params: driver_port: %d, agent_port: %d' %
                               (int(args.port), int(args.agent_port)))
                logger.warning('new_params: driver_port: %d, agent_port: %d' %
                               (self._driver_port, self._agent_port))
            else:
                os.remove(self.pidfile)

        # Start the daemon
        if is_daemon:
            self.daemonize()
        self.run()
コード例 #3
0
    def start(self, is_daemon=True):
        '''启动service
        '''
        pid = self.get_pid()
        if pid:
            process = Process().get_process_by_pid(pid, 'screencapture.py')
            if process:
                Process().kill_process_by_pid(pid)
                logger.warning('Kill old screencapure server process %d' % pid)
            else:
                os.remove(self.pidfile)

        # start damon
        if is_daemon:
            self.daemonize()
        self.run()
コード例 #4
0
 def exist(self):
     '''driverserver进程是否存在
     '''
     pid = self.get_pid()
     if pid:
         if Process().get_process_by_pid(pid, 'driverserver.py'):
             return True
     return False
コード例 #5
0
    def start(self, is_daemon=True):
        """
        Start the daemon
        """
        # Check for a pidfile to see if the daemon already runs
        pid = self.get_pid()

        if pid:
            if Process().get_process_by_pid(pid, 'driverserver.py'):
                message = "pidfile %s already exist. Daemon already running?\n"
                logger.warning(message % self.pidfile)
                return
            else:
                os.remove(self.pidfile)

        # Start the daemon
        if is_daemon:
            self.daemonize()
        self.run()
コード例 #6
0
ファイル: ins.py プロジェクト: sungj521/QT4i
    def notify(self, json_data):
        '''notify
        
        :param json_data: 要通知的内容
        :type json_data: Json
        '''
        dict_data = Json().loads(json_data)
        method = dict_data["method"]
        params = dict_data["params"]
        device_udid = params[0]["environment"]["device_udid"]
        instruments_pid = params[0]["pid"]

        if method == "InstrumentsStarted":
            self.log.info(method)
        if method in [
                'TraceTemplateInvalid', 'TargetAppBundleIDInvalid',
                'DeviceIsCurrentlyLockedWithAPasscode',
                'TheAppMustBeSignedWithADevelopmentIdentity',
                'TargetAppIsNotFrontmost', 'TargetAppDied', 'DeviceDisabled',
                'InstrumentsError', 'InstrumentsTimeout'
        ]:
            if method == "TargetAppDied":
                self.crash_flag = True
            self.device_command_delegator.clean_all(device_udid, method)
            self.TasksLastError.update({device_udid: method})
            self.dispatch_stopped_events()
            Process().kill_process_tree_by_pid(instruments_pid)
            self.log.error(method)

        if method == "InstrumentsTerminated":
            self.device_command_delegator.clean_all(device_udid, method)
            self.TasksEnvironment.pop(device_udid, None)
            self.TasksBoostrapStandBy.pop(device_udid, None)
            self.TasksPID.pop(device_udid, None)
            self.LastExecCommandDeviceUdid = None
            self.dispatch_stopped_events()
            self.log.info(method)
コード例 #7
0
    def start(self, retry=1, timeout=CommandTimeout):
        '''启动Agent,类初始化即调用
        
        :param retry: 启动尝试次数
        :type retry: int
        :param timeout: 单次启动超时 (秒)
        :type timeout: int
        '''
        if self.type == EnumDevice.Simulator:
            dt.DT().reboot(self.udid)
            xcode_version = dt.DT.get_xcode_version()
            if dt.DT.compare_xcode_version("9.0") >= 0:
                self._agent_cmd = self._get_xcodebuild_agent_cmd_for_simulator(
                    xcode_version)
            else:
                self._agent_cmd = self._get_fbsimctl_agent_cmd_for_simulator(
                    xcode_version)
        else:
            self._agent_cmd = ' '.join([
                'xcodebuild',
                '-project %s' % self.XCTestAgentPath,
                '-scheme %s' % 'XCTestAgent',
                '-destination "platform=%s,id=%s"' % (self.type, self.udid),
                'test'
            ])
        # 清理遗留的xcodebuild进程
        Process().kill_process_by_name(self._agent_cmd.replace('"', ''))
        Process().kill_process_by_port(self._server_port)
        start_time = time.time()
        # 启动端口转发线程
        self._tcp_relay()
        for _ in range(retry):
            self.log.info("Start XCTestAgent: %s" % self._agent_cmd)
            self.log.info("XCTestAgent Version: %s" % self.version)
            self._process = ThreadTask(
                command=self._agent_cmd,
                stdout_line_callback=self._stdout_line_callback,
                stderr_line_callback=self._stderr_line_callback)

            time0 = time.time()
            while time.time() - time0 < timeout:
                if self.is_working():
                    exec_time = (time.time() - start_time) * 1000
                    self.log.info('[ %s ] consumed [ %dms ]' %
                                  ('Start XCTestAgent', exec_time))
                    return
                time.sleep(3)

            _dt = dt.DT()
            self.log.info("Uninstall com.apple.test.XCTestAgent-Runner")
            result = _dt.uninstall("com.apple.test.XCTestAgent-Runner",
                                   self.udid)
            if not result:
                self.log.error(_dt.uninstall_error)

        self.stop()
        error_log_name = 'xctest_%s' % self.udid
        agent_error_log = logger.get_agent_error_log(error_log_name,
                                                     start_time)
        raise AgentStartError("Failed to start XCTestAgent.\nDetails:%s" %
                              agent_error_log)
コード例 #8
0
ファイル: ins.py プロジェクト: sungj521/QT4i
 def start(self,
           bundle_id,
           app_params,
           env,
           xmlrpc_uri,
           trace_template=None,
           trace_output=None,
           retry=3,
           timeout=55):
     '''用指定设备启动指定APP在后台运行
     
     :param bundle_id: 要启动的APP的Bundle ID
     :type bundle_id: str
     :param app_params: APP 使用的参数
     :type app_params: dict
     :param env: 任务设备的环境
     :type env: dict
     :param trace_template: 专项测试使用trace_template的路径
     :type trace_template: str
     :param trace_output: 专项测试使用trace_output
     :type trace_output: str
     :param retry: 启动失败重试次数
     :type retry: int
     :param timeout: 单次启动超时 (秒)
     :type timeout: int
     :returns : boolean -- True if start successfully, False if not
     '''
     if timeout < 10:
         raise Exception("timeout must be longer than 10 seconds")
     if self.is_working():
         self.release()
     if env == None:
         env = {}
     self.TasksEnvironment.update({self.udid: env})
     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 range(retry):
         self.log.info("ins start app retry %d of %d times" %
                       (i + 1, retry))
         ins_py_cmd = ' '.join([
             self.PythonPath,
             '"%s"' % self.InstrumentDriverPath,
             '-device_udid "%s"' % self.udid,
             '-device_simulator %s' % False,
             '-bundle_id "%s"' % bundle_id,
             '-params "%s"' % params if params else '',
             '-trace_template "%s"' % trace_template,
             '-trace_output "%s"' % trace_output,
             '-xmlrpc_uri "%s"' % xmlrpc_uri,
             '-timeout %s' % (20 * 60),
             '-cmd_fetch_delegate_timeout %s' % 10,
             '-environment "%s"' % urllib.quote("%s" % env)
         ])
         self.log.info(ins_py_cmd)
         task = ThreadTask(ins_py_cmd,
                           stdout_line_callback=self.log.info,
                           stderr_line_callback=self.log.error)
         if self.wait_for_start(timeout):
             self.TasksPID.update({self.udid: task.pid})
             self.log.info("ins start app successfully")
             return True
         Process().kill_child_processes_by_ppid(task.pid)
         time.sleep(3)
     error = self.TasksLastError.pop(self.udid, None)
     if error:
         raise Exception("[InstrumentsManager] %s" % error)
     return False
コード例 #9
0
ファイル: instruments.py プロジェクト: sungj521/QT4i
 def __timeout_kill_instruments__(self):
     self.instruments.stop()
     Process().kill_child_processes_by_ppid(os.getpid())
     self.__notify__('InstrumentsTimeout')