1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-03 01:18:10 +03:00

selftest: Provide a single bindir_path function across all targets

This will allow a mapping to be made between things like smbtorture4
-> smbtorture that is correct for the different build environments.

Andrew Bartlett
This commit is contained in:
Andrew Bartlett 2011-04-15 12:27:30 +10:00
parent 82fdad8a4c
commit 831955ddf2
5 changed files with 71 additions and 62 deletions

View File

@ -156,7 +156,7 @@ my $opt_testenv = 0;
my $opt_list = 0; my $opt_list = 0;
my $ldap = undef; my $ldap = undef;
my $opt_resetup_env = undef; my $opt_resetup_env = undef;
my $opt_bindir = undef; my $opt_binary_mapping = "";
my $opt_load_list = undef; my $opt_load_list = undef;
my @testlists = (); my @testlists = ();
@ -314,7 +314,6 @@ Target Specific:
--socket-wrapper-keep-pcap keep all pcap files, not just those for tests that --socket-wrapper-keep-pcap keep all pcap files, not just those for tests that
failed failed
--socket-wrapper enable socket wrapper --socket-wrapper enable socket wrapper
--bindir=PATH path to target binaries
Samba4 Specific: Samba4 Specific:
--ldap=openldap|fedora-ds back samba onto specified ldap server --ldap=openldap|fedora-ds back samba onto specified ldap server
@ -351,10 +350,10 @@ my $result = GetOptions (
'list' => \$opt_list, 'list' => \$opt_list,
'ldap:s' => \$ldap, 'ldap:s' => \$ldap,
'resetup-environment' => \$opt_resetup_env, 'resetup-environment' => \$opt_resetup_env,
'bindir:s' => \$opt_bindir,
'image=s' => \$opt_image, 'image=s' => \$opt_image,
'testlist=s' => \@testlists, 'testlist=s' => \@testlists,
'load-list=s' => \$opt_load_list, 'load-list=s' => \$opt_load_list,
'binary-mapping=s' => \$opt_binary_mapping
); );
exit(1) if (not $result); exit(1) if (not $result);
@ -377,7 +376,7 @@ unless (defined($ENV{VALGRIND})) {
# make all our python scripts unbuffered # make all our python scripts unbuffered
$ENV{PYTHONUNBUFFERED} = 1; $ENV{PYTHONUNBUFFERED} = 1;
my $bindir = ($opt_bindir or "$builddir/bin"); my $bindir = "$builddir/bin";
my $bindir_abs = abs_path($bindir); my $bindir_abs = abs_path($bindir);
# Backwards compatibility: # Backwards compatibility:
@ -462,17 +461,41 @@ if ($opt_socket_wrapper) {
my $target; my $target;
my $testenv_default = "none"; 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;
}
}
$ENV{BINARY_MAPPING} = $opt_binary_mapping;
sub bindir_path($$) {
my ($self, $path) = @_;
if (defined($self->{binary_mapping}->{$path})) {
$path = $self->{binary_mapping}->{$path};
}
my $valpath = "$self->{bindir}/$path$self->{exeext}";
return $valpath if (-f $valpath);
return $path;
}
if ($opt_target eq "samba4") { if ($opt_target eq "samba4") {
$testenv_default = "all"; $testenv_default = "all";
require target::Samba4; require target::Samba4;
$target = new Samba4($bindir, $ldap, $srcdir, $exeext); $target = new Samba4($bindir, \%binary_mapping, \&bindir_path, $ldap, $srcdir, $exeext);
} elsif ($opt_target eq "samba3") { } elsif ($opt_target eq "samba3") {
if ($opt_socket_wrapper and `$bindir/smbd -b | grep SOCKET_WRAPPER` eq "") { 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...."); die("You must include --enable-socket-wrapper when compiling Samba in order to execute 'make test'. Exiting....");
} }
$testenv_default = "member"; $testenv_default = "member";
require target::Samba3; require target::Samba3;
$target = new Samba3($bindir, $srcdir_abs); $target = new Samba3($bindir, \%binary_mapping, \&bindir_path, $srcdir_abs, $exeext);
} elsif ($opt_target eq "win") { } elsif ($opt_target eq "win") {
die("Windows tests will not run with socket wrapper enabled.") die("Windows tests will not run with socket wrapper enabled.")
if ($opt_socket_wrapper); if ($opt_socket_wrapper);

View File

@ -22,10 +22,10 @@ import os
import subprocess import subprocess
def srcdir(): def srcdir():
return os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")) return os.path.normpath(os.getenv("SRCDIR", os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")))
def source4dir(): def source4dir():
return os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../source4")) return os.path.normpath(os.path.join(srcdir(), "source4"))
def bindir(): def bindir():
return os.path.normpath(os.path.join(os.getenv("BUILDDIR", "."), "bin")) return os.path.normpath(os.path.join(os.getenv("BUILDDIR", "."), "bin"))

