From 4271b52731a6686853855c0f41ce04f915a2e02e Mon Sep 17 00:00:00 2001 From: "Jerry D. Hedden" Date: Wed, 16 Jul 2008 07:10:35 -0400 Subject: [PATCH] watchdog() for threads tests From: "Jerry D. Hedden" Message-ID: <1ff86f510807160810ib0a01adg4f54cca69a96b623@mail.gmail.com> p4raw-id: //depot/perl@34150 --- ext/threads/t/free.t | 14 ++++++++++---- ext/threads/t/free2.t | 38 ++++++++++++++++++++++---------------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/ext/threads/t/free.t b/ext/threads/t/free.t index 53da950..2c91189 100644 --- a/ext/threads/t/free.t +++ b/ext/threads/t/free.t @@ -6,10 +6,16 @@ BEGIN { chdir 't'; unshift @INC, '../lib'; } + + # Import test.pl into its own package + { + package Test; + require($ENV{PERL_CORE} ? './test.pl' : './t/test.pl'); + } + use Config; if (! $Config{'useithreads'}) { - print("1..0 # SKIP Perl not compiled with 'useithreads'\n"); - exit(0); + Test::skip_all(q/Perl not compiled with 'useithreads'/); } } @@ -23,8 +29,7 @@ BEGIN { threads::shared->import(); }; if ($@ || ! $threads::shared::threads_shared) { - print("1..0 # SKIP threads::shared not available\n"); - exit(0); + Test::skip_all(q/threads::shared not available/); } require Thread::Queue; @@ -33,6 +38,7 @@ BEGIN { print("1..29\n"); ### Number of tests that will be run ### } +Test::watchdog(120); # In case we get stuck my $q = Thread::Queue->new(); my $TEST = 1; diff --git a/ext/threads/t/free2.t b/ext/threads/t/free2.t index e5a9b23..f72bc37 100644 --- a/ext/threads/t/free2.t +++ b/ext/threads/t/free2.t @@ -6,10 +6,16 @@ BEGIN { chdir 't'; unshift @INC, '../lib'; } + + # Import test.pl into its own package + { + package Test; + require($ENV{PERL_CORE} ? './test.pl' : './t/test.pl'); + } + use Config; if (! $Config{'useithreads'}) { - print("1..0 # SKIP Perl not compiled with 'useithreads'\n"); - exit(0); + Test::skip_all(q/Perl not compiled with 'useithreads'/); } } @@ -23,13 +29,11 @@ BEGIN { threads::shared->import(); }; if ($@ || ! $threads::shared::threads_shared) { - print("1..0 # SKIP threads::shared not available\n"); - exit(0); + Test::skip_all(q/threads::shared not available/); } if (($] < 5.008002) && ($threads::shared::VERSION < 0.92)) { - print("1..0 # SKIP Needs threads::shared 0.92 or later\n"); - exit(0); + Test::skip_all(q/Needs threads::shared 0.92 or later/); } require Thread::Queue; @@ -38,6 +42,7 @@ BEGIN { print("1..78\n"); ### Number of tests that will be run ### } +Test::watchdog(60); # In case we get stuck my $q = Thread::Queue->new(); my $TEST = 1; @@ -87,8 +92,8 @@ sub th_start lock(%READY); # Create next thread - if ($tid < 17) { - my $next = 'th' . ($tid+1); + if ($tid < 18) { + my $next = 'th' . $tid; my $th = threads->create($next, $q); } else { # Last thread signals first @@ -123,6 +128,7 @@ sub th_signal { my $q = shift; my $other = shift; + $other++; my $tid = threads->tid(); $q->enqueue($tid, "Thread $tid signalling $other"); @@ -232,8 +238,8 @@ sub th3 th_signal($q, $other); sleep(1); $q->enqueue(1, "Thread $tid getting return from thread $other"); - my $ret = threads->object($other)->join(); - $q->enqueue($ret == $other, "Thread $tid saw that thread $other returned $ret"); + my $ret = threads->object($other+1)->join(); + $q->enqueue($ret == $other+1, "Thread $tid saw that thread $other returned $ret"); th_done($q); } @@ -256,8 +262,8 @@ sub th7 threads->detach(); th_signal($q, $other); $q->enqueue(1, "Thread $tid getting return from thread $other"); - my $ret = threads->object($other)->join(); - $q->enqueue($ret == $other, "Thread $tid saw that thread $other returned $ret"); + my $ret = threads->object($other+1)->join(); + $q->enqueue($ret == $other+1, "Thread $tid saw that thread $other returned $ret"); th_done($q); } @@ -282,8 +288,8 @@ sub th13 th_signal($q, $other); sleep(1); $q->enqueue(1, "Thread $tid getting return from thread $other"); - my $ret = threads->object($other)->join(); - $q->enqueue($ret == $other, "Thread $tid saw that thread $other returned $ret"); + my $ret = threads->object($other+1)->join(); + $q->enqueue($ret == $other+1, "Thread $tid saw that thread $other returned $ret"); th_done($q); } @@ -306,8 +312,8 @@ sub th17 threads->detach(); th_signal($q, $other); $q->enqueue(1, "Thread $tid getting return from thread $other"); - my $ret = threads->object($other)->join(); - $q->enqueue($ret == $other, "Thread $tid saw that thread $other returned $ret"); + my $ret = threads->object($other+1)->join(); + $q->enqueue($ret == $other+1, "Thread $tid saw that thread $other returned $ret"); th_done($q); } -- 2.7.4