6 use POSIX qw(&strftime);
11 my $gdbcvsbare=$ENV{"HOME"}."/redhat/gdb-cvs-bare";
12 my $archermaster=$ENV{"HOME"}."/redhat/master";
13 my $fedoracvsroot=q{:pserver:anonymous:@cvs.fedoraproject.org:/cvs/pkgs};
14 my $rhelcvsroot=q{:pserver:anonymous:@192.168.67.2:3401/cvs/dist};
15 my $arch_i386=qr{(?:x86|i\d86|ia32)}io;
16 my $arch_x86_64=qr{(?:x8664|x86_64|em64t)}io;
17 my @arches=qw(i386 x86_64);
18 my $arches_re=qr{(?:i386|x86_64)};
29 my $parallel=9; # 1 or 2 or 3
37 "i|userid=s"=>\$userid,
39 "1|serial"=>sub { $parallel=1; },
40 "2|standard"=>sub { $parallel=2; },
41 "3|parallel"=>sub { $parallel=3; },
42 "d|distro=s{,}"=>\@distro,
43 "p|path=s{,}"=>\@path,
44 "a|arch=s{,}"=>\@arch,
45 "c|component=s"=>\$component,
46 "s|srcrpm=s"=>\$srcrpm,
49 $component and ($component=~m{^(?:(?:fedora|rhel)(?:gdb|binutils|glibc)|gdbcvs|archer-.*|/home/.*)$} or die "-c|--component required to be: fedoragdb|rhelgdb|fedorabinutils|rhelbinutils|fedoraglibc|rhelglibc|gdbcvs|archer-*|/home/*");
50 $component and $component=~m{^/home/} and (-f "$component/gdb/gdbtypes.c" or die "$component/gdb/gdbtypes.c not found");
51 $component and $srcrpm and die "-c|--component excludes -s|--srcrpm";
52 $component or $srcrpm or die "-c|--component or -s|--srcrpm required";
53 $component||=""; # Make `eq' not complaining.
54 for my $file (@file) {
55 -f $file and -r $file or error "-f|--file $file not readable: $!";
57 # User may want to modify ASAP her files submitted for the test.
58 my $will_copy=@file || $component=~m{^/home/};
59 $parallel||=$will_copy ? 2 : 1;
60 error "Excessive arguments: @ARGV" if @ARGV;
61 @arch=@arches if !@arch;
62 my $path=join(":",@path) if @path;
64 # epel-\d-i386|fedora-\d-i386|fedora-rawhide-i386
67 s{^/var/lib/mock/+}{};
70 s/^(?:devel|rawhide)\b/fedora-rawhide/;
71 s/^(?:epel|rhel|centos)-?(\d)/epel-$1/;
72 s/^(?:f|fedora)-?(\d)/fedora-$1/;
74 @archuse="i386" if s/-$arch_i386$//o;
75 @archuse="x86_64" if s/-$arch_x86_64$//o;
76 @archuse=@arch if !@archuse;
77 for my $archuse (@archuse) {
78 my $basename="$_-$archuse";
79 my $dir="/var/lib/mock/$basename";
80 -d $dir or error "No distro: $dir";
81 push @distrouse,$basename;
89 warn "+ mkdir $dir\n";
90 mkdir $dir or die "mkdir $dir: $!";
99 my $ok="$log.ok" if $log;
100 $cmd="($cmd; touch $ok) 2>&1|tee -a $log; test -f $ok" if $log;
103 system $cmd and die "$cmd: $!";
107 my $basedir=$ENV{"HOME"}."/hammock";
108 -d $basedir or newdir $basedir;
109 my $idbase=strftime("%Y%m%d",localtime());
112 for my $seq (defined $userid ? $userid : (0..99)) {
113 $id=$idbase.(defined $userid ? $seq : sprintf("%02d",$seq));
117 spawn "rm -rf $dir" if -d $dir && $force && defined $userid;
118 error "Directory not free: $dir" if !$id || !$dir || -e $dir;
119 print STDERR "ID = $id | dir = $dir\n";
120 error "No distros specified" if !@distrouse;
121 die "$error errors seen, aborted" if $error;
123 spawn "renice 20 -p $$";
126 spawn "uname -r >$dir/kernel";
129 "component"=>$component,
131 "file"=>join("\n",@file),
133 while (my($name,$val)=each(%dump)) {
136 my $fname="$dir/$name";
137 open F,">$fname" or die $fname;
138 print F "$val\n" or die $fname;
139 close F or die $fname;
144 my($sub,$in,$out)=@_;
149 open F,$in or die $in;
150 local $_=do { local $/; <F>; } or die $in;
153 &{$sub}() or die $_."\nError substituting $in";
155 open F,">$out" or die $out;
156 print F $_ or die $out;
162 for my $distro (@distrouse) {
163 my $rpmbuild="rpmbuild";
168 if ($component=~/^fedora(gdb|binutils|glibc)$/) {
170 $cvsbasedir="F-$1" if $distro=~/^fedora-(\d+)-$arches_re$/;
171 $cvsbasedir="devel" if $distro=~/^fedora-rawhide-$arches_re$/;
172 die "$component vs. $distro" if !$cvsbasedir;
173 $cvsroot=$fedoracvsroot;
175 if ($component=~/^rhel(gdb|binutils|glibc)$/) {
177 $cvsbasedir="RHEL-$1" if $distro=~/^epel-(\d+)-$arches_re$/;
178 die "$component vs. $distro" if !$cvsbasedir;
179 $cvsroot=$rhelcvsroot;
180 # EPEL still uses Berkeley DB version 8 while F-11+ (F-10?) uses version 9.
181 # Using db_dump and db_load would no longer make it mock compatible.
182 $rpmbuild.=q{ --dbpath $PWD --nodeps};
185 my $distrodir="$dir/$distro";
187 $log="$distrodir/log";
188 my $out="$distrodir/out";
192 die if !defined $pid;
194 $child{$pid}=$distro;
199 my $builddir="$distrodir/build";
202 # Do not use mockrun as the rpm database may be in a different version.
203 spawn "rpm -r /var/lib/mock/$distro/root -qa|sort >$distrodir/rpm-qa";
210 $c="export PATH=\"$path:\$PATH\"; $c" if $path;
211 $c="export MAKEFLAGS=\"-j\$[`getconf _NPROCESSORS_ONLN`*3/2]\"; $c"
212 # FIXME: The testsuite results from binutils.spec should be uuencoded.
213 if $component!~/^(?:fedora|rhel)binutils$/;
214 $c="export http_proxy=http://127.0.0.1:3128/; $c";
215 $c="set -ex; cd $builddir; $c";
216 die "found ': $c" if $c=~/'/;
217 spawn "mockrun $::distro '$c'";
223 spawn "cd $distrodir; cvs -q -z3 -d $cvsroot co rpms/$cvsrepo/$cvsbasedir";
224 my $componentdir="$distrodir/rpms/$cvsrepo/$cvsbasedir";
225 -d $componentdir or die "Failed checkout to: $componentdir";
226 # Required for RHEL; Fedora does so automatically.
227 spawn "cd $componentdir/..; cvs -q -z3 -d $cvsroot co common";
228 # Workaround (RHEL-5?) curl which uses `Pragma: nocache' on $http_proxy.
229 subst sub { s{echo "curl }{$&-H 'Pragma: cache' }; },"$componentdir/../common/Makefile.common";
231 for my $file (@file) {
233 $filebase=~s{^.*/}{};
234 my $target="$componentdir/$filebase";
235 # Some *.patch files may be new.
236 # -f $target or die "File $file does not exist at $target";
237 spawn "rm -f $target; cp -p $file $target";
240 my $glob="$componentdir/*.src.rpm";
241 @{[glob $glob]}==0 or die "Found some before test-srpm: $glob";
242 # No `spawn' as we could get:
243 # error: unpacking of archive failed on file X;4a56efef: cpio: MD5 sum mismatch
244 mockrun "cd $componentdir; make test-srpm";
245 my @srcrpm=(glob $glob);
246 @srcrpm==1 or die "Did not find 1 srcrpm: @srcrpm";
251 my $srcrpmbasename=$srcrpm;
252 $srcrpmbasename=~s{^.*/}{};
253 spawn "cp -p $srcrpm $builddir/$srcrpmbasename";
255 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"};
256 $rpmbuildlocal="orphanripper $rpmbuildlocal" if $cvsrepo && $cvsrepo eq "glibc";
257 mockrun $rpmbuildlocal." --rebuild --with testsuite".($parallel<2 ? "" : " --with parallel")." $srcrpmbasename";
262 if ($component eq "gdbcvs") {
263 if (-d $gdbcvsbare) {
264 spawn "cp -a $gdbcvsbare $builddir/src; cd $builddir/src; cvs update -A";
266 spawn "cd $builddir; cvs -q -z3 -d :pserver:anoncvs:\@sourceware.org:/cvs/src co gdb";
268 spawn "cd $builddir/src".q{; test -z "$(cvs update -A)"};
269 $baretestsuite="$builddir/src";
272 if ($component=~/^archer-/) {
273 if (-d $archermaster) {
274 spawn "cp -a $archermaster $builddir/$component; cd $builddir/$component; git pull"
276 spawn "cd $builddir; git clone git://sourceware.org/git/archer.git; mv -f archer $component";
278 spawn "cd $builddir/$component; git checkout -b $component origin/$component; [ \"`git status`\" = \"# On branch $component\nnothing to commit (working directory clean)\" ]";
279 $baretestsuite="$builddir/$component";
282 if ($component=~m{^/home/}) {
283 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 || :";
284 $baretestsuite="$builddir/src";
287 if ($baretestsuite) {
288 for my $file (@file) {
289 my $target="$baretestsuite/$file";
290 if ($file=~m{\Q.patch\E$}) {
292 $fileabs=$ENV{"PWD"}."/$fileabs" if $fileabs!~m{^/};
293 spawn "cd $baretestsuite; patch -p1 <$fileabs";
295 -f $target or $file=~m{/testsuite/} or die "File $file does not exist at $target";
296 spawn "rm -f $target; cp -p $file $target";
300 my @check=($distro=~/-x86_64/ ? qw(-m64 -m32) : -m32);
301 @check=map("check//unix/$_",@check);
302 # FSF GDB has no PIE support.
303 # @check=map({($_,"$_/-fPIE/-pie");} @check);
304 # for i in ".join(" ",@check).";do orphanripper make -k \$i || :;done
305 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;};
308 # Call gdbunpack only if no direct $out directory will be created.
309 # It is needed only for .src.rpm-built testsuites, no matter how .src.rpm
312 if ($component=~/^(?:fedora|rhel)glibc$/) {
313 @testinlog=(qr/={20}TESTING DETAILS={17}/,qr/={20}PLT RELOCS END={18}/);
314 } elsif ($component=~/^(?:fedora|rhel)binutils$/) {
315 @testinlog=(qr/={20}TESTING={25}/,qr/={20}TESTING END={21}/);
318 subst sub { s{^.*?\n($testinlog[0]\n.*\n$testinlog[1]\n).*$}{$1}s; },$log,$out;
319 } elsif ($cvsbasedir || $srcrpm) {
320 spawn "gdbunpack $log";
323 exit 0 if $parallel>1;
327 print STDERR "waiting for ".scalar(keys(%child))." children...\n";
329 last if $pid==-1 && $!==10; # 10==No child processes
330 die "wait()==-1: $!" if $pid==-1;
331 die "not found pid $pid" if !$child{$pid};
332 error "weird status $? for pid $pid: ".$child{$pid} if $?;
333 print STDERR "finished: $pid ".$child{$pid}."\n";
336 die "Uncollected children: ".keys(%child) if keys(%child);
344 $r.=int($sec/(60*60))."h";
347 if ($r || $sec>=60) {
348 $r.=int($sec/60)."m";
356 print STDERR "ID = $id | dir = $dir\n";
357 print STDERR "total time=".timestr(time()-$start)."\n";
358 die "$error errors seen, aborted" if $error;
360 print STDERR "done\n";