File: fork.t

package info (click to toggle)
libautodie-perl 2.10-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 528 kB
  • ctags: 305
  • sloc: perl: 4,012; makefile: 4
file content (46 lines) | stat: -rwxr-xr-x 1,132 bytes parent folder | download | duplicates (4)
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
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/perl -w
use strict;
use Test::More;
use constant TESTS => 3;

BEGIN {
    eval { require BSD::Resource; BSD::Resource->import() };

    if ($@) {
        plan skip_all => "BSD::Resource required to test fork()";
    }
}

plan tests => TESTS;

# This should prevent our process from being allowed to have
# any children.

my $rlimit_success = eval { setrlimit(RLIMIT_NPROC, 0, 0); };

SKIP: {
    skip("setrlimit does not allow child limiting",TESTS)
        if not $rlimit_success;

    # This should return undef quietly, as well as testing that
    # fork is failing.
    my $retval = fork();

    # If our fork was successful, we had better skip out!
    if (defined $retval) {
        $retval or exit(0);   # The child process should just exit.
        skip("fork() still creates children after setrlimit",TESTS);
    }

    eval {
        use autodie qw(fork);

        fork();         # Should die.
    };

    if ($@) {
        ok(1, "autodying fork throws an exception");
        isa_ok($@, 'autodie::exception', '... with the correct class');
        ok($@->matches('fork'), '... which matches fork()');
    }
}