lib/Apache/TestConfig.pm

filter: Statementstmt 26.1% 253 / 967 Branchbran 9.9% 37 / 372 Conditioncond 20.9% 56 / 268 MC/DCmcdc 0.0% 0 / 155 Subroutinesub 34.0% 47 / 138 Podpod 5.3% 5 / 94 totaltotal 19.9% 398 / 1994 CC 319 SCAR 43.6
CC
319
Cov
22%
new
245.9
parse_vhost
210.0
need_reconfiguration
210.0
CRAP 78.6
« lib/Apache/TestConfigPerl.pm ↑ Summary lib/Apache/TestRequest.pm »
1 # Licensed to the Apache Software Foundation (ASF) under one or more
2 # contributor license agreements. See the NOTICE file distributed with
3 # this work for additional information regarding copyright ownership.
4 # The ASF licenses this file to You under the Apache License, Version 2.0
5 # (the "License"); you may not use this file except in compliance with
6 # the License. You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16 package Apache::TestConfig;
17  
18 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 ▶use constant WIN32 => $^O eq 'MSWin32';
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use constant OSX => $^O eq 'darwin';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use constant CYGWIN => $^O eq 'cygwin';
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use constant NETWARE => $^O eq 'NetWare';
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use constant SOLARIS => $^O eq 'solaris';
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use constant AIX => $^O eq 'aix';
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use constant WINFU => WIN32 || NETWARE;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use constant COLOR => ($ENV{APACHE_TEST_COLOR} && -t STDOUT) ? 1 : 0;
Subroutine BEGIN: called CC=3 SCAR=12.5
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'APACHE_TEST_COLOR'} && -t STDOUT ? : 0 1 1
Condition33%1/3
$ENV{"APACHE_TEST_COLOR"} and -t STDOUT
!ll&&!rl&&r
100
MC/DC0%0/2
$ENV{"APACHE_TEST_COLOR"} and -t STDOUT
$ENV{"APACHE_TEST_COLOR"} -t STDOUT
Truth table33%1/3
A and B
A= $ENV{"APACHE_TEST_COLOR"}B= -t STDOUT
ABresult
0X0
100
111
29  
30 1 ▶use constant DEFAULT_PORT => 8529;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 1 ▶use constant IS_MOD_PERL_2 =>
Subroutine BEGIN: called CC=2 SCAR=7.0
33 1 ▶ eval { require mod_perl2 } || 0;
Condition50%1/2
eval { do { require mod_perl2 } } || 0
l!l
01
MC/DC0%0/1
eval { do { require mod_perl2 } } || 0
eval { do { require mod_perl2 } }
Truth table50%1/2
A
A= eval { do { require mod_perl2 } }
Aresult
11
00
34  
35 1 ▶use constant IS_MOD_PERL_2_BUILD => IS_MOD_PERL_2 &&
Subroutine BEGIN: called CC=1 SCAR=0.0
36 1 eval { require Apache2::Build && Apache2::Build::IS_MOD_PERL_BUILD() };
37  
38 1 ▶use constant IS_APACHE_TEST_BUILD =>
Subroutine BEGIN: called CC=1 SCAR=0.0
39 1 grep { -e "$_/lib/Apache/TestConfig.pm" }
40 1 qw(Apache-Test . .. ../Apache-Test);
41  
42 1 ▶use lib ();
Subroutine BEGIN: called CC=1 SCAR=0.0
43 1 ▶use File::Copy ();
Subroutine BEGIN: called CC=1 SCAR=0.0
44 1 ▶use File::Find qw(finddepth);
Subroutine BEGIN: called CC=1 SCAR=0.0
45 1 ▶use File::Basename qw(dirname);
Subroutine BEGIN: called CC=1 SCAR=0.0
46 1 ▶use File::Path ();
Subroutine BEGIN: called CC=1 SCAR=0.0
47 1 ▶use File::Spec::Functions qw(catfile abs2rel splitdir canonpath
Subroutine BEGIN: called CC=1 SCAR=0.0
48 1 catdir file_name_is_absolute devnull);
49 1 ▶use Cwd qw(fastcwd);
Subroutine BEGIN: called CC=1 SCAR=0.0
50 1 ▶use Socket ();
Subroutine BEGIN: called CC=1 SCAR=0.0
51 1 ▶use Symbol ();
Subroutine BEGIN: called CC=1 SCAR=0.0
52  
53 1 ▶use Apache::TestConfigPerl ();
Subroutine BEGIN: called CC=1 SCAR=0.0
54 1 ▶use Apache::TestConfigParse ();
Subroutine BEGIN: called CC=1 SCAR=0.0
55 1 ▶use Apache::TestTrace;
Subroutine BEGIN: called CC=1 SCAR=0.0
56 1 ▶use Apache::TestServer ();
Subroutine BEGIN: called CC=1 SCAR=0.0
57 1 ▶use Apache::TestRun ();
Subroutine BEGIN: called CC=1 SCAR=0.0
58  
59 1 ▶use vars qw(%Usage);
Subroutine BEGIN: called CC=1 SCAR=0.0
60  
61 %Usage = (
62 top_dir => 'top-level directory (default is $PWD)',
63 t_dir => 'the t/ test directory (default is $top_dir/t)',
64 t_conf => 'the conf/ test directory (default is $t_dir/conf)',
65 t_logs => 'the logs/ test directory (default is $t_dir/logs)',
66 t_state => 'the state/ test directory (default is $t_dir/state)',
67 t_pid_file => 'location of the pid file (default is $t_logs/httpd.pid)',
68 t_conf_file => 'test httpd.conf file (default is $t_conf/httpd.conf)',
69 src_dir => 'source directory to look for mod_foos.so',
70 serverroot => 'ServerRoot (default is $t_dir)',
71 documentroot => 'DocumentRoot (default is $ServerRoot/htdocs',
72 port => 'Port [port_number|select] (default ' . DEFAULT_PORT . ')',
73 servername => 'ServerName (default is localhost)',
74 user => 'User to run test server as (default is $USER)',
75 group => 'Group to run test server as (default is $GROUP)',
76 bindir => 'Apache bin/ dir (default is apxs -q BINDIR)',
77 sbindir => 'Apache sbin/ dir (default is apxs -q SBINDIR)',
78 httpd => 'server to use for testing (default is $bindir/httpd)',
79 target => 'name of server binary (default is apxs -q TARGET)',
80 apxs => 'location of apxs (default is from Apache2::BuildConfig)',
81 startup_timeout => 'seconds to wait for the server to start (default is 60)',
82 httpd_conf => 'inherit config from this file (default is apxs derived)',
83 httpd_conf_extra => 'inherit additional config from this file',
84 minclients => 'minimum number of concurrent clients (default is 1)',
85 maxclients => 'maximum number of concurrent clients (default is minclients+1)',
86 threadsperchild => 'number of threads per child when using threaded MPMs (default is 10)',
87 limitrequestline => 'global LimitRequestLine setting (default is 128)',
88 perlpod => 'location of perl pod documents (for testing downloads)',
89 proxyssl_url => 'url for testing ProxyPass / https (default is localhost)',
90 sslca => 'location of SSL CA (default is $t_conf/ssl/ca)',
91 sslcaorg => 'SSL CA organization to use for tests (default is asf)',
92 sslproto => 'SSL/TLS protocol version(s) to test',
93 libmodperl => 'path to mod_perl\'s .so (full or relative to LIBEXECDIR)',
94 defines => 'values to add as -D defines (for example, "VAR1 VAR2")',
95 1 (map { $_ . '_module_name', "$_ module name"} qw(cgi ssl thread access auth php)),
96 );
97  
98 1 my %filepath_conf_opts = map { $_ => 1 }
99 qw(top_dir t_dir t_conf t_logs t_state t_pid_file t_conf_file src_dir serverroot
100 documentroot bindir sbindir httpd apxs httpd_conf httpd_conf_extra
101 perlpod sslca libmodperl);
102  
103 0 ▶sub conf_opt_is_a_filepath {
Subroutine conf_opt_is_a_filepath: not called CC=2 SCAR=17.9
Pod undocumented
104 0 my $opt = shift;
105 0 ▶ $opt && exists $filepath_conf_opts{$opt};
Branch: 1 branch
BranchTrueFalseTotal
$opt and exists $filepath_conf_opts{$opt} 0 0 0
106 }
107  
108 0 ▶sub usage {
Subroutine usage: not called CC=3 SCAR=24.8
Pod undocumented
109 0 for my $hash (\%Usage) {
110 0 for (sort keys %$hash){
111 0 printf " -%-18s %s\n", $_, $hash->{$_};
112 }
113 }
114 }
115  
116 0 ▶sub filter_args {
Subroutine filter_args: not called CC=7 SCAR=40.3
Pod undocumented
117 0 my($args, $wanted_args) = @_;
118 0 my(@pass, %keep);
119  
120 0 my @filter = @$args;
121  
122 0 ▶ if (ref($filter[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $filter[0]) 0 0 0
123 0 push @pass, shift @filter;
124 }
125  
126 0 ▶ while (@filter) {
Branch: 1 branch
BranchTrueFalseTotal
if (@filter) 0 0 0
127 0 my $key = shift @filter;
128 # optinal - or -- prefix
129 0 ▶ if (defined $key && $key =~ /^-?-?(.+)/ && exists $wanted_args->{$1}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key and $key =~ /^-?-?(.+)/ and exists $wanted_args->{$1}) { } 0 0 0
Condition0%0/6
defined $key and $key =~ /^-?-?(.+)/ and exists $wanted_args->{$1}
!ll&&!rl&&r
000
defined $key and $key =~ /^-?-?(.+)/
!ll&&!rl&&r
000
MC/DC0%0/3
defined $key and $key =~ /^-?-?(.+)/ and exists $wanted_args->{$1}
defined $key $key =~ /^-?-?(.+)/ exists $wanted_args->{$1}
Truth table0%0/4
A and B and C
A= defined $keyB= $key =~ /^-?-?(.+)/C= exists $wanted_args->{$1}
ABCresult
0XX0
10X0
1100
1111
130 0 ▶ if (@filter) {
Branch: 1 branch
BranchTrueFalseTotal
if (@filter) { } 0 0 0
131 0 $keep{$1} = shift @filter;
132 }
133 else {
134 0 die "key $1 requires a matching value";
135 }
136 }
137 else {
138 0 push @pass, $key;
139 }
140 }
141  
142 0 return (\@pass, \%keep);
143 }
144  
145 1 my %passenv = map { $_,1 } qw{
146 APACHE_TEST_APXS
147 APACHE_TEST_HTTPD
148 APACHE_TEST_GROUP
149 APACHE_TEST_USER
150 APACHE_TEST_PORT
151 };
152  
153 1 ▶sub passenv {
Subroutine passenv: called CC=1 SCAR=0.0
Pod undocumented
154 1 \%passenv;
155 }
156  
157 0 ▶sub passenv_makestr {
Subroutine passenv_makestr: not called CC=2 SCAR=17.9
Pod undocumented
158 0 my @vars;
159  
160 0 for (sort keys %passenv) {
161 0 push @vars, "$_=\$($_)";
162 }
163  
164 0 "@vars";
165 }
166  
167 2 ▶sub server { shift->{server} }
Subroutine server: called CC=1 SCAR=0.0
Pod undocumented
168  
169 0 ▶sub modperl_build_config {
Subroutine modperl_build_config: not called CC=7 SCAR=40.3
Pod undocumented
170  
171 0 my $self = shift;
172  
173 0 ▶ my $server = ref $self ? $self->server : new_test_server();
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 0 0
174  
175 # we can't do this if we're using httpd 1.3.X
176 # even if mod_perl2 is installed on the box
177 # similarly, we shouldn't be loading mp2 if we're not
178 # absolutely certain we're in a 2.X environment yet
179 # (such as mod_perl's own build or runtime environment)
180 0 ▶ if (($server->{rev} && $server->{rev} == 2) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($server->{"rev"} and $server->{"rev"} == 2 or 0 or $ENV{"MOD_PERL_API_VERSION"}) 0 0 0
Condition0%0/8
$server->{"rev"} and $server->{"rev"} == 2 or 0 or $ENV{"MOD_PERL_API_VERSION"}
l!l&&r!l&&!r
000
$server->{"rev"} and $server->{"rev"} == 2 or 0
l!l
00
$server->{"rev"} and $server->{"rev"} == 2
!ll&&!rl&&r
000
MC/DC0%0/3
$server->{"rev"} and $server->{"rev"} == 2 or 0 or $ENV{"MOD_PERL_API_VERSION"}
$server->{"rev"} $server->{"rev"} == 2 $ENV{"MOD_PERL_API_VERSION"}
Truth table0%0/5
A and B or C
A= $server->{"rev"}B= $server->{"rev"} == 2C= $ENV{"MOD_PERL_API_VERSION"}
ABCresult
11X1
0X11
1011
0X00
1000
181 IS_MOD_PERL_2_BUILD || $ENV{MOD_PERL_API_VERSION}) {
182 0 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Apache2::Build } } or return 0 0 0
183 0 require Apache2::Build;
184 } or return;
185  
186 0 return Apache2::Build->build_config;
187 }
188  
189 0 return;
190 }
191  
192 2 ▶sub new_test_server {
Subroutine new_test_server: called CC=2 SCAR=8.1
Pod undocumented
193 2 my($self, $args) = @_;
194 2 ▶ Apache::TestServer->new($args || $self)
Condition33%1/3
$args || $self
l!l&&r!l&&!r
020
MC/DC0%0/2
$args || $self
$args $self
Truth table33%1/3
A || B
A= $argsB= $self
ABresult
1X1
011
000
195 }
196  
197 # setup httpd-independent components
198 # for httpd-specific call $self->httpd_config()
199 2 ▶sub new {
Subroutine new: called CC=57 SCAR=55.0
Pod undocumented
200 2 my $class = shift;
201  
202 2 my $args;
203  
204 2 ▶ $args = shift if $_[0] and ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] and ref $_[0] 2 0 2
Condition33%1/3
$_[0] and ref $_[0]
!ll&&!rl&&r
002
MC/DC0%0/2
$_[0] and ref $_[0]
$_[0] ref $_[0]
Truth table33%1/3
A and B
A= $_[0]B= ref $_[0]
ABresult
0X0
100
111
205  
206 2 ▶ $args = $args ? {%$args} : {@_}; #copy
Branch: 1 branch
BranchTrueFalseTotal
$args ? : 2 0 2
207  
208 #see Apache::TestMM::{filter_args,generate_script}
209 #we do this so 'perl Makefile.PL' can be passed options such as apxs
210 #without forcing regeneration of configuration and recompilation of c-modules
211 #as 't/TEST apxs /path/to/apache/bin/apxs' would do
212 2 ▶ while (my($key, $val) = each %Apache::TestConfig::Argv) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %Apache::TestConfig::Argv) 0 2 2
213 0 $args->{$key} = $val;
214 }
215  
216 2 my $top_dir = fastcwd;
217 2 $top_dir = pop_dir($top_dir, 't');
218 # untaint as we are going to use it a lot later on in -T sensitive
219 # operations (.e.g @INC)
220 2 ▶ $top_dir = $1 if $top_dir =~ /(.*)/;
Branch: 1 branch
BranchTrueFalseTotal
if $top_dir =~ /(.*)/ 2 0 2
221  
222 # make sure that t/conf/apache_test_config.pm is found
223 # (unfortunately sometimes we get thrown into / by Apache so we
224 # can't just rely on $top_dir
225 2 lib->import($top_dir);
226  
227 2 my $thaw = {};
228 #thaw current config
229 2 for (qw(conf t/conf)) {
230 4 ▶ last if eval {
Branch: 1 branch
BranchTrueFalseTotal
if eval { do { require "$_/apache_test_config.pm"; $thaw = "apache_test_config"->new; delete $thaw->{"save"}; bless $thaw, "Apache::TestConfig" } } 0 4 4
231 4 require "$_/apache_test_config.pm";
232 0 $thaw = 'apache_test_config'->new;
233 0 delete $thaw->{save};
234 #incase class that generated the config was
235 #something else, which we can't be sure how to load
236 0 bless $thaw, 'Apache::TestConfig';
237 };
238 }
239  
240 2 ▶ if ($args->{thaw} and ref($thaw) ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"thaw"} and ref $thaw ne "HASH") 0 2 2
Condition66%2/3
$args->{"thaw"} and ref $thaw ne "HASH"
!ll&&!rl&&r
110
MC/DC0%0/2
$args->{"thaw"} and ref $thaw ne "HASH"
$args->{"thaw"} ref $thaw ne "HASH"
Truth table66%2/3
A and B
A= $args->{"thaw"}B= ref $thaw ne "HASH"
ABresult
0X0
100
111
241 #dont generate any new config
242 0 $thaw->{vars}->{$_} = $args->{$_} for keys %$args;
243 0 $thaw->{server} = $thaw->new_test_server;
244 0 $thaw->add_inc;
245 0 return $thaw;
246 }
247  
248 #regenerating config, so forget old
249 2 ▶ if ($args->{save}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"save"}) 1 1 2
250 1 for (qw(vhosts inherit_config modules inc cmodules)) {
251 5 ▶ delete $thaw->{$_} if exists $thaw->{$_};
Branch: 1 branch
BranchTrueFalseTotal
if exists $thaw->{$_} 0 5 5
252 }
253 }
254  
255 2 ▶ my $self = bless {
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
256 clean => {},
257 vhosts => {},
258 inherit_config => {},
259 modules => {},
260 inc => [],
261 %$thaw,
262 mpm => "",
263 httpd_defines => {},
264 vars => $args,
265 postamble => [],
266 preamble => [],
267 postamble_hooks => [],
268 preamble_hooks => [],
269 }, ref($class) || $class;
270  
271 2 my $vars = $self->{vars}; #things that can be overridden
272  
273 2 for (qw(save verbose)) {
274 4 ▶ next unless exists $args->{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args->{$_} 2 2 4
275 2 $self->{$_} = delete $args->{$_};
276 }
277  
278 2 ▶ $vars->{top_dir} ||= $top_dir;
Condition33%1/3
$vars->{"top_dir"} ||= $top_dir
l!l&&r!l&&!r
020
MC/DC0%0/2
$vars->{"top_dir"} ||= $top_dir
$vars->{"top_dir"} $top_dir
Truth table33%1/3
A ||= B
A= $vars->{"top_dir"}B= $top_dir
ABresult
1X1
011
000
279  
280 2 $self->add_inc;
281  
282 #help to find libmodperl.so
283 2 ▶ unless ($vars->{src_dir}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($vars->{"src_dir"}) 2 0 2
284 2 my $src_dir = catfile $vars->{top_dir}, qw(.. src modules perl);
285  
286 2 ▶ if (-d $src_dir) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $src_dir) { } 0 2 2
287 0 $vars->{src_dir} = $src_dir;
288 } else {
289 2 $src_dir = catfile $vars->{top_dir}, qw(src modules perl);
290 2 ▶ $vars->{src_dir} = $src_dir if -d $src_dir;
Branch: 1 branch
BranchTrueFalseTotal
if -d $src_dir 0 2 2
291 }
292 }
293  
294 2 ▶ $vars->{t_dir} ||= catfile $vars->{top_dir}, 't';
Condition33%1/3
$vars->{"t_dir"} ||= catfile($vars->{"top_dir"}, "t")
l!l&&r!l&&!r
020
MC/DC0%0/2
$vars->{"t_dir"} ||= catfile($vars->{"top_dir"}, "t")
$vars->{"t_dir"} catfile($vars->{"top_dir"}, "t")
Truth table33%1/3
A ||= B
A= $vars->{"t_dir"}B= catfile($vars->{"top_dir"}, "t")
ABresult
1X1
011
000
295 2 ▶ $vars->{serverroot} ||= $vars->{t_dir};
Condition33%1/3
$vars->{"serverroot"} ||= $vars->{"t_dir"}
l!l&&r!l&&!r
020
MC/DC0%0/2
$vars->{"serverroot"} ||= $vars->{"t_dir"}
$vars->{"serverroot"} $vars->{"t_dir"}
Truth table33%1/3
A ||= B
A= $vars->{"serverroot"}B= $vars->{"t_dir"}
ABresult
1X1
011
000
296 2 ▶ $vars->{documentroot} ||= catfile $vars->{serverroot}, 'htdocs';
Condition33%1/3
$vars->{"documentroot"} ||= catfile($vars->{"serverroot"}, "htdocs")
l!l&&r!l&&!r
020
MC/DC0%0/2
$vars->{"documentroot"} ||= catfile($vars->{"serverroot"}, "htdocs")
$vars->{"documentroot"} catfile($vars->{"serverroot"}, "htdocs")
Truth table33%1/3
A ||= B
A= $vars->{"documentroot"}B= catfile($vars->{"serverroot"}, "htdocs")
ABresult
1X1
011
000
297 2 ▶ $vars->{perlpod} ||= $self->find_in_inc('pods') ||
Condition33%2/6
$vars->{"perlpod"} ||= $self->find_in_inc("pods") || $self->find_in_inc("pod")
l!l&&r!l&&!r
020
$self->find_in_inc('pods') || $self->find_in_inc('pod')
l!l&&r!l&&!r
020
MC/DC0%0/3
$vars->{"perlpod"} ||= $self->find_in_inc("pods") || $self->find_in_inc("pod")
$vars->{"perlpod"} $self->find_in_inc('pods') $self->find_in_inc('pod')
Truth table0%0/4
A ||= B || C
A= $vars->{"perlpod"}B= $self->find_in_inc('pods')C= $self->find_in_inc('pod')
ABCresult
1XX1
01X1
0011
0000
298 $self->find_in_inc('pod');
299 2 ▶ $vars->{perl} ||= $^X;
Condition33%1/3
$vars->{"perl"} ||= $^X
l!l&&r!l&&!r
020
MC/DC0%0/2
$vars->{"perl"} ||= $^X
$vars->{"perl"} $^X
Truth table33%1/3
A ||= B
A= $vars->{"perl"}B= $^X
ABresult
1X1
011
000
300 2 ▶ $vars->{t_conf} ||= catfile $vars->{serverroot}, 'conf';
Condition33%1/3
$vars->{"t_conf"} ||= catfile($vars->{"serverroot"}, "conf")
l!l&&r!l&&!r
020
MC/DC0%0/2
$vars->{"t_conf"} ||= catfile($vars->{"serverroot"}, "conf")
$vars->{"t_conf"} catfile($vars->{"serverroot"}, "conf")
Truth table33%1/3
A ||= B
A= $vars->{"t_conf"}B= catfile($vars->{"serverroot"}, "conf")
ABresult
1X1
011
000
301 2 ▶ $vars->{sslca} ||= catfile $vars->{t_conf}, 'ssl', 'ca';
Condition33%1/3
$vars->{"sslca"} ||= catfile($vars->{"t_conf"}, "ssl", "ca")
l!l&&r!l&&!r
020
MC/DC0%0/2
$vars->{"sslca"} ||= catfile($vars->{"t_conf"}, "ssl", "ca")
$vars->{"sslca"} catfile($vars->{"t_conf"}, "ssl", "ca")
Truth table33%1/3
A ||= B
A= $vars->{"sslca"}B= catfile($vars->{"t_conf"}, "ssl", "ca")
ABresult
1X1
011
000
302 2 ▶ $vars->{sslcaorg} ||= 'asf';
Condition50%1/2
$vars->{"sslcaorg"} ||= "asf"
l!l
02
MC/DC0%0/1
$vars->{"sslcaorg"} ||= "asf"
$vars->{"sslcaorg"}
Truth table50%1/2
A
A= $vars->{"sslcaorg"}
Aresult
11
00
303  
304 2 ▶ if (!defined($vars->{sslproto}) and eval { require Apache::TestSSLCA; 1; }) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $vars->{'sslproto'} and eval { do { require Apache::TestSSLCA; 1 } }) { } 2 0 2
Condition33%1/3
not defined $vars->{"sslproto"} and eval { do { require Apache::TestSSLCA; 1 } }
!ll&&!rl&&r
002
MC/DC0%0/2
not defined $vars->{"sslproto"} and eval { do { require Apache::TestSSLCA; 1 } }
not defined $vars->{"sslproto"} eval { do { require Apache::TestSSLCA; 1 } }
Truth table33%1/3
not(A) and B
A= not defined $vars->{"sslproto"}B= eval { do { require Apache::TestSSLCA; 1 } }
ABresult
0X0
100
111
305 2 $vars->{sslproto} = Apache::TestSSLCA::sslproto();
306 }
307 else {
308 0 ▶ $vars->{sslproto} ||= 'all';
Condition0%0/2
$vars->{"sslproto"} ||= "all"
l!l
00
MC/DC0%0/1
$vars->{"sslproto"} ||= "all"
$vars->{"sslproto"}
Truth table0%0/2
A
A= $vars->{"sslproto"}
Aresult
11
00
309 }
310  
311 2 ▶ $vars->{t_logs} ||= catfile $vars->{serverroot}, 'logs';
Condition33%1/3
$vars->{"t_logs"} ||= catfile($vars->{"serverroot"}, "logs")
l!l&&r!l&&!r
020
MC/DC0%0/2
$vars->{"t_logs"} ||= catfile($vars->{"serverroot"}, "logs")
$vars->{"t_logs"} catfile($vars->{"serverroot"}, "logs")
Truth table33%1/3
A ||= B
A= $vars->{"t_logs"}B= catfile($vars->{"serverroot"}, "logs")
ABresult
1X1
011
000
312 2 ▶ $vars->{t_state} ||= catfile $vars->{serverroot}, 'state';
Condition33%1/3
$vars->{"t_state"} ||= catfile($vars->{"serverroot"}, "state")
l!l&&r!l&&!r
020
MC/DC0%0/2
$vars->{"t_state"} ||= catfile($vars->{"serverroot"}, "state")
$vars->{"t_state"} catfile($vars->{"serverroot"}, "state")
Truth table33%1/3
A ||= B
A= $vars->{"t_state"}B= catfile($vars->{"serverroot"}, "state")
ABresult
1X1
011
000
313 2 ▶ $vars->{t_conf_file} ||= catfile $vars->{t_conf}, 'httpd.conf';
Condition33%1/3
$vars->{"t_conf_file"} ||= catfile($vars->{"t_conf"}, "httpd.conf")
l!l&&r!l&&!r
020
MC/DC0%0/2
$vars->{"t_conf_file"} ||= catfile($vars->{"t_conf"}, "httpd.conf")
$vars->{"t_conf_file"} catfile($vars->{"t_conf"}, "httpd.conf")
Truth table33%1/3
A ||= B
A= $vars->{"t_conf_file"}B= catfile($vars->{"t_conf"}, "httpd.conf")
ABresult
1X1
011
000
314 2 ▶ $vars->{t_pid_file} ||= catfile $vars->{t_logs}, 'httpd.pid';
Condition33%1/3
$vars->{"t_pid_file"} ||= catfile($vars->{"t_logs"}, "httpd.pid")
l!l&&r!l&&!r
020
MC/DC0%0/2
$vars->{"t_pid_file"} ||= catfile($vars->{"t_logs"}, "httpd.pid")
$vars->{"t_pid_file"} catfile($vars->{"t_logs"}, "httpd.pid")
Truth table33%1/3
A ||= B
A= $vars->{"t_pid_file"}B= catfile($vars->{"t_logs"}, "httpd.pid")
ABresult
1X1
011
000
315  
316 2 if (WINFU) {
317 for (keys %$vars) {
318 $vars->{$_} =~ s|\\|\/|g if defined $vars->{$_};
319 }
320 }
321  
322 2 ▶ $vars->{scheme} ||= 'http';
Condition50%1/2
$vars->{"scheme"} ||= "http"
l!l
02
MC/DC0%0/1
$vars->{"scheme"} ||= "http"
$vars->{"scheme"}
Truth table50%1/2
A
A= $vars->{"scheme"}
Aresult
11
00
323 2 ▶ $vars->{servername} ||= $self->default_servername;
Condition33%1/3
$vars->{"servername"} ||= $self->default_servername
l!l&&r!l&&!r
020
MC/DC0%0/2
$vars->{"servername"} ||= $self->default_servername
$vars->{"servername"} $self->default_servername
Truth table33%1/3
A ||= B
A= $vars->{"servername"}B= $self->default_servername
ABresult
1X1
011
000
324 2 $vars->{port} = $self->select_first_port;
325 2 ▶ $vars->{remote_addr} ||= $self->our_remote_addr;
Condition33%1/3
$vars->{"remote_addr"} ||= $self->our_remote_addr
l!l&&r!l&&!r
020
MC/DC0%0/2
$vars->{"remote_addr"} ||= $self->our_remote_addr
$vars->{"remote_addr"} $self->our_remote_addr
Truth table33%1/3
A ||= B
A= $vars->{"remote_addr"}B= $self->our_remote_addr
ABresult
1X1
011
000
326  
327 2 ▶ $vars->{user} ||= $self->default_user;
Condition33%1/3
$vars->{"user"} ||= $self->default_user
l!l&&r!l&&!r
020
MC/DC0%0/2
$vars->{"user"} ||= $self->default_user
$vars->{"user"} $self->default_user
Truth table33%1/3
A ||= B
A= $vars->{"user"}B= $self->default_user
ABresult
1X1
011
000
328 2 ▶ $vars->{group} ||= $self->default_group;
Condition33%1/3
$vars->{"group"} ||= $self->default_group
l!l&&r!l&&!r
020
MC/DC0%0/2
$vars->{"group"} ||= $self->default_group
$vars->{"group"} $self->default_group
Truth table33%1/3
A ||= B
A= $vars->{"group"}B= $self->default_group
ABresult
1X1
011
000
329 2 ▶ $vars->{serveradmin} ||= $self->default_serveradmin;
Condition33%1/3
$vars->{"serveradmin"} ||= $self->default_serveradmin
l!l&&r!l&&!r
020
MC/DC0%0/2
$vars->{"serveradmin"} ||= $self->default_serveradmin
$vars->{"serveradmin"} $self->default_serveradmin
Truth table33%1/3
A ||= B
A= $vars->{"serveradmin"}B= $self->default_serveradmin
ABresult
1X1
011
000
330  
331 2 ▶ $vars->{threadsperchild} ||= 10;
Condition50%1/2
$vars->{"threadsperchild"} ||= 10
l!l
02
MC/DC0%0/1
$vars->{"threadsperchild"} ||= 10
$vars->{"threadsperchild"}
Truth table50%1/2
A
A= $vars->{"threadsperchild"}
Aresult
11
00
332 2 ▶ $vars->{minclients} ||= 1;
Condition50%1/2
$vars->{"minclients"} ||= 1
l!l
02
MC/DC0%0/1
$vars->{"minclients"} ||= 1
$vars->{"minclients"}
Truth table50%1/2
A
A= $vars->{"minclients"}
Aresult
11
00
333 2 ▶ $vars->{maxclients_preset} = $vars->{maxclients} || 0;
Condition50%1/2
$vars->{'maxclients'} || 0
l!l
02
MC/DC0%0/1
$vars->{'maxclients'} || 0
$vars->{'maxclients'}
Truth table50%1/2
A
A= $vars->{'maxclients'}
Aresult
11
00
334 # if maxclients wasn't explicitly passed try to
335 # prevent 'server reached MaxClients setting' errors
336 2 ▶ $vars->{maxclients} ||= $vars->{minclients} + 1;
Condition33%1/3
$vars->{"maxclients"} ||= $vars->{"minclients"} + 1
l!l&&r!l&&!r
020
MC/DC0%0/2
$vars->{"maxclients"} ||= $vars->{"minclients"} + 1
$vars->{"maxclients"} $vars->{"minclients"} + 1
Truth table33%1/3
A ||= B
A= $vars->{"maxclients"}B= $vars->{"minclients"} + 1
ABresult
1X1
011
000
337  
338 # if a preset maxclients valus is smaller than minclients,
339 # maxclients overrides minclients
340 2 ▶ if ($vars->{maxclients_preset} &&
Branch: 1 branch
BranchTrueFalseTotal
if ($vars->{"maxclients_preset"} and $vars->{"maxclients_preset"} < $vars->{"minclients"}) 0 2 2
Condition33%1/3
$vars->{"maxclients_preset"} and $vars->{"maxclients_preset"} < $vars->{"minclients"}
!ll&&!rl&&r
200
MC/DC0%0/2
$vars->{"maxclients_preset"} and $vars->{"maxclients_preset"} < $vars->{"minclients"}
$vars->{"maxclients_preset"} $vars->{"maxclients_preset"} < $vars->{"minclients"}
Truth table33%1/3
A and B
A= $vars->{"maxclients_preset"}B= $vars->{"maxclients_preset"} < $vars->{"minclients"}
ABresult
0X0
100
111
341 $vars->{maxclients_preset} < $vars->{minclients}) {
342 0 $vars->{minclients} = $vars->{maxclients_preset};
343 }
344 2 ▶ if ($vars->{minclients} < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vars->{'minclients'} < 2) { } 2 0 2
345 2 $vars->{maxspare} = 2;
346 } else {
347 0 $vars->{maxspare} = $vars->{minclients};
348 }
349 2 ▶ if ($vars->{maxclients} < $vars->{maxspare} + 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vars->{"maxclients"} < $vars->{"maxspare"} + 1) 2 0 2
350 2 $vars->{maxclients} = $vars->{maxspare} + 1;
351 }
352  
353 # for threaded mpms MinClients and MaxClients must be a
354 # multiple of ThreadsPerChild
355 {
356 1 ▶ use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
357 $vars->{minclientsthreadedmpm} = ($vars->{minclients} + $vars->{threadsperchild} - 1) /
358 2 $vars->{threadsperchild} * $vars->{threadsperchild};
359 $vars->{maxclientsthreadedmpm} = ($vars->{maxclients} + $vars->{threadsperchild} - 1) /
360 2 $vars->{threadsperchild} * $vars->{threadsperchild};
361 $vars->{maxsparethreadedmpm} = ($vars->{maxspare} + $vars->{threadsperchild} - 1) /
362 2 $vars->{threadsperchild} * $vars->{threadsperchild};
363 2 $vars->{startserversthreadedmpm} = $vars->{minclientsthreadedmpm} / $vars->{threadsperchild};
364 }
365 2 ▶ if ($vars->{maxsparethreadedmpm} < 2 * $vars->{threadsperchild}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vars->{"maxsparethreadedmpm"} < 2 * $vars->{"threadsperchild"}) 2 0 2
366 2 $vars->{maxsparethreadedmpm} = 2 * $vars->{threadsperchild};
367 }
368 2 ▶ if ($vars->{maxclientsthreadedmpm} < $vars->{maxsparethreadedmpm} + $vars->{threadsperchild}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vars->{"maxclientsthreadedmpm"} < $vars->{"maxsparethreadedmpm"} + $vars->{"threadsperchild"}) 2 0 2
369 2 $vars->{maxclientsthreadedmpm} = $vars->{maxsparethreadedmpm} + $vars->{threadsperchild};
370 }
371  
372 2 ▶ $vars->{limitrequestline} ||= 128;
Condition50%1/2
$vars->{"limitrequestline"} ||= 128
l!l
02
MC/DC0%0/1
$vars->{"limitrequestline"} ||= 128
$vars->{"limitrequestline"}
Truth table50%1/2
A
A= $vars->{"limitrequestline"}
Aresult
11
00
373 2 $vars->{limitrequestlinex2} = 2 * $vars->{limitrequestline};
374  
375 2 ▶ $vars->{proxy} ||= 'off';
Condition50%1/2
$vars->{"proxy"} ||= "off"
l!l
02
MC/DC0%0/1
$vars->{"proxy"} ||= "off"
$vars->{"proxy"}
Truth table50%1/2
A
A= $vars->{"proxy"}
Aresult
11
00
376 2 ▶ $vars->{proxyssl_url} ||= '';
Condition50%1/2
$vars->{"proxyssl_url"} ||= ""
l!l
02
MC/DC0%0/1
$vars->{"proxyssl_url"} ||= ""
$vars->{"proxyssl_url"}
Truth table50%1/2
A
A= $vars->{"proxyssl_url"}
Aresult
11
00
377 2 ▶ $vars->{defines} ||= '';
Condition50%1/2
$vars->{"defines"} ||= ""
l!l
02
MC/DC0%0/1
$vars->{"defines"} ||= ""
$vars->{"defines"}
Truth table50%1/2
A
A= $vars->{"defines"}
Aresult
11
00
378  
379 2 $self->{hostport} = $self->hostport;
380 2 $self->{server} = $self->new_test_server;
381  
382 2 return $self;
383  
384 }
385  
386 # figure out where httpd is and run extra config hooks which require
387 # knowledge of where httpd is
388 0 ▶sub httpd_config {
Subroutine httpd_config: not called CC=3 SCAR=24.8
Pod undocumented
389 0 my $self = shift;
390  
391 0 $self->configure_apxs;
392 0 $self->configure_httpd;
393  
394 0 my $vars = $self->{vars};
395 0 ▶ unless ($vars->{httpd} or $vars->{apxs}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vars->{'httpd'} or $vars->{'apxs'}) { } 0 0 0
Condition0%0/3
$vars->{"httpd"} or $vars->{"apxs"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$vars->{"httpd"} or $vars->{"apxs"}
$vars->{"httpd"} $vars->{"apxs"}
Truth table0%0/3
A or B
A= $vars->{"httpd"}B= $vars->{"apxs"}
ABresult
1X1
011
000
396  
397 # mod_perl 2.0 build (almost) always knows the right httpd
398  
399 # location (and optionally apxs). if we get here we can't
400 # continue because the interactive config can't work with
401 # mod_perl 2.0 build (by design)
402 0 if (IS_MOD_PERL_2_BUILD){
403 my $mp2_build = $self->modperl_build_config();
404 # if mod_perl 2 was built against the httpd source it
405 # doesn't know where to find apxs/httpd, so in this case
406 # fall back to interactive config
407 unless ($mp2_build->{MP_APXS}) {
408 die "mod_perl 2 was built against Apache sources, we " .
409 "don't know where httpd/apxs executables are, therefore " .
410 "skipping the test suite execution"
411 }
412  
413 # not sure what else could go wrong but we can't continue
414 die "something is wrong, mod_perl 2.0 build should have " .
415 "supplied all the needed information to run the tests. " .
416 "Please post lib/Apache2/BuildConfig.pm along with the " .
417 "bug report";
418 }
419  
420 0 $self->clean(1);
421  
422 0 error "You must explicitly specify -httpd and/or -apxs options, " .
423 "or set \$ENV{APACHE_TEST_HTTPD} and \$ENV{APACHE_TEST_APXS}, " .
424 "or set your \$PATH to include the httpd and apxs binaries.";
425 0 Apache::TestRun::exit_perl(1);
426  
427 }
428 else {
429 0 debug "Using httpd: $vars->{httpd}";
430 }
431  
432 0 $self->inherit_config; #see TestConfigParse.pm
433 0 $self->configure_httpd_eapi; #must come after inherit_config
434  
435 0 $self->default_module(cgi => [qw(mod_cgi mod_cgid)]);
436 0 $self->default_module(thread => [qw(worker threaded)]);
437 0 $self->default_module(ssl => [qw(mod_ssl)]);
438 0 $self->default_module(access => [qw(mod_access mod_authz_host)]);
439 0 $self->default_module(auth => [qw(mod_auth mod_auth_basic)]);
440 0 $self->default_module(php => [qw(sapi_apache2 mod_php4 mod_php5)]);
441  
442 0 $self->{server}->post_config;
443  
444 0 return $self;
445 }
446  
447 0 ▶sub default_module {
Subroutine default_module: not called CC=3 SCAR=24.8
Pod undocumented
448 0 my($self, $name, $choices) = @_;
449  
450 0 my $mname = $name . '_module_name';
451  
452 0 ▶ unless ($self->{vars}->{$mname}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"vars"}{$mname}) 0 0 0
453 ($self->{vars}->{$mname}) = grep {
454 0 $self->{modules}->{"$_.c"};
455 } @$choices;
456  
457 0 ▶ $self->{vars}->{$mname} ||= $choices->[0];
Condition0%0/3
$self->{"vars"}{$mname} ||= $choices->[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"vars"}{$mname} ||= $choices->[0]
$self->{"vars"}{$mname} $choices->[0]
Truth table0%0/3
A ||= B
A= $self->{"vars"}{$mname}B= $choices->[0]
ABresult
1X1
011
000
458 }
459  
460 $self->{vars}->{$name . '_module'} =
461 0 $self->{vars}->{$mname} . '.c'
462 }
463  
464 0 ▶sub configure_apxs {
Subroutine configure_apxs: not called CC=8 SCAR=42.8
Pod undocumented
465 0 my $self = shift;
466  
467 0 $self->{APXS} = $self->default_apxs;
468  
469 0 ▶ return unless $self->{APXS};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"APXS"} 0 0 0
470  
471 0 $self->{APXS} =~ s{/}{\\}g if WIN32;
472  
473 0 my $vars = $self->{vars};
474  
475 0 ▶ $vars->{bindir} ||= $self->apxs('BINDIR', 1);
Condition0%0/3
$vars->{"bindir"} ||= $self->apxs("BINDIR", 1)
l!l&&r!l&&!r
000
MC/DC0%0/2
$vars->{"bindir"} ||= $self->apxs("BINDIR", 1)
$vars->{"bindir"} $self->apxs("BINDIR", 1)
Truth table0%0/3
A ||= B
A= $vars->{"bindir"}B= $self->apxs("BINDIR", 1)
ABresult
1X1
011
000
476 0 ▶ $vars->{sbindir} ||= $self->apxs('SBINDIR');
Condition0%0/3
$vars->{"sbindir"} ||= $self->apxs("SBINDIR")
l!l&&r!l&&!r
000
MC/DC0%0/2
$vars->{"sbindir"} ||= $self->apxs("SBINDIR")
$vars->{"sbindir"} $self->apxs("SBINDIR")
Truth table0%0/3
A ||= B
A= $vars->{"sbindir"}B= $self->apxs("SBINDIR")
ABresult
1X1
011
000
477 0 ▶ $vars->{target} ||= $self->apxs('TARGET');
Condition0%0/3
$vars->{"target"} ||= $self->apxs("TARGET")
l!l&&r!l&&!r
000
MC/DC0%0/2
$vars->{"target"} ||= $self->apxs("TARGET")
$vars->{"target"} $self->apxs("TARGET")
Truth table0%0/3
A ||= B
A= $vars->{"target"}B= $self->apxs("TARGET")
ABresult
1X1
011
000
478 0 ▶ $vars->{conf_dir} ||= $self->apxs('SYSCONFDIR');
Condition0%0/3
$vars->{"conf_dir"} ||= $self->apxs("SYSCONFDIR")
l!l&&r!l&&!r
000
MC/DC0%0/2
$vars->{"conf_dir"} ||= $self->apxs("SYSCONFDIR")
$vars->{"conf_dir"} $self->apxs("SYSCONFDIR")
Truth table0%0/3
A ||= B
A= $vars->{"conf_dir"}B= $self->apxs("SYSCONFDIR")
ABresult
1X1
011
000
479  
480 0 ▶ if ($vars->{conf_dir}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vars->{"conf_dir"}) 0 0 0
481 0 ▶ $vars->{httpd_conf} ||= catfile $vars->{conf_dir}, 'httpd.conf';
Condition0%0/3
$vars->{"httpd_conf"} ||= catfile($vars->{"conf_dir"}, "httpd.conf")
l!l&&r!l&&!r
000
MC/DC0%0/2
$vars->{"httpd_conf"} ||= catfile($vars->{"conf_dir"}, "httpd.conf")
$vars->{"httpd_conf"} catfile($vars->{"conf_dir"}, "httpd.conf")
Truth table0%0/3
A ||= B
A= $vars->{"httpd_conf"}B= catfile($vars->{"conf_dir"}, "httpd.conf")
ABresult
1X1
011
000
482 }
483 }
484  
485 0 ▶sub configure_httpd {
Subroutine configure_httpd: not called CC=12 SCAR=50.5
Pod undocumented
486 0 my $self = shift;
487 0 my $vars = $self->{vars};
488  
489 0 debug "configuring httpd";
490  
491 0 ▶ $vars->{target} ||= (WIN32 ? 'Apache.EXE' : 'httpd');
Condition0%0/2
$vars->{"target"} ||= "httpd"
l!l
00
MC/DC0%0/1
$vars->{"target"} ||= "httpd"
$vars->{"target"}
Truth table0%0/2
A
A= $vars->{"target"}
Aresult
11
00
492  
493 0 ▶ unless ($vars->{httpd}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($vars->{"httpd"}) 0 0 0
494 #sbindir should be bin/ with the default layout
495 #but its eaiser to workaround apxs than fix apxs
496 0 for my $dir (map { $vars->{$_} } qw(sbindir bindir)) {
497 0 ▶ next unless defined $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dir 0 0 0
498 0 my $httpd = catfile $dir, $vars->{target};
499 0 ▶ next unless -x $httpd;
Branch: 1 branch
BranchTrueFalseTotal
unless -x $httpd 0 0 0
500 0 $vars->{httpd} = $httpd;
501 0 last;
502 }
503  
504 0 ▶ $vars->{httpd} ||= $self->default_httpd;
Condition0%0/3
$vars->{"httpd"} ||= $self->default_httpd
l!l&&r!l&&!r
000
MC/DC0%0/2
$vars->{"httpd"} ||= $self->default_httpd
$vars->{"httpd"} $self->default_httpd
Truth table0%0/3
A ||= B
A= $vars->{"httpd"}B= $self->default_httpd
ABresult
1X1
011
000
505 }
506  
507 0 ▶ if ($vars->{httpd}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vars->{"httpd"}) 0 0 0
508 0 my @chunks = splitdir $vars->{httpd};
509 #handle both $prefix/bin/httpd and $prefix/Apache.exe
510 0 for (1,2) {
511 0 pop @chunks;
512 0 ▶ last unless @chunks;
Branch: 1 branch
BranchTrueFalseTotal
unless @chunks 0 0 0
513 0 $self->{httpd_basedir} = catfile @chunks;
514 0 ▶ last if -d "$self->{httpd_basedir}/bin";
Branch: 1 branch
BranchTrueFalseTotal
if -d qq[$self->{"httpd_basedir"}/bin] 0 0 0
515 }
516 }
517  
518 #cleanup httpd droppings
519 0 my $sem = catfile $vars->{t_logs}, 'apache_runtime_status.sem';
520 0 ▶ unless (-e $sem) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $sem) 0 0 0
521 0 $self->clean_add_file($sem);
522 }
523 }
524  
525 0 ▶sub configure_httpd_eapi {
Subroutine configure_httpd_eapi: not called CC=3 SCAR=24.8
Pod undocumented
526 0 my $self = shift;
527 0 my $vars = $self->{vars};
528  
529 #deal with EAPI_MM_CORE_PATH if defined.
530 0 ▶ if (defined($self->{httpd_defines}->{EAPI_MM_CORE_PATH})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"httpd_defines"}{"EAPI_MM_CORE_PATH"}) 0 0 0
531 0 my $path = $self->{httpd_defines}->{EAPI_MM_CORE_PATH};
532  
533 #ensure the directory exists
534 0 my @chunks = splitdir $path;
535 0 pop @chunks; #the file component of the path
536 0 $path = catdir @chunks;
537 0 ▶ unless (file_name_is_absolute $path) {
Branch: 1 branch
BranchTrueFalseTotal
unless (file_name_is_absolute($path)) 0 0 0
538 0 $path = catdir $vars->{serverroot}, $path;
539 }
540 0 $self->gendir($path);
541 }
542 }
543  
544 0 ▶sub configure_proxy {
Subroutine configure_proxy: not called CC=3 SCAR=24.8
Pod undocumented
545 0 my $self = shift;
546 0 my $vars = $self->{vars};
547  
548 #if we proxy to ourselves, must bump the maxclients
549 0 ▶ if ($vars->{proxy} =~ /^on$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vars->{"proxy"} =~ /^on$/i) 0 0 0
550 0 ▶ unless ($vars->{maxclients_preset}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($vars->{"maxclients_preset"}) 0 0 0
551 0 $vars->{minclients}++;
552 0 $vars->{maxclients}++;
553 0 $vars->{maxspare}++;
554 0 $vars->{startserversthreadedmpm} ++;
555 0 $vars->{minclientsthreadedmpm} += $vars->{threadsperchild};
556 0 $vars->{maxclientsthreadedmpm} += $vars->{threadsperchild};
557 0 $vars->{maxsparethreadedmpm} += $vars->{threadsperchild};
558 #In addition allow for some backend processes
559 #in keep-alive state. For threaded MPMs we
560 #already should be fine.
561 0 $vars->{maxclients} += 3;
562 }
563 0 $vars->{proxy} = $self->{vhosts}->{'mod_proxy'}->{hostport};
564 0 return $vars->{proxy};
565 }
566  
567 0 return undef;
568 }
569  
570 # adds the config to the head of the group instead of the tail
571 # XXX: would be even better to add to a different sub-group
572 # (e.g. preamble_first) of only those that want to be first and then,
573 # make sure that they are dumped to the config file first in the same
574 # group (e.g. preamble)
575 0 ▶sub add_config_first {
Subroutine add_config_first: not called CC=1 SCAR=6.9
Pod undocumented
576 0 my $self = shift;
577 0 my $where = shift;
578 0 unshift @{ $self->{$where} }, $self->massage_config_args(@_);
579 }
580  
581 0 ▶sub add_config_last {
Subroutine add_config_last: not called CC=1 SCAR=6.9
Pod undocumented
582 0 my $self = shift;
583 0 my $where = shift;
584 0 push @{ $self->{$where} }, $self->massage_config_args(@_);
585 }
586  
587 0 ▶sub massage_config_args {
Subroutine massage_config_args: not called CC=10 SCAR=47.0
Pod undocumented
588 0 my $self = shift;
589 0 my($directive, $arg, $data) = @_;
590 0 my $args = "";
591  
592 0 ▶ if ($data) {
Branch: 2 branches
BranchTrueFalseTotal
if ($data) { } 0 0 0
elsif (ref $directive eq 'ARRAY') { } 0 0 0
593 0 $args = "<$directive $arg>\n";
594 0 ▶ if (ref($data) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $data eq 'HASH') { } 0 0 0
elsif (ref $data eq 'ARRAY') { } 0 0 0
595 0 ▶ while (my($k,$v) = each %$data) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$data) 0 0 0
596 0 $args .= " $k $v\n";
597 }
598 }
599 elsif (ref($data) eq 'ARRAY') {
600 # balanced (key=>val) list
601 0 my $pairs = @$data / 2;
602 0 for my $i (0..($pairs-1)) {
603 0 $args .= sprintf " %s %s\n", $data->[$i*2], $data->[$i*2+1];
604 }
605 }
606 else {
607 0 $data=~s/\n(?!\z)/\n /g;
608 0 $args .= " $data";
609 }
610 0 $args .= "</$directive>\n";
611 }
612 elsif (ref($directive) eq 'ARRAY') {
613 0 $args = join "\n", @$directive;
614 }
615 else {
616 0 ▶ $args = join " ", grep length($_), $directive,
Branch: 1 branch
BranchTrueFalseTotal
ref $arg && ref $arg eq 'ARRAY' ? : 0 0 0
Condition0%0/5
ref $arg and ref $arg eq "ARRAY"
!ll&&!rl&&r
000
$arg or ""
l!l
00
MC/DC0%0/2
ref $arg and ref $arg eq "ARRAY"
ref $arg ref $arg eq "ARRAY"
MC/DC0%0/1
$arg or ""
$arg
Truth table0%0/3
A and B
A= ref $argB= ref $arg eq "ARRAY"
ABresult
0X0
100
111
Truth table0%0/2
A
A= $arg
Aresult
11
00
617 (ref($arg) && (ref($arg) eq 'ARRAY') ? "@$arg" : $arg || "");
618 }
619  
620 0 return $args;
621 }
622  
623 0 ▶sub postamble_first {
Subroutine postamble_first: not called CC=1 SCAR=6.9
Pod undocumented
624 0 shift->add_config_first(postamble => @_);
625 }
626  
627 0 ▶sub postamble {
Subroutine postamble: not called CC=1 SCAR=6.9
Pod undocumented
628 0 shift->add_config_last(postamble => @_);
629 }
630  
631 0 ▶sub preamble_first {
Subroutine preamble_first: not called CC=1 SCAR=6.9
Pod undocumented
632 0 shift->add_config_first(preamble => @_);
633 }
634  
635 0 ▶sub preamble {
Subroutine preamble: not called CC=1 SCAR=6.9
Pod undocumented
636 0 shift->add_config_last(preamble => @_);
637 }
638  
639 0 ▶sub postamble_register {
Subroutine postamble_register: not called CC=1 SCAR=6.9
Pod undocumented
640 0 push @{ shift->{postamble_hooks} }, @_;
641 }
642  
643 0 ▶sub preamble_register {
Subroutine preamble_register: not called CC=1 SCAR=6.9
Pod undocumented
644 0 push @{ shift->{preamble_hooks} }, @_;
645 }
646  
647 0 ▶sub add_config_hooks_run {
Subroutine add_config_hooks_run: not called CC=6 SCAR=37.4
Pod undocumented
648 0 my($self, $where, $out) = @_;
649  
650 0 for (@{ $self->{"${where}_hooks"} }) {
651 0 ▶ if ((ref($_) and ref($_) eq 'CODE') or $self->can($_)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_ and ref $_ eq 'CODE' or $self->can($_)) { } 0 0 0
Condition0%0/6
ref $_ and ref $_ eq "CODE" or $self->can($_)
l!l&&r!l&&!r
000
ref $_ and ref $_ eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/3
ref $_ and ref $_ eq "CODE" or $self->can($_)
ref $_ ref $_ eq "CODE" $self->can($_)
Truth table0%0/5
A and B or C
A= ref $_B= ref $_ eq "CODE"C= $self->can($_)
ABCresult
11X1
0X11
1011
0X00
1000
652 0 $self->$_();
653 }
654 else {
655 0 error "cannot run configure hook: `$_'";
656 }
657 }
658  
659 0 for (@{ $self->{$where} }) {
660 0 $self->replace;
661 0 s/\n?$/\n/;
662 0 print $out "$_";
663 }
664 }
665  
666 0 ▶sub postamble_run {
Subroutine postamble_run: not called CC=1 SCAR=6.9
Pod undocumented
667 0 shift->add_config_hooks_run(postamble => @_);
668 }
669  
670 0 ▶sub preamble_run {
Subroutine preamble_run: not called CC=1 SCAR=6.9
Pod undocumented
671 0 shift->add_config_hooks_run(preamble => @_);
672 }
673  
674 2 ▶sub default_group {
Subroutine default_group: called CC=7 SCAR=28.4
Pod undocumented
675 2 return if WINFU;
676  
677 2 my $gid = $);
678  
679 #use only first value if $) contains more than one
680 2 $gid =~ s/^(\d+).*$/$1/;
681  
682 2 ▶ my $group = $ENV{APACHE_TEST_GROUP} || (getgrgid($gid) || "#$gid");
Condition40%2/5
$ENV{'APACHE_TEST_GROUP'} || (getgrgid $gid || "#$gid")
l!l&&r!l&&!r
020
getgrgid $gid or "#$gid"
l!l
20
MC/DC0%0/2
$ENV{'APACHE_TEST_GROUP'} || (getgrgid $gid || "#$gid")
$ENV{'APACHE_TEST_GROUP'} getgrgid $gid
Truth table33%1/3
A || B
A= $ENV{'APACHE_TEST_GROUP'}B= getgrgid $gid
ABresult
1X1
011
000
683  
684 2 ▶ if ($group eq 'root') {
Branch: 1 branch
BranchTrueFalseTotal
if ($group eq "root") 0 2 2
685 # similar to default_user, we want to avoid perms problems,
686 # when the server is started with group 'root'. When running
687 # under group root it may fail to create dirs and files,
688 # writable only by user
689 0 my $user = default_user();
690 0 ▶ my $gid = $user ? (getpwnam($user))[3] : '';
Branch: 1 branch
BranchTrueFalseTotal
$user ? : 0 0 0
691 0 ▶ $group = (getgrgid($gid) || "#$gid") if $gid;
Branch: 1 branch
BranchTrueFalseTotal
if $gid 0 0 0
Condition0%0/2
getgrgid $gid || "#$gid"
l!l
00
MC/DC0%0/1
getgrgid $gid || "#$gid"
getgrgid $gid
Truth table0%0/2
A
A= getgrgid $gid
Aresult
11
00
692 }
693  
694 2 $group;
695 }
696  
697 2 ▶sub default_user {
Subroutine default_user: called CC=5 SCAR=22.3
Pod undocumented
698 2 return if WINFU;
699  
700 2 my $uid = $>;
701  
702 2 ▶ my $user = $ENV{APACHE_TEST_USER} || (getpwuid($uid) || "#$uid");
Condition40%2/5
$ENV{'APACHE_TEST_USER'} || (getpwuid $uid || "#$uid")
l!l&&r!l&&!r
020
getpwuid $uid or "#$uid"
l!l
20
MC/DC0%0/2
$ENV{'APACHE_TEST_USER'} || (getpwuid $uid || "#$uid")
$ENV{'APACHE_TEST_USER'} getpwuid $uid
Truth table33%1/3
A || B
A= $ENV{'APACHE_TEST_USER'}B= getpwuid $uid
ABresult
1X1
011
000
703  
704 2 ▶ if ($user eq 'root') {
Branch: 1 branch
BranchTrueFalseTotal
if ($user eq "root") 0 2 2
705 0 my $other = (getpwnam('nobody'))[0];
706 0 ▶ if ($other) {
Branch: 1 branch
BranchTrueFalseTotal
if ($other) { } 0 0 0
707 0 $user = $other;
708 }
709 else {
710 0 die "cannot run tests as User root";
711 #XXX: prompt for another username
712 }
713 }
714  
715 2 return $user;
716 }
717  
718 2 ▶sub default_serveradmin {
Subroutine default_serveradmin: called CC=2 SCAR=7.2
Pod undocumented
719 2 my $vars = shift->{vars};
720 2 ▶ join '@', ($vars->{user} || 'unknown'), $vars->{servername};
Condition50%1/2
$vars->{'user'} || 'unknown'
l!l
20
MC/DC0%0/1
$vars->{'user'} || 'unknown'
$vars->{'user'}
Truth table50%1/2
A
A= $vars->{'user'}
Aresult
11
00
721 }
722  
723 0 ▶sub default_apxs {
Subroutine default_apxs: not called CC=6 SCAR=37.4
Pod undocumented
724 0 my $self = shift;
725  
726 0 ▶ return $self->{vars}->{apxs} if $self->{vars}->{apxs};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"vars"}{"apxs"} 0 0 0
727  
728 0 ▶ if (my $build_config = $self->modperl_build_config()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $build_config = $self->modperl_build_config) 0 0 0
729 0 return $build_config->{MP_APXS};
730 }
731  
732 0 ▶ if ($ENV{APACHE_TEST_APXS}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"APACHE_TEST_APXS"}) 0 0 0
733 0 return $ENV{APACHE_TEST_APXS};
734 }
735  
736 # look in PATH as a last resort
737 0 ▶ if (my $apxs = which('apxs')) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $apxs = which('apxs')) { } 0 0 0
elsif ($apxs = which('apxs2')) { } 0 0 0
738 0 return $apxs;
739 } elsif ($apxs = which('apxs2')) {
740 0 return $apxs;
741 }
742
743 0 return;
744 }
745  
746 0 ▶sub default_httpd {
Subroutine default_httpd: not called CC=10 SCAR=47.0
Pod undocumented
747 0 my $self = shift;
748  
749 0 my $vars = $self->{vars};
750  
751 0 ▶ if (my $build_config = $self->modperl_build_config()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $build_config = $self->modperl_build_config) 0 0 0
752 0 ▶ if (my $p = $build_config->{MP_AP_PREFIX}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $p = $build_config->{"MP_AP_PREFIX"}) 0 0 0
753 0 for my $bindir (qw(bin sbin)) {
754 0 my $httpd = catfile $p, $bindir, $vars->{target};
755 0 ▶ return $httpd if -e $httpd;
Branch: 1 branch
BranchTrueFalseTotal
if -e $httpd 0 0 0
756 # The executable on Win32 in Apache/2.2 is httpd.exe,
757 # so try that if Apache.exe doesn't exist
758 0 if (WIN32) {
759 $httpd = catfile $p, $bindir, 'httpd.EXE';
760 if (-e $httpd) {
761 $vars->{target} = 'httpd.EXE';
762 return $httpd;
763 }
764 }
765 }
766 }
767 }
768  
769 0 ▶ if ($ENV{APACHE_TEST_HTTPD}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"APACHE_TEST_HTTPD"}) 0 0 0
770 0 return $ENV{APACHE_TEST_HTTPD};
771 }
772  
773 # look in PATH as a last resort
774 0 ▶ if (my $httpd = which('httpd')) {
Branch: 4 branches
BranchTrueFalseTotal
if (my $httpd = which('httpd')) { } 0 0 0
elsif ($httpd = which('httpd2')) { } 0 0 0
elsif ($httpd = which('apache')) { } 0 0 0
elsif ($httpd = which('apache2')) { } 0 0 0
775 0 return $httpd;
776 } elsif ($httpd = which('httpd2')) {
777 0 return $httpd;
778 } elsif ($httpd = which('apache')) {
779 0 return $httpd;
780 } elsif ($httpd = which('apache2')) {
781 0 return $httpd;
782 }
783
784 0 return;
785 }
786  
787 1 my $localhost;
788  
789 1 ▶sub default_localhost {
Subroutine default_localhost: called CC=2 SCAR=7.2
Pod undocumented
790 1 my $localhost_addr = pack('C4', 127, 0, 0, 1);
791 1 ▶ gethostbyaddr($localhost_addr, Socket::AF_INET()) || 'localhost';
Branch: 1 branch
BranchTrueFalseTotal
gethostbyaddr $localhost_addr, 2 or "localhost" 1 0 1
792 }
793  
794 4 ▶sub default_servername {
Subroutine default_servername: called CC=3 SCAR=11.4
Pod undocumented
795 4 my $self = shift;
796 4 ▶ $localhost ||= $self->default_localhost;
Condition66%2/3
$localhost ||= $self->default_localhost
l!l&&r!l&&!r
310
MC/DC0%0/2
$localhost ||= $self->default_localhost
$localhost $self->default_localhost
Truth table66%2/3
A ||= B
A= $localhostB= $self->default_localhost
ABresult
1X1
011
000
797 4 ▶ die "Can't figure out the default localhost's server name"
Branch: 1 branch
BranchTrueFalseTotal
unless $localhost 0 4 4
798 unless $localhost;
799 }
800  
801 # memoize the selected value (so we make sure that the same port is used
802 # via select). The problem is that select_first_port() is called 3 times after
803 # -clean, and it's possible that a lower port will get released
804 # between calls, leading to various places in the test suite getting a
805 # different base port selection.
806 #
807 # XXX: There is still a problem if two t/TEST's configure at the same
808 # time, so they both see the same port free, but only the first one to
809 # bind() will actually get the port. So there is a need in another
810 # check and reconfiguration just before the server starts.
811 #
812 my $port_memoized;
813 4 ▶sub select_first_port {
Subroutine select_first_port: called CC=9 SCAR=35.0
Pod undocumented
814 4 my $self = shift;
815  
816 my $port ||= $port_memoized || $ENV{APACHE_TEST_PORT}
817 4 ▶ || $self->{vars}{port} || DEFAULT_PORT;
Condition63%7/11
my $port ||= $port_memoized || $ENV{"APACHE_TEST_PORT"} || $self->{"vars"}{"port"} || 8529
l!l&&r!l&&!r
040
$port_memoized || $ENV{'APACHE_TEST_PORT'} || $self->{'vars'}{'port'} || 8529
l!l
31
$port_memoized or $ENV{"APACHE_TEST_PORT"} or $self->{"vars"}{"port"}
l!l&&r!l&&!r
301
$port_memoized or $ENV{"APACHE_TEST_PORT"}
l!l&&r!l&&!r
301
MC/DC0%0/4
my $port ||= $port_memoized || $ENV{"APACHE_TEST_PORT"} || $self->{"vars"}{"port"} || 8529
my $port $port_memoized $ENV{"APACHE_TEST_PORT"} $self->{"vars"}{"port"}
Truth table0%0/5
A ||= B or C or D
A= my $portB= $port_memoizedC= $ENV{"APACHE_TEST_PORT"}D= $self->{"vars"}{"port"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
818  
819 # memoize
820 4 $port_memoized = $port;
821  
822 4 ▶ return $port unless $port eq 'select';
Branch: 1 branch
BranchTrueFalseTotal
unless $port eq "select" 4 0 4
823  
824 # port select mode: try to find another available port, take into
825 # account that each instance of the test suite may use more than
826 # one port for virtual hosts, therefore try to check ports in big
827 # steps (20?).
828 0 my $step = 20;
829 0 my $tries = 20;
830 0 $port = DEFAULT_PORT;
831 0 ▶ until (Apache::TestServer->port_available($port)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("Apache::TestServer"->port_available($port)) 0 0 0
832 0 ▶ unless (--$tries) {
Branch: 1 branch
BranchTrueFalseTotal
unless (--$tries) 0 0 0
833 0 error "no ports available";
834 0 error "tried ports @{[DEFAULT_PORT]} - $port in $step increments";
835 0 return 0;
836 }
837 0 $port += $step;
838 }
839  
840 0 ▶ info "the default base port is used, using base port $port instead"
Branch: 1 branch
BranchTrueFalseTotal
unless $port == 8529 0 0 0
841 unless $port == DEFAULT_PORT;
842  
843 # memoize
844 0 $port_memoized = $port;
845  
846 0 return $port;
847 }
848  
849 1 my $remote_addr;
850  
851 2 ▶sub our_remote_addr {
Subroutine our_remote_addr: called CC=3 SCAR=12.0
Pod undocumented
852 2 my $self = shift;
853 2 my $name = $self->default_servername;
854 2 my $iaddr = (gethostbyname($name))[-1];
855 2 ▶ unless (defined $iaddr) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $iaddr) 0 2 2
856 0 error "Can't resolve host: '$name' (check /etc/hosts)";
857 0 exit 1;
858 }
859 2 ▶ $remote_addr ||= Socket::inet_ntoa($iaddr);
Condition66%2/3
$remote_addr ||= Socket::inet_ntoa($iaddr)
l!l&&r!l&&!r
110
MC/DC0%0/2
$remote_addr ||= Socket::inet_ntoa($iaddr)
$remote_addr Socket::inet_ntoa($iaddr)
Truth table66%2/3
A ||= B
A= $remote_addrB= Socket::inet_ntoa($iaddr)
ABresult
1X1
011
000
860 }
861  
862 0 ▶sub default_loopback {
Subroutine default_loopback: not called CC=1 SCAR=6.9
Pod undocumented
863 0 '127.0.0.1';
864 }
865  
866 2 ▶sub port {
Subroutine port: called CC=3 SCAR=12.7
Pod undocumented
867 2 my($self, $module) = @_;
868  
869 2 ▶ unless ($module) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($module) 2 0 2
870 2 my $vars = $self->{vars};
871 2 ▶ return $self->select_first_port() unless $vars->{scheme} eq 'https';
Branch: 1 branch
BranchTrueFalseTotal
unless $vars->{"scheme"} eq "https" 2 0 2
872 0 $module = $vars->{ssl_module_name};
873 }
874 0 return $self->{vhosts}->{$module}->{port};
875 }
876  
877 2 ▶sub hostport {
Subroutine hostport: called CC=4 SCAR=15.2
Pod undocumented
878 2 my $self = shift;
879 2 ▶ my $vars = shift || $self->{vars};
Condition33%1/3
shift() || $self->{'vars'}
l!l&&r!l&&!r
020
MC/DC0%0/2
shift() || $self->{'vars'}
shift() $self->{'vars'}
Truth table33%1/3
A || B
A= shift()B= $self->{'vars'}
ABresult
1X1
011
000
880 2 ▶ my $module = shift || '';
Condition50%1/2
shift() || ''
l!l
02
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
881  
882 2 my $name = $vars->{servername};
883  
884 2 ▶ join ':', $name , $self->port($module || '');
Condition50%1/2
$module || ''
l!l
02
MC/DC0%0/1
$module || ''
$module
Truth table50%1/2
A
A= $module
Aresult
11
00
885 }
886  
887 #look for mod_foo.so
888 0 ▶sub find_apache_module {
Subroutine find_apache_module: not called CC=5 SCAR=34.0
Pod undocumented
889 0 my($self, $module) = @_;
890  
891 0 ▶ die "find_apache_module: module name argument is required"
Branch: 1 branch
BranchTrueFalseTotal
unless $module 0 0 0
892 unless $module;
893  
894 0 my $vars = $self->{vars};
895 0 my $sroot = $vars->{serverroot};
896  
897 0 my @trys = grep { $_ }
898 ($vars->{src_dir},
899 0 $self->apxs('LIBEXECDIR'),
900 catfile($sroot, 'modules'),
901 catfile($sroot, 'libexec'));
902  
903 0 for (@trys) {
904 0 my $file = catfile $_, $module;
905 0 ▶ if (-e $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $file) 0 0 0
906 0 debug "found $module => $file";
907 0 return $file;
908 }
909 }
910  
911 # if the module wasn't found try to lookup in the list of modules
912 # inherited from the system-wide httpd.conf
913 0 my $name = $module;
914 0 $name =~ s/\.s[ol]$/.c/; #mod_info.so => mod_info.c
915 0 $name =~ s/^lib/mod_/; #libphp4.so => mod_php4.c
916 0 ▶ return $self->{modules}->{$name} if $self->{modules}->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"modules"}{$name} 0 0 0
917  
918 }
919  
920 #generate files and directories
921  
922 my %warn_style = (
923 0 ▶ html => sub { "<!-- @_ -->" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
924 0 ▶ c => sub { "/* @_ */" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
925 0 ▶ php => sub { "<?php /* \n@_ \n*/ ?>" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
926 0 ▶ default => sub { join '', grep {s/^/\# /gm} @_ },
Subroutine __ANON__: not called CC=1 SCAR=6.9
927 1 );
928  
929 my %file_ext = (
930 2 map({$_ => 'html'} qw(htm html)),
931 2 map({$_ => 'c' } qw(c h)),
932 1 map({$_ => 'php' } qw(php)),
933 );
934  
935 # return the passed file's extension or '' if there is no one
936 # note: that '/foo/bar.conf.in' returns an extension: 'conf.in';
937 # note: a hidden file .foo will be recognized as an extension 'foo'
938 0 ▶sub filename_ext {
Subroutine filename_ext: not called CC=2 SCAR=17.9
Pod undocumented
939 0 my ($self, $filename) = @_;
940 0 ▶ my $ext = (File::Basename::fileparse($filename, '\..*'))[2] || '';
Condition0%0/2
(File::Basename::fileparse($filename, '\\..*'))[2] || ''
l!l
00
MC/DC0%0/1
(File::Basename::fileparse($filename, '\\..*'))[2] || ''
(File::Basename::fileparse($filename, '\\..*'))[2]
Truth table0%0/2
A
A= (File::Basename::fileparse($filename, '\\..*'))[2]
Aresult
11
00
941 0 $ext =~ s/^\.(.*)/lc $1/e;
942 0 $ext;
943 }
944  
945 0 ▶sub warn_style_sub_ref {
Subroutine warn_style_sub_ref: not called CC=2 SCAR=17.9
Pod undocumented
946 0 my ($self, $filename) = @_;
947 0 my $ext = $self->filename_ext($filename);
948 0 ▶ return $warn_style{ $file_ext{$ext} || 'default' };
Condition0%0/2
$file_ext{$ext} || 'default'
l!l
00
MC/DC0%0/1
$file_ext{$ext} || 'default'
$file_ext{$ext}
Truth table0%0/2
A
A= $file_ext{$ext}
Aresult
11
00
949 }
950  
951 0 ▶sub genwarning {
Subroutine genwarning: not called CC=3 SCAR=24.8
Pod documented
952 0 my($self, $filename, $from_filename) = @_;
953 0 ▶ return unless $filename;
Branch: 1 branch
BranchTrueFalseTotal
unless $filename 0 0 0
954 0 my $time = scalar localtime;
955 0 my $warning = "WARNING: this file is generated";
956 0 ▶ $warning .= " (from $from_filename)" if defined $from_filename;
Branch: 1 branch
BranchTrueFalseTotal
if defined $from_filename 0 0 0
957 0 $warning .= ", do not edit\n";
958 0 $warning .= "generated on $time\n";
959 0 $warning .= calls_trace();
960 0 return $self->warn_style_sub_ref($filename)->($warning);
961 }
962  
963 0 ▶sub calls_trace {
Subroutine calls_trace: not called CC=2 SCAR=17.9
Pod undocumented
964 0 my $frame = 1;
965 0 my $trace = '';
966  
967 0 while (1) {
968 0 my($package, $filename, $line) = caller($frame);
969 0 ▶ last unless $filename;
Branch: 1 branch
BranchTrueFalseTotal
unless $filename 0 0 0
970 0 $trace .= sprintf "%02d: %s:%d\n", $frame, $filename, $line;
971 0 $frame++;
972 }
973  
974 0 return $trace;
975 }
976  
977 0 ▶sub clean_add_file {
Subroutine clean_add_file: not called CC=1 SCAR=6.9
Pod undocumented
978 0 my($self, $file) = @_;
979  
980 0 $self->{clean}->{files}->{ rel2abs($file) } = 1;
981 }
982  
983 0 ▶sub clean_add_path {
Subroutine clean_add_path: not called CC=2 SCAR=17.9
Pod undocumented
984 0 my($self, $path) = @_;
985  
986 0 $path = rel2abs($path);
987  
988 # remember which dirs were created and should be cleaned up
989 0 while (1) {
990 0 $self->{clean}->{dirs}->{$path} = 1;
991 0 $path = dirname $path;
992 0 ▶ last if -e $path;
Branch: 1 branch
BranchTrueFalseTotal
if -e $path 0 0 0
993 }
994 }
995  
996 0 ▶sub genfile_trace {
Subroutine genfile_trace: not called CC=2 SCAR=17.9
Pod undocumented
997 0 my($self, $file, $from_file) = @_;
998 0 my $name = abs2rel $file, $self->{vars}->{t_dir};
999 0 my $msg = "generating $name";
1000 0 ▶ $msg .= " from $from_file" if defined $from_file;
Branch: 1 branch
BranchTrueFalseTotal
if defined $from_file 0 0 0
1001 0 debug $msg;
1002 }
1003  
1004 0 ▶sub genfile_warning {
Subroutine genfile_warning: not called CC=2 SCAR=17.9
Pod undocumented
1005 0 my($self, $file, $from_file, $fh) = @_;
1006  
1007 0 ▶ if (my $msg = $self->genwarning($file, $from_file)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $msg = $self->genwarning($file, $from_file)) 0 0 0
1008 0 print $fh $msg, "\n";
1009 }
1010 }
1011  
1012 # $from_file == undef if there was no templates used
1013 0 ▶sub genfile {
Subroutine genfile: not called CC=3 SCAR=24.8
Pod documented
1014 0 my($self, $file, $from_file, $nowarning) = @_;
1015  
1016 # create the parent dir if it doesn't exist yet
1017 0 my $dir = dirname $file;
1018 0 $self->makepath($dir);
1019  
1020 0 $self->genfile_trace($file, $from_file);
1021  
1022 0 my $fh = Symbol::gensym();
1023 0 ▶ open $fh, ">$file" or die "open $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">$file" or die "open ${file}: $!" 0 0 0
1024  
1025 0 ▶ $self->genfile_warning($file, $from_file, $fh) unless $nowarning;
Branch: 1 branch
BranchTrueFalseTotal
unless $nowarning 0 0 0
1026  
1027 0 $self->clean_add_file($file);
1028  
1029 0 return $fh;
1030 }
1031  
1032 # gen + write file
1033 0 ▶sub writefile {
Subroutine writefile: not called CC=2 SCAR=17.9
Pod documented
1034 0 my($self, $file, $content, $nowarning) = @_;
1035  
1036 0 my $fh = $self->genfile($file, undef, $nowarning);
1037  
1038 0 ▶ print $fh $content if $content;
Branch: 1 branch
BranchTrueFalseTotal
if $content 0 0 0
1039  
1040 0 close $fh;
1041 }
1042  
1043 0 ▶sub perlscript_header {
Subroutine perlscript_header: not called CC=8 SCAR=42.8
Pod undocumented
1044  
1045 0 require FindBin;
1046  
1047 0 my @dirs = ();
1048  
1049 # mp2 needs its modper-2.0/lib before blib was created
1050 0 ▶ if (IS_MOD_PERL_2_BUILD || $ENV{APACHE_TEST_LIVE_DEV}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"APACHE_TEST_LIVE_DEV"}) 0 0 0
1051 # the live 'lib/' dir of the distro
1052 # (e.g. modperl-2.0/ModPerl-Registry/lib)
1053 0 my $dir = canonpath catdir $FindBin::Bin, "lib";
1054 0 ▶ push @dirs, $dir if -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
if -d $dir 0 0 0
1055  
1056 # the live dir of the top dir if any (e.g. modperl-2.0/lib)
1057 0 ▶ if (-e catfile($FindBin::Bin, "..", "Makefile.PL")) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e catfile($FindBin::Bin, "..", "Makefile.PL")) 0 0 0
1058 0 my $dir = canonpath catdir $FindBin::Bin, "..", "lib";
1059 0 ▶ push @dirs, $dir if -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
if -d $dir 0 0 0
1060 }
1061 }
1062  
1063 0 for (qw(. ..)) {
1064 0 my $dir = canonpath catdir $FindBin::Bin, $_ , "Apache-Test", "lib";
1065 0 ▶ if (-d $dir) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $dir) 0 0 0
1066 0 push @dirs, $dir;
1067 0 last;
1068 }
1069 }
1070  
1071 {
1072 0 my $dir = canonpath catdir $FindBin::Bin, "t", "lib";
1073 0 ▶ push @dirs, $dir if -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
if -d $dir 0 0 0
1074 }
1075  
1076 0 push @dirs, canonpath $FindBin::Bin;
1077
1078 0 my $dirs = join("\n ", '', @dirs) . "\n";;
1079  
1080 0 return <<"EOF";
1081  
1082 use strict;
1083 use warnings FATAL => 'all';
1084  
1085 use lib qw($dirs);
1086  
1087 EOF
1088 }
1089  
1090 # gen + write executable perl script file
1091 0 ▶sub write_perlscript {
Subroutine write_perlscript: not called CC=2 SCAR=17.9
Pod documented
1092 0 my($self, $file, $content) = @_;
1093  
1094 0 my $fh = $self->genfile($file, undef, 1);
1095  
1096 0 my $shebang = make_shebang();
1097 0 print $fh $shebang;
1098  
1099 0 $self->genfile_warning($file, undef, $fh);
1100  
1101 0 ▶ print $fh $content if $content;
Branch: 1 branch
BranchTrueFalseTotal
if $content 0 0 0
1102  
1103 0 close $fh;
1104 0 chmod 0755, $file;
1105 }
1106  
1107 0 ▶sub make_shebang {
Subroutine make_shebang: not called CC=2 SCAR=17.9
Pod undocumented
1108 # if perlpath is longer than 62 chars, some shells on certain
1109 # platforms won't be able to run the shebang line, so when seeing
1110 # a long perlpath use the eval workaround.
1111 # see: http://en.wikipedia.org/wiki/Shebang
1112 # http://homepages.cwi.nl/~aeb/std/shebang/
1113 0 ▶ my $shebang = length $Config{perlpath} < 62
Branch: 1 branch
BranchTrueFalseTotal
length $Apache::TestConfig::Config{'perlpath'} < 62 ? : 0 0 0
1114 ? "#!$Config{perlpath}\n"
1115 : <<EOI;
1116 $Config{'startperl'}
1117 eval 'exec $Config{perlpath} -S \$0 \${1+"\$@"}'
1118 if \$running_under_some_shell;
1119 EOI
1120  
1121 0 return $shebang;
1122 }
1123  
1124 0 ▶sub cpfile {
Subroutine cpfile: not called CC=1 SCAR=6.9
Pod undocumented
1125 0 my($self, $from, $to) = @_;
1126 0 File::Copy::copy($from, $to);
1127 0 $self->clean_add_file($to);
1128 }
1129  
1130 0 ▶sub symlink {
Subroutine symlink: not called CC=1 SCAR=6.9
Pod undocumented
1131 0 my($self, $from, $to) = @_;
1132 0 CORE::symlink($from, $to);
1133 0 $self->clean_add_file($to);
1134 }
1135  
1136 0 ▶sub gendir {
Subroutine gendir: not called CC=1 SCAR=6.9
Pod documented
1137 0 my($self, $dir) = @_;
1138 0 $self->makepath($dir);
1139 }
1140  
1141 # returns a list of dirs successfully created
1142 0 ▶sub makepath {
Subroutine makepath: not called CC=3 SCAR=24.8
Pod undocumented
1143 0 my($self, $path) = @_;
1144  
1145 0 ▶ return if !defined($path) || -e $path;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $path or -e $path 0 0 0
Condition0%0/3
not defined $path or -e $path
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $path or -e $path
not defined $path -e $path
Truth table0%0/3
not(A) or B
A= not defined $pathB= -e $path
ABresult
1X1
011
000
1146  
1147 0 $self->clean_add_path($path);
1148  
1149 0 return File::Path::mkpath($path, 0, 0755);
1150 }
1151  
1152 0 ▶sub open_cmd {
Subroutine open_cmd: not called CC=3 SCAR=24.8
Pod undocumented
1153 0 my($self, $cmd) = @_;
1154 # untaint some %ENV fields
1155 0 local @ENV{ qw(IFS CDPATH ENV BASH_ENV) };
1156 0 local $ENV{PATH} = untaint_path($ENV{PATH});
1157  
1158 # launder for -T
1159 0 ▶ $cmd = $1 if $cmd =~ /(.*)/;
Branch: 1 branch
BranchTrueFalseTotal
if $cmd =~ /(.*)/ 0 0 0
1160  
1161 0 my $handle = Symbol::gensym();
1162 0 ▶ open $handle, "$cmd|" or die "$cmd failed: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $handle, "$cmd|" or die "$cmd failed: $!" 0 0 0
1163  
1164 0 return $handle;
1165 }
1166  
1167 0 ▶sub clean {
Subroutine clean: not called CC=7 SCAR=40.3
Pod undocumented
1168 0 my $self = shift;
1169 0 ▶ $self->{clean_level} = shift || 2; #2 == really clean, 1 == reconfigure
Condition0%0/2
shift() || 2
l!l
00
MC/DC0%0/1
shift() || 2
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
1170  
1171 0 $self->new_test_server->clean;
1172 0 $self->cmodules_clean;
1173 0 $self->sslca_clean;
1174  
1175 0 for (sort keys %{ $self->{clean}->{files} }) {
1176 0 ▶ if (-e $_) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $_) { } 0 0 0
1177 0 debug "unlink $_";
1178 0 unlink $_;
1179 }
1180 else {
1181 0 debug "unlink $_: $!";
1182 }
1183 }
1184  
1185 # if /foo comes before /foo/bar, /foo will never be removed
1186 # hence ensure that sub-dirs are always treated before a parent dir
1187 0 for (reverse sort keys %{ $self->{clean}->{dirs} }) {
1188 0 ▶ if (-d $_) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $_) 0 0 0
1189 0 my $dh = Symbol::gensym();
1190 0 opendir($dh, $_);
1191 0 my $notempty = grep { ! /^\.{1,2}$/ } readdir $dh;
1192 0 closedir $dh;
1193 0 ▶ next if $notempty;
Branch: 1 branch
BranchTrueFalseTotal
if $notempty 0 0 0
1194 0 debug "rmdir $_";
1195 0 rmdir $_;
1196 }
1197 }
1198 }
1199  
1200 my %special_tokens = (
1201 0 ▶ nextavailableport => sub { shift->server->select_next_port }
Subroutine __ANON__: not called CC=1 SCAR=6.9
1202 1 );
1203  
1204 0 ▶sub replace {
Subroutine replace: not called CC=4 SCAR=30.0
Pod undocumented
1205 0 my $self = shift;
1206 0 ▶ my $file = $Apache::TestConfig::File
Branch: 1 branch
BranchTrueFalseTotal
$Apache::TestConfig::File ? : 0 0 0
1207 ? "in file $Apache::TestConfig::File" : '';
1208  
1209 0 s[@(\w+)@]
1210 0 [ my $key = lc $1;
1211 0 ▶ if (my $callback = $special_tokens{$key}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $callback = $special_tokens{$key}) { } 0 0 0
elsif (exists $self->{'vars'}{$key}) { } 0 0 0
1212 0 $self->$callback;
1213 }
1214 elsif (exists $self->{vars}->{$key}) {
1215 0 $self->{vars}->{$key};
1216 }
1217 else {
1218 0 die "invalid token: \@$1\@ $file\n";
1219 }
1220 ]ge;
1221 }
1222  
1223 #need to configure the vhost port for redirects and $ENV{SERVER_PORT}
1224 #to have the correct values
1225 my %servername_config = (
1226 0 ▶ 0 => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1227 0 my($name, $port) = @_;
1228 0 [ServerName => ''], [Port => 0];
1229 },
1230 0 ▶ 1 => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1231 0 my($name, $port) = @_;
1232 0 [ServerName => $name], [Port => $port];
1233 },
1234 0 ▶ 2 => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1235 0 my($name, $port) = @_;
1236 0 [ServerName => "$name:$port"];
1237 },
1238 1 );
1239  
1240 0 ▶sub servername_config {
Subroutine servername_config: not called CC=1 SCAR=6.9
Pod undocumented
1241 0 my $self = shift;
1242 0 $self->server->version_of(\%servername_config)->(@_);
1243 }
1244  
1245 0 ▶sub parse_vhost {
Subroutine parse_vhost: not called CC=14 SCAR=53.5
Pod undocumented
1246 0 my($self, $line) = @_;
1247  
1248 0 my($indent, $module, $namebased);
1249 0 ▶ if ($line =~ /^(\s*)<VirtualHost\s+(?:_default_:|([^:]+):(?!:))?(.*?)\s*>\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^(\s*)<VirtualHost\s+(?:_default_:|([^:]+):(?!:))?(.*?)\s*>\s*$/) { } 0 0 0
1250 0 ▶ $indent = $1 || "";
Condition0%0/2
$1 || ''
l!l
00
MC/DC0%0/1
$1 || ''
$1
Truth table0%0/2
A
A= $1
Aresult
11
00
1251 0 ▶ $namebased = $2 || "";
Condition0%0/2
$2 || ''
l!l
00
MC/DC0%0/1
$2 || ''
$2
Truth table0%0/2
A
A= $2
Aresult
11
00
1252 0 $module = $3;
1253 }
1254 else {
1255 0 return undef;
1256 }
1257  
1258 0 my $vars = $self->{vars};
1259 0 my $mods = $self->{modules};
1260 0 my $have_module = "$module.c";
1261 0 my $ssl_module = $vars->{ssl_module};
1262  
1263 #if module ends with _ssl and it is not the module that implements ssl,
1264 #then assume this module is a vhost with SSLEngine On (or similar)
1265 #see mod_echo in extra.conf.in for example
1266 0 ▶ if ($module =~ /^(mod_\w+)_ssl$/ and $have_module ne $ssl_module) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module =~ /^(mod_\w+)_ssl$/ and $have_module ne $ssl_module) 0 0 0
Condition0%0/3
$module =~ /^(mod_\w+)_ssl$/ and $have_module ne $ssl_module
!ll&&!rl&&r
000
MC/DC0%0/2
$module =~ /^(mod_\w+)_ssl$/ and $have_module ne $ssl_module
$module =~ /^(mod_\w+)_ssl$/ $have_module ne $ssl_module
Truth table0%0/3
A and B
A= $module =~ /^(mod_\w+)_ssl$/B= $have_module ne $ssl_module
ABresult
0X0
100
111
1267 0 $have_module = "$1.c"; #e.g. s/mod_echo_ssl.c/mod_echo.c/
1268 0 ▶ return undef unless $mods->{$ssl_module};
Branch: 1 branch
BranchTrueFalseTotal
unless $mods->{$ssl_module} 0 0 0
1269 }
1270  
1271 #don't allocate a port if this module is not configured
1272 #assumes the configuration is inside an <IfModule $have_module>
1273 0 ▶ if ($module =~ /^mod_/ and not $mods->{$have_module}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module =~ /^mod_/ and not $mods->{$have_module}) 0 0 0
Condition0%0/3
$module =~ /^mod_/ and not $mods->{$have_module}
!ll&&!rl&&r
000
MC/DC0%0/2
$module =~ /^mod_/ and not $mods->{$have_module}
$module =~ /^mod_/ not $mods->{$have_module}
Truth table0%0/3
A and not(B)
A= $module =~ /^mod_/B= not $mods->{$have_module}
ABresult
0X0
100
111
1274 0 return undef;
1275 }
1276  
1277 #allocate a port and configure this module into $self->{vhosts}
1278 0 my $port = $self->new_vhost($module, $namebased);
1279  
1280 #extra config that should go *inside* the <VirtualHost ...>
1281 my @in_config = $self->servername_config($namebased
1282 ? $namebased
1283 : $vars->{servername},
1284 0 ▶ $port);
Branch: 1 branch
BranchTrueFalseTotal
$namebased ? : 0 0 0
1285  
1286 0 my @out_config = ();
1287 0 ▶ if ($self->{vhosts}->{$module}->{namebased} < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"vhosts"}{$module}{"namebased"} < 2) 0 0 0
1288 #extra config that should go *outside* the <VirtualHost ...>
1289 0 @out_config = ([Listen => '0.0.0.0:' . $port]);
1290  
1291 0 ▶ if ($self->{vhosts}->{$module}->{namebased}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"vhosts"}{$module}{"namebased"}) 0 0 0
1292 0 push @out_config => ["<IfVersion < 2.3.11>\n".
1293 "${indent}${indent}NameVirtualHost"
1294 => "*:$port\n${indent}</IfVersion>"];
1295 }
1296 }
1297  
1298 0 $self->{vars}->{$module . '_port'} = $port;
1299  
1300 #there are two ways of building a vhost
1301 #first is when we parse test .pm and .c files
1302 #second is when we scan *.conf.in
1303 0 ▶ my $form_postamble = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1304 0 my $indent = shift;
1305 0 for my $pair (@_) {
1306 0 $self->postamble("$indent@$pair");
1307 }
1308 0 };
1309  
1310 0 ▶ my $form_string = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1311 0 my $indent = shift;
1312 0 join "\n", map { "$indent@$_\n" } @_;
1313 0 };
1314  
1315 0 ▶ my $double_indent = $indent ? $indent x 2 : ' ' x 4;
Branch: 1 branch
BranchTrueFalseTotal
$indent ? : 0 0 0
1316 return {
1317 port => $port,
1318 #used when parsing .pm and .c test modules
1319 0 ▶ in_postamble => sub { $form_postamble->($double_indent, @in_config) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1320 0 ▶ out_postamble => sub { $form_postamble->($indent, @out_config) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1321 #used when parsing *.conf.in files
1322 0 ▶ in_string => $form_string->($double_indent, @in_config),
Branch: 1 branch
BranchTrueFalseTotal
$namebased ? : 0 0 0
1323 out_string => $form_string->($indent, @out_config),
1324 line => "$indent<VirtualHost " . ($namebased ? '*' : '_default_') .
1325 ":$port>",
1326 };
1327 }
1328  
1329 0 ▶sub find_and_load_module {
Subroutine find_and_load_module: not called CC=4 SCAR=30.0
Pod undocumented
1330 0 my ($self, $name) = @_;
1331 0 ▶ my $mod_path = $self->find_apache_module($name) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $mod_path = $self->find_apache_module($name) or return 0 0 0
1332 0 my ($sym) = $name =~ m/mod_(\w+)\./;
1333  
1334 0 ▶ if ($mod_path && -e $mod_path) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mod_path and -e $mod_path) 0 0 0
Condition0%0/3
$mod_path and -e $mod_path
!ll&&!rl&&r
000
MC/DC0%0/2
$mod_path and -e $mod_path
$mod_path -e $mod_path
Truth table0%0/3
A and B
A= $mod_pathB= -e $mod_path
ABresult
0X0
100
111
1335 0 $self->preamble(IfModule => "!mod_$sym.c",
1336 qq{LoadModule ${sym}_module "$mod_path"\n});
1337 }
1338 0 return 1;
1339 }
1340  
1341 0 ▶sub replace_vhost_modules {
Subroutine replace_vhost_modules: not called CC=4 SCAR=30.0
Pod undocumented
1342 0 my $self = shift;
1343  
1344 0 ▶ if (my $cfg = $self->parse_vhost($_)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cfg = $self->parse_vhost($_)) 0 0 0
1345 0 $_ = '';
1346 0 for my $key (qw(out_string line in_string)) {
1347 0 ▶ next unless $cfg->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless $cfg->{$key} 0 0 0
1348 0 $_ .= "$cfg->{$key}\n";
1349 }
1350 }
1351 }
1352  
1353 0 ▶sub replace_vars {
Subroutine replace_vars: not called CC=2 SCAR=17.9
Pod undocumented
1354 0 my($self, $in, $out) = @_;
1355  
1356 0 local $_;
1357 0 ▶ while (<$in>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $in)) 0 0 0
1358 0 $self->replace;
1359 0 $self->replace_vhost_modules;
1360 0 print $out $_;
1361 }
1362 }
1363  
1364 0 ▶sub index_html_template {
Subroutine index_html_template: not called CC=1 SCAR=6.9
Pod undocumented
1365 0 my $self = shift;
1366 0 return "welcome to $self->{server}->{name}\n";
1367 }
1368  
1369 0 ▶sub generate_index_html {
Subroutine generate_index_html: not called CC=2 SCAR=17.9
Pod undocumented
1370 0 my $self = shift;
1371 0 my $dir = $self->{vars}->{documentroot};
1372 0 $self->gendir($dir);
1373 0 my $file = catfile $dir, 'index.html';
1374 0 ▶ return if -e $file;
Branch: 1 branch
BranchTrueFalseTotal
if -e $file 0 0 0
1375 0 my $fh = $self->genfile($file);
1376 0 print $fh $self->index_html_template;
1377 }
1378  
1379 0 ▶sub types_config_template {
Subroutine types_config_template: not called CC=1 SCAR=6.9
Pod undocumented
1380 0 return <<EOF;
1381 text/html html htm
1382 image/gif gif
1383 image/jpeg jpeg jpg jpe
1384 image/png png
1385 text/plain asc txt
1386 EOF
1387 }
1388  
1389 0 ▶sub generate_types_config {
Subroutine generate_types_config: not called CC=3 SCAR=24.8
Pod undocumented
1390 0 my $self = shift;
1391  
1392 # handle the case when mod_mime is built as a shared object
1393 # but wasn't included in the system-wide httpd.conf
1394 0 $self->find_and_load_module('mod_mime.so');
1395  
1396 0 ▶ unless ($self->{inherit_config}->{TypesConfig}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"inherit_config"}{"TypesConfig"}) 0 0 0
1397 0 my $types = catfile $self->{vars}->{t_conf}, 'mime.types';
1398 0 ▶ unless (-e $types) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $types) 0 0 0
1399 0 my $fh = $self->genfile($types);
1400 0 print $fh $self->types_config_template;
1401 0 close $fh;
1402 }
1403 0 $self->postamble(<<EOI);
1404 <IfModule mod_mime.c>
1405 TypesConfig "$types"
1406 </IfModule>
1407 EOI
1408 }
1409 }
1410  
1411 # various dup bugs in older perl and perlio in perl < 5.8.4 need a
1412 # workaround to explicitly rewind the dupped DATA fh before using it
1413 1 my $DATA_pos = tell DATA;
1414 0 ▶sub httpd_conf_template {
Subroutine httpd_conf_template: not called CC=3 SCAR=24.8
Pod undocumented
1415 0 my($self, $try) = @_;
1416  
1417 0 my $in = Symbol::gensym();
1418 0 ▶ if (open $in, $try) {
Branch: 1 branch
BranchTrueFalseTotal
if (open $in, $try) { } 0 0 0
1419 0 return $in;
1420 }
1421 else {
1422 0 my $dup = Symbol::gensym();
1423 0 ▶ open $dup, "<&DATA" or die "Can't dup DATA: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $dup, "<&DATA" or die "Can't dup DATA: $!" 0 0 0
1424 0 seek $dup, $DATA_pos, 0; # rewind to the beginning
1425 0 return $dup; # so we don't close DATA
1426 }
1427 }
1428  
1429 #certain variables may not be available until certain config files
1430 #are generated. for example, we don't know the ssl port until ssl.conf.in
1431 #is parsed. ssl port is needed for proxyssl testing
1432  
1433 0 ▶sub check_vars {
Subroutine check_vars: not called CC=6 SCAR=37.4
Pod undocumented
1434 0 my $self = shift;
1435 0 my $vars = $self->{vars};
1436  
1437 0 ▶ unless ($vars->{proxyssl_url}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($vars->{"proxyssl_url"}) 0 0 0
1438 0 my $ssl = $self->{vhosts}->{ $vars->{ssl_module_name} };
1439 0 ▶ if ($ssl) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ssl) 0 0 0
1440 0 ▶ $vars->{proxyssl_url} ||= $ssl->{hostport};
Condition0%0/3
$vars->{"proxyssl_url"} ||= $ssl->{"hostport"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$vars->{"proxyssl_url"} ||= $ssl->{"hostport"}
$vars->{"proxyssl_url"} $ssl->{"hostport"}
Truth table0%0/3
A ||= B
A= $vars->{"proxyssl_url"}B= $ssl->{"hostport"}
ABresult
1X1
011
000
1441 }
1442  
1443 0 ▶ if ($vars->{proxyssl_url}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vars->{"proxyssl_url"}) 0 0 0
1444 0 ▶ unless ($vars->{maxclients_preset}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($vars->{"maxclients_preset"}) 0 0 0
1445 0 $vars->{minclients}++;
1446 0 $vars->{maxclients}++;
1447 0 $vars->{maxspare}++;
1448 0 $vars->{startserversthreadedmpm} ++;
1449 0 $vars->{minclientsthreadedmpm} += $vars->{threadsperchild};
1450 0 $vars->{maxclientsthreadedmpm} += $vars->{threadsperchild};
1451 0 $vars->{maxsparethreadedmpm} += $vars->{threadsperchild};
1452 #In addition allow for some backend processes
1453 #in keep-alive state. For threaded MPMs we
1454 #already should be fine.
1455 0 $vars->{maxclients} += 3;
1456 }
1457 }
1458 }
1459 }
1460  
1461 0 ▶sub extra_conf_files_needing_update {
Subroutine extra_conf_files_needing_update: not called CC=1 SCAR=6.9
Pod undocumented
1462 0 my $self = shift;
1463  
1464 0 my @need_update = ();
1465 0 ▶ finddepth(sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
1466 0 ▶ return unless /\.in$/;
Branch: 1 branch
BranchTrueFalseTotal
unless /\.in$/ 0 0 0
1467 0 (my $generated = $File::Find::name) =~ s/\.in$//;
1468 0 ▶ push @need_update, $generated
Branch: 1 branch
BranchTrueFalseTotal
unless -e $generated and -M $generated < -M $File::Find::name 0 0 0
Condition0%0/3
-e $generated and -M $generated < -M $File::Find::name
!ll&&!rl&&r
000
MC/DC0%0/2
-e $generated and -M $generated < -M $File::Find::name
-e $generated -M $generated < -M $File::Find::name
Truth table0%0/3
A and B
A= -e $generatedB= -M $generated < -M $File::Find::name
ABresult
0X0
100
111
1469 unless -e $generated && -M $generated < -M $File::Find::name;
1470 0 }, $self->{vars}->{t_conf});
1471  
1472 0 return @need_update;
1473 }
1474  
1475 0 ▶sub generate_extra_conf {
Subroutine generate_extra_conf: not called CC=6 SCAR=37.4
Pod undocumented
1476 0 my $self = shift;
1477  
1478 0 my(@extra_conf, @conf_in, @conf_files);
1479  
1480 0 ▶ finddepth(sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1481 0 ▶ return unless /\.in$/;
Branch: 1 branch
BranchTrueFalseTotal
unless /\.in$/ 0 0 0
1482 0 push @conf_in, catdir $File::Find::dir, $_;
1483 0 }, $self->{vars}->{t_conf});
1484  
1485 #make ssl port always be 8530 when available
1486 0 for my $file (@conf_in) {
1487 0 ▶ if (basename($file) =~ /^ssl/) {
Branch: 1 branch
BranchTrueFalseTotal
if (basename($file) =~ /^ssl/) { } 0 0 0
1488 0 unshift @conf_files, $file;
1489 }
1490 else {
1491 0 push @conf_files, $file;
1492 }
1493 }
1494  
1495 0 for my $file (@conf_files) {
1496 0 (my $generated = $file) =~ s/\.in$//;
1497 0 debug "Will 'Include' $generated config file";
1498 0 push @extra_conf, $generated;
1499 }
1500  
1501 # regenerate .conf files
1502 0 for my $file (@conf_files) {
1503 0 local $Apache::TestConfig::File = $file;
1504  
1505 0 my $in = Symbol::gensym();
1506 0 ▶ open($in, $file) or next;
Branch: 1 branch
BranchTrueFalseTotal
open $in, $file or next 0 0 0
1507  
1508 0 (my $generated = $file) =~ s/\.in$//;
1509 0 my $out = $self->genfile($generated, $file);
1510 0 $self->replace_vars($in, $out);
1511  
1512 0 close $in;
1513 0 close $out;
1514  
1515 0 $self->check_vars;
1516 }
1517  
1518 #we changed order to give ssl the first port after DEFAULT_PORT
1519 #but we want extra.conf Included first so vhosts inherit base config
1520 #such as LimitRequest*
1521 0 return [ sort @extra_conf ];
1522 }
1523  
1524 0 ▶sub sslca_can {
Subroutine sslca_can: not called CC=5 SCAR=34.0
Pod undocumented
1525 0 my($self, $check) = @_;
1526  
1527 0 my $vars = $self->{vars};
1528 0 ▶ return 0 unless $self->{modules}->{ $vars->{ssl_module} };
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"modules"}{$vars->{"ssl_module"}} 0 0 0
1529 0 ▶ return 0 unless -d "$vars->{t_conf}/ssl";
Branch: 1 branch
BranchTrueFalseTotal
unless -d qq[$vars->{"t_conf"}/ssl] 0 0 0
1530  
1531 0 require Apache::TestSSLCA;
1532  
1533 0 ▶ if ($check) {
Branch: 1 branch
BranchTrueFalseTotal
if ($check) 0 0 0
1534 0 my $openssl = Apache::TestSSLCA::openssl();
1535 0 ▶ if (which($openssl)) {
Branch: 1 branch
BranchTrueFalseTotal
if (which($openssl)) 0 0 0
1536 0 return 1;
1537 }
1538  
1539 0 error "cannot locate '$openssl' program required to generate SSL CA";
1540 0 exit(1);
1541 }
1542  
1543 0 return 1;
1544 }
1545  
1546 0 ▶sub sslca_generate {
Subroutine sslca_generate: not called CC=4 SCAR=30.0
Pod undocumented
1547 0 my $self = shift;
1548  
1549 0 my $ca = $self->{vars}->{sslca};
1550 0 ▶ return if $ca and -d $ca; #t/conf/ssl/ca
Branch: 1 branch
BranchTrueFalseTotal
if $ca and -d $ca 0 0 0
Condition0%0/3
$ca and -d $ca
!ll&&!rl&&r
000
MC/DC0%0/2
$ca and -d $ca
$ca -d $ca
Truth table0%0/3
A and B
A= $caB= -d $ca
ABresult
0X0
100
111
1551  
1552 0 ▶ return unless $self->sslca_can(1);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->sslca_can(1) 0 0 0
1553  
1554 0 Apache::TestSSLCA::generate($self);
1555 }
1556  
1557 0 ▶sub sslca_clean {
Subroutine sslca_clean: not called CC=4 SCAR=30.0
Pod undocumented
1558 0 my $self = shift;
1559  
1560 # XXX: httpd config is required, for now just skip ssl clean if
1561 # there is none. should probably add some flag which will tell us
1562 # when httpd_config was already run
1563 0 ▶ return unless $self->{vars}->{httpd} && $self->{vars}->{ssl_module};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"vars"}{"httpd"} and $self->{"vars"}{"ssl_module"} 0 0 0
Condition0%0/3
$self->{"vars"}{"httpd"} and $self->{"vars"}{"ssl_module"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"vars"}{"httpd"} and $self->{"vars"}{"ssl_module"}
$self->{"vars"}{"httpd"} $self->{"vars"}{"ssl_module"}
Truth table0%0/3
A and B
A= $self->{"vars"}{"httpd"}B= $self->{"vars"}{"ssl_module"}
ABresult
0X0
100
111
1564  
1565 0 ▶ return unless $self->sslca_can;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->sslca_can 0 0 0
1566  
1567 0 Apache::TestSSLCA::clean($self);
1568 }
1569  
1570 #XXX: just a quick hack to support t/TEST -ssl
1571 #outside of httpd-test/perl-framework
1572 0 ▶sub generate_ssl_conf {
Subroutine generate_ssl_conf: not called CC=5 SCAR=34.0
Pod undocumented
1573 0 my $self = shift;
1574 0 my $vars = $self->{vars};
1575 0 my $conf = "$vars->{t_conf}/ssl";
1576 0 my $httpd_test_ssl = "../httpd-test/perl-framework/t/conf/ssl";
1577 0 my $ssl_conf = "$vars->{top_dir}/$httpd_test_ssl";
1578  
1579 0 ▶ if (-d $ssl_conf and not -d $conf) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $ssl_conf and not -d $conf) 0 0 0
Condition0%0/3
-d $ssl_conf and not -d $conf
!ll&&!rl&&r
000
MC/DC0%0/2
-d $ssl_conf and not -d $conf
-d $ssl_conf not -d $conf
Truth table0%0/3
A and not(B)
A= -d $ssl_confB= not -d $conf
ABresult
0X0
100
111
1580 0 $self->gendir($conf);
1581 0 for (qw(ssl.conf.in)) {
1582 0 $self->cpfile("$ssl_conf/$_", "$conf/$_");
1583 }
1584 0 for (qw(certs keys crl)) {
1585 0 $self->symlink("$ssl_conf/$_", "$conf/$_");
1586 }
1587 }
1588 }
1589  
1590 4 ▶sub find_in_inc {
Subroutine find_in_inc: called CC=3 SCAR=11.0
Pod undocumented
1591 4 my($self, $dir) = @_;
1592 4 for my $path (@INC) {
1593 44 my $location = "$path/$dir";
1594 44 ▶ return $location if -d $location;
Branch: 1 branch
BranchTrueFalseTotal
if -d $location 2 42 44
1595 }
1596 2 return "";
1597 }
1598  
1599 0 ▶sub prepare_t_conf {
Subroutine prepare_t_conf: not called CC=1 SCAR=6.9
Pod undocumented
1600 0 my $self = shift;
1601 0 $self->gendir($self->{vars}->{t_conf});
1602 }
1603  
1604 1 my %aliases = (
1605 "perl-pod" => "perlpod",
1606 "binary-httpd" => "httpd",
1607 "binary-perl" => "perl",
1608 );
1609 0 ▶sub generate_httpd_conf {
Subroutine generate_httpd_conf: not called CC=13 SCAR=52.0
Pod undocumented
1610 0 my $self = shift;
1611 0 my $vars = $self->{vars};
1612  
1613 #generated httpd.conf depends on these things to exist
1614 0 $self->generate_types_config;
1615 0 $self->generate_index_html;
1616  
1617 0 $self->gendir($vars->{t_logs});
1618 0 $self->gendir($vars->{t_state});
1619 0 $self->gendir($vars->{t_conf});
1620  
1621 0 my @very_last_postamble = ();
1622 0 ▶ if (my $extra_conf = $self->generate_extra_conf) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $extra_conf = $self->generate_extra_conf) 0 0 0
1623 0 for my $file (@$extra_conf) {
1624 0 my $entry;
1625 0 ▶ if ($file =~ /\.conf$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($file =~ /\.conf$/) { } 0 0 0
elsif ($file =~ /\.pl$/) { } 0 0 0
1626 0 ▶ next if $file =~ m|/httpd\.conf$|;
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ m[/httpd\.conf$] 0 0 0
1627 0 $entry = qq(Include "$file");
1628 }
1629 elsif ($file =~ /\.pl$/) {
1630 0 $entry = qq(<IfModule mod_perl.c>\n PerlRequire "$file"\n</IfModule>\n);
1631 }
1632 else {
1633 0 next;
1634 }
1635  
1636 # put the .last includes very last
1637 0 ▶ if ($file =~ /\.last\.(conf|pl)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /\.last\.(conf|pl)$/) { } 0 0 0
1638 0 push @very_last_postamble, $entry;
1639 }
1640 else {
1641 0 $self->postamble($entry);
1642 }
1643  
1644 }
1645 }
1646  
1647 0 $self->configure_proxy;
1648  
1649 0 my $conf_file = $vars->{t_conf_file};
1650 0 my $conf_file_in = join '.', $conf_file, 'in';
1651  
1652 0 my $in = $self->httpd_conf_template($conf_file_in);
1653  
1654 0 my $out = $self->genfile($conf_file);
1655  
1656 0 $self->find_and_load_module('mod_alias.so');
1657  
1658 0 $self->preamble_run($out);
1659  
1660 0 for my $name (qw(user group)) { #win32
1661 0 ▶ if ($vars->{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vars->{$name}) 0 0 0
1662 0 print $out qq[\u$name "$vars->{$name}"\n];
1663 }
1664 }
1665  
1666 #2.0: ServerName $ServerName:$Port
1667 #1.3: ServerName $ServerName
1668 # Port $Port
1669 my @name_cfg = $self->servername_config($vars->{servername},
1670 0 $vars->{port});
1671 0 for my $pair (@name_cfg) {
1672 0 print $out "@$pair\n";
1673 }
1674  
1675 0 $self->replace_vars($in, $out);
1676  
1677 # handle the case when mod_alias is built as a shared object
1678 # but wasn't included in the system-wide httpd.conf
1679  
1680 0 print $out "<IfModule mod_alias.c>\n";
1681 0 for (sort keys %aliases) {
1682 0 ▶ next unless $vars->{$aliases{$_}};
Branch: 1 branch
BranchTrueFalseTotal
unless $$vars{$aliases{$_}} 0 0 0
1683 0 print $out " Alias /getfiles-$_ $vars->{$aliases{$_}}\n";
1684 }
1685 0 print $out "</IfModule>\n";
1686  
1687 0 print $out "\n";
1688  
1689 0 $self->postamble_run($out);
1690  
1691 0 print $out join "\n", @very_last_postamble;
1692  
1693 0 close $in;
1694 0 ▶ close $out or die "close $conf_file: $!";
Branch: 1 branch
BranchTrueFalseTotal
close $out or die "close ${conf_file}: $!" 0 0 0
1695 }
1696  
1697 0 ▶sub need_reconfiguration {
Subroutine need_reconfiguration: not called CC=14 SCAR=53.5
Pod undocumented
1698 0 my($self, $conf_opts) = @_;
1699 0 my @reasons = ();
1700 0 my $vars = $self->{vars};
1701  
1702 # if '-port select' we need to check from scratch which ports are
1703 # available
1704 0 ▶ if (my $port = $conf_opts->{port} || $Apache::TestConfig::Argv{port}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $port = $conf_opts->{"port"} || $Apache::TestConfig::Argv{"port"}) 0 0 0
Condition0%0/3
$conf_opts->{'port'} || $Apache::TestConfig::Argv{'port'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$conf_opts->{'port'} || $Apache::TestConfig::Argv{'port'}
$conf_opts->{'port'} $Apache::TestConfig::Argv{'port'}
Truth table0%0/3
A || B
A= $conf_opts->{'port'}B= $Apache::TestConfig::Argv{'port'}
ABresult
1X1
011
000
1705 0 ▶ if ($port eq 'select') {
Branch: 1 branch
BranchTrueFalseTotal
if ($port eq "select") 0 0 0
1706 0 push @reasons, "'-port $port' requires reconfiguration";
1707 }
1708 }
1709  
1710 0 ▶ my $exe = $vars->{apxs} || $vars->{httpd} || '';
Condition0%0/5
$vars->{'apxs'} || $vars->{'httpd'} || ''
l!l
00
$vars->{"apxs"} or $vars->{"httpd"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$vars->{'apxs'} || $vars->{'httpd'} || ''
$vars->{"apxs"} $vars->{"httpd"}
Truth table0%0/3
A or B
A= $vars->{"apxs"}B= $vars->{"httpd"}
ABresult
1X1
011
000
1711 # if httpd.conf is older than executable
1712 push @reasons,
1713 "$exe is newer than $vars->{t_conf_file}"
1714 if -e $exe &&
1715 -e $vars->{t_conf_file} &&
1716 0 ▶ -M $exe < -M $vars->{t_conf_file};
Branch: 1 branch
BranchTrueFalseTotal
if -e $exe and -e $vars->{"t_conf_file"} and -M $exe < -M $vars->{"t_conf_file"} 0 0 0
Condition0%0/6
-e $exe and -e $vars->{"t_conf_file"} and -M $exe < -M $vars->{"t_conf_file"}
!ll&&!rl&&r
000
-e $exe and -e $vars->{"t_conf_file"}
!ll&&!rl&&r
000
MC/DC0%0/3
-e $exe and -e $vars->{"t_conf_file"} and -M $exe < -M $vars->{"t_conf_file"}
-e $exe -e $vars->{"t_conf_file"} -M $exe < -M $vars->{"t_conf_file"}
Truth table0%0/4
A and B and C
A= -e $exeB= -e $vars->{"t_conf_file"}C= -M $exe < -M $vars->{"t_conf_file"}
ABCresult
0XX0
10X0
1100
1111
1717  
1718 # any .in files are newer than their derived versions?
1719 0 ▶ if (my @files = $self->extra_conf_files_needing_update) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@files) = $self->extra_conf_files_needing_update) 0 0 0
1720 # invalidate the vhosts cache, since a different port could be
1721 # assigned on reparse
1722 0 $self->{vhosts} = {};
1723 0 for my $file (@files) {
1724 0 push @reasons, "$file.in is newer than $file";
1725 }
1726 }
1727  
1728 # if special env variables are used (since they can change any time)
1729 # XXX: may be we could check whether they have changed since the
1730 # last run and thus avoid the reconfiguration?
1731 {
1732 0 my $passenv = passenv();
1733 0 ▶ if (my @env_vars = sort grep { $ENV{$_} } keys %$passenv) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@env_vars) = sort(grep({$ENV{$_};} keys %$passenv))) 0 0 0
1734 0 push @reasons, "environment variables (@env_vars) are set";
1735 }
1736 }
1737  
1738 # if the generated config was created with a version of Apache-Test
1739 # less than the current version
1740 {
1741 0 my $current = Apache::Test->VERSION;
1742 0 my $config = $self->{apache_test_version};
1743  
1744 0 ▶ if (! $config || $config < $current) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $config or $config < $current) 0 0 0
Condition0%0/3
not $config or $config < $current
l!l&&r!l&&!r
000
MC/DC0%0/2
not $config or $config < $current
not $config $config < $current
Truth table0%0/3
not(A) or B
A= not $configB= $config < $current
ABresult
1X1
011
000
1745 0 push @reasons, "configuration generated with old Apache-Test";
1746 }
1747 }
1748  
1749 0 return @reasons;
1750 }
1751  
1752 0 ▶sub error_log {
Subroutine error_log: not called CC=3 SCAR=24.8
Pod undocumented
1753 0 my($self, $rel) = @_;
1754 0 my $file = catfile $self->{vars}->{t_logs}, 'error_log';
1755 0 my $rfile = abs2rel $file, $self->{vars}->{top_dir};
1756 0 ▶ return wantarray ? ($file, $rfile) :
Branch: 2 branches
BranchTrueFalseTotal
wantarray ? : 0 0 0
$rel ? : 0 0 0
1757 $rel ? $rfile : $file;
1758 }
1759  
1760 #utils
1761  
1762 #For Win32 systems, stores the extensions used for executable files
1763 #They may be . prefixed, so we will strip the leading periods.
1764  
1765 1 my @path_ext = ();
1766  
1767 1 if (WIN32) {
1768 if ($ENV{PATHEXT}) {
1769 push @path_ext, split ';', $ENV{PATHEXT};
1770 for my $ext (@path_ext) {
1771 $ext =~ s/^\.*(.+)$/$1/;
1772 }
1773 }
1774 else {
1775 #Win9X: doesn't have PATHEXT
1776 push @path_ext, qw(com exe bat);
1777 }
1778 }
1779  
1780 0 ▶sub which {
Subroutine which: not called CC=13 SCAR=52.0
Pod undocumented
1781 0 my $program = shift;
1782  
1783 0 ▶ return undef unless $program;
Branch: 1 branch
BranchTrueFalseTotal
unless $program 0 0 0
1784  
1785 # No need to search PATH components
1786 # if $program already contains a path
1787 0 ▶ return $program if !OSX and !WINFU and
Branch: 1 branch
BranchTrueFalseTotal
if $program =~ m[/] and -f $program and -x $program 0 0 0
Condition0%0/6
$program =~ m[/] and -f $program and -x $program
!ll&&!rl&&r
000
$program =~ m[/] and -f $program
!ll&&!rl&&r
000
MC/DC0%0/3
$program =~ m[/] and -f $program and -x $program
$program =~ m[/] -f $program -x $program
Truth table0%0/4
A and B and C
A= $program =~ m[/]B= -f $programC= -x $program
ABCresult
0XX0
10X0
1100
1111
1788 $program =~ /\// and -f $program and -x $program;
1789  
1790 0 my @dirs = File::Spec->path();
1791  
1792 0 require Config;
1793 0 ▶ my $perl_bin = $Config::Config{bin} || '';
Condition0%0/2
$Config::Config{'bin'} || ''
l!l
00
MC/DC0%0/1
$Config::Config{'bin'} || ''
$Config::Config{'bin'}
Truth table0%0/2
A
A= $Config::Config{'bin'}
Aresult
11
00
1794 0 ▶ push @dirs, $perl_bin if $perl_bin and -d $perl_bin;
Branch: 1 branch
BranchTrueFalseTotal
if $perl_bin and -d $perl_bin 0 0 0
Condition0%0/3
$perl_bin and -d $perl_bin
!ll&&!rl&&r
000
MC/DC0%0/2
$perl_bin and -d $perl_bin
$perl_bin -d $perl_bin
Truth table0%0/3
A and B
A= $perl_binB= -d $perl_bin
ABresult
0X0
100
111
1795  
1796 0 for my $base (map { catfile $_, $program } @dirs) {
1797 0 ▶ if ($ENV{HOME} and not WIN32) {
Branch: 1 branch
BranchTrueFalseTotal
if () 0 0 0
Condition0%0/2
$ENV{"HOME"} and
!ll
00
MC/DC0%0/1
$ENV{"HOME"} and
$ENV{"HOME"}
Truth table0%0/2
A
A= $ENV{"HOME"}
Aresult
00
11
1798 # only works on Unix, but that's normal:
1799 # on Win32 the shell doesn't have special treatment of '~'
1800 0 $base =~ s/~/$ENV{HOME}/o;
1801 }
1802  
1803 0 ▶ return $base if -x $base && -f _;
Branch: 1 branch
BranchTrueFalseTotal
if -x $base and -f _ 0 0 0
Condition0%0/3
-x $base and -f _
!ll&&!rl&&r
000
MC/DC0%0/2
-x $base and -f _
-x $base -f _
Truth table0%0/3
A and B
A= -x $baseB= -f _
ABresult
0X0
100
111
1804  
1805 0 if (WIN32) {
1806 for my $ext (@path_ext) {
1807 return "$base.$ext" if -x "$base.$ext" && -f _;
1808 }
1809 }
1810 }
1811 }
1812  
1813 0 ▶sub apxs {
Subroutine apxs: not called CC=7 SCAR=40.3
Pod undocumented
1814 0 my($self, $q, $ok_fail) = @_;
1815 0 ▶ return unless $self->{APXS};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"APXS"} 0 0 0
1816 0 my $val;
1817 0 ▶ unless (exists $self->{_apxs}{$q}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"_apxs"}{$q}) 0 0 0
1818 0 local @ENV{ qw(IFS CDPATH ENV BASH_ENV) };
1819 0 local $ENV{PATH} = untaint_path($ENV{PATH});
1820 0 my $devnull = devnull();
1821 0 my $apxs = shell_ready($self->{APXS});
1822 0 $val = qx($apxs -q $q 2>$devnull);
1823 0 ▶ chomp $val if defined $val; # apxs post-2.0.40 adds a new line
Branch: 1 branch
BranchTrueFalseTotal
if defined $val 0 0 0
1824 0 ▶ if ($val) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val) 0 0 0
1825 0 $self->{_apxs}{$q} = $val;
1826 }
1827 0 ▶ unless ($val) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($val) 0 0 0
1828 0 ▶ if ($ok_fail) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok_fail) { } 0 0 0
1829 0 return "";
1830 }
1831 else {
1832 0 warn "APXS ($self->{APXS}) query for $q failed\n";
1833 0 return $val;
1834 }
1835 }
1836 }
1837 0 $self->{_apxs}{$q};
1838 }
1839  
1840 # return an untainted PATH
1841 0 ▶sub untaint_path {
Subroutine untaint_path: not called CC=2 SCAR=17.9
Pod undocumented
1842 0 my $path = shift;
1843 0 ▶ return '' unless defined $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path 0 0 0
1844 0 ($path) = ( $path =~ /(.*)/ );
1845 # win32 uses ';' for a path separator, assume others use ':'
1846 0 my $sep = WIN32 ? ';' : ':';
1847 # -T disallows relative and empty directories in the PATH
1848 0 return join $sep, grep File::Spec->file_name_is_absolute($_),
1849 grep length($_), split /$sep/, $path;
1850 }
1851  
1852 2 ▶sub pop_dir {
Subroutine pop_dir: called CC=3 SCAR=11.0
Pod undocumented
1853 2 my $dir = shift;
1854  
1855 2 my @chunks = splitdir $dir;
1856 2 ▶ while (my $remove = shift) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $remove = shift()) 2 2 4
1857 2 ▶ pop @chunks if $chunks[-1] eq $remove;
Branch: 1 branch
BranchTrueFalseTotal
if $chunks[-1] eq $remove 0 2 2
1858 }
1859  
1860 2 catfile @chunks;
1861 }
1862  
1863 2 ▶sub add_inc {
Subroutine add_inc: called CC=5 SCAR=18.0
Pod undocumented
1864 2 my $self = shift;
1865 2 ▶ return if $ENV{MOD_PERL}; #already setup by mod_perl
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"MOD_PERL"} 0 2 2
1866 2 require lib;
1867 # make sure that Apache-Test/lib will be first in @INC,
1868 # followed by modperl-2.0/lib (or some other project's lib/),
1869 # followed by blib/ and finally system-wide libs.
1870 2 my $top_dir = $self->{vars}->{top_dir};
1871 2 my @dirs = map { catdir $top_dir, "blib", $_ } qw(lib arch);
1872  
1873 2 my $apache_test_dir = catdir $top_dir, "Apache-Test";
1874 2 ▶ unshift @dirs, $apache_test_dir if -d $apache_test_dir;
Branch: 1 branch
BranchTrueFalseTotal
if -d $apache_test_dir 0 2 2
1875  
1876 2 lib::->import(@dirs);
1877  
1878 2 ▶ if ($ENV{APACHE_TEST_LIVE_DEV}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"APACHE_TEST_LIVE_DEV"}) 0 2 2
1879 # add lib/ in a separate call to ensure that it'll end up on
1880 # top of @INC
1881 0 my $lib_dir = catdir $top_dir, "lib";
1882 0 ▶ lib::->import($lib_dir) if -d $lib_dir;
Branch: 1 branch
BranchTrueFalseTotal
if -d $lib_dir 0 0 0
1883 }
1884  
1885 #print join "\n", "add_inc", @INC, "";
1886 }
1887  
1888 #freeze/thaw so other processes can access config
1889  
1890 1 ▶sub thaw {
Subroutine thaw: called CC=1 SCAR=0.0
Pod undocumented
1891 1 my $class = shift;
1892 1 $class->new({thaw => 1, @_});
1893 }
1894  
1895 0 ▶sub freeze {
Subroutine freeze: not called CC=1 SCAR=6.9
Pod undocumented
1896 0 require Data::Dumper;
1897 0 local $Data::Dumper::Terse = 1;
1898 0 my $data = Data::Dumper::Dumper(shift);
1899 0 chomp $data;
1900 0 $data;
1901 }
1902  
1903 0 ▶sub sync_vars {
Subroutine sync_vars: not called CC=10 SCAR=47.0
Pod undocumented
1904 0 my $self = shift;
1905  
1906 0 ▶ return if $self->{save}; #this is not a cached config
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"save"} 0 0 0
1907  
1908 0 my $changed = 0;
1909 0 my $thaw = $self->thaw;
1910 0 my $tvars = $thaw->{vars};
1911 0 my $svars = $self->{vars};
1912  
1913 0 for my $key (@_) {
1914 0 for my $v ($tvars, $svars) {
1915 0 ▶ if (exists $v->{$key} and not defined $v->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $v->{$key} and not defined $v->{$key}) 0 0 0
Condition0%0/3
exists $v->{$key} and not defined $v->{$key}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $v->{$key} and not defined $v->{$key}
exists $v->{$key} not defined $v->{$key}
Truth table0%0/3
A and not(B)
A= exists $v->{$key}B= not defined $v->{$key}
ABresult
0X0
100
111
1916 0 $v->{$key} = ''; #rid undef
1917 }
1918 }
1919 next if exists $tvars->{$key} and exists $svars->{$key} and
1920 0 ▶ $tvars->{$key} eq $svars->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $tvars->{$key} and exists $svars->{$key} and $tvars->{$key} eq $svars->{$key} 0 0 0
Condition0%0/6
exists $tvars->{$key} and exists $svars->{$key} and $tvars->{$key} eq $svars->{$key}
!ll&&!rl&&r
000
exists $tvars->{$key} and exists $svars->{$key}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $tvars->{$key} and exists $svars->{$key} and $tvars->{$key} eq $svars->{$key}
exists $tvars->{$key} exists $svars->{$key} $tvars->{$key} eq $svars->{$key}
Truth table0%0/4
A and B and C
A= exists $tvars->{$key}B= exists $svars->{$key}C= $tvars->{$key} eq $svars->{$key}
ABCresult
0XX0
10X0
1100
1111
1921 0 $tvars->{$key} = $svars->{$key};
1922 0 $changed = 1;
1923 }
1924  
1925 0 ▶ return unless $changed;
Branch: 1 branch
BranchTrueFalseTotal
unless $changed 0 0 0
1926  
1927 0 $thaw->{save} = 1;
1928 0 $thaw->save;
1929 }
1930  
1931 0 ▶sub save {
Subroutine save: not called CC=3 SCAR=24.8
Pod undocumented
1932 0 my($self) = @_;
1933  
1934 0 ▶ return unless $self->{save};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"save"} 0 0 0
1935  
1936 # add in the Apache-Test version for later comparisions
1937 0 $self->{apache_test_version} = Apache::Test->VERSION;
1938  
1939 0 my $name = 'apache_test_config';
1940 0 my $file = catfile $self->{vars}->{t_conf}, "$name.pm";
1941 0 my $fh = $self->genfile($file);
1942  
1943 0 debug "saving config data to $name.pm";
1944  
1945 0 (my $obj = $self->freeze) =~ s/^/ /;
1946  
1947 0 print $fh <<EOF;
1948 package $name;
1949  
1950 sub new {
1951 $obj;
1952 }
1953  
1954 1;
1955 EOF
1956  
1957 0 ▶ close $fh or die "failed to write $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
close $fh or die "failed to write ${file}: $!" 0 0 0
1958 }
1959  
1960 0 ▶sub as_string {
Subroutine as_string: not called CC=2 SCAR=17.9
Pod undocumented
1961 0 my $cfg = '';
1962 0 my $command = '';
1963  
1964 # httpd opts
1965 0 my $test_config = Apache::TestConfig->new({thaw=>1});
1966 # XXX: need to run httpd config to get the value of httpd
1967 0 ▶ if (my $httpd = $test_config->{vars}->{httpd}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $httpd = $test_config->{'vars'}{'httpd'}) { } 0 0 0
1968 0 $httpd = shell_ready($httpd);
1969 0 $command = "$httpd -V";
1970 0 $cfg .= "\n*** $command\n";
1971 0 $cfg .= qx{$command};
1972  
1973 0 $cfg .= ldd_as_string($httpd);
1974 }
1975 else {
1976 0 $cfg .= "\n\n*** The httpd binary was not found\n";
1977 }
1978  
1979 # perl opts
1980 0 my $perl = shell_ready($^X);
1981 0 $command = "$perl -V";
1982 0 $cfg .= "\n\n*** $command\n";
1983 0 $cfg .= qx{$command};
1984  
1985 0 return $cfg;
1986 }
1987  
1988 0 ▶sub ldd_as_string {
Subroutine ldd_as_string: not called CC=3 SCAR=24.8
Pod undocumented
1989 0 my $httpd = shift;
1990  
1991 0 my $command;
1992 0 if (OSX) {
1993 my $otool = which('otool');
1994 $command = "$otool -L $httpd" if $otool;
1995 }
1996 elsif (!WIN32) {
1997 0 my $ldd = which('ldd');
1998 0 ▶ $command = "$ldd $httpd" if $ldd;
Branch: 1 branch
BranchTrueFalseTotal
if $ldd 0 0 0
1999 }
2000  
2001 0 my $cfg = '';
2002 0 ▶ if ($command) {
Branch: 1 branch
BranchTrueFalseTotal
if ($command) 0 0 0
2003 0 $cfg .= "\n*** $command\n";
2004 0 $cfg .= qx{$command};
2005 }
2006  
2007 0 return $cfg;
2008 }
2009  
2010 # make a string suitable for feed to shell calls (wrap in quotes and
2011 # escape quotes)
2012 0 ▶sub shell_ready {
Subroutine shell_ready: not called CC=1 SCAR=6.9
Pod undocumented
2013 0 my $arg = shift;
2014 0 $arg =~ s!\\?"!\\"!g;
2015 0 return qq["$arg"];
2016 }
2017  
2018  
2019 1 1;
2020  
2021 =head1 NAME
2022  
2023 Apache::TestConfig -- Test Configuration setup module
2024  
2025 =head1 SYNOPSIS
2026  
2027 use Apache::TestConfig;
2028  
2029 my $cfg = Apache::TestConfig->new(%args)
2030 my $fh = $cfg->genfile($file);
2031 $cfg->writefile($file, $content);
2032 $cfg->gendir($dir);
2033 ...
2034  
2035 =head1 DESCRIPTION
2036  
2037 C<Apache::TestConfig> is used in creating the C<Apache::Test>
2038 configuration files.
2039  
2040 =head1 FUNCTIONS
2041  
2042 =over
2043  
2044 =item genwarning()
2045  
2046 my $warn = $cfg->genwarning($filename)
2047  
2048 genwarning() returns a warning string as a comment, saying that the
2049 file was autogenerated and that it's not a good idea to modify this
2050 file. After the warning a perl trace of calls to this this function is
2051 appended. This trace is useful for finding what code has created the
2052 file.
2053  
2054 my $warn = $cfg->genwarning($filename, $from_filename)
2055  
2056 If C<$from_filename> is specified it'll be used in the warning to tell
2057 which file it was generated from.
2058  
2059 genwarning() automatically recognizes the comment type based on the
2060 file extension. If the extension is not recognized, the default C<#>
2061 style is used.
2062  
2063 Currently it support C<E<lt>!-- --E<gt>>, C</* ... */> and C<#>
2064 styles.
2065  
2066 =item genfile()
2067  
2068 my $fh = $cfg->genfile($file);
2069  
2070 genfile() creates a new file C<$file> for writing and returns a file
2071 handle.
2072  
2073 If parent directories of C<$file> don't exist they will be
2074 automagically created.
2075  
2076 The file C<$file> and any created parent directories (if found empty)
2077 will be automatically removed on cleanup.
2078  
2079 A comment with a warning and calls trace is added to the top of this
2080 file. See genwarning() for more info about this comment.
2081  
2082 my $fh = $cfg->genfile($file, $from_file);
2083  
2084 If C<$from_filename> is specified it'll be used in the warning to tell
2085 which file it was generated from.
2086  
2087 my $fh = $cfg->genfile($file, $from_file, $nowarning);
2088  
2089 If C<$nowarning> is true, the warning won't be added. If using this
2090 optional argument and there is no C<$from_file> you must pass undef as
2091 in:
2092  
2093 my $fh = $cfg->genfile($file, undef, $nowarning);
2094  
2095  
2096 =item writefile()
2097  
2098 $cfg->writefile($file, $content, [$nowarning]);
2099  
2100 writefile() creates a new file C<$file> with the content of
2101 C<$content>.
2102  
2103 A comment with a warning and calls trace is added to the top of this
2104 file unless C<$nowarnings> is passed and set to a true value. See
2105 genwarning() for more info about this comment.
2106  
2107 If parent directories of C<$file> don't exist they will be
2108 automagically created.
2109  
2110 The file C<$file> and any created parent directories (if found empty)
2111 will be automatically removed on cleanup.
2112  
2113 =item write_perlscript()
2114  
2115 $cfg->write_perlscript($filename, @lines);
2116  
2117 Similar to writefile() but creates an executable Perl script with
2118 correctly set shebang line.
2119  
2120 =item gendir()
2121  
2122 $cfg->gendir($dir);
2123  
2124 gendir() creates a new directory C<$dir>.
2125  
2126 If parent directories of C<$dir> don't exist they will be
2127 automagically created.
2128  
2129 The directory C<$dir> and any created parent directories will be
2130 automatically removed on cleanup if found empty.
2131  
2132 =back
2133  
2134 =head1 Environment Variables
2135  
2136 The following environment variables affect the configuration and the
2137 run-time of the C<Apache::Test> framework:
2138  
2139 =head2 APACHE_TEST_COLOR
2140  
2141 To aid visual control over the configuration process and the run-time
2142 phase, C<Apache::Test> uses coloured fonts when the environment
2143 variable C<APACHE_TEST_COLOR> is set to a true value.
2144  
2145 =head2 APACHE_TEST_LIVE_DEV
2146  
2147 When using C<Apache::Test> during the project development phase, it's
2148 often convenient to have the I<project/lib> (live) directory appearing
2149 first in C<@INC> so any changes to the Perl modules, residing in it,
2150 immediately affect the server, without a need to rerun C<make> to
2151 update I<blib/lib>. When the environment variable
2152 C<APACHE_TEST_LIVE_DEV> is set to a true value during the
2153 configuration phase (C<t/TEST -config>, C<Apache::Test> will
2154 automatically unshift the I<project/lib> directory into C<@INC>, via
2155 the autogenerated I<t/conf/modperl_inc.pl> file.
2156  
2157  
2158 =head1 Special Placeholders
2159  
2160 When generating configuration files from the I<*.in> templates,
2161 special placeholder variables get substituted. To embed a placeholder
2162 use the C<@foo@> syntax. For example in I<extra.conf.in> you can
2163 write:
2164  
2165 Include @ServerRoot@/conf/myconfig.conf
2166  
2167 When I<extra.conf> is generated, C<@ServerRoot@> will get replaced
2168 with the location of the server root.
2169  
2170 Placeholders are case-insensitive.
2171  
2172 Available placeholders:
2173  
2174 =head2 Configuration Options
2175  
2176 All configuration variables that can be passed to C<t/TEST>, such as
2177 C<MaxClients>, C<DocumentRoot>, C<ServerRoot>, etc. To see the
2178 complete list run:
2179  
2180 % t/TEST --help
2181  
2182 and you will find them in the C<configuration options> sections.
2183  
2184 =head2 NextAvailablePort
2185  
2186 Every time this placeholder is encountered it'll be replaced with the
2187 next available port. This is very useful if you need to allocate a
2188 special port, but not hardcode it. Later when running:
2189  
2190 % t/TEST -port=select
2191  
2192 it's possible to run several concurrent test suites on the same
2193 machine, w/o having port collisions.
2194  
2195 =head1 AUTHOR
2196  
2197 =head1 SEE ALSO
2198  
2199 perl(1), Apache::Test(3)
2200  
2201 =cut
2202  
2203  
2204 __DATA__
« lib/Apache/TestConfigPerl.pm ↑ Summary lib/Apache/TestRequest.pm »