2005-07-30 00:21:01 +04:00
|
|
|
#!/usr/bin/perl -w
|
2005-10-11 22:44:16 +04:00
|
|
|
# -*- mode: cperl; c-basic-offset: 8; indent-tabs-mode: nil; -*-
|
|
|
|
|
|
|
|
# ***** BEGIN LICENSE BLOCK *****
|
|
|
|
# Version: MPL 1.1
|
2005-07-30 00:21:01 +04:00
|
|
|
#
|
2005-10-11 22:44:16 +04:00
|
|
|
# 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/
|
2005-07-30 00:21:01 +04:00
|
|
|
#
|
2005-10-11 22:44:16 +04:00
|
|
|
# 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.
|
2005-07-30 00:21:01 +04:00
|
|
|
#
|
|
|
|
# The Original Code is Litmus.
|
|
|
|
#
|
2005-10-11 22:44:16 +04:00
|
|
|
# The Initial Developer of the Original Code is
|
|
|
|
# the Mozilla Corporation.
|
2006-01-25 20:03:40 +03:00
|
|
|
# Portions created by the Initial Developer are Copyright (C) 2006
|
2005-10-11 22:44:16 +04:00
|
|
|
# the Initial Developer. All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Contributor(s):
|
|
|
|
# Chris Cooper <ccooper@deadsquid.com>
|
|
|
|
# Zach Lipton <zach@zachlipton.com>
|
2005-07-30 00:21:01 +04:00
|
|
|
#
|
2005-10-11 22:44:16 +04:00
|
|
|
# ***** END LICENSE BLOCK *****
|
2005-07-30 00:21:01 +04:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
use Litmus;
|
|
|
|
use Litmus::Error;
|
|
|
|
use Litmus::DB::Product;
|
|
|
|
use Litmus::UserAgentDetect;
|
|
|
|
use Litmus::SysConfig;
|
|
|
|
use Litmus::Auth;
|
2005-08-04 04:59:29 +04:00
|
|
|
use Litmus::Utils;
|
2005-10-17 21:00:06 +04:00
|
|
|
use Litmus::DB::Resultbug;
|
2006-06-23 03:21:38 +04:00
|
|
|
use Litmus::XML;
|
2005-07-30 00:21:01 +04:00
|
|
|
|
|
|
|
use CGI;
|
2005-10-15 05:09:42 +04:00
|
|
|
use Date::Manip;
|
2005-10-11 22:44:16 +04:00
|
|
|
use diagnostics;
|
2005-07-30 00:21:01 +04:00
|
|
|
|
2006-01-08 06:56:10 +03:00
|
|
|
my $c = Litmus->cgi();
|
2005-07-30 00:21:01 +04:00
|
|
|
|
2006-06-23 03:21:38 +04:00
|
|
|
if ($c->param('data')) {
|
|
|
|
# we're getting XML result data from an automated testing provider,
|
|
|
|
# so pass that off to XML.pm for processing
|
|
|
|
my $x = Litmus::XML->new();
|
|
|
|
$x->processResults($c->param('data'));
|
|
|
|
|
|
|
|
# return whatever response was generated:
|
|
|
|
print $c->header('text/plain');
|
|
|
|
print $x->response();
|
|
|
|
exit; # that's all folks!
|
|
|
|
}
|
|
|
|
|
2005-07-30 00:21:01 +04:00
|
|
|
my $user;
|
|
|
|
my $sysconfig;
|
|
|
|
if ($c->param("isSysConfig")) {
|
2005-10-17 21:00:06 +04:00
|
|
|
$sysconfig = Litmus::SysConfig->processForm($c);
|
|
|
|
my $email = $c->param("email");
|
|
|
|
$user = Litmus::DB::User->find_or_create(email => $email);
|
|
|
|
print $c->header(-cookie => [$sysconfig->setCookie(), Litmus::Auth::setCookie($user)]);
|
2005-07-30 00:21:01 +04:00
|
|
|
} else {
|
2005-10-17 21:00:06 +04:00
|
|
|
print $c->header();
|
2005-07-30 00:21:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
my @names = $c->param();
|
|
|
|
|
|
|
|
# find all the test numbers contained in this result submission
|
|
|
|
my @tests;
|
|
|
|
foreach my $curname (@names) {
|
2005-10-17 21:00:06 +04:00
|
|
|
if ($curname =~ /testresult_(\d*)/) {
|
|
|
|
push(@tests, $1);
|
|
|
|
}
|
2005-07-30 00:21:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# don't get to use the simple test interface if you really
|
|
|
|
# have more than one test (i.e. you cheated and changed the
|
|
|
|
# hidden input)
|
|
|
|
if (scalar @tests > 1 && $c->param("isSimpleTest")) {
|
2005-10-17 21:00:06 +04:00
|
|
|
invalidInputError("Cannot use simpletest interface with more than one test");
|
2005-07-30 00:21:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
my $testcount;
|
|
|
|
my %resultcounts;
|
2005-08-23 09:22:14 +04:00
|
|
|
my $product;
|
2005-07-30 00:21:01 +04:00
|
|
|
foreach my $curtestid (@tests) {
|
2005-10-17 21:00:06 +04:00
|
|
|
unless ($c->param("testresult_".$curtestid)) {
|
|
|
|
# user didn't submit a result for this test so just skip
|
|
|
|
# it and move on...
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2006-06-05 08:07:29 +04:00
|
|
|
my $curtest = Litmus::DB::Testcase->retrieve($curtestid);
|
2005-10-17 21:00:06 +04:00
|
|
|
unless ($curtest) {
|
|
|
|
# oddly enough, the test doesn't exist
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
$testcount++;
|
2005-10-11 22:44:16 +04:00
|
|
|
|
2005-10-17 21:00:06 +04:00
|
|
|
$product = $curtest->product();
|
|
|
|
|
|
|
|
my $ua = Litmus::UserAgentDetect->new();
|
|
|
|
# for simpletest, build a temporary sysconfig based on the
|
|
|
|
# UA string and product of this test:
|
|
|
|
if ($c->param("isSimpleTest")) {
|
|
|
|
$sysconfig = Litmus::SysConfig->new(
|
|
|
|
$curtest->product(),
|
|
|
|
$ua->platform($curtest->product()),
|
|
|
|
"NULL", # no way to autodetect the opsys
|
|
|
|
$ua->branch($curtest->product()),
|
2006-06-05 08:07:29 +04:00
|
|
|
$ua->build_id(),
|
2005-10-17 21:00:06 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
# get system configuration. If there is no configuration and we're
|
|
|
|
# not doing the simpletest interface, then we make you enter it
|
|
|
|
# Get system configuration. If there is no configuration,
|
|
|
|
# then we make the user enter it.
|
|
|
|
if (!$sysconfig) {
|
|
|
|
$sysconfig = Litmus::SysConfig->getCookie($product);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Users who still don't have a sysconfig for this product
|
|
|
|
# should go configure themselves first.
|
|
|
|
if (!$sysconfig) {
|
|
|
|
Litmus::SysConfig->displayForm($product,
|
|
|
|
"process_test_results.cgi",
|
|
|
|
$c);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2006-06-05 08:07:29 +04:00
|
|
|
my $result_status = Litmus::DB::ResultStatus->retrieve($c->param("testresult_".$curtestid));
|
|
|
|
$resultcounts{$result_status->name()}++;
|
2005-10-17 21:00:06 +04:00
|
|
|
|
|
|
|
my $note = $c->param("comment_".$curtestid);
|
|
|
|
my $bugs = $c->param("bugs_".$curtestid);
|
|
|
|
|
|
|
|
my $time = &Date::Manip::UnixDate("now","%q");
|
|
|
|
|
|
|
|
# normally, the user comes with a cookie, but for simpletest
|
|
|
|
# users, we just use the web-user@mozilla.org user:
|
|
|
|
|
|
|
|
if ($c->param("isSimpleTest")) {
|
|
|
|
$user = $user || Litmus::DB::User->search(email => 'web-tester@mozilla.org')->next();
|
|
|
|
} else {
|
2006-06-05 08:07:29 +04:00
|
|
|
$user = $user || Litmus::Auth::getCookie()->user_id();
|
2005-10-17 21:00:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
my $tr = Litmus::DB::Testresult->create({
|
|
|
|
user => $user,
|
2006-06-05 08:07:29 +04:00
|
|
|
testcase => $curtest,
|
2005-10-17 21:00:06 +04:00
|
|
|
timestamp => $time,
|
|
|
|
last_updated => $time,
|
|
|
|
useragent => $ua,
|
2006-06-05 08:07:29 +04:00
|
|
|
result_status => $result_status,
|
2005-10-17 21:00:06 +04:00
|
|
|
opsys => $sysconfig->opsys(),
|
|
|
|
branch => $sysconfig->branch(),
|
2006-06-05 08:07:29 +04:00
|
|
|
build_id => $sysconfig->build_id(),
|
2005-12-13 06:03:37 +03:00
|
|
|
locale_abbrev => $sysconfig->locale(),
|
2005-10-17 21:00:06 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
# if there's a note, create an entry in the comments table for it
|
|
|
|
if ($note and
|
|
|
|
$note ne '') {
|
|
|
|
Litmus::DB::Comment->create({
|
|
|
|
testresult => $tr,
|
|
|
|
submission_time => $time,
|
|
|
|
last_updated => $time,
|
|
|
|
user => $user,
|
|
|
|
comment => $note
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($bugs and
|
|
|
|
$bugs ne '') {
|
2005-12-14 01:12:22 +03:00
|
|
|
$bugs =~ s/[^0-9,]//g;
|
2005-10-17 21:00:06 +04:00
|
|
|
my @new_bugs = split(/,/,$bugs);
|
|
|
|
foreach my $new_bug (@new_bugs) {
|
2005-12-14 01:12:22 +03:00
|
|
|
next if ($new_bug eq '0');
|
2005-10-17 21:00:06 +04:00
|
|
|
my $bug = Litmus::DB::Resultbug->create({
|
|
|
|
testresult => $tr,
|
|
|
|
last_updated => $time,
|
|
|
|
submission_time => $time,
|
|
|
|
user => $user,
|
|
|
|
bug_id => $new_bug,
|
|
|
|
});
|
|
|
|
}
|
2005-10-11 22:44:16 +04:00
|
|
|
}
|
2005-07-30 00:21:01 +04:00
|
|
|
|
2005-10-17 21:00:06 +04:00
|
|
|
}
|
2006-06-05 09:53:10 +04:00
|
|
|
|
|
|
|
if (! $testcount) {
|
|
|
|
invalidInputError("No results submitted.");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-17 21:00:06 +04:00
|
|
|
|
2005-07-30 00:21:01 +04:00
|
|
|
my $testgroup;
|
|
|
|
if ($c->param("testgroup")) {
|
2006-06-05 09:53:10 +04:00
|
|
|
$testgroup = Litmus::DB::Testgroup->retrieve($c->param("testgroup"));
|
|
|
|
if (! $product) {
|
|
|
|
$product = $testgroup->product();
|
|
|
|
}
|
2005-07-30 00:21:01 +04:00
|
|
|
}
|
|
|
|
|
2005-10-11 22:44:16 +04:00
|
|
|
my $vars;
|
|
|
|
$vars->{'title'} = 'Run Tests';
|
|
|
|
|
|
|
|
my $cookie = Litmus::Auth::getCookie();
|
|
|
|
$vars->{"defaultemail"} = $cookie;
|
|
|
|
$vars->{"show_admin"} = Litmus::Auth::istrusted($cookie);
|
|
|
|
|
2006-02-07 21:20:53 +03:00
|
|
|
$vars->{'testcount'} = $testcount;
|
|
|
|
$vars->{'product'} = $product || undef;
|
|
|
|
$vars->{'resultcounts'} = \%resultcounts || undef;
|
|
|
|
$vars->{'testgroup'} = $testgroup || undef;
|
|
|
|
$vars->{'return'} = $c->param("return") || undef;
|
|
|
|
|
|
|
|
Litmus->template()->process("process/process.html.tmpl", $vars) ||
|
|
|
|
internalError(Litmus->template()->error());
|
|
|
|
|