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
39 # FIXME: Connect make paralellization to the children.
42 "i|userid=s"=>\$userid,
44 "1|serial"=>sub { $parallel=1; },
45 "2|standard"=>sub { $parallel=2; },
46 "3|parallel"=>sub { $parallel=3; },
47 "d|distro=s{,}"=>\@distro,
48 "cd|componentdistro=s{,}"=>\@componentdistro,
49 "p|path=s{,}"=>\@path,
50 "a|arch=s{,}"=>\@arch,
51 "c|component=s"=>\$component,
52 "s|srcrpm=s"=>\$srcrpm,
54 "target=s{,}"=>\@target,
55 "D|distrojobs=s"=>\$distrojobs,
56 "configure=s"=>\$configure,
58 $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/*");
59 $component and $component=~m{^/home/} and (-f "$component/gdb/gdbtypes.c" or die "$component/gdb/gdbtypes.c not found");
60 $component and $srcrpm and die "-c|--component excludes -s|--srcrpm";
61 $component or $srcrpm or die "-c|--component or -s|--srcrpm required";
62 $component||=""; # Make `eq' not complaining.
63 @target and ($srcrpm or $component=~/^(?:fedora|rhel)/) and die "--target is available only for baretestsuite modes";
65 do { error "Duplicate target: $_\n" if $target{$_}++; } for @target;
66 @arch="x86_64" if @target&&!@arch;
67 for my $file (@file) {
68 -f $file and -r $file or error "-f|--file $file not readable: $!";
70 $distrojobs=(@target?1:2) if !defined $distrojobs;
71 $distrojobs=~/^\d+$/ or die "-D|distrojobs must be a number: $distrojobs";
72 $distrojobs>=1 or die "-D|distrojobs must be positive: $distrojobs";
73 # User may want to modify ASAP her files submitted for the test.
74 my $will_copy=@file || $component=~m{^/home/};
75 $parallel||=$will_copy ? 2 : 1;
76 error "Excessive arguments: @ARGV" if @ARGV;
77 @arch=@arches if !@arch;
78 my $path=join(":",@path) if @path;
79 @componentdistro and @componentdistro!=@distro and die "--cd|--componentdistro must have the same elements count as -d|--distro";
81 sub distro_normalize($;$)
86 s{^/var/lib/mock/+}{};
89 s/^(?:devel|rawhide)\b/fedora-rawhide/;
90 s/^(?:epel|rhel|centos)-?(\d)/epel-$1/;
91 s/^(?:f|fedora)-?(\d)/fedora-$1/;
93 @archuse="" if -d "/var/lib/mock/$_";
94 @archuse="i386" if s/-$arch_i386$//o;
95 @archuse="x86_64" if s/-$arch_x86_64$//o;
97 for my $arch (@archuse?@archuse:@arch) {
98 my $dir="/var/lib/mock/$_".(!$arch?"":"-$arch");
99 $force or -d $dir or error "No distro: $dir";
102 return ($_,@archuse);
105 # epel-\d-i386|fedora-\d-i386|fedora-rawhide-i386
107 for my $distroi (0..$#distro) {
108 my $distro=$distro[$distroi];
109 my $componentdistro=$componentdistro[$distroi];
111 if ($componentdistro) {
112 my $force=($componentdistro=~s/!$//);
113 ($componentdistro,@archuse)=distro_normalize $componentdistro,$force;
114 @archuse and die "--cd|--componentdistro must have no arch: ".join(" ",@archuse);
116 ($distro,@archuse)=distro_normalize $distro;
117 $componentdistro||=$distro;
118 @archuse=@arch if !@archuse;
119 for my $archuse (@archuse) {
120 for my $target (@target?@target:undef()) {
121 push @distrouse,{"distro"=>$distro.(!$archuse?"":"-$archuse"),"componentdistro"=>$componentdistro,"target"=>$target};
130 warn "+ mkdir $dir\n";
131 mkdir $dir or die "mkdir $dir: $!";
139 $cmd="set -ex; $cmd";
140 my $ok="$log.ok" if $log;
141 $cmd="($cmd; touch $ok) 2>&1|tee -a $log; test -f $ok" if $log;
144 system $cmd and die "$cmd: $!";
148 my $basedir=$ENV{"HOME"}."/hammock";
149 -d $basedir or newdir $basedir;
150 my $idbase=strftime("%Y%m%d",localtime());
153 for my $seq (defined $userid ? $userid : (0..99)) {
154 $id=$idbase.(defined $userid ? $seq : sprintf("%02d",$seq));
158 spawn "rm -rf $dir" if -d $dir && $force && defined $userid;
159 error "Directory not free: $dir" if !$id || !$dir || -e $dir;
160 print STDERR "ID = $id | dir = $dir\n";
161 error "No distros specified" if !@distrouse;
162 die "$error errors seen, aborted" if $error;
166 my($fname,$content)=@_;
169 open F,">$fname" or die $fname;
170 print F $content or die $fname;
171 close F or die $fname;
174 spawn "renice 20 -p $$";
177 spawn "uname -r >$dir/kernel";
180 "component"=>$component,
182 "file"=>join("\n",@file),
183 "configure"=>$configure,
185 while (my($name,$val)=each(%dump)) {
186 writefile "$dir/$name","$val\n" if $val;
191 my($sub,$in,$out)=@_;
196 open F,$in or die $in;
197 local $_=do { local $/; <F>; } or die $in;
200 &{$sub}() or die $_."\nError substituting $in";
207 while (@distrouse || keys(%child)) {
208 while (keys(%child)<$distrojobs && @distrouse) {
209 my $distrouse=shift @distrouse;
210 my $distro=$distrouse->{"distro"};
211 my $componentdistro=$distrouse->{"componentdistro"};
212 my $target=$distrouse->{"target"};
213 my $rpmbuild="rpmbuild";
218 if ($component=~/^fedora(.*)$/) {
220 $cvsbasedir="F-$1" if $componentdistro=~/^fedora-(\d+)$/;
221 $cvsbasedir="devel" if $componentdistro=~/^fedora-rawhide$/;
222 die "$component vs. $componentdistro" if !$cvsbasedir;
223 $cvsroot=$fedoracvsroot;
225 if ($component=~/^rhel(.*)$/) {
227 $cvsbasedir="RHEL-$1" if $componentdistro=~/^epel-(\d+)$/;
228 die "$component vs. $componentdistro" if !$cvsbasedir;
229 $cvsroot=$rhelcvsroot;
230 # EPEL still uses Berkeley DB version 8 while F-11+ (F-10?) uses version 9.
231 # Using db_dump and db_load would no longer make it mock compatible.
232 $rpmbuild.=q{ --dbpath $PWD --nodeps};
235 my $distrodirbase=$distro;
236 $distrodirbase.="-$target" if $target;
237 my $distrodir="$dir/$distrodirbase";
239 $log="$distrodir/log";
240 my $out="$distrodir/out";
244 die if !defined $pid;
246 $child{$pid}=$distrodirbase;
251 my $builddir="$distrodir/build";
254 # Do not use mockrun as the rpm database may be in a different version.
255 spawn "rpm -r /var/lib/mock/$distro/root -qa|sort >$distrodir/rpm-qa";
262 $c="export PATH=\"$path:\$PATH\"; $c" if $path;
263 $c="export MAKEFLAGS=\"-j\$[`getconf _NPROCESSORS_ONLN`*3/2]\"; $c";
264 $c="export http_proxy=http://127.0.0.1:3128/; $c";
265 $c="set -ex; cd $builddir; $c";
266 die "found ': $c" if $c=~/'/;
267 spawn "mockrun $::distro '$c'";
273 spawn "cd $distrodir; cvs -q -z3 -d $cvsroot co rpms/$cvsrepo/$cvsbasedir";
274 my $componentdir="$distrodir/rpms/$cvsrepo/$cvsbasedir";
275 -d $componentdir or die "Failed checkout to: $componentdir";
276 # Required for RHEL; Fedora does so automatically.
277 spawn "cd $componentdir/..; cvs -q -z3 -d $cvsroot co common";
278 # Workaround (RHEL-5?) curl which uses `Pragma: nocache' on $http_proxy.
279 subst sub { s{echo "curl }{$&-H 'Pragma: cache' }; },"$componentdir/../common/Makefile.common";
281 for my $file (@file) {
283 $filebase=~s{^.*/}{};
284 my $target="$componentdir/$filebase";
285 # Some *.patch files may be new.
286 # -f $target or die "File $file does not exist at $target";
287 spawn "rm -f $target; cp -p $file $target";
290 my $glob="$componentdir/*.src.rpm";
291 @{[glob $glob]}==0 or die "Found some before test-srpm: $glob";
292 # No `spawn' as we could get:
293 # error: unpacking of archive failed on file X;4a56efef: cpio: MD5 sum mismatch
294 mockrun "cd $componentdir; make test-srpm";
295 my @srcrpm=(glob $glob);
296 @srcrpm==1 or die "Did not find 1 srcrpm: @srcrpm";
301 my $srcrpmbasename=$srcrpm;
302 $srcrpmbasename=~s{^.*/}{};
303 spawn "cp -p $srcrpm $builddir/$srcrpmbasename";
305 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"};
306 $rpmbuildlocal="orphanripper $rpmbuildlocal" if $cvsrepo && $cvsrepo eq "glibc";
307 mockrun $rpmbuildlocal." --rebuild --with testsuite".($parallel<2 ? "" : " --with parallel")." $srcrpmbasename";
312 if ($component=~/^(gdb|binutils)cvs$/) {
314 my $cvsbare=$which eq "gdb" ? $gdbcvsbare : $binutilscvsbare;
316 spawn "cp -a $cvsbare $builddir/src; cd $builddir/src; cvs update -A";
318 spawn "cd $builddir; cvs -q -z3 -d :pserver:anoncvs:\@sourceware.org:/cvs/src co $which";
320 spawn "cd $builddir/src".q{; test -z "$(cvs update -A)"};
321 $baretestsuite="$builddir/src";
324 if ($component=~/^archer-/) {
325 if (-d $archermaster) {
326 spawn "cp -a $archermaster $builddir/$component; cd $builddir/$component; git pull"
328 spawn "cd $builddir; git clone git://sourceware.org/git/archer.git; mv -f archer $component";
330 spawn "cd $builddir/$component; git checkout -b $component origin/$component; [ \"`git status`\" = \"# On branch $component\nnothing to commit (working directory clean)\" ]";
331 $baretestsuite="$builddir/$component";
334 if ($component=~m{^/home/}) {
335 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 || :";
336 $baretestsuite="$builddir/src";
339 if ($baretestsuite) {
340 for my $file (@file) {
341 my $target="$baretestsuite/$file";
342 if ($file=~m{[.](R?)patch$}) {
345 $fileabs=$ENV{"PWD"}."/$fileabs" if $fileabs!~m{^/};
346 spawn "cd $baretestsuite; patch -${R}p".($component=~/binutils/ ? "0" : "1")." <$fileabs";
348 -f $target or $file=~m{/testsuite/} or die "File $file does not exist at $target";
349 spawn "rm -f $target; cp -p $file $target";
354 $errs1.=" --target=$target" if $target;
355 $errs1.=" $configure" if $configure;
357 if ($component eq "binutilscvs") {
358 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;};
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 # perl -i -pe 's{\Q'"$HOME"'\E/.*?/build/[^/]*/}{}g' "$base"/*
369 my $HOME=$ENV{"HOME"};
370 for my $file (<$out/*>) {
371 subst sub { s{\Q$HOME\E/.*?/build/[^/]*/}{}g; },$file;
374 die "internal error" if @target;
377 # Call gdbunpack only if no direct $out directory will be created.
378 # It is needed only for .src.rpm-built testsuites, no matter how .src.rpm
381 if ($component=~/^(?:fedora|rhel)glibc$/) {
382 @testinlog=(qr/={20}TESTING DETAILS={17}/,qr/={20}PLT RELOCS END={18}/);
385 subst sub { s{^.*?\n($testinlog[0]\n.*\n$testinlog[1]\n).*$}{$1}s; },$log,$out;
386 } elsif ($cvsbasedir || $srcrpm) {
387 # Applies both to gdb and binutils.
388 spawn "gdbunpack $log";
391 exit 0 if $parallel>1;
394 print STDERR "waiting for ".scalar(keys(%child))." children, ".scalar(@distrouse)." distros to go...\n";
396 next if $pid==-1 && $!==10; # 10==No child processes
397 die "wait()==-1: $!" if $pid==-1;
398 die "not found pid $pid" if !$child{$pid};
399 error "weird status $? for pid $pid: ".$child{$pid} if $?;
400 print STDERR "finished: $pid ".$child{$pid}."\n";
412 $r.=int($sec/(60*60))."h";
415 if ($r || $sec>=60) {
416 $r.=int($sec/60)."m";
424 print STDERR "ID = $id | dir = $dir\n";
425 my $time=timestr(time()-$start);
426 print STDERR "total time=$time\n";
427 writefile "$dir/time","$time\n";
428 die "$error errors seen, aborted" if $error;
429 print STDERR "done\n";