]> git.vpit.fr Git - perl/modules/indirect.git/blob - t/41-threads-teardown.t
Rename I_CHECK_MUTEX_* to I_CHECK_*
[perl/modules/indirect.git] / t / 41-threads-teardown.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 BEGIN { require indirect; }
7
8 use lib 't/lib';
9 use VPIT::TestHelpers (
10  threads => [ 'indirect' => indirect::I_THREADSAFE ],
11 );
12
13 use Test::Leaner tests => 3;
14
15 my $run_perl_failed = 'Could not execute perl subprocess';
16
17 SKIP: {
18  skip 'Fails on 5.8.2 and lower' => 1 if "$]" <= 5.008_002;
19
20  my $status = run_perl <<' RUN';
21   my ($code, @expected);
22   BEGIN {
23    $code = 2;
24    @expected = qw<X Z>;
25   }
26   sub cb { --$code if $_[0] eq shift(@expected) || q{DUMMY} }
27   use threads;
28   $code = threads->create(sub {
29    eval q{return; no indirect hook => \&cb; new X;};
30    return $code;
31   })->join;
32   eval q{new Y;};
33   eval q{return; no indirect hook => \&cb; new Z;};
34   exit $code;
35  RUN
36  skip $run_perl_failed => 1 unless defined $status;
37  is $status, 0,
38         'loading the pragma in a thread and using it outside doesn\'t segfault';
39 }
40
41 SKIP: {
42  my $status = run_perl <<' RUN';
43   use threads;
44   BEGIN { require indirect; }
45   sub X::DESTROY { eval 'no indirect; 1'; exit 1 if $@ }
46   threads->create(sub {
47    my $x = bless { }, 'X';
48    $x->{self} = $x;
49    return;
50   })->join;
51   exit $code;
52  RUN
53  skip $run_perl_failed => 1 unless defined $status;
54  is $status, 0, 'indirect can be loaded in eval STRING during global destruction at the end of a thread';
55 }
56
57 SKIP: {
58  my $status = run_perl <<' RUN';
59   use threads;
60   use threads::shared;
61   my $code : shared;
62   $code = 0;
63   no indirect cb => sub { lock $code; ++$code };
64   sub X::DESTROY { eval $_[0]->{code} }
65   threads->create(sub {
66    my $x = bless { code => 'new Z' }, 'X';
67    $x->{self} = $x;
68    return;
69   })->join;
70   exit $code;
71  RUN
72  skip $run_perl_failed => 1 unless defined $status;
73  is $status, 0, 'indirect does not check eval STRING during global destruction at the end of a thread';
74 }