3 # adt-run is part of autopkgtest
4 # autopkgtest is a tool for testing Debian binary packages
6 # autopkgtest is Copyright (C) 2006-2007 Canonical Ltd.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 # See the file CREDITS for a full list of credits information (often
23 # installed as /usr/share/doc/autopkgtest/CREDITS).
40 from optparse import OptionParser
41 signal.signal(signal.SIGINT, signal.SIG_DFL) # undo stupid Python SIGINT thing
43 try: our_base = os.environ['AUTOPKGTEST_BASE']+'/lib'
44 except KeyError: our_base = '/usr/share/autopkgtest/python';
45 sys.path.insert(1, our_base)
47 from Autopkgtest import *
49 #---------- global variables
51 tmp = None # pathstring on host
52 testbed = None # Testbed
53 errorcode = 0 # exit status that we are going to use
54 timeouts = { 'short':100, 'install':3000, 'test':10000, 'build':100000 }
55 binaries = None # Binaries (.debs we have registered)
56 build_essential = ["build-essential"]
58 os.putenv("APT_LISTBUGS_FRONTEND", "none") # do not consider using apt-listbugs
59 os.putenv("APT_LISTCHANGES_FRONTEND", "none") # do not consider using apt-listchanges
61 #---------- output handling
63 # There are at least the following kinds of output:
65 # 1. stderr output which consists of
67 # 1b. stuff printed to stderr by the virtualisation server
68 # 1c. stuff printed to stderr by our short-lived subprocesseses
69 # which we don't expect to fail
71 # 2. trace information, which consists of
72 # 2a. our trace information from calls to debug()
73 # 2b. progress information and stderr output from
74 # general scripts we run on the host
75 # 2c. progress information and stderr output from things
76 # we run on the testbed including builds
77 # 2d. stderr and stdout output from actual tests
80 # 3. actual test results (printed to our stdout)
82 # Cloning of 1a and 2a, where necessary, is done by us writing
83 # the data twice. Cloning of 1[bc] and 2[bc], where necessary,
84 # is done by forking off a copy of ourselves to do plumbing,
85 # which copy we wait for at the appropriate point.
88 def __init__(do): do.debuglevel = 0
96 if trace_stream is not None: print >>trace_stream, m
98 def debug(m, minlevel=0):
99 if opts.debuglevel < minlevel: return
100 if opts.quiet and trace_stream is None: return
102 if minlevel: p += `minlevel`
104 for l in m.rstrip('\n').split('\n'):
106 if not opts.quiet: print >>sys.stderr, s
107 if trace_stream is not None: print >>trace_stream, s
109 def debug_file(hp, minlevel=0):
110 if opts.debuglevel < minlevel: return
111 def do_copy(stream, what):
112 rc = subprocess.call(['cat',hp], stdout=stream)
113 if rc: bomb('cat failed copying data from %s'
114 ' to %s, exit code %d' % (hp, what, rc))
115 if not opts.quiet: do_copy(sys.stderr, 'stderr')
116 if trace_stream is not None: do_copy(trace_stream, 'trace log')
119 def __init__(ep, critical=False):
120 to_stderr = critical or not opts.quiet
121 count = to_stderr + (trace_stream is not None)
123 ep.stream = open('/dev/null','w')
126 if to_stderr: ep.stream = os.dup(2)
127 else: ep.stream = trace_stream
130 ep._sp = subprocess.Popen(['tee','-a','/dev/stderr'],
131 stdin=subprocess.PIPE, stdout=trace_stream,
133 ep.stream = ep._sp.stdin
135 if ep._sp is None: return
136 if type(ep.stream) == type(2):
141 if rc: bomb('stderr plumbing tee(1) failed, exit code %d' % rc)
144 def subprocess_cooked(cmdl, critical=False, dbg=None, **kwargs):
146 if isinstance(dbg,tuple): (what,script) = dbg
147 else: (what,script) = (dbg,None)
148 debug_subprocess(what, cmdl, script=script)
149 ep = Errplumb(critical)
150 running = subprocess.Popen(cmdl, stderr=ep.stream, **kwargs)
151 output = running.communicate()[0]
157 if summary_stream is not None: print >>summary_stream, m
162 if trace_stream is not None: print >>trace_stream, m
165 def report(tname, result):
166 preport('%-20s %s' % (tname, result))
168 #---------- errors we define
171 def __init__(q,ec,m): q.ec = ec; q.m = m
174 raise Quit(20, "unexpected error: %s" % m)
177 preport('blame: ' + ' '.join(testbed.blamed))
178 preport('badpkg: ' + m)
179 raise Quit(12, "erroneous package: %s" % m)
182 def __init__(u, lno, m):
183 if lno >= 0: u.m = '%s (control line %d)' % (m, lno)
185 def report(u, tname):
188 report(tname, 'SKIP %s' % u.m)
190 #---------- convenience function
192 def mkdir_okexist(pathname, mode=02755):
194 os.mkdir(pathname, mode)
195 except (IOError,OSError), oe:
196 if oe.errno != errno.EEXIST: raise
198 def rmtree(what, pathname):
199 debug('/ %s rmtree %s' % (what, pathname), 2)
200 try: shutil.rmtree(pathname)
201 except (IOError,OSError), oe:
202 if oe.errno != errno.EEXIST: raise
204 def debug_subprocess(what, cmdl=None, script=None):
209 if x is script: x = '<SCRIPT>'
210 ol.append(x. replace('\\','\\\\').
212 o += ' '+ ' '.join(ol)
214 if script is not None and opts.debuglevel >= 1:
216 for l in script.rstrip('\n').split('\n'):
221 return reduce((lambda a,b: a + b), l, [])
223 #---------- fancy automatic file-copying class
227 # p.path[tb] None or path not None => path known
228 # p.file[tb] None or path not None => file exists
229 # p.ephem[tb] boolean True => destroyed by tb reset
230 # p.spec string or None
231 # p.spec_tbp True or False, or not set if spec is None
234 def __init__(p, what):
238 p.ephem = [False,False]
244 return "<AF@%s>" % p.__str__()
247 if p.path[tbp] is None: return '-'+p.dir
248 elif p.file[tbp] is None: return p.path[tbp]+p.dir+'?'
249 else: return p.path[tbp]+p.dir+'!'
251 if p.spec is not None:
252 if not hasattr(p,'spec_tb'): out += '~'
253 elif p.spec_tbp: out += '#'
264 if p.spec is not None:
265 xtra = ' spec[%s]=%s' % (p.spec, getattr(p,'spec_tb',None))
266 raise Exception("internal error: %s (%s)" % (how, str(p)))
268 def _ensure_path(p, tbp):
269 if p.path[tbp] is None:
271 p._debug('tmp-parent %s...' % 'HT'[tbp])
272 TemporaryDir(os.path.dirname(p.what)).write(tbp)
274 p.path[tbp] = tmp+'/'+p.what
277 p.path[tbp] = testbed.scratch.path[True]+'/'+p.what
279 def write(p, tbp=False):
280 p._debug('write %s...' % 'HT'[tbp])
283 if p.dir and not p.file[tbp]:
286 mkdir_okexist(p.path[tbp])
289 'test -d "$1" || mkdir -p "$1"',
291 tf_what = urllib.quote(p.what).replace('/','%2F')
292 rc = testbed.execute('mkdir-'+tf_what, cmdl)
293 if rc: bomb('failed to create directory %s' %
296 p.file[tbp] = p.path[tbp]
299 def read(p, tbp=False):
300 p._debug('read %s...' % 'HT'[tbp])
303 if p.file[tbp] is None:
304 if p.file[not tbp] is None:
305 p._wrong("requesting read but nonexistent")
306 cud = ['copyup','copydown'][tbp]
307 src = p.file[not tbp] + p.dir
308 dst = p.path[tbp] + p.dir
309 testbed.command(cud, (src, dst))
310 p.file[tbp] = p.path[tbp]
312 return p.file[tbp] + p.dir
314 def invalidate(p, tbp=False):
315 if p.path[tbp] is not None:
316 p._debug('invalidating %s' % 'HT'[tbp])
318 if p.spec_tbp != tbp or p.spec is None:
321 def invalidate_ephem(p, tbp=False):
326 debug('/ %s#%x: %s' % (p.what, id(p), m), 3)
329 p._debug('constructed: '+str(p))
334 for tbp in [False,True]:
335 for pf in [p.path, p.file]:
336 if pf[tbp] is None: continue
337 if not pf[tbp]: bomb('empty path specified for %s' % p.what)
338 if p.dir and pf[tbp].endswith('/'):
339 pf[tbp] = pf[tbp].rstrip('/')
340 if not pf[tbp]: pf[tbp] = '/'
341 if not p.dir and pf[tbp].endswith('/'):
342 bomb("directory `%s' specified for "
343 "non-directory %s" % (pf[tbp], p.what))
345 def _relative_init(p, what, parent, leaf, onlyon_tbp, setfiles, sibling):
346 AutoFile.__init__(p,what)
347 sh_on = ''; sh_sibl = ''
348 if onlyon_tbp is not None: sh_on = ' (on %s)' % ('HT'[onlyon_tbp])
349 if sibling: sh_sibl=' (sibling)'
350 parent._debug('using as base: %s: %s%s%s' %
351 (str(parent), leaf, sh_on, sh_sibl))
352 if not sibling and not parent.dir:
353 parent._wrong('asked for non-sibling relative path of non-dir')
354 if sibling: trim = os.path.dirname
355 else: trim = lambda x: x
356 for tbp in [False,True]:
357 p.ephem[tbp] = parent.ephem[tbp]
358 if parent.path[tbp] is None: continue
359 trimmed = trim(parent.path[tbp])
360 if trimmed: trimmed += '/'
361 p.path[tbp] = trimmed + leaf
362 if setfiles and (onlyon_tbp is None or onlyon_tbp == tbp):
363 p.file[tbp] = p.path[tbp]
365 class InputFile(AutoFile):
366 def _init(p, what, spec, spec_tbp=False):
367 AutoFile.__init__(p, what)
369 p.spec_tbp = spec_tbp
370 p.path[spec_tbp] = spec
371 p.file[p.spec_tbp] = p.path[p.spec_tbp]
372 def __init__(p, what, spec, spec_tbp=False):
373 p._init(what,spec,spec_tbp)
376 class InputDir(InputFile):
377 def __init__(p, what, spec, spec_tbp=False):
378 InputFile._init(p,what,spec,spec_tbp)
382 class OutputFile(AutoFile):
383 def _init(p, what, spec, spec_tbp=False):
384 AutoFile.__init__(p, what)
386 p.spec_tbp = spec_tbp
387 p.path[spec_tbp] = spec
388 def __init__(p, what, spec, spec_tbp=False):
389 p._init(what,spec,spec_tbp)
392 class OutputDir(OutputFile):
393 def __init__(p, what, spec, spec_tbp=False):
394 OutputFile._init(p,what,spec,spec_tbp)
398 class RelativeInputDir(AutoFile):
399 def __init__(p, what, parent, leaf, onlyon_tbp=None, sibling=False):
400 p._relative_init(what, parent, leaf, onlyon_tbp, True, sibling)
404 class RelativeInputFile(AutoFile):
405 def __init__(p, what, parent, leaf, onlyon_tbp=None, sibling=False):
406 p._relative_init(what, parent, leaf, onlyon_tbp, True, sibling)
409 class RelativeOutputFile(AutoFile):
410 def __init__(p, what, parent, leaf, sibling=False):
411 p._relative_init(what, parent, leaf, None, False, sibling)
414 class TemporaryFile(AutoFile):
415 def __init__(p, what):
416 AutoFile.__init__(p, what)
419 class TemporaryDir(AutoFile):
420 def __init__(p, what):
421 AutoFile.__init__(p, what)
425 #---------- parsing and representation of the arguments
428 def __init__(a, kind, af, arghandling, what):
429 # extra attributes get added during processing
434 a.missing_tests_control = False
436 return "<Action %s %s %s>" % (a.kind, a.what, `a.af`)
439 global opts, timeouts
440 global n_non_actions # argh, stupid python scoping rules
441 usage = "%prog <options> --- <virt-server>..."
442 parser = OptionParser(usage=usage)
443 pa = parser.add_option
444 pe = parser.add_option
449 'deb_forbuilds': 'auto',
450 'deb_fortests': 'auto',
452 'override_control': None,
455 initial_arghandling = arghandling.copy()
459 # actions (ie, test sets to run, sources to build, binaries to use):
461 def cb_action(op,optstr,value,parser, long,kindpath,is_act):
463 parser.largs.append((value,kindpath))
464 n_non_actions += not(is_act)
466 def pa_action(long, metavar, kindpath, help, is_act=True):
467 pa('','--'+long, action='callback', callback=cb_action,
468 nargs=1, type='string',
469 callback_args=(long,kindpath,is_act), help=help)
471 pa_action('built-tree', 'TREE', '@/',
472 help='run tests from build tree TREE')
474 pa_action('unbuilt-tree', 'TREE', '@//',
475 help='run tests from build tree TREE')
477 pa_action('source', 'DSC', '@.dsc',
478 help='build DSC and use its tests and/or'
479 ' generated binary packages')
481 pa_action('binary', 'DEB', '@.deb',
482 help='use binary package DEB according'
483 ' to most recent --binaries-* settings')
485 def cb_actnoarg(op,optstr,value,parser, largsentry):
486 parser.largs.append(largsentry)
487 pa('','--instantiate', action='callback', callback=cb_actnoarg,
488 callback_args=((None, ('instantiate',)),),
489 help='instantiate testbed now (during testing phase)'
490 ' and install packages'
491 ' selected for automatic installation, even'
492 ' if this might apparently not be required otherwise')
494 pa_action('override-control', 'CONTROL', ('control',), is_act=0,
495 help='run tests from control file CONTROL instead,'
496 ' (applies to next test suite only)')
499 # argument handling settings (what ways to use action
500 # arguments, and pathname processing):
502 def cb_setah(option, opt_str, value, parser, toset,setval):
503 if type(setval) == list:
504 if not value in setval:
505 parser.error('value for %s option (%s) is not '
506 'one of the permitted values (%s)' %
507 (value, opt_str, setval.join(' ')))
508 elif setval is not None:
511 arghandling[v] = value
512 parser.largs.append(arghandling.copy())
514 def pa_setah(long, affected,effect, metavar=None, **kwargs):
516 if type is not None: type = 'string'
517 pa('',long, action='callback', callback=cb_setah,
518 callback_args=(affected,effect), **kwargs)
520 #---- paths: host or testbed:
522 pa_setah('--paths-testbed', ['tb'],True,
523 help='subsequent path specifications refer to the testbed')
524 pa_setah('--paths-host', ['tb'],False,
525 help='subsequent path specifications refer to the host')
527 #---- source processing settings:
529 pa_setah('--sources-tests', ['dsc_tests'],True,
530 help='run tests from builds of subsequent sources')
531 pa_setah('--sources-no-tests', ['dsc_tests'],False,
532 help='do not run tests from builds of subsequent sources')
534 pa_setah('--built-binaries-filter', ['dsc_filter'],None,
535 type='string', metavar='PATTERN-LIST',
536 help='from subsequent sources, use binaries matching'
537 ' PATTERN-LIST (comma-separated glob patterns)'
538 ' according to most recent --binaries-* settings')
539 pa_setah('--no-built-binaries', ['dsc_filter'], '_',
540 help='from subsequent sources, do not use any binaries')
541 #---- binary package processing settings:
543 def pa_setahbins(long,toset,how):
544 pa_setah(long, toset,['ignore','auto','install'],
545 type='string', metavar='IGNORE|AUTO|INSTALL', default='auto',
546 help=how+' ignore binaries, install them as needed'
547 ' for dependencies, or unconditionally install'
548 ' them, respectively')
549 pa_setahbins('--binaries', ['deb_forbuilds','deb_fortests'], '')
550 pa_setahbins('--binaries-forbuilds', ['deb_forbuilds'], 'for builds, ')
551 pa_setahbins('--binaries-fortests', ['deb_fortests'], 'for tests, ')
556 def cb_vserv(op,optstr,value,parser):
557 parser.values.vserver = list(parser.rargs)
560 def cb_path(op,optstr,value,parser, constructor,long,dir):
561 name = long.replace('-','_')
562 af = constructor(long, value,arghandling['tb'])
563 setattr(parser.values, name, af)
565 def pa_path(long, constructor, help, dir=False):
566 pa('','--'+long, action='callback', callback=cb_path,
567 callback_args=(constructor,long,dir),
568 nargs=1, type='string',
569 help=help, metavar='PATH')
571 pa_path('output-dir', OutputDir, dir=True,
572 help='write stderr/out files in PATH')
574 pa('--leave-lang', dest='set_lang', action='store_false',
575 help="leave LANG on testbed set to testbed's default")
576 pa('--set-lang', dest='set_lang', action='store', metavar='LANGVAL',
577 help='set LANG on testbed to LANGVAL', default='C')
579 pa('','--tmp-dir', type='string', dest='tmp',
580 help='write temporary files to TMP, emptying it'
581 ' beforehand and leaving it behind at the end')
582 pa('','--log-file', type='string', dest='logfile',
583 help='write the log LOGFILE, emptying it beforehand,'
584 ' instead of using OUTPUT-DIR/log or TMPDIR/log')
585 pa('','--summary-file', type='string', dest='summary',
586 help='write a summary report to SUMMARY,'
587 ' emptying it beforehand')
589 for k in timeouts.keys():
590 pa('','--timeout-'+k, type='int', dest='timeout_'+k,
591 metavar='T', help='set %s timeout to T')
592 pa('','--timeout-factor', type='float', dest='timeout_factor',
593 metavar='FACTOR', default=1.0,
594 help='multiply all default timeouts by FACTOR')
596 pa('','--user', type='string', dest='user',
597 help='run tests as USER (needs root on testbed)')
598 pa('','--gain-root', type='string', dest='gainroot',
599 help='prefix debian/rules binary with GAINROOT')
600 pa('-q', '--quiet', action='store_true', dest='quiet', default=False);
601 pa('-d', '--debug', action='count', dest='debuglevel', default=0);
602 pa('','--gnupg-home', type='string', dest='gnupghome',
603 default='~/.autopkgtest/gpg',
604 help='use GNUPGHOME rather than ~/.autopkgtest (for'
605 " signing private apt archive);"
606 " `fresh' means generate new key each time.")
611 class SpecialOption(optparse.Option): pass
612 vs_op = SpecialOption('','--VSERVER-DUMMY')
613 vs_op.action = 'callback'
617 vs_op.callback = cb_vserv
618 vs_op.callback_args = ( )
619 vs_op.callback_kwargs = { }
620 vs_op.help = 'introduces virtualisation server and args'
621 vs_op._short_opts = []
622 vs_op._long_opts = ['---']
626 (opts,args) = parser.parse_args()
627 if not hasattr(opts,'vserver'):
628 parser.error('you must specifiy --- <virt-server>...')
629 if n_non_actions >= len(parser.largs):
630 parser.error('nothing to do specified')
632 for k in timeouts.keys():
633 t = getattr(opts,'timeout_'+k)
634 if t is None: t = timeouts[k] * opts.timeout_factor
637 arghandling = initial_arghandling
641 if type(act) == dict:
644 elif type(act) == tuple:
646 elif type(act) == str:
649 raise Exception("unknown action in list `%s' having"
650 " type `%s'" % (act, type(act)))
651 (pathstr, kindpath) = act
653 constructor = InputFile
654 if type(kindpath) is tuple: kind = kindpath[0]
655 elif kindpath.endswith('.deb'): kind = 'deb'
656 elif kindpath.endswith('.dsc'): kind = 'dsc'
657 elif kindpath.endswith('//'):
659 constructor = InputDir
660 elif kindpath.endswith('/'):
662 constructor = InputDir
663 else: parser.error("do not know how to handle filename `%s';"
664 " specify --source --binary or --build-tree" %
667 what = '%s%s' % (kind,ix); ix += 1
669 if kind == 'dsc': fwhatx = '/' + os.path.basename(pathstr)
670 else: fwhatx = '-'+kind
672 if pathstr is None: af = None
673 else: af = constructor(what+fwhatx, pathstr, arghandling['tb'])
674 opts.actions.append(Action(kind, af, arghandling, what))
677 global trace_stream, tmp, summary_stream
679 if opts.tmp is not None:
680 rmtree('tmp(specified)',opts.tmp)
681 mkdir_okexist(opts.tmp, 0700)
685 tmp = tempfile.mkdtemp()
687 if opts.logfile is None:
688 if opts.output_dir is not None and opts.output_dir.spec_tbp:
689 opts.logfile = opts.output_dir.spec + '/log'
690 elif opts.tmp is not None:
691 opts.logfile = opts.tmp + '/log'
692 if opts.logfile is not None:
693 trace_stream = open(opts.logfile, 'w', 0)
694 if opts.summary is not None:
695 summary_stream = open(opts.summary, 'w', 0)
697 debug('options: '+`opts`+'; timeouts: '+`timeouts`, 1)
699 def finalise_options():
700 global opts, tb, build_essential
702 if opts.user is None and 'root-on-testbed' not in testbed.caps:
705 if opts.user is None:
706 su = 'suggested-normal-user='
709 for e in testbed.caps
718 if 'root-on-testbed' not in testbed.caps:
719 pstderr("warning: virtualisation"
720 " system does not offer root on testbed,"
721 " but --user option specified: failure likely")
722 opts.user_wrap = lambda x: "su %s -c '%s'" % (opts.user, x)
724 opts.user_wrap = lambda x: x
726 if opts.gainroot is None:
729 'root-on-testbed' not in testbed.caps):
730 opts.gainroot = 'fakeroot'
731 build_essential += ['fakeroot']
733 if opts.gnupghome.startswith('~/'):
734 try: home = os.environ['HOME']
736 parser.error("HOME environment variable"
737 " not set, needed for --gnupghome=`%s"
739 opts.gnupghome = home + opts.gnupghome[1:]
740 elif opts.gnupghome == 'fresh':
741 opts.gnupghome = None
743 #---------- testbed management - the Testbed class
753 tb._need_reset_apt = False
754 def _debug(tb, m, minlevel=0):
755 debug('** '+m, minlevel)
759 debug_subprocess('vserver', opts.vserver)
760 tb._errplumb = Errplumb(True)
761 tb.sp = subprocess.Popen(opts.vserver,
762 stdin=p, stdout=p, stderr=tb._errplumb.stream)
764 tb.caps = tb.commandr('capabilities')
768 if tb.sp is None: return
769 ec = tb.sp.returncode
776 tb.bomb('testbed gave exit status %d after quit' % ec)
779 tb._debug('open, scratch=%s' % tb.scratch)
780 if tb.scratch is not None: return
781 pl = tb.commandr('open')
784 tb.scratch = InputDir('tb-scratch', pl[0], True)
785 tb.deps_processed = []
786 for af in paths: af.invalidate_ephem(True)
787 tb._auxverbscript_make()
788 def _auxverbscript_make(tb):
789 pec = tb.commandr('print-auxverb-command')
790 if len(pec) < 1: tb.bomb('too few results from print-execute-command')
791 cmdl = map(urllib.unquote, pec[0].split(','))
793 tb._debug('cmdl = %s' % (`cmdl`))
795 tb.ec_auxverbscript = TemporaryFile('satdep-auxverb')
796 print >>open(tb.ec_auxverbscript.write(),'w'), (
799 if [ $# = 2 ] && [ "x$1" = xdpkg-architecture ] && [ "x$2" = x-qDEB_HOST_ARCH ]; then
800 # This is a pretty nasty hack. Hopefully it can go away
801 # eventually. See #635763.
802 set -- dpkg --print-architecture
804 exec '''+shellquote_cmdl(cmdl)+' "$@"'+"\n"
806 os.chmod(tb.ec_auxverbscript.write(), 0755)
808 def mungeing_apt(tb):
809 if not 'revert' in tb.caps:
810 tb._need_reset_apt = True
812 if not tb._need_reset_apt: return
813 what = 'aptget-update-reset'
814 cmdl = ['sh','-c','apt-get -qy update 2>&1']
815 rc = tb.execute(what, cmdl, kind='install')
817 pstderr("\n" "warning: failed to restore"
818 " testbed apt cache, exit code %d" % rc)
819 what = 'aptconf-reset'
820 cmdl = ['rm','-f','/etc/apt/apt.conf.d/90autopkgtest',
821 '/etc/apt/sources.list.d/autopkgtest.list',
822 '/etc/apt/preferences.d/90autopkgtest']
823 rc = tb.execute(what, cmdl, kind='install')
825 pstderr("\n" "warning: failed to reset changes"
826 " made to testbed apt configuration, exit code %d" % rc)
827 tb._need_reset_apt = False
829 tb._debug('close, scratch=%s' % tb.scratch)
830 if tb.scratch is None: return
832 if tb.sp is None: return
834 def prepare1(tb, deps_new):
835 tb._debug('prepare1, modified=%s, deps_processed=%s, deps_new=%s' %
836 (tb.modified, tb.deps_processed, deps_new), 1)
837 if 'revert' in tb.caps and (tb.modified or
838 [d for d in tb.deps_processed if d not in deps_new]):
839 for af in paths: af.read(False)
840 tb._debug('reset **')
841 pl = tb.commandr('revert')
844 def prepare2(tb, deps_new):
845 tb._debug('prepare2, deps_new=%s' % deps_new, 1)
847 tb._install_deps(deps_new)
848 def prepare(tb, deps_new):
849 tb.prepare1(deps_new)
850 tb.prepare2(deps_new)
851 def _install_deps(tb, deps_new):
852 tb._debug(' installing dependencies '+`deps_new`, 1)
853 tb.deps_processed = deps_new
854 if not deps_new: return
855 tb.satisfy_dependencies_string(', '.join(deps_new), 'install-deps')
857 tb._debug('needs_reset, previously=%s' % tb.modified, 1)
860 tb._debug('blame += %s' % m, 1)
863 tb._debug('bomb %s' % m)
864 if tb.sp is not None:
868 if ec: pstderr('adt-run: testbed failing,'
869 ' exit status %d' % ec)
871 raise Quit(16, 'testbed failed: %s' % m)
872 def send(tb, string):
875 debug('>> '+string, 2)
876 print >>tb.sp.stdin, string
880 (type, value, dummy) = sys.exc_info()
881 tb.bomb('cannot send to testbed: %s' % traceback.
882 format_exception_only(type, value))
883 def expect(tb, keyword, nresults=None):
884 l = tb.sp.stdout.readline()
885 if not l: tb.bomb('unexpected eof from the testbed')
886 if not l.endswith('\n'): tb.bomb('unterminated line from the testbed')
890 if not ll: tb.bomb('unexpected whitespace-only line from the testbed')
892 if tb.lastsend is None:
893 tb.bomb("got banner `%s', expected `%s...'" %
896 tb.bomb("sent `%s', got `%s', expected `%s...'" %
897 (tb.lastsend, l, keyword))
899 if nresults is not None and len(ll) != nresults:
900 tb.bomb("sent `%s', got `%s' (%d result parameters),"
901 " expected %d result parameters" %
902 (tb.lastsend, l, len(ll), nresults))
904 def commandr(tb, cmd, args=(), nresults=None, unquote=True):
905 # pass args=[None,...] or =(None,...) to avoid more url quoting
906 if type(cmd) is str: cmd = [cmd]
907 if len(args) and args[0] is None: args = args[1:]
908 else: args = map(urllib.quote, args)
910 tb.send(string.join(al))
911 ll = tb.expect('ok', nresults)
912 if unquote: ll = map(urllib.unquote, ll)
914 def command(tb, cmd, args=()):
915 tb.commandr(cmd, args, 0)
916 def commandr1(tb, cmd, args=()):
917 rl = tb.commandr(cmd, args, 1)
919 def execute(tb, what, cmdl,
920 si='/dev/null', so='/dev/null', se=None, cwd=None,
921 script=False, xenv=[], kind='short'):
922 # Options for script:
923 # False - do not call debug_subprocess, no synch. reporting required
924 # None or string - call debug_subprocess with that value,
925 # plumb stderr through synchronously if possible
927 # None - usual Errplumb (output is of kind 2c)
928 # string - path on testbed (output is of kind 2d)
930 timeout = timeouts[kind]
932 if script is not False: debug_subprocess(what, cmdl, script=script)
933 if cwd is None: cwd = tb.scratch.write(True)
938 se_catch = TemporaryFile(what+'-xerr')
939 se_use = se_catch.write(True)
940 if not opts.quiet: xdump = 'debug=2-2'
941 elif trace_stream is not None:
942 xdump = 'debug=2-%d' % trace_stream.fileno()
949 ','.join(map(urllib.quote, cmdl)),
952 if timeout is not None and timeout > 0:
953 cmdl.append('timeout=%d' % timeout)
955 if xdump is not None and 'execute-debug' in tb.caps: cmdl += [xdump]
956 for e in xenv: cmdl.append('env=%s' % e)
957 if kind=='install': cmdl.append('env=DEBIAN_FRONTEND=noninteractive')
958 if opts.set_lang is not False:
959 cmdl.append('env=LANG=%s' % opts.set_lang)
961 rc = tb.commandr1('execute', cmdl)
963 except ValueError: bomb("execute for %s gave invalid response `%s'"
966 if se_catch is not None:
967 debug_file(se_catch.read())
973 def satisfy_dependencies_string(tb, deps, what):
974 # Must have called Binaries.configure_apt
975 debug('dependencies: %s: satisfying %s' % (what,deps))
976 dsc = TemporaryFile('deps.dsc')
977 print >>open(dsc.write(),'w'), 'Build-Depends: ', deps, '\n\n'
978 # pbuilder-satisfydepends has a bug where it ignores the
979 # Build-Depends if it's the last line in the dsc (#635696)
980 tb.satisfy_dependencies_dsc(dsc, what)
982 def satisfy_dependencies_dsc(tb, dsc, what):
983 # Must have called Binaries.configure_apt
984 cmdl = [ '/usr/lib/pbuilder/pbuilder-satisfydepends-classic',
985 '--binary-all', # --check-key
986 '--internal-chrootexec',tb.ec_auxverbscript.read(),
989 # The --internal-chrootexec option is really handy but
990 # perhaps we are not supposed to use it ? See also #635697.
991 debug('dependencies: %s: running %s' % (what,`cmdl`))
992 rc = subprocess.call(cmdl, stdout=None, stderr=None)
993 if rc: badpkg('dependency install failed, exit code %d' % rc)
995 #---------- representation of test control files: Field*, Test, etc.
998 def __init__(f, fname, stz, base, tnames, vl):
1005 def distribute(vle):
1008 r = map((lambda w: (lno, w)), r)
1010 return flatten(map(distribute, f.vl))
1013 (f.lno, f.v) = vl[0]
1015 raise Unsupported(f.vl[1][0],
1016 'only one %s field allowed' % fn)
1019 class FieldIgnore(FieldBase):
1023 def __init__(r,rname,base): pass
1025 class Restriction_rw_build_tree(Restriction): pass
1026 class Restriction_build_needed(Restriction): pass
1027 class Restriction_breaks_testbed(Restriction):
1028 def __init__(r, rname, base):
1029 if 'revert-full-system' not in testbed.caps:
1030 raise Unsupported(-1,
1031 'Test breaks testbed but testbed does not advertise revert-full-system')
1032 class Restriction_needs_root(Restriction):
1033 def __init__(r, rname, base):
1034 if 'root-on-testbed' not in testbed.caps:
1035 raise Unsupported(-1,
1036 'Test needs root on testbed which is not available')
1038 class Field_Restrictions(FieldBase):
1040 for wle in f.words():
1042 nrname = rname.replace('-','_')
1043 try: rclass = globals()['Restriction_'+nrname]
1044 except KeyError: raise Unsupported(lno,
1045 'unknown restriction %s' % rname)
1046 r = rclass(nrname, f.base)
1047 f.base['restriction_names'].append(rname)
1048 f.base['restrictions'].append(r)
1050 class Field_Features(FieldIgnore):
1052 for wle in f.words():
1054 f.base['feature_names'].append(fname)
1055 nfname = fname.replace('-','_')
1056 try: fclass = globals()['Feature_'+nfname]
1057 except KeyError: continue
1058 ft = fclass(nfname, f.base)
1059 f.base['features'].append(ft)
1061 class Field_Tests(FieldIgnore): pass
1063 class Field_Depends(FieldBase):
1065 debug("Field_DependS: %s %s %s %s" % (f.stz, f.base, f.tnames, f.vl), 2)
1066 dl = map(lambda x: x.strip(),
1067 flatten(map(lambda (lno, v): v.split(','), f.vl)))
1068 re = regexp.compile('[^-.+:~0-9a-z()<>=*@]')
1071 badpkg("Test Depends field contains dependency"
1072 " `%s' with invalid characters" % d)
1073 f.base['depends'] = dl
1075 class Field_Tests_directory(FieldBase):
1078 if td.startswith('/'): raise Unspported(f.lno,
1079 'Tests-Directory may not be absolute')
1080 f.base['testsdir'] = td
1082 def run_tests(stanzas, tree):
1083 global errorcode, testbed
1085 report('*', 'SKIP no tests in this package')
1087 for stanza in stanzas:
1088 tests = stanza[' tests']
1090 report('*', 'SKIP package has metadata but no tests')
1095 if 'breaks-testbed' in t.restriction_names:
1096 testbed.needs_reset()
1097 testbed.needs_reset()
1100 def __init__(t, tname, base, act):
1101 if '/' in tname: raise Unsupported(base[' lno'],
1102 'test name may not contain / character')
1103 for k in base: setattr(t,k,base[k])
1106 t.what = act.what+'t-'+tname
1107 if len(base['testsdir']): t.path = base['testsdir'] + '/' + tname
1108 else: t.path = tname
1109 t._debug('constructed; path=%s' % t.path)
1110 t._debug(' .depends=%s' % t.depends)
1112 debug('& %s: %s' % (t.what, m))
1115 def reportfail(t, m):
1118 report(t.what, 'FAIL ' + m)
1119 def prepare(t, tree):
1120 t._debug('preparing')
1123 t._debug(' processing dependency '+d)
1125 t._debug(' literal dependency '+d)
1128 for pkg in packages_from_source(t.act, tree):
1129 dp = d.replace('@',pkg)
1130 t._debug(' synthesised dependency '+dp)
1134 t._debug('[----------------------------------------')
1136 idstr = t.what + '-' + oe
1137 if opts.output_dir is not None and opts.output_dir.spec_tbp:
1138 use_dir = opts.output_dir
1140 use_dir = testbed.scratch
1141 return RelativeOutputFile(idstr, use_dir, idstr)
1143 if hasattr(t.act,'work'): t.act.work.write(True)
1146 af = RelativeInputFile(t.what, tree, t.path)
1147 so = stdouterr('stdout')
1148 se = stdouterr('stderr')
1153 rc = testbed.execute('testchmod-'+t.what, ['chmod','+x','--',tf])
1154 if rc: bomb('failed to chmod +x %s' % tf)
1156 testtmp = '%s%s-testtmp' % (testbed.scratch.read(True), t.what)
1158 script = 'buildtree="$1"; shift\n'
1159 script += 'rm -rf -- "$@"; mkdir -- "$@"\n'
1161 if 'needs-root' not in t.restriction_names and opts.user is not None:
1162 tfl = ['su',opts.user,'-c',tf]
1164 script += 'chown %s "$@"\n' % opts.user
1165 if 'rw-build-tree' in t.restriction_names:
1166 script += ('chown -R %s "$buildtree"\n'
1171 test_tmpdir = testtmp+'/tmpdir'; xenv.append('TMPDIR=%s' % test_tmpdir)
1172 test_adttmp = testtmp+'/adttmp'; xenv.append('ADTTMP=%s' % test_adttmp)
1173 rc = testbed.execute('mktmpdir-'+t.what,
1174 ['sh','-xec',script,'x', tree.read(True),
1175 testtmp, test_tmpdir, test_adttmp,
1177 if rc: bomb("could not create test tmp dirs in `%s', exit code %d"
1180 rc = testbed.execute('test-'+t.what, tfl,
1181 so=so.write(True), se=se.write(True), cwd=tree.read(True),
1182 xenv=xenv, kind='test')
1187 t._debug(' - - - - - - - - - - results - - - - - - - - - -')
1188 stab = os.stat(se_read)
1189 if stab.st_size != 0:
1190 l = open(se_read).readline()
1191 l = l.rstrip('\n \t\r')
1192 if len(l) > 35: l = l[:35] + '...'
1193 t.reportfail('status: %d, stderr: %s' % (rc, l))
1194 t._debug(' - - - - - - - - - - stderr - - - - - - - - - -')
1197 t.reportfail('non-zero exit status %d' % rc)
1201 stab = os.stat(so_read)
1202 if stab.st_size != 0:
1203 t._debug(' - - - - - - - - - - stdout - - - - - - - - - -')
1206 t._debug('----------------------------------------]')
1208 def read_stanzas(af):
1212 control = open(af.read(), 'r')
1213 except (IOError,OSError), oe:
1214 if oe[0] != errno.ENOENT: raise
1218 def badctrl(m): testbed.bomb('tests/control line %d: %s' % (lno, m))
1219 stz = { } # stz[field_name][index] = (lno, value)
1220 # special field names:
1221 # stz[' lno'] = number
1222 # stz[' tests'] = list of Test objects
1223 # empty dictionary means we're between stanzas
1225 return stz.has_key(' lno')
1226 def end_stanza(stz):
1227 if not in_stanza(stz): return
1229 stanzas.append(stz.copy())
1233 initre = regexp.compile('([A-Z][-0-9a-zA-Z]*)\s*\:\s*(.*)$')
1235 l = control.readline()
1238 if not l.endswith('\n'): badctrl('unterminated line')
1239 if regexp.compile('\s*\#').match(l): continue
1240 if not regexp.compile('\S').match(l): end_stanza(stz); continue
1241 initmat = initre.match(l)
1243 (fname, l) = initmat.groups()
1244 fname = string.capwords(fname)
1245 if not in_stanza(stz):
1246 stz = { ' lno': lno, ' tests': [] }
1247 if not stz.has_key(fname): stz[fname] = [ ]
1248 hcurrent = stz[fname]
1249 elif regexp.compile('\s').match(l):
1250 if not hcurrent: badctrl('unexpected continuation')
1252 badctrl('syntax error')
1253 hcurrent.append((lno, l))
1258 def read_control(act, tree, control_override):
1260 if control_override is not None:
1261 control_af = control_override
1262 testbed.blame('arg:'+control_override.spec)
1264 if act.missing_tests_control:
1266 control_af = RelativeInputFile(act.what+'-testcontrol',
1267 tree, 'debian/tests/control')
1269 stanzas = read_stanzas(control_af)
1271 def testbadctrl(stz, lno, m):
1272 report_badctrl(lno, m)
1277 try: tnames = stz['Tests']
1280 raise Unsupported(stz[' lno'],
1282 tnames = map((lambda lt: lt[1]), tnames)
1283 tnames = string.join(tnames).split()
1285 'restriction_names': [],
1287 'feature_names': [],
1289 'testsdir': 'debian/tests',
1292 for fname in stz.keys():
1293 if fname.startswith(' '): continue
1295 try: fclass = globals()['Field_'+
1296 fname.replace('-','_')]
1297 except KeyError: raise Unsupported(vl[0][0],
1298 'unknown metadata field %s' % fname)
1299 f = fclass(stz, fname, base, tnames, vl)
1301 for tname in tnames:
1302 t = Test(tname, base, act)
1303 stz[' tests'].append(t)
1304 except Unsupported, u:
1305 for tname in tnames: u.report(tname)
1310 def print_exception(ei, msgprefix=''):
1311 if msgprefix: pstderr(msgprefix)
1314 pstderr('adt-run: ' + q.m)
1315 psummary('quitting: '+q.m)
1318 pstderr("adt-run: unexpected, exceptional, error:")
1319 psummary('quitting: unexpected error, consult transcript')
1320 traceback.print_exc(None, sys.stderr)
1321 if trace_stream is not None:
1322 traceback.print_exc(None, trace_stream)
1328 if testbed is not None:
1331 if opts.tmp is None and tmp is not None:
1333 if trace_stream is not None:
1334 trace_stream.close()
1337 print_exception(sys.exc_info(),
1338 '\nadt-run: error cleaning up:\n')
1341 #---------- registration, installation etc. of .deb's: Binaries
1343 def determine_package(act):
1344 cmd = 'dpkg-deb --info --'.split(' ')+[act.af.read(),'control']
1345 (rc, output) = subprocess_cooked(cmd, stdout=subprocess.PIPE)
1346 if rc: badpkg('failed to parse binary package, code %d' % rc)
1347 re = regexp.compile('^\s*Package\s*:\s*([0-9a-z][-+.0-9a-z]*)\s*$')
1349 for l in output.split('\n'):
1352 if act.pkg: badpkg('two Package: lines in control file')
1353 act.pkg = m.groups()[0]
1354 if not act.pkg: badpkg('no good Package: line in control file')
1356 def packages_from_source(act, tree):
1357 (rc, output) = subprocess_cooked(['dh_listpackages'],
1358 stdout=subprocess.PIPE, cwd=tree.read(True))
1359 if rc: badpkg('failed to parse packages built from source, code %d' % rc)
1361 # filter out empty lines
1362 packages = [p for p in output.split() if p]
1365 control_af = RelativeInputFile(act.what+'-control',
1366 tree, 'debian/control')
1367 for st in read_stanzas(control_af):
1368 if 'Package' not in st:
1371 if 'Xc-package-type' in st:
1373 packages.remove(st['Package'][0][1])
1380 def __init__(b, tb):
1381 b.dir = TemporaryDir('binaries')
1385 if opts.gnupghome is None:
1386 opts.gnupghome = tmp+'/gnupg'
1388 b._debug('initialising')
1390 for x in ['pubring','secring']:
1391 os.stat(opts.gnupghome + '/' + x + '.gpg')
1393 except (IOError,OSError), oe:
1394 if oe.errno != errno.ENOENT: raise
1396 if ok: b._debug('no key generation needed')
1403 b._debug('preparing for key generation')
1405 mkdir_okexist(os.path.dirname(opts.gnupghome), 02755)
1406 mkdir_okexist(opts.gnupghome, 0700)
1411 cat <<"END" >key-gen-params
1415 Name-Real: autopkgtest per-run key
1416 Name-Comment: do not trust this key
1417 Name-Email: autopkgtest@example.com
1420 gpg --homedir="$1" --batch --gen-key key-gen-params
1422 cmdl = ['sh','-ec',script,'x',opts.gnupghome]
1423 rc = subprocess_cooked(cmdl, dbg=('genkey',script))[0]
1424 if rc: bomb('key generation failed, code %d' % rc)
1428 "Debug::pkgProblemResolver": "true",
1429 "APT::Get::force-yes" : "true",
1430 "APT::Get::Assume-Yes" : "true",
1434 def _configure_apt(b, tb):
1435 config = OutputFile('apt-config','/etc/apt/apt.conf.d/90autopkgtest',
1437 f = open(config.write(),'w')
1438 for (k,v) in b.apt_configs().iteritems():
1439 print >>f, '%s { "%s"; };' % (k, v)
1443 prefs = OutputFile('apt-prefs','/etc/apt/preferences.d/90autopkgtest',
1445 print >>open(prefs.write(),'w'), '''
1453 ag = ['apt-get','-q']
1454 for kv in b.apt_configs().iteritems():
1455 ag += ['-o', '%s=%s' % kv]
1460 rmtree('binaries', b.dir.read())
1465 b.registered = set()
1467 def register(b, act, pkg, af, forwhat, blamed):
1468 b._debug('register what=%s deb_%s=%s pkg=%s af=%s'
1469 % (act.what, forwhat, act.ah['deb_'+forwhat], pkg, str(af)))
1471 if act.ah['deb_'+forwhat] == 'ignore': return
1473 b.blamed += testbed.blamed
1475 leafname = pkg+'.deb'
1476 dest = RelativeOutputFile('binaries--'+leafname, b.dir, leafname)
1478 try: os.remove(dest.write())
1479 except (IOError,OSError), oe:
1480 if oe.errno != errno.ENOENT: raise e
1482 try: os.link(af.read(), dest.write())
1483 except (IOError,OSError), oe:
1484 if oe.errno != errno.EXDEV: raise e
1485 shutil.copy(af.read(), dest)
1487 if act.ah['deb_'+forwhat] == 'install':
1488 b.install.append(pkg)
1490 b.registered.add(pkg)
1495 b._configure_apt(testbed)
1500 apt-ftparchive packages . >Packages
1501 gzip <Packages >Packages.gz
1502 apt-ftparchive release . >Release
1504 gpg --homedir="$2" --batch --detach-sign --armour -o Release.gpg Release
1505 gpg --homedir="$2" --batch --export >archive-key.pgp
1507 cmdl = ['sh','-ec',script,'x',b.dir.write(),opts.gnupghome]
1508 rc = subprocess_cooked(cmdl, dbg=('ftparchive',script))[0]
1509 if rc: bomb('apt-ftparchive or signature failed, code %d' % rc)
1511 b.dir.invalidate(True)
1512 apt_source = b.dir.read(True)
1514 so = TemporaryFile('vlds')
1517 apt-key add archive-key.pgp
1518 echo "deb file://'''+apt_source+''' /" >/etc/apt/sources.list.d/autopkgtest.list
1519 if [ "x`ls /var/lib/dpkg/updates`" != x ]; then
1520 echo >&2 "/var/lib/dpkg/updates contains some files, aargh"; exit 1
1522 '''+ b._apt_get() +''' update >&2
1523 cat /var/lib/dpkg/status >&3
1525 testbed.mungeing_apt()
1526 rc = testbed.execute('apt-key', ['sh','-ec',script],
1527 so=so.write(True), cwd=b.dir.write(True),
1528 script=script, kind='install')
1529 if rc: bomb('apt setup failed with exit code %d' % rc)
1531 testbed.blamed += b.blamed
1533 b._debug('publish reinstall checking...')
1534 pkgs_reinstall = set()
1536 for l in open(so.read()):
1537 if l.startswith('Package: '):
1538 pkg = l[9:].rstrip()
1539 elif l.startswith('Status: install '):
1540 if pkg in b.registered:
1541 pkgs_reinstall.add(pkg)
1542 b._debug(' publish reinstall needs '+pkg)
1545 for pkg in pkgs_reinstall: testbed.blame(pkg)
1546 what = 'apt-get-reinstall'
1547 cmdl = (b._apt_get() + ' --reinstall install '+
1548 ' '.join([pkg for pkg in pkgs_reinstall])+' >&2')
1549 cmdl = ['sh','-c',cmdl]
1550 rc = testbed.execute(what, cmdl, script=None, kind='install')
1551 if rc: badpkg("installation of basic binarries failed,"
1552 " exit code %d" % rc)
1554 b._debug('publish install...')
1555 for pkg in b.install:
1556 what = 'apt-get-install-%s' % pkg
1558 cmdl = b._apt_get() + ' install ' + pkg + ' >&2'
1559 cmdl = ['sh','-c',cmdl]
1560 rc = testbed.execute(what, cmdl, script=None, kind='install')
1561 if rc: badpkg("installation of %s failed, exit code %d"
1564 b._debug('publish done')
1566 #---------- processing of sources (building)
1568 def source_rules_command(act,script,what,which,work,cwd,
1569 results_lines=0,xargs=[]):
1570 script = [ "exec 3>&1 >&2",
1572 script = '\n'.join(script)
1573 so = TemporaryFile('%s-%s-results' % (what,which))
1574 rc = testbed.execute('%s-%s' % (what,which),
1575 ['sh','-ec',script]+xargs, script=script,
1576 so=so.write(True), cwd=cwd, kind='build')
1577 results = open(so.read()).read().rstrip('\n')
1578 if len(results): results = results.split("\n")
1580 if rc: badpkg("rules %s failed with exit code %d" % (which,rc))
1581 if results_lines is not None and len(results) != results_lines:
1582 badpkg("got %d lines of results from %s where %d expected"
1583 % (len(results), which, results_lines))
1584 if results_lines==1: return results[0]
1587 def build_source(act, control_override):
1588 act.blame = 'arg:'+act.af.spec
1589 testbed.blame(act.blame)
1590 testbed.prepare1([])
1591 testbed.needs_reset()
1594 basename = act.af.spec
1595 debiancontrol = None
1598 def debug_b(m): debug('* <%s:%s> %s' % (act.kind, act.what, m))
1600 if act.kind == 'dsc':
1602 dsc_file = open(dsc.read())
1604 fre = regexp.compile('^\s+[0-9a-f]+\s+\d+\s+([^/.][^/]*)$')
1607 if l.startswith('Files:'): in_files = True; continue
1608 elif l.startswith('#'): pass
1609 elif not l.startswith(' '):
1611 if l.startswith('Source:'):
1612 act.blame = 'dsc:'+l[7:].strip()
1613 testbed.blame(act.blame)
1614 if not in_files: continue
1617 if not m: badpkg(".dsc contains unparseable line"
1618 " in Files: `%s'" % l)
1619 leaf = m.groups(0)[0]
1620 subfile = RelativeInputFile(what+'/'+leaf, dsc, leaf,
1625 if act.kind == 'ubtree':
1626 debiancontrol = RelativeInputFile(what+'-debiancontrol',
1627 act.af, 'debian/control')
1628 dsc = TemporaryFile(what+'-fakedsc')
1629 dsc_w = open(dsc.write(), 'w')
1630 for l in open(debiancontrol.read()):
1632 if not len(l): break
1634 print >>dsc_w, 'Binary: none-so-this-is-not-a-package-name'
1637 if act.kind == 'dsc':
1638 testbed.prepare2([])
1639 testbed.satisfy_dependencies_string('dpkg-dev',
1642 work = TemporaryDir(what+'-build')
1645 tmpdir = work.write(True)+'/tmpdir'
1648 'rm -rf -- "$TMPDIR"',
1650 opts.user_wrap('mkdir -- "$TMPDIR"'),
1653 if act.kind == 'ubtree':
1654 spec = '%s/real-tree' % work.write(True)
1655 create_command = '''
1658 cp -rP --preserve=timestamps,links -- "$origpwd"/. "$spec"/.
1660 initcwd = act.af.read(True)
1662 if act.kind == 'dsc':
1663 spec = dsc.read(True)
1664 create_command = '''
1665 dpkg-source -x $spec
1667 initcwd = work.write(True)
1672 'cd '+work.write(True)
1676 script += ([ 'chown '+opts.user+' .' ] +
1678 [ 'spec="$spec" origpwd="$origpwd" '
1679 +opts.user_wrap(create_command) ])
1681 script += (tmpdir_script +
1687 'set +e; test -f debian/tests/control; echo $? >&3'
1689 (result_pwd, control_test_rc) = source_rules_command(
1690 act,script,what,'extract',work,
1691 cwd=initcwd, results_lines=2, xargs=['x',tmpdir,spec])
1693 filter = act.ah['dsc_filter']
1695 if control_test_rc == '1': act.missing_tests_control = True
1697 # For optional builds:
1699 # We might need to build the package because:
1700 # - we want its binaries (filter isn't _ and at least one of the
1701 # deb_... isn't ignore)
1702 # - the test control file says so
1703 # (assuming we have any tests)
1705 class NeedBuildException: pass
1706 def build_needed(m):
1707 debug_b('build needed for %s' % m)
1708 raise NeedBuildException()
1711 if filter != '_' and (act.ah['deb_forbuilds'] != 'ignore' or
1712 act.ah['deb_fortests'] != 'ignore'):
1713 build_needed('binaries')
1715 result_pwd_af = InputDir(what+'-treeforcontrol',
1717 stanzas = read_control(act, result_pwd_af, control_override)
1718 for stanza in stanzas:
1719 for t in stanza[' tests']:
1720 if 'build-needed' in t.restriction_names:
1721 build_needed('test %s' % t.tname)
1723 debug_b('build not needed')
1726 except NeedBuildException:
1728 if act.kind != 'dsc':
1729 testbed.prepare2([])
1731 testbed.satisfy_dependencies_string('build-essential',
1732 'install build-essential')
1733 testbed.satisfy_dependencies_dsc(dsc, 'build dependencies')
1735 script = tmpdir_script + [
1737 'dpkg-checkbuilddeps',
1738 opts.user_wrap('debian/rules build'),
1740 source_rules_command(act,script,what,'build',work,
1741 cwd=initcwd, xargs=['x',tmpdir,result_pwd])
1743 if os.path.dirname(result_pwd)+'/' != work.read(True):
1744 badpkg("results dir `%s' is not in expected parent"
1745 " dir `%s'" % (result_pwd, work.read(True)))
1749 act.tests_tree = RelativeInputDir(what+'-tests-tree',
1750 work, os.path.basename(result_pwd),
1757 act.blamed = copy.copy(testbed.blamed)
1759 debug_b('filter=%s' % filter)
1761 script = tmpdir_script + [
1762 'cd '+work.write(True)+'/[a-z0-9]*-*/.',
1763 opts.user_wrap(opts.gainroot+' debian/rules binary'),
1767 result_debs = source_rules_command(act,script,what,
1768 'binary',work,work.write(True),
1769 results_lines=1, xargs=['x',tmpdir])
1770 if result_debs == '*.deb': debs = []
1771 else: debs = result_debs.split(' ')
1772 debug_b('debs='+`debs`)
1773 re = regexp.compile('^([-+.0-9a-z]+)_[^_/]+(?:_[^_/]+)\.deb$')
1776 if not m: badpkg("badly-named binary `%s'" % deb)
1778 debug_b(' deb=%s, pkg=%s' % (deb,pkg))
1779 for pat in filter.split(','):
1780 debug_b(' pat=%s' % pat)
1781 if not fnmatch.fnmatchcase(pkg,pat):
1782 debug_b(' no match')
1784 deb_what = pkg+'_'+what+'.deb'
1785 bin = RelativeInputFile(deb_what,work,deb,True)
1786 debug_b(' deb_what=%s, bin=%s' %
1787 (deb_what, str(bin)))
1788 binaries.register(act,pkg,bin,
1789 'forbuilds',testbed.blamed)
1790 act.binaries.append((pkg,bin))
1792 debug_b('all done.')
1794 #---------- main processing loop and main program
1796 def process_actions():
1799 def debug_a1(m): debug('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ '+m)
1800 def debug_a2(m): debug('@@@@@@@@@@@@@@@@@@@@ '+m)
1801 def debug_a3(m): debug('@@@@@@@@@@ '+m)
1803 debug_a1('starting')
1805 binaries = Binaries(testbed)
1808 control_override = None
1810 debug_a1('builds ...')
1811 for act in opts.actions:
1813 (act.kind, act.what))
1815 if act.kind == 'control':
1816 control_override = act.af
1817 if act.kind == 'deb':
1818 testbed.blame('arg:'+act.af.spec)
1819 determine_package(act)
1820 testbed.blame('deb:'+act.pkg)
1821 binaries.register(act,act.pkg,act.af,
1822 'forbuilds',testbed.blamed)
1823 if act.kind == 'dsc' or act.kind == 'ubtree':
1824 build_source(act, control_override)
1825 if act.kind == 'tree':
1827 if act.kind.endswith('tree') or act.kind == 'dsc':
1828 control_override = None
1829 if act.kind == 'instantiate':
1832 debug_a1('builds done.')
1835 control_override = None
1837 debug_a1('tests ...')
1838 for act in opts.actions:
1839 debug_a2('test %s %s' % (act.kind, act.what))
1841 testbed.needs_reset()
1842 if act.kind == 'control':
1843 control_override = act.af
1844 if act.kind == 'deb':
1845 binaries.register(act,act.pkg,act.af,'fortests',
1847 if act.kind == 'dsc' or act.kind == 'ubtree':
1848 for (pkg,bin) in act.binaries:
1849 binaries.register(act,pkg,bin,'fortests',
1851 if act.kind == 'dsc':
1852 if act.ah['dsc_tests']:
1853 debug_a3('read control ...')
1854 stanzas = read_control(act, act.tests_tree,
1856 testbed.blamed += act.blamed
1857 debug_a3('run_tests ...')
1858 run_tests(stanzas, act.tests_tree)
1859 control_override = None
1860 if act.kind == 'tree' or act.kind == 'ubtree':
1861 testbed.blame('arg:'+act.af.spec)
1862 stanzas = read_control(act, act.af, control_override)
1863 debug_a3('run_tests ...')
1864 run_tests(stanzas, act.af)
1865 control_override = None
1866 if act.kind == 'instantiate':
1868 debug_a1('tests done.')
1875 except SystemExit, se:
1884 ec = print_exception(sys.exc_info(), '')