https://bugzilla.redhat.com/show_bug.cgi?id=1434601#c5
[nethome.git] / bin / hammock
index 76f8c5b..d1de04f 100755 (executable)
@@ -1,5 +1,4 @@
 #! /usr/bin/perl
-# $Id$
 
 use strict;
 use warnings;
@@ -8,17 +7,17 @@ use Getopt::Long qw(:config no_ignore_case);
 use Carp qw(&carp);
 my $start=time();
 
-my $gdbcvsmaster=$ENV{"HOME"}."/redhat/gdb-cvs-master";
-my $binutilscvsmaster=$ENV{"HOME"}."/redhat/binutils-cvs-master";
-my $archermaster=$ENV{"HOME"}."/redhat/archer-master";
-my $fedoracvsroot=q{:pserver:anonymous:@cvs.fedoraproject.org:/cvs/pkgs};
-#Unknown host cvs.devel.redhat.com.
-#my $rhelcvsroot=q{:pserver:anonymous:@cvs.devel.redhat.com:/cvs/dist};
-my $rhelcvsroot=q{:pserver:anonymous:@192.168.67.2:3401/cvs/dist};
+my $sourcewaregdbgit="git://sourceware.org/git/binutils-gdb.git";
+#my $sourcewaregdbgit="https://gitorious.org/gdb/gdb.git";
+my $gdbgitmaster=$ENV{"HOME"}."/redhat/gdb-master";
+my $fedoragitroot=q{git://pkgs.fedoraproject.org};
+my $rhelgitroot=q{git://pkgs.devel.redhat.com/rpms};
+my $sourcewaregit=q{git://pkgs.devel.redhat.com/rpms};
 my $arch_i386=qr{(?:x86|i\d86|ia32)}io;
 my $arch_x86_64=qr{(?:x8664|x86_64|em64t)}io;
 my $resultdir=$ENV{"HOME"}."/.hammock-result";
 my @arches=qw(i386 x86_64);
+#$ENV{"CCACHE_DISABLE"}="1";delete $ENV{"CCACHE_NODISABLE"};
 
 my $error=0;
 sub error
@@ -29,10 +28,11 @@ sub error
 
 my $userid;
 my $force;
-my $parallel=9;        # 1 or 2 or 3
+my $parallel=1;
 my @distro;
 my @componentdistro;
 my @path;
+my @prefixpath;
 my @arch;
 my $component;
 my $srcrpm;
@@ -42,15 +42,36 @@ my $configure;
 my $branch;
 # FIXME: Connect make paralellization to the children.
 my $distrojobs;
+my $gdbgitpie;
+my $strip;
+# FIXME: 20100911servpatched-f14:
+# readchar: Connection reset by peer
+# Remote side has terminated connection.  GDBserver will reopen the connection.
+# Can't bind address: Address already in use.
+# <last 2 lines repearing>
+my $gdbserver;
+my $valgrind;
+my $bfd32;
+my $gdbindex;
+my $dwz;
+my $dwarf;
+# Use --dwarf=X0 for: --dwarf=X -fno-debug-types-section
+# Use --dwarf=X1 for: --dwarf=X    -fdebug-types-section
+my $optimg;
+my $stabs;
+my $debug_types_section;
+my $orphanripper=1;
+my $options;
+my $asan;
 die if !GetOptions(
   "i|userid=s"=>\$userid,
     "force"=>\$force,
-  "1|serial"=>sub { $parallel=1; },
-  "2|standard"=>sub { $parallel=2; },
-  "3|parallel"=>sub { $parallel=3; },
+    "serial"=>sub { $parallel=0; },
+    "parallel"=>sub { $parallel=1; },
   "d|distro=s{,}"=>\@distro,
     "cd|componentdistro=s{,}"=>\@componentdistro,
   "p|path=s{,}"=>\@path,
+  "P|prefixpath=s{,}"=>\@prefixpath,
   "a|arch=s{,}"=>\@arch,
   "c|component=s"=>\$component,
   "s|srcrpm=s"=>\$srcrpm,
@@ -59,36 +80,67 @@ die if !GetOptions(
   "D|distrojobs=s"=>\$distrojobs,
     "configure=s"=>\$configure,
     "branch=s"=>\$branch,
+    "gdbgitpie"=>\$gdbgitpie,
+    "strip"=>\$strip,
+    "gdbserver"=>\$gdbserver,
+    "valgrind"=>\$valgrind,
+    "bfd32"=>\$bfd32,
+    "gdbindex"=>\$gdbindex,
+    "dwz"=>\$dwz,
+    "dwarf=i"=>\$dwarf,
+    "optimg"=>\$optimg,
+    "stabs=i"=>\$stabs,
+    "orphanripper!"=>\$orphanripper,
+    "options=s"=>\$options,
+    "asan"=>\$asan,
 );
-$component and ($component=~m{^(?:(?:fedora|rhel)(?:gdb|binutils|glibc)|gdbcvs|binutilscvs|archer-.*|/home/.*)$} or die "-c|--component required to be: fedoragdb|rhelgdb|fedorabinutils|rhelbinutils|fedoraglibc|rhelglibc|gdbcvs|binutilscvs|archer-*|/home/*");
+$component and ($component=~m{^(?:(?:fedora|rhel)(?:gdb|binutils|glibc)|gdbgit|/home/.*)$} or die "-c|--component required to be: fedoragdb|rhelgdb|fedorabinutils|rhelbinutils|fedoraglibc|rhelglibc|gdbgit|/home/*");
 $component and $component=~m{^/home/} and (-f "$component/gdb/gdbtypes.c" or die "$component/gdb/gdbtypes.c not found");
 $component and $srcrpm and die "-c|--component excludes -s|--srcrpm";
 $component or $srcrpm or die "-c|--component or -s|--srcrpm required";
 $component||="";  # Make `eq' not complaining.
-my $cvsbranch;
-if ($component=~/^(gdb|binutils)cvs$/) {
-  $cvsbranch=(!$branch?"-A":"-r $branch");
-} else {
-  die "--branch currently unsupported for non-CVS sources" if $branch;
+if ($component ne "gdbgit") {
+#  $gitbranch=(!$branch?"":"-r $branch"); # "-A" is broken with new sourceware.org
+  die "--branch currently unsupported for non-GIT sources" if $branch;
 }
+$branch||="master";
+!$gdbgitpie or $component eq "gdbgit" or die "--gdbgitpie requires -c gdbgit";
 @target and ($srcrpm or $component=~/^(?:fedora|rhel)/) and die "--target is available only for baretestsuite modes";
+$strip and ($srcrpm or $component=~/^(?:fedora|rhel)/) and die "--strip is available only for baretestsuite modes";
+$options and ($srcrpm or $component=~/^(?:fedora|rhel)/) and die "--options is available only for baretestsuite modes";
+$gdbserver and $component!~m{^(?:gdbgit|/home/.*)$} and die "--gdbserver is available only for gdbgit||/home/*";
+$valgrind and $component!~m{^(?:gdbgit|/home/.*)$} and die "--valgrind is available only for gdbgit||/home/*";
+$asan and $component!~m{^(?:gdbgit|/home/.*)$} and die "--asan is available only for gdbgit||/home/*";
+$gdbserver and $valgrind and die "--gdbserver and --valgrind are mutually exclusive";
+($gdbserver || $valgrind) and ($gdbindex || $dwz) and die "--gdbserver|--valgrind and --gdbindex|--dwz are mutually exclusive";
+do { $debug_types_section=$dwarf%10; $dwarf=int($dwarf/10); } if ($dwarf||0)>=40;
+!defined $dwarf or ($dwarf>=2 && $dwarf<=5) or die "--dwarf requires DWARF version number";
+!defined $stabs or ($stabs>=0 && $stabs<=2) or die "--stabs is 0=off or 1=-gstabs or 2=-gstabs+";
+($gdbserver || $valgrind || $gdbindex || $dwz) and ($dwarf || $stabs) and die "--gdbserver|--valgrind|--gdbindex and --dwarf|--stabs are mutually exclusive";
+$orphanripper=($orphanripper?"orphanripper":"");
 my %target;
 do { error "Duplicate target: $_\n" if $target{$_}++; } for @target;
 @arch="x86_64" if @target&&!@arch;
 for my $file (@file) {
   -f $file and -r $file or error "-f|--file $file not readable: $!";
 }
+###push @file,"/home/jkratoch/redhat/fedora/gdb/master/gdb-index-assert.patch" if $component eq "gdbgit";
+###push @file,"/home/jkratoch/redhat/fedora/gdb/master/gdb-dejagnu-go.patch"   if $component eq "gdbgit";
+###push @file,"/home/jkratoch/t/signed32.patch"   if $component eq "gdbgit";
 $distrojobs=(@target?1:2) if !defined $distrojobs;
+###$distrojobs=1; # FIXME
 $distrojobs=~/^\d+$/ or die "-D|distrojobs must be a number: $distrojobs";
 $distrojobs>=1 or die "-D|distrojobs must be positive: $distrojobs";
-# User may want to modify ASAP her files submitted for the test.
-my $will_copy=@file || $component=~m{^/home/};
-$parallel||=$will_copy ? 2 : 1;
 error "Excessive arguments: @ARGV" if @ARGV;
 @arch=@arches if !@arch;
 my $path=join(":",@path) if @path;
 @componentdistro and @componentdistro!=@distro and die "--cd|--componentdistro must have the same elements count as -d|--distro";
 
+#FIXME:push @file,"/home/jkratoch/t/gdbserverasyncnonstop.patch" if $component eq "gdbgit";
+push @file,"/home/jkratoch/t/watchpointfork2.patch" if $component eq "gdbgit";
+#push @file,"/home/jkratoch/t/or1k-m32.patch" if $component eq "gdbgit";
+#push @file,"/home/jkratoch/t/gdb-breakpointchanged.patch" if $component eq "gdbgit";
+
 sub distro_normalize($;$)
 {
   my($name,$force)=@_;
@@ -192,7 +244,30 @@ sub writefile
   close F or die $fname;
 }
 
-spawn "renice 20 -p $$";
+sub readfile
+{
+  my($fname)=@_;
+
+  local *F;
+  open F,"$fname" or die $fname;
+  local $/=undef();
+  defined(my $r=<F>) or die $fname;
+  close F or die $fname;
+  return $r;
+}
+
+sub ln($$)
+{
+  my($old,$new)=@_;
+  link $old,$new or spawn "cp -p '$old' '$new'";
+}
+
+# /etc/cgconfig.conf
+spawn "cgclassify -g '*':hammock $$ || :";
+
+#spawn "renice +19 -p $$";
+spawn "renice +5 -p $$||:";
+spawn "ionice -c3 -p $$";
 newdir $dir;
 $log="$dir/log";
 my $resultid="$resultdir/$id";
@@ -204,23 +279,37 @@ unlink $resultidxz or $!{ENOENT} or die "unlink $resultidxz: $!";
 spawn "uname -r >$dir/kernel";
 my %dump=(
   "path"=>$path,
+  "prefixpath"=>join(":",@prefixpath),
   "component"=>$component,
+  "branch"=>$branch,
   "srcrpm"=>$srcrpm,
   "file"=>join("\n",@file),
   "configure"=>$configure,
+  "gdbgitpie"=>$gdbgitpie,
+  "gdbserver"=>$gdbserver,
+  "valgrind"=>$valgrind,
+  "bfd32"=>$bfd32,
+  "gdbindex"=>$gdbindex,
+  "dwz"=>$dwz,
+  "dwarf"=>$dwarf,
+  "optimg"=>$optimg,
+  "stabs"=>$stabs,
+  "debug_types_section"=>$debug_types_section,
+  "orphanripper"=>$orphanripper,
+  "options"=>$options,
 );
 while (my($name,$val)=each(%dump)) {
   next if !$val;
   writefile "$dir/$name","$val\n";
-  link "$dir/$name","$resultid/$name" or warn "link $dir/$name $resultid/$name: $!";
+  ln "$dir/$name","$resultid/$name";
 }
 for my $file (@file) {
   newdir "$dir/file.d","mayexist";
   (my $base=$file)=~s{^.*/}{};
   my $d="$dir/file.d/$base";
-  link $file,$d or die "link $file $d: $!";
+  ln $file,$d;
   newdir "$resultid/file.d","mayexist";
-  link $d,"$resultid/file.d/$base" or warn "link $file $resultid/file.d/$base: $!";
+  ln $d,"$resultid/file.d/$base";
 }
 
 sub subst
@@ -239,6 +328,20 @@ sub subst
   writefile $out,$_;
 }
 
+sub copyfiles($)
+{
+  my($targetdir)=@_;
+
+  for my $file (@file) {
+    my $filebase=$file;
+    $filebase=~s{^.*/}{};
+    my $target="$targetdir/$filebase";
+    # Some *.patch files may be new.
+    # -f $target or die "File $file does not exist at $target";
+    spawn "rm -f $target; cp -p $file $target";
+  }
+}
+
 # PID->distro
 my %child;
 while (@distrouse || keys(%child)) {
@@ -247,23 +350,26 @@ while (@distrouse || keys(%child)) {
     my $distro=$distrouse->{"distro"};
     my $componentdistro=$distrouse->{"componentdistro"};
     my $target=$distrouse->{"target"};
-    my $rpmbuild="rpmbuild";
+    my $rpmbuild="rpmbuild --with buildisa";
 
-    my $cvsbasedir;
-    my $cvsroot;
-    my $cvsrepo;
+    my $gitbranch;
+    my $gitpkg;
+    my $gitroot;
+    my $gitrepo;
     if ($component=~/^fedora(.*)$/) {
-      $cvsrepo=$1;
-      $cvsbasedir="F-$1" if $componentdistro=~/^fedora-(\d+)$/;
-      $cvsbasedir="devel" if $componentdistro=~/^fedora-rawhide$/;
-      die "$component vs. $componentdistro" if !$cvsbasedir;
-      $cvsroot=$fedoracvsroot;
+      $gitrepo=$1;
+      $gitbranch="f$1" if $componentdistro=~/^fedora-(\d+)/;
+      $gitbranch="master" if $componentdistro=~/^fedora-rawhide/;
+      die "$component vs. $componentdistro" if !$gitbranch;
+      $gitroot=$fedoragitroot;
+      $gitpkg="fedpkg";
     }
     if ($component=~/^rhel(.*)$/) {
-      $cvsrepo=$1;
-      $cvsbasedir="RHEL-$1" if $componentdistro=~/^(?:epel|rhel)-(\d+)$/;
-      die "$component vs. $componentdistro" if !$cvsbasedir;
-      $cvsroot=$rhelcvsroot;
+      $gitrepo=$1;
+      $gitbranch="auto";
+      $gitroot=$rhelgitroot;
+      $gitpkg="https_proxy= rhpkg";
+      #$gitpkg="https_proxy= fedpkg --dist master";
       # EPEL still uses Berkeley DB version 8 while F-11+ (F-10?) uses version 9.
       # Using db_dump and db_load would no longer make it mock compatible.
       $rpmbuild.=q{ --dbpath $PWD --nodeps};
@@ -275,8 +381,9 @@ while (@distrouse || keys(%child)) {
     newdir $distrodir;
     $log="$distrodir/log";
     my $out="$distrodir/out";
+    newdir $out;
 
-    if ($parallel>1) {
+    if ($parallel) {
       my $pid=fork();
       die if !defined $pid;
       if ($pid) {
@@ -289,7 +396,7 @@ while (@distrouse || keys(%child)) {
     newdir $builddir;
 
     # Do not use mockrun as the rpm database may be in a different version.
-    spawn "rpm -r /var/lib/mock/$distro/root -qa|sort >$distrodir/rpm-qa";
+    spawn "rpm -r /var/lib/mock/$distro/root -qa|sort >$out/rpm-qa";
 
     $::distro=$distro;
     sub mockrun($)
@@ -297,38 +404,49 @@ while (@distrouse || keys(%child)) {
       my($c)=@_;
 
       $c="export PATH=\"$path:\$PATH\"; $c" if $path;
-      $c="export MAKEFLAGS=\"-j\$[`getconf _NPROCESSORS_ONLN`*3/2]\"; $c";
+      for my $prefixpath (@prefixpath) {
+       $c="export PATH=\"$prefixpath/bin:\$PATH\"; $c";
+       $c="export LD_LIBRARY_PATH=\"$prefixpath/lib64:$prefixpath/lib\${LD_LIBRARY_PATH:+:\$LD_LIBRARY_PATH}\"; $c";
+      }
+      $c="export PATH=\"\$HOME/bin:\$PATH\"; $c";
+      # $c="export MAKEFLAGS=\"-j\$[`getconf _NPROCESSORS_ONLN`*3/2]\"; $c";
+      # gdbgit: 16=6m5s 32=5m49s(seen OOM) 64=5m42s
+      $c="export MAKEFLAGS=\"-j24\"; $c";
       $c="export http_proxy=http://127.0.0.1:3128/; $c";
       $c="set -ex; cd $builddir; $c";
       die "found ': $c" if $c=~/'/;
       spawn "mockrun $::distro '$c'";
     }
 
-    if ($cvsbasedir) {
-      die if !$cvsroot;
-      die if !$cvsrepo;
-      spawn "cd $distrodir; cvs -q -z3 -d $cvsroot co rpms/$cvsrepo/$cvsbasedir";
-      my $componentdir="$distrodir/rpms/$cvsrepo/$cvsbasedir";
+    if ($gitbranch) {
+      die if !$gitroot;
+      die if !$gitrepo;
+      die if !$gitbranch;
+      die if !$gitpkg;
+      spawn "cd $distrodir; git clone ".($gitbranch eq "auto"?"":"-b $gitbranch")." $gitroot/$gitrepo $component";
+      my $componentdir="$distrodir/$component";
       -d $componentdir or die "Failed checkout to: $componentdir";
-      # Required for RHEL; Fedora does so automatically.
-      spawn "cd $componentdir/..; cvs -q -z3 -d $cvsroot co common";
-      # Workaround (RHEL-5?) curl which uses `Pragma: nocache' on $http_proxy.
-      subst sub { s{echo "curl }{$&-H 'Pragma: cache' }; },"$componentdir/../common/Makefile.common";
-
-      for my $file (@file) {
-       my $filebase=$file;
-       $filebase=~s{^.*/}{};
-       my $target="$componentdir/$filebase";
-       # Some *.patch files may be new.
-       # -f $target or die "File $file does not exist at $target";
-       spawn "rm -f $target; cp -p $file $target";
+      if ($gitbranch eq "auto") {
+       $componentdistro=~/^(?:rhel|epel)-(\d+)$/ or die $componentdistro;
+       my $major=$1;
+       my @l=grep { m{^\s*origin/rhel-$major\.\d+\s*$} } split /\n/,readfile "cd $componentdir; git branch -r |";
+       sub minor
+       {
+         local $_=$_[0];
+         s{^\s*origin/rhel-\d+\.(\d+)\s*$}{$1} or die;
+         return $_;
+       }
+       @l=sort { minor($b) <=> minor($a); } @l;
+       $gitbranch=($l[0]=~m{^\s*origin/(.*?)\s*$})[0] or die;
+       spawn "cd $componentdir; git checkout $gitbranch";
       }
-
+      copyfiles $componentdir;
+      spawn "cd $componentdir; $gitpkg verrel >$out/verrel";
       my $glob="$componentdir/*.src.rpm";
       @{[glob $glob]}==0 or die "Found some before test-srpm: $glob";
       # No `spawn' as we could get:
       # error: unpacking of archive failed on file X;4a56efef: cpio: MD5 sum mismatch
-      mockrun "cd $componentdir; make test-srpm";
+      mockrun "cd $componentdir; $gitpkg srpm";
       my @srcrpm=(glob $glob);
       @srcrpm==1 or die "Did not find 1 srcrpm: @srcrpm";
       $srcrpm=$srcrpm[0];
@@ -340,36 +458,23 @@ while (@distrouse || keys(%child)) {
       spawn "cp -p $srcrpm $builddir/$srcrpmbasename";
 
       my $rpmbuildlocal=$rpmbuild.q{ --define "_topdir $PWD" --define "_builddir $PWD" --define "_rpmdir $PWD" --define "_sourcedir $PWD" --define "_specdir $PWD" --define "_srcrpmdir $PWD" --define "_build_name_fmt %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm"};
-      $rpmbuildlocal="orphanripper $rpmbuildlocal" if $cvsrepo && $cvsrepo eq "glibc";
-      mockrun $rpmbuildlocal." --rebuild --with testsuite".($parallel<2 ? "" : " --with parallel")." $srcrpmbasename";
+      # $rpmbuildlocal="$orphanripper $rpmbuildlocal" if $gitrepo && $gitrepo eq "glibc";
+      mockrun $rpmbuildlocal." --rebuild --with testsuite $srcrpmbasename";
     }
 
     my $baretestsuite;
 
-    if ($component=~/^(gdb|binutils)cvs$/) {
-      my $which=$1;
-      my $cvsmaster=$which eq "gdb" ? $gdbcvsmaster : $binutilscvsmaster;
-      if (-d $cvsmaster) {
-       spawn "cp -a $cvsmaster $builddir/src; cd $builddir/src; cvs update $cvsbranch";
-      } else {
-       spawn "cd $builddir; cvs -q -z3 -d :pserver:anoncvs:\@sourceware.org:/cvs/src co $cvsbranch $which";
-      }
-      spawn "cd $builddir/src; test -z \"\$(cvs update $cvsbranch)\"";
-      $baretestsuite="$builddir/src";
-    }
-
-    if ($component=~/^archer-/) {
-      if (-d $archermaster) {
-       spawn "cp -a $archermaster $builddir/$component; cd $builddir/$component; git pull"
-      } else {
-       spawn "cd $builddir; git clone git://sourceware.org/git/archer.git; mv -f archer $component";
-      }
-      spawn "cd $builddir/$component; git checkout -b $component origin/$component; [ \"`git status`\" = \"# On branch $component\nnothing to commit (working directory clean)\" ]";
+    if ($component eq "gdbgit") {
+      spawn "git clone ".(!-d $gdbgitmaster ? "" : "--reference $gdbgitmaster")." -b $branch $sourcewaregdbgit $builddir/$component";
+      #spawn "cd $builddir/$component; git fetch";
+      spawn "cd $builddir/$component; git pull";
+###      spawn "cd $builddir/$component; git checkout -b $component origin/$component; [ \"`git status`\" = \"# On branch $component\nnothing to commit (working directory clean)\" ]";
       $baretestsuite="$builddir/$component";
     }
 
     if ($component=~m{^/home/}) {
-      spawn "cp -a $component $builddir/src; cd $builddir/src; find -name \"*.[oa]\" -o -name \"*.l[oa]\" -o -name gdb.sum -o -name gdb.log|xargs rm -f; make clean || :";
+      # spawn "cp -a $component $builddir/src; cd $builddir/src; find -name \"*.[oa]\" -o -name \"*.l[oa]\" -o -name gdb.sum -o -name gdb.log|xargs rm -f; make clean || :";
+      spawn "git clone $component $builddir/src; cd $builddir/src";
       $baretestsuite="$builddir/src";
     }
 
@@ -380,31 +485,83 @@ while (@distrouse || keys(%child)) {
          my $R=$1;
          my $fileabs=$file;
          $fileabs=$ENV{"PWD"}."/$fileabs" if $fileabs!~m{^/};
-         spawn "cd $baretestsuite; patch -${R}p".($component=~/binutils/ ? "0" : "1")." <$fileabs";
+         spawn "cd $baretestsuite; patch -${R}p1 <$fileabs";
        } else {
          -f $target or $file=~m{/testsuite/} or die "File $file does not exist at $target";
          spawn "rm -f $target; cp -p $file $target";
        }
+       spawn "rm -f $baretestsuite/gdb/testsuite/dg-extract-results.py"; ### Fedora gdb-no-dg-extract-results-py.patch
       }
 
-      my $errs1="errs1";
-      $errs1.=" --target=$target" if $target;
-      $errs1.=" $configure" if $configure;
-
-      if ($component eq "binutilscvs") {
-       mockrun "cd $baretestsuite; $errs1; errs2; ulimit -c unlimited; orphanripper make -k check || :; mkdir $out; ".q{for file in {gas/testsuite/gas,ld/ld,binutils/binutils}.{sum,log};do ln $file}." $out/binutils-$distro-".q{$(basename $file) || :; done;};
-      } else {
+      my $errs12="errs12";
+      $errs12.=" --noasan" if !$asan;
+      $errs12.=" -s" if $strip;
+      $errs12.=" --target=$target" if $target;
+      #$errs12.=" --disable-binutils --disable-gas --disable-gold --disable-gprof --disable-ld";
+      #$errs12.=" --binutils" if $gdbindex; # for objcopy but that is needed only for cross-targets
+      $errs12.=" $options" if $options;
+      $errs12.=" $configure" if $configure;
+
+#      if ($component eq "binutilsgit") {
+#      mockrun "cd $baretestsuite; $errs12; ulimit -c unlimited; $orphanripper make -k check || :; ".q{for file in {gas/testsuite/gas,ld/ld,binutils/binutils}.{sum,log};do ln $file}." $out/binutils-$distro-".q{$(basename $file) || :; done;};
+#      }
+      {
+       if ($valgrind) {
+         # FIXME
+         do { unlink $_ or warn "$_: $!"; } for "$baretestsuite/gdb/testsuite/gdb.base/break-interp.exp";
+       }
        my @check=($distro=~/-x86_64/ ? qw(-m64 -m32) : -m32);
        @check=map("check//unix/$_",@check);
-### FIXME:
-###    @check=map({($_,"$_/-fPIE/-pie");} @check);
-       # for i in ".join(" ",@check).";do orphanripper make -k \$i || :;done
-       mockrun "cd $baretestsuite; $errs1; errs2; cd gdb; ulimit -c unlimited; orphanripper make -k ".join(" ",@check)." || :; mkdir $out; ".q{for t in sum log;do for file in testsuite*/gdb.$t;do suffix="${file#testsuite.unix.}"; suffix="${suffix%/gdb.$t}"; ln $file}." $out/gdb-$distro".q{$suffix.$t || :; done; done;};
+       @check=map({($_,"$_/-fPIE/-pie");} @check) if $gdbgitpie;
+       my %flags=("CC_FOR_TARGET"   =>"gcc",
+                  "CXX_FOR_TARGET"  =>"g++",
+                  "GO_FOR_TARGET"   =>"gccgo",
+                  "GO_LD_FOR_TARGET"=>"gccgo",
+                  );
+       # for i in ".join(" ",@check).";do $orphanripper make -k \$i || :;done
+       sub runtestcc($)
+       {
+         my($q0)=@_;
+         (my $q1=$q0)=~s/ /\\ /g;
+         (my $q2=$q1)=~s/ /\\ /g;
+         return ' RUNTESTFLAGS="'.join(' ',map($_.'='.$flags{$_}.'\ '.$q1,keys(%flags))).' GNATMAKE_FOR_TARGET=gnatmake\ --GCC=gcc\\ '.$q2.'"';
+       }
+       die "FIXME" if $valgrind;
+         # .(!$valgrind?"":' RUNTESTFLAGS=--target_board=valgrind')
+         # .(!$valgrind?"":' HAMMOCK_VALGRIND=1')
+         # .(!$valgrind?"":' --without-python')        # FIXME: Fix valgrind --suppressions
+       if ($gdbindex||$dwz) {
+         for my $key (keys(%flags)) {
+           writefile "$baretestsuite/hammock-$key",''
+             .' GDB="'.$baretestsuite.'/gdb/gdb -data-directory '.$baretestsuite.'/gdb/data-directory"'
+             .' GDB_ADD_INDEX='.$baretestsuite.'/gdb/contrib/gdb-add-index.sh'
+             .' '.$baretestsuite.'/gdb/contrib/cc-with-tweaks.sh '
+               .(!$gdbindex?'':' -i')
+               .(!$dwz?'':' -m')
+               .' '.$flags{$key}.' "$@"'
+             ."\n";
+         }
+       }
+       mockrun "cd $baretestsuite;"
+               ." $errs12"
+               .(!$bfd32?"":' --disable-64-bit-bfd')
+               ."; cd gdb; ulimit -c unlimited; DEJAGNU=$baretestsuite/site.exp "
+               ."$orphanripper make -k ".join(" ",@check)
+               # Ensure serial run if FORCE_PARALLEL=1 is not present
+               ." RUNTESTFLAGS=DUMMY=dummy"
+               .(!$gdbserver?"":' RUNTESTFLAGS=--target_board=native-gdbserver')
+               # Missing GNATMAKE_FOR_TARGET!
+               .(!($gdbindex||$dwz)?"":' RUNTESTFLAGS="'.join(' ',map("$_=/bin/sh\\ $baretestsuite/hammock-$_",keys(%flags))).'"')
+               .(!$dwarf?"":runtestcc "-gdwarf-$dwarf".(!defined $debug_types_section?"":'\ '.($debug_types_section?"-fdebug-types-section":"-fno-debug-types-section"))." -g0")
+               .(!$optimg?"":runtestcc "-Og -g0")
+               .(!$stabs?"":runtestcc(($stabs==1?"-gstabs":"-gstabs+")." -g0"))
+               .(!$parallel?"":' FORCE_PARALLEL=1')
+               ." || :; ".q{for t in sum log;do for file in testsuite*/gdb.$t;do suffix="${file#testsuite.unix.}"; suffix="${suffix%/gdb.$t}"; ln $file}." $out/gdb".q{$suffix.$t || :; done; done;};
       }
       # gdbunpack does:
       #                perl -i -pe 's{\Q'"$HOME"'\E/.*?/build/[^/]*/}{}g' "$base"/*
       my $HOME=$ENV{"HOME"};
-      for my $file (<$out/*>) {
+      for my $file (glob("$out/*.sum"),glob("$out/*.log")) {
        subst sub { s{\Q$HOME\E/.*?/build/[^/]*/}{}g; },$file;
       }
     } else {
@@ -420,9 +577,16 @@ while (@distrouse || keys(%child)) {
     }
     if (@testinlog) {
       subst sub { s{^.*?\n($testinlog[0]\n.*\n$testinlog[1]\n).*$}{$1}s; },$log,$out;
-    } elsif ($cvsbasedir || $srcrpm) {
+    } elsif ($srcrpm) {
       # Applies both to gdb and binutils.
-      spawn "gdbunpack $log";
+      spawn "mv $out $out.x; gdbunpack $log; mv $out.x/* $out/; rmdir $out.x";
+    }
+
+    if ($valgrind) {
+      for my $from (glob "$out/*.log") {
+       (my $to=$from).="filt";
+       spawn q{sed -n 's/^==[0-9]*== \([A-Z]\)/\1/p' <}.$from.q{|grep -v '^\(Conditional jump \|Invalid read \|Use of uninitialised value \|Syscall param .* uninitialised byte\)' >}.$to;
+      }
     }
 
     my $resultout="$resultdir/$id/$distrodirbase";
@@ -433,10 +597,10 @@ while (@distrouse || keys(%child)) {
       (my $base=$fname)=~s{^.*/}{};
       my $d="$resultout/$base";
       warn "+ link $fname $d\n";
-      link $fname,$d or warn $!;
+      ln $fname,$d;
     }
 
-    exit 0 if $parallel>1;
+    exit 0 if $parallel;
   }
 
   print STDERR "waiting for ".scalar(keys(%child))." children, ".scalar(@distrouse)." distros to go...\n";