2 ////////////////////////////////////////////////////////////////////////////////
6 // Description: Produce Daily Test Report, Test Suite Report and Test Steps
8 // Author: Andrew@ClearSCM.com
9 // Created: Mon Apr 28 15:20:06 MST 2008
13 // (c) Copyright 2008, General Dynamics, all rights reserved.
15 // All rights reserved except as subject to DFARS 252.227-7014 of contract
16 // number CP02H8901N issued under prime contract N00039-04-C-2009.
18 // Warning: This document contains technical data whose export is restricted
19 // by the Arms Export Control Act (Title 22, U.S.C., Sec 2751, et seq.) or the
20 // Export Administration Act of 1979, as amended, Title, 50, U.S.C., App. 2401
21 // et seq. Violations of these export laws are subject to severe criminal
22 // penalties. Disseminate in accordance with provisions of DoD Directive
25 ////////////////////////////////////////////////////////////////////////////////
26 $script = basename ($_SERVER["PHP_SELF"]);
28 include_once "$_SERVER[DOCUMENT_ROOT]/php/Utils.php";
29 include_once "$_SERVER[DOCUMENT_ROOT]/php/RantestDB.php";
31 $testName = $_REQUEST["testName"];
32 $runid = $_REQUEST["runid"];
33 $date = $_REQUEST["date"];
34 $suiteid = $_REQUEST["suiteid"];
35 $user = $_REQUEST["user"];
37 $type = (empty ($_REQUEST["type"])) ? "All" : $_REQUEST["type"];
38 $action = (empty ($_REQUEST["action"])) ? "Report" : $_REQUEST["action"];
39 $sortBy = (empty ($_REQUEST["sortBy"])) ? "Start" : $_REQUEST["sortBy"];
40 $direction = (empty ($_REQUEST["direction"])) ? "descending" : $_REQUEST["direction"];
42 function createTestStepsHeader ($testcase) {
44 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
45 "http://www.w3.org/TR/html4/strict.dtd">
48 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
49 <link rel="stylesheet" type="text/css" media="screen" href="/css/Testing.css">
50 <link rel="stylesheet" type="text/css" media="screen" href="/css/Tables.css">
51 <title>Test Steps for $testcase</title>
59 <h1 align="center">Test Steps for $testcase</h1>
63 } // createTestStepsHeader
65 function createTestRunsHeader ($day) {
69 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
70 "http://www.w3.org/TR/html4/strict.dtd">
73 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
74 <link rel="stylesheet" type="text/css" media="screen" href="/css/Testing.css">
75 <link rel="stylesheet" type="text/css" media="screen" href="/css/Tables.css">
76 <title>Daily Test Report for $day</title>
77 <script language="javascript">
78 function ChangeDay (day, script) {
79 window.location = script + "?day=" + day;
81 function ChangeType (day, type, script) {
82 window.location = script + "?day=" + day + "&type=" + type;
91 <h1 align="center">Daily Test Report for $dateDropdown</h1>
95 } // createTestRunsHeader
97 function createSuiteRunsHeader ($id) {
98 $suite = getName ("suite", $id);
101 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
102 "http://www.w3.org/TR/html4/strict.dtd">
105 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
106 <link rel="stylesheet" type="text/css" media="screen" href="/css/Testing.css">
107 <link rel="stylesheet" type="text/css" media="screen" href="/css/Tables.css">
108 <title>Suite Report for $suite</title>
114 $header .= banner ();
117 } // createSuiteRunsHeader
119 function createTestStepsPage ($testName, $forEmail = false, $message = "") {
120 global $runid, $date, $script;
122 $data = getTestSteps ($runid);
125 if (isset ($message)) {
126 $page .= "<div align=center>$message</div>";
131 <table align=center width=90%>
133 DUT: <font class="standout">{$data[_header][DUTVersion]}</font>
134 EAST: <font class="standout">{$data[_header][EASTVersion]}</font>
135 TM500: <font class="standout">{$data[_header][TM500Version]}</font>
136 NMS: <font class="standout">{$data[_header][NMSVersion]}</font>
137 RANTEST: <font class="standout">{$data[_header][RANTESTVersion]}</font>
138 Date: <font class="standout">$date</font>
146 <th class="clear" align="left"><a href="$script?action=Export&testName=$testName&runid=$runid&date=$date"><input type="submit" value="Export to CSV"></a> <a href="TestHistory.php?testcase=$testName"><input type="submit" value="History"></a></th>
147 <th class=clear colspan="4" align="right"><form action="$script?action=Mail&date=$date&testName=$testName&runid=$runid" method="post">
150 $page .= emailUsersDropdown ();
153 <input type="submit" value="Send"></form>
161 <th class=left>Step</th>
165 <th class=right>Duration</th>
171 foreach ($data["_steps"] as $line) {
173 $row_color = setRowColor ($line["Status"]);
174 $line["Status"] = colorResult ($line["Status"]);
175 $total_time += $line[Duration];
176 $startTime = substr ($line["Start"], 11, 8);
177 $endTime = substr ($line["End"], 11, 8);
182 <td>$line[Status]</td>
183 <td align="center">$startTime</td>
184 <td align="center">$endTime</td>
187 $page .= FormatDuration ($line[Duration]);
191 $total_duration = FormatDuration ($total_time);
193 $logs = logs ($data["_header"]["_eastlogs"], $forEmail);
195 $username = getUserName ($data["_header"]["userid"]);
200 <th align="left">Total steps run in $testName: $steps</th>
201 <th align="right" colspan="2">Run by: <a href="mailto:{$data[_header][userid]}@gdc4s.com" class="tablelink">$username</a></th>
202 <th align="center">$logs</th>
203 <th align="right">$total_duration</th>
211 } // createTestStepsPage
213 function createTestRunsPage ($day, $forEmail = false, $message = "") {
214 global $sortBy, $direction, $day, $type, $script, $testTypes;
217 if ($sortBy == "Suite") {
218 $suiteDirection = ($direction == "ascending")
219 ? "<img src=/images/down.png border=0>"
220 : "<img src=/images/up.png border=0>";
221 } elseif ($sortBy == "Testcase") {
222 $testcaseDirection = ($direction == "ascending")
223 ? "<img src=/images/down.png border=0>"
224 : "<img src=/images/up.png border=0>";
225 } elseif ($sortBy == "Type") {
226 $typeDirection = ($direction == "ascending")
227 ? "<img src=/images/down.png border=0>"
228 : "<img src=/images/up.png border=0>";
229 } elseif ($sortBy == "Unit") {
230 $unitDirection = ($direction == "ascending")
231 ? "<img src=/images/down.png border=0>"
232 : "<img src=/images/up.png border=0>";
233 } elseif ($sortBy == "Status") {
234 $statusDirection = ($direction == "ascending")
235 ? "<img src=/images/down.png border=0>"
236 : "<img src=/images/up.png border=0>";
237 } elseif ($sortBy == "Start") {
238 $startDirection = ($direction == "ascending")
239 ? "<img src=/images/down.png border=0>"
240 : "<img src=/images/up.png border=0>";
241 } elseif ($sortBy == "End") {
242 $endDirection = ($direction == "ascending")
243 ? "<img src=/images/down.png border=0>"
244 : "<img src=/images/up.png border=0>";
245 } elseif ($sortBy == "Duration") {
246 $durationDirection = ($direction == "ascending")
247 ? "<img src=/images/down.png border=0>"
248 : "<img src=/images/up.png border=0>";
251 if (isset ($message)) {
252 $page .= "<div align=center>$message</div>";
264 <th class="clear" align="left" colspan="5">
265 <a href="$script?action=Export&day=$day"><input type="submit"
266 value="Export to CSV"></a> <a href="FailureAnalysis.php?day=$day">
267 <input type="submit" value="Analyze Failures"></a>
268 Type: <select name="type" class="inputfield" onChange="ChangeType('$day',this.value,'$script');">
271 foreach ($testTypes as $t) {
273 $page .= "<option>$t</option>";
275 $page .= "<option selected=\"selected\">$t</option>";
281 <th class=clear colspan="5" align="right"><form action="$script?action=Mail&day=$day&type=$type" method="post">
284 $page .= emailUsersDropdown ();
287 <input type="submit" value="Send"></form>
292 $page .= "<th class=\"clear\" colspan=\"10\">Type: $type Sorted by: $sortBy ($direction)</th>";
295 $direction = ($direction == "ascending") ? "descending" : "ascending";
296 $urlParms = "$script?day=$day&&direction=$direction&type=$type&sortBy";
300 <th class="left">#</th>
301 <th><a href="$urlParms=Suite">Suite $suiteDirection</a></th>
302 <th><a href="$urlParms=Testcase">Testcase $testcaseDirection</a></th>
303 <th><a href="$urlParms=Type">Type $typeDirection</a></th>
304 <th><a href="$urlParms=Unit">Unit/Version $unitDirection</a></th>
306 <th><a href="$urlParms=Status">Status $statusDirection</a></th>
307 <th><a href="$urlParms=Start">Start $startDirection</a></th>
308 <th><a href="$urlParms=End">End $endDirection</a></th>
309 <th class="right"><a href="$urlParms=Duration">Duration $durationDirection</</th>
318 $data = getTestRuns (MDY2YMD ($day), $type);
322 foreach ($data as $line) {
323 // WARNING: This is odd! $line["Suite"] should be empty if there
324 // was no suite associated with it (thereby suiteid=0) but for
325 // some odd reason due to the complex select statement used
326 // suiteid ends up being 1 which is associated with the suite name
328 if ($line["Suite"] == "nightly") {
329 $line["Suite"] = "<font color=#999999>Standalone</font>";
331 $line["Suite"] = "<a href=\"$me?suiteid=$line[_suiteid]\">$line[Suite]</a>";
334 $row_color = setRowColor ($line["Status"]);
335 $testResult = colorResult ($line["Status"]);
336 $total_time += $line["Duration"];
337 $me = ($script == "index.php") ? "" : $script;
338 $logs = logs ($line["_eastlogs"], $forEmail);
343 <td align=center>$tests</td>
344 <td>$line[Suite]</td>
345 <td><a href=$me?testName=
347 $page .= $line["Testcase"];
348 $page .= "&runid=$line[_runid]&date=$day>";
349 $page .= $line["Testcase"];
352 <td align="center">$line[Type]</td>
355 $page .= $line["Unit/Version"];
358 <td align="center">$logs</td>
359 <td align="center">$testResult</td>
360 <td align="center">$line[Start]</td>
361 <td align="center">$line[End]</td>
365 $page .= FormatDuration ($line["Duration"]);
366 $page .= "</td></tr>";
369 $total_duration = FormatDuration ($total_time);
374 <th align="left" colspan="9">$tests Run
376 $page .= stats ($day, $type);
379 <th align="right">$total_duration</th>
386 } // createTestRunsPage
388 function createSuiteRunsPage ($suiteid, $forEmail = false, $message = "") {
389 global $sortBy, $direction, $day;
391 $name = getName ("suite", $suiteid);
392 $page = "<h1 align=center>Test Suite Report for $name</h1>";
395 if ($sortBy == "Status") {
396 $statusDirection = ($direction == "ascending")
397 ? "<img src=/images/down.png border=0>"
398 : "<img src=/images/up.png border=0>";
399 } elseif ($sortBy == "Start") {
400 $startDirection = ($direction == "ascending")
401 ? "<img src=/images/down.png border=0>"
402 : "<img src=/images/up.png border=0>";
403 } elseif ($sortBy == "End") {
404 $endDirection = ($direction == "ascending")
405 ? "<img src=/images/down.png border=0>"
406 : "<img src=/images/up.png border=0>";
407 } elseif ($sortBy == "Duration") {
408 $durationDirection = ($direction == "ascending")
409 ? "<img src=/images/down.png border=0>"
410 : "<img src=/images/up.png border=0>";
413 if (isset ($message)) {
414 $page .= "<div align=center>$message</div>";
419 <table align=center width="75%">
426 <th class="clear" align="left" colspan="2"><a href="$script?action=Export&suiteid=$suiteid"><input type="submit" value="Export to CSV"></a>
431 <th class=clear colspan="2" align="right"><form action="$script?action=Mail&suiteid=$suiteid" method="post">
434 $page .= emailUsersDropdown ();
437 <input type="submit" value="Send"></form>
443 $direction = ($direction == "ascending") ? "descending" : "ascending";
444 $urlParms = "$script?suiteid=$suiteid&direction=$direction&&sortBy";
446 $data = getSuiteRuns ($suiteid);
450 <th class=left><a href="$urlParms=Status">Status $statusDirection</a></th>
451 <th><a href="$urlParms=Start">Start $startDirection</a></th>
452 <th><a href="$urlParms=End">End $endDirection</a></th>
453 <th class=right><a href="$urlParms=Duration">Duration $durationDirection</a></th>
459 foreach ($data as $line) {
460 $row_color = setRowColor ($line["Status"]);
461 $status = colorResult ($line["Status"]);
462 $duration = FormatDuration ($line["Duration"]);
465 $total_time += $line["Duration"];
470 <td align="center">$line[Start]</td>
471 <td align="center">$line[End]</td>
472 <td align="right">$duration</td>
477 $total_duration = FormatDuration ($total_time);
482 <th align="left" colspan="3">Total sutie runs for $name: $suiteruns</th>
483 <th align="right">$total_duration</th>
491 } // createSuiteRunsPage
493 function displayStepRun ($testName, $message = "") {
494 print createTestStepsHeader ($testName);
495 print createTestStepsPage ($testName, false, $message);
500 function displayTestRuns ($day, $message = "") {
501 print createTestRunsHeader ($day);
502 print createTestRunsPage ($day, false, $message);
507 function displaySuiteRun ($suiteid, $message = "") {
508 print createSuiteRunsHeader ($suiteid);
509 print createSuiteRunsPage ($suiteid, false, $message);
514 // The $data structure for test steps is unique so handle exportion
516 function exportStepRunCSV ($data, $title) {
521 // Put out header information
522 $csv .= "DUT, EAST, TM500, NMS, RANTEST, USER, DATE, LOGS\n";
532 foreach ($versions as $version) {
533 if ($data["_header"][$version] == $na) {
536 $csv .= $data["_header"][$version] . ",";
540 $csv .= $data["_header"]["userid"] . ",";
541 $csv .= YMD2MDY ($data["_header"]["Date"]) . ",";
542 $csv .= logs ($data["_header"]["_eastlogs"], true) . "\n\n";
544 // Create header line
547 foreach ($data["_steps"][0] as $key => $value) {
548 // Skip "hidden" fields - fields beginning with "_"
549 if (preg_match ("/^_/", $key) == 1) {
564 foreach ($data["_steps"] as $entry) {
567 foreach ($entry as $key => $value) {
568 // Skip "hidden" fields - fields beginning with "_"
569 if (preg_match ("/^_/", $key) == 1) {
579 $csv .= "\"$value\"";
586 } // exportStepRunCSV
588 function exportStepRun ($testcase, $runid, $date) {
589 $timestamp = getTestRunTimestamp ($runid);
590 $filename = "Step Report." . $timestamp . ".csv";
592 header ("Content-Type: application/octect-stream");
593 header ("Content-Disposition: attachment; filename=\"$filename\"");
595 print exportStepRunCSV (getTestSteps ($runid), "Step Report for $testcase");
600 function exportTestRuns ($day) {
603 $filename = "Daily Test Report." . $day . ".csv";
605 header ("Content-Type: application/octect-stream");
606 header ("Content-Disposition: attachment; filename=\"$filename\"");
608 print exportCSV (getTestRuns (MDY2YMD ($day), $type, true), "Daily Test Report for $day");
613 function exportSuiteRun ($suiteid) {
614 $suite = getName ("suite", $suiteid);
615 $filename = "Suite Report." . $suite . ".csv";
617 header ("Content-Type: application/octect-stream");
618 header ("Content-Disposition: attachment; filename=\"$filename\"");
620 print exportCSV (getSuiteRuns ($suiteid), "Suite Report for $suite");
625 function mailStepRunReport ($testName, $pnbr, $username) {
628 $subject = "Step Report for $testName";
629 $body = createTestStepsPage ($testName, true);
630 $timestamp = getTestRunTimestamp ($runid);
631 $filename = "Step Report." . $timestamp . ".csv";
632 $attachment = exportStepRunCSV (getTestSteps ($runid), $subject);
634 return mailReport ($pnbr, $username, $subject, $body, $filename, $attachment);
637 function mailTestRunsReport ($day, $pnbr, $username) {
640 $subject = "Daily Test Report for $day";
641 $body = createTestRunsPage ($day, true);
642 $filename = "TestRuns.$day.csv";
643 $attachment = exportCSV (getTestRuns (MDY2YMD ($day), $type, true), $subject);
645 return mailReport ($pnbr, $username, $subject, $body, $filename, $attachment);
646 } // mailTestRunsReport
648 function mailSuiteRunReport ($suiteid, $pnbr, $username) {
649 $subject = "Suite Report for $suitid";
650 $body = createSuiteRunsPage ($suiteid, true);
651 $filename = "Suite Runs.$suiteid.csv";
653 $attachment = exportCSV (getSuiteRuns ($suiteid, true), $subject);
655 return mailReport ($pnbr, $username, $subject, $body, $filename, $attachment);
656 } // mailSuiteRunReport
660 $dateDropdown = reportDateDropdown ();
665 exportSuiteRun ($suiteid);
666 } elseif (isset ($testName)) {
667 exportStepRun ($testName, $runid, $date);
669 exportTestRuns ($day);
675 list ($pnbr, $username) = explode (":", $user);
677 if (isset ($suiteid)) {
678 $message = mailSuiteRunReport ($suiteid, $pnbr, $username);
679 displaySuiteRun ($suiteid, $message);
680 } elseif (isset ($testName)) {
681 $message = mailStepRunReport ($testName, $pnbr, $username);
682 displayStepRun ($testName, $message);
684 $message = mailTestRunsReport ($day, $pnbr, $username);
686 displayTestRuns ($day, $message);
692 if (isset ($suiteid)) {
693 displaySuiteRun ($suiteid);
694 } elseif (isset ($testName)) {
695 displayStepRun ($testName);
697 displayTestRuns ($day);