Exemplo n.º 1
0
def test_make_clean():
  fs.cd("lib/labm8/data/test/makeproj")
  make.make()
  assert fs.isfile("foo")
  assert fs.isfile("foo.o")
  make.clean()
  assert not fs.isfile("foo")
  assert not fs.isfile("foo.o")
  fs.cdpop()
Exemplo n.º 2
0
def test_rm():
    system.echo("Hello, world!", "/tmp/labm8.tmp")
    assert fs.isfile("/tmp/labm8.tmp")
    fs.rm("/tmp/labm8.tmp")
    assert not fs.isfile("/tmp/labm8.tmp")
    fs.rm("/tmp/labm8.tmp")
    fs.rm("/tmp/labm8.tmp")
    fs.rm("/tmp/labm8.dir")
    fs.mkdir("/tmp/labm8.dir/foo/bar")
    system.echo("Hello, world!", "/tmp/labm8.dir/foo/bar/baz")
    assert fs.isfile("/tmp/labm8.dir/foo/bar/baz")
    fs.rm("/tmp/labm8.dir")
    assert not fs.isfile("/tmp/labm8.dir/foo/bar/baz")
    assert not fs.isfile("/tmp/labm8.dir/")
Exemplo n.º 3
0
def test_rmtrash():
    with tempfile.NamedTemporaryFile(prefix='labm8_') as f:
        assert fs.isfile(f.name)
        fs.rmtrash(f.name)
        assert not fs.isfile(f.name)
        fs.rmtrash(f.name)
        fs.rm(f.name)
    with tempfile.TemporaryDirectory() as d:
        fs.rm(d)
        fs.mkdir(d, "foo/bar")
        system.echo("Hello, world!", fs.path(d, "foo/bar/baz"))
        assert fs.isfile(f, "foo/bar/baz")
        fs.rmtrash(d)
        assert not fs.isfile(d, "foo/bar/baz")
        assert not fs.isdir(d)
Exemplo n.º 4
0
def test_cp_over_dir():
    fs.mkdir("/tmp/labm8.tmp.src")
    system.echo("Hello, world!", "/tmp/labm8.tmp.src/foo")
    fs.rm("/tmp/labm8.tmp.copy")
    fs.mkdir("/tmp/labm8.tmp.copy")
    assert fs.isdir("/tmp/labm8.tmp.src")
    assert fs.isfile("/tmp/labm8.tmp.src/foo")
    assert fs.isdir("/tmp/labm8.tmp.copy")
    assert not fs.isfile("/tmp/labm8.tmp.copy/foo")
    fs.cp("/tmp/labm8.tmp.src", "/tmp/labm8.tmp.copy/")
    assert fs.isdir("/tmp/labm8.tmp.src")
    assert fs.isfile("/tmp/labm8.tmp.src/foo")
    assert fs.isdir("/tmp/labm8.tmp.copy")
    assert fs.isfile("/tmp/labm8.tmp.copy/foo")
    assert (fs.read("/tmp/labm8.tmp.src/foo") == fs.read(
        "/tmp/labm8.tmp.copy/foo"))
Exemplo n.º 5
0
def test_set_and_get():
    fs.rm("/tmp/labm8-cache-set-and-get")
    c = cache.FSCache("/tmp/labm8-cache-set-and-get")
    # create file
    system.echo("Hello, world!", "/tmp/labm8.testfile.txt")
    # sanity check
    assert fs.read("/tmp/labm8.testfile.txt") == ["Hello, world!"]
    # insert file into cache
    c['foobar'] = "/tmp/labm8.testfile.txt"
    # file must be in cache
    assert fs.isfile(c.keypath("foobar"))
    # file must have been moved
    assert not fs.isfile("/tmp/labm8.testfile.txt")
    # check file contents
    assert fs.read(c['foobar']) == ["Hello, world!"]
    assert fs.read(c['foobar']) == fs.read(c.get('foobar'))
    c.clear()
Exemplo n.º 6
0
Arquivo: llvm.py Projeto: BeauJoh/phd
def assert_program_exists(path):
    """
  Assert that a program exists.

  If the given path does not exist and is not a file, raises
  ProgramNotFoundError.
  """
    if not fs.exists(path) or not fs.isfile(path):
        raise ProgramNotFoundError(path)
Exemplo n.º 7
0
def get_all_sampler_datasets():
    datasets = []
    sampledirs = []
    for versioncache in fs.ls(fs.path("~/.cache/clgen"), abspaths=True):
        samplerdir = fs.path(versioncache, "sampler")
        if fs.isdir(samplerdir):
            sampledirs += fs.ls(samplerdir, abspaths=True)

    for samplerdir in sampledirs:
        inpath = fs.path(samplerdir, "kernels.db")
        if fs.isfile(inpath):
            datasets.append(inpath)
    return datasets
Exemplo n.º 8
0
def test_rm_glob():
    fs.mkdir("/tmp/labm8.glob")
    system.echo("Hello, world!", "/tmp/labm8.glob/1")
    system.echo("Hello, world!", "/tmp/labm8.glob/2")
    system.echo("Hello, world!", "/tmp/labm8.glob/abc")

    fs.rm("/tmp/labm8.glob/a*", glob=False)
    assert fs.isfile("/tmp/labm8.glob/1")
    assert fs.isfile("/tmp/labm8.glob/2")
    assert fs.isfile("/tmp/labm8.glob/abc")

    fs.rm("/tmp/labm8.glob/a*")
    assert fs.isfile("/tmp/labm8.glob/1")
    assert fs.isfile("/tmp/labm8.glob/2")
    assert not fs.isfile("/tmp/labm8.glob/abc")

    fs.rm("/tmp/labm8.glob/*")
    assert not fs.isfile("/tmp/labm8.glob/1")
    assert not fs.isfile("/tmp/labm8.glob/2")
    assert not fs.isfile("/tmp/labm8.glob/abc")
