1 # Copyright (C) 2001-2017 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2, or (at your option)
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <https://www.gnu.org/licenses/>.
18 if (eval { require 5.007_002
; } # for CLONE support
19 && $Config{useithreads
}
20 && !$ENV{WANT_NO_THREADS
})
30 use Automake
::Condition qw
/TRUE FALSE/;
31 use Automake
::DisjConditions
;
35 my $true = new Automake
::DisjConditions TRUE
;
36 my $false = new Automake
::DisjConditions FALSE
;
37 my $cond = new Automake
::Condition
"COND1_TRUE", "COND2_FALSE";
38 return threads
->new (sub {
39 my $other = new Automake
::Condition
"COND3_FALSE";
40 my $another = new Automake
::Condition
"COND3_TRUE", "COND4_FALSE";
41 return threads
->new (sub {
42 my $set1 = new Automake
::DisjConditions
$cond, $other;
43 return threads
->new (sub {
44 my $set2 = new Automake
::DisjConditions
$other, $cond;
45 my $set3 = new Automake
::DisjConditions FALSE
, $another;
46 return 1 unless $set1 == $set2;
47 return 1 if $set1->false;
48 return 1 if $set1->true;
49 return 1 unless (new Automake
::DisjConditions
)->false;
50 return 1 if (new Automake
::DisjConditions
)->true;
51 return 1 unless $true->human eq 'TRUE';
52 return 1 unless $false->human eq 'FALSE';
53 return 1 unless $set1->human eq "(COND1 and !COND2) or (!COND3)";
54 return 1 unless $set2->human eq "(COND1 and !COND2) or (!COND3)";
55 my $one_cond_human = $set1->one_cond->human;
56 return 1 unless $one_cond_human eq "!COND3"
57 || $one_cond_human eq "COND1 and !COND2";
58 return 1 unless $set1->string eq "COND1_TRUE COND2_FALSE | COND3_FALSE";
60 my $merged1 = $set1->merge ($set2);
61 my $merged2 = $set1->merge ($cond);
62 my $mult1 = $set1->multiply ($set3);
63 return threads
->new (sub {
64 my $mult2 = $set1->multiply ($another);
65 return threads
->new (sub {
66 return 1 unless $merged1->simplify->string eq "COND1_TRUE COND2_FALSE | COND3_FALSE";
67 return 1 unless $merged2->simplify->string eq "COND1_TRUE COND2_FALSE | COND3_FALSE";
68 return 1 unless $mult1->string eq "COND1_TRUE COND2_FALSE COND3_TRUE COND4_FALSE";
69 return 1 unless $mult1 == $mult2;
84 push @set, new Automake
::Condition @
$cond;
86 return new Automake
::DisjConditions
@set;
91 my @tests = ([[["FALSE"]],
97 [[["COND1_TRUE", "COND2_TRUE"],
98 ["COND3_FALSE", "COND2_TRUE"]],
100 ["COND1_FALSE", "COND3_TRUE"]]],
102 [[["COND1_TRUE", "COND2_TRUE"],
106 [[["COND1_TRUE", "COND2_TRUE"],
113 [["COND1_FALSE", "COND2_TRUE"]]]
118 my $set = build_set @
{$t->[0]};
120 if threads
->new(sub {
121 my $res = build_set @
{$t->[1]};
122 my $inv = $set->invert;
125 print " (I) " . $set->string . "\n\t"
126 . $inv->string . ' != ' . $res->string . "\n";
137 my @tests = ([[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
138 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"]],
139 [["FOO_TRUE", "BAR_FALSE"]]],
141 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
142 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
143 ["FOO_TRUE", "BAR_TRUE"]],
146 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
147 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
148 ["FOO_TRUE", "BAR_TRUE"],
152 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
153 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
154 ["BAR_TRUE", "BAZ_TRUE"],
155 ["BAR_FALSE", "BAZ_TRUE"]],
156 [["BAZ_TRUE"], ["FOO_TRUE", "BAR_FALSE"]]],
158 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
159 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
160 ["BAR_TRUE", "BAZ_TRUE"],
161 ["BAR_FALSE", "BAZ_TRUE"],
163 [["FOO_FALSE"], ["BAZ_TRUE"], ["BAR_FALSE"]]],
166 ["A_FALSE", "B_TRUE"]],
170 ["A_FALSE", "B_FALSE", "C_TRUE"],
171 ["A_FALSE", "B_FALSE", "C_FALSE"]],
172 [["A_FALSE"], ["B_TRUE"]]],
175 ["A_FALSE", "B_FALSE", "C_TRUE"],
176 ["A_FALSE", "B_FALSE", "C_FALSE"],
177 ["A_TRUE", "B_FALSE"]],
180 [[["A_TRUE", "B_TRUE"],
181 ["A_TRUE", "B_FALSE"],
182 ["A_TRUE", "C_FALSE", "D_FALSE"]],
185 [[["A_FALSE", "B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"],
186 ["A_FALSE", "B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
187 ["A_FALSE", "B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
188 ["A_FALSE", "B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"],
189 ["A_TRUE", "B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"],
190 ["A_TRUE", "B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
191 ["A_TRUE", "B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
192 ["A_TRUE", "B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"]],
193 [ ["B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"],
194 ["B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
195 ["B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
196 ["B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"]]],
198 [[["A_FALSE", "B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"],
199 ["A_FALSE", "B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
200 ["A_FALSE", "B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
201 ["A_FALSE", "B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"],
202 ["A_TRUE", "B_TRUE", "C_FALSE", "D_FALSE", "E_FALSE"],
203 ["A_TRUE", "B_TRUE", "C_TRUE", "D_FALSE", "E_TRUE"],
204 ["A_TRUE", "B_FALSE", "C_TRUE", "D_TRUE", "E_TRUE"],
205 ["A_TRUE", "B_FALSE", "C_FALSE", "D_TRUE", "E_FALSE"],
206 ["A_FALSE", "B_FALSE", "C_FALSE", "D_FALSE", "E_FALSE"],
207 ["A_FALSE", "B_FALSE", "C_TRUE", "D_FALSE", "E_TRUE"],
208 ["A_FALSE", "B_TRUE", "C_TRUE", "D_TRUE", "E_TRUE"],
209 ["A_FALSE", "B_TRUE", "C_FALSE", "D_TRUE", "E_FALSE"],
210 ["A_TRUE", "B_TRUE", "C_FALSE", "D_TRUE", "E_FALSE"],
211 ["A_TRUE", "B_TRUE", "C_TRUE", "D_TRUE", "E_TRUE"],
212 ["A_TRUE", "B_FALSE", "C_TRUE", "D_FALSE", "E_TRUE"],
213 ["A_TRUE", "B_FALSE", "C_FALSE", "D_FALSE", "E_FALSE"]],
214 [["C_FALSE", "E_FALSE"],
215 ["C_TRUE", "E_TRUE"]]],
218 ["A_TRUE", "B_FALSE"],
219 ["A_TRUE", "B_TRUE", "C_FALSE"],
220 ["A_TRUE", "B_TRUE", "C_TRUE", "D_FALSE"],
221 ["A_TRUE", "B_TRUE", "C_TRUE", "D_TRUE", "E_FALSE"],
222 ["A_TRUE", "B_TRUE", "C_TRUE", "D_TRUE", "E_TRUE", "F_FALSE"],
223 ["A_TRUE", "B_TRUE", "C_TRUE", "D_TRUE", "E_TRUE"]],
226 # Simplify should work with up to 31 variables.
227 [[["V01_TRUE", "V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
228 "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
229 "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
230 "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
231 "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
232 "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE",
234 ["V01_TRUE", "V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
235 "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
236 "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
237 "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
238 "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
239 "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE",
241 ["V01_FALSE","V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
242 "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
243 "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
244 "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
245 "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
246 "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE",
248 ["V01_FALSE","V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
249 "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
250 "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
251 "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
252 "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
253 "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE",
255 [[ "V02_TRUE", "V03_TRUE", "V04_TRUE", "V05_TRUE",
256 "V06_TRUE", "V07_TRUE", "V08_TRUE", "V09_TRUE", "V10_TRUE",
257 "V11_TRUE", "V12_TRUE", "V13_TRUE", "V14_TRUE", "V15_TRUE",
258 "V16_TRUE", "V17_TRUE", "V18_TRUE", "V19_TRUE", "V20_TRUE",
259 "V21_TRUE", "V22_TRUE", "V23_TRUE", "V24_TRUE", "V25_TRUE",
260 "V26_TRUE", "V27_TRUE", "V28_TRUE", "V29_TRUE", "V30_TRUE"
265 my $set = build_set @
{$t->[0]};
267 if threads
->new(sub {
268 my $res = build_set @
{$t->[1]};
269 return threads
->new(sub {
271 # Make sure simplify() yields the expected result.
272 my $sim = $set->simplify;
273 return threads
->new(sub {
276 print " (S1) " . $set->string . "\n\t"
277 . $sim->string . ' != ' . $res->string . "\n";
281 # Make sure simplify() is idempotent.
282 my $sim2 = $sim->simplify;
283 return threads
->new(sub {
286 print " (S2) " . $sim->string . "\n\t"
287 . $sim2->string . ' != ' . $sim->string . "\n";
291 # Also exercise invert() while we are at it.
293 my $inv1 = $set->invert->simplify;
294 return threads
->new(sub {
295 my $inv2 = $sim->invert->simplify;
296 return threads
->new(sub {
299 print " (S3) " . $set->string . ", " . $sim->string . "\n\t"
300 . $inv1->string . ' -= ' . $inv2->string . "\n";
314 sub test_sub_conditions
()
316 my @tests = ([[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
317 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
320 [["BAR_FALSE", "BAZ_FALSE"],
321 ["BAR_FALSE", "BAZ_TRUE"]]],
323 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
324 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
326 ["FOO_TRUE", "BAR_FALSE"],
330 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
331 ["FOO_TRUE", "BAR_FALSE", "BAZ_TRUE"],
333 ["FOO_TRUE", "BAR_TRUE"],
336 [[["FOO_TRUE", "BAR_FALSE", "BAZ_FALSE"],
337 ["FOO_TRUE", "BAZ_TRUE"],
339 ["FOO_TRUE", "BAR_TRUE"],
342 [[["FOO_TRUE", "BAR_FALSE"],
343 ["FOO_TRUE", "BAR_TRUE"]],
344 ["FOO_TRUE", "BAR_TRUE"],
361 my $t1 = build_set @
{$t->[0]};
363 if threads
->new(sub {
364 my $t2 = new Automake
::Condition @
{$t->[1]};
365 return threads
->new(sub {
366 my $t3 = build_set @
{$t->[2]};
367 return threads
->new(sub {
369 # Make sure sub_conditions() yields the expected result.
370 my $s = $t1->sub_conditions ($t2);
374 print " (SC) " . $t1->string . "\n\t"
375 . $s->string . ' != ' . $t3->string . "\n";
387 my @tests = ([[["TRUE"]],
397 ["C1_TRUE", "C2_TRUE"],
399 [[["C1_TRUE", "C2_TRUE"]],
401 "which is included in"],
407 ["C1_FALSE", "C2_TRUE"],
413 my $t1 = build_set @
{$t->[0]};
415 if threads
->new(sub {
416 my $t2 = new Automake
::Condition @
{$t->[1]};
418 return threads
->new(sub {
419 my ($ans, $cond) = $t1->ambiguous_p ("FOO", $t2);
420 return threads
->new(sub {
421 if ($t3 && $ans !~ /FOO.*$t3/)
423 print " (A1) " . $t1->string . " vs. " . $t2->string . "\n\t"
424 . "Error message '$ans' does not match '$t3'\n";
427 if (!$t3 && $ans ne '')
429 print " (A2) " . $t1->string . " vs. " . $t2->string . "\n\t"
430 . "Unexpected error message: $ans\n";
443 || test_sub_conditions
446 ### Setup "GNU" style for perl-mode and cperl-mode.
448 ## perl-indent-level: 2
449 ## perl-continued-statement-offset: 2
450 ## perl-continued-brace-offset: 0
451 ## perl-brace-offset: 0
452 ## perl-brace-imaginary-offset: 0
453 ## perl-label-offset: -2
454 ## cperl-indent-level: 2
455 ## cperl-brace-offset: 0
456 ## cperl-continued-brace-offset: 0
457 ## cperl-label-offset: -2
458 ## cperl-extra-newline-before-brace: t
459 ## cperl-merge-trailing-else: nil
460 ## cperl-continued-statement-offset: 2