Apache-Test
view release on metacpan or search on metacpan
lib/Apache/TestConfig.pm view on Meta::CPAN
$vars->{proxy} ||= 'off';
$vars->{proxyssl_url} ||= '';
$vars->{defines} ||= '';
$self->{hostport} = $self->hostport;
$self->{server} = $self->new_test_server;
return $self;
}
# figure out where httpd is and run extra config hooks which require
# knowledge of where httpd is
sub httpd_config {
my $self = shift;
$self->configure_apxs;
$self->configure_httpd;
my $vars = $self->{vars};
unless ($vars->{httpd} or $vars->{apxs}) {
# mod_perl 2.0 build (almost) always knows the right httpd
# location (and optionally apxs). if we get here we can't
# continue because the interactive config can't work with
# mod_perl 2.0 build (by design)
if (IS_MOD_PERL_2_BUILD){
my $mp2_build = $self->modperl_build_config();
# if mod_perl 2 was built against the httpd source it
# doesn't know where to find apxs/httpd, so in this case
# fall back to interactive config
unless ($mp2_build->{MP_APXS}) {
die "mod_perl 2 was built against Apache sources, we " .
"don't know where httpd/apxs executables are, therefore " .
"skipping the test suite execution"
}
# not sure what else could go wrong but we can't continue
die "something is wrong, mod_perl 2.0 build should have " .
"supplied all the needed information to run the tests. " .
"Please post lib/Apache2/BuildConfig.pm along with the " .
"bug report";
}
$self->clean(1);
error "You must explicitly specify -httpd and/or -apxs options, " .
"or set \$ENV{APACHE_TEST_HTTPD} and \$ENV{APACHE_TEST_APXS}, " .
"or set your \$PATH to include the httpd and apxs binaries.";
Apache::TestRun::exit_perl(1);
}
else {
debug "Using httpd: $vars->{httpd}";
}
$self->inherit_config; #see TestConfigParse.pm
$self->configure_httpd_eapi; #must come after inherit_config
$self->default_module(cgi => [qw(mod_cgi mod_cgid)]);
$self->default_module(thread => [qw(worker threaded)]);
$self->default_module(ssl => [qw(mod_ssl)]);
$self->default_module(access => [qw(mod_access mod_authz_host)]);
$self->default_module(auth => [qw(mod_auth mod_auth_basic)]);
$self->default_module(php => [qw(sapi_apache2 mod_php4 mod_php5)]);
$self->{server}->post_config;
return $self;
}
sub default_module {
my($self, $name, $choices) = @_;
my $mname = $name . '_module_name';
unless ($self->{vars}->{$mname}) {
($self->{vars}->{$mname}) = grep {
$self->{modules}->{"$_.c"};
} @$choices;
$self->{vars}->{$mname} ||= $choices->[0];
}
$self->{vars}->{$name . '_module'} =
$self->{vars}->{$mname} . '.c'
}
sub configure_apxs {
my $self = shift;
$self->{APXS} = $self->default_apxs;
return unless $self->{APXS};
$self->{APXS} =~ s{/}{\\}g if WIN32;
my $vars = $self->{vars};
$vars->{bindir} ||= $self->apxs('BINDIR', 1);
$vars->{sbindir} ||= $self->apxs('SBINDIR');
$vars->{target} ||= $self->apxs('TARGET');
$vars->{conf_dir} ||= $self->apxs('SYSCONFDIR');
if ($vars->{conf_dir}) {
$vars->{httpd_conf} ||= catfile $vars->{conf_dir}, 'httpd.conf';
}
}
sub configure_httpd {
my $self = shift;
my $vars = $self->{vars};
debug "configuring httpd";
$vars->{target} ||= (WIN32 ? 'Apache.EXE' : 'httpd');
unless ($vars->{httpd}) {
#sbindir should be bin/ with the default layout
#but its eaiser to workaround apxs than fix apxs
lib/Apache/TestConfig.pm view on Meta::CPAN
(ref($arg) && (ref($arg) eq 'ARRAY') ? "@$arg" : $arg || "");
}
return $args;
}
sub postamble_first {
shift->add_config_first(postamble => @_);
}
sub postamble {
shift->add_config_last(postamble => @_);
}
sub preamble_first {
shift->add_config_first(preamble => @_);
}
sub preamble {
shift->add_config_last(preamble => @_);
}
sub postamble_register {
push @{ shift->{postamble_hooks} }, @_;
}
sub preamble_register {
push @{ shift->{preamble_hooks} }, @_;
}
sub add_config_hooks_run {
my($self, $where, $out) = @_;
for (@{ $self->{"${where}_hooks"} }) {
if ((ref($_) and ref($_) eq 'CODE') or $self->can($_)) {
$self->$_();
}
else {
error "cannot run configure hook: `$_'";
}
}
for (@{ $self->{$where} }) {
$self->replace;
s/\n?$/\n/;
print $out "$_";
}
}
sub postamble_run {
shift->add_config_hooks_run(postamble => @_);
}
sub preamble_run {
shift->add_config_hooks_run(preamble => @_);
}
sub default_group {
return if WINFU;
my $gid = $);
#use only first value if $) contains more than one
$gid =~ s/^(\d+).*$/$1/;
my $group = $ENV{APACHE_TEST_GROUP} || (getgrgid($gid) || "#$gid");
if ($group eq 'root') {
# similar to default_user, we want to avoid perms problems,
# when the server is started with group 'root'. When running
# under group root it may fail to create dirs and files,
# writable only by user
my $user = default_user();
my $gid = $user ? (getpwnam($user))[3] : '';
$group = (getgrgid($gid) || "#$gid") if $gid;
}
$group;
}
sub default_user {
return if WINFU;
my $uid = $>;
my $user = $ENV{APACHE_TEST_USER} || (getpwuid($uid) || "#$uid");
if ($user eq 'root') {
my $other = (getpwnam('nobody'))[0];
if ($other) {
$user = $other;
}
else {
die "cannot run tests as User root";
#XXX: prompt for another username
}
}
return $user;
}
sub default_serveradmin {
my $vars = shift->{vars};
join '@', ($vars->{user} || 'unknown'), $vars->{servername};
}
sub default_apxs {
my $self = shift;
return $self->{vars}->{apxs} if $self->{vars}->{apxs};
if (my $build_config = $self->modperl_build_config()) {
return $build_config->{MP_APXS};
}
if ($ENV{APACHE_TEST_APXS}) {
return $ENV{APACHE_TEST_APXS};
}
# look in PATH as a last resort
if (my $apxs = which('apxs')) {
return $apxs;
} elsif ($apxs = which('apxs2')) {
return $apxs;
}
return;
}
sub default_httpd {
my $self = shift;
my $vars = $self->{vars};
if (my $build_config = $self->modperl_build_config()) {
lib/Apache/TestConfig.pm view on Meta::CPAN
Placeholders are case-insensitive.
Available placeholders:
=head2 Configuration Options
All configuration variables that can be passed to C<t/TEST>, such as
C<MaxClients>, C<DocumentRoot>, C<ServerRoot>, etc. To see the
complete list run:
% t/TEST --help
and you will find them in the C<configuration options> sections.
=head2 NextAvailablePort
Every time this placeholder is encountered it'll be replaced with the
next available port. This is very useful if you need to allocate a
special port, but not hardcode it. Later when running:
% t/TEST -port=select
it's possible to run several concurrent test suites on the same
machine, w/o having port collisions.
=head1 AUTHOR
=head1 SEE ALSO
perl(1), Apache::Test(3)
=cut
__DATA__
Listen 0.0.0.0:@Port@
ServerRoot "@ServerRoot@"
DocumentRoot "@DocumentRoot@"
PidFile @t_pid_file@
ErrorLog @t_logs@/error_log
LogLevel debug
<IfModule mod_version.c>
<IfVersion > 2.4.1>
DefaultRunTimeDir "@t_logs@"
LogLevel trace8
</IfVersion>
<IfVersion > 2.4.34>
<IfDirective DefaultStateDir>
DefaultStateDir "@t_state@"
</IfDirective>
</IfVersion>
</IfModule>
<IfModule mod_log_config.c>
TransferLog @t_logs@/access_log
</IfModule>
<IfModule mod_cgid.c>
ScriptSock @t_logs@/cgisock
</IfModule>
ServerAdmin @ServerAdmin@
#needed for http/1.1 testing
KeepAlive On
HostnameLookups Off
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<IfModule @THREAD_MODULE@>
<IfModule mod_version.c>
<IfVersion < 2.3.4>
LockFile @t_logs@/accept.lock
</IfVersion>
</IfModule>
StartServers @StartServersThreadedMPM@
MinSpareThreads @ThreadsPerChild@
MaxSpareThreads @MaxSpareThreadedMPM@
ThreadsPerChild @ThreadsPerChild@
MaxClients @MaxClientsThreadedMPM@
MaxRequestsPerChild 0
</IfModule>
<IfModule perchild.c>
<IfModule mod_version.c>
<IfVersion < 2.3.4>
LockFile @t_logs@/accept.lock
</IfVersion>
</IfModule>
NumServers 1
StartThreads @MinClients@
MinSpareThreads 1
MaxSpareThreads @MaxSpare@
MaxThreadsPerChild @MaxClients@
MaxRequestsPerChild 0
</IfModule>
<IfModule prefork.c>
<IfModule mod_version.c>
<IfVersion < 2.3.4>
LockFile @t_logs@/accept.lock
</IfVersion>
</IfModule>
StartServers @MinClients@
MinSpareServers 1
MaxSpareServers @MaxSpare@
MaxClients @MaxClients@
MaxRequestsPerChild 0
</IfModule>
<IfDefine APACHE1>
LockFile @t_logs@/accept.lock
StartServers @MinClients@
MinSpareServers 1
( run in 0.429 second using v1.01-cache-2.11-cpan-5735350b133 )