r24345: Add --format=html option to selftest.
authorJelmer Vernooij <jelmer@samba.org>
Sun, 12 Aug 2007 04:00:15 +0000 (04:00 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 20:01:42 +0000 (15:01 -0500)
source/main.mk
source/samba4-knownfail
source/selftest/output/buildfarm.pm
source/selftest/output/html.pm [new file with mode: 0644]
source/selftest/output/plain.pm
source/selftest/selftest.pl

index f99cb3c630e33e94c0701971e5ca0f84b8faa4e0..f2412d33d5162e1eaeda40ce1e87252b9284e30e 100644 (file)
@@ -289,6 +289,9 @@ SELFTEST = $(PERL) $(srcdir)/selftest/selftest.pl --prefix=${selftest_prefix} \
     --skip=$(srcdir)/samba4-skip \
     $(TEST_OPTIONS) 
 
+htmltest: everything
+       $(SELFTEST) $(DEFAULT_TEST_OPTIONS) --format=html $(TESTS)
+
 test: everything
        $(SELFTEST) $(DEFAULT_TEST_OPTIONS) --immediate $(TESTS)
 
index 0caf59ae4fb68809dd760b8eabb238e14fe73faa..e7f4560ec1877e3cd0f39adc7330cf684026e4cd 100644 (file)
@@ -8,3 +8,4 @@ RAW-OPLOCK/OPLOCK
 RPC-WINREG
 RPC-WKSSVC.*NetWkstaGetInfo
 RPC-WKSSVC.*NetWkstaTransportEnum
+blackbox.smbclient.*USER.*PASSWD
index 11d65d7306ba41aa27f6735537fe850d0847b916..a605f1736cc0257e5fad7d4af1304d08d95e156f 100644 (file)
@@ -92,4 +92,11 @@ sub missing_env($$$)
        print "FAIL: $name (ENV[$envname] not available!)\n";
 }
 
+sub skip_testsuite($$)
+{
+       my ($self, $name) = @_;
+
+       print "SKIPPED: $name\n";
+}
+
 1;
diff --git a/source/selftest/output/html.pm b/source/selftest/output/html.pm
new file mode 100644 (file)
index 0000000..6e83d81
--- /dev/null
@@ -0,0 +1,130 @@
+#!/usr/bin/perl
+
+package output::html;
+use Exporter;
+@ISA = qw(Exporter);
+
+use strict;
+
+sub new($$$$) {
+       my ($class, $dirname, $statistics) = @_;
+       my $self = { 
+               dirname => $dirname,
+               statistics => $statistics,
+               active_test => undef,
+               msg => ""
+       };
+
+       open(INDEX, ">$dirname/index.html");
+
+       print INDEX "<html>\n";
+       print INDEX "<body>\n";
+       print INDEX "<table>\n";
+       print INDEX "<tr><td>Test</td><td>Environment</td><td>Result</td><td>Duration</td></tr>\n";
+
+       $self->{INDEX} = *INDEX;
+
+       bless($self, $class);
+}
+
+sub output_msg($$$);
+
+sub start_testsuite($$)
+{
+       my ($self, $state) = @_;
+
+       $state->{HTMLFILE} = "$state->{NAME}.html";
+
+       $state->{HTMLFILE} =~ s/[:\t\n ]/_/g;
+
+       open(TEST, ">$self->{dirname}/$state->{HTMLFILE}");
+
+       print TEST "<html>\n";
+       print TEST "<body>\n";
+}
+
+sub output_msg($$$)
+{
+       my ($self, $state, $output) = @_;
+
+       unless (defined($self->{active_test})) {
+               print TEST "$output<br>";
+       } else {
+               $self->{msg} .= "$output<br>";
+       }
+}
+
+sub end_testsuite($$$$$)
+{
+       my ($self, $state, $expected_ret, $ret, $envlog) = @_;
+
+       print TEST "</body>\n";
+       print TEST "</html>\n";
+
+       close(TEST);
+
+       print {$self->{INDEX}} "<tr><td><a href=\"$state->{HTMLFILE}\">$state->{NAME}</a></td><td>$state->{ENVNAME}</td>";
+
+       if ($ret == $expected_ret) {
+               print {$self->{INDEX}} "<td bgcolor=\"green\">OK</td>";
+       } else {
+               print {$self->{INDEX}} "<td bgcolor=\"red\">FAIL</td>";
+       }
+
+       print {$self->{INDEX}} "<td>" . (time() - $state->{START_TIME}) . "</td>\n";
+
+       print {$self->{INDEX}} "</tr>\n";
+}
+
+sub start_test($$$)
+{
+       my ($self, $state, $testname) = @_;
+
+       print TEST "<h3>$testname</h3>\n";
+
+       $self->{active_test} = $testname;
+       $self->{msg} = "";
+}
+
+sub end_test($$$$$)
+{
+       my ($self, $state, $testname, $result, $unexpected) = @_;
+
+       if ($result eq "skip") {
+               print TEST "<div bgcolor=\"yellow\">\n";
+       } elsif ($unexpected) {
+               print TEST "<div bgcolor=\"red\">\n";
+       }
+
+       print TEST $self->{msg};
+
+       print TEST "</div>\n";
+
+       $self->{active_test} = undef;
+}
+
+sub summary($)
+{
+       my ($self) = @_;
+       print {$self->{INDEX}} "</table>\n";
+       print {$self->{INDEX}} "FAILED ($self->{statistics}->{TESTS_UNEXPECTED_FAIL} failures and $self->{statistics}->{TESTS_ERROR} errors in $self->{statistics}->{SUITES_FAIL} testsuites)\n";
+
+       print {$self->{INDEX}} "</body>\n";
+       print {$self->{INDEX}} "</html>\n";
+}
+
+sub missing_env($$$)
+{
+       my ($self, $name, $envname) = @_;
+
+       print "FAIL: $name (ENV[$envname] not available!)\n";
+}
+
+sub skip_testsuite($$)
+{
+       my ($self, $name) = @_;
+
+       print {$self->{INDEX}} "<tr><td>$name</td><td>N/A</td><td bgcolor=\"yellow\">SKIPPED</td><td>N/A</td></tr>\n";
+}
+
+1;
index 05a8bcce18e06effb4bed959466a6ad9fd19b867..d3ffe228a7fc0b1c2660390122cbf4f0d27176ee 100644 (file)
@@ -98,4 +98,11 @@ sub missing_env($$$)
        print "FAIL: $name (ENV[$envname] not available!)\n";
 }
 
