<%perl>
# unit-test-results.html
#
# @author D. Chang
#
# TODO: Retrieve password from a file.
# TODO: Add display of testing totals.
# @todo Add link to testing state.
# @todo Group by categories or modules.
</%perl>

<%args>
$test_run_id
</%args>

<%perl>
use DBI;
my $dbuser="root";
my $dbpass="panstar1";
#my $dbuser="mops";
#my $dbpass="mops";
my $dbname="psmops_testing_results";
my $dbhost="schmopc01.ifa.hawaii.edu";
my $dbconnect="DBI:mysql:$dbname:$dbhost";
my $dbh=DBI->connect($dbconnect,$dbuser,$dbpass) || die "ERROR: Cannot connect to database $dbname.";
my $sql="SELECT id,test_run,number,psmops_function,module,cvs_version,test,modifier1,modifier2,result,FORMAT(wall,5),cpu FROM unit_test_results WHERE test_run=$test_run_id";
my $sth=$dbh->prepare($sql);
my $result=$sth->execute;
my $ref;
if($result){
    $ref=$sth->fetchall_arrayref();
}

# Get Test Run time.
$sql="SELECT DATE_FORMAT(time,'%Y-%b-%d %a %H:%i') FROM test_runs WHERE id=$test_run_id";
$sth=$dbh->prepare($sql);
$result=$sth->execute;
my $test_run_time;
if($result){
    $test_run_time=$sth->fetchall_arrayref();
}

# Count test runs.
$sql="SELECT COUNT(utr.id)
      FROM unit_test_results utr
      WHERE test_run=$test_run_id AND result!='n'";
$sth=$dbh->prepare($sql);
$result=$sth->execute;
my $test_cnts;
if($result){
    $test_cnts=$sth->fetchall_arrayref();
}

# Count successful tests.
$sql="SELECT COUNT(utr.id)
      FROM unit_test_results utr
      WHERE test_run=$test_run_id AND result='p'";
$sth=$dbh->prepare($sql);
$result=$sth->execute;
my $pass_cnts;
if($result){
    $pass_cnts=$sth->fetchall_arrayref();
}
</%perl>

<& header.mas &>

<table>
<tr>
<td>
&nbsp;<a href="/testing/testing-state.html?test_run_id=<% $test_run_id %>">Testing State (<% $test_run_id %>)</a><br>
</td>
</tr>
</table>

<p>
<table width="100%">
<tr>
<td width="90%">
<h2>Unit Test Results</h2>
</td>
<td width="10%" align="right">
<a href="#legend">Legend</a>
</td>
</tr>
<tr>
<td>Test Run ID = <% $test_run_id %>, Time = <% $test_run_time->[0]->[0] %> GMT, Result =

<%perl>
my $passed=$pass_cnts->[0]->[0];
my $total=$test_cnts->[0]->[0];
print " $passed/$total";
</%perl>

</td>
</tr>
</table>
<p>
<table border="1">
<tr>
<td>Number</td>
<td>PSMOPS</td>
<td>Module</td>
<td>Version</td>
<td>Test</td>
<td>Modifier1</td>
<td>Modifier2</td>
<td>Result</td>
<td>Wall [s]</td>
<td>CPU [s]</td>
</tr>

% for(my $i=0;$i<scalar(@$ref);$i++) {

<tr>
<td>
<% $ref->[$i]->[2] %>
</td>
<td>
<% $ref->[$i]->[3] %>
</td>
<td>
<% $ref->[$i]->[4] %>
</td>
<td>
<% $ref->[$i]->[5] %>
</td>
<td>
<% $ref->[$i]->[6] %>
</td>
<td>

<%perl>
my $r=$ref->[$i]->[7];
if(!defined($r)){
    print "&nbsp;";
}
else {
    print $r;
}
</%perl>

</td>
<td>

<%perl>
$r=$ref->[$i]->[8];
if(!defined($r)){
    print "&nbsp;";
}
else {
    print $r;
}
</%perl>

</td>

<%perl>
my $result=$ref->[$i]->[9];
if($result eq "P") {
    print "<td bgcolor=\"#009900\">";
    print "PASS";
    print "</td>";
}
elsif($result eq "F") {
    print "<td bgcolor=\"#990000\">FAIL!</td>";
}
elsif($result eq "N") {
    print "<td bgcolor=\"#888888\">NI</td>";
}
else { print "<td>NONE</td>"; }
</%perl>

</td>
<td>
<% $ref->[$i]->[10] %>
</td>
<td>
<% $ref->[$i]->[11] %>
</td>
</tr>

% }

<table>
<p>
<a name="legend">
<font size="-1">
<b>PSMOPS</b> Value 1 indicates test corresponds directly to a PS-MOPS function, 0 otherwise.<br>
<b>Version</b> CVS version<br>
<b>Modifier1, Modifier2</b> Used to distinguish test variations.<br>
<b>Result</b> PASS for success, FAIL! for failure, NI for not implemented.<br>
</font>
</p>
</body>
</html>
