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{KRB5CCNAME
} = "$prefix/krb5ticket";
321 $ENV{PREFIX_ABS
} = $prefix_abs;
322 $ENV{SRCDIR
} = $srcdir;
323 $ENV{SRCDIR_ABS
} = $srcdir_abs;
324 $ENV{GNUPGHOME
} = "$srcdir_abs/selftest/gnupg";
325 $ENV{BINDIR
} = $bindir_abs;
327 my $tls_enabled = not $opt_quick;
328 $ENV{TLS_ENABLED
} = ($tls_enabled?
"yes":"no");
330 sub prefix_pathvar
($$)
332 my ($name, $newpath) = @_;
333 if (defined($ENV{$name})) {
334 $ENV{$name} = "$newpath:$ENV{$name}";
336 $ENV{$name} = $newpath;
339 prefix_pathvar
("PKG_CONFIG_PATH", "$bindir_abs/pkgconfig");
340 prefix_pathvar
("PYTHONPATH", "$bindir_abs/python");
342 if ($opt_socket_wrapper_keep_pcap) {
343 # Socket wrapper keep pcap implies socket wrapper pcap
344 $opt_socket_wrapper_pcap = 1;
347 if ($opt_socket_wrapper_pcap) {
348 # Socket wrapper pcap implies socket wrapper
349 $opt_socket_wrapper = 1;
352 my $ld_preload = $ENV{LD_PRELOAD
};
354 if ($opt_libnss_wrapper_so_path) {
356 $ld_preload = "$ld_preload:$opt_libnss_wrapper_so_path";
358 $ld_preload = "$opt_libnss_wrapper_so_path";
362 if ($opt_libresolv_wrapper_so_path) {
364 $ld_preload = "$ld_preload:$opt_libresolv_wrapper_so_path";
366 $ld_preload = "$opt_libresolv_wrapper_so_path";
370 if ($opt_libsocket_wrapper_so_path) {
372 $ld_preload = "$ld_preload:$opt_libsocket_wrapper_so_path";
374 $ld_preload = "$opt_libsocket_wrapper_so_path";
378 if ($opt_libuid_wrapper_so_path) {
380 $ld_preload = "$ld_preload:$opt_libuid_wrapper_so_path";
382 $ld_preload = "$opt_libuid_wrapper_so_path";
386 $ENV{LD_PRELOAD
} = $ld_preload;
387 print "LD_PRELOAD=$ENV{LD_PRELOAD}\n";
389 # Enable uid_wrapper globally
390 $ENV{UID_WRAPPER
} = 1;
392 # Disable RTLD_DEEPBIND hack for Samba bind dlz module
394 # This is needed in order to allow the ldb_*ldap module
395 # to work with a preloaded socket wrapper.
396 $ENV{LDB_MODULES_DISABLE_DEEPBIND
} = 1;
398 my $socket_wrapper_dir;
399 if ($opt_socket_wrapper) {
400 $socket_wrapper_dir = SocketWrapper
::setup_dir
("$prefix_abs/w", $opt_socket_wrapper_pcap);
401 print "SOCKET_WRAPPER_DIR=$socket_wrapper_dir\n";
402 } elsif (not $opt_list) {
404 warn("not using socket wrapper, but also not running as root. Will not be able to listen on proper ports");
408 if ($opt_use_dns_faking) {
409 print "DNS: Faking nameserver\n";
410 $ENV{SAMBA_DNS_FAKING
} = 1;
414 my $testenv_default = "none";
416 # After this many seconds, the server will self-terminate. All tests
417 # must terminate in this time, and testenv will only stay alive this
422 # 1 year should be enough :-)
423 $server_maxtime = 365 * 24 * 60 * 60;
425 # make test should run under 4 hours
426 $server_maxtime = 4 * 60 * 60;
429 if (defined($ENV{SMBD_MAXTIME
}) and $ENV{SMBD_MAXTIME
} ne "") {
430 $server_maxtime = $ENV{SMBD_MAXTIME
};
434 if ($opt_target eq "samba") {
435 $testenv_default = "ad_dc_ntvfs";
436 require target
::Samba
;
437 $target = new Samba
($bindir, $ldap, $srcdir, $server_maxtime);
438 } elsif ($opt_target eq "samba3") {
439 $testenv_default = "nt4_member";
440 require target
::Samba3
;
441 $target = new Samba3
($bindir, $srcdir_abs, $server_maxtime);
445 sub read_test_regexes
($)
449 open(LF
, "<$name") or die("unable to read $name: $!");
453 if (/^(.*?)([ \t]+)\#([\t ]*)(.*?)$/) {
454 push (@ret, [$1, $4]);
456 s/^(.*?)([ \t]+)\#([\t ]*)(.*?)$//;
457 push (@ret, [$_, undef]);
464 foreach (@opt_exclude) {
465 push (@excludes, read_test_regexes
($_));
468 foreach (@opt_include) {
469 push (@includes, read_test_regexes
($_));
472 my $interfaces = join(',', ("127.0.0.11/8",
479 my $clientdir = "$prefix_abs/client";
481 my $conffile = "$clientdir/client.conf";
482 $ENV{SMB_CONF_PATH
} = $conffile;
484 sub write_clientconf
($$$)
486 my ($conffile, $clientdir, $vars) = @_;
488 mkdir("$clientdir", 0777) unless -d
"$clientdir";
490 if ( -d
"$clientdir/private" ) {
491 unlink <$clientdir/private/*>;
493 mkdir("$clientdir/private", 0777);
496 if ( -d
"$clientdir/lockdir" ) {
497 unlink <$clientdir/lockdir/*>;
499 mkdir("$clientdir/lockdir", 0777);
502 if ( -d
"$clientdir/statedir" ) {
503 unlink <$clientdir/statedir/*>;
505 mkdir("$clientdir/statedir", 0777);
508 if ( -d
"$clientdir/cachedir" ) {
509 unlink <$clientdir/cachedir/*>;
511 mkdir("$clientdir/cachedir", 0777);
514 # this is ugly, but the ncalrpcdir needs exactly 0755
515 # otherwise tests fail.
518 if ( -d
"$clientdir/ncalrpcdir/np" ) {
519 unlink <$clientdir/ncalrpcdir/np
/*>;
520 rmdir "$clientdir/ncalrpcdir/np";
522 if ( -d
"$clientdir/ncalrpcdir" ) {
523 unlink <$clientdir/ncalrpcdir/*>;
524 rmdir "$clientdir/ncalrpcdir";
526 mkdir("$clientdir/ncalrpcdir", 0755);
529 my $cadir = "$ENV{SRCDIR_ABS}/selftest/manage-ca/CA-samba.example.com";
530 my $cacert = "$cadir/Public/CA-samba.example.com-cert.pem";
531 my $cacrl_pem = "$cadir/Public/CA-samba.example.com-crl.pem";
532 my $ca_users_dir = "$cadir/Users";
534 if ( -d
"$clientdir/pkinit" ) {
535 unlink <$clientdir/pkinit/*>;
537 mkdir("$clientdir/pkinit", 0700);
540 # each user has a USER-${USER_PRINCIPAL_NAME}-cert.pem and
541 # USER-${USER_PRINCIPAL_NAME}-private-key.pem symlink
542 # We make a copy here and make the certificated easily
543 # accessable in the client environment.
546 opendir USERS
, "${ca_users_dir}" or die "Could not open dir '${ca_users_dir}': $!";
547 for my $d (readdir USERS
) {
548 my $user_dir = "${ca_users_dir}/${d}";
549 next if ${d
} =~ /^\./;
550 next if (! -d
"${user_dir}");
551 opendir USER
, "${user_dir}" or die "Could not open dir '${user_dir}': $!";
552 for my $l (readdir USER
) {
553 my $user_link = "${user_dir}/${l}";
554 next if ${l
} =~ /^\./;
555 next if (! -l
"${user_link}");
557 my $dest = "${clientdir}/pkinit/${l}";
558 Samba
::copy_file_content
(${user_link
}, ${dest
});
565 open(CF
, ">$conffile");
566 print CF
"[global]\n";
567 print CF
"\tnetbios name = client\n";
568 if (defined($vars->{DOMAIN
})) {
569 print CF
"\tworkgroup = $vars->{DOMAIN}\n";
571 if (defined($vars->{REALM
})) {
572 print CF
"\trealm = $vars->{REALM}\n";
574 if ($opt_socket_wrapper) {
575 print CF
"\tinterfaces = $interfaces\n";
578 private dir = $clientdir/private
579 lock dir = $clientdir/lockdir
580 state directory = $clientdir/statedir
581 cache directory = $clientdir/cachedir
582 ncalrpc dir = $clientdir/ncalrpcdir
583 panic action = $RealBin/gdb_backtrace \%d
585 notify:inotify = false
587 system:anonymous = true
588 client lanman auth = Yes
590 torture:basedir = $clientdir
591 #We don't want to pass our self-tests if the PAC code is wrong
592 gensec:require_pac = true
593 #We don't want to run 'speed' tests for very long
594 torture:timelimit = 1
595 winbind separator = /
596 tls cafile = ${cacert}
597 tls crlfile = ${cacrl_pem}
598 tls verify peer = no_check
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{TEST_DATA_PREFIX
} = "$tmpdir_abs";
658 if ($opt_socket_wrapper) {
659 $ENV{SELFTEST_INTERFACES
} = $interfaces;
661 $ENV{SELFTEST_INTERFACES
} = "";
664 $ENV{SELFTEST_QUICK
} = "1";
666 $ENV{SELFTEST_QUICK
} = "";
668 $ENV{SELFTEST_MAXTIME
} = $torture_maxtime;
671 foreach my $fn (@testlists) {
672 foreach (read_testlist
($fn)) {
674 next if (@includes and not defined(find_in_list
(\
@includes, $name)));
675 push (@available, $_);
679 my $restricted = undef;
680 my $restricted_used = {};
682 if ($opt_load_list) {
684 open(LOAD_LIST
, "<$opt_load_list") or die("Unable to open $opt_load_list");
685 while (<LOAD_LIST
>) {
687 push (@
$restricted, $_);
692 my $individual_tests = undef;
693 $individual_tests = {};
695 foreach my $testsuite (@available) {
696 my $name = $$testsuite[0];
697 my $skipreason = skip
($name);
698 if (defined($restricted)) {
699 # Find the testsuite for this test
701 foreach my $r (@
$restricted) {
703 $individual_tests->{$name} = [];
705 $restricted_used->{$r} = 1;
706 } elsif (substr($r, 0, length($name)+1) eq "$name.") {
707 push(@
{$individual_tests->{$name}}, $r);
709 $restricted_used->{$r} = 1;
713 if (defined($skipreason)) {
715 Subunit
::skip_testsuite
($name, $skipreason);
718 push(@todo, $testsuite);
721 } elsif (defined($skipreason)) {
723 Subunit
::skip_testsuite
($name, $skipreason);
726 push(@todo, $testsuite);
730 if (defined($restricted)) {
731 foreach (@
$restricted) {
732 unless (defined($restricted_used->{$_})) {
733 print "No test or testsuite found matching $_\n";
736 } elsif ($#todo == -1) {
737 print STDERR
"No tests to run\n";
741 my $suitestotal = $#todo + 1;
744 Subunit
::progress
($suitestotal);
745 Subunit
::report_time
(time());
751 my %running_envs = ();
753 sub get_running_env
($)
761 return $running_envs{$envname};
764 my @exported_envvars = (
769 # stuff related to a trusted domain
779 # domain controller stuff
789 "MEMBER_SERVER_IPV6",
790 "MEMBER_NETBIOSNAME",
791 "MEMBER_NETBIOSALIAS",
793 # rpc proxy controller stuff
795 "RPC_PROXY_SERVER_IP",
796 "RPC_PROXY_SERVER_IPV6",
797 "RPC_PROXY_NETBIOSNAME",
798 "RPC_PROXY_NETBIOSALIAS",
800 # domain controller stuff for Vampired DC
802 "VAMPIRE_DC_SERVER_IP",
803 "VAMPIRE_DC_SERVER_IPV6",
804 "VAMPIRE_DC_NETBIOSNAME",
805 "VAMPIRE_DC_NETBIOSALIAS",
807 "PROMOTED_DC_SERVER",
808 "PROMOTED_DC_SERVER_IP",
809 "PROMOTED_DC_SERVER_IPV6",
810 "PROMOTED_DC_NETBIOSNAME",
811 "PROMOTED_DC_NETBIOSALIAS",
827 # UID/GID for rfc2307 mapping tests
833 "SELFTEST_WINBINDD_SOCKET_DIR",
834 "WINBINDD_PRIV_PIPE_DIR",
840 "UNACCEPTABLE_PASSWORD",
843 "NSS_WRAPPER_PASSWD",
846 "NSS_WRAPPER_MODULE_SO_PATH",
847 "NSS_WRAPPER_MODULE_FN_PREFIX",
850 "RESOLV_WRAPPER_CONF",
851 "RESOLV_WRAPPER_HOSTS",
858 $SIG{INT
} = $SIG{QUIT
} = $SIG{TERM
} = 'DEFAULT';
859 $SIG{PIPE
} = 'IGNORE';
861 open(STDOUT
, ">&STDERR") or die "can't dup STDOUT to STDERR: $!";
863 print "$0: PID[$$]: Got SIG${signame} teardown environments.\n";
864 teardown_env
($_) foreach(keys %running_envs);
865 system("pstree -p $$");
866 print "$0: PID[$$]: Exiting...\n";
870 $SIG{INT
} = $SIG{QUIT
} = $SIG{TERM
} = $SIG{PIPE
} = \
&sighandler
;
874 my ($name, $prefix) = @_;
876 my $testenv_vars = undef;
882 $option =~ s/^[^:]*//;
885 $option = "client" if $option eq "";
887 if (defined(get_running_env
($envname))) {
888 $testenv_vars = get_running_env
($envname);
889 if (not $testenv_vars->{target
}->check_env($testenv_vars)) {
890 print $testenv_vars->{target
}->getlog_env($testenv_vars);
891 $testenv_vars = undef;
894 $testenv_vars = $target->setup_env($envname, $prefix);
895 if (defined($testenv_vars) and $testenv_vars eq "UNKNOWN") {
896 return $testenv_vars;
897 } elsif (defined($testenv_vars) && not defined($testenv_vars->{target
})) {
898 $testenv_vars->{target
} = $target;
900 if (not defined($testenv_vars)) {
901 warn("$opt_target can't start up known environment '$envname'");
905 return undef unless defined($testenv_vars);
907 $running_envs{$envname} = $testenv_vars;
909 if ($option eq "local") {
910 SocketWrapper
::set_default_iface
($testenv_vars->{SOCKET_WRAPPER_DEFAULT_IFACE
});
911 $ENV{SMB_CONF_PATH
} = $testenv_vars->{SERVERCONFFILE
};
912 } elsif ($option eq "client") {
913 SocketWrapper
::set_default_iface
(11);
914 write_clientconf
($conffile, $clientdir, $testenv_vars);
915 $ENV{SMB_CONF_PATH
} = $conffile;
917 die("Unknown option[$option] for envname[$envname]");
920 foreach (@exported_envvars) {
921 if (defined($testenv_vars->{$_})) {
922 $ENV{$_} = $testenv_vars->{$_};
928 return $testenv_vars;
931 sub exported_envvars_str
($)
933 my ($testenv_vars) = @_;
936 foreach (@exported_envvars) {
937 next unless defined($testenv_vars->{$_});
938 $out .= $_."=".$testenv_vars->{$_}."\n";
947 return "" if ($envname eq "none");
948 my $env = get_running_env
($envname);
949 return $env->{target
}->getlog_env($env);
955 my $env = get_running_env
($envname);
956 return $env->{target
}->check_env($env);
962 return if ($envname eq "none");
963 print STDERR
"teardown_env($envname)\n";
964 my $env = get_running_env
($envname);
965 $env->{target
}->teardown_env($env);
966 delete $running_envs{$envname};
969 # This 'global' file needs to be empty when we start
970 unlink("$prefix_abs/dns_host_file");
971 unlink("$prefix_abs/hosts");
973 if ($opt_random_order) {
975 my @newtodo = List
::Util
::shuffle
(@todo);
980 my $testenv_name = $ENV{SELFTEST_TESTENV
};
981 $testenv_name = $testenv_default unless defined($testenv_name);
983 my $testenv_vars = setup_env
($testenv_name, $prefix);
985 if (not $testenv_vars or $testenv_vars eq "UNKNOWN") {
986 die("Unable to setup environment $testenv_name");
989 $ENV{PIDDIR
} = $testenv_vars->{PIDDIR
};
990 $ENV{ENVNAME
} = $testenv_name;
992 my $envvarstr = exported_envvars_str
($testenv_vars);
994 my @term_args = ("echo -e \"
995 Welcome to the Samba4 Test environment '$testenv_name'
997 This matches the client environment used in make test
998 server is pid `cat \$PIDDIR/samba.pid`
1000 Some useful environment variables:
1001 TORTURE_OPTIONS=\$TORTURE_OPTIONS
1002 SMB_CONF_PATH=\$SMB_CONF_PATH
1005 \" && LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH} bash");
1007 if ($ENV{TERMINAL
}) {
1008 @term = ($ENV{TERMINAL
});
1010 @term = ("xterm", "-e");
1011 unshift(@term_args, ("bash", "-c"));
1014 system(@term, @term_args);
1016 teardown_env
($testenv_name);
1017 } elsif ($opt_list) {
1020 my $envname = $$_[1];
1022 my $listcmd = $$_[3];
1024 unless (defined($listcmd)) {
1025 warn("Unable to list tests in $name");
1026 # Rather than ignoring this testsuite altogether, just pretend the entire testsuite is
1035 die("Unable to run $listcmd: $!");
1036 } elsif ($?
& 127) {
1037 die(sprintf("%s died with signal %d, %s coredump\n", $listcmd, ($?
& 127), ($?
& 128) ?
'with' : 'without'));
1040 my $exitcode = $?
>> 8;
1041 if ($exitcode != 0) {
1042 die("$cmd exited with exit code $exitcode");
1050 my $envname = $$_[1];
1052 my $envvars = setup_env
($envname, $prefix);
1053 if (not defined($envvars)) {
1054 Subunit
::start_testsuite
($name);
1055 Subunit
::end_testsuite
($name, "error",
1056 "unable to set up environment $envname - exiting");
1058 } elsif ($envvars eq "UNKNOWN") {
1059 Subunit
::start_testsuite
($name);
1060 Subunit
::end_testsuite
($name, "skip",
1061 "environment $envname is unknown in this test backend - skipping");
1065 # Generate a file with the individual tests to run, if the
1066 # test runner for this test suite supports it.
1067 if ($individual_tests and $individual_tests->{$name}) {
1069 my ($fh, $listid_file) = tempfile
(UNLINK
=> 0);
1070 foreach my $test (@
{$individual_tests->{$name}}) {
1071 print $fh substr($test, length($name)+1) . "\n";
1073 $cmd =~ s/\$LOADLIST/--load-list=$listid_file/g;
1075 warn("Unable to run individual tests in $name, it does not support --loadlist.");
1079 run_testsuite
($envname, $name, $cmd, $i, $suitestotal);
1081 teardown_env
($envname) if ($opt_resetup_env);
1087 teardown_env
($_) foreach (keys %running_envs);
1091 # if there were any valgrind failures, show them
1092 foreach (<$prefix/valgrind
.log*>) {
1093 next unless (-s
$_);
1094 print "VALGRIND FAILURE\n";