chiark / gitweb /
get adtxenu username right; suppress debug properly when !--debug
[autopkgtest.git] / runner / adt-run
index c3fc5e8be84df2cc41600ce01bc7a378d8e240e6..d329d00ee48f13014416c723c074901eadbde6f5 100755 (executable)
@@ -35,6 +35,7 @@ import os
 import errno
 import fnmatch
 import shutil
+import copy
 
 from optparse import OptionParser
 signal.signal(signal.SIGINT, signal.SIG_DFL) # undo stupid Python SIGINT thing
@@ -51,8 +52,12 @@ binaries = None              # Binaries (.debs we have registered)
 class Quit:
        def __init__(q,ec,m): q.ec = ec; q.m = m
 
-def bomb(m): raise Quit(20, "unexpected error: %s" % m)
-def badpkg(m):
+def bomb(m, se=''):
+       print >>sys.stderr, se
+       raise Quit(20, "unexpected error: %s" % m)
+
+def badpkg(m, se=''):
+       print >>sys.stderr, se
        print 'blame: ', ' '.join(testbed.blamed)
        raise Quit(12, "erroneous package: %s" % m)
 
@@ -70,167 +75,229 @@ class Unsupported:
 def debug(m):
        global opts
        if not opts.debug: return
-       print >>sys.stderr, 'atd-run: debug:', m
+       for l in m.rstrip('\n').split('\n'):
+               print >>sys.stderr, 'atd-run: debug:', l
+
+def mkdir_okexist(pathname, mode=02755):
+       try:
+               os.mkdir(pathname, mode)
+       except OSError, oe:
+               if oe.errno != errno.EEXIST: raise
+
+def rmtree(what, pathname):
+       debug('/ %s rmtree %s' % (what, pathname))
+       shutil.rmtree(pathname)
+
+def debug_subprocess(what, cmdl=None, script=None):
+       o = '$ '+what+':'
+       if cmdl is not None:
+               ol = []
+               for x in cmdl:
+                       if x is script: x = '<SCRIPT>'
+                       ol.append(x.    replace('\\','\\\\').
+                                       replace(' ','\\ ')      )
+               o += ' '+ ' '.join(ol)
+       if script is not None:
+               o += '\n'
+               for l in script.rstrip('\n').split('\n'):
+                       o += '$     '+l+'\n'
+       debug(o)
 
 def flatten(l):
        return reduce((lambda a,b: a + b), l, []) 
 
 #---------- fancy automatic file-copying class
 
-class Path:
+class AutoFile:
+       # p.what
        # p.path[tb]    None or path    not None => path known
        # p.file[tb]    None or path    not None => file exists
-       # p.what
-       # p.spec
-       # p.spec_tb
-       # p.tb_scratch
-
- def ensure_path(p, tb=False):
-       if tb and not p.spec_tb:
-               if not testbed.scratch:
-                       error "called ensure_path for `%s' when testbed closed"
-                               % what
-               if not p.tb_scratch or p.tb_scratch is not testbed.scratch:
-                       
+       # p.spec        string or None
+       # p.spec_tbp    True or False, or not set if spec is None
+       # p.dir         '' or '/'
 
-       if p.path[tb] is not None: return
-       if tb: p.path[tb] = p.tb_tmpdir
-       else: p.path[tb] = tmpdir
-       p.path[tb] += '/'+p.what
-
- def ensure_file(p, tb=False):
-       if p.file[tb] is not None: return
-       p.ensure_path(tb)
-       testbed.open()
-       
-
- def write(p, tb=False):
-       p.ensure_path(tb)
-       return p.path[tb]
- def read(p, tb=False):
-       p.ensure_file(tb)
-
-class InputPath:
-class OutputPath:
-class OutputPath:
-
- def __init__(p, path, spec_tb, what, dir=False):
-       if p.tb:
-               if p.p[:1] != '/':
-                       bomb("path %s specified as being in testbed but"
-                               " not absolute: `%s'" % (what, p.p))
-       p.path[spec_tb] = p.file[spec_tb] = path
+ def __init__(p, what):
        p.what = what
+       p.path = [None,None]
+       p.file = [None,None]
+       p.spec = None
+       p.dir = ''
 
-
-       if spec_tb:
-               p.
-tb_path = path
-               p.tb_onpath = path
-               p.tb_onhost = None
-       
-
-4 def __init__(p, tb, path, what, dir=False, tbscratch=None, xfmap=None
-               lpath=None):
-       p.tb = tb
-       p.p = path
-       p.what = what
-       p.dir = dir
-       p.tbscratch = tbscratch
-       p.lpath = None
-       if p.tb:
-               if p.p[:1] != '/':
-                       bomb("path %s specified as being in testbed but"
-                               " not absolute: `%s'" % (what, p.p))
-               p.local = None
-               p.down = p.p
-       else:
-               p.local = p.p
-               p.down = None
-       if p.dir: p.dirsfx = '/'
-       else: p.dirsfx = ''
- 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,
-                       tbscratch=p.tbscratch)
  def __str__(p):
-       if p.tb: pfx = '/VIRT'
-       elif p.p[:1] == '/': pfx = '/HOST'
-       else: pfx = './'
-       return pfx + p.p
-
- def xfmapcopy(p, cud, dstdir):
-       if p.xfmap is None: return
-       srcdir = os.path.dirname(p.path()+'/')
-       dstdir = p.xfmapdstdir+'/'
-       for f in p.xfmap(file(p.local)):
-               if '/' in f: bomb("control file %s mentions other filename"
-                               "containing slash" % p.what)
-               testbed.command(cud, (srcdir+f, dstdir+f))
-
- def onhost(p, lpath = None):
-       if lpath is not None:
-               if p.lpath is not None: assert(p.lpath == lpath)
-               p.lpath = lpath
-       if p.local is not None:
-               if p.lpath is not None: assert(p.local == p.lpath)
-               return p.local
-
-       if p.xfmap is None:
-               p.local = p.lpath
-               if p.local is None: p.local = tmpdir + '/tb-' + p.what
-       else:
-               assert(p.lpath is None)
-               assert(not p.dir)
-               p.xfmapdstdir = tmpdir + '/tbd-' + p.what
-               os.mkdir(p.xfmapdstdir)
-               p.local = p.xfmapdstdir + '/' + os.path.basename(p.down)
-
-       testbed.command('copyup', (p.path(), p.local + p.dirsfx))
-       p.xfmapcopy('copyup')
-
-       return p.local
-
- def maybe_onhost(p):
-       if p.lpath is None: return None
-       return p.onhost()
-
- def ontb(p):
-
-       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")
+       def ptbp(tbp):
+               if p.path[tbp] is None: return '-'+p.dir
+               elif p.file[tbp] is None: return p.path[tbp]+p.dir+'?'
+               else: return p.path[tbp]+p.dir+'!'
+       out = p.what
+       if p.spec is not None:
+               if p.spec_tbp: out += '#'
+               else: out += '='
+               out += p.spec
+       out += ':'
+       out += ptbp(False)
+       out += '|'
+       out += ptbp(True)
+       return out
+
+ def _wrong(p, how):
+       xtra = ''
+       if p.spec is not None: xtra = ' spec[%s]=%s' % (p.spec, p.spec_tb)
+       raise ("internal error: %s (%s)" % (how, str(p)))
+
+ def _ensure_path(p, tbp):
+       if p.path[tbp] is None:
+               if '/' in p.what:
+                       p._debug('tmp-parent %s...' % 'HT'[tbp])
+                       TemporaryDir(os.path.dirname(p.what)).write(tbp)
+               if not tbp:
+                       p.path[tbp] = tmpdir+'/'+p.what
+               else:
+                       p.path[tbp] = testbed.scratch.path[True]+'/'+p.what
 
-       if p.xfmap is None:
-               p.down = testbed.scratch.p + '/host-' + p.what          
-       else:
-               assert(not p.dir)
-               p.xfmapdstdir = testbed.scratch.p + '/hostd-' + p.what
-               testbed.command('mkdir '+p.xfmapdstdir)
-               p.down = p.xfmapdstdir + '/' + os.path.basename(p.local)
+ def write(p, tbp=False):
+       p._debug('write %s...' % 'HT'[tbp])
+       p._ensure_path(tbp)
 
-       p.tbscratch = testbed.scratch
-       testbed.command('copydown', (p.path(), p.down + p.dirsfx))
-       p.xfmapcopy('copydown')
-       return p.down
+       if p.dir and not p.file[tbp]:
+               if not tbp:
+                       p._debug('mkdir H')
+                       mkdir_okexist(p.path[tbp])
+               else:
+                       cmdl = ['sh','-ec',
+                               'test -d "$1" || mkdir "$1"',
+                               'x', p.path[tbp]]
+                       tf_what = urllib.quote(p.what).replace('/','%2F')
+                       (rc,se) = testbed.execute('mkdir-'+tf_what, cmdl)
+                       if rc: bomb('failed to create directory %s' %
+                               p.path[tbp], se)
+
+       p.file[tbp] = p.path[tbp]
+       return p.path[tbp]
+
+ def read(p, tbp=False):
+       p._debug('read %s...' % 'HT'[tbp])
+       p._ensure_path(tbp)
+
+       if p.file[tbp] is None:
+               if p.file[not tbp] is None:
+                       p._wrong("requesting read but nonexistent")
+               cud = ['copyup','copydown'][tbp]
+               src = p.file[not tbp] + p.dir
+               dst = p.path[tbp] + p.dir
+               testbed.command(cud, (src, dst))
+               p.file[tbp] = p.path[tbp]
+
+       return p.file[tbp] + p.dir
+
+ def invalidate(p, tbp=False):
+       p.file[tbp] = None
+       p._debug('invalidated %s' % 'HT'[tbp])
+
+ def _debug(p, m):
+       debug('/ %s#%x: %s' % (p.what, id(p), m))
+
+ def _constructed(p):
+       p._debug('constructed: '+str(p))
+       p._check()
+
+ def _check(p):
+       for tbp in [False,True]:
+        for pf in [p.path, p.file]:
+               if pf[tbp] is None: continue
+               if not pf[tbp]: bomb('empty path specified for '+p.what)
+               if p.dir and pf[tbp].endswith('/'):
+                       pf[tbp] = pf[tbp].rstrip('/')
+                       if not pf[tbp]: pf[tbp] = '/'
+               if not p.dir and pf[tbp].endswith('/'):
+                       bomb("directory `%s' specified for "
+                            "non-directory %s" % (pf[tbp], p.what))
+
+ def _relative_init(p, what, parent, leaf, onlyon_tbp, setfiles, sibling):
+       AutoFile.__init__(p,what)
+       sh_on = ''; sh_sibl = ''
+       if onlyon_tbp is not None: sh_on = ' (on %s)' % ('HT'[onlyon_tbp])
+       if sibling: sh_sibl=' (sibling)'
+       parent._debug('using as base: %s: %s%s%s' %
+                       (str(parent), leaf, sh_on, sh_sibl))
+       if not sibling and not parent.dir:
+               parent._wrong('asked for non-sibling relative path of non-dir')
+       if sibling: trim = os.path.dirname
+       else: trim = lambda x: x
+       for tbp in [False,True]:
+               if parent.path[tbp] is None: continue
+               trimmed = trim(parent.path[tbp])
+               if trimmed: trimmed += '/'
+               p.path[tbp] = trimmed + leaf
+               if setfiles and (onlyon_tbp is None or onlyon_tbp == tbp):
+                       p.file[tbp] = p.path[tbp]
+
+class InputFile(AutoFile):
+ def _init(p, what, spec, spec_tbp=False):
+       AutoFile.__init__(p, what)
+       p.spec = spec
+       p.spec_tbp = spec_tbp
+       p.path[spec_tbp] = spec
+       p.file[p.spec_tbp] = p.path[p.spec_tbp]
+ def __init__(p, what, spec, spec_tbp=False):
+       p._init(what,spec,spec_tbp)
+       p._constructed()
+
+class InputDir(InputFile):
+ def __init__(p, what, spec, spec_tbp=False):
+       InputFile._init(p,what,spec,spec_tbp)
+       p.dir = '/'
+       p._constructed()
+
+class OutputFile(AutoFile):
+ def _init(p, what, spec, spec_tbp=False):
+       AutoFile.__init__(p, what)
+       p.spec = spec
+       p.spec_tbp = spec_tbp
+       p.path[spec_tbp] = spec
+ def __init__(p, what, spec, spec_tbp=False):
+       p._init(what,spec,spec_tbp)
+       p._constructed()
+
+class OutputDir(OutputFile):
+ def __init__(p, what, spec, spec_tbp=False):
+       OutputFile._init(p,what,spec,spec_tbp)
+       p.dir = '/'
+       p._constructed()
+
+class RelativeInputFile(AutoFile):
+ def __init__(p, what, parent, leaf, onlyon_tbp=None, sibling=False):
+       p._relative_init(what, parent, leaf, onlyon_tbp, True, sibling)
+       p._constructed()
+
+class RelativeOutputFile(AutoFile):
+ def __init__(p, what, parent, leaf, sibling=False):
+       p._relative_init(what, parent, leaf, None, False, sibling)
+       p._constructed()
+
+class TemporaryFile(AutoFile):
+ def __init__(p, what):
+       AutoFile.__init__(p, what)
+       p._constructed()
+
+class TemporaryDir(AutoFile):
+ def __init__(p, what):
+       AutoFile.__init__(p, what)
+       p.dir = '/'
+       p._constructed()
 
 #---------- parsing and representation of the arguments
 
 class Action:
- def __init__(a, kind, path, arghandling, ix):
+ def __init__(a, kind, af, arghandling, what):
        # extra attributes get added during processing
        a.kind = kind
-       a.path = path # just a string
+       a.af = af
        a.ah = arghandling
-       a.what = '%s%s' % (kind,ix)
+       a.what = what
 
 def parse_args():
        global opts
-       usage = "%prog <options> -- <virt-server>..."
+       usage = "%prog <options> --- <virt-server>..."
        parser = OptionParser(usage=usage)
        pa = parser.add_option
        pe = parser.add_option
@@ -244,14 +311,15 @@ def parse_args():
                'override_control': None
        }
        initial_arghandling = arghandling.copy()
-       n_actions = 0
+       n_non_actions = 0
 
        #----------
        # actions (ie, test sets to run, sources to build, binaries to use):
 
        def cb_action(op,optstr,value,parser, long,kindpath,is_act):
+               print >>sys.stderr, "cb_action", is_act
                parser.largs.append((value,kindpath))
-               n_actions += is_act
+               n_non_actions += not(is_act)
 
        def pa_action(long, metavar, kindpath, help, is_act=True):
                pa('','--'+long, action='callback', callback=cb_action,
@@ -270,7 +338,7 @@ def parse_args():
                    ' to most recent --binaries-* settings')
 
        pa_action('override-control',   'CONTROL', ('control',), is_act=0,
-              help='run tests from control file CONTROL instead,
+              help='run tests from control file CONTROL instead,'
                    ' (applies to next test suite only)')
 
        #----------
@@ -289,11 +357,11 @@ def parse_args():
                        arghandling[v] = value
                parser.largs.append(arghandling.copy())
 
-       def pa_setah(long, affected,effect, **kwargs):
-               type = metavar; if type: type = 'string'
+       def pa_setah(long, affected,effect, metavar=None, **kwargs):
+               type = metavar
+               if type is not None: type = 'string'
                pa('',long, action='callback', callback=cb_setah,
                   callback_args=(affected,effect), **kwargs)
-                    ' according to most recent --binaries-* settings')
 
        #---- paths: host or testbed:
        #
@@ -310,7 +378,7 @@ def parse_args():
                help='do not run tests from builds of subsequent sources')
 
        pa_setah('--built-binaries-filter', ['dsc_filter'],None,
-               type=string, metavar='PATTERN-LIST',
+               type='string', metavar='PATTERN-LIST',
                help='from subsequent sources, use binaries matching'
                     ' PATTERN-LIST (comma-separated glob patterns)'
                     ' according to most recent --binaries-* settings')
@@ -321,7 +389,7 @@ def parse_args():
 
        def pa_setahbins(long,toset,how):
         pa_setah(long, toset,['ignore','auto','install'],
-               type=string, metavar='IGNORE|AUTO|INSTALL', default='auto',
+               type='string', metavar='IGNORE|AUTO|INSTALL', default='auto',
                help=how+' ignore binaries, install them as needed'
                        ' for dependencies, or unconditionally install'
                        ' them, respectively')
@@ -336,26 +404,32 @@ def parse_args():
                parser.values.vserver = list(parser.rargs)
                del parser.rargs[:]
 
-       def cb_path(op,optstr,value,parser, long,dir,xfmap):
+       def cb_path(op,optstr,value,parser, constructor,long,dir):
                name = long.replace('-','_')
-               path = Path(arghandling['tb'], value, long, dir, xfmap=xfmap)
-               setattr(parser.values, name, path)
+               af = constructor(arghandling['tb'], value, long, dir)
+               setattr(parser.values, name, af)
 
-       def pa_path(long, help, dir=False, xfmap=None):
+       def pa_path(long, constructor, help, dir=False):
                pa('','--'+long, action='callback', callback=cb_path,
-                       nargs=1, type='string', callback_args=(long,dir,xfmap),
-                       help=, metavar='PATH')
+                       callback_args=(constructor,long,dir),
+                       nargs=1, type='string',
+                       help=help, metavar='PATH')
+
+       pa_path('output-dir', OutputDir, dir=True,
+               help='write stderr/out files in PATH')
 
-       pa_path('output-dir', 'write stderr/out files in PATH', dir=True)
+       pa('','--tmp-dir',              type='string', dest='tmpdir',
+               help='write temporary files to TMPDIR, emptying it'
+                    ' beforehand and leaving it behind at the end')
 
        pa('','--user',                 type='string', dest='user',
                help='run tests as USER (needs root on testbed)')
-       pa('','--fakeroot',             type='string', dest='fakeroot',
-               help='prefix debian/rules build with FAKEROOT')
+       pa('','--gain-root',            type='string', dest='gainroot',
+               help='prefix debian/rules binary with GAINROOT')
        pa('-d', '--debug', action='store_true', dest='debug');
        pa('','--gnupg-home',           type='string', dest='gnupghome',
                default='~/.autopkgtest/gpg',
-               help='use GNUPGHOME rather than ~/.autopkgtest (for
+               help='use GNUPGHOME rather than ~/.autopkgtest (for'
                        " signing private apt archive);"
                        " `fresh' means generate new key each time.")
 
@@ -380,7 +454,7 @@ def parse_args():
        (opts,args) = parser.parse_args()
        if not hasattr(opts,'vserver'):
                parser.error('you must specifiy --- <virt-server>...')
-       if not n_actions:
+       if n_non_actions >= len(parser.largs):
                parser.error('nothing to do specified')
 
        arghandling = initial_arghandling
@@ -392,61 +466,71 @@ def parse_args():
                        continue
                elif type(act) == tuple:
                        pass
-               elif type(act) == string:
+               elif type(act) == str:
                        act = (act,act)
                else:
-                       error "unknown action in list `%s' having"
-                             "type `%s' % (act, type(act))
-               (pathname, kindpath) = act
+                       raise ("unknown action in list `%s' having"
+                             " type `%s'" % (act, type(act)))
+               (pathstr, kindpath) = act
 
+               constructor = InputFile
                if type(kindpath) is tuple:             kind = kindpath[0]
-               elif kindpath.endswith('/'):            kind = 'tree'
                elif kindpath.endswith('.deb'):         kind = 'deb'
                elif kindpath.endswith('.dsc'):         kind = 'dsc'
+               elif kindpath.endswith('/'):
+                       kind = 'tree'
+                       constructor = InputDir
                else: parser.error("do not know how to handle filename \`%s';"
                        " specify --source --binary or --build-tree")
 
-               path = InputPath(pathname, arghandling['tb'])
+               what = '%s%s' % (kind,ix); ix += 1
 
-               opts.actions.append(Action(kind, path, arghandling, ix))
-               ix++
+               if kind == 'dsc': fwhatx = '/' + os.path.basename(pathstr)
+               else: fwhatx = '-'+kind
+
+               af = constructor(what+fwhatx, pathstr, arghandling['tb'])
+               opts.actions.append(Action(kind, af, arghandling, what))
 
 def finalise_options():
-       global opts, testbed
+       global opts, tb, tmpdir
+
+       if opts.tmpdir is not None:
+               rmtree('tmpdir(specified)',opts.tmpdir)
+               mkdir_okexist(opts.tmpdir, 0700)
+               tmpdir = opts.tmpdir
+       else:
+               assert(tmpdir is None)
+               tmpdir = tempfile.mkdtemp()
 
-       if opts.user is None and 'root-on-testbed' not in caps:
+       if opts.user is None and 'root-on-testbed' not in testbed.caps:
                opts.user = ''
 
        if opts.user is None:
                su = 'suggested-normal-user='
                ul = [
-                       e[length(su):]
-                       for e in caps
+                       e[len(su):]
+                       for e in testbed.caps
                        if e.startswith(su)
                        ]
-               if len(ul) > 1:
-                       print >>sys.stderr, "warning: virtualisation"
-                               " system offers several suggested-normal-user"
-                               " values: "+('/'.join(ul))+", using "+ul[0]
                if ul:
                        opts.user = ul[0]
                else:
                        opts.user = ''
 
        if opts.user:
-               if 'root-on-testbed' not in caps:
-                       print >>sys.stderr, "warning: virtualisation"
+               if 'root-on-testbed' not in testbed.caps:
+                       print >>sys.stderr, ("warning: virtualisation"
                                " system does not offer root on testbed,"
-                               " but --user option specified: failure likely"
+                               " but --user option specified: failure likely")
                opts.user_wrap = lambda x: 'su %s -c "%s"' % (opts.user, x)
        else:
                opts.user_wrap = lambda x: x
 
-       if opts.fakeroot is None:
-               opts.fakeroot = ''
-               if opts.user or
-                  'root-on-testbed' not in testbed.caps:
-                       opts.fakeroot = 'fakeroot'
+       if opts.gainroot is None:
+               opts.gainroot = ''
+               if (opts.user or
+                   'root-on-testbed' not in testbed.caps):
+                       opts.gainroot = 'fakeroot'
 
        if opts.gnupghome.startswith('~/'):
                try: home = os.environ['HOME']
@@ -467,13 +551,19 @@ class Testbed:
        tb.scratch = None
        tb.modified = False
        tb.blamed = []
+       tb._debug('init')
+ def _debug(tb, m):
+       debug('** '+m)
  def start(tb):
+       tb._debug('start')
        p = subprocess.PIPE
+       debug_subprocess('vserver', opts.vserver)
        tb.sp = subprocess.Popen(opts.vserver,
                stdin=p, stdout=p, stderr=None)
        tb.expect('ok')
-       tb.caps = tb.command('capabilities')
+       tb.caps = tb.commandr('capabilities')
  def stop(tb):
+       tb._debug('stop')
        tb.close()
        if tb.sp is None: return
        ec = tb.sp.returncode
@@ -485,26 +575,32 @@ class Testbed:
        if ec:
                tb.bomb('testbed gave exit status %d after quit' % ec)
  def open(tb):
+       tb._debug('open, scratch=%s' % tb.scratch)
        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
+       pl = tb.commandr('open')
+       tb.scratch = InputDir('tb-scratch', pl[0], True)
  def close(tb):
+       tb._debug('close, scratch=%s' % tb.scratch)
        if tb.scratch is None: return
        tb.scratch = None
        if tb.sp is None: return
        tb.command('close')
  def prepare(tb):
-       if tb.modified and 'reset' in caps:
+       tb._debug('prepare, modified=%s' % tb.modified)
+       if tb.modified and 'reset' in tb.caps:
+               tb._debug('reset **')
                tb.command('reset')
                tb.blamed = []
        tb.modified = False
-       binaries.publish(act)
+       binaries.publish()
  def needs_reset(tb):
+       tb._debug('needs_reset, previously=%s' % tb.modified)
        tb.modified = True
  def blame(tb, m):
+       tb._debug('blame += %s' % m)
        tb.blamed.append(m)
  def bomb(tb, m):
+       tb._debug('bomb %s' % m)
        if tb.sp is not None:
                tb.sp.stdout.close()
                tb.sp.stdin.close()
@@ -524,7 +620,7 @@ class Testbed:
                (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):
+ def expect(tb, keyword, nresults=None):
        l = tb.sp.stdout.readline()
        if not l: tb.bomb('unexpected eof from the testbed')
        if not l.endswith('\n'): tb.bomb('unterminated line from the testbed')
@@ -540,23 +636,44 @@ class Testbed:
                        tb.bomb("sent `%s', got `%s', expected `%s...'" %
                                (tb.lastsend, l, keyword))
        ll = ll[1:]
-       if nresults >= 0 and len(ll) != nresults:
+       if nresults is not None and len(ll) != nresults:
                tb.bomb("sent `%s', got `%s' (%d result parameters),"
                        " expected %d result parameters" %
                        (string, l, len(ll), nresults))
        return ll
- def commandr(tb, cmd, nresults, args=()):
+ def commandr(tb, cmd, args=(), nresults=None):
+       # pass args=[None,...] or =(None,...) to avoid more url quoting
        if type(cmd) is str: cmd = [cmd]
-       al = cmd + map(urllib.quote, args)
+       if len(args) and args[0] is None: args = args[1:]
+       else: args = map(urllib.quote, args)
+       al = cmd + args
        tb.send(string.join(al))
-       ll = tb.expect('ok')
+       ll = tb.expect('ok', nresults)
        rl = map(urllib.unquote, ll)
        return rl
  def command(tb, cmd, args=()):
-       tb.commandr(cmd, 0, args)
+       tb.commandr(cmd, args, 0)
  def commandr1(tb, cmd, args=()):
-       rl = tb.commandr(cmd, 1, args)
+       rl = tb.commandr(cmd, args, 1)
        return rl[0]
+ def execute(tb, what, cmdargs,
+               si='/dev/null', so='/dev/null', se=None, cwd=None,
+               dump_fd=None):
+       if cwd is None: cwd = tb.scratch.write(True)
+       se_use = se
+       if se_use is None:
+               se_af = TemporaryFile('xerr-'+what)
+               se_use = se_af.write(True)
+       cmdl = [None,
+               ','.join(map(urllib.quote, cmdargs)),
+               si, so, se_use, cwd]
+       if dump_fd is not None: cmdl += ['debug=%d-%d' % (dump_fd,2)]
+       rc = tb.commandr1('execute', cmdl)
+       try: rc = int(rc)
+       except ValueError: bomb("execute for %s gave invalid response `%s'"
+                                       % (what,rc))
+       if se is not None: return rc
+       return (rc, file(se_af.read()).read())
 
 #---------- representation of test control files: Field*, Test, etc.
 
@@ -588,9 +705,11 @@ class FieldIgnore(FieldBase):
 class Restriction:
  def __init__(r,rname,base): pass
 
+class Restriction_rw_build_tree(Restriction): pass
 class Restriction_rw_tests_tree(Restriction): pass
 class Restriction_breaks_testbed(Restriction):
-       if 'reset' not in caps:
+ def __init__(r, rname, base):
+       if 'reset' not in testbed.caps:
                raise Unsupported(f.lno,
                        'Test breaks testbed but testbed cannot reset')
 
@@ -614,8 +733,8 @@ class Field_Tests_directory(FieldBase):
                'Tests-Directory may not be absolute')
        base['testsdir'] = td
 
-def run_tests(stanzas):
-       global errorcode
+def run_tests(stanzas, tree):
+       global errorcode, testbed
        for stanza in stanzas:
                tests = stanza[' tests']
                if not tests:
@@ -623,52 +742,48 @@ def run_tests(stanzas):
                        errorcode |= 8
                for t in tests:
                        testbed.prepare()
-                       t.run()
+                       t.run(tree)
                        if 'breaks-testbed' in t.restrictions:
                                testbed.needs_reset()
                testbed.needs_reset()
 
 class Test:
- def __init__(t, tname, base):
+ def __init__(t, tname, base, act_what):
        if '/' in tname: raise Unsupported(base[' lno'],
                'test name may not contain / character')
        for k in base: setattr(t,k,base[k])
        t.tname = tname
-       if len(base['testsdir']): tpath = base['testsdir'] + '/' + tname
-       else: tpath = tname
-       t.p = opts.tests_tree.append(tpath, 'test-'+tname)
+       t.what = act_what+'t-'+tname
+       if len(base['testsdir']): t.path = base['testsdir'] + '/' + tname
+       else: t.path = tname
  def report(t, m):
-       report(t.tname, m)
+       report(t.what, m)
  def reportfail(t, m):
        global errorcode
        errorcode |= 4
-       report(t.tname, 'FAIL ' + m)
- def run(t):
+       report(t.what, 'FAIL ' + m)
+ def run(t, tree):
        def stdouterr(oe):
-               idstr = oe + '-' + t.tname
+               idstr = t.what + '-' + oe
                if opts.output_dir is not None and opts.output_dir.tb:
-                       return opts.output_dir.append(idstr)
+                       use_dir = opts.output_dir
                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)
+                       use_dir = testbed.scratch
+               return RelativeOutputFile(idstr, use_dir, idstr)
+
+       af = RelativeInputFile(t.what, tree, t.path)
        so = stdouterr('stdout')
        se = stdouterr('stderr')
-       rc = testbed.commandr1('execute',(t.p.ontb(),
-               '/dev/null', so.ontb(), se.ontb(), opts.tests_tree.ontb()))
-       soh = stdouterrh(so, 'stdout')
-       seh = stdouterrh(se, 'stderr')
-       rc = int(rc)
-       stab = os.stat(seh)
+       rc = testbed.execute('test-'+t.what,
+               [opts.user_wrap(af.read(True))],
+               so=so.write(True), se=se.write(True), cwd=tree.write(True))
+                       
+       stab = os.stat(se.read())
        if stab.st_size != 0:
-               l = file(seh).readline()
+               l = file(se.read()).readline()
                l = l.rstrip('\n \t\r')
                if len(l) > 40: l = l[:40] + '...'
-               t.reportfail('stderr: %s' % l)
+               t.reportfail('status: %d, stderr: %s' % (rc, l))
        elif rc != 0:
                t.reportfail('non-zero exit status %d' % rc)
        else:
@@ -678,15 +793,14 @@ def read_control(act, tree, control_override):
        stanzas = [ ]
 
        if control_override is not None:
-               control_path = control_override
-               testbed.blame('arg:'+control_path)
+               control_af = control_override
+               testbed.blame('arg:'+control_override.spec)
        else:
-               control_path = tree.append('/debian/tests/control')
-               testbed.blame('arg:'+tree.spec)
-
+               control_af = RelativeInputFile(act.what+'-testcontrol',
+                       tree, 'debian/tests/control')
        try:
-               control = file(control_path.onhost(), 'r')
-       except IOError, oe:
+               control = file(control_af.read(), 'r')
+       except OSError, oe:
                if oe[0] != errno.ENOENT: raise
                return []
 
@@ -753,7 +867,7 @@ def read_control(act, tree, control_override):
                                f = fclass(stz, fname, base, tnames, vl)
                                f.parse()
                        for tname in tnames:
-                               t = Test(tname, base)
+                               t = Test(tname, base, act.what)
                                stz[' tests'].append(t)
                except Unsupported, u:
                        for tname in tnames: u.report(tname)
@@ -775,8 +889,8 @@ def print_exception(ei, msgprefix=''):
 def cleanup():
        try:
                rm_ec = 0
-               if tmpdir is not None:
-                       shutil.rmtree(tmpdir)
+               if opts.tmpdir is None and tmpdir is not None:
+                       rmtree('tmpdir', tmpdir)
                if testbed is not None:
                        testbed.stop()
                if rm_ec: bomb('rm -rf -- %s failed, code %d' % (tmpdir, ec))
@@ -788,7 +902,7 @@ def cleanup():
 #---------- registration, installation etc. of .deb's: Binaries
 
 def determine_package(act):
-       cmd = 'dpkg-deb --info --'.split(' ')+[act.path.read(),'control']
+       cmd = 'dpkg-deb --info --'.split(' ')+[act.af.read(),'control']
        running = Popen(cmd, stdout=PIPE)
        output = running.communicate()[0]
        rc = running.wait()
@@ -804,20 +918,34 @@ def determine_package(act):
 
 class Binaries:
  def __init__(b):
-       b.dir = tmpdir+'/binaries'
+       b.dir = TemporaryDir('binaries')
+       b.dir.write()
+       ok = False
 
        if opts.gnupghome is None:
                opts.gnupghome = tmpdir+'/gnupg'
 
+       b._debug('initialising')
        try:
                for x in ['pubring','secring']:
                        os.stat(opts.gnupghome + '/' + x + '.gpg')
-       except IOError, oe:
+               ok = True
+       except OSError, oe:
                if oe.errno != errno.ENOENT: raise
 
-       try: os.mkdir(opts.gnupghome, 0700)
-       except IOError, oe: if oe.errno != errno.EEXIST: raise
-               script = '
+       if ok: b._debug('no key generation needed')
+       else: b.genkey()
+
+ def _debug(b, s):
+       debug('* '+s)
+
+ def genkey(b):
+       b._debug('preparing for key generation')
+
+       mkdir_okexist(os.path.dirname(opts.gnupghome), 02755)
+       mkdir_okexist(opts.gnupghome, 0700)
+
+       script = '''
   cd "$1"
   exec >key-gen-log 2>&1
   cat <<"END" >key-gen-params
@@ -830,224 +958,281 @@ Name-Email: autopkgtest@example.com
 END
   set -x
   gpg --homedir="$1" --batch --gen-key key-gen-params
-                       '
-               cmdl = ['sh','-ec',script,'x',opts.gnupghome]
-               rc = subprocess.call(cmdl)
-               if rc:
-                       try:
-                               f = open(opts.gnupghome+'/key-gen-log')
-                               tp = file.read()
-                       except IOError, e: tp = e
-                       print >>sys.stderr, tp
-                       bomb('key generation failed, code %d' % rc)
-       
+               '''
+       cmdl = ['sh','-ec',script,'x',opts.gnupghome]
+       debug_subprocess('genkey', cmdl, script=script)
+       rc = subprocess.call(cmdl)
+       if rc:
+               try:
+                       f = open(opts.gnupghome+'/key-gen-log')
+                       tp = file.read()
+               except OSError, e: tp = e
+               print >>sys.stderr, tp
+               bomb('key generation failed, code %d' % rc)
+
  def reset(b):
-       shutil.rmtree(b.dir)
-       os.mkdir(b.dir)
-       b.tbpath = testbed.scratch.append('/binaries')
+       b._debug('reset')
+       rmtree('binaries', b.dir.read())
+       b.dir.invalidate()
+       b.dir.write()
        b.install = []
        b.blamed = []
 
- def register(b, act, pkg, path, forwhat, blamed):
+ def register(b, act, pkg, af, forwhat, blamed):
+       b._debug('register what=%s deb_%s=%s pkg=%s af=%s'
+               % (act.what, forwhat, act.ah['deb_'+forwhat], pkg, str(af)))
+
        if act.ah['deb_'+forwhat] == 'ignore': return
 
        b.blamed += testbed.blamed
 
-       here = path.read()
        leafname = pkg+'.deb'
-       dest = b.dir+'/'+leafname
+       dest = RelativeOutputFile('binaries--'+leafname, b.dir, leafname)
 
-       try: os.remove(dest)
-       except IOError, oe:
+       try: os.remove(dest.write())
+       except OSError, oe:
                if oe.errno != errno.ENOENT: raise e
 
-       try: os.link(here, dest)
-       except IOError, oe:
+       try: os.link(af.read(), dest.write())
+       except OSError, oe:
                if oe.errno != errno.EXDEV: raise e
-               shutil.copy(here, dest)
+               shutil.copy(af.read(), dest)
 
        if act.ah['deb_'+forwhat] == 'install':
                b.install.append(pkg)
 
  def publish(b):
-       script = '
+       b._debug('publish')
+
+       script = '''
   cd "$1"
   apt-ftparchive packages . >Packages
   gzip -f Packages
   apt-ftparchive release . >Release
   gpg --homedir="$2" --batch --detach-sign --armour -o Release.gpg Release
   gpg --homedir="$2" --batch --export >archive-key.pgp
-       '
-       cmdl = ['sh','-ec',script,'x',b.dir,opts.gnupghome]
-       rc = subprocess.call(cmd)
+               '''
+       cmdl = ['sh','-ec',script,'x',b.dir.write(),opts.gnupghome]
+       debug_subprocess('ftparchive', cmdl, script)
+       rc = subprocess.call(cmdl)
        if rc: bomb('apt-ftparchive or signature failed, code %d' % rc)
 
-       tbp = b.tbpath.write(True)
-       testbed.command('copydown', (b.dir+'/', tbp+'/'))
+       b.dir.invalidate(True)
+       apt_source = b.dir.read(True)
 
-       se = TemporaryPath('%s-aptkey-stderr' % act.what)
-       script = '
+       script = '''
   apt-key add archive-key.pgp
-  echo "deb file:///'+tbp+'/ /" >/etc/apt/sources.list.d/autopkgtest
-       '
-       rc = testbed.commandr1(['execute',
-                       ','.join(map(urllib.quote, ['sh','-ec','script']))],
-                       '/dev/null', '/dev/null', se.write(True), tbp)
+  echo "deb file:///'''+apt_source+'''/ /" >/etc/apt/sources.list.d/autopkgtest
+               '''
+       debug_subprocess('apt-key', script=script)
+       (rc,se) = testbed.execute('apt-key',
+                               ['sh','-ec',script],
+                               cwd=b.dir.write(True))
        if rc: bomb('apt setup failed with exit code %d' % rc, se)
 
        testbed.blamed += b.blamed
 
        for pkg in b.install:
+               b._debug('publish install %s' % pkg)
                testbed.blame(pkg)
-               se = TemporaryPath('%s-install-%s-stderr' % (act.what,pkg))
-               rc = testbed.commandr1('execute','apt-get,-qy,install,'+pkg,
-                               '/dev/null','/dev/null',se.ontb(),
-                               tb.scratch.read(True))
-               if rc:
-                       badpkg("installation of %s failed, exit code %d"
+               debug_subprocess('apt-get(b.install)', script=script)
+               (rc,se) = testbed.execute('install-%s'+act.what,
+                       ['apt-get','-qy','install',pkg])
+               if rc: badpkg("installation of %s failed, exit code %d"
                                % (pkg, rc), se)
 
+       b._debug('publish done')
+
 #---------- processing of sources (building)
 
-def source_rules_command(act,script,which,work,results_lines=0):
-       script = "exec 3>&1 >&2\n" + '\n'.join(script)
-       so = TemporaryPath('%s-%s-results' % (what,which))
-       se = TemporaryPath('%s-%s-log' & (what,which))
-       rc = testbed.commandr1(['execute',
-               ','.join(map(urllib.quote, ['sh','-xec',script]))],
-               '/dev/null', so.write(True), se.write(True), work.write(True))
-       results = file(so.read()).read().split("\n")
-       if rc:
-               badpkg_se("%s failed with exit code %d" % (which,rc), se)
+def source_rules_command(act,script,what,which,work,results_lines=0):
+       if opts.debug:
+               trace = "%s-%s-trace" % (what,which)
+               script = [      "mkfifo -m600 "+trace,
+                               "tee <"+trace+" /dev/stderr >&4 &",
+                               "exec >"+trace+" 2>&1"  ] + script
+
+       script = [      "exec 3>&1 >&2",
+                       "set -x"        ] + script
+       script = '\n'.join(script)
+       so = TemporaryFile('%s-%s-results' % (what,which))
+       se = TemporaryFile('%s-%s-log' % (what,which))
+       debug_subprocess('source-rules-command/%s/%s' % (act.what, which),
+                       script=script)
+       rc = testbed.execute('%s-%s' % (what,which),
+                       ['sh','-xec',script],
+                       so=so.write(True), se=se.write(True),
+                       cwd= work.write(True), dump_fd=4)
+       results = file(so.read()).read().rstrip('\n').split("\n")
+       se = file(se.read()).read()
+       if rc: badpkg("%s failed with exit code %d" % (which,rc), se)
        if results_lines is not None and len(results) != results_lines:
-               badpkg_se("got %d lines of results from %s where %d expected"
+               badpkg("got %d lines of results from %s where %d expected"
                        % (len(results), which, results_lines), se)
        if results_lines==1: return results[0]
        return results
 
 def build_source(act):
-       act.blame = 'arg:'+act.path.spec()
+       act.blame = 'arg:'+act.af.spec
        testbed.blame(act.blame)
        testbed.needs_reset()
 
-       what = act.ah['what']
-       dsc = act.path
-       basename = dsc.spec; if basename is None: basename = 'source.dsc'
-       dsc_what = what+'/'+basename
+       what = act.what
+       dsc = act.af
+       basename = dsc.spec
 
        dsc_file = open(dsc.read())
        in_files = False
        fre = regexp.compile('^\s+[0-9a-f]+\s+\d+\s+([^/.][^/]*)$')
-       for l in dsc_file():
-               if l.startswith('Files:'): in_files = True
+       for l in dsc_file:
+               l = l.rstrip('\n')
+               if l.startswith('Files:'): in_files = True; continue
                elif l.startswith('#'): pass
                elif not l.startswith(' '):
                        in_files = False
                        if l.startswith('Source:'):
                                act.blame = 'dsc:'+l[7:].strip()
                                testbed.blame(act.blame)
-               elif not in_files: pass
-               if not dsc.spec_tb: continue
-               m = re.match(l)
+               if not in_files: continue
+
+               m = fre.match(l)
                if not m: badpkg(".dsc contains unparseable line"
-                               " in Files: `%s'" % (`dsc`,l))
-               subfile = dsc.enclosingdir().append('/'+m.groups(0))
+                               " in Files: `%s'" % l)
+               leaf = m.groups(0)[0]
+               subfile = RelativeInputFile(what+'/'+leaf, dsc, leaf,
+                               sibling=True)
                subfile.read(True)
        dsc.read(True)
        
-       work = AccumulationPath(what+'/build', dir=True)
+       work = TemporaryDir(what+'-build')
 
        script = [
                        'cd '+work.write(True),
-                       'gdebi '+dsc.read(True),
+                       'apt-get update',
+                       'apt-get -qy install build-essential',
+                       'gdebi '+dsc.read(True) +' ||apt-get -y install dpatch bison', # fixme fixme
                        'dpkg-source -x '+dsc.read(True),
                        'cd */.',
+                       'dpkg-checkbuilddeps',
                        'pwd >&3',
                        opts.user_wrap('debian/rules build'),
        ]
        result_pwd = source_rules_command(act,script,what,'build',work,1)
 
-       if os.path.dirname(result_pwd) != work.read(True):
-               badpkg_se("results dir `%s' is not in expected parent dir `%s'"
-                       % (results[0], work.read(True)), se)
+       if os.path.dirname(result_pwd)+'/' != work.read(True):
+               badpkg("results dir `%s' is not in expected parent dir `%s'"
+                       % (result_pwd, work.read(True)))
 
-       act.tests_tree = work.append('/'+os.path.basename(results[0]))
+       act.tests_tree = InputDir(what+'-tests-tree',
+                               work.read(True)+os.path.basename(result_pwd),
+                               True)
        if act.ah['dsc_tests']:
-               act.tests_tree.preserve_now()
+               act.tests_tree.read()
+               act.tests_tree.invalidate(True)
 
-       act.blamed = testbed.blamed.copy()
+       act.blamed = copy.copy(testbed.blamed)
 
+       def debug_b(m): debug('* <dsc:%s> %s' % (act.what, m))
        act.binaries = []
-       if act.ah['dsc_filter'] != '_':
+       filter = act.ah['dsc_filter']
+       debug_b('filter=%s' % filter)
+       if filter != '_':
                script = [
                        'cd '+work.write(True)+'/*/.',
-                       opts.user_wrap(opts.fakeroot+' debian/rules binary'),
+                       opts.user_wrap(opts.gainroot+' debian/rules binary'),
                        'cd ..',
                        'echo *.deb >&3',
                        ]
                result_debs = source_rules_command(act,script,what,
-                               'debian/rules binary',work,1)
+                               'binary',work,1)
                if result_debs == '*': debs = []
-               else: debs = debs.split(' ')
+               else: debs = result_debs.split(' ')
+               debug_b('debs='+`debs`)
                re = regexp.compile('^([-+.0-9a-z]+)_[^_/]+(?:_[^_/]+)\.deb$')
                for deb in debs:
                        m = re.match(deb)
                        if not m: badpkg("badly-named binary `%s'" % deb)
-                       pkg = m.groups(0)
-                       for pat in act.ah['dsc_filter'].split(','):
-                               if fnmatch.fnmatchcase(pkg,pat):
-                                       deb_path = work.read()+'/'+deb
-                                       deb_what = pkg+'_'+what+'.deb'
-                                       bin = InputPath(deb_what,deb_path,True)
-                                       bin.preserve_now()
-                                       binaries.register(act,pkg,bin,'builds',
-                                               testbed.blamed)
-                                       act.binaries.append((pkg,bin))
-                                       break
+                       pkg = m.groups()[0]
+                       debug_b(' deb=%s, pkg=%s' % (deb,pkg))
+                       for pat in filter.split(','):
+                               debug_b('  pat=%s' % pat)
+                               if not fnmatch.fnmatchcase(pkg,pat):
+                                       debug_b('   no match')
+                                       continue
+                               deb_what = pkg+'_'+what+'.deb'
+                               bin = RelativeInputFile(deb_what,work,deb,True)
+                               debug_b('  deb_what=%s, bin=%s' %
+                                       (deb_what, str(bin)))
+                               binaries.register(act,pkg,bin,
+                                       'forbuilds',testbed.blamed)
+                               act.binaries.append((pkg,bin))
+                               break
+               debug_b('all done.')
 
 #---------- main processing loop and main program
 
 def process_actions():
        global binaries
+
+       def debug_a1(m): debug('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ '+m)
+       def debug_a2(m): debug('@@@@@@@@@@@@@@@@@@@@ '+m)
+       def debug_a3(m): debug('@@@@@@@@@@ '+m)
+
+       debug_a1('starting')
+       testbed.open()
        binaries = Binaries()
 
-       b.reset()
+       binaries.reset()
+
+       debug_a1('builds ...')
        for act in opts.actions:
+               debug_a2('%s %s' %
+                       (act.kind, act.what))
+
                testbed.prepare()
                if act.kind == 'deb':
-                       blame('arg:'+path.spec)
+                       blame('arg:'+act.af.spec)
                        determine_package(act)
                        blame('deb:'+act.pkg)
-                       binaries.register(act,act.pkg,act.path,'builds',
-                               testbed.blamed)
+                       binaries.register(act,act.pkg,act.af,
+                               'forbuilds',testbed.blamed)
                if act.kind == 'dsc':
                        build_source(act)
 
-       b.reset()
+       debug_a1('builds done.')
+
+       binaries.reset()
        control_override = None
+
+       debug_a1('tests ...')
        for act in opts.actions:
-               testbed.prepare()
+               debug_a2('test %s %s' % (act.kind, act.what))
+
+               testbed.needs_reset()
                if act.kind == 'control':
-                       control_override = act.path
+                       control_override = act.af
                if act.kind == 'deb':
-                       binaries.register(act,act.pkg,act.path,'tests',
+                       binaries.register(act,act.pkg,act.af,'fortests',
                                ['deb:'+act.pkg])
                if act.kind == 'dsc':
                        for (pkg,bin) in act.binaries:
-                               binaries.register(act,pkg,bin,'tests',
+                               binaries.register(act,pkg,bin,'fortests',
                                        act.blamed)
-                       if not act.ah['dsc_tests']: continue
-                       stanzas = read_control(act, act.tests_tree,
-                                       control_override)
-                       testbed.blamed += act.blamed
-                       run_tests(act, stanzas)
+                       if act.ah['dsc_tests']:
+                               debug_a3('read control ...')
+                               stanzas = read_control(act, act.tests_tree,
+                                               control_override)
+                               testbed.blamed += act.blamed
+                               debug_a3('run_tests ...')
+                               run_tests(stanzas, act.tests_tree)
                        control_override = None
                if act.kind == 'tree':
-                       testbed.blame('arg:'+act.path.spec)
-                       stanzas = read_control(act, act.path,
-                                       control_override)
-                       run_tests(act, stanzas)
+                       testbed.blame('arg:'+act.af.spec)
+                       stanzas = read_control(act, act.af, control_override)
+                       debug_a3('run_tests ...')
+                       run_tests(stanzas, act.af)
                        control_override = None
+       debug_a1('tests done.')
 
 def main():
        global testbed
@@ -1057,7 +1242,6 @@ def main():
        except SystemExit, se:
                os._exit(20)
        try:
-               tmpdir = tempfile.mkdtemp()
                testbed = Testbed()
                testbed.start()
                finalise_options()