def process_run_result(self, result, context): raise WAError()
def adb_shell(device, command, timeout=None, check_exit_code=False, as_root=False): # NOQA # pylint: disable=too-many-branches, too-many-locals, too-many-statements _check_env() if as_root: command = 'echo \'{}\' | su'.format(escape_single_quotes(command)) device_part = ['-s', device] if device else [] device_string = ' {} {}'.format(*device_part) if device_part else '' full_command = 'adb{} shell "{}"'.format(device_string, escape_double_quotes(command)) logger.debug(full_command) if check_exit_code: adb_shell_command = '({}); echo \"\n$?\"'.format(command) actual_command = ['adb'] + device_part + ['shell', adb_shell_command] try: raw_output, error = check_output(actual_command, timeout, shell=False) except CalledProcessErrorWithStderr as e: raw_output = e.output error = e.error exit_code = e.returncode if exit_code == 1: logger.debug( "Exit code 1 could be either the return code of the command or mean ADB failed" ) if raw_output: if raw_output.endswith('\r\n'): newline = '\r\n' elif raw_output.endswith('\n'): newline = '\n' else: raise WAError( "Unknown new line separator in: {}".format(raw_output)) try: output, exit_code, _ = raw_output.rsplit(newline, 2) except ValueError: exit_code, _ = raw_output.rsplit(newline, 1) output = '' else: # raw_output is empty exit_code = '969696' # just because output = '' exit_code = exit_code.strip() if exit_code.isdigit(): if int(exit_code): message = 'Got exit code {}\nfrom: {}\nSTDOUT: {}\nSTDERR: {}'.format( exit_code, full_command, output, error) raise DeviceError(message) elif am_start_error.findall(output): message = 'Could not start activity; got the following:' message += '\n{}'.format(am_start_error.findall(output)[0]) raise DeviceError(message) else: # not all digits if am_start_error.findall(output): message = 'Could not start activity; got the following:' message += '\n{}'.format(am_start_error.findall(output)[0]) raise DeviceError(message) else: message = 'adb has returned early; did not get an exit code. '\ 'Was kill-server invoked?\nOUTPUT:\n-----\n{}\n'\ '-----ERROR:\n-----\n{}\n-----' raise DeviceError(message.format(raw_output, error)) else: # do not check exit code try: output, error = check_output(full_command, timeout, shell=True) if output is None: output = error elif error is not None: output = '\n'.join([output, error]) except CalledProcessErrorWithStderr as e: output = e.error or e.output exit_code = e.returncode if e.returncode == 1: logger.debug( "Got Exit code 1, could be either the return code of the command or mean ADB failed" ) return output
def process_iteration_result(self, result, context): raise WAError()