示例#1
0
文件: test.py 项目: ralphbean/pbs
    def test_command_wrapper(self):
        from pbs import Command, which

        ls = Command(which("ls"))
        wc = Command(which("wc"))

        c1 = int(wc(ls("-A1"), l=True))
        c2 = len(os.listdir("."))

        self.assertEqual(c1, c2)
示例#2
0
def check_llvm():
    try:
        llvm_path = './llvm/Release+Asserts'
        assert isfile(llvm_path + '/lib/ocaml/llvm.cma')  # is llvm.cma there?
        llvm_config = Command(llvm_path + '/bin/llvm-config')
        ver = llvm_config('--version')  # try calling llvm-config
        print ver
        assert '3.2' in ver
        return True
    except:
        return False
示例#3
0
    def _run_query(self, input_string):
        # Trying to make the buffering process working.
        try:
            self.output = StringIO()
            #def grab_output(line): #hopefully we can get this working in the future...
            #    print line
            #    self.output.write(line.replace('\xfa','.'))
            #self.gnash(_in=input_string, _out=grab_output).wait()
            self.gnash = Command(gnash_path + "Gnash.exe")
            self.gnash(_in=input_string, _out="temp.txt").wait()

        except:
            print "Error, cannot run the query on Gnash"
示例#4
0
文件: core.py 项目: xylix/gitless
import itertools
import json
from locale import getpreferredencoding
import os
import re
import shutil

import pygit2

import sys
if sys.platform != 'win32':
    from sh import git, ErrorReturnCode
else:
    from pbs import Command, ErrorReturnCode
    git = Command('git')

git = git.bake('--no-pager')

ENCODING = getpreferredencoding() or 'utf-8'

# Errors


class GlError(Exception):
    pass


class NotInRepoError(GlError):
    pass
示例#5
0
def test_cpp(name):
    
    global failures
    
    # status(name, "Building libHalide.a")
    # Make sure Halide.a is built
    make('-C', '../cpp_bindings/', 'libHalide.a')

    curdir = os.getcwd()

    # Dive in
    os.chdir(name)

    srcfile = "test.cpp"
    logfile = "log.txt"
    errfile = "err.txt"
    
    # Clean up old stuff
    remove("generated.o")
    remove("generated.bc")
    remove("passes.txt")
    remove("a.out")
    remove(logfile)
    remove(errfile)
    
    # Threading these through as file handles shared by all PBS tasks makes
    # sure each task appends to the main logs, and flushes on exception.
    with open(logfile, "wt") as log:
        with open(errfile, "wt") as err:
            # status(name, "Compiling %s" % srcfile)
            compile_cmd = ["-I../../../cpp_bindings",
                           "-Wno-format",
                           "-fPIC",
                           srcfile]
            if platform in ['linux', 'darwin']:
                compile_cmd.append("../../../cpp_bindings/libHalide.a")
            compile_cmd.extend(["-ldl", "-lpthread"])
            if platform is 'linux':
                compile_cmd.append("-rdynamic")

            if os.path.exists("/usr/local/cuda"):
                compile_cmd.extend(["-L/usr/local/cuda/lib", "-lcuda"])
                if platform is 'linux':
                    compile_cmd.append("-L/usr/lib/nvidia-current")
            
            try:
                # Build the test
                # status(name, " ".join(compile_cmd))
                if platform is 'cygwin':
                    objfile = srcfile[:-srcfile[::-1].find('.')] + "o"
                    compile_cmd.append("-c")
                    compile_cmd.append("-o "+objfile)
                    cxx(compile_cmd, _out=log, _err=err)
                    flexlink = Command("flexlink")
                    link_cmd = ["../../../cpp_bindings/libHalide.a",
                                objfile,
                                "-chain cygwin",
                                "-exe",
                                "-lstdc++",
                                "-o a.out",
								"--",
								"-export-all-symbols"] 
                    flexlink(link_cmd, _out=log, _err=err)
                else:
				    cxx(compile_cmd, _out=log, _err=err)
                # Run the test
                # status(name, "Running test")
                tester = Command("./a.out")
                tester(_out=log, _err=err)
                sys.stdout.write(".")
                sys.stdout.flush()
            except:
                sys.stdout.write("E")
                sys.stdout.flush()
                failures.append(name)

    # Pop back up
    os.chdir(curdir)
