}
eval {
require Time::HiRes;
- import Time::HiRes qw(time);
+ Time::HiRes->import('time');
};
if ($@) {
print("1..0 # Skip: Time::HiRes not available.\n");
BEGIN {
$| = 1;
- print("1..63\n"); ### Number of tests that will be run ###
+ print("1..57\n"); ### Number of tests that will be run ###
};
use threads;
# RedHat users should see https://rhn.redhat.com/errata/RHBA-2003-136.html
# and consider upgrading their glibc.
+
sub forko (&$$); # To prevent deadlock from underlying pthread_* bugs (as in
# stock RH9 glibc/NPTL) or from our own errors, we run tests
# in separately forked and alarmed processes.
my $bump = $expected;
- $patience ||= 60;
-
unless (defined($pid = open(CHLD, "-|"))) {
die "fork: $!\n";
}
if (! $pid) { # Child -- run the test
- $patience ||= 60;
- alarm $patience;
+ alarm($patience || 60);
&$code;
exit;
}
close(CHLD);
while ($expected--) {
- $test_num++;
- print "not ok $test_num - child status $?\n";
+ ok(++$test_num, 0, "missing test result: child status $?");
}
$Base += $bump;
-
};
+
# - TEST basics
my @wait_how = (
foreach (@wait_how) {
$test = "cond_timedwait [$_]";
threads->create(\&ctw, 0.05)->join;
- $Base += 6;
+ $Base += 5;
}
- }, 6*@wait_how, 5);
+ }, 5*@wait_how, 5);
sub ctw($) {
- my $to = shift;
- my $thr;
+ my $to = shift;
- { # -- begin lock scope; which lock to obtain?
+ # which lock to obtain?
$test =~ /twain/ ? lock($lock) : lock($cond);
ok(1,1, "$test: obtained initial lock");
- $thr = threads->create(\&signaller);
+ my $thr = threads->create(\&signaller);
my $ok = 0;
for ($test) {
$ok=cond_timedwait($cond, time() + $to), last if /simple/;
$ok=cond_timedwait($cond, time() + $to, $lock), last if /twain/;
die "$test: unknown test\n";
}
+ $thr->join;
ok(5,$ok, "$test: condition obtained");
- } # -- end lock scope
-
- $thr->join;
- ok(6,1, "$test: join completed");
}
# - TEST cond_timedwait timeout
die "$test: unknown test\n";
}
$delta = time() - $delta;
- if (($to < 0) || ($^O eq 'os2')) {
- ok(2, ! defined($ok), "$test: timeout");
- } else {
- # This is a bit problematic, as scheduling and compute latencies
- # can inject delays in our computation. For now, assume -10/+20%
- # is reasonable
- if (! ok(2, ! defined($ok) &&
- ($delta > (0.9 * $to)) &&
- ($delta < (1.2 * $to)),
- "$test: timeout"))
- {
- print(STDERR "# Timeout: specified=$to actual=$delta secs.\n");
+ ok(2, ! defined($ok), "$test: timeout");
+
+ if (($to > 0) && ($^O ne 'os2')) {
+ # Timing tests can be problematic
+ if (($delta < (0.9 * $to)) || ($delta > (1.0 + $to))) {
+ print(STDERR "# Timeout: specified=$to actual=$delta secs.\n");
}
}
}
foreach (@wait_how) {
$test = "cond_timedwait [$_]";
threads->create(\&ctw2, 0.05)->join;
- $Base += 6;
+ $Base += 5;
}
- }, 6*@wait_how, 5);
+ }, 5*@wait_how, 5);
sub ctw2($) {
- my $to = shift;
- my $thr;
+ my $to = shift;
- { # -- begin lock scope; which lock to obtain?
+ # which lock to obtain?
$test =~ /twain/ ? lock($lock) : lock($cond);
ok(1,1, "$test: obtained initial lock");
- $thr = threads->create(\&signaller2);
+ my $thr = threads->create(\&signaller2);
my $ok = 0;
for ($test) {
$ok=cond_timedwait($cond, time() + $to), last if /simple/;
$ok=cond_timedwait($cond, time() + $to, $lock), last if /twain/;
die "$test: unknown test\n";
}
+ $thr->join;
ok(5,$ok, "$test: condition obtained");
- } # -- end lock scope
-
- $thr->join;
- ok(6,1, "$test: join completed");
}
# - TEST cond_timedwait timeout
die "$test: unknown test\n";
}
$delta = time() - $delta;
- if (($to < 0) || ($^O eq 'os2')) {
- ok(2,!$ok, "$test: timeout");
- } else {
- # This is a bit problematic, as scheduling and compute latencies
- # can inject delays in our computation. For now, assume -10/+20%
- # is reasonable
- if (! ok(2, ! $ok &&
- ($delta > (0.9 * $to)) &&
- ($delta < (1.2 * $to)),
- "$test: timeout"))
- {
- print(STDERR "# Timeout: specified=$to actual=$delta secs.\n");
+ ok(2, ! $ok, "$test: timeout");
+
+ if (($to > 0) && ($^O ne 'os2')) {
+ # Timing tests can be problematic
+ if (($delta < (0.9 * $to)) || ($delta > (1.0 + $to))) {
+ print(STDERR "# Timeout: specified=$to actual=$delta secs.\n");
}
}
}