diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2007-04-18 00:12:39 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:51:03 -0500 |
commit | 21379ee620547820b36094b5424f54afc55b5a07 (patch) | |
tree | fac077b06f7749f510f8dd900e2f3e1f757c095e /source4 | |
parent | c2d5d6d04612d8400fd732c71c26c5574fd94cee (diff) | |
download | samba-21379ee620547820b36094b5424f54afc55b5a07.tar.gz samba-21379ee620547820b36094b5424f54afc55b5a07.tar.bz2 samba-21379ee620547820b36094b5424f54afc55b5a07.zip |
r22326: Merge some more test improvements.
(This used to be commit 3f85eab5908b8aa6761f23702f987d89f2977179)
Diffstat (limited to 'source4')
-rw-r--r-- | source4/script/tests/Samba3.pm | 330 | ||||
-rwxr-xr-x | source4/script/tests/selftest.pl | 44 |
2 files changed, 288 insertions, 86 deletions
diff --git a/source4/script/tests/Samba3.pm b/source4/script/tests/Samba3.pm index 950f7e3479..e133a6394e 100644 --- a/source4/script/tests/Samba3.pm +++ b/source4/script/tests/Samba3.pm @@ -6,120 +6,292 @@ package Samba3; use strict; +use Cwd qw(abs_path); use FindBin qw($RealBin); -use POSIX; -sub new($$$) { - my ($classname, $bindir, $setupdir) = @_; - my $self = { bindir => $bindir, setupdir => $setupdir }; +sub binpath($$) +{ + my ($self, $binary) = @_; + + if (defined($self->{bindir})) { + my $path = "$self->{bindir}/$binary"; + -f $path or die("File $path doesn't exist"); + return $path; + } + + return $binary; +} + +sub new($$) { + my ($classname, $bindir) = @_; + my $self = { bindir => $bindir }; bless $self; return $self; } -sub check_or_start($$$) +sub teardown_env($$) { - my ($self, $env_vars, $max_time) = @_; - return 0 if ( -p $env_vars->{SMBD_TEST_FIFO}); + my ($self, $envvars) = @_; - unlink($env_vars->{SMBD_TEST_FIFO}); - POSIX::mkfifo($env_vars->{SMBD_TEST_FIFO}, 0700); - unlink($env_vars->{SMBD_TEST_LOG}); + $self->samba3_stop_sig_term($envvars->{PIDDIR}); + $self->samba3_stop_sig_kill($envvars->{PIDDIR}); + + return 0; +} + +sub setup_env($$$) +{ + my ($self, $envname, $path) = @_; - my $valgrind = ""; - if (defined($ENV{SMBD_VALGRIND})) { - $valgrind = $ENV{SMBD_VALGRIND}; - } + if ($envname eq "dc") { + return $self->setup_dc("$path/dc"); + } else { + die("Samba4 can't provide environment '$envname'"); + } +} + +sub setup_dc($$) +{ + my ($self, $path) = @_; - print "STARTING SMBD... "; + my $vars = $self->provision($path); + + $self->check_or_start($vars, ($ENV{NMBD_MAXTIME} or 2700), ($ENV{SMBD_MAXTIME} or 2700)); + + $self->wait_for_start($vars); + + return $vars; +} + +sub stop($) +{ + my ($self) = @_; +} + +sub samba3_stop_sig_term($$) { + my ($self, $piddir) = @_; + my $ret = 0; + kill("USR1", `cat $piddir/timelimit.nmbd.pid`) or \ + kill("ALRM", `cat $piddir/timelimit.nmbd.pid`) or $ret++; + + kill("USR1", `cat $piddir/timelimit.smbd.pid`) or \ + kill("ALRM", `cat $piddir/timelimit.smbd.pid`) or $ret++; + + return $ret; +} + +sub samba3_stop_sig_kill($$) { + my ($self, $piddir) = @_; + kill("ALRM", `cat $piddir/timelimit.nmbd.pid`); + kill("ALRM", `cat $piddir/timelimit.smbd.pid`); + return 0; +} + +sub check_or_start($$$$) { + my ($self, $env_vars, $nmbd_maxtime, $smbd_maxtime) = @_; + + unlink($env_vars->{NMBD_TEST_LOG}); + print "STARTING NMBD..."; my $pid = fork(); if ($pid == 0) { - open STDIN, $env_vars->{SMBD_TEST_FIFO}; - open STDOUT, ">$env_vars->{SMBD_TEST_LOG}"; + open STDOUT, ">$env_vars->{NMBD_TEST_LOG}"; open STDERR, '>&STDOUT'; - my $optarg = ""; - if (defined($max_time)) { - $optarg = "--maximum-runtime=$max_time "; - } - my $ret = system("$valgrind $self->{bindir}/smbd $optarg -s $env_vars->{CONFFILE} -M single -i --leak-report-full"); - if ($? == -1) { - print "Unable to start smbd: $ret: $!\n"; - exit 1; - } - unlink($env_vars->{SMBD_TEST_FIFO}); - my $exit = $? >> 8; - if ( $ret == 0 ) { - print "smbd exits with status $exit\n"; - } elsif ( $ret & 127 ) { - print "smbd got signal ".($ret & 127)." and exits with $exit!\n"; - } else { - $ret = $? >> 8; - print "smbd failed with status $exit!\n"; - } - exit $exit; + + $ENV{MAKE_TEST_BINARY} = $self->binpath("nmbd"); + exec($self->binpath("timelimit"), $nmbd_maxtime, $self->binpath("nmbd"), "-F", "-S", "--no-process-group", "-d0" ,"-s", $env_vars->{SERVERCONFFILE}) or die("Unable to start nmbd: $!"); } + open(PID, ">$env_vars->{PIDDIR}/timelimit.nmbd.pid"); + print PID $pid; + close(PID); print "DONE\n"; - open(DATA, ">$env_vars->{SMBD_TEST_FIFO}"); + unlink($env_vars->{SMBD_TEST_LOG}); + print "STARTING SMBD..."; + my $pid = fork(); + if ($pid == 0) { + open STDOUT, ">$env_vars->{SMBD_TEST_LOG}"; + open STDERR, '>&STDOUT'; + + $ENV{MAKE_TEST_BINARY} = $self->binpath("smbd"); + exec($self->binpath("timelimit"), $nmbd_maxtime, $self->binpath("smbd"), "-F", "-S", "--no-process-group", "-d0" ,"-s", $env_vars->{SERVERCONFFILE}) or die("Unable to start smbd: $!"); + } + open(PID, ">$env_vars->{PIDDIR}/timelimit.smbd.pid"); + print PID $pid; + close(PID); + print "DONE\n"; - return $pid; + return 0; } -sub wait_for_start($) +sub create_clientconf($$$) { - # give time for nbt server to register its names - print "delaying for nbt name registration\n"; + my ($self, $prefix, $domain) = @_; + + my $lockdir = "$prefix/locks"; + my $logdir = "$prefix/logs"; + my $piddir = "$prefix/pid"; + my $privatedir = "$prefix/private"; + my $scriptdir = "$RealBin/.."; + my $conffile = "$prefix/smb.conf"; + + my $torture_interfaces='127.0.0.6/8,127.0.0.7/8,127.0.0.8/8,127.0.0.9/8,127.0.0.10/8,127.0.0.11/8'; + open(CONF, ">$conffile"); + print CONF " +[global] + workgroup = $domain - # This will return quickly when things are up, but be slow if we - # need to wait for (eg) SSL init - system("bin/nmblookup $ENV{CONFIGURATION} $ENV{SERVER}"); - system("bin/nmblookup $ENV{CONFIGURATION} -U $ENV{SERVER} $ENV{SERVER}"); - system("bin/nmblookup $ENV{CONFIGURATION} $ENV{SERVER}"); - system("bin/nmblookup $ENV{CONFIGURATION} -U $ENV{SERVER} $ENV{NETBIOSNAME}"); - system("bin/nmblookup $ENV{CONFIGURATION} $ENV{NETBIOSNAME}"); - system("bin/nmblookup $ENV{CONFIGURATION} -U $ENV{SERVER} $ENV{NETBIOSNAME}"); - system("bin/nmblookup $ENV{CONFIGURATION} $ENV{NETBIOSNAME}"); - system("bin/nmblookup $ENV{CONFIGURATION} -U $ENV{SERVER} $ENV{NETBIOSNAME}"); + private dir = $privatedir + pid directory = $piddir + lock directory = $lockdir + log file = $logdir/log.\%m + log level = 0 + + name resolve order = bcast + + netbios name = TORTURE_6 + interfaces = $torture_interfaces + panic action = $scriptdir/gdb_backtrace \%d %\$(MAKE_TEST_BINARY) + + passdb backend = tdbsam + "; + close(CONF); } -sub provision($$$) +sub provision($$) { - my ($self, $environment, $prefix) = @_; + my ($self, $prefix) = @_; + + ## + ## setup the various environment variables we need + ## + my %ret = (); - print "PROVISIONING..."; - open(IN, "$RealBin/mktestdc.sh $prefix|") or die("Unable to setup"); - while (<IN>) { - die ("Error parsing `$_'") unless (/^([A-Z0-9a-z_]+)=(.*)$/); - $ret{$1} = $2; - } - close(IN); + my $server = "localhost2"; + my $server_ip = "127.0.0.2"; + my $username = `PATH=/usr/ucb:$ENV{PATH} whoami`; + my $password = "test"; - $ret{SMBD_TEST_FIFO} = "$prefix/smbd_test.fifo"; - $ret{SMBD_TEST_LOG} = "$prefix/smbd_test.log"; - return \%ret; -} + my $srcdir="$RealBin/../.."; + my $scriptdir="$srcdir/script/tests"; + my $prefix_abs = abs_path($prefix); + my $shrdir="$prefix_abs/tmp"; + my $libdir="$prefix_abs/lib"; + my $piddir="$prefix_abs/pid"; + my $conffile="$libdir/server.conf"; + my $privatedir="$prefix_abs/private"; + my $lockdir="$prefix_abs/lockdir"; + my $logdir="$prefix_abs/logs"; + my $domain = "SAMBA-TEST"; -sub stop($) -{ - my ($self) = @_; + ## + ## create the test directory layout + ## + mkdir($prefix_abs); + print "CREATE TEST ENVIRONMENT IN '$prefix'..."; + system("rm -rf $prefix_abs/*"); + mkdir($_) foreach($privatedir,$libdir,$piddir,$lockdir,$logdir); + my $tmpdir = "$prefix_abs/tmp"; + mkdir($tmpdir); + chmod 0777, $tmpdir; - close(DATA); + open(CONF, ">$conffile") or die("Unable to open $conffile"); + print CONF " +[global] + workgroup = $domain - sleep(2); + private dir = $privatedir + pid directory = $piddir + lock directory = $lockdir + log file = $logdir/log.\%m + log level = 0 - my $failed = $? >> 8; + name resolve order = bcast - if (-f "$ENV{PIDDIR}/smbd.pid" ) { - open(IN, "<$ENV{PIDDIR}/smbd.pid") or die("unable to open smbd pid file"); - kill 9, <IN>; - close(IN); - } + netbios name = $server + interfaces = $server_ip/8 + bind interfaces only = yes + panic action = $scriptdir/gdb_backtrace %d %\$(MAKE_TEST_BINARY) + + passdb backend = tdbsam + + ; Necessary to add the build farm hacks + add user script = /bin/false + add machine script = /bin/false + + kernel oplocks = no + kernel change notify = no + + syslog = no + printing = bsd + printcap name = /dev/null + +[tmp] + path = $tmpdir + read only = no + smbd:sharedelay = 100000 + map hidden = yes + map system = yes + create mask = 755 +[hideunread] + copy = tmp + hide unreadable = yes +[hideunwrite] + copy = tmp + hide unwriteable files = yes +[print1] + copy = tmp + printable = yes + printing = test +[print2] + copy = print1 +[print3] + copy = print1 +[print4] + copy = print1 + "; + close(CONF); - return $failed; + ## + ## create a test account + ## + + open(PWD, "|".$self->binpath("smbpasswd")." -c $conffile -L -s -a $username"); + print PWD "$password\n$password\n"; + close(PWD) or die("Unable to set password for test account"); + + print "DONE\n"; + + $ret{SERVER_IP} = $server_ip; + $ret{NMBD_TEST_LOG} = "$prefix/nmbd_test.log"; + $ret{SMBD_TEST_LOG} = "$prefix/smbd_test.log"; + $ret{SERVERCONFFILE} = $conffile; + $ret{CONFIGURATION} ="-s $conffile"; + $ret{SERVER} = $server; + $ret{USERNAME} = $username; + $ret{DOMAIN} = $domain; + $ret{NETBIOSNAME} = $server; + $ret{PASSWORD} = $password; + $ret{PIDDIR} = $piddir; + return \%ret; } -sub setup_env($$) +sub wait_for_start($$) { - my ($self, $name) = @_; + my ($self, $envvars) = @_; + + # give time for nbt server to register its names + print "delaying for nbt name registration\n"; + sleep(10); + # This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init + system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} __SAMBA__"); + system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} __SAMBA__"); + system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} -U 127.255.255.255 __SAMBA__"); + system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} $envvars->{SERVER}"); + system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} $envvars->{SERVER}"); + # make sure smbd is also up set + print "wait for smbd\n"; + system($self->binpath("smbclient") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER_IP} -U% -p 139 | head -2"); + system($self->binpath("smbclient") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER_IP} -U% -p 139 | head -2"); } 1; diff --git a/source4/script/tests/selftest.pl b/source4/script/tests/selftest.pl index f834918b8e..52875ed1ee 100755 --- a/source4/script/tests/selftest.pl +++ b/source4/script/tests/selftest.pl @@ -124,6 +124,7 @@ my $opt_target = "samba4"; my $opt_quick = 0; my $opt_socket_wrapper = 0; my $opt_socket_wrapper_pcap = undef; +my $opt_socket_wrapper_keep_pcap = undef; my $opt_one = 0; my $opt_immediate = 0; my $opt_expected_failures = undef; @@ -133,6 +134,7 @@ my $opt_testenv = 0; my $ldap = undef; my $opt_analyse_cmd = undef; my $opt_resetup_env = undef; +my $opt_bindir = undef; my $srcdir = "."; my $builddir = "."; @@ -227,6 +229,8 @@ sub run_test_buildfarm($$$$) print "TEST FAILED: $name (status $ret)\n"; } print "==========================================\n"; + + return ($ret == $expected_ret); } my $test_output = {}; @@ -286,6 +290,8 @@ sub run_test_plain($$$$) } else { $statistics->{SUITES_OK}++; } + + return ($ret == $expected_ret); } sub ShowHelp() @@ -297,6 +303,7 @@ Usage: $Script [OPTIONS] PREFIX Generic options: --help this help page + --target=samba4|samba3|win Samba version to target Paths: --prefix=DIR prefix to run tests in [st] @@ -304,12 +311,18 @@ Paths: --builddir=DIR output directory [.] Target Specific: - --target=samba4|samba3|win Samba version to target - --socket-wrapper-pcap=FILE save traffic to pcap file + --socket-wrapper-pcap=DIR 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 --expected-failures=FILE specify list of tests that is guaranteed to fail + +Samba4 Specific: --ldap=openldap|fedora back smbd onto specified ldap server +Samba3 Specific: + --bindir=PATH path to binaries + Behaviour: --quick run quick overall test --one abort when the first test fails @@ -325,7 +338,8 @@ my $result = GetOptions ( 'target=s' => \$opt_target, 'prefix=s' => \$prefix, 'socket-wrapper' => \$opt_socket_wrapper, - 'socket-wrapper-pcap=s' => \$opt_socket_wrapper_pcap, + 'socket-wrapper-pcap' => \$opt_socket_wrapper_pcap, + 'socket-wrapper-keep-pcap' => \$opt_socket_wrapper_keep_pcap, 'quick' => \$opt_quick, 'one' => \$opt_one, 'immediate' => \$opt_immediate, @@ -338,6 +352,7 @@ my $result = GetOptions ( 'ldap:s' => \$ldap, 'analyse-cmd=s' => \$opt_analyse_cmd, 'resetup-environment' => \$opt_resetup_env, + 'bindir:s' => \$opt_bindir, ); exit(1) if (not $result); @@ -401,8 +416,10 @@ if (defined($ENV{LD_LIBRARY_PATH})) { $ENV{PKG_CONFIG_PATH} = "$old_pwd/bin/pkgconfig:$ENV{PKG_CONFIG_PATH}"; $ENV{PATH} = "$old_pwd/bin:$ENV{PATH}"; +my $pcap_dir = "$prefix/pcap"; + if ($opt_socket_wrapper_pcap) { - SocketWrapper::setup_pcap($opt_socket_wrapper_pcap); + mkdir($pcap_dir); # Socket wrapper pcap implies socket wrapper $opt_socket_wrapper = 1; } @@ -420,7 +437,11 @@ my $target; if ($opt_target eq "samba4") { $target = new Samba4("$srcdir/bin", $ldap, "$srcdir/setup"); } elsif ($opt_target eq "samba3") { - $target = new Samba3("$srcdir/bin", "$srcdir/setup"); + if ($opt_socket_wrapper and `smbd -b | grep SOCKET_WRAPPER` eq "") { + die("You must include --enable-socket-wrapper when compiling Samba in order to execute 'make test'. Exiting...."); + } + + $target = new Samba3($opt_bindir); } elsif ($opt_target eq "win") { die("Windows tests will not run with socket wrapper enabled.") if ($opt_socket_wrapper); @@ -619,10 +640,19 @@ NETBIOSNAME=\$NETBIOSNAME\" && bash'"); setup_env($envname); + my $pcap_file = "$pcap_dir/$name.cap"; + + SocketWrapper::setup_pcap($pcap_file) if ($opt_socket_wrapper_pcap); + my $result; if ($from_build_farm) { - run_test_buildfarm($name, $cmd, $i, $suitestotal); + $result = run_test_buildfarm($name, $cmd, $i, $suitestotal); } else { - run_test_plain($name, $cmd, $i, $suitestotal); + $result = run_test_plain($name, $cmd, $i, $suitestotal); + } + + if ($opt_socket_wrapper_pcap and $result and + not $opt_socket_wrapper_keep_pcap) { + unlink($pcap_file); } if (defined($opt_analyse_cmd)) { |