1b39c5158Smillertuse strict; 2b39c5158Smillertuse warnings; 3b39c5158Smillert 4b39c5158SmillertBEGIN { 5b39c5158Smillert use Config; 6b39c5158Smillert if (! $Config{'useithreads'}) { 7b39c5158Smillert print("1..0 # SKIP Perl not compiled with 'useithreads'\n"); 8b39c5158Smillert exit(0); 9b39c5158Smillert } 10b39c5158Smillert} 11b39c5158Smillert 12b39c5158Smillertuse ExtUtils::testlib; 13b39c5158Smillert 14b39c5158Smillertsub ok { 15b39c5158Smillert my ($id, $ok, $name) = @_; 16b39c5158Smillert 17b39c5158Smillert # You have to do it this way or VMS will get confused. 18b39c5158Smillert if ($ok) { 19b39c5158Smillert print("ok $id - $name\n"); 20b39c5158Smillert } else { 21b39c5158Smillert print("not ok $id - $name\n"); 22b39c5158Smillert printf("# Failed test at line %d\n", (caller)[2]); 23b39c5158Smillert } 24b39c5158Smillert 25b39c5158Smillert return ($ok); 26b39c5158Smillert} 27b39c5158Smillert 28*256a93a4Safresh1sub is { 29*256a93a4Safresh1 my ($id, $got, $expected, $name) = @_; 30*256a93a4Safresh1 31*256a93a4Safresh1 my $ok = ok($id, $got == $expected, $name); 32*256a93a4Safresh1 if (! $ok) { 33*256a93a4Safresh1 print(" GOT: $got\n"); 34*256a93a4Safresh1 print("EXPECTED: $expected\n"); 35*256a93a4Safresh1 } 36*256a93a4Safresh1 37*256a93a4Safresh1 return ($ok); 38*256a93a4Safresh1} 39*256a93a4Safresh1 40*256a93a4Safresh1my $frame_size; 41*256a93a4Safresh1my $frames; 42*256a93a4Safresh1my $size; 43*256a93a4Safresh1 44b39c5158SmillertBEGIN { 45b39c5158Smillert $| = 1; 46b39c5158Smillert print("1..4\n"); ### Number of tests that will be run ### 47b39c5158Smillert 48*256a93a4Safresh1 # XXX Note that if the default stack size happens to be the same as these 49*256a93a4Safresh1 # numbers, that test 2 would return success just out of happenstance. 50*256a93a4Safresh1 # This possibility could be lessened by choosing $frames to be something 51*256a93a4Safresh1 # less likely than a power of 2 52*256a93a4Safresh1 53*256a93a4Safresh1 $frame_size = 4096; 54*256a93a4Safresh1 $frames = 128; 55*256a93a4Safresh1 $size = $frames * $frame_size; 56*256a93a4Safresh1 57*256a93a4Safresh1 $ENV{'PERL5_ITHREADS_STACK_SIZE'} = $size; 58b39c5158Smillert}; 59b39c5158Smillert 60b39c5158Smillertuse threads; 61b39c5158Smillertok(1, 1, 'Loaded'); 62b39c5158Smillert 63b39c5158Smillert### Start of Testing ### 64b39c5158Smillert 65*256a93a4Safresh1my $actual_size = threads->get_stack_size(); 66*256a93a4Safresh1 67*256a93a4Safresh1{ 68*256a93a4Safresh1 if ($actual_size > $size) { 69*256a93a4Safresh1 print("ok 2 # skip because system needs larger minimum stack size\n"); 70*256a93a4Safresh1 $size = $actual_size; 71*256a93a4Safresh1 } 72*256a93a4Safresh1 else { 73*256a93a4Safresh1 is(2, $actual_size, $size, '$ENV{PERL5_ITHREADS_STACK_SIZE}'); 74*256a93a4Safresh1 } 75*256a93a4Safresh1} 76*256a93a4Safresh1 77*256a93a4Safresh1my $size_plus_eighth = $size * 1.125; # 128 frames map to 144 78*256a93a4Safresh1is(3, threads->set_stack_size($size_plus_eighth), $size, 79b39c5158Smillert 'Set returns previous value'); 80*256a93a4Safresh1is(4, threads->get_stack_size(), $size_plus_eighth, 81b39c5158Smillert 'Get stack size'); 82b39c5158Smillert 83b39c5158Smillertexit(0); 84b39c5158Smillert 85b39c5158Smillert# EOF 86