5 if ($ENV{'PERL_CORE'}){
7 unshift @INC, '../lib';
10 # Import test.pl into its own package
13 require($ENV{PERL_CORE} ? './test.pl' : './t/test.pl');
17 if (! $Config{'useithreads'}) {
18 Test::skip_all(q/Perl not compiled with 'useithreads'/);
22 use ExtUtils::testlib;
25 my ($id, $ok, $name) = @_;
27 # You have to do it this way or VMS will get confused.
29 print("ok $id - $name\n");
31 print("not ok $id - $name\n");
32 printf("# Failed test at line %d\n", (caller)[2]);
40 print("1..91\n"); ### Number of tests that will be run ###
46 Test::watchdog(300); # In case we get stuck
49 ok($TEST++, 1, 'Loaded');
51 ### Start of Testing ###
53 # cond_wait and cond_timedwait extended tests adapted from cond.t
55 # The two skips later on in these tests refer to this quote from the
56 # pod/perl583delta.pod:
58 # =head1 Platform Specific Problems
60 # The regression test ext/threads/shared/t/wait.t fails on early RedHat 9
61 # and HP-UX 10.20 due to bugs in their threading implementations.
62 # RedHat users should see https://rhn.redhat.com/errata/RHBA-2003-136.html
63 # and consider upgrading their glibc.
68 ok($TEST++, defined &cond_wait, "cond_wait() present");
69 ok($TEST++, (prototype(\&cond_wait) eq '\[$@%];\[$@%]'),
70 q/cond_wait() prototype '\[$@%];\[$@%]'/);
71 ok($TEST++, defined &cond_timedwait, "cond_timedwait() present");
72 ok($TEST++, (prototype(\&cond_timedwait) eq '\[$@%]$;\[$@%]'),
73 q/cond_timedwait() prototype '\[$@%]$;\[$@%]'/);
77 "simple", # cond var == lock var; implicit lock; e.g.: cond_wait($c)
78 "repeat", # cond var == lock var; explicit lock; e.g.: cond_wait($c, $c)
79 "twain" # cond var != lock var; explicit lock; e.g.: cond_wait($c, $l)
84 my $test_type :shared; # simple|repeat|twain
89 ok($TEST++, 1, "Shared synchronization tests preparation");
95 ok($testno++, 1, "$test_type: child before lock");
96 $test_type =~ /twain/ ? lock($lock) : lock($cond);
97 ok($testno++, 1, "$test_type: child obtained lock");
99 if ($test_type =~ 'twain') {
100 no warnings 'threads'; # lock var != cond var, so disable warnings
105 ok($testno++, 1, "$test_type: child signalled condition");
114 my ($testnum, $to) = @_;
116 # Which lock to obtain?
117 $test_type =~ /twain/ ? lock($lock) : lock($cond);
118 ok($testnum++, 1, "$test_type: obtained initial lock");
120 my $thr = threads->create(\&signaller, $testnum);
122 cond_wait($cond), last if /simple/;
123 cond_wait($cond, $cond), last if /repeat/;
124 cond_wait($cond, $lock), last if /twain/;
125 die "$test_type: unknown test\n";
127 $testnum = $thr->join();
128 ok($testnum++, 1, "$test_type: condition obtained");
133 foreach (@wait_how) {
134 $test_type = "cond_wait [$_]";
135 my $thr = threads->create(\&cw, $TEST);
136 $TEST = $thr->join();
139 # - TEST cond_timedwait success
143 my ($testnum, $to) = @_;
145 # Which lock to obtain?
146 $test_type =~ /twain/ ? lock($lock) : lock($cond);
147 ok($testnum++, 1, "$test_type: obtained initial lock");
149 my $thr = threads->create(\&signaller, $testnum);
152 $ok = cond_timedwait($cond, time() + $to), last if /simple/;
153 $ok = cond_timedwait($cond, time() + $to, $cond), last if /repeat/;
154 $ok = cond_timedwait($cond, time() + $to, $lock), last if /twain/;
155 die "$test_type: unknown test\n";
157 $testnum = $thr->join();
158 ok($testnum++, $ok, "$test_type: condition obtained");
163 foreach (@wait_how) {
164 $test_type = "cond_timedwait [$_]";
165 my $thr = threads->create(\&ctw_ok, $TEST, 5);
166 $TEST = $thr->join();
169 # - TEST cond_timedwait timeout
173 my ($testnum, $to) = @_;
175 if ($^O eq "hpux" && $Config{osvers} <= 10.20) {
176 # The lock obtaining would pass, but the wait will not.
177 ok($testnum++, 1, "$test_type: obtained initial lock");
178 ok($testnum++, 0, "# SKIP see perl583delta");
181 $test_type =~ /twain/ ? lock($lock) : lock($cond);
182 ok($testnum++, 1, "$test_type: obtained initial lock");
185 $ok = cond_timedwait($cond, time() + $to), last if /simple/;
186 $ok = cond_timedwait($cond, time() + $to, $cond), last if /repeat/;
187 $ok = cond_timedwait($cond, time() + $to, $lock), last if /twain/;
188 die "$test_type: unknown test\n";
190 ok($testnum++, ! defined($ok), "$test_type: timeout");
196 foreach (@wait_how) {
197 $test_type = "cond_timedwait pause, timeout [$_]";
198 my $thr = threads->create(\&ctw_fail, $TEST, 3);
199 $TEST = $thr->join();
202 foreach (@wait_how) {
203 $test_type = "cond_timedwait instant timeout [$_]";
204 my $thr = threads->create(\&ctw_fail, $TEST, -60);
205 $TEST = $thr->join();
208 } # -- SYNCH_SHARED block
211 # same as above, but with references to lock and cond vars
214 my $test_type :shared; # simple|repeat|twain
216 my $true_cond :shared;
217 my $true_lock :shared;
219 my $cond = \$true_cond;
220 my $lock = \$true_lock;
222 ok($TEST++, 1, "Synchronization reference tests preparation");
228 ok($testno++, 1, "$test_type: child before lock");
229 $test_type =~ /twain/ ? lock($lock) : lock($cond);
230 ok($testno++, 1, "$test_type: child obtained lock");
232 if ($test_type =~ 'twain') {
233 no warnings 'threads'; # lock var != cond var, so disable warnings
238 ok($testno++, 1, "$test_type: child signalled condition");
247 my ($testnum, $to) = @_;
249 # Which lock to obtain?
250 $test_type =~ /twain/ ? lock($lock) : lock($cond);
251 ok($testnum++, 1, "$test_type: obtained initial lock");
253 my $thr = threads->create(\&signaller2, $testnum);
255 cond_wait($cond), last if /simple/;
256 cond_wait($cond, $cond), last if /repeat/;
257 cond_wait($cond, $lock), last if /twain/;
258 die "$test_type: unknown test\n";
260 $testnum = $thr->join();
261 ok($testnum++, 1, "$test_type: condition obtained");
266 foreach (@wait_how) {
267 $test_type = "cond_wait [$_]";
268 my $thr = threads->create(\&cw2, $TEST);
269 $TEST = $thr->join();
272 # - TEST cond_timedwait success
276 my ($testnum, $to) = @_;
278 # Which lock to obtain?
279 $test_type =~ /twain/ ? lock($lock) : lock($cond);
280 ok($testnum++, 1, "$test_type: obtained initial lock");
282 my $thr = threads->create(\&signaller2, $testnum);
285 $ok = cond_timedwait($cond, time() + $to), last if /simple/;
286 $ok = cond_timedwait($cond, time() + $to, $cond), last if /repeat/;
287 $ok = cond_timedwait($cond, time() + $to, $lock), last if /twain/;
288 die "$test_type: unknown test\n";
290 $testnum = $thr->join();
291 ok($testnum++, $ok, "$test_type: condition obtained");
296 foreach (@wait_how) {
297 $test_type = "cond_timedwait [$_]";
298 my $thr = threads->create(\&ctw_ok2, $TEST, 5);
299 $TEST = $thr->join();
302 # - TEST cond_timedwait timeout
306 my ($testnum, $to) = @_;
308 if ($^O eq "hpux" && $Config{osvers} <= 10.20) {
309 # The lock obtaining would pass, but the wait will not.
310 ok($testnum++, 1, "$test_type: obtained initial lock");
311 ok($testnum++, 0, "# SKIP see perl583delta");
314 $test_type =~ /twain/ ? lock($lock) : lock($cond);
315 ok($testnum++, 1, "$test_type: obtained initial lock");
318 $ok = cond_timedwait($cond, time() + $to), last if /simple/;
319 $ok = cond_timedwait($cond, time() + $to, $cond), last if /repeat/;
320 $ok = cond_timedwait($cond, time() + $to, $lock), last if /twain/;
321 die "$test_type: unknown test\n";
323 ok($testnum++, ! defined($ok), "$test_type: timeout");
329 foreach (@wait_how) {
330 $test_type = "cond_timedwait pause, timeout [$_]";
331 my $thr = threads->create(\&ctw_fail2, $TEST, 3);
332 $TEST = $thr->join();
335 foreach (@wait_how) {
336 $test_type = "cond_timedwait instant timeout [$_]";
337 my $thr = threads->create(\&ctw_fail2, $TEST, -60);
338 $TEST = $thr->join();
341 } # -- SYNCH_REFS block