- adding script for Tracy -> submits Eggplant results to Litmus via web services
This commit is contained in:
ccooper%deadsquid.com 2007-05-14 19:30:21 +00:00
Родитель 68e729cc6c
Коммит 3b0ad42593
2 изменённых файлов: 344 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1 @@
deny from all

Просмотреть файл

@ -0,0 +1,343 @@
#!/usr/bin/perl -w
# -*- mode: cperl; c-basic-offset: 8; indent-tabs-mode: nil; -*-
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Litmus.
#
# The Initial Developer of the Original Code is
# the Mozilla Corporation.
# Portions created by the Initial Developer are Copyright (C) 2007
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Chris Cooper <ccooper@deadsquid.com>
#
# ***** END LICENSE BLOCK *****
use strict;
$|++;
use Data::Dumper;
use Date::Manip;
use Getopt::Long;
use Sys::Hostname;
use Test::Litmus;
my $help = 0;
my $results_file;
my $username;
my $authtoken;
my $product;
my $branch;
my $platform;
my $opsys;
my $build_id;
my $locale;
my $server;
my $machinename;
my $build_type;
my $validate_only;
GetOptions(
"help|?" => \$help,
"results_file=s" => \$results_file,
"username=s" => \$username,
"authtoken=s" => \$authtoken,
"product=s" => \$product,
"branch=s" => \$branch,
"platform=s" => \$platform,
"opsys=s" => \$opsys,
"build_id=s" => \$build_id,
"locale=s" => \$locale,
"server=s" => \$server,
"machinename=s" => \$machinename,
"build_type=s" => \$build_type,
"validate_only" => \$validate_only,
);
if ($help) {
&usage();
exit 0;
}
if (!$results_file or $results_file eq '') {
print STDERR "You must specify a results file.\n";
&usage();
exit 1;
}
if (! -e $results_file or ! -r $results_file) {
print STDERR "Results file: $results_file does not exist, or is not readable.\n";
exit 1;
}
if (!$username or $username eq '') {
print STDERR "You must specify a username.\n";
&usage();
exit 1;
}
if (!$authtoken or $authtoken eq '') {
print STDERR "You must specify an authtoken.\n";
&usage();
exit 1;
}
if (!$product or $product eq '') {
print STDERR "You must specify a product.\n";
&usage();
exit 1;
}
if (!$branch or $branch eq '') {
print STDERR "You must specify a branch.\n";
&usage();
exit 1;
}
if (!$platform or $platform eq '') {
print STDERR "You must specify a platform.\n";
&usage();
exit 1;
}
if (!$opsys or $opsys eq '') {
print STDERR "You must specify an operating sytem (opsys).\n";
&usage();
exit 1;
}
if (!$build_id or $build_id eq '') {
$build_id = &createFakeBuildID();
} elsif ($build_id !~ /^\d{10,10}$/) {
print STDERR "A build ID is a date-based 10-digit number.\n";
&usage();
exit 0;
}
if (!$locale or $locale eq '') {
$locale='en-US';
}
if (!$server or $server eq '') {
$server='http://litmus.mozilla.org/process_test.cgi';
}
if (!$machinename or $machinename eq '') {
$machinename = hostname;
}
if (!$build_type or $build_type eq '') {
$build_type = 'Nightly';
}
my $t = Test::Litmus->new(-server => $server,
-machinename => $machinename,
-username => $username,
-authtoken => $authtoken,
);
$t->sysconfig(-product => $product,
-platform => $platform,
-opsys => $opsys,
-branch => $branch,
-buildid => $build_id,
-buildtype => $build_type,
-locale => $locale);
my $num_results_added = &parseResultsFile($t, $results_file);
# add log information that should be linked with
# all results (i.e. env variables, config info)
my $log_text = &toString($results_file);
if ($log_text and $log_text ne '') {
$t->addLog(Test::Litmus::Log->new(
-type => 'STDOUT',
-data => $log_text)
);
}
if ($validate_only) {
print Dumper $t;
exit 0;
}
my $res = $t->submit();
# $res is 0 for non-fatal errors (some results were submitted), and
# undef for fatal errors (no results were submitted successfully)
if (!$res or $res != 1) {
if ($t->errstr()) {
die $t->errstr();
}
}
exit 0;
#########################################################################
sub usage() {
print<<EOUSAGE;
./submit_eggplant_results_to_litmus.pl --results_file=/path/to/result_file
--username=<your\@litmus.account>
--authtoken=yourlitmusauthtoken
--product=<product_name>
--branch=<testing_branch>
--platform=<testing_platform>
--opsys=<platform_opsys>
[--build_id=##########]
[--locale=<locale>]
[--server=http://your.litmus.server/process_test.cgi/]
[--machinename=HOSTNAME]
[--build_type=<build_type>]
[--help|-?]
[--validate_only]
results_file: the full path to the eggplant result file you are submitting
username: the email address with an associated authtoken for submitting
automated results.
authtoken: the authtoken for the Litmus account
product: the product you are testing
branch: the branch you are testing
platform: the testing platform: Windows|Mac (Intel)|Mac (PPC)|Linux|Solaris
opsys: depends on your chosen platform, e.g. Windows Vista
build_id: the 10-digit build ID of the build you are testing. If not
provided, a "fake" nightly build ID will be created based on the
current date in the format YYYYMMDD99
locale: the locale of the build you are testing, defaults to en-US
server: the hostname of your Litmus server, suffixed with
process_test.cgi. Defaults to:
http://litmus.mozilla.org/process_test.cgi
machinename: the hostname of the machine you are testing on
build_type:
help: displays this message and then exits
validate_only: confirms that you have all the necessary parameters set and that
the results file is parsable, but doesn't submit any results
EOUSAGE
}
#########################################################################
sub createFakeBuildID() {
return &UnixDate("now","%Y%m%d99");
}
#########################################################################
sub parseResultsFile {
my ($t, $results_file) = @_;
my ($short_name, $result_status, $testcase_id, $duration);
my @results;
open(RESULTSFILE, $results_file) or die "Can't open $results_file: $!";
while (<RESULTSFILE>) {
if (/^Test Case : (.*)$/) {
if ($result_status and
$testcase_id) {
my %hash = (
result_status => $result_status,
testcase_id => $testcase_id,
duration => $duration || 0,
);
push @results, \%hash;
undef $short_name;
undef $result_status;
undef $testcase_id;
undef $duration;
}
$short_name = $1;
next;
}
if ($short_name) {
if (/^Status : ([a-zA-Z]*)$/) {
my $status = $1;
if ($status =~ /PASS/i) {
$result_status = 'pass';
} elsif ($status =~ /FAIL/i) {
$result_status = 'fail';
} else {
print STDERR "Unknown result status: $status. Skipping...\n";
undef $short_name;
undef $result_status;
undef $testcase_id;
undef $duration;
}
next;
}
if (/^Litmus ID :\s+(\d+)$/) {
$testcase_id = $1;
next;
}
if (/^Duration : (\d+) seconds/) {
$duration = $1;
next;
}
}
}
close(RESULTSFILE);
# Add last result if necessary
if ($result_status and
$testcase_id) {
my %hash = (
result_status => $result_status,
testcase_id => $testcase_id,
duration => $duration || 0,
);
push @results, \%hash;
undef $short_name;
undef $result_status;
undef $testcase_id;
undef $duration;
}
my $now = &UnixDate("now","%q");
foreach my $current_result (@results) {
my $result_obj = Test::Litmus::Result->new(
-isAutomatedResult => 1, # optional
-testid => $current_result->{'testcase_id'},
-resultstatus => $current_result->{'result_status'},
-exitstatus => 'Exited Normally',
-duration => $current_result->{'duration'} || 0,
-timestamp => $now,
);
$t->addResult($result_obj);
}
}
#########################################################################
sub toString {
my ($file) = @_;
my $file_as_string = "";
my $in_header = 1;
open(FILE, $file) or die "Can't open $file: $!";
while (<FILE>) {
# Check for the testcase boundary line as our clue that we're out of
# the mail header.
if ($in_header and
/^======================================$/) {
$in_header = 0;
}
next if ($in_header);
$file_as_string .= $_;
last if (/^test run duration:/);
}
close(FILE);
return $file_as_string;
}