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;
53 my $opt_resetup_env = undef;
54 my $opt_load_list = undef;
55 my $opt_libnss_wrapper_so_path = "";
56 my $opt_libresolv_wrapper_so_path = "";
57 my $opt_libsocket_wrapper_so_path = "";
58 my $opt_libuid_wrapper_so_path = "";
59 my $opt_use_dns_faking = 0;
71 my ($list, $fullname) = @_;
74 if ($fullname =~ /$$_[0]/) {
75 return ($$_[1]) if ($$_[1]);
87 return find_in_list
(\
@excludes, $name);
96 return unless ($opt_socket_wrapper_pcap);
97 return unless defined($ENV{SOCKET_WRAPPER_PCAP_DIR
});
100 $fname =~ s
%[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\
-]%_%g;
102 my $pcap_file = "$ENV{SOCKET_WRAPPER_PCAP_DIR}/$fname.pcap";
104 SocketWrapper
::setup_pcap
($pcap_file);
111 my ($pcap_file, $exitcode) = @_;
113 return unless ($opt_socket_wrapper_pcap);
114 return if ($opt_socket_wrapper_keep_pcap);
115 return unless ($exitcode == 0);
116 return unless defined($pcap_file);
121 # expand strings from %ENV
122 sub expand_environment_strings
($)
125 # we use a reverse sort so we do the longer ones first
126 foreach my $k (sort { $b cmp $a } keys %ENV) {
127 $s =~ s/\$$k/$ENV{$k}/g;
132 sub run_testsuite
($$$$$)
134 my ($envname, $name, $cmd, $i, $totalsuites) = @_;
135 my $pcap_file = setup_pcap
($name);
137 Subunit
::start_testsuite
($name);
138 Subunit
::progress_push
();
139 Subunit
::report_time
(time());
141 Subunit
::report_time
(time());
142 Subunit
::progress_pop
();
145 Subunit
::progress_pop
();
146 Subunit
::end_testsuite
($name, "error", "Unable to run $cmd: $!");
149 Subunit
::end_testsuite
($name, "error",
150 sprintf("%s died with signal %d, %s coredump\n", $cmd, ($?
& 127), ($?
& 128) ?
'with' : 'without'));
154 my $exitcode = $?
>> 8;
156 my $envlog = getlog_env
($envname);
158 print "envlog: $envlog\n";
161 print "command: $cmd\n";
162 printf "expanded command: %s\n", expand_environment_strings
($cmd);
164 if ($exitcode == 0) {
165 Subunit
::end_testsuite
($name, "success");
167 Subunit
::end_testsuite
($name, "failure", "Exit code was $exitcode");
170 cleanup_pcap
($pcap_file, $exitcode);
172 if (not $opt_socket_wrapper_keep_pcap and defined($pcap_file)) {
173 print "PCAP FILE: $pcap_file\n";
176 if ($exitcode != 0) {
177 exit(1) if ($opt_one);
185 print "Samba test runner
186 Copyright (C) Jelmer Vernooij <jelmer\@samba.org>
187 Copyright (C) Stefan Metzmacher <metze\@samba.org>
189 Usage: $Script [OPTIONS] TESTNAME-REGEX
192 --help this help page
193 --target=samba[3]|win Samba version to target
194 --testlist=FILE file to read available tests from
195 --exclude=FILE Exclude tests listed in the file
196 --include=FILE Include tests listed in the file
199 --prefix=DIR prefix to run tests in [st]
200 --srcdir=DIR source directory [.]
201 --bindir=DIR binaries directory [./bin]
204 --nss_wrapper_so_path=FILE the nss_wrapper library to preload
205 --resolv_wrapper_so_path=FILE the resolv_wrapper library to preload
206 --socket_wrapper_so_path=FILE the socket_wrapper library to preload
207 --uid_wrapper_so_path=FILE the uid_wrapper library to preload
210 --use-dns-faking Fake DNS entries rather than talking to our
214 --socket-wrapper-pcap save traffic to pcap directories
215 --socket-wrapper-keep-pcap keep all pcap files, not just those for tests that
217 --socket-wrapper enable socket wrapper
220 --ldap=openldap|fedora-ds back samba onto specified ldap server
223 --quick run quick overall test
224 --one abort when the first test fails
225 --testenv run a shell in the requested test environment
226 --list list available tests
231 my $result = GetOptions
(
232 'help|h|?' => \
$opt_help,
233 'target=s' => \
$opt_target,
234 'prefix=s' => \
$prefix,
235 'socket-wrapper' => \
$opt_socket_wrapper,
236 'socket-wrapper-pcap' => \
$opt_socket_wrapper_pcap,
237 'socket-wrapper-keep-pcap' => \
$opt_socket_wrapper_keep_pcap,
238 'quick' => \
$opt_quick,
240 'exclude=s' => \
@opt_exclude,
241 'include=s' => \
@opt_include,
242 'srcdir=s' => \
$srcdir,
243 'bindir=s' => \
$bindir,
244 'testenv' => \
$opt_testenv,
245 'list' => \
$opt_list,
247 'resetup-environment' => \
$opt_resetup_env,
248 'testlist=s' => \
@testlists,
249 'random-order' => \
$opt_random_order,
250 'load-list=s' => \
$opt_load_list,
251 'nss_wrapper_so_path=s' => \
$opt_libnss_wrapper_so_path,
252 'resolv_wrapper_so_path=s' => \
$opt_libresolv_wrapper_so_path,
253 'socket_wrapper_so_path=s' => \
$opt_libsocket_wrapper_so_path,
254 'uid_wrapper_so_path=s' => \
$opt_libuid_wrapper_so_path,
255 'use-dns-faking' => \
$opt_use_dns_faking
258 exit(1) if (not $result);
260 ShowHelp
() if ($opt_help);
262 die("--list and --testenv are mutually exclusive") if ($opt_list and $opt_testenv);
264 # we want unbuffered output
269 # quick hack to disable rpc validation when using valgrind - its way too slow
270 unless (defined($ENV{VALGRIND
})) {
271 $ENV{VALIDATE
} = "validate";
272 $ENV{MALLOC_CHECK_
} = 3;
275 # make all our python scripts unbuffered
276 $ENV{PYTHONUNBUFFERED
} = 1;
278 my $bindir_abs = abs_path
($bindir);
280 # Backwards compatibility:
281 if (defined($ENV{TEST_LDAP
}) and $ENV{TEST_LDAP
} eq "yes") {
282 if (defined($ENV{FEDORA_DS_ROOT
})) {
289 my $torture_maxtime = ($ENV{TORTURE_MAXTIME
} or 1200);
292 $torture_maxtime *= 2;
299 die("using an empty prefix isn't allowed") unless $prefix ne "";
301 # Ensure we have the test prefix around.
303 # We need restrictive
304 # permissions on this as some subdirectories in this tree will have
305 # wider permissions (ie 0777) and this would allow other users on the
306 # host to subvert the test process.
307 mkdir($prefix, 0700) unless -d
$prefix;
310 my $prefix_abs = abs_path
($prefix);
311 my $tmpdir_abs = abs_path
("$prefix/tmp");
312 mkdir($tmpdir_abs, 0777) unless -d
$tmpdir_abs;
314 my $srcdir_abs = abs_path
($srcdir);
316 die("using an empty absolute prefix isn't allowed") unless $prefix_abs ne "";
317 die("using '/' as absolute prefix isn't allowed") unless $prefix_abs ne "/";
319 $ENV{PREFIX
} = $prefix;
320 $ENV{PREFIX_ABS
} = $prefix_abs;
321 $ENV{SRCDIR
} = $srcdir;
322 $ENV{SRCDIR_ABS
} = $srcdir_abs;
323 $ENV{GNUPGHOME
} = "$srcdir_abs/selftest/gnupg";
324 $ENV{BINDIR
} = $bindir_abs;
326 my $tls_enabled = not $opt_quick;
327 $ENV{TLS_ENABLED
} = ($tls_enabled?
"yes":"no");
329 sub prefix_pathvar
($$)
331 my ($name, $newpath) = @_;
332 if (defined($ENV{$name})) {
333 $ENV{$name} = "$newpath:$ENV{$name}";
335 $ENV{$name} = $newpath;
338 prefix_pathvar
("PKG_CONFIG_PATH", "$bindir_abs/pkgconfig");
339 prefix_pathvar
("PYTHONPATH", "$bindir_abs/python");
341 if ($opt_socket_wrapper_keep_pcap) {
342 # Socket wrapper keep pcap implies socket wrapper pcap
343 $opt_socket_wrapper_pcap = 1;
346 if ($opt_socket_wrapper_pcap) {
347 # Socket wrapper pcap implies socket wrapper
348 $opt_socket_wrapper = 1;
351 my $ld_preload = $ENV{LD_PRELOAD
};
353 if ($opt_libnss_wrapper_so_path) {
355 $ld_preload = "$ld_preload:$opt_libnss_wrapper_so_path";
357 $ld_preload = "$opt_libnss_wrapper_so_path";
361 if ($opt_libresolv_wrapper_so_path) {
363 $ld_preload = "$ld_preload:$opt_libresolv_wrapper_so_path";
365 $ld_preload = "$opt_libresolv_wrapper_so_path";
369 if ($opt_libsocket_wrapper_so_path) {
371 $ld_preload = "$ld_preload:$opt_libsocket_wrapper_so_path";
373 $ld_preload = "$opt_libsocket_wrapper_so_path";
377 if ($opt_libuid_wrapper_so_path) {
379 $ld_preload = "$ld_preload:$opt_libuid_wrapper_so_path";
381 $ld_preload = "$opt_libuid_wrapper_so_path";
385 $ENV{LD_PRELOAD
} = $ld_preload;
386 print "LD_PRELOAD=$ENV{LD_PRELOAD}\n";
388 # Enable uid_wrapper globally
389 $ENV{UID_WRAPPER
} = 1;
391 # Disable RTLD_DEEPBIND hack for Samba bind dlz module
393 # This is needed in order to allow the ldb_*ldap module
394 # to work with a preloaded socket wrapper.
395 $ENV{LDB_MODULES_DISABLE_DEEPBIND
} = 1;
397 my $socket_wrapper_dir;
398 if ($opt_socket_wrapper) {
399 $socket_wrapper_dir = SocketWrapper
::setup_dir
("$prefix_abs/w", $opt_socket_wrapper_pcap);
400 print "SOCKET_WRAPPER_DIR=$socket_wrapper_dir\n";
401 } elsif (not $opt_list) {
403 warn("not using socket wrapper, but also not running as root. Will not be able to listen on proper ports");
407 if ($opt_use_dns_faking) {
408 print "DNS: Faking nameserver\n";
409 $ENV{SAMBA_DNS_FAKING
} = 1;
413 my $testenv_default = "none";
415 # After this many seconds, the server will self-terminate. All tests
416 # must terminate in this time, and testenv will only stay alive this
421 # 1 year should be enough :-)
422 $server_maxtime = 365 * 24 * 60 * 60;
424 # make test should run under 4 hours
425 $server_maxtime = 4 * 60 * 60;
428 if (defined($ENV{SMBD_MAXTIME
}) and $ENV{SMBD_MAXTIME
} ne "") {
429 $server_maxtime = $ENV{SMBD_MAXTIME
};
433 if ($opt_target eq "samba") {
434 $testenv_default = "ad_dc_ntvfs";
435 require target
::Samba
;
436 $target = new Samba
($bindir, $ldap, $srcdir, $server_maxtime);
437 } elsif ($opt_target eq "samba3") {
438 $testenv_default = "nt4_member";
439 require target
::Samba3
;
440 $target = new Samba3
($bindir, $srcdir_abs, $server_maxtime);
444 sub read_test_regexes
($)
448 open(LF
, "<$name") or die("unable to read $name: $!");
452 if (/^(.*?)([ \t]+)\#([\t ]*)(.*?)$/) {
453 push (@ret, [$1, $4]);
455 s/^(.*?)([ \t]+)\#([\t ]*)(.*?)$//;
456 push (@ret, [$_, undef]);
463 foreach (@opt_exclude) {
464 push (@excludes, read_test_regexes
($_));
467 foreach (@opt_include) {
468 push (@includes, read_test_regexes
($_));
471 my $interfaces = join(',', ("127.0.0.11/8",
478 my $clientdir = "$prefix_abs/client";
480 my $conffile = "$clientdir/client.conf";
481 $ENV{SMB_CONF_PATH
} = $conffile;
483 sub write_clientconf
($$$)
485 my ($conffile, $clientdir, $vars) = @_;
487 mkdir("$clientdir", 0777) unless -d
"$clientdir";
489 if ( -d
"$clientdir/private" ) {
490 unlink <$clientdir/private/*>;
492 mkdir("$clientdir/private", 0777);
495 if ( -d
"$clientdir/lockdir" ) {
496 unlink <$clientdir/lockdir/*>;
498 mkdir("$clientdir/lockdir", 0777);
501 if ( -d
"$clientdir/statedir" ) {
502 unlink <$clientdir/statedir/*>;
504 mkdir("$clientdir/statedir", 0777);
507 if ( -d
"$clientdir/cachedir" ) {
508 unlink <$clientdir/cachedir/*>;
510 mkdir("$clientdir/cachedir", 0777);
513 # this is ugly, but the ncalrpcdir needs exactly 0755
514 # otherwise tests fail.
517 if ( -d
"$clientdir/ncalrpcdir/np" ) {
518 unlink <$clientdir/ncalrpcdir/np
/*>;
519 rmdir "$clientdir/ncalrpcdir/np";
521 if ( -d
"$clientdir/ncalrpcdir" ) {
522 unlink <$clientdir/ncalrpcdir/*>;
523 rmdir "$clientdir/ncalrpcdir";
525 mkdir("$clientdir/ncalrpcdir", 0755);
528 my $cadir = "$ENV{SRCDIR_ABS}/selftest/manage-ca/CA-samba.example.com";
529 my $cacert = "$cadir/Public/CA-samba.example.com-cert.pem";
530 my $cacrl_pem = "$cadir/Public/CA-samba.example.com-crl.pem";
531 my $ca_users_dir = "$cadir/Users";
533 if ( -d
"$clientdir/pkinit" ) {
534 unlink <$clientdir/pkinit/*>;
536 mkdir("$clientdir/pkinit", 0700);
539 # each user has a USER-${USER_PRINCIPAL_NAME}-cert.pem and
540 # USER-${USER_PRINCIPAL_NAME}-private-key.pem symlink
541 # We make a copy here and make the certificated easily
542 # accessable in the client environment.
545 opendir USERS
, "${ca_users_dir}" or die "Could not open dir '${ca_users_dir}': $!";
546 for my $d (readdir USERS
) {
547 my $user_dir = "${ca_users_dir}/${d}";
548 next if ${d
} =~ /^\./;
549 next if (! -d
"${user_dir}");
550 opendir USER
, "${user_dir}" or die "Could not open dir '${user_dir}': $!";
551 for my $l (readdir USER
) {
552 my $user_link = "${user_dir}/${l}";
553 next if ${l
} =~ /^\./;
554 next if (! -l
"${user_link}");
556 my $dest = "${clientdir}/pkinit/${l}";
557 Samba
::copy_file_content
(${user_link
}, ${dest
});
564 open(CF
, ">$conffile");
565 print CF
"[global]\n";
566 print CF
"\tnetbios name = client\n";
567 if (defined($vars->{DOMAIN
})) {
568 print CF
"\tworkgroup = $vars->{DOMAIN}\n";
570 if (defined($vars->{REALM
})) {
571 print CF
"\trealm = $vars->{REALM}\n";
573 if ($opt_socket_wrapper) {
574 print CF
"\tinterfaces = $interfaces\n";
577 private dir = $clientdir/private
578 lock dir = $clientdir/lockdir
579 state directory = $clientdir/statedir
580 cache directory = $clientdir/cachedir
581 ncalrpc dir = $clientdir/ncalrpcdir
582 panic action = $RealBin/gdb_backtrace \%d
584 notify:inotify = false
586 system:anonymous = true
587 client lanman auth = Yes
589 torture:basedir = $clientdir
590 #We don't want to pass our self-tests if the PAC code is wrong
591 gensec:require_pac = true
592 #We don't want to run 'speed' tests for very long
593 torture:timelimit = 1
594 winbind separator = /
595 tls cafile = ${cacert}
596 tls crlfile = ${cacrl_pem}
597 tls verify peer = no_check
598 include system krb5 conf = no
605 sub should_run_test
($)
611 for (my $i=0; $i <= $#tests; $i++) {
612 if ($name =~ /$tests[$i]/i) {
624 open(IN
, $filename) or die("Unable to open $filename: $!");
627 if (/-- TEST(-LOADLIST|) --\n/) {
628 my $supports_loadlist = (defined($1) and $1 eq "-LOADLIST");
634 if ($supports_loadlist) {
636 $loadlist =~ s/\n//g;
640 if (should_run_test
($name) == 1) {
641 push (@ret, [$name, $env, $cmdline, $loadlist]);
647 close(IN
) or die("Error creating recipe from $filename");
651 if ($#testlists == -1) {
652 die("No testlists specified");
655 $ENV{SELFTEST_PREFIX
} = "$prefix_abs";
656 $ENV{SELFTEST_TMPDIR
} = "$tmpdir_abs";
657 $ENV{TMPDIR
} = "$tmpdir_abs";
658 $ENV{TEST_DATA_PREFIX
} = "$tmpdir_abs";
659 if ($opt_socket_wrapper) {
660 $ENV{SELFTEST_INTERFACES
} = $interfaces;
662 $ENV{SELFTEST_INTERFACES
} = "";
665 $ENV{SELFTEST_QUICK
} = "1";
667 $ENV{SELFTEST_QUICK
} = "";
669 $ENV{SELFTEST_MAXTIME
} = $torture_maxtime;
671 my $selftest_krbt_ccache_path = "$tmpdir_abs/selftest.krb5_ccache";
672 $ENV{KRB5CCNAME
} = "FILE:${selftest_krbt_ccache_path}.global";
675 foreach my $fn (@testlists) {
676 foreach (read_testlist
($fn)) {
678 next if (@includes and not defined(find_in_list
(\
@includes, $name)));
679 push (@available, $_);
683 my $restricted = undef;
684 my $restricted_used = {};
686 if ($opt_load_list) {
688 open(LOAD_LIST
, "<$opt_load_list") or die("Unable to open $opt_load_list");
689 while (<LOAD_LIST
>) {
691 push (@
$restricted, $_);
696 my $individual_tests = undef;
697 $individual_tests = {};
699 foreach my $testsuite (@available) {
700 my $name = $$testsuite[0];
701 my $skipreason = skip
($name);
702 if (defined($restricted)) {
703 # Find the testsuite for this test
705 foreach my $r (@
$restricted) {
707 $individual_tests->{$name} = [];
709 $restricted_used->{$r} = 1;
710 } elsif (substr($r, 0, length($name)+1) eq "$name.") {
711 push(@
{$individual_tests->{$name}}, $r);
713 $restricted_used->{$r} = 1;
717 if (defined($skipreason)) {
719 Subunit
::skip_testsuite
($name, $skipreason);
722 push(@todo, $testsuite);
725 } elsif (defined($skipreason)) {
727 Subunit
::skip_testsuite
($name, $skipreason);
730 push(@todo, $testsuite);
734 if (defined($restricted)) {
735 foreach (@
$restricted) {
736 unless (defined($restricted_used->{$_})) {
737 print "No test or testsuite found matching $_\n";
740 } elsif ($#todo == -1) {
741 print STDERR
"No tests to run\n";
745 my $suitestotal = $#todo + 1;
748 Subunit
::progress
($suitestotal);
749 Subunit
::report_time
(time());
755 my %running_envs = ();
757 sub get_running_env
($)
765 return $running_envs{$envname};
768 my @exported_envvars = (
773 # stuff related to a trusted domain
783 # domain controller stuff
793 "MEMBER_SERVER_IPV6",
794 "MEMBER_NETBIOSNAME",
795 "MEMBER_NETBIOSALIAS",
797 # rpc proxy controller stuff
799 "RPC_PROXY_SERVER_IP",
800 "RPC_PROXY_SERVER_IPV6",
801 "RPC_PROXY_NETBIOSNAME",
802 "RPC_PROXY_NETBIOSALIAS",
804 # domain controller stuff for Vampired DC
806 "VAMPIRE_DC_SERVER_IP",
807 "VAMPIRE_DC_SERVER_IPV6",
808 "VAMPIRE_DC_NETBIOSNAME",
809 "VAMPIRE_DC_NETBIOSALIAS",
811 "PROMOTED_DC_SERVER",
812 "PROMOTED_DC_SERVER_IP",
813 "PROMOTED_DC_SERVER_IPV6",
814 "PROMOTED_DC_NETBIOSNAME",
815 "PROMOTED_DC_NETBIOSALIAS",
831 # UID/GID for rfc2307 mapping tests
838 "SELFTEST_WINBINDD_SOCKET_DIR",
839 "WINBINDD_PRIV_PIPE_DIR",
845 "UNACCEPTABLE_PASSWORD",
848 "NSS_WRAPPER_PASSWD",
851 "NSS_WRAPPER_MODULE_SO_PATH",
852 "NSS_WRAPPER_MODULE_FN_PREFIX",
855 "RESOLV_WRAPPER_CONF",
856 "RESOLV_WRAPPER_HOSTS",
863 $SIG{INT
} = $SIG{QUIT
} = $SIG{TERM
} = 'DEFAULT';
864 $SIG{PIPE
} = 'IGNORE';
866 open(STDOUT
, ">&STDERR") or die "can't dup STDOUT to STDERR: $!";
868 print "$0: PID[$$]: Got SIG${signame} teardown environments.\n";
869 teardown_env
($_) foreach(keys %running_envs);
870 system("pstree -p $$");
871 print "$0: PID[$$]: Exiting...\n";
875 $SIG{INT
} = $SIG{QUIT
} = $SIG{TERM
} = $SIG{PIPE
} = \
&sighandler
;
879 my ($name, $prefix) = @_;
881 my $testenv_vars = undef;
887 $option =~ s/^[^:]*//;
890 $option = "client" if $option eq "";
892 $ENV{KRB5CCNAME
} = "FILE:${selftest_krbt_ccache_path}.${envname}/ignore";
894 if (defined(get_running_env
($envname))) {
895 $testenv_vars = get_running_env
($envname);
896 if (not $testenv_vars->{target
}->check_env($testenv_vars)) {
897 print $testenv_vars->{target
}->getlog_env($testenv_vars);
898 $testenv_vars = undef;
901 $testenv_vars = $target->setup_env($envname, $prefix);
902 if (defined($testenv_vars) and $testenv_vars eq "UNKNOWN") {
903 return $testenv_vars;
904 } elsif (defined($testenv_vars) && not defined($testenv_vars->{target
})) {
905 $testenv_vars->{target
} = $target;
907 if (not defined($testenv_vars)) {
908 warn("$opt_target can't start up known environment '$envname'");
912 return undef unless defined($testenv_vars);
914 $running_envs{$envname} = $testenv_vars;
916 if ($option eq "local") {
917 SocketWrapper
::set_default_iface
($testenv_vars->{SOCKET_WRAPPER_DEFAULT_IFACE
});
918 $ENV{SMB_CONF_PATH
} = $testenv_vars->{SERVERCONFFILE
};
919 } elsif ($option eq "client") {
920 SocketWrapper
::set_default_iface
(11);
921 write_clientconf
($conffile, $clientdir, $testenv_vars);
922 $ENV{SMB_CONF_PATH
} = $conffile;
924 die("Unknown option[$option] for envname[$envname]");
927 foreach (@exported_envvars) {
928 if (defined($testenv_vars->{$_})) {
929 $ENV{$_} = $testenv_vars->{$_};
935 my $krb5_ccache_path = "${selftest_krbt_ccache_path}.${envname}.${option}";
936 unlink($krb5_ccache_path);
937 $ENV{KRB5CCNAME
} = "FILE:${krb5_ccache_path}";
938 return $testenv_vars;
941 sub exported_envvars_str
($)
943 my ($testenv_vars) = @_;
946 foreach (@exported_envvars) {
947 next unless defined($testenv_vars->{$_});
948 $out .= $_."=".$testenv_vars->{$_}."\n";
957 return "" if ($envname eq "none");
958 my $env = get_running_env
($envname);
959 return $env->{target
}->getlog_env($env);
965 my $env = get_running_env
($envname);
966 return $env->{target
}->check_env($env);
972 return if ($envname eq "none");
973 print STDERR
"teardown_env($envname)\n";
974 my $env = get_running_env
($envname);
975 $env->{target
}->teardown_env($env);
976 delete $running_envs{$envname};
979 # This 'global' file needs to be empty when we start
980 unlink("$prefix_abs/dns_host_file");
981 unlink("$prefix_abs/hosts");
983 if ($opt_random_order) {
985 my @newtodo = List
::Util
::shuffle
(@todo);
990 my $testenv_name = $ENV{SELFTEST_TESTENV
};
991 $testenv_name = $testenv_default unless defined($testenv_name);
993 my $testenv_vars = setup_env
($testenv_name, $prefix);
995 if (not $testenv_vars or $testenv_vars eq "UNKNOWN") {
996 die("Unable to setup environment $testenv_name");
999 $ENV{PIDDIR
} = $testenv_vars->{PIDDIR
};
1000 $ENV{ENVNAME
} = $testenv_name;
1002 my $envvarstr = exported_envvars_str
($testenv_vars);
1004 my @term_args = ("echo -e \"
1005 Welcome to the Samba4 Test environment '$testenv_name'
1007 This matches the client environment used in make test
1008 server is pid `cat \$PIDDIR/samba.pid`
1010 Some useful environment variables:
1011 TORTURE_OPTIONS=\$TORTURE_OPTIONS
1012 SMB_CONF_PATH=\$SMB_CONF_PATH
1015 \" && LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH} bash");
1017 if ($ENV{TERMINAL
}) {
1018 @term = ($ENV{TERMINAL
});
1020 @term = ("xterm", "-e");
1021 unshift(@term_args, ("bash", "-c"));
1024 system(@term, @term_args);
1026 teardown_env
($testenv_name);
1027 } elsif ($opt_list) {
1030 my $envname = $$_[1];
1032 my $listcmd = $$_[3];
1034 unless (defined($listcmd)) {
1035 warn("Unable to list tests in $name");
1036 # Rather than ignoring this testsuite altogether, just pretend the entire testsuite is
1045 die("Unable to run $listcmd: $!");
1046 } elsif ($?
& 127) {
1047 die(sprintf("%s died with signal %d, %s coredump\n", $listcmd, ($?
& 127), ($?
& 128) ?
'with' : 'without'));
1050 my $exitcode = $?
>> 8;
1051 if ($exitcode != 0) {
1052 die("$cmd exited with exit code $exitcode");
1060 my $envname = $$_[1];
1062 my $envvars = setup_env
($envname, $prefix);
1063 if (not defined($envvars)) {
1064 Subunit
::start_testsuite
($name);
1065 Subunit
::end_testsuite
($name, "error",
1066 "unable to set up environment $envname - exiting");
1068 } elsif ($envvars eq "UNKNOWN") {
1069 Subunit
::start_testsuite
($name);
1070 Subunit
::end_testsuite
($name, "skip",
1071 "environment $envname is unknown in this test backend - skipping");
1075 # Generate a file with the individual tests to run, if the
1076 # test runner for this test suite supports it.
1077 if ($individual_tests and $individual_tests->{$name}) {
1079 my ($fh, $listid_file) = tempfile
(UNLINK
=> 0);
1080 foreach my $test (@
{$individual_tests->{$name}}) {
1081 print $fh substr($test, length($name)+1) . "\n";
1083 $cmd =~ s/\$LOADLIST/--load-list=$listid_file/g;
1085 warn("Unable to run individual tests in $name, it does not support --loadlist.");
1089 run_testsuite
($envname, $name, $cmd, $i, $suitestotal);
1091 teardown_env
($envname) if ($opt_resetup_env);
1097 teardown_env
($_) foreach (keys %running_envs);
1101 # if there were any valgrind failures, show them
1102 foreach (<$prefix/valgrind
.log*>) {
1103 next unless (-s
$_);
1104 print "VALGRIND FAILURE\n";