def IsServerOnline(cls): status, output = cmd_helper.GetCmdStatusAndOutput(['pgrep', 'adb']) output = [int(x) for x in output.split()] logger.info('PIDs for adb found: %r', output) return status == 0
def testGetCmdStatusAndOutput_unicode(self): # pylint: disable=no-self-use cmd = 'echo "\x80\x31Hello World\n"' cmd_helper.GetCmdStatusAndOutput(cmd, shell=True)
def Map(port_pairs, device, tool=None): """Runs the forwarder. Args: port_pairs: A list of tuples (device_port, host_port) to forward. Note that you can specify 0 as a device_port, in which case a port will by dynamically assigned on the device. You can get the number of the assigned port using the DevicePortForHostPort method. device: A DeviceUtils instance. tool: Tool class to use to get wrapper, if necessary, for executing the forwarder (see valgrind_tools.py). Raises: Exception on failure to forward the port. """ if not tool: tool = base_tool.BaseTool() with _FileLock(Forwarder._LOCK_PATH): instance = Forwarder._GetInstanceLocked(tool) instance._InitDeviceLocked(device, tool) device_serial = str(device) redirection_commands = [[ '--adb=' + devil_env.config.FetchPath('adb'), '--serial-id=' + device_serial, '--map', str(device_port), str(host_port) ] for device_port, host_port in port_pairs] logging.info('Forwarding using commands: %s', redirection_commands) for redirection_command in redirection_commands: try: (exit_code, output) = cmd_helper.GetCmdStatusAndOutput( [instance._host_forwarder_path] + redirection_command) except OSError as e: if e.errno == 2: raise HostForwarderError( 'Unable to start host forwarder. ' 'Make sure you have built host_forwarder.') else: raise if exit_code != 0: try: Forwarder._KillDeviceLocked(device, tool) except device_errors.CommandFailedError: # We don't want the failure to kill the device forwarder to # supersede the original failure to map. pass _LogMapFailureDiagnostics(device) raise HostForwarderError('%s exited with %d:\n%s' % (instance._host_forwarder_path, exit_code, '\n'.join(output))) tokens = output.split(':') if len(tokens) != 2: raise HostForwarderError( 'Unexpected host forwarder output "%s", ' 'expected "device_port:host_port"' % output) device_port = int(tokens[0]) host_port = int(tokens[1]) serial_with_port = (device_serial, device_port) instance._device_to_host_port_map[serial_with_port] = host_port instance._host_to_device_port_map[host_port] = serial_with_port logging.info('Forwarding device port: %d to host port: %d.', device_port, host_port)
def testGetCmdStatusAndOutput_success(self): cmd = 'echo "Hello World"' status, output = cmd_helper.GetCmdStatusAndOutput(cmd, shell=True) self.assertEqual(status, 0) self.assertEqual(output.rstrip(), "Hello World")