5 use POSIX qw(&strftime);
6 use Getopt::Long qw(:config no_ignore_case);
10 my $gdbcvsmaster=$ENV{"HOME"}."/redhat/gdb-cvs-master";
11 my $binutilscvsmaster=$ENV{"HOME"}."/redhat/binutils-cvs-master";
12 my $archermaster=$ENV{"HOME"}."/redhat/gdb-master";
13 my $fedoragitroot=q{git://pkgs.fedoraproject.org};
14 #Unknown host cvs.devel.redhat.com.
15 #my $rhelcvsroot=q{:pserver:anonymous:@cvs.devel.redhat.com:/cvs/dist};
16 my $rhelcvsroot=q{:ext:cvs.devel.redhat.com:/cvs/dist};
17 my $arch_i386=qr{(?:x86|i\d86|ia32)}io;
18 my $arch_x86_64=qr{(?:x8664|x86_64|em64t)}io;
19 my $resultdir=$ENV{"HOME"}."/.hammock-result";
20 my @arches=qw(i386 x86_64);
42 # FIXME: Connect make paralellization to the children.
46 # FIXME: 20100911servpatched-f14:
47 # readchar: Connection reset by peer
48 # Remote side has terminated connection. GDBserver will reopen the connection.
49 # Can't bind address: Address already in use.
50 # <last 2 lines repearing>
55 # Use --dwarf=40 for: --dwarf=4 -fno-debug-types-section
56 # Use --dwarf=41 for: --dwarf=4 -fdebug-types-section
57 my $debug_types_section;
60 "i|userid=s"=>\$userid,
62 "serial"=>sub { $parallel=0; },
63 "parallel"=>sub { $parallel=1; },
64 "d|distro=s{,}"=>\@distro,
65 "cd|componentdistro=s{,}"=>\@componentdistro,
66 "p|path=s{,}"=>\@path,
67 "a|arch=s{,}"=>\@arch,
68 "c|component=s"=>\$component,
69 "s|srcrpm=s"=>\$srcrpm,
71 "target=s{,}"=>\@target,
72 "D|distrojobs=s"=>\$distrojobs,
73 "configure=s"=>\$configure,
75 "gdbcvspie"=>\$gdbcvspie,
77 "gdbserver"=>\$gdbserver,
78 "valgrind"=>\$valgrind,
79 "gdbindex"=>\$gdbindex,
81 "orphanripper!"=>\$orphanripper,
83 $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/*");
84 $component and $component=~m{^/home/} and (-f "$component/gdb/gdbtypes.c" or die "$component/gdb/gdbtypes.c not found");
85 $component and $srcrpm and die "-c|--component excludes -s|--srcrpm";
86 $component or $srcrpm or die "-c|--component or -s|--srcrpm required";
87 $component||=""; # Make `eq' not complaining.
89 if ($component=~/^(gdb|binutils)cvs$/) {
90 $cvsbranch=(!$branch?"-A":"-r $branch");
92 die "--branch currently unsupported for non-CVS sources" if $branch;
94 !$gdbcvspie or $component eq "gdbcvs" or die "--gdbcvspie requires -c gdbcvs";
95 @target and ($srcrpm or $component=~/^(?:fedora|rhel)/) and die "--target is available only for baretestsuite modes";
96 $strip and ($srcrpm or $component=~/^(?:fedora|rhel)/) and die "--strip is available only for baretestsuite modes";
97 $gdbserver and $component ne "gdbcvs" and die "--gdbserver is available only for gdbcvs";
98 $valgrind and $component ne "gdbcvs" and die "--valgrind is available only for gdbcvs";
99 $gdbserver and $valgrind and die "--gdbserver and --valgrind are mutually exclusive";
100 ($gdbserver || $valgrind) and $gdbindex and die "--gdbserver|--valgrind and --gdbindex are mutually exclusive";
101 do { $debug_types_section=0; $dwarf=4; } if ($dwarf||0)==40;
102 do { $debug_types_section=1; $dwarf=4; } if ($dwarf||0)==41;
103 !defined $dwarf or ($dwarf>=2 && $dwarf<=4) or die "--dwarf requires DWARF version number";
104 ($gdbserver || $valgrind || $gdbindex) and $dwarf and die "--gdbserver|--valgrind|--gdbindex and --dwarf are mutually exclusive";
105 $orphanripper=($orphanripper?"orphanripper":"");
107 do { error "Duplicate target: $_\n" if $target{$_}++; } for @target;
108 @arch="x86_64" if @target&&!@arch;
109 for my $file (@file) {
110 -f $file and -r $file or error "-f|--file $file not readable: $!";
112 $distrojobs=(@target?1:2) if !defined $distrojobs;
113 $distrojobs=~/^\d+$/ or die "-D|distrojobs must be a number: $distrojobs";
114 $distrojobs>=1 or die "-D|distrojobs must be positive: $distrojobs";
115 error "Excessive arguments: @ARGV" if @ARGV;
116 @arch=@arches if !@arch;
117 my $path=join(":",@path) if @path;
118 @componentdistro and @componentdistro!=@distro and die "--cd|--componentdistro must have the same elements count as -d|--distro";
120 sub distro_normalize($;$)
125 s{^/var/lib/mock/+}{};
128 s/^(?:devel|rawhide)\b/fedora-rawhide/;
129 s/^(?:epel|centos)-?(\d)/epel-$1/;
130 s/^(?:rhel)-?(\d)/rhel-$1/;
131 s/^(?:f|fedora)-?(\d)/fedora-$1/;
133 @archuse="" if -d "/var/lib/mock/$_";
134 @archuse="i386" if s/-$arch_i386$//o;
135 @archuse="x86_64" if s/-$arch_x86_64$//o;
137 for my $arch (@archuse?@archuse:@arch) {
138 my $dir="/var/lib/mock/$_".(!$arch?"":"-$arch");
139 $force or -d $dir or error "No distro: $dir";
142 return ($_,@archuse);
145 # epel-\d-i386|fedora-\d-i386|fedora-rawhide-i386
147 for my $distroi (0..$#distro) {
148 my $distro=$distro[$distroi];
149 my $componentdistro=$componentdistro[$distroi];
151 if ($componentdistro) {
152 my $force=($componentdistro=~s/!$//);
153 ($componentdistro,@archuse)=distro_normalize $componentdistro,$force;
154 @archuse and die "--cd|--componentdistro must have no arch: ".join(" ",@archuse);
156 ($distro,@archuse)=distro_normalize $distro;
157 $componentdistro||=$distro;
158 @archuse=@arch if !@archuse;
159 for my $archuse (@archuse) {
160 for my $target (@target?@target:undef()) {
161 push @distrouse,{"distro"=>$distro.(!$archuse?"":"-$archuse"),"componentdistro"=>$componentdistro,"target"=>$target};
171 my %opt=map(($_=>1),@opt);
172 warn "+ mkdir".($opt{"-p"} ? " -p" : "")." $dir\n";
173 mkdir $dir or ($opt{"mayexist"} && $!{EEXIST}) or die "mkdir $dir: $!";
182 my %opt=map(($_=>1),@opt);
185 $cmd="set -ex; $cmd";
186 $ok="$log.ok" if $log;
187 $cmd="($cmd; touch $ok) 2>&1|tee -a $log; test -f $ok" if $log;
193 system $cmd and die "$cmd: $!";
197 my $basedir=$ENV{"HOME"}."/hammock";
198 newdir $basedir,"mayexist";
199 my $idbase=strftime("%Y%m%d",localtime());
202 for my $seq (defined $userid ? $userid : (0..99)) {
203 $id=$idbase.(defined $userid ? $seq : sprintf("%02d",$seq));
207 spawn "chmod -R u+w $dir; rm -rf $dir" if -d $dir && $force && defined $userid;
208 error "Directory not free: $dir" if !$id || !$dir || -e $dir;
209 print STDERR "ID = $id | dir = $dir\n";
210 error "No distros specified" if !@distrouse;
211 die "$error errors seen, aborted" if $error;
215 my($fname,$content)=@_;
218 open F,">$fname" or die $fname;
219 print F $content or die $fname;
220 close F or die $fname;
224 spawn "cgclassify -g '*':hammock $$ || :";
226 spawn "renice +19 -p $$";
227 spawn "ionice -c3 -p $$";
230 my $resultid="$resultdir/$id";
231 my $resultidxz="$resultid.tar.xz";
232 newdir $resultdir,"mayexist";
233 spawn "rm -rf $resultid" if -d $resultid && $force;
235 unlink $resultidxz or $!{ENOENT} or die "unlink $resultidxz: $!";
236 spawn "uname -r >$dir/kernel";
239 "component"=>$component,
242 "file"=>join("\n",@file),
243 "configure"=>$configure,
244 "gdbcvspie"=>$gdbcvspie,
245 "gdbserver"=>$gdbserver,
246 "valgrind"=>$valgrind,
247 "gdbindex"=>$gdbindex,
249 "debug_types_section"=>$debug_types_section,
250 "orphanripper"=>$orphanripper,
252 while (my($name,$val)=each(%dump)) {
254 writefile "$dir/$name","$val\n";
255 link "$dir/$name","$resultid/$name" or warn "link $dir/$name $resultid/$name: $!";
257 for my $file (@file) {
258 newdir "$dir/file.d","mayexist";
259 (my $base=$file)=~s{^.*/}{};
260 my $d="$dir/file.d/$base";
261 link $file,$d or spawn "cp -p '$file' '$d'";
262 newdir "$resultid/file.d","mayexist";
263 link $d,"$resultid/file.d/$base" or warn "link $file $resultid/file.d/$base: $!";
268 my($sub,$in,$out)=@_;
273 open F,$in or die $in;
274 local $_=do { local $/; <F>; } or die $in;
277 &{$sub}() or die $_."\nError substituting $in";
286 for my $file (@file) {
288 $filebase=~s{^.*/}{};
289 my $target="$targetdir/$filebase";
290 # Some *.patch files may be new.
291 # -f $target or die "File $file does not exist at $target";
292 spawn "rm -f $target; cp -p $file $target";
298 while (@distrouse || keys(%child)) {
299 while (keys(%child)<$distrojobs && @distrouse) {
300 my $distrouse=shift @distrouse;
301 my $distro=$distrouse->{"distro"};
302 my $componentdistro=$distrouse->{"componentdistro"};
303 my $target=$distrouse->{"target"};
304 my $rpmbuild="rpmbuild";
312 if ($component=~/^fedora(.*)$/) {
314 $gitbranch="f$1" if $componentdistro=~/^fedora-(\d+)$/;
315 $gitbranch="master" if $componentdistro=~/^fedora-rawhide$/;
316 die "$component vs. $componentdistro" if !$gitbranch;
317 $gitroot=$fedoragitroot;
319 if ($component=~/^rhel(.*)$/) {
321 $cvsbasedir="RHEL-$1" if $componentdistro=~/^(?:epel|rhel)-(\d+)$/;
322 die "$component vs. $componentdistro" if !$cvsbasedir;
323 $cvsroot=$rhelcvsroot;
324 # EPEL still uses Berkeley DB version 8 while F-11+ (F-10?) uses version 9.
325 # Using db_dump and db_load would no longer make it mock compatible.
326 $rpmbuild.=q{ --dbpath $PWD --nodeps};
329 my $distrodirbase=$distro;
330 $distrodirbase.="-$target" if $target;
331 my $distrodir="$dir/$distrodirbase";
333 $log="$distrodir/log";
334 my $out="$distrodir/out";
339 die if !defined $pid;
341 $child{$pid}=$distrodirbase;
346 my $builddir="$distrodir/build";
349 # Do not use mockrun as the rpm database may be in a different version.
350 spawn "rpm -r /var/lib/mock/$distro/root -qa|sort >$out/rpm-qa";
357 $c="export PATH=\"$path:\$PATH\"; $c" if $path;
358 $c="export MAKEFLAGS=\"-j\$[`getconf _NPROCESSORS_ONLN`*3/2]\"; $c";
359 $c="export http_proxy=http://127.0.0.1:3128/; $c";
360 $c="set -ex; cd $builddir; $c";
361 die "found ': $c" if $c=~/'/;
362 spawn "mockrun $::distro '$c'";
369 spawn "cd $distrodir; git clone -b $gitbranch $gitroot/$gitrepo $component";
370 my $componentdir="$distrodir/$component";
371 -d $componentdir or die "Failed checkout to: $componentdir";
372 copyfiles $componentdir;
373 spawn "cd $componentdir; fedpkg verrel >$out/verrel";
374 my $glob="$componentdir/*.src.rpm";
375 @{[glob $glob]}==0 or die "Found some before test-srpm: $glob";
376 # No `spawn' as we could get:
377 # error: unpacking of archive failed on file X;4a56efef: cpio: MD5 sum mismatch
378 mockrun "cd $componentdir; fedpkg srpm";
379 my @srcrpm=(glob $glob);
380 @srcrpm==1 or die "Did not find 1 srcrpm: @srcrpm";
388 spawn "cd $distrodir; cvs -q -z3 -d $cvsroot co rpms/$cvsrepo/$cvsbasedir";
389 my $componentdir="$distrodir/rpms/$cvsrepo/$cvsbasedir";
390 -d $componentdir or die "Failed checkout to: $componentdir";
391 # Required for RHEL; Fedora does so automatically.
392 spawn "cd $componentdir/..; cvs -q -z3 -d $cvsroot co common";
393 # Workaround (RHEL-5?) curl which uses `Pragma: nocache' on $http_proxy.
394 subst sub { s{echo "curl }{$&-H 'Pragma: cache' }; },"$componentdir/../common/Makefile.common";
395 copyfiles $componentdir;
396 spawn "cd $componentdir; make verrel >$out/verrel";
397 my $glob="$componentdir/*.src.rpm";
398 @{[glob $glob]}==0 or die "Found some before test-srpm: $glob";
399 # No `spawn' as we could get:
400 # error: unpacking of archive failed on file X;4a56efef: cpio: MD5 sum mismatch
401 mockrun "cd $componentdir; make test-srpm";
402 my @srcrpm=(glob $glob);
403 @srcrpm==1 or die "Did not find 1 srcrpm: @srcrpm";
408 my $srcrpmbasename=$srcrpm;
409 $srcrpmbasename=~s{^.*/}{};
410 spawn "cp -p $srcrpm $builddir/$srcrpmbasename";
412 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"};
413 $rpmbuildlocal="$orphanripper $rpmbuildlocal" if $cvsrepo && $cvsrepo eq "glibc";
414 mockrun $rpmbuildlocal." --rebuild --with testsuite $srcrpmbasename";
419 if ($component=~/^(gdb|binutils)cvs$/) {
421 my $cvsmaster=$which eq "gdb" ? $gdbcvsmaster : $binutilscvsmaster;
423 spawn "cp -a $cvsmaster $builddir/src; cd $builddir/src; cvs update $cvsbranch";
425 spawn "cd $builddir; cvs -q -z3 -d :pserver:anoncvs:\@sourceware.org:/cvs/src co $cvsbranch $which";
427 spawn "cd $builddir/src; test -z \"\$(cvs update $cvsbranch)\"";
428 $baretestsuite="$builddir/src";
431 if ($component=~/^archer-/) {
432 spawn "git clone ".(!-d $archermaster ? "" : "--reference $archermaster")." git://sourceware.org/git/archer.git $builddir/$component";
433 spawn "cd $builddir/$component; git fetch";
434 spawn "cd $builddir/$component; git checkout -b $component origin/$component; [ \"`git status`\" = \"# On branch $component\nnothing to commit (working directory clean)\" ]";
435 $baretestsuite="$builddir/$component";
438 if ($component=~m{^/home/}) {
439 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 || :";
440 $baretestsuite="$builddir/src";
443 if ($baretestsuite) {
444 for my $file (@file) {
445 my $target="$baretestsuite/$file";
446 if ($file=~m{[.](R?)patch$}) {
449 $fileabs=$ENV{"PWD"}."/$fileabs" if $fileabs!~m{^/};
450 spawn "cd $baretestsuite; patch -${R}p1 <$fileabs";
452 -f $target or $file=~m{/testsuite/} or die "File $file does not exist at $target";
453 spawn "rm -f $target; cp -p $file $target";
458 $errs12.=" -s" if $strip;
459 $errs12.=" --target=$target" if $target;
460 $errs12.=" $configure" if $configure;
462 if ($component eq "binutilscvs") {
463 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;};
467 do { unlink $_ or warn "$_: $!"; } for "$baretestsuite/gdb/testsuite/gdb.base/break-interp.exp";
469 my @check=($distro=~/-x86_64/ ? qw(-m64 -m32) : -m32);
470 @check=map("check//unix/$_",@check);
471 @check=map({($_,"$_/-fPIE/-pie");} @check) if $gdbcvspie;
472 # for i in ".join(" ",@check).";do $orphanripper make -k \$i || :;done
477 return ' RUNTESTFLAGS="CC_FOR_TARGET=gcc\ '.$_.' CXX_FOR_TARGET=g++\ '.$_.'"'
479 mockrun "cd $baretestsuite;"
480 .(!$valgrind?"":' HAMMOCK_VALGRIND=1')
482 .(!$valgrind?"":' --without-python') # FIXME: Fix valgrind --suppressions
483 ."; cd gdb; ulimit -c unlimited; "
484 .(!$gdbserver?"":'DEJAGNU=$HOME/src/runtest-gdbserver/site.exp ')
485 .(!$valgrind?"":'DEJAGNU=$HOME/src/runtest-valgrind/site.exp ')
486 ."$orphanripper make -k ".join(" ",@check)
487 # Ensure serial run if FORCE_PARALLEL=1 is not present
488 ." RUNTESTFLAGS=DUMMY=dummy"
489 .(!$gdbserver?"":' RUNTESTFLAGS=--target_board=native-gdbserver')
490 .(!$valgrind?"":' RUNTESTFLAGS=--target_board=valgrind')
491 .(!$gdbindex?"":' RUNTESTFLAGS="CC_FOR_TARGET=/bin/sh\ $PWD/cc-with-index.sh\ gcc CXX_FOR_TARGET=/bin/sh\ $PWD/cc-with-index.sh\ g++"')
492 .(!$dwarf?"":runtestcc "-gdwarf-$dwarf".(!defined $debug_types_section?"":'\ '.($debug_types_section?"-fdebug-types-section":"-fno-debug-types-section"))." -g0")
493 .(!$parallel?"":' FORCE_PARALLEL=1')
494 ." || :; ".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;};
497 # perl -i -pe 's{\Q'"$HOME"'\E/.*?/build/[^/]*/}{}g' "$base"/*
498 my $HOME=$ENV{"HOME"};
499 for my $file (glob("$out/*.sum"),glob("$out/*.log")) {
500 subst sub { s{\Q$HOME\E/.*?/build/[^/]*/}{}g; },$file;
503 die "internal error" if @target;
506 # Call gdbunpack only if no direct $out directory will be created.
507 # It is needed only for .src.rpm-built testsuites, no matter how .src.rpm
510 if ($component=~/^(?:fedora|rhel)glibc$/) {
511 @testinlog=(qr/={20}TESTING DETAILS={17}/,qr/={20}PLT RELOCS END={18}/);
514 subst sub { s{^.*?\n($testinlog[0]\n.*\n$testinlog[1]\n).*$}{$1}s; },$log,$out;
515 } elsif ($cvsbasedir || $srcrpm) {
516 # Applies both to gdb and binutils.
517 spawn "mv $out $out.x; gdbunpack $log; mv $out.x/* $out/; rmdir $out.x";
521 for my $from (glob "$out/*.log") {
522 (my $to=$from).="filt";
523 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;
527 my $resultout="$resultdir/$id/$distrodirbase";
531 for my $fname (glob "$out/*") {
532 (my $base=$fname)=~s{^.*/}{};
533 my $d="$resultout/$base";
534 warn "+ link $fname $d\n";
535 link $fname,$d or warn $!;
541 print STDERR "waiting for ".scalar(keys(%child))." children, ".scalar(@distrouse)." distros to go...\n";
543 next if $pid==-1 && $!==10; # 10==No child processes
544 die "wait()==-1: $!" if $pid==-1;
545 die "not found pid $pid" if !$child{$pid};
546 error "weird status $? for pid $pid: ".$child{$pid} if $?;
547 print STDERR "finished: $pid ".$child{$pid}."\n";
553 spawn "(set -e -o pipefail;cd $resultdir;tar cf - $id|xz -9e >$resultidxz;rm -rf $id)&","bare";
561 $r.=int($sec/(60*60))."h";
564 if ($r || $sec>=60) {
565 $r.=int($sec/60)."m";
573 print STDERR "ID = $id | dir = $dir\n";
574 my $time=timestr(time()-$start);
575 print STDERR "total time=$time\n";
576 writefile "$dir/time","$time\n";
577 die "$error errors seen, aborted" if $error;
578 print STDERR "done\n";