6 use POSIX qw(&strftime);
7 use Getopt::Long qw(:config no_ignore_case);
11 my $gdbcvsbare=$ENV{"HOME"}."/redhat/gdb-cvs-bare";
12 my $binutilscvsbare=$ENV{"HOME"}."/redhat/binutils-cvs-bare";
13 my $archermaster=$ENV{"HOME"}."/redhat/archer-master";
14 my $fedoracvsroot=q{:pserver:anonymous:@cvs.fedoraproject.org:/cvs/pkgs};
15 my $rhelcvsroot=q{:pserver:anonymous:@192.168.67.2:3401/cvs/dist};
16 my $arch_i386=qr{(?:x86|i\d86|ia32)}io;
17 my $arch_x86_64=qr{(?:x8664|x86_64|em64t)}io;
18 my @arches=qw(i386 x86_64);
29 my $parallel=9; # 1 or 2 or 3
40 # FIXME: Connect make paralellization to the children.
43 "i|userid=s"=>\$userid,
45 "1|serial"=>sub { $parallel=1; },
46 "2|standard"=>sub { $parallel=2; },
47 "3|parallel"=>sub { $parallel=3; },
48 "d|distro=s{,}"=>\@distro,
49 "cd|componentdistro=s{,}"=>\@componentdistro,
50 "p|path=s{,}"=>\@path,
51 "a|arch=s{,}"=>\@arch,
52 "c|component=s"=>\$component,
53 "s|srcrpm=s"=>\$srcrpm,
55 "target=s{,}"=>\@target,
56 "D|distrojobs=s"=>\$distrojobs,
57 "configure=s"=>\$configure,
60 $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/*");
61 $component and $component=~m{^/home/} and (-f "$component/gdb/gdbtypes.c" or die "$component/gdb/gdbtypes.c not found");
62 $component and $srcrpm and die "-c|--component excludes -s|--srcrpm";
63 $component or $srcrpm or die "-c|--component or -s|--srcrpm required";
64 $component||=""; # Make `eq' not complaining.
66 if ($component=~/^(gdb|binutils)cvs$/) {
67 $cvsbranch=(!$branch?"-A":"-r $branch");
69 die "--branch currently unsupported for non-CVS sources" if $branch;
71 @target and ($srcrpm or $component=~/^(?:fedora|rhel)/) and die "--target is available only for baretestsuite modes";
73 do { error "Duplicate target: $_\n" if $target{$_}++; } for @target;
74 @arch="x86_64" if @target&&!@arch;
75 for my $file (@file) {
76 -f $file and -r $file or error "-f|--file $file not readable: $!";
78 $distrojobs=(@target?1:2) if !defined $distrojobs;
79 $distrojobs=~/^\d+$/ or die "-D|distrojobs must be a number: $distrojobs";
80 $distrojobs>=1 or die "-D|distrojobs must be positive: $distrojobs";
81 # User may want to modify ASAP her files submitted for the test.
82 my $will_copy=@file || $component=~m{^/home/};
83 $parallel||=$will_copy ? 2 : 1;
84 error "Excessive arguments: @ARGV" if @ARGV;
85 @arch=@arches if !@arch;
86 my $path=join(":",@path) if @path;
87 @componentdistro and @componentdistro!=@distro and die "--cd|--componentdistro must have the same elements count as -d|--distro";
89 sub distro_normalize($;$)
94 s{^/var/lib/mock/+}{};
97 s/^(?:devel|rawhide)\b/fedora-rawhide/;
98 s/^(?:epel|rhel|centos)-?(\d)/epel-$1/;
99 s/^(?:f|fedora)-?(\d)/fedora-$1/;
101 @archuse="" if -d "/var/lib/mock/$_";
102 @archuse="i386" if s/-$arch_i386$//o;
103 @archuse="x86_64" if s/-$arch_x86_64$//o;
105 for my $arch (@archuse?@archuse:@arch) {
106 my $dir="/var/lib/mock/$_".(!$arch?"":"-$arch");
107 $force or -d $dir or error "No distro: $dir";
110 return ($_,@archuse);
113 # epel-\d-i386|fedora-\d-i386|fedora-rawhide-i386
115 for my $distroi (0..$#distro) {
116 my $distro=$distro[$distroi];
117 my $componentdistro=$componentdistro[$distroi];
119 if ($componentdistro) {
120 my $force=($componentdistro=~s/!$//);
121 ($componentdistro,@archuse)=distro_normalize $componentdistro,$force;
122 @archuse and die "--cd|--componentdistro must have no arch: ".join(" ",@archuse);
124 ($distro,@archuse)=distro_normalize $distro;
125 $componentdistro||=$distro;
126 @archuse=@arch if !@archuse;
127 for my $archuse (@archuse) {
128 for my $target (@target?@target:undef()) {
129 push @distrouse,{"distro"=>$distro.(!$archuse?"":"-$archuse"),"componentdistro"=>$componentdistro,"target"=>$target};
138 warn "+ mkdir $dir\n";
139 mkdir $dir or die "mkdir $dir: $!";
147 $cmd="set -ex; $cmd";
148 my $ok="$log.ok" if $log;
149 $cmd="($cmd; touch $ok) 2>&1|tee -a $log; test -f $ok" if $log;
152 system $cmd and die "$cmd: $!";
156 my $basedir=$ENV{"HOME"}."/hammock";
157 -d $basedir or newdir $basedir;
158 my $idbase=strftime("%Y%m%d",localtime());
161 for my $seq (defined $userid ? $userid : (0..99)) {
162 $id=$idbase.(defined $userid ? $seq : sprintf("%02d",$seq));
166 spawn "rm -rf $dir" if -d $dir && $force && defined $userid;
167 error "Directory not free: $dir" if !$id || !$dir || -e $dir;
168 print STDERR "ID = $id | dir = $dir\n";
169 error "No distros specified" if !@distrouse;
170 die "$error errors seen, aborted" if $error;
174 my($fname,$content)=@_;
177 open F,">$fname" or die $fname;
178 print F $content or die $fname;
179 close F or die $fname;
182 spawn "renice 20 -p $$";
185 spawn "uname -r >$dir/kernel";
188 "component"=>$component,
190 "file"=>join("\n",@file),
191 "configure"=>$configure,
193 while (my($name,$val)=each(%dump)) {
194 writefile "$dir/$name","$val\n" if $val;
199 my($sub,$in,$out)=@_;
204 open F,$in or die $in;
205 local $_=do { local $/; <F>; } or die $in;
208 &{$sub}() or die $_."\nError substituting $in";
215 while (@distrouse || keys(%child)) {
216 while (keys(%child)<$distrojobs && @distrouse) {
217 my $distrouse=shift @distrouse;
218 my $distro=$distrouse->{"distro"};
219 my $componentdistro=$distrouse->{"componentdistro"};
220 my $target=$distrouse->{"target"};
221 my $rpmbuild="rpmbuild";
226 if ($component=~/^fedora(.*)$/) {
228 $cvsbasedir="F-$1" if $componentdistro=~/^fedora-(\d+)$/;
229 $cvsbasedir="devel" if $componentdistro=~/^fedora-rawhide$/;
230 die "$component vs. $componentdistro" if !$cvsbasedir;
231 $cvsroot=$fedoracvsroot;
233 if ($component=~/^rhel(.*)$/) {
235 $cvsbasedir="RHEL-$1" if $componentdistro=~/^epel-(\d+)$/;
236 die "$component vs. $componentdistro" if !$cvsbasedir;
237 $cvsroot=$rhelcvsroot;
238 # EPEL still uses Berkeley DB version 8 while F-11+ (F-10?) uses version 9.
239 # Using db_dump and db_load would no longer make it mock compatible.
240 $rpmbuild.=q{ --dbpath $PWD --nodeps};
243 my $distrodirbase=$distro;
244 $distrodirbase.="-$target" if $target;
245 my $distrodir="$dir/$distrodirbase";
247 $log="$distrodir/log";
248 my $out="$distrodir/out";
252 die if !defined $pid;
254 $child{$pid}=$distrodirbase;
259 my $builddir="$distrodir/build";
262 # Do not use mockrun as the rpm database may be in a different version.
263 spawn "rpm -r /var/lib/mock/$distro/root -qa|sort >$distrodir/rpm-qa";
270 $c="export PATH=\"$path:\$PATH\"; $c" if $path;
271 $c="export MAKEFLAGS=\"-j\$[`getconf _NPROCESSORS_ONLN`*3/2]\"; $c";
272 $c="export http_proxy=http://127.0.0.1:3128/; $c";
273 $c="set -ex; cd $builddir; $c";
274 die "found ': $c" if $c=~/'/;
275 spawn "mockrun $::distro '$c'";
281 spawn "cd $distrodir; cvs -q -z3 -d $cvsroot co rpms/$cvsrepo/$cvsbasedir";
282 my $componentdir="$distrodir/rpms/$cvsrepo/$cvsbasedir";
283 -d $componentdir or die "Failed checkout to: $componentdir";
284 # Required for RHEL; Fedora does so automatically.
285 spawn "cd $componentdir/..; cvs -q -z3 -d $cvsroot co common";
286 # Workaround (RHEL-5?) curl which uses `Pragma: nocache' on $http_proxy.
287 subst sub { s{echo "curl }{$&-H 'Pragma: cache' }; },"$componentdir/../common/Makefile.common";
289 for my $file (@file) {
291 $filebase=~s{^.*/}{};
292 my $target="$componentdir/$filebase";
293 # Some *.patch files may be new.
294 # -f $target or die "File $file does not exist at $target";
295 spawn "rm -f $target; cp -p $file $target";
298 my $glob="$componentdir/*.src.rpm";
299 @{[glob $glob]}==0 or die "Found some before test-srpm: $glob";
300 # No `spawn' as we could get:
301 # error: unpacking of archive failed on file X;4a56efef: cpio: MD5 sum mismatch
302 mockrun "cd $componentdir; make test-srpm";
303 my @srcrpm=(glob $glob);
304 @srcrpm==1 or die "Did not find 1 srcrpm: @srcrpm";
309 my $srcrpmbasename=$srcrpm;
310 $srcrpmbasename=~s{^.*/}{};
311 spawn "cp -p $srcrpm $builddir/$srcrpmbasename";
313 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"};
314 $rpmbuildlocal="orphanripper $rpmbuildlocal" if $cvsrepo && $cvsrepo eq "glibc";
315 mockrun $rpmbuildlocal." --rebuild --with testsuite".($parallel<2 ? "" : " --with parallel")." $srcrpmbasename";
320 if ($component=~/^(gdb|binutils)cvs$/) {
322 my $cvsbare=$which eq "gdb" ? $gdbcvsbare : $binutilscvsbare;
324 spawn "cp -a $cvsbare $builddir/src; cd $builddir/src; cvs update $cvsbranch";
326 spawn "cd $builddir; cvs -q -z3 -d :pserver:anoncvs:\@sourceware.org:/cvs/src co $cvsbranch $which";
328 spawn "cd $builddir/src; test -z \"\$(cvs update $cvsbranch)\"";
329 $baretestsuite="$builddir/src";
332 if ($component=~/^archer-/) {
333 if (-d $archermaster) {
334 spawn "cp -a $archermaster $builddir/$component; cd $builddir/$component; git pull"
336 spawn "cd $builddir; git clone git://sourceware.org/git/archer.git; mv -f archer $component";
338 spawn "cd $builddir/$component; git checkout -b $component origin/$component; [ \"`git status`\" = \"# On branch $component\nnothing to commit (working directory clean)\" ]";
339 $baretestsuite="$builddir/$component";
342 if ($component=~m{^/home/}) {
343 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 || :";
344 $baretestsuite="$builddir/src";
347 if ($baretestsuite) {
348 for my $file (@file) {
349 my $target="$baretestsuite/$file";
350 if ($file=~m{[.](R?)patch$}) {
353 $fileabs=$ENV{"PWD"}."/$fileabs" if $fileabs!~m{^/};
354 spawn "cd $baretestsuite; patch -${R}p".($component=~/binutils/ ? "0" : "1")." <$fileabs";
356 -f $target or $file=~m{/testsuite/} or die "File $file does not exist at $target";
357 spawn "rm -f $target; cp -p $file $target";
362 $errs1.=" --target=$target" if $target;
363 $errs1.=" $configure" if $configure;
365 if ($component eq "binutilscvs") {
366 mockrun "cd $baretestsuite; $errs1; errs2; ulimit -c unlimited; orphanripper make -k check || :; mkdir $out; ".q{for file in {gas/testsuite/gas,ld/ld,binutils/binutils}.{sum,log};do ln $file}." $out/binutils-$distro-".q{$(basename $file) || :; done;};
368 my @check=($distro=~/-x86_64/ ? qw(-m64 -m32) : -m32);
369 @check=map("check//unix/$_",@check);
370 # FSF GDB has no PIE support.
371 # @check=map({($_,"$_/-fPIE/-pie");} @check);
372 # for i in ".join(" ",@check).";do orphanripper make -k \$i || :;done
373 mockrun "cd $baretestsuite; $errs1; errs2; cd gdb; ulimit -c unlimited; orphanripper make -k ".join(" ",@check)." || :; mkdir $out; ".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-$distro".q{$suffix.$t || :; done; done;};
376 # perl -i -pe 's{\Q'"$HOME"'\E/.*?/build/[^/]*/}{}g' "$base"/*
377 my $HOME=$ENV{"HOME"};
378 for my $file (<$out/*>) {
379 subst sub { s{\Q$HOME\E/.*?/build/[^/]*/}{}g; },$file;
382 die "internal error" if @target;
385 # Call gdbunpack only if no direct $out directory will be created.
386 # It is needed only for .src.rpm-built testsuites, no matter how .src.rpm
389 if ($component=~/^(?:fedora|rhel)glibc$/) {
390 @testinlog=(qr/={20}TESTING DETAILS={17}/,qr/={20}PLT RELOCS END={18}/);
393 subst sub { s{^.*?\n($testinlog[0]\n.*\n$testinlog[1]\n).*$}{$1}s; },$log,$out;
394 } elsif ($cvsbasedir || $srcrpm) {
395 # Applies both to gdb and binutils.
396 spawn "gdbunpack $log";
399 exit 0 if $parallel>1;
402 print STDERR "waiting for ".scalar(keys(%child))." children, ".scalar(@distrouse)." distros to go...\n";
404 next if $pid==-1 && $!==10; # 10==No child processes
405 die "wait()==-1: $!" if $pid==-1;
406 die "not found pid $pid" if !$child{$pid};
407 error "weird status $? for pid $pid: ".$child{$pid} if $?;
408 print STDERR "finished: $pid ".$child{$pid}."\n";
420 $r.=int($sec/(60*60))."h";
423 if ($r || $sec>=60) {
424 $r.=int($sec/60)."m";
432 print STDERR "ID = $id | dir = $dir\n";
433 my $time=timestr(time()-$start);
434 print STDERR "total time=$time\n";
435 writefile "$dir/time","$time\n";
436 die "$error errors seen, aborted" if $error;
437 print STDERR "done\n";