smbd: Use dos_mode_debug_print in get_ea_dos_attribute
[kai/samba-autobuild/.git] / selftest / selftest.pl
index 8342bfe8d2c429cc3c7deb5657b762d4fee75125..db5da05091eecb2fbe3870bdef8de0178b918f01 100755 (executable)
@@ -50,11 +50,12 @@ 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 = ".";
@@ -190,6 +191,8 @@ Generic options:
  --help                     this help page
  --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]
@@ -198,9 +201,14 @@ Paths:
 
 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-keep-pcap keep all pcap files, not just those for tests that 
@@ -239,10 +247,11 @@ my $result = GetOptions (
                'testlist=s' => \@testlists,
                'random-order' => \$opt_random_order,
                'load-list=s' => \$opt_load_list,
-               '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
+               'uid_wrapper_so_path=s' => \$opt_libuid_wrapper_so_path,
+               'use-dns-faking' => \$opt_use_dns_faking
            );
 
 exit(1) if (not $result);
@@ -348,6 +357,14 @@ if ($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";
@@ -381,43 +398,37 @@ 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";
 } elsif (not $opt_list) {
-        unless ($< == 0) { 
+        unless ($< == 0) {
                 warn("not using socket wrapper, but also not running as root. Will not be able to listen on proper ports");
         }
 }
 
-my $target;
-my $testenv_default = "none";
-
-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;
-    }
+if ($opt_use_dns_faking) {
+       print "DNS: Faking nameserver\n";
+       $ENV{SAMBA_DNS_FAKING} = 1;
 }
 
-$ENV{BINARY_MAPPING} = $opt_binary_mapping;
+my $target;
+my $testenv_default = "none";
 
 # 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;
+my $server_maxtime = 10800;
 if (defined($ENV{SMBD_MAXTIME}) and $ENV{SMBD_MAXTIME} ne "") {
     $server_maxtime = $ENV{SMBD_MAXTIME};
 }
 
 unless ($opt_list) {
        if ($opt_target eq "samba") {
-               $testenv_default = "dc";
+               $testenv_default = "ad_dc_ntvfs";
                require target::Samba;
-               $target = new Samba($bindir, \%binary_mapping, $ldap, $srcdir, $server_maxtime);
+               $target = new Samba($bindir, $ldap, $srcdir, $server_maxtime);
        } elsif ($opt_target eq "samba3") {
-               $testenv_default = "member";
+               $testenv_default = "nt4_member";
                require target::Samba3;
-               $target = new Samba3($bindir, \%binary_mapping, $srcdir_abs, $server_maxtime);
+               $target = new Samba3($bindir, $srcdir_abs, $server_maxtime);
        }
 }
 
@@ -523,7 +534,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
@@ -534,7 +544,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
-       resolv:host file = $prefix_abs/dns_host_file
 #We don't want to run 'speed' tests for very long
         torture:timelimit = 1
         winbind separator = /
@@ -566,23 +575,27 @@ sub read_testlist($)
        open(IN, $filename) or die("Unable to open $filename: $!");
 
        while (<IN>) {
-               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 = <IN>;
                        $name =~ s/\n//g;
                        my $env = <IN>;
                        $env =~ s/\n//g;
+                       my $loadlist;
+                       if ($supports_loadlist) {
+                               $loadlist = <IN>;
+                               $loadlist =~ s/\n//g;
+                       }
                        my $cmdline = <IN>;
                        $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;
 }
 
@@ -704,6 +717,16 @@ my @exported_envvars = (
        "DOMAIN",
        "REALM",
 
+       # stuff related to a trusted domain
+       "TRUST_SERVER",
+       "TRUST_SERVER_IP",
+       "TRUST_SERVER_IPV6",
+       "TRUST_NETBIOSNAME",
+       "TRUST_USERNAME",
+       "TRUST_PASSWORD",
+       "TRUST_DOMAIN",
+       "TRUST_REALM",
+
        # domain controller stuff
        "DC_SERVER",
        "DC_SERVER_IP",
@@ -752,6 +775,10 @@ my @exported_envvars = (
        "DC_USERNAME",
        "DC_PASSWORD",
 
+       # UID/GID for rfc2307 mapping tests
+       "UID_RFC2307TEST",
+       "GID_RFC2307TEST",
+
        # misc stuff
        "KRB5_CONFIG",
        "SELFTEST_WINBINDD_SOCKET_DIR",
@@ -759,13 +786,16 @@ my @exported_envvars = (
        "NMBD_SOCKET_DIR",
        "LOCAL_PATH",
 
-        # nss_wrapper
-        "NSS_WRAPPER_PASSWD",
-        "NSS_WRAPPER_GROUP",
+       # nss_wrapper
+       "NSS_WRAPPER_PASSWD",
+       "NSS_WRAPPER_GROUP",
+       "NSS_WRAPPER_HOSTS",
+       "NSS_WRAPPER_MODULE_SO_PATH",
+       "NSS_WRAPPER_MODULE_FN_PREFIX",
 
-        # UID/GID for rfc2307 mapping tests
-        "UID_RFC2307TEST",
-        "GID_RFC2307TEST"
+       # resolv_wrapper
+       "RESOLV_WRAPPER_CONF",
+       "RESOLV_WRAPPER_HOSTS",
 );
 
 sub sighandler($)
@@ -801,9 +831,7 @@ sub setup_env($$)
 
        $option = "client" if $option eq "";
 
-       if ($envname eq "none") {
-               $testenv_vars = {};
-       } elsif (defined(get_running_env($envname))) {
+       if (defined(get_running_env($envname))) {
                $testenv_vars = get_running_env($envname);
                if (not $testenv_vars->{target}->check_env($testenv_vars)) {
                        print $testenv_vars->{target}->getlog_env($testenv_vars);
@@ -821,7 +849,6 @@ sub setup_env($$)
                }
        }
 
-       
        return undef unless defined($testenv_vars);
 
        $running_envs{$envname} = $testenv_vars;
@@ -872,7 +899,6 @@ sub getlog_env($)
 sub check_env($)
 {
        my ($envname) = @_;
-       return 1 if ($envname eq "none");
        my $env = get_running_env($envname);
        return $env->{target}->check_env($env);
 }
@@ -937,23 +963,25 @@ $envvarstr
        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(sprintf("%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;
@@ -990,9 +1018,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.");
                        }
                }