File: 001_basic.t

package info (click to toggle)
libposix-atfork-perl 0.04-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 192 kB
  • sloc: perl: 1,946; ansic: 64; makefile: 2; sh: 1
file content (35 lines) | stat: -rw-r--r-- 628 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!perl
use strict;
use warnings;
use Test::More tests => 6;
use Test::SharedFork;
use POSIX::AtFork qw(:all);

my $prepare = 0;
my $parent  = 0;
my $child   = 0;

pthread_atfork(
    sub { $prepare++ },
    sub { $parent++ },
    sub { $child++ },
);

my $pid = fork;
die "Failed to fork: $!" if not defined $pid;

if($pid != 0) {
    is $prepare, 1, '&prepare in parent';
    is $parent,  1, '&parent in parent';
    is $child,   0, '&child in parent';
    waitpid $pid, 0;
    exit;
}
else {
    is $prepare, 1, '&prepare in child';
    is $parent,  0, '&parent in child';
    is $child,   1, '&child in child';
    exit;
}