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);
31 use Time
::HiRes
qw(time);
35 Time
::HiRes
->import("time");
38 print "You don't have Time::Hires installed !\n";
42 my $opt_target = "samba";
44 my $opt_socket_wrapper = 0;
45 my $opt_socket_wrapper_pcap = undef;
46 my $opt_socket_wrapper_keep_pcap = undef;
47 my $opt_random_order = 0;
51 my @opt_exclude_env = ();
52 my @opt_include_env = ();
57 my $opt_resetup_env = undef;
58 my $opt_load_list = undef;
59 my $opt_libnss_wrapper_so_path = "";
60 my $opt_libresolv_wrapper_so_path = "";
61 my $opt_libsocket_wrapper_so_path = "";
62 my $opt_libuid_wrapper_so_path = "";
63 my $opt_use_dns_faking = 0;
75 my ($list, $fullname) = @_;
78 if ($fullname =~ /$$_[0]/) {
79 return ($$_[1]) if ($$_[1]);
89 my ($name, $envname) = @_;
90 my ($env_basename, $env_localpart) = split(/:/, $envname);
92 if ($opt_target eq "samba3" && $Samba::ENV_NEEDS_AD_DC
{$env_basename}) {
93 return "environment $envname is disabled as this build does not include an AD DC";
96 if (@opt_include_env && !(grep {$_ eq $env_basename} @opt_include_env)) {
97 return "environment $envname is disabled (via --include-env command line option) in this test run - skipping";
98 } elsif (@opt_exclude_env && grep {$_ eq $env_basename} @opt_exclude_env) {
99 return "environment $envname is disabled (via --exclude-env command line option) in this test run - skipping";
102 return find_in_list
(\
@excludes, $name);
111 return unless ($opt_socket_wrapper_pcap);
112 return unless defined($ENV{SOCKET_WRAPPER_PCAP_DIR
});
115 $fname =~ s
%[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\
-]%_%g;
117 my $pcap_file = "$ENV{SOCKET_WRAPPER_PCAP_DIR}/$fname.pcap";
119 SocketWrapper
::setup_pcap
($pcap_file);
126 my ($pcap_file, $exitcode) = @_;
128 return unless ($opt_socket_wrapper_pcap);
129 return if ($opt_socket_wrapper_keep_pcap);
130 return unless ($exitcode == 0);
131 return unless defined($pcap_file);
136 # expand strings from %ENV
137 sub expand_environment_strings
($)
140 # we use a reverse sort so we do the longer ones first
141 foreach my $k (sort { $b cmp $a } keys %ENV) {
142 $s =~ s/\$$k/$ENV{$k}/g;
147 sub run_testsuite
($$$$$)
149 my ($envname, $name, $cmd, $i, $totalsuites) = @_;
150 my $pcap_file = setup_pcap
($name);
152 Subunit
::start_testsuite
($name);
153 Subunit
::progress_push
();
154 Subunit
::report_time
();
156 Subunit
::report_time
();
157 Subunit
::progress_pop
();
160 print "command: $cmd\n";
161 printf "expanded command: %s\n", expand_environment_strings
($cmd);
162 Subunit
::end_testsuite
($name, "error", "Unable to run $cmd: $!");
165 print "command: $cmd\n";
166 printf "expanded command: %s\n", expand_environment_strings
($cmd);
167 Subunit
::end_testsuite
($name, "error",
168 sprintf("%s died with signal %d, %s coredump\n", $cmd, ($?
& 127), ($?
& 128) ?
'with' : 'without'));
172 my $exitcode = $?
>> 8;
174 my $envlog = getlog_env
($envname);
176 print "envlog: $envlog\n";
179 print "command: $cmd\n";
180 printf "expanded command: %s\n", expand_environment_strings
($cmd);
182 if ($exitcode == 0) {
183 Subunit
::end_testsuite
($name, "success");
185 Subunit
::end_testsuite
($name, "failure", "Exit code was $exitcode");
188 cleanup_pcap
($pcap_file, $exitcode);
190 if (not $opt_socket_wrapper_keep_pcap and defined($pcap_file)) {
191 print "PCAP FILE: $pcap_file\n";
194 if ($exitcode != 0) {
195 exit(1) if ($opt_one);
203 print "Samba test runner
204 Copyright (C) Jelmer Vernooij <jelmer\@samba.org>
205 Copyright (C) Stefan Metzmacher <metze\@samba.org>
207 Usage: $Script [OPTIONS] TESTNAME-REGEX [TESTNAME-REGEX...]
210 --help this help page
211 --target=samba[3]|win Samba version to target
212 --testlist=FILE file to read available tests from
213 --exclude=FILE Exclude tests listed in the file
214 --include=FILE Include tests listed in the file
215 --exclude-env=ENV Exclude tests for the specified environment
216 --include-env=ENV Include tests for the specified environment
219 --prefix=DIR prefix to run tests in [st]
220 --srcdir=DIR source directory [.]
221 --bindir=DIR binaries directory [./bin]
224 --nss_wrapper_so_path=FILE the nss_wrapper library to preload
225 --resolv_wrapper_so_path=FILE the resolv_wrapper library to preload
226 --socket_wrapper_so_path=FILE the socket_wrapper library to preload
227 --uid_wrapper_so_path=FILE the uid_wrapper library to preload
230 --use-dns-faking Fake DNS entries rather than talking to our
234 --socket-wrapper-pcap save traffic to pcap directories
235 --socket-wrapper-keep-pcap keep all pcap files, not just those for tests that
237 --socket-wrapper enable socket wrapper
240 --ldap=openldap|fedora-ds back samba onto specified ldap server
243 --quick run quick overall test
244 --one abort when the first test fails
245 --testenv run a shell in the requested test environment
246 --list list available tests
251 my $result = GetOptions
(
252 'help|h|?' => \
$opt_help,
253 'target=s' => \
$opt_target,
254 'prefix=s' => \
$prefix,
255 'socket-wrapper' => \
$opt_socket_wrapper,
256 'socket-wrapper-pcap' => \
$opt_socket_wrapper_pcap,
257 'socket-wrapper-keep-pcap' => \
$opt_socket_wrapper_keep_pcap,
258 'quick' => \
$opt_quick,
260 'exclude=s' => \
@opt_exclude,
261 'include=s' => \
@opt_include,
262 'exclude-env=s' => \
@opt_exclude_env,
263 'include-env=s' => \
@opt_include_env,
264 'srcdir=s' => \
$srcdir,
265 'bindir=s' => \
$bindir,
266 'testenv' => \
$opt_testenv,
267 'list' => \
$opt_list,
268 'mitkrb5' => \
$opt_mitkrb5,
270 'resetup-environment' => \
$opt_resetup_env,
271 'testlist=s' => \
@testlists,
272 'random-order' => \
$opt_random_order,
273 'load-list=s' => \
$opt_load_list,
274 'nss_wrapper_so_path=s' => \
$opt_libnss_wrapper_so_path,
275 'resolv_wrapper_so_path=s' => \
$opt_libresolv_wrapper_so_path,
276 'socket_wrapper_so_path=s' => \
$opt_libsocket_wrapper_so_path,
277 'uid_wrapper_so_path=s' => \
$opt_libuid_wrapper_so_path,
278 'use-dns-faking' => \
$opt_use_dns_faking
281 exit(1) if (not $result);
283 ShowHelp
() if ($opt_help);
285 die("--list and --testenv are mutually exclusive") if ($opt_list and $opt_testenv);
287 # we want unbuffered output
292 # quick hack to disable rpc validation when using valgrind - its way too slow
293 unless (defined($ENV{VALGRIND
})) {
294 $ENV{VALIDATE
} = "validate";
295 $ENV{MALLOC_CHECK_
} = 3;
298 # make all our python scripts unbuffered
299 $ENV{PYTHONUNBUFFERED
} = 1;
301 my $bindir_abs = abs_path
($bindir);
303 # Backwards compatibility:
304 if (defined($ENV{TEST_LDAP
}) and $ENV{TEST_LDAP
} eq "yes") {
305 if (defined($ENV{FEDORA_DS_ROOT
})) {
312 my $torture_maxtime = ($ENV{TORTURE_MAXTIME
} or 1200);
315 $torture_maxtime *= 2;
322 die("using an empty prefix isn't allowed") unless $prefix ne "";
324 # Ensure we have the test prefix around.
326 # We need restrictive
327 # permissions on this as some subdirectories in this tree will have
328 # wider permissions (ie 0777) and this would allow other users on the
329 # host to subvert the test process.
331 mkdir($prefix, 0700) unless -d
$prefix;
333 # We need to have no umask limitations for the tests.
336 my $prefix_abs = abs_path
($prefix);
337 my $tmpdir_abs = abs_path
("$prefix/tmp");
338 mkdir($tmpdir_abs, 0777) unless -d
$tmpdir_abs;
340 my $srcdir_abs = abs_path
($srcdir);
342 die("using an empty absolute prefix isn't allowed") unless $prefix_abs ne "";
343 die("using '/' as absolute prefix isn't allowed") unless $prefix_abs ne "/";
345 $ENV{SAMBA_SELFTEST
} = "1";
347 $ENV{PREFIX
} = $prefix;
348 $ENV{PREFIX_ABS
} = $prefix_abs;
349 $ENV{SRCDIR
} = $srcdir;
350 $ENV{SRCDIR_ABS
} = $srcdir_abs;
351 $ENV{GNUPGHOME
} = "$srcdir_abs/selftest/gnupg";
352 $ENV{BINDIR
} = $bindir_abs;
354 my $tls_enabled = not $opt_quick;
355 $ENV{TLS_ENABLED
} = ($tls_enabled?
"yes":"no");
357 sub prefix_pathvar
($$)
359 my ($name, $newpath) = @_;
360 if (defined($ENV{$name})) {
361 $ENV{$name} = "$newpath:$ENV{$name}";
363 $ENV{$name} = $newpath;
366 prefix_pathvar
("PKG_CONFIG_PATH", "$bindir_abs/pkgconfig");
367 prefix_pathvar
("PYTHONPATH", "$bindir_abs/python");
369 if ($opt_socket_wrapper_keep_pcap) {
370 # Socket wrapper keep pcap implies socket wrapper pcap
371 $opt_socket_wrapper_pcap = 1;
374 if ($opt_socket_wrapper_pcap) {
375 # Socket wrapper pcap implies socket wrapper
376 $opt_socket_wrapper = 1;
379 my $ld_preload = $ENV{LD_PRELOAD
};
381 if ($opt_libnss_wrapper_so_path) {
383 $ld_preload = "$ld_preload:$opt_libnss_wrapper_so_path";
385 $ld_preload = "$opt_libnss_wrapper_so_path";
389 if ($opt_libresolv_wrapper_so_path) {
391 $ld_preload = "$ld_preload:$opt_libresolv_wrapper_so_path";
393 $ld_preload = "$opt_libresolv_wrapper_so_path";
397 if ($opt_libsocket_wrapper_so_path) {
399 $ld_preload = "$ld_preload:$opt_libsocket_wrapper_so_path";
401 $ld_preload = "$opt_libsocket_wrapper_so_path";
405 if ($opt_libuid_wrapper_so_path) {
407 $ld_preload = "$ld_preload:$opt_libuid_wrapper_so_path";
409 $ld_preload = "$opt_libuid_wrapper_so_path";
413 $ENV{LD_PRELOAD
} = $ld_preload;
414 print "LD_PRELOAD=$ENV{LD_PRELOAD}\n";
416 # Enable uid_wrapper globally
417 $ENV{UID_WRAPPER
} = 1;
419 # Disable RTLD_DEEPBIND hack for Samba bind dlz module
421 # This is needed in order to allow the ldb_*ldap module
422 # to work with a preloaded socket wrapper.
423 $ENV{LDB_MODULES_DISABLE_DEEPBIND
} = 1;
425 my $socket_wrapper_dir;
426 if ($opt_socket_wrapper) {
427 $socket_wrapper_dir = SocketWrapper
::setup_dir
("$prefix_abs/w", $opt_socket_wrapper_pcap);
428 print "SOCKET_WRAPPER_DIR=$socket_wrapper_dir\n";
429 } elsif (not $opt_list) {
431 warn("not using socket wrapper, but also not running as root. Will not be able to listen on proper ports");
435 if ($opt_use_dns_faking) {
436 print "DNS: Faking nameserver\n";
437 $ENV{SAMBA_DNS_FAKING
} = 1;
441 my $testenv_default = "none";
443 if ($opt_mitkrb5 == 1) {
444 $ENV{MITKRB5
} = $opt_mitkrb5;
447 # After this many seconds, the server will self-terminate. All tests
448 # must terminate in this time, and testenv will only stay alive this
453 # 1 year should be enough :-)
454 $server_maxtime = 365 * 24 * 60 * 60;
456 # make test should run under 5 hours
457 $server_maxtime = 5 * 60 * 60;
460 if (defined($ENV{SMBD_MAXTIME
}) and $ENV{SMBD_MAXTIME
} ne "") {
461 $server_maxtime = $ENV{SMBD_MAXTIME
};
464 $target = new Samba
($bindir, $ldap, $srcdir, $server_maxtime);
466 if ($opt_target eq "samba") {
467 $testenv_default = "ad_dc";
468 } elsif ($opt_target eq "samba3") {
469 $testenv_default = "nt4_member";
473 sub read_test_regexes
($)
477 open(LF
, "<$name") or die("unable to read $name: $!");
481 if (/^(.*?)([ \t]+)\#([\t ]*)(.*?)$/) {
482 push (@ret, [$1, $4]);
484 s/^(.*?)([ \t]+)\#([\t ]*)(.*?)$//;
485 push (@ret, [$_, undef]);
492 foreach (@opt_exclude) {
493 push (@excludes, read_test_regexes
($_));
496 foreach (@opt_include) {
497 push (@includes, read_test_regexes
($_));
500 my $interfaces = join(',', ("127.0.0.11/8",
507 my $clientdir = "$prefix_abs/client";
509 my $conffile = "$clientdir/client.conf";
510 $ENV{SMB_CONF_PATH
} = $conffile;
512 sub write_clientconf
($$$)
514 my ($conffile, $clientdir, $vars) = @_;
516 mkdir("$clientdir", 0777) unless -d
"$clientdir";
518 if ( -d
"$clientdir/private" ) {
519 unlink <$clientdir/private/*>;
521 mkdir("$clientdir/private", 0777);
524 if ( -d
"$clientdir/bind-dns" ) {
525 unlink <$clientdir/bind-dns/*>;
527 mkdir("$clientdir/bind-dns", 0777);
530 if ( -d
"$clientdir/lockdir" ) {
531 unlink <$clientdir/lockdir/*>;
533 mkdir("$clientdir/lockdir", 0777);
536 if ( -d
"$clientdir/statedir" ) {
537 unlink <$clientdir/statedir/*>;
539 mkdir("$clientdir/statedir", 0777);
542 if ( -d
"$clientdir/cachedir" ) {
543 unlink <$clientdir/cachedir/*>;
545 mkdir("$clientdir/cachedir", 0777);
548 # this is ugly, but the ncalrpcdir needs exactly 0755
549 # otherwise tests fail.
552 if ( -d
"$clientdir/ncalrpcdir/np" ) {
553 unlink <$clientdir/ncalrpcdir/np
/*>;
554 rmdir "$clientdir/ncalrpcdir/np";
556 if ( -d
"$clientdir/ncalrpcdir" ) {
557 unlink <$clientdir/ncalrpcdir/*>;
558 rmdir "$clientdir/ncalrpcdir";
560 mkdir("$clientdir/ncalrpcdir", 0755);
563 my $cadir = "$ENV{SRCDIR_ABS}/selftest/manage-ca/CA-samba.example.com";
564 my $cacert = "$cadir/Public/CA-samba.example.com-cert.pem";
565 my $cacrl_pem = "$cadir/Public/CA-samba.example.com-crl.pem";
566 my $ca_users_dir = "$cadir/Users";
568 if ( -d
"$clientdir/pkinit" ) {
569 unlink <$clientdir/pkinit/*>;
571 mkdir("$clientdir/pkinit", 0700);
574 # each user has a USER-${USER_PRINCIPAL_NAME}-cert.pem and
575 # USER-${USER_PRINCIPAL_NAME}-private-key.pem symlink
576 # We make a copy here and make the certificated easily
577 # accessable in the client environment.
580 opendir USERS
, "${ca_users_dir}" or die "Could not open dir '${ca_users_dir}': $!";
581 for my $d (readdir USERS
) {
582 my $user_dir = "${ca_users_dir}/${d}";
583 next if ${d
} =~ /^\./;
584 next if (! -d
"${user_dir}");
585 opendir USER
, "${user_dir}" or die "Could not open dir '${user_dir}': $!";
586 for my $l (readdir USER
) {
587 my $user_link = "${user_dir}/${l}";
588 next if ${l
} =~ /^\./;
589 next if (! -l
"${user_link}");
591 my $dest = "${clientdir}/pkinit/${l}";
592 Samba
::copy_file_content
(${user_link
}, ${dest
});
599 open(CF
, ">$conffile");
600 print CF
"[global]\n";
601 print CF
"\tnetbios name = client\n";
602 if (defined($vars->{DOMAIN
})) {
603 print CF
"\tworkgroup = $vars->{DOMAIN}\n";
605 if (defined($vars->{REALM
})) {
606 print CF
"\trealm = $vars->{REALM}\n";
608 if ($opt_socket_wrapper) {
609 print CF
"\tinterfaces = $interfaces\n";
612 private dir = $clientdir/private
613 binddns dir = $clientdir/bind-dns
614 lock dir = $clientdir/lockdir
615 state directory = $clientdir/statedir
616 cache directory = $clientdir/cachedir
617 ncalrpc dir = $clientdir/ncalrpcdir
618 panic action = $RealBin/gdb_backtrace \%d
620 notify:inotify = false
622 system:anonymous = true
623 client lanman auth = Yes
625 torture:basedir = $clientdir
626 #We don't want to pass our self-tests if the PAC code is wrong
627 gensec:require_pac = true
628 #We don't want to run 'speed' tests for very long
629 torture:timelimit = 1
630 winbind separator = /
631 tls cafile = ${cacert}
632 tls crlfile = ${cacrl_pem}
633 tls verify peer = no_check
634 include system krb5 conf = no
641 sub should_run_test
($)
647 for (my $i=0; $i <= $#tests; $i++) {
648 if ($name =~ /$tests[$i]/i) {
660 open(IN
, $filename) or die("Unable to open $filename: $!");
663 if (/-- TEST(-LOADLIST|) --\n/) {
664 my $supports_loadlist = (defined($1) and $1 eq "-LOADLIST");
670 if ($supports_loadlist) {
672 $loadlist =~ s/\n//g;
676 if (should_run_test
($name) == 1) {
677 push (@ret, [$name, $env, $cmdline, $loadlist]);
683 close(IN
) or die("Error creating recipe from $filename");
687 if ($#testlists == -1) {
688 die("No testlists specified");
691 $ENV{SELFTEST_PREFIX
} = "$prefix_abs";
692 $ENV{SELFTEST_TMPDIR
} = "$tmpdir_abs";
693 $ENV{TMPDIR
} = "$tmpdir_abs";
694 $ENV{TEST_DATA_PREFIX
} = "$tmpdir_abs";
695 if ($opt_socket_wrapper) {
696 $ENV{SELFTEST_INTERFACES
} = $interfaces;
698 $ENV{SELFTEST_INTERFACES
} = "";
701 $ENV{SELFTEST_QUICK
} = "1";
703 $ENV{SELFTEST_QUICK
} = "";
705 $ENV{SELFTEST_MAXTIME
} = $torture_maxtime;
707 my $selftest_krbt_ccache_path = "$tmpdir_abs/selftest.krb5_ccache";
708 $ENV{KRB5CCNAME
} = "FILE:${selftest_krbt_ccache_path}.global";
711 foreach my $fn (@testlists) {
712 foreach (read_testlist
($fn)) {
714 next if (@includes and not defined(find_in_list
(\
@includes, $name)));
715 push (@available, $_);
719 my $restricted = undef;
720 my $restricted_used = {};
722 if ($opt_load_list) {
724 open(LOAD_LIST
, "<$opt_load_list") or die("Unable to open $opt_load_list");
725 while (<LOAD_LIST
>) {
727 push (@
$restricted, $_);
732 my $individual_tests = undef;
733 $individual_tests = {};
735 foreach my $testsuite (@available) {
736 my $name = $$testsuite[0];
737 my $skipreason = skip
(@
$testsuite);
738 if (defined($restricted)) {
739 # Find the testsuite for this test
741 foreach my $r (@
$restricted) {
743 $individual_tests->{$name} = [];
745 $restricted_used->{$r} = 1;
746 } elsif (substr($r, 0, length($name)+1) eq "$name.") {
747 push(@
{$individual_tests->{$name}}, $r);
749 $restricted_used->{$r} = 1;
753 if (defined($skipreason)) {
755 Subunit
::skip_testsuite
($name, $skipreason);
758 push(@todo, $testsuite);
761 } elsif (defined($skipreason)) {
763 Subunit
::skip_testsuite
($name, $skipreason);
766 push(@todo, $testsuite);
770 if (defined($restricted)) {
771 foreach (@
$restricted) {
772 unless (defined($restricted_used->{$_})) {
773 print "No test or testsuite found matching $_\n";
776 } elsif ($#todo == -1) {
777 print STDERR
"No tests to run\n";
781 my $suitestotal = $#todo + 1;
784 Subunit
::progress
($suitestotal);
785 Subunit
::report_time
();
791 my %running_envs = ();
793 sub get_running_env
($)
801 return $running_envs{$envname};
804 my @exported_envvars = (
810 # stuff related to a trusted domain
821 # domain controller stuff
831 "MEMBER_SERVER_IPV6",
832 "MEMBER_NETBIOSNAME",
833 "MEMBER_NETBIOSALIAS",
835 # rpc proxy controller stuff
837 "RPC_PROXY_SERVER_IP",
838 "RPC_PROXY_SERVER_IPV6",
839 "RPC_PROXY_NETBIOSNAME",
840 "RPC_PROXY_NETBIOSALIAS",
842 # domain controller stuff for Vampired DC
844 "VAMPIRE_DC_SERVER_IP",
845 "VAMPIRE_DC_SERVER_IPV6",
846 "VAMPIRE_DC_NETBIOSNAME",
847 "VAMPIRE_DC_NETBIOSALIAS",
849 # domain controller stuff for RODC
852 "RODC_DC_SERVER_IPV6",
853 "RODC_DC_NETBIOSNAME",
855 # domain controller stuff for FL 2000 Vampired DC
856 "VAMPIRE_2000_DC_SERVER",
857 "VAMPIRE_2000_DC_SERVER_IP",
858 "VAMPIRE_2000_DC_SERVER_IPV6",
859 "VAMPIRE_2000_DC_NETBIOSNAME",
860 "VAMPIRE_2000_DC_NETBIOSALIAS",
862 "PROMOTED_DC_SERVER",
863 "PROMOTED_DC_SERVER_IP",
864 "PROMOTED_DC_SERVER_IPV6",
865 "PROMOTED_DC_NETBIOSNAME",
866 "PROMOTED_DC_NETBIOSALIAS",
883 # UID/GID for rfc2307 mapping tests
890 "SELFTEST_WINBINDD_SOCKET_DIR",
896 "UNACCEPTABLE_PASSWORD",
901 "NSS_WRAPPER_PASSWD",
904 "NSS_WRAPPER_HOSTNAME",
905 "NSS_WRAPPER_MODULE_SO_PATH",
906 "NSS_WRAPPER_MODULE_FN_PREFIX",
909 "RESOLV_WRAPPER_CONF",
910 "RESOLV_WRAPPER_HOSTS",
917 $SIG{INT
} = $SIG{QUIT
} = $SIG{TERM
} = 'DEFAULT';
918 $SIG{PIPE
} = 'IGNORE';
920 open(STDOUT
, ">&STDERR") or die "can't dup STDOUT to STDERR: $!";
922 print "$0: PID[$$]: Got SIG${signame} teardown environments.\n";
923 teardown_env
($_) foreach(keys %running_envs);
924 system("pstree -p $$");
925 print "$0: PID[$$]: Exiting...\n";
929 $SIG{INT
} = $SIG{QUIT
} = $SIG{TERM
} = $SIG{PIPE
} = \
&sighandler
;
933 my ($name, $prefix) = @_;
935 my $testenv_vars = undef;
941 $option =~ s/^[^:]*//;
944 $option = "client" if $option eq "";
946 # Initially clear out the environment for the provision, so previous envs'
947 # variables don't leak in. Provisioning steps must explicitly set their
948 # necessary variables when calling out to other executables
949 foreach (@exported_envvars) {
950 unless ($_ == "NSS_WRAPPER_HOSTS" ||
951 $_ == "RESOLV_WRAPPER_HOSTS")
956 delete $ENV{SOCKET_WRAPPER_DEFAULT_IFACE
};
957 delete $ENV{SMB_CONF_PATH
};
959 $ENV{KRB5CCNAME
} = "FILE:${selftest_krbt_ccache_path}.${envname}/ignore";
961 if (defined(get_running_env
($envname))) {
962 $testenv_vars = get_running_env
($envname);
963 if (not $testenv_vars->{target
}->check_env($testenv_vars)) {
964 print $testenv_vars->{target
}->getlog_env($testenv_vars);
965 $testenv_vars = undef;
968 $testenv_vars = $target->setup_env($envname, $prefix);
969 if (defined($testenv_vars) and $testenv_vars eq "UNKNOWN") {
970 return $testenv_vars;
971 } elsif (defined($testenv_vars) && not defined($testenv_vars->{target
})) {
972 $testenv_vars->{target
} = $target;
974 if (not defined($testenv_vars)) {
975 warn("$opt_target can't start up known environment '$envname'");
979 return undef unless defined($testenv_vars);
981 $running_envs{$envname} = $testenv_vars;
983 if ($option eq "local") {
984 SocketWrapper
::set_default_iface
($testenv_vars->{SOCKET_WRAPPER_DEFAULT_IFACE
});
985 $ENV{SMB_CONF_PATH
} = $testenv_vars->{SERVERCONFFILE
};
986 } elsif ($option eq "client") {
987 SocketWrapper
::set_default_iface
(11);
988 write_clientconf
($conffile, $clientdir, $testenv_vars);
989 $ENV{SMB_CONF_PATH
} = $conffile;
991 die("Unknown option[$option] for envname[$envname]");
994 foreach (@exported_envvars) {
995 if (defined($testenv_vars->{$_})) {
996 $ENV{$_} = $testenv_vars->{$_};
1002 my $krb5_ccache_path = "${selftest_krbt_ccache_path}.${envname}.${option}";
1003 unlink($krb5_ccache_path);
1004 $ENV{KRB5CCNAME
} = "FILE:${krb5_ccache_path}";
1005 return $testenv_vars;
1008 sub exported_envvars_str
($)
1010 my ($testenv_vars) = @_;
1013 foreach (@exported_envvars) {
1014 next unless defined($testenv_vars->{$_});
1015 $out .= $_."=".$testenv_vars->{$_}."\n";
1024 return "" if ($envname eq "none");
1025 my $env = get_running_env
($envname);
1026 return $env->{target
}->getlog_env($env);
1032 my $env = get_running_env
($envname);
1033 return $env->{target
}->check_env($env);
1039 return if ($envname eq "none");
1040 print STDERR
"teardown_env($envname)\n";
1041 my $env = get_running_env
($envname);
1042 $env->{target
}->teardown_env($env);
1043 delete $running_envs{$envname};
1046 # This 'global' file needs to be empty when we start
1047 unlink("$prefix_abs/dns_host_file");
1048 unlink("$prefix_abs/hosts");
1050 if ($opt_random_order) {
1052 my @newtodo = List
::Util
::shuffle
(@todo);
1057 my $testenv_name = $ENV{SELFTEST_TESTENV
};
1058 $testenv_name = $testenv_default unless defined($testenv_name);
1060 my $testenv_vars = setup_env
($testenv_name, $prefix);
1062 if (not $testenv_vars or $testenv_vars eq "UNKNOWN") {
1063 die("Unable to setup environment $testenv_name");
1066 $ENV{PIDDIR
} = $testenv_vars->{PIDDIR
};
1067 $ENV{ENVNAME
} = $testenv_name;
1069 my $envvarstr = exported_envvars_str
($testenv_vars);
1071 my @term_args = ("echo -e \"
1072 Welcome to the Samba4 Test environment '$testenv_name'
1074 This matches the client environment used in make test
1075 server is pid `cat \$PIDDIR/samba.pid`
1077 Some useful environment variables:
1078 TORTURE_OPTIONS=\$TORTURE_OPTIONS
1079 SMB_CONF_PATH=\$SMB_CONF_PATH
1082 \" && LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH} bash");
1084 if ($ENV{TERMINAL
}) {
1085 @term = ($ENV{TERMINAL
});
1087 @term = ("xterm", "-e");
1088 unshift(@term_args, ("bash", "-c"));
1091 system(@term, @term_args);
1093 teardown_env
($testenv_name);
1094 } elsif ($opt_list) {
1097 my $envname = $$_[1];
1099 my $listcmd = $$_[3];
1101 unless (defined($listcmd)) {
1102 warn("Unable to list tests in $name");
1103 # Rather than ignoring this testsuite altogether, just pretend the entire testsuite is
1112 die("Unable to run $listcmd: $!");
1113 } elsif ($?
& 127) {
1114 die(sprintf("%s died with signal %d, %s coredump\n", $listcmd, ($?
& 127), ($?
& 128) ?
'with' : 'without'));
1117 my $exitcode = $?
>> 8;
1118 if ($exitcode != 0) {
1119 die("$cmd exited with exit code $exitcode");
1127 my $envname = $$_[1];
1128 my $envvars = setup_env
($envname, $prefix);
1130 if (not defined($envvars)) {
1131 Subunit
::start_testsuite
($name);
1132 Subunit
::end_testsuite
($name, "error",
1133 "unable to set up environment $envname - exiting");
1135 } elsif ($envvars eq "UNKNOWN") {
1136 Subunit
::start_testsuite
($name);
1137 Subunit
::end_testsuite
($name, "error",
1138 "environment $envname is unknown - exiting");
1142 # Generate a file with the individual tests to run, if the
1143 # test runner for this test suite supports it.
1144 if ($individual_tests and $individual_tests->{$name}) {
1146 my ($fh, $listid_file) = tempfile
(UNLINK
=> 0);
1147 foreach my $test (@
{$individual_tests->{$name}}) {
1148 print $fh substr($test, length($name)+1) . "\n";
1150 $cmd =~ s/\$LOADLIST/--load-list=$listid_file/g;
1152 warn("Unable to run individual tests in $name, it does not support --loadlist.");
1156 run_testsuite
($envname, $name, $cmd, $i, $suitestotal);
1158 teardown_env
($envname) if ($opt_resetup_env);
1164 teardown_env
($_) foreach (keys %running_envs);
1168 # if there were any valgrind failures, show them
1169 foreach (<$prefix/valgrind
.log*>) {
1170 next unless (-s
$_);
1171 print "VALGRIND FAILURE\n";