Exemplo n.º 1
0
 def _adb_cmd(adb_command,
              output_file=None,
              append_file=False,
              output_string=False):
     """Run an adb command and return result."""
     cmd = runcommand.RunCommand("adb {}".format(adb_command), output_file,
                                 append_file)
     if output_string:
         return cmd.execute_with_output()
     return cmd.execute_save_output()
Exemplo n.º 2
0
 def systrace_start(self, output_file=None):
     """Start the systrace.py script to collect CPU usage."""
     self._tempfile = tempfile.NamedTemporaryFile(delete=False).name
     self._cmd = runcommand.RunCommand(output_file=self._tempfile,
                                       propagate_signals=False)
     self._cmd.add_file(sys.executable)
     self._cmd.add_file(self.systrace_script)
     self._cmd.add("--json")
     self._cmd.add("-o")
     self._cmd.add_file(output_file)
     self._cmd.add("dalvik sched freq idle load")
     self._cmd.start_process()
Exemplo n.º 3
0
def parse_evergreen_file(path, evergreen_binary="evergreen"):
    """Read an Evergreen file and return EvergreenProjectConfig instance."""
    if evergreen_binary:
        if not distutils.spawn.find_executable(evergreen_binary):
            raise EnvironmentError(
                "Executable '{}' does not exist or is not in the PATH.".format(evergreen_binary))

        # Call 'evergreen evaluate path' to pre-process the project configuration file.
        cmd = runcommand.RunCommand(evergreen_binary)
        cmd.add("evaluate")
        cmd.add_file(path)
        error_code, output = cmd.execute()
        if error_code:
            raise RuntimeError("Unable to evaluate {}: {}".format(path, output))
        config = yaml.load(output)
    else:
        with open(path, "r") as fstream:
            config = yaml.load(fstream)

    return EvergreenProjectConfig(config)
Exemplo n.º 4
0
    def shell(adb_shell_command):
        """Run an adb shell command and return output_string.

        Raise an exception if the exit status is non-zero.

        Since the adb shell command does not return an exit status. We simulate it by
        saving the exit code in the output and then stripping if off.

        See https://stackoverflow.com/questions/9379400/adb-error-codes
        """
        cmd_prefix = "set -o errexit; function _exit_ { echo __EXIT__:$?; } ; trap _exit_ EXIT ;"
        cmd = runcommand.RunCommand("adb shell {} {}".format(
            cmd_prefix, adb_shell_command))
        cmd_output = cmd.execute_with_output()
        if "__EXIT__" in cmd_output:
            exit_code = int(cmd_output.split()[-1].split(":")[1])
            cmd_output_stripped = re.split("__EXIT__.*\n", cmd_output)[0]
            if exit_code:
                raise RuntimeError("{}: {}".format(exit_code,
                                                   cmd_output_stripped))
            return cmd_output_stripped
        return cmd_output