s3-builtin: Add some builtin groups.
[Samba/bjacke.git] / selftest / selftest.pl
blob7bbad62bbf8f2cb520d5c6ff6af193855495be61
1 #!/usr/bin/perl
2 # Bootstrap Samba and run a number of tests against it.
3 # Copyright (C) 2005-2009 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/>.
19 =pod
21 =head1 NAME
23 selftest - Samba test runner
25 =head1 SYNOPSIS
27 selftest --help
29 selftest [--srcdir=DIR] [--builddir=DIR] [--exeext=EXT][--target=samba4|samba3|win|kvm] [--socket-wrapper] [--quick] [--exclude=FILE] [--include=FILE] [--one] [--prefix=prefix] [--testlist=FILE] [TESTS]
31 =head1 DESCRIPTION
33 A simple test runner. TESTS is a regular expression with tests to run.
35 =head1 OPTIONS
37 =over 4
39 =item I<--help>
41 Show list of available options.
43 =item I<--srcdir=DIR>
45 Source directory.
47 =item I<--builddir=DIR>
49 Build directory.
51 =item I<--exeext=EXT>
53 Executable extention
55 =item I<--prefix=DIR>
57 Change directory to run tests in. Default is 'st'.
59 =item I<--target samba4|samba3|win|kvm>
61 Specify test target against which to run. Default is 'samba4'.
63 =item I<--quick>
65 Run only a limited number of tests. Intended to run in about 30 seconds on
66 moderately recent systems.
68 =item I<--socket-wrapper>
70 Use socket wrapper library for communication with server. Only works
71 when the server is running locally.
73 Will prevent TCP and UDP ports being opened on the local host but
74 (transparently) redirects these calls to use unix domain sockets.
76 =item I<--exclude>
78 Specify a file containing a list of tests that should be skipped. Possible
79 candidates are tests that segfault the server, flip or don't end.
81 =item I<--include>
83 Specify a file containing a list of tests that should be run. Same format
84 as the --exclude flag.
86 Not includes specified means all tests will be run.
88 =item I<--one>
90 Abort as soon as one test fails.
92 =item I<--testlist>
94 Load a list of tests from the specified location.
96 =back
98 =head1 ENVIRONMENT
100 =over 4
102 =item I<SMBD_VALGRIND>
104 =item I<TORTURE_MAXTIME>
106 =item I<VALGRIND>
108 =item I<TLS_ENABLED>
110 =item I<srcdir>
112 =back
114 =head1 LICENSE
116 selftest is licensed under the GNU General Public License L<http://www.gnu.org/licenses/gpl.html>.
118 =head1 AUTHOR
120 Jelmer Vernooij
122 =cut
124 use strict;
126 use FindBin qw($RealBin $Script);
127 use File::Spec;
128 use Getopt::Long;
129 use POSIX;
130 use Cwd qw(abs_path);
131 use lib "$RealBin";
132 use Subunit qw(parse_results);
133 use Subunit::Filter;
134 use SocketWrapper;
136 my $opt_help = 0;
137 my $opt_target = "samba4";
138 my $opt_quick = 0;
139 my $opt_socket_wrapper = 0;
140 my $opt_socket_wrapper_pcap = undef;
141 my $opt_socket_wrapper_keep_pcap = undef;
142 my $opt_one = 0;
143 my @opt_exclude = ();
144 my @opt_include = ();
145 my $opt_verbose = 0;
146 my $opt_image = undef;
147 my $opt_testenv = 0;
148 my $ldap = undef;
149 my $opt_analyse_cmd = undef;
150 my $opt_resetup_env = undef;
151 my $opt_bindir = undef;
152 my $opt_no_lazy_setup = undef;
153 my @testlists = ();
155 my $srcdir = ".";
156 my $builddir = ".";
157 my $exeext = "";
158 my $prefix = "./st";
160 my @includes = ();
161 my @excludes = ();
163 sub find_in_list($$)
165 my ($list, $fullname) = @_;
167 foreach (@$list) {
168 if ($fullname =~ /$$_[0]/) {
169 return ($$_[1]) if ($$_[1]);
170 return "";
174 return undef;
177 sub skip($)
179 my ($name) = @_;
181 return find_in_list(\@excludes, $name);
184 sub getlog_env($);
186 sub setup_pcap($)
188 my ($name) = @_;
190 return unless ($opt_socket_wrapper_pcap);
191 return unless defined($ENV{SOCKET_WRAPPER_PCAP_DIR});
193 my $fname = $name;
194 $fname =~ s%[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\-]%_%g;
196 my $pcap_file = "$ENV{SOCKET_WRAPPER_PCAP_DIR}/$fname.pcap";
198 SocketWrapper::setup_pcap($pcap_file);
200 return $pcap_file;
203 sub cleanup_pcap($$)
205 my ($pcap_file, $exitcode) = @_;
207 return unless ($opt_socket_wrapper_pcap);
208 return if ($opt_socket_wrapper_keep_pcap);
209 return unless ($exitcode == 0);
210 return unless defined($pcap_file);
212 unlink($pcap_file);
215 # expand strings from %ENV
216 sub expand_environment_strings($)
218 my $s = shift;
219 # we use a reverse sort so we do the longer ones first
220 foreach my $k (sort { $b cmp $a } keys %ENV) {
221 $s =~ s/\$$k/$ENV{$k}/g;
223 return $s;
226 sub run_testsuite($$$$$)
228 my ($envname, $name, $cmd, $i, $totalsuites) = @_;
229 my $pcap_file = setup_pcap($name);
231 Subunit::start_testsuite($name);
232 Subunit::report_time(time());
234 open(RESULTS, "$cmd 2>&1|");
235 my $statistics = {
236 TESTS_UNEXPECTED_OK => 0,
237 TESTS_EXPECTED_OK => 0,
238 TESTS_UNEXPECTED_FAIL => 0,
239 TESTS_EXPECTED_FAIL => 0,
240 TESTS_ERROR => 0,
241 TESTS_SKIP => 0,
244 my $msg_ops = new Subunit::Filter("$name\.", []);
246 parse_results($msg_ops, $statistics, *RESULTS);
248 my $ret = 0;
250 unless (close(RESULTS)) {
251 if ($!) {
252 Subunit::end_testsuite($name, "error", "Unable to run $cmd: $!");
253 return 0;
254 } else {
255 $ret = $?;
259 if ($ret & 127) {
260 Subunit::end_testsuite($name, "error", sprintf("Testsuite died with signal %d, %s coredump", ($ret & 127), ($ret & 128) ? "with": "without"));
261 return 0;
263 my $envlog = getlog_env($envname);
264 if ($envlog ne "") {
265 print "envlog: $envlog\n";
268 print "command: $cmd\n";
269 printf "expanded command: %s\n", expand_environment_strings($cmd);
271 my $exitcode = $ret >> 8;
273 Subunit::report_time(time());
274 if ($exitcode == 0) {
275 Subunit::end_testsuite($name, "success");
276 } else {
277 Subunit::end_testsuite($name, "failure", "Exit code was $exitcode");
280 cleanup_pcap($pcap_file, $exitcode);
282 if (not $opt_socket_wrapper_keep_pcap and defined($pcap_file)) {
283 print "PCAP FILE: $pcap_file\n";
286 if ($exitcode != 0) {
287 exit(1) if ($opt_one);
290 return $exitcode;
293 sub ShowHelp()
295 print "Samba test runner
296 Copyright (C) Jelmer Vernooij <jelmer\@samba.org>
297 Copyright (C) Stefan Metzmacher <metze\@samba.org>
299 Usage: $Script [OPTIONS] TESTNAME-REGEX
301 Generic options:
302 --help this help page
303 --target=samba[34]|win|kvm Samba version to target
304 --testlist=FILE file to read available tests from
306 Paths:
307 --prefix=DIR prefix to run tests in [st]
308 --srcdir=DIR source directory [.]
309 --builddir=DIR output directory [.]
310 --exeext=EXT executable extention []
312 Target Specific:
313 --socket-wrapper-pcap save traffic to pcap directories
314 --socket-wrapper-keep-pcap keep all pcap files, not just those for tests that
315 failed
316 --socket-wrapper enable socket wrapper
317 --bindir=PATH path to target binaries
319 Samba4 Specific:
320 --ldap=openldap|fedora-ds back samba onto specified ldap server
322 Kvm Specific:
323 --image=PATH path to KVM image
325 Behaviour:
326 --quick run quick overall test
327 --one abort when the first test fails
328 --verbose be verbose
329 --analyse-cmd CMD command to run after each test
331 exit(0);
334 my $result = GetOptions (
335 'help|h|?' => \$opt_help,
336 'target=s' => \$opt_target,
337 'prefix=s' => \$prefix,
338 'socket-wrapper' => \$opt_socket_wrapper,
339 'socket-wrapper-pcap' => \$opt_socket_wrapper_pcap,
340 'socket-wrapper-keep-pcap' => \$opt_socket_wrapper_keep_pcap,
341 'quick' => \$opt_quick,
342 'one' => \$opt_one,
343 'exclude=s' => \@opt_exclude,
344 'include=s' => \@opt_include,
345 'srcdir=s' => \$srcdir,
346 'builddir=s' => \$builddir,
347 'exeext=s' => \$exeext,
348 'verbose' => \$opt_verbose,
349 'testenv' => \$opt_testenv,
350 'ldap:s' => \$ldap,
351 'analyse-cmd=s' => \$opt_analyse_cmd,
352 'no-lazy-setup' => \$opt_no_lazy_setup,
353 'resetup-environment' => \$opt_resetup_env,
354 'bindir:s' => \$opt_bindir,
355 'image=s' => \$opt_image,
356 'testlist=s' => \@testlists
359 exit(1) if (not $result);
361 ShowHelp() if ($opt_help);
363 # we want unbuffered output
364 $| = 1;
366 my @tests = @ARGV;
368 # quick hack to disable rpc validation when using valgrind - its way too slow
369 unless (defined($ENV{VALGRIND})) {
370 $ENV{VALIDATE} = "validate";
371 $ENV{MALLOC_CHECK_} = 2;
374 # make all our python scripts unbuffered
375 $ENV{PYTHONUNBUFFERED} = 1;
377 my $bindir = ($opt_bindir or "$builddir/bin");
378 my $bindir_abs = abs_path($bindir);
380 # Backwards compatibility:
381 if (defined($ENV{TEST_LDAP}) and $ENV{TEST_LDAP} eq "yes") {
382 if (defined($ENV{FEDORA_DS_ROOT})) {
383 $ldap = "fedora-ds";
384 } else {
385 $ldap = "openldap";
389 my $torture_maxtime = ($ENV{TORTURE_MAXTIME} or 1200);
390 if ($ldap) {
391 # LDAP is slow
392 $torture_maxtime *= 2;
395 $prefix =~ s+//+/+;
396 $prefix =~ s+/./+/+;
397 $prefix =~ s+/$++;
399 die("using an empty prefix isn't allowed") unless $prefix ne "";
401 #Ensure we have the test prefix around
402 mkdir($prefix, 0777) unless -d $prefix;
404 my $prefix_abs = abs_path($prefix);
405 my $srcdir_abs = abs_path($srcdir);
406 my $builddir_abs = abs_path($builddir);
408 die("using an empty absolute prefix isn't allowed") unless $prefix_abs ne "";
409 die("using '/' as absolute prefix isn't allowed") unless $prefix_abs ne "/";
411 $ENV{PREFIX} = $prefix;
412 $ENV{KRB5CCNAME} = "$prefix/krb5ticket";
413 $ENV{PREFIX_ABS} = $prefix_abs;
414 $ENV{SRCDIR} = $srcdir;
415 $ENV{SRCDIR_ABS} = $srcdir_abs;
416 $ENV{BUILDDIR} = $builddir;
417 $ENV{BUILDDIR_ABS} = $builddir_abs;
418 $ENV{EXEEXT} = $exeext;
420 my $tls_enabled = not $opt_quick;
421 $ENV{TLS_ENABLED} = ($tls_enabled?"yes":"no");
422 $ENV{LDB_MODULES_PATH} = "$bindir_abs/modules/ldb";
423 $ENV{LD_SAMBA_MODULE_PATH} = "$bindir_abs/modules";
424 sub prefix_pathvar($$)
426 my ($name, $newpath) = @_;
427 if (defined($ENV{$name})) {
428 $ENV{$name} = "$newpath:$ENV{$name}";
429 } else {
430 $ENV{$name} = $newpath;
433 prefix_pathvar("PKG_CONFIG_PATH", "$bindir_abs/pkgconfig");
434 prefix_pathvar("PYTHONPATH", "$bindir_abs/python");
436 if ($opt_socket_wrapper_keep_pcap) {
437 # Socket wrapper keep pcap implies socket wrapper pcap
438 $opt_socket_wrapper_pcap = 1;
441 if ($opt_socket_wrapper_pcap) {
442 # Socket wrapper pcap implies socket wrapper
443 $opt_socket_wrapper = 1;
446 my $socket_wrapper_dir;
447 if ($opt_socket_wrapper) {
448 $socket_wrapper_dir = SocketWrapper::setup_dir("$prefix_abs/w", $opt_socket_wrapper_pcap);
449 print "SOCKET_WRAPPER_DIR=$socket_wrapper_dir\n";
450 } else {
451 unless ($< == 0) {
452 print "WARNING: Not using socket wrapper, but also not running as root. Will not be able to listen on proper ports\n";
456 my $target;
457 my $testenv_default = "none";
459 if ($opt_target eq "samba4") {
460 $testenv_default = "all";
461 require target::Samba4;
462 $target = new Samba4($bindir, $ldap, "$srcdir/setup", $exeext);
463 } elsif ($opt_target eq "samba3") {
464 if ($opt_socket_wrapper and `$bindir/smbd -b | grep SOCKET_WRAPPER` eq "") {
465 die("You must include --enable-socket-wrapper when compiling Samba in order to execute 'make test'. Exiting....");
467 $testenv_default = "member";
468 require target::Samba3;
469 $target = new Samba3($bindir);
470 } elsif ($opt_target eq "win") {
471 die("Windows tests will not run with socket wrapper enabled.")
472 if ($opt_socket_wrapper);
473 $testenv_default = "dc";
474 require target::Windows;
475 $target = new Windows();
476 } elsif ($opt_target eq "kvm") {
477 die("Kvm tests will not run with socket wrapper enabled.")
478 if ($opt_socket_wrapper);
479 require target::Kvm;
480 die("No image specified") unless ($opt_image);
481 $target = new Kvm($opt_image, undef);
485 # Start a Virtual Distributed Ethernet Switch
486 # Returns the pid of the switch.
488 sub start_vde_switch($)
490 my ($path) = @_;
492 system("vde_switch --pidfile $path/vde.pid --sock $path/vde.sock --daemon");
494 open(PID, "$path/vde.pid");
495 <PID> =~ /([0-9]+)/;
496 my $pid = $1;
497 close(PID);
499 return $pid;
502 # Stop a Virtual Distributed Ethernet Switch
503 sub stop_vde_switch($)
505 my ($pid) = @_;
506 kill 9, $pid;
509 sub read_test_regexes($)
511 my ($name) = @_;
512 my @ret = ();
513 open(LF, "<$name") or die("unable to read $name: $!");
514 while (<LF>) {
515 chomp;
516 next if (/^#/);
517 if (/^(.*?)([ \t]+)\#([\t ]*)(.*?)$/) {
518 push (@ret, [$1, $4]);
519 } else {
520 s/^(.*?)([ \t]+)\#([\t ]*)(.*?)$//;
521 push (@ret, [$_, undef]);
524 close(LF);
525 return @ret;
528 foreach (@opt_exclude) {
529 push (@excludes, read_test_regexes($_));
532 foreach (@opt_include) {
533 push (@includes, read_test_regexes($_));
536 my $interfaces = join(',', ("127.0.0.6/8",
537 "127.0.0.7/8",
538 "127.0.0.8/8",
539 "127.0.0.9/8",
540 "127.0.0.10/8",
541 "127.0.0.11/8"));
543 my $conffile = "$prefix_abs/client/client.conf";
544 $ENV{SMB_CONF_PATH} = $conffile;
546 sub write_clientconf($$)
548 my ($conffile, $vars) = @_;
550 mkdir("$prefix/client", 0777) unless -d "$prefix/client";
552 if ( -d "$prefix/client/private" ) {
553 unlink <$prefix/client/private/*>;
554 } else {
555 mkdir("$prefix/client/private", 0777);
558 if ( -d "$prefix/client/lockdir" ) {
559 unlink <$prefix/client/lockdir/*>;
560 } else {
561 mkdir("$prefix/client/lockdir", 0777);
564 if ( -d "$prefix_abs/client/ncalrpcdir" ) {
565 unlink <$prefix/client/ncalrpcdir/*>;
566 } else {
567 mkdir("$prefix/client/ncalrpcdir", 0777);
570 open(CF, ">$conffile");
571 print CF "[global]\n";
572 if (defined($ENV{VALGRIND})) {
573 print CF "\ticonv:native = true\n";
574 } else {
575 print CF "\ticonv:native = false\n";
577 print CF "\tnetbios name = client\n";
578 if (defined($vars->{DOMAIN})) {
579 print CF "\tworkgroup = $vars->{DOMAIN}\n";
581 if (defined($vars->{REALM})) {
582 print CF "\trealm = $vars->{REALM}\n";
584 if ($opt_socket_wrapper) {
585 print CF "\tinterfaces = $interfaces\n";
587 print CF "
588 private dir = $prefix_abs/client/private
589 lock dir = $prefix_abs/client/lockdir
590 ncalrpc dir = $prefix_abs/client/ncalrpcdir
591 name resolve order = bcast file
592 panic action = $RealBin/gdb_backtrace \%PID\% \%PROG\%
593 max xmit = 32K
594 notify:inotify = false
595 ldb:nosync = true
596 system:anonymous = true
597 client lanman auth = Yes
598 torture:basedir = $prefix_abs/client
599 #We don't want to pass our self-tests if the PAC code is wrong
600 gensec:require_pac = true
601 modules dir = $ENV{LD_SAMBA_MODULE_PATH}
602 setup directory = ./setup
603 resolv:host file = $prefix_abs/dns_host_file
605 close(CF);
608 my @todo = ();
610 my $testsdir = "$srcdir/selftest";
612 my %required_envs = ();
614 sub should_run_test($)
616 my $name = shift;
617 if ($#tests == -1) {
618 return 1;
620 for (my $i=0; $i <= $#tests; $i++) {
621 if ($name =~ /$tests[$i]/i) {
622 return 1;
625 return 0;
628 sub read_testlist($)
630 my ($filename) = @_;
632 my @ret = ();
633 open(IN, $filename) or die("Unable to open $filename: $!");
635 while (<IN>) {
636 if ($_ eq "-- TEST --\n") {
637 my $name = <IN>;
638 $name =~ s/\n//g;
639 my $env = <IN>;
640 $env =~ s/\n//g;
641 my $cmdline = <IN>;
642 $cmdline =~ s/\n//g;
643 if (should_run_test($name) == 1) {
644 $required_envs{$env} = 1;
645 push (@ret, [$name, $env, $cmdline]);
647 } else {
648 print;
651 close(IN) or die("Error creating recipe");
652 return @ret;
655 if ($#testlists == -1) {
656 die("No testlists specified");
659 $ENV{SELFTEST_PREFIX} = "$prefix_abs";
660 if ($opt_socket_wrapper) {
661 $ENV{SELFTEST_INTERFACES} = $interfaces;
662 } else {
663 $ENV{SELFTEST_INTERFACES} = "";
665 if ($opt_verbose) {
666 $ENV{SELFTEST_VERBOSE} = "1";
667 } else {
668 $ENV{SELFTEST_VERBOSE} = "";
670 if ($opt_quick) {
671 $ENV{SELFTEST_QUICK} = "1";
672 } else {
673 $ENV{SELFTEST_QUICK} = "";
675 $ENV{SELFTEST_TARGET} = $opt_target;
676 $ENV{SELFTEST_MAXTIME} = $torture_maxtime;
678 my @available = ();
679 foreach my $fn (@testlists) {
680 foreach (read_testlist($fn)) {
681 my $name = $$_[0];
682 next if (@includes and not defined(find_in_list(\@includes, $name)));
683 push (@available, $_);
687 Subunit::testsuite_count($#available+1);
688 Subunit::report_time(time());
690 foreach (@available) {
691 my $name = $$_[0];
692 my $skipreason = skip($name);
693 if (defined($skipreason)) {
694 Subunit::skip_testsuite($name, $skipreason);
695 } else {
696 push(@todo, $_);
700 if ($#todo == -1) {
701 print STDERR "No tests to run\n";
702 exit(1);
705 my $suitestotal = $#todo + 1;
706 my $i = 0;
707 $| = 1;
709 my %running_envs = ();
711 sub get_running_env($)
713 my ($name) = @_;
715 my $envname = $name;
717 $envname =~ s/:.*//;
719 return $running_envs{$envname};
722 my @exported_envvars = (
723 # domain stuff
724 "DOMAIN",
725 "REALM",
727 # domain controller stuff
728 "DC_SERVER",
729 "DC_SERVER_IP",
730 "DC_NETBIOSNAME",
731 "DC_NETBIOSALIAS",
733 # domain controller stuff
734 "MEMBER_SERVER",
735 "MEMBER_SERVER_IP",
736 "MEMBER_NETBIOSNAME",
737 "MEMBER_NETBIOSALIAS",
739 # domain controller stuff
740 "RPC_PROXY_SERVER",
741 "RPC_PROXY_SERVER_IP",
742 "RPC_PROXY_NETBIOSNAME",
743 "RPC_PROXY_NETBIOSALIAS",
745 # server stuff
746 "SERVER",
747 "SERVER_IP",
748 "NETBIOSNAME",
749 "NETBIOSALIAS",
751 # user stuff
752 "USERNAME",
753 "PASSWORD",
754 "DC_USERNAME",
755 "DC_PASSWORD",
757 # misc stuff
758 "KRB5_CONFIG",
759 "WINBINDD_SOCKET_DIR",
760 "WINBINDD_PRIV_PIPE_DIR"
763 $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
764 my $signame = shift;
765 teardown_env($_) foreach(keys %running_envs);
766 die("Received signal $signame");
769 sub setup_env($)
771 my ($name) = @_;
773 my $testenv_vars = undef;
775 my $envname = $name;
776 my $option = $name;
778 $envname =~ s/:.*//;
779 $option =~ s/^[^:]*//;
780 $option =~ s/^://;
782 $option = "client" if $option eq "";
784 if ($envname eq "none") {
785 $testenv_vars = {};
786 } elsif (defined(get_running_env($envname))) {
787 $testenv_vars = get_running_env($envname);
788 if (not $target->check_env($testenv_vars)) {
789 $testenv_vars = undef;
791 } else {
792 $testenv_vars = $target->setup_env($envname, $prefix);
795 return undef unless defined($testenv_vars);
797 $running_envs{$envname} = $testenv_vars;
799 if ($option eq "local") {
800 SocketWrapper::set_default_iface($testenv_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
801 $ENV{SMB_CONF_PATH} = $testenv_vars->{SERVERCONFFILE};
802 } elsif ($option eq "client") {
803 SocketWrapper::set_default_iface(6);
804 write_clientconf($conffile, $testenv_vars);
805 $ENV{SMB_CONF_PATH} = $conffile;
806 } else {
807 die("Unknown option[$option] for envname[$envname]");
810 foreach (@exported_envvars) {
811 if (defined($testenv_vars->{$_})) {
812 $ENV{$_} = $testenv_vars->{$_};
813 } else {
814 delete $ENV{$_};
818 return $testenv_vars;
821 sub exported_envvars_str($)
823 my ($testenv_vars) = @_;
824 my $out = "";
826 foreach (@exported_envvars) {
827 next unless defined($testenv_vars->{$_});
828 $out .= $_."=".$testenv_vars->{$_}."\n";
831 return $out;
834 sub getlog_env($)
836 my ($envname) = @_;
837 return "" if ($envname eq "none");
838 return $target->getlog_env(get_running_env($envname));
841 sub check_env($)
843 my ($envname) = @_;
844 return 1 if ($envname eq "none");
845 return $target->check_env(get_running_env($envname));
848 sub teardown_env($)
850 my ($envname) = @_;
851 return if ($envname eq "none");
852 $target->teardown_env(get_running_env($envname));
853 delete $running_envs{$envname};
856 # This 'global' file needs to be empty when we start
857 unlink("$prefix_abs/dns_host_file");
859 if ($opt_no_lazy_setup) {
860 setup_env($_) foreach (keys %required_envs);
863 if ($opt_testenv) {
864 my $testenv_name = $ENV{SELFTEST_TESTENV};
865 $testenv_name = $testenv_default unless defined($testenv_name);
867 my $testenv_vars = setup_env($testenv_name);
869 $ENV{PIDDIR} = $testenv_vars->{PIDDIR};
871 my $envvarstr = exported_envvars_str($testenv_vars);
873 my $term = ($ENV{TERMINAL} or "xterm");
874 system("$term -e 'echo -e \"
875 Welcome to the Samba4 Test environment '$testenv_name'
877 This matches the client environment used in make test
878 server is pid `cat \$PIDDIR/samba.pid`
880 Some useful environment variables:
881 TORTURE_OPTIONS=\$TORTURE_OPTIONS
882 SMB_CONF_PATH=\$SMB_CONF_PATH
884 $envvarstr
885 \" && LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH} bash'");
886 teardown_env($testenv_name);
887 } else {
888 foreach (@todo) {
889 $i++;
890 my $cmd = $$_[2];
891 $cmd =~ s/([\(\)])/\\$1/g;
892 my $name = $$_[0];
893 my $envname = $$_[1];
895 my $envvars = setup_env($envname);
896 if (not defined($envvars)) {
897 Subunit::skip_testsuite($name,
898 "unable to set up environment $envname");
899 next;
902 run_testsuite($envname, $name, $cmd, $i, $suitestotal);
904 if (defined($opt_analyse_cmd)) {
905 system("$opt_analyse_cmd \"$name\"");
908 teardown_env($envname) if ($opt_resetup_env);
912 print "\n";
914 teardown_env($_) foreach (keys %running_envs);
916 $target->stop();
918 my $failed = 0;
920 # if there were any valgrind failures, show them
921 foreach (<$prefix/valgrind.log*>) {
922 next unless (-s $_);
923 print "VALGRIND FAILURE\n";
924 $failed++;
925 system("cat $_");
927 exit 0;