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 = ();
56 my $opt_resetup_env = undef;
57 my $opt_load_list = undef;
58 my $opt_libnss_wrapper_so_path = "";
59 my $opt_libresolv_wrapper_so_path = "";
60 my $opt_libsocket_wrapper_so_path = "";
61 my $opt_libuid_wrapper_so_path = "";
62 my $opt_libasan_so_path = "";
63 my $opt_use_dns_faking = 0;
75 my ($list, $fullname) = @_;
78 if ($fullname =~ /$$_[0]/) {
79 return ($$_[1]) if ($$_[1]);
89 my ($name, $envname) = @_;
90 my ($env_basename, $env_localpart) = split(/:/, $envname);
92 if ($opt_target eq "samba3" && $Samba::ENV_NEEDS_AD_DC
{$env_basename}) {
93 return "environment $envname is disabled as this build does not include an AD DC";
96 if (@opt_include_env && !(grep {$_ eq $env_basename} @opt_include_env)) {
97 return "environment $envname is disabled (via --include-env command line option) in this test run - skipping";
98 } elsif (@opt_exclude_env && grep {$_ eq $env_basename} @opt_exclude_env) {
99 return "environment $envname is disabled (via --exclude-env command line option) in this test run - skipping";
102 return find_in_list
(\
@excludes, $name);
111 return unless ($opt_socket_wrapper_pcap);
112 return unless defined($ENV{SOCKET_WRAPPER_PCAP_DIR
});
115 $fname =~ s
%[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\
-]%_%g;
117 my $pcap_file = "$ENV{SOCKET_WRAPPER_PCAP_DIR}/$fname.pcap";
119 SocketWrapper
::setup_pcap
($pcap_file);
126 my ($pcap_file, $exitcode) = @_;
128 return unless ($opt_socket_wrapper_pcap);
129 return if ($opt_socket_wrapper_keep_pcap);
130 return unless ($exitcode == 0);
131 return unless defined($pcap_file);
136 # expand strings from %ENV
137 sub expand_environment_strings
($)
140 # we use a reverse sort so we do the longer ones first
141 foreach my $k (sort { $b cmp $a } keys %ENV) {
142 $s =~ s/\$$k/$ENV{$k}/g;
147 sub run_testsuite
($$$$$)
149 my ($envname, $name, $cmd, $i, $totalsuites) = @_;
150 my $pcap_file = setup_pcap
($name);
152 Subunit
::start_testsuite
($name);
153 Subunit
::progress_push
();
154 Subunit
::report_time
();
156 Subunit
::report_time
();
157 Subunit
::progress_pop
();
160 print "command: $cmd\n";
161 printf "expanded command: %s\n", expand_environment_strings
($cmd);
162 Subunit
::end_testsuite
($name, "error", "Unable to run $cmd: $!");
165 print "command: $cmd\n";
166 printf "expanded command: %s\n", expand_environment_strings
($cmd);
167 Subunit
::end_testsuite
($name, "error",
168 sprintf("%s died with signal %d, %s coredump\n", $cmd, ($?
& 127), ($?
& 128) ?
'with' : 'without'));
172 my $exitcode = $?
>> 8;
174 my $envlog = getlog_env
($envname);
176 print "envlog: $envlog\n";
179 print "command: $cmd\n";
180 printf "expanded command: %s\n", expand_environment_strings
($cmd);
182 if ($exitcode == 0) {
183 Subunit
::end_testsuite
($name, "success");
185 Subunit
::end_testsuite
($name, "failure", "Exit code was $exitcode");
188 cleanup_pcap
($pcap_file, $exitcode);
190 if (not $opt_socket_wrapper_keep_pcap and defined($pcap_file)) {
191 print "PCAP FILE: $pcap_file\n";
194 if ($exitcode != 0) {
195 exit(1) if ($opt_one);
203 print "Samba test runner
204 Copyright (C) Jelmer Vernooij <jelmer\@samba.org>
205 Copyright (C) Stefan Metzmacher <metze\@samba.org>
207 Usage: $Script [OPTIONS] TESTNAME-REGEX [TESTNAME-REGEX...]
210 --help this help page
211 --target=samba[3]|win Samba version to target
212 --testlist=FILE file to read available tests from
213 --exclude=FILE Exclude tests listed in the file
214 --include=FILE Include tests listed in the file
215 --exclude-env=ENV Exclude tests for the specified environment
216 --include-env=ENV Include tests for the specified environment
219 --prefix=DIR prefix to run tests in [st]
220 --srcdir=DIR source directory [.]
221 --bindir=DIR binaries directory [./bin]
224 --nss_wrapper_so_path=FILE the nss_wrapper library to preload
225 --resolv_wrapper_so_path=FILE the resolv_wrapper library to preload
226 --socket_wrapper_so_path=FILE the socket_wrapper library to preload
227 --uid_wrapper_so_path=FILE the uid_wrapper library to preload
228 --asan_so_path=FILE the asan library to preload
231 --use-dns-faking Fake DNS entries rather than talking to our
235 --socket-wrapper-pcap save traffic to pcap directories
236 --socket-wrapper-keep-pcap keep all pcap files, not just those for tests that
238 --socket-wrapper enable socket wrapper
241 --quick run quick overall test
242 --one abort when the first test fails
243 --testenv run a shell in the requested test environment
244 --list list available tests
249 my $result = GetOptions
(
250 'help|h|?' => \
$opt_help,
251 'target=s' => \
$opt_target,
252 'prefix=s' => \
$prefix,
253 'socket-wrapper' => \
$opt_socket_wrapper,
254 'socket-wrapper-pcap' => \
$opt_socket_wrapper_pcap,
255 'socket-wrapper-keep-pcap' => \
$opt_socket_wrapper_keep_pcap,
256 'quick' => \
$opt_quick,
258 'exclude=s' => \
@opt_exclude,
259 'include=s' => \
@opt_include,
260 'exclude-env=s' => \
@opt_exclude_env,
261 'include-env=s' => \
@opt_include_env,
262 'srcdir=s' => \
$srcdir,
263 'bindir=s' => \
$bindir,
264 'testenv' => \
$opt_testenv,
265 'list' => \
$opt_list,
266 'mitkrb5' => \
$opt_mitkrb5,
267 'resetup-environment' => \
$opt_resetup_env,
268 'testlist=s' => \
@testlists,
269 'random-order' => \
$opt_random_order,
270 'load-list=s' => \
$opt_load_list,
271 'nss_wrapper_so_path=s' => \
$opt_libnss_wrapper_so_path,
272 'resolv_wrapper_so_path=s' => \
$opt_libresolv_wrapper_so_path,
273 'socket_wrapper_so_path=s' => \
$opt_libsocket_wrapper_so_path,
274 'uid_wrapper_so_path=s' => \
$opt_libuid_wrapper_so_path,
275 'asan_so_path=s' => \
$opt_libasan_so_path,
276 'use-dns-faking' => \
$opt_use_dns_faking
279 exit(1) if (not $result);
281 ShowHelp
() if ($opt_help);
283 die("--list and --testenv are mutually exclusive") if ($opt_list and $opt_testenv);
285 # we want unbuffered output
290 # quick hack to disable rpc validation when using valgrind - its way too slow
291 unless (defined($ENV{VALGRIND
})) {
292 $ENV{VALIDATE
} = "validate";
293 $ENV{MALLOC_CHECK_
} = 3;
296 # make all our python scripts unbuffered
297 $ENV{PYTHONUNBUFFERED
} = 1;
299 # do not depend on the users setup
302 my $bindir_abs = abs_path
($bindir);
304 my $torture_maxtime = ($ENV{TORTURE_MAXTIME
} or 1200);
310 die("using an empty prefix isn't allowed") unless $prefix ne "";
312 # Ensure we have the test prefix around.
314 # We need restrictive
315 # permissions on this as some subdirectories in this tree will have
316 # wider permissions (ie 0777) and this would allow other users on the
317 # host to subvert the test process.
319 mkdir($prefix, 0700) unless -d
$prefix;
321 # We need to have no umask limitations for the tests.
324 my $prefix_abs = abs_path
($prefix);
325 my $tmpdir_abs = abs_path
("$prefix/tmp");
326 mkdir($tmpdir_abs, 0777) unless -d
$tmpdir_abs;
328 my $srcdir_abs = abs_path
($srcdir);
330 die("using an empty absolute prefix isn't allowed") unless $prefix_abs ne "";
331 die("using '/' as absolute prefix isn't allowed") unless $prefix_abs ne "/";
333 $ENV{SAMBA_SELFTEST
} = "1";
335 $ENV{PREFIX
} = $prefix;
336 $ENV{PREFIX_ABS
} = $prefix_abs;
337 $ENV{SRCDIR
} = $srcdir;
338 $ENV{SRCDIR_ABS
} = $srcdir_abs;
339 $ENV{GNUPGHOME
} = "$srcdir_abs/selftest/gnupg";
340 $ENV{BINDIR
} = $bindir_abs;
342 my $tls_enabled = not $opt_quick;
343 $ENV{TLS_ENABLED
} = ($tls_enabled?
"yes":"no");
345 sub prefix_pathvar
($$)
347 my ($name, $newpath) = @_;
348 if (defined($ENV{$name})) {
349 $ENV{$name} = "$newpath:$ENV{$name}";
351 $ENV{$name} = $newpath;
354 prefix_pathvar
("PKG_CONFIG_PATH", "$bindir_abs/pkgconfig");
355 prefix_pathvar
("PYTHONPATH", "$bindir_abs/python");
357 if ($opt_socket_wrapper_keep_pcap) {
358 # Socket wrapper keep pcap implies socket wrapper pcap
359 $opt_socket_wrapper_pcap = 1;
362 if ($opt_socket_wrapper_pcap) {
363 # Socket wrapper pcap implies socket wrapper
364 $opt_socket_wrapper = 1;
367 my $ld_preload = $ENV{LD_PRELOAD
};
369 if ($opt_libasan_so_path) {
371 $ld_preload = "$ld_preload:$opt_libasan_so_path";
373 $ld_preload = "$opt_libasan_so_path";
377 if ($opt_libnss_wrapper_so_path) {
379 $ld_preload = "$ld_preload:$opt_libnss_wrapper_so_path";
381 $ld_preload = "$opt_libnss_wrapper_so_path";
385 if ($opt_libresolv_wrapper_so_path) {
387 $ld_preload = "$ld_preload:$opt_libresolv_wrapper_so_path";
389 $ld_preload = "$opt_libresolv_wrapper_so_path";
393 if ($opt_libsocket_wrapper_so_path) {
395 $ld_preload = "$ld_preload:$opt_libsocket_wrapper_so_path";
397 $ld_preload = "$opt_libsocket_wrapper_so_path";
401 if ($opt_libuid_wrapper_so_path) {
403 $ld_preload = "$ld_preload:$opt_libuid_wrapper_so_path";
405 $ld_preload = "$opt_libuid_wrapper_so_path";
409 if (defined($ENV{USE_NAMESPACES
})) {
410 print "Using linux containerization for selftest testenv(s)...\n";
412 # Create a common bridge to connect up the testenv namespaces. We give
413 # it the client's IP address, as this is where the tests will run from
414 my $ipv4_addr = Samba
::get_ipv4_addr
("client");
415 my $ipv6_addr = Samba
::get_ipv6_addr
("client");
416 system "$ENV{SRCDIR_ABS}/selftest/ns/create_bridge.sh selftest0 $ipv4_addr $ipv6_addr";
419 $ENV{LD_PRELOAD
} = $ld_preload;
420 print "LD_PRELOAD=$ENV{LD_PRELOAD}\n";
422 # Enable uid_wrapper globally
423 $ENV{UID_WRAPPER
} = 1;
425 # We are already hitting the limit, so double it.
426 $ENV{NSS_WRAPPER_MAX_HOSTENTS
} = 200;
428 # Disable RTLD_DEEPBIND hack for Samba bind dlz module
430 # This is needed in order to allow the ldb_*ldap module
431 # to work with a preloaded socket wrapper.
432 $ENV{LDB_MODULES_DISABLE_DEEPBIND
} = 1;
434 my $socket_wrapper_dir;
435 if ($opt_socket_wrapper) {
436 $socket_wrapper_dir = SocketWrapper
::setup_dir
("$prefix_abs/w", $opt_socket_wrapper_pcap);
437 print "SOCKET_WRAPPER_DIR=$socket_wrapper_dir\n";
438 } elsif (not $opt_list) {
440 warn("not using socket wrapper, but also not running as root. Will not be able to listen on proper ports");
444 if ($opt_use_dns_faking) {
445 print "DNS: Faking nameserver\n";
446 $ENV{SAMBA_DNS_FAKING
} = 1;
450 my $testenv_default = "none";
452 if ($opt_mitkrb5 == 1) {
453 $ENV{MITKRB5
} = $opt_mitkrb5;
456 # After this many seconds, the server will self-terminate. All tests
457 # must terminate in this time, and testenv will only stay alive this
462 # 1 year should be enough :-)
463 $server_maxtime = 365 * 24 * 60 * 60;
465 # make test should run under 5 hours
466 $server_maxtime = 5 * 60 * 60;
469 if (defined($ENV{SMBD_MAXTIME
}) and $ENV{SMBD_MAXTIME
} ne "") {
470 $server_maxtime = $ENV{SMBD_MAXTIME
};
473 $target = new Samba
($bindir, $srcdir, $server_maxtime);
475 if ($opt_target eq "samba") {
476 $testenv_default = "ad_dc";
477 } elsif ($opt_target eq "samba3") {
478 $testenv_default = "nt4_member";
482 sub read_test_regexes
($)
486 open(LF
, "<$name") or die("unable to read $name: $!");
490 if (/^(.*?)([ \t]+)\#([\t ]*)(.*?)$/) {
491 push (@ret, [$1, $4]);
493 s/^(.*?)([ \t]+)\#([\t ]*)(.*?)$//;
494 push (@ret, [$_, undef]);
501 foreach (@opt_exclude) {
502 push (@excludes, read_test_regexes
($_));
505 foreach (@opt_include) {
506 push (@includes, read_test_regexes
($_));
509 # We give the selftest client 6 different IPv4 addresses to use. Most tests
510 # only use the first (.11) IP. Note that winsreplication.c is one test that
511 # uses the other IPs (search for iface_list_count()).
512 my $interfaces = Samba
::get_interfaces_config
("client", 6);
514 my $clientdir = "$prefix_abs/client";
516 my $conffile = "$clientdir/client.conf";
517 $ENV{SMB_CONF_PATH
} = $conffile;
519 sub write_clientconf
($$$)
521 my ($conffile, $clientdir, $vars) = @_;
523 mkdir("$clientdir", 0777) unless -d
"$clientdir";
525 if ( -d
"$clientdir/private" ) {
526 unlink <$clientdir/private/*>;
528 mkdir("$clientdir/private", 0777);
531 if ( -d
"$clientdir/bind-dns" ) {
532 unlink <$clientdir/bind-dns/*>;
534 mkdir("$clientdir/bind-dns", 0777);
537 if ( -d
"$clientdir/lockdir" ) {
538 unlink <$clientdir/lockdir/*>;
540 mkdir("$clientdir/lockdir", 0777);
543 if ( -d
"$clientdir/statedir" ) {
544 unlink <$clientdir/statedir/*>;
546 mkdir("$clientdir/statedir", 0777);
549 if ( -d
"$clientdir/cachedir" ) {
550 unlink <$clientdir/cachedir/*>;
552 mkdir("$clientdir/cachedir", 0777);
555 # this is ugly, but the ncalrpcdir needs exactly 0755
556 # otherwise tests fail.
559 if ( -d
"$clientdir/ncalrpcdir/np" ) {
560 unlink <$clientdir/ncalrpcdir/np
/*>;
561 rmdir "$clientdir/ncalrpcdir/np";
563 if ( -d
"$clientdir/ncalrpcdir" ) {
564 unlink <$clientdir/ncalrpcdir/*>;
565 rmdir "$clientdir/ncalrpcdir";
567 mkdir("$clientdir/ncalrpcdir", 0755);
570 my $cadir = "$ENV{SRCDIR_ABS}/selftest/manage-ca/CA-samba.example.com";
571 my $cacert = "$cadir/Public/CA-samba.example.com-cert.pem";
572 my $cacrl_pem = "$cadir/Public/CA-samba.example.com-crl.pem";
573 my $ca_users_dir = "$cadir/Users";
575 if ( -d
"$clientdir/pkinit" ) {
576 unlink <$clientdir/pkinit/*>;
578 mkdir("$clientdir/pkinit", 0700);
581 # each user has a USER-${USER_PRINCIPAL_NAME}-cert.pem and
582 # USER-${USER_PRINCIPAL_NAME}-private-key.pem symlink
583 # We make a copy here and make the certificated easily
584 # accessable in the client environment.
587 opendir USERS
, "${ca_users_dir}" or die "Could not open dir '${ca_users_dir}': $!";
588 for my $d (readdir USERS
) {
589 my $user_dir = "${ca_users_dir}/${d}";
590 next if ${d
} =~ /^\./;
591 next if (! -d
"${user_dir}");
592 opendir USER
, "${user_dir}" or die "Could not open dir '${user_dir}': $!";
593 for my $l (readdir USER
) {
594 my $user_link = "${user_dir}/${l}";
595 next if ${l
} =~ /^\./;
596 next if (! -l
"${user_link}");
598 my $dest = "${clientdir}/pkinit/${l}";
599 Samba
::copy_file_content
(${user_link
}, ${dest
});
606 open(CF
, ">$conffile");
607 print CF
"[global]\n";
608 print CF
"\tnetbios name = client\n";
609 if (defined($vars->{DOMAIN
})) {
610 print CF
"\tworkgroup = $vars->{DOMAIN}\n";
612 if (defined($vars->{REALM
})) {
613 print CF
"\trealm = $vars->{REALM}\n";
615 if ($opt_socket_wrapper) {
616 print CF
"\tinterfaces = $interfaces\n";
619 private dir = $clientdir/private
620 binddns dir = $clientdir/bind-dns
621 lock dir = $clientdir/lockdir
622 state directory = $clientdir/statedir
623 cache directory = $clientdir/cachedir
624 ncalrpc dir = $clientdir/ncalrpcdir
625 panic action = $RealBin/gdb_backtrace \%d
627 notify:inotify = false
629 system:anonymous = true
630 client lanman auth = Yes
631 client min protocol = CORE
633 torture:basedir = $clientdir
634 #We don't want to pass our self-tests if the PAC code is wrong
635 gensec:require_pac = true
636 #We don't want to run 'speed' tests for very long
637 torture:timelimit = 1
638 winbind separator = /
639 tls cafile = ${cacert}
640 tls crlfile = ${cacrl_pem}
641 tls verify peer = no_check
642 include system krb5 conf = no
643 elasticsearch:mappings = $srcdir_abs/source3/rpc_server/mdssvc/elasticsearch_mappings.json
650 sub should_run_test
($)
656 for (my $i=0; $i <= $#tests; $i++) {
657 if ($name =~ /$tests[$i]/i) {
669 open(IN
, $filename) or die("Unable to open $filename: $!");
672 if (/-- TEST(-LOADLIST|) --\n/) {
673 my $supports_loadlist = (defined($1) and $1 eq "-LOADLIST");
679 if ($supports_loadlist) {
681 $loadlist =~ s/\n//g;
685 if (should_run_test
($name) == 1) {
686 push (@ret, [$name, $env, $cmdline, $loadlist]);
692 close(IN
) or die("Error creating recipe from $filename");
696 if ($#testlists == -1) {
697 die("No testlists specified");
700 $ENV{SELFTEST_PREFIX
} = "$prefix_abs";
701 $ENV{SELFTEST_TMPDIR
} = "$tmpdir_abs";
702 $ENV{TMPDIR
} = "$tmpdir_abs";
703 $ENV{TEST_DATA_PREFIX
} = "$tmpdir_abs";
705 $ENV{SELFTEST_QUICK
} = "1";
707 $ENV{SELFTEST_QUICK
} = "";
709 $ENV{SELFTEST_MAXTIME
} = $torture_maxtime;
711 my $selftest_krbt_ccache_path = "$tmpdir_abs/selftest.krb5_ccache";
712 $ENV{KRB5CCNAME
} = "FILE:${selftest_krbt_ccache_path}.global";
715 foreach my $fn (@testlists) {
716 foreach (read_testlist
($fn)) {
718 next if (@includes and not defined(find_in_list
(\
@includes, $name)));
719 push (@available, $_);
723 my $restricted = undef;
724 my $restricted_used = {};
726 if ($opt_load_list) {
728 open(LOAD_LIST
, "<$opt_load_list") or die("Unable to open $opt_load_list");
729 while (<LOAD_LIST
>) {
731 push (@
$restricted, $_);
736 my $individual_tests = undef;
737 $individual_tests = {};
739 foreach my $testsuite (@available) {
740 my $name = $$testsuite[0];
741 my $skipreason = skip
(@
$testsuite);
742 if (defined($restricted)) {
743 # Find the testsuite for this test
745 foreach my $r (@
$restricted) {
747 $individual_tests->{$name} = [];
749 $restricted_used->{$r} = 1;
750 } elsif (substr($r, 0, length($name)+1) eq "$name.") {
751 push(@
{$individual_tests->{$name}}, $r);
753 $restricted_used->{$r} = 1;
757 if (defined($skipreason)) {
759 Subunit
::skip_testsuite
($name, $skipreason);
762 push(@todo, $testsuite);
765 } elsif (defined($skipreason)) {
767 Subunit
::skip_testsuite
($name, $skipreason);
770 push(@todo, $testsuite);
774 if (defined($restricted)) {
775 foreach (@
$restricted) {
776 unless (defined($restricted_used->{$_})) {
777 print "No test or testsuite found matching $_\n";
780 } elsif ($#todo == -1) {
781 print STDERR
"No tests to run\n";
785 my $suitestotal = $#todo + 1;
788 Subunit
::progress
($suitestotal);
789 Subunit
::report_time
();
795 my %running_envs = ();
797 sub get_running_env
($)
805 return $running_envs{$envname};
812 $SIG{INT
} = $SIG{QUIT
} = $SIG{TERM
} = 'DEFAULT';
813 $SIG{PIPE
} = 'IGNORE';
815 open(STDOUT
, ">&STDERR") or die "can't dup STDOUT to STDERR: $!";
817 print "$0: PID[$$]: Got SIG${signame} teardown environments.\n";
818 teardown_env
($_) foreach(keys %running_envs);
819 system("pstree -p $$");
820 print "$0: PID[$$]: Exiting...\n";
824 $SIG{INT
} = $SIG{QUIT
} = $SIG{TERM
} = $SIG{PIPE
} = \
&sighandler
;
828 my ($name, $prefix) = @_;
830 my $testenv_vars = undef;
836 $option =~ s/^[^:]*//;
839 $option = "client" if $option eq "";
841 # Initially clear out the environment for the provision, so previous envs'
842 # variables don't leak in. Provisioning steps must explicitly set their
843 # necessary variables when calling out to other executables
844 Samba
::clear_exported_envvars
();
845 delete $ENV{SOCKET_WRAPPER_DEFAULT_IFACE
};
846 delete $ENV{SMB_CONF_PATH
};
848 $ENV{KRB5CCNAME
} = "FILE:${selftest_krbt_ccache_path}.${envname}/ignore";
850 if (defined(get_running_env
($envname))) {
851 $testenv_vars = get_running_env
($envname);
852 if (not $testenv_vars->{target
}->check_env($testenv_vars)) {
853 print $testenv_vars->{target
}->getlog_env($testenv_vars);
854 $testenv_vars = undef;
857 $testenv_vars = $target->setup_env($envname, $prefix);
858 if (defined($testenv_vars) and $testenv_vars eq "UNKNOWN") {
859 return $testenv_vars;
860 } elsif (defined($testenv_vars) && not defined($testenv_vars->{target
})) {
861 $testenv_vars->{target
} = $target;
863 if (not defined($testenv_vars)) {
865 die("$opt_target can't start up known environment '$envname'");
867 warn("$opt_target can't start up known environment '$envname'");
872 return undef unless defined($testenv_vars);
874 $running_envs{$envname} = $testenv_vars;
876 if ($option eq "local") {
877 SocketWrapper
::set_default_iface
($testenv_vars->{SOCKET_WRAPPER_DEFAULT_IFACE
});
878 $ENV{SMB_CONF_PATH
} = $testenv_vars->{SERVERCONFFILE
};
879 } elsif ($option eq "client") {
880 SocketWrapper
::set_default_iface
(11);
881 write_clientconf
($conffile, $clientdir, $testenv_vars);
882 $ENV{SMB_CONF_PATH
} = $conffile;
884 die("Unknown option[$option] for envname[$envname]");
887 # export the environment variables for the testenv (SERVER, SERVER_IP, etc)
888 Samba
::export_envvars
($testenv_vars);
890 my $krb5_ccache_path = "${selftest_krbt_ccache_path}.${envname}.${option}";
891 unlink($krb5_ccache_path);
892 $ENV{KRB5CCNAME
} = "FILE:${krb5_ccache_path}";
893 return $testenv_vars;
899 return "" if ($envname eq "none");
900 my $env = get_running_env
($envname);
901 return $env->{target
}->getlog_env($env);
907 my $env = get_running_env
($envname);
908 return $env->{target
}->check_env($env);
914 return if ($envname eq "none");
915 print STDERR
"teardown_env($envname)\n";
916 my $env = get_running_env
($envname);
917 $env->{target
}->teardown_env($env);
918 delete $running_envs{$envname};
921 # This 'global' file needs to be empty when we start
922 unlink("$prefix_abs/dns_host_file");
923 unlink("$prefix_abs/hosts");
925 if ($opt_random_order) {
927 my @newtodo = List
::Util
::shuffle
(@todo);
932 my $testenv_name = $ENV{SELFTEST_TESTENV
};
933 $testenv_name = $testenv_default unless defined($testenv_name);
935 my $testenv_vars = setup_env
($testenv_name, $prefix);
937 if (not $testenv_vars or $testenv_vars eq "UNKNOWN") {
938 die("Unable to setup environment $testenv_name");
941 $ENV{PIDDIR
} = $testenv_vars->{PIDDIR
};
942 $ENV{ENVNAME
} = $testenv_name;
944 my $envvarstr = Samba
::exported_envvars_str
($testenv_vars);
946 my @term_args = ("echo -e \"
947 Welcome to the Samba4 Test environment '$testenv_name'
949 This matches the client environment used in make test
950 server is pid `cat \$PIDDIR/samba.pid`
952 Some useful environment variables:
953 TORTURE_OPTIONS=\$TORTURE_OPTIONS
954 SMB_CONF_PATH=\$SMB_CONF_PATH
957 \" && LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH} bash");
959 if ($ENV{TERMINAL
}) {
960 @term = ($ENV{TERMINAL
});
961 # override the default terminal args (if specified)
962 if (defined($ENV{TERMINAL_ARGS
})) {
963 @term_args = split(/ /, $ENV{TERMINAL_ARGS
});
966 @term = ("xterm", "-e");
967 unshift(@term_args, ("bash", "-c"));
970 system(@term, @term_args);
972 teardown_env
($testenv_name);
973 } elsif ($opt_list) {
976 my $envname = $$_[1];
978 my $listcmd = $$_[3];
980 unless (defined($listcmd)) {
981 warn("Unable to list tests in $name");
982 # Rather than ignoring this testsuite altogether, just pretend the entire testsuite is
991 die("Unable to run $listcmd: $!");
993 die(sprintf("%s died with signal %d, %s coredump\n", $listcmd, ($?
& 127), ($?
& 128) ?
'with' : 'without'));
996 my $exitcode = $?
>> 8;
997 if ($exitcode != 0) {
998 die("$cmd exited with exit code $exitcode");
1006 my $envname = $$_[1];
1007 my $envvars = setup_env
($envname, $prefix);
1009 if (not defined($envvars)) {
1010 Subunit
::start_testsuite
($name);
1011 Subunit
::end_testsuite
($name, "error",
1012 "unable to set up environment $envname - exiting");
1014 } elsif ($envvars eq "UNKNOWN") {
1015 Subunit
::start_testsuite
($name);
1016 Subunit
::end_testsuite
($name, "error",
1017 "environment $envname is unknown - exiting");
1021 # Generate a file with the individual tests to run, if the
1022 # test runner for this test suite supports it.
1023 if ($individual_tests and $individual_tests->{$name}) {
1025 my ($fh, $listid_file) = tempfile
(UNLINK
=> 0);
1026 foreach my $test (@
{$individual_tests->{$name}}) {
1027 print $fh substr($test, length($name)+1) . "\n";
1029 $cmd =~ s/\$LOADLIST/--load-list=$listid_file/g;
1031 warn("Unable to run individual tests in $name, it does not support --loadlist.");
1035 run_testsuite
($envname, $name, $cmd, $i, $suitestotal);
1037 teardown_env
($envname) if ($opt_resetup_env);
1043 teardown_env
($_) foreach (keys %running_envs);
1047 # if there were any valgrind failures, show them
1048 foreach (<$prefix/valgrind
.log*>) {
1049 next unless (-s
$_);
1050 print "VALGRIND FAILURE\n";