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/archer-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>
57 "i|userid=s"=>\$userid,
59 "serial"=>sub { $parallel=0; },
60 "parallel"=>sub { $parallel=1; },
61 "d|distro=s{,}"=>\@distro,
62 "cd|componentdistro=s{,}"=>\@componentdistro,
63 "p|path=s{,}"=>\@path,
64 "a|arch=s{,}"=>\@arch,
65 "c|component=s"=>\$component,
66 "s|srcrpm=s"=>\$srcrpm,
68 "target=s{,}"=>\@target,
69 "D|distrojobs=s"=>\$distrojobs,
70 "configure=s"=>\$configure,
72 "gdbcvspie"=>\$gdbcvspie,
74 "gdbserver"=>\$gdbserver,
75 "valgrind"=>\$valgrind,
76 "gdbindex"=>\$gdbindex,
78 "orphanripper!"=>\$orphanripper,
80 $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/*");
81 $component and $component=~m{^/home/} and (-f "$component/gdb/gdbtypes.c" or die "$component/gdb/gdbtypes.c not found");
82 $component and $srcrpm and die "-c|--component excludes -s|--srcrpm";
83 $component or $srcrpm or die "-c|--component or -s|--srcrpm required";
84 $component||=""; # Make `eq' not complaining.
86 if ($component=~/^(gdb|binutils)cvs$/) {
87 $cvsbranch=(!$branch?"-A":"-r $branch");
89 die "--branch currently unsupported for non-CVS sources" if $branch;
91 !$gdbcvspie or $component eq "gdbcvs" or die "--gdbcvspie requires -c gdbcvs";
92 @target and ($srcrpm or $component=~/^(?:fedora|rhel)/) and die "--target is available only for baretestsuite modes";
93 $strip and ($srcrpm or $component=~/^(?:fedora|rhel)/) and die "--strip is available only for baretestsuite modes";
94 $gdbserver and $component ne "gdbcvs" and die "--gdbserver is available only for gdbcvs";
95 $valgrind and $component ne "gdbcvs" and die "--valgrind is available only for gdbcvs";
96 $gdbserver and $valgrind and die "--gdbserver and --valgrind are mutually exclusive";
97 ($gdbserver || $valgrind) and $gdbindex and die "--gdbserver|--valgrind and --gdbindex are mutually exclusive";
98 !defined $dwarf or ($dwarf>=2 && $dwarf<=4) or die "--dwarf requires DWARF version number";
99 ($gdbserver || $valgrind || $gdbindex) and $dwarf and die "--gdbserver|--valgrind|--gdbindex and --dwarf are mutually exclusive";
100 $orphanripper=($orphanripper?"orphanripper":"");
102 do { error "Duplicate target: $_\n" if $target{$_}++; } for @target;
103 @arch="x86_64" if @target&&!@arch;
104 for my $file (@file) {
105 -f $file and -r $file or error "-f|--file $file not readable: $!";
107 $distrojobs=(@target?1:2) if !defined $distrojobs;
108 $distrojobs=~/^\d+$/ or die "-D|distrojobs must be a number: $distrojobs";
109 $distrojobs>=1 or die "-D|distrojobs must be positive: $distrojobs";
110 error "Excessive arguments: @ARGV" if @ARGV;
111 @arch=@arches if !@arch;
112 my $path=join(":",@path) if @path;
113 @componentdistro and @componentdistro!=@distro and die "--cd|--componentdistro must have the same elements count as -d|--distro";
115 sub distro_normalize($;$)
120 s{^/var/lib/mock/+}{};
123 s/^(?:devel|rawhide)\b/fedora-rawhide/;
124 s/^(?:epel|centos)-?(\d)/epel-$1/;
125 s/^(?:rhel)-?(\d)/rhel-$1/;
126 s/^(?:f|fedora)-?(\d)/fedora-$1/;
128 @archuse="" if -d "/var/lib/mock/$_";
129 @archuse="i386" if s/-$arch_i386$//o;
130 @archuse="x86_64" if s/-$arch_x86_64$//o;
132 for my $arch (@archuse?@archuse:@arch) {
133 my $dir="/var/lib/mock/$_".(!$arch?"":"-$arch");
134 $force or -d $dir or error "No distro: $dir";
137 return ($_,@archuse);
140 # epel-\d-i386|fedora-\d-i386|fedora-rawhide-i386
142 for my $distroi (0..$#distro) {
143 my $distro=$distro[$distroi];
144 my $componentdistro=$componentdistro[$distroi];
146 if ($componentdistro) {
147 my $force=($componentdistro=~s/!$//);
148 ($componentdistro,@archuse)=distro_normalize $componentdistro,$force;
149 @archuse and die "--cd|--componentdistro must have no arch: ".join(" ",@archuse);
151 ($distro,@archuse)=distro_normalize $distro;
152 $componentdistro||=$distro;
153 @archuse=@arch if !@archuse;
154 for my $archuse (@archuse) {
155 for my $target (@target?@target:undef()) {
156 push @distrouse,{"distro"=>$distro.(!$archuse?"":"-$archuse"),"componentdistro"=>$componentdistro,"target"=>$target};
166 my %opt=map(($_=>1),@opt);
167 warn "+ mkdir".($opt{"-p"} ? " -p" : "")." $dir\n";
168 mkdir $dir or ($opt{"mayexist"} && $!{EEXIST}) or die "mkdir $dir: $!";
177 my %opt=map(($_=>1),@opt);
180 $cmd="set -ex; $cmd";
181 $ok="$log.ok" if $log;
182 $cmd="($cmd; touch $ok) 2>&1|tee -a $log; test -f $ok" if $log;
188 system $cmd and die "$cmd: $!";
192 my $basedir=$ENV{"HOME"}."/hammock";
193 newdir $basedir,"mayexist";
194 my $idbase=strftime("%Y%m%d",localtime());
197 for my $seq (defined $userid ? $userid : (0..99)) {
198 $id=$idbase.(defined $userid ? $seq : sprintf("%02d",$seq));
202 spawn "chmod -R u+w $dir; rm -rf $dir" if -d $dir && $force && defined $userid;
203 error "Directory not free: $dir" if !$id || !$dir || -e $dir;
204 print STDERR "ID = $id | dir = $dir\n";
205 error "No distros specified" if !@distrouse;
206 die "$error errors seen, aborted" if $error;
210 my($fname,$content)=@_;
213 open F,">$fname" or die $fname;
214 print F $content or die $fname;
215 close F or die $fname;
219 spawn "echo cgclassify -g '*':hammock $$ || :";
221 spawn "renice +19 -p $$";
222 spawn "ionice -c3 -p $$";
225 my $resultid="$resultdir/$id";
226 my $resultidxz="$resultid.tar.xz";
227 newdir $resultdir,"mayexist";
228 spawn "rm -rf $resultid" if -d $resultid && $force;
230 unlink $resultidxz or $!{ENOENT} or die "unlink $resultidxz: $!";
231 spawn "uname -r >$dir/kernel";
234 "component"=>$component,
237 "file"=>join("\n",@file),
238 "configure"=>$configure,
239 "gdbcvspie"=>$gdbcvspie,
240 "gdbserver"=>$gdbserver,
241 "valgrind"=>$valgrind,
242 "gdbindex"=>$gdbindex,
244 "orphanripper"=>$orphanripper,
246 while (my($name,$val)=each(%dump)) {
248 writefile "$dir/$name","$val\n";
249 link "$dir/$name","$resultid/$name" or warn "link $dir/$name $resultid/$name: $!";
251 for my $file (@file) {
252 newdir "$dir/file.d","mayexist";
253 (my $base=$file)=~s{^.*/}{};
254 my $d="$dir/file.d/$base";
255 link $file,$d or die "link $file $d: $!";
256 newdir "$resultid/file.d","mayexist";
257 link $d,"$resultid/file.d/$base" or warn "link $file $resultid/file.d/$base: $!";
262 my($sub,$in,$out)=@_;
267 open F,$in or die $in;
268 local $_=do { local $/; <F>; } or die $in;
271 &{$sub}() or die $_."\nError substituting $in";
280 for my $file (@file) {
282 $filebase=~s{^.*/}{};
283 my $target="$targetdir/$filebase";
284 # Some *.patch files may be new.
285 # -f $target or die "File $file does not exist at $target";
286 spawn "rm -f $target; cp -p $file $target";
292 while (@distrouse || keys(%child)) {
293 while (keys(%child)<$distrojobs && @distrouse) {
294 my $distrouse=shift @distrouse;
295 my $distro=$distrouse->{"distro"};
296 my $componentdistro=$distrouse->{"componentdistro"};
297 my $target=$distrouse->{"target"};
298 my $rpmbuild="rpmbuild";
306 if ($component=~/^fedora(.*)$/) {
308 $gitbranch="f$1/master" if $componentdistro=~/^fedora-(\d+)$/;
309 $gitbranch="master" if $componentdistro=~/^fedora-rawhide$/;
310 die "$component vs. $componentdistro" if !$gitbranch;
311 $gitroot=$fedoragitroot;
313 if ($component=~/^rhel(.*)$/) {
315 $cvsbasedir="RHEL-$1" if $componentdistro=~/^(?:epel|rhel)-(\d+)$/;
316 die "$component vs. $componentdistro" if !$cvsbasedir;
317 $cvsroot=$rhelcvsroot;
318 # EPEL still uses Berkeley DB version 8 while F-11+ (F-10?) uses version 9.
319 # Using db_dump and db_load would no longer make it mock compatible.
320 $rpmbuild.=q{ --dbpath $PWD --nodeps};
323 my $distrodirbase=$distro;
324 $distrodirbase.="-$target" if $target;
325 my $distrodir="$dir/$distrodirbase";
327 $log="$distrodir/log";
328 my $out="$distrodir/out";
333 die if !defined $pid;
335 $child{$pid}=$distrodirbase;
340 my $builddir="$distrodir/build";
343 # Do not use mockrun as the rpm database may be in a different version.
344 spawn "rpm -r /var/lib/mock/$distro/root -qa|sort >$out/rpm-qa";
351 $c="export PATH=\"$path:\$PATH\"; $c" if $path;
352 $c="export MAKEFLAGS=\"-j\$[`getconf _NPROCESSORS_ONLN`*3/2]\"; $c";
353 $c="export http_proxy=http://127.0.0.1:3128/; $c";
354 $c="set -ex; cd $builddir; $c";
355 die "found ': $c" if $c=~/'/;
356 spawn "mockrun $::distro '$c'";
363 spawn "cd $distrodir; git clone -b $gitbranch $gitroot/$gitrepo $component";
364 my $componentdir="$distrodir/$component";
365 -d $componentdir or die "Failed checkout to: $componentdir";
366 copyfiles $componentdir;
367 spawn "cd $componentdir; fedpkg verrel >$out/verrel";
368 my $glob="$componentdir/*.src.rpm";
369 @{[glob $glob]}==0 or die "Found some before test-srpm: $glob";
370 # No `spawn' as we could get:
371 # error: unpacking of archive failed on file X;4a56efef: cpio: MD5 sum mismatch
372 mockrun "cd $componentdir; fedpkg srpm";
373 my @srcrpm=(glob $glob);
374 @srcrpm==1 or die "Did not find 1 srcrpm: @srcrpm";
382 spawn "cd $distrodir; cvs -q -z3 -d $cvsroot co rpms/$cvsrepo/$cvsbasedir";
383 my $componentdir="$distrodir/rpms/$cvsrepo/$cvsbasedir";
384 -d $componentdir or die "Failed checkout to: $componentdir";
385 # Required for RHEL; Fedora does so automatically.
386 spawn "cd $componentdir/..; cvs -q -z3 -d $cvsroot co common";
387 # Workaround (RHEL-5?) curl which uses `Pragma: nocache' on $http_proxy.
388 subst sub { s{echo "curl }{$&-H 'Pragma: cache' }; },"$componentdir/../common/Makefile.common";
389 copyfiles $componentdir;
390 spawn "cd $componentdir; make verrel >$out/verrel";
391 my $glob="$componentdir/*.src.rpm";
392 @{[glob $glob]}==0 or die "Found some before test-srpm: $glob";
393 # No `spawn' as we could get:
394 # error: unpacking of archive failed on file X;4a56efef: cpio: MD5 sum mismatch
395 mockrun "cd $componentdir; make test-srpm";
396 my @srcrpm=(glob $glob);
397 @srcrpm==1 or die "Did not find 1 srcrpm: @srcrpm";
402 my $srcrpmbasename=$srcrpm;
403 $srcrpmbasename=~s{^.*/}{};
404 spawn "cp -p $srcrpm $builddir/$srcrpmbasename";
406 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"};
407 $rpmbuildlocal="$orphanripper $rpmbuildlocal" if $cvsrepo && $cvsrepo eq "glibc";
408 mockrun $rpmbuildlocal." --rebuild --with testsuite $srcrpmbasename";
413 if ($component=~/^(gdb|binutils)cvs$/) {
415 my $cvsmaster=$which eq "gdb" ? $gdbcvsmaster : $binutilscvsmaster;
417 spawn "cp -a $cvsmaster $builddir/src; cd $builddir/src; cvs update $cvsbranch";
419 spawn "cd $builddir; cvs -q -z3 -d :pserver:anoncvs:\@sourceware.org:/cvs/src co $cvsbranch $which";
421 spawn "cd $builddir/src; test -z \"\$(cvs update $cvsbranch)\"";
422 $baretestsuite="$builddir/src";
425 if ($component=~/^archer-/) {
426 spawn "git clone ".(!-d $archermaster ? "" : "--reference $archermaster")." git://sourceware.org/git/archer.git $builddir/$component";
427 spawn "cd $builddir/$component; git fetch";
428 spawn "cd $builddir/$component; git checkout -b $component origin/$component; [ \"`git status`\" = \"# On branch $component\nnothing to commit (working directory clean)\" ]";
429 $baretestsuite="$builddir/$component";
432 if ($component=~m{^/home/}) {
433 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 || :";
434 $baretestsuite="$builddir/src";
437 if ($baretestsuite) {
438 for my $file (@file) {
439 my $target="$baretestsuite/$file";
440 if ($file=~m{[.](R?)patch$}) {
443 $fileabs=$ENV{"PWD"}."/$fileabs" if $fileabs!~m{^/};
444 spawn "cd $baretestsuite; patch -${R}p1 <$fileabs";
446 -f $target or $file=~m{/testsuite/} or die "File $file does not exist at $target";
447 spawn "rm -f $target; cp -p $file $target";
452 $errs12.=" -s" if $strip;
453 $errs12.=" --target=$target" if $target;
454 $errs12.=" $configure" if $configure;
456 if ($component eq "binutilscvs") {
457 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;};
459 my @check=($distro=~/-x86_64/ ? qw(-m64 -m32) : -m32);
460 @check=map("check//unix/$_",@check);
461 @check=map({($_,"$_/-fPIE/-pie");} @check) if $gdbcvspie;
462 # for i in ".join(" ",@check).";do $orphanripper make -k \$i || :;done
463 mockrun "cd $baretestsuite;"
464 .(!$valgrind?"":' HAMMOCK_VALGRIND=1')
466 .(!$valgrind?"":' --without-python') # FIXME: Fix valgrind --suppressions
467 ."; cd gdb; ulimit -c unlimited; "
468 .(!$gdbserver?"":'DEJAGNU=$HOME/src/runtest-gdbserver/site.exp ')
469 .(!$valgrind?"":'DEJAGNU=$HOME/src/runtest-valgrind/site.exp ')
470 ."$orphanripper make -k ".join(" ",@check)
471 # Ensure serial run if FORCE_PARALLEL=1 is not present
472 ." RUNTESTFLAGS=DUMMY=dummy"
473 .(!$gdbserver?"":' RUNTESTFLAGS=--target_board=native-gdbserver')
474 .(!$valgrind?"":' RUNTESTFLAGS=--target_board=valgrind')
475 .(!$gdbindex?"":' RUNTESTFLAGS="CC_FOR_TARGET=/bin/sh\ $PWD/cc-with-index.sh\ gcc CXX_FOR_TARGET=/bin/sh\ $PWD/cc-with-index.sh\ g++"')
476 .(!$dwarf?"":' RUNTESTFLAGS="CC_FOR_TARGET=gcc\ -gdwarf-'.$dwarf.'\ -g0 CXX_FOR_TARGET=g++\ -gdwarf-'.$dwarf.'\ -g0"')
477 .(!$parallel?"":' FORCE_PARALLEL=1')
478 ." || :; ".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;};
481 # perl -i -pe 's{\Q'"$HOME"'\E/.*?/build/[^/]*/}{}g' "$base"/*
482 my $HOME=$ENV{"HOME"};
483 for my $file (glob("$out/*.sum"),glob("$out/*.log")) {
484 subst sub { s{\Q$HOME\E/.*?/build/[^/]*/}{}g; },$file;
487 die "internal error" if @target;
490 # Call gdbunpack only if no direct $out directory will be created.
491 # It is needed only for .src.rpm-built testsuites, no matter how .src.rpm
494 if ($component=~/^(?:fedora|rhel)glibc$/) {
495 @testinlog=(qr/={20}TESTING DETAILS={17}/,qr/={20}PLT RELOCS END={18}/);
498 subst sub { s{^.*?\n($testinlog[0]\n.*\n$testinlog[1]\n).*$}{$1}s; },$log,$out;
499 } elsif ($cvsbasedir || $srcrpm) {
500 # Applies both to gdb and binutils.
501 spawn "mv $out $out.x; gdbunpack $log; mv $out.x/* $out/; rmdir $out.x";
505 for my $from (glob "$out/*.log") {
506 (my $to=$from).="filt";
507 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;
511 my $resultout="$resultdir/$id/$distrodirbase";
515 for my $fname (glob "$out/*") {
516 (my $base=$fname)=~s{^.*/}{};
517 my $d="$resultout/$base";
518 warn "+ link $fname $d\n";
519 link $fname,$d or warn $!;
525 print STDERR "waiting for ".scalar(keys(%child))." children, ".scalar(@distrouse)." distros to go...\n";
527 next if $pid==-1 && $!==10; # 10==No child processes
528 die "wait()==-1: $!" if $pid==-1;
529 die "not found pid $pid" if !$child{$pid};
530 error "weird status $? for pid $pid: ".$child{$pid} if $?;
531 print STDERR "finished: $pid ".$child{$pid}."\n";
537 spawn "(set -e -o pipefail;cd $resultdir;tar cf - $id|xz -9e >$resultidxz;rm -rf $id)&","bare";
545 $r.=int($sec/(60*60))."h";
548 if ($r || $sec>=60) {
549 $r.=int($sec/60)."m";
557 print STDERR "ID = $id | dir = $dir\n";
558 my $time=timestr(time()-$start);
559 print STDERR "total time=$time\n";
560 writefile "$dir/time","$time\n";
561 die "$error errors seen, aborted" if $error;
562 print STDERR "done\n";