@@ -33,7 +33,7 @@ sub ok {
3333
3434BEGIN {
3535 $| = 1;
36- print (" 1..103 \n " ); # ## Number of tests that will be run ###
36+ print (" 1..91 \n " ); # ## Number of tests that will be run ###
3737};
3838
3939use threads;
@@ -55,6 +55,7 @@ $Base++;
5555# RedHat users should see https://rhn.redhat.com/errata/RHBA-2003-136.html
5656# and consider upgrading their glibc.
5757
58+
5859sub forko (&$$ ); # To prevent deadlock from underlying pthread_* bugs (as in
5960 # stock RH9 glibc/NPTL) or from our own errors, we run tests
6061 # in separately forked and alarmed processes.
@@ -68,14 +69,11 @@ sub forko (&$$); # To prevent deadlock from underlying pthread_* bugs (as in
6869
6970 my $bump = $expected ;
7071
71- $patience ||= 60;
72-
7372 unless (defined ($pid = open (CHLD, " -|" ))) {
7473 die " fork: $! \n " ;
7574 }
7675 if (! $pid ) { # Child -- run the test
77- $patience ||= 60;
78- alarm $patience ;
76+ alarm($patience || 60);
7977 &$code ;
8078 exit ;
8179 }
@@ -89,14 +87,13 @@ sub forko (&$$); # To prevent deadlock from underlying pthread_* bugs (as in
8987 close (CHLD);
9088
9189 while ($expected --) {
92- $test_num ++;
93- print " not ok $test_num - child status $? \n " ;
90+ ok(++$test_num , 0, " missing test result: child status $? " );
9491 }
9592
9693 $Base += $bump ;
97-
9894};
9995
96+
10097# - TEST basics
10198
10299ok(1, defined &cond_wait, " cond_wait() present" );
@@ -140,29 +137,24 @@ SYNC_SHARED: {
140137 foreach (@wait_how ) {
141138 $test = " cond_wait [$_ ]" ;
142139 threads-> create(\&cw)-> join ;
143- $Base += 6 ;
140+ $Base += 5 ;
144141 }
145- }, 6 *@wait_how , 90);
142+ }, 5 *@wait_how , 90);
146143
147144 sub cw {
148- my $thr ;
149-
150- { # -- begin lock scope; which lock to obtain?
145+ # which lock to obtain?
151146 $test =~ / twain/ ? lock($lock ) : lock($cond );
152147 ok(1,1, " $test : obtained initial lock" );
153148
154- $thr = threads-> create(\&signaller);
149+ my $thr = threads-> create(\&signaller);
155150 for ($test ) {
156151 cond_wait($cond ), last if / simple/ ;
157152 cond_wait($cond , $cond ), last if / repeat/ ;
158153 cond_wait($cond , $lock ), last if / twain/ ;
159- die " $test : unknown test\n " ;
154+ die " $test : unknown test\n " ;
160155 }
156+ $thr -> join ;
161157 ok(5,1, " $test : condition obtained" );
162- } # -- end lock scope
163-
164- $thr -> join ;
165- ok(6,1, " $test : join completed" );
166158 }
167159
168160 # - TEST cond_timedwait success
@@ -171,31 +163,27 @@ SYNC_SHARED: {
171163 foreach (@wait_how ) {
172164 $test = " cond_timedwait [$_ ]" ;
173165 threads-> create(\&ctw, 5)-> join ;
174- $Base += 6 ;
166+ $Base += 5 ;
175167 }
176- }, 6 *@wait_how , 90);
168+ }, 5 *@wait_how , 90);
177169
178170 sub ctw ($) {
179- my $to = shift ;
180- my $thr ;
171+ my $to = shift ;
181172
182- { # -- begin lock scope; which lock to obtain?
173+ # which lock to obtain?
183174 $test =~ / twain/ ? lock($lock ) : lock($cond );
184175 ok(1,1, " $test : obtained initial lock" );
185176
186- $thr = threads-> create(\&signaller);
177+ my $thr = threads-> create(\&signaller);
187178 my $ok = 0;
188179 for ($test ) {
189180 $ok =cond_timedwait($cond , time () + $to ), last if / simple/ ;
190181 $ok =cond_timedwait($cond , time () + $to , $cond ), last if / repeat/ ;
191182 $ok =cond_timedwait($cond , time () + $to , $lock ), last if / twain/ ;
192- die " $test : unknown test\n " ;
183+ die " $test : unknown test\n " ;
193184 }
185+ $thr -> join ;
194186 ok(5,$ok , " $test : condition obtained" );
195- } # -- end lock scope
196-
197- $thr -> join ;
198- ok(6,1, " $test : join completed" );
199187 }
200188
201189 # - TEST cond_timedwait timeout
@@ -231,7 +219,7 @@ SYNC_SHARED: {
231219 $ok =cond_timedwait($cond , time () + $to ), last if / simple/ ;
232220 $ok =cond_timedwait($cond , time () + $to , $cond ), last if / repeat/ ;
233221 $ok =cond_timedwait($cond , time () + $to , $lock ), last if / twain/ ;
234- die " $test : unknown test\n " ;
222+ die " $test : unknown test\n " ;
235223 }
236224 ok(2,!defined ($ok ), " $test : timeout" );
237225 }
@@ -244,7 +232,7 @@ SYNC_SHARED: {
244232
245233SYNCH_REFS: {
246234 my $test : shared; # simple|repeat|twain
247-
235+
248236 my $true_cond ; share($true_cond );
249237 my $true_lock ; share($true_lock );
250238
@@ -272,29 +260,24 @@ SYNCH_REFS: {
272260 foreach (@wait_how ) {
273261 $test = " cond_wait [$_ ]" ;
274262 threads-> create(\&cw2)-> join ;
275- $Base += 6 ;
263+ $Base += 5 ;
276264 }
277- }, 6 *@wait_how , 90);
265+ }, 5 *@wait_how , 90);
278266
279267 sub cw2 {
280- my $thr ;
281-
282- { # -- begin lock scope; which lock to obtain?
268+ # which lock to obtain?
283269 $test =~ / twain/ ? lock($lock ) : lock($cond );
284270 ok(1,1, " $test : obtained initial lock" );
285271
286- $thr = threads-> create(\&signaller2);
272+ my $thr = threads-> create(\&signaller2);
287273 for ($test ) {
288274 cond_wait($cond ), last if / simple/ ;
289275 cond_wait($cond , $cond ), last if / repeat/ ;
290276 cond_wait($cond , $lock ), last if / twain/ ;
291- die " $test : unknown test\n " ;
277+ die " $test : unknown test\n " ;
292278 }
279+ $thr -> join ;
293280 ok(5,1, " $test : condition obtained" );
294- } # -- end lock scope
295-
296- $thr -> join ;
297- ok(6,1, " $test : join completed" );
298281 }
299282
300283 # - TEST cond_timedwait success
@@ -303,31 +286,27 @@ SYNCH_REFS: {
303286 foreach (@wait_how ) {
304287 $test = " cond_timedwait [$_ ]" ;
305288 threads-> create(\&ctw2, 5)-> join ;
306- $Base += 6 ;
289+ $Base += 5 ;
307290 }
308- }, 6 *@wait_how , 90);
291+ }, 5 *@wait_how , 90);
309292
310293 sub ctw2 ($) {
311- my $to = shift ;
312- my $thr ;
294+ my $to = shift ;
313295
314- { # -- begin lock scope; which lock to obtain?
296+ # which lock to obtain?
315297 $test =~ / twain/ ? lock($lock ) : lock($cond );
316298 ok(1,1, " $test : obtained initial lock" );
317299
318- $thr = threads-> create(\&signaller2);
300+ my $thr = threads-> create(\&signaller2);
319301 my $ok = 0;
320302 for ($test ) {
321303 $ok =cond_timedwait($cond , time () + $to ), last if / simple/ ;
322304 $ok =cond_timedwait($cond , time () + $to , $cond ), last if / repeat/ ;
323305 $ok =cond_timedwait($cond , time () + $to , $lock ), last if / twain/ ;
324- die " $test : unknown test\n " ;
306+ die " $test : unknown test\n " ;
325307 }
308+ $thr -> join ;
326309 ok(5,$ok , " $test : condition obtained" );
327- } # -- end lock scope
328-
329- $thr -> join ;
330- ok(6,1, " $test : join completed" );
331310 }
332311
333312 # - TEST cond_timedwait timeout
@@ -363,7 +342,7 @@ SYNCH_REFS: {
363342 $ok =cond_timedwait($cond , time () + $to ), last if / simple/ ;
364343 $ok =cond_timedwait($cond , time () + $to , $cond ), last if / repeat/ ;
365344 $ok =cond_timedwait($cond , time () + $to , $lock ), last if / twain/ ;
366- die " $test : unknown test\n " ;
345+ die " $test : unknown test\n " ;
367346 }
368347 ok(2,!$ok , " $test : timeout" );
369348 }
0 commit comments