X-Git-Url: http://git.samba.org/?a=blobdiff_plain;f=selftest%2Fselftest.pl;h=25470265c1fc29ccfa7defbfce2c95ac614aab8c;hb=2e4c15110b8c3f079f32645660dfbb20e32877e5;hp=f41ff33d53ad099376fcbfd610ab7e5d0b007ff9;hpb=8dcfe2e5c44184298b0aa5bb1a13e2108b31a9c4;p=obnox%2Fsamba%2Fsamba-obnox.git diff --git a/selftest/selftest.pl b/selftest/selftest.pl index f41ff33d53a..25470265c1f 100755 --- a/selftest/selftest.pl +++ b/selftest/selftest.pl @@ -16,111 +16,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -=pod - -=head1 NAME - -selftest - Samba test runner - -=head1 SYNOPSIS - -selftest --help - -selftest [--srcdir=DIR] [--bindir=DIR] [--exeext=EXT][--target=samba|samba3|win|kvm] [--socket-wrapper] [--quick] [--exclude=FILE] [--include=FILE] [--one] [--prefix=prefix] [--testlist=FILE] [TESTS] - -=head1 DESCRIPTION - -A simple test runner. TESTS is a regular expression with tests to run. - -=head1 OPTIONS - -=over 4 - -=item I<--help> - -Show list of available options. - -=item I<--srcdir=DIR> - -Source directory. - -=item I<--bindir=DIR> - -Built binaries directory. - -=item I<--exeext=EXT> - -Executable extention - -=item I<--prefix=DIR> - -Change directory to run tests in. Default is 'st'. - -=item I<--target samba|samba3|win|kvm> - -Specify test target against which to run. Default is 'samba4'. - -=item I<--quick> - -Run only a limited number of tests. Intended to run in about 30 seconds on -moderately recent systems. - -=item I<--socket-wrapper> - -Use socket wrapper library for communication with server. Only works -when the server is running locally. - -Will prevent TCP and UDP ports being opened on the local host but -(transparently) redirects these calls to use unix domain sockets. - -=item I<--exclude> - -Specify a file containing a list of tests that should be skipped. Possible -candidates are tests that segfault the server, flip or don't end. - -=item I<--include> - -Specify a file containing a list of tests that should be run. Same format -as the --exclude flag. - -Not includes specified means all tests will be run. - -=item I<--one> - -Abort as soon as one test fails. - -=item I<--testlist> - -Load a list of tests from the specified location. - -=back - -=head1 ENVIRONMENT - -=over 4 - -=item I - -=item I - -=item I - -=item I - -=item I - -=back - -=head1 LICENSE - -selftest is licensed under the GNU General Public License L. - -=head1 AUTHOR - -Jelmer Vernooij - -=cut - use strict; use FindBin qw($RealBin $Script); @@ -147,35 +42,30 @@ my $opt_quick = 0; my $opt_socket_wrapper = 0; my $opt_socket_wrapper_pcap = undef; my $opt_socket_wrapper_keep_pcap = undef; +my $opt_random_order = 0; my $opt_one = 0; my @opt_exclude = (); my @opt_include = (); -my $opt_verbose = 0; -my $opt_image = undef; my $opt_testenv = 0; my $opt_list = 0; my $ldap = undef; my $opt_resetup_env = undef; my $opt_binary_mapping = ""; my $opt_load_list = undef; +my $opt_libnss_wrapper_so_path = ""; +my $opt_libresolv_wrapper_so_path = ""; +my $opt_libsocket_wrapper_so_path = ""; +my $opt_libuid_wrapper_so_path = ""; +my $opt_use_dns_faking = 0; my @testlists = (); my $srcdir = "."; my $bindir = "./bin"; -my $exeext = ""; my $prefix = "./st"; my @includes = (); my @excludes = (); -sub pipe_handler { - my $sig = shift @_; - print STDERR "Exiting early because of SIGPIPE.\n"; - exit(1); -} - -$SIG{PIPE} = \&pipe_handler; - sub find_in_list($$) { my ($list, $fullname) = @_; @@ -300,17 +190,28 @@ Usage: $Script [OPTIONS] TESTNAME-REGEX Generic options: --help this help page - --target=samba[3]|win|kvm Samba version to target - --testlist=FILE file to read available tests from + --target=samba[3]|win Samba version to target + --testlist=FILE file to read available tests from + --exclude=FILE Exclude tests listed in the file + --include=FILE Include tests listed in the file Paths: --prefix=DIR prefix to run tests in [st] --srcdir=DIR source directory [.] --bindir=DIR binaries directory [./bin] - --exeext=EXT executable extention [] + +Preload cwrap: + --nss_wrapper_so_path=FILE the nss_wrapper library to preload + --resolv_wrapper_so_path=FILE the resolv_wrapper library to preload + --socket_wrapper_so_path=FILE the socket_wrapper library to preload + --uid_wrapper_so_path=FILE the uid_wrapper library to preload + +DNS: + --use-dns-faking Fake DNS entries rather than talking to our + DNS implementation. Target Specific: - --socket-wrapper-pcap save traffic to pcap directories + --socket-wrapper-pcap save traffic to pcap directories --socket-wrapper-keep-pcap keep all pcap files, not just those for tests that failed --socket-wrapper enable socket wrapper @@ -318,13 +219,9 @@ Target Specific: Samba4 Specific: --ldap=openldap|fedora-ds back samba onto specified ldap server -Kvm Specific: - --image=PATH path to KVM image - Behaviour: --quick run quick overall test --one abort when the first test fails - --verbose be verbose --testenv run a shell in the requested test environment --list list available tests "; @@ -344,16 +241,19 @@ my $result = GetOptions ( 'include=s' => \@opt_include, 'srcdir=s' => \$srcdir, 'bindir=s' => \$bindir, - 'exeext=s' => \$exeext, - 'verbose' => \$opt_verbose, 'testenv' => \$opt_testenv, 'list' => \$opt_list, 'ldap:s' => \$ldap, 'resetup-environment' => \$opt_resetup_env, - 'image=s' => \$opt_image, 'testlist=s' => \@testlists, + 'random-order' => \$opt_random_order, 'load-list=s' => \$opt_load_list, - 'binary-mapping=s' => \$opt_binary_mapping + 'binary-mapping=s' => \$opt_binary_mapping, + 'nss_wrapper_so_path=s' => \$opt_libnss_wrapper_so_path, + 'resolv_wrapper_so_path=s' => \$opt_libresolv_wrapper_so_path, + 'socket_wrapper_so_path=s' => \$opt_libsocket_wrapper_so_path, + 'uid_wrapper_so_path=s' => \$opt_libuid_wrapper_so_path, + 'use-dns-faking' => \$opt_use_dns_faking ); exit(1) if (not $result); @@ -370,7 +270,7 @@ my @tests = @ARGV; # quick hack to disable rpc validation when using valgrind - its way too slow unless (defined($ENV{VALGRIND})) { $ENV{VALIDATE} = "validate"; - $ENV{MALLOC_CHECK_} = 2; + $ENV{MALLOC_CHECK_} = 3; } # make all our python scripts unbuffered @@ -423,7 +323,6 @@ $ENV{PREFIX_ABS} = $prefix_abs; $ENV{SRCDIR} = $srcdir; $ENV{SRCDIR_ABS} = $srcdir_abs; $ENV{BINDIR} = $bindir_abs; -$ENV{EXEEXT} = $exeext; my $tls_enabled = not $opt_quick; $ENV{TLS_ENABLED} = ($tls_enabled?"yes":"no"); @@ -450,16 +349,67 @@ if ($opt_socket_wrapper_pcap) { $opt_socket_wrapper = 1; } +my $ld_preload = $ENV{LD_PRELOAD}; + +if ($opt_libnss_wrapper_so_path) { + if ($ld_preload) { + $ld_preload = "$ld_preload:$opt_libnss_wrapper_so_path"; + } else { + $ld_preload = "$opt_libnss_wrapper_so_path"; + } +} + +if ($opt_libresolv_wrapper_so_path) { + if ($ld_preload) { + $ld_preload = "$ld_preload:$opt_libresolv_wrapper_so_path"; + } else { + $ld_preload = "$opt_libresolv_wrapper_so_path"; + } +} + +if ($opt_libsocket_wrapper_so_path) { + if ($ld_preload) { + $ld_preload = "$ld_preload:$opt_libsocket_wrapper_so_path"; + } else { + $ld_preload = "$opt_libsocket_wrapper_so_path"; + } +} + +if ($opt_libuid_wrapper_so_path) { + if ($ld_preload) { + $ld_preload = "$ld_preload:$opt_libuid_wrapper_so_path"; + } else { + $ld_preload = "$opt_libuid_wrapper_so_path"; + } +} + +$ENV{LD_PRELOAD} = $ld_preload; +print "LD_PRELOAD=$ENV{LD_PRELOAD}\n"; + +# Enable uid_wrapper globally +$ENV{UID_WRAPPER} = 1; + +# Disable RTLD_DEEPBIND hack for Samba bind dlz module +# +# This is needed in order to allow the ldb_*ldap module +# to work with a preloaded socket wrapper. +$ENV{LDB_MODULES_DISABLE_DEEPBIND} = 1; + my $socket_wrapper_dir; if ($opt_socket_wrapper) { $socket_wrapper_dir = SocketWrapper::setup_dir("$prefix_abs/w", $opt_socket_wrapper_pcap); print "SOCKET_WRAPPER_DIR=$socket_wrapper_dir\n"; -} else { +} elsif (not $opt_list) { unless ($< == 0) { - print "WARNING: Not using socket wrapper, but also not running as root. Will not be able to listen on proper ports\n"; + warn("not using socket wrapper, but also not running as root. Will not be able to listen on proper ports"); } } +if ($opt_use_dns_faking) { + print "DNS: Faking namerserver\n"; + $ENV{SAMBA_DNS_FAKING} = 1; +} + my $target; my $testenv_default = "none"; @@ -483,57 +433,16 @@ if (defined($ENV{SMBD_MAXTIME}) and $ENV{SMBD_MAXTIME} ne "") { $server_maxtime = $ENV{SMBD_MAXTIME}; } -if ($opt_target eq "samba") { - if ($opt_socket_wrapper and `$bindir/smbd -b | grep SOCKET_WRAPPER` eq "") { - die("You must include --enable-socket-wrapper when compiling Samba in order to execute 'make test'. Exiting...."); - } - $testenv_default = "all"; - require target::Samba; - $target = new Samba($bindir, \%binary_mapping, $ldap, $srcdir, $exeext, $server_maxtime); -} elsif ($opt_target eq "samba3") { - if ($opt_socket_wrapper and `$bindir/smbd -b | grep SOCKET_WRAPPER` eq "") { - die("You must include --enable-socket-wrapper when compiling Samba in order to execute 'make test'. Exiting...."); +unless ($opt_list) { + if ($opt_target eq "samba") { + $testenv_default = "dc"; + require target::Samba; + $target = new Samba($bindir, \%binary_mapping, $ldap, $srcdir, $server_maxtime); + } elsif ($opt_target eq "samba3") { + $testenv_default = "member"; + require target::Samba3; + $target = new Samba3($bindir, \%binary_mapping, $srcdir_abs, $server_maxtime); } - $testenv_default = "member"; - require target::Samba3; - $target = new Samba3($bindir, \%binary_mapping, $srcdir_abs, $exeext, $server_maxtime); -} elsif ($opt_target eq "win") { - die("Windows tests will not run with socket wrapper enabled.") - if ($opt_socket_wrapper); - $testenv_default = "dc"; - require target::Windows; - $target = new Windows(); -} elsif ($opt_target eq "kvm") { - die("Kvm tests will not run with socket wrapper enabled.") - if ($opt_socket_wrapper); - require target::Kvm; - die("No image specified") unless ($opt_image); - $target = new Kvm($opt_image, undef); -} - -# -# Start a Virtual Distributed Ethernet Switch -# Returns the pid of the switch. -# -sub start_vde_switch($) -{ - my ($path) = @_; - - system("vde_switch --pidfile $path/vde.pid --sock $path/vde.sock --daemon"); - - open(PID, "$path/vde.pid"); - =~ /([0-9]+)/; - my $pid = $1; - close(PID); - - return $pid; -} - -# Stop a Virtual Distributed Ethernet Switch -sub stop_vde_switch($) -{ - my ($pid) = @_; - kill 9, $pid; } sub read_test_regexes($) @@ -638,7 +547,6 @@ sub write_clientconf($$$) state directory = $clientdir/statedir cache directory = $clientdir/cachedir ncalrpc dir = $clientdir/ncalrpcdir - name resolve order = file bcast panic action = $RealBin/gdb_backtrace \%d max xmit = 32K notify:inotify = false @@ -649,9 +557,9 @@ sub write_clientconf($$$) torture:basedir = $clientdir #We don't want to pass our self-tests if the PAC code is wrong gensec:require_pac = true - resolv:host file = $prefix_abs/dns_host_file #We don't want to run 'speed' tests for very long torture:timelimit = 1 + winbind separator = / "; close(CF); } @@ -680,23 +588,27 @@ sub read_testlist($) open(IN, $filename) or die("Unable to open $filename: $!"); while () { - if (/-- TEST(-LOADLIST|-IDLIST|) --\n/) { + if (/-- TEST(-LOADLIST|) --\n/) { my $supports_loadlist = (defined($1) and $1 eq "-LOADLIST"); - my $supports_idlist = (defined($1) and $1 eq "-IDLIST"); my $name = ; $name =~ s/\n//g; my $env = ; $env =~ s/\n//g; + my $loadlist; + if ($supports_loadlist) { + $loadlist = ; + $loadlist =~ s/\n//g; + } my $cmdline = ; $cmdline =~ s/\n//g; if (should_run_test($name) == 1) { - push (@ret, [$name, $env, $cmdline, $supports_loadlist, $supports_idlist]); + push (@ret, [$name, $env, $cmdline, $loadlist]); } } else { print; } } - close(IN) or die("Error creating recipe"); + close(IN) or die("Error creating recipe from $filename"); return @ret; } @@ -712,11 +624,6 @@ if ($opt_socket_wrapper) { } else { $ENV{SELFTEST_INTERFACES} = ""; } -if ($opt_verbose) { - $ENV{SELFTEST_VERBOSE} = "1"; -} else { - $ENV{SELFTEST_VERBOSE} = ""; -} if ($opt_quick) { $ENV{SELFTEST_QUICK} = "1"; } else { @@ -768,13 +675,17 @@ foreach my $testsuite (@available) { } if ($match) { if (defined($skipreason)) { + if (not $opt_list) { Subunit::skip_testsuite($name, $skipreason); + } } else { push(@todo, $testsuite); } } } elsif (defined($skipreason)) { - Subunit::skip_testsuite($name, $skipreason); + if (not $opt_list) { + Subunit::skip_testsuite($name, $skipreason); + } } else { push(@todo, $testsuite); } @@ -793,8 +704,10 @@ if (defined($restricted)) { my $suitestotal = $#todo + 1; -Subunit::progress($suitestotal); -Subunit::report_time(time()); +unless ($opt_list) { + Subunit::progress($suitestotal); + Subunit::report_time(time()); +} my $i = 0; $| = 1; @@ -820,30 +733,41 @@ my @exported_envvars = ( # domain controller stuff "DC_SERVER", "DC_SERVER_IP", + "DC_SERVER_IPV6", "DC_NETBIOSNAME", "DC_NETBIOSALIAS", # domain member "MEMBER_SERVER", "MEMBER_SERVER_IP", + "MEMBER_SERVER_IPV6", "MEMBER_NETBIOSNAME", "MEMBER_NETBIOSALIAS", # rpc proxy controller stuff "RPC_PROXY_SERVER", "RPC_PROXY_SERVER_IP", + "RPC_PROXY_SERVER_IPV6", "RPC_PROXY_NETBIOSNAME", "RPC_PROXY_NETBIOSALIAS", # domain controller stuff for Vampired DC "VAMPIRE_DC_SERVER", "VAMPIRE_DC_SERVER_IP", + "VAMPIRE_DC_SERVER_IPV6", "VAMPIRE_DC_NETBIOSNAME", "VAMPIRE_DC_NETBIOSALIAS", + "PROMOTED_DC_SERVER", + "PROMOTED_DC_SERVER_IP", + "PROMOTED_DC_SERVER_IPV6", + "PROMOTED_DC_NETBIOSNAME", + "PROMOTED_DC_NETBIOSALIAS", + # server stuff "SERVER", "SERVER_IP", + "SERVER_IPV6", "NETBIOSNAME", "NETBIOSALIAS", @@ -854,20 +778,44 @@ my @exported_envvars = ( "DC_USERNAME", "DC_PASSWORD", + # UID/GID for rfc2307 mapping tests + "UID_RFC2307TEST", + "GID_RFC2307TEST", + # misc stuff "KRB5_CONFIG", - "WINBINDD_SOCKET_DIR", + "SELFTEST_WINBINDD_SOCKET_DIR", "WINBINDD_PRIV_PIPE_DIR", "NMBD_SOCKET_DIR", - "LOCAL_PATH" + "LOCAL_PATH", + + # nss_wrapper + "NSS_WRAPPER_PASSWD", + "NSS_WRAPPER_GROUP", + "NSS_WRAPPER_HOSTS", + + # resolv_wrapper + "RESOLV_WRAPPER_CONF", ); -$SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub { +sub sighandler($) +{ my $signame = shift; + + $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = 'DEFAULT'; + $SIG{PIPE} = 'IGNORE'; + + open(STDOUT, ">&STDERR") or die "can't dup STDOUT to STDERR: $!"; + + print "$0: PID[$$]: Got SIG${signame} teardown environments.\n"; teardown_env($_) foreach(keys %running_envs); - die("Received signal $signame"); + system("pstree -p $$"); + print "$0: PID[$$]: Exiting...\n"; + exit(1); }; +$SIG{INT} = $SIG{QUIT} = $SIG{TERM} = $SIG{PIPE} = \&sighandler; + sub setup_env($$) { my ($name, $prefix) = @_; @@ -893,15 +841,16 @@ sub setup_env($$) } } else { $testenv_vars = $target->setup_env($envname, $prefix); - if (defined($testenv_vars) && not defined($testenv_vars->{target})) { + if (defined($testenv_vars) and $testenv_vars eq "UNKNOWN") { + return $testenv_vars; + } elsif (defined($testenv_vars) && not defined($testenv_vars->{target})) { $testenv_vars->{target} = $target; } if (not defined($testenv_vars)) { - warn("$opt_target can't provide environment '$envname'"); + warn("$opt_target can't start up known environment '$envname'"); } } - return undef unless defined($testenv_vars); $running_envs{$envname} = $testenv_vars; @@ -961,6 +910,7 @@ sub teardown_env($) { my ($envname) = @_; return if ($envname eq "none"); + print STDERR "teardown_env($envname)\n"; my $env = get_running_env($envname); $env->{target}->teardown_env($env); delete $running_envs{$envname}; @@ -968,6 +918,13 @@ sub teardown_env($) # This 'global' file needs to be empty when we start unlink("$prefix_abs/dns_host_file"); +unlink("$prefix_abs/hosts"); + +if ($opt_random_order) { + require List::Util; + my @newtodo = List::Util::shuffle(@todo); + @todo = @newtodo; +} if ($opt_testenv) { my $testenv_name = $ENV{SELFTEST_TESTENV}; @@ -975,15 +932,16 @@ if ($opt_testenv) { my $testenv_vars = setup_env($testenv_name, $prefix); - die("Unable to setup environment $testenv_name") unless ($testenv_vars); + if (not $testenv_vars or $testenv_vars eq "UNKNOWN") { + die("Unable to setup environment $testenv_name"); + } $ENV{PIDDIR} = $testenv_vars->{PIDDIR}; $ENV{ENVNAME} = $testenv_name; my $envvarstr = exported_envvars_str($testenv_vars); - my $term = ($ENV{TERMINAL} or "xterm -e"); - system("$term 'echo -e \" + my @term_args = ("echo -e \" Welcome to the Samba4 Test environment '$testenv_name' This matches the client environment used in make test @@ -994,27 +952,39 @@ TORTURE_OPTIONS=\$TORTURE_OPTIONS SMB_CONF_PATH=\$SMB_CONF_PATH $envvarstr -\" && LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH} bash'"); +\" && LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH} bash"); + my @term = (); + if ($ENV{TERMINAL}) { + @term = ($ENV{TERMINAL}); + } else { + @term = ("xterm", "-e"); + unshift(@term_args, ("bash", "-c")); + } + + system(@term, @term_args); + teardown_env($testenv_name); } elsif ($opt_list) { foreach (@todo) { - my $cmd = $$_[2]; my $name = $$_[0]; my $envname = $$_[1]; + my $cmd = $$_[2]; + my $listcmd = $$_[3]; - unless($cmd =~ /\$LISTOPT/) { + unless (defined($listcmd)) { warn("Unable to list tests in $name"); + # Rather than ignoring this testsuite altogether, just pretend the entire testsuite is + # a single "test". + print "$name\n"; next; } - $cmd =~ s/\$LISTOPT/--list/g; - - system($cmd); + system($listcmd); if ($? == -1) { - die("Unable to run $cmd: $!"); + die("Unable to run $listcmd: $!"); } elsif ($? & 127) { - die(snprintf("%s died with signal %d, %s coredump\n", $cmd, ($? & 127), ($? & 128) ? 'with' : 'without')); + die(sprintf("%s died with signal %d, %s coredump\n", $listcmd, ($? & 127), ($? & 128) ? 'with' : 'without')); } my $exitcode = $? >> 8; @@ -1035,6 +1005,11 @@ $envvarstr Subunit::end_testsuite($name, "error", "unable to set up environment $envname - exiting"); next; + } elsif ($envvars eq "UNKNOWN") { + Subunit::start_testsuite($name); + Subunit::end_testsuite($name, "skip", + "environment $envname is unknown in this test backend - skipping"); + next; } # Generate a file with the individual tests to run, if the @@ -1046,9 +1021,8 @@ $envvarstr print $fh substr($test, length($name)+1) . "\n"; } $cmd =~ s/\$LOADLIST/--load-list=$listid_file/g; - } elsif ($$_[4]) { - $cmd =~ s/\s+[^\s]+\s*$//; - $cmd .= " " . join(' ', @{$individual_tests->{$name}}); + } else { + warn("Unable to run individual tests in $name, it does not support --loadlist."); } }