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);
31 my $parallel=9; # 1 or 2 or 3
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>
56 "i|userid=s"=>\$userid,
58 "1|serial"=>sub { $parallel=1; },
59 "2|standard"=>sub { $parallel=2; },
60 "3|parallel"=>sub { $parallel=3; },
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,
79 $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/*");
80 $component and $component=~m{^/home/} and (-f "$component/gdb/gdbtypes.c" or die "$component/gdb/gdbtypes.c not found");
81 $component and $srcrpm and die "-c|--component excludes -s|--srcrpm";
82 $component or $srcrpm or die "-c|--component or -s|--srcrpm required";
83 $component||=""; # Make `eq' not complaining.
85 if ($component=~/^(gdb|binutils)cvs$/) {
86 $cvsbranch=(!$branch?"-A":"-r $branch");
88 die "--branch currently unsupported for non-CVS sources" if $branch;
90 !$gdbcvspie or $component eq "gdbcvs" or die "--gdbcvspie requires -c gdbcvs";
91 @target and ($srcrpm or $component=~/^(?:fedora|rhel)/) and die "--target is available only for baretestsuite modes";
92 $strip and ($srcrpm or $component=~/^(?:fedora|rhel)/) and die "--strip is available only for baretestsuite modes";
93 $gdbserver and $component ne "gdbcvs" and die "--gdbserver is available only for gdbcvs";
94 $valgrind and $component ne "gdbcvs" and die "--valgrind is available only for gdbcvs";
95 $gdbserver and $valgrind and die "--gdbserver and --valgrind are mutually exclusive";
96 ($gdbserver || $valgrind) and $gdbindex and die "--gdbserver|--valgrind and --gdbindex are mutually exclusive";
97 ($gdbserver || $valgrind || $gdbindex) and $dwarf4 and die "--gdbserver|--valgrind|--gdbindex and --dwarf4 are mutually exclusive";
99 do { error "Duplicate target: $_\n" if $target{$_}++; } for @target;
100 @arch="x86_64" if @target&&!@arch;
101 for my $file (@file) {
102 -f $file and -r $file or error "-f|--file $file not readable: $!";
104 $distrojobs=(@target?1:2) if !defined $distrojobs;
105 $distrojobs=~/^\d+$/ or die "-D|distrojobs must be a number: $distrojobs";
106 $distrojobs>=1 or die "-D|distrojobs must be positive: $distrojobs";
107 # User may want to modify ASAP her files submitted for the test.
108 my $will_copy=@file || $component=~m{^/home/};
109 $parallel||=$will_copy ? 2 : 1;
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,
245 while (my($name,$val)=each(%dump)) {
247 writefile "$dir/$name","$val\n";
248 link "$dir/$name","$resultid/$name" or warn "link $dir/$name $resultid/$name: $!";
250 for my $file (@file) {
251 newdir "$dir/file.d","mayexist";
252 (my $base=$file)=~s{^.*/}{};
253 my $d="$dir/file.d/$base";
254 link $file,$d or die "link $file $d: $!";
255 newdir "$resultid/file.d","mayexist";
256 link $d,"$resultid/file.d/$base" or warn "link $file $resultid/file.d/$base: $!";
261 my($sub,$in,$out)=@_;
266 open F,$in or die $in;
267 local $_=do { local $/; <F>; } or die $in;
270 &{$sub}() or die $_."\nError substituting $in";
279 for my $file (@file) {
281 $filebase=~s{^.*/}{};
282 my $target="$targetdir/$filebase";
283 # Some *.patch files may be new.
284 # -f $target or die "File $file does not exist at $target";
285 spawn "rm -f $target; cp -p $file $target";
291 while (@distrouse || keys(%child)) {
292 while (keys(%child)<$distrojobs && @distrouse) {
293 my $distrouse=shift @distrouse;
294 my $distro=$distrouse->{"distro"};
295 my $componentdistro=$distrouse->{"componentdistro"};
296 my $target=$distrouse->{"target"};
297 my $rpmbuild="rpmbuild";
305 if ($component=~/^fedora(.*)$/) {
307 $gitbranch="f$1/master" if $componentdistro=~/^fedora-(\d+)$/;
308 $gitbranch="master" if $componentdistro=~/^fedora-rawhide$/;
309 die "$component vs. $componentdistro" if !$gitbranch;
310 $gitroot=$fedoragitroot;
312 if ($component=~/^rhel(.*)$/) {
314 $cvsbasedir="RHEL-$1" if $componentdistro=~/^(?:epel|rhel)-(\d+)$/;
315 die "$component vs. $componentdistro" if !$cvsbasedir;
316 $cvsroot=$rhelcvsroot;
317 # EPEL still uses Berkeley DB version 8 while F-11+ (F-10?) uses version 9.
318 # Using db_dump and db_load would no longer make it mock compatible.
319 $rpmbuild.=q{ --dbpath $PWD --nodeps};
322 my $distrodirbase=$distro;
323 $distrodirbase.="-$target" if $target;
324 my $distrodir="$dir/$distrodirbase";
326 $log="$distrodir/log";
327 my $out="$distrodir/out";
332 die if !defined $pid;
334 $child{$pid}=$distrodirbase;
339 my $builddir="$distrodir/build";
342 # Do not use mockrun as the rpm database may be in a different version.
343 spawn "rpm -r /var/lib/mock/$distro/root -qa|sort >$out/rpm-qa";
350 $c="export PATH=\"$path:\$PATH\"; $c" if $path;
351 $c="export MAKEFLAGS=\"-j\$[`getconf _NPROCESSORS_ONLN`*3/2]\"; $c";
352 $c="export http_proxy=http://127.0.0.1:3128/; $c";
353 $c="set -ex; cd $builddir; $c";
354 die "found ': $c" if $c=~/'/;
355 spawn "mockrun $::distro '$c'";
362 spawn "cd $distrodir; git clone -b $gitbranch $gitroot/$gitrepo $component";
363 my $componentdir="$distrodir/$component";
364 -d $componentdir or die "Failed checkout to: $componentdir";
365 copyfiles $componentdir;
366 spawn "cd $componentdir; fedpkg verrel >$out/verrel";
367 my $glob="$componentdir/*.src.rpm";
368 @{[glob $glob]}==0 or die "Found some before test-srpm: $glob";
369 # No `spawn' as we could get:
370 # error: unpacking of archive failed on file X;4a56efef: cpio: MD5 sum mismatch
371 mockrun "cd $componentdir; fedpkg srpm";
372 my @srcrpm=(glob $glob);
373 @srcrpm==1 or die "Did not find 1 srcrpm: @srcrpm";
381 spawn "cd $distrodir; cvs -q -z3 -d $cvsroot co rpms/$cvsrepo/$cvsbasedir";
382 my $componentdir="$distrodir/rpms/$cvsrepo/$cvsbasedir";
383 -d $componentdir or die "Failed checkout to: $componentdir";
384 # Required for RHEL; Fedora does so automatically.
385 spawn "cd $componentdir/..; cvs -q -z3 -d $cvsroot co common";
386 # Workaround (RHEL-5?) curl which uses `Pragma: nocache' on $http_proxy.
387 subst sub { s{echo "curl }{$&-H 'Pragma: cache' }; },"$componentdir/../common/Makefile.common";
388 copyfiles $componentdir;
389 spawn "cd $componentdir; make verrel >$out/verrel";
390 my $glob="$componentdir/*.src.rpm";
391 @{[glob $glob]}==0 or die "Found some before test-srpm: $glob";
392 # No `spawn' as we could get:
393 # error: unpacking of archive failed on file X;4a56efef: cpio: MD5 sum mismatch
394 mockrun "cd $componentdir; make test-srpm";
395 my @srcrpm=(glob $glob);
396 @srcrpm==1 or die "Did not find 1 srcrpm: @srcrpm";
401 my $srcrpmbasename=$srcrpm;
402 $srcrpmbasename=~s{^.*/}{};
403 spawn "cp -p $srcrpm $builddir/$srcrpmbasename";
405 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"};
406 $rpmbuildlocal="orphanripper $rpmbuildlocal" if $cvsrepo && $cvsrepo eq "glibc";
407 mockrun $rpmbuildlocal." --rebuild --with testsuite".($parallel<2 ? "" : " --with parallel")." $srcrpmbasename";
412 if ($component=~/^(gdb|binutils)cvs$/) {
414 my $cvsmaster=$which eq "gdb" ? $gdbcvsmaster : $binutilscvsmaster;
416 spawn "cp -a $cvsmaster $builddir/src; cd $builddir/src; cvs update $cvsbranch";
418 spawn "cd $builddir; cvs -q -z3 -d :pserver:anoncvs:\@sourceware.org:/cvs/src co $cvsbranch $which";
420 spawn "cd $builddir/src; test -z \"\$(cvs update $cvsbranch)\"";
421 $baretestsuite="$builddir/src";
424 if ($component=~/^archer-/) {
425 spawn "git clone ".(!-d $archermaster ? "" : "--reference $archermaster")." git://sourceware.org/git/archer.git $builddir/$component";
426 spawn "cd $builddir/$component; git fetch";
427 spawn "cd $builddir/$component; git checkout -b $component origin/$component; [ \"`git status`\" = \"# On branch $component\nnothing to commit (working directory clean)\" ]";
428 $baretestsuite="$builddir/$component";
431 if ($component=~m{^/home/}) {
432 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 || :";
433 $baretestsuite="$builddir/src";
436 if ($baretestsuite) {
437 for my $file (@file) {
438 my $target="$baretestsuite/$file";
439 if ($file=~m{[.](R?)patch$}) {
442 $fileabs=$ENV{"PWD"}."/$fileabs" if $fileabs!~m{^/};
443 spawn "cd $baretestsuite; patch -${R}p1 <$fileabs";
445 -f $target or $file=~m{/testsuite/} or die "File $file does not exist at $target";
446 spawn "rm -f $target; cp -p $file $target";
451 $errs12.=" -s" if $strip;
452 $errs12.=" --target=$target" if $target;
453 $errs12.=" $configure" if $configure;
455 if ($component eq "binutilscvs") {
456 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;};
458 my @check=($distro=~/-x86_64/ ? qw(-m64 -m32) : -m32);
459 @check=map("check//unix/$_",@check);
460 @check=map({($_,"$_/-fPIE/-pie");} @check) if $gdbcvspie;
461 # for i in ".join(" ",@check).";do orphanripper make -k \$i || :;done
462 mockrun "cd $baretestsuite; $errs12"
463 .(!$valgrind?"":' --without-python') # FIXME: Fix valgrind --suppressions
464 ."; cd gdb; ulimit -c unlimited; "
465 .(!$gdbserver?"":'DEJAGNU=$HOME/src/runtest-gdbserver/site.exp ')
466 .(!$valgrind?"":'DEJAGNU=$HOME/src/runtest-valgrind/site.exp ')
467 ."orphanripper make -k ".join(" ",@check)
468 .(!$gdbserver?"":' RUNTESTFLAGS=--target_board=native-gdbserver')
469 .(!$valgrind?"":' RUNTESTFLAGS=--target_board=valgrind')
470 .(!$gdbindex?"":' RUNTESTFLAGS="CC_FOR_TARGET=/bin/sh\ $PWD/cc-with-index.sh\ gcc CXX_FOR_TARGET=/bin/sh\ $PWD/cc-with-index.sh\ g++"')
471 .(!$dwarf4?"":' RUNTESTFLAGS="CC_FOR_TARGET=gcc\ -gdwarf-4\ -g0 CXX_FOR_TARGET=g++\ -gdwarf-4\ -g0"')
472 ." 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;};
475 # perl -i -pe 's{\Q'"$HOME"'\E/.*?/build/[^/]*/}{}g' "$base"/*
476 my $HOME=$ENV{"HOME"};
477 for my $file (glob("$out/*.sum"),glob("$out/*.log")) {
478 subst sub { s{\Q$HOME\E/.*?/build/[^/]*/}{}g; },$file;
481 die "internal error" if @target;
484 # Call gdbunpack only if no direct $out directory will be created.
485 # It is needed only for .src.rpm-built testsuites, no matter how .src.rpm
488 if ($component=~/^(?:fedora|rhel)glibc$/) {
489 @testinlog=(qr/={20}TESTING DETAILS={17}/,qr/={20}PLT RELOCS END={18}/);
492 subst sub { s{^.*?\n($testinlog[0]\n.*\n$testinlog[1]\n).*$}{$1}s; },$log,$out;
493 } elsif ($cvsbasedir || $srcrpm) {
494 # Applies both to gdb and binutils.
495 spawn "mv $out $out.x; gdbunpack $log; mv $out.x/* $out/; rmdir $out.x";
499 for my $from (glob "$out/*.log") {
500 (my $to=$from).="filt";
501 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;
505 my $resultout="$resultdir/$id/$distrodirbase";
509 for my $fname (glob "$out/*") {
510 (my $base=$fname)=~s{^.*/}{};
511 my $d="$resultout/$base";
512 warn "+ link $fname $d\n";
513 link $fname,$d or warn $!;
516 exit 0 if $parallel>1;
519 print STDERR "waiting for ".scalar(keys(%child))." children, ".scalar(@distrouse)." distros to go...\n";
521 next if $pid==-1 && $!==10; # 10==No child processes
522 die "wait()==-1: $!" if $pid==-1;
523 die "not found pid $pid" if !$child{$pid};
524 error "weird status $? for pid $pid: ".$child{$pid} if $?;
525 print STDERR "finished: $pid ".$child{$pid}."\n";
531 spawn "(set -e -o pipefail;cd $resultdir;tar cf - $id|xz -9e >$resultidxz;rm -rf $id)&","bare";
539 $r.=int($sec/(60*60))."h";
542 if ($r || $sec>=60) {
543 $r.=int($sec/60)."m";
551 print STDERR "ID = $id | dir = $dir\n";
552 my $time=timestr(time()-$start);
553 print STDERR "total time=$time\n";
554 writefile "$dir/time","$time\n";
555 die "$error errors seen, aborted" if $error;
556 print STDERR "done\n";