-
Notifications
You must be signed in to change notification settings - Fork 75
/
testDetails.php
341 lines (301 loc) · 11.1 KB
/
testDetails.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
<?php
/*=========================================================================
Program: CDash - Cross-Platform Dashboard System
Module: $Id$
Language: PHP
Date: $Date$
Version: $Revision$
Copyright (c) Kitware, Inc. All rights reserved.
See LICENSE or http://www.cdash.org/licensing/ 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.
=========================================================================*/
/*
* testDetails.php shows more detailed information for a particular test that
* was run. This includes test output and image comparison information
*/
include dirname(dirname(dirname(__DIR__))) . '/config/config.php';
require_once 'include/pdo.php';
require_once 'include/api_common.php';
include_once 'include/repository.php';
include 'include/version.php';
use CDash\Model\Build;
use CDash\Model\Project;
use CDash\Model\Site;
use CDash\Database;
$start = microtime_float();
$_REQUEST['buildid'] = $_GET['build'];
$build = get_request_build();
$testid = pdo_real_escape_numeric($_GET['test']);
// Checks
if (!isset($testid) || !is_numeric($testid)) {
json_error_response(['error' => 'A valid test was not specified.']);
}
$projectid = $build->ProjectId;
if (!$projectid) {
json_error_response(['error' => 'This build does not exist.']);
}
if (!can_access_project($projectid)) {
return;
}
$pdo = Database::getInstance()->getPdo();
$response = begin_JSON_response();
$response['title'] = 'CDash : Test Details';
// If we have a fileid we download it.
if (isset($_GET['fileid']) && is_numeric($_GET['fileid'])) {
$stmt = $pdo->prepare(
"SELECT id, value, name FROM testmeasurement
WHERE testid = :testid AND type = 'file'
ORDER BY id");
pdo_execute($stmt, [':testid' => $testid]);
for ($i = 0; $i < $_GET['fileid']; $i++) {
$result_array = $stmt->fetch();
}
header('Content-type: tar/gzip');
header('Content-Disposition: attachment; filename="' . $result_array['name'] . '.tgz"');
if ($CDASH_DB_TYPE == 'pgsql') {
$buf = '';
while (!feof($result_array['value'])) {
$buf .= fread($result_array['value'], 2048);
}
$buf = stripslashes($buf);
} else {
$buf = $result_array['value'];
}
echo base64_decode($buf);
flush();
return;
}
$project = new Project();
$project->Id = $projectid;
$project->Fill();
$site = new Site();
$site->Id = $build->SiteId;
$site->Fill();
$date = get_dashboard_date_from_build_starttime($build->StartTime, $project->NightlyTime);
list($previousdate, $currenttime, $nextdate) = get_dates($date, $project->NightlyTime);
$logoid = getLogoID($projectid);
$response['title'] = "CDash : $project->Name";
get_dashboard_JSON_by_name($project->Name, $date, $response);
$project_response = [];
$project_response['showtesttime'] = $project->ShowTestTime;
$response['project'] = $project_response;
$stmt = $pdo->prepare(
'SELECT * FROM build2test b2t
JOIN test t ON t.id = b2t.testid
WHERE b2t.testid = :testid AND b2t.buildid = :buildid');
pdo_execute($stmt, [':testid' => $testid, ':buildid' => $build->Id]);
$testRow = $stmt->fetch();
$testName = $testRow['name'];
// Helper function
function findTest($buildid, $testName, $pdo)
{
$stmt = $pdo->prepare(
'SELECT build2test.testid FROM build2test
WHERE build2test.buildid = :buildid
AND build2test.testid IN
(SELECT id FROM test WHERE name = :testname)');
pdo_execute($stmt, [':buildid' => $buildid, ':testname' => $testName]);
$testid = $stmt->fetchColumn();
if ($testid === false) {
return 0;
}
return $testid;
}
$menu = [];
$menu['back'] = "viewTest.php?buildid=$build->Id";
$previous_buildid = $build->GetPreviousBuildId();
$current_buildid = $build->GetCurrentBuildId();
$next_buildid = $build->GetNextBuildId();
// Did the user request a specific chart?
// If so we should make that chart appear when they click next or previous.
$extra_url = '';
if (array_key_exists('graph', $_GET)) {
$extra_url = "&graph=" . $_GET['graph'];
}
// Previous build
if ($previous_buildid > 0) {
$previous_testid = findTest($previous_buildid, $testName, $pdo);
if ($previous_testid) {
$menu['previous'] = "testDetails.php?test=$previous_testid&build=$previous_buildid$extra_url";
}
} else {
$menu['noprevious'] = '1';
}
// Current build
if ($current_testid = findTest($current_buildid, $testName, $pdo)) {
$menu['current'] = "testDetails.php?test=$current_testid&build=$current_buildid$extra_url";
}
// Next build
if ($next_buildid > 0) {
if ($next_testid = findTest($next_buildid, $testName, $pdo)) {
$menu['next'] = "testDetails.php?test=$next_testid&build=$next_buildid$extra_url";
}
} else {
$menu['nonext'] = '1';
}
$response['menu'] = $menu;
$summaryLink = "testSummary.php?project=$projectid&name=$testName&date=$date";
$test_response = [];
$test_response['id'] = $testid;
$test_response['buildid'] = $build->Id;
$test_response['build'] = $build->Name;
$test_response['buildstarttime'] = date(FMT_DATETIMESTD, strtotime($build->StartTime . ' UTC'));
$test_response['site'] = $site->Name;
$test_response['siteid'] = $site->Id;
$test_response['test'] = $testName;
$test_response['time'] = time_difference($testRow['time'], true, '', true);
$test_response['command'] = $testRow['command'];
$test_response['details'] = $testRow['details'];
// Helper function to remove bad characters for XML parser
function utf8_for_xml($string)
{
return preg_replace('/[^\x{0009}\x{000a}\x{000d}\x{001b}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u', ' ', $string);
}
if ($CDASH_USE_COMPRESSION) {
if ($CDASH_DB_TYPE == 'pgsql') {
if (is_resource($testRow['output'])) {
$testRow['output'] = base64_decode(stream_get_contents($testRow['output']));
} else {
$testRow['output'] = base64_decode($testRow['output']);
}
}
@$uncompressedrow = gzuncompress($testRow['output']);
if ($uncompressedrow !== false) {
$test_response['output'] = utf8_for_xml($uncompressedrow);
} else {
$test_response['output'] = utf8_for_xml($testRow['output']);
}
} else {
$test_response['output'] = utf8_for_xml($testRow['output']);
}
$test_response['summaryLink'] = $summaryLink;
switch ($testRow['status']) {
case 'passed':
$test_response['status'] = 'Passed';
$test_response['statusColor'] = 'normal-text';
break;
case 'failed':
$test_response['status'] = 'Failed';
$test_response['statusColor'] = 'error-text';
break;
case 'notrun':
$test_response['status'] = 'Not Run';
$test_response['statusColor'] = 'warning-text';
break;
}
// Find the repository revision.
$update_response = [];
$stmt = $pdo->prepare(
'SELECT status, revision, priorrevision, path
FROM buildupdate bu
JOIN build2update b2u ON (b2u.updateid = bu.id)
WHERE b2u.buildid = :buildid');
pdo_execute($stmt, [':buildid' => $build->Id]);
$status_array = $stmt->fetch();
if (strlen($status_array['status']) > 0 && $status_array['status'] != '0') {
$update_response['status'] = $status_array['status'];
} else {
$update_response['status'] = ''; // empty status
}
$update_response['revision'] = $status_array['revision'];
$update_response['priorrevision'] = $status_array['priorrevision'];
$update_response['path'] = $status_array['path'];
$update_response['revisionurl'] =
get_revision_url($projectid, $status_array['revision'], $status_array['priorrevision']);
$update_response['revisiondiff'] =
get_revision_url($projectid, $status_array['priorrevision'], ''); // no prior revision...
$test_response['update'] = $update_response;
$test_response['timemean'] = $testRow['timemean'];
$test_response['timestd'] = $testRow['timestd'];
$testtimemaxstatus = $project->TestTimeMaxStatus;
if ($testRow['timestatus'] == 0) {
$test_response['timestatus'] = 'Passed';
$test_response['timeStatusColor'] = 'normal-text';
} else {
$threshold = $test_response['timemean'] +
$project->TestTimeStd * $test_response['timestd'];
$test_response['threshold'] = time_difference($threshold, true, '', true);
if ($testRow['timestatus'] >= $testtimemaxstatus) {
$test_response['timestatus'] = 'Failed';
$test_response['timeStatusColor'] = 'error-text';
} else {
$test_response['timestatus'] = 'Warning';
$test_response['timeStatusColor'] = 'warning-text';
}
}
// Get any images associated with this test.
$compareimages_response = [];
$stmt = $pdo->prepare(
"SELECT imgid, role FROM test2image
WHERE testid = :testid AND
(role = 'TestImage' OR role = 'ValidImage' OR role = 'BaselineImage' OR
role ='DifferenceImage2')
ORDER BY id");
pdo_execute($stmt, [':testid' => $testid]);
while ($row = $stmt->fetch()) {
$image_response = [];
$image_response['imgid'] = $row['imgid'];
$image_response['role'] = $row['role'];
$compareimages_response[] = $image_response;
}
if (!empty($compareimages_response)) {
$test_response['compareimages'] = $compareimages_response;
}
$images_response = [];
$stmt = $pdo->prepare(
"SELECT imgid, role FROM test2image
WHERE testid = :testid AND
role != 'ValidImage' AND role != 'BaselineImage' AND
role != 'DifferenceImage2'
ORDER BY id");
pdo_execute($stmt, [':testid' => $testid]);
while ($row = $stmt->fetch()) {
$image_response = [];
$image_response['imgid'] = $row['imgid'];
$image_response['role'] = $row['role'];
$images_response[] = $image_response;
}
if (!empty($images_response)) {
$test_response['images'] = $images_response;
}
// Get any measurements associated with this test.
$measurements_response = [];
$stmt = $pdo->prepare(
'SELECT name, type, value FROM testmeasurement
WHERE testid = :testid
ORDER BY id');
pdo_execute($stmt, [':testid' => $testid]);
$fileid = 1;
while ($row = $stmt->fetch()) {
$measurement_response = [];
$measurement_response['name'] = $row['name'];
$measurement_response['type'] = $row['type'];
// ctest base64 encode the type text/plain...
$value = $row['value'];
if ($row['type'] == 'text/plain') {
if (substr($value, strlen($value) - 2) == '==') {
$value = base64_decode($value);
}
} elseif ($row['type'] == 'file') {
$measurement_response['fileid'] = $fileid++;
}
// Add nl2br for type text/plain and text/string
if ($row['type'] == 'text/plain' || $row['type'] == 'text/string') {
$value = nl2br($value);
}
// If the type is a file we just don't pass the text (too big) to the output
if ($row['type'] == 'file') {
$value = '';
}
$measurement_response['value'] = $value;
$measurements_response[] = $measurement_response;
}
if (!empty($measurements_response)) {
$test_response['measurements'] = $measurements_response;
}
$response['test'] = $test_response;
$end = microtime_float();
$response['generationtime'] = round($end - $start, 3);
echo json_encode($response);