View File

@ -10,23 +10,15 @@ use Cwd qw(abs_path);
use FindBin qw($RealBin); use FindBin qw($RealBin);
use POSIX; use POSIX;
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($$) { sub new($$) {
my ($classname, $bindir, $srcdir) = @_; my ($classname, $bindir, $binary_mapping, $bindir_path, $srcdir, $exeext) = @_;
my $self = { bindir => $bindir, $exeext = "" unless defined($exeext);
srcdir => $srcdir my $self = { vars => {},
bindir => $bindir,
binary_mapping => $binary_mapping,
bindir_path => $bindir_path,
srcdir => $srcdir,
exeext => $exeext
}; };
bless $self; bless $self;
return $self; return $self;
@ -180,7 +172,7 @@ sub setup_member($$$)
$ret or return undef; $ret or return undef;
my $net = $self->binpath("net"); my $net = $self->{bindir_path}->($self, "net");
my $cmd = ""; my $cmd = "";
$cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" "; $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
$cmd .= "$net join $ret->{CONFIGURATION} $dcvars->{DOMAIN} member"; $cmd .= "$net join $ret->{CONFIGURATION} $dcvars->{DOMAIN} member";
@ -411,14 +403,14 @@ sub check_or_start($$$$$) {
@optargs = split(/ /, $ENV{NMBD_OPTIONS}); @optargs = split(/ /, $ENV{NMBD_OPTIONS});
} }
$ENV{MAKE_TEST_BINARY} = $self->binpath("nmbd"); $ENV{MAKE_TEST_BINARY} = $self->{bindir_path}->($self, "nmbd");
my @preargs = ($self->binpath("timelimit"), $maxtime); my @preargs = ($self->{bindir_path}->($self, "timelimit"), $maxtime);
if(defined($ENV{NMBD_VALGRIND})) { if(defined($ENV{NMBD_VALGRIND})) {
@preargs = split(/ /, $ENV{NMBD_VALGRIND}); @preargs = split(/ /, $ENV{NMBD_VALGRIND});
} }
exec(@preargs, $self->binpath("nmbd"), "-F", "--no-process-group", "-S", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start nmbd: $!"); exec(@preargs, $self->{bindir_path}->($self, "nmbd"), "-F", "--no-process-group", "-S", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start nmbd: $!");
} }
write_pid($env_vars, "nmbd", $pid); write_pid($env_vars, "nmbd", $pid);
print "DONE\n"; print "DONE\n";
@ -454,14 +446,14 @@ sub check_or_start($$$$$) {
@optargs = split(/ /, $ENV{WINBINDD_OPTIONS}); @optargs = split(/ /, $ENV{WINBINDD_OPTIONS});
} }
$ENV{MAKE_TEST_BINARY} = $self->binpath("winbindd"); $ENV{MAKE_TEST_BINARY} = $self->{bindir_path}->($self, "winbindd");
my @preargs = ($self->binpath("timelimit"), $maxtime); my @preargs = ($self->{bindir_path}->($self, "timelimit"), $maxtime);
if(defined($ENV{WINBINDD_VALGRIND})) { if(defined($ENV{WINBINDD_VALGRIND})) {
@preargs = split(/ /, $ENV{WINBINDD_VALGRIND}); @preargs = split(/ /, $ENV{WINBINDD_VALGRIND});
} }
exec(@preargs, $self->binpath("winbindd"), "-F", "--no-process-group", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start winbindd: $!"); exec(@preargs, $self->{bindir_path}->($self, "winbindd"), "-F", "--no-process-group", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start winbindd: $!");
} }
write_pid($env_vars, "winbindd", $pid); write_pid($env_vars, "winbindd", $pid);
print "DONE\n"; print "DONE\n";
@ -492,16 +484,16 @@ sub check_or_start($$$$$) {
exit 0; exit 0;
} }
$ENV{MAKE_TEST_BINARY} = $self->binpath("smbd"); $ENV{MAKE_TEST_BINARY} = $self->{bindir_path}->($self, "smbd");
my @optargs = ("-d0"); my @optargs = ("-d0");
if (defined($ENV{SMBD_OPTIONS})) { if (defined($ENV{SMBD_OPTIONS})) {
@optargs = split(/ /, $ENV{SMBD_OPTIONS}); @optargs = split(/ /, $ENV{SMBD_OPTIONS});
} }
my @preargs = ($self->binpath("timelimit"), $maxtime); my @preargs = ($self->{bindir_path}->($self, "timelimit"), $maxtime);
if(defined($ENV{SMBD_VALGRIND})) { if(defined($ENV{SMBD_VALGRIND})) {
@preargs = split(/ /,$ENV{SMBD_VALGRIND}); @preargs = split(/ /,$ENV{SMBD_VALGRIND});
} }
exec(@preargs, $self->binpath("smbd"), "-F", "--no-process-group", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start smbd: $!"); exec(@preargs, $self->{bindir_path}->($self, "smbd"), "-F", "--no-process-group", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start smbd: $!");
} }
write_pid($env_vars, "smbd", $pid); write_pid($env_vars, "smbd", $pid);
print "DONE\n"; print "DONE\n";
@ -824,7 +816,7 @@ domusers:X:$gid_domusers:
$ENV{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd; $ENV{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
$ENV{NSS_WRAPPER_GROUP} = $nss_wrapper_group; $ENV{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
open(PWD, "|".$self->binpath("smbpasswd")." -c $conffile -L -s -a $unix_name >/dev/null"); open(PWD, "|".$self->{bindir_path}->($self, "smbpasswd")." -c $conffile -L -s -a $unix_name >/dev/null");
print PWD "$password\n$password\n"; print PWD "$password\n$password\n";
close(PWD) or die("Unable to set password for test account"); close(PWD) or die("Unable to set password for test account");
@ -871,11 +863,11 @@ sub wait_for_start($$)
print "delaying for nbt name registration\n"; print "delaying for nbt name registration\n";
sleep(10); sleep(10);
# This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init # 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->{bindir_path}->($self, "nmblookup") ." $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} __SAMBA__");
system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} __SAMBA__"); system($self->{bindir_path}->($self, "nmblookup") ." $envvars->{CONFIGURATION} __SAMBA__");
system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} -U 127.255.255.255 __SAMBA__"); system($self->{bindir_path}->($self, "nmblookup") ." $envvars->{CONFIGURATION} -U 127.255.255.255 __SAMBA__");
system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} $envvars->{SERVER}"); system($self->{bindir_path}->($self, "nmblookup") ." $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} $envvars->{SERVER}");
system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} $envvars->{SERVER}"); system($self->{bindir_path}->($self, "nmblookup") ." $envvars->{CONFIGURATION} $envvars->{SERVER}");
# make sure smbd is also up set # make sure smbd is also up set
print "wait for smbd\n"; print "wait for smbd\n";
@ -883,7 +875,7 @@ sub wait_for_start($$)
my $count = 0; my $count = 0;
my $ret; my $ret;
do { do {
$ret = system($self->binpath("smbclient") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER} -U% -p 139"); $ret = system($self->{bindir_path}->($self, "smbclient") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER} -U% -p 139");
if ($ret != 0) { if ($ret != 0) {
sleep(2); sleep(2);
} }
@ -895,7 +887,7 @@ sub wait_for_start($$)
return 0; return 0;
} }
# Ensure we have domain users mapped. # Ensure we have domain users mapped.
$ret = system($self->binpath("net") ." $envvars->{CONFIGURATION} groupmap add rid=513 unixgroup=domusers type=domain"); $ret = system($self->{bindir_path}->($self, "net") ." $envvars->{CONFIGURATION} groupmap add rid=513 unixgroup=domusers type=domain");
if ($ret != 0) { if ($ret != 0) {
return 1; return 1;
} }

