Initial add of defaria.com
[clearscm.git] / defaria.com / GD / Rantest / AverageRunTime.php
1 <?php
2 ////////////////////////////////////////////////////////////////////////////////
3 //
4 // File:        AverageRunTime.php
5 // Revision:    1.2
6 // Description: Produce a report of the average run time
7 // Author:      Andrew@ClearSCM.com
8 // Created:     Mon Apr 28 15:20:06 MST 2008
9 // Modified:    
10 // Language:    PHP
11 //
12 // (c) Copyright 2008, General Dynamics, all rights reserved.
13 //
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.
16 //
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
22 // 5230.25.
23 //
24 ////////////////////////////////////////////////////////////////////////////////
25 $script = basename ($_SERVER["PHP_SELF"]);
26 include_once "$_SERVER[DOCUMENT_ROOT]/php/Utils.php";
27 include_once "$_SERVER[DOCUMENT_ROOT]/php/RantestDB.php";
28
29 $build  = $_REQUEST["build"];
30 $level  = $_REQUEST["level"];
31 $DUT    = $_REQUEST["DUT"];
32 $test   = $_REQUEST["test"];
33
34 if (!isset ($test) or ($test == "")) {
35   $test = "%";
36 } // if
37
38 // Replace "*"'s with "%"'s
39 $build  = preg_replace ("/\*/", "%", $build);
40 $level  = preg_replace ("/\*/", "%", $level);
41 $DUT    = preg_replace ("/\*/", "%", $DUT);
42 $test   = preg_replace ("/\*/", "%", $test);
43
44 if ($build == "%" and
45     $level == "%" and
46     $DUT   == "%" and
47     $test  == "%") {
48   $testcase = "<All Tests>";
49 } else {
50   $testcase  = "${build}_${level}_${DUT}_${test}";
51 } // if
52
53 $testname2 = preg_replace ("/%/", "*", $testcase);
54 ?>
55 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
56    "http://www.w3.org/TR/html4/strict.dtd">
57 <html>
58 <head>
59   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
60   <link rel="stylesheet" type="text/css" media="screen" href="/css/Testing.css">
61   <link rel="stylesheet" type="text/css" media="screen" href="/css/Tables.css">
62   <title>Test history for <?php print ($testcase == "<All Tests>") ? "All Tests" : $testname2;?></title>
63
64 <body>
65
66 <h1 align="center">Test history for <?php print ($testcase == "<All Tests>") ? "All Tests" : $testname2;?></h1>
67
68 <?php
69   if ($testcase == "<All Tests>") {
70     print <<<END
71 <table align=center width=40%>
72   <thead>
73     <tr>
74       <th class=left>#</th>
75       <th>Test case</th>
76       <th>Passed</th>
77       <th>Failed</th>
78       <th class=right>Total</th>
79 END;
80   } else {
81     print <<<END
82 <table align=center>
83   <thead>
84     <tr>
85       <th class=left>#</th>
86       <th>Test case</th>
87       <th>Start</th>
88       <th>End</th>
89       <th>Logs</th>
90       <th class=right>Result</th> 
91 END;
92   } // if
93 ?>
94     </tr>
95   </thead>
96   <tbody>
97
98 <?php
99 OpenDB ();
100
101 $row_nbr = 0;
102
103 if ($testcase == "<All Tests>") {
104   $statement = <<<END
105 select
106   test.name             as testname,
107   count(*)              as count,
108   status.name           as status
109 from
110   testruns,
111   status,
112   test
113 where
114   test.id = testruns.tcid       and 
115   testruns.statusid = status.id
116 group by
117   testname,
118   status
119 END;
120
121   $result = mysql_query ($statement)
122     or DBError ("Unable to execute query: ", $statement);
123
124   $lastTestcase = "unknown";
125
126   $passed  = 0;
127   $failed  = 0;
128
129   while ($row = mysql_fetch_array ($result)) {
130     $logs = logs ($row["eastlogs"]);
131
132     if ($row["testcase"] == $lastTestcase) {
133       if ($row["status"] == "Success") {
134          $passed = $row["count"];
135       } else {
136          $failed = $row["count"];
137       } // if
138
139       $row_color = ($row_nbr++ % 2 == 0) ? " class=other" : "";
140
141       $total = $passed + $failed;
142
143       print <<<END
144         <tr $row_color>
145           <td align=center>$row_nbr</td>
146           <td><a href="$script?testcase=$row[testname]">$row[testname]</a></td>
147           <td align=right>$passed</td>
148           <td align=right>$failed</td>
149           <td align=right>$total</td>
150       </tr>
151 END;
152       $lastTestcase = "unknown";
153
154       $passed = 0;
155       $failed = 0;
156     } else {
157       $lastTestcase = $row["testcase"];
158
159       if ($row["status"] == "Success") {
160          $passed = $row["count"];
161       } else {
162          $failed = $row["count"];
163       } // if
164     } // if
165   } // while
166 } else {
167   $statement = <<<END
168 select
169   testruns.runid        as runid,
170   testrun.start         as start,
171   testruns.end          as end,
172   test.name             as testname,
173   status.name           as status,
174   testruns.eastlogs     as eastlogs
175 from
176   testrun,
177   testruns,
178   status,
179   test
180 where
181   test.name             like "$testcase"        and
182   test.id               = testruns.tcid         and
183   testrun.id            = testruns.runid        and
184   testruns.statusid     = status.id
185 order by
186   left(start,10) desc,
187   testname
188 END;
189
190   $result = mysql_query ($statement)
191     or DBError ("Unable to execute query: ", $statement);
192
193   while ($row = mysql_fetch_array ($result)) {
194     $class  = SetRowColor ($row["status"]);
195     $status = colorResult ($row["status"]);
196     $date   = YMD2MDY (substr ($row["start"], 0, 10));
197
198     $row_nbr++;
199     $logs = logs ($row["eastlogs"]);
200
201     print <<<END
202       <tr $class>
203         <td align=center>$row_nbr</td>
204         <td><a href="/rantest.php?testName=$row[testname]&runID=$row[runid]&date=$date">$row[testname]</a></td>
205         <td align=center>$row[start]</td>
206         <td align=center>$row[end]</td>
207         <td>$logs</td>
208         <td>$status</td>
209       </tr>
210 END;
211    } // while
212 }// if
213
214 print <<<END
215   </tbody>
216 </table>
217 END;
218
219 copyright ();
220 ?>
221 </body>
222 </html>
223