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

selftest: move {setup,cleanup}_pcap() to selftest/target/Samba.pm

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
This commit is contained in:
Stefan Metzmacher 2020-02-04 17:03:17 +01:00
parent c48ae9cf4d
commit 4effc5585e
2 changed files with 40 additions and 34 deletions

View File

@ -105,35 +105,6 @@ sub skip
sub getlog_env($); sub getlog_env($);
sub setup_pcap($)
{
my ($name) = @_;
return unless ($opt_socket_wrapper_pcap);
return unless defined($ENV{SOCKET_WRAPPER_PCAP_DIR});
my $fname = $name;
$fname =~ s%[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\-]%_%g;
my $pcap_file = "$ENV{SOCKET_WRAPPER_PCAP_DIR}/$fname.pcap";
SocketWrapper::setup_pcap($pcap_file);
return $pcap_file;
}
sub cleanup_pcap($$)
{
my ($pcap_file, $exitcode) = @_;
return unless ($opt_socket_wrapper_pcap);
return if ($opt_socket_wrapper_keep_pcap);
return unless ($exitcode == 0);
return unless defined($pcap_file);
unlink($pcap_file);
}
# expand strings from %ENV # expand strings from %ENV
sub expand_environment_strings($) sub expand_environment_strings($)
{ {
@ -145,10 +116,12 @@ sub expand_environment_strings($)
return $s; return $s;
} }
my $target;
sub run_testsuite($$$$$) sub run_testsuite($$$$$)
{ {
my ($envname, $name, $cmd, $i, $totalsuites) = @_; my ($envname, $name, $cmd, $i, $totalsuites) = @_;
my $pcap_file = setup_pcap($name); my $pcap_file = $target->setup_pcap($name);
Subunit::start_testsuite($name); Subunit::start_testsuite($name);
Subunit::progress_push(); Subunit::progress_push();
@ -186,7 +159,7 @@ sub run_testsuite($$$$$)
Subunit::end_testsuite($name, "failure", "Exit code was $exitcode"); Subunit::end_testsuite($name, "failure", "Exit code was $exitcode");
} }
cleanup_pcap($pcap_file, $exitcode); $target->cleanup_pcap($pcap_file, $exitcode);
if (not $opt_socket_wrapper_keep_pcap and defined($pcap_file)) { if (not $opt_socket_wrapper_keep_pcap and defined($pcap_file)) {
print "PCAP FILE: $pcap_file\n"; print "PCAP FILE: $pcap_file\n";
@ -449,7 +422,6 @@ if ($opt_use_dns_faking) {
$ENV{SAMBA_DNS_FAKING} = 1; $ENV{SAMBA_DNS_FAKING} = 1;
} }
my $target;
my $testenv_default = "none"; my $testenv_default = "none";
if ($opt_mitkrb5 == 1) { if ($opt_mitkrb5 == 1) {
@ -473,7 +445,9 @@ if (defined($ENV{SMBD_MAXTIME}) and $ENV{SMBD_MAXTIME} ne "") {
$server_maxtime = $ENV{SMBD_MAXTIME}; $server_maxtime = $ENV{SMBD_MAXTIME};
} }
$target = new Samba($bindir, $srcdir, $server_maxtime); $target = new Samba($bindir, $srcdir, $server_maxtime,
$opt_socket_wrapper_pcap,
$opt_socket_wrapper_keep_pcap);
unless ($opt_list) { unless ($opt_list) {
if ($opt_target eq "samba") { if ($opt_target eq "samba") {
$testenv_default = "ad_dc"; $testenv_default = "ad_dc";

View File

@ -14,11 +14,14 @@ use Cwd qw(abs_path);
use IO::Poll qw(POLLIN); use IO::Poll qw(POLLIN);
sub new($$$$$) { sub new($$$$$) {
my ($classname, $bindir, $srcdir, $server_maxtime) = @_; my ($classname, $bindir, $srcdir, $server_maxtime,
$opt_socket_wrapper_pcap, $opt_socket_wrapper_keep_pcap) = @_;
my $self = { my $self = {
samba3 => new Samba3($bindir, $srcdir, $server_maxtime), samba3 => new Samba3($bindir, $srcdir, $server_maxtime),
samba4 => new Samba4($bindir, $srcdir, $server_maxtime), samba4 => new Samba4($bindir, $srcdir, $server_maxtime),
opt_socket_wrapper_pcap => $opt_socket_wrapper_pcap,
opt_socket_wrapper_keep_pcap => $opt_socket_wrapper_keep_pcap,
}; };
bless $self; bless $self;
return $self; return $self;
@ -44,6 +47,35 @@ foreach my $env (keys %Samba3::ENV_DEPS) {
$ENV_NEEDS_AD_DC{$env} = ($env =~ /^ad_/); $ENV_NEEDS_AD_DC{$env} = ($env =~ /^ad_/);
} }
sub setup_pcap($$)
{
my ($self, $name) = @_;
return unless ($self->{opt_socket_wrapper_pcap});
return unless defined($ENV{SOCKET_WRAPPER_PCAP_DIR});
my $fname = $name;
$fname =~ s%[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\-]%_%g;
my $pcap_file = "$ENV{SOCKET_WRAPPER_PCAP_DIR}/$fname.pcap";
SocketWrapper::setup_pcap($pcap_file);
return $pcap_file;
}
sub cleanup_pcap($$$)
{
my ($self, $pcap_file, $exitcode) = @_;
return unless ($self->{opt_socket_wrapper_pcap});
return if ($self->{opt_socket_wrapper_keep_pcap});
return unless ($exitcode == 0);
return unless defined($pcap_file);
unlink($pcap_file);
}
sub setup_env($$$) sub setup_env($$$)
{ {
my ($self, $envname, $path) = @_; my ($self, $envname, $path) = @_;