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/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
38 # FIXME: Connect make paralellization to the children.
41 "i|userid=s"=>\$userid,
43 "1|serial"=>sub { $parallel=1; },
44 "2|standard"=>sub { $parallel=2; },
45 "3|parallel"=>sub { $parallel=3; },
46 "d|distro=s{,}"=>\@distro,
47 "cd|componentdistro=s{,}"=>\@componentdistro,
48 "p|path=s{,}"=>\@path,
49 "a|arch=s{,}"=>\@arch,
50 "c|component=s"=>\$component,
51 "s|srcrpm=s"=>\$srcrpm,
53 "target=s{,}"=>\@target,
54 "D|distrojobs=s"=>\$distrojobs,
56 $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/*");
57 $component and $component=~m{^/home/} and (-f "$component/gdb/gdbtypes.c" or die "$component/gdb/gdbtypes.c not found");
58 $component and $srcrpm and die "-c|--component excludes -s|--srcrpm";
59 $component or $srcrpm or die "-c|--component or -s|--srcrpm required";
60 $component||=""; # Make `eq' not complaining.
61 @target and ($srcrpm or $component=~/^(?:fedora|rhel)/) and die "--target is available only for baretestsuite modes";
63 do { error "Duplicate target: $_\n" if $target{$_}++; } for @target;
64 @arch="x86_64" if @target&&!@arch;
65 for my $file (@file) {
66 -f $file and -r $file or error "-f|--file $file not readable: $!";
68 $distrojobs=(@target?1:2) if !defined $distrojobs;
69 $distrojobs=~/^\d+$/ or die "-D|distrojobs must be a number: $distrojobs";
70 $distrojobs>=1 or die "-D|distrojobs must be positive: $distrojobs";
71 # User may want to modify ASAP her files submitted for the test.
72 my $will_copy=@file || $component=~m{^/home/};
73 $parallel||=$will_copy ? 2 : 1;
74 error "Excessive arguments: @ARGV" if @ARGV;
75 @arch=@arches if !@arch;
76 my $path=join(":",@path) if @path;
77 @componentdistro and @componentdistro!=@distro and die "--cd|--componentdistro must have the same elements count as -d|--distro";
79 sub distro_normalize($)
83 s{^/var/lib/mock/+}{};
86 s/^(?:devel|rawhide)\b/fedora-rawhide/;
87 s/^(?:epel|rhel|centos)-?(\d)/epel-$1/;
88 s/^(?:f|fedora)-?(\d)/fedora-$1/;
90 @archuse="i386" if s/-$arch_i386$//o;
91 @archuse="x86_64" if s/-$arch_x86_64$//o;
93 for my $arch (@archuse?@archuse:@arch) {
94 my $dir="/var/lib/mock/$_-$arch";
95 -d $dir or error "No distro: $dir";
101 # epel-\d-i386|fedora-\d-i386|fedora-rawhide-i386
103 for my $distroi (0..$#distro) {
104 my $distro=$distro[$distroi];
105 my $componentdistro=$componentdistro[$distroi];
107 if ($componentdistro) {
108 ($componentdistro,@archuse)=distro_normalize $componentdistro;
109 @archuse and die "--cd|--componentdistro must have no arch: ".join(" ",@archuse);
111 ($distro,@archuse)=distro_normalize $distro;
112 $componentdistro||=$distro;
113 @archuse=@arch if !@archuse;
114 for my $archuse (@archuse) {
115 for my $target (@target?@target:undef()) {
116 push @distrouse,{"distro"=>"$distro-$archuse","componentdistro"=>$componentdistro,"target"=>$target};
125 warn "+ mkdir $dir\n";
126 mkdir $dir or die "mkdir $dir: $!";
134 $cmd="set -ex; $cmd";
135 my $ok="$log.ok" if $log;
136 $cmd="($cmd; touch $ok) 2>&1|tee -a $log; test -f $ok" if $log;
139 system $cmd and die "$cmd: $!";
143 my $basedir=$ENV{"HOME"}."/hammock";
144 -d $basedir or newdir $basedir;
145 my $idbase=strftime("%Y%m%d",localtime());
148 for my $seq (defined $userid ? $userid : (0..99)) {
149 $id=$idbase.(defined $userid ? $seq : sprintf("%02d",$seq));
153 spawn "rm -rf $dir" if -d $dir && $force && defined $userid;
154 error "Directory not free: $dir" if !$id || !$dir || -e $dir;
155 print STDERR "ID = $id | dir = $dir\n";
156 error "No distros specified" if !@distrouse;
157 die "$error errors seen, aborted" if $error;
161 my($fname,$content)=@_;
164 open F,">$fname" or die $fname;
165 print F $content or die $fname;
166 close F or die $fname;
169 spawn "renice 20 -p $$";
172 spawn "uname -r >$dir/kernel";
175 "component"=>$component,
177 "file"=>join("\n",@file),
179 while (my($name,$val)=each(%dump)) {
180 writefile "$dir/$name","$val\n" if $val;
185 my($sub,$in,$out)=@_;
190 open F,$in or die $in;
191 local $_=do { local $/; <F>; } or die $in;
194 &{$sub}() or die $_."\nError substituting $in";
201 while (@distrouse || keys(%child)) {
202 while (keys(%child)<$distrojobs && @distrouse) {
203 my $distrouse=shift @distrouse;
204 my $distro=$distrouse->{"distro"};
205 my $componentdistro=$distrouse->{"componentdistro"};
206 my $target=$distrouse->{"target"};
207 my $rpmbuild="rpmbuild";
212 if ($component=~/^fedora(.*)$/) {
214 $cvsbasedir="F-$1" if $componentdistro=~/^fedora-(\d+)$/;
215 $cvsbasedir="devel" if $componentdistro=~/^fedora-rawhide$/;
216 die "$component vs. $componentdistro" if !$cvsbasedir;
217 $cvsroot=$fedoracvsroot;
219 if ($component=~/^rhel(.*)$/) {
221 $cvsbasedir="RHEL-$1" if $componentdistro=~/^epel-(\d+)$/;
222 die "$component vs. $componentdistro" if !$cvsbasedir;
223 $cvsroot=$rhelcvsroot;
224 # EPEL still uses Berkeley DB version 8 while F-11+ (F-10?) uses version 9.
225 # Using db_dump and db_load would no longer make it mock compatible.
226 $rpmbuild.=q{ --dbpath $PWD --nodeps};
229 my $distrodirbase=$distro;
230 $distrodirbase.="-$target" if $target;
231 my $distrodir="$dir/$distrodirbase";
233 $log="$distrodir/log";
234 my $out="$distrodir/out";
238 die if !defined $pid;
240 $child{$pid}=$distrodirbase;
245 my $builddir="$distrodir/build";
248 # Do not use mockrun as the rpm database may be in a different version.
249 spawn "rpm -r /var/lib/mock/$distro/root -qa|sort >$distrodir/rpm-qa";
256 $c="export PATH=\"$path:\$PATH\"; $c" if $path;
257 $c="export MAKEFLAGS=\"-j\$[`getconf _NPROCESSORS_ONLN`*3/2]\"; $c";
258 $c="export http_proxy=http://127.0.0.1:3128/; $c";
259 $c="set -ex; cd $builddir; $c";
260 die "found ': $c" if $c=~/'/;
261 spawn "mockrun $::distro '$c'";
267 spawn "cd $distrodir; cvs -q -z3 -d $cvsroot co rpms/$cvsrepo/$cvsbasedir";
268 my $componentdir="$distrodir/rpms/$cvsrepo/$cvsbasedir";
269 -d $componentdir or die "Failed checkout to: $componentdir";
270 # Required for RHEL; Fedora does so automatically.
271 spawn "cd $componentdir/..; cvs -q -z3 -d $cvsroot co common";
272 # Workaround (RHEL-5?) curl which uses `Pragma: nocache' on $http_proxy.
273 subst sub { s{echo "curl }{$&-H 'Pragma: cache' }; },"$componentdir/../common/Makefile.common";
275 for my $file (@file) {
277 $filebase=~s{^.*/}{};
278 my $target="$componentdir/$filebase";
279 # Some *.patch files may be new.
280 # -f $target or die "File $file does not exist at $target";
281 spawn "rm -f $target; cp -p $file $target";
284 my $glob="$componentdir/*.src.rpm";
285 @{[glob $glob]}==0 or die "Found some before test-srpm: $glob";
286 # No `spawn' as we could get:
287 # error: unpacking of archive failed on file X;4a56efef: cpio: MD5 sum mismatch
288 mockrun "cd $componentdir; make test-srpm";
289 my @srcrpm=(glob $glob);
290 @srcrpm==1 or die "Did not find 1 srcrpm: @srcrpm";
295 my $srcrpmbasename=$srcrpm;
296 $srcrpmbasename=~s{^.*/}{};
297 spawn "cp -p $srcrpm $builddir/$srcrpmbasename";
299 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"};
300 $rpmbuildlocal="orphanripper $rpmbuildlocal" if $cvsrepo && $cvsrepo eq "glibc";
301 mockrun $rpmbuildlocal." --rebuild --with testsuite".($parallel<2 ? "" : " --with parallel")." $srcrpmbasename";
306 if ($component=~/^(gdb|binutils)cvs$/) {
308 my $cvsbare=$which eq "gdb" ? $gdbcvsbare : $binutilscvsbare;
310 spawn "cp -a $cvsbare $builddir/src; cd $builddir/src; cvs update -A";
312 spawn "cd $builddir; cvs -q -z3 -d :pserver:anoncvs:\@sourceware.org:/cvs/src co $which";
314 spawn "cd $builddir/src".q{; test -z "$(cvs update -A)"};
315 $baretestsuite="$builddir/src";
318 if ($component=~/^archer-/) {
319 if (-d $archermaster) {
320 spawn "cp -a $archermaster $builddir/$component; cd $builddir/$component; git pull"
322 spawn "cd $builddir; git clone git://sourceware.org/git/archer.git; mv -f archer $component";
324 spawn "cd $builddir/$component; git checkout -b $component origin/$component; [ \"`git status`\" = \"# On branch $component\nnothing to commit (working directory clean)\" ]";
325 $baretestsuite="$builddir/$component";
328 if ($component=~m{^/home/}) {
329 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 || :";
330 $baretestsuite="$builddir/src";
333 if ($baretestsuite) {
334 for my $file (@file) {
335 my $target="$baretestsuite/$file";
336 if ($file=~m{[.](R?)patch$}) {
339 $fileabs=$ENV{"PWD"}."/$fileabs" if $fileabs!~m{^/};
340 spawn "cd $baretestsuite; patch -${R}p".($component=~/binutils/ ? "0" : "1")." <$fileabs";
342 -f $target or $file=~m{/testsuite/} or die "File $file does not exist at $target";
343 spawn "rm -f $target; cp -p $file $target";
348 $errs1.=" --target=$target" if $target;
350 if ($component eq "binutilscvs") {
351 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;};
354 # perl -i -pe 's{\Q'"$HOME"'\E/.*?/build/[^/]*/}{}g' "$base"/*
355 my $HOME=$ENV{"HOME"};
356 for my $file (<$out/*>) {
357 subst sub { s{\Q$HOME\E/.*?/build/[^/]*/}{}g; },$file;
360 my @check=($distro=~/-x86_64/ ? qw(-m64 -m32) : -m32);
361 @check=map("check//unix/$_",@check);
362 # FSF GDB has no PIE support.
363 # @check=map({($_,"$_/-fPIE/-pie");} @check);
364 # for i in ".join(" ",@check).";do orphanripper make -k \$i || :;done
365 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;};
368 die "internal error" if @target;
371 # Call gdbunpack only if no direct $out directory will be created.
372 # It is needed only for .src.rpm-built testsuites, no matter how .src.rpm
375 if ($component=~/^(?:fedora|rhel)glibc$/) {
376 @testinlog=(qr/={20}TESTING DETAILS={17}/,qr/={20}PLT RELOCS END={18}/);
379 subst sub { s{^.*?\n($testinlog[0]\n.*\n$testinlog[1]\n).*$}{$1}s; },$log,$out;
380 } elsif ($cvsbasedir || $srcrpm) {
381 # Applies both to gdb and binutils.
382 spawn "gdbunpack $log";
385 exit 0 if $parallel>1;
388 print STDERR "waiting for ".scalar(keys(%child))." children, ".scalar(@distrouse)." distros to go...\n";
390 next if $pid==-1 && $!==10; # 10==No child processes
391 die "wait()==-1: $!" if $pid==-1;
392 die "not found pid $pid" if !$child{$pid};
393 error "weird status $? for pid $pid: ".$child{$pid} if $?;
394 print STDERR "finished: $pid ".$child{$pid}."\n";
406 $r.=int($sec/(60*60))."h";
409 if ($r || $sec>=60) {
410 $r.=int($sec/60)."m";
418 print STDERR "ID = $id | dir = $dir\n";
419 my $time=timestr(time()-$start);
420 print STDERR "total time=$time\n";
421 writefile "$dir/time","$time\n";
422 die "$error errors seen, aborted" if $error;
423 print STDERR "done\n";