2007-01-12 05:33:09 +03:00
#!/usr/bin/perl
# Bootstrap Samba and run a number of tests against it.
2010-09-24 02:14:57 +04:00
# Copyright (C) 2005-2010 Jelmer Vernooij <jelmer@samba.org>
2009-02-04 13:20:14 +03:00
# Copyright (C) 2007-2009 Stefan Metzmacher <metze@samba.org>
2009-03-25 17:40:39 +03:00
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2007-03-06 00:28:55 +03:00
2007-01-12 05:33:09 +03:00
use strict ;
use FindBin qw( $RealBin $Script ) ;
use File::Spec ;
2010-04-11 00:20:12 +04:00
use File::Temp qw( tempfile ) ;
2007-01-13 19:08:58 +03:00
use Getopt::Long ;
2007-01-12 05:33:09 +03:00
use POSIX ;
2007-04-17 17:06:00 +04:00
use Cwd qw( abs_path ) ;
2007-03-06 00:28:55 +03:00
use lib "$RealBin" ;
2010-09-14 02:22:55 +04:00
use Subunit ;
2007-03-06 00:28:55 +03:00
use SocketWrapper ;
2016-01-09 23:21:25 +03:00
use target::Samba ;
2007-01-12 05:33:09 +03:00
2010-09-14 01:22:35 +04:00
eval {
require Time::HiRes ;
2010-10-18 20:21:12 +04:00
Time::HiRes - > import ( "time" ) ;
2010-09-14 01:22:35 +04:00
} ;
2010-10-18 20:21:12 +04:00
if ( $@ ) {
print "You don't have Time::Hires installed !\n" ;
2010-09-14 01:22:35 +04:00
}
2007-03-06 00:28:55 +03:00
my $ opt_help = 0 ;
2011-10-26 08:21:11 +04:00
my $ opt_target = "samba" ;
2007-03-06 00:28:55 +03:00
my $ opt_quick = 0 ;
my $ opt_socket_wrapper = 0 ;
my $ opt_socket_wrapper_pcap = undef ;
2007-04-18 04:12:39 +04:00
my $ opt_socket_wrapper_keep_pcap = undef ;
2012-10-27 03:53:57 +04:00
my $ opt_random_order = 0 ;
2007-03-06 00:28:55 +03:00
my $ opt_one = 0 ;
2007-10-26 00:20:52 +04:00
my @ opt_exclude = ( ) ;
my @ opt_include = ( ) ;
2007-03-07 05:11:40 +03:00
my $ opt_testenv = 0 ;
2010-12-09 16:46:09 +03:00
my $ opt_list = 0 ;
2007-04-17 04:30:01 +04:00
my $ ldap = undef ;
2007-04-11 00:19:31 +04:00
my $ opt_resetup_env = undef ;
2010-04-08 18:16:15 +04:00
my $ opt_load_list = undef ;
2014-01-31 19:34:25 +04:00
my $ opt_libnss_wrapper_so_path = "" ;
2014-09-03 19:16:36 +04:00
my $ opt_libresolv_wrapper_so_path = "" ;
2014-02-13 18:49:27 +04:00
my $ opt_libsocket_wrapper_so_path = "" ;
2013-07-03 14:55:29 +04:00
my $ opt_libuid_wrapper_so_path = "" ;
2014-11-03 15:22:38 +03:00
my $ opt_use_dns_faking = 0 ;
2007-10-26 00:20:52 +04:00
my @ testlists = ( ) ;
2007-01-12 05:33:09 +03:00
2007-03-06 00:28:55 +03:00
my $ srcdir = "." ;
2011-04-15 06:41:22 +04:00
my $ bindir = "./bin" ;
2007-04-17 17:06:00 +04:00
my $ prefix = "./st" ;
2007-03-06 00:28:55 +03:00
2007-10-26 00:20:52 +04:00
my @ includes = ( ) ;
my @ excludes = ( ) ;
2007-03-06 00:28:55 +03:00
2007-09-02 04:24:38 +04:00
sub find_in_list ($$)
2007-01-12 05:33:09 +03:00
{
2007-09-02 04:24:38 +04:00
my ( $ list , $ fullname ) = @ _ ;
2007-01-12 05:33:09 +03:00
2007-09-02 04:24:38 +04:00
foreach ( @$ list ) {
if ( $ fullname =~ /$$_[0]/ ) {
return ( $$ _ [ 1 ] ) if ( $$ _ [ 1 ] ) ;
2009-06-05 18:10:12 +04:00
return "" ;
2007-09-02 04:24:38 +04:00
}
2007-04-18 18:18:33 +04:00
}
2007-01-12 05:33:09 +03:00
2007-09-02 04:24:38 +04:00
return undef ;
2007-03-06 00:28:55 +03:00
}
2007-09-02 04:24:38 +04:00
sub skip ($)
{
my ( $ name ) = @ _ ;
2007-10-26 00:20:52 +04:00
2007-10-31 16:48:48 +03:00
return find_in_list ( \ @ excludes , $ name ) ;
2007-03-06 01:24:21 +03:00
}
2007-04-18 18:02:26 +04:00
sub getlog_env ($) ;
2007-12-20 19:07:21 +03:00
sub setup_pcap ($)
2007-04-19 12:04:35 +04:00
{
2008-02-21 17:54:31 +03:00
my ( $ name ) = @ _ ;
2007-04-19 12:04:35 +04:00
return unless ( $ opt_socket_wrapper_pcap ) ;
return unless defined ( $ ENV { SOCKET_WRAPPER_PCAP_DIR } ) ;
2007-12-20 17:54:05 +03:00
my $ fname = $ name ;
2007-04-19 12:04:35 +04:00
$ fname =~ s%[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\-]%_%g ;
2007-12-20 19:07:21 +03:00
my $ pcap_file = "$ENV{SOCKET_WRAPPER_PCAP_DIR}/$fname.pcap" ;
2007-04-19 12:04:35 +04:00
2007-12-20 19:07:21 +03:00
SocketWrapper:: setup_pcap ( $ pcap_file ) ;
return $ pcap_file ;
2007-04-19 12:04:35 +04:00
}
2009-06-04 15:49:11 +04:00
sub cleanup_pcap ($$)
2007-04-19 12:04:35 +04:00
{
2009-06-04 15:49:11 +04:00
my ( $ pcap_file , $ exitcode ) = @ _ ;
2007-04-19 12:04:35 +04:00
return unless ( $ opt_socket_wrapper_pcap ) ;
return if ( $ opt_socket_wrapper_keep_pcap ) ;
2009-06-04 15:49:11 +04:00
return unless ( $ exitcode == 0 ) ;
2007-12-20 19:07:21 +03:00
return unless defined ( $ pcap_file ) ;
2007-04-19 12:04:35 +04:00
2007-12-20 19:07:21 +03:00
unlink ( $ pcap_file ) ;
2007-04-19 12:04:35 +04:00
}
2010-01-11 01:36:48 +03:00
# expand strings from %ENV
sub expand_environment_strings ($)
{
my $ s = shift ;
# we use a reverse sort so we do the longer ones first
foreach my $ k ( sort { $ b cmp $ a } keys % ENV ) {
$ s =~ s/\$$k/$ENV{$k}/g ;
}
return $ s ;
}
2010-04-11 00:20:12 +04:00
sub run_testsuite ($$$$$)
2007-08-12 05:49:38 +04:00
{
2010-04-11 00:20:12 +04:00
my ( $ envname , $ name , $ cmd , $ i , $ totalsuites ) = @ _ ;
2007-12-20 19:07:21 +03:00
my $ pcap_file = setup_pcap ( $ name ) ;
2007-08-12 05:49:38 +04:00
2009-06-05 18:10:12 +04:00
Subunit:: start_testsuite ( $ name ) ;
2010-03-30 16:42:23 +04:00
Subunit:: progress_push ( ) ;
2009-06-17 23:37:49 +04:00
Subunit:: report_time ( time ( ) ) ;
2010-09-22 22:30:34 +04:00
system ( $ cmd ) ;
Subunit:: report_time ( time ( ) ) ;
Subunit:: progress_pop ( ) ;
2007-08-12 05:49:38 +04:00
2010-09-22 22:30:34 +04:00
if ( $? == - 1 ) {
2010-03-30 16:30:08 +04:00
Subunit:: progress_pop ( ) ;
2010-09-22 22:30:34 +04:00
Subunit:: end_testsuite ( $ name , "error" , "Unable to run $cmd: $!" ) ;
2010-10-19 07:49:17 +04:00
exit ( 1 ) ;
2010-09-22 22:30:34 +04:00
} elsif ( $? & 127 ) {
Subunit:: end_testsuite ( $ name , "error" ,
sprintf ( "%s died with signal %d, %s coredump\n" , $ cmd , ( $? & 127 ) , ( $? & 128 ) ? 'with' : 'without' ) ) ;
2010-09-24 02:14:57 +04:00
exit ( 1 ) ;
2008-04-16 01:52:06 +04:00
}
2010-09-22 22:30:34 +04:00
my $ exitcode = $? >> 8 ;
2007-12-20 17:54:02 +03:00
my $ envlog = getlog_env ( $ envname ) ;
2009-06-04 15:49:11 +04:00
if ( $ envlog ne "" ) {
2009-06-04 19:30:23 +04:00
print "envlog: $envlog\n" ;
2009-06-04 15:49:11 +04:00
}
2007-12-20 17:54:05 +03:00
2009-06-04 19:30:23 +04:00
print "command: $cmd\n" ;
2010-01-11 01:36:48 +03:00
printf "expanded command: %s\n" , expand_environment_strings ( $ cmd ) ;
2007-04-19 12:04:35 +04:00
2009-06-04 15:49:11 +04:00
if ( $ exitcode == 0 ) {
2009-06-05 18:32:52 +04:00
Subunit:: end_testsuite ( $ name , "success" ) ;
2007-12-20 17:54:02 +03:00
} else {
2009-06-05 18:32:52 +04:00
Subunit:: end_testsuite ( $ name , "failure" , "Exit code was $exitcode" ) ;
2007-12-20 17:54:02 +03:00
}
2007-04-19 12:04:35 +04:00
2009-06-04 15:49:11 +04:00
cleanup_pcap ( $ pcap_file , $ exitcode ) ;
2007-08-12 04:50:25 +04:00
2008-04-16 01:52:06 +04:00
if ( not $ opt_socket_wrapper_keep_pcap and defined ( $ pcap_file ) ) {
2009-06-04 15:49:11 +04:00
print "PCAP FILE: $pcap_file\n" ;
2007-08-12 04:50:25 +04:00
}
2007-04-19 12:04:35 +04:00
2009-06-04 15:49:11 +04:00
if ( $ exitcode != 0 ) {
2007-03-06 00:28:55 +03:00
exit ( 1 ) if ( $ opt_one ) ;
2007-01-12 05:33:09 +03:00
}
2007-04-18 04:12:39 +04:00
2009-06-04 15:49:11 +04:00
return $ exitcode ;
2007-01-12 05:33:09 +03:00
}
2007-01-13 19:08:58 +03:00
sub ShowHelp ()
{
print " Samba test runner
Copyright ( C ) Jelmer Vernooij <jelmer\@samba.org>
2009-02-04 13:20:14 +03:00
Copyright ( C ) Stefan Metzmacher <metze\@samba.org>
2007-01-13 19:08:58 +03:00
2008-10-19 16:50:25 +04:00
Usage: $ Script [ OPTIONS ] TESTNAME - REGEX
2007-01-13 19:08:58 +03:00
Generic options:
2007-01-13 23:02:10 +03:00
- - help this help page
2011-11-30 23:42:58 +04:00
- - target = samba [ 3 ] | win Samba version to target
- - testlist = FILE file to read available tests from
2014-10-13 07:59:02 +04:00
- - exclude = FILE Exclude tests listed in the file
- - include = FILE Include tests listed in the file
2007-03-06 00:28:55 +03:00
Paths:
- - prefix = DIR prefix to run tests in [ st ]
- - srcdir = DIR source directory [ . ]
2011-04-15 06:41:22 +04:00
- - bindir = DIR binaries directory [ . / bin ]
2007-03-06 00:28:55 +03:00
2013-07-03 14:55:29 +04:00
Preload cwrap:
2014-01-31 19:34:25 +04:00
- - nss_wrapper_so_path = FILE the nss_wrapper library to preload
2014-09-03 19:16:36 +04:00
- - resolv_wrapper_so_path = FILE the resolv_wrapper library to preload
2014-02-13 18:49:27 +04:00
- - socket_wrapper_so_path = FILE the socket_wrapper library to preload
2013-07-03 14:55:29 +04:00
- - uid_wrapper_so_path = FILE the uid_wrapper library to preload
2014-11-03 15:22:38 +03:00
DNS:
- - use - dns - faking Fake DNS entries rather than talking to our
DNS implementation .
2007-03-06 00:28:55 +03:00
Target Specific:
2011-11-30 23:42:58 +04:00
- - socket - wrapper - pcap save traffic to pcap directories
2007-04-18 04:12:39 +04:00
- - socket - wrapper - keep - pcap keep all pcap files , not just those for tests that
failed
2007-01-13 23:02:10 +03:00
- - socket - wrapper enable socket wrapper
2007-04-18 04:12:39 +04:00
Samba4 Specific:
2008-10-19 16:50:25 +04:00
- - ldap = openldap | fedora - ds back samba onto specified ldap server
2007-03-06 00:28:55 +03:00
Behaviour:
2007-01-13 23:02:10 +03:00
- - quick run quick overall test
2007-01-14 07:32:11 +03:00
- - one abort when the first test fails
2010-12-09 15:37:13 +03:00
- - testenv run a shell in the requested test environment
2010-12-09 16:46:09 +03:00
- - list list available tests
2007-01-13 19:08:58 +03:00
" ;
exit ( 0 ) ;
}
my $ result = GetOptions (
2007-04-12 16:45:41 +04:00
'help|h|?' = > \ $ opt_help ,
2007-03-06 00:28:55 +03:00
'target=s' = > \ $ opt_target ,
'prefix=s' = > \ $ prefix ,
2007-01-13 23:02:10 +03:00
'socket-wrapper' = > \ $ opt_socket_wrapper ,
2007-04-18 04:12:39 +04:00
'socket-wrapper-pcap' = > \ $ opt_socket_wrapper_pcap ,
'socket-wrapper-keep-pcap' = > \ $ opt_socket_wrapper_keep_pcap ,
2007-01-14 07:32:11 +03:00
'quick' = > \ $ opt_quick ,
2007-03-06 00:28:55 +03:00
'one' = > \ $ opt_one ,
2007-10-26 00:20:52 +04:00
'exclude=s' = > \ @ opt_exclude ,
'include=s' = > \ @ opt_include ,
2007-03-06 00:28:55 +03:00
'srcdir=s' = > \ $ srcdir ,
2011-04-15 06:41:22 +04:00
'bindir=s' = > \ $ bindir ,
2007-03-21 18:57:07 +03:00
'testenv' = > \ $ opt_testenv ,
2010-12-09 16:46:09 +03:00
'list' = > \ $ opt_list ,
2007-04-17 04:30:01 +04:00
'ldap:s' = > \ $ ldap ,
2007-04-11 00:19:31 +04:00
'resetup-environment' = > \ $ opt_resetup_env ,
2010-04-08 18:16:15 +04:00
'testlist=s' = > \ @ testlists ,
2012-10-27 03:53:57 +04:00
'random-order' = > \ $ opt_random_order ,
2010-04-08 18:16:15 +04:00
'load-list=s' = > \ $ opt_load_list ,
2014-01-31 19:34:25 +04:00
'nss_wrapper_so_path=s' = > \ $ opt_libnss_wrapper_so_path ,
2014-09-03 19:16:36 +04:00
'resolv_wrapper_so_path=s' = > \ $ opt_libresolv_wrapper_so_path ,
2014-02-13 18:49:27 +04:00
'socket_wrapper_so_path=s' = > \ $ opt_libsocket_wrapper_so_path ,
2014-11-03 15:22:38 +03:00
'uid_wrapper_so_path=s' = > \ $ opt_libuid_wrapper_so_path ,
'use-dns-faking' = > \ $ opt_use_dns_faking
2007-01-13 19:08:58 +03:00
) ;
2007-03-06 00:28:55 +03:00
exit ( 1 ) if ( not $ result ) ;
2007-01-13 19:08:58 +03:00
ShowHelp ( ) if ( $ opt_help ) ;
2007-01-12 05:33:09 +03:00
2010-12-09 16:46:09 +03:00
die ( "--list and --testenv are mutually exclusive" ) if ( $ opt_list and $ opt_testenv ) ;
2009-11-16 18:34:13 +03:00
# we want unbuffered output
$| = 1 ;
2009-08-14 07:04:21 +04:00
my @ tests = @ ARGV ;
2007-01-12 05:33:09 +03:00
2007-03-06 00:28:55 +03:00
# quick hack to disable rpc validation when using valgrind - its way too slow
unless ( defined ( $ ENV { VALGRIND } ) ) {
$ ENV { VALIDATE } = "validate" ;
2013-03-20 13:58:22 +04:00
$ ENV { MALLOC_CHECK_ } = 3 ;
2007-01-12 05:33:09 +03:00
}
2009-10-22 04:04:40 +04:00
# make all our python scripts unbuffered
$ ENV { PYTHONUNBUFFERED } = 1 ;
2009-02-02 14:43:20 +03:00
my $ bindir_abs = abs_path ( $ bindir ) ;
2007-04-17 04:30:01 +04:00
# Backwards compatibility:
if ( defined ( $ ENV { TEST_LDAP } ) and $ ENV { TEST_LDAP } eq "yes" ) {
2007-12-21 11:33:43 +03:00
if ( defined ( $ ENV { FEDORA_DS_ROOT } ) ) {
2007-05-29 17:06:08 +04:00
$ ldap = "fedora-ds" ;
2007-04-17 04:30:01 +04:00
} else {
$ ldap = "openldap" ;
}
2007-03-21 18:57:07 +03:00
}
my $ torture_maxtime = ( $ ENV { TORTURE_MAXTIME } or 1200 ) ;
if ( $ ldap ) {
# LDAP is slow
$ torture_maxtime *= 2 ;
}
2007-01-12 05:33:09 +03:00
$ prefix =~ s + // + / + ;
2007-04-17 17:06:00 +04:00
$ prefix =~ s + /./ + / + ;
$ prefix =~ s + / $+ + ;
2007-04-19 11:39:45 +04:00
die ( "using an empty prefix isn't allowed" ) unless $ prefix ne "" ;
2011-04-29 09:54:20 +04:00
# Ensure we have the test prefix around.
#
# We need restrictive
# permissions on this as some subdirectories in this tree will have
# wider permissions (ie 0777) and this would allow other users on the
# host to subvert the test process.
mkdir ( $ prefix , 0700 ) unless - d $ prefix ;
chmod 0700 , $ prefix ;
2007-04-19 11:39:45 +04:00
2007-04-17 17:06:00 +04:00
my $ prefix_abs = abs_path ( $ prefix ) ;
2010-10-01 05:31:06 +04:00
my $ tmpdir_abs = abs_path ( "$prefix/tmp" ) ;
mkdir ( $ tmpdir_abs , 0777 ) unless - d $ tmpdir_abs ;
2007-04-17 17:06:00 +04:00
my $ srcdir_abs = abs_path ( $ srcdir ) ;
die ( "using an empty absolute prefix isn't allowed" ) unless $ prefix_abs ne "" ;
die ( "using '/' as absolute prefix isn't allowed" ) unless $ prefix_abs ne "/" ;
2007-01-12 05:33:09 +03:00
$ ENV { PREFIX } = $ prefix ;
2007-07-12 13:52:32 +04:00
$ ENV { PREFIX_ABS } = $ prefix_abs ;
2007-01-12 05:33:09 +03:00
$ ENV { SRCDIR } = $ srcdir ;
2007-07-12 13:52:32 +04:00
$ ENV { SRCDIR_ABS } = $ srcdir_abs ;
2016-01-12 15:51:00 +03:00
$ ENV { GNUPGHOME } = "$srcdir_abs/selftest/gnupg" ;
2011-02-21 08:01:44 +03:00
$ ENV { BINDIR } = $ bindir_abs ;
2007-01-12 05:33:09 +03:00
2007-10-08 19:22:26 +04:00
my $ tls_enabled = not $ opt_quick ;
2007-01-12 05:33:09 +03:00
$ ENV { TLS_ENABLED } = ( $ tls_enabled ? "yes" : "no" ) ;
2010-10-30 04:29:49 +04:00
2008-05-23 17:20:32 +04:00
sub prefix_pathvar ($$)
{
my ( $ name , $ newpath ) = @ _ ;
if ( defined ( $ ENV { $ name } ) ) {
$ ENV { $ name } = "$newpath:$ENV{$name}" ;
} else {
$ ENV { $ name } = $ newpath ;
}
2007-12-17 13:12:26 +03:00
}
2009-02-02 14:43:20 +03:00
prefix_pathvar ( "PKG_CONFIG_PATH" , "$bindir_abs/pkgconfig" ) ;
prefix_pathvar ( "PYTHONPATH" , "$bindir_abs/python" ) ;
2007-01-12 05:33:09 +03:00
2007-10-12 10:08:46 +04:00
if ( $ opt_socket_wrapper_keep_pcap ) {
# Socket wrapper keep pcap implies socket wrapper pcap
$ opt_socket_wrapper_pcap = 1 ;
}
2007-04-18 04:12:39 +04:00
2007-03-06 00:28:55 +03:00
if ( $ opt_socket_wrapper_pcap ) {
# Socket wrapper pcap implies socket wrapper
$ opt_socket_wrapper = 1 ;
}
2007-01-12 05:33:09 +03:00
2013-07-03 14:55:29 +04:00
my $ ld_preload = $ ENV { LD_PRELOAD } ;
2014-01-31 19:34:25 +04:00
if ( $ opt_libnss_wrapper_so_path ) {
if ( $ ld_preload ) {
$ ld_preload = "$ld_preload:$opt_libnss_wrapper_so_path" ;
} else {
$ ld_preload = "$opt_libnss_wrapper_so_path" ;
}
}
2014-09-03 19:16:36 +04:00
if ( $ opt_libresolv_wrapper_so_path ) {
if ( $ ld_preload ) {
$ ld_preload = "$ld_preload:$opt_libresolv_wrapper_so_path" ;
} else {
$ ld_preload = "$opt_libresolv_wrapper_so_path" ;
}
}
2014-02-13 18:49:27 +04:00
if ( $ opt_libsocket_wrapper_so_path ) {
if ( $ ld_preload ) {
$ ld_preload = "$ld_preload:$opt_libsocket_wrapper_so_path" ;
} else {
$ ld_preload = "$opt_libsocket_wrapper_so_path" ;
}
}
2013-07-03 14:55:29 +04:00
if ( $ opt_libuid_wrapper_so_path ) {
if ( $ ld_preload ) {
$ ld_preload = "$ld_preload:$opt_libuid_wrapper_so_path" ;
} else {
$ ld_preload = "$opt_libuid_wrapper_so_path" ;
}
}
$ ENV { LD_PRELOAD } = $ ld_preload ;
print "LD_PRELOAD=$ENV{LD_PRELOAD}\n" ;
2014-04-03 12:42:30 +04:00
# Enable uid_wrapper globally
$ ENV { UID_WRAPPER } = 1 ;
2014-03-04 16:52:52 +04:00
# Disable RTLD_DEEPBIND hack for Samba bind dlz module
#
# This is needed in order to allow the ldb_*ldap module
# to work with a preloaded socket wrapper.
$ ENV { LDB_MODULES_DISABLE_DEEPBIND } = 1 ;
2007-03-06 00:28:55 +03:00
my $ socket_wrapper_dir ;
2007-04-04 18:24:44 +04:00
if ( $ opt_socket_wrapper ) {
2010-01-19 02:55:48 +03:00
$ socket_wrapper_dir = SocketWrapper:: setup_dir ( "$prefix_abs/w" , $ opt_socket_wrapper_pcap ) ;
2007-03-06 00:28:55 +03:00
print "SOCKET_WRAPPER_DIR=$socket_wrapper_dir\n" ;
2011-11-27 22:53:35 +04:00
} elsif ( not $ opt_list ) {
2015-01-30 04:22:46 +03:00
unless ( $< == 0 ) {
2011-11-27 22:53:35 +04:00
warn ( "not using socket wrapper, but also not running as root. Will not be able to listen on proper ports" ) ;
2008-10-20 14:09:36 +04:00
}
2007-01-12 05:33:09 +03:00
}
2014-11-03 15:22:38 +03:00
if ( $ opt_use_dns_faking ) {
2015-01-30 04:22:46 +03:00
print "DNS: Faking nameserver\n" ;
2014-11-03 15:22:38 +03:00
$ ENV { SAMBA_DNS_FAKING } = 1 ;
}
2007-03-21 18:57:07 +03:00
my $ target ;
2007-09-30 13:07:07 +04:00
my $ testenv_default = "none" ;
2007-03-06 00:28:55 +03:00
2011-04-19 07:50:40 +04:00
# After this many seconds, the server will self-terminate. All tests
# must terminate in this time, and testenv will only stay alive this
# long
2016-01-22 18:57:15 +03:00
my $ server_maxtime ;
if ( $ opt_testenv ) {
# 1 year should be enough :-)
$ server_maxtime = 365 * 24 * 60 * 60 ;
} else {
2016-03-01 22:54:42 +03:00
# make test should run under 4 hours
$ server_maxtime = 4 * 60 * 60 ;
2016-01-22 18:57:15 +03:00
}
2011-04-19 07:50:40 +04:00
if ( defined ( $ ENV { SMBD_MAXTIME } ) and $ ENV { SMBD_MAXTIME } ne "" ) {
$ server_maxtime = $ ENV { SMBD_MAXTIME } ;
}
2011-11-30 23:42:14 +04:00
unless ( $ opt_list ) {
if ( $ opt_target eq "samba" ) {
2015-03-06 01:38:26 +03:00
$ testenv_default = "ad_dc_ntvfs" ;
2011-11-30 23:42:14 +04:00
require target::Samba ;
2015-06-05 03:22:45 +03:00
$ target = new Samba ( $ bindir , $ ldap , $ srcdir , $ server_maxtime ) ;
2011-11-30 23:42:14 +04:00
} elsif ( $ opt_target eq "samba3" ) {
2015-03-06 12:01:33 +03:00
$ testenv_default = "nt4_member" ;
2011-11-30 23:42:14 +04:00
require target::Samba3 ;
2015-06-05 03:22:45 +03:00
$ target = new Samba3 ( $ bindir , $ srcdir_abs , $ server_maxtime ) ;
2007-04-18 04:12:39 +04:00
}
2007-01-12 05:33:09 +03:00
}
2007-09-02 04:24:38 +04:00
sub read_test_regexes ($)
{
my ( $ name ) = @ _ ;
my @ ret = ( ) ;
open ( LF , "<$name" ) or die ( "unable to read $name: $!" ) ;
while ( <LF> ) {
2007-03-06 00:28:55 +03:00
chomp ;
2008-05-29 20:17:42 +04:00
next if ( /^#/ ) ;
2007-10-26 23:15:04 +04:00
if ( /^(.*?)([ \t]+)\#([\t ]*)(.*?)$/ ) {
push ( @ ret , [ $ 1 , $ 4 ] ) ;
2007-09-02 04:24:38 +04:00
} else {
2007-10-26 23:15:04 +04:00
s/^(.*?)([ \t]+)\#([\t ]*)(.*?)$// ;
2007-09-02 04:24:38 +04:00
push ( @ ret , [ $ _ , undef ] ) ;
}
}
close ( LF ) ;
return @ ret ;
}
2007-10-26 00:20:52 +04:00
foreach ( @ opt_exclude ) {
push ( @ excludes , read_test_regexes ( $ _ ) ) ;
}
foreach ( @ opt_include ) {
push ( @ includes , read_test_regexes ( $ _ ) ) ;
2007-03-06 01:24:21 +03:00
}
2010-06-16 13:02:48 +04:00
my $ interfaces = join ( ',' , ( "127.0.0.11/8" ,
"127.0.0.12/8" ,
"127.0.0.13/8" ,
"127.0.0.14/8" ,
"127.0.0.15/8" ,
"127.0.0.16/8" ) ) ;
2007-01-12 05:33:09 +03:00
2010-09-23 12:42:57 +04:00
my $ clientdir = "$prefix_abs/client" ;
my $ conffile = "$clientdir/client.conf" ;
2008-10-20 12:53:26 +04:00
$ ENV { SMB_CONF_PATH } = $ conffile ;
2007-04-11 00:19:31 +04:00
2010-09-23 12:42:57 +04:00
sub write_clientconf ($$$)
2007-04-11 00:19:31 +04:00
{
2010-09-23 12:42:57 +04:00
my ( $ conffile , $ clientdir , $ vars ) = @ _ ;
2007-04-11 00:19:31 +04:00
2010-09-23 12:42:57 +04:00
mkdir ( "$clientdir" , 0777 ) unless - d "$clientdir" ;
2010-09-04 20:24:02 +04:00
2010-09-23 12:42:57 +04:00
if ( - d "$clientdir/private" ) {
unlink <$clientdir/private/*> ;
2007-04-11 16:10:40 +04:00
} else {
2010-09-23 12:42:57 +04:00
mkdir ( "$clientdir/private" , 0777 ) ;
2007-04-11 16:10:40 +04:00
}
2010-09-23 12:42:57 +04:00
if ( - d "$clientdir/lockdir" ) {
unlink <$clientdir/lockdir/*> ;
2009-01-28 13:59:26 +03:00
} else {
2010-09-23 12:42:57 +04:00
mkdir ( "$clientdir/lockdir" , 0777 ) ;
2009-01-28 13:59:26 +03:00
}
2011-07-12 15:12:50 +04:00
if ( - d "$clientdir/statedir" ) {
unlink <$clientdir/statedir/*> ;
} else {
mkdir ( "$clientdir/statedir" , 0777 ) ;
}
if ( - d "$clientdir/cachedir" ) {
unlink <$clientdir/cachedir/*> ;
} else {
mkdir ( "$clientdir/cachedir" , 0777 ) ;
}
2011-05-22 21:40:19 +04:00
# this is ugly, but the ncalrpcdir needs exactly 0755
# otherwise tests fail.
my $ mask = umask ;
umask 0022 ;
if ( - d "$clientdir/ncalrpcdir/np" ) {
unlink <$clientdir/ncalrpcdir/np/*> ;
2011-07-04 19:01:29 +04:00
rmdir "$clientdir/ncalrpcdir/np" ;
2011-05-22 21:40:19 +04:00
}
2010-09-23 12:42:57 +04:00
if ( - d "$clientdir/ncalrpcdir" ) {
unlink <$clientdir/ncalrpcdir/*> ;
2011-07-04 19:01:29 +04:00
rmdir "$clientdir/ncalrpcdir" ;
2009-05-01 20:18:31 +04:00
}
2011-05-22 21:40:19 +04:00
mkdir ( "$clientdir/ncalrpcdir" , 0755 ) ;
umask $ mask ;
2009-05-01 20:18:31 +04:00
2016-01-09 23:21:25 +03:00
my $ cadir = "$ENV{SRCDIR_ABS}/selftest/manage-ca/CA-samba.example.com" ;
my $ cacert = "$cadir/Public/CA-samba.example.com-cert.pem" ;
my $ cacrl_pem = "$cadir/Public/CA-samba.example.com-crl.pem" ;
my $ ca_users_dir = "$cadir/Users" ;
if ( - d "$clientdir/pkinit" ) {
unlink <$clientdir/pkinit/*> ;
} else {
mkdir ( "$clientdir/pkinit" , 0700 ) ;
}
# each user has a USER-${USER_PRINCIPAL_NAME}-cert.pem and
# USER-${USER_PRINCIPAL_NAME}-private-key.pem symlink
# We make a copy here and make the certificated easily
# accessable in the client environment.
my $ mask = umask ;
umask 0077 ;
opendir USERS , "${ca_users_dir}" or die "Could not open dir '${ca_users_dir}': $!" ;
for my $ d ( readdir USERS ) {
my $ user_dir = "${ca_users_dir}/${d}" ;
next if $ { d } =~ /^\./ ;
next if ( ! - d "${user_dir}" ) ;
opendir USER , "${user_dir}" or die "Could not open dir '${user_dir}': $!" ;
for my $ l ( readdir USER ) {
my $ user_link = "${user_dir}/${l}" ;
next if $ { l } =~ /^\./ ;
next if ( ! - l "${user_link}" ) ;
my $ dest = "${clientdir}/pkinit/${l}" ;
Samba:: copy_file_content ( $ { user_link } , $ { dest } ) ;
}
closedir USER ;
}
closedir USERS ;
umask $ mask ;
2007-04-11 00:19:31 +04:00
open ( CF , ">$conffile" ) ;
print CF "[global]\n" ;
2007-04-12 16:45:41 +04:00
print CF "\tnetbios name = client\n" ;
2007-04-11 00:19:31 +04:00
if ( defined ( $ vars - > { DOMAIN } ) ) {
print CF "\tworkgroup = $vars->{DOMAIN}\n" ;
}
if ( defined ( $ vars - > { REALM } ) ) {
print CF "\trealm = $vars->{REALM}\n" ;
}
2008-02-19 20:03:02 +03:00
if ( $ opt_socket_wrapper ) {
print CF "\tinterfaces = $interfaces\n" ;
}
2007-04-11 00:19:31 +04:00
print CF "
2010-09-23 12:42:57 +04:00
private dir = $ clientdir / private
lock dir = $ clientdir / lockdir
2011-07-20 15:02:22 +04:00
state directory = $ clientdir / statedir
cache directory = $ clientdir / cachedir
2010-09-23 12:42:57 +04:00
ncalrpc dir = $ clientdir / ncalrpcdir
2011-07-13 11:26:31 +04:00
panic action = $ RealBin / gdb_backtrace \ % d
2007-04-09 04:53:05 +04:00
max xmit = 32 K
notify:inotify = false
ldb:nosync = true
system : anonymous = true
2008-10-31 17:07:34 +03:00
client lanman auth = Yes
2010-09-02 10:46:20 +04:00
log level = 1
2010-09-23 12:42:57 +04:00
torture:basedir = $ clientdir
2007-04-11 16:10:40 +04:00
#We don't want to pass our self-tests if the PAC code is wrong
2007-04-09 04:53:05 +04:00
gensec:require_pac = true
2010-09-23 11:32:46 +04:00
#We don't want to run 'speed' tests for very long
torture:timelimit = 1
2014-03-31 11:47:18 +04:00
winbind separator = /
2016-01-09 23:21:25 +03:00
tls cafile = $ { cacert }
tls crlfile = $ { cacrl_pem }
2016-03-26 10:38:46 +03:00
tls verify peer = no_check
2007-04-09 04:53:05 +04:00
" ;
2007-04-11 00:19:31 +04:00
close ( CF ) ;
}
2007-01-14 07:32:11 +03:00
my @ todo = ( ) ;
2007-01-12 05:33:09 +03:00
2009-08-14 07:04:21 +04:00
sub should_run_test ($)
{
my $ name = shift ;
if ( $# tests == - 1 ) {
return 1 ;
}
for ( my $ i = 0 ; $ i <= $# tests ; $ i + + ) {
if ( $ name =~ /$tests[$i]/i ) {
return 1 ;
}
}
return 0 ;
}
2007-09-02 15:16:16 +04:00
sub read_testlist ($)
{
my ( $ filename ) = @ _ ;
my @ ret = ( ) ;
open ( IN , $ filename ) or die ( "Unable to open $filename: $!" ) ;
while ( <IN> ) {
2014-10-27 06:17:20 +03:00
if ( /-- TEST(-LOADLIST|) --\n/ ) {
2010-04-12 18:11:31 +04:00
my $ supports_loadlist = ( defined ( $ 1 ) and $ 1 eq "-LOADLIST" ) ;
2007-09-02 15:16:16 +04:00
my $ name = <IN> ;
$ name =~ s/\n//g ;
my $ env = <IN> ;
$ env =~ s/\n//g ;
2014-11-02 01:13:18 +03:00
my $ loadlist ;
if ( $ supports_loadlist ) {
$ loadlist = <IN> ;
$ loadlist =~ s/\n//g ;
}
2007-09-02 15:16:16 +04:00
my $ cmdline = <IN> ;
$ cmdline =~ s/\n//g ;
2009-08-14 07:04:21 +04:00
if ( should_run_test ( $ name ) == 1 ) {
2014-11-02 01:13:18 +03:00
push ( @ ret , [ $ name , $ env , $ cmdline , $ loadlist ] ) ;
2007-09-02 15:16:16 +04:00
}
} else {
print ;
}
}
2014-09-01 09:13:39 +04:00
close ( IN ) or die ( "Error creating recipe from $filename" ) ;
2007-09-02 15:16:16 +04:00
return @ ret ;
}
2007-10-26 00:20:52 +04:00
if ( $# testlists == - 1 ) {
die ( "No testlists specified" ) ;
2007-03-21 18:57:07 +03:00
}
2007-09-02 15:16:16 +04:00
2008-10-19 18:07:00 +04:00
$ ENV { SELFTEST_PREFIX } = "$prefix_abs" ;
2010-10-01 05:31:06 +04:00
$ ENV { SELFTEST_TMPDIR } = "$tmpdir_abs" ;
2010-12-27 14:57:18 +03:00
$ ENV { TEST_DATA_PREFIX } = "$tmpdir_abs" ;
2008-10-19 18:07:00 +04:00
if ( $ opt_socket_wrapper ) {
$ ENV { SELFTEST_INTERFACES } = $ interfaces ;
} else {
$ ENV { SELFTEST_INTERFACES } = "" ;
}
if ( $ opt_quick ) {
$ ENV { SELFTEST_QUICK } = "1" ;
} else {
$ ENV { SELFTEST_QUICK } = "" ;
}
$ ENV { SELFTEST_MAXTIME } = $ torture_maxtime ;
2007-12-20 17:54:05 +03:00
my @ available = ( ) ;
foreach my $ fn ( @ testlists ) {
foreach ( read_testlist ( $ fn ) ) {
my $ name = $$ _ [ 0 ] ;
2009-06-05 18:10:12 +04:00
next if ( @ includes and not defined ( find_in_list ( \ @ includes , $ name ) ) ) ;
2007-12-20 17:54:05 +03:00
push ( @ available , $ _ ) ;
}
}
2010-04-08 18:16:15 +04:00
my $ restricted = undef ;
2010-09-05 05:16:48 +04:00
my $ restricted_used = { } ;
2010-04-08 18:16:15 +04:00
if ( $ opt_load_list ) {
$ restricted = [] ;
open ( LOAD_LIST , "<$opt_load_list" ) or die ( "Unable to open $opt_load_list" ) ;
2010-09-05 04:20:56 +04:00
while ( <LOAD_LIST> ) {
chomp ;
2010-04-08 18:16:15 +04:00
push ( @$ restricted , $ _ ) ;
}
close ( LOAD_LIST ) ;
}
my $ individual_tests = undef ;
$ individual_tests = { } ;
foreach my $ testsuite ( @ available ) {
my $ name = $$ testsuite [ 0 ] ;
2007-12-20 17:54:05 +03:00
my $ skipreason = skip ( $ name ) ;
2010-09-23 06:28:02 +04:00
if ( defined ( $ restricted ) ) {
2010-04-08 18:16:15 +04:00
# Find the testsuite for this test
2010-09-05 05:16:48 +04:00
my $ match = undef ;
2010-04-08 18:16:15 +04:00
foreach my $ r ( @$ restricted ) {
if ( $ r eq $ name ) {
$ individual_tests - > { $ name } = [] ;
2010-09-05 05:16:48 +04:00
$ match = $ r ;
$ restricted_used - > { $ r } = 1 ;
2010-09-22 04:35:53 +04:00
} elsif ( substr ( $ r , 0 , length ( $ name ) + 1 ) eq "$name." ) {
2010-09-23 06:21:58 +04:00
push ( @ { $ individual_tests - > { $ name } } , $ r ) ;
2010-09-05 05:16:48 +04:00
$ match = $ r ;
$ restricted_used - > { $ r } = 1 ;
2010-04-08 18:16:15 +04:00
}
}
2010-09-23 06:28:02 +04:00
if ( $ match ) {
if ( defined ( $ skipreason ) ) {
2011-11-27 22:53:35 +04:00
if ( not $ opt_list ) {
2010-09-23 06:28:02 +04:00
Subunit:: skip_testsuite ( $ name , $ skipreason ) ;
2011-11-27 22:53:35 +04:00
}
2010-09-23 06:28:02 +04:00
} else {
push ( @ todo , $ testsuite ) ;
}
}
} elsif ( defined ( $ skipreason ) ) {
2011-11-27 22:53:35 +04:00
if ( not $ opt_list ) {
Subunit:: skip_testsuite ( $ name , $ skipreason ) ;
}
2007-12-20 17:54:05 +03:00
} else {
2010-09-23 06:28:02 +04:00
push ( @ todo , $ testsuite ) ;
2007-10-31 16:48:48 +03:00
}
2007-01-14 07:32:11 +03:00
}
2010-09-05 04:20:56 +04:00
if ( defined ( $ restricted ) ) {
foreach ( @$ restricted ) {
2010-09-05 05:16:48 +04:00
unless ( defined ( $ restricted_used - > { $ _ } ) ) {
2010-09-05 04:20:56 +04:00
print "No test or testsuite found matching $_\n" ;
}
}
} elsif ( $# todo == - 1 ) {
2007-10-08 18:57:11 +04:00
print STDERR "No tests to run\n" ;
exit ( 1 ) ;
2010-09-05 04:20:56 +04:00
}
2007-10-08 18:57:11 +04:00
2007-03-06 00:28:55 +03:00
my $ suitestotal = $# todo + 1 ;
2010-09-23 06:28:02 +04:00
2011-11-27 22:53:35 +04:00
unless ( $ opt_list ) {
Subunit:: progress ( $ suitestotal ) ;
Subunit:: report_time ( time ( ) ) ;
}
2010-09-23 06:28:02 +04:00
2007-01-14 07:32:11 +03:00
my $ i = 0 ;
$| = 1 ;
2007-04-11 00:19:31 +04:00
my % running_envs = ( ) ;
2007-03-06 00:28:55 +03:00
2009-01-30 10:25:27 +03:00
sub get_running_env ($)
{
my ( $ name ) = @ _ ;
my $ envname = $ name ;
$ envname =~ s/:.*// ;
return $ running_envs { $ envname } ;
}
2007-04-28 12:48:11 +04:00
my @ exported_envvars = (
# domain stuff
"DOMAIN" ,
"REALM" ,
2015-02-11 11:58:07 +03:00
# stuff related to a trusted domain
"TRUST_SERVER" ,
"TRUST_SERVER_IP" ,
"TRUST_SERVER_IPV6" ,
"TRUST_NETBIOSNAME" ,
"TRUST_USERNAME" ,
"TRUST_PASSWORD" ,
"TRUST_DOMAIN" ,
"TRUST_REALM" ,
2007-04-28 12:57:06 +04:00
# domain controller stuff
"DC_SERVER" ,
"DC_SERVER_IP" ,
2014-06-19 19:21:16 +04:00
"DC_SERVER_IPV6" ,
2007-04-28 12:57:06 +04:00
"DC_NETBIOSNAME" ,
"DC_NETBIOSALIAS" ,
2010-03-12 02:36:12 +03:00
# domain member
2010-02-19 07:56:30 +03:00
"MEMBER_SERVER" ,
"MEMBER_SERVER_IP" ,
2014-06-19 19:21:16 +04:00
"MEMBER_SERVER_IPV6" ,
2010-02-19 07:56:30 +03:00
"MEMBER_NETBIOSNAME" ,
"MEMBER_NETBIOSALIAS" ,
2010-03-12 02:36:12 +03:00
# rpc proxy controller stuff
2010-02-19 07:56:30 +03:00
"RPC_PROXY_SERVER" ,
"RPC_PROXY_SERVER_IP" ,
2014-06-19 19:21:16 +04:00
"RPC_PROXY_SERVER_IPV6" ,
2010-02-19 07:56:30 +03:00
"RPC_PROXY_NETBIOSNAME" ,
"RPC_PROXY_NETBIOSALIAS" ,
2010-03-12 02:36:12 +03:00
# domain controller stuff for Vampired DC
"VAMPIRE_DC_SERVER" ,
"VAMPIRE_DC_SERVER_IP" ,
2014-06-19 19:21:16 +04:00
"VAMPIRE_DC_SERVER_IPV6" ,
2010-03-12 02:36:12 +03:00
"VAMPIRE_DC_NETBIOSNAME" ,
"VAMPIRE_DC_NETBIOSALIAS" ,
2013-05-13 20:16:24 +04:00
"PROMOTED_DC_SERVER" ,
"PROMOTED_DC_SERVER_IP" ,
2014-06-19 19:21:16 +04:00
"PROMOTED_DC_SERVER_IPV6" ,
2013-05-13 20:16:24 +04:00
"PROMOTED_DC_NETBIOSNAME" ,
"PROMOTED_DC_NETBIOSALIAS" ,
2007-04-28 12:48:11 +04:00
# server stuff
"SERVER" ,
2007-04-28 12:57:06 +04:00
"SERVER_IP" ,
2014-06-19 19:21:16 +04:00
"SERVER_IPV6" ,
2007-04-28 12:48:11 +04:00
"NETBIOSNAME" ,
2007-04-28 12:57:06 +04:00
"NETBIOSALIAS" ,
2007-04-28 12:48:11 +04:00
# user stuff
"USERNAME" ,
2010-06-02 17:35:33 +04:00
"USERID" ,
2007-04-28 12:48:11 +04:00
"PASSWORD" ,
2007-04-28 12:57:06 +04:00
"DC_USERNAME" ,
"DC_PASSWORD" ,
2007-04-28 12:48:11 +04:00
2014-09-10 13:00:28 +04:00
# UID/GID for rfc2307 mapping tests
"UID_RFC2307TEST" ,
"GID_RFC2307TEST" ,
2007-04-28 12:48:11 +04:00
# misc stuff
2007-07-13 12:38:51 +04:00
"KRB5_CONFIG" ,
2016-09-22 19:46:28 +03:00
"KRB5CCNAME" ,
2014-02-20 13:34:49 +04:00
"SELFTEST_WINBINDD_SOCKET_DIR" ,
2010-06-02 17:35:33 +04:00
"WINBINDD_PRIV_PIPE_DIR" ,
2011-01-08 08:28:45 +03:00
"NMBD_SOCKET_DIR" ,
2012-06-27 06:40:59 +04:00
"LOCAL_PATH" ,
2016-03-17 07:13:28 +03:00
"DNS_FORWARDER1" ,
"DNS_FORWARDER2" ,
2016-06-10 06:43:37 +03:00
"RESOLV_CONF" ,
2016-06-13 06:42:46 +03:00
"UNACCEPTABLE_PASSWORD" ,
2012-06-27 06:40:59 +04:00
2014-09-10 13:00:28 +04:00
# nss_wrapper
"NSS_WRAPPER_PASSWD" ,
"NSS_WRAPPER_GROUP" ,
"NSS_WRAPPER_HOSTS" ,
2015-02-02 16:54:01 +03:00
"NSS_WRAPPER_MODULE_SO_PATH" ,
"NSS_WRAPPER_MODULE_FN_PREFIX" ,
2012-06-27 06:40:59 +04:00
2014-09-10 13:00:28 +04:00
# resolv_wrapper
"RESOLV_WRAPPER_CONF" ,
2015-03-16 19:43:59 +03:00
"RESOLV_WRAPPER_HOSTS" ,
2007-04-28 12:48:11 +04:00
) ;
2014-07-10 16:28:56 +04:00
sub sighandler ($)
{
2007-09-02 21:13:56 +04:00
my $ signame = shift ;
2014-07-10 16:28:56 +04:00
$ SIG { INT } = $ SIG { QUIT } = $ SIG { TERM } = 'DEFAULT' ;
$ SIG { PIPE } = 'IGNORE' ;
open ( STDOUT , ">&STDERR" ) or die "can't dup STDOUT to STDERR: $!" ;
print "$0: PID[$$]: Got SIG${signame} teardown environments.\n" ;
2007-09-02 21:13:56 +04:00
teardown_env ( $ _ ) foreach ( keys % running_envs ) ;
2014-07-10 16:28:56 +04:00
system ( "pstree -p $$" ) ;
print "$0: PID[$$]: Exiting...\n" ;
exit ( 1 ) ;
2007-09-02 21:13:56 +04:00
} ;
2014-07-10 16:28:56 +04:00
$ SIG { INT } = $ SIG { QUIT } = $ SIG { TERM } = $ SIG { PIPE } = \ & sighandler ;
2010-09-23 21:28:22 +04:00
sub setup_env ($$)
2007-04-11 00:19:31 +04:00
{
2010-09-23 21:28:22 +04:00
my ( $ name , $ prefix ) = @ _ ;
2009-01-30 10:25:27 +03:00
my $ testenv_vars = undef ;
my $ envname = $ name ;
my $ option = $ name ;
$ envname =~ s/:.*// ;
2009-01-30 12:01:48 +03:00
$ option =~ s/^[^:]*// ;
$ option =~ s/^:// ;
2009-01-30 10:25:27 +03:00
$ option = "client" if $ option eq "" ;
2007-04-09 03:55:01 +04:00
2015-10-26 08:38:08 +03:00
if ( defined ( get_running_env ( $ envname ) ) ) {
2009-01-30 10:25:27 +03:00
$ testenv_vars = get_running_env ( $ envname ) ;
2011-04-18 07:44:36 +04:00
if ( not $ testenv_vars - > { target } - > check_env ( $ testenv_vars ) ) {
print $ testenv_vars - > { target } - > getlog_env ( $ testenv_vars ) ;
2007-04-19 18:54:09 +04:00
$ testenv_vars = undef ;
}
2007-04-11 00:19:31 +04:00
} else {
2007-04-11 07:45:39 +04:00
$ testenv_vars = $ target - > setup_env ( $ envname , $ prefix ) ;
2012-02-13 05:14:57 +04:00
if ( defined ( $ testenv_vars ) and $ testenv_vars eq "UNKNOWN" ) {
return $ testenv_vars ;
} elsif ( defined ( $ testenv_vars ) && not defined ( $ testenv_vars - > { target } ) ) {
2011-04-19 06:43:54 +04:00
$ testenv_vars - > { target } = $ target ;
}
if ( not defined ( $ testenv_vars ) ) {
2012-02-23 09:34:47 +04:00
warn ( "$opt_target can't start up known environment '$envname'" ) ;
2011-04-18 07:44:36 +04:00
}
2007-04-11 00:19:31 +04:00
}
2007-04-19 18:54:09 +04:00
return undef unless defined ( $ testenv_vars ) ;
2007-09-02 21:13:56 +04:00
$ running_envs { $ envname } = $ testenv_vars ;
2009-01-30 10:25:27 +03:00
if ( $ option eq "local" ) {
SocketWrapper:: set_default_iface ( $ testenv_vars - > { SOCKET_WRAPPER_DEFAULT_IFACE } ) ;
$ ENV { SMB_CONF_PATH } = $ testenv_vars - > { SERVERCONFFILE } ;
} elsif ( $ option eq "client" ) {
2010-06-16 13:02:48 +04:00
SocketWrapper:: set_default_iface ( 11 ) ;
2010-09-23 12:42:57 +04:00
write_clientconf ( $ conffile , $ clientdir , $ testenv_vars ) ;
2009-01-30 10:25:27 +03:00
$ ENV { SMB_CONF_PATH } = $ conffile ;
} else {
die ( "Unknown option[$option] for envname[$envname]" ) ;
}
2007-04-28 12:48:11 +04:00
foreach ( @ exported_envvars ) {
2007-04-11 00:19:31 +04:00
if ( defined ( $ testenv_vars - > { $ _ } ) ) {
$ ENV { $ _ } = $ testenv_vars - > { $ _ } ;
} else {
delete $ ENV { $ _ } ;
}
}
return $ testenv_vars ;
}
2007-04-28 12:48:11 +04:00
sub exported_envvars_str ($)
{
my ( $ testenv_vars ) = @ _ ;
my $ out = "" ;
foreach ( @ exported_envvars ) {
next unless defined ( $ testenv_vars - > { $ _ } ) ;
$ out . = $ _ . "=" . $ testenv_vars - > { $ _ } . "\n" ;
}
return $ out ;
}
2007-04-18 18:02:26 +04:00
sub getlog_env ($)
{
my ( $ envname ) = @ _ ;
return "" if ( $ envname eq "none" ) ;
2011-04-18 07:44:36 +04:00
my $ env = get_running_env ( $ envname ) ;
return $ env - > { target } - > getlog_env ( $ env ) ;
2007-04-18 18:02:26 +04:00
}
2007-04-19 18:54:09 +04:00
sub check_env ($)
{
my ( $ envname ) = @ _ ;
2011-04-18 07:44:36 +04:00
my $ env = get_running_env ( $ envname ) ;
return $ env - > { target } - > check_env ( $ env ) ;
2007-04-19 18:54:09 +04:00
}
2007-04-11 00:19:31 +04:00
sub teardown_env ($)
{
my ( $ envname ) = @ _ ;
2007-04-17 04:30:01 +04:00
return if ( $ envname eq "none" ) ;
2014-07-10 16:28:56 +04:00
print STDERR "teardown_env($envname)\n" ;
2011-04-18 07:44:36 +04:00
my $ env = get_running_env ( $ envname ) ;
$ env - > { target } - > teardown_env ( $ env ) ;
2007-04-11 00:19:31 +04:00
delete $ running_envs { $ envname } ;
}
2007-04-16 07:16:23 +04:00
2010-03-12 02:45:16 +03:00
# This 'global' file needs to be empty when we start
unlink ( "$prefix_abs/dns_host_file" ) ;
2013-06-27 18:12:47 +04:00
unlink ( "$prefix_abs/hosts" ) ;
2010-03-12 02:45:16 +03:00
2012-10-27 03:53:57 +04:00
if ( $ opt_random_order ) {
require List::Util ;
my @ newtodo = List::Util:: shuffle ( @ todo ) ;
@ todo = @ newtodo ;
}
2007-03-07 05:11:40 +03:00
if ( $ opt_testenv ) {
2007-04-28 12:48:11 +04:00
my $ testenv_name = $ ENV { SELFTEST_TESTENV } ;
2007-09-30 13:07:07 +04:00
$ testenv_name = $ testenv_default unless defined ( $ testenv_name ) ;
2007-04-28 12:48:11 +04:00
2010-09-23 21:28:22 +04:00
my $ testenv_vars = setup_env ( $ testenv_name , $ prefix ) ;
2007-04-28 12:48:11 +04:00
2013-07-03 23:49:43 +04:00
if ( not $ testenv_vars or $ testenv_vars eq "UNKNOWN" ) {
die ( "Unable to setup environment $testenv_name" ) ;
}
2010-09-14 16:36:56 +04:00
2007-04-09 03:55:01 +04:00
$ ENV { PIDDIR } = $ testenv_vars - > { PIDDIR } ;
2010-10-03 01:23:43 +04:00
$ ENV { ENVNAME } = $ testenv_name ;
2007-04-28 12:48:11 +04:00
my $ envvarstr = exported_envvars_str ( $ testenv_vars ) ;
2013-01-04 02:33:45 +04:00
my @ term_args = ( " echo - e \ "
2007-04-28 12:48:11 +04:00
Welcome to the Samba4 Test environment '$testenv_name'
2007-03-07 05:11:40 +03:00
This matches the client environment used in make test
2008-09-24 05:16:15 +04:00
server is pid `cat \$PIDDIR/samba.pid`
2007-03-07 05:11:40 +03:00
Some useful environment variables:
TORTURE_OPTIONS = \ $ TORTURE_OPTIONS
2009-01-30 13:03:45 +03:00
SMB_CONF_PATH = \ $ SMB_CONF_PATH
2007-04-28 12:48:11 +04:00
$ envvarstr
2012-09-29 14:40:13 +04:00
\ " && LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH} bash" ) ;
2013-01-04 02:33:45 +04:00
my @ term = ( ) ;
if ( $ ENV { TERMINAL } ) {
@ term = ( $ ENV { TERMINAL } ) ;
} else {
@ term = ( "xterm" , "-e" ) ;
unshift ( @ term_args , ( "bash" , "-c" ) ) ;
}
2012-09-29 14:40:13 +04:00
system ( @ term , @ term_args ) ;
2007-04-28 12:48:11 +04:00
teardown_env ( $ testenv_name ) ;
2010-12-09 16:46:09 +03:00
} elsif ( $ opt_list ) {
foreach ( @ todo ) {
my $ name = $$ _ [ 0 ] ;
my $ envname = $$ _ [ 1 ] ;
2014-11-02 01:13:18 +03:00
my $ cmd = $$ _ [ 2 ] ;
my $ listcmd = $$ _ [ 3 ] ;
2010-12-09 16:46:09 +03:00
2014-11-02 01:13:18 +03:00
unless ( defined ( $ listcmd ) ) {
2010-12-09 16:46:09 +03:00
warn ( "Unable to list tests in $name" ) ;
2014-10-13 04:49:39 +04:00
# Rather than ignoring this testsuite altogether, just pretend the entire testsuite is
# a single "test".
print "$name\n" ;
2010-12-09 16:46:09 +03:00
next ;
}
2014-11-02 01:13:18 +03:00
system ( $ listcmd ) ;
2010-12-09 18:48:24 +03:00
if ( $? == - 1 ) {
2014-11-02 01:13:18 +03:00
die ( "Unable to run $listcmd: $!" ) ;
2010-12-09 18:48:24 +03:00
} elsif ( $? & 127 ) {
2014-11-02 01:13:18 +03:00
die ( sprintf ( "%s died with signal %d, %s coredump\n" , $ listcmd , ( $? & 127 ) , ( $? & 128 ) ? 'with' : 'without' ) ) ;
2010-12-09 18:48:24 +03:00
}
my $ exitcode = $? >> 8 ;
if ( $ exitcode != 0 ) {
die ( "$cmd exited with exit code $exitcode" ) ;
}
2010-12-09 16:46:09 +03:00
}
2007-03-07 05:11:40 +03:00
} else {
foreach ( @ todo ) {
$ i + + ;
2007-03-21 18:57:07 +03:00
my $ cmd = $$ _ [ 2 ] ;
2007-03-07 05:11:40 +03:00
my $ name = $$ _ [ 0 ] ;
2007-03-21 18:57:07 +03:00
my $ envname = $$ _ [ 1 ] ;
2010-09-05 04:20:56 +04:00
2010-09-23 21:28:22 +04:00
my $ envvars = setup_env ( $ envname , $ prefix ) ;
2007-04-19 18:54:09 +04:00
if ( not defined ( $ envvars ) ) {
2010-09-14 16:36:56 +04:00
Subunit:: start_testsuite ( $ name ) ;
Subunit:: end_testsuite ( $ name , "error" ,
2010-10-19 07:49:17 +04:00
"unable to set up environment $envname - exiting" ) ;
2007-04-19 18:54:09 +04:00
next ;
2012-02-13 05:14:57 +04:00
} elsif ( $ envvars eq "UNKNOWN" ) {
Subunit:: start_testsuite ( $ name ) ;
Subunit:: end_testsuite ( $ name , "skip" ,
"environment $envname is unknown in this test backend - skipping" ) ;
next ;
2007-04-19 18:54:09 +04:00
}
2007-03-21 18:57:07 +03:00
2010-06-25 04:35:29 +04:00
# Generate a file with the individual tests to run, if the
# test runner for this test suite supports it.
2010-09-22 07:36:50 +04:00
if ( $ individual_tests and $ individual_tests - > { $ name } ) {
if ( $$ _ [ 3 ] ) {
my ( $ fh , $ listid_file ) = tempfile ( UNLINK = > 0 ) ;
foreach my $ test ( @ { $ individual_tests - > { $ name } } ) {
2010-09-23 06:21:58 +04:00
print $ fh substr ( $ test , length ( $ name ) + 1 ) . "\n" ;
2010-09-22 07:36:50 +04:00
}
2010-09-23 06:08:37 +04:00
$ cmd =~ s/\$LOADLIST/--load-list=$listid_file/g ;
2014-10-27 06:17:20 +03:00
} else {
warn ( "Unable to run individual tests in $name, it does not support --loadlist." ) ;
2010-04-11 00:20:12 +04:00
}
}
2010-09-14 16:36:56 +04:00
run_testsuite ( $ envname , $ name , $ cmd , $ i , $ suitestotal ) ;
2007-03-21 18:57:07 +03:00
2007-04-11 00:19:31 +04:00
teardown_env ( $ envname ) if ( $ opt_resetup_env ) ;
2007-01-14 07:32:11 +03:00
}
2007-01-13 23:02:10 +03:00
}
2007-01-12 05:33:09 +03:00
2007-01-14 07:32:11 +03:00
print "\n" ;
2007-04-11 00:19:31 +04:00
teardown_env ( $ _ ) foreach ( keys % running_envs ) ;
my $ failed = 0 ;
2007-01-12 05:33:09 +03:00
# if there were any valgrind failures, show them
foreach ( <$prefix/valgrind.log*> ) {
next unless ( - s $ _ ) ;
2009-10-19 15:58:23 +04:00
print "VALGRIND FAILURE\n" ;
$ failed + + ;
system ( "cat $_" ) ;
2007-01-12 05:33:09 +03:00
}
2009-06-04 15:49:11 +04:00
exit 0 ;