From: Jerry D. Hedden Date: Sun, 1 Jul 2007 15:03:41 +0000 (-0400) Subject: Fixes to threads tests X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a662d730755bd4763502de042ac949ef3a7a71ae;p=p5sagit%2Fp5-mst-13.2.git Fixes to threads tests From: "Jerry D. Hedden" Message-ID: <1ff86f510707011203qc90c31he6f6b86d08d34e39@mail.gmail.com> p4raw-id: //depot/perl@31516 --- diff --git a/ext/threads/Changes b/ext/threads/Changes index 9dd628b..0ebd9d2 100755 --- a/ext/threads/Changes +++ b/ext/threads/Changes @@ -1,5 +1,8 @@ Revision history for Perl extension threads. +- + - Sundry test suite fixes + 1.63 Tue Jun 26 21:15:27 EDT 2007 - Avoid double-free of the thread function - Added reference in POD to perlmod section on thread safety diff --git a/ext/threads/t/stack.t b/ext/threads/t/stack.t index b5cb11e..ea22893 100644 --- a/ext/threads/t/stack.t +++ b/ext/threads/t/stack.t @@ -34,72 +34,72 @@ BEGIN { print("1..18\n"); ### Number of tests that will be run ### }; -use threads ('stack_size' => 32*4096); +use threads ('stack_size' => 128*4096); ok(1, 1, 'Loaded'); ### Start of Testing ### -ok(2, threads->get_stack_size() == 32*4096, +ok(2, threads->get_stack_size() == 128*4096, 'Stack size set in import'); -ok(3, threads->set_stack_size(64*4096) == 32*4096, +ok(3, threads->set_stack_size(160*4096) == 128*4096, 'Set returns previous value'); -ok(4, threads->get_stack_size() == 64*4096, +ok(4, threads->get_stack_size() == 160*4096, 'Get stack size'); threads->create( sub { - ok(5, threads->get_stack_size() == 64*4096, + ok(5, threads->get_stack_size() == 160*4096, 'Get stack size in thread'); - ok(6, threads->self()->get_stack_size() == 64*4096, + ok(6, threads->self()->get_stack_size() == 160*4096, 'Thread gets own stack size'); - ok(7, threads->set_stack_size(32*4096) == 64*4096, + ok(7, threads->set_stack_size(128*4096) == 160*4096, 'Thread changes stack size'); - ok(8, threads->get_stack_size() == 32*4096, + ok(8, threads->get_stack_size() == 128*4096, 'Get stack size in thread'); - ok(9, threads->self()->get_stack_size() == 64*4096, + ok(9, threads->self()->get_stack_size() == 160*4096, 'Thread stack size unchanged'); } )->join(); -ok(10, threads->get_stack_size() == 32*4096, +ok(10, threads->get_stack_size() == 128*4096, 'Default thread sized changed in thread'); threads->create( - { 'stack' => 64*4096 }, + { 'stack' => 160*4096 }, sub { - ok(11, threads->get_stack_size() == 32*4096, + ok(11, threads->get_stack_size() == 128*4096, 'Get stack size in thread'); - ok(12, threads->self()->get_stack_size() == 64*4096, + ok(12, threads->self()->get_stack_size() == 160*4096, 'Thread gets own stack size'); } )->join(); -my $thr = threads->create( { 'stack' => 64*4096 }, sub { } ); +my $thr = threads->create( { 'stack' => 160*4096 }, sub { } ); $thr->create( sub { - ok(13, threads->get_stack_size() == 32*4096, + ok(13, threads->get_stack_size() == 128*4096, 'Get stack size in thread'); - ok(14, threads->self()->get_stack_size() == 64*4096, + ok(14, threads->self()->get_stack_size() == 160*4096, 'Thread gets own stack size'); } )->join(); $thr->create( - { 'stack' => 48*4096 }, + { 'stack' => 144*4096 }, sub { - ok(15, threads->get_stack_size() == 32*4096, + ok(15, threads->get_stack_size() == 128*4096, 'Get stack size in thread'); - ok(16, threads->self()->get_stack_size() == 48*4096, + ok(16, threads->self()->get_stack_size() == 144*4096, 'Thread gets own stack size'); - ok(17, threads->set_stack_size(64*4096) == 32*4096, + ok(17, threads->set_stack_size(160*4096) == 128*4096, 'Thread changes stack size'); } )->join(); $thr->join(); -ok(18, threads->get_stack_size() == 64*4096, +ok(18, threads->get_stack_size() == 160*4096, 'Default thread sized changed in thread'); # EOF diff --git a/ext/threads/t/stack_env.t b/ext/threads/t/stack_env.t index 18ad794..09de083 100644 --- a/ext/threads/t/stack_env.t +++ b/ext/threads/t/stack_env.t @@ -33,7 +33,7 @@ BEGIN { $| = 1; print("1..4\n"); ### Number of tests that will be run ### - $ENV{'PERL5_ITHREADS_STACK_SIZE'} = 196608; + $ENV{'PERL5_ITHREADS_STACK_SIZE'} = 128*4096; }; use threads; @@ -41,11 +41,11 @@ ok(1, 1, 'Loaded'); ### Start of Testing ### -ok(2, threads->get_stack_size() == 48*4096, +ok(2, threads->get_stack_size() == 128*4096, '$ENV{PERL5_ITHREADS_STACK_SIZE}'); -ok(3, threads->set_stack_size(32*4096) == 48*4096, +ok(3, threads->set_stack_size(144*4096) == 128*4096, 'Set returns previous value'); -ok(4, threads->get_stack_size() == 32*4096, +ok(4, threads->get_stack_size() == 144*4096, 'Get stack size'); # EOF diff --git a/ext/threads/t/stress_cv.t b/ext/threads/t/stress_cv.t index d82d174..322fb46 100644 --- a/ext/threads/t/stress_cv.t +++ b/ext/threads/t/stress_cv.t @@ -15,14 +15,16 @@ BEGIN { use ExtUtils::testlib; +my $test = 0; sub ok { - my ($id, $ok, $name) = @_; + my ($ok, $name) = @_; + $test++; # You have to do it this way or VMS will get confused. if ($ok) { - print("ok $id - $name\n"); + print("ok $test - $name\n"); } else { - print("not ok $id - $name\n"); + print("not ok $test - $name\n"); printf("# Failed test at line %d\n", (caller)[2]); } @@ -31,27 +33,29 @@ sub ok { BEGIN { $| = 1; - print("1..63\n"); ### Number of tests that will be run ### + print("1..61\n"); ### Number of tests that will be run ### }; use threads; -ok(1, 1, 'Loaded'); +ok(1, 'Loaded'); ### Start of Testing ### +my $cnt = 30; + my @threads; -for (2..32) { - ok($_, 1, "Multiple thread test"); - push(@threads , threads->create(sub { - my $i = shift; - for (1..500000) { $i++ } - }, $_)); +for (1..$cnt) { + my $thr = threads->create(sub { my $ii = shift; + for (1..500000) { $ii++ } }, $_); + ok($thr, "Thread created - iter $_"); + push(@threads, $thr); } -my $i = 33; -for (@threads) { - $_->join; - ok($i++, 1 ,"Thread joined"); +for (1..$cnt) { + my ($result, $thr); + $thr = $threads[$_-1]; + $result = $thr->join if $thr; + ok($thr, "Thread joined - iter $_"); } # EOF diff --git a/ext/threads/t/stress_re.t b/ext/threads/t/stress_re.t index 6ba36ed..0a32ab9 100644 --- a/ext/threads/t/stress_re.t +++ b/ext/threads/t/stress_re.t @@ -15,14 +15,16 @@ BEGIN { use ExtUtils::testlib; +my $test = 0; sub ok { - my ($id, $ok, $name) = @_; + my ($ok, $name) = @_; + $test++; # You have to do it this way or VMS will get confused. if ($ok) { - print("ok $id - $name\n"); + print("ok $test - $name\n"); } else { - print("not ok $id - $name\n"); + print("not ok $test - $name\n"); printf("# Failed test at line %d\n", (caller)[2]); } @@ -31,11 +33,11 @@ sub ok { BEGIN { $| = 1; - print("1..31\n"); ### Number of tests that will be run ### + print("1..61\n"); ### Number of tests that will be run ### }; use threads; -ok(1, 1, 'Loaded'); +ok(1, 'Loaded'); ### Start of Testing ### @@ -50,12 +52,16 @@ sub stress_re { my @threads; for (1..$cnt) { - push(@threads, threads->create('stress_re', $_)); + my $thr = threads->create('stress_re', $_); + ok($thr, "Thread created - iter $_"); + push(@threads, $thr); } for (1..$cnt) { - my $result = $threads[$_-1]->join; - ok($_+1, defined($result) && ($result eq 'ok'), "stress re - iter $_"); + my ($result, $thr); + $thr = $threads[$_-1]; + $result = $thr->join if $thr; + ok($thr && defined($result) && ($result eq 'ok'), "Thread joined - iter $_"); } # EOF diff --git a/ext/threads/t/stress_string.t b/ext/threads/t/stress_string.t index 2a744ea..9cd0cd2 100644 --- a/ext/threads/t/stress_string.t +++ b/ext/threads/t/stress_string.t @@ -15,14 +15,16 @@ BEGIN { use ExtUtils::testlib; +my $test = 0; sub ok { - my ($id, $ok, $name) = @_; + my ($ok, $name) = @_; + $test++; # You have to do it this way or VMS will get confused. if ($ok) { - print("ok $id - $name\n"); + print("ok $test - $name\n"); } else { - print("not ok $id - $name\n"); + print("not ok $test - $name\n"); printf("# Failed test at line %d\n", (caller)[2]); } @@ -31,28 +33,33 @@ sub ok { BEGIN { $| = 1; - print("1..63\n"); ### Number of tests that will be run ### + print("1..61\n"); ### Number of tests that will be run ### }; use threads; -ok(1, 1, 'Loaded'); +ok(1, 'Loaded'); ### Start of Testing ### +my $cnt = 30; + sub test9 { my $i = shift; for (1..500000) { $i++ }; } + my @threads; -for (2..32) { - ok($_, 1, "Multiple thread test"); - push(@threads, threads->create('test9', $_)); +for (1..$cnt) { + my $thr = threads->create('test9', $_); + ok($thr, "Thread created - iter $_"); + push(@threads, $thr); } -my $i = 33; -for (@threads) { - $_->join; - ok($i++, 1, "Thread joined"); +for (1..$cnt) { + my ($result, $thr); + $thr = $threads[$_-1]; + $result = $thr->join if $thr; + ok($thr, "Thread joined - iter $_"); } # EOF