s3-selftest Fix use of the 'fake DNS' file
[idra/samba.git] / selftest / selftest.pl
index 7431bed8ed8ad3eda71ef7f6df53c55ee8d7abf2..fbb36a2d58d8553f5fdf42e3ee2e3aef965282ad 100755 (executable)
@@ -153,6 +153,7 @@ 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_bindir = undef;
@@ -253,7 +254,7 @@ sub run_testsuite($$$$$)
        if ($? == -1) {
                Subunit::progress_pop();
                Subunit::end_testsuite($name, "error", "Unable to run $cmd: $!");
-               return 0;
+               exit(1);
        } elsif ($? & 127) {
                Subunit::end_testsuite($name, "error",
                        sprintf("%s died with signal %d, %s coredump\n", $cmd, ($? & 127),  ($? & 128) ? 'with' : 'without'));
@@ -325,7 +326,8 @@ Behaviour:
  --quick                    run quick overall test
  --one                      abort when the first test fails
  --verbose                  be verbose
- --analyse-cmd CMD          command to run after each test
+ --testenv                  run a shell in the requested test environment
+ --list                     list available tests
 ";
        exit(0);
 }
@@ -346,6 +348,7 @@ my $result = GetOptions (
                'exeext=s' => \$exeext,
                'verbose' => \$opt_verbose,
                'testenv' => \$opt_testenv,
+               'list' => \$opt_list,
                'ldap:s' => \$ldap,
                'resetup-environment' => \$opt_resetup_env,
                'bindir:s' => \$opt_bindir,
@@ -358,6 +361,8 @@ exit(1) if (not $result);
 
 ShowHelp() if ($opt_help);
 
+die("--list and --testenv are mutually exclusive") if ($opt_list and $opt_testenv);
+
 # we want unbuffered output
 $| = 1;
 
@@ -416,12 +421,12 @@ $ENV{SRCDIR} = $srcdir;
 $ENV{SRCDIR_ABS} = $srcdir_abs;
 $ENV{BUILDDIR} = $builddir;
 $ENV{BUILDDIR_ABS} = $builddir_abs;
+$ENV{BINDIR} = $bindir_abs;
 $ENV{EXEEXT} = $exeext;
 
 my $tls_enabled = not $opt_quick;
 $ENV{TLS_ENABLED} = ($tls_enabled?"yes":"no");
-$ENV{LDB_MODULES_PATH} = "$bindir_abs/modules/ldb";
-$ENV{LD_SAMBA_MODULE_PATH} = "$bindir_abs/modules";
+
 sub prefix_pathvar($$)
 {
        my ($name, $newpath) = @_;
@@ -460,14 +465,14 @@ my $testenv_default = "none";
 if ($opt_target eq "samba4") {
        $testenv_default = "all";
        require target::Samba4;
-       $target = new Samba4($bindir, $ldap, "$srcdir/setup", $exeext);
+       $target = new Samba4($bindir, $ldap, $srcdir, $exeext);
 } 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....");
        }
        $testenv_default = "member";
        require target::Samba3;
-       $target = new Samba3($bindir);
+       $target = new Samba3($bindir, $srcdir_abs);
 } elsif ($opt_target eq "win") {
        die("Windows tests will not run with socket wrapper enabled.") 
                if ($opt_socket_wrapper);
@@ -591,7 +596,7 @@ sub write_clientconf($$$)
        private dir = $clientdir/private
        lock dir = $clientdir/lockdir
        ncalrpc dir = $clientdir/ncalrpcdir
-       name resolve order = bcast file
+       name resolve order = file bcast
        panic action = $RealBin/gdb_backtrace \%PID\% \%PROG\%
        max xmit = 32K
        notify:inotify = false
@@ -602,8 +607,6 @@ 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
-       modules dir = $ENV{LD_SAMBA_MODULE_PATH}
-       setup directory = ./setup
        resolv:host file = $prefix_abs/dns_host_file
 #We don't want to run 'speed' tests for very long
         torture:timelimit = 1
@@ -613,8 +616,6 @@ sub write_clientconf($$$)
 
 my @todo = ();
 
-my $testsdir = "$srcdir/selftest";
-
 sub should_run_test($)
 {
        my $name = shift;
@@ -663,6 +664,7 @@ if ($#testlists == -1) {
 
 $ENV{SELFTEST_PREFIX} = "$prefix_abs";
 $ENV{SELFTEST_TMPDIR} = "$tmpdir_abs";
+$ENV{TEST_DATA_PREFIX} = "$tmpdir_abs";
 if ($opt_socket_wrapper) {
        $ENV{SELFTEST_INTERFACES} = $interfaces;
 } else {
@@ -815,6 +817,7 @@ my @exported_envvars = (
        "KRB5_CONFIG",
        "WINBINDD_SOCKET_DIR",
        "WINBINDD_PRIV_PIPE_DIR",
+       "NMBD_SOCKET_DIR",
        "LOCAL_PATH"
 );
 
@@ -942,6 +945,32 @@ SMB_CONF_PATH=\$SMB_CONF_PATH
 $envvarstr
 \" && LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH} bash'");
        teardown_env($testenv_name);
+} elsif ($opt_list) {
+       foreach (@todo) {
+               my $cmd = $$_[2];
+               my $name = $$_[0];
+               my $envname = $$_[1];
+
+               unless($cmd =~ /\$LISTOPT/) {
+                       warn("Unable to list tests in $name");
+                       next;
+               }
+
+               $cmd =~ s/\$LISTOPT/--list/g;
+
+               system($cmd);
+
+               if ($? == -1) {
+                       die("Unable to run $cmd: $!");
+               } elsif ($? & 127) {
+                       die(snprintf("%s died with signal %d, %s coredump\n", $cmd, ($? & 127),  ($? & 128) ? 'with' : 'without'));
+               }
+
+               my $exitcode = $? >> 8;
+               if ($exitcode != 0) {
+                       die("$cmd exited with exit code $exitcode");
+               }
+       }
 } else {
        foreach (@todo) {
                $i++;
@@ -953,7 +982,7 @@ $envvarstr
                if (not defined($envvars)) {
                        Subunit::start_testsuite($name);
                        Subunit::end_testsuite($name, "error",
-                               "unable to set up environment $envname");
+                               "unable to set up environment $envname - exiting");
                        next;
                }