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>
54 "i|userid=s"=>\$userid,
56 "1|serial"=>sub { $parallel=1; },
57 "2|standard"=>sub { $parallel=2; },
58 "3|parallel"=>sub { $parallel=3; },
59 "d|distro=s{,}"=>\@distro,
60 "cd|componentdistro=s{,}"=>\@componentdistro,
61 "p|path=s{,}"=>\@path,
62 "a|arch=s{,}"=>\@arch,
63 "c|component=s"=>\$component,
64 "s|srcrpm=s"=>\$srcrpm,
66 "target=s{,}"=>\@target,
67 "D|distrojobs=s"=>\$distrojobs,
68 "configure=s"=>\$configure,
70 "gdbcvspie"=>\$gdbcvspie,
72 "gdbserver"=>\$gdbserver,
74 $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/*");
75 $component and $component=~m{^/home/} and (-f "$component/gdb/gdbtypes.c" or die "$component/gdb/gdbtypes.c not found");
76 $component and $srcrpm and die "-c|--component excludes -s|--srcrpm";
77 $component or $srcrpm or die "-c|--component or -s|--srcrpm required";
78 $component||=""; # Make `eq' not complaining.
80 if ($component=~/^(gdb|binutils)cvs$/) {
81 $cvsbranch=(!$branch?"-A":"-r $branch");
83 die "--branch currently unsupported for non-CVS sources" if $branch;
85 !$gdbcvspie or $component eq "gdbcvs" or die "--gdbcvspie requires -c gdbcvs";
86 @target and ($srcrpm or $component=~/^(?:fedora|rhel)/) and die "--target is available only for baretestsuite modes";
87 $strip and ($srcrpm or $component=~/^(?:fedora|rhel)/) and die "--strip is available only for baretestsuite modes";
88 $gdbserver and $component ne "gdbcvs" and die "--gdbserver is available only gdbcvs";
90 do { error "Duplicate target: $_\n" if $target{$_}++; } for @target;
91 @arch="x86_64" if @target&&!@arch;
92 for my $file (@file) {
93 -f $file and -r $file or error "-f|--file $file not readable: $!";
95 $distrojobs=(@target?1:2) if !defined $distrojobs;
96 $distrojobs=~/^\d+$/ or die "-D|distrojobs must be a number: $distrojobs";
97 $distrojobs>=1 or die "-D|distrojobs must be positive: $distrojobs";
98 # User may want to modify ASAP her files submitted for the test.
99 my $will_copy=@file || $component=~m{^/home/};
100 $parallel||=$will_copy ? 2 : 1;
101 error "Excessive arguments: @ARGV" if @ARGV;
102 @arch=@arches if !@arch;
103 my $path=join(":",@path) if @path;
104 @componentdistro and @componentdistro!=@distro and die "--cd|--componentdistro must have the same elements count as -d|--distro";
106 sub distro_normalize($;$)
111 s{^/var/lib/mock/+}{};
114 s/^(?:devel|rawhide)\b/fedora-rawhide/;
115 s/^(?:epel|centos)-?(\d)/epel-$1/;
116 s/^(?:rhel)-?(\d)/rhel-$1/;
117 s/^(?:f|fedora)-?(\d)/fedora-$1/;
119 @archuse="" if -d "/var/lib/mock/$_";
120 @archuse="i386" if s/-$arch_i386$//o;
121 @archuse="x86_64" if s/-$arch_x86_64$//o;
123 for my $arch (@archuse?@archuse:@arch) {
124 my $dir="/var/lib/mock/$_".(!$arch?"":"-$arch");
125 $force or -d $dir or error "No distro: $dir";
128 return ($_,@archuse);
131 # epel-\d-i386|fedora-\d-i386|fedora-rawhide-i386
133 for my $distroi (0..$#distro) {
134 my $distro=$distro[$distroi];
135 my $componentdistro=$componentdistro[$distroi];
137 if ($componentdistro) {
138 my $force=($componentdistro=~s/!$//);
139 ($componentdistro,@archuse)=distro_normalize $componentdistro,$force;
140 @archuse and die "--cd|--componentdistro must have no arch: ".join(" ",@archuse);
142 ($distro,@archuse)=distro_normalize $distro;
143 $componentdistro||=$distro;
144 @archuse=@arch if !@archuse;
145 for my $archuse (@archuse) {
146 for my $target (@target?@target:undef()) {
147 push @distrouse,{"distro"=>$distro.(!$archuse?"":"-$archuse"),"componentdistro"=>$componentdistro,"target"=>$target};
157 my %opt=map(($_=>1),@opt);
158 warn "+ mkdir".($opt{"-p"} ? " -p" : "")." $dir\n";
159 mkdir $dir or ($opt{"mayexist"} && $!{EEXIST}) or die "mkdir $dir: $!";
168 my %opt=map(($_=>1),@opt);
171 $cmd="set -ex; $cmd";
172 $ok="$log.ok" if $log;
173 $cmd="($cmd; touch $ok) 2>&1|tee -a $log; test -f $ok" if $log;
179 system $cmd and die "$cmd: $!";
183 my $basedir=$ENV{"HOME"}."/hammock";
184 newdir $basedir,"mayexist";
185 my $idbase=strftime("%Y%m%d",localtime());
188 for my $seq (defined $userid ? $userid : (0..99)) {
189 $id=$idbase.(defined $userid ? $seq : sprintf("%02d",$seq));
193 spawn "chmod -R u+w $dir; rm -rf $dir" if -d $dir && $force && defined $userid;
194 error "Directory not free: $dir" if !$id || !$dir || -e $dir;
195 print STDERR "ID = $id | dir = $dir\n";
196 error "No distros specified" if !@distrouse;
197 die "$error errors seen, aborted" if $error;
201 my($fname,$content)=@_;
204 open F,">$fname" or die $fname;
205 print F $content or die $fname;
206 close F or die $fname;
209 spawn "renice +19 -p $$";
210 spawn "ionice -c3 -p $$";
213 my $resultid="$resultdir/$id";
214 my $resultidxz="$resultid.tar.xz";
215 newdir $resultdir,"mayexist";
216 spawn "rm -rf $resultid" if -d $resultid && $force;
218 unlink $resultidxz or $!{ENOENT} or die "unlink $resultidxz: $!";
219 spawn "uname -r >$dir/kernel";
222 "component"=>$component,
225 "file"=>join("\n",@file),
226 "configure"=>$configure,
227 "gdbcvspie"=>$gdbcvspie,
229 while (my($name,$val)=each(%dump)) {
231 writefile "$dir/$name","$val\n";
232 link "$dir/$name","$resultid/$name" or warn "link $dir/$name $resultid/$name: $!";
234 for my $file (@file) {
235 newdir "$dir/file.d","mayexist";
236 (my $base=$file)=~s{^.*/}{};
237 my $d="$dir/file.d/$base";
238 link $file,$d or die "link $file $d: $!";
239 newdir "$resultid/file.d","mayexist";
240 link $d,"$resultid/file.d/$base" or warn "link $file $resultid/file.d/$base: $!";
245 my($sub,$in,$out)=@_;
250 open F,$in or die $in;
251 local $_=do { local $/; <F>; } or die $in;
254 &{$sub}() or die $_."\nError substituting $in";
263 for my $file (@file) {
265 $filebase=~s{^.*/}{};
266 my $target="$targetdir/$filebase";
267 # Some *.patch files may be new.
268 # -f $target or die "File $file does not exist at $target";
269 spawn "rm -f $target; cp -p $file $target";
275 while (@distrouse || keys(%child)) {
276 while (keys(%child)<$distrojobs && @distrouse) {
277 my $distrouse=shift @distrouse;
278 my $distro=$distrouse->{"distro"};
279 my $componentdistro=$distrouse->{"componentdistro"};
280 my $target=$distrouse->{"target"};
281 my $rpmbuild="rpmbuild";
289 if ($component=~/^fedora(.*)$/) {
291 $gitbranch="f$1/master" if $componentdistro=~/^fedora-(\d+)$/;
292 $gitbranch="master" if $componentdistro=~/^fedora-rawhide$/;
293 die "$component vs. $componentdistro" if !$gitbranch;
294 $gitroot=$fedoragitroot;
296 if ($component=~/^rhel(.*)$/) {
298 $cvsbasedir="RHEL-$1" if $componentdistro=~/^(?:epel|rhel)-(\d+)$/;
299 die "$component vs. $componentdistro" if !$cvsbasedir;
300 $cvsroot=$rhelcvsroot;
301 # EPEL still uses Berkeley DB version 8 while F-11+ (F-10?) uses version 9.
302 # Using db_dump and db_load would no longer make it mock compatible.
303 $rpmbuild.=q{ --dbpath $PWD --nodeps};
306 my $distrodirbase=$distro;
307 $distrodirbase.="-$target" if $target;
308 my $distrodir="$dir/$distrodirbase";
310 $log="$distrodir/log";
311 my $out="$distrodir/out";
316 die if !defined $pid;
318 $child{$pid}=$distrodirbase;
323 my $builddir="$distrodir/build";
326 # Do not use mockrun as the rpm database may be in a different version.
327 spawn "rpm -r /var/lib/mock/$distro/root -qa|sort >$out/rpm-qa";
334 $c="export PATH=\"$path:\$PATH\"; $c" if $path;
335 $c="export MAKEFLAGS=\"-j\$[`getconf _NPROCESSORS_ONLN`*3/2]\"; $c";
336 $c="export http_proxy=http://127.0.0.1:3128/; $c";
337 $c="set -ex; cd $builddir; $c";
338 die "found ': $c" if $c=~/'/;
339 spawn "mockrun $::distro '$c'";
346 spawn "cd $distrodir; git clone -b $gitbranch $gitroot/$gitrepo $component";
347 my $componentdir="$distrodir/$component";
348 -d $componentdir or die "Failed checkout to: $componentdir";
349 copyfiles $componentdir;
350 spawn "cd $componentdir; fedpkg verrel >$out/verrel";
351 my $glob="$componentdir/*.src.rpm";
352 @{[glob $glob]}==0 or die "Found some before test-srpm: $glob";
353 # No `spawn' as we could get:
354 # error: unpacking of archive failed on file X;4a56efef: cpio: MD5 sum mismatch
355 mockrun "cd $componentdir; fedpkg srpm";
356 my @srcrpm=(glob $glob);
357 @srcrpm==1 or die "Did not find 1 srcrpm: @srcrpm";
365 spawn "cd $distrodir; cvs -q -z3 -d $cvsroot co rpms/$cvsrepo/$cvsbasedir";
366 my $componentdir="$distrodir/rpms/$cvsrepo/$cvsbasedir";
367 -d $componentdir or die "Failed checkout to: $componentdir";
368 # Required for RHEL; Fedora does so automatically.
369 spawn "cd $componentdir/..; cvs -q -z3 -d $cvsroot co common";
370 # Workaround (RHEL-5?) curl which uses `Pragma: nocache' on $http_proxy.
371 subst sub { s{echo "curl }{$&-H 'Pragma: cache' }; },"$componentdir/../common/Makefile.common";
372 copyfiles $componentdir;
373 spawn "cd $componentdir; make 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; make test-srpm";
379 my @srcrpm=(glob $glob);
380 @srcrpm==1 or die "Did not find 1 srcrpm: @srcrpm";
385 my $srcrpmbasename=$srcrpm;
386 $srcrpmbasename=~s{^.*/}{};
387 spawn "cp -p $srcrpm $builddir/$srcrpmbasename";
389 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"};
390 $rpmbuildlocal="orphanripper $rpmbuildlocal" if $cvsrepo && $cvsrepo eq "glibc";
391 mockrun $rpmbuildlocal." --rebuild --with testsuite".($parallel<2 ? "" : " --with parallel")." $srcrpmbasename";
396 if ($component=~/^(gdb|binutils)cvs$/) {
398 my $cvsmaster=$which eq "gdb" ? $gdbcvsmaster : $binutilscvsmaster;
400 spawn "cp -a $cvsmaster $builddir/src; cd $builddir/src; cvs update $cvsbranch";
402 spawn "cd $builddir; cvs -q -z3 -d :pserver:anoncvs:\@sourceware.org:/cvs/src co $cvsbranch $which";
404 spawn "cd $builddir/src; test -z \"\$(cvs update $cvsbranch)\"";
405 $baretestsuite="$builddir/src";
408 if ($component=~/^archer-/) {
409 spawn "git clone ".(!-d $archermaster ? "" : "--reference $archermaster")." git://sourceware.org/git/archer.git $builddir/$component";
410 spawn "cd $builddir/$component; git fetch";
411 spawn "cd $builddir/$component; git checkout -b $component origin/$component; [ \"`git status`\" = \"# On branch $component\nnothing to commit (working directory clean)\" ]";
412 $baretestsuite="$builddir/$component";
415 if ($component=~m{^/home/}) {
416 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 || :";
417 $baretestsuite="$builddir/src";
420 if ($baretestsuite) {
421 for my $file (@file) {
422 my $target="$baretestsuite/$file";
423 if ($file=~m{[.](R?)patch$}) {
426 $fileabs=$ENV{"PWD"}."/$fileabs" if $fileabs!~m{^/};
427 spawn "cd $baretestsuite; patch -${R}p1 <$fileabs";
429 -f $target or $file=~m{/testsuite/} or die "File $file does not exist at $target";
430 spawn "rm -f $target; cp -p $file $target";
435 $errs12.=" -s" if $strip;
436 $errs12.=" --target=$target" if $target;
437 $errs12.=" $configure" if $configure;
439 if ($component eq "binutilscvs") {
440 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;};
442 my @check=($distro=~/-x86_64/ ? qw(-m64 -m32) : -m32);
443 @check=map("check//unix/$_",@check);
444 @check=map({($_,"$_/-fPIE/-pie");} @check) if $gdbcvspie;
445 # for i in ".join(" ",@check).";do orphanripper make -k \$i || :;done
446 mockrun "cd $baretestsuite; $errs12; cd gdb; ulimit -c unlimited; ".(!$gdbserver?"":'DEJAGNU=$HOME/src/runtest-gdbserver/site.exp ')."orphanripper make -k ".join(" ",@check).(!$gdbserver?"":' RUNTESTFLAGS=--target_board=native-gdbserver')." 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;};
449 # perl -i -pe 's{\Q'"$HOME"'\E/.*?/build/[^/]*/}{}g' "$base"/*
450 my $HOME=$ENV{"HOME"};
451 for my $file (glob("$out/*.sum"),glob("$out/*.log")) {
452 subst sub { s{\Q$HOME\E/.*?/build/[^/]*/}{}g; },$file;
455 die "internal error" if @target;
458 # Call gdbunpack only if no direct $out directory will be created.
459 # It is needed only for .src.rpm-built testsuites, no matter how .src.rpm
462 if ($component=~/^(?:fedora|rhel)glibc$/) {
463 @testinlog=(qr/={20}TESTING DETAILS={17}/,qr/={20}PLT RELOCS END={18}/);
466 subst sub { s{^.*?\n($testinlog[0]\n.*\n$testinlog[1]\n).*$}{$1}s; },$log,$out;
467 } elsif ($cvsbasedir || $srcrpm) {
468 # Applies both to gdb and binutils.
469 spawn "mv $out $out.x; gdbunpack $log; mv $out.x/* $out/; rmdir $out.x";
472 my $resultout="$resultdir/$id/$distrodirbase";
476 for my $fname (glob "$out/*") {
477 (my $base=$fname)=~s{^.*/}{};
478 my $d="$resultout/$base";
479 warn "+ link $fname $d\n";
480 link $fname,$d or warn $!;
483 exit 0 if $parallel>1;
486 print STDERR "waiting for ".scalar(keys(%child))." children, ".scalar(@distrouse)." distros to go...\n";
488 next if $pid==-1 && $!==10; # 10==No child processes
489 die "wait()==-1: $!" if $pid==-1;
490 die "not found pid $pid" if !$child{$pid};
491 error "weird status $? for pid $pid: ".$child{$pid} if $?;
492 print STDERR "finished: $pid ".$child{$pid}."\n";
498 spawn "(set -e -o pipefail;cd $resultdir;tar cf - $id|xz -9e >$resultidxz;rm -rf $id)&","bare";
506 $r.=int($sec/(60*60))."h";
509 if ($r || $sec>=60) {
510 $r.=int($sec/60)."m";
518 print STDERR "ID = $id | dir = $dir\n";
519 my $time=timestr(time()-$start);
520 print STDERR "total time=$time\n";
521 writefile "$dir/time","$time\n";
522 die "$error errors seen, aborted" if $error;
523 print STDERR "done\n";