X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fas3%2Fruntests.py;h=b46206dfdc0be4f708dca2390979cf8f85985fb2;hb=7f52a1e9e7c8113b2a78141e131b8f4ccc3949cf;hp=cc24f8f24a04670e9ea3970f70d98fc5e2b01ed6;hpb=19f7d1e5b9ff2faba72b6447ed3bd31c3d58acab;p=swftools.git diff --git a/lib/as3/runtests.py b/lib/as3/runtests.py index cc24f8f..b46206d 100644 --- a/lib/as3/runtests.py +++ b/lib/as3/runtests.py @@ -24,6 +24,9 @@ import sys import os import time import subprocess +import marshal +import select +from optparse import OptionParser def check(s): row = None @@ -56,24 +59,71 @@ def check(s): return 0 def runcmd(cmd,args,wait): - #fo = open(tempfile, "wb") - fo= os.tmpfile() + #fo = os.tmpfile() + fi,fo = os.pipe() + fo = os.fdopen(fo, "wb") p = subprocess.Popen([cmd] + args, executable=cmd, stdout=fo, stderr=fo) ret = -1 + output = "" for i in range(wait*10): + if fi in select.select([fi],[],[], 0.01)[0]: + output += os.read(fi, 8192) + if "[exit]" in output: + break ret = p.poll() if ret is not None: break time.sleep(0.1) else: os.kill(p.pid, 9) - os.system("killall -9 "+cmd) - - fo.seek(0) - output = fo.read() + os.system("killall -9 %s >/dev/null 2>/dev/null" % cmd) fo.close() + + if fi in select.select([fi],[],[], 0.01)[0]: + output += os.read(fi, 8192) + + os.close(fi) return ret,output +class Cache: + def __init__(self, filename): + try: + self.filename2status = marshal.load(open(filename, "rb")) + except IOError: + self.filename2status = {} + + def parse_args(self): + parser = OptionParser() + parser.add_option("-d", "--diff", dest="diff", help="Only run tests that failed the last time",action="store_true") + (options, args) = parser.parse_args() + self.__dict__.update(options.__dict__) + + self.checknum=-1 + if len(args): + self.checknum = int(args[0]) + + @staticmethod + def load(filename): + return Cache(filename) + + def save(self, filename): + fi = open(filename, "wb") + marshal.dump(self.filename2status, fi) + fi.close() + + def highlight(self, nr, filename): + return self.checknum==nr + + def skip_file(self, nr, filename): + if self.checknum>=0 and nr!=self.checknum: + return 1 + if self.diff and self.filename2status[filename]=="ok": + return 1 + return 0 + + def file_status(self, filename, status): + self.filename2status[filename] = status + class TestBase: def __init__(self, nr, file, run): self.nr = nr @@ -90,10 +140,16 @@ class TestBase: ret,output = runcmd("./parser",[self.file],wait=60) self.compile_error = 0 self.compile_output = output + self.exit_status = 0 if ret: + self.compile_output += "\nExit status %d" % (-ret) + self.exit_status = -ret self.compile_error = 1 + return 0 if not os.path.isfile("abc.swf"): self.compile_error = 1 + return 0 + return 1 def run(self): ret,output = runcmd("flashplayer",["abc.swf"],wait=1) @@ -102,16 +158,21 @@ class TestBase: if not check(self.flash_output): self.flash_error = 1 + return 0 + return 1 def doprint(self): print self.r(str(self.nr),3)," ", if self.compile_error: if self.dorun: - print "err"," - ", + if self.exit_status == 11: + print "crash"," - ", + else: + print "err "," - ", else: - print "err"," ", + print "err "," ", else: - print "ok ", + print "ok ", if self.dorun: if not self.flash_error: print "ok ", @@ -125,13 +186,13 @@ class TestBase: def doprintlong(self): print self.nr, self.file print "================================" - print "compile:", (test.compile_error and "error" or "ok") - print test.compile_output + print "compile:", (self.compile_error and "error" or "ok") + print self.compile_output if not self.dorun: return print "================================" - print "run:", (test.flash_error and "error" or "ok") - print test.flash_output + print "run:", (self.flash_error and "error" or "ok") + print self.flash_output print "================================" def r(self,s,l): @@ -144,21 +205,27 @@ class TestBase: return s + (" "*(l-len(s))) class Test(TestBase): - def __init__(self, nr, file): + def __init__(self, cache, nr, file): TestBase.__init__(self, nr, file, run=1) - self.compile() - if not self.compile_error: - self.run() + if self.compile() and self.run(): + cache.file_status(file, "ok") + else: + cache.file_status(file, "error") class ErrTest(TestBase): - def __init__(self, nr, file): + def __init__(self, cache, nr, file): TestBase.__init__(self, nr, file, run=0) - self.compile() - self.compile_error = not self.compile_error + if self.compile(): + cache.file_status(file, "error") + self.compile_error = True + else: + cache.file_status(file, "ok") + self.compile_error = False class Suite: - def __init__(self, dir): + def __init__(self, cache, dir): self.dir = dir + self.cache = cache self.errtest = "err" in dir def run(self, nr): print "-"*40,"tests \""+self.dir+"\"","-"*40 @@ -167,23 +234,26 @@ class Suite: continue nr = nr + 1 file = os.path.join(self.dir, file) - if checknum>=0 and nr!=checknum: + + if cache.skip_file(nr, file): continue + if self.errtest: - test = ErrTest(nr,file) + test = ErrTest(cache, nr, file) else: - test = Test(nr,file) - if checknum!=nr: + test = Test(cache, nr, file) + + if not cache.highlight(nr, file): test.doprint() else: test.doprintlong() return nr -checknum=-1 -if len(sys.argv)>1: - checknum = int(sys.argv[1]) +cache = Cache.load(".tests.cache") +cache.parse_args() nr = 0 -nr = Suite("err").run(nr) -nr = Suite("ok").run(nr) +nr = Suite(cache, "err").run(nr) +nr = Suite(cache, "ok").run(nr) +cache.save(".tests.cache")