xref: /aoo4110/main/solenv/bin/subsequenttests (revision b1cdbd2c)
1*b1cdbd2cSJim Jagielskieval 'exec "$PERL" -Sw "$0" "$@"'
2*b1cdbd2cSJim Jagielski    if 0;
3*b1cdbd2cSJim Jagielski#**************************************************************
4*b1cdbd2cSJim Jagielski#
5*b1cdbd2cSJim Jagielski#  Licensed to the Apache Software Foundation (ASF) under one
6*b1cdbd2cSJim Jagielski#  or more contributor license agreements.  See the NOTICE file
7*b1cdbd2cSJim Jagielski#  distributed with this work for additional information
8*b1cdbd2cSJim Jagielski#  regarding copyright ownership.  The ASF licenses this file
9*b1cdbd2cSJim Jagielski#  to you under the Apache License, Version 2.0 (the
10*b1cdbd2cSJim Jagielski#  "License"); you may not use this file except in compliance
11*b1cdbd2cSJim Jagielski#  with the License.  You may obtain a copy of the License at
12*b1cdbd2cSJim Jagielski#
13*b1cdbd2cSJim Jagielski#    http://www.apache.org/licenses/LICENSE-2.0
14*b1cdbd2cSJim Jagielski#
15*b1cdbd2cSJim Jagielski#  Unless required by applicable law or agreed to in writing,
16*b1cdbd2cSJim Jagielski#  software distributed under the License is distributed on an
17*b1cdbd2cSJim Jagielski#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18*b1cdbd2cSJim Jagielski#  KIND, either express or implied.  See the License for the
19*b1cdbd2cSJim Jagielski#  specific language governing permissions and limitations
20*b1cdbd2cSJim Jagielski#  under the License.
21*b1cdbd2cSJim Jagielski#
22*b1cdbd2cSJim Jagielski#**************************************************************
23*b1cdbd2cSJim Jagielski
24*b1cdbd2cSJim Jagielskiuse lib("$ENV{SOLARENV}/bin/modules");
25*b1cdbd2cSJim Jagielskiuse SourceConfig;
26*b1cdbd2cSJim Jagielski
27*b1cdbd2cSJim Jagielskimy $keep_going = 0;
28*b1cdbd2cSJim Jagielskimy $dry_run = 0;
29*b1cdbd2cSJim Jagielskimy $max_running = 1;
30*b1cdbd2cSJim Jagielskiwhile (@ARGV) {
31*b1cdbd2cSJim Jagielski    my $arg = shift(@ARGV);
32*b1cdbd2cSJim Jagielski    if ($arg =~ /^-P([1-9]\d*)$/) {
33*b1cdbd2cSJim Jagielski        $max_running = $1;
34*b1cdbd2cSJim Jagielski    } elsif ($arg eq '--') {
35*b1cdbd2cSJim Jagielski        last;
36*b1cdbd2cSJim Jagielski    } else {
37*b1cdbd2cSJim Jagielski        my $n = substr($arg, 0, 1) eq '-' ? 1 : 0;
38*b1cdbd2cSJim Jagielski        while ($n && $n < length($arg)) {
39*b1cdbd2cSJim Jagielski            my $c = substr($arg, $n++, 1);
40*b1cdbd2cSJim Jagielski            if ($c eq 'k') {
41*b1cdbd2cSJim Jagielski                $keep_going = 1;
42*b1cdbd2cSJim Jagielski            } elsif ($c eq 'n') {
43*b1cdbd2cSJim Jagielski                $dry_run = 1;
44*b1cdbd2cSJim Jagielski            } else {
45*b1cdbd2cSJim Jagielski                $n = 0;
46*b1cdbd2cSJim Jagielski                last;
47*b1cdbd2cSJim Jagielski            }
48*b1cdbd2cSJim Jagielski        }
49*b1cdbd2cSJim Jagielski        if (!$n) {
50*b1cdbd2cSJim Jagielski            print STDERR "unknown argument \"$arg\"\n";
51*b1cdbd2cSJim Jagielski            print STDERR "usage: $0 [-kn] [-P<n>] [-- <args>]\n";
52*b1cdbd2cSJim Jagielski            print STDERR " -k     continue with other dmake invocations upon\n";
53*b1cdbd2cSJim Jagielski            print STDERR "        failure\n";
54*b1cdbd2cSJim Jagielski            print STDERR " -n     write directories that would be processed\n";
55*b1cdbd2cSJim Jagielski            print STDERR "        to standard output\n";
56*b1cdbd2cSJim Jagielski            print STDERR " -P<n>  number of parallel dmake invocations\n";
57*b1cdbd2cSJim Jagielski            print STDERR " <args> are passed to dmake invocations\n";
58*b1cdbd2cSJim Jagielski            exit(1);
59*b1cdbd2cSJim Jagielski        }
60*b1cdbd2cSJim Jagielski    }
61*b1cdbd2cSJim Jagielski}
62*b1cdbd2cSJim Jagielski
63*b1cdbd2cSJim Jagielskimy @testpaths = ();
64*b1cdbd2cSJim Jagielskimy $sc = SourceConfig->new($ENV{'SOLARSRC'});
65*b1cdbd2cSJim Jagielskimy $module;
66*b1cdbd2cSJim Jagielskimy $gbuildpath = "$ENV{'SOLARSRC'}/GNUmakefile";
67*b1cdbd2cSJim Jagielskiforeach $module ($sc->get_active_modules()) {
68*b1cdbd2cSJim Jagielski    my $buildlst = $sc->get_module_build_list($module);
69*b1cdbd2cSJim Jagielski    next unless defined($buildlst);
70*b1cdbd2cSJim Jagielski    my %deps = ();
71*b1cdbd2cSJim Jagielski    open(BUILDLST, $buildlst) or die("cannot open $buildlst");
72*b1cdbd2cSJim Jagielski    while (<BUILDLST>) {
73*b1cdbd2cSJim Jagielski        next unless
74*b1cdbd2cSJim Jagielski            /^\s*\w+\s+(\S+)\s+nmake\s+-\s+all\s+(\S+)(\s+(:?\S+\s+)*)NULL\s*$/;
75*b1cdbd2cSJim Jagielski        my ($dir, $id, $ids) = ($1, $2, $3);
76*b1cdbd2cSJim Jagielski        $dir =~ s|\\|/|g;
77*b1cdbd2cSJim Jagielski        $dir =~ s|^[^/]+||;
78*b1cdbd2cSJim Jagielski        my $path = $sc->get_module_path($module) . $dir;
79*b1cdbd2cSJim Jagielski        my $makefile = $path . '/makefile.mk';
80*b1cdbd2cSJim Jagielski        open(MAKEFILE, $makefile) or die("cannot open $makefile");
81*b1cdbd2cSJim Jagielski        while (<MAKEFILE>) {
82*b1cdbd2cSJim Jagielski            if (/\bOOO_SUBSEQUENT_TESTS\b/) {
83*b1cdbd2cSJim Jagielski                push(@testpaths, $path);
84*b1cdbd2cSJim Jagielski                $deps{$id} = $ids;
85*b1cdbd2cSJim Jagielski                last;
86*b1cdbd2cSJim Jagielski            }
87*b1cdbd2cSJim Jagielski        }
88*b1cdbd2cSJim Jagielski        close(MAKEFILE);
89*b1cdbd2cSJim Jagielski    }
90*b1cdbd2cSJim Jagielski    close(BUILDLST);
91*b1cdbd2cSJim Jagielski    my $id1;
92*b1cdbd2cSJim Jagielski    foreach $id1 (keys(%deps)) {
93*b1cdbd2cSJim Jagielski        my ($id2, $ids);
94*b1cdbd2cSJim Jagielski        while (($id2, $ids) = each(%deps)) {
95*b1cdbd2cSJim Jagielski            $ids !~ /\s\Q$id1\E\s/ or die("$module: $id2 depends on $id1");
96*b1cdbd2cSJim Jagielski        }
97*b1cdbd2cSJim Jagielski    }
98*b1cdbd2cSJim Jagielski}
99*b1cdbd2cSJim Jagielski
100*b1cdbd2cSJim Jagielskiif ($dry_run) {
101*b1cdbd2cSJim Jagielski    foreach $path (@testpaths) {
102*b1cdbd2cSJim Jagielski        print "$path\n";
103*b1cdbd2cSJim Jagielski    }
104*b1cdbd2cSJim Jagielski    print "$gbuildpath\n";
105*b1cdbd2cSJim Jagielski    exit(0);
106*b1cdbd2cSJim Jagielski}
107*b1cdbd2cSJim Jagielski
108*b1cdbd2cSJim Jagielskimy @failedpaths = ();
109*b1cdbd2cSJim Jagielskimy @gbuildargs = ("-j$max_running", "-s", "-r");
110*b1cdbd2cSJim Jagielskiif ($keep_going) {
111*b1cdbd2cSJim Jagielski    push(@gbuildargs,"-k");
112*b1cdbd2cSJim Jagielski}
113*b1cdbd2cSJim Jagielskipush(@gbuildargs, "--file=$gbuildpath");
114*b1cdbd2cSJim Jagielskipush(@gbuildargs, "subsequentcheck");
115*b1cdbd2cSJim Jagielskiif (system($ENV{'GNUMAKE'}, @gbuildargs) != 0) {
116*b1cdbd2cSJim Jagielski	push(@failedpaths,$gbuildpath);
117*b1cdbd2cSJim Jagielski	@testpaths = () unless $keep_going;
118*b1cdbd2cSJim Jagielski}
119*b1cdbd2cSJim Jagielski
120*b1cdbd2cSJim Jagielskimy $cmd = 'dmake';
121*b1cdbd2cSJim Jagielskiforeach (@ARGV) {
122*b1cdbd2cSJim Jagielski    s/'/'\''/g;
123*b1cdbd2cSJim Jagielski    $cmd .= " '" . $_ . "'";
124*b1cdbd2cSJim Jagielski}
125*b1cdbd2cSJim Jagielski$cmd .= ' 2>&1 |';
126*b1cdbd2cSJim Jagielski
127*b1cdbd2cSJim Jagielskimy %pids = ();
128*b1cdbd2cSJim Jagielskimy $running = 0;
129*b1cdbd2cSJim Jagielskimy $counter = 0;
130*b1cdbd2cSJim Jagielskiwhile (@testpaths || $running > 0) {
131*b1cdbd2cSJim Jagielski    while (@testpaths && $running < $max_running) {
132*b1cdbd2cSJim Jagielski        my $testpath = shift(@testpaths);
133*b1cdbd2cSJim Jagielski        ++$counter;
134*b1cdbd2cSJim Jagielski        print("$counter: make $testpath\n");
135*b1cdbd2cSJim Jagielski        my $pid = fork();
136*b1cdbd2cSJim Jagielski        defined($pid) or die("$counter: $!");
137*b1cdbd2cSJim Jagielski        if ($pid == 0) {
138*b1cdbd2cSJim Jagielski            chdir($testpath) or die("$counter: $!");
139*b1cdbd2cSJim Jagielski            $ENV{'OOO_SUBSEQUENT_TESTS'} = 'TRUE';
140*b1cdbd2cSJim Jagielski            open(OUTPUT, $cmd) or die("$counter: $!");
141*b1cdbd2cSJim Jagielski            while (<OUTPUT>) {
142*b1cdbd2cSJim Jagielski                s/\r?\n$//;
143*b1cdbd2cSJim Jagielski                print("$counter: $_\n");
144*b1cdbd2cSJim Jagielski            }
145*b1cdbd2cSJim Jagielski            close(OUTPUT);
146*b1cdbd2cSJim Jagielski            exit($? == 0 ? 0 : 1);
147*b1cdbd2cSJim Jagielski        }
148*b1cdbd2cSJim Jagielski        $pids{$pid} = $testpath;
149*b1cdbd2cSJim Jagielski        ++$running;
150*b1cdbd2cSJim Jagielski    }
151*b1cdbd2cSJim Jagielski    my $pid = wait();
152*b1cdbd2cSJim Jagielski    $pid != -1 or die($!);
153*b1cdbd2cSJim Jagielski    my $testpath = delete($pids{$pid});
154*b1cdbd2cSJim Jagielski    defined($testpath) or die("unmatched PID $pid");
155*b1cdbd2cSJim Jagielski    if ($? != 0) {
156*b1cdbd2cSJim Jagielski        push(@failedpaths, $testpath);
157*b1cdbd2cSJim Jagielski        @testpaths = () unless $keep_going;
158*b1cdbd2cSJim Jagielski    }
159*b1cdbd2cSJim Jagielski    --$running;
160*b1cdbd2cSJim Jagielski}
161*b1cdbd2cSJim Jagielskimy $failedpath;
162*b1cdbd2cSJim Jagielskiforeach $failedpath (@failedpaths) {
163*b1cdbd2cSJim Jagielski    print STDERR "failed in $failedpath\n";
164*b1cdbd2cSJim Jagielski}
165*b1cdbd2cSJim Jagielskiexit(scalar(@failedpaths) == 0 ? 0 : 1);
166