Commit | Line | Data |
514612b7 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | BEGIN { |
5 | if ($ENV{'PERL_CORE'}){ |
6 | chdir 't'; |
7 | unshift @INC, '../lib'; |
8 | } |
9 | use Config; |
10 | if (! $Config{'useithreads'}) { |
561ee912 |
11 | print("1..0 # SKIP Perl not compiled with 'useithreads'\n"); |
514612b7 |
12 | exit(0); |
13 | } |
14 | } |
15 | |
16 | use ExtUtils::testlib; |
17 | |
18 | sub ok { |
19 | my ($id, $ok, $name) = @_; |
20 | |
21 | # You have to do it this way or VMS will get confused. |
22 | if ($ok) { |
23 | print("ok $id - $name\n"); |
24 | } else { |
25 | print("not ok $id - $name\n"); |
26 | printf("# Failed test at line %d\n", (caller)[2]); |
27 | } |
28 | |
29 | return ($ok); |
30 | } |
31 | |
32 | BEGIN { |
33 | $| = 1; |
34 | print("1..18\n"); ### Number of tests that will be run ### |
35 | }; |
36 | |
a662d730 |
37 | use threads ('stack_size' => 128*4096); |
514612b7 |
38 | ok(1, 1, 'Loaded'); |
39 | |
40 | ### Start of Testing ### |
41 | |
a662d730 |
42 | ok(2, threads->get_stack_size() == 128*4096, |
514612b7 |
43 | 'Stack size set in import'); |
a662d730 |
44 | ok(3, threads->set_stack_size(160*4096) == 128*4096, |
514612b7 |
45 | 'Set returns previous value'); |
a662d730 |
46 | ok(4, threads->get_stack_size() == 160*4096, |
514612b7 |
47 | 'Get stack size'); |
48 | |
49 | threads->create( |
50 | sub { |
a662d730 |
51 | ok(5, threads->get_stack_size() == 160*4096, |
514612b7 |
52 | 'Get stack size in thread'); |
a662d730 |
53 | ok(6, threads->self()->get_stack_size() == 160*4096, |
514612b7 |
54 | 'Thread gets own stack size'); |
a662d730 |
55 | ok(7, threads->set_stack_size(128*4096) == 160*4096, |
514612b7 |
56 | 'Thread changes stack size'); |
a662d730 |
57 | ok(8, threads->get_stack_size() == 128*4096, |
514612b7 |
58 | 'Get stack size in thread'); |
a662d730 |
59 | ok(9, threads->self()->get_stack_size() == 160*4096, |
514612b7 |
60 | 'Thread stack size unchanged'); |
61 | } |
62 | )->join(); |
63 | |
a662d730 |
64 | ok(10, threads->get_stack_size() == 128*4096, |
514612b7 |
65 | 'Default thread sized changed in thread'); |
66 | |
67 | threads->create( |
a662d730 |
68 | { 'stack' => 160*4096 }, |
514612b7 |
69 | sub { |
a662d730 |
70 | ok(11, threads->get_stack_size() == 128*4096, |
514612b7 |
71 | 'Get stack size in thread'); |
a662d730 |
72 | ok(12, threads->self()->get_stack_size() == 160*4096, |
514612b7 |
73 | 'Thread gets own stack size'); |
74 | } |
75 | )->join(); |
76 | |
a662d730 |
77 | my $thr = threads->create( { 'stack' => 160*4096 }, sub { } ); |
514612b7 |
78 | |
79 | $thr->create( |
80 | sub { |
a662d730 |
81 | ok(13, threads->get_stack_size() == 128*4096, |
514612b7 |
82 | 'Get stack size in thread'); |
a662d730 |
83 | ok(14, threads->self()->get_stack_size() == 160*4096, |
514612b7 |
84 | 'Thread gets own stack size'); |
85 | } |
86 | )->join(); |
87 | |
88 | $thr->create( |
a662d730 |
89 | { 'stack' => 144*4096 }, |
514612b7 |
90 | sub { |
a662d730 |
91 | ok(15, threads->get_stack_size() == 128*4096, |
514612b7 |
92 | 'Get stack size in thread'); |
a662d730 |
93 | ok(16, threads->self()->get_stack_size() == 144*4096, |
514612b7 |
94 | 'Thread gets own stack size'); |
a662d730 |
95 | ok(17, threads->set_stack_size(160*4096) == 128*4096, |
514612b7 |
96 | 'Thread changes stack size'); |
97 | } |
98 | )->join(); |
99 | |
100 | $thr->join(); |
101 | |
a662d730 |
102 | ok(18, threads->get_stack_size() == 160*4096, |
514612b7 |
103 | 'Default thread sized changed in thread'); |
104 | |
561ee912 |
105 | exit(0); |
106 | |
514612b7 |
107 | # EOF |