View File

@ -12,12 +12,15 @@ use POSIX;
use SocketWrapper; use SocketWrapper;
sub new($$$$$) { sub new($$$$$) {
my ($classname, $bindir, $ldap, $srcdir, $exeext) = @_; my ($classname, $bindir, $binary_mapping, $bindir_path, $ldap, $srcdir, $exeext) = @_;
$exeext = "" unless defined($exeext); $exeext = "" unless defined($exeext);
my $self = { my $self = {
vars => {}, vars => {},
ldap => $ldap, ldap => $ldap,
bindir => $bindir, bindir => $bindir,
binary_mapping => $binary_mapping,
bindir_path => $bindir_path,
srcdir => $srcdir, srcdir => $srcdir,
exeext => $exeext exeext => $exeext
}; };
@ -25,15 +28,6 @@ sub new($$$$$) {
return $self; return $self;
} }
sub bindir_path($$) {
my ($self, $path) = @_;
my $valpath = "$self->{bindir}/$path$self->{exeext}";
return $valpath if (-f $valpath);
return $path;
}
sub scriptdir_path($$) { sub scriptdir_path($$) {
my ($self, $path) = @_; my ($self, $path) = @_;
return "$self->{srcdir}/source4/scripting/$path"; return "$self->{srcdir}/source4/scripting/$path";
@ -46,7 +40,7 @@ sub slapd_start($$)
{ {
my $count = 0; my $count = 0;
my ($self, $env_vars) = @_; my ($self, $env_vars) = @_;
my $ldbsearch = $self->bindir_path("ldbsearch"); my $ldbsearch = $self->bindir_path($self, "ldbsearch");
my $uri = $env_vars->{LDAP_URI}; my $uri = $env_vars->{LDAP_URI};
@ -138,7 +132,7 @@ sub check_or_start($$$)
if (defined($ENV{SAMBA_OPTIONS})) { if (defined($ENV{SAMBA_OPTIONS})) {
$optarg.= " $ENV{SAMBA_OPTIONS}"; $optarg.= " $ENV{SAMBA_OPTIONS}";
} }
my $samba = $self->bindir_path("samba"); my $samba = $self->{bindir_path}->($self, "samba");
# allow selection of the process model using # allow selection of the process model using
# the environment varibale SAMBA_PROCESS_MODEL # the environment varibale SAMBA_PROCESS_MODEL
@ -186,7 +180,7 @@ sub wait_for_start($$)
# This will return quickly when things are up, but be slow if we # This will return quickly when things are up, but be slow if we
# need to wait for (eg) SSL init # need to wait for (eg) SSL init
my $nmblookup = $self->bindir_path("nmblookup"); my $nmblookup = $self->{bindir_path}->($self, "nmblookup");
system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}"); system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}"); system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}"); system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
@ -207,7 +201,7 @@ sub write_ldb_file($$$)
{ {
my ($self, $file, $ldif) = @_; my ($self, $file, $ldif) = @_;
my $ldbadd = $self->bindir_path("ldbadd"); my $ldbadd = $self->{bindir_path}->($self, "ldbadd");
open(LDIF, "|$ldbadd -H $file >/dev/null"); open(LDIF, "|$ldbadd -H $file >/dev/null");
print LDIF $ldif; print LDIF $ldif;
return(close(LDIF)); return(close(LDIF));
@ -895,7 +889,7 @@ sub provision_member($$$)
return undef; return undef;
} }
my $samba_tool = $self->bindir_path("samba-tool"); my $samba_tool = $self->{bindir_path}->($self, "samba-tool");
my $cmd = ""; my $cmd = "";
$cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" "; $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
$cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" "; $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
@ -950,7 +944,7 @@ sub provision_rpc_proxy($$$)
return undef; return undef;
} }
my $samba_tool = $self->bindir_path("samba-tool"); my $samba_tool = $self->{bindir_path}->($self, "samba-tool");
my $cmd = ""; my $cmd = "";
$cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" "; $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
$cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" "; $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
@ -1013,7 +1007,7 @@ sub provision_vampire_dc($$$)
return undef; return undef;
} }
my $samba_tool = $self->bindir_path("samba-tool"); my $samba_tool = $self->{bindir_path}->($self, "samba-tool");
my $cmd = ""; my $cmd = "";
$cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" "; $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
$cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" "; $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
@ -1192,7 +1186,7 @@ sub provision_rodc($$$)
return undef; return undef;
} }
my $samba_tool = $self->bindir_path("samba-tool"); my $samba_tool = $self->{bindir_path}->($self, "samba-tool");
my $cmd = ""; my $cmd = "";
$cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" "; $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
$cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" "; $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
@ -1498,7 +1492,7 @@ sub setup_vampire_dc($$$)
# force replicated DC to update repsTo/repsFrom # force replicated DC to update repsTo/repsFrom
# for vampired partitions # for vampired partitions
my $samba_tool = $self->bindir_path("samba-tool"); my $samba_tool = $self->{bindir_path}->($self, "samba-tool");
my $cmd = ""; my $cmd = "";
$cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\""; $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
$cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\""; $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";

View File

@ -6,7 +6,7 @@ use lib $RealBin;
use lib "$RealBin/target"; use lib "$RealBin/target";
use Samba4; use Samba4;
my $s = new Samba4("bin", undef, $RealBin."/../setup"); my $s = new Samba4("bin", undef, undef, undef, $RealBin."/../setup");
ok($s); ok($s);