diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2007-08-12 00:50:25 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 15:01:40 -0500 |
commit | 4da477d4fa891703497608c6b93402c4fc278f95 (patch) | |
tree | e932c07a9879d5fbac6c2244d89d82be7b63e0a4 | |
parent | 7ce6a75f4b7c0fc282fbc0d4387843a278430eb1 (diff) | |
download | samba-4da477d4fa891703497608c6b93402c4fc278f95.tar.gz samba-4da477d4fa891703497608c6b93402c4fc278f95.tar.bz2 samba-4da477d4fa891703497608c6b93402c4fc278f95.zip |
r24339: Move output functions to separate files.
(This used to be commit f4ff4c5f61189c71ab60a5455272302add9e1d97)
-rw-r--r-- | source4/selftest/output/buildfarm.pm | 95 | ||||
-rw-r--r-- | source4/selftest/output/plain.pm | 101 | ||||
-rwxr-xr-x | source4/selftest/selftest.pl | 209 | ||||
-rwxr-xr-x | testprogs/blackbox/test_smbclient.sh | 2 |
4 files changed, 228 insertions, 179 deletions
diff --git a/source4/selftest/output/buildfarm.pm b/source4/selftest/output/buildfarm.pm new file mode 100644 index 0000000000..11d65d7306 --- /dev/null +++ b/source4/selftest/output/buildfarm.pm @@ -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 index 0000000000..05a8bcce18 --- /dev/null +++ b/source4/selftest/output/plain.pm @@ -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; diff --git a/source4/selftest/selftest.pl b/source4/selftest/selftest.pl index 9d4426a6e3..68eb194ab3 100755 --- a/source4/selftest/selftest.pl +++ b/source4/selftest/selftest.pl @@ -140,12 +140,12 @@ my $srcdir = "."; my $builddir = "."; my $prefix = "./st"; -my $suitesfailed = []; -my $start = time(); my @expected_failures = (); my @skips = (); my $statistics = { + START_TIME => time(), + SUITES_FAIL => 0, SUITES_OK => 0, SUITES_SKIPPED => 0, @@ -181,149 +181,6 @@ sub skip($) 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) = @_; @@ -363,65 +220,71 @@ sub run_test($$$$$$) CMD => $cmd, INDEX => $i, TOTAL => $totalsuites, - START => time() + START_TIME => time() }; setup_pcap($msg_state); - $msg_ops->{start_testsuite}->($msg_state); + $msg_ops->start_testsuite($msg_state); 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; - $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}++; - $msg_ops->{end_test}->($msg_state, $2, $1, 1); + $msg_ops->end_test($msg_state, $2, $1, 1); } 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}++; - $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}++; - $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}; - $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}; - $msg_ops->{end_test}->($msg_state, $2, $1, 1); + $msg_ops->end_test($msg_state, $2, $1, 1); } } } 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); - $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) { - push(@$suitesfailed, $name); $statistics->{SUITES_FAIL}++; exit(1) if ($opt_one); } else { @@ -818,9 +681,11 @@ sub teardown_env($) my $msg_ops; if ($from_build_farm) { - $msg_ops = $buildfarm_msg_ops; + require output::buildfarm; + $msg_ops = new output::buildfarm(); } else { - $msg_ops = $plain_msg_ops; + require output::plain; + $msg_ops = new output::plain($opt_verbose, $opt_immediate, $statistics); } if ($opt_no_lazy_setup) { @@ -867,10 +732,9 @@ $envvarstr my $envvars = setup_env($envname); if (not defined($envvars)) { - push(@$suitesfailed, $name); $statistics->{SUITES_FAIL}++; $statistics->{TESTS_ERROR}++; - print "FAIL: $name (ENV[$envname] not available!)\n"; + $msg_ops->missing_env($name, $envname); next; } @@ -890,26 +754,15 @@ teardown_env($_) foreach (keys %running_envs); $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 { - 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"; diff --git a/testprogs/blackbox/test_smbclient.sh b/testprogs/blackbox/test_smbclient.sh index b2787e5260..5431e4ce59 100755 --- a/testprogs/blackbox/test_smbclient.sh +++ b/testprogs/blackbox/test_smbclient.sh @@ -141,7 +141,7 @@ testit "Test login with PASSWD" $VALGRIND bin/smbclient -c 'ls' $CONFIGURATION / 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 |