File: basic.pm

package info (click to toggle)
libapache2-mod-perl2 2.0.9~1624218-2%2Bdeb8u2
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 11,912 kB
  • ctags: 4,588
  • sloc: perl: 95,064; ansic: 14,527; makefile: 49; sh: 18
file content (97 lines) | stat: -rw-r--r-- 2,991 bytes parent folder | download | duplicates (7)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package TestApache2::basic;

use strict;
use warnings;

use Apache::Test qw(-withtestmore);

use Apache2::Const -compile => qw(OK);
use Apache2::SizeLimit;
use Config;

use constant ONE_MB => 1024;
use constant TEN_MB => 1024 * 10;

sub handler {
    my $r = shift;

    plan $r, tests => 10;

    {
        local ($Apache::SizeLimit::Core::MAX_PROCESS_SIZE,
               $Apache::SizeLimit::Core::MIN_SHARE_SIZE,
               $Apache::SizeLimit::Core::MAX_UNSHARED_SIZE);
        ok( ! Apache2::SizeLimit->_limits_are_exceeded(),
            'check that _limits_are_exceeded() returns false without any limits set' );
    }

    {
        my ( $size, $shared ) = Apache2::SizeLimit->_check_size();
        cmp_ok( $size, '>', 0, 'proc size is reported > 0' );

        {
            # test with USE_SMAPS=0
            my $smaps = $Apache2::SizeLimit::USE_SMAPS;
            $Apache2::SizeLimit::USE_SMAPS = 0;
            my ( $size, $shared ) = Apache2::SizeLimit->_check_size();
            cmp_ok( $size, '>', 0, 'proc size is reported > 0' );
            $Apache2::SizeLimit::USE_SMAPS = $smaps;
        }

    SKIP:
        {
            skip 'I have no idea what getppid() on Win32 might return', 1
                if $Config{'osname'} eq 'MSWin32';

            cmp_ok( Apache2::SizeLimit->_platform_getppid(), '>', 1,
                    'real_getppid() > 1' );
        }
    }

    {
        # We can assume this will use _at least_ 10MB of memory, based on
        # assuming a scalar consumes >= 1K.
        my @big = ('x') x TEN_MB;

        my ( $size, $shared ) = Apache2::SizeLimit->_check_size();
        cmp_ok( $size, '>', TEN_MB, 'proc size is reported > ' . TEN_MB );

        Apache2::SizeLimit->set_max_process_size(ONE_MB);

        ok( Apache2::SizeLimit->_limits_are_exceeded(),
            'check that _limits_are_exceeded() returns true based on max process size' );

    SKIP:
        {
            skip 'We cannot get shared memory on this platform.', 3
                unless $shared > 0;

            cmp_ok( $size, '>', $shared, 'proc size is greater than shared size' );

            Apache2::SizeLimit->set_max_process_size(0);
            Apache2::SizeLimit->set_min_shared_size( ONE_MB * 100 );

            ok( Apache2::SizeLimit->_limits_are_exceeded(),
                'check that _limits_are_exceeded() returns true based on min share size' );

            Apache2::SizeLimit->set_min_shared_size(0);
            Apache2::SizeLimit->set_max_unshared_size(1);

            ok( Apache2::SizeLimit->_limits_are_exceeded(),
                'check that _limits_are_exceeded() returns true based on max unshared size' );
        }
    }

    {
        # Lame test - A way to check that setting this _does_
        # something would be welcome ;)
        Apache2::SizeLimit->set_check_interval(10);
        is( $Apache2::SizeLimit::CHECK_EVERY_N_REQUESTS, 10,
            'set_check_interval set global' );
    }

    return Apache2::Const::OK;
}


1;