12 suppressrepeatedemails=false
13 arch=`dpkg --print-architecture`
17 for config in "$@"; do
19 *=*) eval "$config" ;;
25 echo >&2 'disabled because config inadequate (no disable=false)'
29 : ${destdirtail:=$distro-$target}
30 : ${destdirfin:="$destdircommon$destdirtail"}
39 descx="${target#binary-}"
42 echo >&2 'target must be source or binary-*'
47 printf >&3 "starting "
55 echo '(log diverted to stdout)' >>"$tmp"/_log_raw
57 exec >>"$tmp"/_log_raw
62 echo "++++++ $1 ++++++"
66 progress "fetching $1"
70 gurl "$mirror/dists/$distro/$suite/$target/$sources.gz" "$tmp"/_$sources.gz
71 zcat "$tmp"/_$sources.gz >"$tmp"/_$sources-in
73 lastinfo="$var"/lastinfo-$target
74 : "${scorelog:="$var"/scores-$target}"
81 if test $target = source; then
82 blacklist="$blacklistsourcepackages"
84 blacklist="$blacklistbinarypackages"
87 if [ "x$pkg" = x ]; then
92 $vre= "[-+.0-9a-zA-Z:~]+";
94 sub f1() { $fn=shift @ARGV; open F, $fn or die "$fn $!"; }
95 sub f2() { F->error and die "$fn $!"; close F or die "$fn $!"; }
97 $scorelog= "'"$scorelog"'";
98 if (length $scorelog) { open SCORE, "> $scorelog.new" or die $!; }
100 return unless length $scorelog;
101 printf SCORE "%$_[1]s", $_[0] or die $!;
104 sub readpkglist ($$) {
105 my ($arrayref, $filename) = @_;
106 return unless length $filename;
107 unshift @ARGV, $filename; f1();
109 next if m/^\#/ or !m/\S/;
110 die unless m/^($pre)(?:\S.*)?\s*$/;
115 readpkglist(\%suppress, "'"$suppresspackages"'");
116 readpkglist(\%blacklist, "'"$blacklist"'");
120 die unless m/^($pre) ($vre) (\d+)( .*)?$/;
128 sub scorepackage () {
129 return if length $skip;
130 return if $blacklist{$package};
131 return if $score < $best_score
132 or ($score==$best_score and \
133 $package gt $best_package);
134 #printf STDERR " <----- best score=%s best_score=%s\n", $score, $best_score;
137 $best_package= $package;
140 return unless (defined $package
144 die unless defined $package;
145 die unless defined $version;
146 $source= $package if !defined $source;
148 $score= '$now' - $lasttime{$package};
149 pscore("$package ",-30);
150 pscore("$source ",-25);
157 pscore(" $lastver{$package}",-25);
158 pscore(" $version ",-25);
160 if ($lastver{$package} ne $version) {
164 if ($extras{$package} =~ m/ nt /) {
169 if ($suppress{$source}) {
173 $scorechars.="[$skip]" if length $skip;
175 pscore("-$scorechars",-7);
178 #print STDERR "SCORE package=$package score $score source=$source\n";
187 if (m/^Package: ($pre)$/) {
188 die if defined $package;
190 } elsif (m/^Version: ($vre)$/) {
191 die if defined $version;
193 } elsif (m/^Source: ($pre)$/) {
194 die if defined $source;
196 } elsif (m/^Architecture:.*/ &&
197 !m/\s(?:'$arch'|all|any)\s/) {
198 #printf STDERR " <----- skip %s %s\n", $&, "'$arch'";
206 if (length $scorelog) {
207 close SCORE or die $!;
208 rename "$scorelog.new","$scorelog" or die $!;
210 die unless length $best_package;
211 open L, ">&4" or die $!;
212 printf L "selected %s (age %s, score %d)\n",
214 exists($lastime{$best_package})
215 ? '$now' - $lasttime{$best_package}
218 print "$best_package\n" or die $!;
219 ' "$lastinfo" "$tmp"/_$sources-in`"
221 printf >&4 "package forced: %s\n" "$pkg"
224 sed -n "/^Package: $pkg\$/,/^\$/p" \
225 <"$tmp"/_$sources-in >"$tmp"/_this-stanza
228 cat "$tmp"/_this-stanza
232 sed -n '\''s/^'$1': //p'\'' \
237 printf >&3 "selected \"%s\" " $pkg
240 mkdir "$tp" "$tp/src" "$tp/tmp" "$tp/out"
245 if [ "x$pSource" != x ]; then
251 if test $target = source; then
254 sed -n '/^Files:/,/^([^ ].*)?$/{ /^ /{
255 s/^ [0-9a-z][0-9a-z]* *[0-9][0-9]* //; p
259 for leafname in $leafnames; do
260 df="$tp/src/$leafname"
262 */*|.*) echo >&2 "bad leafname: $leafname"; exit 1;;
265 gurl "$mirror/$pDirectory/$leafname" "$df"
270 : ${upload_if_ok:=true}
271 email_package_header="$email_sourcepackage_header"
274 fot="$tp/src/$pkg.deb"
275 gurl "$mirror/$pFilename" "$fot"
276 testmode='--binaries=install --binary'
277 testmode2=--instantiate
279 : ${upload_if_ok:=false}
280 email_package_header="$email_binarypackage_header"
283 if [ "x$maintainer_email_override" = x ]; then
285 maintainer_email=pMaintainer
287 maintainer_email=maintainer_email_override
290 printf >&3 "adt-run "
292 progress "starting test"
302 echo 'fatal: adt-run did not start properly' >"$tmp"/_summary
304 xrc adt-run --tmp-dir "$tp"/tmp \
305 --output-dir "$tp"/out \
306 --log-file "$tp"/log \
307 --summary "$tmp"/_summary \
309 $testmode "$fot" $testmode2 \
312 $adtvirt_extra_opts \
321 : ${upload_if_notests:=false}
325 0) summary='all OK'; email=''
326 upload=$upload_if_ok ;;
327 2) summary='OK (some skipped)'; email=''
328 upload=$upload_if_ok ;;
329 8) summary='package declares no tests'; email=''
330 upload=$upload_if_notests; extras='nt' ;;
331 4|6) summary='test(s) failed!'; email="$maintainer_email" ;;
332 12) summary='erroneous package!'; email="$maintainer_email" ;;
333 16) summary='testbed failed!'; email="administrator_email" ;;
334 *) summary='unexpected failure!'; email="administrator_email"; ourx=20;;
337 progress "RESULTS $summary"
339 if [ "x$suppresspackages" != x ] \
340 && grep -x "$src" "$suppresspackages" >/dev/null; then
341 printf >&3 "email-suppressed "
347 printf "\n%s\n" "$summary" >>"$tmp"/_summary
349 edest=${email%_email}
350 esummary="$var"/emailed/last-$pkg,$edest
351 if [ "x$edest" = x ]; then
352 printf >&3 "email-none "
353 rm -f "$var"/emailed/last-$pkg,*
355 elif $suppressrepeatedemails \
356 && [ -f "$esummary" ] \
357 && diff -u "$esummary" "$tmp"/_summary >"$var"/emailed/diff-$pkg; then
358 printf >&3 "email-same $email "
362 cp "$tmp"/_summary "$esummary".new
365 ln -f "$tmp"/_summary "$tp"/summary
367 for odir in tmp out; do
368 if test -d "$tp"/$odir; then
369 GZIP=-2 tar -f "$tp"/$odir.tar.gz -C "$tp" -zc $odir
375 printf >&3 "uploading"
376 $rsync -rltH --safe-links --delete "$tp" "$destrsynchead/$destdirfin/"
380 if [ "x$email" != x ]; then
381 progress "contacting $email"
382 eval "email_addr=\$$email"
383 printf >&3 "email \"%s\" " "$email_addr"
384 cat >"$tmp"/_email_header <<END
387 Subject: autopkgtest $distro $desc: $summary
391 email_package_header="${email_package_header//@p/$pkg}"
392 email_package_header="${email_package_header//@s/$src}"
393 email_package_header="${email_package_header//@v/$pVersion}"
394 email_package_header="${email_package_header//@a/@}"
395 printf >"$tmp"/_email "%s" "$email_package_header"
397 cat >>"$tmp"/_email <<END
398 Test executed for: $distro $target $pkg
401 sed -e 's/^/ /' "$tmp"/_summary >>"$tmp"/_email
402 cat >>"$tmp"/_email <<END
404 This message is automatically generated by the autopkgtest package
405 testing system. You are receiving it because:
409 cat >>"$tmp"/_email <<END
410 You are listed in the Maintainer field of the $pkg package in $distro
411 and the test results appear to indicate a problem with the package.
414 maintainer_email_override)
415 cat >>"$tmp"/_email <<END
416 The test results appear to indicate a problem with the package
417 and reports for package maintainers for $distro are being directed to
418 $maintainer_email_override
422 cat >>"$tmp"/_email <<END
423 You are the administrator for the autopkgtest installation.
427 echo >&2 "huh email $email is what why?"
431 cat >>"$tmp/_email" <<END
433 The top and tail of the test log, which is intended to be sufficient
434 to diagnose most failures, can be found below. However, in case this
435 is not sufficient, a complete log can be found along with output
436 files, saved temporary files, and so on, at:
437 $desthttphead/$destdirfin/
439 If you have any questions about this service please contact me at:
449 printf >>"$var"/log "%s=%s rc=%s emailed='%s'\n" \
450 "$target" "$pkg" $rc "$email_addr"
452 if [ "x$ourx" = x0 ]; then
453 sed -e "/^$pkg /d" <"$lastinfo" >"$lastinfo".new
454 printf "%s %s %s %s\n" "$pkg" "$pVersion" "$now" "$extras" \
456 mv "$lastinfo".new "$lastinfo"
459 progress "fault ($ourx)."
462 perl <"$tmp"/_log_raw >"$tmp"/_log -ne '
463 s/[^\012\040-\133\135-\176]/
467 $& eq "\\" ? "\\\\" :
468 sprintf "\\x%02x", ord $&
473 $middle=1 if $headlen > '"$logheadmaxbytes"';
480 while ($taillen > '"$logtailmaxbytes"') {
481 $taillen -= length shift @tail;
486 print "...\n" or die $! if $some_dropped;
487 print @tail or die $!;
491 if [ "x$email" = x ]; then
492 if $interactive; then
496 cat >>"$tmp"/_email 2>&1 "$tmp"/_log ||:
498 if [ "x$email_signing_key" != x ]; then
499 printf >&3 "signing "
501 gpg -u"$email_signing_key" --clearsign \
502 <"$tmp/_email" >"$tmp/_email.asc"
503 mv -f "$tmp/_email.asc" "$tmp/_email"
505 cat "$tmp/_email_header" "$tmp/_email" >"$tmp/_email.new"
506 mv -f "$tmp/_email.new" "$tmp/_email"
508 if $interactive; then
509 cat "$tmp"/_email >&2
511 sendmail -odi -oem -t -oi <"$tmp"/_email
512 if [ "x$esummary" != x ]; then
513 printf >&3 "email-recorded "
514 mv "$esummary".new "esummary"
519 printf >&3 "done %s.\n" $ourx