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 print "command: $cmd\n";
146 printf "expanded command: %s\n", expand_environment_strings
($cmd);
147 Subunit
::end_testsuite
($name, "error", "Unable to run $cmd: $!");
150 print "command: $cmd\n";
151 printf "expanded command: %s\n", expand_environment_strings
($cmd);
152 Subunit
::end_testsuite
($name, "error",
153 sprintf("%s died with signal %d, %s coredump\n", $cmd, ($?
& 127), ($?
& 128) ?
'with' : 'without'));
157 my $exitcode = $?
>> 8;
159 my $envlog = getlog_env
($envname);
161 print "envlog: $envlog\n";
164 print "command: $cmd\n";
165 printf "expanded command: %s\n", expand_environment_strings
($cmd);
167 if ($exitcode == 0) {
168 Subunit
::end_testsuite
($name, "success");
170 Subunit
::end_testsuite
($name, "failure", "Exit code was $exitcode");
173 cleanup_pcap
($pcap_file, $exitcode);
175 if (not $opt_socket_wrapper_keep_pcap and defined($pcap_file)) {
176 print "PCAP FILE: $pcap_file\n";
179 if ($exitcode != 0) {
180 exit(1) if ($opt_one);
188 print "Samba test runner
189 Copyright (C) Jelmer Vernooij <jelmer\@samba.org>
190 Copyright (C) Stefan Metzmacher <metze\@samba.org>
192 Usage: $Script [OPTIONS] TESTNAME-REGEX [TESTNAME-REGEX...]
195 --help this help page
196 --target=samba[3]|win Samba version to target
197 --testlist=FILE file to read available tests from
198 --exclude=FILE Exclude tests listed in the file
199 --include=FILE Include tests listed in the file
202 --prefix=DIR prefix to run tests in [st]
203 --srcdir=DIR source directory [.]
204 --bindir=DIR binaries directory [./bin]
207 --nss_wrapper_so_path=FILE the nss_wrapper library to preload
208 --resolv_wrapper_so_path=FILE the resolv_wrapper library to preload
209 --socket_wrapper_so_path=FILE the socket_wrapper library to preload
210 --uid_wrapper_so_path=FILE the uid_wrapper library to preload
213 --use-dns-faking Fake DNS entries rather than talking to our
217 --socket-wrapper-pcap save traffic to pcap directories
218 --socket-wrapper-keep-pcap keep all pcap files, not just those for tests that
220 --socket-wrapper enable socket wrapper
223 --ldap=openldap|fedora-ds back samba onto specified ldap server
226 --quick run quick overall test
227 --one abort when the first test fails
228 --testenv run a shell in the requested test environment
229 --list list available tests
234 my $result = GetOptions
(
235 'help|h|?' => \
$opt_help,
236 'target=s' => \
$opt_target,
237 'prefix=s' => \
$prefix,
238 'socket-wrapper' => \
$opt_socket_wrapper,
239 'socket-wrapper-pcap' => \
$opt_socket_wrapper_pcap,
240 'socket-wrapper-keep-pcap' => \
$opt_socket_wrapper_keep_pcap,
241 'quick' => \
$opt_quick,
243 'exclude=s' => \
@opt_exclude,
244 'include=s' => \
@opt_include,
245 'srcdir=s' => \
$srcdir,
246 'bindir=s' => \
$bindir,
247 'testenv' => \
$opt_testenv,
248 'list' => \
$opt_list,
250 'resetup-environment' => \
$opt_resetup_env,
251 'testlist=s' => \
@testlists,
252 'random-order' => \
$opt_random_order,
253 'load-list=s' => \
$opt_load_list,
254 'nss_wrapper_so_path=s' => \
$opt_libnss_wrapper_so_path,
255 'resolv_wrapper_so_path=s' => \
$opt_libresolv_wrapper_so_path,
256 'socket_wrapper_so_path=s' => \
$opt_libsocket_wrapper_so_path,
257 'uid_wrapper_so_path=s' => \
$opt_libuid_wrapper_so_path,
258 'use-dns-faking' => \
$opt_use_dns_faking
261 exit(1) if (not $result);
263 ShowHelp
() if ($opt_help);
265 die("--list and --testenv are mutually exclusive") if ($opt_list and $opt_testenv);
267 # we want unbuffered output
272 # quick hack to disable rpc validation when using valgrind - its way too slow
273 unless (defined($ENV{VALGRIND
})) {
274 $ENV{VALIDATE
} = "validate";
275 $ENV{MALLOC_CHECK_
} = 3;
278 # make all our python scripts unbuffered
279 $ENV{PYTHONUNBUFFERED
} = 1;
281 my $bindir_abs = abs_path
($bindir);
283 # Backwards compatibility:
284 if (defined($ENV{TEST_LDAP
}) and $ENV{TEST_LDAP
} eq "yes") {
285 if (defined($ENV{FEDORA_DS_ROOT
})) {
292 my $torture_maxtime = ($ENV{TORTURE_MAXTIME
} or 1200);
295 $torture_maxtime *= 2;
302 die("using an empty prefix isn't allowed") unless $prefix ne "";
304 # Ensure we have the test prefix around.
306 # We need restrictive
307 # permissions on this as some subdirectories in this tree will have
308 # wider permissions (ie 0777) and this would allow other users on the
309 # host to subvert the test process.
311 mkdir($prefix, 0700) unless -d
$prefix;
313 # We need to have no umask limitations for the tests.
316 my $prefix_abs = abs_path
($prefix);
317 my $tmpdir_abs = abs_path
("$prefix/tmp");
318 mkdir($tmpdir_abs, 0777) unless -d
$tmpdir_abs;
320 my $srcdir_abs = abs_path
($srcdir);
322 die("using an empty absolute prefix isn't allowed") unless $prefix_abs ne "";
323 die("using '/' as absolute prefix isn't allowed") unless $prefix_abs ne "/";
325 $ENV{PREFIX
} = $prefix;
326 $ENV{PREFIX_ABS
} = $prefix_abs;
327 $ENV{SRCDIR
} = $srcdir;
328 $ENV{SRCDIR_ABS
} = $srcdir_abs;
329 $ENV{GNUPGHOME
} = "$srcdir_abs/selftest/gnupg";
330 $ENV{BINDIR
} = $bindir_abs;
332 my $tls_enabled = not $opt_quick;
333 $ENV{TLS_ENABLED
} = ($tls_enabled?
"yes":"no");
335 sub prefix_pathvar
($$)
337 my ($name, $newpath) = @_;
338 if (defined($ENV{$name})) {
339 $ENV{$name} = "$newpath:$ENV{$name}";
341 $ENV{$name} = $newpath;
344 prefix_pathvar
("PKG_CONFIG_PATH", "$bindir_abs/pkgconfig");
345 prefix_pathvar
("PYTHONPATH", "$bindir_abs/python");
347 if ($opt_socket_wrapper_keep_pcap) {
348 # Socket wrapper keep pcap implies socket wrapper pcap
349 $opt_socket_wrapper_pcap = 1;
352 if ($opt_socket_wrapper_pcap) {
353 # Socket wrapper pcap implies socket wrapper
354 $opt_socket_wrapper = 1;
357 my $ld_preload = $ENV{LD_PRELOAD
};
359 if ($opt_libnss_wrapper_so_path) {
361 $ld_preload = "$ld_preload:$opt_libnss_wrapper_so_path";
363 $ld_preload = "$opt_libnss_wrapper_so_path";
367 if ($opt_libresolv_wrapper_so_path) {
369 $ld_preload = "$ld_preload:$opt_libresolv_wrapper_so_path";
371 $ld_preload = "$opt_libresolv_wrapper_so_path";
375 if ($opt_libsocket_wrapper_so_path) {
377 $ld_preload = "$ld_preload:$opt_libsocket_wrapper_so_path";
379 $ld_preload = "$opt_libsocket_wrapper_so_path";
383 if ($opt_libuid_wrapper_so_path) {
385 $ld_preload = "$ld_preload:$opt_libuid_wrapper_so_path";
387 $ld_preload = "$opt_libuid_wrapper_so_path";
391 $ENV{LD_PRELOAD
} = $ld_preload;
392 print "LD_PRELOAD=$ENV{LD_PRELOAD}\n";
394 # Enable uid_wrapper globally
395 $ENV{UID_WRAPPER
} = 1;
397 # Disable RTLD_DEEPBIND hack for Samba bind dlz module
399 # This is needed in order to allow the ldb_*ldap module
400 # to work with a preloaded socket wrapper.
401 $ENV{LDB_MODULES_DISABLE_DEEPBIND
} = 1;
403 my $socket_wrapper_dir;
404 if ($opt_socket_wrapper) {
405 $socket_wrapper_dir = SocketWrapper
::setup_dir
("$prefix_abs/w", $opt_socket_wrapper_pcap);
406 print "SOCKET_WRAPPER_DIR=$socket_wrapper_dir\n";
407 } elsif (not $opt_list) {
409 warn("not using socket wrapper, but also not running as root. Will not be able to listen on proper ports");
413 if ($opt_use_dns_faking) {
414 print "DNS: Faking nameserver\n";
415 $ENV{SAMBA_DNS_FAKING
} = 1;
419 my $testenv_default = "none";
421 # After this many seconds, the server will self-terminate. All tests
422 # must terminate in this time, and testenv will only stay alive this
427 # 1 year should be enough :-)
428 $server_maxtime = 365 * 24 * 60 * 60;
430 # make test should run under 4 hours
431 $server_maxtime = 4 * 60 * 60;
434 if (defined($ENV{SMBD_MAXTIME
}) and $ENV{SMBD_MAXTIME
} ne "") {
435 $server_maxtime = $ENV{SMBD_MAXTIME
};
439 if ($opt_target eq "samba") {
440 $testenv_default = "ad_dc_ntvfs";
441 require target
::Samba
;
442 $target = new Samba
($bindir, $ldap, $srcdir, $server_maxtime);
443 } elsif ($opt_target eq "samba3") {
444 $testenv_default = "nt4_member";
445 require target
::Samba3
;
446 $target = new Samba3
($bindir, $srcdir_abs, $server_maxtime);
450 sub read_test_regexes
($)
454 open(LF
, "<$name") or die("unable to read $name: $!");
458 if (/^(.*?)([ \t]+)\#([\t ]*)(.*?)$/) {
459 push (@ret, [$1, $4]);
461 s/^(.*?)([ \t]+)\#([\t ]*)(.*?)$//;
462 push (@ret, [$_, undef]);
469 foreach (@opt_exclude) {
470 push (@excludes, read_test_regexes
($_));
473 foreach (@opt_include) {
474 push (@includes, read_test_regexes
($_));
477 my $interfaces = join(',', ("127.0.0.11/8",
484 my $clientdir = "$prefix_abs/client";
486 my $conffile = "$clientdir/client.conf";
487 $ENV{SMB_CONF_PATH
} = $conffile;
489 sub write_clientconf
($$$)
491 my ($conffile, $clientdir, $vars) = @_;
493 mkdir("$clientdir", 0777) unless -d
"$clientdir";
495 if ( -d
"$clientdir/private" ) {
496 unlink <$clientdir/private/*>;
498 mkdir("$clientdir/private", 0777);
501 if ( -d
"$clientdir/lockdir" ) {
502 unlink <$clientdir/lockdir/*>;
504 mkdir("$clientdir/lockdir", 0777);
507 if ( -d
"$clientdir/statedir" ) {
508 unlink <$clientdir/statedir/*>;
510 mkdir("$clientdir/statedir", 0777);
513 if ( -d
"$clientdir/cachedir" ) {
514 unlink <$clientdir/cachedir/*>;
516 mkdir("$clientdir/cachedir", 0777);
519 # this is ugly, but the ncalrpcdir needs exactly 0755
520 # otherwise tests fail.
523 if ( -d
"$clientdir/ncalrpcdir/np" ) {
524 unlink <$clientdir/ncalrpcdir/np
/*>;
525 rmdir "$clientdir/ncalrpcdir/np";
527 if ( -d
"$clientdir/ncalrpcdir" ) {
528 unlink <$clientdir/ncalrpcdir/*>;
529 rmdir "$clientdir/ncalrpcdir";
531 mkdir("$clientdir/ncalrpcdir", 0755);
534 my $cadir = "$ENV{SRCDIR_ABS}/selftest/manage-ca/CA-samba.example.com";
535 my $cacert = "$cadir/Public/CA-samba.example.com-cert.pem";
536 my $cacrl_pem = "$cadir/Public/CA-samba.example.com-crl.pem";
537 my $ca_users_dir = "$cadir/Users";
539 if ( -d
"$clientdir/pkinit" ) {
540 unlink <$clientdir/pkinit/*>;
542 mkdir("$clientdir/pkinit", 0700);
545 # each user has a USER-${USER_PRINCIPAL_NAME}-cert.pem and
546 # USER-${USER_PRINCIPAL_NAME}-private-key.pem symlink
547 # We make a copy here and make the certificated easily
548 # accessable in the client environment.
551 opendir USERS
, "${ca_users_dir}" or die "Could not open dir '${ca_users_dir}': $!";
552 for my $d (readdir USERS
) {
553 my $user_dir = "${ca_users_dir}/${d}";
554 next if ${d
} =~ /^\./;
555 next if (! -d
"${user_dir}");
556 opendir USER
, "${user_dir}" or die "Could not open dir '${user_dir}': $!";
557 for my $l (readdir USER
) {
558 my $user_link = "${user_dir}/${l}";
559 next if ${l
} =~ /^\./;
560 next if (! -l
"${user_link}");
562 my $dest = "${clientdir}/pkinit/${l}";
563 Samba
::copy_file_content
(${user_link
}, ${dest
});
570 open(CF
, ">$conffile");
571 print CF
"[global]\n";
572 print CF
"\tnetbios name = client\n";
573 if (defined($vars->{DOMAIN
})) {
574 print CF
"\tworkgroup = $vars->{DOMAIN}\n";
576 if (defined($vars->{REALM
})) {
577 print CF
"\trealm = $vars->{REALM}\n";
579 if ($opt_socket_wrapper) {
580 print CF
"\tinterfaces = $interfaces\n";
583 private dir = $clientdir/private
584 lock dir = $clientdir/lockdir
585 state directory = $clientdir/statedir
586 cache directory = $clientdir/cachedir
587 ncalrpc dir = $clientdir/ncalrpcdir
588 panic action = $RealBin/gdb_backtrace \%d
590 notify:inotify = false
592 system:anonymous = true
593 client lanman auth = Yes
595 torture:basedir = $clientdir
596 #We don't want to pass our self-tests if the PAC code is wrong
597 gensec:require_pac = true
598 #We don't want to run 'speed' tests for very long
599 torture:timelimit = 1
600 winbind separator = /
601 tls cafile = ${cacert}
602 tls crlfile = ${cacrl_pem}
603 tls verify peer = no_check
604 include system krb5 conf = no
611 sub should_run_test
($)
617 for (my $i=0; $i <= $#tests; $i++) {
618 if ($name =~ /$tests[$i]/i) {
630 open(IN
, $filename) or die("Unable to open $filename: $!");
633 if (/-- TEST(-LOADLIST|) --\n/) {
634 my $supports_loadlist = (defined($1) and $1 eq "-LOADLIST");
640 if ($supports_loadlist) {
642 $loadlist =~ s/\n//g;
646 if (should_run_test
($name) == 1) {
647 push (@ret, [$name, $env, $cmdline, $loadlist]);
653 close(IN
) or die("Error creating recipe from $filename");
657 if ($#testlists == -1) {
658 die("No testlists specified");
661 $ENV{SELFTEST_PREFIX
} = "$prefix_abs";
662 $ENV{SELFTEST_TMPDIR
} = "$tmpdir_abs";
663 $ENV{TMPDIR
} = "$tmpdir_abs";
664 $ENV{TEST_DATA_PREFIX
} = "$tmpdir_abs";
665 if ($opt_socket_wrapper) {
666 $ENV{SELFTEST_INTERFACES
} = $interfaces;
668 $ENV{SELFTEST_INTERFACES
} = "";
671 $ENV{SELFTEST_QUICK
} = "1";
673 $ENV{SELFTEST_QUICK
} = "";
675 $ENV{SELFTEST_MAXTIME
} = $torture_maxtime;
677 my $selftest_krbt_ccache_path = "$tmpdir_abs/selftest.krb5_ccache";
678 $ENV{KRB5CCNAME
} = "FILE:${selftest_krbt_ccache_path}.global";
681 foreach my $fn (@testlists) {
682 foreach (read_testlist
($fn)) {
684 next if (@includes and not defined(find_in_list
(\
@includes, $name)));
685 push (@available, $_);
689 my $restricted = undef;
690 my $restricted_used = {};
692 if ($opt_load_list) {
694 open(LOAD_LIST
, "<$opt_load_list") or die("Unable to open $opt_load_list");
695 while (<LOAD_LIST
>) {
697 push (@
$restricted, $_);
702 my $individual_tests = undef;
703 $individual_tests = {};
705 foreach my $testsuite (@available) {
706 my $name = $$testsuite[0];
707 my $skipreason = skip
($name);
708 if (defined($restricted)) {
709 # Find the testsuite for this test
711 foreach my $r (@
$restricted) {
713 $individual_tests->{$name} = [];
715 $restricted_used->{$r} = 1;
716 } elsif (substr($r, 0, length($name)+1) eq "$name.") {
717 push(@
{$individual_tests->{$name}}, $r);
719 $restricted_used->{$r} = 1;
723 if (defined($skipreason)) {
725 Subunit
::skip_testsuite
($name, $skipreason);
728 push(@todo, $testsuite);
731 } elsif (defined($skipreason)) {
733 Subunit
::skip_testsuite
($name, $skipreason);
736 push(@todo, $testsuite);
740 if (defined($restricted)) {
741 foreach (@
$restricted) {
742 unless (defined($restricted_used->{$_})) {
743 print "No test or testsuite found matching $_\n";
746 } elsif ($#todo == -1) {
747 print STDERR
"No tests to run\n";
751 my $suitestotal = $#todo + 1;
754 Subunit
::progress
($suitestotal);
755 Subunit
::report_time
(time());
761 my %running_envs = ();
763 sub get_running_env
($)
771 return $running_envs{$envname};
774 my @exported_envvars = (
779 # stuff related to a trusted domain
789 # domain controller stuff
799 "MEMBER_SERVER_IPV6",
800 "MEMBER_NETBIOSNAME",
801 "MEMBER_NETBIOSALIAS",
803 # rpc proxy controller stuff
805 "RPC_PROXY_SERVER_IP",
806 "RPC_PROXY_SERVER_IPV6",
807 "RPC_PROXY_NETBIOSNAME",
808 "RPC_PROXY_NETBIOSALIAS",
810 # domain controller stuff for Vampired DC
812 "VAMPIRE_DC_SERVER_IP",
813 "VAMPIRE_DC_SERVER_IPV6",
814 "VAMPIRE_DC_NETBIOSNAME",
815 "VAMPIRE_DC_NETBIOSALIAS",
817 # domain controller stuff for FL 2000 Vampired DC
818 "VAMPIRE_2000_DC_SERVER",
819 "VAMPIRE_2000_DC_SERVER_IP",
820 "VAMPIRE_2000_DC_SERVER_IPV6",
821 "VAMPIRE_2000_DC_NETBIOSNAME",
822 "VAMPIRE_2000_DC_NETBIOSALIAS",
824 "PROMOTED_DC_SERVER",
825 "PROMOTED_DC_SERVER_IP",
826 "PROMOTED_DC_SERVER_IPV6",
827 "PROMOTED_DC_NETBIOSNAME",
828 "PROMOTED_DC_NETBIOSALIAS",
844 # UID/GID for rfc2307 mapping tests
851 "SELFTEST_WINBINDD_SOCKET_DIR",
857 "UNACCEPTABLE_PASSWORD",
860 "NSS_WRAPPER_PASSWD",
863 "NSS_WRAPPER_MODULE_SO_PATH",
864 "NSS_WRAPPER_MODULE_FN_PREFIX",
867 "RESOLV_WRAPPER_CONF",
868 "RESOLV_WRAPPER_HOSTS",
875 $SIG{INT
} = $SIG{QUIT
} = $SIG{TERM
} = 'DEFAULT';
876 $SIG{PIPE
} = 'IGNORE';
878 open(STDOUT
, ">&STDERR") or die "can't dup STDOUT to STDERR: $!";
880 print "$0: PID[$$]: Got SIG${signame} teardown environments.\n";
881 teardown_env
($_) foreach(keys %running_envs);
882 system("pstree -p $$");
883 print "$0: PID[$$]: Exiting...\n";
887 $SIG{INT
} = $SIG{QUIT
} = $SIG{TERM
} = $SIG{PIPE
} = \
&sighandler
;
891 my ($name, $prefix) = @_;
893 my $testenv_vars = undef;
899 $option =~ s/^[^:]*//;
902 $option = "client" if $option eq "";
904 $ENV{KRB5CCNAME
} = "FILE:${selftest_krbt_ccache_path}.${envname}/ignore";
906 if (defined(get_running_env
($envname))) {
907 $testenv_vars = get_running_env
($envname);
908 if (not $testenv_vars->{target
}->check_env($testenv_vars)) {
909 print $testenv_vars->{target
}->getlog_env($testenv_vars);
910 $testenv_vars = undef;
913 $testenv_vars = $target->setup_env($envname, $prefix);
914 if (defined($testenv_vars) and $testenv_vars eq "UNKNOWN") {
915 return $testenv_vars;
916 } elsif (defined($testenv_vars) && not defined($testenv_vars->{target
})) {
917 $testenv_vars->{target
} = $target;
919 if (not defined($testenv_vars)) {
920 warn("$opt_target can't start up known environment '$envname'");
924 return undef unless defined($testenv_vars);
926 $running_envs{$envname} = $testenv_vars;
928 if ($option eq "local") {
929 SocketWrapper
::set_default_iface
($testenv_vars->{SOCKET_WRAPPER_DEFAULT_IFACE
});
930 $ENV{SMB_CONF_PATH
} = $testenv_vars->{SERVERCONFFILE
};
931 } elsif ($option eq "client") {
932 SocketWrapper
::set_default_iface
(11);
933 write_clientconf
($conffile, $clientdir, $testenv_vars);
934 $ENV{SMB_CONF_PATH
} = $conffile;
936 die("Unknown option[$option] for envname[$envname]");
939 foreach (@exported_envvars) {
940 if (defined($testenv_vars->{$_})) {
941 $ENV{$_} = $testenv_vars->{$_};
947 my $krb5_ccache_path = "${selftest_krbt_ccache_path}.${envname}.${option}";
948 unlink($krb5_ccache_path);
949 $ENV{KRB5CCNAME
} = "FILE:${krb5_ccache_path}";
950 return $testenv_vars;
953 sub exported_envvars_str
($)
955 my ($testenv_vars) = @_;
958 foreach (@exported_envvars) {
959 next unless defined($testenv_vars->{$_});
960 $out .= $_."=".$testenv_vars->{$_}."\n";
969 return "" if ($envname eq "none");
970 my $env = get_running_env
($envname);
971 return $env->{target
}->getlog_env($env);
977 my $env = get_running_env
($envname);
978 return $env->{target
}->check_env($env);
984 return if ($envname eq "none");
985 print STDERR
"teardown_env($envname)\n";
986 my $env = get_running_env
($envname);
987 $env->{target
}->teardown_env($env);
988 delete $running_envs{$envname};
991 # This 'global' file needs to be empty when we start
992 unlink("$prefix_abs/dns_host_file");
993 unlink("$prefix_abs/hosts");
995 if ($opt_random_order) {
997 my @newtodo = List
::Util
::shuffle
(@todo);
1002 my $testenv_name = $ENV{SELFTEST_TESTENV
};
1003 $testenv_name = $testenv_default unless defined($testenv_name);
1005 my $testenv_vars = setup_env
($testenv_name, $prefix);
1007 if (not $testenv_vars or $testenv_vars eq "UNKNOWN") {
1008 die("Unable to setup environment $testenv_name");
1011 $ENV{PIDDIR
} = $testenv_vars->{PIDDIR
};
1012 $ENV{ENVNAME
} = $testenv_name;
1014 my $envvarstr = exported_envvars_str
($testenv_vars);
1016 my @term_args = ("echo -e \"
1017 Welcome to the Samba4 Test environment '$testenv_name'
1019 This matches the client environment used in make test
1020 server is pid `cat \$PIDDIR/samba.pid`
1022 Some useful environment variables:
1023 TORTURE_OPTIONS=\$TORTURE_OPTIONS
1024 SMB_CONF_PATH=\$SMB_CONF_PATH
1027 \" && LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH} bash");
1029 if ($ENV{TERMINAL
}) {
1030 @term = ($ENV{TERMINAL
});
1032 @term = ("xterm", "-e");
1033 unshift(@term_args, ("bash", "-c"));
1036 system(@term, @term_args);
1038 teardown_env
($testenv_name);
1039 } elsif ($opt_list) {
1042 my $envname = $$_[1];
1044 my $listcmd = $$_[3];
1046 unless (defined($listcmd)) {
1047 warn("Unable to list tests in $name");
1048 # Rather than ignoring this testsuite altogether, just pretend the entire testsuite is
1057 die("Unable to run $listcmd: $!");
1058 } elsif ($?
& 127) {
1059 die(sprintf("%s died with signal %d, %s coredump\n", $listcmd, ($?
& 127), ($?
& 128) ?
'with' : 'without'));
1062 my $exitcode = $?
>> 8;
1063 if ($exitcode != 0) {
1064 die("$cmd exited with exit code $exitcode");
1072 my $envname = $$_[1];
1074 my $envvars = setup_env
($envname, $prefix);
1075 if (not defined($envvars)) {
1076 Subunit
::start_testsuite
($name);
1077 Subunit
::end_testsuite
($name, "error",
1078 "unable to set up environment $envname - exiting");
1080 } elsif ($envvars eq "UNKNOWN") {
1081 Subunit
::start_testsuite
($name);
1082 Subunit
::end_testsuite
($name, "skip",
1083 "environment $envname is unknown in this test backend - skipping");
1087 # Generate a file with the individual tests to run, if the
1088 # test runner for this test suite supports it.
1089 if ($individual_tests and $individual_tests->{$name}) {
1091 my ($fh, $listid_file) = tempfile
(UNLINK
=> 0);
1092 foreach my $test (@
{$individual_tests->{$name}}) {
1093 print $fh substr($test, length($name)+1) . "\n";
1095 $cmd =~ s/\$LOADLIST/--load-list=$listid_file/g;
1097 warn("Unable to run individual tests in $name, it does not support --loadlist.");
1101 run_testsuite
($envname, $name, $cmd, $i, $suitestotal);
1103 teardown_env
($envname) if ($opt_resetup_env);
1109 teardown_env
($_) foreach (keys %running_envs);
1113 # if there were any valgrind failures, show them
1114 foreach (<$prefix/valgrind
.log*>) {
1115 next unless (-s
$_);
1116 print "VALGRIND FAILURE\n";