From: des Date: Fri, 15 Jun 2007 09:23:25 +0000 (+0000) Subject: Add reporting functionality. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=306056c659d7b63680362c459e08ff908748f558;p=varnish Add reporting functionality. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1522 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-tools/regress/lib/Varnish/Test.pm b/varnish-tools/regress/lib/Varnish/Test.pm index 6e31b07c..5d269b2c 100644 --- a/varnish-tools/regress/lib/Varnish/Test.pm +++ b/varnish-tools/regress/lib/Varnish/Test.pm @@ -132,4 +132,10 @@ sub run_case($$) { } } +sub results($) { + my ($self) = @_; + + map { $_->results() } @{$self->{'cases'}}; +} + 1; diff --git a/varnish-tools/regress/lib/Varnish/Test/Case.pm b/varnish-tools/regress/lib/Varnish/Test/Case.pm index 373da5ee..61310d9a 100644 --- a/varnish-tools/regress/lib/Varnish/Test/Case.pm +++ b/varnish-tools/regress/lib/Varnish/Test/Case.pm @@ -36,6 +36,7 @@ use Varnish::Test::Logger; use HTTP::Request; use HTTP::Response; +use Time::HiRes qw(gettimeofday tv_interval); sub new($$) { my ($this, $engine) = @_; @@ -113,6 +114,7 @@ sub run($;@) { if (!@tests) { @tests = sort grep {/^test(\w+)/} (keys %{ref($self) . '::'}); } + $self->{'start'} = [gettimeofday()]; foreach my $method (@tests) { eval { $self->{'count'} += 1; @@ -127,6 +129,7 @@ sub run($;@) { $self->{'count'}, $method, $@)); } } + $self->{'stop'} = [gettimeofday()]; } sub run_loop($@) { @@ -141,6 +144,22 @@ sub new_client($) { return Varnish::Test::Client->new($self->{'engine'}); } +sub results($) { + my ($self) = @_; + + no strict 'refs'; + my $name = ${ref($self)."::NAME"} || (split('::', ref($self)))[-1]; + my $descr = ${ref($self)."::DESCR"} || "N/A"; + return { + 'name' => $name, + 'descr' => $descr, + 'count' => $self->{'count'}, + 'pass' => $self->{'successful'}, + 'fail' => $self->{'failed'}, + 'time' => tv_interval($self->{'start'}, $self->{'stop'}), + }; +} + sub ev_client_response($$$) { my ($self, $client, $response) = @_; diff --git a/varnish-tools/regress/lib/Varnish/Test/Report.pm b/varnish-tools/regress/lib/Varnish/Test/Report.pm new file mode 100644 index 00000000..679951c9 --- /dev/null +++ b/varnish-tools/regress/lib/Varnish/Test/Report.pm @@ -0,0 +1,64 @@ +#!/usr/bin/perl -w +#- +# Copyright (c) 2006 Linpro AS +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer +# in this position and unchanged. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $Id$ +# + +package Varnish::Test::Report; + +use strict; + +use Template; + +sub new($) { + my ($this) = @_; + my $class = ref($this) || $this; + + my $self = bless({ + 'config' => { + }, + 'template' => undef, + }, $class); + + ($self->{'config'}->{'INCLUDE_PATH'} = $INC{'Varnish/Test/Report.pm'}) =~ s/\.pm$//; + + $self->init(); + + return $self; +} + +sub run($@) { + my ($self, @cases) = @_; + + die "No template defined\n" + unless defined($self->{'template'}); + my $template = new Template($self->{'config'}); + $template->process($self->{'template'}, { 'cases' => \@cases }) + or die $template->error(); +} + +1; diff --git a/varnish-tools/regress/lib/Varnish/Test/Report/HTML.pm b/varnish-tools/regress/lib/Varnish/Test/Report/HTML.pm new file mode 100644 index 00000000..c0743a40 --- /dev/null +++ b/varnish-tools/regress/lib/Varnish/Test/Report/HTML.pm @@ -0,0 +1,44 @@ +#!/usr/bin/perl -w +#- +# Copyright (c) 2006 Linpro AS +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer +# in this position and unchanged. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $Id$ +# + +package Varnish::Test::Report::HTML; + +use strict; + +use base 'Varnish::Test::Report'; + +sub init($) { + my ($self) = @_; + + $self->{'template'} = 'report.html'; + $self->{'config'}->{'TAG_STYLE'} = 'html'; +} + +1; diff --git a/varnish-tools/regress/lib/Varnish/Test/Report/report.html b/varnish-tools/regress/lib/Varnish/Test/Report/report.html new file mode 100644 index 00000000..6fbcdf8a --- /dev/null +++ b/varnish-tools/regress/lib/Varnish/Test/Report/report.html @@ -0,0 +1,43 @@ + + + + + Varnish test report + + + + +

Varnish test report

+ + + + + + + + + + + + + + + + + + + + + + + +
NameTimeTestsPassedFailedDescription
+ + diff --git a/varnish-tools/regress/varnish-regress.pl b/varnish-tools/regress/varnish-regress.pl index f0d9dce7..5a27cfdb 100755 --- a/varnish-tools/regress/varnish-regress.pl +++ b/varnish-tools/regress/varnish-regress.pl @@ -36,17 +36,20 @@ use lib "$FindBin::Bin/lib"; use Getopt::Long; use Varnish::Test; +use Varnish::Test::Report::HTML; sub usage() { print STDERR <stop_engine(); - foreach my $case (@{$controller->{'cases'}}) { - (my $name = ref($case)) =~ s/.*://; - - printf("%s: Successful: %d Failed: %d\n", - $name, $case->{'successful'}, $case->{'failed'}); - } + my $report = new Varnish::Test::Report::HTML; + $report->run($controller->results()); }