示例#6
0
def test(name):
    if name.startswith('cpp/'): return test_cpp(name)

    # status(name, 'Building bitcode')

    # Set up filenames
    cfgfile = "%s.json" % name

    bcfile = "%s.bc" % name
    asmfile = "%s.s" % name
    sofile = "%s.so" % name

    outfile = "%s.png" % name
    tmpfile = "%s.tmp" % name
    logfile = "%s.log" % name
    errfile = "%s.err" % name
    timefile = "%s.time" % name

    # Build the ocaml test
    target = '%s/%s.byte' % (name, name)
    cmd = "-no-links %s" % target
    ocamlbuild(cmd.split(' '))
    
    # Dive in
    os.chdir(name)
    
    # Clean up old cruft
    remove(bcfile)
    remove(asmfile)
    remove(sofile)
    remove(outfile)
    remove(logfile)
    remove(errfile)
    remove(timefile)
    
    # Codegen the bitcode
    runner = Command("../_build/%s" % target)
    runner()

    # Compile the plugin
    # status(name, 'Building plugin')
    # Codegen the bitcode
    llc("-O3", "-disable-cfi", bcfile)
    # Load plugin info from generated json
    opts = json.load(open(cfgfile))
    # TODO: move helpstr, num_popped into externs imported straight from the LLVM module?
    assert opts['name'] == name
    opts['classname'] = 'Test'+name.title()
    opts['namestr'] = 'test_'+name
    # Compile the thing
    cmd = [
        "-O3",
        "-Xlinker", "-dylib", "-Xlinker", "-undefined", "-Xlinker", "dynamic_lookup",
        "-DCLASSNAME=%(classname)s" % opts,
        "-DNUM_POPPED=%(num_popped)d" % opts,
        "-DHELPSTR=\"%(helpstr)s\"" % opts,
        "-DNAMESTR=\"%(namestr)s\"" % opts,
        "../test_plugin.cpp",
        asmfile,
        "-I../../ImageStack/src",
        "-o", sofile
    ]
    cxx(cmd)

    # Run the plugin
    # status(name, 'Running plugin')
    cmd = [
        '-plugin', sofile,
    ]
    cmd = cmd + opts['before_run'] + ['-test_%s' % name] + opts['args'] + ['-save', outfile] + ['-save', tmpfile]
    cmd = cmd + opts['validation']
    out = imagestack(cmd, _out=logfile, _err=errfile)

    # Expect result as float in last line of output
    try:
        residual = float(out.splitlines()[-1])
        assert(residual < EPSILON)
        sys.stdout.write(".")
        sys.stdout.flush()
    except:
        print "%s failed!" % name
        if verbose:
            print "Output:\n%s" % out

    # Expect runtime as float (seconds) in some line like "_im_time: %f"
    time = 0.0
    try:
        timestr = "_im_time: "
        times = [l.split(timestr)[-1] for l in out.splitlines() if l.startswith(timestr)]
        time = [float(t) for t in times][0]
        with open(timefile, "w") as f:
            f.write("%f" % time)
    except:
       print "Failed to get time!"

    # Pop out
    os.chdir("..")
示例#7
0
# TODO: make pch: `g++ -x c++-header -I ../ImageStack/src test_plugin.h`
EPSILON = 0.001

verbose = False

def status(name, s):
    print '%s: %s' % (name, s)

def remove(filename):
    try: os.remove(filename)
    except: pass

proj_root = os.path.join('..', '..')
llvm_path = os.path.join(proj_root, 'llvm', 'Release+Asserts', 'bin')
llc = Command(os.path.join(llvm_path, 'llc'))
clang = Command(os.path.join(llvm_path, 'clang++'))
imagestack = Command(os.path.join(proj_root, 'ImageStack', 'bin', 'ImageStack'))

cxx = None
gcc_versions = [which('g++')]
for gcc in gcc_versions:
    cxx = Command(gcc)
    try:
        cxx('--version')
    except:
        continue
    break
if not cxx:
    print 'Halide requires g++ to be in the path.'
    sys.exit(-1)
示例#8
0
# Licensed under MIT
"""End-to-end test."""

from __future__ import unicode_literals

import logging
import os
import re
import time

import sys
if sys.platform != 'win32':
    from sh import ErrorReturnCode, gl, git
else:
    from pbs import ErrorReturnCode, Command
    gl = Command('gl')
    git = Command('git')

from gitless.tests import utils

try:
    text = unicode
except NameError:
    text = str


class TestEndToEnd(utils.TestBase):
    def setUp(self):
        super(TestEndToEnd, self).setUp('gl-e2e-test')
        gl.init()
        # Disable colored output so that we don't need to worry about ANSI escape
示例#9
0
        status('Testing for package libc6-dev-i386')
        assert isfile('/usr/include/x86_64-linux-gnu/gnu/stubs-32.h')
        print '...OK!'

        status('Testing for package libsexplib-camlp4-dev')
        assert isdir('/usr/lib/ocaml/sexplib')
        print '...OK!'
    except:
        print 'You appear to be missing some required packages. Try:'
        print 'sudo apt-get install g++ libc6-i386-dev ocaml libsexplib-camlp4-dev'
        sys.exit(1)

if 'darwin' in platform:
    status('Testing for a sufficiently new g++')
    gxx = Command('g++')
    ver = gxx('--version')
    try:
        assert 'g++-4.' in ver
        print '...OK!'
    except:
        print 'Your g++ compiler is missing or too old.'
        print 'Trying installing the command line tools from xcode.'
        print 'They can be found in preferences -> downloads -> command line tools.'
        print 'If that doesn\'t work, update xcode and try again.'
        sys.exit(1)

# Submodule update/init
# TODO: make --recursive optional
status('Checking out submodules')
git('submodule', 'update', '--init', '--recursive')
示例#10
0
print '...OK!'

# Submodule update/init
# TODO: make --recursive optional
status('Checking out submodules')
git('submodule', 'update', '--init', '--recursive')

# TODO: always run make -C llvm, just to make sure it's up to date. Does configure cache its settings when a reconfigure is forced?
# TODO: make install in subdir, with docs
#        requires graphviz, doxygen; target ocamlbuild to alt dir?; make clean?
# Build llvm
if check_llvm():
    status('llvm appears to be present -- skipping')
else:
    chdir('llvm')
    configure = Command('./configure')
    llvm_cfg = ['--enable-assertions', '--enable-optimized']
    if minimal:
        llvm_cfg = llvm_cfg + ['--enable-targets=host,ptx,x86_64,arm']
    else:
        llvm_cfg = llvm_cfg + [
            '--enable-targets=all', '--enable-docs', '--enable-doxygen'
        ]
    status('''Configuring llvm:
    %s''' % llvm_cfg)
    print configure(llvm_cfg)

    status('Building llvm')
    # print make('-j', '--load-average=%f' % max_load)
    print make('-j12')
示例#11
0
文件: test.py 项目: ralphbean/pbs
    def test_command_wrapper_equivalence(self):
        from pbs import Command, ls, which

        self.assertEqual(Command(which("ls")), ls)