示例#1
0
def run_tests(command=None,verbose=False,srec=False):
    
    startpath = os.path.abspath(os.getcwd())
    failed = set()
    ntests = 0
    prevfailed = read_failcache()
    try:
        testpath = discovery.discover_testpath()
        os.chdir(testpath)
        
        tests = [x[:-2] for x in glob.glob("*.c")]
        tests.sort()
        #rerun failed tests only
        if len(prevfailed):
            tests = [x for x in tests if x in prevfailed]
        ntests = len(tests)
        for t in tests:
            kernel = t
            if srec:
                kernel += ".srec"
            print "Test: %s" %t
            logfile = None
            if verbose:
                logfile = sys.stdout
            emu = pexpect.spawn(command.format(KERNEL=kernel),logfile=logfile,timeout=5)
            try:
                idx = emu.expect(["PASS","FAIL"])
                if idx != 0:
                    print "    failed"
                    failed.add(t)
                emu.expect(pexpect.EOF)
            except pexpect.EOF:
                print "    Unexpected EOF"
                failed.add(t)
            except pexpect.TIMEOUT:
                print "    Unexpected TIMEOUT"
                failed.add(t)
    finally:
        os.chdir(startpath)
    
    write_failcache(failed)
    
    print "List of failed tests:"
    for t in sorted(failed):
        print "  " + t
    print "passed %s of %s tests" % (ntests - len(failed),ntests)
示例#2
0
def build_tests(files=None,verbose=False,force=False):
    import glob
    toolchainpath = discovery.discover_toolchain_path()
    testpath = discovery.discover_testpath()
    startpath = os.path.abspath(os.getcwd())
    #Build all the single source tests
    try:
        os.chdir(testpath)
        if files == None:
            files = glob.glob("*.c")
        for csource in files:
            lastbuild = 0
            if os.path.isfile(csource[:-2]) and os.path.isfile(csource[:-2]+'.srec') and not force:
                lastbuild = min(os.path.getmtime(csource[:-2]),os.path.getmtime(csource[:-2]+'.srec'))
            
            if os.path.getmtime(csource) > lastbuild:
                output,code = pexpect.run("bash build.sh %s %s" % ( toolchainpath,csource ),withexitstatus=True)
                if code != 0:
                    print output
                    raise Exception("build of single_source %s failed with retcode %s"%(csource,code))
                print "Built: %s" % csource
    finally:
        os.chdir(startpath)