+sub skip_testsuite($$)
+{
+       my ($self, $name) = @_;
+
+       print "SKIPPED: $name\n";
+}
+
 1;
index 72fad8f2d0209be1972cf5b97c16c1c4b5f46b1e..1dbb494edbc6e845617607c0242e71502cc3ba42 100755 (executable)
@@ -136,6 +136,7 @@ my $opt_analyse_cmd = undef;
 my $opt_resetup_env = undef;
 my $opt_bindir = undef;
 my $opt_no_lazy_setup = undef;
+my $opt_format = "plain";
 
 my $srcdir = ".";
 my $builddir = ".";
@@ -239,7 +240,6 @@ sub parse_subunit_results($$$$)
                                        $msg_ops->end_test($msg_state, $2, $1, 0);
                                        $expected_ret = 0;
                                } else {
-                                       print "n:$msg_state->{NAME}/$2\n";
                                        $statistics->{TESTS_UNEXPECTED_FAIL}++;
                                        $msg_ops->end_test($msg_state, $2, $1, 1);
                                }
@@ -285,7 +285,7 @@ sub run_test($$$$$$)
 
        my $ret = close(RESULT);
 
-       cleanup_pcap($msg_state,  $expected_ret, $ret);
+       cleanup_pcap($msg_state, $expected_ret, $ret);
 
        $msg_ops->end_testsuite($msg_state, $expected_ret, $ret,
                                                        getlog_env($msg_state->{ENVNAME}));
@@ -366,6 +366,7 @@ my $result = GetOptions (
                'no-lazy-setup' => \$opt_no_lazy_setup,
                'resetup-environment' => \$opt_resetup_env,
                'bindir:s' => \$opt_bindir,
+               'format=s' => \$opt_format,
            );
 
 exit(1) if (not $result);
@@ -418,8 +419,10 @@ $ENV{SRCDIR} = $srcdir;
 $ENV{SRCDIR_ABS} = $srcdir_abs;
 
 my $tls_enabled = not $opt_quick;
-my $from_build_farm = (defined($ENV{RUN_FROM_BUILD_FARM}) and 
-                      ($ENV{RUN_FROM_BUILD_FARM} eq "yes"));
+if (defined($ENV{RUN_FROM_BUILD_FARM}) and 
+       ($ENV{RUN_FROM_BUILD_FARM} eq "yes")) {
+       $opt_format = "buildfarm";
+}
 
 $ENV{TLS_ENABLED} = ($tls_enabled?"yes":"no");
 $ENV{LD_LDB_MODULE_PATH} = "$old_pwd/bin/modules/ldb";
@@ -551,7 +554,7 @@ push (@torture_options, "--configfile=$conffile");
 # ensure any one smbtorture call doesn't run too long
 push (@torture_options, "--maximum-runtime=$torture_maxtime");
 push (@torture_options, "--target=$opt_target");
-push (@torture_options, "--option=torture:progress=no") if ($from_build_farm);
+push (@torture_options, "--option=torture:progress=no") if ($opt_format eq "buildfarm");
 push (@torture_options, "--format=subunit");
 push (@torture_options, "--option=torture:quick=yes") if ($opt_quick);
 
@@ -692,12 +695,18 @@ sub teardown_env($)
 }
 
 my $msg_ops;
-if ($from_build_farm) {
+if ($opt_format eq "buildfarm") {
        require output::buildfarm;
        $msg_ops = new output::buildfarm();
-} else {
+} elsif ($opt_format eq "plain") {
        require output::plain;
        $msg_ops = new output::plain($opt_verbose, $opt_immediate, $statistics);
+} elsif ($opt_format eq "html") {
+       require output::html;
+       mkdir "test-results";
+       $msg_ops = new output::html("test-results", $statistics);
+} else {
+       die("Invalid output format '$opt_format'");
 }
 
 if ($opt_no_lazy_setup) {
@@ -737,7 +746,7 @@ $envvarstr
                my $envname = $$_[1];
                
                if (skip($name)) {
-                       print "SKIPPED: $name\n";
+                       $msg_ops->skip_testsuite($name);
                        $statistics->{SUITES_SKIPPED}++;
                        next;
                }
@@ -791,7 +800,7 @@ foreach (<$prefix/valgrind.log*>) {
        }
 }
 
-if ($from_build_farm) {
+if ($opt_format eq "buildfarm") {
        print "TEST STATUS: $numfailed\n";
 }