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/>.
22 use FindBin
qw($RealBin $Script);
24 use File::Temp qw(tempfile);
25 use File
::Path
qw(remove_tree);
33 use Time
::HiRes
qw(time);
37 Time
::HiRes
->import("time");
40 print "You don't have Time::Hires installed !\n";
44 my $opt_target = "samba";
46 my $opt_socket_wrapper = 0;
47 my $opt_socket_wrapper_pcap = undef;
48 my $opt_socket_wrapper_keep_pcap = undef;
49 my $opt_random_order = 0;
53 my @opt_exclude_env = ();
54 my @opt_include_env = ();
58 my $opt_default_ldb_backend = "mdb";
59 my $opt_resetup_env = undef;
60 my $opt_load_list = undef;
61 my $opt_libnss_wrapper_so_path = "";
62 my $opt_libresolv_wrapper_so_path = "";
63 my $opt_libsocket_wrapper_so_path = "";
64 my $opt_libuid_wrapper_so_path = "";
65 my $opt_libasan_so_path = "";
66 my $opt_libcrypt_so_path = "";
67 my $opt_use_dns_faking = 0;
79 my ($list, $fullname) = @_;
82 if ($fullname =~ /$$_[0]/) {
83 return ($$_[1]) if ($$_[1]);
93 my ($name, $envname) = @_;
94 my ($env_basename, $env_localpart) = split(/:/, $envname);
96 if ($opt_target eq "samba3" && $Samba::ENV_NEEDS_AD_DC
{$env_basename}) {
97 return "environment $envname is disabled as this build does not include an AD DC";
100 if (@opt_include_env && !(grep {$_ eq $env_basename} @opt_include_env)) {
101 return "environment $envname is disabled (via --include-env command line option) in this test run - skipping";
102 } elsif (@opt_exclude_env && grep {$_ eq $env_basename} @opt_exclude_env) {
103 return "environment $envname is disabled (via --exclude-env command line option) in this test run - skipping";
106 return find_in_list
(\
@excludes, $name);
111 # expand strings from %ENV
112 sub expand_environment_strings
($)
115 # we use a reverse sort so we do the longer ones first
116 foreach my $k (sort { $b cmp $a } keys %ENV) {
117 $s =~ s/\$$k/$ENV{$k}/g;
124 sub run_testsuite
($$$$$)
126 my ($envname, $name, $cmd, $i, $totalsuites) = @_;
127 my $pcap_file = $target->setup_pcap($name);
129 Subunit
::start_testsuite
($name);
130 Subunit
::progress_push
();
131 Subunit
::report_time
();
132 # Enable pipefail so that we catch failing testsuites that are part of a
133 # pipeline (typically, piped through filter-subunit). This won't catch
134 # any testsuite failures that are turned into testsuite-xfails by
136 system("bash", "-o", "pipefail", "-c", $cmd);
137 Subunit
::report_time
();
138 Subunit
::progress_pop
();
141 print "command: $cmd\n";
142 printf "expanded command: %s\n", expand_environment_strings
($cmd);
143 Subunit
::end_testsuite
($name, "error", "Unable to run $cmd: $!");
146 print "command: $cmd\n";
147 printf "expanded command: %s\n", expand_environment_strings
($cmd);
148 Subunit
::end_testsuite
($name, "error",
149 sprintf("%s died with signal %d, %s coredump\n", $cmd, ($?
& 127), ($?
& 128) ?
'with' : 'without'));
153 my $exitcode = $?
>> 8;
155 my $envlog = getlog_env
($envname);
157 print "envlog: $envlog\n";
160 print "command: $cmd\n";
161 printf "expanded command: %s\n", expand_environment_strings
($cmd);
163 if ($exitcode == 0) {
164 Subunit
::end_testsuite
($name, "success");
166 Subunit
::end_testsuite
($name, "failure", "Exit code was $exitcode");
169 $target->cleanup_pcap($pcap_file, $exitcode);
171 if (not $opt_socket_wrapper_keep_pcap and defined($pcap_file)) {
172 print "PCAP FILE: $pcap_file\n";
175 if ($exitcode != 0) {
176 exit(1) if ($opt_one);
184 print "Samba test runner
185 Copyright (C) Jelmer Vernooij <jelmer\@samba.org>
186 Copyright (C) Stefan Metzmacher <metze\@samba.org>
188 Usage: $Script [OPTIONS] TESTNAME-REGEX [TESTNAME-REGEX...]
191 --help this help page
192 --target=samba[3]|win Samba version to target
193 --testlist=FILE file to read available tests from
194 --exclude=FILE Exclude tests listed in the file
195 --include=FILE Include tests listed in the file
196 --exclude-env=ENV Exclude tests for the specified environment
197 --include-env=ENV Include tests for the specified environment
200 --prefix=DIR prefix to run tests in [st]
201 --srcdir=DIR source directory [.]
202 --bindir=DIR binaries directory [./bin]
205 --nss_wrapper_so_path=FILE the nss_wrapper library to preload
206 --resolv_wrapper_so_path=FILE the resolv_wrapper library to preload
207 --socket_wrapper_so_path=FILE the socket_wrapper library to preload
208 --uid_wrapper_so_path=FILE the uid_wrapper library to preload
209 --asan_so_path=FILE the asan library to preload
212 --use-dns-faking Fake DNS entries rather than talking to our
216 --socket-wrapper-pcap save traffic to pcap directories
217 --socket-wrapper-keep-pcap keep all pcap files, not just those for tests that
219 --socket-wrapper enable socket wrapper
222 --quick run quick overall test
223 --one abort when the first test fails
224 --testenv run a shell in the requested test environment
225 --list list available tests
230 my $result = GetOptions
(
231 'help|h|?' => \
$opt_help,
232 'target=s' => \
$opt_target,
233 'prefix=s' => \
$prefix,
234 'socket-wrapper' => \
$opt_socket_wrapper,
235 'socket-wrapper-pcap' => \
$opt_socket_wrapper_pcap,
236 'socket-wrapper-keep-pcap' => \
$opt_socket_wrapper_keep_pcap,
237 'quick' => \
$opt_quick,
239 'exclude=s' => \
@opt_exclude,
240 'include=s' => \
@opt_include,
241 'exclude-env=s' => \
@opt_exclude_env,
242 'include-env=s' => \
@opt_include_env,
243 'srcdir=s' => \
$srcdir,
244 'bindir=s' => \
$bindir,
245 'testenv' => \
$opt_testenv,
246 'list' => \
$opt_list,
247 'mitkrb5' => \
$opt_mitkrb5,
248 'default-ldb-backend=s' => \
$opt_default_ldb_backend,
249 'resetup-environment' => \
$opt_resetup_env,
250 'testlist=s' => \
@testlists,
251 'random-order' => \
$opt_random_order,
252 'load-list=s' => \
$opt_load_list,
253 'nss_wrapper_so_path=s' => \
$opt_libnss_wrapper_so_path,
254 'resolv_wrapper_so_path=s' => \
$opt_libresolv_wrapper_so_path,
255 'socket_wrapper_so_path=s' => \
$opt_libsocket_wrapper_so_path,
256 'uid_wrapper_so_path=s' => \
$opt_libuid_wrapper_so_path,
257 'asan_so_path=s' => \
$opt_libasan_so_path,
258 'crypt_so_path=s' => \
$opt_libcrypt_so_path,
259 'use-dns-faking' => \
$opt_use_dns_faking
262 exit(1) if (not $result);
264 ShowHelp
() if ($opt_help);
266 die("--list and --testenv are mutually exclusive") if ($opt_list and $opt_testenv);
268 # we want unbuffered output
273 # quick hack to disable rpc validation when using valgrind - its way too slow
274 unless (defined($ENV{VALGRIND
})) {
275 $ENV{VALIDATE
} = "validate";
276 $ENV{MALLOC_CHECK_
} = 3;
279 # make all our python scripts unbuffered
280 $ENV{PYTHONUNBUFFERED
} = 1;
282 $ENV{SAMBA_DEPRECATED_SUPPRESS
} = 1;
284 # do not depend on the users setup
285 # see also bootstrap/config.py
287 $ENV{LC_ALL
} = $ENV{LANG
} = "en_US.utf8";
288 $ENV{LANGUAGE
} = "en_US";
290 my $bindir_abs = abs_path
($bindir);
292 my $torture_maxtime = ($ENV{TORTURE_MAXTIME
} or 1200);
295 $prefix =~ s
+/\./+/+;
298 die("using an empty prefix isn't allowed") unless $prefix ne "";
300 # Ensure we have the test prefix around.
302 # We need restrictive
303 # permissions on this as some subdirectories in this tree will have
304 # wider permissions (ie 0777) and this would allow other users on the
305 # host to subvert the test process.
307 mkdir($prefix, 0700) unless -d
$prefix;
309 # We need to have no umask limitations for the tests.
312 my $prefix_abs = abs_path
($prefix);
313 my $tmpdir_abs = abs_path
("$prefix/tmp");
314 mkdir($tmpdir_abs, 0777) unless -d
$tmpdir_abs;
316 my $srcdir_abs = abs_path
($srcdir);
318 die("using an empty absolute prefix isn't allowed") unless $prefix_abs ne "";
319 die("using '/' as absolute prefix isn't allowed") unless $prefix_abs ne "/";
321 $ENV{SAMBA_SELFTEST
} = "1";
323 $ENV{PREFIX
} = $prefix;
324 $ENV{PREFIX_ABS
} = $prefix_abs;
325 $ENV{SRCDIR
} = $srcdir;
326 $ENV{SRCDIR_ABS
} = $srcdir_abs;
327 $ENV{BINDIR
} = $bindir_abs;
329 my $tls_enabled = not $opt_quick;
330 $ENV{TLS_ENABLED
} = ($tls_enabled?
"yes":"no");
332 sub prefix_pathvar
($$)
334 my ($name, $newpath) = @_;
335 if (defined($ENV{$name})) {
336 $ENV{$name} = "$newpath:$ENV{$name}";
338 $ENV{$name} = $newpath;
341 prefix_pathvar
("PKG_CONFIG_PATH", "$bindir_abs/pkgconfig");
342 prefix_pathvar
("PYTHONPATH", "$bindir_abs/python");
344 if ($opt_socket_wrapper_keep_pcap) {
345 # Socket wrapper keep pcap implies socket wrapper pcap
346 $opt_socket_wrapper_pcap = 1;
349 if ($opt_socket_wrapper_pcap) {
350 # Socket wrapper pcap implies socket wrapper
351 $opt_socket_wrapper = 1;
354 my $ld_preload = $ENV{LD_PRELOAD
};
356 if ($opt_libasan_so_path) {
358 if ($opt_libcrypt_so_path) {
359 $ld_preload = "$opt_libasan_so_path:$opt_libcrypt_so_path:$ld_preload";
361 $ld_preload = "$opt_libasan_so_path:$ld_preload";
364 if ($opt_libcrypt_so_path) {
365 $ld_preload = "$opt_libasan_so_path:$opt_libcrypt_so_path";
367 $ld_preload = "$opt_libasan_so_path";
372 if ($opt_libnss_wrapper_so_path) {
374 $ld_preload = "$ld_preload:$opt_libnss_wrapper_so_path";
376 $ld_preload = "$opt_libnss_wrapper_so_path";
380 if ($opt_libresolv_wrapper_so_path) {
382 $ld_preload = "$ld_preload:$opt_libresolv_wrapper_so_path";
384 $ld_preload = "$opt_libresolv_wrapper_so_path";
388 if ($opt_libsocket_wrapper_so_path) {
390 $ld_preload = "$ld_preload:$opt_libsocket_wrapper_so_path";
392 $ld_preload = "$opt_libsocket_wrapper_so_path";
396 if ($opt_libuid_wrapper_so_path) {
398 $ld_preload = "$ld_preload:$opt_libuid_wrapper_so_path";
400 $ld_preload = "$opt_libuid_wrapper_so_path";
404 if (defined($ENV{USE_NAMESPACES
})) {
405 print "Using linux containerization for selftest testenv(s)...\n";
407 # Create a common bridge to connect up the testenv namespaces. We give
408 # it the client's IP address, as this is where the tests will run from
409 my $ipv4_addr = Samba
::get_ipv4_addr
("client");
410 my $ipv6_addr = Samba
::get_ipv6_addr
("client");
411 system "$ENV{SRCDIR_ABS}/selftest/ns/create_bridge.sh selftest0 $ipv4_addr $ipv6_addr";
414 $ENV{LD_PRELOAD
} = $ld_preload;
415 print "LD_PRELOAD=$ENV{LD_PRELOAD}\n";
417 # Enable uid_wrapper globally
418 $ENV{UID_WRAPPER
} = 1;
420 # We are already hitting the limit, so double it.
421 $ENV{NSS_WRAPPER_MAX_HOSTENTS
} = 200;
423 # Disable RTLD_DEEPBIND hack for Samba bind dlz module
425 # This is needed in order to allow the ldb_*ldap module
426 # to work with a preloaded socket wrapper.
427 $ENV{LDB_MODULES_DISABLE_DEEPBIND
} = 1;
429 my $socket_wrapper_dir;
430 if ($opt_socket_wrapper) {
431 $socket_wrapper_dir = SocketWrapper
::setup_dir
("$prefix_abs/w", $opt_socket_wrapper_pcap);
432 print "SOCKET_WRAPPER_DIR=$socket_wrapper_dir\n";
433 } elsif (not $opt_list) {
435 warn("not using socket wrapper, but also not running as root. Will not be able to listen on proper ports");
439 if ($opt_use_dns_faking) {
440 print "DNS: Faking nameserver\n";
441 $ENV{SAMBA_DNS_FAKING
} = 1;
444 my $testenv_default = "none";
446 if ($opt_mitkrb5 == 1) {
447 $ENV{MITKRB5
} = $opt_mitkrb5;
448 $ENV{KRB5RCACHETYPE
} = "none";
451 # After this many seconds, the server will self-terminate. All tests
452 # must terminate in this time, and testenv will only stay alive this
457 # 1 year should be enough :-)
458 $server_maxtime = 365 * 24 * 60 * 60;
460 # make test should run under 5 hours
461 $server_maxtime = 5 * 60 * 60;
464 if (defined($ENV{SMBD_MAXTIME
}) and $ENV{SMBD_MAXTIME
} ne "") {
465 $server_maxtime = $ENV{SMBD_MAXTIME
};
468 $target = new Samba
($bindir, $srcdir, $server_maxtime,
469 $opt_socket_wrapper_pcap,
470 $opt_socket_wrapper_keep_pcap,
471 $opt_default_ldb_backend);
473 if ($opt_target eq "samba") {
474 $testenv_default = "ad_dc";
475 } elsif ($opt_target eq "samba3") {
476 $testenv_default = "nt4_member";
480 sub read_test_regexes
($)
484 open(LF
, "<$name") or die("unable to read $name: $!");
488 if (/^(.*?)([ \t]+)\#([\t ]*)(.*?)$/) {
489 push (@ret, [$1, $4]);
491 s/^(.*?)([ \t]+)\#([\t ]*)(.*?)$//;
492 push (@ret, [$_, undef]);
499 foreach (@opt_exclude) {
500 push (@excludes, read_test_regexes
($_));
503 foreach (@opt_include) {
504 push (@includes, read_test_regexes
($_));
507 # We give the selftest client 6 different IPv4 addresses to use. Most tests
508 # only use the first (.11) IP. Note that winsreplication.c is one test that
509 # uses the other IPs (search for iface_list_count()).
510 $ENV{SOCKET_WRAPPER_IPV4_NETWORK
} = "10.53.57.0";
511 my $interfaces = Samba
::get_interfaces_config
("client", 6);
513 my $clientdir = "$prefix_abs/client";
515 my $conffile = "$clientdir/client.conf";
516 $ENV{SMB_CONF_PATH
} = $conffile;
518 sub write_clientconf
($$$)
520 my ($conffile, $clientdir, $vars) = @_;
522 mkdir("$clientdir", 0777) unless -d
"$clientdir";
525 { name
=> "private", mask
=> 0777 },
526 { name
=> "bind-dns", mask
=> 0777 },
527 { name
=> "lockdir", mask
=> 0777 },
528 { name
=> "statedir", mask
=> 0777 },
529 { name
=> "cachedir", mask
=> 0777 },
530 { name
=> "pkinit", mask
=> 0700 },
531 { name
=> "pid", mask
=> 0777 },
532 # the ncalrpcdir needs exactly 0755 otherwise tests fail.
533 { name
=> "ncalrpcdir", mask
=> 0755, umask => 0022 },
536 foreach my $sub (@subdirs) {
537 my $dir = "$clientdir/$sub->{name}";
540 if (defined($sub->{umask})) {
543 mkdir($dir, $sub->{mask
});
547 my $cadir = "$ENV{SRCDIR_ABS}/selftest/manage-ca/CA-samba.example.com";
548 my $cacert = "$cadir/Public/CA-samba.example.com-cert.pem";
549 my $cacrl_pem = "$cadir/Public/CA-samba.example.com-crl.pem";
550 my $ca_users_dir = "$cadir/Users";
551 my $client_loglevel = $ENV{CLIENT_LOG_LEVEL
} || 1;
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 # accessible 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 binddns dir = $clientdir/bind-dns
593 lock dir = $clientdir/lockdir
594 state directory = $clientdir/statedir
595 cache directory = $clientdir/cachedir
596 ncalrpc dir = $clientdir/ncalrpcdir
597 pid directory = $clientdir/pid
598 panic action = $RealBin/gdb_backtrace \%d
600 notify:inotify = false
602 system:anonymous = true
603 client lanman auth = Yes
604 client min protocol = CORE
605 log level = $client_loglevel
606 torture:basedir = $clientdir
607 #We don't want to run 'speed' tests for very long
608 torture:timelimit = 1
609 winbind separator = /
610 tls cafile = ${cacert}
611 tls crlfile = ${cacrl_pem}
612 tls verify peer = no_check
613 include system krb5 conf = no
614 elasticsearch:mappings = $srcdir_abs/source3/rpc_server/mdssvc/elasticsearch_mappings.json
621 sub should_run_test
($)
627 for (my $i=0; $i <= $#tests; $i++) {
628 if ($name =~ /$tests[$i]/i) {
640 open(IN
, $filename) or die("Unable to open $filename: $!");
643 if (/-- TEST(-LOADLIST|) --\n/) {
644 my $supports_loadlist = (defined($1) and $1 eq "-LOADLIST");
650 if ($supports_loadlist) {
652 $loadlist =~ s/\n//g;
656 if (should_run_test
($name) == 1) {
657 push (@ret, [$name, $env, $cmdline, $loadlist]);
663 close(IN
) or die("Error creating recipe from $filename");
667 if ($#testlists == -1) {
668 die("No testlists specified");
671 $ENV{SELFTEST_PREFIX
} = "$prefix_abs";
672 $ENV{SELFTEST_TMPDIR
} = "$tmpdir_abs";
673 $ENV{TMPDIR
} = "$tmpdir_abs";
674 $ENV{TEST_DATA_PREFIX
} = "$tmpdir_abs";
676 $ENV{SELFTEST_QUICK
} = "1";
678 $ENV{SELFTEST_QUICK
} = "";
680 $ENV{SELFTEST_MAXTIME
} = $torture_maxtime;
682 my $selftest_resolv_conf_path = "$tmpdir_abs/selftest.resolv.conf";
683 $ENV{RESOLV_CONF
} = "${selftest_resolv_conf_path}.global";
685 my $selftest_krbt_ccache_path = "$tmpdir_abs/selftest.krb5_ccache";
686 $ENV{KRB5CCNAME
} = "FILE:${selftest_krbt_ccache_path}.global";
688 my $selftest_gnupghome_path = "$tmpdir_abs/selftest.no.gnupg";
689 $ENV{GNUPGHOME
} = "${selftest_gnupghome_path}.global";
692 foreach my $fn (@testlists) {
693 foreach (read_testlist
($fn)) {
695 next if (@includes and not defined(find_in_list
(\
@includes, $name)));
696 push (@available, $_);
700 my $restricted = undef;
701 my $restricted_used = {};
703 if ($opt_load_list) {
705 open(LOAD_LIST
, "<$opt_load_list") or die("Unable to open $opt_load_list");
706 while (<LOAD_LIST
>) {
708 push (@
$restricted, $_);
713 my $individual_tests = undef;
714 $individual_tests = {};
716 foreach my $testsuite (@available) {
717 my $name = $$testsuite[0];
718 my $skipreason = skip
(@
$testsuite);
719 if (defined($restricted)) {
720 # Find the testsuite for this test
722 foreach my $r (@
$restricted) {
724 $individual_tests->{$name} = [];
726 $restricted_used->{$r} = 1;
727 } elsif (substr($r, 0, length($name)+1) eq "$name.") {
728 push(@
{$individual_tests->{$name}}, $r);
730 $restricted_used->{$r} = 1;
734 if (defined($skipreason)) {
736 Subunit
::skip_testsuite
($name, $skipreason);
739 push(@todo, $testsuite);
742 } elsif (defined($skipreason)) {
744 Subunit
::skip_testsuite
($name, $skipreason);
747 push(@todo, $testsuite);
751 if (defined($restricted)) {
752 foreach (@
$restricted) {
753 unless (defined($restricted_used->{$_})) {
754 print "No test or testsuite found matching $_\n";
757 } elsif ($#todo == -1) {
758 print STDERR
"No tests to run\n";
762 my $suitestotal = $#todo + 1;
765 Subunit
::progress
($suitestotal);
766 Subunit
::report_time
();
772 my %running_envs = ();
774 sub get_running_env
($)
782 return $running_envs{$envname};
789 $SIG{INT
} = $SIG{QUIT
} = $SIG{TERM
} = 'DEFAULT';
790 $SIG{PIPE
} = 'IGNORE';
792 open(STDOUT
, ">&STDERR") or die "can't dup STDOUT to STDERR: $!";
794 print "$0: PID[$$]: Got SIG${signame} teardown environments.\n";
795 teardown_env
($_) foreach(keys %running_envs);
796 system("pstree -p $$");
797 print "$0: PID[$$]: Exiting...\n";
801 $SIG{INT
} = $SIG{QUIT
} = $SIG{TERM
} = $SIG{PIPE
} = \
&sighandler
;
805 my ($name, $prefix) = @_;
807 my $testenv_vars = undef;
813 $option =~ s/^[^:]*//;
816 $option = "client" if $option eq "";
818 # Initially clear out the environment for the provision, so previous envs'
819 # variables don't leak in. Provisioning steps must explicitly set their
820 # necessary variables when calling out to other executables
821 Samba
::clear_exported_envvars
();
822 delete $ENV{SOCKET_WRAPPER_DEFAULT_IFACE
};
823 delete $ENV{SMB_CONF_PATH
};
825 $ENV{RESOLV_CONF
} = "${selftest_resolv_conf_path}.${envname}/ignore";
826 $ENV{KRB5CCNAME
} = "FILE:${selftest_krbt_ccache_path}.${envname}/ignore";
827 $ENV{GNUPGHOME
} = "${selftest_gnupghome_path}.${envname}/ignore";
829 if (defined(get_running_env
($envname))) {
830 $testenv_vars = get_running_env
($envname);
831 if (not $testenv_vars->{target
}->check_env($testenv_vars)) {
832 print $testenv_vars->{target
}->getlog_env($testenv_vars);
833 $testenv_vars = undef;
836 $testenv_vars = $target->setup_env($envname, $prefix);
837 if (not defined($testenv_vars)) {
838 my $msg = "$opt_target can't start up known environment '$envname'";
845 if (ref $testenv_vars ne "HASH") {
846 return $testenv_vars;
848 if (defined($testenv_vars->{target
})) {
849 $testenv_vars->{target
} = $target;
853 return undef unless defined($testenv_vars);
855 $running_envs{$envname} = $testenv_vars;
857 if ($option eq "local") {
858 SocketWrapper
::set_default_iface
($testenv_vars->{SOCKET_WRAPPER_DEFAULT_IFACE
});
859 $ENV{SMB_CONF_PATH
} = $testenv_vars->{SERVERCONFFILE
};
860 } elsif ($option eq "client") {
861 SocketWrapper
::set_default_iface
(11);
862 write_clientconf
($conffile, $clientdir, $testenv_vars);
863 $ENV{SMB_CONF_PATH
} = $conffile;
865 die("Unknown option[$option] for envname[$envname]");
868 # export the environment variables for the testenv (SERVER, SERVER_IP, etc)
869 Samba
::export_envvars
($testenv_vars);
871 my $krb5_ccache_path = "${selftest_krbt_ccache_path}.${envname}.${option}";
872 unlink($krb5_ccache_path);
873 $ENV{KRB5CCNAME
} = "FILE:${krb5_ccache_path}";
874 return $testenv_vars;
880 return "" if ($envname eq "none");
881 my $env = get_running_env
($envname);
882 return $env->{target
}->getlog_env($env);
888 my $env = get_running_env
($envname);
889 return $env->{target
}->check_env($env);
895 return if ($envname eq "none");
896 print STDERR
"teardown_env($envname)\n";
897 my $env = get_running_env
($envname);
898 $env->{target
}->teardown_env($env);
899 delete $running_envs{$envname};
902 # This 'global' file needs to be empty when we start
903 unlink("$prefix_abs/dns_host_file");
904 unlink("$prefix_abs/hosts");
906 if ($opt_random_order) {
908 my @newtodo = List
::Util
::shuffle
(@todo);
913 my $testenv_name = $ENV{SELFTEST_TESTENV
};
914 $testenv_name = $testenv_default unless defined($testenv_name);
916 my $testenv_vars = setup_env
($testenv_name, $prefix);
918 if (not $testenv_vars or $testenv_vars eq "UNKNOWN") {
919 die("Unable to setup environment $testenv_name");
922 $ENV{PIDDIR
} = $testenv_vars->{PIDDIR
};
923 $ENV{ENVNAME
} = $testenv_name;
925 my $envvarstr = Samba
::exported_envvars_str
($testenv_vars);
927 my @term_args = ("echo -e \"
928 Welcome to the Samba4 Test environment '$testenv_name'
930 This matches the client environment used in make test
931 server is pid `cat \$PIDDIR/samba.pid`
933 Some useful environment variables:
934 TORTURE_OPTIONS=\$TORTURE_OPTIONS
935 SMB_CONF_PATH=\$SMB_CONF_PATH
938 \" && LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH} bash");
940 if ($ENV{TERMINAL
}) {
941 @term = ($ENV{TERMINAL
});
942 # override the default terminal args (if specified)
943 if (defined($ENV{TERMINAL_ARGS
})) {
944 @term_args = split(/ /, $ENV{TERMINAL_ARGS
});
947 @term = ("xterm", "-e");
948 unshift(@term_args, ("bash", "-c"));
951 system(@term, @term_args);
953 teardown_env
($testenv_name);
954 } elsif ($opt_list) {
957 my $envname = $$_[1];
959 my $listcmd = $$_[3];
961 unless (defined($listcmd)) {
962 warn("Unable to list tests in $name");
963 # Rather than ignoring this testsuite altogether, just pretend the entire testsuite is
972 die("Unable to run $listcmd: $!");
974 die(sprintf("%s died with signal %d, %s coredump\n", $listcmd, ($?
& 127), ($?
& 128) ?
'with' : 'without'));
977 my $exitcode = $?
>> 8;
978 if ($exitcode != 0) {
979 die("$cmd exited with exit code $exitcode");
987 my $envname = $$_[1];
988 my $envvars = setup_env
($envname, $prefix);
990 if (not defined($envvars)) {
991 Subunit
::start_testsuite
($name);
992 Subunit
::end_testsuite
($name, "error",
993 "unable to set up environment $envname - exiting");
995 } elsif ($envvars eq "UNKNOWN") {
996 Subunit
::start_testsuite
($name);
997 Subunit
::end_testsuite
($name, "error",
998 "environment $envname is unknown - exiting");
1002 # Generate a file with the individual tests to run, if the
1003 # test runner for this test suite supports it.
1004 if ($individual_tests and $individual_tests->{$name}) {
1006 my ($fh, $listid_file) = tempfile
(UNLINK
=> 0);
1007 foreach my $test (@
{$individual_tests->{$name}}) {
1008 print $fh substr($test, length($name)+1) . "\n";
1010 $cmd =~ s/\$LOADLIST/--load-list=$listid_file/g;
1012 warn("Unable to run individual tests in $name, it does not support --loadlist.");
1016 run_testsuite
($envname, $name, $cmd, $i, $suitestotal);
1018 teardown_env
($envname) if ($opt_resetup_env);
1024 teardown_env
($_) foreach (keys %running_envs);
1028 # if there were any valgrind failures, show them
1029 foreach (<$prefix/valgrind
.log*>) {
1030 next unless (-s
$_);
1031 print "VALGRIND FAILURE\n";