def run(self): logging.info('Start running the thread!') self.wait_event.clear() self._GenerateCommandLineArguments() command = constants.DIR_SOURCE_ROOT if self.arguments['server-type'] == 'sync': command = [ os.path.join(command, 'sync', 'tools', 'testserver', 'sync_testserver.py') ] + self.command_line else: command = [ os.path.join(command, 'net', 'tools', 'testserver', 'testserver.py') ] + self.command_line logging.info('Running: %s', command) # Disable PYTHONUNBUFFERED because it has a bad interaction with the # testserver. Remove once this interaction is fixed. unbuf = os.environ.pop('PYTHONUNBUFFERED', None) # Pass DIR_SOURCE_ROOT as the child's working directory so that relative # paths in the arguments are resolved correctly. self.process = subprocess.Popen( command, preexec_fn=self._CloseUnnecessaryFDsForTestServerProcess, cwd=constants.DIR_SOURCE_ROOT) if unbuf: os.environ['PYTHONUNBUFFERED'] = unbuf if self.process: if self.pipe_out: self.is_ready = self._WaitToStartAndGetPortFromTestServer() else: self.is_ready = _CheckPortNotAvailable(self.host_port) if self.is_ready: Forwarder.Map([(0, self.host_port)], self.device, self.tool) # Check whether the forwarder is ready on the device. self.is_ready = False device_port = Forwarder.DevicePortForHostPort(self.host_port) if device_port and _CheckDevicePortStatus(self.device, device_port): self.is_ready = True self.forwarder_device_port = device_port # Wake up the request handler thread. self.ready_event.set() # Keep thread running until Stop() gets called. _WaitUntil(lambda: self.stop_flag, max_attempts=sys.maxint) if self.process.poll() is None: self.process.kill() Forwarder.UnmapDevicePort(self.forwarder_device_port, self.device) self.process = None self.is_ready = False if self.pipe_out: os.close(self.pipe_in) os.close(self.pipe_out) self.pipe_in = None self.pipe_out = None logging.info('Test-server has died.') self.wait_event.set()
def run(self): logging.info('Start running the thread!') self.wait_event.clear() self._GenerateCommandLineArguments() command = constants.DIR_SOURCE_ROOT if self.arguments['server-type'] == 'sync': command = [ os.path.join(command, 'sync', 'tools', 'testserver', 'sync_testserver.py') ] + self.command_line else: command = [ os.path.join(command, 'net', 'tools', 'testserver', 'testserver.py') ] + self.command_line logging.info('Running: %s', command) self.process = subprocess.Popen( command, preexec_fn=self._CloseUnnecessaryFDsForTestServerProcess) if self.process: if self.pipe_out: self.is_ready = self._WaitToStartAndGetPortFromTestServer() else: self.is_ready = _CheckPortStatus(self.host_port, True) if self.is_ready: Forwarder.Map([(0, self.host_port)], self.adb, self.build_type, self.tool) # Check whether the forwarder is ready on the device. self.is_ready = False device_port = Forwarder.DevicePortForHostPort(self.host_port) if device_port and _CheckDevicePortStatus(self.adb, device_port): self.is_ready = True self.forwarder_device_port = device_port # Wake up the request handler thread. self.ready_event.set() # Keep thread running until Stop() gets called. _WaitUntil(lambda: self.stop_flag, max_attempts=sys.maxint) if self.process.poll() is None: self.process.kill() Forwarder.UnmapDevicePort(self.forwarder_device_port, self.adb) self.process = None self.is_ready = False if self.pipe_out: os.close(self.pipe_in) os.close(self.pipe_out) self.pipe_in = None self.pipe_out = None logging.info('Test-server has died.') self.wait_event.set()
def _ForwardPorts(self, port_pairs): """Forwards a port.""" Forwarder.Map(port_pairs, self.adb, self.build_type, self.tool)
def _ForwardPorts(self, port_pairs): """Forwards a port.""" Forwarder.Map(port_pairs, self.device, self.tool)