upgradeprovision: reduce the number of attribute that we skip
[ira/wip.git] / selftest / selftest.pl
index 1da13318cddd653237b9bb9e14ae42d7eefcd063..d72c409fa26505796d0bd161e40d62ee2820577b 100755 (executable)
@@ -26,7 +26,7 @@ selftest - Samba test runner
 
 selftest --help
 
-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]
+selftest [--srcdir=DIR] [--bindir=DIR] [--exeext=EXT][--target=samba4|samba3|win|kvm] [--socket-wrapper] [--quick] [--exclude=FILE] [--include=FILE] [--one] [--prefix=prefix] [--testlist=FILE] [TESTS]
 
 =head1 DESCRIPTION
 
@@ -44,9 +44,9 @@ Show list of available options.
 
 Source directory.
 
-=item I<--builddir=DIR>
+=item I<--bindir=DIR>
 
-Build directory.
+Built binaries directory.
 
 =item I<--exeext=EXT>
 
@@ -156,12 +156,12 @@ my $opt_testenv = 0;
 my $opt_list = 0;
 my $ldap = undef;
 my $opt_resetup_env = undef;
-my $opt_bindir = undef;
+my $opt_binary_mapping = "";
 my $opt_load_list = undef;
 my @testlists = ();
 
 my $srcdir = ".";
-my $builddir = ".";
+my $bindir = "./bin";
 my $exeext = "";
 my $prefix = "./st";
 
@@ -306,7 +306,7 @@ Generic options:
 Paths:
  --prefix=DIR               prefix to run tests in [st]
  --srcdir=DIR               source directory [.]
- --builddir=DIR             output directory [.]
+ --bindir=DIR               binaries directory [./bin]
  --exeext=EXT               executable extention []
 
 Target Specific:
@@ -314,7 +314,6 @@ Target Specific:
  --socket-wrapper-keep-pcap keep all pcap files, not just those for tests that 
                             failed
  --socket-wrapper           enable socket wrapper
- --bindir=PATH              path to target binaries
 
 Samba4 Specific:
  --ldap=openldap|fedora-ds  back samba onto specified ldap server
@@ -344,17 +343,17 @@ my $result = GetOptions (
                'exclude=s' => \@opt_exclude,
                'include=s' => \@opt_include,
                'srcdir=s' => \$srcdir,
-               'builddir=s' => \$builddir,
+               'bindir=s' => \$bindir,
                'exeext=s' => \$exeext,
                'verbose' => \$opt_verbose,
                'testenv' => \$opt_testenv,
                'list' => \$opt_list,
                'ldap:s' => \$ldap,
                'resetup-environment' => \$opt_resetup_env,
-               'bindir:s' => \$opt_bindir,
                'image=s' => \$opt_image,
                'testlist=s' => \@testlists,
                'load-list=s' => \$opt_load_list,
+                'binary-mapping=s' => \$opt_binary_mapping
            );
 
 exit(1) if (not $result);
