[PATCH[ threads 1.53
[p5sagit/p5-mst-13.2.git] / ext / threads / t / libc.t
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'}) {
11         print("1..0 # Skip: Perl not compiled with 'useithreads'\n");
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 use threads;
33
34 BEGIN {
35     $| = 1;
36     print("1..12\n");   ### Number of tests that will be run ###
37 };
38
39 ok(1, 1, 'Loaded');
40
41 ### Start of Testing ###
42
43 my $i = 10;
44 my $y = 20000;
45
46 my %localtime;
47 for (0..$i) {
48     $localtime{$_} = localtime($_);
49 };
50
51 my @threads;
52 for (0..$i) {
53     my $thread = threads->create(sub {
54                     my $arg = $_;
55                     my $localtime = $localtime{$arg};
56                     my $error = 0;
57                     for (0..$y) {
58                         my $lt = localtime($arg);
59                         if ($localtime ne $lt) {
60                             $error++;
61                         }
62                     }
63                     return $error;
64                   });
65     push @threads, $thread;
66 }
67
68 for (0..$i) {
69     my $result = $threads[$_]->join();
70     ok($_ + 2, defined($result) && ("$result" eq '0'), 'localtime safe');
71 }
72
73 # EOF