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 ;
2019-12-07 12:37:00 +03:00
use warnings ;
2007-01-12 05:33:09 +03:00
use FindBin qw( $RealBin $Script ) ;
use File::Spec ;
2010-04-11 00:20:12 +04:00
use File::Temp qw( tempfile ) ;
2020-09-16 14:00:33 +03:00
use File::Path qw( remove_tree ) ;
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 ;
2018-01-25 07:23:06 +03:00
use Time::HiRes qw( time ) ;
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 = ( ) ;
2017-02-28 00:45:24 +03:00
my @ opt_exclude_env = ( ) ;
my @ opt_include_env = ( ) ;
2007-03-07 05:11:40 +03:00
my $ opt_testenv = 0 ;
2010-12-09 16:46:09 +03:00
my $ opt_list = 0 ;
2014-05-05 15:27:58 +04:00
my $ opt_mitkrb5 = 0 ;
2022-11-22 12:31:19 +03:00
my $ opt_default_ldb_backend = "mdb" ;
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 = "" ;
2018-05-03 06:47:45 +03:00
my $ opt_libasan_so_path = "" ;
2022-09-06 09:59:56 +03:00
my $ opt_libcrypt_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
}
2018-02-08 06:51:23 +03:00
sub skip
2007-09-02 04:24:38 +04:00
{
2018-02-21 03:33:49 +03:00
my ( $ name , $ envname ) = @ _ ;
my ( $ env_basename , $ env_localpart ) = split ( /:/ , $ envname ) ;
if ( $ opt_target eq "samba3" && $ Samba:: ENV_NEEDS_AD_DC { $ env_basename } ) {
return "environment $envname is disabled as this build does not include an AD DC" ;
}
2007-10-26 00:20:52 +04:00
2018-02-01 07:46:37 +03:00
if ( @ opt_include_env && ! ( grep { $ _ eq $ env_basename } @ opt_include_env ) ) {
return "environment $envname is disabled (via --include-env command line option) in this test run - skipping" ;
} elsif ( @ opt_exclude_env && grep { $ _ eq $ env_basename } @ opt_exclude_env ) {
return "environment $envname is disabled (via --exclude-env command line option) in this test run - skipping" ;
}
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 ($) ;
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 ;
}
2020-02-04 19:03:17 +03:00
my $ target ;
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 ) = @ _ ;
2020-02-04 19:03:17 +03:00
my $ pcap_file = $ target - > 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 ( ) ;
2018-01-25 07:23:06 +03:00
Subunit:: report_time ( ) ;
2023-04-06 07:31:09 +03:00
# Enable pipefail so that we catch failing testsuites that are part of a
# pipeline (typically, piped through filter-subunit). This won't catch
# any testsuite failures that are turned into testsuite-xfails by
# filter-subunit.
system ( "bash" , "-o" , "pipefail" , "-c" , $ cmd ) ;
2018-01-25 07:23:06 +03:00
Subunit:: report_time ( ) ;
2010-09-22 22:30:34 +04:00
Subunit:: progress_pop ( ) ;
2007-08-12 05:49:38 +04:00
2010-09-22 22:30:34 +04:00
if ( $? == - 1 ) {
2016-12-29 14:35:48 +03:00
print "command: $cmd\n" ;
printf "expanded command: %s\n" , expand_environment_strings ( $ cmd ) ;
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 ) {
2016-12-29 14:35:48 +03:00
print "command: $cmd\n" ;
printf "expanded command: %s\n" , expand_environment_strings ( $ cmd ) ;
2010-09-22 22:30:34 +04:00
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
2020-02-04 19:03:17 +03:00
$ target - > 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
2017-01-27 05:10:29 +03:00
Usage: $ Script [ OPTIONS ] TESTNAME - REGEX [ 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
2017-02-28 00:45:24 +03:00
- - exclude - env = ENV Exclude tests for the specified environment
- - include - env = ENV Include tests for the specified environment
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
2018-05-03 06:47:45 +03:00
- - asan_so_path = FILE the asan library to preload
2013-07-03 14:55:29 +04:00
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
2022-09-06 09:48:49 +03:00
- - socket - wrapper - keep - pcap keep all pcap files , not just those for tests that
2007-04-18 04:12:39 +04:00
failed
2007-01-13 23:02:10 +03:00
- - socket - wrapper enable socket wrapper
2007-04-18 04:12:39 +04:00
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 ,
2017-02-28 00:45:24 +03:00
'exclude-env=s' = > \ @ opt_exclude_env ,
'include-env=s' = > \ @ opt_include_env ,
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 ,
2014-05-05 15:27:58 +04:00
'mitkrb5' = > \ $ opt_mitkrb5 ,
2022-11-22 12:31:19 +03:00
'default-ldb-backend=s' = > \ $ opt_default_ldb_backend ,
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 ,
2018-05-03 06:47:45 +03:00
'asan_so_path=s' = > \ $ opt_libasan_so_path ,
2022-09-06 09:59:56 +03:00
'crypt_so_path=s' = > \ $ opt_libcrypt_so_path ,
2014-11-03 15:22:38 +03:00
'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 ;
2021-07-09 15:12:39 +03:00
$ ENV { SAMBA_DEPRECATED_SUPPRESS } = 1 ;
2019-02-27 10:22:09 +03:00
# do not depend on the users setup
2019-11-19 00:02:13 +03:00
# see also bootstrap/config.py
2019-02-27 10:22:09 +03:00
$ ENV { TZ } = "UTC" ;
2019-11-19 00:02:13 +03:00
$ ENV { LC_ALL } = $ ENV { LANG } = "en_US.utf8" ;
2023-06-09 14:51:56 +03:00
$ ENV { LANGUAGE } = "en_US" ;
2019-02-27 10:22:09 +03:00
2009-02-02 14:43:20 +03:00
my $ bindir_abs = abs_path ( $ bindir ) ;
2007-04-17 04:30:01 +04:00
2007-03-21 18:57:07 +03:00
my $ torture_maxtime = ( $ ENV { TORTURE_MAXTIME } or 1200 ) ;
2007-01-12 05:33:09 +03:00
$ prefix =~ s + // + / + ;
2020-11-19 19:19:53 +03:00
$ prefix =~ s + /\./ + / + ;
2007-04-17 17:06:00 +04:00
$ 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.
2017-04-07 11:39:31 +03:00
umask 0077 ;
2011-04-29 09:54:20 +04:00
mkdir ( $ prefix , 0700 ) unless - d $ prefix ;
chmod 0700 , $ prefix ;
2017-04-07 11:39:31 +03:00
# We need to have no umask limitations for the tests.
umask 0000 ;
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 "/" ;
2016-09-12 22:52:23 +03:00
$ ENV { SAMBA_SELFTEST } = "1" ;
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 ;
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 } ;
2018-05-03 06:47:45 +03:00
if ( $ opt_libasan_so_path ) {
if ( $ ld_preload ) {
2022-09-06 09:59:56 +03:00
if ( $ opt_libcrypt_so_path ) {
$ ld_preload = "$opt_libasan_so_path:$opt_libcrypt_so_path:$ld_preload" ;
} else {
$ ld_preload = "$opt_libasan_so_path:$ld_preload" ;
}
2018-05-03 06:47:45 +03:00
} else {
2022-09-06 09:59:56 +03:00
if ( $ opt_libcrypt_so_path ) {
$ ld_preload = "$opt_libasan_so_path:$opt_libcrypt_so_path" ;
} else {
$ ld_preload = "$opt_libasan_so_path" ;
}
2018-05-03 06:47:45 +03:00
}
}
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" ;
}
}
2019-05-23 08:44:37 +03:00
if ( defined ( $ ENV { USE_NAMESPACES } ) ) {
print "Using linux containerization for selftest testenv(s)...\n" ;
# Create a common bridge to connect up the testenv namespaces. We give
# it the client's IP address, as this is where the tests will run from
my $ ipv4_addr = Samba:: get_ipv4_addr ( "client" ) ;
my $ ipv6_addr = Samba:: get_ipv6_addr ( "client" ) ;
system "$ENV{SRCDIR_ABS}/selftest/ns/create_bridge.sh selftest0 $ipv4_addr $ipv6_addr" ;
}
2013-07-03 14:55:29 +04:00
$ 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 ;
2019-03-21 14:06:58 +03:00
# We are already hitting the limit, so double it.
$ ENV { NSS_WRAPPER_MAX_HOSTENTS } = 200 ;
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-09-30 13:07:07 +04:00
my $ testenv_default = "none" ;
2007-03-06 00:28:55 +03:00
2014-05-05 15:27:58 +04:00
if ( $ opt_mitkrb5 == 1 ) {
$ ENV { MITKRB5 } = $ opt_mitkrb5 ;
2020-03-06 19:15:45 +03:00
$ ENV { KRB5RCACHETYPE } = "none" ;
2014-05-05 15:27:58 +04: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 {
2017-12-28 01:45:49 +03:00
# make test should run under 5 hours
$ server_maxtime = 5 * 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 } ;
}
2020-02-04 19:03:17 +03:00
$ target = new Samba ( $ bindir , $ srcdir , $ server_maxtime ,
$ opt_socket_wrapper_pcap ,
2022-11-22 12:31:19 +03:00
$ opt_socket_wrapper_keep_pcap ,
$ opt_default_ldb_backend ) ;
2011-11-30 23:42:14 +04:00
unless ( $ opt_list ) {
if ( $ opt_target eq "samba" ) {
2017-06-19 15:34:02 +03:00
$ testenv_default = "ad_dc" ;
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" ;
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: $!" ) ;
2022-09-06 09:48:49 +03:00
while ( <LF> ) {
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 ]*)(.*?)$// ;
2022-09-06 09:48:49 +03:00
push ( @ ret , [ $ _ , undef ] ) ;
2007-09-02 04:24:38 +04:00
}
}
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
}
2019-03-18 07:55:39 +03:00
# We give the selftest client 6 different IPv4 addresses to use. Most tests
# only use the first (.11) IP. Note that winsreplication.c is one test that
# uses the other IPs (search for iface_list_count()).
2019-01-24 00:29:19 +03:00
$ ENV { SOCKET_WRAPPER_IPV4_NETWORK } = "10.53.57.0" ;
2019-03-18 07:55:39 +03:00
my $ interfaces = Samba:: get_interfaces_config ( "client" , 6 ) ;
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
2020-09-16 14:00:33 +03:00
my @ subdirs = (
{ name = > "private" , mask = > 0777 } ,
{ name = > "bind-dns" , mask = > 0777 } ,
{ name = > "lockdir" , mask = > 0777 } ,
{ name = > "statedir" , mask = > 0777 } ,
{ name = > "cachedir" , mask = > 0777 } ,
{ name = > "pkinit" , mask = > 0700 } ,
2020-09-15 14:32:00 +03:00
{ name = > "pid" , mask = > 0777 } ,
2020-09-16 14:00:33 +03:00
# the ncalrpcdir needs exactly 0755 otherwise tests fail.
{ name = > "ncalrpcdir" , mask = > 0755 , umask = > 0022 } ,
) ;
foreach my $ sub ( @ subdirs ) {
my $ dir = "$clientdir/$sub->{name}" ;
remove_tree ( $ dir ) ;
my $ mask = umask ;
if ( defined ( $ sub - > { umask } ) ) {
umask $ sub - > { umask } ;
}
mkdir ( $ dir , $ sub - > { mask } ) ;
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" ;
2021-03-31 16:24:20 +03:00
my $ client_loglevel = $ ENV { CLIENT_LOG_LEVEL } || 1 ;
2016-01-09 23:21:25 +03:00
# 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
2023-06-30 13:04:33 +03:00
# accessible in the client environment.
2020-09-16 14:00:33 +03:00
my $ mask = umask ;
2016-01-09 23:21:25 +03:00
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
2017-08-22 18:10:01 +03:00
binddns dir = $ clientdir / bind - dns
2010-09-23 12:42:57 +04:00
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
2020-09-15 14:32:00 +03:00
pid directory = $ clientdir / pid
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
2019-07-08 12:31:27 +03:00
client min protocol = CORE
2021-03-31 16:24:20 +03:00
log level = $ client_loglevel
2010-09-23 12:42:57 +04:00
torture:basedir = $ clientdir
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
2016-12-01 10:18:58 +03:00
include system krb5 conf = no
2019-07-30 13:47:03 +03:00
elasticsearch:mappings = $ srcdir_abs /source3/ rpc_server /mdssvc/ elasticsearch_mappings . json
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" ;
2016-12-15 12:31:50 +03:00
$ ENV { 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_quick ) {
$ ENV { SELFTEST_QUICK } = "1" ;
} else {
$ ENV { SELFTEST_QUICK } = "" ;
}
$ ENV { SELFTEST_MAXTIME } = $ torture_maxtime ;
2019-10-30 20:17:36 +03:00
my $ selftest_resolv_conf_path = "$tmpdir_abs/selftest.resolv.conf" ;
$ ENV { RESOLV_CONF } = "${selftest_resolv_conf_path}.global" ;
2016-12-16 13:09:16 +03:00
my $ selftest_krbt_ccache_path = "$tmpdir_abs/selftest.krb5_ccache" ;
$ ENV { KRB5CCNAME } = "FILE:${selftest_krbt_ccache_path}.global" ;
2020-11-23 01:28:31 +03:00
my $ selftest_gnupghome_path = "$tmpdir_abs/selftest.no.gnupg" ;
$ ENV { GNUPGHOME } = "${selftest_gnupghome_path}.global" ;
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 ] ;
2018-02-21 03:33:49 +03:00
my $ skipreason = skip ( @$ testsuite ) ;
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 ) ;
2018-01-25 07:23:06 +03:00
Subunit:: report_time ( ) ;
2011-11-27 22:53:35 +04:00
}
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 } ;
}
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
selftest: Clear environment before provision
Currently, if an environment is being provisioned after a test which used
ad_member_rfc2307, the provisioning process has all of the following in its
environment:
{
'DC_NETBIOSNAME' => 'LOCALDC',
'DC_PASSWORD' => 'locDCpass1',
'DC_SERVER_IP' => '127.0.0.21',
'DC_SERVER_IPV6' => 'fd00:0000:0000:0000:0000:0000:5357:5f15',
'DC_SERVER' => 'localdc',
'DC_USERNAME' => 'Administrator',
'DOMAIN' => 'SAMBADOMAIN',
'LOCAL_PATH' => '/.../st/ad_member_rfc2307/share',
'LOCK_DIR' => '/.../st/ad_member_rfc2307/lockdir',
'NETBIOSNAME' => 'RFC2307MEMBER',
'NMBD_SOCKET_DIR' => '/.../st/ad_member_rfc2307/nmbd',
'NSS_WRAPPER_GROUP' => '/.../st/ad_member_rfc2307/private/group',
'NSS_WRAPPER_HOSTNAME' => 'rfc2307member.samba.example.com',
'NSS_WRAPPER_HOSTS' => '/.../st/hosts',
'NSS_WRAPPER_MODULE_FN_PREFIX' => 'winbind',
'NSS_WRAPPER_MODULE_SO_PATH' => '/.../bin/default/nsswitch/libnss-wrapper-winbind.so',
'NSS_WRAPPER_PASSWD' => '/.../st/ad_member_rfc2307/private/passwd',
'PASSWORD' => 'loCalMemberPass',
'REALM' => 'SAMBA.EXAMPLE.COM',
'RESOLV_WRAPPER_HOSTS' => '/.../st/dns_host_file',
'SELFTEST_WINBINDD_SOCKET_DIR' => '/.../st/ad_member_rfc2307/winbindd',
'SERVER_IP' => '127.0.0.34',
'SERVER_IPV6' => 'fd00:0000:0000:0000:0000:0000:5357:5f22',
'SERVER' => 'RFC2307MEMBER',
'USERID' => '55668',
'USERNAME' => 'jamiemcclymont',
}
Unsurprisingly, some of these can cause issues for the provisioning process, if
a reduced subset of tests is being run which causes the provision to encounter
never-before-seen pairs of adjacent environments.
For example, a run with only
TESTS='--include-env=vampire_dc --include-env=ad_member_rfc2307'
would fail to start up the vampire_dc with:
Could not find machine account in secrets database:
Failed to fetch machine account password from secrets.ldb:
Could not find entry to match filter:
'(&(flatname=SAMBADOMAIN)(objectclass=primaryDomain))' base: 'cn=Primary Domains': No such object: dsdb_search at ../source4/dsdb/common/util.c:4641
Signed-off-by: Jamie McClymont <jamiemcclymont@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2018-01-29 08:59:34 +03:00
# Initially clear out the environment for the provision, so previous envs'
# variables don't leak in. Provisioning steps must explicitly set their
# necessary variables when calling out to other executables
2019-02-26 03:26:25 +03:00
Samba:: clear_exported_envvars ( ) ;
selftest: Clear environment before provision
Currently, if an environment is being provisioned after a test which used
ad_member_rfc2307, the provisioning process has all of the following in its
environment:
{
'DC_NETBIOSNAME' => 'LOCALDC',
'DC_PASSWORD' => 'locDCpass1',
'DC_SERVER_IP' => '127.0.0.21',
'DC_SERVER_IPV6' => 'fd00:0000:0000:0000:0000:0000:5357:5f15',
'DC_SERVER' => 'localdc',
'DC_USERNAME' => 'Administrator',
'DOMAIN' => 'SAMBADOMAIN',
'LOCAL_PATH' => '/.../st/ad_member_rfc2307/share',
'LOCK_DIR' => '/.../st/ad_member_rfc2307/lockdir',
'NETBIOSNAME' => 'RFC2307MEMBER',
'NMBD_SOCKET_DIR' => '/.../st/ad_member_rfc2307/nmbd',
'NSS_WRAPPER_GROUP' => '/.../st/ad_member_rfc2307/private/group',
'NSS_WRAPPER_HOSTNAME' => 'rfc2307member.samba.example.com',
'NSS_WRAPPER_HOSTS' => '/.../st/hosts',
'NSS_WRAPPER_MODULE_FN_PREFIX' => 'winbind',
'NSS_WRAPPER_MODULE_SO_PATH' => '/.../bin/default/nsswitch/libnss-wrapper-winbind.so',
'NSS_WRAPPER_PASSWD' => '/.../st/ad_member_rfc2307/private/passwd',
'PASSWORD' => 'loCalMemberPass',
'REALM' => 'SAMBA.EXAMPLE.COM',
'RESOLV_WRAPPER_HOSTS' => '/.../st/dns_host_file',
'SELFTEST_WINBINDD_SOCKET_DIR' => '/.../st/ad_member_rfc2307/winbindd',
'SERVER_IP' => '127.0.0.34',
'SERVER_IPV6' => 'fd00:0000:0000:0000:0000:0000:5357:5f22',
'SERVER' => 'RFC2307MEMBER',
'USERID' => '55668',
'USERNAME' => 'jamiemcclymont',
}
Unsurprisingly, some of these can cause issues for the provisioning process, if
a reduced subset of tests is being run which causes the provision to encounter
never-before-seen pairs of adjacent environments.
For example, a run with only
TESTS='--include-env=vampire_dc --include-env=ad_member_rfc2307'
would fail to start up the vampire_dc with:
Could not find machine account in secrets database:
Failed to fetch machine account password from secrets.ldb:
Could not find entry to match filter:
'(&(flatname=SAMBADOMAIN)(objectclass=primaryDomain))' base: 'cn=Primary Domains': No such object: dsdb_search at ../source4/dsdb/common/util.c:4641
Signed-off-by: Jamie McClymont <jamiemcclymont@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2018-01-29 08:59:34 +03:00
delete $ ENV { SOCKET_WRAPPER_DEFAULT_IFACE } ;
delete $ ENV { SMB_CONF_PATH } ;
2019-10-30 20:17:36 +03:00
$ ENV { RESOLV_CONF } = "${selftest_resolv_conf_path}.${envname}/ignore" ;
2016-12-16 13:09:16 +03:00
$ ENV { KRB5CCNAME } = "FILE:${selftest_krbt_ccache_path}.${envname}/ignore" ;
2020-11-23 01:28:31 +03:00
$ ENV { GNUPGHOME } = "${selftest_gnupghome_path}.${envname}/ignore" ;
2016-12-16 13:09:16 +03: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 ) ;
2011-04-19 06:43:54 +04:00
if ( not defined ( $ testenv_vars ) ) {
2019-12-07 13:22:45 +03:00
my $ msg = "$opt_target can't start up known environment '$envname'" ;
2019-02-18 05:34:51 +03:00
if ( $ opt_one ) {
2019-12-07 13:22:45 +03:00
die ( $ msg ) ;
2019-02-18 05:34:51 +03:00
}
2019-12-07 13:22:45 +03:00
warn $ msg ;
return ;
}
if ( ref $ testenv_vars ne "HASH" ) {
return $ testenv_vars ;
}
if ( defined ( $ testenv_vars - > { target } ) ) {
$ testenv_vars - > { target } = $ target ;
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
2019-02-26 03:26:25 +03:00
# export the environment variables for the testenv (SERVER, SERVER_IP, etc)
Samba:: export_envvars ( $ testenv_vars ) ;
2007-04-11 00:19:31 +04:00
2016-12-16 13:09:16 +03:00
my $ krb5_ccache_path = "${selftest_krbt_ccache_path}.${envname}.${option}" ;
unlink ( $ krb5_ccache_path ) ;
$ ENV { KRB5CCNAME } = "FILE:${krb5_ccache_path}" ;
2007-04-11 00:19:31 +04:00
return $ testenv_vars ;
}
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
2019-02-26 03:26:25 +03:00
my $ envvarstr = Samba:: exported_envvars_str ( $ testenv_vars ) ;
2007-04-28 12:48:11 +04:00
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 } ) ;
2019-05-31 03:33:59 +03:00
# override the default terminal args (if specified)
if ( defined ( $ ENV { TERMINAL_ARGS } ) ) {
@ term_args = split ( / / , $ ENV { TERMINAL_ARGS } ) ;
}
2013-01-04 02:33:45 +04:00
} 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 ] ;
2018-02-01 07:46:37 +03:00
my $ envvars = setup_env ( $ envname , $ prefix ) ;
2017-02-28 00:45:24 +03:00
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 ) ;
2018-02-13 06:58:26 +03:00
Subunit:: end_testsuite ( $ name , "error" ,
"environment $envname is unknown - exiting" ) ;
2012-02-13 05:14:57 +04:00
next ;
2007-04-19 18:54:09 +04:00
}
2007-03-21 18:57:07 +03:00
2022-09-06 09:48:49 +03:00
# Generate a file with the individual tests to run, if the
2010-06-25 04:35:29 +04:00
# 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 ;