chiark / gitweb /
remove some debugging prints
[autopkgtest.git] / runner / adt-run
index 2c8c807d8bc3400f90e15b58686e90c634760d04..21f97860a815db9e189600069f1c43e9b4aae532 100755 (executable)
@@ -21,6 +21,7 @@ import subprocess
 import traceback
 import urllib
 import string
+import re as regexp
 
 from optparse import OptionParser
 
@@ -35,11 +36,21 @@ class Quit:
 def bomb(m): raise Quit(20, "unexpected error: %s" % m)
 def badpkg(m): raise Quit(12, "erroneous package: %s" % m)
 
+class Unsupported:
+ def __init__(u, lno, m):
+       if lno >= 0: u.m = '%s (control line %d)' % (m, lno)
+       else: u.m = m
+ def report(u, tname):
+       print '%-20s SKIP %s' % (tname, u.m)
+
 def debug(m):
        global opts
        if not opts.debug: return
        print >>sys.stderr, 'atd-run: debug:', m
 
+def flatten(l):
+       return reduce((lambda a,b: a + b), l, []) 
+
 class Path:
  def __init__(p, tb, path, what, dir=False):
        p.tb = tb
@@ -85,7 +96,7 @@ def parse_args():
 
        def cb_path(op,optstr,value,parser, long,tb,dir):
                name = long.replace('-','_')
-               parser.values.__dict__[name] = Path(tb, value, long, dir)
+               setattr(parser.values, name, Path(tb, value, long, dir))
 
        def pa_path(long, dir, help):
                def papa_tb(long, ca, pahelp):
@@ -208,8 +219,133 @@ class Testbed:
        rl = tb.commandr(cmd, 1, args)
        return rl[0]
 
+class FieldBase:
+ def __init__(f, fname, stz, base, tnames, vl):
+       f.stz = stz
+       f.base = base
+       f.tnames = tnames
+       f.vl = vl
+ def words(f):
+       def distribute(vle):
+               (lno, v) = vle
+               r = v.split()
+               r = map((lambda w: (lno, w)), r)
+               return r
+       return flatten(map(distribute, f.vl))
+ def atmostone(f, default):
+       if not vl:
+               f.v = default
+               f.lno = -1
+       elif len(vl) == 1:
+               (f.lno, f.v) = vl[0]
+       else:
+               raise Unsupported(f.vl[1][0],
+                       'only one %s field allowed' % fn)
+       return f.v
+
+class FieldIgnore(FieldBase):
+ def parse(f): pass
+
+class Restriction:
+ def __init__(r,rname,base): pass
+
+class Restriction_rw_build_tree(Restriction): pass
+
+class Field_Restrictions(FieldBase):
+ def parse(f):
+       for wle in f.words():
+               (lno, rname) = wle
+               rname = rname.replace('-','_')
+               try: rclass = globals()['Restriction_'+rname]
+               except KeyError: raise Unsupported(lno,
+                       'unknown restriction %s' % rname)
+               r = rclass(rname, f.base)
+               f.base['restrictions'].append(r)
+
+class Field_Tests(FieldIgnore): pass
+
+class Field_Tests_directory(FieldBase):
+ def parse(f):
+       base['testsdir'] = oneonly(f)
+
+class Test:
+ def __init__(t, tname, base):
+       t.tname = tname
+       for k in base: setattr(t,k,base[k])
+
 def read_control():
+       global tests
        control = file(opts.control.onhost(), 'r')
+       lno = 0
+       def badctrl(m): testbed.badpkg('tests/control line %d: %s' % (lno, m))
+       stz = None # stz[field_name][index] = (lno, value)
+
+       stanzas = [ ]
+       stz = None
+
+       def end_stanza(stz):
+               if stz is None: return
+               stz[' errs'] = 0
+               stanzas.append(stz)
+               stz = None
+               hcurrent = None
+
+       initre = regexp.compile('([A-Z][-0-9a-z]*)\s*\:\s*(.*)$')
+       while 1:
+               l = control.readline()
+               if not l: break
+               lno += 1
+               if not l.endswith('\n'): badctrl('unterminated line')
+               if regexp.compile('\s*\#').match(l): continue
+               if not regexp.compile('\S').match(l): end_stanza(stz); continue
+               initmat = initre.match(l)
+               if initmat:
+                       (fname, l) = initmat.groups()
+                       fname = string.capwords(fname)
+                       if stz is None:
+                               stz = { ' lno': lno }
+                       if not stz.has_key(fname): stz[fname] = [ ]
+                       hcurrent = stz[fname]
+               elif regexp.compile('\s').match(l):
+                       if not hcurrent: badctrl('unexpected continuation')
+               else:
+                       badctrl('syntax error')
+               hcurrent.append((lno, l))
+       end_stanza(stz)
+
+       def testbadctrl(stz, lno, m):
+               report_badctrl(lno, m)
+               stz[' errs'] += 1
+
+       for stz in stanzas:
+               try:
+                       try: tnames = stz['Tests']
+                       except KeyError:
+                               tnames = ['*']
+                               raise Unsupported(stz[' lno'],
+                                       'no Tests field')
+                       tnames = map((lambda lt: lt[1]), tnames)
+                       tnames = string.join(tnames).split()
+                       base = {
+                               'restrictions': [],
+                               'testsdir': 'debian/tests'
+                       }
+                       for fname in stz.keys():
+                               if fname.startswith(' '): continue
+                               vl = stz[fname]
+                               try: fclass = globals()['Field_'+
+                                       fname.replace('-','_')]
+                               except KeyError: raise Unsupported(vl[0][0],
+                                       'unknown metadata field %s' % fname)
+                               f = fclass(stz, fname, base, tnames, vl)
+                               f.parse()
+               except Unsupported, u:
+                       for tname in tnames: u.report(tname)
+                       continue
+               tests = []
+               for tname in tnames:
+                       t = Test(tname, base)
+                       tests.append(t)
        testbed.close()
 
 def print_exception(ei, msgprefix=''):