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);
34 Time
::HiRes
->import("time");
37 print "You don't have Time::Hires installed !\n";
41 my $opt_target = "samba";
43 my $opt_socket_wrapper = 0;
44 my $opt_socket_wrapper_pcap = undef;
45 my $opt_socket_wrapper_keep_pcap = undef;
46 my $opt_random_order = 0;
50 my @opt_exclude_env = ();
51 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_use_dns_faking = 0;
74 my ($list, $fullname) = @_;
77 if ($fullname =~ /$$_[0]/) {
78 return ($$_[1]) if ($$_[1]);
90 return find_in_list
(\
@excludes, $name);
99 return unless ($opt_socket_wrapper_pcap);
100 return unless defined($ENV{SOCKET_WRAPPER_PCAP_DIR
});
103 $fname =~ s
%[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\
-]%_%g;
105 my $pcap_file = "$ENV{SOCKET_WRAPPER_PCAP_DIR}/$fname.pcap";
107 SocketWrapper
::setup_pcap
($pcap_file);
114 my ($pcap_file, $exitcode) = @_;
116 return unless ($opt_socket_wrapper_pcap);
117 return if ($opt_socket_wrapper_keep_pcap);
118 return unless ($exitcode == 0);
119 return unless defined($pcap_file);
124 # expand strings from %ENV
125 sub expand_environment_strings
($)
128 # we use a reverse sort so we do the longer ones first
129 foreach my $k (sort { $b cmp $a } keys %ENV) {
130 $s =~ s/\$$k/$ENV{$k}/g;
135 sub run_testsuite
($$$$$)
137 my ($envname, $name, $cmd, $i, $totalsuites) = @_;
138 my $pcap_file = setup_pcap
($name);
140 Subunit
::start_testsuite
($name);
141 Subunit
::progress_push
();
142 Subunit
::report_time
(time());
144 Subunit
::report_time
(time());
145 Subunit
::progress_pop
();
148 print "command: $cmd\n";
149 printf "expanded command: %s\n", expand_environment_strings
($cmd);
150 Subunit
::end_testsuite
($name, "error", "Unable to run $cmd: $!");
153 print "command: $cmd\n";
154 printf "expanded command: %s\n", expand_environment_strings
($cmd);
155 Subunit
::end_testsuite
($name, "error",
156 sprintf("%s died with signal %d, %s coredump\n", $cmd, ($?
& 127), ($?
& 128) ?
'with' : 'without'));
160 my $exitcode = $?
>> 8;
162 my $envlog = getlog_env
($envname);
164 print "envlog: $envlog\n";
167 print "command: $cmd\n";
168 printf "expanded command: %s\n", expand_environment_strings
($cmd);
170 if ($exitcode == 0) {
171 Subunit
::end_testsuite
($name, "success");
173 Subunit
::end_testsuite
($name, "failure", "Exit code was $exitcode");
176 cleanup_pcap
($pcap_file, $exitcode);
178 if (not $opt_socket_wrapper_keep_pcap and defined($pcap_file)) {
179 print "PCAP FILE: $pcap_file\n";
182 if ($exitcode != 0) {
183 exit(1) if ($opt_one);
191 print "Samba test runner
192 Copyright (C) Jelmer Vernooij <jelmer\@samba.org>
193 Copyright (C) Stefan Metzmacher <metze\@samba.org>
195 Usage: $Script [OPTIONS] TESTNAME-REGEX [TESTNAME-REGEX...]
198 --help this help page
199 --target=samba[3]|win Samba version to target
200 --testlist=FILE file to read available tests from
201 --exclude=FILE Exclude tests listed in the file
202 --include=FILE Include tests listed in the file
203 --exclude-env=ENV Exclude tests for the specified environment
204 --include-env=ENV Include tests for the specified environment
207 --prefix=DIR prefix to run tests in [st]
208 --srcdir=DIR source directory [.]
209 --bindir=DIR binaries directory [./bin]
212 --nss_wrapper_so_path=FILE the nss_wrapper library to preload
213 --resolv_wrapper_so_path=FILE the resolv_wrapper library to preload
214 --socket_wrapper_so_path=FILE the socket_wrapper library to preload
215 --uid_wrapper_so_path=FILE the uid_wrapper library to preload
218 --use-dns-faking Fake DNS entries rather than talking to our
222 --socket-wrapper-pcap save traffic to pcap directories
223 --socket-wrapper-keep-pcap keep all pcap files, not just those for tests that
225 --socket-wrapper enable socket wrapper
228 --ldap=openldap|fedora-ds back samba onto specified ldap server
231 --quick run quick overall test
232 --one abort when the first test fails
233 --testenv run a shell in the requested test environment
234 --list list available tests
239 my $result = GetOptions
(
240 'help|h|?' => \
$opt_help,
241 'target=s' => \
$opt_target,
242 'prefix=s' => \
$prefix,
243 'socket-wrapper' => \
$opt_socket_wrapper,
244 'socket-wrapper-pcap' => \
$opt_socket_wrapper_pcap,
245 'socket-wrapper-keep-pcap' => \
$opt_socket_wrapper_keep_pcap,
246 'quick' => \
$opt_quick,
248 'exclude=s' => \
@opt_exclude,
249 'include=s' => \
@opt_include,
250 'exclude-env=s' => \
@opt_exclude_env,
251 'include-env=s' => \
@opt_include_env,
252 'srcdir=s' => \
$srcdir,
253 'bindir=s' => \
$bindir,
254 'testenv' => \
$opt_testenv,
255 'list' => \
$opt_list,
256 'mitkrb5' => \
$opt_mitkrb5,
258 'resetup-environment' => \
$opt_resetup_env,
259 'testlist=s' => \
@testlists,
260 'random-order' => \
$opt_random_order,
261 'load-list=s' => \
$opt_load_list,
262 'nss_wrapper_so_path=s' => \
$opt_libnss_wrapper_so_path,
263 'resolv_wrapper_so_path=s' => \
$opt_libresolv_wrapper_so_path,
264 'socket_wrapper_so_path=s' => \
$opt_libsocket_wrapper_so_path,
265 'uid_wrapper_so_path=s' => \
$opt_libuid_wrapper_so_path,
266 'use-dns-faking' => \
$opt_use_dns_faking
269 exit(1) if (not $result);
271 ShowHelp
() if ($opt_help);
273 die("--list and --testenv are mutually exclusive") if ($opt_list and $opt_testenv);
275 # we want unbuffered output
280 # quick hack to disable rpc validation when using valgrind - its way too slow
281 unless (defined($ENV{VALGRIND
})) {
282 $ENV{VALIDATE
} = "validate";
283 $ENV{MALLOC_CHECK_
} = 3;
286 # make all our python scripts unbuffered
287 $ENV{PYTHONUNBUFFERED
} = 1;
289 my $bindir_abs = abs_path
($bindir);
291 # Backwards compatibility:
292 if (defined($ENV{TEST_LDAP
}) and $ENV{TEST_LDAP
} eq "yes") {
293 if (defined($ENV{FEDORA_DS_ROOT
})) {
300 my $torture_maxtime = ($ENV{TORTURE_MAXTIME
} or 1200);
303 $torture_maxtime *= 2;
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_libnss_wrapper_so_path) {
371 $ld_preload = "$ld_preload:$opt_libnss_wrapper_so_path";
373 $ld_preload = "$opt_libnss_wrapper_so_path";
377 if ($opt_libresolv_wrapper_so_path) {
379 $ld_preload = "$ld_preload:$opt_libresolv_wrapper_so_path";
381 $ld_preload = "$opt_libresolv_wrapper_so_path";
385 if ($opt_libsocket_wrapper_so_path) {
387 $ld_preload = "$ld_preload:$opt_libsocket_wrapper_so_path";
389 $ld_preload = "$opt_libsocket_wrapper_so_path";
393 if ($opt_libuid_wrapper_so_path) {
395 $ld_preload = "$ld_preload:$opt_libuid_wrapper_so_path";
397 $ld_preload = "$opt_libuid_wrapper_so_path";
401 $ENV{LD_PRELOAD
} = $ld_preload;
402 print "LD_PRELOAD=$ENV{LD_PRELOAD}\n";
404 # Enable uid_wrapper globally
405 $ENV{UID_WRAPPER
} = 1;
407 # Disable RTLD_DEEPBIND hack for Samba bind dlz module
409 # This is needed in order to allow the ldb_*ldap module
410 # to work with a preloaded socket wrapper.
411 $ENV{LDB_MODULES_DISABLE_DEEPBIND
} = 1;
413 my $socket_wrapper_dir;
414 if ($opt_socket_wrapper) {
415 $socket_wrapper_dir = SocketWrapper
::setup_dir
("$prefix_abs/w", $opt_socket_wrapper_pcap);
416 print "SOCKET_WRAPPER_DIR=$socket_wrapper_dir\n";
417 } elsif (not $opt_list) {
419 warn("not using socket wrapper, but also not running as root. Will not be able to listen on proper ports");
423 if ($opt_use_dns_faking) {
424 print "DNS: Faking nameserver\n";
425 $ENV{SAMBA_DNS_FAKING
} = 1;
429 my $testenv_default = "none";
431 if ($opt_mitkrb5 == 1) {
432 $ENV{MITKRB5
} = $opt_mitkrb5;
435 # After this many seconds, the server will self-terminate. All tests
436 # must terminate in this time, and testenv will only stay alive this
441 # 1 year should be enough :-)
442 $server_maxtime = 365 * 24 * 60 * 60;
444 # make test should run under 4 hours
445 $server_maxtime = 4 * 60 * 60;
448 if (defined($ENV{SMBD_MAXTIME
}) and $ENV{SMBD_MAXTIME
} ne "") {
449 $server_maxtime = $ENV{SMBD_MAXTIME
};
453 if ($opt_target eq "samba") {
454 $testenv_default = "ad_dc";
455 require target
::Samba
;
456 $target = new Samba
($bindir, $ldap, $srcdir, $server_maxtime);
457 } elsif ($opt_target eq "samba3") {
458 $testenv_default = "nt4_member";
459 require target
::Samba3
;
460 $target = new Samba3
($bindir, $srcdir_abs, $server_maxtime);
464 sub read_test_regexes
($)
468 open(LF
, "<$name") or die("unable to read $name: $!");
472 if (/^(.*?)([ \t]+)\#([\t ]*)(.*?)$/) {
473 push (@ret, [$1, $4]);
475 s/^(.*?)([ \t]+)\#([\t ]*)(.*?)$//;
476 push (@ret, [$_, undef]);
483 foreach (@opt_exclude) {
484 push (@excludes, read_test_regexes
($_));
487 foreach (@opt_include) {
488 push (@includes, read_test_regexes
($_));
491 my $interfaces = join(',', ("127.0.0.11/8",
498 my $clientdir = "$prefix_abs/client";
500 my $conffile = "$clientdir/client.conf";
501 $ENV{SMB_CONF_PATH
} = $conffile;
503 sub write_clientconf
($$$)
505 my ($conffile, $clientdir, $vars) = @_;
507 mkdir("$clientdir", 0777) unless -d
"$clientdir";
509 if ( -d
"$clientdir/private" ) {
510 unlink <$clientdir/private/*>;
512 mkdir("$clientdir/private", 0777);
515 if ( -d
"$clientdir/lockdir" ) {
516 unlink <$clientdir/lockdir/*>;
518 mkdir("$clientdir/lockdir", 0777);
521 if ( -d
"$clientdir/statedir" ) {
522 unlink <$clientdir/statedir/*>;
524 mkdir("$clientdir/statedir", 0777);
527 if ( -d
"$clientdir/cachedir" ) {
528 unlink <$clientdir/cachedir/*>;
530 mkdir("$clientdir/cachedir", 0777);
533 # this is ugly, but the ncalrpcdir needs exactly 0755
534 # otherwise tests fail.
537 if ( -d
"$clientdir/ncalrpcdir/np" ) {
538 unlink <$clientdir/ncalrpcdir/np
/*>;
539 rmdir "$clientdir/ncalrpcdir/np";
541 if ( -d
"$clientdir/ncalrpcdir" ) {
542 unlink <$clientdir/ncalrpcdir/*>;
543 rmdir "$clientdir/ncalrpcdir";
545 mkdir("$clientdir/ncalrpcdir", 0755);
548 my $cadir = "$ENV{SRCDIR_ABS}/selftest/manage-ca/CA-samba.example.com";
549 my $cacert = "$cadir/Public/CA-samba.example.com-cert.pem";
550 my $cacrl_pem = "$cadir/Public/CA-samba.example.com-crl.pem";
551 my $ca_users_dir = "$cadir/Users";
553 if ( -d
"$clientdir/pkinit" ) {
554 unlink <$clientdir/pkinit/*>;
556 mkdir("$clientdir/pkinit", 0700);
559 # each user has a USER-${USER_PRINCIPAL_NAME}-cert.pem and
560 # USER-${USER_PRINCIPAL_NAME}-private-key.pem symlink
561 # We make a copy here and make the certificated easily
562 # accessable in the client environment.
565 opendir USERS
, "${ca_users_dir}" or die "Could not open dir '${ca_users_dir}': $!";
566 for my $d (readdir USERS
) {
567 my $user_dir = "${ca_users_dir}/${d}";
568 next if ${d
} =~ /^\./;
569 next if (! -d
"${user_dir}");
570 opendir USER
, "${user_dir}" or die "Could not open dir '${user_dir}': $!";
571 for my $l (readdir USER
) {
572 my $user_link = "${user_dir}/${l}";
573 next if ${l
} =~ /^\./;
574 next if (! -l
"${user_link}");
576 my $dest = "${clientdir}/pkinit/${l}";
577 Samba
::copy_file_content
(${user_link
}, ${dest
});
584 open(CF
, ">$conffile");
585 print CF
"[global]\n";
586 print CF
"\tnetbios name = client\n";
587 if (defined($vars->{DOMAIN
})) {
588 print CF
"\tworkgroup = $vars->{DOMAIN}\n";
590 if (defined($vars->{REALM
})) {
591 print CF
"\trealm = $vars->{REALM}\n";
593 if ($opt_socket_wrapper) {
594 print CF
"\tinterfaces = $interfaces\n";
597 private dir = $clientdir/private
598 lock dir = $clientdir/lockdir
599 state directory = $clientdir/statedir
600 cache directory = $clientdir/cachedir
601 ncalrpc dir = $clientdir/ncalrpcdir
602 panic action = $RealBin/gdb_backtrace \%d
604 notify:inotify = false
606 system:anonymous = true
607 client lanman auth = Yes
609 torture:basedir = $clientdir
610 #We don't want to pass our self-tests if the PAC code is wrong
611 gensec:require_pac = true
612 #We don't want to run 'speed' tests for very long
613 torture:timelimit = 1
614 winbind separator = /
615 tls cafile = ${cacert}
616 tls crlfile = ${cacrl_pem}
617 tls verify peer = no_check
618 include system krb5 conf = no
625 sub should_run_test
($)
631 for (my $i=0; $i <= $#tests; $i++) {
632 if ($name =~ /$tests[$i]/i) {
644 open(IN
, $filename) or die("Unable to open $filename: $!");
647 if (/-- TEST(-LOADLIST|) --\n/) {
648 my $supports_loadlist = (defined($1) and $1 eq "-LOADLIST");
654 if ($supports_loadlist) {
656 $loadlist =~ s/\n//g;
660 if (should_run_test
($name) == 1) {
661 push (@ret, [$name, $env, $cmdline, $loadlist]);
667 close(IN
) or die("Error creating recipe from $filename");
671 if ($#testlists == -1) {
672 die("No testlists specified");
675 $ENV{SELFTEST_PREFIX
} = "$prefix_abs";
676 $ENV{SELFTEST_TMPDIR
} = "$tmpdir_abs";
677 $ENV{TMPDIR
} = "$tmpdir_abs";
678 $ENV{TEST_DATA_PREFIX
} = "$tmpdir_abs";
679 if ($opt_socket_wrapper) {
680 $ENV{SELFTEST_INTERFACES
} = $interfaces;
682 $ENV{SELFTEST_INTERFACES
} = "";
685 $ENV{SELFTEST_QUICK
} = "1";
687 $ENV{SELFTEST_QUICK
} = "";
689 $ENV{SELFTEST_MAXTIME
} = $torture_maxtime;
691 my $selftest_krbt_ccache_path = "$tmpdir_abs/selftest.krb5_ccache";
692 $ENV{KRB5CCNAME
} = "FILE:${selftest_krbt_ccache_path}.global";
695 foreach my $fn (@testlists) {
696 foreach (read_testlist
($fn)) {
698 next if (@includes and not defined(find_in_list
(\
@includes, $name)));
699 push (@available, $_);
703 my $restricted = undef;
704 my $restricted_used = {};
706 if ($opt_load_list) {
708 open(LOAD_LIST
, "<$opt_load_list") or die("Unable to open $opt_load_list");
709 while (<LOAD_LIST
>) {
711 push (@
$restricted, $_);
716 my $individual_tests = undef;
717 $individual_tests = {};
719 foreach my $testsuite (@available) {
720 my $name = $$testsuite[0];
721 my $skipreason = skip
($name);
722 if (defined($restricted)) {
723 # Find the testsuite for this test
725 foreach my $r (@
$restricted) {
727 $individual_tests->{$name} = [];
729 $restricted_used->{$r} = 1;
730 } elsif (substr($r, 0, length($name)+1) eq "$name.") {
731 push(@
{$individual_tests->{$name}}, $r);
733 $restricted_used->{$r} = 1;
737 if (defined($skipreason)) {
739 Subunit
::skip_testsuite
($name, $skipreason);
742 push(@todo, $testsuite);
745 } elsif (defined($skipreason)) {
747 Subunit
::skip_testsuite
($name, $skipreason);
750 push(@todo, $testsuite);
754 if (defined($restricted)) {
755 foreach (@
$restricted) {
756 unless (defined($restricted_used->{$_})) {
757 print "No test or testsuite found matching $_\n";
760 } elsif ($#todo == -1) {
761 print STDERR
"No tests to run\n";
765 my $suitestotal = $#todo + 1;
768 Subunit
::progress
($suitestotal);
769 Subunit
::report_time
(time());
775 my %running_envs = ();
777 sub get_running_env
($)
785 return $running_envs{$envname};
788 my @exported_envvars = (
793 # stuff related to a trusted domain
803 # domain controller stuff
813 "MEMBER_SERVER_IPV6",
814 "MEMBER_NETBIOSNAME",
815 "MEMBER_NETBIOSALIAS",
817 # rpc proxy controller stuff
819 "RPC_PROXY_SERVER_IP",
820 "RPC_PROXY_SERVER_IPV6",
821 "RPC_PROXY_NETBIOSNAME",
822 "RPC_PROXY_NETBIOSALIAS",
824 # domain controller stuff for Vampired DC
826 "VAMPIRE_DC_SERVER_IP",
827 "VAMPIRE_DC_SERVER_IPV6",
828 "VAMPIRE_DC_NETBIOSNAME",
829 "VAMPIRE_DC_NETBIOSALIAS",
831 # domain controller stuff for FL 2000 Vampired DC
832 "VAMPIRE_2000_DC_SERVER",
833 "VAMPIRE_2000_DC_SERVER_IP",
834 "VAMPIRE_2000_DC_SERVER_IPV6",
835 "VAMPIRE_2000_DC_NETBIOSNAME",
836 "VAMPIRE_2000_DC_NETBIOSALIAS",
838 "PROMOTED_DC_SERVER",
839 "PROMOTED_DC_SERVER_IP",
840 "PROMOTED_DC_SERVER_IPV6",
841 "PROMOTED_DC_NETBIOSNAME",
842 "PROMOTED_DC_NETBIOSALIAS",
858 # UID/GID for rfc2307 mapping tests
865 "SELFTEST_WINBINDD_SOCKET_DIR",
871 "UNACCEPTABLE_PASSWORD",
875 "NSS_WRAPPER_PASSWD",
878 "NSS_WRAPPER_MODULE_SO_PATH",
879 "NSS_WRAPPER_MODULE_FN_PREFIX",
882 "RESOLV_WRAPPER_CONF",
883 "RESOLV_WRAPPER_HOSTS",
890 $SIG{INT
} = $SIG{QUIT
} = $SIG{TERM
} = 'DEFAULT';
891 $SIG{PIPE
} = 'IGNORE';
893 open(STDOUT
, ">&STDERR") or die "can't dup STDOUT to STDERR: $!";
895 print "$0: PID[$$]: Got SIG${signame} teardown environments.\n";
896 teardown_env
($_) foreach(keys %running_envs);
897 system("pstree -p $$");
898 print "$0: PID[$$]: Exiting...\n";
902 $SIG{INT
} = $SIG{QUIT
} = $SIG{TERM
} = $SIG{PIPE
} = \
&sighandler
;
906 my ($name, $prefix) = @_;
908 my $testenv_vars = undef;
914 $option =~ s/^[^:]*//;
917 $option = "client" if $option eq "";
919 $ENV{KRB5CCNAME
} = "FILE:${selftest_krbt_ccache_path}.${envname}/ignore";
921 if (defined(get_running_env
($envname))) {
922 $testenv_vars = get_running_env
($envname);
923 if (not $testenv_vars->{target
}->check_env($testenv_vars)) {
924 print $testenv_vars->{target
}->getlog_env($testenv_vars);
925 $testenv_vars = undef;
928 $testenv_vars = $target->setup_env($envname, $prefix);
929 if (defined($testenv_vars) and $testenv_vars eq "UNKNOWN") {
930 return $testenv_vars;
931 } elsif (defined($testenv_vars) && not defined($testenv_vars->{target
})) {
932 $testenv_vars->{target
} = $target;
934 if (not defined($testenv_vars)) {
935 warn("$opt_target can't start up known environment '$envname'");
939 return undef unless defined($testenv_vars);
941 $running_envs{$envname} = $testenv_vars;
943 if ($option eq "local") {
944 SocketWrapper
::set_default_iface
($testenv_vars->{SOCKET_WRAPPER_DEFAULT_IFACE
});
945 $ENV{SMB_CONF_PATH
} = $testenv_vars->{SERVERCONFFILE
};
946 } elsif ($option eq "client") {
947 SocketWrapper
::set_default_iface
(11);
948 write_clientconf
($conffile, $clientdir, $testenv_vars);
949 $ENV{SMB_CONF_PATH
} = $conffile;
951 die("Unknown option[$option] for envname[$envname]");
954 foreach (@exported_envvars) {
955 if (defined($testenv_vars->{$_})) {
956 $ENV{$_} = $testenv_vars->{$_};
962 my $krb5_ccache_path = "${selftest_krbt_ccache_path}.${envname}.${option}";
963 unlink($krb5_ccache_path);
964 $ENV{KRB5CCNAME
} = "FILE:${krb5_ccache_path}";
965 return $testenv_vars;
968 sub exported_envvars_str
($)
970 my ($testenv_vars) = @_;
973 foreach (@exported_envvars) {
974 next unless defined($testenv_vars->{$_});
975 $out .= $_."=".$testenv_vars->{$_}."\n";
984 return "" if ($envname eq "none");
985 my $env = get_running_env
($envname);
986 return $env->{target
}->getlog_env($env);
992 my $env = get_running_env
($envname);
993 return $env->{target
}->check_env($env);
999 return if ($envname eq "none");
1000 print STDERR
"teardown_env($envname)\n";
1001 my $env = get_running_env
($envname);
1002 $env->{target
}->teardown_env($env);
1003 delete $running_envs{$envname};
1006 # This 'global' file needs to be empty when we start
1007 unlink("$prefix_abs/dns_host_file");
1008 unlink("$prefix_abs/hosts");
1010 if ($opt_random_order) {
1012 my @newtodo = List
::Util
::shuffle
(@todo);
1017 my $testenv_name = $ENV{SELFTEST_TESTENV
};
1018 $testenv_name = $testenv_default unless defined($testenv_name);
1020 my $testenv_vars = setup_env
($testenv_name, $prefix);
1022 if (not $testenv_vars or $testenv_vars eq "UNKNOWN") {
1023 die("Unable to setup environment $testenv_name");
1026 $ENV{PIDDIR
} = $testenv_vars->{PIDDIR
};
1027 $ENV{ENVNAME
} = $testenv_name;
1029 my $envvarstr = exported_envvars_str
($testenv_vars);
1031 my @term_args = ("echo -e \"
1032 Welcome to the Samba4 Test environment '$testenv_name'
1034 This matches the client environment used in make test
1035 server is pid `cat \$PIDDIR/samba.pid`
1037 Some useful environment variables:
1038 TORTURE_OPTIONS=\$TORTURE_OPTIONS
1039 SMB_CONF_PATH=\$SMB_CONF_PATH
1042 \" && LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH} bash");
1044 if ($ENV{TERMINAL
}) {
1045 @term = ($ENV{TERMINAL
});
1047 @term = ("xterm", "-e");
1048 unshift(@term_args, ("bash", "-c"));
1051 system(@term, @term_args);
1053 teardown_env
($testenv_name);
1054 } elsif ($opt_list) {
1057 my $envname = $$_[1];
1059 my $listcmd = $$_[3];
1061 unless (defined($listcmd)) {
1062 warn("Unable to list tests in $name");
1063 # Rather than ignoring this testsuite altogether, just pretend the entire testsuite is
1072 die("Unable to run $listcmd: $!");
1073 } elsif ($?
& 127) {
1074 die(sprintf("%s died with signal %d, %s coredump\n", $listcmd, ($?
& 127), ($?
& 128) ?
'with' : 'without'));
1077 my $exitcode = $?
>> 8;
1078 if ($exitcode != 0) {
1079 die("$cmd exited with exit code $exitcode");
1087 my $envname = $$_[1];
1088 my ($env_basename, $env_localpart) = split(/:/, $envname);
1089 my $envvars = "SKIP";
1091 if (@opt_include_env) {
1092 foreach my $env (@opt_include_env) {
1093 if ($env_basename eq $env) {
1094 $envvars = setup_env
($envname, $prefix);
1097 } elsif (@opt_exclude_env) {
1099 foreach my $env (@opt_exclude_env) {
1100 if ($env_basename eq $env) {
1104 if ($excluded == 0) {
1105 $envvars = setup_env
($envname, $prefix);
1108 $envvars = setup_env
($envname, $prefix);
1111 if (not defined($envvars)) {
1112 Subunit
::start_testsuite
($name);
1113 Subunit
::end_testsuite
($name, "error",
1114 "unable to set up environment $envname - exiting");
1116 } elsif ($envvars eq "SKIP") {
1117 Subunit
::start_testsuite
($name);
1118 Subunit
::end_testsuite
($name, "skip",
1119 "environment $envname is disabled (via --exclude-env / --include-env command line options) in this test run - skipping");
1121 } elsif ($envvars eq "UNKNOWN") {
1122 Subunit
::start_testsuite
($name);
1123 Subunit
::end_testsuite
($name, "skip",
1124 "environment $envname is unknown in this test backend - skipping");
1128 # Generate a file with the individual tests to run, if the
1129 # test runner for this test suite supports it.
1130 if ($individual_tests and $individual_tests->{$name}) {
1132 my ($fh, $listid_file) = tempfile
(UNLINK
=> 0);
1133 foreach my $test (@
{$individual_tests->{$name}}) {
1134 print $fh substr($test, length($name)+1) . "\n";
1136 $cmd =~ s/\$LOADLIST/--load-list=$listid_file/g;
1138 warn("Unable to run individual tests in $name, it does not support --loadlist.");
1142 run_testsuite
($envname, $name, $cmd, $i, $suitestotal);
1144 teardown_env
($envname) if ($opt_resetup_env);
1150 teardown_env
($_) foreach (keys %running_envs);
1154 # if there were any valgrind failures, show them
1155 foreach (<$prefix/valgrind
.log*>) {
1156 next unless (-s
$_);
1157 print "VALGRIND FAILURE\n";