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;
54 my $opt_resetup_env = undef;
55 my $opt_load_list = undef;
56 my $opt_libnss_wrapper_so_path = "";
57 my $opt_libresolv_wrapper_so_path = "";
58 my $opt_libsocket_wrapper_so_path = "";
59 my $opt_libuid_wrapper_so_path = "";
60 my $opt_use_dns_faking = 0;
72 my ($list, $fullname) = @_;
75 if ($fullname =~ /$$_[0]/) {
76 return ($$_[1]) if ($$_[1]);
88 return find_in_list
(\
@excludes, $name);
97 return unless ($opt_socket_wrapper_pcap);
98 return unless defined($ENV{SOCKET_WRAPPER_PCAP_DIR
});
101 $fname =~ s
%[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\
-]%_%g;
103 my $pcap_file = "$ENV{SOCKET_WRAPPER_PCAP_DIR}/$fname.pcap";
105 SocketWrapper
::setup_pcap
($pcap_file);
112 my ($pcap_file, $exitcode) = @_;
114 return unless ($opt_socket_wrapper_pcap);
115 return if ($opt_socket_wrapper_keep_pcap);
116 return unless ($exitcode == 0);
117 return unless defined($pcap_file);
122 # expand strings from %ENV
123 sub expand_environment_strings
($)
126 # we use a reverse sort so we do the longer ones first
127 foreach my $k (sort { $b cmp $a } keys %ENV) {
128 $s =~ s/\$$k/$ENV{$k}/g;
133 sub run_testsuite
($$$$$)
135 my ($envname, $name, $cmd, $i, $totalsuites) = @_;
136 my $pcap_file = setup_pcap
($name);
138 Subunit
::start_testsuite
($name);
139 Subunit
::progress_push
();
140 Subunit
::report_time
(time());
142 Subunit
::report_time
(time());
143 Subunit
::progress_pop
();
146 print "command: $cmd\n";
147 printf "expanded command: %s\n", expand_environment_strings
($cmd);
148 Subunit
::end_testsuite
($name, "error", "Unable to run $cmd: $!");
151 print "command: $cmd\n";
152 printf "expanded command: %s\n", expand_environment_strings
($cmd);
153 Subunit
::end_testsuite
($name, "error",
154 sprintf("%s died with signal %d, %s coredump\n", $cmd, ($?
& 127), ($?
& 128) ?
'with' : 'without'));
158 my $exitcode = $?
>> 8;
160 my $envlog = getlog_env
($envname);
162 print "envlog: $envlog\n";
165 print "command: $cmd\n";
166 printf "expanded command: %s\n", expand_environment_strings
($cmd);
168 if ($exitcode == 0) {
169 Subunit
::end_testsuite
($name, "success");
171 Subunit
::end_testsuite
($name, "failure", "Exit code was $exitcode");
174 cleanup_pcap
($pcap_file, $exitcode);
176 if (not $opt_socket_wrapper_keep_pcap and defined($pcap_file)) {
177 print "PCAP FILE: $pcap_file\n";
180 if ($exitcode != 0) {
181 exit(1) if ($opt_one);
189 print "Samba test runner
190 Copyright (C) Jelmer Vernooij <jelmer\@samba.org>
191 Copyright (C) Stefan Metzmacher <metze\@samba.org>
193 Usage: $Script [OPTIONS] TESTNAME-REGEX [TESTNAME-REGEX...]
196 --help this help page
197 --target=samba[3]|win Samba version to target
198 --testlist=FILE file to read available tests from
199 --exclude=FILE Exclude tests listed in the file
200 --include=FILE Include tests listed in the file
203 --prefix=DIR prefix to run tests in [st]
204 --srcdir=DIR source directory [.]
205 --bindir=DIR binaries directory [./bin]
208 --nss_wrapper_so_path=FILE the nss_wrapper library to preload
209 --resolv_wrapper_so_path=FILE the resolv_wrapper library to preload
210 --socket_wrapper_so_path=FILE the socket_wrapper library to preload
211 --uid_wrapper_so_path=FILE the uid_wrapper library to preload
214 --use-dns-faking Fake DNS entries rather than talking to our
218 --socket-wrapper-pcap save traffic to pcap directories
219 --socket-wrapper-keep-pcap keep all pcap files, not just those for tests that
221 --socket-wrapper enable socket wrapper
224 --ldap=openldap|fedora-ds back samba onto specified ldap server
227 --quick run quick overall test
228 --one abort when the first test fails
229 --testenv run a shell in the requested test environment
230 --list list available tests
235 my $result = GetOptions
(
236 'help|h|?' => \
$opt_help,
237 'target=s' => \
$opt_target,
238 'prefix=s' => \
$prefix,
239 'socket-wrapper' => \
$opt_socket_wrapper,
240 'socket-wrapper-pcap' => \
$opt_socket_wrapper_pcap,
241 'socket-wrapper-keep-pcap' => \
$opt_socket_wrapper_keep_pcap,
242 'quick' => \
$opt_quick,
244 'exclude=s' => \
@opt_exclude,
245 'include=s' => \
@opt_include,
246 'srcdir=s' => \
$srcdir,
247 'bindir=s' => \
$bindir,
248 'testenv' => \
$opt_testenv,
249 'list' => \
$opt_list,
250 'mitkrb5' => \
$opt_mitkrb5,
252 'resetup-environment' => \
$opt_resetup_env,
253 'testlist=s' => \
@testlists,
254 'random-order' => \
$opt_random_order,
255 'load-list=s' => \
$opt_load_list,
256 'nss_wrapper_so_path=s' => \
$opt_libnss_wrapper_so_path,
257 'resolv_wrapper_so_path=s' => \
$opt_libresolv_wrapper_so_path,
258 'socket_wrapper_so_path=s' => \
$opt_libsocket_wrapper_so_path,
259 'uid_wrapper_so_path=s' => \
$opt_libuid_wrapper_so_path,
260 'use-dns-faking' => \
$opt_use_dns_faking
263 exit(1) if (not $result);
265 ShowHelp
() if ($opt_help);
267 die("--list and --testenv are mutually exclusive") if ($opt_list and $opt_testenv);
269 # we want unbuffered output
274 # quick hack to disable rpc validation when using valgrind - its way too slow
275 unless (defined($ENV{VALGRIND
})) {
276 $ENV{VALIDATE
} = "validate";
277 $ENV{MALLOC_CHECK_
} = 3;
280 # make all our python scripts unbuffered
281 $ENV{PYTHONUNBUFFERED
} = 1;
283 my $bindir_abs = abs_path
($bindir);
285 # Backwards compatibility:
286 if (defined($ENV{TEST_LDAP
}) and $ENV{TEST_LDAP
} eq "yes") {
287 if (defined($ENV{FEDORA_DS_ROOT
})) {
294 my $torture_maxtime = ($ENV{TORTURE_MAXTIME
} or 1200);
297 $torture_maxtime *= 2;
304 die("using an empty prefix isn't allowed") unless $prefix ne "";
306 # Ensure we have the test prefix around.
308 # We need restrictive
309 # permissions on this as some subdirectories in this tree will have
310 # wider permissions (ie 0777) and this would allow other users on the
311 # host to subvert the test process.
313 mkdir($prefix, 0700) unless -d
$prefix;
315 # We need to have no umask limitations for the tests.
318 my $prefix_abs = abs_path
($prefix);
319 my $tmpdir_abs = abs_path
("$prefix/tmp");
320 mkdir($tmpdir_abs, 0777) unless -d
$tmpdir_abs;
322 my $srcdir_abs = abs_path
($srcdir);
324 die("using an empty absolute prefix isn't allowed") unless $prefix_abs ne "";
325 die("using '/' as absolute prefix isn't allowed") unless $prefix_abs ne "/";
327 $ENV{SAMBA_SELFTEST
} = "1";
329 $ENV{PREFIX
} = $prefix;
330 $ENV{PREFIX_ABS
} = $prefix_abs;
331 $ENV{SRCDIR
} = $srcdir;
332 $ENV{SRCDIR_ABS
} = $srcdir_abs;
333 $ENV{GNUPGHOME
} = "$srcdir_abs/selftest/gnupg";
334 $ENV{BINDIR
} = $bindir_abs;
336 my $tls_enabled = not $opt_quick;
337 $ENV{TLS_ENABLED
} = ($tls_enabled?
"yes":"no");
339 sub prefix_pathvar
($$)
341 my ($name, $newpath) = @_;
342 if (defined($ENV{$name})) {
343 $ENV{$name} = "$newpath:$ENV{$name}";
345 $ENV{$name} = $newpath;
348 prefix_pathvar
("PKG_CONFIG_PATH", "$bindir_abs/pkgconfig");
349 prefix_pathvar
("PYTHONPATH", "$bindir_abs/python");
351 if ($opt_socket_wrapper_keep_pcap) {
352 # Socket wrapper keep pcap implies socket wrapper pcap
353 $opt_socket_wrapper_pcap = 1;
356 if ($opt_socket_wrapper_pcap) {
357 # Socket wrapper pcap implies socket wrapper
358 $opt_socket_wrapper = 1;
361 my $ld_preload = $ENV{LD_PRELOAD
};
363 if ($opt_libnss_wrapper_so_path) {
365 $ld_preload = "$ld_preload:$opt_libnss_wrapper_so_path";
367 $ld_preload = "$opt_libnss_wrapper_so_path";
371 if ($opt_libresolv_wrapper_so_path) {
373 $ld_preload = "$ld_preload:$opt_libresolv_wrapper_so_path";
375 $ld_preload = "$opt_libresolv_wrapper_so_path";
379 if ($opt_libsocket_wrapper_so_path) {
381 $ld_preload = "$ld_preload:$opt_libsocket_wrapper_so_path";
383 $ld_preload = "$opt_libsocket_wrapper_so_path";
387 if ($opt_libuid_wrapper_so_path) {
389 $ld_preload = "$ld_preload:$opt_libuid_wrapper_so_path";
391 $ld_preload = "$opt_libuid_wrapper_so_path";
395 $ENV{LD_PRELOAD
} = $ld_preload;
396 print "LD_PRELOAD=$ENV{LD_PRELOAD}\n";
398 # Enable uid_wrapper globally
399 $ENV{UID_WRAPPER
} = 1;
401 # Disable RTLD_DEEPBIND hack for Samba bind dlz module
403 # This is needed in order to allow the ldb_*ldap module
404 # to work with a preloaded socket wrapper.
405 $ENV{LDB_MODULES_DISABLE_DEEPBIND
} = 1;
407 my $socket_wrapper_dir;
408 if ($opt_socket_wrapper) {
409 $socket_wrapper_dir = SocketWrapper
::setup_dir
("$prefix_abs/w", $opt_socket_wrapper_pcap);
410 print "SOCKET_WRAPPER_DIR=$socket_wrapper_dir\n";
411 } elsif (not $opt_list) {
413 warn("not using socket wrapper, but also not running as root. Will not be able to listen on proper ports");
417 if ($opt_use_dns_faking) {
418 print "DNS: Faking nameserver\n";
419 $ENV{SAMBA_DNS_FAKING
} = 1;
423 my $testenv_default = "none";
425 if ($opt_mitkrb5 == 1) {
426 $ENV{MITKRB5
} = $opt_mitkrb5;
429 # After this many seconds, the server will self-terminate. All tests
430 # must terminate in this time, and testenv will only stay alive this
435 # 1 year should be enough :-)
436 $server_maxtime = 365 * 24 * 60 * 60;
438 # make test should run under 4 hours
439 $server_maxtime = 4 * 60 * 60;
442 if (defined($ENV{SMBD_MAXTIME
}) and $ENV{SMBD_MAXTIME
} ne "") {
443 $server_maxtime = $ENV{SMBD_MAXTIME
};
447 if ($opt_target eq "samba") {
448 $testenv_default = "ad_dc_ntvfs";
449 require target
::Samba
;
450 $target = new Samba
($bindir, $ldap, $srcdir, $server_maxtime);
451 } elsif ($opt_target eq "samba3") {
452 $testenv_default = "nt4_member";
453 require target
::Samba3
;
454 $target = new Samba3
($bindir, $srcdir_abs, $server_maxtime);
458 sub read_test_regexes
($)
462 open(LF
, "<$name") or die("unable to read $name: $!");
466 if (/^(.*?)([ \t]+)\#([\t ]*)(.*?)$/) {
467 push (@ret, [$1, $4]);
469 s/^(.*?)([ \t]+)\#([\t ]*)(.*?)$//;
470 push (@ret, [$_, undef]);
477 foreach (@opt_exclude) {
478 push (@excludes, read_test_regexes
($_));
481 foreach (@opt_include) {
482 push (@includes, read_test_regexes
($_));
485 my $interfaces = join(',', ("127.0.0.11/8",
492 my $clientdir = "$prefix_abs/client";
494 my $conffile = "$clientdir/client.conf";
495 $ENV{SMB_CONF_PATH
} = $conffile;
497 sub write_clientconf
($$$)
499 my ($conffile, $clientdir, $vars) = @_;
501 mkdir("$clientdir", 0777) unless -d
"$clientdir";
503 if ( -d
"$clientdir/private" ) {
504 unlink <$clientdir/private/*>;
506 mkdir("$clientdir/private", 0777);
509 if ( -d
"$clientdir/lockdir" ) {
510 unlink <$clientdir/lockdir/*>;
512 mkdir("$clientdir/lockdir", 0777);
515 if ( -d
"$clientdir/statedir" ) {
516 unlink <$clientdir/statedir/*>;
518 mkdir("$clientdir/statedir", 0777);
521 if ( -d
"$clientdir/cachedir" ) {
522 unlink <$clientdir/cachedir/*>;
524 mkdir("$clientdir/cachedir", 0777);
527 # this is ugly, but the ncalrpcdir needs exactly 0755
528 # otherwise tests fail.
531 if ( -d
"$clientdir/ncalrpcdir/np" ) {
532 unlink <$clientdir/ncalrpcdir/np
/*>;
533 rmdir "$clientdir/ncalrpcdir/np";
535 if ( -d
"$clientdir/ncalrpcdir" ) {
536 unlink <$clientdir/ncalrpcdir/*>;
537 rmdir "$clientdir/ncalrpcdir";
539 mkdir("$clientdir/ncalrpcdir", 0755);
542 my $cadir = "$ENV{SRCDIR_ABS}/selftest/manage-ca/CA-samba.example.com";
543 my $cacert = "$cadir/Public/CA-samba.example.com-cert.pem";
544 my $cacrl_pem = "$cadir/Public/CA-samba.example.com-crl.pem";
545 my $ca_users_dir = "$cadir/Users";
547 if ( -d
"$clientdir/pkinit" ) {
548 unlink <$clientdir/pkinit/*>;
550 mkdir("$clientdir/pkinit", 0700);
553 # each user has a USER-${USER_PRINCIPAL_NAME}-cert.pem and
554 # USER-${USER_PRINCIPAL_NAME}-private-key.pem symlink
555 # We make a copy here and make the certificated easily
556 # accessable in the client environment.
559 opendir USERS
, "${ca_users_dir}" or die "Could not open dir '${ca_users_dir}': $!";
560 for my $d (readdir USERS
) {
561 my $user_dir = "${ca_users_dir}/${d}";
562 next if ${d
} =~ /^\./;
563 next if (! -d
"${user_dir}");
564 opendir USER
, "${user_dir}" or die "Could not open dir '${user_dir}': $!";
565 for my $l (readdir USER
) {
566 my $user_link = "${user_dir}/${l}";
567 next if ${l
} =~ /^\./;
568 next if (! -l
"${user_link}");
570 my $dest = "${clientdir}/pkinit/${l}";
571 Samba
::copy_file_content
(${user_link
}, ${dest
});
578 open(CF
, ">$conffile");
579 print CF
"[global]\n";
580 print CF
"\tnetbios name = client\n";
581 if (defined($vars->{DOMAIN
})) {
582 print CF
"\tworkgroup = $vars->{DOMAIN}\n";
584 if (defined($vars->{REALM
})) {
585 print CF
"\trealm = $vars->{REALM}\n";
587 if ($opt_socket_wrapper) {
588 print CF
"\tinterfaces = $interfaces\n";
591 private dir = $clientdir/private
592 lock dir = $clientdir/lockdir
593 state directory = $clientdir/statedir
594 cache directory = $clientdir/cachedir
595 ncalrpc dir = $clientdir/ncalrpcdir
596 panic action = $RealBin/gdb_backtrace \%d
598 notify:inotify = false
600 system:anonymous = true
601 client lanman auth = Yes
603 torture:basedir = $clientdir
604 #We don't want to pass our self-tests if the PAC code is wrong
605 gensec:require_pac = true
606 #We don't want to run 'speed' tests for very long
607 torture:timelimit = 1
608 winbind separator = /
609 tls cafile = ${cacert}
610 tls crlfile = ${cacrl_pem}
611 tls verify peer = no_check
612 include system krb5 conf = no
619 sub should_run_test
($)
625 for (my $i=0; $i <= $#tests; $i++) {
626 if ($name =~ /$tests[$i]/i) {
638 open(IN
, $filename) or die("Unable to open $filename: $!");
641 if (/-- TEST(-LOADLIST|) --\n/) {
642 my $supports_loadlist = (defined($1) and $1 eq "-LOADLIST");
648 if ($supports_loadlist) {
650 $loadlist =~ s/\n//g;
654 if (should_run_test
($name) == 1) {
655 push (@ret, [$name, $env, $cmdline, $loadlist]);
661 close(IN
) or die("Error creating recipe from $filename");
665 if ($#testlists == -1) {
666 die("No testlists specified");
669 $ENV{SELFTEST_PREFIX
} = "$prefix_abs";
670 $ENV{SELFTEST_TMPDIR
} = "$tmpdir_abs";
671 $ENV{TMPDIR
} = "$tmpdir_abs";
672 $ENV{TEST_DATA_PREFIX
} = "$tmpdir_abs";
673 if ($opt_socket_wrapper) {
674 $ENV{SELFTEST_INTERFACES
} = $interfaces;
676 $ENV{SELFTEST_INTERFACES
} = "";
679 $ENV{SELFTEST_QUICK
} = "1";
681 $ENV{SELFTEST_QUICK
} = "";
683 $ENV{SELFTEST_MAXTIME
} = $torture_maxtime;
685 my $selftest_krbt_ccache_path = "$tmpdir_abs/selftest.krb5_ccache";
686 $ENV{KRB5CCNAME
} = "FILE:${selftest_krbt_ccache_path}.global";
689 foreach my $fn (@testlists) {
690 foreach (read_testlist
($fn)) {
692 next if (@includes and not defined(find_in_list
(\
@includes, $name)));
693 push (@available, $_);
697 my $restricted = undef;
698 my $restricted_used = {};
700 if ($opt_load_list) {
702 open(LOAD_LIST
, "<$opt_load_list") or die("Unable to open $opt_load_list");
703 while (<LOAD_LIST
>) {
705 push (@
$restricted, $_);
710 my $individual_tests = undef;
711 $individual_tests = {};
713 foreach my $testsuite (@available) {
714 my $name = $$testsuite[0];
715 my $skipreason = skip
($name);
716 if (defined($restricted)) {
717 # Find the testsuite for this test
719 foreach my $r (@
$restricted) {
721 $individual_tests->{$name} = [];
723 $restricted_used->{$r} = 1;
724 } elsif (substr($r, 0, length($name)+1) eq "$name.") {
725 push(@
{$individual_tests->{$name}}, $r);
727 $restricted_used->{$r} = 1;
731 if (defined($skipreason)) {
733 Subunit
::skip_testsuite
($name, $skipreason);
736 push(@todo, $testsuite);
739 } elsif (defined($skipreason)) {
741 Subunit
::skip_testsuite
($name, $skipreason);
744 push(@todo, $testsuite);
748 if (defined($restricted)) {
749 foreach (@
$restricted) {
750 unless (defined($restricted_used->{$_})) {
751 print "No test or testsuite found matching $_\n";
754 } elsif ($#todo == -1) {
755 print STDERR
"No tests to run\n";
759 my $suitestotal = $#todo + 1;
762 Subunit
::progress
($suitestotal);
763 Subunit
::report_time
(time());
769 my %running_envs = ();
771 sub get_running_env
($)
779 return $running_envs{$envname};
782 my @exported_envvars = (
787 # stuff related to a trusted domain
797 # domain controller stuff
807 "MEMBER_SERVER_IPV6",
808 "MEMBER_NETBIOSNAME",
809 "MEMBER_NETBIOSALIAS",
811 # rpc proxy controller stuff
813 "RPC_PROXY_SERVER_IP",
814 "RPC_PROXY_SERVER_IPV6",
815 "RPC_PROXY_NETBIOSNAME",
816 "RPC_PROXY_NETBIOSALIAS",
818 # domain controller stuff for Vampired DC
820 "VAMPIRE_DC_SERVER_IP",
821 "VAMPIRE_DC_SERVER_IPV6",
822 "VAMPIRE_DC_NETBIOSNAME",
823 "VAMPIRE_DC_NETBIOSALIAS",
825 # domain controller stuff for FL 2000 Vampired DC
826 "VAMPIRE_2000_DC_SERVER",
827 "VAMPIRE_2000_DC_SERVER_IP",
828 "VAMPIRE_2000_DC_SERVER_IPV6",
829 "VAMPIRE_2000_DC_NETBIOSNAME",
830 "VAMPIRE_2000_DC_NETBIOSALIAS",
832 "PROMOTED_DC_SERVER",
833 "PROMOTED_DC_SERVER_IP",
834 "PROMOTED_DC_SERVER_IPV6",
835 "PROMOTED_DC_NETBIOSNAME",
836 "PROMOTED_DC_NETBIOSALIAS",
852 # UID/GID for rfc2307 mapping tests
859 "SELFTEST_WINBINDD_SOCKET_DIR",
865 "UNACCEPTABLE_PASSWORD",
869 "NSS_WRAPPER_PASSWD",
872 "NSS_WRAPPER_MODULE_SO_PATH",
873 "NSS_WRAPPER_MODULE_FN_PREFIX",
876 "RESOLV_WRAPPER_CONF",
877 "RESOLV_WRAPPER_HOSTS",
884 $SIG{INT
} = $SIG{QUIT
} = $SIG{TERM
} = 'DEFAULT';
885 $SIG{PIPE
} = 'IGNORE';
887 open(STDOUT
, ">&STDERR") or die "can't dup STDOUT to STDERR: $!";
889 print "$0: PID[$$]: Got SIG${signame} teardown environments.\n";
890 teardown_env
($_) foreach(keys %running_envs);
891 system("pstree -p $$");
892 print "$0: PID[$$]: Exiting...\n";
896 $SIG{INT
} = $SIG{QUIT
} = $SIG{TERM
} = $SIG{PIPE
} = \
&sighandler
;
900 my ($name, $prefix) = @_;
902 my $testenv_vars = undef;
908 $option =~ s/^[^:]*//;
911 $option = "client" if $option eq "";
913 $ENV{KRB5CCNAME
} = "FILE:${selftest_krbt_ccache_path}.${envname}/ignore";
915 if (defined(get_running_env
($envname))) {
916 $testenv_vars = get_running_env
($envname);
917 if (not $testenv_vars->{target
}->check_env($testenv_vars)) {
918 print $testenv_vars->{target
}->getlog_env($testenv_vars);
919 $testenv_vars = undef;
922 $testenv_vars = $target->setup_env($envname, $prefix);
923 if (defined($testenv_vars) and $testenv_vars eq "UNKNOWN") {
924 return $testenv_vars;
925 } elsif (defined($testenv_vars) && not defined($testenv_vars->{target
})) {
926 $testenv_vars->{target
} = $target;
928 if (not defined($testenv_vars)) {
929 warn("$opt_target can't start up known environment '$envname'");
933 return undef unless defined($testenv_vars);
935 $running_envs{$envname} = $testenv_vars;
937 if ($option eq "local") {
938 SocketWrapper
::set_default_iface
($testenv_vars->{SOCKET_WRAPPER_DEFAULT_IFACE
});
939 $ENV{SMB_CONF_PATH
} = $testenv_vars->{SERVERCONFFILE
};
940 } elsif ($option eq "client") {
941 SocketWrapper
::set_default_iface
(11);
942 write_clientconf
($conffile, $clientdir, $testenv_vars);
943 $ENV{SMB_CONF_PATH
} = $conffile;
945 die("Unknown option[$option] for envname[$envname]");
948 foreach (@exported_envvars) {
949 if (defined($testenv_vars->{$_})) {
950 $ENV{$_} = $testenv_vars->{$_};
956 my $krb5_ccache_path = "${selftest_krbt_ccache_path}.${envname}.${option}";
957 unlink($krb5_ccache_path);
958 $ENV{KRB5CCNAME
} = "FILE:${krb5_ccache_path}";
959 return $testenv_vars;
962 sub exported_envvars_str
($)
964 my ($testenv_vars) = @_;
967 foreach (@exported_envvars) {
968 next unless defined($testenv_vars->{$_});
969 $out .= $_."=".$testenv_vars->{$_}."\n";
978 return "" if ($envname eq "none");
979 my $env = get_running_env
($envname);
980 return $env->{target
}->getlog_env($env);
986 my $env = get_running_env
($envname);
987 return $env->{target
}->check_env($env);
993 return if ($envname eq "none");
994 print STDERR
"teardown_env($envname)\n";
995 my $env = get_running_env
($envname);
996 $env->{target
}->teardown_env($env);
997 delete $running_envs{$envname};
1000 # This 'global' file needs to be empty when we start
1001 unlink("$prefix_abs/dns_host_file");
1002 unlink("$prefix_abs/hosts");
1004 if ($opt_random_order) {
1006 my @newtodo = List
::Util
::shuffle
(@todo);
1011 my $testenv_name = $ENV{SELFTEST_TESTENV
};
1012 $testenv_name = $testenv_default unless defined($testenv_name);
1014 my $testenv_vars = setup_env
($testenv_name, $prefix);
1016 if (not $testenv_vars or $testenv_vars eq "UNKNOWN") {
1017 die("Unable to setup environment $testenv_name");
1020 $ENV{PIDDIR
} = $testenv_vars->{PIDDIR
};
1021 $ENV{ENVNAME
} = $testenv_name;
1023 my $envvarstr = exported_envvars_str
($testenv_vars);
1025 my @term_args = ("echo -e \"
1026 Welcome to the Samba4 Test environment '$testenv_name'
1028 This matches the client environment used in make test
1029 server is pid `cat \$PIDDIR/samba.pid`
1031 Some useful environment variables:
1032 TORTURE_OPTIONS=\$TORTURE_OPTIONS
1033 SMB_CONF_PATH=\$SMB_CONF_PATH
1036 \" && LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH} bash");
1038 if ($ENV{TERMINAL
}) {
1039 @term = ($ENV{TERMINAL
});
1041 @term = ("xterm", "-e");
1042 unshift(@term_args, ("bash", "-c"));
1045 system(@term, @term_args);
1047 teardown_env
($testenv_name);
1048 } elsif ($opt_list) {
1051 my $envname = $$_[1];
1053 my $listcmd = $$_[3];
1055 unless (defined($listcmd)) {
1056 warn("Unable to list tests in $name");
1057 # Rather than ignoring this testsuite altogether, just pretend the entire testsuite is
1066 die("Unable to run $listcmd: $!");
1067 } elsif ($?
& 127) {
1068 die(sprintf("%s died with signal %d, %s coredump\n", $listcmd, ($?
& 127), ($?
& 128) ?
'with' : 'without'));
1071 my $exitcode = $?
>> 8;
1072 if ($exitcode != 0) {
1073 die("$cmd exited with exit code $exitcode");
1081 my $envname = $$_[1];
1083 my $envvars = setup_env
($envname, $prefix);
1084 if (not defined($envvars)) {
1085 Subunit
::start_testsuite
($name);
1086 Subunit
::end_testsuite
($name, "error",
1087 "unable to set up environment $envname - exiting");
1089 } elsif ($envvars eq "UNKNOWN") {
1090 Subunit
::start_testsuite
($name);
1091 Subunit
::end_testsuite
($name, "skip",
1092 "environment $envname is unknown in this test backend - skipping");
1096 # Generate a file with the individual tests to run, if the
1097 # test runner for this test suite supports it.
1098 if ($individual_tests and $individual_tests->{$name}) {
1100 my ($fh, $listid_file) = tempfile
(UNLINK
=> 0);
1101 foreach my $test (@
{$individual_tests->{$name}}) {
1102 print $fh substr($test, length($name)+1) . "\n";
1104 $cmd =~ s/\$LOADLIST/--load-list=$listid_file/g;
1106 warn("Unable to run individual tests in $name, it does not support --loadlist.");
1110 run_testsuite
($envname, $name, $cmd, $i, $suitestotal);
1112 teardown_env
($envname) if ($opt_resetup_env);
1118 teardown_env
($_) foreach (keys %running_envs);
1122 # if there were any valgrind failures, show them
1123 foreach (<$prefix/valgrind
.log*>) {
1124 next unless (-s
$_);
1125 print "VALGRIND FAILURE\n";