2 # Bootstrap Samba and run a number of tests against it.
3 # Copyright (C) 2005-2010 Jelmer Vernooij <jelmer@samba.org>
4 # Copyright (C) 2007-2009 Stefan Metzmacher <metze@samba.org>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 use FindBin
qw($RealBin $Script);
24 use File::Temp qw(tempfile);
25 use File
::Path
qw(remove_tree);
33 use Time
::HiRes
qw(time);
37 Time
::HiRes
->import("time");
40 print "You don't have Time::Hires installed !\n";
44 my $opt_target = "samba";
46 my $opt_socket_wrapper = 0;
47 my $opt_socket_wrapper_pcap = undef;
48 my $opt_socket_wrapper_keep_pcap = undef;
49 my $opt_random_order = 0;
53 my @opt_exclude_env = ();
54 my @opt_include_env = ();
58 my $opt_default_ldb_backend = "mdb";
59 my $opt_resetup_env = undef;
60 my $opt_load_list = undef;
61 my $opt_libnss_wrapper_so_path = "";
62 my $opt_libresolv_wrapper_so_path = "";
63 my $opt_libsocket_wrapper_so_path = "";
64 my $opt_libuid_wrapper_so_path = "";
65 my $opt_libasan_so_path = "";
66 my $opt_libcrypt_so_path = "";
67 my $opt_use_dns_faking = 0;
79 my ($list, $fullname) = @_;
82 if ($fullname =~ /$$_[0]/) {
83 return ($$_[1]) if ($$_[1]);
93 my ($name, $envname) = @_;
94 my ($env_basename, $env_localpart) = split(/:/, $envname);
96 if ($opt_target eq "samba3" && $Samba::ENV_NEEDS_AD_DC
{$env_basename}) {
97 return "environment $envname is disabled as this build does not include an AD DC";
100 if (@opt_include_env && !(grep {$_ eq $env_basename} @opt_include_env)) {
101 return "environment $envname is disabled (via --include-env command line option) in this test run - skipping";
102 } elsif (@opt_exclude_env && grep {$_ eq $env_basename} @opt_exclude_env) {
103 return "environment $envname is disabled (via --exclude-env command line option) in this test run - skipping";
106 return find_in_list
(\
@excludes, $name);
111 # expand strings from %ENV
112 sub expand_environment_strings
($)
115 # we use a reverse sort so we do the longer ones first
116 foreach my $k (sort { $b cmp $a } keys %ENV) {
117 $s =~ s/\$$k/$ENV{$k}/g;
124 sub run_testsuite
($$$$$)
126 my ($envname, $name, $cmd, $i, $totalsuites) = @_;
127 my $pcap_file = $target->setup_pcap($name);
129 Subunit
::start_testsuite
($name);
130 Subunit
::progress_push
();
131 Subunit
::report_time
();
132 # Enable pipefail so that we catch failing testsuites that are part of a
133 # pipeline (typically, piped through filter-subunit). This won't catch
134 # any testsuite failures that are turned into testsuite-xfails by
136 system("bash", "-o", "pipefail", "-c", $cmd);
137 Subunit
::report_time
();
138 Subunit
::progress_pop
();
141 print "command: $cmd\n";
142 printf "expanded command: %s\n", expand_environment_strings
($cmd);
143 Subunit
::end_testsuite
($name, "error", "Unable to run $cmd: $!");
146 print "command: $cmd\n";
147 printf "expanded command: %s\n", expand_environment_strings
($cmd);
148 Subunit
::end_testsuite
($name, "error",
149 sprintf("%s died with signal %d, %s coredump\n", $cmd, ($?
& 127), ($?
& 128) ?
'with' : 'without'));
153 my $exitcode = $?
>> 8;
155 my $envlog = getlog_env
($envname);
157 print "envlog: $envlog\n";
160 print "command: $cmd\n";
161 printf "expanded command: %s\n", expand_environment_strings
($cmd);
163 if ($exitcode == 0) {
164 Subunit
::end_testsuite
($name, "success");
166 Subunit
::end_testsuite
($name, "failure", "Exit code was $exitcode");
169 $target->cleanup_pcap($pcap_file, $exitcode);
171 if (not $opt_socket_wrapper_keep_pcap and defined($pcap_file)) {
172 print "PCAP FILE: $pcap_file\n";
175 if ($exitcode != 0) {
176 exit(1) if ($opt_one);
184 print "Samba test runner
185 Copyright (C) Jelmer Vernooij <jelmer\@samba.org>
186 Copyright (C) Stefan Metzmacher <metze\@samba.org>
188 Usage: $Script [OPTIONS] TESTNAME-REGEX [TESTNAME-REGEX...]
191 --help this help page
192 --target=samba[3]|win Samba version to target
193 --testlist=FILE file to read available tests from
194 --exclude=FILE Exclude tests listed in the file
195 --include=FILE Include tests listed in the file
196 --exclude-env=ENV Exclude tests for the specified environment
197 --include-env=ENV Include tests for the specified environment
200 --prefix=DIR prefix to run tests in [st]
201 --srcdir=DIR source directory [.]
202 --bindir=DIR binaries directory [./bin]
205 --nss_wrapper_so_path=FILE the nss_wrapper library to preload
206 --resolv_wrapper_so_path=FILE the resolv_wrapper library to preload
207 --socket_wrapper_so_path=FILE the socket_wrapper library to preload
208 --uid_wrapper_so_path=FILE the uid_wrapper library to preload
209 --asan_so_path=FILE the asan library to preload
212 --use-dns-faking Fake DNS entries rather than talking to our
216 --socket-wrapper-pcap save traffic to pcap directories
217 --socket-wrapper-keep-pcap keep all pcap files, not just those for tests that
219 --socket-wrapper enable socket wrapper
222 --quick run quick overall test
223 --one abort when the first test fails
224 --testenv run a shell in the requested test environment
225 --list list available tests
230 my $result = GetOptions
(
231 'help|h|?' => \
$opt_help,
232 'target=s' => \
$opt_target,
233 'prefix=s' => \
$prefix,
234 'socket-wrapper' => \
$opt_socket_wrapper,
235 'socket-wrapper-pcap' => \
$opt_socket_wrapper_pcap,
236 'socket-wrapper-keep-pcap' => \
$opt_socket_wrapper_keep_pcap,
237 'quick' => \
$opt_quick,
239 'exclude=s' => \
@opt_exclude,
240 'include=s' => \
@opt_include,
241 'exclude-env=s' => \
@opt_exclude_env,
242 'include-env=s' => \
@opt_include_env,
243 'srcdir=s' => \
$srcdir,
244 'bindir=s' => \
$bindir,
245 'testenv' => \
$opt_testenv,
246 'list' => \
$opt_list,
247 'mitkrb5' => \
$opt_mitkrb5,
248 'default-ldb-backend=s' => \
$opt_default_ldb_backend,
249 'resetup-environment' => \
$opt_resetup_env,
250 'testlist=s' => \
@testlists,
251 'random-order' => \
$opt_random_order,
252 'load-list=s' => \
$opt_load_list,
253 'nss_wrapper_so_path=s' => \
$opt_libnss_wrapper_so_path,
254 'resolv_wrapper_so_path=s' => \
$opt_libresolv_wrapper_so_path,
255 'socket_wrapper_so_path=s' => \
$opt_libsocket_wrapper_so_path,
256 'uid_wrapper_so_path=s' => \
$opt_libuid_wrapper_so_path,
257 'asan_so_path=s' => \
$opt_libasan_so_path,
258 'crypt_so_path=s' => \
$opt_libcrypt_so_path,
259 'use-dns-faking' => \
$opt_use_dns_faking
262 exit(1) if (not $result);
264 ShowHelp
() if ($opt_help);
266 die("--list and --testenv are mutually exclusive") if ($opt_list and $opt_testenv);
268 # we want unbuffered output
273 # quick hack to disable rpc validation when using valgrind - its way too slow
274 unless (defined($ENV{VALGRIND
})) {
275 $ENV{VALIDATE
} = "validate";
276 $ENV{MALLOC_CHECK_
} = 3;
279 # make all our python scripts unbuffered
280 $ENV{PYTHONUNBUFFERED
} = 1;
282 $ENV{SAMBA_DEPRECATED_SUPPRESS
} = 1;
284 # do not depend on the users setup
285 # see also bootstrap/config.py
287 $ENV{LC_ALL
} = $ENV{LANG
} = "en_US.utf8";
289 my $bindir_abs = abs_path
($bindir);
291 my $torture_maxtime = ($ENV{TORTURE_MAXTIME
} or 1200);
294 $prefix =~ s
+/\./+/+;
297 die("using an empty prefix isn't allowed") unless $prefix ne "";
299 # Ensure we have the test prefix around.
301 # We need restrictive
302 # permissions on this as some subdirectories in this tree will have
303 # wider permissions (ie 0777) and this would allow other users on the
304 # host to subvert the test process.
306 mkdir($prefix, 0700) unless -d
$prefix;
308 # We need to have no umask limitations for the tests.
311 my $prefix_abs = abs_path
($prefix);
312 my $tmpdir_abs = abs_path
("$prefix/tmp");
313 mkdir($tmpdir_abs, 0777) unless -d
$tmpdir_abs;
315 my $srcdir_abs = abs_path
($srcdir);
317 die("using an empty absolute prefix isn't allowed") unless $prefix_abs ne "";
318 die("using '/' as absolute prefix isn't allowed") unless $prefix_abs ne "/";
320 $ENV{SAMBA_SELFTEST
} = "1";
322 $ENV{PREFIX
} = $prefix;
323 $ENV{PREFIX_ABS
} = $prefix_abs;
324 $ENV{SRCDIR
} = $srcdir;
325 $ENV{SRCDIR_ABS
} = $srcdir_abs;
326 $ENV{BINDIR
} = $bindir_abs;
328 my $tls_enabled = not $opt_quick;
329 $ENV{TLS_ENABLED
} = ($tls_enabled?
"yes":"no");
331 sub prefix_pathvar
($$)
333 my ($name, $newpath) = @_;
334 if (defined($ENV{$name})) {
335 $ENV{$name} = "$newpath:$ENV{$name}";
337 $ENV{$name} = $newpath;
340 prefix_pathvar
("PKG_CONFIG_PATH", "$bindir_abs/pkgconfig");
341 prefix_pathvar
("PYTHONPATH", "$bindir_abs/python");
343 if ($opt_socket_wrapper_keep_pcap) {
344 # Socket wrapper keep pcap implies socket wrapper pcap
345 $opt_socket_wrapper_pcap = 1;
348 if ($opt_socket_wrapper_pcap) {
349 # Socket wrapper pcap implies socket wrapper
350 $opt_socket_wrapper = 1;
353 my $ld_preload = $ENV{LD_PRELOAD
};
355 if ($opt_libasan_so_path) {
357 if ($opt_libcrypt_so_path) {
358 $ld_preload = "$opt_libasan_so_path:$opt_libcrypt_so_path:$ld_preload";
360 $ld_preload = "$opt_libasan_so_path:$ld_preload";
363 if ($opt_libcrypt_so_path) {
364 $ld_preload = "$opt_libasan_so_path:$opt_libcrypt_so_path";
366 $ld_preload = "$opt_libasan_so_path";
371 if ($opt_libnss_wrapper_so_path) {
373 $ld_preload = "$ld_preload:$opt_libnss_wrapper_so_path";
375 $ld_preload = "$opt_libnss_wrapper_so_path";
379 if ($opt_libresolv_wrapper_so_path) {
381 $ld_preload = "$ld_preload:$opt_libresolv_wrapper_so_path";
383 $ld_preload = "$opt_libresolv_wrapper_so_path";
387 if ($opt_libsocket_wrapper_so_path) {
389 $ld_preload = "$ld_preload:$opt_libsocket_wrapper_so_path";
391 $ld_preload = "$opt_libsocket_wrapper_so_path";
395 if ($opt_libuid_wrapper_so_path) {
397 $ld_preload = "$ld_preload:$opt_libuid_wrapper_so_path";
399 $ld_preload = "$opt_libuid_wrapper_so_path";
403 if (defined($ENV{USE_NAMESPACES
})) {
404 print "Using linux containerization for selftest testenv(s)...\n";
406 # Create a common bridge to connect up the testenv namespaces. We give
407 # it the client's IP address, as this is where the tests will run from
408 my $ipv4_addr = Samba
::get_ipv4_addr
("client");
409 my $ipv6_addr = Samba
::get_ipv6_addr
("client");
410 system "$ENV{SRCDIR_ABS}/selftest/ns/create_bridge.sh selftest0 $ipv4_addr $ipv6_addr";
413 $ENV{LD_PRELOAD
} = $ld_preload;
414 print "LD_PRELOAD=$ENV{LD_PRELOAD}\n";
416 # Enable uid_wrapper globally
417 $ENV{UID_WRAPPER
} = 1;
419 # We are already hitting the limit, so double it.
420 $ENV{NSS_WRAPPER_MAX_HOSTENTS
} = 200;
422 # Disable RTLD_DEEPBIND hack for Samba bind dlz module
424 # This is needed in order to allow the ldb_*ldap module
425 # to work with a preloaded socket wrapper.
426 $ENV{LDB_MODULES_DISABLE_DEEPBIND
} = 1;
428 my $socket_wrapper_dir;
429 if ($opt_socket_wrapper) {
430 $socket_wrapper_dir = SocketWrapper
::setup_dir
("$prefix_abs/w", $opt_socket_wrapper_pcap);
431 print "SOCKET_WRAPPER_DIR=$socket_wrapper_dir\n";
432 } elsif (not $opt_list) {
434 warn("not using socket wrapper, but also not running as root. Will not be able to listen on proper ports");
438 if ($opt_use_dns_faking) {
439 print "DNS: Faking nameserver\n";
440 $ENV{SAMBA_DNS_FAKING
} = 1;
443 my $testenv_default = "none";
445 if ($opt_mitkrb5 == 1) {
446 $ENV{MITKRB5
} = $opt_mitkrb5;
447 $ENV{KRB5RCACHETYPE
} = "none";
450 # After this many seconds, the server will self-terminate. All tests
451 # must terminate in this time, and testenv will only stay alive this
456 # 1 year should be enough :-)
457 $server_maxtime = 365 * 24 * 60 * 60;
459 # make test should run under 5 hours
460 $server_maxtime = 5 * 60 * 60;
463 if (defined($ENV{SMBD_MAXTIME
}) and $ENV{SMBD_MAXTIME
} ne "") {
464 $server_maxtime = $ENV{SMBD_MAXTIME
};
467 $target = new Samba
($bindir, $srcdir, $server_maxtime,
468 $opt_socket_wrapper_pcap,
469 $opt_socket_wrapper_keep_pcap,
470 $opt_default_ldb_backend);
472 if ($opt_target eq "samba") {
473 $testenv_default = "ad_dc";
474 } elsif ($opt_target eq "samba3") {
475 $testenv_default = "nt4_member";
479 sub read_test_regexes
($)
483 open(LF
, "<$name") or die("unable to read $name: $!");
487 if (/^(.*?)([ \t]+)\#([\t ]*)(.*?)$/) {
488 push (@ret, [$1, $4]);
490 s/^(.*?)([ \t]+)\#([\t ]*)(.*?)$//;
491 push (@ret, [$_, undef]);
498 foreach (@opt_exclude) {
499 push (@excludes, read_test_regexes
($_));
502 foreach (@opt_include) {
503 push (@includes, read_test_regexes
($_));
506 # We give the selftest client 6 different IPv4 addresses to use. Most tests
507 # only use the first (.11) IP. Note that winsreplication.c is one test that
508 # uses the other IPs (search for iface_list_count()).
509 $ENV{SOCKET_WRAPPER_IPV4_NETWORK
} = "10.53.57.0";
510 my $interfaces = Samba
::get_interfaces_config
("client", 6);
512 my $clientdir = "$prefix_abs/client";
514 my $conffile = "$clientdir/client.conf";
515 $ENV{SMB_CONF_PATH
} = $conffile;
517 sub write_clientconf
($$$)
519 my ($conffile, $clientdir, $vars) = @_;
521 mkdir("$clientdir", 0777) unless -d
"$clientdir";
524 { name
=> "private", mask
=> 0777 },
525 { name
=> "bind-dns", mask
=> 0777 },
526 { name
=> "lockdir", mask
=> 0777 },
527 { name
=> "statedir", mask
=> 0777 },
528 { name
=> "cachedir", mask
=> 0777 },
529 { name
=> "pkinit", mask
=> 0700 },
530 { name
=> "pid", mask
=> 0777 },
531 # the ncalrpcdir needs exactly 0755 otherwise tests fail.
532 { name
=> "ncalrpcdir", mask
=> 0755, umask => 0022 },
535 foreach my $sub (@subdirs) {
536 my $dir = "$clientdir/$sub->{name}";
539 if (defined($sub->{umask})) {
542 mkdir($dir, $sub->{mask
});
546 my $cadir = "$ENV{SRCDIR_ABS}/selftest/manage-ca/CA-samba.example.com";
547 my $cacert = "$cadir/Public/CA-samba.example.com-cert.pem";
548 my $cacrl_pem = "$cadir/Public/CA-samba.example.com-crl.pem";
549 my $ca_users_dir = "$cadir/Users";
550 my $client_loglevel = $ENV{CLIENT_LOG_LEVEL
} || 1;
552 # each user has a USER-${USER_PRINCIPAL_NAME}-cert.pem and
553 # USER-${USER_PRINCIPAL_NAME}-private-key.pem symlink
554 # We make a copy here and make the certificated easily
555 # accessable in the client environment.
558 opendir USERS
, "${ca_users_dir}" or die "Could not open dir '${ca_users_dir}': $!";
559 for my $d (readdir USERS
) {
560 my $user_dir = "${ca_users_dir}/${d}";
561 next if ${d
} =~ /^\./;
562 next if (! -d
"${user_dir}");
563 opendir USER
, "${user_dir}" or die "Could not open dir '${user_dir}': $!";
564 for my $l (readdir USER
) {
565 my $user_link = "${user_dir}/${l}";
566 next if ${l
} =~ /^\./;
567 next if (! -l
"${user_link}");
569 my $dest = "${clientdir}/pkinit/${l}";
570 Samba
::copy_file_content
(${user_link
}, ${dest
});
577 open(CF
, ">$conffile");
578 print CF
"[global]\n";
579 print CF
"\tnetbios name = client\n";
580 if (defined($vars->{DOMAIN
})) {
581 print CF
"\tworkgroup = $vars->{DOMAIN}\n";
583 if (defined($vars->{REALM
})) {
584 print CF
"\trealm = $vars->{REALM}\n";
586 if ($opt_socket_wrapper) {
587 print CF
"\tinterfaces = $interfaces\n";
590 private dir = $clientdir/private
591 binddns dir = $clientdir/bind-dns
592 lock dir = $clientdir/lockdir
593 state directory = $clientdir/statedir
594 cache directory = $clientdir/cachedir
595 ncalrpc dir = $clientdir/ncalrpcdir
596 pid directory = $clientdir/pid
597 panic action = $RealBin/gdb_backtrace \%d
599 notify:inotify = false
601 system:anonymous = true
602 client lanman auth = Yes
603 client min protocol = CORE
604 log level = $client_loglevel
605 torture:basedir = $clientdir
606 #We don't want to run 'speed' tests for very long
607 torture:timelimit = 1
608 winbind separator = /
609 tls cafile = ${cacert}
610 tls crlfile = ${cacrl_pem}
611 tls verify peer = no_check
612 include system krb5 conf = no
613 elasticsearch:mappings = $srcdir_abs/source3/rpc_server/mdssvc/elasticsearch_mappings.json
620 sub should_run_test
($)
626 for (my $i=0; $i <= $#tests; $i++) {
627 if ($name =~ /$tests[$i]/i) {
639 open(IN
, $filename) or die("Unable to open $filename: $!");
642 if (/-- TEST(-LOADLIST|) --\n/) {
643 my $supports_loadlist = (defined($1) and $1 eq "-LOADLIST");
649 if ($supports_loadlist) {
651 $loadlist =~ s/\n//g;
655 if (should_run_test
($name) == 1) {
656 push (@ret, [$name, $env, $cmdline, $loadlist]);
662 close(IN
) or die("Error creating recipe from $filename");
666 if ($#testlists == -1) {
667 die("No testlists specified");
670 $ENV{SELFTEST_PREFIX
} = "$prefix_abs";
671 $ENV{SELFTEST_TMPDIR
} = "$tmpdir_abs";
672 $ENV{TMPDIR
} = "$tmpdir_abs";
673 $ENV{TEST_DATA_PREFIX
} = "$tmpdir_abs";
675 $ENV{SELFTEST_QUICK
} = "1";
677 $ENV{SELFTEST_QUICK
} = "";
679 $ENV{SELFTEST_MAXTIME
} = $torture_maxtime;
681 my $selftest_resolv_conf_path = "$tmpdir_abs/selftest.resolv.conf";
682 $ENV{RESOLV_CONF
} = "${selftest_resolv_conf_path}.global";
684 my $selftest_krbt_ccache_path = "$tmpdir_abs/selftest.krb5_ccache";
685 $ENV{KRB5CCNAME
} = "FILE:${selftest_krbt_ccache_path}.global";
687 my $selftest_gnupghome_path = "$tmpdir_abs/selftest.no.gnupg";
688 $ENV{GNUPGHOME
} = "${selftest_gnupghome_path}.global";
691 foreach my $fn (@testlists) {
692 foreach (read_testlist
($fn)) {
694 next if (@includes and not defined(find_in_list
(\
@includes, $name)));
695 push (@available, $_);
699 my $restricted = undef;
700 my $restricted_used = {};
702 if ($opt_load_list) {
704 open(LOAD_LIST
, "<$opt_load_list") or die("Unable to open $opt_load_list");
705 while (<LOAD_LIST
>) {
707 push (@
$restricted, $_);
712 my $individual_tests = undef;
713 $individual_tests = {};
715 foreach my $testsuite (@available) {
716 my $name = $$testsuite[0];
717 my $skipreason = skip
(@
$testsuite);
718 if (defined($restricted)) {
719 # Find the testsuite for this test
721 foreach my $r (@
$restricted) {
723 $individual_tests->{$name} = [];
725 $restricted_used->{$r} = 1;
726 } elsif (substr($r, 0, length($name)+1) eq "$name.") {
727 push(@
{$individual_tests->{$name}}, $r);
729 $restricted_used->{$r} = 1;
733 if (defined($skipreason)) {
735 Subunit
::skip_testsuite
($name, $skipreason);
738 push(@todo, $testsuite);
741 } elsif (defined($skipreason)) {
743 Subunit
::skip_testsuite
($name, $skipreason);
746 push(@todo, $testsuite);
750 if (defined($restricted)) {
751 foreach (@
$restricted) {
752 unless (defined($restricted_used->{$_})) {
753 print "No test or testsuite found matching $_\n";
756 } elsif ($#todo == -1) {
757 print STDERR
"No tests to run\n";
761 my $suitestotal = $#todo + 1;
764 Subunit
::progress
($suitestotal);
765 Subunit
::report_time
();
771 my %running_envs = ();
773 sub get_running_env
($)
781 return $running_envs{$envname};
788 $SIG{INT
} = $SIG{QUIT
} = $SIG{TERM
} = 'DEFAULT';
789 $SIG{PIPE
} = 'IGNORE';
791 open(STDOUT
, ">&STDERR") or die "can't dup STDOUT to STDERR: $!";
793 print "$0: PID[$$]: Got SIG${signame} teardown environments.\n";
794 teardown_env
($_) foreach(keys %running_envs);
795 system("pstree -p $$");
796 print "$0: PID[$$]: Exiting...\n";
800 $SIG{INT
} = $SIG{QUIT
} = $SIG{TERM
} = $SIG{PIPE
} = \
&sighandler
;
804 my ($name, $prefix) = @_;
806 my $testenv_vars = undef;
812 $option =~ s/^[^:]*//;
815 $option = "client" if $option eq "";
817 # Initially clear out the environment for the provision, so previous envs'
818 # variables don't leak in. Provisioning steps must explicitly set their
819 # necessary variables when calling out to other executables
820 Samba
::clear_exported_envvars
();
821 delete $ENV{SOCKET_WRAPPER_DEFAULT_IFACE
};
822 delete $ENV{SMB_CONF_PATH
};
824 $ENV{RESOLV_CONF
} = "${selftest_resolv_conf_path}.${envname}/ignore";
825 $ENV{KRB5CCNAME
} = "FILE:${selftest_krbt_ccache_path}.${envname}/ignore";
826 $ENV{GNUPGHOME
} = "${selftest_gnupghome_path}.${envname}/ignore";
828 if (defined(get_running_env
($envname))) {
829 $testenv_vars = get_running_env
($envname);
830 if (not $testenv_vars->{target
}->check_env($testenv_vars)) {
831 print $testenv_vars->{target
}->getlog_env($testenv_vars);
832 $testenv_vars = undef;
835 $testenv_vars = $target->setup_env($envname, $prefix);
836 if (not defined($testenv_vars)) {
837 my $msg = "$opt_target can't start up known environment '$envname'";
844 if (ref $testenv_vars ne "HASH") {
845 return $testenv_vars;
847 if (defined($testenv_vars->{target
})) {
848 $testenv_vars->{target
} = $target;
852 return undef unless defined($testenv_vars);
854 $running_envs{$envname} = $testenv_vars;
856 if ($option eq "local") {
857 SocketWrapper
::set_default_iface
($testenv_vars->{SOCKET_WRAPPER_DEFAULT_IFACE
});
858 $ENV{SMB_CONF_PATH
} = $testenv_vars->{SERVERCONFFILE
};
859 } elsif ($option eq "client") {
860 SocketWrapper
::set_default_iface
(11);
861 write_clientconf
($conffile, $clientdir, $testenv_vars);
862 $ENV{SMB_CONF_PATH
} = $conffile;
864 die("Unknown option[$option] for envname[$envname]");
867 # export the environment variables for the testenv (SERVER, SERVER_IP, etc)
868 Samba
::export_envvars
($testenv_vars);
870 my $krb5_ccache_path = "${selftest_krbt_ccache_path}.${envname}.${option}";
871 unlink($krb5_ccache_path);
872 $ENV{KRB5CCNAME
} = "FILE:${krb5_ccache_path}";
873 return $testenv_vars;
879 return "" if ($envname eq "none");
880 my $env = get_running_env
($envname);
881 return $env->{target
}->getlog_env($env);
887 my $env = get_running_env
($envname);
888 return $env->{target
}->check_env($env);
894 return if ($envname eq "none");
895 print STDERR
"teardown_env($envname)\n";
896 my $env = get_running_env
($envname);
897 $env->{target
}->teardown_env($env);
898 delete $running_envs{$envname};
901 # This 'global' file needs to be empty when we start
902 unlink("$prefix_abs/dns_host_file");
903 unlink("$prefix_abs/hosts");
905 if ($opt_random_order) {
907 my @newtodo = List
::Util
::shuffle
(@todo);
912 my $testenv_name = $ENV{SELFTEST_TESTENV
};
913 $testenv_name = $testenv_default unless defined($testenv_name);
915 my $testenv_vars = setup_env
($testenv_name, $prefix);
917 if (not $testenv_vars or $testenv_vars eq "UNKNOWN") {
918 die("Unable to setup environment $testenv_name");
921 $ENV{PIDDIR
} = $testenv_vars->{PIDDIR
};
922 $ENV{ENVNAME
} = $testenv_name;
924 my $envvarstr = Samba
::exported_envvars_str
($testenv_vars);
926 my @term_args = ("echo -e \"
927 Welcome to the Samba4 Test environment '$testenv_name'
929 This matches the client environment used in make test
930 server is pid `cat \$PIDDIR/samba.pid`
932 Some useful environment variables:
933 TORTURE_OPTIONS=\$TORTURE_OPTIONS
934 SMB_CONF_PATH=\$SMB_CONF_PATH
937 \" && LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH} bash");
939 if ($ENV{TERMINAL
}) {
940 @term = ($ENV{TERMINAL
});
941 # override the default terminal args (if specified)
942 if (defined($ENV{TERMINAL_ARGS
})) {
943 @term_args = split(/ /, $ENV{TERMINAL_ARGS
});
946 @term = ("xterm", "-e");
947 unshift(@term_args, ("bash", "-c"));
950 system(@term, @term_args);
952 teardown_env
($testenv_name);
953 } elsif ($opt_list) {
956 my $envname = $$_[1];
958 my $listcmd = $$_[3];
960 unless (defined($listcmd)) {
961 warn("Unable to list tests in $name");
962 # Rather than ignoring this testsuite altogether, just pretend the entire testsuite is
971 die("Unable to run $listcmd: $!");
973 die(sprintf("%s died with signal %d, %s coredump\n", $listcmd, ($?
& 127), ($?
& 128) ?
'with' : 'without'));
976 my $exitcode = $?
>> 8;
977 if ($exitcode != 0) {
978 die("$cmd exited with exit code $exitcode");
986 my $envname = $$_[1];
987 my $envvars = setup_env
($envname, $prefix);
989 if (not defined($envvars)) {
990 Subunit
::start_testsuite
($name);
991 Subunit
::end_testsuite
($name, "error",
992 "unable to set up environment $envname - exiting");
994 } elsif ($envvars eq "UNKNOWN") {
995 Subunit
::start_testsuite
($name);
996 Subunit
::end_testsuite
($name, "error",
997 "environment $envname is unknown - exiting");
1001 # Generate a file with the individual tests to run, if the
1002 # test runner for this test suite supports it.
1003 if ($individual_tests and $individual_tests->{$name}) {
1005 my ($fh, $listid_file) = tempfile
(UNLINK
=> 0);
1006 foreach my $test (@
{$individual_tests->{$name}}) {
1007 print $fh substr($test, length($name)+1) . "\n";
1009 $cmd =~ s/\$LOADLIST/--load-list=$listid_file/g;
1011 warn("Unable to run individual tests in $name, it does not support --loadlist.");
1015 run_testsuite
($envname, $name, $cmd, $i, $suitestotal);
1017 teardown_env
($envname) if ($opt_resetup_env);
1023 teardown_env
($_) foreach (keys %running_envs);
1027 # if there were any valgrind failures, show them
1028 foreach (<$prefix/valgrind
.log*>) {
1029 next unless (-s
$_);
1030 print "VALGRIND FAILURE\n";