r24339: Move output functions to separate files.
authorJelmer Vernooij <jelmer@samba.org>
Sun, 12 Aug 2007 00:50:25 +0000 (00:50 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 20:01:40 +0000 (15:01 -0500)
(This used to be commit f4ff4c5f61189c71ab60a5455272302add9e1d97)

source4/selftest/output/buildfarm.pm [new file with mode: 0644]
source4/selftest/output/plain.pm [new file with mode: 0644]
source4/selftest/selftest.pl
testprogs/blackbox/test_smbclient.sh

diff --git a/source4/selftest/output/buildfarm.pm b/source4/selftest/output/buildfarm.pm
new file mode 100644 (file)
index 0000000..11d65d7
--- /dev/null
@@ -0,0 +1,95 @@
+#!/usr/bin/perl
+
+package output::buildfarm;
+
+use Exporter;
+@ISA = qw(Exporter);
+
+use strict;
+
+sub new($$) {
+       my ($class) = @_;
+       my $self = { 
+               start => time(),
+               test_output => {}
+       };
+       bless($self, $class);
+}
+
+sub start_testsuite($$)
+{
+       my ($self, $state) = @_;
+       my $out = "";
+
+       $out .= "--==--==--==--==--==--==--==--==--==--==--\n";
+       $out .= "Running test $state->{NAME} (level 0 stdout)\n";
+       $out .= "--==--==--==--==--==--==--==--==--==--==--\n";
+       $out .= scalar(localtime())."\n";
+       $out .= "SELFTEST RUNTIME: " . ($state->{START_TIME} - $self->{START_TIME}) . "s\n";
+       $out .= "NAME: $state->{NAME}\n";
+       $out .= "CMD: $state->{CMD}\n";
+
+       $self->{test_output}->{$state->{NAME}} = "";
+
+       print $out;
+}
+
+sub output_msg($$$)
+{
+       my ($self, $state, $output) = @_;
+
+       $self->{test_output}->{$state->{NAME}} .= $output;
+}
+
+sub end_testsuite($$$$$)
+{
+       my ($self, $state, $expected_ret, $ret, $envlog) = @_;
+       my $out = "";
+
+       $out .= "TEST RUNTIME: " . (time() - $state->{START_TIME}) . "s\n";
+
+       if ($ret == $expected_ret) {
+               $out .= "ALL OK\n";
+       } else {
+               $out .= "ERROR: $ret";
+               $out .= $self->{test_output}->{$state->{NAME}};
+       }
+
+       $out .= "PCAP FILE: $state->{PCAP_FILE}\n" if defined($state->{PCAP_FILE});
+
+       $out .= $envlog;
+
+       $out .= "==========================================\n";
+       if ($ret == $expected_ret) {
+               $out .= "TEST PASSED: $state->{NAME}\n";
+       } else {
+               $out .= "TEST FAILED: $state->{NAME} (status $ret)\n";
+       }
+       $out .= "==========================================\n";
+
+       print $out;
+}
+
+sub start_test($$$)
+{
+       my ($self, $state, $testname) = @_;
+}
+
+sub end_test($$$$$)
+{
+       my ($self, $state, $testname, $result, $expected) = @_;
+}
+
+sub summary($)
+{
+       my ($self) = @_;
+}
+
+sub missing_env($$$)
+{
+       my ($self, $name, $envname) = @_;
+
+       print "FAIL: $name (ENV[$envname] not available!)\n";
+}
+
+1;
diff --git a/source4/selftest/output/plain.pm b/source4/selftest/output/plain.pm
new file mode 100644 (file)
index 0000000..05a8bcc
--- /dev/null
@@ -0,0 +1,101 @@
+#!/usr/bin/perl
+
+package output::plain;
+use Exporter;
+@ISA = qw(Exporter);
+
+use strict;
+
+sub new($$$$) {
+       my ($class, $verbose, $immediate, $statistics) = @_;
+       my $self = { 
+               verbose => $verbose, 
+               immediate => $immediate, 
+               statistics => $statistics,
+               test_output => {},
+               suitesfailed => [],
+               start => time()
+       };
+       bless($self, $class);
+}
+
+sub output_msg($$$);
+
+sub start_testsuite($$)
+{
+       my ($self, $state) = @_;
+       my $out = "";
+
+       my $duration = $state->{START_TIME} - $self->{statistics}->{START_TIME};
+       $out .= "[$state->{INDEX}/$state->{TOTAL} in ".$duration."s";
+       $out .= sprintf(", %d errors", $self->{statistics}->{SUITES_FAIL}) if ($self->{statistics}->{SUITES_FAIL} > 0);
+       $out .= "] $state->{NAME}\n", 
+
+       $self->{test_output}->{$state->{NAME}} = "" unless($self->{verbose});
+
+       $self->output_msg($state, "CMD: $state->{CMD}\n");
+
+       print $out;
+}
+
+sub output_msg($$$)
+{
+       my ($self, $state, $output) = @_;
+
+       if ($self->{verbose}) {
+               print $output;
+       } else {
+               $self->{test_output}->{$state->{NAME}} .= $output;
+       }
+}
+
+sub end_testsuite($$$$$)
+{
+       my ($self, $state, $expected_ret, $ret, $envlog) = @_;
+       my $out = "";
+
+       if ($ret != $expected_ret) {
+               $self->output_msg($state, "ERROR: $ret\n");
+       }
+
+       if ($ret != $expected_ret and $self->{immediate} and not $self->{verbose}) {
+               $out .= $self->{test_output}->{$state->{NAME}};
+       }
+
+       print $out;
+}
+
+sub start_test($$)
+{
+       my ($state, $testname) = @_;
+}
+
+sub end_test($$$$)
+{
+       my ($state, $testname, $result, $unexpected) = @_;
+}
+
+sub summary($)
+{
+       my ($self) = @_;
+
+       if (not $self->{immediate} and not $self->{verbose}) {
+               foreach (@{$self->{suitesfailed}}) {
+                       print "===============================================================================\n";
+                       print "FAIL: $_\n";
+                       print $self->{test_output}->{$_};
+                       print "\n";
+               }
+       }
+
+       print "FAILED ($self->{statistics}->{TESTS_UNEXPECTED_FAIL} failures and $self->{statistics}->{TESTS_ERROR} errors in $self->{statistics}->{SUITES_FAIL} testsuites)\n";
+}
+
+sub missing_env($$$)
+{
+       my ($self, $name, $envname) = @_;
+
+       print "FAIL: $name (ENV[$envname] not available!)\n";
+}
+
+1;
index 9d4426a6e31080cfa2963cc77d0ddb9a98dedac1..68eb194ab37a123289a3f16e3c5ff060d6da22f0 100755 (executable)
@@ -140,12 +140,12 @@ my $srcdir = ".";
 my $builddir = ".";
 my $prefix = "./st";
 
 my $builddir = ".";
 my $prefix = "./st";
 
-my $suitesfailed = [];
-my $start = time();
 my @expected_failures = ();
 my @skips = ();
 
 my $statistics = {
 my @expected_failures = ();
 my @skips = ();
 
 my $statistics = {
+       START_TIME => time(),
+
        SUITES_FAIL => 0,
        SUITES_OK => 0,
        SUITES_SKIPPED => 0,
        SUITES_FAIL => 0,
        SUITES_OK => 0,
        SUITES_SKIPPED => 0,
@@ -181,149 +181,6 @@ sub skip($)
 
 sub getlog_env($);
 
 
 sub getlog_env($);
 
-my $test_output = {};
-
-sub buildfarm_start_testsuite($)
-{
-       my ($state) = @_;
-       my $out = "";
-
-       $out .= "--==--==--==--==--==--==--==--==--==--==--\n";
-       $out .= "Running test $state->{NAME} (level 0 stdout)\n";
-       $out .= "--==--==--==--==--==--==--==--==--==--==--\n";
-       $out .= scalar(localtime())."\n";
-       $out .= "SELFTEST RUNTIME: " . ($state->{START} - $start) . "s\n";
-       $out .= "NAME: $state->{NAME}\n";
-       $out .= "CMD: $state->{CMD}\n";
-
-       $test_output->{$state->{NAME}} = "";
-
-       print $out;
-}
-
-sub buildfarm_output_msg($$)
-{
-       my ($state, $output) = @_;
-
-       $test_output->{$state->{NAME}} .= $output;
-}
-
-sub buildfarm_end_testsuite($$$)
-{
-       my ($state, $expected_ret, $ret) = @_;
-       my $out = "";
-
-       $out .= "TEST RUNTIME: " . (time() - $state->{START}) . "s\n";
-
-       if ($ret == $expected_ret) {
-               $out .= "ALL OK\n";
-       } else {
-               $out .= "ERROR: $ret";
-               $out .= $test_output->{$state->{NAME}};
-       }
-
-       $out .= "PCAP FILE: $state->{PCAP_FILE}\n" if defined($state->{PCAP_FILE});
-
-       $out .= getlog_env($state->{ENVNAME});
-
-       $out .= "==========================================\n";
-       if ($ret == $expected_ret) {
-               $out .= "TEST PASSED: $state->{NAME}\n";
-       } else {
-               $out .= "TEST FAILED: $state->{NAME} (status $ret)\n";
-       }
-       $out .= "==========================================\n";
-
-       print $out;
-}
-
-sub buildfarm_start_test($$)
-{
-       my ($state, $testname) = @_;
-}
-
-sub buildfarm_end_test($$$$)
-{
-       my ($state, $testname, $result, $expected) = @_;
-}
-
-my $buildfarm_msg_ops = {
-       start_testsuite => \&buildfarm_start_testsuite,
-       output_msg      => \&buildfarm_output_msg,
-       end_testsuite           => \&buildfarm_end_testsuite,
-       start_test => \&buildfarm_start_test,
-       end_test => \&buildfarm_end_test,
-};
-
-sub plain_output_msg($$);
-
-sub plain_start_testsuite($)
-{
-       my ($state) = @_;
-       my $out = "";
-
-       $out .= "[$state->{INDEX}/$state->{TOTAL} in " . ($state->{START} - $start) . "s";
-       $out .= ", ".($#$suitesfailed+1)." errors" if ($#$suitesfailed+1 > 0);
-       $out .= "] $state->{NAME}\n";
-
-       $test_output->{$state->{NAME}} = "" unless $opt_verbose;
-
-       plain_output_msg($state, "CMD: $state->{CMD}\n");
-
-       print $out;
-}
-
-sub plain_output_msg($$)
-{
-       my ($state, $output) = @_;
-
-       if ($opt_verbose) {
-               print $output;
-       } else {
-               $test_output->{$state->{NAME}} .= $output;
-       }
-}
-
-sub plain_end_testsuite($$$)
-{
-       my ($state, $expected_ret, $ret) = @_;
-       my $out = "";
-
-       if ($ret != $expected_ret) {
-               plain_output_msg($state, "ERROR: $ret\n");
-       }
-
-       if ($ret != $expected_ret and ($opt_immediate or $opt_one) and not $opt_verbose) {
-               $out .= $test_output->{$state->{NAME}};
-       }
-
-       if (not $opt_socket_wrapper_keep_pcap and defined($state->{PCAP_FILE})) {
-               $out .= "PCAP FILE: $state->{PCAP_FILE}\n";
-       }
-
-       $out .= getlog_env($state->{ENVNAME});
-
-       print $out;
-}
-
-sub plain_start_test($$)
-{
-       my ($state, $testname) = @_;
-}
-
-sub plain_end_test($$$$)
-{
-       my ($state, $testname, $result, $expected) = @_;
-}
-
-my $plain_msg_ops = {
-       start_testsuite => \&plain_start_testsuite,
-       output_msg      => \&plain_output_msg,
-       end_testsuite           => \&plain_end_testsuite,
-       start_test => \&plain_start_test,
-       end_test => \&plain_end_test,
-};
-
 sub setup_pcap($)
 {
        my ($state) = @_;
 sub setup_pcap($)
 {
        my ($state) = @_;
@@ -363,65 +220,71 @@ sub run_test($$$$$$)
                CMD     => $cmd,
                INDEX   => $i,
                TOTAL   => $totalsuites,
                CMD     => $cmd,
                INDEX   => $i,
                TOTAL   => $totalsuites,
-               START   => time()
+               START_TIME      => time()
        };
 
        setup_pcap($msg_state);
 
        };
 
        setup_pcap($msg_state);
 
-       $msg_ops->{start_testsuite}->($msg_state);
+       $msg_ops->start_testsuite($msg_state);
 
        open(RESULT, "$cmd 2>&1|");
        while (<RESULT>) {
 
        open(RESULT, "$cmd 2>&1|");
        while (<RESULT>) {
-               $msg_ops->{output_msg}->($msg_state, $_);
+               $msg_ops->output_msg($msg_state, $_);
                if (/^test: (.+)\n/) {
                        $open_tests->{$1} = 1;
                if (/^test: (.+)\n/) {
                        $open_tests->{$1} = 1;
-                       $msg_ops->{start_test}->($msg_state, $1);
+                       $msg_ops->start_test($msg_state, $1);
                } elsif (/^(success|failure|skip|error): (.*?)( \[)?\n/) {
                        my $result = $1;
                        if ($1 eq "success") {
                                delete $open_tests->{$2};
                                if (expecting_failure("$name/$2")) {
                                        $statistics->{TESTS_UNEXPECTED_OK}++;
                } elsif (/^(success|failure|skip|error): (.*?)( \[)?\n/) {
                        my $result = $1;
                        if ($1 eq "success") {
                                delete $open_tests->{$2};
                                if (expecting_failure("$name/$2")) {
                                        $statistics->{TESTS_UNEXPECTED_OK}++;
-                                       $msg_ops->{end_test}->($msg_state, $2, $1, 1);
+                                       $msg_ops->end_test($msg_state, $2, $1, 1);
                                } else {
                                        $statistics->{TESTS_EXPECTED_OK}++;
                                } else {
                                        $statistics->{TESTS_EXPECTED_OK}++;
-                                       $msg_ops->{end_test}->($msg_state, $2, $1, 0);
+                                       $msg_ops->end_test($msg_state, $2, $1, 0);
                                }
                        } elsif ($1 eq "failure") {
                                delete $open_tests->{$2};
                                if (expecting_failure("$name/$2")) {
                                        $statistics->{TESTS_EXPECTED_FAIL}++;
                                }
                        } elsif ($1 eq "failure") {
                                delete $open_tests->{$2};
                                if (expecting_failure("$name/$2")) {
                                        $statistics->{TESTS_EXPECTED_FAIL}++;
-                                       $msg_ops->{end_test}->($msg_state, $2, $1, 0);
+                                       $msg_ops->end_test($msg_state, $2, $1, 0);
                                        $expected_ret = 0;
                                } else {
                                        print "n:$name/$2\n";
                                        $statistics->{TESTS_UNEXPECTED_FAIL}++;
                                        $expected_ret = 0;
                                } else {
                                        print "n:$name/$2\n";
                                        $statistics->{TESTS_UNEXPECTED_FAIL}++;
-                                       $msg_ops->{end_test}->($msg_state, $2, $1, 1);
+                                       $msg_ops->end_test($msg_state, $2, $1, 1);
                                }
                        } elsif ($1 eq "skip") {
                                delete $open_tests->{$2};
                                }
                        } elsif ($1 eq "skip") {
                                delete $open_tests->{$2};
-                               $msg_ops->{end_test}->($msg_state, $2, $1, 0);
+                               $msg_ops->end_test($msg_state, $2, $1, 0);
                        } elsif ($1 eq "error") {
                                $statistics->{TESTS_ERROR}++;
                                delete $open_tests->{$2};
                        } elsif ($1 eq "error") {
                                $statistics->{TESTS_ERROR}++;
                                delete $open_tests->{$2};
-                               $msg_ops->{end_test}->($msg_state, $2, $1, 1);
+                               $msg_ops->end_test($msg_state, $2, $1, 1);
                        }
                }
        }
 
        foreach (keys %$open_tests) {
                        }
                }
        }
 
        foreach (keys %$open_tests) {
-               $msg_ops->{end_test}->($msg_state, $_, "error", 1);
-               $msg_ops->{output_msg}->($msg_state, "$_ was started but never finished!");
+               $msg_ops->end_test($msg_state, $_, "error", 1);
+               $msg_ops->output_msg($msg_state, "$_ was started but never finished!");
                $statistics->{TESTS_ERROR}++;
        }
        my $ret = close(RESULT);
 
        cleanup_pcap($msg_state,  $expected_ret, $ret);
 
                $statistics->{TESTS_ERROR}++;
        }
        my $ret = close(RESULT);
 
        cleanup_pcap($msg_state,  $expected_ret, $ret);
 
-       $msg_ops->{end_testsuite}->($msg_state, $expected_ret, $ret);
+       $msg_ops->end_testsuite($msg_state, $expected_ret, $ret,
+                                                       getlog_env($msg_state->{ENVNAME}));
+
+       if (not $opt_socket_wrapper_keep_pcap and 
+               defined($msg_state->{PCAP_FILE})) {
+               $msg_ops->output_msg($msg_state, 
+                       "PCAP FILE: $msg_state->{PCAP_FILE}\n");
+       }
 
        if ($ret != $expected_ret) {
 
        if ($ret != $expected_ret) {
-               push(@$suitesfailed, $name);
                $statistics->{SUITES_FAIL}++;
                exit(1) if ($opt_one);
        } else {
                $statistics->{SUITES_FAIL}++;
                exit(1) if ($opt_one);
        } else {
@@ -818,9 +681,11 @@ sub teardown_env($)
 
 my $msg_ops;
 if ($from_build_farm) {
 
 my $msg_ops;
 if ($from_build_farm) {
-       $msg_ops = $buildfarm_msg_ops;
+       require output::buildfarm;
+       $msg_ops = new output::buildfarm();
 } else {
 } else {
-       $msg_ops = $plain_msg_ops;
+       require output::plain;
+       $msg_ops = new output::plain($opt_verbose, $opt_immediate, $statistics);
 }
 
 if ($opt_no_lazy_setup) {
 }
 
 if ($opt_no_lazy_setup) {
@@ -867,10 +732,9 @@ $envvarstr
 
                my $envvars = setup_env($envname);
                if (not defined($envvars)) {
 
                my $envvars = setup_env($envname);
                if (not defined($envvars)) {
-                       push(@$suitesfailed, $name);
                        $statistics->{SUITES_FAIL}++;
                        $statistics->{TESTS_ERROR}++;
                        $statistics->{SUITES_FAIL}++;
                        $statistics->{TESTS_ERROR}++;
-                       print "FAIL: $name (ENV[$envname] not available!)\n";
+                       $msg_ops->missing_env($name, $envname);
                        next;
                }
 
                        next;
                }
 
@@ -890,26 +754,15 @@ teardown_env($_) foreach (keys %running_envs);
 
 $target->stop();
 
 
 $target->stop();
 
-my $end = time();
-my $duration = ($end-$start);
-my $numfailed = $#$suitesfailed+1;
+$statistics->{END_TIME} = time();
+my $duration = ($statistics->{END_TIME}-$statistics->{START_TIME});
+my $numfailed = $statistics->{SUITES_FAIL};
 if ($numfailed == 0) {
        my $ok = $statistics->{TESTS_EXPECTED_OK} + 
                 $statistics->{TESTS_EXPECTED_FAIL};
        print "ALL OK ($ok tests in $statistics->{SUITES_OK} testsuites)\n";
 } else {
 if ($numfailed == 0) {
        my $ok = $statistics->{TESTS_EXPECTED_OK} + 
                 $statistics->{TESTS_EXPECTED_FAIL};
        print "ALL OK ($ok tests in $statistics->{SUITES_OK} testsuites)\n";
 } else {
-       unless ($from_build_farm) {
-               if (not $opt_immediate and not $opt_verbose) {
-                       foreach (@$suitesfailed) {
-                               print "===============================================================================\n";
-                               print "FAIL: $_\n";
-                               print $test_output->{$_};
-                               print "\n";
-                       }
-               }
-
-               print "FAILED ($statistics->{TESTS_UNEXPECTED_FAIL} failures and $statistics->{TESTS_ERROR} errors in $statistics->{SUITES_FAIL} testsuites)\n";
-       }
+       $msg_ops->summary();
 }
 print "DURATION: $duration seconds\n";
 
 }
 print "DURATION: $duration seconds\n";
 
index b2787e5260513083c74e02cada639d5c72a8ab30..5431e4ce59dd69a5aef60c69d8ae0d03dbf27a69 100755 (executable)
@@ -141,7 +141,7 @@ testit "Test login with PASSWD" $VALGRIND bin/smbclient -c 'ls' $CONFIGURATION /
 oldUSER=$USER
 USER="$USERNAME" 
 export USER
 oldUSER=$USER
 USER="$USERNAME" 
 export USER
-testit "Test login with USER and PASSWD" $VALGRIND bin/smbclient -c 'ls' $CONFIGURATION //$SERVER/tmp -W "$DOMAIN" | failed=`expr $failed + 1`
+testit "Test login with USER and PASSWD" $VALGRIND bin/smbclient -c 'ls' $CONFIGURATION //$SERVER/tmp -W "$DOMAIN" || failed=`expr $failed + 1`
 PASSWD=
 export PASSWD
 unset PASSWD
 PASSWD=
 export PASSWD
 unset PASSWD