6 use POSIX qw(&strftime);
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);
19 my $arches_re=qr{(?:i386|x86_64)};
30 my $parallel=9; # 1 or 2 or 3
38 "i|userid=s"=>\$userid,
40 "1|serial"=>sub { $parallel=1; },
41 "2|standard"=>sub { $parallel=2; },
42 "3|parallel"=>sub { $parallel=3; },
43 "d|distro=s{,}"=>\@distro,
44 "p|path=s{,}"=>\@path,
45 "a|arch=s{,}"=>\@arch,
46 "c|component=s"=>\$component,
47 "s|srcrpm=s"=>\$srcrpm,
50 $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/*");
51 $component and $component=~m{^/home/} and (-f "$component/gdb/gdbtypes.c" or die "$component/gdb/gdbtypes.c not found");
52 $component and $srcrpm and die "-c|--component excludes -s|--srcrpm";
53 $component or $srcrpm or die "-c|--component or -s|--srcrpm required";
54 $component||=""; # Make `eq' not complaining.
55 for my $file (@file) {
56 -f $file and -r $file or error "-f|--file $file not readable: $!";
58 # User may want to modify ASAP her files submitted for the test.
59 my $will_copy=@file || $component=~m{^/home/};
60 $parallel||=$will_copy ? 2 : 1;
61 error "Excessive arguments: @ARGV" if @ARGV;
62 @arch=@arches if !@arch;
63 my $path=join(":",@path) if @path;
65 # epel-\d-i386|fedora-\d-i386|fedora-rawhide-i386
68 s{^/var/lib/mock/+}{};
71 s/^(?:devel|rawhide)\b/fedora-rawhide/;
72 s/^(?:epel|rhel|centos)-?(\d)/epel-$1/;
73 s/^(?:f|fedora)-?(\d)/fedora-$1/;
75 @archuse="i386" if s/-$arch_i386$//o;
76 @archuse="x86_64" if s/-$arch_x86_64$//o;
77 @archuse=@arch if !@archuse;
78 for my $archuse (@archuse) {
79 my $basename="$_-$archuse";
80 my $dir="/var/lib/mock/$basename";
81 -d $dir or error "No distro: $dir";
82 push @distrouse,$basename;
90 warn "+ mkdir $dir\n";
91 mkdir $dir or die "mkdir $dir: $!";
100 my $ok="$log.ok" if $log;
101 $cmd="($cmd; touch $ok) 2>&1|tee -a $log; test -f $ok" if $log;
104 system $cmd and die "$cmd: $!";
108 my $basedir=$ENV{"HOME"}."/hammock";
109 -d $basedir or newdir $basedir;
110 my $idbase=strftime("%Y%m%d",localtime());
113 for my $seq (defined $userid ? $userid : (0..99)) {
114 $id=$idbase.(defined $userid ? $seq : sprintf("%02d",$seq));
118 spawn "rm -rf $dir" if -d $dir && $force && defined $userid;
119 error "Directory not free: $dir" if !$id || !$dir || -e $dir;
120 print STDERR "ID = $id | dir = $dir\n";
121 error "No distros specified" if !@distrouse;
122 die "$error errors seen, aborted" if $error;
124 spawn "renice 20 -p $$";
127 spawn "uname -r >$dir/kernel";
130 "component"=>$component,
132 "file"=>join("\n",@file),
134 while (my($name,$val)=each(%dump)) {
137 my $fname="$dir/$name";
138 open F,">$fname" or die $fname;
139 print F "$val\n" or die $fname;
140 close F or die $fname;
145 my($sub,$in,$out)=@_;
150 open F,$in or die $in;
151 local $_=do { local $/; <F>; } or die $in;
154 &{$sub}() or die $_."\nError substituting $in";
156 open F,">$out" or die $out;
157 print F $_ or die $out;
163 for my $distro (@distrouse) {
164 my $rpmbuild="rpmbuild";
169 if ($component=~/^fedora(gdb|binutils|glibc)$/) {
171 $cvsbasedir="F-$1" if $distro=~/^fedora-(\d+)-$arches_re$/;
172 $cvsbasedir="devel" if $distro=~/^fedora-rawhide-$arches_re$/;
173 die "$component vs. $distro" if !$cvsbasedir;
174 $cvsroot=$fedoracvsroot;
176 if ($component=~/^rhel(gdb|binutils|glibc)$/) {
178 $cvsbasedir="RHEL-$1" if $distro=~/^epel-(\d+)-$arches_re$/;
179 die "$component vs. $distro" if !$cvsbasedir;
180 $cvsroot=$rhelcvsroot;
181 # EPEL still uses Berkeley DB version 8 while F-11+ (F-10?) uses version 9.
182 # Using db_dump and db_load would no longer make it mock compatible.
183 $rpmbuild.=q{ --dbpath $PWD --nodeps};
186 my $distrodir="$dir/$distro";
188 $log="$distrodir/log";
189 my $out="$distrodir/out";
193 die if !defined $pid;
195 $child{$pid}=$distro;
200 my $builddir="$distrodir/build";
203 # Do not use mockrun as the rpm database may be in a different version.
204 spawn "rpm -r /var/lib/mock/$distro/root -qa|sort >$distrodir/rpm-qa";
211 $c="export PATH=\"$path:\$PATH\"; $c" if $path;
212 $c="export MAKEFLAGS=\"-j\$[`getconf _NPROCESSORS_ONLN`*3/2]\"; $c";
213 $c="export http_proxy=http://127.0.0.1:3128/; $c";
214 $c="set -ex; cd $builddir; $c";
215 die "found ': $c" if $c=~/'/;
216 spawn "mockrun $::distro '$c'";
222 spawn "cd $distrodir; cvs -q -z3 -d $cvsroot co rpms/$cvsrepo/$cvsbasedir";
223 my $componentdir="$distrodir/rpms/$cvsrepo/$cvsbasedir";
224 -d $componentdir or die "Failed checkout to: $componentdir";
225 # Required for RHEL; Fedora does so automatically.
226 spawn "cd $componentdir/..; cvs -q -z3 -d $cvsroot co common";
227 # Workaround (RHEL-5?) curl which uses `Pragma: nocache' on $http_proxy.
228 subst sub { s{echo "curl }{$&-H 'Pragma: cache' }; },"$componentdir/../common/Makefile.common";
230 for my $file (@file) {
232 $filebase=~s{^.*/}{};
233 my $target="$componentdir/$filebase";
234 # Some *.patch files may be new.
235 # -f $target or die "File $file does not exist at $target";
236 spawn "rm -f $target; cp -p $file $target";
239 my $glob="$componentdir/*.src.rpm";
240 @{[glob $glob]}==0 or die "Found some before test-srpm: $glob";
241 # No `spawn' as we could get:
242 # error: unpacking of archive failed on file X;4a56efef: cpio: MD5 sum mismatch
243 mockrun "cd $componentdir; make test-srpm";
244 my @srcrpm=(glob $glob);
245 @srcrpm==1 or die "Did not find 1 srcrpm: @srcrpm";
250 my $srcrpmbasename=$srcrpm;
251 $srcrpmbasename=~s{^.*/}{};
252 spawn "cp -p $srcrpm $builddir/$srcrpmbasename";
254 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"};
255 $rpmbuildlocal="orphanripper $rpmbuildlocal" if $cvsrepo && $cvsrepo eq "glibc";
256 mockrun $rpmbuildlocal." --rebuild --with testsuite".($parallel<2 ? "" : " --with parallel")." $srcrpmbasename";
261 if ($component=~/^(gdb|binutils)cvs$/) {
263 my $cvsbare=$which eq "gdb" ? $gdbcvsbare : $binutilscvsbare;
265 spawn "cp -a $cvsbare $builddir/src; cd $builddir/src; cvs update -A";
267 spawn "cd $builddir; cvs -q -z3 -d :pserver:anoncvs:\@sourceware.org:/cvs/src co $which";
269 spawn "cd $builddir/src".q{; test -z "$(cvs update -A)"};
270 $baretestsuite="$builddir/src";
273 if ($component=~/^archer-/) {
274 if (-d $archermaster) {
275 spawn "cp -a $archermaster $builddir/$component; cd $builddir/$component; git pull"
277 spawn "cd $builddir; git clone git://sourceware.org/git/archer.git; mv -f archer $component";
279 spawn "cd $builddir/$component; git checkout -b $component origin/$component; [ \"`git status`\" = \"# On branch $component\nnothing to commit (working directory clean)\" ]";
280 $baretestsuite="$builddir/$component";
283 if ($component=~m{^/home/}) {
284 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 || :";
285 $baretestsuite="$builddir/src";
288 if ($baretestsuite) {
289 for my $file (@file) {
290 my $target="$baretestsuite/$file";
291 if ($file=~m{[.](R?)patch$}) {
294 $fileabs=$ENV{"PWD"}."/$fileabs" if $fileabs!~m{^/};
295 spawn "cd $baretestsuite; patch -${R}p1 <$fileabs";
297 -f $target or $file=~m{/testsuite/} or die "File $file does not exist at $target";
298 spawn "rm -f $target; cp -p $file $target";
302 if ($component eq "binutilscvs") {
303 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;};
306 # perl -i -pe 's{\Q'"$HOME"'\E/.*?/build/[^/]*/}{}g' "$base"/*
307 my $HOME=$ENV{"HOME"};
308 for my $file (<$out/*>) {
309 subst sub { s{\Q$HOME\E/.*?/build/[^/]*/}{}g; },$file;
312 my @check=($distro=~/-x86_64/ ? qw(-m64 -m32) : -m32);
313 @check=map("check//unix/$_",@check);
314 # FSF GDB has no PIE support.
315 # @check=map({($_,"$_/-fPIE/-pie");} @check);
316 # for i in ".join(" ",@check).";do orphanripper make -k \$i || :;done
317 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;};
321 # Call gdbunpack only if no direct $out directory will be created.
322 # It is needed only for .src.rpm-built testsuites, no matter how .src.rpm
325 if ($component=~/^(?:fedora|rhel)glibc$/) {
326 @testinlog=(qr/={20}TESTING DETAILS={17}/,qr/={20}PLT RELOCS END={18}/);
329 subst sub { s{^.*?\n($testinlog[0]\n.*\n$testinlog[1]\n).*$}{$1}s; },$log,$out;
330 } elsif ($cvsbasedir || $srcrpm) {
331 # Applies both to gdb and binutils.
332 spawn "gdbunpack $log";
335 exit 0 if $parallel>1;
339 print STDERR "waiting for ".scalar(keys(%child))." children...\n";
341 last if $pid==-1 && $!==10; # 10==No child processes
342 die "wait()==-1: $!" if $pid==-1;
343 die "not found pid $pid" if !$child{$pid};
344 error "weird status $? for pid $pid: ".$child{$pid} if $?;
345 print STDERR "finished: $pid ".$child{$pid}."\n";
348 die "Uncollected children: ".keys(%child) if keys(%child);
356 $r.=int($sec/(60*60))."h";
359 if ($r || $sec>=60) {
360 $r.=int($sec/60)."m";
368 print STDERR "ID = $id | dir = $dir\n";
369 print STDERR "total time=".timestr(time()-$start)."\n";
370 die "$error errors seen, aborted" if $error;
372 print STDERR "done\n";