1<?php 2/*========================================================================= 3 4 Program: CDash - Cross-Platform Dashboard System 5 Module: $Id$ 6 Language: PHP 7 Date: $Date$ 8 Version: $Revision$ 9 10 Copyright (c) 2002 Kitware, Inc. All rights reserved. 11 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details. 12 13 This software is distributed WITHOUT ANY WARRANTY; without even 14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 15 PURPOSE. See the above copyright notices for more information. 16 17=========================================================================*/ 18 19/* 20* testSummary.php displays a list of all builds that performed a given test 21* on a specific day. It also displays information (success, execution time) 22* about each copy of the test that was run. 23*/ 24$noforcelogin = 1; 25include("cdash/config.php"); 26require_once("cdash/pdo.php"); 27include('login.php'); 28include_once("cdash/common.php"); 29include_once("cdash/repository.php"); 30include("cdash/version.php"); 31 32$date = htmlspecialchars(pdo_real_escape_string($_GET["date"])); 33if(!isset($date) || strlen($date)==0) 34 { 35 die('Error: no date supplied in query string'); 36 } 37$projectid = pdo_real_escape_numeric($_GET["project"]); 38if(!isset($projectid)) 39 { 40 die('Error: no project supplied in query string'); 41 } 42// Checks 43if(!isset($projectid) || !is_numeric($projectid)) 44 { 45 echo "Not a valid projectid!"; 46 return; 47 } 48 49$testName = htmlspecialchars(pdo_real_escape_string($_GET["name"])); 50if(!isset($testName)) 51 { 52 die('Error: no test name supplied in query string'); 53 } 54 55$start = microtime_float(); 56 57$db = pdo_connect("$CDASH_DB_HOST", "$CDASH_DB_LOGIN","$CDASH_DB_PASS"); 58pdo_select_db("$CDASH_DB_NAME",$db); 59$project = pdo_query("SELECT * FROM project WHERE id='$projectid'"); 60if(pdo_num_rows($project)>0) 61 { 62 $project_array = pdo_fetch_array($project); 63 $projectname = $project_array["name"]; 64 $nightlytime = $project_array["nightlytime"]; 65 $projectshowtesttime = $project_array["showtesttime"]; 66 } 67 68checkUserPolicy(@$_SESSION['cdash']['loginid'],$project_array["id"]); 69 70$xml = begin_XML_for_XSLT(); 71$xml .= "<title>CDash : ".$projectname."</title>"; 72 73$xml .= get_cdash_dashboard_xml_by_name($projectname,$date); 74$xml .= add_XML_value("testName",$testName); 75 76$xml .= "<menu>"; 77list ($previousdate, $currentstarttime, $nextdate,$today) = get_dates($date,$nightlytime); 78$xml .= add_XML_value("back","index.php?project=".urlencode($projectname)."&date=".$date); 79$xml .= add_XML_value("previous", "testSummary.php?project=$projectid&name=$testName&date=$previousdate"); 80$xml .= add_XML_value("current", "testSummary.php?project=$projectid&name=$testName&date=".date(FMT_DATE)); 81if($date!="" && date(FMT_DATE, $currentstarttime)!=date(FMT_DATE)) 82 { 83 $xml .= add_XML_value("next","testSummary.php?project=$projectid&name=$testName&date=$nextdate"); 84 } 85else 86 { 87 $xml .= add_XML_value("nonext","1"); 88 } 89$xml .= "</menu>"; 90$testName = pdo_real_escape_string($testName); 91list ($previousdate, $currentstarttime, $nextdate) = get_dates($date,$project_array["nightlytime"]); 92$beginning_timestamp = $currentstarttime; 93$end_timestamp = $currentstarttime+3600*24; 94 95$beginning_UTCDate = gmdate(FMT_DATETIME,$beginning_timestamp); 96$end_UTCDate = gmdate(FMT_DATETIME,$end_timestamp); 97 98$getcolumnnumber=pdo_query("SELECT testmeasurement.name, COUNT(DISTINCT test.name) as xxx FROM test 99JOIN testmeasurement ON (test.id = testmeasurement.testid) 100JOIN build2test ON (build2test.testid = test.id) 101JOIN build ON (build.id = build2test.buildid) 102JOIN measurement ON (test.projectid=measurement.projectid AND testmeasurement.name=measurement.name) 103WHERE test.name='$testName' 104AND build.starttime>='$beginning_UTCDate' 105AND build.starttime<'$end_UTCDate' 106AND test.projectid=$projectid 107AND measurement.summarypage= 1 108GROUP by testmeasurement.name 109"); // We need to keep the count of columns for correct column-data assign 110 111$columns = array(); 112while($row=pdo_fetch_array($getcolumnnumber)) 113 { 114 $xml .= add_XML_value("columnname",$row["name"])."\n"; 115 $columns[]=$row["name"]; 116 } 117 118$columncount=pdo_num_rows($getcolumnnumber); 119// If at least one column is selected 120if($columncount>0) 121 { 122 $etestquery=pdo_query("SELECT test.id, test.projectid, build2test.buildid, build2test.status, build2test.timestatus, test.name, 123 testmeasurement.name, testmeasurement.value, build.starttime, build2test.time, measurement.testpage FROM test 124 JOIN testmeasurement ON (test.id = testmeasurement.testid) 125 JOIN build2test ON (build2test.testid = test.id) 126 JOIN build ON (build.id = build2test.buildid) 127 JOIN measurement ON (test.projectid=measurement.projectid AND testmeasurement.name=measurement.name) 128 WHERE test.name='$testName' 129 AND build.starttime>='$beginning_UTCDate' 130 AND build.starttime<'$end_UTCDate' 131 AND test.projectid=$projectid 132 AND measurement.summarypage= 1 133 ORDER BY build2test.buildid, testmeasurement.name 134 "); 135 136 $xml .= "<etests>\n"; // Start creating etests for each column with matching buildid, testname and the value. 137 $i=0; 138 $currentcolumn=-1; 139 $prevtestid=0; 140 $checkarray = array(); 141 while($etestquery && $row=pdo_fetch_array($etestquery)) 142 { 143 if(!isset($checkarray[$row["name"]]) || !in_array($row["id"],$checkarray[$row["name"]])) 144 { 145 for($columnkey=0;$columnkey<$columncount;$columnkey++) 146 { 147 if($columns[$columnkey]==$row['name']) 148 { 149 $columnkey+=1; 150 break; 151 } 152 } 153 $currentcolumn=($currentcolumn+1)%$columncount; // Go to next column 154 if($currentcolumn==0) 155 { 156 $prevtestid=$row["id"]; 157 } 158 if($currentcolumn!=$columnkey-1) // If data does not belong to this column 159 { 160 for($t=0;$t<$columncount;$t++) 161 { 162 if(($currentcolumn+$t)%$columncount!=$columnkey-1) // Add blank values till you find the required column 163 { 164 $xml .="<etest>\n"; 165 $xml .= add_XML_value("name",""); 166 $xml .= add_XML_value("testid", $row["id"]); 167 $xml .= add_XML_value("buildid", $row["buildid"]); 168 $xml .= add_XML_value("value", ""); 169 $xml .= "\n</etest>\n"; 170 $prevtestid=$row["id"]; 171 } 172 else 173 { 174 $currentcolumn=($currentcolumn+$t)%$columncount; // Go to next column again 175 break; 176 } 177 } 178 // Add correct values to correct column 179 if($prevtestid==$row["id"] and $currentcolumn!=0) 180 { 181 $xml .="<etest>\n"; 182 $xml .= add_XML_value("name",$row["name"]); 183 $xml .= add_XML_value("testid", $row["id"]); 184 $xml .= add_XML_value("buildid", $row["buildid"]); 185 $xml .= add_XML_value("value", $row["value"]); 186 $xml .= "\n</etest>\n"; 187 $checkarray[$row["name"]][$i]=$row["id"]; 188 $prevtestid=$row["id"]; 189 } 190 else 191 { 192 if($prevtestid!=$row["id"] and $prevtestid!=0 and $currentcolumn!=0) 193 { 194 for($t=0;$t<$columncount;$t++) 195 { 196 $xml .="<etest>\n"; 197 $xml .= add_XML_value("name",""); 198 $xml .= add_XML_value("testid", ""); 199 $xml .= add_XML_value("buildid", ""); 200 $xml .= add_XML_value("rowcheck", "-"); 201 $xml .= "\n</etest>\n"; 202 } 203 } 204 205 $xml .="<etest>\n"; 206 $xml .= add_XML_value("name",$row["name"]); 207 $xml .= add_XML_value("testid", $row["id"]); 208 $xml .= add_XML_value("buildid", $row["buildid"]); 209 $xml .= add_XML_value("value", $row["value"]); 210 $xml .= "\n</etest>\n"; 211 $checkarray[$row["name"]][$i]=$row["id"]; 212 $prevtestid=$row["id"]; 213 } 214 215 } 216 else 217 { 218 if ($prevtestid!=$row["id"] and $prevtestid!=0 and $currentcolumn!=0) 219 { 220 for($t=0;$t<$columncount;$t++) 221 { 222 $xml .="<etest>\n"; 223 $xml .= add_XML_value("name",""); 224 $xml .= add_XML_value("testid", ""); 225 $xml .= add_XML_value("buildid", ""); 226 $xml .= add_XML_value("value", ""); 227 $xml .= "\n</etest>\n"; 228 } 229 230 231 } 232 // Add correct values to correct column 233 $xml .="<etest>\n"; 234 $xml .= add_XML_value("name",$row["name"]); 235 $xml .= add_XML_value("testid", $row["id"]); 236 $xml .= add_XML_value("buildid", $row["buildid"]); 237 $xml .= add_XML_value("value", $row["value"]); 238 $xml .= "\n</etest>\n"; 239 $checkarray[$row["name"]][$i]=$row["id"]; 240 $prevtestid=$row["id"]; 241 } 242 } 243 $i++; 244 } 245 $xml .= "</etests>\n"; 246 } 247//Get information about all the builds for the given date and project 248$xml .= "<builds>\n"; 249 250// Add the date/time 251$xml .= add_XML_value("projectid",$projectid); 252$xml .= add_XML_value("currentstarttime",$currentstarttime); 253$xml .= add_XML_value("teststarttime",date(FMT_DATETIME,$beginning_timestamp)); 254$xml .= add_XML_value("testendtime",date(FMT_DATETIME,$end_timestamp)); 255 256$columncount=pdo_num_rows($getcolumnnumber); 257// If at least one column is selected 258if($columncount>0) 259 { 260 $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 261 JOIN testmeasurement ON (test.id = testmeasurement.testid) 262 JOIN build2test ON (build2test.testid = test.id) 263 JOIN build ON (build.id = build2test.buildid) 264 JOIN measurements ON (test.projectid=measurement.projectid AND testmeasurement.name=measurement.name) 265 WHERE test.name='$testName' 266 AND build.starttime>='$beginning_UTCDate' 267 AND build.starttime<'$end_UTCDate' 268 AND test.projectid=$projectid 269 AND measurement.summarypage= 1 270 ORDER BY build2test.buildid, testmeasurement.name 271 "); 272 } 273 274$query = "SELECT build.id,build.name,build.stamp,build2test.status,build2test.buildid,build2test.time,build2test.testid AS testid,site.name AS sitename 275 FROM build 276 JOIN build2test ON (build.id = build2test.buildid) 277 JOIN site ON (build.siteid = site.id) 278 WHERE build.projectid = '$projectid' 279 AND build.starttime>='$beginning_UTCDate' 280 AND build.starttime<'$end_UTCDate' 281 AND build2test.testid IN (SELECT id FROM test WHERE name='$testName') 282 ORDER BY build2test.buildid"; 283 284$result = pdo_query($query); 285 286if(isset($_GET['export']) && $_GET['export']=="csv") // If user wants to export as CSV file 287 { 288 header("Cache-Control: public"); 289 header("Content-Description: File Transfer"); 290 header("Content-Disposition: attachment; filename=testExport.csv"); // Prepare some headers to download 291 header("Content-Type: application/octet-stream;"); 292 header("Content-Transfer-Encoding: binary"); 293 $filecontent = "Site,Build Name,Build Stamp,Status,Time(s)"; // Standard columns 294 295 // Store named measurements in an array 296 while(isset($etestquery) && $row = pdo_fetch_array($etestquery)) 297 { 298 $etest[$row['buildid']][$row['name']]=$row['value']; 299 } 300 301 for($c=0;$c<count($columns);$c++) { 302 $filecontent .= ",".$columns[$c]; // Add selected columns to the next 303 } 304 305 $filecontent .= "\n"; 306 307 while($row = pdo_fetch_array($result)) 308 { 309 $currentStatus = $row["status"]; 310 311 $filecontent .= "{$row["sitename"]},{$row["name"]},{$row["stamp"]},{$row["time"]},"; 312 313 if($projectshowtesttime) 314 { 315 if($row["timestatus"] < $testtimemaxstatus) 316 { 317 $filecontent.="Passed,"; 318 } 319 else 320 { 321 $filecontent.="Failed,"; 322 } 323 } // end projectshowtesttime 324 325 switch($currentStatus) 326 { 327 case "passed": 328 $filecontent.="Passed,"; 329 break; 330 case "failed": 331 $filecontent.="Failed,"; 332 break; 333 case "notrun": 334 $filecontent.="Not Run,"; 335 break; 336 } 337 // start writing test results 338 for($t=0;$t<count($columns);$t++) $filecontent .= $etest[$row['id']][$columns[$t]].","; 339 $filecontent .= "\n"; 340 } 341 echo ($filecontent); // Start file download 342 die; // to suppress unwanted output 343 } 344 345//now that we have the data we need, generate some XML 346while($row = pdo_fetch_array($result)) 347 { 348 $buildid = $row["id"]; 349 $xml .= "<build>\n"; 350 351 // Find the repository revision 352 $xml .= "<update>"; 353 // Return the status 354 $status_array = pdo_fetch_array(pdo_query("SELECT status,revision,priorrevision,path 355 FROM buildupdate,build2update AS b2u 356 WHERE b2u.updateid=buildupdate.id 357 AND b2u.buildid='$buildid'")); 358 if(strlen($status_array["status"]) > 0 && $status_array["status"]!="0") 359 { 360 $xml .= add_XML_value("status",$status_array["status"]); 361 } 362 else 363 { 364 $xml .= add_XML_value("status",""); // empty status 365 } 366 $xml .= add_XML_value("revision",$status_array["revision"]); 367 $xml .= add_XML_value("priorrevision",$status_array["priorrevision"]); 368 $xml .= add_XML_value("path",$status_array["path"]); 369 $xml .= add_XML_value("revisionurl", 370 get_revision_url($projectid, $status_array["revision"], $status_array["priorrevision"])); 371 $xml .= add_XML_value("revisiondiff", 372 get_revision_url($projectid, $status_array["priorrevision"], '')); // no prior prior revision... 373 $xml .= "</update>"; 374 375 $xml .= add_XML_value("site", $row["sitename"]); 376 $xml .= add_XML_value("buildName", $row["name"]); 377 $xml .= add_XML_value("buildStamp", $row["stamp"]); 378 $xml .= add_XML_value("time", $row["time"]); 379 380//$xml .= add_XML_value("details", $row["details"]) . "\n"; 381 382 $buildLink = "viewTest.php?buildid=$buildid"; 383 $xml .= add_XML_value("buildid", $buildid); 384 $xml .= add_XML_value("buildLink", $buildLink); 385 $testid = $row["testid"]; 386 $testLink = "testDetails.php?test=$testid&build=$buildid"; 387 $xml .= add_XML_value("testLink", $testLink); 388 switch($row["status"]) 389 { 390 case "passed": 391 $xml .= add_XML_value("status", "Passed"); 392 $xml .= add_XML_value("statusclass", "normal"); 393 break; 394 case "failed": 395 $xml .= add_XML_value("status", "Failed"); 396 $xml .= add_XML_value("statusclass", "error"); 397 break; 398 case "notrun": 399 $xml .= add_XML_value("status", "Not Run"); 400 $xml .= add_XML_value("statusclass", "warning"); 401 break; 402 } 403 $xml .= "</build>\n"; 404 } 405$xml .= "</builds>\n"; 406$xml .= "<csvlink>".htmlspecialchars($_SERVER["REQUEST_URI"])."&export=csv</csvlink>"; 407$end = microtime_float(); 408$xml .= "<generationtime>".round($end-$start,3)."</generationtime>"; 409$count=count($columns); 410$xml .= "<columncount>$count</columncount>"; 411$xml .= "</cdash>\n"; 412// Now doing the xslt transition 413generate_XSLT($xml,"testSummary"); 414?> 415