Пример #1
0
    def sample(self):
        """
        Collect a sample.

        Returns the program output as a string and the returncode as
        an integer.
        """
        output, returncode = system.run("./SimpleBig")
        return {"output": output, "returncode": returncode}
Пример #2
0
    def sample(self):
        """
        Collect a sample.

        Execute the program and graph the runtime from the stdout.
        """
        _, output, _ = system.run(["./examples/example1"])
        match = re.search(self.TIME_RE, output)
        if match:
            return {"Runtime": float(match.group(1))}
Пример #3
0
def make(target="all", dir=".", **kwargs):
    """
    Run make clean.

    Arguments:

        target (str, optional): Name of the target to build. Defaults
          to "all".
        dir (str, optional): Path to directory containing Makefile.
        **kwargs (optional): Any additional arguments to be passed to
          system.run().

    Returns:

        (int, str, str): The first element is the return code of the
          make command. The second and third elements are the stdout
          and stderr of the process.

    Raises:

        NoMakefileError: In case a Makefile is not found in the target
          directory.
        NoTargetError: In case the Makefile does not support the
          requested target.
        MakeError: In case the target rule fails.
    """
    if not fs.isfile(fs.path(dir, "Makefile")):
        raise NoMakefileError("No makefile in '{}'".format(fs.abspath(dir)))

    fs.cd(dir)

    # Default parameters to system.run()
    if "timeout" not in kwargs: kwargs["timeout"] = 300

    ret, out, err = system.run(["make", target], **kwargs)
    fs.cdpop()

    if ret > 0:
        if re.search(_BAD_TARGET_RE, err):
            raise NoTargetError("No rule for target '{}'"
                                .format(target))
        else:
            raise MakeError("Target '{}' failed".format(target))

        raise MakeError("Failed")

    return ret, out, err
Пример #4
0
def make(target="all", dir=".", **kwargs):
    """
  Run make.

  Arguments:

      target (str, optional): Name of the target to build. Defaults
        to "all".
      dir (str, optional): Path to directory containing Makefile.
      **kwargs (optional): Any additional arguments to be passed to
        system.run().

  Returns:

      (int, str, str): The first element is the return code of the
        make command. The second and third elements are the stdout
        and stderr of the process.

  Raises:

      NoMakefileError: In case a Makefile is not found in the target
        directory.
      NoTargetError: In case the Makefile does not support the
        requested target.
      MakeError: In case the target rule fails.
  """
    if not fs.isfile(fs.path(dir, "Makefile")):
        raise NoMakefileError("No makefile in '{}'".format(fs.abspath(dir)))

    fs.cd(dir)

    # Default parameters to system.run()
    if "timeout" not in kwargs: kwargs["timeout"] = 300

    ret, out, err = system.run(["make", target], **kwargs)
    fs.cdpop()

    if ret > 0:
        if re.search(_BAD_TARGET_RE, err):
            raise NoTargetError("No rule for target '{}'".format(target))
        else:
            raise MakeError("Target '{}' failed".format(target))

        raise MakeError("Failed")

    return ret, out, err
Пример #5
0
def run_example_prog(prog, args):
    """
    Run a SkelCL example program.

    Arguments:

        prog (str): The name of the program to run
        args (list of str): Any arguments
    """
    fs.cd(fs.path(experiment.EXAMPLES_BUILD, prog))
    cmd = ["./" + prog] + args
    cmd_str = " ".join(cmd)
    io.info("COMMAND:", io.colourise(io.Colours.RED, cmd_str))
    ret, _, _ = system.run(cmd, stdout=system.STDOUT, stderr=system.STDERR)
    if ret:
        system.echo(cmd_str, "/tmp/naughty.txt", append=True)

    return ret
Пример #6
0
def run_job(i, n, wgsize, program, args):
    wg_c, wg_r = unhash_params(wgsize)

    # Set environment variable.
    os.environ["OMNITUNE_OFFLINE_TRAINING"] = "1"
    os.environ["OMNITUNE_STENCIL_WG_C"] = str(wg_c)
    os.environ["OMNITUNE_STENCIL_WG_R"] = str(wg_r)

    fs.cd(fs.path(experiment.EXAMPLES_BUILD, program))

    cmd_str = "./{} {}".format(program, args.rstrip())
    cmd = cmd_str.split()

    io.info(i, "of", n, " - ", wgsize, "COMMAND:", io.colourise(io.Colours.RED, cmd_str))
    ret, _, _ = system.run(cmd, stdout=system.STDOUT, stderr=system.STDERR)

    if ret:
        print(ret, wgsize, program, args, sep="\t", file=errlog)
    else:
        print(ret, wgsize, program, args, sep="\t", file=runlog)
Пример #7
0
 def test_run(self):
     self._test((0, None, None), system.run(["true"]))
     self._test((1, None, None), system.run(["false"]))
Пример #8
0
def test_run_timeout():
  with pytest.raises(system.SubprocessError):
    system.run(["sleep 10"], timeout=.1, shell=True)
  with pytest.raises(system.SubprocessError):
    system.run(["sleep 10"], timeout=.1, num_retries=2, shell=True)
Пример #9
0
def test_run():
  assert system.run(["true"]) == (0, None, None)
  assert system.run(["false"]) == (1, None, None)