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/>.
21 use FindBin
qw($RealBin $Script);
23 use File::Temp qw(tempfile);
31 use Time
::HiRes
qw(time);
35 Time
::HiRes
->import("time");
38 print "You don't have Time::Hires installed !\n";
42 my $opt_target = "samba";
44 my $opt_socket_wrapper = 0;
45 my $opt_socket_wrapper_pcap = undef;
46 my $opt_socket_wrapper_keep_pcap = undef;
47 my $opt_random_order = 0;
51 my @opt_exclude_env = ();
52 my @opt_include_env = ();
57 my $opt_resetup_env = undef;
58 my $opt_load_list = undef;
59 my $opt_libnss_wrapper_so_path = "";
60 my $opt_libresolv_wrapper_so_path = "";
61 my $opt_libsocket_wrapper_so_path = "";
62 my $opt_libuid_wrapper_so_path = "";
63 my $opt_libasan_so_path = "";
64 my $opt_use_dns_faking = 0;
76 my ($list, $fullname) = @_;
79 if ($fullname =~ /$$_[0]/) {
80 return ($$_[1]) if ($$_[1]);
90 my ($name, $envname) = @_;
91 my ($env_basename, $env_localpart) = split(/:/, $envname);
93 if ($opt_target eq "samba3" && $Samba::ENV_NEEDS_AD_DC
{$env_basename}) {
94 return "environment $envname is disabled as this build does not include an AD DC";
97 if (@opt_include_env && !(grep {$_ eq $env_basename} @opt_include_env)) {
98 return "environment $envname is disabled (via --include-env command line option) in this test run - skipping";
99 } elsif (@opt_exclude_env && grep {$_ eq $env_basename} @opt_exclude_env) {
100 return "environment $envname is disabled (via --exclude-env command line option) in this test run - skipping";
103 return find_in_list
(\
@excludes, $name);
112 return unless ($opt_socket_wrapper_pcap);
113 return unless defined($ENV{SOCKET_WRAPPER_PCAP_DIR
});
116 $fname =~ s
%[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\
-]%_%g;
118 my $pcap_file = "$ENV{SOCKET_WRAPPER_PCAP_DIR}/$fname.pcap";
120 SocketWrapper
::setup_pcap
($pcap_file);
127 my ($pcap_file, $exitcode) = @_;
129 return unless ($opt_socket_wrapper_pcap);
130 return if ($opt_socket_wrapper_keep_pcap);
131 return unless ($exitcode == 0);
132 return unless defined($pcap_file);
137 # expand strings from %ENV
138 sub expand_environment_strings
($)
141 # we use a reverse sort so we do the longer ones first
142 foreach my $k (sort { $b cmp $a } keys %ENV) {
143 $s =~ s/\$$k/$ENV{$k}/g;
148 sub run_testsuite
($$$$$)
150 my ($envname, $name, $cmd, $i, $totalsuites) = @_;
151 my $pcap_file = setup_pcap
($name);
153 Subunit
::start_testsuite
($name);
154 Subunit
::progress_push
();
155 Subunit
::report_time
();
157 Subunit
::report_time
();
158 Subunit
::progress_pop
();
161 print "command: $cmd\n";
162 printf "expanded command: %s\n", expand_environment_strings
($cmd);
163 Subunit
::end_testsuite
($name, "error", "Unable to run $cmd: $!");
166 print "command: $cmd\n";
167 printf "expanded command: %s\n", expand_environment_strings
($cmd);
168 Subunit
::end_testsuite
($name, "error",
169 sprintf("%s died with signal %d, %s coredump\n", $cmd, ($?
& 127), ($?
& 128) ?
'with' : 'without'));
173 my $exitcode = $?
>> 8;
175 my $envlog = getlog_env
($envname);
177 print "envlog: $envlog\n";
180 print "command: $cmd\n";
181 printf "expanded command: %s\n", expand_environment_strings
($cmd);
183 if ($exitcode == 0) {
184 Subunit
::end_testsuite
($name, "success");
186 Subunit
::end_testsuite
($name, "failure", "Exit code was $exitcode");
189 cleanup_pcap
($pcap_file, $exitcode);
191 if (not $opt_socket_wrapper_keep_pcap and defined($pcap_file)) {
192 print "PCAP FILE: $pcap_file\n";
195 if ($exitcode != 0) {
196 exit(1) if ($opt_one);
204 print "Samba test runner
205 Copyright (C) Jelmer Vernooij <jelmer\@samba.org>
206 Copyright (C) Stefan Metzmacher <metze\@samba.org>
208 Usage: $Script [OPTIONS] TESTNAME-REGEX [TESTNAME-REGEX...]
211 --help this help page
212 --target=samba[3]|win Samba version to target
213 --testlist=FILE file to read available tests from
214 --exclude=FILE Exclude tests listed in the file
215 --include=FILE Include tests listed in the file
216 --exclude-env=ENV Exclude tests for the specified environment
217 --include-env=ENV Include tests for the specified environment
220 --prefix=DIR prefix to run tests in [st]
221 --srcdir=DIR source directory [.]
222 --bindir=DIR binaries directory [./bin]
225 --nss_wrapper_so_path=FILE the nss_wrapper library to preload
226 --resolv_wrapper_so_path=FILE the resolv_wrapper library to preload
227 --socket_wrapper_so_path=FILE the socket_wrapper library to preload
228 --uid_wrapper_so_path=FILE the uid_wrapper library to preload
229 --asan_so_path=FILE the asan library to preload
232 --use-dns-faking Fake DNS entries rather than talking to our
236 --socket-wrapper-pcap save traffic to pcap directories
237 --socket-wrapper-keep-pcap keep all pcap files, not just those for tests that
239 --socket-wrapper enable socket wrapper
242 --ldap=openldap|fedora-ds back samba onto specified ldap server
245 --quick run quick overall test
246 --one abort when the first test fails
247 --testenv run a shell in the requested test environment
248 --list list available tests
253 my $result = GetOptions
(
254 'help|h|?' => \
$opt_help,
255 'target=s' => \
$opt_target,
256 'prefix=s' => \
$prefix,
257 'socket-wrapper' => \
$opt_socket_wrapper,
258 'socket-wrapper-pcap' => \
$opt_socket_wrapper_pcap,
259 'socket-wrapper-keep-pcap' => \
$opt_socket_wrapper_keep_pcap,
260 'quick' => \
$opt_quick,
262 'exclude=s' => \
@opt_exclude,
263 'include=s' => \
@opt_include,
264 'exclude-env=s' => \
@opt_exclude_env,
265 'include-env=s' => \
@opt_include_env,
266 'srcdir=s' => \
$srcdir,
267 'bindir=s' => \
$bindir,
268 'testenv' => \
$opt_testenv,
269 'list' => \
$opt_list,
270 'mitkrb5' => \
$opt_mitkrb5,
272 'resetup-environment' => \
$opt_resetup_env,
273 'testlist=s' => \
@testlists,
274 'random-order' => \
$opt_random_order,
275 'load-list=s' => \
$opt_load_list,
276 'nss_wrapper_so_path=s' => \
$opt_libnss_wrapper_so_path,
277 'resolv_wrapper_so_path=s' => \
$opt_libresolv_wrapper_so_path,
278 'socket_wrapper_so_path=s' => \
$opt_libsocket_wrapper_so_path,
279 'uid_wrapper_so_path=s' => \
$opt_libuid_wrapper_so_path,
280 'asan_so_path=s' => \
$opt_libasan_so_path,
281 'use-dns-faking' => \
$opt_use_dns_faking
284 exit(1) if (not $result);
286 ShowHelp
() if ($opt_help);
288 die("--list and --testenv are mutually exclusive") if ($opt_list and $opt_testenv);
290 # we want unbuffered output
295 # quick hack to disable rpc validation when using valgrind - its way too slow
296 unless (defined($ENV{VALGRIND
})) {
297 $ENV{VALIDATE
} = "validate";
298 $ENV{MALLOC_CHECK_
} = 3;
301 # make all our python scripts unbuffered
302 $ENV{PYTHONUNBUFFERED
} = 1;
304 # do not depend on the users setup
307 my $bindir_abs = abs_path
($bindir);
309 # Backwards compatibility:
310 if (defined($ENV{TEST_LDAP
}) and $ENV{TEST_LDAP
} eq "yes") {
311 if (defined($ENV{FEDORA_DS_ROOT
})) {
318 my $torture_maxtime = ($ENV{TORTURE_MAXTIME
} or 1200);
321 $torture_maxtime *= 2;
328 die("using an empty prefix isn't allowed") unless $prefix ne "";
330 # Ensure we have the test prefix around.
332 # We need restrictive
333 # permissions on this as some subdirectories in this tree will have
334 # wider permissions (ie 0777) and this would allow other users on the
335 # host to subvert the test process.
337 mkdir($prefix, 0700) unless -d
$prefix;
339 # We need to have no umask limitations for the tests.
342 my $prefix_abs = abs_path
($prefix);
343 my $tmpdir_abs = abs_path
("$prefix/tmp");
344 mkdir($tmpdir_abs, 0777) unless -d
$tmpdir_abs;
346 my $srcdir_abs = abs_path
($srcdir);
348 die("using an empty absolute prefix isn't allowed") unless $prefix_abs ne "";
349 die("using '/' as absolute prefix isn't allowed") unless $prefix_abs ne "/";
351 $ENV{SAMBA_SELFTEST
} = "1";
353 $ENV{PREFIX
} = $prefix;
354 $ENV{PREFIX_ABS
} = $prefix_abs;
355 $ENV{SRCDIR
} = $srcdir;
356 $ENV{SRCDIR_ABS
} = $srcdir_abs;
357 $ENV{GNUPGHOME
} = "$srcdir_abs/selftest/gnupg";
358 $ENV{BINDIR
} = $bindir_abs;
360 my $tls_enabled = not $opt_quick;
361 $ENV{TLS_ENABLED
} = ($tls_enabled?
"yes":"no");
363 sub prefix_pathvar
($$)
365 my ($name, $newpath) = @_;
366 if (defined($ENV{$name})) {
367 $ENV{$name} = "$newpath:$ENV{$name}";
369 $ENV{$name} = $newpath;
372 prefix_pathvar
("PKG_CONFIG_PATH", "$bindir_abs/pkgconfig");
373 prefix_pathvar
("PYTHONPATH", "$bindir_abs/python");
375 if ($opt_socket_wrapper_keep_pcap) {
376 # Socket wrapper keep pcap implies socket wrapper pcap
377 $opt_socket_wrapper_pcap = 1;
380 if ($opt_socket_wrapper_pcap) {
381 # Socket wrapper pcap implies socket wrapper
382 $opt_socket_wrapper = 1;
385 my $ld_preload = $ENV{LD_PRELOAD
};
387 if ($opt_libasan_so_path) {
389 $ld_preload = "$ld_preload:$opt_libasan_so_path";
391 $ld_preload = "$opt_libasan_so_path";
395 if ($opt_libnss_wrapper_so_path) {
397 $ld_preload = "$ld_preload:$opt_libnss_wrapper_so_path";
399 $ld_preload = "$opt_libnss_wrapper_so_path";
403 if ($opt_libresolv_wrapper_so_path) {
405 $ld_preload = "$ld_preload:$opt_libresolv_wrapper_so_path";
407 $ld_preload = "$opt_libresolv_wrapper_so_path";
411 if ($opt_libsocket_wrapper_so_path) {
413 $ld_preload = "$ld_preload:$opt_libsocket_wrapper_so_path";
415 $ld_preload = "$opt_libsocket_wrapper_so_path";
419 if ($opt_libuid_wrapper_so_path) {
421 $ld_preload = "$ld_preload:$opt_libuid_wrapper_so_path";
423 $ld_preload = "$opt_libuid_wrapper_so_path";
427 $ENV{LD_PRELOAD
} = $ld_preload;
428 print "LD_PRELOAD=$ENV{LD_PRELOAD}\n";
430 # Enable uid_wrapper globally
431 $ENV{UID_WRAPPER
} = 1;
433 # We are already hitting the limit, so double it.
434 $ENV{NSS_WRAPPER_MAX_HOSTENTS
} = 200;
436 # Disable RTLD_DEEPBIND hack for Samba bind dlz module
438 # This is needed in order to allow the ldb_*ldap module
439 # to work with a preloaded socket wrapper.
440 $ENV{LDB_MODULES_DISABLE_DEEPBIND
} = 1;
442 my $socket_wrapper_dir;
443 if ($opt_socket_wrapper) {
444 $socket_wrapper_dir = SocketWrapper
::setup_dir
("$prefix_abs/w", $opt_socket_wrapper_pcap);
445 print "SOCKET_WRAPPER_DIR=$socket_wrapper_dir\n";
446 } elsif (not $opt_list) {
448 warn("not using socket wrapper, but also not running as root. Will not be able to listen on proper ports");
452 if ($opt_use_dns_faking) {
453 print "DNS: Faking nameserver\n";
454 $ENV{SAMBA_DNS_FAKING
} = 1;
458 my $testenv_default = "none";
460 if ($opt_mitkrb5 == 1) {
461 $ENV{MITKRB5
} = $opt_mitkrb5;
464 # After this many seconds, the server will self-terminate. All tests
465 # must terminate in this time, and testenv will only stay alive this
470 # 1 year should be enough :-)
471 $server_maxtime = 365 * 24 * 60 * 60;
473 # make test should run under 5 hours
474 $server_maxtime = 5 * 60 * 60;
477 if (defined($ENV{SMBD_MAXTIME
}) and $ENV{SMBD_MAXTIME
} ne "") {
478 $server_maxtime = $ENV{SMBD_MAXTIME
};
481 $target = new Samba
($bindir, $ldap, $srcdir, $server_maxtime);
483 if ($opt_target eq "samba") {
484 $testenv_default = "ad_dc";
485 } elsif ($opt_target eq "samba3") {
486 $testenv_default = "nt4_member";
490 sub read_test_regexes
($)
494 open(LF
, "<$name") or die("unable to read $name: $!");
498 if (/^(.*?)([ \t]+)\#([\t ]*)(.*?)$/) {
499 push (@ret, [$1, $4]);
501 s/^(.*?)([ \t]+)\#([\t ]*)(.*?)$//;
502 push (@ret, [$_, undef]);
509 foreach (@opt_exclude) {
510 push (@excludes, read_test_regexes
($_));
513 foreach (@opt_include) {
514 push (@includes, read_test_regexes
($_));
517 # We give the selftest client 6 different IPv4 addresses to use. Most tests
518 # only use the first (.11) IP. Note that winsreplication.c is one test that
519 # uses the other IPs (search for iface_list_count()).
520 my $interfaces = Samba
::get_interfaces_config
("client", 6);
522 my $clientdir = "$prefix_abs/client";
524 my $conffile = "$clientdir/client.conf";
525 $ENV{SMB_CONF_PATH
} = $conffile;
527 sub write_clientconf
($$$)
529 my ($conffile, $clientdir, $vars) = @_;
531 mkdir("$clientdir", 0777) unless -d
"$clientdir";
533 if ( -d
"$clientdir/private" ) {
534 unlink <$clientdir/private/*>;
536 mkdir("$clientdir/private", 0777);
539 if ( -d
"$clientdir/bind-dns" ) {
540 unlink <$clientdir/bind-dns/*>;
542 mkdir("$clientdir/bind-dns", 0777);
545 if ( -d
"$clientdir/lockdir" ) {
546 unlink <$clientdir/lockdir/*>;
548 mkdir("$clientdir/lockdir", 0777);
551 if ( -d
"$clientdir/statedir" ) {
552 unlink <$clientdir/statedir/*>;
554 mkdir("$clientdir/statedir", 0777);
557 if ( -d
"$clientdir/cachedir" ) {
558 unlink <$clientdir/cachedir/*>;
560 mkdir("$clientdir/cachedir", 0777);
563 # this is ugly, but the ncalrpcdir needs exactly 0755
564 # otherwise tests fail.
567 if ( -d
"$clientdir/ncalrpcdir/np" ) {
568 unlink <$clientdir/ncalrpcdir/np
/*>;
569 rmdir "$clientdir/ncalrpcdir/np";
571 if ( -d
"$clientdir/ncalrpcdir" ) {
572 unlink <$clientdir/ncalrpcdir/*>;
573 rmdir "$clientdir/ncalrpcdir";
575 mkdir("$clientdir/ncalrpcdir", 0755);
578 my $cadir = "$ENV{SRCDIR_ABS}/selftest/manage-ca/CA-samba.example.com";
579 my $cacert = "$cadir/Public/CA-samba.example.com-cert.pem";
580 my $cacrl_pem = "$cadir/Public/CA-samba.example.com-crl.pem";
581 my $ca_users_dir = "$cadir/Users";
583 if ( -d
"$clientdir/pkinit" ) {
584 unlink <$clientdir/pkinit/*>;
586 mkdir("$clientdir/pkinit", 0700);
589 # each user has a USER-${USER_PRINCIPAL_NAME}-cert.pem and
590 # USER-${USER_PRINCIPAL_NAME}-private-key.pem symlink
591 # We make a copy here and make the certificated easily
592 # accessable in the client environment.
595 opendir USERS
, "${ca_users_dir}" or die "Could not open dir '${ca_users_dir}': $!";
596 for my $d (readdir USERS
) {
597 my $user_dir = "${ca_users_dir}/${d}";
598 next if ${d
} =~ /^\./;
599 next if (! -d
"${user_dir}");
600 opendir USER
, "${user_dir}" or die "Could not open dir '${user_dir}': $!";
601 for my $l (readdir USER
) {
602 my $user_link = "${user_dir}/${l}";
603 next if ${l
} =~ /^\./;
604 next if (! -l
"${user_link}");
606 my $dest = "${clientdir}/pkinit/${l}";
607 Samba
::copy_file_content
(${user_link
}, ${dest
});
614 open(CF
, ">$conffile");
615 print CF
"[global]\n";
616 print CF
"\tnetbios name = client\n";
617 if (defined($vars->{DOMAIN
})) {
618 print CF
"\tworkgroup = $vars->{DOMAIN}\n";
620 if (defined($vars->{REALM
})) {
621 print CF
"\trealm = $vars->{REALM}\n";
623 if ($opt_socket_wrapper) {
624 print CF
"\tinterfaces = $interfaces\n";
627 private dir = $clientdir/private
628 binddns dir = $clientdir/bind-dns
629 lock dir = $clientdir/lockdir
630 state directory = $clientdir/statedir
631 cache directory = $clientdir/cachedir
632 ncalrpc dir = $clientdir/ncalrpcdir
633 panic action = $RealBin/gdb_backtrace \%d
635 notify:inotify = false
637 system:anonymous = true
638 client lanman auth = Yes
640 torture:basedir = $clientdir
641 #We don't want to pass our self-tests if the PAC code is wrong
642 gensec:require_pac = true
643 #We don't want to run 'speed' tests for very long
644 torture:timelimit = 1
645 winbind separator = /
646 tls cafile = ${cacert}
647 tls crlfile = ${cacrl_pem}
648 tls verify peer = no_check
649 include system krb5 conf = no
656 sub should_run_test
($)
662 for (my $i=0; $i <= $#tests; $i++) {
663 if ($name =~ /$tests[$i]/i) {
675 open(IN
, $filename) or die("Unable to open $filename: $!");
678 if (/-- TEST(-LOADLIST|) --\n/) {
679 my $supports_loadlist = (defined($1) and $1 eq "-LOADLIST");
685 if ($supports_loadlist) {
687 $loadlist =~ s/\n//g;
691 if (should_run_test
($name) == 1) {
692 push (@ret, [$name, $env, $cmdline, $loadlist]);
698 close(IN
) or die("Error creating recipe from $filename");
702 if ($#testlists == -1) {
703 die("No testlists specified");
706 $ENV{SELFTEST_PREFIX
} = "$prefix_abs";
707 $ENV{SELFTEST_TMPDIR
} = "$tmpdir_abs";
708 $ENV{TMPDIR
} = "$tmpdir_abs";
709 $ENV{TEST_DATA_PREFIX
} = "$tmpdir_abs";
711 $ENV{SELFTEST_QUICK
} = "1";
713 $ENV{SELFTEST_QUICK
} = "";
715 $ENV{SELFTEST_MAXTIME
} = $torture_maxtime;
717 my $selftest_krbt_ccache_path = "$tmpdir_abs/selftest.krb5_ccache";
718 $ENV{KRB5CCNAME
} = "FILE:${selftest_krbt_ccache_path}.global";
721 foreach my $fn (@testlists) {
722 foreach (read_testlist
($fn)) {
724 next if (@includes and not defined(find_in_list
(\
@includes, $name)));
725 push (@available, $_);
729 my $restricted = undef;
730 my $restricted_used = {};
732 if ($opt_load_list) {
734 open(LOAD_LIST
, "<$opt_load_list") or die("Unable to open $opt_load_list");
735 while (<LOAD_LIST
>) {
737 push (@
$restricted, $_);
742 my $individual_tests = undef;
743 $individual_tests = {};
745 foreach my $testsuite (@available) {
746 my $name = $$testsuite[0];
747 my $skipreason = skip
(@
$testsuite);
748 if (defined($restricted)) {
749 # Find the testsuite for this test
751 foreach my $r (@
$restricted) {
753 $individual_tests->{$name} = [];
755 $restricted_used->{$r} = 1;
756 } elsif (substr($r, 0, length($name)+1) eq "$name.") {
757 push(@
{$individual_tests->{$name}}, $r);
759 $restricted_used->{$r} = 1;
763 if (defined($skipreason)) {
765 Subunit
::skip_testsuite
($name, $skipreason);
768 push(@todo, $testsuite);
771 } elsif (defined($skipreason)) {
773 Subunit
::skip_testsuite
($name, $skipreason);
776 push(@todo, $testsuite);
780 if (defined($restricted)) {
781 foreach (@
$restricted) {
782 unless (defined($restricted_used->{$_})) {
783 print "No test or testsuite found matching $_\n";
786 } elsif ($#todo == -1) {
787 print STDERR
"No tests to run\n";
791 my $suitestotal = $#todo + 1;
794 Subunit
::progress
($suitestotal);
795 Subunit
::report_time
();
801 my %running_envs = ();
803 sub get_running_env
($)
811 return $running_envs{$envname};
818 $SIG{INT
} = $SIG{QUIT
} = $SIG{TERM
} = 'DEFAULT';
819 $SIG{PIPE
} = 'IGNORE';
821 open(STDOUT
, ">&STDERR") or die "can't dup STDOUT to STDERR: $!";
823 print "$0: PID[$$]: Got SIG${signame} teardown environments.\n";
824 teardown_env
($_) foreach(keys %running_envs);
825 system("pstree -p $$");
826 print "$0: PID[$$]: Exiting...\n";
830 $SIG{INT
} = $SIG{QUIT
} = $SIG{TERM
} = $SIG{PIPE
} = \
&sighandler
;
834 my ($name, $prefix) = @_;
836 my $testenv_vars = undef;
842 $option =~ s/^[^:]*//;
845 $option = "client" if $option eq "";
847 # Initially clear out the environment for the provision, so previous envs'
848 # variables don't leak in. Provisioning steps must explicitly set their
849 # necessary variables when calling out to other executables
850 Samba
::clear_exported_envvars
();
851 delete $ENV{SOCKET_WRAPPER_DEFAULT_IFACE
};
852 delete $ENV{SMB_CONF_PATH
};
854 $ENV{KRB5CCNAME
} = "FILE:${selftest_krbt_ccache_path}.${envname}/ignore";
856 if (defined(get_running_env
($envname))) {
857 $testenv_vars = get_running_env
($envname);
858 if (not $testenv_vars->{target
}->check_env($testenv_vars)) {
859 print $testenv_vars->{target
}->getlog_env($testenv_vars);
860 $testenv_vars = undef;
863 $testenv_vars = $target->setup_env($envname, $prefix);
864 if (defined($testenv_vars) and $testenv_vars eq "UNKNOWN") {
865 return $testenv_vars;
866 } elsif (defined($testenv_vars) && not defined($testenv_vars->{target
})) {
867 $testenv_vars->{target
} = $target;
869 if (not defined($testenv_vars)) {
871 die("$opt_target can't start up known environment '$envname'");
873 warn("$opt_target can't start up known environment '$envname'");
878 return undef unless defined($testenv_vars);
880 $running_envs{$envname} = $testenv_vars;
882 if ($option eq "local") {
883 SocketWrapper
::set_default_iface
($testenv_vars->{SOCKET_WRAPPER_DEFAULT_IFACE
});
884 $ENV{SMB_CONF_PATH
} = $testenv_vars->{SERVERCONFFILE
};
885 } elsif ($option eq "client") {
886 SocketWrapper
::set_default_iface
(11);
887 write_clientconf
($conffile, $clientdir, $testenv_vars);
888 $ENV{SMB_CONF_PATH
} = $conffile;
890 die("Unknown option[$option] for envname[$envname]");
893 # export the environment variables for the testenv (SERVER, SERVER_IP, etc)
894 Samba
::export_envvars
($testenv_vars);
896 my $krb5_ccache_path = "${selftest_krbt_ccache_path}.${envname}.${option}";
897 unlink($krb5_ccache_path);
898 $ENV{KRB5CCNAME
} = "FILE:${krb5_ccache_path}";
899 return $testenv_vars;
905 return "" if ($envname eq "none");
906 my $env = get_running_env
($envname);
907 return $env->{target
}->getlog_env($env);
913 my $env = get_running_env
($envname);
914 return $env->{target
}->check_env($env);
920 return if ($envname eq "none");
921 print STDERR
"teardown_env($envname)\n";
922 my $env = get_running_env
($envname);
923 $env->{target
}->teardown_env($env);
924 delete $running_envs{$envname};
927 # This 'global' file needs to be empty when we start
928 unlink("$prefix_abs/dns_host_file");
929 unlink("$prefix_abs/hosts");
931 if ($opt_random_order) {
933 my @newtodo = List
::Util
::shuffle
(@todo);
938 my $testenv_name = $ENV{SELFTEST_TESTENV
};
939 $testenv_name = $testenv_default unless defined($testenv_name);
941 my $testenv_vars = setup_env
($testenv_name, $prefix);
943 if (not $testenv_vars or $testenv_vars eq "UNKNOWN") {
944 die("Unable to setup environment $testenv_name");
947 $ENV{PIDDIR
} = $testenv_vars->{PIDDIR
};
948 $ENV{ENVNAME
} = $testenv_name;
950 my $envvarstr = Samba
::exported_envvars_str
($testenv_vars);
952 my @term_args = ("echo -e \"
953 Welcome to the Samba4 Test environment '$testenv_name'
955 This matches the client environment used in make test
956 server is pid `cat \$PIDDIR/samba.pid`
958 Some useful environment variables:
959 TORTURE_OPTIONS=\$TORTURE_OPTIONS
960 SMB_CONF_PATH=\$SMB_CONF_PATH
963 \" && LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH} bash");
965 if ($ENV{TERMINAL
}) {
966 @term = ($ENV{TERMINAL
});
968 @term = ("xterm", "-e");
969 unshift(@term_args, ("bash", "-c"));
972 system(@term, @term_args);
974 teardown_env
($testenv_name);
975 } elsif ($opt_list) {
978 my $envname = $$_[1];
980 my $listcmd = $$_[3];
982 unless (defined($listcmd)) {
983 warn("Unable to list tests in $name");
984 # Rather than ignoring this testsuite altogether, just pretend the entire testsuite is
993 die("Unable to run $listcmd: $!");
995 die(sprintf("%s died with signal %d, %s coredump\n", $listcmd, ($?
& 127), ($?
& 128) ?
'with' : 'without'));
998 my $exitcode = $?
>> 8;
999 if ($exitcode != 0) {
1000 die("$cmd exited with exit code $exitcode");
1008 my $envname = $$_[1];
1009 my $envvars = setup_env
($envname, $prefix);
1011 if (not defined($envvars)) {
1012 Subunit
::start_testsuite
($name);
1013 Subunit
::end_testsuite
($name, "error",
1014 "unable to set up environment $envname - exiting");
1016 } elsif ($envvars eq "UNKNOWN") {
1017 Subunit
::start_testsuite
($name);
1018 Subunit
::end_testsuite
($name, "error",
1019 "environment $envname is unknown - exiting");
1023 # Generate a file with the individual tests to run, if the
1024 # test runner for this test suite supports it.
1025 if ($individual_tests and $individual_tests->{$name}) {
1027 my ($fh, $listid_file) = tempfile
(UNLINK
=> 0);
1028 foreach my $test (@
{$individual_tests->{$name}}) {
1029 print $fh substr($test, length($name)+1) . "\n";
1031 $cmd =~ s/\$LOADLIST/--load-list=$listid_file/g;
1033 warn("Unable to run individual tests in $name, it does not support --loadlist.");
1037 run_testsuite
($envname, $name, $cmd, $i, $suitestotal);
1039 teardown_env
($envname) if ($opt_resetup_env);
1045 teardown_env
($_) foreach (keys %running_envs);
1049 # if there were any valgrind failures, show them
1050 foreach (<$prefix/valgrind
.log*>) {
1051 next unless (-s
$_);
1052 print "VALGRIND FAILURE\n";