-#!/usr/bin/python2.4
+#!/usr/bin/python2.6
#
# adt-run is part of autopkgtest
# autopkgtest is a tool for testing Debian binary packages
from optparse import OptionParser
signal.signal(signal.SIGINT, signal.SIG_DFL) # undo stupid Python SIGINT thing
+try: our_base = os.environ['AUTOPKGTEST_BASE']+'/lib'
+except KeyError: our_base = '/usr/share/autopkgtest/python';
+sys.path.insert(1, our_base)
+
+from Autopkgtest import *
+
#---------- global variables
tmpdir = None # pathstring on host
timeouts = { 'short':100, 'install':3000, 'test':10000, 'build':100000 }
binaries = None # Binaries (.debs we have registered)
build_essential = ["build-essential"]
+paths = []
#---------- output handling
#
# p.what
# p.path[tb] None or path not None => path known
# p.file[tb] None or path not None => file exists
+ # p.ephem[tb] boolean True => destroyed by tb reset
# p.spec string or None
# p.spec_tbp True or False, or not set if spec is None
# p.dir '' or '/'
p.what = what
p.path = [None,None]
p.file = [None,None]
+ p.ephem = [False,False]
p.spec = None
+ p.spec_tbp = None
p.dir = ''
def __repr__(p):
xtra = ''
if p.spec is not None:
xtra = ' spec[%s]=%s' % (p.spec, getattr(p,'spec_tb',None))
- raise ("internal error: %s (%s)" % (how, str(p)))
+ raise Exception("internal error: %s (%s)" % (how, str(p)))
def _ensure_path(p, tbp):
if p.path[tbp] is None:
if not tbp:
p.path[tbp] = tmpdir+'/'+p.what
else:
+ p.ephem[tbp] = True
p.path[tbp] = testbed.scratch.path[True]+'/'+p.what
def write(p, tbp=False):
return p.file[tbp] + p.dir
def invalidate(p, tbp=False):
+ if p.path[tbp] is not None:
+ p._debug('invalidating %s' % 'HT'[tbp])
p.file[tbp] = None
- p._debug('invalidated %s' % 'HT'[tbp])
+ if p.spec_tbp != tbp or p.spec is None:
+ p.path[tbp] = None
+
+ def invalidate_ephem(p, tbp=False):
+ if p.ephem[tbp]:
+ p.invalidate(tbp)
def _debug(p, m):
debug('/ %s#%x: %s' % (p.what, id(p), m), 3)
def _constructed(p):
p._debug('constructed: '+str(p))
p._check()
+ paths.append(p)
def _check(p):
for tbp in [False,True]:
if sibling: trim = os.path.dirname
else: trim = lambda x: x
for tbp in [False,True]:
+ p.ephem[tbp] = parent.ephem[tbp]
if parent.path[tbp] is None: continue
trimmed = trim(parent.path[tbp])
if trimmed: trimmed += '/'
p.dir = '/'
p._constructed()
+class RelativeInputDir(AutoFile):
+ def __init__(p, what, parent, leaf, onlyon_tbp=None, sibling=False):
+ p._relative_init(what, parent, leaf, onlyon_tbp, True, sibling)
+ 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)
help='run tests as USER (needs root on testbed)')
pa('','--gain-root', type='string', dest='gainroot',
help='prefix debian/rules binary with GAINROOT')
- pa('-q', '--quiet', action='store_false', dest='quiet', default=False);
+ pa('-q', '--quiet', action='store_true', dest='quiet', default=False);
pa('-d', '--debug', action='count', dest='debuglevel', default=0);
pa('','--gnupg-home', type='string', dest='gnupghome',
default='~/.autopkgtest/gpg',
elif type(act) == str:
act = (act,act)
else:
- raise ("unknown action in list `%s' having"
+ raise Exception("unknown action in list `%s' having"
" type `%s'" % (act, type(act)))
(pathstr, kindpath) = act
tb.scratch = None
tb.modified = False
tb.blamed = []
- tb._ephemeral = []
tb._debug('init')
tb._need_reset_apt = False
def _debug(tb, m, minlevel=0):
stdin=p, stdout=p, stderr=tb._errplumb.stream)
tb.expect('ok')
tb.caps = tb.commandr('capabilities')
- if not 'print-execute-command' in tb.caps:
- tb.bomb('testbed does not support print-execute-command')
def stop(tb):
tb._debug('stop')
tb.close()
tb._debug('open, scratch=%s' % tb.scratch)
if tb.scratch is not None: return
pl = tb.commandr('open')
+ tb._opened(pl)
+ def _opened(tb, pl):
tb.scratch = InputDir('tb-scratch', pl[0], True)
tb.deps_processed = []
+ for af in paths: af.invalidate_ephem(True)
tb._auxverbscript_make()
-
def _auxverbscript_make(tb):
- pec = tb.commandr('print-execute-command')
- if len(pec) < 2: tb.bomb('too few results from print-execute-command')
- tb.ec_cmdl = map(urllib.unquote, pec[0].split(','))
- tb.ec_mode = urllib.unquote(pec[1])
- tb.ec_infos = map(urllib.unquote,pec[2:])
-
- shellquote_re = regexp.compile(r'([\\"$`])')
- def shellquote_arg(s): return '"' + shellquote_re.sub(r'\\\1', s) + '"'
- def shellquote_cmdl(l): return ' '.join(map(shellquote_arg,l))
+ pec = tb.commandr('print-auxverb-command')
+ if len(pec) < 1: tb.bomb('too few results from print-execute-command')
+ cmdl = map(urllib.unquote, pec[0].split(','))
- tb._debug('tb.ec_cmdl = %s' % (`tb.ec_cmdl`))
+ tb._debug('cmdl = %s' % (`cmdl`))
tb.ec_auxverbscript = TemporaryFile('satdep-auxverb')
print >>open(tb.ec_auxverbscript.write(),'w'), (
'''#!/bin/sh
-set -ex
-echo >&2 ": $*"
+set -e
if [ $# = 2 ] && [ "x$1" = xdpkg-architecture ] && [ "x$2" = x-qDEB_HOST_ARCH ]; then
+ # This is a pretty nasty hack. Hopefully it can go away
+ # eventually. See #635763.
set -- dpkg --print-architecture
fi
-if [ "x$1" = xsh ] && [ "x$2" = x-c ]; then
- shift; shift
- # what a horrible hack!
-fi
-exec '''+shellquote_cmdl(tb.ec_cmdl)+' "$*"'+"\n"
+exec '''+shellquote_cmdl(cmdl)+' "$@"'+"\n"
)
os.chmod(tb.ec_auxverbscript.write(), 0755)
(tb.modified, tb.deps_processed, deps_new), 1)
if 'revert' in tb.caps and (tb.modified or
[d for d in tb.deps_processed if d not in deps_new]):
- for af in tb._ephemeral: af.read(False)
+ for af in paths: af.read(False)
tb._debug('reset **')
- tb.command('revert')
- tb.blamed = []
- for af in tb._ephemeral: af.invalidate(True)
- tb._auxverbscript_make()
+ pl = tb.commandr('revert')
+ tb._opened(pl)
tb.modified = False
def prepare2(tb, deps_new):
tb._debug('prepare2, deps_new=%s' % deps_new, 1)
def prepare(tb, deps_new):
tb.prepare1(deps_new)
tb.prepare2(deps_new)
- def register_ephemeral(tb, af):
- tb._ephemeral.append(af)
def _install_deps(tb, deps_new):
tb._debug(' installing dependencies '+`deps_new`, 1)
tb.deps_processed = deps_new
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))
+ (tb.lastsend, l, len(ll), nresults))
return ll
def commandr(tb, cmd, args=(), nresults=None, unquote=True):
# pass args=[None,...] or =(None,...) to avoid more url quoting
dsc = TemporaryFile('deps.dsc')
print >>open(dsc.write(),'w'), 'Build-Depends: ', deps, '\n\n'
# pbuilder-satisfydepends has a bug where it ignores the
- # Build-Depends if it's the last line in the dsc
+ # Build-Depends if it's the last line in the dsc (#635696)
tb.satisfy_dependencies_dsc(dsc, what)
def satisfy_dependencies_dsc(tb, dsc, what):
'--internal-chrootexec',tb.ec_auxverbscript.read(),
'-c',dsc.read()
]
+ # The --internal-chrootexec option is really handy but
+ # perhaps we are not supposed to use it ? See also #635697.
debug('dependencies: %s: running %s' % (what,`cmdl`))
rc = subprocess.call(cmdl, stdout=None, stderr=None)
if rc: badpkg('dependency install failed, exit code %d' % rc)
def __init__(r,rname,base): pass
class Restriction_rw_build_tree(Restriction): pass
+class Restriction_build_neeeded(Restriction): pass
class Restriction_breaks_testbed(Restriction):
def __init__(r, rname, base):
- if 'revert' not in testbed.caps:
+ if 'revert-full-system' not in testbed.caps:
raise Unsupported(f.lno,
- 'Test breaks testbed but testbed cannot revert')
+ 'Test breaks testbed but testbed does not advertise revert-full-system')
class Restriction_needs_root(Restriction):
def __init__(r, rname, base):
if 'root-on-testbed' not in testbed.caps:
return []
lno = 0
- def badctrl(m): act.bomb('tests/control line %d: %s' % (lno, m))
- stz = None # stz[field_name][index] = (lno, value)
+ def badctrl(m): testbed.bomb('tests/control line %d: %s' % (lno, m))
+ stz = { } # stz[field_name][index] = (lno, value)
# special field names:
# stz[' lno'] = number
# stz[' tests'] = list of Test objects
+ # empty dictionary means we're between stanzas
+ def in_stanza(stz):
+ return stz.has_key(' lno')
def end_stanza(stz):
- if stz is None: return
+ if not in_stanza(stz): return
stz[' errs'] = 0
- stanzas.append(stz)
- stz = None
+ stanzas.append(stz.copy())
+ stz.clear()
hcurrent = None
- initre = regexp.compile('([A-Z][-0-9a-z]*)\s*\:\s*(.*)$')
+ initre = regexp.compile('([A-Z][-0-9a-zA-Z]*)\s*\:\s*(.*)$')
while 1:
l = control.readline()
if not l: break
if initmat:
(fname, l) = initmat.groups()
fname = string.capwords(fname)
- if stz is None:
+ if not in_stanza(stz):
stz = { ' lno': lno, ' tests': [] }
if not stz.has_key(fname): stz[fname] = [ ]
hcurrent = stz[fname]
if not act.pkg: badpkg('no good Package: line in control file')
class Binaries:
- def __init__(b):
+ def __init__(b, tb):
b.dir = TemporaryDir('binaries')
b.dir.write()
ok = False
def apt_configs(b):
return {
- "Dir::Etc::sourcelist": b.dir.read(True)+'sources.list',
"Debug::pkgProblemResolver": "true",
+ "APT::Get::force-yes" : "true",
+ "APT::Get::Assume-Yes" : "true",
+ "quiet" : "true",
}
def _configure_apt(b, tb):
for (k,v) in b.apt_configs().iteritems():
print >>f, '%s { "%s"; };' % (k, v)
f.close()
+ config.read(True)
+
+ prefs = OutputFile('apt-prefs','/etc/apt/preferences.d/90autopkgtest',
+ True)
+ print >>open(prefs.write(),'w'), '''
+Package: *
+Pin: origin ""
+Pin-Priority: 1002
+'''
+ prefs.read(True)
def _apt_get(b):
- ag = ['apt-get','-qy']
+ ag = ['apt-get','-q']
for kv in b.apt_configs().iteritems():
ag += ['-o', '%s=%s' % kv]
return ' '.join(ag)
script = '''
exec 3>&1 >&2
apt-key add archive-key.pgp
- echo "deb file://'''+apt_source+''' /" >sources.list
- cat /etc/apt/sources.list >>sources.list
+ echo "deb file://'''+apt_source+''' /" >/etc/apt/sources.list.d/autopkgtest.list
if [ "x`ls /var/lib/dpkg/updates`" != x ]; then
echo >&2 "/var/lib/dpkg/updates contains some files, aargh"; exit 1
fi
stanzas = read_control(act, result_pwd_af, control_override)
for stanza in stanzas:
for t in stanza[' tests']:
- if 'no-build-needed' not in t.feature_names:
+ if 'build-needed' in t.restriction_names:
build_needed('test %s' % t.tname)
- for d in t.depends:
- if '@' in d:
- build_needed('test %s '
- 'dependency %s' % (t.tname,d))
debug_b('build not needed')
built = False
built = True
- act.tests_tree = InputDir(what+'-tests-tree',
- work.read(True)+os.path.basename(result_pwd),
+ act.tests_tree = RelativeInputDir(what+'-tests-tree',
+ work, os.path.basename(result_pwd),
True)
- if act.ah['dsc_tests']:
- testbed.register_ephemeral(act.work)
- testbed.register_ephemeral(act.tests_tree)
if not built:
act.blamed = []
debug_a1('starting')
testbed.open()
- binaries = Binaries()
-
- for act in opts.actions:
- if act.af is not None and not act.af.spec_tbp:
- testbed.register_ephemeral(act.af)
+ binaries = Binaries(testbed)
binaries.reset()
control_override = None