6 use POSIX qw(&strftime);
7 use Getopt::Long qw(:config no_ignore_case);
11 my $gdbcvsmaster=$ENV{"HOME"}."/redhat/gdb-cvs-master";
12 my $binutilscvsmaster=$ENV{"HOME"}."/redhat/binutils-cvs-master";
13 my $archermaster=$ENV{"HOME"}."/redhat/archer-master";
14 my $fedoragitroot=q{git://pkgs.fedoraproject.org};
15 #Unknown host cvs.devel.redhat.com.
16 #my $rhelcvsroot=q{:pserver:anonymous:@cvs.devel.redhat.com:/cvs/dist};
17 my $rhelcvsroot=q{:ext:cvs.devel.redhat.com:/cvs/dist};
18 my $arch_i386=qr{(?:x86|i\d86|ia32)}io;
19 my $arch_x86_64=qr{(?:x8664|x86_64|em64t)}io;
20 my $resultdir=$ENV{"HOME"}."/.hammock-result";
21 my @arches=qw(i386 x86_64);
32 my $parallel=9; # 1 or 2 or 3
43 # FIXME: Connect make paralellization to the children.
47 # FIXME: 20100911servpatched-f14:
48 # readchar: Connection reset by peer
49 # Remote side has terminated connection. GDBserver will reopen the connection.
50 # Can't bind address: Address already in use.
51 # <last 2 lines repearing>
55 "i|userid=s"=>\$userid,
57 "1|serial"=>sub { $parallel=1; },
58 "2|standard"=>sub { $parallel=2; },
59 "3|parallel"=>sub { $parallel=3; },
60 "d|distro=s{,}"=>\@distro,
61 "cd|componentdistro=s{,}"=>\@componentdistro,
62 "p|path=s{,}"=>\@path,
63 "a|arch=s{,}"=>\@arch,
64 "c|component=s"=>\$component,
65 "s|srcrpm=s"=>\$srcrpm,
67 "target=s{,}"=>\@target,
68 "D|distrojobs=s"=>\$distrojobs,
69 "configure=s"=>\$configure,
71 "gdbcvspie"=>\$gdbcvspie,
73 "gdbserver"=>\$gdbserver,
74 "valgrind"=>\$valgrind,
76 $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/*");
77 $component and $component=~m{^/home/} and (-f "$component/gdb/gdbtypes.c" or die "$component/gdb/gdbtypes.c not found");
78 $component and $srcrpm and die "-c|--component excludes -s|--srcrpm";
79 $component or $srcrpm or die "-c|--component or -s|--srcrpm required";
80 $component||=""; # Make `eq' not complaining.
82 if ($component=~/^(gdb|binutils)cvs$/) {
83 $cvsbranch=(!$branch?"-A":"-r $branch");
85 die "--branch currently unsupported for non-CVS sources" if $branch;
87 !$gdbcvspie or $component eq "gdbcvs" or die "--gdbcvspie requires -c gdbcvs";
88 @target and ($srcrpm or $component=~/^(?:fedora|rhel)/) and die "--target is available only for baretestsuite modes";
89 $strip and ($srcrpm or $component=~/^(?:fedora|rhel)/) and die "--strip is available only for baretestsuite modes";
90 $gdbserver and $component ne "gdbcvs" and die "--gdbserver is available only for gdbcvs";
91 $valgrind and $component ne "gdbcvs" and die "--valgrind is available only for gdbcvs";
92 $gdbserver and $valgrind and die "--gdbserver and --valgrind are mutually exclusive";
94 do { error "Duplicate target: $_\n" if $target{$_}++; } for @target;
95 @arch="x86_64" if @target&&!@arch;
96 for my $file (@file) {
97 -f $file and -r $file or error "-f|--file $file not readable: $!";
99 $distrojobs=(@target?1:2) if !defined $distrojobs;
100 $distrojobs=~/^\d+$/ or die "-D|distrojobs must be a number: $distrojobs";
101 $distrojobs>=1 or die "-D|distrojobs must be positive: $distrojobs";
102 # User may want to modify ASAP her files submitted for the test.
103 my $will_copy=@file || $component=~m{^/home/};
104 $parallel||=$will_copy ? 2 : 1;
105 error "Excessive arguments: @ARGV" if @ARGV;
106 @arch=@arches if !@arch;
107 my $path=join(":",@path) if @path;
108 @componentdistro and @componentdistro!=@distro and die "--cd|--componentdistro must have the same elements count as -d|--distro";
110 sub distro_normalize($;$)
115 s{^/var/lib/mock/+}{};
118 s/^(?:devel|rawhide)\b/fedora-rawhide/;
119 s/^(?:epel|centos)-?(\d)/epel-$1/;
120 s/^(?:rhel)-?(\d)/rhel-$1/;
121 s/^(?:f|fedora)-?(\d)/fedora-$1/;
123 @archuse="" if -d "/var/lib/mock/$_";
124 @archuse="i386" if s/-$arch_i386$//o;
125 @archuse="x86_64" if s/-$arch_x86_64$//o;
127 for my $arch (@archuse?@archuse:@arch) {
128 my $dir="/var/lib/mock/$_".(!$arch?"":"-$arch");
129 $force or -d $dir or error "No distro: $dir";
132 return ($_,@archuse);
135 # epel-\d-i386|fedora-\d-i386|fedora-rawhide-i386
137 for my $distroi (0..$#distro) {
138 my $distro=$distro[$distroi];
139 my $componentdistro=$componentdistro[$distroi];
141 if ($componentdistro) {
142 my $force=($componentdistro=~s/!$//);
143 ($componentdistro,@archuse)=distro_normalize $componentdistro,$force;
144 @archuse and die "--cd|--componentdistro must have no arch: ".join(" ",@archuse);
146 ($distro,@archuse)=distro_normalize $distro;
147 $componentdistro||=$distro;
148 @archuse=@arch if !@archuse;
149 for my $archuse (@archuse) {
150 for my $target (@target?@target:undef()) {
151 push @distrouse,{"distro"=>$distro.(!$archuse?"":"-$archuse"),"componentdistro"=>$componentdistro,"target"=>$target};
161 my %opt=map(($_=>1),@opt);
162 warn "+ mkdir".($opt{"-p"} ? " -p" : "")." $dir\n";
163 mkdir $dir or ($opt{"mayexist"} && $!{EEXIST}) or die "mkdir $dir: $!";
172 my %opt=map(($_=>1),@opt);
175 $cmd="set -ex; $cmd";
176 $ok="$log.ok" if $log;
177 $cmd="($cmd; touch $ok) 2>&1|tee -a $log; test -f $ok" if $log;
183 system $cmd and die "$cmd: $!";
187 my $basedir=$ENV{"HOME"}."/hammock";
188 newdir $basedir,"mayexist";
189 my $idbase=strftime("%Y%m%d",localtime());
192 for my $seq (defined $userid ? $userid : (0..99)) {
193 $id=$idbase.(defined $userid ? $seq : sprintf("%02d",$seq));
197 spawn "chmod -R u+w $dir; rm -rf $dir" if -d $dir && $force && defined $userid;
198 error "Directory not free: $dir" if !$id || !$dir || -e $dir;
199 print STDERR "ID = $id | dir = $dir\n";
200 error "No distros specified" if !@distrouse;
201 die "$error errors seen, aborted" if $error;
205 my($fname,$content)=@_;
208 open F,">$fname" or die $fname;
209 print F $content or die $fname;
210 close F or die $fname;
213 spawn "renice +19 -p $$";
214 spawn "ionice -c3 -p $$";
217 my $resultid="$resultdir/$id";
218 my $resultidxz="$resultid.tar.xz";
219 newdir $resultdir,"mayexist";
220 spawn "rm -rf $resultid" if -d $resultid && $force;
222 unlink $resultidxz or $!{ENOENT} or die "unlink $resultidxz: $!";
223 spawn "uname -r >$dir/kernel";
226 "component"=>$component,
229 "file"=>join("\n",@file),
230 "configure"=>$configure,
231 "gdbcvspie"=>$gdbcvspie,
233 while (my($name,$val)=each(%dump)) {
235 writefile "$dir/$name","$val\n";
236 link "$dir/$name","$resultid/$name" or warn "link $dir/$name $resultid/$name: $!";
238 for my $file (@file) {
239 newdir "$dir/file.d","mayexist";
240 (my $base=$file)=~s{^.*/}{};
241 my $d="$dir/file.d/$base";
242 link $file,$d or die "link $file $d: $!";
243 newdir "$resultid/file.d","mayexist";
244 link $d,"$resultid/file.d/$base" or warn "link $file $resultid/file.d/$base: $!";
249 my($sub,$in,$out)=@_;
254 open F,$in or die $in;
255 local $_=do { local $/; <F>; } or die $in;
258 &{$sub}() or die $_."\nError substituting $in";
267 for my $file (@file) {
269 $filebase=~s{^.*/}{};
270 my $target="$targetdir/$filebase";
271 # Some *.patch files may be new.
272 # -f $target or die "File $file does not exist at $target";
273 spawn "rm -f $target; cp -p $file $target";
279 while (@distrouse || keys(%child)) {
280 while (keys(%child)<$distrojobs && @distrouse) {
281 my $distrouse=shift @distrouse;
282 my $distro=$distrouse->{"distro"};
283 my $componentdistro=$distrouse->{"componentdistro"};
284 my $target=$distrouse->{"target"};
285 my $rpmbuild="rpmbuild";
293 if ($component=~/^fedora(.*)$/) {
295 $gitbranch="f$1/master" if $componentdistro=~/^fedora-(\d+)$/;
296 $gitbranch="master" if $componentdistro=~/^fedora-rawhide$/;
297 die "$component vs. $componentdistro" if !$gitbranch;
298 $gitroot=$fedoragitroot;
300 if ($component=~/^rhel(.*)$/) {
302 $cvsbasedir="RHEL-$1" if $componentdistro=~/^(?:epel|rhel)-(\d+)$/;
303 die "$component vs. $componentdistro" if !$cvsbasedir;
304 $cvsroot=$rhelcvsroot;
305 # EPEL still uses Berkeley DB version 8 while F-11+ (F-10?) uses version 9.
306 # Using db_dump and db_load would no longer make it mock compatible.
307 $rpmbuild.=q{ --dbpath $PWD --nodeps};
310 my $distrodirbase=$distro;
311 $distrodirbase.="-$target" if $target;
312 my $distrodir="$dir/$distrodirbase";
314 $log="$distrodir/log";
315 my $out="$distrodir/out";
320 die if !defined $pid;
322 $child{$pid}=$distrodirbase;
327 my $builddir="$distrodir/build";
330 # Do not use mockrun as the rpm database may be in a different version.
331 spawn "rpm -r /var/lib/mock/$distro/root -qa|sort >$out/rpm-qa";
338 $c="export PATH=\"$path:\$PATH\"; $c" if $path;
339 $c="export MAKEFLAGS=\"-j\$[`getconf _NPROCESSORS_ONLN`*3/2]\"; $c";
340 $c="export http_proxy=http://127.0.0.1:3128/; $c";
341 $c="set -ex; cd $builddir; $c";
342 die "found ': $c" if $c=~/'/;
343 spawn "mockrun $::distro '$c'";
350 spawn "cd $distrodir; git clone -b $gitbranch $gitroot/$gitrepo $component";
351 my $componentdir="$distrodir/$component";
352 -d $componentdir or die "Failed checkout to: $componentdir";
353 copyfiles $componentdir;
354 spawn "cd $componentdir; fedpkg verrel >$out/verrel";
355 my $glob="$componentdir/*.src.rpm";
356 @{[glob $glob]}==0 or die "Found some before test-srpm: $glob";
357 # No `spawn' as we could get:
358 # error: unpacking of archive failed on file X;4a56efef: cpio: MD5 sum mismatch
359 mockrun "cd $componentdir; fedpkg srpm";
360 my @srcrpm=(glob $glob);
361 @srcrpm==1 or die "Did not find 1 srcrpm: @srcrpm";
369 spawn "cd $distrodir; cvs -q -z3 -d $cvsroot co rpms/$cvsrepo/$cvsbasedir";
370 my $componentdir="$distrodir/rpms/$cvsrepo/$cvsbasedir";
371 -d $componentdir or die "Failed checkout to: $componentdir";
372 # Required for RHEL; Fedora does so automatically.
373 spawn "cd $componentdir/..; cvs -q -z3 -d $cvsroot co common";
374 # Workaround (RHEL-5?) curl which uses `Pragma: nocache' on $http_proxy.
375 subst sub { s{echo "curl }{$&-H 'Pragma: cache' }; },"$componentdir/../common/Makefile.common";
376 copyfiles $componentdir;
377 spawn "cd $componentdir; make verrel >$out/verrel";
378 my $glob="$componentdir/*.src.rpm";
379 @{[glob $glob]}==0 or die "Found some before test-srpm: $glob";
380 # No `spawn' as we could get:
381 # error: unpacking of archive failed on file X;4a56efef: cpio: MD5 sum mismatch
382 mockrun "cd $componentdir; make test-srpm";
383 my @srcrpm=(glob $glob);
384 @srcrpm==1 or die "Did not find 1 srcrpm: @srcrpm";
389 my $srcrpmbasename=$srcrpm;
390 $srcrpmbasename=~s{^.*/}{};
391 spawn "cp -p $srcrpm $builddir/$srcrpmbasename";
393 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"};
394 $rpmbuildlocal="orphanripper $rpmbuildlocal" if $cvsrepo && $cvsrepo eq "glibc";
395 mockrun $rpmbuildlocal." --rebuild --with testsuite".($parallel<2 ? "" : " --with parallel")." $srcrpmbasename";
400 if ($component=~/^(gdb|binutils)cvs$/) {
402 my $cvsmaster=$which eq "gdb" ? $gdbcvsmaster : $binutilscvsmaster;
404 spawn "cp -a $cvsmaster $builddir/src; cd $builddir/src; cvs update $cvsbranch";
406 spawn "cd $builddir; cvs -q -z3 -d :pserver:anoncvs:\@sourceware.org:/cvs/src co $cvsbranch $which";
408 spawn "cd $builddir/src; test -z \"\$(cvs update $cvsbranch)\"";
409 $baretestsuite="$builddir/src";
412 if ($component=~/^archer-/) {
413 spawn "git clone ".(!-d $archermaster ? "" : "--reference $archermaster")." git://sourceware.org/git/archer.git $builddir/$component";
414 spawn "cd $builddir/$component; git fetch";
415 spawn "cd $builddir/$component; git checkout -b $component origin/$component; [ \"`git status`\" = \"# On branch $component\nnothing to commit (working directory clean)\" ]";
416 $baretestsuite="$builddir/$component";
419 if ($component=~m{^/home/}) {
420 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 || :";
421 $baretestsuite="$builddir/src";
424 if ($baretestsuite) {
425 for my $file (@file) {
426 my $target="$baretestsuite/$file";
427 if ($file=~m{[.](R?)patch$}) {
430 $fileabs=$ENV{"PWD"}."/$fileabs" if $fileabs!~m{^/};
431 spawn "cd $baretestsuite; patch -${R}p1 <$fileabs";
433 -f $target or $file=~m{/testsuite/} or die "File $file does not exist at $target";
434 spawn "rm -f $target; cp -p $file $target";
439 $errs12.=" -s" if $strip;
440 $errs12.=" --target=$target" if $target;
441 $errs12.=" $configure" if $configure;
443 if ($component eq "binutilscvs") {
444 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;};
446 my @check=($distro=~/-x86_64/ ? qw(-m64 -m32) : -m32);
447 @check=map("check//unix/$_",@check);
448 @check=map({($_,"$_/-fPIE/-pie");} @check) if $gdbcvspie;
449 # for i in ".join(" ",@check).";do orphanripper make -k \$i || :;done
450 mockrun "cd $baretestsuite; $errs12"
451 .(!$valgrind?"":' --without-python') # FIXME: Fix valgrind --suppressions
452 ."; cd gdb; ulimit -c unlimited; "
453 .(!$gdbserver?"":'DEJAGNU=$HOME/src/runtest-gdbserver/site.exp ')
454 .(!$valgrind?"":'DEJAGNU=$HOME/src/runtest-valgrind/site.exp ')
455 ."orphanripper make -k ".join(" ",@check)
456 .(!$gdbserver?"":' RUNTESTFLAGS=--target_board=native-gdbserver')
457 .(!$valgrind?"":' RUNTESTFLAGS=--target_board=valgrind')
458 ." 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;};
461 # perl -i -pe 's{\Q'"$HOME"'\E/.*?/build/[^/]*/}{}g' "$base"/*
462 my $HOME=$ENV{"HOME"};
463 for my $file (glob("$out/*.sum"),glob("$out/*.log")) {
464 subst sub { s{\Q$HOME\E/.*?/build/[^/]*/}{}g; },$file;
467 die "internal error" if @target;
470 # Call gdbunpack only if no direct $out directory will be created.
471 # It is needed only for .src.rpm-built testsuites, no matter how .src.rpm
474 if ($component=~/^(?:fedora|rhel)glibc$/) {
475 @testinlog=(qr/={20}TESTING DETAILS={17}/,qr/={20}PLT RELOCS END={18}/);
478 subst sub { s{^.*?\n($testinlog[0]\n.*\n$testinlog[1]\n).*$}{$1}s; },$log,$out;
479 } elsif ($cvsbasedir || $srcrpm) {
480 # Applies both to gdb and binutils.
481 spawn "mv $out $out.x; gdbunpack $log; mv $out.x/* $out/; rmdir $out.x";
484 my $resultout="$resultdir/$id/$distrodirbase";
488 for my $fname (glob "$out/*") {
489 (my $base=$fname)=~s{^.*/}{};
490 my $d="$resultout/$base";
491 warn "+ link $fname $d\n";
492 link $fname,$d or warn $!;
495 exit 0 if $parallel>1;
498 print STDERR "waiting for ".scalar(keys(%child))." children, ".scalar(@distrouse)." distros to go...\n";
500 next if $pid==-1 && $!==10; # 10==No child processes
501 die "wait()==-1: $!" if $pid==-1;
502 die "not found pid $pid" if !$child{$pid};
503 error "weird status $? for pid $pid: ".$child{$pid} if $?;
504 print STDERR "finished: $pid ".$child{$pid}."\n";
510 spawn "(set -e -o pipefail;cd $resultdir;tar cf - $id|xz -9e >$resultidxz;rm -rf $id)&","bare";
518 $r.=int($sec/(60*60))."h";
521 if ($r || $sec>=60) {
522 $r.=int($sec/60)."m";
530 print STDERR "ID = $id | dir = $dir\n";
531 my $time=timestr(time()-$start);
532 print STDERR "total time=$time\n";
533 writefile "$dir/time","$time\n";
534 die "$error errors seen, aborted" if $error;
535 print STDERR "done\n";