Commit | Line | Data |
47ba8780 |
1 | # Before `make install' is performed this script should be runnable with |
2 | # `make test'. After `make install' it should work as `perl test.pl' |
3 | |
4 | ######################### |
5 | |
6 | # change 'tests => 1' to 'tests => last_test_to_print'; |
7 | use ExtUtils::testlib; |
8 | use Test; |
9 | use strict; |
10 | BEGIN { plan tests => 16 }; |
11 | use threads; |
12 | |
13 | |
14 | ok(1); # If we made it this far, we're ok. |
15 | |
16 | ######################### |
17 | |
18 | # Insert your test code below, the Test module is use()ed here so read |
19 | # its man page ( perldoc Test ) for help writing this test script. |
20 | #my $bar; |
21 | |
22 | skip('The ignores are here to keep test numbers correct','The ignores are here to keep test numbers correct'); |
23 | |
24 | #test passing of simple argument |
25 | my $thread = threads->create(sub { ok('bar',$_[0]) },"bar"); |
26 | $thread->join(); |
27 | skip('Ignore','Ignore'); |
28 | |
29 | #test passing of complex argument |
30 | |
31 | $thread = threads->create(sub { ok('bar',$_[0]->[0]->{foo})},[{foo => 'bar'}]); |
32 | |
33 | $thread->join(); |
34 | skip('Ignore','Ignore'); |
35 | |
36 | #test execuion of normal sub |
37 | sub bar { ok(1,shift()) } |
38 | threads->create(\&bar,1)->join(); |
39 | skip('Ignore','Ignore'); |
40 | |
41 | #check Config |
42 | ok("1", "$Config::threads"); |
43 | |
44 | #test trying to detach thread |
45 | |
46 | my $thread1 = threads->create(sub {ok(1);}); |
47 | |
48 | $thread1->detach(); |
49 | skip('Ignore','Ignore'); |
50 | sleep 1; |
51 | ok(1); |
52 | #create nested threads |
53 | unless($^O eq 'MSWin32') { |
54 | my $thread3 = threads->create(sub { threads->create(sub {})})->join(); |
55 | ok(1); |
56 | } else { |
57 | skip('thread trees are unsafe under win32','thread trees are unsafe under win32'); |
58 | } |
59 | skip('Ignore','Ignore'); |
60 | |
61 | my @threads; |
62 | my $i; |
63 | unless($^O eq 'MSWin32') { |
64 | for(1..25) { |
65 | push @threads, threads->create(sub { for(1..100000) { my $i } threads->create(sub { sleep 2})->join() }); |
66 | } |
67 | foreach my $thread (@threads) { |
68 | $thread->join(); |
69 | } |
70 | } |
71 | ok(1); |
72 | threads->create(sub { |
73 | my $self = threads->self(); |
74 | ok($self->tid(),57); |
75 | })->join(); |
76 | skip('Ignore','Ignore'); |
77 | threads->create(sub { |
78 | my $self = threads->self(); |
79 | ok($self->tid(),58); |
80 | })->join(); |
81 | skip('Ignore','Ignore'); |
82 | |
83 | #check support for threads->self() in main thread |
84 | ok(0,threads->self->tid()); |
85 | ok(0,threads->tid()); |
86 | |
87 | |
88 | |
89 | |
90 | |
91 | |
92 | |
93 | |
94 | |
95 | |