Commit ddcefb20 authored by Daniel P. Berrange's avatar Daniel P. Berrange

Switch over to perl script instead of shell, and add a XML formatter for recording results

parent cf0c7fd4
#!/bin/sh
# -*- shell -*-
#!/usr/bin/perl
# -*- perl -*-
DATADIR=/usr/share/libvirt-tck
TESTDIR=$DATADIR/tests
CONFDIR=/etc/libvirt-tck
use strict;
use warnings;
HOSTNAME=`hostname`
MODE=text
#MODE=html
use Getopt::Long;
use Sys::Hostname;
use App::Prove;
CONFNAME=$1
my $datadir = "/usr/share/libvirt-tck";
my $confdir = "/etc/libvirt-tck";
help () {
echo "syntax: $0 CONFNAME [TESTDIR]"
my $host = hostname();
use Getopt::Long;
my $verbose = 0;
my $format = "text";
my $testdir = "$datadir/tests";
my $archive;
GetOptions("verbose" => \$verbose,
"archive=s" => \$archive,
"format=s" => \$format,
"testdir=s" => \$testdir);
sub help {
print "syntax: $0 CONFNAME\n";
exit 1;
}
if [ -z "$CONFNAME" ]; then
help
exit 1
fi
if [ -f "$CONFNAME.cfg" ]; then
CONFFILE="$CONFNAME.cfg"
else
if [ -f "./conf/$CONFNAME.cfg" ]; then
CONFFILE="./conf/$CONFNAME.cfg"
else
CONFFILE="$CONFDIR/$CONFNAME.cfg"
if [ ! -f "$CONFFILE" ]; then
echo "config file $CONFFILE does not exist"
exit 2
fi
fi
fi
ARCHIVE="libvirt-tck-$CONFNAME-$HOSTNAME.tar.gz"
EXTRAARGS=
if [ $MODE = "text" ]; then
OUTPUTFILE=libvirt-tck-$CONFNAME-$HOSTNAME.log
EXTRAARGS="-v"
else
OUTPUTFILE=libvirt-tck-$CONFNAME-$HOSTNAME.html
EXTRAARGS="-m -Q --formatter=TAP::Formatter::HTML"
fi
if [ ! -z "$2" ]; then
TESTDIR=$2
fi
export LIBVIRT_TCK_CONFIG=$CONFFILE
#exec prove -a $ARCHIVE $EXTRAARGS -r --norc $TESTDIR > $OUTPUTFILE
exec prove -a $ARCHIVE $EXTRAARGS -r --norc $TESTDIR
my $conf = shift @ARGV;
&help unless $conf;
my $conffile;
if (-f "$conf.cfg") {
$conffile = "$conf.cfg";
} elsif (-f "./conf/$conf.cfg") {
$conffile = "./conf/$conf.cfg"
} else {
$conffile = "$confdir/$conf.cfg";
unless (-f "$conffile") {
print STDERR "config file $conffile does not exist\n";
exit 2;
}
}
my @newargv = ("-r", "--norc", $testdir);
if ($archive) {
push @newargv, "-a", $archive;
}
if ($verbose) {
push @newargv, "-v";
} elsif ($format ne "text") {
push @newargv, "-m", "-Q";
}
if ($format eq "xml") {
push @newargv, "--formatter=Sys::Virt::TCK::TAP::XMLFormatter";
}
if ($format eq "html") {
push @newargv, "--formatter=TAP::Formatter::HTML"
}
$ENV{LIBVIRT_TCK_CONFIG} = $conffile;
my $app = App::Prove->new;
$app->process_args(@newargv);
exit ($app->run ? 0 : 1);
package Sys::Virt::TCK::TAP::XMLFormatter;
use strict;
use warnings;
use base qw(TAP::Base);
use accessors qw(verbosity xml);
use Sys::Virt::TCK::TAP::XMLFormatterSession;
use XML::Writer;
sub _initialize {
my $self = shift;
my $args = shift;
$args ||= {};
$self->SUPER::_initialize($args);
$self->verbosity(0);
my $w = XML::Writer->new(OUTPUT => \*STDOUT,
DATA_MODE => 1,
DATA_INDENT => 2);
$self->xml($w);
return $self;
}
use Data::Dumper;
sub prepare {
my $self = shift;
my @tests = @_;
$self->xml->startTag("results");
}
sub open_test {
my $self = shift;
my $test = shift;
my $parser = shift;
return Sys::Virt::TCK::TAP::XMLFormatterSession->new({ test => $test, parser => $parser, xml => $self->xml });
}
sub summary {
my $self = shift;
my $agg = shift;
$self->xml->startTag("summary",
total => int($agg->total),
passed => int($agg->passed),
failed => int($agg->failed),
todo => int($agg->todo),
unexpected => int($agg->todo_passed),
skipped => int($agg->skipped),
errors => int($agg->parse_errors));
$self->xml->endTag("summary");
$self->xml->endTag("results");
$self->xml->end;
}
1;
package Sys::Virt::TCK::TAP::XMLFormatterSession;
use strict;
use warnings;
use base qw(TAP::Base);
use accessors qw(xml parser);
sub _initialize {
my $self = shift;
my $args = shift;
$args ||= {};
$self->SUPER::_initialize($args);
$self->xml($args->{xml});
$self->parser($args->{parser});
$self->xml->startTag("test",
name => $args->{test});
return $self;
}
sub result {
my $self = shift;
my $result = shift;
my $meth = "result_" . $result->type;
if ($self->can($meth)) {
$self->$meth($result);
}
}
sub result_plan {
my $self = shift;
my $result = shift;
if ($result->has_skip) {
$self->xml->startTag("plan",
count => $result->tests_planned);
$self->xml->dataElement("skip", $result->explanation);
$self->xml->endTag("plan");
} else {
$self->xml->emptyTag("plan",
count => $result->tests_planned);
}
}
sub result_pragma {
my $self = shift;
my $result = shift;
foreach ($result->pragmas) {
$self->dataElement("pragma", $_);
}
}
sub result_test {
my $self = shift;
my $result = shift;
$self->xml->startTag("test",
id => $result->number);
if ($result->is_ok) {
$self->xml->emptyTag("pass");
} else {
$self->xml->emptyTag("fail");
}
$self->xml->emptyTag("unplanned") if $result->is_unplanned;
$self->xml->cdataElement("desc", $result->description);
if ($result->has_todo) {
$self->xml->cdataElement("todo", $result->explanation,
pass => $result->todo_passed ? "yes" : "no");
}
if ($result->has_skip) {
$self->xml->cdataElement("skip", $result->explanation);
}
$self->xml->endTag("test");
}
sub result_bailout {
my $self = shift;
my $result = shift;
$self->xml->cdataElement("bailout",
$result->explanation);
}
sub result_version {
my $self = shift;
my $result = shift;
$self->xml->dataElement("version", $result->version);
}
sub result_comment {
my $self = shift;
my $result = shift;
return if $result->comment eq "";
$self->xml->cdataElement("comment", $result->comment);
}
sub result_unknown {
my $self = shift;
my $result = shift;
return if $result->raw eq "";
$self->xml->cdataElement("unknown", $result->raw);
}
sub result_yaml {
my $self = shift;
my $result = shift;
$self->xml->cdataElement("yaml", $result->data);
}
sub close_test {
my $self = shift;
$self->xml->startTag("summary",
passed => int($self->parser->passed),
failed => int($self->parser->failed),
todo => int($self->parser->todo),
unexpected => int($self->parser->todo_passed),
skipped => int($self->parser->skipped));
if ($self->parser->skip_all) {
$self->xml->startTag("plan",
expected => int($self->parser->tests_planned),
actual => int($self->parser->tests_run));
$self->xml->cdataElement("skip", $self->parser->skip_all);
$self->xml->endTag("plan");
} else {
$self->xml->emptyTag("plan",
expected => int($self->parser->tests_planned),
actual => int($self->parser->tests_run));
}
$self->xml->emptyTag("status",
wait => $self->parser->wait,
exit => $self->parser->exit);
$self->xml->emptyTag("timing",
start => $self->parser->start_time,
end => $self->parser->end_time);
$self->xml->endTag("summary");
$self->xml->endTag("test");
}
1;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment