Debian Codegraph @

tests/t/lib/ProFTPD/Tests/Modules/mod_rlimit.pm

raw
1 package ProFTPD::Tests::Modules::mod_rlimit;
2
3 use lib qw(t/lib);
4 use base qw(ProFTPD::TestSuite::Child);
5 use strict;
6
7 use File::Path qw(mkpath);
8 use File::Spec;
9 use IO::Handle;
10
11 use ProFTPD::TestSuite::FTP;
12 use ProFTPD::TestSuite::Utils qw(:auth :config :running :test :testsuite);
13
14 $| = 1;
15
16 my $order = 0;
17
18 my $TESTS = {
19 rlimit_memory => {
20 order => ++$order,
21 test_class => [qw(forking)],
22 },
23
24 };
25
26 sub new {
27 return shift()->SUPER::new(@_);
28 }
29
30 sub list_tests {
31 return testsuite_get_runnable_tests($TESTS);
32 }
33
34 sub rlimit_memory {
35 my $self = shift;
36 my $tmpdir = $self->{tmpdir};
37 my $setup = test_setup($tmpdir, 'rlimit');
38
39 my $rlimit_mem = '32K';
40
41 my $config = {
42 PidFile => $setup->{pid_file},
43 ScoreboardFile => $setup->{scoreboard_file},
44 SystemLog => $setup->{log_file},
45 TraceLog => $setup->{log_file},
46 Trace => 'response:10',
47
48 AuthUserFile => $setup->{auth_user_file},
49 AuthGroupFile => $setup->{auth_group_file},
50 AuthOrder => 'mod_auth_file.c',
51
52 IfModules => {
53 'mod_delay.c' => {
54 DelayEngine => 'off',
55 },
56
57 'mod_rlimit.c' => {
58 RLimitMemory => "session $rlimit_mem $rlimit_mem",
59 },
60 },
61 };
62
63 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
64 $config);
65
66 # Open pipes, for use between the parent and child processes. Specifically,
67 # the child will indicate when it's done with its test by writing a message
68 # to the parent.
69 my ($rfh, $wfh);
70 unless (pipe($rfh, $wfh)) {
71 die("Can't open pipe: $!");
72 }
73
74 my $ex;
75
76 # Fork child
77 $self->handle_sigchld();
78 defined(my $pid = fork()) or die("Can't fork: $!");
79 if ($pid) {
80 eval {
81 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
82 $client->login($setup->{user}, $setup->{passwd});
83
84 my $conn = $client->stor_raw('test.dat');
85 unless ($conn) {
86 die("STOR failed: " . $client->response_code() . ' ' .
87 $client->response_msg());
88 }
89
90 my $count = 100;
91 my $buf = 'AbCdEfGh' x 8192;
92 for (my $i = 0; $i < $count; $i++) {
93 $conn->write($buf, length($buf), 15);
94 }
95 eval { $conn->close() };
96
97 my $resp_code = $client->response_code();
98 my $resp_msg = $client->response_msg();
99 $self->assert_transfer_ok($resp_code, $resp_msg);
100
101 $client->quit();
102 };
103
104 if ($@) {
105 $ex = $@;
106 }
107
108 $wfh->print("done\n");
109 $wfh->flush();
110
111 } else {
112 eval { server_wait($setup->{config_file}, $rfh) };
113 if ($@) {
114 warn($@);
115 exit 1;
116 }
117
118 exit 0;
119 }
120
121 # Stop server
122 server_stop($setup->{pid_file});
123
124 $self->assert_child_ok($pid);
125
126 test_cleanup($setup->{log_file}, $ex);
127 }
128
129 1;