2 ////////////////////////////////////////////////////////////////////////////////
4 // File: TestHistory.php
6 // Description: Produce a historical report about a testcase
7 // Author: Andrew@ClearSCM.com
8 // Created: Mon Apr 28 15:20:06 MST 2008
12 // (c) Copyright 2008, General Dynamics, all rights reserved.
14 // All rights reserved except as subject to DFARS 252.227-7014 of contract
15 // number CP02H8901N issued under prime contract N00039-04-C-2009.
17 // Warning: This document contains technical data whose export is restricted
18 // by the Arms Export Control Act (Title 22, U.S.C., Sec 2751, et seq.) or the
19 // Export Administration Act of 1979, as amended, Title, 50, U.S.C., App. 2401
20 // et seq. Violations of these export laws are subject to severe criminal
21 // penalties. Disseminate in accordance with provisions of DoD Directive
24 ////////////////////////////////////////////////////////////////////////////////
25 $script = basename ($_SERVER["PHP_SELF"]);
27 include_once "$_SERVER[DOCUMENT_ROOT]/php/Utils.php";
28 include_once "$_SERVER[DOCUMENT_ROOT]/php/RantestDB.php";
30 $testcase = $_REQUEST["testcase"];
31 $user = $_REQUEST["user"];
33 $build = (empty ($_REQUEST["build"])) ? "*" : $_REQUEST["build"];
34 $level = (empty ($_REQUEST["level"])) ? "*" : $_REQUEST["level"];
35 $DUT = (empty ($_REQUEST["DUT"])) ? "*" : $_REQUEST["DUT"];
36 $test = (empty ($_REQUEST["test"])) ? "*" : $_REQUEST["test"];
38 $action = (empty ($_REQUEST["action"])) ? "Report" : $_REQUEST["action"];
39 $type = (empty ($_REQUEST["type"])) ? "All" : $_REQUEST["type"];
40 $sortBy = (empty ($_REQUEST["sortBy"])) ? "Date" : $_REQUEST["sortBy"];
41 $direction = (empty ($_REQUEST["direction"])) ? "descending" : $_REQUEST["direction"];
43 $historyFor = setTestcase ($testcase);
46 function sortDUT ($a, $b) {
49 return cmpStr ($a, $b, "DUT", $direction);
52 function sortAvgRunTime ($a, $b) {
55 return cmpNbr ($a, $b, "AvgRunTime", $direction);
58 function getData ($testcase) {
61 $data = getTestHistory ($testcase);
64 if ($sortBy == "Passed") {
65 uasort ($data, "sortPassed");
66 } elseif ($sortBy == "Failed") {
67 uasort ($data, "sortFailed");
68 } elseif ($sortBy == "Total") {
69 uasort ($data, "sortTotal");
70 } elseif ($sortBy == "AvgRunTime") {
71 uasort ($data, "sortAvgRunTime");
72 } elseif ($sortBy == "DUT") {
73 uasort ($data, "sortDUT");
74 } elseif ($sortBy == "Type") {
75 uasort ($data, "sortType");
76 } elseif ($sortBy == "Start") {
77 uasort ($data, "sortStart");
78 } elseif ($sortBy == "End") {
79 uasort ($data, "sortEnd");
80 } elseif ($sortBy == "Duration") {
81 uasort ($data, "sortDuration");
82 } elseif ($sortBy == "Status") {
83 uasort ($data, "sortStatus");
85 uasort ($data, "sortTestcase");
91 function createHeader () {
95 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
96 "http://www.w3.org/TR/html4/strict.dtd">
99 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
100 <link rel="stylesheet" type="text/css" media="screen" href="/css/Testing.css">
101 <link rel="stylesheet" type="text/css" media="screen" href="/css/Tables.css">
102 <title>Test history for $historyFor</title>
108 $header .= banner ();
110 <h1 align="center">Test history for $historyFor</h1>
116 function createPage ($testcase, $forEmail = false, $message = "") {
117 global $webdir, $direction, $sortBy, $script;
119 $data = getData ($testcase);
123 $direction = ($direction == "ascending") ? "descending" : "ascending";
125 if ($sortBy == "DUT") {
126 $DUTDirection = ($direction == "ascending")
127 ? "<img src=/images/down.png border=0>"
128 : "<img src=/images/up.png border=0>";
129 } elseif ($sortBy == "Type") {
130 $typeDirection = ($direction == "ascending")
131 ? "<img src=/images/down.png border=0>"
132 : "<img src=/images/up.png border=0>";
133 } elseif ($sortBy == "Start") {
134 $startDirection = ($direction == "ascending")
135 ? "<img src=/images/down.png border=0>"
136 : "<img src=/images/up.png border=0>";
137 } elseif ($sortBy == "End") {
138 $endDirection = ($direction == "ascending")
139 ? "<img src=/images/down.png border=0>"
140 : "<img src=/images/up.png border=0>";
141 } elseif ($sortBy == "Duration") {
142 $durationDirection = ($direction == "ascending")
143 ? "<img src=/images/down.png border=0>"
144 : "<img src=/images/up.png border=0>";
145 } elseif ($sortBy == "Status") {
146 $statusDirection = ($direction == "ascending")
147 ? "<img src=/images/down.png border=0>"
148 : "<img src=/images/up.png border=0>";
149 } elseif ($sortBy == "Passed") {
150 $passedDirection = ($direction == "ascending")
151 ? "<img src=/images/down.png border=0>"
152 : "<img src=/images/up.png border=0>";
153 } elseif ($sortBy == "Failed") {
154 $failedDirection = ($direction == "ascending")
155 ? "<img src=/images/down.png border=0>"
156 : "<img src=/images/up.png border=0>";
157 } elseif ($sortBy == "Total") {
158 $totalDirection = ($direction == "ascending")
159 ? "<img src=/images/down.png border=0>"
160 : "<img src=/images/up.png border=0>";
161 } elseif ($sortBy == "AvgRunTime") {
162 $avgRunTimeDirection = ($direction == "ascending")
163 ? "<img src=/images/down.png border=0>"
164 : "<img src=/images/up.png border=0>";
166 $testcaseDirection = ($direction == "ascending")
167 ? "<img src=/images/down.png border=0>"
168 : "<img src=/images/up.png border=0>";
171 if (isset ($message)) {
172 $page .= "<div align=center>$message</div>";
182 if (isset ($testcase)) {
185 <th class=clear align="left" colspan="2"><a href="$script?action=Export&testcase=$testcase"><input type="submit" value="Export to CSV"></a></th>
186 <th class=clear align="right" colspan="7"><form action="$script?action=Mail&testcase=$testcase" method="post">
191 <th class=clear align="left" colspan="2"><a href="$script?action=Export&testcase=$testcase"><input type="submit" value="Export to CSV"></a></th>
192 <th class=clear align="right" colspan="4"><form action="$script?action=Mail&testcase=$testcase" method="post">
196 $page .= emailUsersDropdown ();
199 <input type="submit" value="Send"></form>
205 if (isset ($testcase)) {
206 $urlParms = "$script?testcase=$testcase&action=$action&direction=$direction&sortBy";
209 <th class=left>#</th>
210 <th><a href=$urlParms=Testcase>Testcase $testcaseDirection</a></th>
211 <th><a href=$urlParms=DUT>DUT $DUTDirection</a></th>
212 <th><a href=$urlParms=Type>Type $typeDirection</a></th>
213 <th><a href=$urlParms=Start>Start $startDirection</a></th>
214 <th><a href=$urlParms=End>End $endDirection</a></th>
215 <th><a href=$urlParms=Duration>Duration $durationDirection</a></th>
217 <th class=right><a href=$urlParms=Status>Status $statusDirection</a></th>
220 $urlParms = "$script?build=$build&level=$level&DUT=$DUT&test=$test&action=$action&direction=$direction&sortBy";
223 <th class=left>#</th>
224 <th><a href=$urlParms=Testcase>Testcase $testcaseDirection</a></th>
225 <th><a href=$urlParms=Passed>Passed $passedDirection</a></th>
226 <th><a href=$urlParms=Failed>Failed $failedDirection</a></th>
227 <th><a href=$urlParms=Total>Total $totalDirection</a></th>
228 <th class=right><a href=$urlParms=AvgRunTime>Avg Run Time $avgRunTimeDirection</a></th>
242 foreach ($data as $line) {
245 if (isset ($testcase)) {
246 $class = SetRowColor ($line["Status"]);
247 $status = colorResult ($line["Status"]);
248 $date = YMD2MDY (substr ($line["Start"], 0, 10));
249 $duration = FormatDuration ($line["Duration"]);
250 $logs = logs ($line["_eastlogs"]);
254 <td align=center>$row_nbr</td>
255 <td><a href="$webdir/rantest.php?testName=$line[Testcase]&runid=$line[_runid]&date=$date">$line[Testcase]</a></td>
256 <td align=center>$line[DUT]</td>
257 <td align=center>$line[Type]</td>
258 <td align=center>$line[Start]</td>
259 <td align=center>$line[End]</td>
261 <td align=center>$logs</td>
266 $row_color = ($row_nbr % 2 == 0) ? " class=other" : " class=white";
270 <td align=center>$row_nbr</td>
271 <td><a href="$script?testcase=$line[Testcase]">$line[Testcase]</a></td>
272 <td align=right>$line[Passed]</td>
273 <td align=right>$line[Failed]</td>
274 <td align=right>$line[Total]</td>
277 $page .= FormatDuration ($line[AvgRunTime]);
278 $page .= "</td></tr>";
279 $total_passed += $line["Passed"];
280 $total_failed += $line["Failed"];
281 $total_total += $line["Total"];
286 if (empty ($testcase)) {
290 <th colspan=2>Total</th>
291 <th align=right>$total_passed</th>
292 <th align=right>$total_failed</th>
293 <th align=right>$total_total</th>
308 function exportTestHistoryCSV ($testcase) {
311 if (isset ($testcase)) {
312 $title = "Test History for $historyFor";
313 $filename = "Test History." . $testcase . ".csv";
315 $title = "Test History for All Tests";
316 $filename = "Test History.All Tests.csv";
319 // Protect $filename from wildcards
320 $filename = preg_replace ("/\*/", "%", $filename);
322 header ("Content-Type: application/octect-stream");
323 header ("Content-Disposition: attachment; filename=\"$filename\"");
325 print exportCSV (getData ($testcase), $title);
328 } // exportTestHistoryCSV
330 function setTestcase () {
331 global $testcase, $build, $level, $DUT, $test;
333 if (empty ($testcase)) {
338 if ($build == "*" and
345 $testcase = "${build}_${level}_${DUT}_${test}";
352 function displayReport ($testcase, $message = "") {
353 print createHeader ();
354 print createPage ($testcase, false, $message);
359 function mailTestHistoryReport ($testcase, $pnbr, $username) {
362 if (isset ($testcase)) {
363 $subject = "Test History for $historyFor";
364 $filename = "Test History." . $testcase . ".csv";
366 $subject = "Test History for All Tests";
367 $filename = "Test History.All Tests.csv";
370 // Protect $filename from wildcards
371 $filename = preg_replace ("/\*/", "%", $filename);
373 $body = createPage ($testcase, true);
374 $attachment = exportCSV (getData ($testcase, true), $subject);
376 return mailReport ($pnbr, $username, $subject, $body, $filename, $attachment);
377 } // mailTestHistoryReport
381 $historyFor = setTestcase ();
385 exportTestHistoryCSV ($testcase);
389 list ($pnbr, $username) = explode (":", $user);
390 displayReport ($testcase, mailTestHistoryReport ($testcase, $pnbr, $username));
394 displayReport ($testcase);