From e338b4b47b6271ca46060a1fe8c61ab8afaecc8f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 10 Apr 2007 20:19:31 +0000 Subject: r22156: - Lazy evaluate variable names. - Don't set up environments until necessary - Add --resetup-environment option - Add 'none' environment (This used to be commit ed0410309bfdefb0d31cb247c26b947956fb1137) --- source4/script/tests/Samba4.pm | 58 ++++++++++----- source4/script/tests/mk-openldap.sh | 2 +- source4/script/tests/mktestdc.sh | 2 - source4/script/tests/selftest.pl | 111 ++++++++++++++++++++-------- source4/script/tests/test_binding_string.sh | 33 +++------ source4/script/tests/test_blackbox.sh | 18 ++--- source4/script/tests/test_echo.sh | 27 +------ source4/script/tests/test_ejs.sh | 21 ++---- source4/script/tests/test_ldap.sh | 25 ++----- source4/script/tests/test_local.sh | 7 -- source4/script/tests/test_nbt.sh | 17 +---- source4/script/tests/test_net.sh | 15 +--- source4/script/tests/test_posix.sh | 14 +--- source4/script/tests/test_quick.sh | 18 +---- source4/script/tests/test_rpc.sh | 17 +---- source4/script/tests/test_rpc_quick.sh | 15 +--- source4/script/tests/test_session_key.sh | 24 ++---- source4/script/tests/test_simple.sh | 18 +---- source4/script/tests/tests_all.sh | 22 +++--- source4/script/tests/tests_quick.sh | 10 +-- 20 files changed, 186 insertions(+), 288 deletions(-) (limited to 'source4/script/tests') diff --git a/source4/script/tests/Samba4.pm b/source4/script/tests/Samba4.pm index fa20ccbdaf..ac3dc653b8 100644 --- a/source4/script/tests/Samba4.pm +++ b/source4/script/tests/Samba4.pm @@ -16,10 +16,14 @@ sub new($$$$) { return $self; } -sub slapd_start($$$) +sub slapd_start($$) { my $count = 0; - my ($self, $conf, $uri) = @_; + my ($self, $env_vars) = @_; + + my $conf = $env_vars->{SLAPD_CONF}; + my $uri = $env_vars->{LDAP_URI}; + # running slapd in the background means it stays in the same process group, so it can be # killed by timelimit if (defined($ENV{FEDORA_DS_PREFIX})) { @@ -33,7 +37,7 @@ sub slapd_start($$$) while (system("$self->{bindir}/ldbsearch -H $uri -s base -b \"\" supportedLDAPVersion > /dev/null") != 0) { $count++; if ($count > 10) { - $self->slapd_stop(); + $self->slapd_stop($env_vars); return 0; } sleep(1); @@ -41,13 +45,13 @@ sub slapd_start($$$) return 1; } -sub slapd_stop($) +sub slapd_stop($$) { - my ($self) = @_; - if (defined($ENV{FEDORA_DS_PREFIX})) { - system("$ENV{LDAPDIR}/slapd-samba4/stop-slapd"); + my ($self, $envvars) = @_; + if (defined($envvars->{FEDORA_DS_PREFIX})) { + system("$envvars->{LDAPDIR}/slapd-samba4/stop-slapd"); } else { - open(IN, "<$ENV{PIDDIR}/slapd.pid") or + open(IN, "<$envvars->{PIDDIR}/slapd.pid") or die("unable to open slapd pid file"); kill 9, ; close(IN); @@ -61,7 +65,7 @@ sub check_or_start($$$$) # Start slapd before smbd if ($self->{ldap}) { - $self->slapd_start($ENV{SLAPD_CONF}, $ENV{LDAP_URI}) or + $self->slapd_start($env_vars) or die("couldn't start slapd"); print "LDAP PROVISIONING..."; @@ -132,9 +136,9 @@ sub wait_for_start($$) system("bin/nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER} $testenv_vars->{NETBIOSNAME}"); } -sub provision($$$) +sub provision($$) { - my ($self, $environment, $prefix) = @_; + my ($self, $prefix) = @_; my %ret = (); print "PROVISIONING..."; open(IN, "$RealBin/mktestdc.sh $prefix|") or die("Unable to setup"); @@ -156,9 +160,9 @@ sub provision_ldap($) die("LDAP PROVISIONING failed: $self->{bindir}/smbscript $self->{setupdir}/provision $ENV{PROVISION_OPTIONS} \"$ENV{PROVISION_ACI}\" --ldap-backend=$ENV{LDAP_URI}"); } -sub stop($) +sub teardown_env($$) { - my ($self) = @_; + my ($self, $envvars) = @_; close(DATA); @@ -166,22 +170,33 @@ sub stop($) my $failed = $? >> 8; - if (-f "$ENV{PIDDIR}/smbd.pid" ) { - open(IN, "<$ENV{PIDDIR}/smbd.pid") or die("unable to open smbd pid file"); + if (-f "$envvars->{PIDDIR}/smbd.pid" ) { + open(IN, "<$envvars->{PIDDIR}/smbd.pid") or die("unable to open smbd pid file"); kill 9, ; close(IN); } - $self->slapd_stop() if ($self->{ldap}); + $self->slapd_stop($envvars) if ($self->{ldap}); return $failed; } -sub setup_env($$$) +sub setup_env($$$$) { - my ($self, $name, $path, $socket_wrapper_dir) = @_; + my ($self, $envname, $path, $socket_wrapper_dir) = @_; + + if ($envname eq "dc") { + return $self->setup_dc("$path/dc", $socket_wrapper_dir); + } else { + die("Samba4 can't provide environment $envname"); + } +} + +sub setup_dc($$$) +{ + my ($self, $path, $socket_wrapper_dir) = @_; - my $env = $self->provision($name, $path); + my $env = $self->provision($path); $self->check_or_start($env, $socket_wrapper_dir, ($ENV{SMBD_MAX_TIME} or 5400)); @@ -191,4 +206,9 @@ sub setup_env($$$) return $env; } +sub stop($) +{ + my ($self) = @_; +} + 1; diff --git a/source4/script/tests/mk-openldap.sh b/source4/script/tests/mk-openldap.sh index b580d75417..a70db73c74 100755 --- a/source4/script/tests/mk-openldap.sh +++ b/source4/script/tests/mk-openldap.sh @@ -99,7 +99,7 @@ rm -f $MODCONF touch $MODCONF slaptest -u -f $SLAPD_CONF >&2 || { - echo "enabling slapd modules" >&2 + # echo "enabling slapd modules" >&2 cat > $MODCONF < 0) { $err = ", ".($#$suitesfailed+1)." errors"; } - printf "[$i/$totalsuites in " . (time() - $start)."s$err] $name\n"; + print "[$i/$totalsuites in " . (time() - $start)."s$err] $name\n"; open(RESULT, "$cmd 2>&1|"); my $expected_ret = 1; my $open_tests = {}; @@ -335,6 +336,7 @@ my $result = GetOptions ( 'testenv' => \$opt_testenv, 'ldap' => \$opt_ldap, 'analyse-cmd=s' => \$opt_analyse_cmd, + 'resetup-environment' => \$opt_resetup_env, ); exit(1) if (not $result); @@ -434,28 +436,44 @@ my $interfaces = join(',', ("127.0.0.6/8", "127.0.0.10/8", "127.0.0.11/8")); -my $testenv_vars = $target->setup_env("dc", "$prefix/dc", $socket_wrapper_dir); - my $conffile = "$prefix/client.conf"; -my $abs_srcdir = cwd(); -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 + +sub write_clientconf($$) +{ + my ($conffile, $vars) = @_; + + my $abs_srcdir = cwd(); + + 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 " netbios name = localtest netbios aliases = localhost - workgroup = $testenv_vars->{DOMAIN} - realm = $testenv_vars->{REALM} - pid directory = $testenv_vars->{PIDDIR} - ncalrpc dir = $testenv_vars->{NCALRPCDIR} +"; + if (defined($vars->{DOMAIN})) { + print CF "\tworkgroup = $vars->{DOMAIN}\n"; + } + if (defined($vars->{REALM})) { + print CF "\trealm = $vars->{REALM}\n"; + } + if (defined($vars->{PIDDIR})) { + print CF "\tpid directory = $vars->{PIDDIR}\n"; + } + if (defined($vars->{NCALRPCDIR})) { + print CF "\tncalrpc dir = $vars->{NCALRPCDIR}\n"; + } + if (defined($vars->{WINBINDD_SOCKET_DIR})) { + print CF "\twinbindd socket directory = $vars->{WINBINDD_SOCKET_DIR}\n"; + } + print CF " js include = $abs_srcdir/scripting/libjs - winbindd socket directory = $testenv_vars->{WINBINDD_SOCKET_DIR} name resolve order = bcast - interfaces = 127.0.0.1/8 + interfaces = $interfaces panic action = $abs_srcdir/script/gdb_backtrace \%PID\% \%PROG\% max xmit = 32K notify:inotify = false @@ -465,10 +483,11 @@ print CF torture:basedir = ./st gensec:require_pac = true "; -close(CF); + close(CF); +} + my @torture_options = (); -push (@torture_options, "--option=interfaces=$interfaces"); push (@torture_options, "--configfile=$conffile"); # ensure any one smbtorture call doesn't run too long push (@torture_options, "--maximum-runtime=$torture_maxtime"); @@ -480,15 +499,12 @@ push (@torture_options, "--option=torture:quick=yes") if ($opt_quick); $ENV{TORTURE_OPTIONS} = join(' ', @torture_options); print "OPTIONS $ENV{TORTURE_OPTIONS}\n"; -foreach ("PASSWORD", "DOMAIN", "SERVER", "USERNAME", "NETBIOSNAME") { - $ENV{$_} = $testenv_vars->{$_}; -} - my @todo = (); my $testsdir = "$srcdir/script/tests"; $ENV{CONFIGURATION} = "--configfile=$conffile"; + if ($opt_quick) { open(IN, "$testsdir/tests_quick.sh|"); } else { @@ -514,14 +530,44 @@ my $suitestotal = $#todo + 1; my $i = 0; $| = 1; -# The Kerberos tests fail if this variable is set. -delete $ENV{DOMAIN}; +my %running_envs = (); -$ENV{KRB5_CONFIG} = $testenv_vars->{KRB5_CONFIG}; +sub setup_env($) +{ + my ($envname) = @_; + my $testenv_vars; + if (defined($running_envs{$envname})) { + $testenv_vars = $running_envs{$envname}; + } elsif ($envname eq "none") { + $testenv_vars = {}; + } else { + $testenv_vars = $target->setup_env($envname, $prefix, $socket_wrapper_dir); + } + write_clientconf($conffile, $testenv_vars); + foreach ("PASSWORD", "DOMAIN", "SERVER", "USERNAME", "NETBIOSNAME", + "KRB5_CONFIG") { + if (defined($testenv_vars->{$_})) { + $ENV{$_} = $testenv_vars->{$_}; + } else { + delete $ENV{$_}; + } + } + + $running_envs{$envname} = $testenv_vars; + return $testenv_vars; +} + +sub teardown_env($) +{ + my ($envname) = @_; + $target->teardown_env($running_envs{$envname}); + delete $running_envs{$envname}; +} SocketWrapper::set_default_iface(6); if ($opt_testenv) { + my $testenv_vars = setup_env("dc"); $ENV{PIDDIR} = $testenv_vars->{PIDDIR}; my $term = ($ENV{TERM} or "xterm"); system("$term -e 'echo -e \"Welcome to the Samba4 Test environment @@ -533,6 +579,7 @@ TORTURE_OPTIONS=\$TORTURE_OPTIONS CONFIGURATION=\$CONFIGURATION SERVER=\$SERVER NETBIOSNAME=\$NETBIOSNAME\" && bash'"); + teardown_env("dc"); } else { foreach (@todo) { $i++; @@ -547,7 +594,7 @@ NETBIOSNAME=\$NETBIOSNAME\" && bash'"); next; } - # $target->setup_env($envname, "$prefix/$envname", $socket_wrapper_dir); + setup_env($envname); if ($from_build_farm) { run_test_buildfarm($name, $cmd, $i, $suitestotal); @@ -558,12 +605,16 @@ NETBIOSNAME=\$NETBIOSNAME\" && bash'"); if (defined($opt_analyse_cmd)) { system("$opt_analyse_cmd \"$name\""); } + + teardown_env($envname) if ($opt_resetup_env); } } print "\n"; -my $failed = $target->stop(); +teardown_env($_) foreach (keys %running_envs); + +$target->stop(); my $end = time(); my $duration = ($end-$start); @@ -587,6 +638,8 @@ if ($numfailed == 0) { } print "DURATION: $duration seconds\n"; +my $failed = 0; + # if there were any valgrind failures, show them foreach (<$prefix/valgrind.log*>) { next unless (-s $_); diff --git a/source4/script/tests/test_binding_string.sh b/source4/script/tests/test_binding_string.sh index 9558893981..a8afc07ac1 100755 --- a/source4/script/tests/test_binding_string.sh +++ b/source4/script/tests/test_binding_string.sh @@ -1,31 +1,18 @@ #!/bin/sh -if [ $# -lt 4 ]; then -cat < /dev/null; then p=ldaps - for options in "" "-U$USERNAME%$PASSWORD"; do - plantest "TESTING PROTOCOL $p with options $options" ldap ../testprogs/blackbox/test_ldb.sh $p $SERVER $options + for options in "" "-U\$USERNAME%\$PASSWORD"; do + plantest "TESTING PROTOCOL $p with options $options" dc ../testprogs/blackbox/test_ldb.sh $p \$SERVER $options done fi for t in LDAP-CLDAP LDAP-BASIC LDAP-SCHEMA LDAP-UPTODATENESS do - plantest "$t" ldap bin/smbtorture $TORTURE_OPTIONS "-U$USERNAME%$PASSWORD" //$SERVER/_none_ $t + plantest "$t" dc bin/smbtorture $TORTURE_OPTIONS "-U\$USERNAME%\$PASSWORD" //\$SERVER/_none_ $t done # only do the ldb tests when not in quick mode - they are quite slow, and ldb @@ -36,9 +25,9 @@ done test "$TORTURE_QUICK" = "yes" || { LDBDIR=lib/ldb export LDBDIR - plantest "ldb" ldap $LDBDIR/tests/test-tdb.sh + plantest "ldb" dc $LDBDIR/tests/test-tdb.sh } SCRIPTDIR=../testprogs/ejs -plantest "ejs ldap" ldap $SCRIPTDIR/ldap.js $CONFIGURATION $SERVER -U$USERNAME%$PASSWORD +plantest "ejs ldap" dc $SCRIPTDIR/ldap.js $CONFIGURATION \$SERVER -U\$USERNAME%\$PASSWORD diff --git a/source4/script/tests/test_local.sh b/source4/script/tests/test_local.sh index 57e11961bb..e8bf10c901 100755 --- a/source4/script/tests/test_local.sh +++ b/source4/script/tests/test_local.sh @@ -8,13 +8,6 @@ if [ `uname` = "Linux" ]; then local_tests="$local_tests LOCAL-ICONV" fi -if [ $# -lt 0 ]; then -cat < -EOF -exit 1; -fi - -unc="$1" -username="$2" -password="$3" -start="$4" -shift 4 ADDARGS="$*" incdir=`dirname $0` @@ -30,5 +18,5 @@ for t in $tests; do continue; fi start="" - plantest "$t" smb $VALGRIND bin/smbtorture $TORTURE_OPTIONS $ADDARGS $unc -U"$username"%"$password" $t + plantest "$t" dc $VALGRIND bin/smbtorture $TORTURE_OPTIONS $ADDARGS //\$SERVER/tmp -U"\$USERNAME"%"\$PASSWORD" $t done diff --git a/source4/script/tests/test_quick.sh b/source4/script/tests/test_quick.sh index 19dfab5730..e601bc7f9b 100755 --- a/source4/script/tests/test_quick.sh +++ b/source4/script/tests/test_quick.sh @@ -1,18 +1,6 @@ #!/bin/sh # run a quick set of filesystem tests -if [ $# -lt 3 ]; then -cat < -EOF -exit 1; -fi - -unc="$1" -username="$2" -password="$3" -start="$4" -shift 4 ADDARGS="$*" incdir=`dirname $0` @@ -26,10 +14,6 @@ tests="$tests RAW-UNLINK RAW-READ RAW-CLOSE RAW-IOCTL RAW-RENAME" tests="$tests RAW-EAS RAW-STREAMS" for t in $tests; do - if [ ! -z "$start" -a "$start" != $t ]; then - continue; - fi - start="" name="$t" - plantest "$name" base $VALGRIND bin/smbtorture $TORTURE_OPTIONS $ADDARGS $unc -U"$username"%"$password" $t + plantest "$name" base $VALGRIND bin/smbtorture $TORTURE_OPTIONS $ADDARGS //\$SERVER/cifs -U"\$USERNAME"%"\$PASSWORD" $t done diff --git a/source4/script/tests/test_rpc.sh b/source4/script/tests/test_rpc.sh index 59a403a735..1b8b57d534 100755 --- a/source4/script/tests/test_rpc.sh +++ b/source4/script/tests/test_rpc.sh @@ -9,19 +9,6 @@ slow_ncacn_np_tests="RPC-SAMLOGON RPC-SAMR RPC-SAMR-USERS RPC-SAMR-PASSWORDS RPC slow_ncalrpc_tests="RPC-SAMR RPC-SAMR-USERS RPC-SAMR-PASSWORDS RPC-COUNTCALLS RPC-CRACKNAMES" slow_ncacn_ip_tcp_tests="RPC-SAMR RPC-SAMR-USERS RPC-SAMR-PASSWORDS RPC-COUNTCALLS RPC-CRACKNAMES" -if [ $# -lt 4 ]; then -cat < -EOF -exit 1; -fi - -unc="$1" -username="$2" -password="$3" -start="$4" -shift 4 ADDARGS="$*" incdir=`dirname $0` @@ -21,10 +9,6 @@ incdir=`dirname $0` tests="BASE-RW1" for t in $tests; do - if [ ! -z "$start" -a "$start" != $t ]; then - continue; - fi - start="" name="$t" - plantest "$name" smb $VALGRIND bin/smbtorture $TORTURE_OPTIONS $ADDARGS $unc -U"$username"%"$password" $t + plantest "$name" dc $VALGRIND bin/smbtorture $TORTURE_OPTIONS $ADDARGS //\$SERVER/simple -U"\$USERNAME"%"\$PASSWORD" $t done diff --git a/source4/script/tests/tests_all.sh b/source4/script/tests/tests_all.sh index 79694df98e..1d761efea3 100755 --- a/source4/script/tests/tests_all.sh +++ b/source4/script/tests/tests_all.sh @@ -1,15 +1,15 @@ #!/bin/sh - $SRCDIR/script/tests/test_ejs.sh $DOMAIN $USERNAME $PASSWORD $CONFIGURATION - $SRCDIR/script/tests/test_ldap.sh $SERVER $USERNAME $PASSWORD - $SRCDIR/script/tests/test_nbt.sh $SERVER $USERNAME $PASSWORD - $SRCDIR/script/tests/test_rpc.sh $SERVER $USERNAME $PASSWORD $DOMAIN - $SRCDIR/script/tests/test_net.sh $SERVER $USERNAME $PASSWORD $DOMAIN - $SRCDIR/script/tests/test_session_key.sh $SERVER $USERNAME $PASSWORD $DOMAIN $NETBIOSNAME - $SRCDIR/script/tests/test_binding_string.sh $SERVER $USERNAME $PASSWORD $DOMAIN - $SRCDIR/script/tests/test_echo.sh $SERVER $USERNAME $PASSWORD $DOMAIN - $SRCDIR/script/tests/test_posix.sh //$SERVER/tmp $USERNAME $PASSWORD "" + $SRCDIR/script/tests/test_ejs.sh $CONFIGURATION + $SRCDIR/script/tests/test_ldap.sh + $SRCDIR/script/tests/test_nbt.sh + $SRCDIR/script/tests/test_rpc.sh + $SRCDIR/script/tests/test_net.sh + $SRCDIR/script/tests/test_session_key.sh + $SRCDIR/script/tests/test_binding_string.sh + $SRCDIR/script/tests/test_echo.sh + $SRCDIR/script/tests/test_posix.sh $SRCDIR/script/tests/test_local.sh $SRCDIR/script/tests/test_pidl.sh - $SRCDIR/script/tests/test_blackbox.sh $SERVER $USERNAME $PASSWORD $DOMAIN $PREFIX - $SRCDIR/script/tests/test_simple.sh //$SERVER/simple $USERNAME $PASSWORD "" + $SRCDIR/script/tests/test_blackbox.sh $PREFIX/blackbox + $SRCDIR/script/tests/test_simple.sh $SRCDIR/script/tests/test_s3upgrade.sh $PREFIX/upgrade diff --git a/source4/script/tests/tests_quick.sh b/source4/script/tests/tests_quick.sh index f66b035e7e..9c57f8b20a 100755 --- a/source4/script/tests/tests_quick.sh +++ b/source4/script/tests/tests_quick.sh @@ -2,8 +2,8 @@ TORTURE_QUICK="yes" export TORTURE_QUICK -$SRCDIR/script/tests/test_ejs.sh $DOMAIN $USERNAME $PASSWORD $CONFIGURATION -$SRCDIR/script/tests/test_ldap.sh $SERVER $USERNAME $PASSWORD -$SRCDIR/script/tests/test_nbt.sh $SERVER $USERNAME $PASSWORD -$SRCDIR/script/tests/test_quick.sh //$SERVER/cifs $USERNAME $PASSWORD "" -$SRCDIR/script/tests/test_rpc_quick.sh $SERVER $USERNAME $PASSWORD $DOMAIN +$SRCDIR/script/tests/test_ejs.sh $CONFIGURATION +$SRCDIR/script/tests/test_ldap.sh +$SRCDIR/script/tests/test_nbt.sh +$SRCDIR/script/tests/test_quick.sh +$SRCDIR/script/tests/test_rpc_quick.sh -- cgit