Debian Codegraph @

t/forks.t

raw
1 use Test2::V0 -no_srand => 1;
2 use FFI::CheckLib;
3 use FFI::Platypus;
4 use File::Spec;
5
6 BEGIN
7 {
8 my $path;
9 foreach my $inc (@INC)
10 {
11 $path = File::Spec->catfile($inc, 'forks.pm');
12 last if -f $path;
13 }
14
15 skip_all 'Test requires forks' unless defined $path && -f $path;
16 }
17
18 use forks;
19
20 my $ffi = FFI::Platypus->new(lib => find_lib(lib => 'test', symbol => 'f0', libpath => 't/ffi' ));
21
22 sub f0
23 {
24 $ffi->function(f0 => ['uint8'] => 'uint8')->call(@_);
25 }
26
27 sub otherthread
28 {
29 my $val = f0(22);
30 undef $ffi;
31 $val;
32 }
33
34 ok 1;
35
36 is(threads->create(\&otherthread)->join(), 22, 'works in a thread');
37
38 is f0(24), 24, 'works in main thread';
39
40 done_testing;