@@ -377,7 +376,6 @@ unless (defined($ENV{VALGRIND})) {
 # make all our python scripts unbuffered
 $ENV{PYTHONUNBUFFERED} = 1;
 
-my $bindir = ($opt_bindir or "$builddir/bin");
 my $bindir_abs = abs_path($bindir);
 
 # Backwards compatibility:
@@ -401,15 +399,20 @@ $prefix =~ s+/$++;
 
 die("using an empty prefix isn't allowed") unless $prefix ne "";
 
-#Ensure we have the test prefix around
-mkdir($prefix, 0777) unless -d $prefix;
+# Ensure we have the test prefix around.
+#
+# We need restrictive
+# permissions on this as some subdirectories in this tree will have
+# wider permissions (ie 0777) and this would allow other users on the
+# host to subvert the test process.
+mkdir($prefix, 0700) unless -d $prefix;
+chmod 0700, $prefix;
 
 my $prefix_abs = abs_path($prefix);
 my $tmpdir_abs = abs_path("$prefix/tmp");
 mkdir($tmpdir_abs, 0777) unless -d $tmpdir_abs;
 
 my $srcdir_abs = abs_path($srcdir);
-my $builddir_abs = abs_path($builddir);
 
 die("using an empty absolute prefix isn't allowed") unless $prefix_abs ne "";
 die("using '/' as absolute prefix isn't allowed") unless $prefix_abs ne "/";
@@ -419,8 +422,7 @@ $ENV{KRB5CCNAME} = "$prefix/krb5ticket";
 $ENV{PREFIX_ABS} = $prefix_abs;
 $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;
@@ -461,17 +463,44 @@ if ($opt_socket_wrapper) {
 my $target;
 my $testenv_default = "none";
 
-if ($opt_target eq "samba4") {
+my %binary_mapping = ();
+if ($opt_binary_mapping) {
+    my @binmapping_list = split(/,/, $opt_binary_mapping);
+    foreach my $mapping (@binmapping_list) {
+       my ($bin, $map) = split(/\:/, $mapping);
+       $binary_mapping{$bin} = $map;
+    }
+}
+
+$ENV{BINARY_MAPPING} = $opt_binary_mapping;
+
+# After this many seconds, the server will self-terminate.  All tests
+# must terminate in this time, and testenv will only stay alive this
+# long
+
+my $server_maxtime = 7500;
+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 "samba4") {
        $testenv_default = "all";
        require target::Samba4;
-       $target = new Samba4($bindir, $ldap, "$srcdir/setup", $exeext);
+       $target = new Samba4($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....");
        }
        $testenv_default = "member";
        require target::Samba3;
-       $target = new Samba3($bindir);
+       $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);
@@ -568,19 +597,23 @@ sub write_clientconf($$$)
                mkdir("$clientdir/lockdir", 0777);
        }
 
+       # this is ugly, but the ncalrpcdir needs exactly 0755
+       # otherwise tests fail.
+       my $mask = umask;
+       umask 0022;
+       if ( -d "$clientdir/ncalrpcdir/np" ) {
+               unlink <$clientdir/ncalrpcdir/np/*>;
+               rmdir "$clientdir/ncalrpcdir/np";
+       }
        if ( -d "$clientdir/ncalrpcdir" ) {
                unlink <$clientdir/ncalrpcdir/*>;
-       } else {
-               mkdir("$clientdir/ncalrpcdir", 0777);
+               rmdir "$clientdir/ncalrpcdir";
        }
+       mkdir("$clientdir/ncalrpcdir", 0755);
+       umask $mask;
 
        open(CF, ">$conffile");
        print CF "[global]\n";
-       if (defined($ENV{VALGRIND})) {
-               print CF "\ticonv:native = true\n";
-       } else {
-               print CF "\ticonv:native = false\n";
-       }
        print CF "\tnetbios name = client\n";
        if (defined($vars->{DOMAIN})) {
                print CF "\tworkgroup = $vars->{DOMAIN}\n";
@@ -595,8 +628,8 @@ sub write_clientconf($$$)
        private dir = $clientdir/private
        lock dir = $clientdir/lockdir
        ncalrpc dir = $clientdir/ncalrpcdir
-       name resolve order = bcast file
-       panic action = $RealBin/gdb_backtrace \%PID\% \%PROG\%
+       name resolve order = file bcast
+       panic action = $RealBin/gdb_backtrace \%PID\%
        max xmit = 32K
        notify:inotify = false
        ldb:nosync = true
@@ -606,7 +639,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
-       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
@@ -616,8 +648,6 @@ sub write_clientconf($$$)
 
 my @todo = ();
 
-my $testsdir = "$srcdir/selftest";
-
 sub should_run_test($)
 {
        my $name = shift;
@@ -682,7 +712,6 @@ if ($opt_quick) {
 } else {
        $ENV{SELFTEST_QUICK} = "";
 }
-$ENV{SELFTEST_TARGET} = $opt_target;
 $ENV{SELFTEST_MAXTIME} = $torture_maxtime;
 
 my @available = ();
@@ -848,14 +877,21 @@ sub setup_env($$)
                $testenv_vars = {};
        } elsif (defined(get_running_env($envname))) {
                $testenv_vars = get_running_env($envname);
-               if (not $target->check_env($testenv_vars)) {
-                       print $target->getlog_env($testenv_vars);
+               if (not $testenv_vars->{target}->check_env($testenv_vars)) {
+                       print $testenv_vars->{target}->getlog_env($testenv_vars);
                        $testenv_vars = undef;
                }
        } else {
                $testenv_vars = $target->setup_env($envname, $prefix);
+               if (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'");
+               }
        }
 
+       
        return undef unless defined($testenv_vars);
 
        $running_envs{$envname} = $testenv_vars;
@@ -899,21 +935,24 @@ sub getlog_env($)
 {
        my ($envname) = @_;
        return "" if ($envname eq "none");
-       return $target->getlog_env(get_running_env($envname));
+       my $env = get_running_env($envname);
+       return $env->{target}->getlog_env($env);
 }
 
 sub check_env($)
 {
        my ($envname) = @_;
        return 1 if ($envname eq "none");
-       return $target->check_env(get_running_env($envname));
+       my $env = get_running_env($envname);
+       return $env->{target}->check_env($env);
 }
 
 sub teardown_env($)
 {
        my ($envname) = @_;
        return if ($envname eq "none");
-       $target->teardown_env(get_running_env($envname));
+       my $env = get_running_env($envname);
+       $env->{target}->teardown_env($env);
        delete $running_envs{$envname};
 }