forked from Kitware/CDash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviewTest.php
496 lines (433 loc) · 14.2 KB
/
viewTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
<?php
/*=========================================================================
Program: CDash - Cross-Platform Dashboard System
Module: $Id$
Language: PHP
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
$noforcelogin = 1;
include("cdash/config.php");
require_once("cdash/pdo.php");
include('login.php');
include_once("cdash/common.php");
include("cdash/version.php");
require_once("filterdataFunctions.php");
include_once("models/build.php");
@$buildid = $_GET["buildid"];
if ($buildid != NULL)
{
$buildid = pdo_real_escape_numeric($buildid);
}
@$date = $_GET["date"];
if ($date != NULL)
{
$date = htmlspecialchars(pdo_real_escape_string($date));
}
// Checks
if(!isset($buildid) || !is_numeric($buildid))
{
echo "Not a valid buildid!";
return;
}
$start = microtime_float();
$db = pdo_connect("$CDASH_DB_HOST", "$CDASH_DB_LOGIN","$CDASH_DB_PASS");
pdo_select_db("$CDASH_DB_NAME",$db);
$build_array = pdo_fetch_array(pdo_query("SELECT * FROM build WHERE id='$buildid'"));
$projectid = $build_array["projectid"];
if(!isset($projectid) || $projectid==0)
{
echo "This build doesn't exist. Maybe it has been deleted.";
exit();
}
checkUserPolicy(@$_SESSION['cdash']['loginid'],$projectid);
$project = pdo_query("SELECT name,showtesttime,testtimemaxstatus,nightlytime,displaylabels FROM project WHERE id='$projectid'");
if(pdo_num_rows($project)>0)
{
$project_array = pdo_fetch_array($project);
$projectname = $project_array["name"];
$projectshowtesttime = $project_array["showtesttime"];
$testtimemaxstatus = $project_array["testtimemaxstatus"];
}
$siteid = $build_array["siteid"];
$buildtype = $build_array["type"];
$buildname = $build_array["name"];
$starttime = $build_array["starttime"];
$date = get_dashboard_date_from_build_starttime($starttime, $project_array["nightlytime"]);
$xml = begin_XML_for_XSLT();
$xml .= "<title>CDash : ".$projectname."</title>";
$xml .= get_cdash_dashboard_xml_by_name($projectname,$date);
// Menu
$xml .= "<menu>";
$onlypassed = 0;
$onlyfailed = 0;
$onlytimestatus = 0;
$onlynotrun = 0;
$onlydelta = 0;
$extraquery = "";
if(isset($_GET["onlypassed"]))
{
$onlypassed = 1;
$extraquery = "&onlypassed";
}
else if(isset($_GET["onlyfailed"]))
{
$onlyfailed = 1;
$extraquery = "&onlyfailed";
}
else if(isset($_GET["onlytimestatus"]))
{
$onlytimestatus = 1;
$extraquery = "&onlytimestatus";
}
else if(isset($_GET["onlynotrun"]))
{
$onlynotrun = 1;
$extraquery = "&onlynotrun";
}
else if(isset($_GET["onlydelta"])) // new test that are showing up for this category
{
$onlydelta = 1;
$extraquery = "&onlydelta";
}
$nightlytime = get_project_property($projectname,"nightlytime");
$xml .= add_XML_value("back","index.php?project=".urlencode($projectname)."&date=".get_dashboard_date_from_build_starttime($build_array["starttime"],$nightlytime));
$previousbuildid = get_previous_buildid($projectid,$siteid,$buildtype,$buildname,$starttime);
if($previousbuildid>0)
{
$xml .= add_XML_value("previous","viewTest.php?buildid=".$previousbuildid.$extraquery);
}
else
{
$xml .= add_XML_value("noprevious","1");
}
$xml .= add_XML_value("current","viewTest.php?buildid=".get_last_buildid($projectid,$siteid,$buildtype,$buildname,$starttime).$extraquery);
$nextbuildid = get_next_buildid($projectid,$siteid,$buildtype,$buildname,$starttime);
if($nextbuildid>0)
{
$xml .= add_XML_value("next","viewTest.php?buildid=".$nextbuildid.$extraquery);
}
else
{
$xml .= add_XML_value("nonext","1");
}
$xml .= "</menu>";
$site_array = pdo_fetch_array(pdo_query("SELECT name FROM site WHERE id='$siteid'"));
$xml .= "<build>\n";
$xml .= add_XML_value("displaylabels",$project_array["displaylabels"]);
$xml .= add_XML_value("site",$site_array["name"]);
$xml .= add_XML_value("siteid",$siteid);
$xml .= add_XML_value("buildname",$build_array["name"]);
$xml .= add_XML_value("buildid",$build_array["id"]);
$xml .= add_XML_value("testtime", $build_array["endtime"]);
// Find the OS and compiler information
$buildinformation = pdo_query("SELECT * FROM buildinformation WHERE buildid='$buildid'");
if(pdo_num_rows($buildinformation)>0)
{
$buildinformation_array = pdo_fetch_array($buildinformation);
if($buildinformation_array["osname"]!="")
{
$xml .= add_XML_value("osname",$buildinformation_array["osname"]);
}
if($buildinformation_array["osplatform"]!="")
{
$xml .= add_XML_value("osplatform",$buildinformation_array["osplatform"]);
}
if($buildinformation_array["osrelease"]!="")
{
$xml .= add_XML_value("osrelease",$buildinformation_array["osrelease"]);
}
if($buildinformation_array["osversion"]!="")
{
$xml .= add_XML_value("osversion",$buildinformation_array["osversion"]);
}
if($buildinformation_array["compilername"]!="")
{
$xml .= add_XML_value("compilername",$buildinformation_array["compilername"]);
}
if($buildinformation_array["compilerversion"]!="")
{
$xml .= add_XML_value("compilerversion",$buildinformation_array["compilerversion"]);
}
}
$xml .= "</build>\n";
$xml .= "<csvlink>".htmlspecialchars($_SERVER["REQUEST_URI"])."&export=csv</csvlink>";
$xml .= "<project>";
$xml .= add_XML_value("showtesttime", $projectshowtesttime);
$xml .= "</project>";
$displaydetails = 1;
$status = '';
$order = 't.name';
if($onlypassed)
{
$displaydetails = 0;
$status = "AND bt.status='passed'";
}
else if($onlyfailed)
{
$status = "AND bt.status='failed'";
}
else if($onlynotrun)
{
$displaydetails = 0;
$status = "AND bt.status='notrun'";
}
else if($onlytimestatus)
{
$status = "AND bt.timestatus>='$testtimemaxstatus'";
}
else
{
$order = 'bt.status,bt.timestatus DESC,t.name';
}
$xml .= add_XML_value("displaydetails", $displaydetails);
$xml .= add_XML_value("onlypassed", $onlypassed);
$xml .= add_XML_value("onlyfailed", $onlyfailed);
$xml .= add_XML_value("onlytimestatus", $onlytimestatus);
$xml .= add_XML_value("onlynotrun", $onlynotrun);
// Filters:
//
$filterdata = get_filterdata_from_request();
$filter_sql = $filterdata['sql'];
$limit_sql = '';
if ($filterdata['limit']>0)
{
$limit_sql = ' LIMIT '.$filterdata['limit'];
}
$xml .= $filterdata['xml'];
$limitnew = "";
$onlydelta_extra = "";
if($onlydelta)
{
$limitnew = " AND newstatus=1 ";
$onlydelta_extra = " AND build2test.newstatus=1 ";
}
$sql = "SELECT bt.status,bt.newstatus,bt.timestatus,t.id,bt.time,t.details,t.name " .
"FROM test as t,build2test as bt " .
"WHERE bt.buildid='$buildid' AND t.id=bt.testid " . $status . " " .
$filter_sql . " " .$limitnew.
"ORDER BY t.id" . $limit_sql;
$result = pdo_query($sql);
$numPassed = 0;
$numFailed = 0;
$numNotRun = 0;
$numTimeFailed = 0;
$columns = array();
$getcolumnnumber=pdo_query("SELECT testmeasurement.name, COUNT(DISTINCT test.name) as xxx FROM test
JOIN testmeasurement ON (test.id = testmeasurement.testid)
JOIN build2test ON (build2test.testid = test.id)
JOIN build ON (build.id = build2test.buildid)
JOIN measurement ON (test.projectid=measurement.projectid AND testmeasurement.name=measurement.name)
WHERE build.id='$buildid'
AND measurement.testpage=1
GROUP by testmeasurement.name
"); // We need to keep the count of columns for correct column-data assign
while($row=pdo_fetch_array($getcolumnnumber))
{
$xml .= add_XML_value("columnname",$row["name"])."\n";
$columns[]=$row["name"];
}
$columncount=pdo_num_rows($getcolumnnumber);
// If at least one column is selected
$extras = "";
if($onlypassed) $extras .= "AND build2test.status='passed'";
elseif($onlyfailed) $extras .= "AND build2test.status='failed'";
elseif($onlynotrun) $extras .= "AND build2test.status='notrun'";
$getalltestlistsql="SELECT test.id
FROM test
JOIN build2test ON (build2test.testid = test.id)
JOIN build ON (build.id = build2test.buildid)
WHERE build.id='$buildid' $onlydelta_extra
$extras
ORDER BY test.id
";
// Allocate empty array for all possible measurements
$tmpr = array();
$getalltestlist=pdo_query($getalltestlistsql);
while($row = pdo_fetch_array($getalltestlist))
{
for($i=0;$i<$columncount;$i++)
{
$tmpr[$row['id']][$columns[$i]]="";
}
}
$etestquery = NULL;
if($columncount>0)
{
$etestquery=pdo_query("SELECT test.id, test.projectid, build2test.buildid,
build2test.status, build2test.timestatus, test.name, testmeasurement.name,
testmeasurement.value, build.starttime,
build2test.time, measurement.testpage FROM test
JOIN testmeasurement ON (test.id = testmeasurement.testid)
JOIN build2test ON (build2test.testid = test.id)
JOIN build ON (build.id = build2test.buildid)
JOIN measurement ON (test.projectid=measurement.projectid AND testmeasurement.name=measurement.name)
WHERE build.id= '$buildid'
AND measurement.testpage=1 $onlydelta_extra
$extras
ORDER BY test.id, testmeasurement.name
");
}
if(@$_GET['export']=="csv") // If user wants to export as CSV file
{
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=testExport.csv"); // Prepare some headers to download
header("Content-Type: application/octet-stream;");
header("Content-Transfer-Encoding: binary");
$filecontent = "Name,Time,Details,Status,Time Status"; // Standard columns
// Store named measurements in an array
while($row = pdo_fetch_array($etestquery))
{
$etest[$row['id']][$row['name']]=$row['value'];
}
for($c=0;$c<count($columns);$c++)
{
$filecontent .= ",".$columns[$c]; // Add selected columns to the next
}
$filecontent .= "\n";
while($row = pdo_fetch_array($result))
{
$currentStatus = $row["status"];
$testName = $row["name"];
$filecontent .= "$testName,{$row["time"]},{$row["details"]},";
if($projectshowtesttime)
{
if($row["timestatus"] < $testtimemaxstatus)
{
$filecontent.="Passed,";
}
else
{
$filecontent.="Failed,";
}
} // end projectshowtesttime
switch($currentStatus)
{
case "passed":
$filecontent.="Passed,";
break;
case "failed":
$filecontent.="Failed,";
break;
case "notrun":
$filecontent.="Not Run,";
break;
}
// start writing test results
for($t=0;$t<count($columns);$t++) $filecontent .= $etest[$row['id']][$columns[$t]].",";
$filecontent .= "\n";
}
echo ($filecontent); // Start file download
die; // to suppress unwanted output
}
$xml .= "<etests>\n"; // Start creating etests for each column with matching buildid, testname and the value.
$i=0;
$currentcolumn=-1;
$prevtestid=0;
$checkarray = array();
// Overwrite the empty values with the correct ones if exists
while($etestquery && $row=pdo_fetch_array($etestquery))
{
$tmpr[$row['id']][$row['name']]=$row['value'];
}
// Write everything we have in the array
foreach ($tmpr as $testid => $testname) {
foreach ($testname as $val) {
$xml .="<etest>\n";
$xml .= add_XML_value("name",key($testname));
$xml .= add_XML_value("testid", $testid);
$xml .= add_XML_value("value", $val);
$xml .= "\n</etest>\n";
}
}
$xml .= "</etests>\n";
// Gather test info
$xml .= "<tests>\n";
// Find the time to run all the tests
$time_array = pdo_fetch_array(pdo_query("SELECT SUM(time) FROM build2test WHERE buildid='$buildid'"));
$time = $time_array[0];
$xml .= add_XML_value("totaltime", time_difference($time,true,'',true));
while($row = pdo_fetch_array($result))
{
$currentStatus = $row["status"];
$previousStatus;
$testName = $row["name"];
$xml .= "<test>\n";
$xml .= add_XML_value("name", $testName);
if($row["newstatus"])
{
$xml .= add_XML_value("new","1");
}
$xml .= add_XML_value("execTimeFull",$row["time"]);
$xml .= add_XML_value("execTime", time_difference($row["time"],true,'',true));
$xml .= add_XML_value("details", $row["details"]);
$testdate = get_dashboard_date_from_build_starttime($build_array["starttime"],$nightlytime);
$summaryLink = "testSummary.php?project=$projectid&name=".urlencode($testName)."&date=$testdate";
$xml .= add_XML_value("summaryLink", $summaryLink);
$testid = $row["id"];
$detailsLink = "testDetails.php?test=$testid&build=$buildid";
$xml .= add_XML_value("detailsLink", $detailsLink);
$xml .= add_XML_value("id", $testid);
if($projectshowtesttime)
{
if($row["timestatus"] < $testtimemaxstatus)
{
$xml .= add_XML_value("timestatus", "Passed");
$xml .= add_XML_value("timestatusclass", "normal");
}
else
{
$xml .= add_XML_value("timestatus", "Failed");
$xml .= add_XML_value("timestatusclass", "error");
}
} // end projectshowtesttime
switch($currentStatus)
{
case "passed":
$xml .= add_XML_value("status", "Passed");
$xml .= add_XML_value("statusclass", "normal");
$numPassed++;
break;
case "failed":
$xml .= add_XML_value("status", "Failed");
$xml .= add_XML_value("statusclass", "error");
$numFailed++;
break;
case "notrun":
$xml .= add_XML_value("status", "Not Run");
$xml .= add_XML_value("statusclass", "warning");
$numNotRun++;
break;
}
if($row["timestatus"] >= $testtimemaxstatus)
{
$numTimeFailed++;
}
$testid = $row['id'];
$xml .= get_labels_xml_from_query_results(
"SELECT text FROM label, label2test WHERE ".
"label.id=label2test.labelid AND ".
"label2test.testid='$testid' AND ".
"label2test.buildid='$buildid' ".
"ORDER BY text ASC"
);
$xml .= "</test>\n";
}
$xml .= "</tests>\n";
$xml .= add_XML_value("numPassed", $numPassed);
$xml .= add_XML_value("numFailed", $numFailed);
$xml .= add_XML_value("numNotRun", $numNotRun);
$xml .= add_XML_value("numTimeFailed", $numTimeFailed);
$end = microtime_float();
$xml .= "<generationtime>".round($end-$start,3)."</generationtime>";
$xml .= "<columncount>$columncount</columncount>";
$xml .= "</cdash>";
// Now doing the xslt transition
generate_XSLT($xml,"viewTest");
?>