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|glibc)|gdbcvs|archer-.*|/home/.*)$} or die "-c|--component required to be: fedoragdb|rhelgdb|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 for my $distro (@distrouse) {
148 if ($component=~/^fedora(gdb|glibc)$/) {
150 $cvsbasedir="F-$1" if $distro=~/^fedora-(\d+)-$arches_re$/;
151 $cvsbasedir="devel" if $distro=~/^fedora-rawhide-$arches_re$/;
152 die "$component vs. $distro" if !$cvsbasedir;
153 $cvsroot=$fedoracvsroot;
155 if ($component=~/^rhel(gdb|glibc)$/) {
157 $cvsbasedir="RHEL-$1" if $distro=~/^epel-(\d+)-$arches_re$/;
158 die "$component vs. $distro" if !$cvsbasedir;
159 $cvsroot=$rhelcvsroot;
162 my $distrodir="$dir/$distro";
164 $log="$distrodir/log";
165 my $out="$distrodir/out";
169 die if !defined $pid;
171 $child{$pid}=$distro;
176 my $builddir="$distrodir/build";
184 $c="export PATH=\"$path:\$PATH\"; $c" if $path;
185 $c="export MAKEFLAGS=\"-j\$[`getconf _NPROCESSORS_ONLN`*3/2]\"; $c";
186 $c="set -ex; cd $builddir; $c";
187 die "found ': $c" if $c=~/'/;
188 spawn "mockrun $::distro '$c'";
191 mockrun "rpm -qa|sort >$distrodir/rpm-qa";
196 spawn "cd $distrodir; cvs -q -z3 -d $cvsroot co rpms/$cvsrepo/$cvsbasedir";
197 my $componentdir="$distrodir/rpms/$cvsrepo/$cvsbasedir";
198 -d $componentdir or die "Failed checkout to: $componentdir";
199 # Required for RHEL; Fedora does so automatically.
200 spawn "cd $componentdir/..; cvs -q -z3 -d $cvsroot co common";
202 for my $file (@file) {
204 $filebase=~s{^.*/}{};
205 my $target="$componentdir/$filebase";
206 # Some *.patch files may be new.
207 # -f $target or die "File $file does not exist at $target";
208 spawn "rm -f $target; cp -p $file $target";
211 my $glob="$componentdir/*.src.rpm";
212 @{[glob $glob]}==0 or die "Found some before test-srpm: $glob";
213 spawn "cd $componentdir; make test-srpm";
214 my @srcrpm=(glob $glob);
215 @srcrpm==1 or die "Did not find 1 srcrpm: @srcrpm";
220 my $srcrpmbasename=$srcrpm;
221 $srcrpmbasename=~s{^.*/}{};
222 spawn "cp -p $srcrpm $builddir/$srcrpmbasename";
224 my $rpmbuildlocal=q{rpmbuild --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"};
225 $rpmbuildlocal="orphanripper $rpmbuildlocal" if $cvsrepo && $cvsrepo eq "glibc";
226 mockrun $rpmbuildlocal." --rebuild --with testsuite".($parallel<2 ? "" : " --with parallel")." $srcrpmbasename";
231 if ($component eq "gdbcvs") {
232 if (-d $gdbcvsbare) {
233 spawn "cp -a $gdbcvsbare $builddir/src; cd $builddir/src; cvs update -A";
235 spawn "cd $builddir; cvs -q -z3 -d :pserver:anoncvs:\@sourceware.org:/cvs/src co gdb";
237 spawn "cd $builddir/src".q{; test -z "$(cvs update -A)"};
238 $baretestsuite="$builddir/src";
241 if ($component=~/^archer-/) {
242 if (-d $archermaster) {
243 spawn "cp -a $archermaster $builddir/$component; cd $builddir/$component; git pull"
245 spawn "cd $builddir; git clone git://sourceware.org/git/archer.git; mv -f archer $component";
247 spawn "cd $builddir/$component; git checkout -b $component origin/$component; [ \"`git status`\" = \"# On branch $component\nnothing to commit (working directory clean)\" ]";
248 $baretestsuite="$builddir/$component";
251 if ($component=~m{^/home/}) {
252 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 || :";
253 $baretestsuite="$builddir/src";
256 if ($baretestsuite) {
257 for my $file (@file) {
258 my $target="$baretestsuite/$file";
259 if ($file=~m{\Q.patch\E$}) {
261 $fileabs=$ENV{"PWD"}."/$fileabs" if $fileabs!~m{^/};
262 spawn "cd $baretestsuite; patch -p1 <$fileabs";
264 -f $target or $file=~m{/testsuite/} or die "File $file does not exist at $target";
265 spawn "rm -f $target; cp -p $file $target";
269 my @check=($distro=~/-x86_64/ ? qw(-m64 -m32) : -m32);
270 @check=map("check//unix/$_",@check);
271 # FSF GDB has no PIE support.
272 # @check=map({($_,"$_/-fPIE/-pie");} @check);
273 # for i in ".join(" ",@check).";do orphanripper make -k \$i || :;done
274 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;};
277 # Call gdbunpack only if no direct $out directory will be created.
278 # It is needed only for .src.rpm-built testsuites, no matter how .src.rpm
280 if ($component=~/^(?:fedora|rhel)glibc$/) {
282 open F,$log or die $log;
283 my $F=do { local $/; <F>; } or die $log;
285 $F=~s{^.*?\n(={20}TESTING DETAILS={17}\n.*\n={20}PLT RELOCS END={18}\n).*$}{$1}s or die "No TESTING part found: $log";
287 open F,">$out" or die $out;
288 print F $F or die $out;
290 } elsif ($cvsbasedir || $srcrpm) {
291 spawn "gdbunpack $log";
294 exit 0 if $parallel>1;
298 print STDERR "waiting for ".scalar(keys(%child))." children...\n";
300 last if $pid==-1 && $!==10; # 10==No child processes
301 die "wait()==-1: $!" if $pid==-1;
302 die "not found pid $pid" if !$child{$pid};
303 error "weird status $? for pid $pid: ".$child{$pid} if $?;
304 print STDERR "finished: $pid ".$child{$pid}."\n";
307 die "Uncollected children: ".keys(%child) if keys(%child);
315 $r.=int($sec/(60*60))."h";
318 if ($r || $sec>=60) {
319 $r.=int($sec/60)."m";
327 print STDERR "ID = $id | dir = $dir\n";
328 print STDERR "total time=".timestr(time()-$start)."\n";
329 die "$error errors seen, aborted" if $error;
331 print STDERR "done\n";