chiark / gitweb /
delete debug msgs; bomb surviving path better; get tbscratch default right
[autopkgtest.git] / runner / adt-run
index 8b52320c5fc30285170ed1abf43dbcb797a36787..e663a2a76a8e0070ed1ff3f9db5e266f946dc855 100755 (executable)
@@ -67,11 +67,12 @@ def flatten(l):
        return reduce((lambda a,b: a + b), l, []) 
 
 class Path:
- def __init__(p, tb, path, what, dir=False):
+ def __init__(p, tb, path, what, dir=False, tbscratch=None):
        p.tb = tb
        p.p = path
        p.what = what
        p.dir = dir
+       p.tbscratch = tbscratch
        if p.tb:
                if p.p[:1] != '/':
                        bomb("path %s specified as being in testbed but"
@@ -86,21 +87,32 @@ class Path:
  def path(p):
        return p.p + p.dirsfx
  def append(p, suffix, what, dir=False):
-       return Path(p.tb, p.path() + suffix, what=what, dir=dir)
+       return Path(p.tb, p.path() + suffix, what=what, dir=dir,
+                       tbscratch=p.tbscratch)
  def __str__(p):
        if p.tb: pfx = '/VIRT'
        elif p.p[:1] == '/': pfx = '/HOST'
        else: pfx = './'
        return pfx + p.p
- def onhost(p):
-       if p.local is not None: return p.local
+ def onhost(p, lpath = None):
+       if p.local is not None:
+               if lpath is not None: assert(p.local == lpath)
+               return p.local
        testbed.open()
-       p.local = tmpdir + '/tb-' + p.what
+       p.local = lpath
+       if p.local is None: p.local = tmpdir + '/tb-' + p.what
        testbed.command('copyup', (p.path(), p.local + p.dirsfx))
        return p.local
  def ontb(p):
+       testbed.open()
+       if p.tbscratch is not None:
+               if p.tbscratch != testbed.scratch:
+                       p.down = None
        if p.down is not None: return p.down
+       if p.tb:
+               bomb("testbed scratch path " + str(p) + " survived testbed")
        p.down = testbed.scratch.p + '/host-' + p.what
+       p.tbscratch = testbed.scratch
        testbed.command('copydown', (p.path(), p.down + p.dirsfx))
        return p.down
 
@@ -129,6 +141,7 @@ def parse_args():
 
        pa_path('build-tree',   True, 'use build tree from PATH on %s')
        pa_path('control',      False, 'read control file PATH on %s')
+       pa_path('output-dir',   True, 'write stderr/out files in PATH on %s')
 
        pa('-d', '--debug', action='store_true', dest='debug');
        # pa('','--user', type='string',
@@ -186,9 +199,11 @@ class Testbed:
        if tb.scratch is not None: return
        p = tb.commandr1('open')
        tb.scratch = Path(True, p, 'tb-scratch', dir=True)
+       tb.scratch.tbscratch = tb.scratch
  def close(tb):
        if tb.scratch is None: return
        tb.scratch = None
+       if tb.sp is None: return
        tb.command('close')
  def bomb(tb, m):
        if tb.sp is not None:
@@ -200,14 +215,16 @@ class Testbed:
        tb.sp = None
        raise Quit(16, 'testbed failed: %s' % m)
  def send(tb, string):
+       tb.sp.stdin
        try:
                debug('>> '+string)
                print >>tb.sp.stdin, string
                tb.sp.stdin.flush()
                tb.lastsend = string
        except:
-               tb.bomb('cannot send to testbed: %s' %
-                       formatexception_only(sys.last_type, sys.last_value))
+               (type, value, dummy) = sys.exc_info()
+               tb.bomb('cannot send to testbed: %s' % traceback.
+                       format_exception_only(type, value))
  def expect(tb, keyword, nresults=-1):
        l = tb.sp.stdout.readline()
        if not l: tb.bomb('unexpected eof from the testbed')
@@ -306,8 +323,9 @@ class Test:
                'test name may not contain / character')
        for k in base: setattr(t,k,base[k])
        t.tname = tname
-       t.p = opts.build_tree.append(tname, 'test-'+tname)
-       t.p.ontb()
+       if len(base['testsdir']): tpath = base['testsdir'] + '/' + tname
+       else: tpath = tname
+       t.p = opts.build_tree.append(tpath, 'test-'+tname)
  def report(t, m):
        report(t.tname, m)
  def reportfail(t, m):
@@ -316,12 +334,24 @@ class Test:
        report(t.tname, 'FAIL ' + m)
  def run(t):
        testbed.open()
-       so = testbed.scratch.append('stdout-' + t.tname, 'stdout-' + t.tname)
-       se = testbed.scratch.append('stdout-' + t.tname, 'stdout-' + t.tname)
+       def stdouterr(oe):
+               idstr = oe + '-' + t.tname
+               if opts.output_dir is not None and opts.output_dir.tb:
+                       return opts.output_dir.append(idstr)
+               else:
+                       return testbed.scratch.append(idstr, idstr)
+       def stdouterrh(p, oe):
+               idstr = oe + '-' + t.tname
+               if opts.output_dir is None or opts.output_dir.tb:
+                       return p.onhost()
+               else:
+                       return p.onhost(opts.output_dir.onhost() + '/' + idstr)
+       so = stdouterr('stdout')
+       se = stdouterr('stderr')
        rc = testbed.commandr1('execute',(t.p.ontb(),
                '/dev/null', so.ontb(), se.ontb()))
-       soh = so.onhost()
-       seh = se.onhost()
+       soh = stdouterrh(so, 'stdout')
+       soe = stdouterrh(se, 'stderr')
        testbed.close()
        rc = int(rc)
        stab = os.stat(soh)
@@ -449,6 +479,8 @@ def main():
                tmpdir = tempfile.mkdtemp()
                testbed = Testbed()
                testbed.start()
+               testbed.open()
+               testbed.close()
                read_control()
                run_tests()
        except: