chiark / gitweb /
* adt-xenlvm-with-testbed: sleep 1 after xm destroy, which is racy.
[autopkgtest.git] / runner / adt-run
index 2b211ee31de46236524f8a09d697ef7b3eb17391..7787e5761971fb566993e8e87bd40058ed5d01b4 100755 (executable)
@@ -45,7 +45,7 @@ signal.signal(signal.SIGINT, signal.SIG_DFL) # undo stupid Python SIGINT thing
 tmpdir = None          # pathstring on host
 testbed = None         # Testbed
 errorcode = 0          # exit status that we are going to use
-timeouts = { 'short':10, 'install':900, 'test':600, 'build':3000 }
+timeouts = { 'short':100, 'install':3000, 'test':10000, 'build':100000 }
 binaries = None                # Binaries (.debs we have registered)
 build_essential = ["build-essential"]
 
@@ -114,7 +114,7 @@ class Errplumb:
                ep.stream = open('/dev/null','w')
                ep._sp = None
        elif count == 1:
-               if to_stderr: ep.stream = sys.stderr
+               if to_stderr: ep.stream = os.dup(2)
                else: ep.stream = trace_stream
                ep._sp = None
        else:
@@ -124,6 +124,9 @@ class Errplumb:
                ep.stream = ep._sp.stdin
  def wait(ep):
        if ep._sp is None: return
+       if type(ep.stream) == type(2):
+               os.close(ep.stream)
+               ep.stream = ()
        ep._sp.stdin.close()
        rc = ep._sp.wait()
        if rc: bomb('stderr plumbing tee(1) failed, exit code %d' % rc)
@@ -180,12 +183,14 @@ class Unsupported:
 def mkdir_okexist(pathname, mode=02755):
        try:
                os.mkdir(pathname, mode)
-       except OSError, oe:
+       except (IOError,OSError), oe:
                if oe.errno != errno.EEXIST: raise
 
 def rmtree(what, pathname):
        debug('/ %s rmtree %s' % (what, pathname), 2)
-       shutil.rmtree(pathname)
+       try: shutil.rmtree(pathname)
+       except (IOError,OSError), oe:
+               if oe.errno != errno.EEXIST: raise
 
 def debug_subprocess(what, cmdl=None, script=None):
        o = '$ '+what+':'
@@ -403,7 +408,7 @@ class Action:
        return "<Action %s %s %s>" % (a.kind, a.what, `a.af`)
 
 def parse_args():
-       global opts
+       global opts, timeouts
        global n_non_actions # argh, stupid python scoping rules
        usage = "%prog <options> --- <virt-server>..."
        parser = OptionParser(usage=usage)
@@ -416,7 +421,8 @@ def parse_args():
                'deb_forbuilds': 'auto',
                'deb_fortests': 'auto',
                'tb': False,
-               'override_control': None
+               'override_control': None,
+               'set_lang': 'C'
        }
        initial_arghandling = arghandling.copy()
        n_non_actions = 0
@@ -504,7 +510,6 @@ def parse_args():
                     ' according to most recent --binaries-* settings')
        pa_setah('--no-built-binaries', ['dsc_filter'], '_',
                help='from subsequent sources, do not use any binaries')
-
        #---- binary package processing settings:
 
        def pa_setahbins(long,toset,how):
@@ -538,6 +543,11 @@ def parse_args():
        pa_path('output-dir', OutputDir, dir=True,
                help='write stderr/out files in PATH')
 
+       pa('--leave-lang', dest='set_lang', action='store_false',
+               help="leave LANG on testbed set to testbed's default")
+       pa('--set-lang', dest='set_lang', action='store', metavar='LANGVAL',
+               help='set LANG on testbed to LANGVAL', default='C')
+
        pa('','--tmp-dir',              type='string', dest='tmpdir',
                help='write temporary files to TMPDIR, emptying it'
                     ' beforehand and leaving it behind at the end')
@@ -548,6 +558,13 @@ def parse_args():
                help='write a summary report to SUMMARY,'
                     ' emptying it beforehand')
 
