12 suppressrepeatedemails=false
13 arch=`dpkg --print-architecture`
18 for config in "$@"; do
20 *=*) eval "$config" ;;
26 echo >&2 'disabled because config inadequate (no disable=false)'
30 : ${destdirtail:=$distro-$target}
31 : ${destdirfin:="$destdircommon$destdirtail"}
40 descx="${target#binary-}"
43 echo >&2 'target must be source or binary-*'
48 printf >&3 "starting "
56 echo '(log diverted to stdout)' >>"$tmp"/_log_raw
58 exec >>"$tmp"/_log_raw
63 echo "++++++ $1 ++++++"
67 progress "fetching $1"
71 gurl "$mirror/dists/$distro/$suite/$target/$sources.gz" "$tmp"/_$sources.gz
72 zcat "$tmp"/_$sources.gz >"$tmp"/_$sources-in
74 lastinfo="$var"/lastinfo-$target
75 : "${scorelog:="$var"/scores-$target}"
82 if test $target = source; then
83 blacklist="$blacklistsourcepackages"
85 blacklist="$blacklistbinarypackages"
88 if [ "x$pkg" = x ]; then
93 $vre= "[-+.0-9a-zA-Z:~]+";
95 sub f1() { $fn=shift @ARGV; open F, $fn or die "$fn $!"; }
96 sub f2() { F->error and die "$fn $!"; close F or die "$fn $!"; }
98 $scorelog= "'"$scorelog"'";
99 if (length $scorelog) { open SCORE, "> $scorelog.new" or die $!; }
101 return unless length $scorelog;
102 printf SCORE "%$_[1]s", $_[0] or die $!;
105 sub readpkglist ($$) {
106 my ($arrayref, $filename) = @_;
107 return unless length $filename;
108 unshift @ARGV, $filename; f1();
110 next if m/^\#/ or !m/\S/;
111 die unless m/^($pre)(?:\S.*)?\s*$/;
116 readpkglist(\%suppress, "'"$suppresspackages"'");
117 readpkglist(\%blacklist, "'"$blacklist"'");
121 die unless m/^($pre) ($vre) (\d+)( .*)?$/;
129 sub scorepackage () {
130 return if length $skip;
131 return if $blacklist{$package};
132 return if $score < $best_score
133 or ($score==$best_score and \
134 $package gt $best_package);
135 #printf STDERR " <----- best score=%s best_score=%s\n", $score, $best_score;
138 $best_package= $package;
141 return unless (defined $package
145 die unless defined $package;
146 die unless defined $version;
147 $source= $package if !defined $source;
149 $score= '$now' - $lasttime{$package};
150 pscore("$package ",-30);
151 pscore("$source ",-25);
158 pscore(" $lastver{$package}",-25);
159 pscore(" $version ",-25);
161 if ($lastver{$package} ne $version) {
165 if ($extras{$package} =~ m/ nt /) {
170 if ($suppress{$source}) {
174 $scorechars.="[$skip]" if length $skip;
176 pscore("-$scorechars",-7);
179 #print STDERR "SCORE package=$package score $score source=$source\n";
188 if (m/^Package: ($pre)$/) {
189 die if defined $package;
191 } elsif (m/^Version: ($vre)$/) {
192 die if defined $version;
194 } elsif (m/^Source: ($pre)$/) {
195 die if defined $source;
197 } elsif (m/^Architecture:.*/ &&
198 !m/\s(?:'$arch'|all|any)\s/) {
199 #printf STDERR " <----- skip %s %s\n", $&, "'$arch'";
207 if (length $scorelog) {
208 close SCORE or die $!;
209 rename "$scorelog.new","$scorelog" or die $!;
211 die unless length $best_package;
212 open L, ">&4" or die $!;
213 printf L "selected %s (age %s, score %d)\n",
215 exists($lastime{$best_package})
216 ? '$now' - $lasttime{$best_package}
219 print "$best_package\n" or die $!;
220 ' "$lastinfo" "$tmp"/_$sources-in`"
222 printf >&4 "package forced: %s\n" "$pkg"
225 sed -n "/^Package: $pkg\$/,/^\$/p" \
226 <"$tmp"/_$sources-in >"$tmp"/_this-stanza
229 cat "$tmp"/_this-stanza
233 sed -n '\''s/^'$1': //p'\'' \
238 printf >&3 "selected \"%s\" " $pkg
241 mkdir "$tp" "$tp/src" "$tp/tmp" "$tp/out"
246 if [ "x$pSource" != x ]; then
252 if test $target = source; then
255 sed -n '/^Files:/,/^([^ ].*)?$/{ /^ /{
256 s/^ [0-9a-z][0-9a-z]* *[0-9][0-9]* //; p
260 for leafname in $leafnames; do
261 df="$tp/src/$leafname"
263 */*|.*) echo >&2 "bad leafname: $leafname"; exit 1;;
266 gurl "$mirror/$pDirectory/$leafname" "$df"
271 : ${upload_if_ok:=true}
272 email_package_header="$email_sourcepackage_header"
275 fot="$tp/src/$pkg.deb"
276 gurl "$mirror/$pFilename" "$fot"
277 testmode='--binaries=install --binary'
278 testmode2=--instantiate
280 : ${upload_if_ok:=false}
281 email_package_header="$email_binarypackage_header"
284 if [ "x$maintainer_email_override" = x ]; then
286 maintainer_email=pMaintainer
288 maintainer_email=maintainer_email_override
291 printf >&3 "adt-run "
293 progress "starting test"
303 echo 'fatal: adt-run did not start properly' >"$tmp"/_summary
305 xrc adt-run --tmp-dir "$tp"/tmp \
306 --output-dir "$tp"/out \
307 --log-file "$tp"/log \
308 --summary "$tmp"/_summary \
310 $testmode "$fot" $testmode2 \
313 $adtvirt_extra_opts \
322 : ${upload_if_notests:=false}
326 0) summary='all OK'; email=''
327 upload=$upload_if_ok ;;
328 2) summary='OK (some skipped)'; email=''
329 upload=$upload_if_ok ;;
330 8) summary='package declares no tests'; email=''
331 upload=$upload_if_notests; extras='nt' ;;
332 4|6) summary='test(s) failed!'; email="$maintainer_email" ;;
333 12) summary='erroneous package!'; email="$maintainer_email" ;;
334 16) summary='testbed failed!'; email="administrator_email" ;;
335 *) summary='unexpected failure!'; email="administrator_email"; ourx=20;;
338 progress "RESULTS $summary"
340 if [ "x$suppresspackages" != x ] \
341 && grep -x "$src" "$suppresspackages" >/dev/null; then
342 printf >&3 "email-suppressed "
348 printf "\n%s\n" "$summary" >>"$tmp"/_summary
350 edest=${email%_email}
351 esummary="$var"/emailed/last-$pkg,$edest
352 if [ "x$edest" = x ]; then
353 printf >&3 "email-none "
354 rm -f "$var"/emailed/last-$pkg,*
356 elif $suppressrepeatedemails \
357 && [ -f "$esummary" ] \
358 && diff -u "$esummary" "$tmp"/_summary >"$var"/emailed/diff-$pkg; then
359 printf >&3 "email-same $email "
363 cp "$tmp"/_summary "$esummary".new
366 ln -f "$tmp"/_summary "$tp"/summary
368 for odir in tmp out; do
369 if test -d "$tp"/$odir; then
370 GZIP=-2 tar -f "$tp"/$odir.tar.gz -C "$tp" -zc $odir
375 if ! $upload_src; then
380 printf >&3 "uploading"
381 $rsync -rltH --safe-links --delete "$tp" "$destrsynchead/$destdirfin/"
385 if [ "x$email" != x ]; then
386 progress "contacting $email"
387 eval "email_addr=\$$email"
388 printf >&3 "email \"%s\" " "$email_addr"
389 cat >"$tmp"/_email_header <<END
392 Subject: autopkgtest $distro $desc: $summary
396 email_package_header="${email_package_header//@p/$pkg}"
397 email_package_header="${email_package_header//@s/$src}"
398 email_package_header="${email_package_header//@v/$pVersion}"
399 email_package_header="${email_package_header//@_/@}"
400 printf >"$tmp"/_email "%s" "$email_package_header"
402 cat >>"$tmp"/_email <<END
403 Test executed for: $distro $target $pkg
406 sed -e 's/^/ /' "$tmp"/_summary >>"$tmp"/_email
407 cat >>"$tmp"/_email <<END
409 This message is automatically generated by the autopkgtest package
410 testing system. You are receiving it because:
414 cat >>"$tmp"/_email <<END
415 You are listed in the Maintainer field of the $pkg package in $distro
416 and the test results appear to indicate a problem with the package.
419 maintainer_email_override)
420 cat >>"$tmp"/_email <<END
421 The test results appear to indicate a problem with the package
422 and reports for package maintainers for $distro are being directed to
423 $maintainer_email_override
427 cat >>"$tmp"/_email <<END
428 You are the administrator for the autopkgtest installation.
432 echo >&2 "huh email $email is what why?"
436 cat >>"$tmp/_email" <<END
438 The top and tail of the test log, which is intended to be sufficient
439 to diagnose most failures, can be found below. However, in case this
440 is not sufficient, a complete log can be found along with output
441 files, saved temporary files, and so on, at:
442 $desthttphead/$destdirfin/
444 If you have any questions about this service please contact me at:
454 printf >>"$var"/log "%s=%s rc=%s emailed='%s'\n" \
455 "$target" "$pkg" $rc "$email_addr"
457 if [ "x$ourx" = x0 ]; then
458 sed -e "/^$pkg /d" <"$lastinfo" >"$lastinfo".new
459 printf "%s %s %s %s\n" "$pkg" "$pVersion" "$now" "$extras" \
461 mv "$lastinfo".new "$lastinfo"
464 progress "fault ($ourx)."
467 perl <"$tmp"/_log_raw >"$tmp"/_log -ne '
468 s/[^\012\040-\133\135-\176]/
472 $& eq "\\" ? "\\\\" :
473 sprintf "\\x%02x", ord $&
478 $middle=1 if $headlen > '"$logheadmaxbytes"';
485 while ($taillen > '"$logtailmaxbytes"') {
486 $taillen -= length shift @tail;
491 print "...\n" or die $! if $some_dropped;
492 print @tail or die $!;
496 if [ "x$email" = x ]; then
497 if $interactive; then
501 cat >>"$tmp"/_email 2>&1 "$tmp"/_log ||:
503 if [ "x$email_signing_key" != x ]; then
504 printf >&3 "signing "
506 gpg -u"$email_signing_key" --clearsign \
507 <"$tmp/_email" >"$tmp/_email.asc"
508 mv -f "$tmp/_email.asc" "$tmp/_email"
510 cat "$tmp/_email_header" "$tmp/_email" >"$tmp/_email.new"
511 mv -f "$tmp/_email.new" "$tmp/_email"
513 if $interactive; then
514 cat "$tmp"/_email >&2
516 sendmail -odi -oem -t -oi <"$tmp"/_email
517 if [ "x$esummary" != x ]; then
518 printf >&3 "email-recorded "
519 mv "$esummary".new "esummary"
524 printf >&3 "done %s.\n" $ourx