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