1 # Copyright (C) 2001, 2002, 2003, 2008, 2009 Free Software Foundation,
4 # This file is part of GNU Automake.
6 # GNU Automake is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
11 # GNU Automake is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 if (eval { require 5.007_002; } # for CLONE support
22 && $Config{useithreads}
23 && !$ENV{WANT_NO_THREADS})
33 use Automake::Condition qw/TRUE FALSE/;
34 use Automake::DisjConditions;
38 my $true = new Automake::DisjConditions TRUE;
39 my $false = new Automake::DisjConditions FALSE;
40 my $cond = new Automake::Condition "COND1_TRUE", "COND2_FALSE";
41 return threads->new (sub {
42 my $other = new Automake::Condition "COND3_FALSE";
43 my $another = new Automake::Condition "COND3_TRUE", "COND4_FALSE";
44 return threads->new (sub {
45 my $set1 = new Automake::DisjConditions $cond, $other;
46 return threads->new (sub {
47 my $set2 = new Automake::DisjConditions $other, $cond;
48 my $set3 = new Automake::DisjConditions FALSE, $another;
49 return 1 unless $set1 == $set2;
50 return 1 if $set1->false;
51 return 1 if $set1->true;
52 return 1 unless (new Automake::DisjConditions)->false;
53 return 1 if (new Automake::DisjConditions)->true;
54 return 1 unless $true->human eq 'TRUE';
55 return 1 unless $false->human eq 'FALSE';
56 return 1 unless $set1->human eq "(COND1 and !COND2) or (!COND3)";
57 return 1 unless $set2->human eq "(COND1 and !COND2) or (!COND3)";
58 my $one_cond_human = $set1->one_cond->human;
59 return 1 unless $one_cond_human eq "!COND3"
60 || $one_cond_human eq "COND1 and !COND2";
61 return 1 unless $set1->string eq "COND1_TRUE COND2_FALSE | COND3_FALSE";
63 my $merged1 = $set1->merge ($set2);
64 my $merged2 = $set1->merge ($cond);
65 my $mult1 = $set1->multiply ($set3);
66 return threads->new (sub {
67 my $mult2 = $set1->multiply ($another);
68 return threads->new (sub {
69 return 1 unless $merged1->simplify->string eq "COND1_TRUE COND2_FALSE | COND3_FALSE";
70 return 1 unless $merged2->simplify->string eq "COND1_TRUE COND2_FALSE | COND3_FALSE";
71 return 1 unless $mult1->string eq "COND1_TRUE COND2_FALSE COND3_TRUE COND4_FALSE";
72 return 1 unless $mult1 == $mult2;
87 push @set, new Automake::Condition @$cond;
89 return new Automake::DisjConditions @set;
94 my @tests = ([[["FALSE"]],
100 [[["COND1_TRUE", "COND2_TRUE"],
101 ["COND3_FALSE", "COND2_TRUE"]],
103 ["COND1_FALSE", "COND3_TRUE"]]],
105 [[["COND1_TRUE", "COND2_TRUE"],
109 [[["COND1_TRUE", "COND2_TRUE"],
116 [["COND1_FALSE", "COND2_TRUE"]]]
121 my $set = build_set @{$t->[0]};
123 if threads->new(sub {
124 my $res = build_set @{$t->[1]};
125 my $inv = $set->invert;
128 print " (I) " . $set->string . "\n\t"
129 . $inv->string . ' != ' . $res->string . "\n";
140 my @tests = ([[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
141 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"]],
142 [["FOO_TRUE", "BAR_FALSE"]]],
144 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
145 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
146 ["FOO_TRUE", "BAR_TRUE"]],
149 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
150 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
151 ["FOO_TRUE", "BAR_TRUE"],
155 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
156 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
157 ["BAR_TRUE", "BAZ_TRUE"],
158 ["BAR_FALSE", "BAZ_TRUE"]],
159 [["BAZ_TRUE"], ["FOO_TRUE", "BAR_FALSE"]]],
161 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
162 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
163 ["BAR_TRUE", "BAZ_TRUE"],
164 ["BAR_FALSE", "BAZ_TRUE"],
166 [["FOO_FALSE"], ["BAZ_TRUE"], ["BAR_FALSE"]]],
169 ["A_FALSE", "B_TRUE"]],
173 ["A_FALSE", "B_FALSE", "C_TRUE"],
174 ["A_FALSE", "B_FALSE", "C_FALSE"]],
175 [["A_FALSE"], ["B_TRUE"]]],
178 ["A_FALSE", "B_FALSE", "C_TRUE"],
179 ["A_FALSE", "B_FALSE", "C_FALSE"],
180 ["A_TRUE", "B_FALSE"]],
183 [[["A_TRUE", "B_TRUE"],
184 ["A_TRUE", "B_FALSE"],
185 ["A_TRUE", "C_FALSE", "D_FALSE"]],
188 [[["A_FALSE", "B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"],
189 ["A_FALSE", "B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
190 ["A_FALSE", "B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
191 ["A_FALSE", "B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"],
192 ["A_TRUE", "B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"],
193 ["A_TRUE", "B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
194 ["A_TRUE", "B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
195 ["A_TRUE", "B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"]],
196 [ ["B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"],
197 ["B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
198 ["B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
199 ["B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"]]],
201 [[["A_FALSE", "B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"],
202 ["A_FALSE", "B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
203 ["A_FALSE", "B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
204 ["A_FALSE", "B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"],
205 ["A_TRUE", "B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"],
206 ["A_TRUE", "B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
207 ["A_TRUE", "B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
208 ["A_TRUE", "B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"],
209 ["A_FALSE", "B_FALSE", "C_FALSE", "D_FALSE", "E_FALSE"],
210 ["A_FALSE", "B_FALSE", "C_TRUE", "D_FALSE", "E_TRUE"],
211 ["A_FALSE", "B_TRUE", "C_TRUE", "D_TRUE", "E_TRUE"],
212 ["A_FALSE", "B_TRUE", "C_FALSE", "D_TRUE", "E_FALSE"],
213 ["A_TRUE", "B_TRUE", "C_FALSE", "D_TRUE", "E_FALSE"],
214 ["A_TRUE", "B_TRUE", "C_TRUE", "D_TRUE", "E_TRUE"],
215 ["A_TRUE", "B_FALSE", "C_TRUE", "D_FALSE", "E_TRUE"],
216 ["A_TRUE", "B_FALSE", "C_FALSE", "D_FALSE", "E_FALSE"]],
217 [["C_FALSE", "E_FALSE"],
218 ["C_TRUE", "E_TRUE"]]],
221 ["A_TRUE", "B_FALSE"],
222 ["A_TRUE", "B_TRUE", "C_FALSE"],
223 ["A_TRUE", "B_TRUE", "C_TRUE", "D_FALSE"],
224 ["A_TRUE", "B_TRUE", "C_TRUE", "D_TRUE", "E_FALSE"],
225 ["A_TRUE", "B_TRUE", "C_TRUE", "D_TRUE", "E_TRUE", "F_FALSE"],
226 ["A_TRUE", "B_TRUE", "C_TRUE", "D_TRUE", "E_TRUE"]],
229 # Simplify should work with up to 31 variables.
230 [[["V01_TRUE", "V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
231 "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
232 "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
233 "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
234 "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
235 "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE",
237 ["V01_TRUE", "V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
238 "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
239 "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
240 "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
241 "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
242 "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE",
244 ["V01_FALSE","V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
245 "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
246 "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
247 "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
248 "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
249 "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE",
251 ["V01_FALSE","V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
252 "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
253 "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
254 "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
255 "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
256 "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE",
258 [[ "V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
259 "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
260 "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
261 "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
262 "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
263 "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE"
268 my $set = build_set @{$t->[0]};
270 if threads->new(sub {
271 my $res = build_set @{$t->[1]};
272 return threads->new(sub {
274 # Make sure simplify() yields the expected result.
275 my $sim = $set->simplify;
276 return threads->new(sub {
279 print " (S1) " . $set->string . "\n\t"
280 . $sim->string . ' != ' . $res->string . "\n";
284 # Make sure simplify() is idempotent.
285 my $sim2 = $sim->simplify;
286 return threads->new(sub {
289 print " (S2) " . $sim->string . "\n\t"
290 . $sim2->string . ' != ' . $sim->string . "\n";
294 # Also exercise invert() while we are at it.
296 my $inv1 = $set->invert->simplify;
297 return threads->new(sub {
298 my $inv2 = $sim->invert->simplify;
299 return threads->new(sub {
302 print " (S3) " . $set->string . ", " . $sim->string . "\n\t"
303 . $inv1->string . ' -= ' . $inv2->string . "\n";
317 sub test_sub_conditions ()
319 my @tests = ([[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
320 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
323 [["BAR_FALSE", "BAZ_FALSE"],
324 ["BAR_FALSE", "BAZ_TRUE"]]],
326 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
327 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
329 ["FOO_TRUE", "BAR_FALSE"],
333 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
334 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
336 ["FOO_TRUE", "BAR_TRUE"],
339 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
340 ["FOO_TRUE", "BAZ_TRUE"],
342 ["FOO_TRUE", "BAR_TRUE"],
345 [[["FOO_TRUE", "BAR_FALSE"],
346 ["FOO_TRUE", "BAR_TRUE"]],
347 ["FOO_TRUE", "BAR_TRUE"],
364 my $t1 = build_set @{$t->[0]};
366 if threads->new(sub {
367 my $t2 = new Automake::Condition @{$t->[1]};
368 return threads->new(sub {
369 my $t3 = build_set @{$t->[2]};
370 return threads->new(sub {
372 # Make sure sub_conditions() yields the expected result.
373 my $s = $t1->sub_conditions ($t2);
377 print " (SC) " . $t1->string . "\n\t"
378 . $s->string . ' != ' . $t3->string . "\n";
390 my @tests = ([[["TRUE"]],
400 ["C1_TRUE", "C2_TRUE"],
402 [[["C1_TRUE", "C2_TRUE"]],
404 "which is included in"],
410 ["C1_FALSE", "C2_TRUE"],
416 my $t1 = build_set @{$t->[0]};
418 if threads->new(sub {
419 my $t2 = new Automake::Condition @{$t->[1]};
421 return threads->new(sub {
422 my ($ans, $cond) = $t1->ambiguous_p ("FOO", $t2);
423 return threads->new(sub {
424 if ($t3 && $ans !~ /FOO.*$t3/)
426 print " (A1) " . $t1->string . " vs. " . $t2->string . "\n\t"
427 . "Error message '$ans' does not match '$t3'\n";
430 if (!$t3 && $ans ne '')
432 print " (A2) " . $t1->string . " vs. " . $t2->string . "\n\t"
433 . "Unexpected error message: $ans\n";
446 || test_sub_conditions
449 ### Setup "GNU" style for perl-mode and cperl-mode.
451 ## perl-indent-level: 2
452 ## perl-continued-statement-offset: 2
453 ## perl-continued-brace-offset: 0
454 ## perl-brace-offset: 0
455 ## perl-brace-imaginary-offset: 0
456 ## perl-label-offset: -2
457 ## cperl-indent-level: 2
458 ## cperl-brace-offset: 0
459 ## cperl-continued-brace-offset: 0
460 ## cperl-label-offset: -2
461 ## cperl-extra-newline-before-brace: t
462 ## cperl-merge-trailing-else: nil
463 ## cperl-continued-statement-offset: 2