+--gdbindex
[nethome.git] / bin / hammock
index 3859c36..748bb43 100755 (executable)
@@ -1,5 +1,4 @@
 #! /usr/bin/perl
-# $Id$
 
 use strict;
 use warnings;
@@ -8,11 +7,13 @@ use Getopt::Long qw(:config no_ignore_case);
 use Carp qw(&carp);
 my $start=time();
 
-my $gdbcvsbare=$ENV{"HOME"}."/redhat/gdb-cvs-bare";
-my $binutilscvsbare=$ENV{"HOME"}."/redhat/binutils-cvs-bare";
+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};
-my $rhelcvsroot=q{:pserver:anonymous:@192.168.67.2:3401/cvs/dist};
+my $fedoragitroot=q{git://pkgs.fedoraproject.org};
+#Unknown host cvs.devel.redhat.com.
+#my $rhelcvsroot=q{:pserver:anonymous:@cvs.devel.redhat.com:/cvs/dist};
+my $rhelcvsroot=q{:ext:cvs.devel.redhat.com:/cvs/dist};
 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";
@@ -40,6 +41,17 @@ my $configure;
 my $branch;
 # FIXME: Connect make paralellization to the children.
 my $distrojobs;
+my $gdbcvspie;
+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 $gdbindex;
+my $dwarf4;
 die if !GetOptions(
   "i|userid=s"=>\$userid,
     "force"=>\$force,
@@ -57,6 +69,12 @@ die if !GetOptions(
   "D|distrojobs=s"=>\$distrojobs,
     "configure=s"=>\$configure,
     "branch=s"=>\$branch,
+    "gdbcvspie"=>\$gdbcvspie,
+    "strip"=>\$strip,
+    "gdbserver"=>\$gdbserver,
+    "valgrind"=>\$valgrind,
+    "gdbindex"=>\$gdbindex,
+    "dwarf4"=>\$dwarf4,
 );
 $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{^/home/} and (-f "$component/gdb/gdbtypes.c" or die "$component/gdb/gdbtypes.c not found");
@@ -69,7 +87,14 @@ if ($component=~/^(gdb|binutils)cvs$/) {
 } else {
   die "--branch currently unsupported for non-CVS sources" if $branch;
 }
+!$gdbcvspie or $component eq "gdbcvs" or die "--gdbcvspie requires -c gdbcvs";
 @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";
+$gdbserver and $component ne "gdbcvs" and die "--gdbserver is available only for gdbcvs";
+$valgrind and $component ne "gdbcvs" and die "--valgrind is available only for gdbcvs";
+$gdbserver and $valgrind and die "--gdbserver and --valgrind are mutually exclusive";
+($gdbserver || $valgrind) and $gdbindex and die "--gdbserver|--valgrind and --gdbindex are mutually exclusive";
+($gdbserver || $valgrind || $gdbindex) and $dwarf4 and die "--gdbserver|--valgrind|--gdbindex and --dwarf4 are mutually exclusive";
 my %target;
 do { error "Duplicate target: $_\n" if $target{$_}++; } for @target;
 @arch="x86_64" if @target&&!@arch;
@@ -174,7 +199,7 @@ for my $seq (defined $userid ? $userid : (0..99)) {
   $dir="$basedir/$id";
   last if ! -e $dir;
 }
-spawn "rm -rf $dir" if -d $dir && $force && defined $userid;
+spawn "chmod -R u+w $dir; rm -rf $dir" if -d $dir && $force && defined $userid;
 error "Directory not free: $dir" if !$id || !$dir || -e $dir;
 print STDERR "ID = $id | dir = $dir\n";
 error "No distros specified" if !@distrouse;
@@ -190,7 +215,11 @@ sub writefile
   close F or die $fname;
 }
 
-spawn "renice 20 -p $$";
+# /etc/cgconfig.conf
+spawn "echo cgclassify -g '*':hammock $$ || :";
+
+spawn "renice +19 -p $$";
+spawn "ionice -c3 -p $$";
 newdir $dir;
 $log="$dir/log";
 my $resultid="$resultdir/$id";
@@ -203,9 +232,15 @@ spawn "uname -r >$dir/kernel";
 my %dump=(
   "path"=>$path,
   "component"=>$component,
+  "branch"=>$branch,
   "srcrpm"=>$srcrpm,
   "file"=>join("\n",@file),
   "configure"=>$configure,
+  "gdbcvspie"=>$gdbcvspie,
+  "gdbserver"=>$gdbserver,
+  "valgrind"=>$valgrind,
+  "gdbindex"=>$gdbindex,
+  "dwarf4"=>$dwarf4,
 );
 while (my($name,$val)=each(%dump)) {
   next if !$val;
@@ -237,6 +272,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)) {
@@ -248,14 +297,17 @@ while (@distrouse || keys(%child)) {
     my $rpmbuild="rpmbuild";
 
     my $cvsbasedir;
+    my $gitbranch;
     my $cvsroot;
+    my $gitroot;
     my $cvsrepo;
+    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/master" if $componentdistro=~/^fedora-(\d+)$/;
+      $gitbranch="master" if $componentdistro=~/^fedora-rawhide$/;
+      die "$component vs. $componentdistro" if !$gitbranch;
+      $gitroot=$fedoragitroot;
     }
     if ($component=~/^rhel(.*)$/) {
       $cvsrepo=$1;
@@ -273,6 +325,7 @@ while (@distrouse || keys(%child)) {
     newdir $distrodir;
     $log="$distrodir/log";
     my $out="$distrodir/out";
+    newdir $out;
 
     if ($parallel>1) {
       my $pid=fork();
@@ -287,7 +340,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($)
@@ -302,9 +355,29 @@ while (@distrouse || keys(%child)) {
       spawn "mockrun $::distro '$c'";
     }
 
+    if ($gitbranch) {
+      die if !$gitroot;
+      die if !$gitrepo;
+      die if !$gitbranch;
+      spawn "cd $distrodir; git clone -b $gitbranch $gitroot/$gitrepo $component";
+      my $componentdir="$distrodir/$component";
+      -d $componentdir or die "Failed checkout to: $componentdir";
+      copyfiles $componentdir;
+      spawn "cd $componentdir; fedpkg 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; fedpkg srpm";
+      my @srcrpm=(glob $glob);
+      @srcrpm==1 or die "Did not find 1 srcrpm: @srcrpm";
+      $srcrpm=$srcrpm[0];
+    }
+
     if ($cvsbasedir) {
       die if !$cvsroot;
       die if !$cvsrepo;
+      die if !$cvsbasedir;
       spawn "cd $distrodir; cvs -q -z3 -d $cvsroot co rpms/$cvsrepo/$cvsbasedir";
       my $componentdir="$distrodir/rpms/$cvsrepo/$cvsbasedir";
       -d $componentdir or die "Failed checkout to: $componentdir";
@@ -312,16 +385,8 @@ while (@distrouse || keys(%child)) {
       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";
-      }
-
+      copyfiles $componentdir;
+      spawn "cd $componentdir; make 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:
@@ -346,9 +411,9 @@ while (@distrouse || keys(%child)) {
 
     if ($component=~/^(gdb|binutils)cvs$/) {
       my $which=$1;
-      my $cvsbare=$which eq "gdb" ? $gdbcvsbare : $binutilscvsbare;
-      if (-d $cvsbare) {
-       spawn "cp -a $cvsbare $builddir/src; cd $builddir/src; cvs update $cvsbranch";
+      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";
       }
@@ -357,11 +422,8 @@ while (@distrouse || keys(%child)) {
     }
 
     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 "git clone ".(!-d $archermaster ? "" : "--reference $archermaster")." git://sourceware.org/git/archer.git $builddir/$component";
+      spawn "cd $builddir/$component; git fetch";
       spawn "cd $builddir/$component; git checkout -b $component origin/$component; [ \"`git status`\" = \"# On branch $component\nnothing to commit (working directory clean)\" ]";
       $baretestsuite="$builddir/$component";
     }
@@ -378,30 +440,41 @@ 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";
        }
       }
 
-      my $errs1="errs1";
-      $errs1.=" --target=$target" if $target;
-      $errs1.=" $configure" if $configure;
+      my $errs12="errs12";
+      $errs12.=" -s" if $strip;
+      $errs12.=" --target=$target" if $target;
+      $errs12.=" $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;};
+       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;};
       } else {
        my @check=($distro=~/-x86_64/ ? qw(-m64 -m32) : -m32);
        @check=map("check//unix/$_",@check);
-       @check=map({($_,"$_/-fPIE/-pie");} @check);
+       @check=map({($_,"$_/-fPIE/-pie");} @check) if $gdbcvspie;
        # 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;};
+       mockrun "cd $baretestsuite; $errs12"
+               .(!$valgrind?"":' --without-python')    # FIXME: Fix valgrind --suppressions
+               ."; cd gdb; ulimit -c unlimited; "
+               .(!$gdbserver?"":'DEJAGNU=$HOME/src/runtest-gdbserver/site.exp ')
+               .(!$valgrind?"":'DEJAGNU=$HOME/src/runtest-valgrind/site.exp ')
+               ."orphanripper make -k ".join(" ",@check)
+               .(!$gdbserver?"":' RUNTESTFLAGS=--target_board=native-gdbserver')
+               .(!$valgrind?"":' RUNTESTFLAGS=--target_board=valgrind')
+               .(!$gdbindex?"":' RUNTESTFLAGS="CC_FOR_TARGET=/bin/sh\ $PWD/cc-with-index.sh\ gcc CXX_FOR_TARGET=/bin/sh\ $PWD/cc-with-index.sh\ g++"')
+               .(!$dwarf4?"":' RUNTESTFLAGS="CC_FOR_TARGET=gcc\ -gdwarf-4\ -g0 CXX_FOR_TARGET=g++\ -gdwarf-4\ -g0"')
+               ." 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 {
@@ -419,7 +492,14 @@ while (@distrouse || keys(%child)) {
       subst sub { s{^.*?\n($testinlog[0]\n.*\n$testinlog[1]\n).*$}{$1}s; },$log,$out;
     } elsif ($cvsbasedir || $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";