2 ////////////////////////////////////////////////////////////////////////////////
6 // Description: PHP Module to access the rantest database
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 include_once ("Utils.php");
31 $userid = "pswitreader";
36 $sortBy = (empty ($_REQUEST["sortBy"])) ? "Start" : $_REQUEST["sortBy"];
37 $direction = (empty ($_REQUEST["direction"])) ? "descending" : $_REQUEST["direction"];
38 $day = (empty ($_REQUEST["day"])) ? date ("m/d/Y") : $_REQUEST["day"];
41 $na = "<font color=#999999>N/A</font>";
43 $failureTypes = array (
54 $nonFailures = array (
67 function dbError ($msg, $statement) {
68 $errno = mysql_errno ();
69 $errmsg = mysql_error ();
72 <h2><font color="red">ERROR:</font> $msg</h2>
73 <b>Error #$errno:</b><br>
74 <blockquote>$errmsg</blockquote>
75 <b>SQL Statement:</b><br>
76 <blockquote>$statement</blockquote>
88 $db = mysql_connect ($dbserver, $userid, $password)
89 or dbError (__FUNCTION__ . ": Unable to connect to database server $dbserver", "Connect");
91 mysql_select_db ($dbname)
92 or dbError (__FUNCTION__ . ": Unable to select the $dbname database", "$dbname");
98 $statement = "select start from testrun group by left (start, 10) order by start desc";
100 $result = mysql_query ($statement)
101 or dbError (__FUNCTION__ . ": Unable to execute query: ", $statement);
103 while ($row = mysql_fetch_array ($result)) {
104 array_push ($days, YMD2MDY ($row["start"]));
110 function setRowColor ($result) {
111 if ($result == "Success") {
112 return " class=success";
113 } elseif ($result == "Failure") {
114 return " class=failure";
115 } elseif ($result == "Timed out") {
116 return " class=timed_out";
117 } elseif ($result == "In progress" ||
118 $result == "Logging started") {
119 return " class=in_progress";
121 return " class=white";
125 function colorResult ($result) {
126 if ($result == "Success") {
127 return "<b><font color=green>$result</b></font>";
128 } elseif ($result == "Failure") {
129 return "<b><font color=red>$result</b></font>";
135 function sortPassed ($a, $b) {
138 return cmpNbr ($a, $b, "Passed", $direction);
141 function sortFailed ($a, $b) {
144 return cmpNbr ($a, $b, "Failed", $direction);
147 function sortSuccess ($a, $b) {
150 return cmpNbr ($a, $b, "Success", $direction);
153 function sortFailure ($a, $b) {
156 return cmpNbr ($a, $b, "Failure", $direction);
159 function sortTotal ($a, $b) {
162 return cmpNbr ($a, $b, "Total", $direction);
165 function sortSuite ($a, $b) {
168 return cmpStr ($a, $b, "Suite", $direction);
171 function sortStart ($a, $b) {
174 return cmpStr ($a, $b, "Start", $direction);
177 function sortDate ($a, $b) {
180 return cmpStr ($a, $b, "Start", $direction);
183 function sortEnd ($a, $b) {
186 return cmpStr ($a, $b, "End", $direction);
189 function sortTestcase ($a, $b) {
192 return cmpStr ($a, $b, "Testcase", $direction);
195 function sortType ($a, $b) {
198 return cmpStr ($a, $b, "Type", $direction);
201 function sortUnitVersion ($a, $b) {
204 return cmpStr ($a, $b, "Unit/Version", $direction);
207 function sortUnit ($a, $b) {
210 return cmpStr ($a, $b, "Unit", $direction);
213 function sortStatus ($a, $b) {
216 return cmpStr ($a, $b, "Status", $direction);
219 function sortDuration ($a, $b) {
222 return cmpNbr ($a, $b, "Duration", $direction);
225 function getName ($table, $id) {
226 $statement = "select name from $table where id=$id";
228 $result = mysql_query ($statement)
229 or dbError (__FUNCTION__ . ": Unable to execute query: ", $statement);
231 $row = mysql_fetch_array ($result);
236 function getTestNames () {
237 $statement = "select name from test order by name";
239 $result = mysql_query ($statement)
240 or dbError (__FUNCTION__ . ": Unable to execute query: ", $statement);
242 $names = array ("<All Tests>");
244 while ($row = mysql_fetch_array ($result)) {
245 array_push ($names, $row["name"]);
251 function getBuildNbr ($runid) {
254 $statement = "select name from version where type=\"ran_version\" and runid=$runid";
256 $result = mysql_query ($statement)
257 or dbError (__FUNCTION__ . ": Unable to execute query: ", $statement);
259 $row = mysql_fetch_array ($result);
261 if (isset ($row["name"])) {
262 $buildNbr = preg_replace ("/.*\-(\w+)/", "$1", $row["name"]);
269 function getVersion ($type, $runid) {
272 $statement = "select name from version where type=\"$type\" and runid=$runid";
274 $result = mysql_query ($statement)
275 or dbError (__FUNCTION__ . ": Unable to execute query: ", $statement);
277 $row = mysql_fetch_array ($result);
279 if (isset ($row["name"])) {
286 function getVersions ($type) {
287 $statement = "select name from version where type=\"$type\" group by name";
289 $result = mysql_query ($statement)
290 or dbError (__FUNCTION__ . ": Unable to execute query: ", $statement);
292 // $names = array ("<All Versions>");
295 while ($row = mysql_fetch_array ($result)) {
296 array_push ($names, $row["name"]);
302 function getTestVersions ($testcase) {
303 if (isset ($testcase)) {
304 $testcase = preg_replace ("/\*/", "%", $testcase);
305 $condition = "and test.name like \"$testcase\"";
312 testruns.runid as runid,
313 testrun.start as start,
315 testruns.unit as unit,
316 testruns.exectype as type,
317 test.name as testcase,
318 status.name as status,
319 testruns.eastlogs as eastlogs,
320 version.name as version
328 version.runid = testruns.runid and
329 test.id = testruns.tcid and
330 testrun.id = testruns.runid and
331 testruns.statusid = status.id and
332 version.type = "ran_version"
336 $result = mysql_query ($statement)
337 or DBError ("Unable to execute query: ", $statement);
341 while ($row = mysql_fetch_array ($result)) {
342 $line["Testcase"] = $row["testcase"];
343 $line["Start"] = $row["start"];
344 $line["Version"] = $row["version"];
345 $line["End"] = $row["end"];
346 $line["Unit"] = $row["unit"];
347 $line["Type"] = $row["type"];
348 $line["Status"] = $row["status"];
349 $line["Duration"] = strtotime ($row["end"]) - strtotime ($row["start"]);
350 $line["Version"] = $row["version"];
351 $line["_eastlogs"] = $row["eastlogs"];
352 $line["_runid"] = $row["runid"];
354 array_push ($data, $line);
360 function getLatestDate () {
361 $statement = "select left (start,10) as start from testrun order by start desc limit 0,1";
363 $result = mysql_query ($statement)
364 or dbError (__FUNCTION__ . ": Unable to execute query: ", $statement);
366 $row = mysql_fetch_array ($result);
368 return $row["start"];
371 function getEarliestDate () {
372 $statement = "select left (start,10) as start from testrun order by start limit 0,1";
374 $result = mysql_query ($statement)
375 or dbError (__FUNCTION__ . ": Unable to execute query: ", $statement);
377 $row = mysql_fetch_array ($result);
379 return $row["start"];
382 function reportDateDropdown () {
383 global $script, $day;
387 $dateDropdown .= "<select name=day class=inputfield onChange=\"ChangeDay(this.value,'$script');\">";
389 if (count ($days) < 2) {
391 } elseif (!isset ($day)) {
392 $day = date ("m/d/Y");
395 foreach ($days as $d) {
396 $dateDropdown .= "<option";
399 $dateDropdown .= " selected=\"selected\"";
402 $dateDropdown .= ">$d</option>";
405 $dateDropdown .= "</select>";
407 return $dateDropdown;
408 } // reportDateDropdown
410 function stats ($date = "", $type = "") {
412 $date = getLatestDate ();
414 $date = MDY2YMD ($date);
421 $typecond = ($type == "All") ? "" : "exectype = \"$type\" and";
426 status.name as result
432 left (start,10) = "$date" and
434 testrun.id = testruns.runid and
435 testruns.statusid = status.id
440 $result = mysql_query ($statement)
441 or dbError (__FUNCTION__ . ": Unable to execute query: ", $statement);
443 while ($row = mysql_fetch_array ($result)) {
444 if ($row["count"] == 0) {
445 $stats .= "No $row[result] ";
446 } elseif ($row["count"] == 1) {
447 $stats .= "1 $row[result] ";
449 if ($row["result"] == "Failure") {
450 $stats .= "$row[count] Failures ";
452 $stats .= "$row[count] Successes ";
460 function logs ($logs, $forEmail = false) {
463 if (file_exists ($logs)) {
467 // Chop off "/east/seast1"
468 $logs = substr ($logs, 12);
469 return "<a href=\"$logs\"><img border=0 src=\"/images/log.png\" height=20 title=\"Browse to logfiles\"></a>";
475 return "<img border=0 src=\"/icons/broken.png\" height=20 title=\"Unable to find log file for this test execution - Perhaps the logfiles have aged away\">";
481 function getStatus ($startDate, $endDate, $type = "") {
484 if (isset ($startDate)) {
485 $startDate = MDY2YMD ($startDate);
488 if (isset ($endDate)) {
489 $endDate = MDY2YMD ($endDate);
492 if (isset ($startDate) and isset ($endDate)) {
493 $dateCond = "and left (testrun.start, 10) >= \"$startDate\" " .
494 "and left (testruns.end, 10) <= \"$endDate\"" ;
495 } elseif ($startDate) {
496 $dateCond = "and left (testrun.start, 10) >= \"$startDate\"";
497 } elseif ($endDate) {
498 $dateCond = "and left (testruns.end, 10) <= \"$endDate\"";
503 if ($type != "" and $type != "All") {
504 $exectypeCond = "and testruns.exectype = \"$type\"";
509 status.name as status,
510 left (testrun.start,10) as date
517 test.id = testruns.tcid and
518 testrun.id = testruns.runid and
519 testruns.statusid = status.id
524 $result = mysql_query ($statement)
525 or dbError (__FUNCTION__ . ": Unable to execute query: ", $statement);
527 while ($row = mysql_fetch_array ($result)) {
528 if (empty ($status{$row["date"]}["Success"])) {
529 $status{$row["date"]}["Success"] = 0;
531 if (empty ($status{$row["date"]}["Failure"])) {
532 $status{$row["date"]}["Failure"] = 0;
534 $status{$row["date"]}{$row["status"]}++;
535 $status{$row["date"]}{Total}++;
538 // We used $row["date"] as the key so that we could do the totalling
539 // above but return an array with date inside it.
542 foreach ($status as $key => $value) {
543 $data["Date"] = $key;
544 $data["Success"] = $value["Success"];
545 $data["Failure"] = $value["Failure"];
546 $data["Total"] = $value["Total"];
548 array_push ($stats, $data);
554 function getStepFailures ($runid) {
555 global $failureTypes, $nonFailures;
560 status.name as status
566 steprun.stepid = step.id and
567 steprun.statusid = status.id and
573 $result = mysql_query ($statement)
574 or dbError (__FUNCTION__ . ": Unable to execute query: ", $statement);
576 $stepFailures = array ();
578 while ($row = mysql_fetch_array ($result)) {
579 // We only care about failures...
580 if (array_search ($row["status"], $nonFailures) !== false) {
584 $stepFailure["Step"] = $row["step"];
585 $stepFailure["Reason"] = $row["status"];
586 $stepFailure["Count"] = $row["count"];
588 array_push ($stepFailures, $stepFailure);
591 return $stepFailures;
594 function getFailures ($day) {
595 global $failureTypes;
597 $dateCond = "and left (testrun.start, 10) = \"" . MDY2YMD ($day) . "\"";
601 test.name as testcase,
602 testruns.unit as unit,
603 status.name as status,
604 testrun.start as timestamp,
605 testruns.runid as runid
612 test.id = testruns.tcid and
613 testrun.id = testruns.runid and
614 testruns.statusid = status.id
620 $result = mysql_query ($statement)
621 or dbError (__FUNCTION__ . ": Unable to execute query: ", $statement);
625 while ($row = mysql_fetch_array ($result)) {
626 // We only care about failures...
627 if ($row["status"] == "Success") {
633 $record["Testcase"] = $row["testcase"];
634 $record["Unit"] = $row["unit"];
635 $record["Time"] = substr ($row["timestamp"], 11, 8);
636 $record["_runid"] = $row["runid"];
637 $record["Failures"] = getStepFailures ($row["runid"]);
639 array_push ($data, $record);
645 function getTestHistory ($testcase) {
646 if (empty ($testcase)) {
649 $testcase = preg_replace ("/\*/", "%", $testcase);
652 if ($testcase != "%") {
655 testruns.runid as runid,
656 testrun.start as start,
658 testruns.unit as unit,
659 testruns.exectype as type,
660 test.name as testname,
661 status.name as status,
662 testruns.eastlogs as eastlogs
669 test.name like "$testcase" and
670 test.id = testruns.tcid and
671 testrun.id = testruns.runid and
672 testruns.statusid = status.id
677 test.name as testname,
678 status.name as status,
679 count(if(status.name="Success",1,NULL)) as passed,
680 count(if(status.name="Failure",1,NULL)) as failed,
687 test.id = testruns.tcid and
688 testruns.statusid = status.id
694 $result = mysql_query ($statement)
695 or DBError ("Unable to execute query: ", $statement);
699 while ($row = mysql_fetch_array ($result)) {
700 $line["Testcase"] = $row["testname"];
702 if ($testcase != "%") {
703 $line["DUT"] = $row["unit"];
704 $line["Type"] = $row["type"];
705 $line["Start"] = $row["start"];
706 $line["End"] = $row["end"];
707 $line["Duration"] = strtotime ($row["end"]) - strtotime ($row["start"]);
708 $line["_eastlogs"] = $row["eastlogs"];
709 $line["Status"] = $row["status"];
710 $line["_runid"] = $row["runid"];
712 array_push ($data, $line);
714 $line["Passed"] = $row["passed"];
715 $line["Failed"] = $row["failed"];
716 $line["Total"] = $row["total"];
717 $line["AvgRunTime"] = averageRunTime ($row["testname"]);
719 array_push ($data, $line);
726 function getTestcaseVersions ($version) {
727 if ($version == "<All Versions>") {
731 if (isset ($version)) {
732 $condition = "and version.name = \"$version\"";
739 testruns.runid as runid,
740 testrun.start as start,
742 testruns.unit as unit,
743 testruns.exectype as type,
744 test.name as testcase,
745 status.name as status,
746 version.name as version
754 version.runid = testruns.runid and
755 test.id = testruns.tcid and
756 testrun.id = testruns.runid and
757 testruns.statusid = status.id
761 $result = mysql_query ($statement)
762 or DBError ("Unable to execute query: ", $statement);
766 while ($row = mysql_fetch_array ($result)) {
767 $line["Testcase"] = $row["testcase"];
768 $line["Start"] = $row["start"];
769 $line["End"] = $row["end"];
770 $line["Unit"] = $row["unit"];
771 $line["Type"] = $row["type"];
772 $line["Status"] = $row["status"];
773 $line["Duration"] = strtotime ($row["end"]) - strtotime ($row["start"]);
774 $line["Version"] = $row["version"];
775 $line["_runid"] = $row["runid"];
777 array_push ($data, $line);
781 } // getTestcaseVersions
783 function averageRunTime ($name) {
786 testrun.start as start,
793 test.id = testruns.tcid and
794 testrun.id = testruns.runid and
798 $result = mysql_query ($statement)
799 or dbError (__FUNCTION__ . ": Unable to execute query: ", $statement);
803 while ($row = mysql_fetch_array ($result)) {
804 $duration = (strtotime ($row["end"]) - strtotime ($row["start"]));
810 return round ($total / $i);
813 function getSuiteruns ($id) {
814 global $sortBy, $direction;
818 status.name as Status,
829 $result = mysql_query ($statement)
830 or dbError (__FUNCTION__ . ": Unable to execute query: ", $statement);
834 while ($row = mysql_fetch_array ($result)) {
835 $line["Status"] = $row["Status"];
836 $line["Start"] = $row["Start"];
837 $line["End"] = $row["End"];
838 $line[Duration] = strtotime ($row["End"]) - strtotime ($row["Start"]);
840 array_push ($data, $line);
844 if ($sortBy == "Status") {
845 uasort ($data, "sortStatus");
846 } elseif ($sortBy == "End") {
847 uasort ($data, "sortEnd");
848 } elseif ($sortBy == "Duration") {
849 uasort ($data, "sortDuration");
851 uasort ($data, "sortStart");
857 function getTestSteps ($runid) {
858 $data["_header"]["DUTVersion"] = getVersion ("ran_version", $runid);
859 $data["_header"]["EASTVersion"] = getVersion ("east_version", $runid);
860 $data["_header"]["TM500Version"] = getVersion ("tm500_version", $runid);
861 $data["_header"]["NMSVersion"] = getVersion ("nms_version", $runid);
862 $data["_header"]["RANTESTVersion"] = getVersion ("rantest_version", $runid);
866 steprun.runid as _runid,
868 left (start, 10) as date,
871 status.name as status,
872 eastlogs as _eastlogs,
880 steprun.runid = $runid and
881 steprun.runid = testruns.runid and
882 step.id = steprun.stepid and
883 status.id = steprun.statusid
888 $result = mysql_query ($statement)
889 or dbError (__FUNCTION__ . ": Unable to execute query: ", $statement);
891 $data["_header"]["userid"] = "Unknown";
892 $data["_steps"] = array ();
894 while ($row = mysql_fetch_array ($result)) {
895 $line["Step"] = $row["step"];
896 $line["Status"] = $row["status"];
897 $data["_header"]["Date"] = $row["date"];
898 $line["Start"] = $row["start"];
899 $line["End"] = $row["end"];
900 $line["Duration"] = strtotime ($row["end"]) - strtotime ($row["start"]);
901 $data["_header"]["userid"] = $row["userid"];
902 $data["_header"]["_eastlogs"] = $row["_eastlogs"];
904 array_push ($data[_steps], $line);
910 function getTestRunTimestamp ($runid) {
913 left (start, 10) as startDate,
914 right (start, 8) as startTime
921 $result = mysql_query ($statement)
922 or dbError (__FUNCTION__ . ": Unable to execute query: ", $statement);
924 $row = mysql_fetch_array ($result);
926 return $row["startDate"] . "." . $row["startTime"];
927 } // getTestRunTimestamp
929 function getTestRuns ($day, $type, $export = false) {
930 global $sortBy, $direction;
932 $typecond = ($type == "All") ? "" : "exectype = \"$type\" and";
936 test.name as testcase,
937 status.name as status,
939 testrun.start as start,
940 testruns.runid as _runid,
942 testruns.unit as unit,
943 testruns.exectype as exectype,
944 testruns.eastlogs as _eastlogs,
945 testruns.suiteid as _suiteid
953 left (start, 10) = "$day" and
955 testruns.runid = testrun.id and
956 testruns.tcid = test.id and
957 statusid = status.id and
958 (suiteid = suite.id or
964 $result = mysql_query ($statement)
965 or dbError (__FUNCTION__ . ": Unable to execute query: ", $statement);
970 while ($row = mysql_fetch_array ($result)) {
975 $line["Suite"] = $row["suite"];
976 $line["Testcase"] = $row["testcase"];
977 $line["Type"] = $row["exectype"];
978 $line["Unit/Version"] = "$row[unit]-" . getBuildNbr ($row["_runid"]);
979 $line["Logs"] = (file_exists ($row["eastlogs"])) ? "yes" : "no";
980 $line["Status"] = $row["status"];
981 $line["Start"] = substr ($row["start"], 11);
982 $line["End"] = substr ($row["end"], 11);
983 $line["Duration"] = strtotime ($row["end"]) - strtotime ($row["start"]);
985 $line["_runid"] = $row["_runid"];
986 $line["_eastlogs"] = $row["_eastlogs"];
987 $line["_suiteid"] = $row["_suiteid"];
989 array_push ($data, $line);
993 if ($sortBy == "Suite") {
994 uasort ($data, "sortSuite");
995 } elseif ($sortBy == "Testcase") {
996 uasort ($data, "sortTestcase");
997 } elseif ($sortBy == "Type") {
998 uasort ($data, "sortType");
999 } elseif ($sortBy == "Unit") {
1000 uasort ($data, "sortUnitVersion");
1001 } elseif ($sortBy == "Status") {
1002 uasort ($data, "sortStatus");
1003 } elseif ($sortBy == "End") {
1004 uasort ($data, "sortEnd");
1005 } elseif ($sortBy == "Duration") {
1006 uasort ($data, "sortDuration");
1008 uasort ($data, "sortStart");