]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
selftest: move {setup,cleanup}_pcap() to selftest/target/Samba.pm
authorStefan Metzmacher <metze@samba.org>
Tue, 4 Feb 2020 16:03:17 +0000 (17:03 +0100)
committerStefan Metzmacher <metze@samba.org>
Thu, 6 Feb 2020 14:57:42 +0000 (14:57 +0000)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
selftest/selftest.pl
selftest/target/Samba.pm

index ded3dc402dfa1adcb9f25544d547a3394a1a66b3..02848f83794a623af16813b65fac16747742167a 100755 (executable)
@@ -105,35 +105,6 @@ sub skip
 
 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
 sub expand_environment_strings($)
 {
@@ -145,10 +116,12 @@ sub expand_environment_strings($)
        return $s;
 }
 
+my $target;
+
 sub run_testsuite($$$$$)
 {
        my ($envname, $name, $cmd, $i, $totalsuites) = @_;
-       my $pcap_file = setup_pcap($name);
+       my $pcap_file = $target->setup_pcap($name);
 
        Subunit::start_testsuite($name);
        Subunit::progress_push();
@@ -186,7 +159,7 @@ sub run_testsuite($$$$$)
                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)) {
                print "PCAP FILE: $pcap_file\n";
@@ -449,7 +422,6 @@ if ($opt_use_dns_faking) {
        $ENV{SAMBA_DNS_FAKING} = 1;
 }
 
-my $target;
 my $testenv_default = "none";
 
 if ($opt_mitkrb5 == 1) {
@@ -473,7 +445,9 @@ if (defined($ENV{SMBD_MAXTIME}) and $ENV{SMBD_MAXTIME} ne "") {
     $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) {
        if ($opt_target eq "samba") {
                $testenv_default = "ad_dc";
index b7b46413b6828accce1eb619e662df5f86e832fa..de35eda5ce7a4f9e132928666bd92c82d1d3668c 100644 (file)
@@ -14,11 +14,14 @@ use Cwd qw(abs_path);
 use IO::Poll qw(POLLIN);
 
 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 = {
            samba3 => new Samba3($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;
        return $self;
@@ -44,6 +47,35 @@ foreach my $env (keys %Samba3::ENV_DEPS) {
     $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($$$)
 {
        my ($self, $envname, $path) = @_;