Exemplo n.º 9
0
Arquivo: make.py Projeto: BeauJoh/phd
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
Exemplo n.º 10
0
def merge(outpath, inpaths=[]):
    if not fs.isfile(outpath):
        dbutil.create_db(outpath)
        log.info("created", outpath)

    db = dbutil.connect(outpath)

    if not inpaths:
        inpaths = get_all_sampler_datasets()

    for inpath in inpaths:
        log.info("merging from", inpath)
        c = db.cursor()
        c.execute("ATTACH '{}' AS rhs".format(inpath))
        c.execute("INSERT OR IGNORE INTO ContentFiles "
                  "SELECT * FROM rhs.ContentFiles")
        c.execute("INSERT OR IGNORE INTO PreprocessedFiles "
                  "SELECT * FROM rhs.PreprocessedFiles")
        c.execute("DETACH rhs")
        db.commit()

    explore.explore(outpath)
Exemplo n.º 11
0
#!/usr/bin/env python3.6

import sys
from phd.lib.labm8 import crypto
from phd.lib.labm8 import fs
from progressbar import ProgressBar


if __name__ == "__main__":
  inpath = sys.argv[1]
  outdir = sys.argv[2]
  print(f"reading from {inpath} into {outdir}")

  assert fs.isfile(inpath)
  assert not fs.exists(outdir) or fs.isdir(outdir)
  fs.mkdir(outdir)

  with open(inpath) as infile:
    text = infile.read()

  kernels = text.split("// ==== START SAMPLE ====")
  kernels = [kernel.strip() for kernel in kernels if kernel.strip()]
  print(len(kernels), "kernels")

  sha1s = [crypto.sha1_str(kernel) for kernel in kernels]
  for kernel, sha1 in ProgressBar()(list(zip(kernels, sha1s))):
    with open(f"{outdir}/{sha1}.txt", "w") as outfile:
      print(kernel, file=outfile)
Exemplo n.º 12
0
def test_make():
  ret, out, err = make.make(dir="lib/labm8/data/test/makeproj")
  assert not ret
  assert out
  assert fs.isfile("lib/labm8/data/test/makeproj/foo")
  assert fs.isfile("lib/labm8/data/test/makeproj/foo.o")
Exemplo n.º 13
0
def test_isfile():
    assert fs.isfile(__file__)
    assert not fs.isfile("/")
    assert not fs.isfile("/not/a/real/path (I hope!)")
Exemplo n.º 14
0
def load_config(path="~/.omnitunerc.json"):
  path = fs.abspath(path)
  if fs.isfile(path):
    return json.load(open(path))
  else:
    raise ConfigNotFoundError("File '{}' not found!".format(path))
Exemplo n.º 15
0
def IsRepoMetaFile(f: str):
    """Determine if a path is a GitHubRepoMetadata message."""
    return (fs.isfile(f) and pbutil.ProtoIsReadable(
        f, scrape_repos_pb2.GitHubRepoMetadata()))
Exemplo n.º 16
0
    parser.add_argument("--clsmith",
                        action="store_true",
                        help="Only reduce CLSmith results")
    parser.add_argument("--clgen",
                        action="store_true",
                        help="Only reduce CLgen results")
    parser.add_argument("--recheck",
                        action="store_true",
                        help="Re-check existing errors")
    args = parser.parse_args()

    db.init(args.hostname)  # initialize db engine

    clang = fs.abspath(f"../lib/llvm/build/{args.clang}/bin/clang")

    if not args.recheck and not fs.isfile(clang):
        print(f"fatal: clang '{clang}' does not exist")
        sys.exit(1)

    if args.clgen and args.clsmith:
        tablesets = [CLSMITH_TABLES, CLGEN_TABLES]
    elif args.clsmith:
        tablesets = [CLSMITH_TABLES]
    elif args.clgen:
        tablesets = [CLGEN_TABLES]
    else:
        tablesets = [CLSMITH_TABLES, CLGEN_TABLES]

    with Session(commit=True) as s:

        def next_batch():
Exemplo n.º 17
0
from experimental.dsmith import Colors

runtime_t = NewType('runtime_t', float)
status_t = NewType('status_t', int)
return_t = namedtuple('return_t', ['runtime', 'status', 'stdout', 'stderr'])

# build paths
exec_path = dsmith.root_path("third_party", "clsmith", "build", "CLSmith")
cl_launcher_path = dsmith.root_path("third_party", "clsmith", "build",
                                    "cl_launcher")
include_path = dsmith.root_path("third_party", "clsmith", "runtime")

# sanity checks
assert fs.isexe(exec_path)
assert fs.isexe(cl_launcher_path)
assert fs.isfile(fs.path(include_path, "CLSmith.h"))


def clsmith_cli(*args, timeout: int = 60, exec_path=exec_path) -> List[str]:
    return ["timeout", "--signal=9", str(timeout), exec_path] + list(args)


def clsmith(*args, exec_path=exec_path) -> return_t:
    """
      Returns:
          return_t: A named tuple consisting of runtime (float),
              status (int), stdout (str), and stderr (str).
  """
    start_time = time()

    cli = clsmith_cli(*args)