+       for k in timeouts.keys():
+               pa('','--timeout-'+k,   type='int', dest='timeout_'+k,
+                       metavar='T', help='set %s timeout to T')
+       pa('','--timeout-factor',       type='float', dest='timeout_factor',
+                       metavar='FACTOR', default=1.0,
+                       help='multiply all default timeouts by FACTOR')
+
        pa('','--user',                 type='string', dest='user',
                help='run tests as USER (needs root on testbed)')
        pa('','--gain-root',            type='string', dest='gainroot',
@@ -584,6 +601,11 @@ def parse_args():
        if n_non_actions >= len(parser.largs):
                parser.error('nothing to do specified')
 
+       for k in timeouts.keys():
+               t = getattr(opts,'timeout_'+k)
+               if t is None: t = timeouts[k] * opts.timeout_factor
+               timeouts[k] = int(t)
+
        arghandling = initial_arghandling
        opts.actions = []
        ix = 0
@@ -610,8 +632,9 @@ def parse_args():
                elif kindpath.endswith('/'):
                        kind = 'tree'
                        constructor = InputDir
-               else: parser.error("do not know how to handle filename \`%s';"
-                       " specify --source --binary or --build-tree")
+               else: parser.error("do not know how to handle filename `%s';"
+                       " specify --source --binary or --build-tree" %
+                       kindpath)
 
                what = '%s%s' % (kind,ix); ix += 1
 
@@ -643,7 +666,7 @@ def setup_trace():
        if opts.summary is not None:
                summary_stream = open(opts.summary, 'w', 0)
 
-       debug('options: '+`opts`, 1)
+       debug('options: '+`opts`+'; timeouts: '+`timeouts`, 1)
 
 def finalise_options():
        global opts, tb, build_essential
@@ -887,6 +910,8 @@ class Testbed:
        if xdump is not None and 'execute-debug' in tb.caps: cmdl += [xdump]
        if tmpdir is not None: cmdl.append('env=TMPDIR=%s' % tmpdir)
        if kind=='install': cmdl.append('env=DEBIAN_FRONTEND=noninteractive')
+       if opts.set_lang is not False:
+               cmdl.append('env=LANG=%s' % opts.set_lang)
 
        rc = tb.commandr1('execute', cmdl)
        try: rc = int(rc)
@@ -1047,7 +1072,8 @@ class Test:
                        use_dir = testbed.scratch
                return RelativeOutputFile(idstr, use_dir, idstr)
 
-       t.act.work.write(True)
+       if hasattr(t.act,'work'): t.act.work.write(True)
+       tree.read(True)
 
        af = RelativeInputFile(t.what, tree, t.path)
        so = stdouterr('stdout')
@@ -1055,7 +1081,6 @@ class Test:
 
        tf = af.read(True)
        tmpdir = None
-       tree.read(True)
 
        rc = testbed.execute('testchmod-'+t.what, ['chmod','+x','--',tf])
        if rc: bomb('failed to chmod +x %s' % tf)
@@ -1115,7 +1140,7 @@ def read_control(act, tree, control_override):
                        tree, 'debian/tests/control')
        try:
                control = open(control_af.read(), 'r')
-       except OSError, oe:
+       except (IOError,OSError), oe:
                if oe[0] != errno.ENOENT: raise
                return []
 
@@ -1212,13 +1237,11 @@ def print_exception(ei, msgprefix=''):
 def cleanup():
        global trace_stream
        try:
-               rm_ec = 0
-               if opts.tmpdir is None and tmpdir is not None:
-                       rmtree('tmpdir', tmpdir)
                if testbed is not None:
                        testbed.reset_apt()
                        testbed.stop()
-               if rm_ec: bomb('rm -rf -- %s failed, code %d' % (tmpdir, ec))
+               if opts.tmpdir is None and tmpdir is not None:
+                       rmtree('tmpdir', tmpdir)
                if trace_stream is not None:
                        trace_stream.close()
                        trace_stream = None
@@ -1256,7 +1279,7 @@ class Binaries:
                for x in ['pubring','secring']:
                        os.stat(opts.gnupghome + '/' + x + '.gpg')
                ok = True
-       except OSError, oe:
+       except (IOError,OSError), oe:
                if oe.errno != errno.ENOENT: raise
 
        if ok: b._debug('no key generation needed')
@@ -1287,17 +1310,12 @@ END
                '''
        cmdl = ['sh','-ec',script,'x',opts.gnupghome]
        rc = subprocess_cooked(cmdl, dbg=('genkey',script))[0]
-       if rc:
-               try:
-                       f = open(opts.gnupghome+'/key-gen-log')
-                       tp = file.read()
-               except OSError, e: tp = e
-               pstderr(tp)
-               bomb('key generation failed, code %d' % rc)
+       if rc: bomb('key generation failed, code %d' % rc)
 
  def apt_configs(b):
        return {
                "Dir::Etc::sourcelist": b.dir.read(True)+'sources.list',
+               "Debug::pkgProblemResolver": "true",
        }
 
  def apt_pkg_gdebi_script(b, arg, middle):
@@ -1353,11 +1371,11 @@ END
        dest = RelativeOutputFile('binaries--'+leafname, b.dir, leafname)
 
        try: os.remove(dest.write())
-       except OSError, oe:
+       except (IOError,OSError), oe:
                if oe.errno != errno.ENOENT: raise e
 
        try: os.link(af.read(), dest.write())
-       except OSError, oe:
+       except (IOError,OSError), oe:
                if oe.errno != errno.EXDEV: raise e
                shutil.copy(af.read(), dest)
 
@@ -1565,7 +1583,7 @@ def build_source(act, control_override):
                        [ create_command ])
 
        script += [
-                       'cd */.',
+                       'cd [a-z0-9]*-*/.',
                        'pwd >&3',
                        'set +e; test -f debian/tests/control; echo $? >&3'
                ]
@@ -1664,7 +1682,7 @@ def build_source(act, control_override):
        debug_b('filter=%s' % filter)
        if filter != '_':
                script = tmpdir_script + [
-                       'cd '+work.write(True)+'/*/.',
+                       'cd '+work.write(True)+'/[a-z0-9]*-*/.',
                        opts.user_wrap(opts.gainroot+' debian/rules binary'),
                        'cd ..',
                        'echo *.deb >&3',
@@ -1672,7 +1690,7 @@ def build_source(act, control_override):
                result_debs = source_rules_command(act,script,what,
                                'binary',work,work.write(True),
                                results_lines=1, xargs=['x',tmpdir])
-               if result_debs == '*': debs = []
+               if result_debs == '*.deb': debs = []
                else: debs = result_debs.split(' ')
                debug_b('debs='+`debs`)
                re = regexp.compile('^([-+.0-9a-z]+)_[^_/]+(?:_[^_/]+)\.deb$')