blob: 8901e16ebb9c1f273e0d94366a722f7f1fc2cdad [file] [log] [blame]
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001// Copyright (C) 2012 Google Inc. All rights reserved.
2//
3// Redistribution and use in source and binary forms, with or without
4// modification, are permitted provided that the following conditions are
5// met:
6//
7// * Redistributions of source code must retain the above copyright
8// notice, this list of conditions and the following disclaimer.
9// * Redistributions in binary form must reproduce the above
10// copyright notice, this list of conditions and the following disclaimer
11// in the documentation and/or other materials provided with the
12// distribution.
13// * Neither the name of Google Inc. nor the names of its
14// contributors may be used to endorse or promote products derived from
15// this software without specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29//////////////////////////////////////////////////////////////////////////////
30// CONSTANTS
31//////////////////////////////////////////////////////////////////////////////
32var ALL = 'ALL';
33var FORWARD = 'forward';
34var BACKWARD = 'backward';
35var GTEST_MODIFIERS = ['FLAKY', 'FAILS', 'MAYBE', 'DISABLED'];
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010036var TEST_URL_BASE_PATH_IN_VERSION_CONTROL = 'http://src.chromium.org/viewvc/blink/trunk/LayoutTests/';
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +000037var TEST_URL_BASE_PATH = "http://svn.webkit.org/repository/webkit/trunk/LayoutTests/";
38var EXPECTATIONS_URL_BASE_PATH = TEST_URL_BASE_PATH + "platform/";
39var TEST_RESULTS_BASE_PATH = 'http://build.chromium.org/f/chromium/layout_test_results/';
40var GPU_RESULTS_BASE_PATH = 'http://chromium-browser-gpu-tests.commondatastorage.googleapis.com/runs/'
41
42var PLATFORMS = {
43 'CHROMIUM': {
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010044 expectationsDirectory: null, /* FIXME: cleanup post blink split 'chromium', */
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +000045 subPlatforms: {
46 'LION': { fallbackPlatforms: ['CHROMIUM'] },
47 'SNOWLEOPARD': { fallbackPlatforms: ['CHROMIUM'] },
48 'XP': { fallbackPlatforms: ['CHROMIUM'] },
49 'VISTA': { fallbackPlatforms: ['CHROMIUM'] },
50 'WIN7': { fallbackPlatforms: ['CHROMIUM'] },
51 'LUCID': { fallbackPlatforms: ['CHROMIUM'] },
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010052 'ANDROID': { fallbackPlatforms: ['CHROMIUM'], expectationsDirectory: null /* 'chromium-android' */ }
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +000053 },
54 platformModifierUnions: {
55 'MAC': ['CHROMIUM_LION', 'CHROMIUM_SNOWLEOPARD'],
56 'WIN': ['CHROMIUM_XP', 'CHROMIUM_VISTA', 'CHROMIUM_WIN7'],
57 'LINUX': ['CHROMIUM_LUCID']
58 }
59 },
60 'APPLE': {
61 subPlatforms: {
62 'MAC': {
63 expectationsDirectory: 'mac',
64 subPlatforms: {
65 'LION': {
66 expectationsDirectory: 'mac-lion',
67 subPlatforms: {
68 'WK1': { fallbackPlatforms: ['APPLE_MAC_LION', 'APPLE_MAC'] },
69 'WK2': { fallbackPlatforms: ['APPLE_MAC_LION', 'APPLE_MAC', 'WK2'] }
70 }
71 },
72 'SNOWLEOPARD': {
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010073 expectationsDirectory: null,
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +000074 subPlatforms: {
75 'WK1': { fallbackPlatforms: ['APPLE_MAC_SNOWLEOPARD', 'APPLE_MAC'] },
76 'WK2': { fallbackPlatforms: ['APPLE_MAC_SNOWLEOPARD', 'APPLE_MAC', 'WK2'] }
77 }
78 }
79 }
80 },
81 'WIN': {
82 expectationsDirectory: 'win',
83 subPlatforms: {
84 'XP': { fallbackPlatforms: ['APPLE_WIN'] },
85 'WIN7': { fallbackPlatforms: ['APPLE_WIN'] }
86 }
87 }
88 }
89 },
90 'GTK': {
91 expectationsDirectory: 'gtk',
92 subPlatforms: {
93 'LINUX': {
94 subPlatforms: {
95 'WK1': { fallbackPlatforms: ['GTK'] },
96 'WK2': { fallbackPlatforms: ['GTK', 'WK2'], expectationsDirectory: 'gtk-wk2' }
97 }
98 }
99 }
100 },
101 'QT': {
102 expectationsDirectory: 'qt',
103 subPlatforms: {
104 'LINUX': { fallbackPlatforms: ['QT'] }
105 }
106 },
107 'EFL': {
108 expectationsDirectory: 'efl',
109 subPlatforms: {
110 'LINUX': {
111 subPlatforms: {
112 'WK1': { fallbackPlatforms: ['EFL'], expectationsDirectory: 'efl-wk1' },
113 'WK2': { fallbackPlatforms: ['EFL', 'WK2'], expectationsDirectory: 'efl-wk2' }
114 }
115 }
116 }
117 },
118 'WK2': {
119 basePlatform: true,
120 expectationsDirectory: 'wk2'
121 }
122};
123
124var BUILD_TYPES = {'DEBUG': 'DBG', 'RELEASE': 'RELEASE'};
125var MIN_SECONDS_FOR_SLOW_TEST = 4;
126var MIN_SECONDS_FOR_SLOW_TEST_DEBUG = 2 * MIN_SECONDS_FOR_SLOW_TEST;
127var FAIL_RESULTS = ['IMAGE', 'IMAGE+TEXT', 'TEXT', 'MISSING'];
128var CHUNK_SIZE = 25;
129var MAX_RESULTS = 1500;
130
131// FIXME: Figure out how to make this not be hard-coded.
132var VIRTUAL_SUITES = {
133 'platform/chromium/virtual/gpu/fast/canvas': 'fast/canvas',
134 'platform/chromium/virtual/gpu/canvas/philip': 'canvas/philip'
135};
136
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000137var resourceLoader;
138
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100139function generatePage(historyInstance)
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000140{
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100141 if (historyInstance.crossDashboardState.useTestData)
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000142 return;
143
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000144 document.body.innerHTML = '<div id="loading-ui">LOADING...</div>';
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000145 resourceLoader.showErrors();
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000146
147 // tests expands to all tests that match the CSV list.
148 // result expands to all tests that ever have the given result
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100149 if (historyInstance.dashboardSpecificState.tests || historyInstance.dashboardSpecificState.result)
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000150 generatePageForIndividualTests(individualTests());
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100151 else if (historyInstance.dashboardSpecificState.expectationsUpdate)
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000152 generatePageForExpectationsUpdate();
153 else
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100154 generatePageForBuilder(historyInstance.dashboardSpecificState.builder || currentBuilderGroup().defaultBuilder());
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000155
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000156 for (var builder in currentBuilders())
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000157 processTestResultsForBuilderAsync(builder);
158
159 postHeightChangedMessage();
160}
161
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100162function handleValidHashParameter(historyInstance, key, value)
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000163{
164 switch(key) {
165 case 'tests':
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100166 history.validateParameter(historyInstance.dashboardSpecificState, key, value,
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000167 function() {
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000168 return string.isValidName(value);
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000169 });
170 return true;
171
172 case 'result':
173 value = value.toUpperCase();
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100174 history.validateParameter(historyInstance.dashboardSpecificState, key, value,
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000175 function() {
176 for (var result in LAYOUT_TEST_EXPECTATIONS_MAP_) {
177 if (value == LAYOUT_TEST_EXPECTATIONS_MAP_[result])
178 return true;
179 }
180 return false;
181 });
182 return true;
183
184 case 'builder':
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100185 history.validateParameter(historyInstance.dashboardSpecificState, key, value,
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000186 function() {
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000187 return value in currentBuilders();
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000188 });
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000189
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000190 return true;
191
192 case 'sortColumn':
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100193 history.validateParameter(historyInstance.dashboardSpecificState, key, value,
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000194 function() {
195 // Get all possible headers since the actual used set of headers
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100196 // depends on the values in historyInstance.dashboardSpecificState, which are currently being set.
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000197 var headers = tableHeaders(true);
198 for (var i = 0; i < headers.length; i++) {
199 if (value == sortColumnFromTableHeader(headers[i]))
200 return true;
201 }
202 return value == 'test' || value == 'builder';
203 });
204 return true;
205
206 case 'sortOrder':
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100207 history.validateParameter(historyInstance.dashboardSpecificState, key, value,
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000208 function() {
209 return value == FORWARD || value == BACKWARD;
210 });
211 return true;
212
213 case 'resultsHeight':
214 case 'updateIndex':
215 case 'revision':
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100216 history.validateParameter(historyInstance.dashboardSpecificState, key, Number(value),
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000217 function() {
218 return value.match(/^\d+$/);
219 });
220 return true;
221
222 case 'showChrome':
223 case 'showCorrectExpectations':
224 case 'showWrongExpectations':
225 case 'showExpectations':
226 case 'showFlaky':
227 case 'showLargeExpectations':
228 case 'legacyExpectationsSemantics':
229 case 'showSkipped':
230 case 'showSlow':
231 case 'showUnexpectedPasses':
232 case 'showWontFixSkip':
233 case 'expectationsUpdate':
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100234 historyInstance.dashboardSpecificState[key] = value == 'true';
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000235 return true;
236
237 default:
238 return false;
239 }
240}
241
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100242// @param {Object} params New or modified query parameters as key: value.
243function handleQueryParameterChange(historyInstance, params)
244{
245 for (key in params) {
246 if (key == 'tests') {
247 // Entering cross-builder view, only keep valid keys for that view.
248 for (var currentKey in historyInstance.dashboardSpecificState) {
249 if (isInvalidKeyForCrossBuilderView(currentKey)) {
250 delete historyInstance.dashboardSpecificState[currentKey];
251 }
252 }
253 } else if (isInvalidKeyForCrossBuilderView(key)) {
254 delete historyInstance.dashboardSpecificState.tests;
255 delete historyInstance.dashboardSpecificState.result;
256 }
257 }
258
259 return true;
260}
261
262var defaultDashboardSpecificStateValues = {
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000263 sortOrder: BACKWARD,
264 sortColumn: 'flakiness',
265 showExpectations: false,
266 showFlaky: true,
267 showLargeExpectations: false,
268 legacyExpectationsSemantics: true,
269 showChrome: true,
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100270 showCorrectExpectations: false,
271 showWrongExpectations: false,
272 showWontFixSkip: false,
273 showSlow: false,
274 showSkipped: false,
275 showUnexpectedPasses: false,
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000276 expectationsUpdate: false,
277 updateIndex: 0,
278 resultsHeight: 300,
279 revision: null,
280 tests: '',
281 result: '',
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000282 builder: null
283};
284
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100285var DB_SPECIFIC_INVALIDATING_PARAMETERS = {
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000286 'tests' : 'builder',
287 'testType': 'builder',
288 'group': 'builder'
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000289};
290
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100291
292var flakinessConfig = {
293 defaultStateValues: defaultDashboardSpecificStateValues,
294 generatePage: generatePage,
295 handleValidHashParameter: handleValidHashParameter,
296 handleQueryParameterChange: handleQueryParameterChange,
297 invalidatingHashParameters: DB_SPECIFIC_INVALIDATING_PARAMETERS
298};
299
300// FIXME(jparent): Eventually remove all usage of global history object.
301var g_history = new history.History(flakinessConfig);
302g_history.parseCrossDashboardParameters();
303
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000304//////////////////////////////////////////////////////////////////////////////
305// GLOBALS
306//////////////////////////////////////////////////////////////////////////////
307
308var g_perBuilderPlatformAndBuildType = {};
309var g_perBuilderFailures = {};
310// Map of builder to arrays of tests that are listed in the expectations file
311// but have for that builder.
312var g_perBuilderWithExpectationsButNoFailures = {};
313// Map of builder to arrays of paths that are skipped. This shows the raw
314// path used in TestExpectations rather than the test path since we
315// don't actually have any data here for skipped tests.
316var g_perBuilderSkippedPaths = {};
317// Maps test path to an array of {builder, testResults} objects.
318var g_testToResultsMap = {};
319// Tests that the user wants to update expectations for.
320var g_confirmedTests = {};
321
322function traversePlatformsTree(callback)
323{
324 function traverse(platformObject, parentPlatform) {
325 Object.keys(platformObject).forEach(function(platformName) {
326 var platform = platformObject[platformName];
327 platformName = parentPlatform ? parentPlatform + platformName : platformName;
328
329 if (platform.subPlatforms)
330 traverse(platform.subPlatforms, platformName + '_');
331 else if (!platform.basePlatform)
332 callback(platform, platformName);
333 });
334 }
335 traverse(PLATFORMS, null);
336}
337
338function createResultsObjectForTest(test, builder)
339{
340 return {
341 test: test,
342 builder: builder,
343 // HTML for display of the results in the flakiness column
344 html: '',
345 flips: 0,
346 slowestTime: 0,
347 slowestNonTimeoutCrashTime: 0,
348 meetsExpectations: true,
349 isWontFixSkip: false,
350 isFlaky: false,
351 // Sorted string of missing expectations
352 missing: '',
353 // String of extra expectations (i.e. expectations that never occur).
354 extra: '',
355 modifiers: '',
356 bugs: '',
357 expectations : '',
358 rawResults: '',
359 // List of all the results the test actually has.
360 actualResults: []
361 };
362}
363
364function matchingElement(stringToMatch, elementsMap)
365{
366 for (var element in elementsMap) {
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000367 if (string.contains(stringToMatch, elementsMap[element]))
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000368 return element;
369 }
370}
371
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000372function chromiumPlatform(builderNameUpperCase)
373{
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000374 if (string.contains(builderNameUpperCase, 'MAC')) {
375 if (string.contains(builderNameUpperCase, '10.7'))
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000376 return 'CHROMIUM_LION';
377 // The webkit.org 'Chromium Mac Release (Tests)' bot runs SnowLeopard.
378 return 'CHROMIUM_SNOWLEOPARD';
379 }
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000380 if (string.contains(builderNameUpperCase, 'WIN7'))
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000381 return 'CHROMIUM_WIN7';
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000382 if (string.contains(builderNameUpperCase, 'VISTA'))
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000383 return 'CHROMIUM_VISTA';
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000384 if (string.contains(builderNameUpperCase, 'WIN') || string.contains(builderNameUpperCase, 'XP'))
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000385 return 'CHROMIUM_XP';
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000386 if (string.contains(builderNameUpperCase, 'LINUX'))
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000387 return 'CHROMIUM_LUCID';
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000388 if (string.contains(builderNameUpperCase, 'ANDROID'))
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000389 return 'CHROMIUM_ANDROID';
390 // The interactive bot is XP, but doesn't have an OS in it's name.
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000391 if (string.contains(builderNameUpperCase, 'INTERACTIVE'))
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000392 return 'CHROMIUM_XP';
393}
394
395
396function platformAndBuildType(builderName)
397{
398 if (!g_perBuilderPlatformAndBuildType[builderName]) {
399 var builderNameUpperCase = builderName.toUpperCase();
400
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100401 var platform = chromiumPlatform(builderNameUpperCase);
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000402
403 if (!platform)
404 console.error('Could not resolve platform for builder: ' + builderName);
405
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000406 var buildType = string.contains(builderNameUpperCase, 'DBG') || string.contains(builderNameUpperCase, 'DEBUG') ? 'DEBUG' : 'RELEASE';
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000407 g_perBuilderPlatformAndBuildType[builderName] = {platform: platform, buildType: buildType};
408 }
409 return g_perBuilderPlatformAndBuildType[builderName];
410}
411
412function isDebug(builderName)
413{
414 return platformAndBuildType(builderName).buildType == 'DEBUG';
415}
416
417// Returns the expectation string for the given single character result.
418// This string should match the expectations that are put into
419// test_expectations.py.
420//
421// For example, if we start explicitly listing IMAGE result failures,
422// this function should start returning 'IMAGE'.
423function expectationsFileStringForResult(result)
424{
425 // For the purposes of comparing against the expecations of a test,
426 // consider simplified diff failures as just text failures since
427 // the test_expectations file doesn't treat them specially.
428 if (result == 'S')
429 return 'TEXT';
430
431 if (result == 'N')
432 return '';
433
434 return expectationsMap()[result];
435}
436
437var TestTrie = function(builders, resultsByBuilder)
438{
439 this._trie = {};
440
441 for (var builder in builders) {
442 var testsForBuilder = resultsByBuilder[builder].tests;
443 for (var test in testsForBuilder)
444 this._addTest(test.split('/'), this._trie);
445 }
446}
447
448TestTrie.prototype.forEach = function(callback, startingTriePath)
449{
450 var testsTrie = this._trie;
451 if (startingTriePath) {
452 var splitPath = startingTriePath.split('/');
453 while (splitPath.length && testsTrie)
454 testsTrie = testsTrie[splitPath.shift()];
455 }
456
457 if (!testsTrie)
458 return;
459
460 function traverse(trie, triePath) {
461 if (trie == true)
462 callback(triePath);
463 else {
464 for (var member in trie)
465 traverse(trie[member], triePath ? triePath + '/' + member : member);
466 }
467 }
468 traverse(testsTrie, startingTriePath);
469}
470
471TestTrie.prototype._addTest = function(test, trie)
472{
473 var rootComponent = test.shift();
474 if (!test.length) {
475 if (!trie[rootComponent])
476 trie[rootComponent] = true;
477 return;
478 }
479
480 if (!trie[rootComponent] || trie[rootComponent] == true)
481 trie[rootComponent] = {};
482 this._addTest(test, trie[rootComponent]);
483}
484
485// Map of all tests to true values. This is just so we can have the list of
486// all tests across all the builders.
487var g_allTestsTrie;
488
489function getAllTestsTrie()
490{
491 if (!g_allTestsTrie)
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000492 g_allTestsTrie = new TestTrie(currentBuilders(), g_resultsByBuilder);
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000493
494 return g_allTestsTrie;
495}
496
497// Returns an array of tests to be displayed in the individual tests view.
498// Note that a directory can be listed as a test, so we expand that into all
499// tests in the directory.
500function individualTests()
501{
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000502 if (g_history.dashboardSpecificState.result)
503 return allTestsWithResult(g_history.dashboardSpecificState.result);
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000504
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000505 if (!g_history.dashboardSpecificState.tests)
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000506 return [];
507
508 return individualTestsForSubstringList();
509}
510
511function substringList()
512{
513 // Convert windows slashes to unix slashes.
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000514 var tests = g_history.dashboardSpecificState.tests.replace(/\\/g, '/');
515 var separator = string.contains(tests, ' ') ? ' ' : ',';
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000516 var testList = tests.split(separator);
517
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000518 if (g_history.isLayoutTestResults())
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000519 return testList;
520
521 var testListWithoutModifiers = [];
522 testList.forEach(function(path) {
523 GTEST_MODIFIERS.forEach(function(modifier) {
524 path = path.replace('.' + modifier + '_', '.');
525 });
526 testListWithoutModifiers.push(path);
527 });
528 return testListWithoutModifiers;
529}
530
531function individualTestsForSubstringList()
532{
533 var testList = substringList();
534
535 // Put the tests into an object first and then move them into an array
536 // as a way of deduping.
537 var testsMap = {};
538 for (var i = 0; i < testList.length; i++) {
539 var path = testList[i];
540
541 // Ignore whitespace entries as they'd match every test.
542 if (path.match(/^\s*$/))
543 continue;
544
545 var hasAnyMatches = false;
546 getAllTestsTrie().forEach(function(triePath) {
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000547 if (string.caseInsensitiveContains(triePath, path)) {
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000548 testsMap[triePath] = 1;
549 hasAnyMatches = true;
550 }
551 });
552
553 // If a path doesn't match any tests, then assume it's a full path
554 // to a test that passes on all builders.
555 if (!hasAnyMatches)
556 testsMap[path] = 1;
557 }
558
559 var testsArray = [];
560 for (var test in testsMap)
561 testsArray.push(test);
562 return testsArray;
563}
564
565// Returns whether this test's slowest time is above the cutoff for
566// being a slow test.
567function isSlowTest(resultsForTest)
568{
569 var maxTime = isDebug(resultsForTest.builder) ? MIN_SECONDS_FOR_SLOW_TEST_DEBUG : MIN_SECONDS_FOR_SLOW_TEST;
570 return resultsForTest.slowestNonTimeoutCrashTime > maxTime;
571}
572
573// Returns whether this test's slowest time is *well* below the cutoff for
574// being a slow test.
575function isFastTest(resultsForTest)
576{
577 var maxTime = isDebug(resultsForTest.builder) ? MIN_SECONDS_FOR_SLOW_TEST_DEBUG : MIN_SECONDS_FOR_SLOW_TEST;
578 return resultsForTest.slowestNonTimeoutCrashTime < maxTime / 2;
579}
580
581function allTestsWithResult(result)
582{
583 processTestRunsForAllBuilders();
584 var retVal = [];
585
586 getAllTestsTrie().forEach(function(triePath) {
587 for (var i = 0; i < g_testToResultsMap[triePath].length; i++) {
588 if (g_testToResultsMap[triePath][i].actualResults.indexOf(result) != -1) {
589 retVal.push(triePath);
590 break;
591 }
592 }
593 });
594
595 return retVal;
596}
597
598
599// Adds all the tests for the given builder to the testMapToPopulate.
600function addTestsForBuilder(builder, testMapToPopulate)
601{
602 var tests = g_resultsByBuilder[builder].tests;
603 for (var test in tests) {
604 testMapToPopulate[test] = true;
605 }
606}
607
608// Map of all tests to true values by platform and build type.
609// e.g. g_allTestsByPlatformAndBuildType['XP']['DEBUG'] will have the union
610// of all tests run on the xp-debug builders.
611var g_allTestsByPlatformAndBuildType = {};
612traversePlatformsTree(function(platform, platformName) {
613 g_allTestsByPlatformAndBuildType[platformName] = {};
614});
615
616// Map of all tests to true values by platform and build type.
617// e.g. g_allTestsByPlatformAndBuildType['WIN']['DEBUG'] will have the union
618// of all tests run on the win-debug builders.
619function allTestsWithSamePlatformAndBuildType(platform, buildType)
620{
621 if (!g_allTestsByPlatformAndBuildType[platform][buildType]) {
622 var tests = {};
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000623 for (var thisBuilder in currentBuilders()) {
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000624 var thisBuilderBuildInfo = platformAndBuildType(thisBuilder);
625 if (thisBuilderBuildInfo.buildType == buildType && thisBuilderBuildInfo.platform == platform) {
626 addTestsForBuilder(thisBuilder, tests);
627 }
628 }
629 g_allTestsByPlatformAndBuildType[platform][buildType] = tests;
630 }
631
632 return g_allTestsByPlatformAndBuildType[platform][buildType];
633}
634
635function getExpectations(test, platform, buildType)
636{
637 var testObject = g_allExpectations[test];
638 if (!testObject)
639 return null;
640
641 var platformObject = testObject[platform];
642 if (!platformObject)
643 return null;
644
645 return platformObject[buildType];
646}
647
648function filterBugs(modifiers)
649{
650 var bugs = modifiers.match(/\b(Bug|webkit.org|crbug.com|code.google.com)\S*/g);
651 if (!bugs)
652 return {bugs: '', modifiers: modifiers};
653 for (var j = 0; j < bugs.length; j++)
654 modifiers = modifiers.replace(bugs[j], '');
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000655 return {bugs: bugs.join(' '), modifiers: string.collapseWhitespace(string.trimString(modifiers))};
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000656}
657
658function populateExpectationsData(resultsObject)
659{
660 var buildInfo = platformAndBuildType(resultsObject.builder);
661 var expectations = getExpectations(resultsObject.test, buildInfo.platform, buildInfo.buildType);
662 if (!expectations)
663 return;
664
665 resultsObject.expectations = expectations.expectations;
666 var filteredModifiers = filterBugs(expectations.modifiers);
667 resultsObject.modifiers = filteredModifiers.modifiers;
668 resultsObject.bugs = filteredModifiers.bugs;
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000669 resultsObject.isWontFixSkip = string.contains(expectations.modifiers, 'WONTFIX') || string.contains(expectations.modifiers, 'SKIP');
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000670}
671
672function platformObjectForName(platformName)
673{
674 var platformsList = platformName.split("_");
675 var platformObject = PLATFORMS[platformsList.shift()];
676 platformsList.forEach(function(platformName) {
677 platformObject = platformObject.subPlatforms[platformName];
678 });
679 return platformObject;
680}
681
682// Data structure to hold the processed expectations.
683// g_allExpectations[testPath][platform][buildType] gets the object that has
684// expectations and modifiers properties for this platform/buildType.
685//
686// platform and buildType both go through fallback sets of keys from most
687// specific key to least specific. For example, on Windows XP, we first
688// check the platform WIN-XP, if there's no such object, we check WIN,
689// then finally we check ALL. For build types, we check the current
690// buildType, then ALL.
691var g_allExpectations;
692
693function getParsedExpectations(data)
694{
695 var expectations = [];
696 var lines = data.split('\n');
697 lines.forEach(function(line) {
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000698 line = string.trimString(line);
699 if (!line || string.startsWith(line, '#'))
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000700 return;
701
702 // This code mimics _tokenize_line_using_new_format() in
703 // Tools/Scripts/webkitpy/layout_tests/models/test_expectations.py
704 //
705 // FIXME: consider doing more error checking here.
706 //
707 // FIXME: Clean this all up once we've fully cut over to the new syntax.
708 var tokens = line.split(/\s+/)
709 var parsed_bugs = [];
710 var parsed_modifiers = [];
711 var parsed_path;
712 var parsed_expectations = [];
713 var state = 'start';
714
715 // This clones _configuration_tokens_list in test_expectations.py.
716 // FIXME: unify with the platforms constants at the top of the file.
717 var configuration_tokens = {
718 'Release': 'RELEASE',
719 'Debug': 'DEBUG',
720 'Mac': 'MAC',
721 'Win': 'WIN',
722 'Linux': 'LINUX',
723 'SnowLeopard': 'SNOWLEOPARD',
724 'Lion': 'LION',
725 'MountainLion': 'MOUNTAINLION',
726 'Win7': 'WIN7',
727 'XP': 'XP',
728 'Vista': 'VISTA',
729 'Android': 'ANDROID',
730 };
731
732 var expectation_tokens = {
733 'Crash': 'CRASH',
734 'Failure': 'FAIL',
735 'ImageOnlyFailure': 'IMAGE',
736 'Missing': 'MISSING',
737 'Pass': 'PASS',
738 'Rebaseline': 'REBASELINE',
739 'Skip': 'SKIP',
740 'Slow': 'SLOW',
741 'Timeout': 'TIMEOUT',
742 'WontFix': 'WONTFIX',
743 };
744
745
746 tokens.forEach(function(token) {
747 if (token.indexOf('Bug') != -1 ||
748 token.indexOf('webkit.org') != -1 ||
749 token.indexOf('crbug.com') != -1 ||
750 token.indexOf('code.google.com') != -1) {
751 parsed_bugs.push(token);
752 } else if (token == '[') {
753 if (state == 'start') {
754 state = 'configuration';
755 } else if (state == 'name_found') {
756 state = 'expectations';
757 }
758 } else if (token == ']') {
759 if (state == 'configuration') {
760 state = 'name';
761 } else if (state == 'expectations') {
762 state = 'done';
763 }
764 } else if (state == 'configuration') {
765 parsed_modifiers.push(configuration_tokens[token]);
766 } else if (state == 'expectations') {
767 if (token == 'Rebaseline' || token == 'Skip' || token == 'Slow' || token == 'WontFix') {
768 parsed_modifiers.push(token.toUpperCase());
769 } else {
770 parsed_expectations.push(expectation_tokens[token]);
771 }
772 } else if (token == '#') {
773 state = 'done';
774 } else if (state == 'name' || state == 'start') {
775 parsed_path = token;
776 state = 'name_found';
777 }
778 });
779
780 if (!parsed_expectations.length) {
781 if (parsed_modifiers.indexOf('Slow') == -1) {
782 parsed_modifiers.push('Skip');
783 parsed_expectations = ['Pass'];
784 }
785 }
786
787 // FIXME: Should we include line number and comment lines here?
788 expectations.push({
789 modifiers: parsed_bugs.concat(parsed_modifiers).join(' '),
790 path: parsed_path,
791 expectations: parsed_expectations.join(' '),
792 });
793 });
794 return expectations;
795}
796
797
798function addTestToAllExpectationsForPlatform(test, platformName, expectations, modifiers)
799{
800 if (!g_allExpectations[test])
801 g_allExpectations[test] = {};
802
803 if (!g_allExpectations[test][platformName])
804 g_allExpectations[test][platformName] = {};
805
806 var allBuildTypes = [];
807 modifiers.split(' ').forEach(function(modifier) {
808 if (modifier in BUILD_TYPES) {
809 allBuildTypes.push(modifier);
810 return;
811 }
812 });
813 if (!allBuildTypes.length)
814 allBuildTypes = Object.keys(BUILD_TYPES);
815
816 allBuildTypes.forEach(function(buildType) {
817 g_allExpectations[test][platformName][buildType] = {modifiers: modifiers, expectations: expectations};
818 });
819}
820
821function processExpectationsForPlatform(platformObject, platformName, expectationsArray)
822{
823 if (!g_allExpectations)
824 g_allExpectations = {};
825
826 if (!expectationsArray)
827 return;
828
829 // Sort the array to hit more specific paths last. More specific
830 // paths (e.g. foo/bar/baz.html) override entries for less-specific ones (e.g. foo/bar).
831 expectationsArray.sort(alphanumericCompare('path'));
832
833 for (var i = 0; i < expectationsArray.length; i++) {
834 var path = expectationsArray[i].path;
835 var modifiers = expectationsArray[i].modifiers;
836 var expectations = expectationsArray[i].expectations;
837
838 var shouldProcessExpectation = false;
839 var hasPlatformModifierUnions = false;
840 if (platformObject.fallbackPlatforms) {
841 platformObject.fallbackPlatforms.forEach(function(fallbackPlatform) {
842 if (shouldProcessExpectation)
843 return;
844
845 var fallbackPlatformObject = platformObjectForName(fallbackPlatform);
846 if (!fallbackPlatformObject.platformModifierUnions)
847 return;
848
849 modifiers.split(' ').forEach(function(modifier) {
850 if (modifier in fallbackPlatformObject.platformModifierUnions) {
851 hasPlatformModifierUnions = true;
852 if (fallbackPlatformObject.platformModifierUnions[modifier].indexOf(platformName) != -1)
853 shouldProcessExpectation = true;
854 }
855 });
856 });
857 }
858
859 if (!hasPlatformModifierUnions)
860 shouldProcessExpectation = true;
861
862 if (!shouldProcessExpectation)
863 continue;
864
865 getAllTestsTrie().forEach(function(triePath) {
866 addTestToAllExpectationsForPlatform(triePath, platformName, expectations, modifiers);
867 }, path);
868 }
869}
870
871function processExpectations()
872{
873 // FIXME: An expectations-by-platform object should be passed into this function rather than checking
874 // for a global object. That way this function can be better tested and meaningful errors can
875 // be reported when expectations for a given platform are not found in that object.
876 if (!g_expectationsByPlatform)
877 return;
878
879 traversePlatformsTree(function(platform, platformName) {
880 if (platform.fallbackPlatforms) {
881 platform.fallbackPlatforms.forEach(function(fallbackPlatform) {
882 if (fallbackPlatform in g_expectationsByPlatform)
883 processExpectationsForPlatform(platform, platformName, g_expectationsByPlatform[fallbackPlatform]);
884 });
885 }
886
887 if (platformName in g_expectationsByPlatform)
888 processExpectationsForPlatform(platform, platformName, g_expectationsByPlatform[platformName]);
889 });
890
891 g_expectationsByPlatform = undefined;
892}
893
894function processMissingTestsWithExpectations(builder, platform, buildType)
895{
896 var noFailures = [];
897 var skipped = [];
898
899 var allTestsForPlatformAndBuildType = allTestsWithSamePlatformAndBuildType(platform, buildType);
900 for (var test in g_allExpectations) {
901 var expectations = getExpectations(test, platform, buildType);
902
903 if (!expectations)
904 continue;
905
906 // Test has expectations, but no result in the builders results.
907 // This means it's either SKIP or passes on all builds.
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000908 if (!allTestsForPlatformAndBuildType[test] && !string.contains(expectations.modifiers, 'WONTFIX')) {
909 if (string.contains(expectations.modifiers, 'SKIP'))
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000910 skipped.push(test);
911 else if (!expectations.expectations.match(/^\s*PASS\s*$/)) {
912 // Don't show tests expected to always pass. This is used in ways like
913 // the following:
914 // foo/bar = FAIL
915 // foo/bar/baz.html = PASS
916 noFailures.push({test: test, expectations: expectations.expectations, modifiers: expectations.modifiers});
917 }
918 }
919 }
920
921 g_perBuilderSkippedPaths[builder] = skipped.sort();
922 g_perBuilderWithExpectationsButNoFailures[builder] = noFailures.sort();
923}
924
925function processTestResultsForBuilderAsync(builder)
926{
927 setTimeout(function() { processTestRunsForBuilder(builder); }, 0);
928}
929
930function processTestRunsForAllBuilders()
931{
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000932 for (var builder in currentBuilders())
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000933 processTestRunsForBuilder(builder);
934}
935
936function processTestRunsForBuilder(builderName)
937{
938 if (g_perBuilderFailures[builderName])
939 return;
940
941 if (!g_resultsByBuilder[builderName]) {
942 console.error('No tests found for ' + builderName);
943 g_perBuilderFailures[builderName] = [];
944 return;
945 }
946
947 processExpectations();
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000948
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000949 var buildInfo = platformAndBuildType(builderName);
950 var platform = buildInfo.platform;
951 var buildType = buildInfo.buildType;
952 processMissingTestsWithExpectations(builderName, platform, buildType);
953
954 var failures = [];
955 var allTestsForThisBuilder = g_resultsByBuilder[builderName].tests;
956
957 for (var test in allTestsForThisBuilder) {
958 var resultsForTest = createResultsObjectForTest(test, builderName);
959 populateExpectationsData(resultsForTest);
960
961 var rawTest = g_resultsByBuilder[builderName].tests[test];
962 resultsForTest.rawTimes = rawTest.times;
963 var rawResults = rawTest.results;
964 resultsForTest.rawResults = rawResults;
965
966 // FIXME: Switch to resultsByBuild
967 var times = resultsForTest.rawTimes;
968 var numTimesSeen = 0;
969 var numResultsSeen = 0;
970 var resultsIndex = 0;
971 var currentResult;
972 for (var i = 0; i < times.length; i++) {
973 numTimesSeen += times[i][RLE.LENGTH];
974
975 while (rawResults[resultsIndex] && numTimesSeen > (numResultsSeen + rawResults[resultsIndex][RLE.LENGTH])) {
976 numResultsSeen += rawResults[resultsIndex][RLE.LENGTH];
977 resultsIndex++;
978 }
979
980 if (rawResults && rawResults[resultsIndex])
981 currentResult = rawResults[resultsIndex][RLE.VALUE];
982
983 var time = times[i][RLE.VALUE]
984
985 // Ignore times for crashing/timeout runs for the sake of seeing if
986 // a test should be marked slow.
987 if (currentResult != 'C' && currentResult != 'T')
988 resultsForTest.slowestNonTimeoutCrashTime = Math.max(resultsForTest.slowestNonTimeoutCrashTime, time);
989 resultsForTest.slowestTime = Math.max(resultsForTest.slowestTime, time);
990 }
991
992 processMissingAndExtraExpectations(resultsForTest);
993 failures.push(resultsForTest);
994
995 if (!g_testToResultsMap[test])
996 g_testToResultsMap[test] = [];
997 g_testToResultsMap[test].push(resultsForTest);
998 }
999
1000 g_perBuilderFailures[builderName] = failures;
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001001}
1002
1003function processMissingAndExtraExpectations(resultsForTest)
1004{
1005 // Heuristic for determining whether expectations apply to a given test:
1006 // -If a test result happens < MIN_RUNS_FOR_FLAKE, then consider it a flaky
1007 // result and include it in the list of expected results.
1008 // -Otherwise, grab the first contiguous set of runs with the same result
1009 // for >= MIN_RUNS_FOR_FLAKE and ignore all following runs >=
1010 // MIN_RUNS_FOR_FLAKE.
1011 // This lets us rule out common cases of a test changing expectations for
1012 // a few runs, then being fixed or otherwise modified in a non-flaky way.
1013 var rawResults = resultsForTest.rawResults;
1014
1015 // If the first result is no-data that means the test is skipped or is
1016 // being run on a different builder (e.g. moved from one shard to another).
1017 // Ignore these results since we have no real data about what's going on.
1018 if (rawResults[0][RLE.VALUE] == 'N')
1019 return;
1020
1021 // Only consider flake if it doesn't happen twice in a row.
1022 var MIN_RUNS_FOR_FLAKE = 2;
1023 var resultsMap = {}
1024 var numResultsSeen = 0;
1025 var haveSeenNonFlakeResult = false;
1026 var numRealResults = 0;
1027
1028 var seenResults = {};
1029 for (var i = 0; i < rawResults.length; i++) {
1030 var numResults = rawResults[i][RLE.LENGTH];
1031 numResultsSeen += numResults;
1032
1033 var result = rawResults[i][RLE.VALUE];
1034
1035 var hasMinRuns = numResults >= MIN_RUNS_FOR_FLAKE;
1036 if (haveSeenNonFlakeResult && hasMinRuns)
1037 continue;
1038 else if (hasMinRuns)
1039 haveSeenNonFlakeResult = true;
1040 else if (!seenResults[result]) {
1041 // Only consider a short-lived result if we've seen it more than once.
1042 // Otherwise, we include lots of false-positives due to tests that fail
1043 // for a couple runs and then start passing.
1044 seenResults[result] = true;
1045 continue;
1046 }
1047
1048 var expectation = expectationsFileStringForResult(result);
1049 resultsMap[expectation] = true;
1050 numRealResults++;
1051 }
1052
1053 resultsForTest.flips = i - 1;
1054 resultsForTest.isFlaky = numRealResults > 1;
1055
1056 var missingExpectations = [];
1057 var extraExpectations = [];
1058
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001059 if (g_history.isLayoutTestResults()) {
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001060 var expectationsArray = resultsForTest.expectations ? resultsForTest.expectations.split(' ') : [];
1061 extraExpectations = expectationsArray.filter(
1062 function(element) {
1063 // FIXME: Once all the FAIL lines are removed from
1064 // TestExpectations, delete all the legacyExpectationsSemantics
1065 // code.
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001066 if (g_history.dashboardSpecificState.legacyExpectationsSemantics) {
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001067 if (element == 'FAIL') {
1068 for (var i = 0; i < FAIL_RESULTS.length; i++) {
1069 if (resultsMap[FAIL_RESULTS[i]])
1070 return false;
1071 }
1072 return true;
1073 }
1074 }
1075
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001076 return element && !resultsMap[element] && !string.contains(element, 'BUG');
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001077 });
1078
1079 for (var result in resultsMap) {
1080 resultsForTest.actualResults.push(result);
1081 var hasExpectation = false;
1082 for (var i = 0; i < expectationsArray.length; i++) {
1083 var expectation = expectationsArray[i];
1084 // FIXME: Once all the FAIL lines are removed from
1085 // TestExpectations, delete all the legacyExpectationsSemantics
1086 // code.
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001087 if (g_history.dashboardSpecificState.legacyExpectationsSemantics) {
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001088 if (expectation == 'FAIL') {
1089 for (var j = 0; j < FAIL_RESULTS.length; j++) {
1090 if (result == FAIL_RESULTS[j]) {
1091 hasExpectation = true;
1092 break;
1093 }
1094 }
1095 }
1096 }
1097
1098 if (result == expectation)
1099 hasExpectation = true;
1100
1101 if (hasExpectation)
1102 break;
1103 }
1104 // If we have no expectations for a test and it only passes, then don't
1105 // list PASS as a missing expectation. We only want to list PASS if it
1106 // flaky passes, so there would be other expectations.
1107 if (!hasExpectation && !(!expectationsArray.length && result == 'PASS' && numRealResults == 1))
1108 missingExpectations.push(result);
1109 }
1110
1111 // Only highlight tests that take > 2 seconds as needing to be marked as
1112 // slow. There are too many tests that take ~2 seconds every couple
1113 // hundred runs. It's not worth the manual maintenance effort.
1114 // Also, if a test times out, then it should not be marked as slow.
1115 var minTimeForNeedsSlow = isDebug(resultsForTest.builder) ? 2 : 1;
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001116 if (isSlowTest(resultsForTest) && !resultsMap['TIMEOUT'] && (!resultsForTest.modifiers || !string.contains(resultsForTest.modifiers, 'SLOW')))
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001117 missingExpectations.push('SLOW');
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001118 else if (isFastTest(resultsForTest) && resultsForTest.modifiers && string.contains(resultsForTest.modifiers, 'SLOW'))
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001119 extraExpectations.push('SLOW');
1120
1121 // If there are no missing results or modifiers besides build
1122 // type, platform, or bug and the expectations are all extra
1123 // that is, extraExpectations - expectations = PASS,
1124 // include PASS as extra, since that means this line in
1125 // test_expectations can be deleted..
1126 if (!missingExpectations.length && !(resultsForTest.modifiers && realModifiers(resultsForTest.modifiers))) {
1127 var extraPlusPass = extraExpectations.concat(['PASS']);
1128 if (extraPlusPass.sort().toString() == expectationsArray.slice(0).sort().toString())
1129 extraExpectations.push('PASS');
1130 }
1131
1132 }
1133
1134 resultsForTest.meetsExpectations = !missingExpectations.length && !extraExpectations.length;
1135 resultsForTest.missing = missingExpectations.sort().join(' ');
1136 resultsForTest.extra = extraExpectations.sort().join(' ');
1137}
1138
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001139var BUG_URL_PREFIX = '<a href="http://';
1140var BUG_URL_POSTFIX = '/$1">crbug.com/$1</a> ';
1141var WEBKIT_BUG_URL_POSTFIX = '/$1">webkit.org/b/$1</a> ';
1142var INTERNAL_BUG_REPLACE_VALUE = BUG_URL_PREFIX + 'b' + BUG_URL_POSTFIX;
1143var EXTERNAL_BUG_REPLACE_VALUE = BUG_URL_PREFIX + 'crbug.com' + BUG_URL_POSTFIX;
1144var WEBKIT_BUG_REPLACE_VALUE = BUG_URL_PREFIX + 'webkit.org/b' + WEBKIT_BUG_URL_POSTFIX;
1145
1146function htmlForBugs(bugs)
1147{
1148 bugs = bugs.replace(/crbug.com\/(\d+)(\ |$)/g, EXTERNAL_BUG_REPLACE_VALUE);
1149 bugs = bugs.replace(/webkit.org\/b\/(\d+)(\ |$)/g, WEBKIT_BUG_REPLACE_VALUE);
1150 return bugs;
1151}
1152
1153function linkHTMLToOpenWindow(url, text)
1154{
1155 return '<a href="' + url + '" target="_blank">' + text + '</a>';
1156}
1157
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001158// Returns whether the result for index'th result for testName on builder was
1159// a failure.
1160function isFailure(builder, testName, index)
1161{
1162 var currentIndex = 0;
1163 var rawResults = g_resultsByBuilder[builder].tests[testName].results;
1164 for (var i = 0; i < rawResults.length; i++) {
1165 currentIndex += rawResults[i][RLE.LENGTH];
1166 if (currentIndex > index)
1167 return isFailingResult(rawResults[i][RLE.VALUE]);
1168 }
1169 console.error('Index exceeds number of results: ' + index);
1170}
1171
1172// Returns an array of indexes for all builds where this test failed.
1173function indexesForFailures(builder, testName)
1174{
1175 var rawResults = g_resultsByBuilder[builder].tests[testName].results;
1176 var buildNumbers = g_resultsByBuilder[builder].buildNumbers;
1177 var index = 0;
1178 var failures = [];
1179 for (var i = 0; i < rawResults.length; i++) {
1180 var numResults = rawResults[i][RLE.LENGTH];
1181 if (isFailingResult(rawResults[i][RLE.VALUE])) {
1182 for (var j = 0; j < numResults; j++)
1183 failures.push(index + j);
1184 }
1185 index += numResults;
1186 }
1187 return failures;
1188}
1189
1190// Returns the path to the failure log for this non-webkit test.
1191function pathToFailureLog(testName)
1192{
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001193 return '/steps/' + g_history.crossDashboardState.testType + '/logs/' + testName.split('.')[1]
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001194}
1195
1196function showPopupForBuild(e, builder, index, opt_testName)
1197{
1198 var html = '';
1199
1200 var time = g_resultsByBuilder[builder].secondsSinceEpoch[index];
1201 if (time) {
1202 var date = new Date(time * 1000);
1203 html += date.toLocaleDateString() + ' ' + date.toLocaleTimeString();
1204 }
1205
1206 var buildNumber = g_resultsByBuilder[builder].buildNumbers[index];
1207 var master = builderMaster(builder);
1208 var buildBasePath = master.logPath(builder, buildNumber);
1209
1210 html += '<ul><li>' + linkHTMLToOpenWindow(buildBasePath, 'Build log') +
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +01001211 '</li><li>Blink: ' + ui.html.blinkRevisionLink(g_resultsByBuilder[builder], index) + '</li>';
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001212
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +01001213 html += '</li><li>Chromium: ' + ui.html.chromiumRevisionLink(g_resultsByBuilder[builder], index) + '</li>';
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001214
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +01001215 var chromeRevision = g_resultsByBuilder[builder].chromeRevision[index];
1216 if (chromeRevision && g_history.isLayoutTestResults()) {
1217 html += '<li><a href="' + TEST_RESULTS_BASE_PATH + currentBuilders()[builder] +
1218 '/' + chromeRevision + '/layout-test-results.zip">layout-test-results.zip</a></li>';
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001219 }
1220
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001221 if (!g_history.isLayoutTestResults() && opt_testName && isFailure(builder, opt_testName, index))
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001222 html += '<li>' + linkHTMLToOpenWindow(buildBasePath + pathToFailureLog(opt_testName), 'Failure log') + '</li>';
1223
1224 html += '</ul>';
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001225 ui.popup.show(e.target, html);
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001226}
1227
1228function htmlForTestResults(test)
1229{
1230 var html = '';
1231 var results = test.rawResults.concat();
1232 var times = test.rawTimes.concat();
1233 var builder = test.builder;
1234 var master = builderMaster(builder);
1235 var buildNumbers = g_resultsByBuilder[builder].buildNumbers;
1236
1237 var indexToReplaceCurrentResult = -1;
1238 var indexToReplaceCurrentTime = -1;
1239 var currentResultArray, currentTimeArray, currentResult, innerHTML, resultString;
1240 for (var i = 0; i < buildNumbers.length; i++) {
1241 if (i > indexToReplaceCurrentResult) {
1242 currentResultArray = results.shift();
1243 if (currentResultArray) {
1244 currentResult = currentResultArray[RLE.VALUE];
1245 // Treat simplified diff failures as just text failures.
1246 if (currentResult == 'S')
1247 currentResult = 'F';
1248 indexToReplaceCurrentResult += currentResultArray[RLE.LENGTH];
1249 } else {
1250 currentResult = 'N';
1251 indexToReplaceCurrentResult += buildNumbers.length;
1252 }
1253 resultString = expectationsFileStringForResult(currentResult);
1254 }
1255
1256 if (i > indexToReplaceCurrentTime) {
1257 currentTimeArray = times.shift();
1258 var currentTime = 0;
1259 if (currentResultArray) {
1260 currentTime = currentTimeArray[RLE.VALUE];
1261 indexToReplaceCurrentTime += currentTimeArray[RLE.LENGTH];
1262 } else
1263 indexToReplaceCurrentTime += buildNumbers.length;
1264
1265 innerHTML = currentTime || '&nbsp;';
1266 }
1267
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001268 html += '<td title="' + (resultString || 'NO DATA') + '. Click for more info." class="results ' + currentResult +
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +01001269 '" onclick=\'showPopupForBuild(event, "' + builder + '",' + i + ',"' + test.test + '")\'>' + innerHTML;
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001270 }
1271 return html;
1272}
1273
1274function htmlForTestsWithExpectationsButNoFailures(builder)
1275{
1276 var tests = g_perBuilderWithExpectationsButNoFailures[builder];
1277 var skippedPaths = g_perBuilderSkippedPaths[builder];
1278 var showUnexpectedPassesLink = linkHTMLToToggleState('showUnexpectedPasses', 'tests that have not failed in last ' + g_resultsByBuilder[builder].buildNumbers.length + ' runs');
1279 var showSkippedLink = linkHTMLToToggleState('showSkipped', 'skipped tests in TestExpectations');
1280
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001281 var html = '';
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +01001282 if (g_history.isLayoutTestResults() && (tests.length || skippedPaths.length)) {
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001283 var buildInfo = platformAndBuildType(builder);
1284 html += '<h2 style="display:inline-block">Expectations for ' + buildInfo.platform + '-' + buildInfo.buildType + '</h2> ';
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001285 if (!g_history.dashboardSpecificState.showUnexpectedPasses && tests.length)
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001286 html += showUnexpectedPassesLink;
1287 html += ' ';
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001288 if (!g_history.dashboardSpecificState.showSkipped && skippedPaths.length)
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001289 html += showSkippedLink;
1290 }
1291
1292 var open = '<div onclick="selectContents(this)">';
1293
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001294 if (g_history.dashboardSpecificState.showUnexpectedPasses && tests.length) {
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001295 html += '<div id="passing-tests">' + showUnexpectedPassesLink;
1296 for (var i = 0; i < tests.length; i++)
1297 html += open + tests[i].test + '</div>';
1298 html += '</div>';
1299 }
1300
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001301 if (g_history.dashboardSpecificState.showSkipped && skippedPaths.length)
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001302 html += '<div id="skipped-tests">' + showSkippedLink + open + skippedPaths.join('</div>' + open) + '</div></div>';
1303 return html + '<br>';
1304}
1305
1306// Returns whether we should exclude test results from the test table.
1307function shouldHideTest(testResult)
1308{
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +01001309 // For non-layout tests, we always show everything.
1310 if (!g_history.isLayoutTestResults())
1311 return false;
1312
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001313 if (testResult.isWontFixSkip)
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001314 return !g_history.dashboardSpecificState.showWontFixSkip;
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001315
1316 if (testResult.isFlaky)
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001317 return !g_history.dashboardSpecificState.showFlaky;
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001318
1319 if (isSlowTest(testResult))
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001320 return !g_history.dashboardSpecificState.showSlow;
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001321
1322 if (testResult.meetsExpectations)
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001323 return !g_history.dashboardSpecificState.showCorrectExpectations;
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001324
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001325 return !g_history.dashboardSpecificState.showWrongExpectations;
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001326}
1327
1328// Sets the browser's selection to the element's contents.
1329function selectContents(element)
1330{
1331 window.getSelection().selectAllChildren(element);
1332}
1333
1334function createBugHTML(test)
1335{
1336 var symptom = test.isFlaky ? 'flaky' : 'failing';
1337 var title = encodeURIComponent('Layout Test ' + test.test + ' is ' + symptom);
1338 var description = encodeURIComponent('The following layout test is ' + symptom + ' on ' +
1339 '[insert platform]\n\n' + test.test + '\n\nProbable cause:\n\n' +
1340 '[insert probable cause]');
1341
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +01001342 url = 'https://code.google.com/p/chromium/issues/entry?template=Layout%20Test%20Failure&summary=' + title + '&comment=' + description;
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001343 return '<a href="' + url + '" class="file-bug">FILE BUG</a>';
1344}
1345
1346function isCrossBuilderView()
1347{
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001348 return g_history.dashboardSpecificState.tests || g_history.dashboardSpecificState.result || g_history.dashboardSpecificState.expectationsUpdate;
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001349}
1350
1351function tableHeaders(opt_getAll)
1352{
1353 var headers = [];
1354 if (isCrossBuilderView() || opt_getAll)
1355 headers.push('builder');
1356
1357 if (!isCrossBuilderView() || opt_getAll)
1358 headers.push('test');
1359
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001360 if (g_history.isLayoutTestResults() || opt_getAll)
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001361 headers.push('bugs', 'modifiers', 'expectations');
1362
1363 headers.push('slowest run', 'flakiness (numbers are runtimes in seconds)');
1364 return headers;
1365}
1366
1367function htmlForSingleTestRow(test)
1368{
1369 if (!isCrossBuilderView() && shouldHideTest(test)) {
1370 // The innerHTML call is considerably faster if we exclude the rows for
1371 // items we're not showing than if we hide them using display:none.
1372 // For the crossBuilderView, we want to show all rows the user is
1373 // explicitly listing tests to view.
1374 return '';
1375 }
1376
1377 var headers = tableHeaders();
1378 var html = '';
1379 for (var i = 0; i < headers.length; i++) {
1380 var header = headers[i];
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001381 if (string.startsWith(header, 'test') || string.startsWith(header, 'builder')) {
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001382 // If isCrossBuilderView() is true, we're just viewing a single test
1383 // with results for many builders, so the first column is builder names
1384 // instead of test paths.
1385 var testCellClassName = 'test-link' + (isCrossBuilderView() ? ' builder-name' : '');
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001386 var testCellHTML = isCrossBuilderView() ? test.builder : '<span class="link" onclick="g_history.setQueryParameter(\'tests\',\'' + test.test +'\');">' + test.test + '</span>';
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001387
1388 html += '<tr><td class="' + testCellClassName + '">' + testCellHTML;
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001389 } else if (string.startsWith(header, 'bugs'))
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001390 html += '<td class=options-container>' + (test.bugs ? htmlForBugs(test.bugs) : createBugHTML(test));
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001391 else if (string.startsWith(header, 'modifiers'))
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001392 html += '<td class=options-container>' + test.modifiers;
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001393 else if (string.startsWith(header, 'expectations'))
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001394 html += '<td class=options-container>' + test.expectations;
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001395 else if (string.startsWith(header, 'slowest'))
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001396 html += '<td>' + (test.slowestTime ? test.slowestTime + 's' : '');
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001397 else if (string.startsWith(header, 'flakiness'))
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001398 html += htmlForTestResults(test);
1399 }
1400 return html;
1401}
1402
1403function sortColumnFromTableHeader(headerText)
1404{
1405 return headerText.split(' ', 1)[0];
1406}
1407
1408function htmlForTableColumnHeader(headerName, opt_fillColSpan)
1409{
1410 // Use the first word of the header title as the sortkey
1411 var thisSortValue = sortColumnFromTableHeader(headerName);
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001412 var arrowHTML = thisSortValue == g_history.dashboardSpecificState.sortColumn ?
1413 '<span class=' + g_history.dashboardSpecificState.sortOrder + '>' + (g_history.dashboardSpecificState.sortOrder == FORWARD ? '&uarr;' : '&darr;' ) + '</span>' : '';
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001414 return '<th sortValue=' + thisSortValue +
1415 // Extend last th through all the rest of the columns.
1416 (opt_fillColSpan ? ' colspan=10000' : '') +
1417 // Extra span here is so flex boxing actually centers.
1418 // There's probably a better way to do this with CSS only though.
1419 '><div class=table-header-content><span></span>' + arrowHTML +
1420 '<span class=header-text>' + headerName + '</span>' + arrowHTML + '</div></th>';
1421}
1422
1423function htmlForTestTable(rowsHTML, opt_excludeHeaders)
1424{
1425 var html = '<table class=test-table>';
1426 if (!opt_excludeHeaders) {
1427 html += '<thead><tr>';
1428 var headers = tableHeaders();
1429 for (var i = 0; i < headers.length; i++)
1430 html += htmlForTableColumnHeader(headers[i], i == headers.length - 1);
1431 html += '</tr></thead>';
1432 }
1433 return html + '<tbody>' + rowsHTML + '</tbody></table>';
1434}
1435
1436function appendHTML(html)
1437{
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001438 // InnerHTML to a div that's not in the document. This is
1439 // ~300ms faster in Safari 4 and Chrome 4 on mac.
1440 var div = document.createElement('div');
1441 div.innerHTML = html;
1442 document.body.appendChild(div);
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001443 postHeightChangedMessage();
1444}
1445
1446function alphanumericCompare(column, reverse)
1447{
1448 return reversibleCompareFunction(function(a, b) {
1449 // Put null entries at the bottom
1450 var a = a[column] ? String(a[column]) : 'z';
1451 var b = b[column] ? String(b[column]) : 'z';
1452
1453 if (a < b)
1454 return -1;
1455 else if (a == b)
1456 return 0;
1457 else
1458 return 1;
1459 }, reverse);
1460}
1461
1462function numericSort(column, reverse)
1463{
1464 return reversibleCompareFunction(function(a, b) {
1465 a = parseFloat(a[column]);
1466 b = parseFloat(b[column]);
1467 return a - b;
1468 }, reverse);
1469}
1470
1471function reversibleCompareFunction(compare, reverse)
1472{
1473 return function(a, b) {
1474 return compare(reverse ? b : a, reverse ? a : b);
1475 };
1476}
1477
1478function changeSort(e)
1479{
1480 var target = e.currentTarget;
1481 e.preventDefault();
1482
1483 var sortValue = target.getAttribute('sortValue');
1484 while (target && target.tagName != 'TABLE')
1485 target = target.parentNode;
1486
1487 var sort = 'sortColumn';
1488 var orderKey = 'sortOrder';
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001489 if (sortValue == g_history.dashboardSpecificState[sort] && g_history.dashboardSpecificState[orderKey] == FORWARD)
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001490 order = BACKWARD;
1491 else
1492 order = FORWARD;
1493
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001494 g_history.setQueryParameter(sort, sortValue, orderKey, order);
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001495}
1496
1497function sortTests(tests, column, order)
1498{
1499 var resultsProperty, sortFunctionGetter;
1500 if (column == 'flakiness') {
1501 sortFunctionGetter = numericSort;
1502 resultsProperty = 'flips';
1503 } else if (column == 'slowest') {
1504 sortFunctionGetter = numericSort;
1505 resultsProperty = 'slowestTime';
1506 } else {
1507 sortFunctionGetter = alphanumericCompare;
1508 resultsProperty = column;
1509 }
1510
1511 tests.sort(sortFunctionGetter(resultsProperty, order == BACKWARD));
1512}
1513
1514// Sorts a space separated expectations string in alphanumeric order.
1515// @param {string} str The expectations string.
1516// @return {string} The sorted string.
1517function sortExpectationsString(str)
1518{
1519 return str.split(' ').sort().join(' ');
1520}
1521
1522function addUpdate(testsNeedingUpdate, test, builderName, missing, extra)
1523{
1524 if (!testsNeedingUpdate[test])
1525 testsNeedingUpdate[test] = {};
1526
1527 var buildInfo = platformAndBuildType(builderName);
1528 var builder = buildInfo.platform + ' ' + buildInfo.buildType;
1529 if (!testsNeedingUpdate[test][builder])
1530 testsNeedingUpdate[test][builder] = {};
1531
1532 if (missing)
1533 testsNeedingUpdate[test][builder].missing = sortExpectationsString(missing);
1534
1535 if (extra)
1536 testsNeedingUpdate[test][builder].extra = sortExpectationsString(extra);
1537}
1538
1539
1540// From a string of modifiers, returns a string of modifiers that
1541// are for real result changes, like SLOW, and excludes modifiers
1542// that specificy things like platform, build_type, bug.
1543// @param {string} modifierString String containing all modifiers.
1544// @return {string} String containing only modifiers that effect the results.
1545function realModifiers(modifierString)
1546{
1547 var modifiers = modifierString.split(' ');;
1548 return modifiers.filter(function(modifier) {
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001549 if (modifier in BUILD_TYPES || string.startsWith(modifier, 'BUG'))
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001550 return false;
1551
1552 var matchesPlatformOrUnion = false;
1553 traversePlatformsTree(function(platform, platformName) {
1554 if (matchesPlatformOrUnion)
1555 return;
1556
1557 if (platform.fallbackPlatforms) {
1558 platform.fallbackPlatforms.forEach(function(fallbackPlatform) {
1559 if (matchesPlatformOrUnion)
1560 return;
1561
1562 var fallbackPlatformObject = platformObjectForName(fallbackPlatform);
1563 if (!fallbackPlatformObject.platformModifierUnions)
1564 return;
1565
1566 matchesPlatformOrUnion = modifier in fallbackPlatformObject.subPlatforms || modifier in fallbackPlatformObject.platformModifierUnions;
1567 });
1568 }
1569 });
1570
1571 return !matchesPlatformOrUnion;
1572 }).join(' ');
1573}
1574
1575function generatePageForExpectationsUpdate()
1576{
1577 // Always show all runs when auto-updating expectations.
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001578 if (!g_history.crossDashboardState.showAllRuns)
1579 g_history.setQueryParameter('showAllRuns', true);
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001580
1581 processTestRunsForAllBuilders();
1582 var testsNeedingUpdate = {};
1583 for (var test in g_testToResultsMap) {
1584 var results = g_testToResultsMap[test];
1585 for (var i = 0; i < results.length; i++) {
1586 var thisResult = results[i];
1587
1588 if (!thisResult.missing && !thisResult.extra)
1589 continue;
1590
1591 var allPassesOrNoDatas = thisResult.rawResults.filter(function (x) { return x[1] != "P" && x[1] != "N"; }).length == 0;
1592
1593 if (allPassesOrNoDatas)
1594 continue;
1595
1596 addUpdate(testsNeedingUpdate, test, thisResult.builder, thisResult.missing, thisResult.extra);
1597 }
1598 }
1599
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001600 for (var builder in currentBuilders()) {
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001601 var tests = g_perBuilderWithExpectationsButNoFailures[builder]
1602 for (var i = 0; i < tests.length; i++) {
1603 // Anything extra in this case is what is listed in expectations
1604 // plus modifiers other than bug, platform, build type.
1605 var modifiers = realModifiers(tests[i].modifiers);
1606 var extras = tests[i].expectations;
1607 extras += modifiers ? ' ' + modifiers : '';
1608 addUpdate(testsNeedingUpdate, tests[i].test, builder, null, extras);
1609 }
1610 }
1611
1612 // Get the keys in alphabetical order, so it is easy to process groups
1613 // of tests.
1614 var keys = Object.keys(testsNeedingUpdate).sort();
1615 showUpdateInfoForTest(testsNeedingUpdate, keys);
1616}
1617
1618// Show the test results and the json for differing expectations, and
1619// allow the user to include or exclude this update.
1620//
1621// @param {Object} testsNeedingUpdate Tests that need updating.
1622// @param {Array.<string>} keys Keys into the testNeedingUpdate object.
1623function showUpdateInfoForTest(testsNeedingUpdate, keys)
1624{
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001625 var test = keys[g_history.dashboardSpecificState.updateIndex];
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001626 document.body.innerHTML = '';
1627
1628 // FIXME: Make this DOM creation less verbose.
1629 var index = document.createElement('div');
1630 index.style.cssFloat = 'right';
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001631 index.textContent = (g_history.dashboardSpecificState.updateIndex + 1) + ' of ' + keys.length + ' tests';
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001632 document.body.appendChild(index);
1633
1634 var buttonRegion = document.createElement('div');
1635 var includeBtn = document.createElement('input');
1636 includeBtn.type = 'button';
1637 includeBtn.value = 'include selected';
1638 includeBtn.addEventListener('click', partial(handleUpdate, testsNeedingUpdate, keys), false);
1639 buttonRegion.appendChild(includeBtn);
1640
1641 var previousBtn = document.createElement('input');
1642 previousBtn.type = 'button';
1643 previousBtn.value = 'previous';
1644 previousBtn.addEventListener('click',
1645 function() {
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001646 setUpdateIndex(g_history.dashboardSpecificState.updateIndex - 1, testsNeedingUpdate, keys);
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001647 },
1648 false);
1649 buttonRegion.appendChild(previousBtn);
1650
1651 var nextBtn = document.createElement('input');
1652 nextBtn.type = 'button';
1653 nextBtn.value = 'next';
1654 nextBtn.addEventListener('click', partial(nextUpdate, testsNeedingUpdate, keys), false);
1655 buttonRegion.appendChild(nextBtn);
1656
1657 var doneBtn = document.createElement('input');
1658 doneBtn.type = 'button';
1659 doneBtn.value = 'done';
1660 doneBtn.addEventListener('click', finishUpdate, false);
1661 buttonRegion.appendChild(doneBtn);
1662
1663 document.body.appendChild(buttonRegion);
1664
1665 var updates = testsNeedingUpdate[test];
1666 var checkboxes = document.createElement('div');
1667 for (var builder in updates) {
1668 // Create a checkbox for each builder.
1669 var checkboxRegion = document.createElement('div');
1670 var checkbox = document.createElement('input');
1671 checkbox.type = 'checkbox';
1672 checkbox.id = builder;
1673 checkbox.checked = true;
1674 checkboxRegion.appendChild(checkbox);
1675 checkboxRegion.appendChild(document.createTextNode(builder + ' : ' + JSON.stringify(updates[builder])));
1676 checkboxes.appendChild(checkboxRegion);
1677 }
1678 document.body.appendChild(checkboxes);
1679
1680 var div = document.createElement('div');
1681 div.innerHTML = htmlForIndividualTestOnAllBuildersWithResultsLinks(test);
1682 document.body.appendChild(div);
1683 appendExpectations();
1684}
1685
1686
1687// When the user has finished selecting expectations to update, provide them
1688// with json to copy over.
1689function finishUpdate()
1690{
1691 document.body.innerHTML = 'The next step is to copy the output below ' +
1692 'into a local file and save it. Then, run<br><code>python ' +
1693 'src/webkit/tools/layout_tests/webkitpy/layout_tests/update_expectat' +
1694 'ions_from_dashboard.py path/to/local/file</code><br>in order to ' +
1695 'update the expectations file.<br><textarea id="results" '+
1696 'style="width:600px;height:600px;"> ' +
1697 JSON.stringify(g_confirmedTests) + '</textarea>';
1698 results.focus();
1699 document.execCommand('SelectAll');
1700}
1701
1702// Handle user click on "include selected" button.
1703// Includes the tests that are selected and exclude the rest.
1704// @param {Object} testsNeedingUpdate Tests that need updating.
1705// @param {Array.<string>} keys Keys into the testNeedingUpdate object.
1706function handleUpdate(testsNeedingUpdate, keys)
1707{
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001708 var test = keys[g_history.dashboardSpecificState.updateIndex];
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001709 var updates = testsNeedingUpdate[test];
1710 for (var builder in updates) {
1711 // Add included tests, and delete excluded tests if
1712 // they were previously included.
1713 if ($(builder).checked) {
1714 if (!g_confirmedTests[test])
1715 g_confirmedTests[test] = {};
1716 g_confirmedTests[test][builder] = testsNeedingUpdate[test][builder];
1717 } else if (g_confirmedTests[test] && g_confirmedTests[test][builder]) {
1718 delete g_confirmedTests[test][builder];
1719 if (!Object.keys(g_confirmedTests[test]).length)
1720 delete g_confirmedTests[test];
1721 }
1722 }
1723 nextUpdate(testsNeedingUpdate, keys);
1724}
1725
1726
1727// Move to the next item to update.
1728// @param {Object} testsNeedingUpdate Tests that need updating.
1729// @param {Array.<string>} keys Keys into the testNeedingUpdate object.
1730function nextUpdate(testsNeedingUpdate, keys)
1731{
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001732 setUpdateIndex(g_history.dashboardSpecificState.updateIndex + 1, testsNeedingUpdate, keys);
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001733}
1734
1735
1736// Advance the index we are updating at. If we walk over the end
1737// or beginning, just loop.
1738// @param {string} newIndex The index into the keys to move to.
1739// @param {Object} testsNeedingUpdate Tests that need updating.
1740// @param {Array.<string>} keys Keys into the testNeedingUpdate object.
1741function setUpdateIndex(newIndex, testsNeedingUpdate, keys)
1742{
1743 if (newIndex == -1)
1744 newIndex = keys.length - 1;
1745 else if (newIndex == keys.length)
1746 newIndex = 0;
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001747 g_history.setQueryParameter("updateIndex", newIndex);
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001748 showUpdateInfoForTest(testsNeedingUpdate, keys);
1749}
1750
1751function htmlForIndividualTestOnAllBuilders(test)
1752{
1753 processTestRunsForAllBuilders();
1754
1755 var testResults = g_testToResultsMap[test];
1756 if (!testResults)
1757 return '<div class="not-found">Test not found. Either it does not exist, is skipped or passes on all platforms.</div>';
1758
1759 var html = '';
1760 var shownBuilders = [];
1761 for (var j = 0; j < testResults.length; j++) {
1762 shownBuilders.push(testResults[j].builder);
1763 html += htmlForSingleTestRow(testResults[j]);
1764 }
1765
1766 var skippedBuilders = []
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001767 for (builder in currentBuilders()) {
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001768 if (shownBuilders.indexOf(builder) == -1)
1769 skippedBuilders.push(builder);
1770 }
1771
1772 var skippedBuildersHtml = '';
1773 if (skippedBuilders.length) {
1774 skippedBuildersHtml = '<div>The following builders either don\'t run this test (e.g. it\'s skipped) or all runs passed:</div>' +
1775 '<div class=skipped-builder-list><div class=skipped-builder>' + skippedBuilders.join('</div><div class=skipped-builder>') + '</div></div>';
1776 }
1777
1778 return htmlForTestTable(html) + skippedBuildersHtml;
1779}
1780
1781function htmlForIndividualTestOnAllBuildersWithResultsLinks(test)
1782{
1783 processTestRunsForAllBuilders();
1784
1785 var testResults = g_testToResultsMap[test];
1786 var html = '';
1787 html += htmlForIndividualTestOnAllBuilders(test);
1788
1789 html += '<div class=expectations test=' + test + '><div>' +
1790 linkHTMLToToggleState('showExpectations', 'results')
1791
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001792 if (g_history.isLayoutTestResults() || g_history.isGPUTestResults()) {
1793 if (g_history.isLayoutTestResults())
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001794 html += ' | ' + linkHTMLToToggleState('showLargeExpectations', 'large thumbnails');
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001795 html += ' | <b>Only shows actual results/diffs from the most recent *failure* on each bot.</b>';
1796 } else {
1797 html += ' | <span>Results height:<input ' +
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001798 'onchange="g_history.setQueryParameter(\'resultsHeight\',this.value)" value="' +
1799 g_history.dashboardSpecificState.resultsHeight + '" style="width:2.5em">px</span>';
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001800 }
1801 html += '</div></div>';
1802 return html;
1803}
1804
1805function getExpectationsContainer(expectationsContainers, parentContainer, expectationsType)
1806{
1807 if (!expectationsContainers[expectationsType]) {
1808 var container = document.createElement('div');
1809 container.className = 'expectations-container';
1810 parentContainer.appendChild(container);
1811 expectationsContainers[expectationsType] = container;
1812 }
1813 return expectationsContainers[expectationsType];
1814}
1815
1816function ensureTrailingSlash(path)
1817{
1818 if (path.match(/\/$/))
1819 return path;
1820 return path + '/';
1821}
1822
1823function maybeAddPngChecksum(expectationDiv, pngUrl)
1824{
1825 // pngUrl gets served from the browser cache since we just loaded it in an
1826 // <img> tag.
1827 loader.request(pngUrl,
1828 function(xhr) {
1829 // Convert the first 2k of the response to a byte string.
1830 var bytes = xhr.responseText.substring(0, 2048);
1831 for (var position = 0; position < bytes.length; ++position)
1832 bytes[position] = bytes[position] & 0xff;
1833
1834 // Look for the comment.
1835 var commentKey = 'tEXtchecksum\x00';
1836 var checksumPosition = bytes.indexOf(commentKey);
1837 if (checksumPosition == -1)
1838 return;
1839
1840 var checksum = bytes.substring(checksumPosition + commentKey.length, checksumPosition + commentKey.length + 32);
1841 var checksumContainer = document.createElement('span');
1842 checksumContainer.innerText = 'Embedded checksum: ' + checksum;
1843 checksumContainer.setAttribute('class', 'pngchecksum');
1844 expectationDiv.parentNode.appendChild(checksumContainer);
1845 },
1846 function(xhr) {},
1847 true);
1848}
1849
1850// Adds a specific expectation. If it's an image, it's only added on the
1851// image's onload handler. If it's a text file, then a script tag is appended
1852// as a hack to see if the file 404s (necessary since it's cross-domain).
1853// Once all the expectations for a specific type have loaded or errored
1854// (e.g. all the text results), then we go through and identify which platform
1855// uses which expectation.
1856//
1857// @param {Object} expectationsContainers Map from expectations type to
1858// container DIV.
1859// @param {Element} parentContainer Container element for
1860// expectationsContainer divs.
1861// @param {string} platform Platform string. Empty string for non-platform
1862// specific expectations.
1863// @param {string} path Relative path to the expectation.
1864// @param {string} base Base path for the expectation URL.
1865// @param {string} opt_builder Builder whose actual results this expectation
1866// points to.
1867// @param {string} opt_suite "virtual suite" that the test belongs to, if any.
1868function addExpectationItem(expectationsContainers, parentContainer, platform, path, base, opt_builder, opt_suite)
1869{
1870 var parts = path.split('.')
1871 var fileExtension = parts[parts.length - 1];
1872 if (fileExtension == 'html')
1873 fileExtension = 'txt';
1874
1875 var container = getExpectationsContainer(expectationsContainers, parentContainer, fileExtension);
1876 var isImage = path.match(/\.png$/);
1877
1878 // FIXME: Stop using script tags once all the places we pull from support CORS.
1879 var platformPart = platform ? ensureTrailingSlash(platform) : '';
1880 var suitePart = opt_suite ? ensureTrailingSlash(opt_suite) : '';
1881
1882 var childContainer = document.createElement('span');
1883 childContainer.className = 'unloaded';
1884
1885 var appendExpectationsItem = function(item) {
1886 childContainer.appendChild(expectationsTitle(platformPart + suitePart, path, opt_builder));
1887 childContainer.className = 'expectations-item';
1888 item.className = 'expectation ' + fileExtension;
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001889 if (g_history.dashboardSpecificState.showLargeExpectations)
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001890 item.className += ' large';
1891 childContainer.appendChild(item);
1892 handleFinishedLoadingExpectations(container);
1893 };
1894
1895 var url = base + platformPart + path;
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001896 if (isImage || !string.startsWith(base, 'http://svn.webkit.org')) {
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001897 var dummyNode = document.createElement(isImage ? 'img' : 'script');
1898 dummyNode.src = url;
1899 dummyNode.onload = function() {
1900 var item;
1901 if (isImage) {
1902 item = dummyNode;
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001903 if (string.startsWith(base, 'http://svn.webkit.org'))
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001904 maybeAddPngChecksum(item, url);
1905 } else {
1906 item = document.createElement('iframe');
1907 item.src = url;
1908 }
1909 appendExpectationsItem(item);
1910 }
1911 dummyNode.onerror = function() {
1912 childContainer.parentNode.removeChild(childContainer);
1913 handleFinishedLoadingExpectations(container);
1914 }
1915
1916 // Append script elements now so that they load. Images load without being
1917 // appended to the DOM.
1918 if (!isImage)
1919 childContainer.appendChild(dummyNode);
1920 } else {
1921 loader.request(url,
1922 function(xhr) {
1923 var item = document.createElement('pre');
1924 item.innerText = xhr.responseText;
1925 appendExpectationsItem(item);
1926 },
1927 function(xhr) {/* Do nothing on errors since they're expected */});
1928 }
1929
1930 container.appendChild(childContainer);
1931}
1932
1933
1934// Identifies which expectations are used on which platform once all the
1935// expectations of a given type have loaded (e.g. the container for png
1936// expectations for this test had no child elements with the class
1937// "unloaded").
1938//
1939// @param {string} container Element containing the expectations for a given
1940// test and a given type (e.g. png).
1941function handleFinishedLoadingExpectations(container)
1942{
1943 if (container.getElementsByClassName('unloaded').length)
1944 return;
1945
1946 var titles = container.getElementsByClassName('expectations-title');
1947 for (var platform in g_fallbacksMap) {
1948 var fallbacks = g_fallbacksMap[platform];
1949 var winner = null;
1950 var winningIndex = -1;
1951 for (var i = 0; i < titles.length; i++) {
1952 var title = titles[i];
1953
1954 if (!winner && title.platform == "") {
1955 winner = title;
1956 continue;
1957 }
1958
1959 var rawPlatform = title.platform && title.platform.replace('platform/', '');
1960 for (var j = 0; j < fallbacks.length; j++) {
1961 if ((winningIndex == -1 || winningIndex > j) && rawPlatform == fallbacks[j]) {
1962 winningIndex = j;
1963 winner = title;
1964 break;
1965 }
1966 }
1967 }
1968 if (winner)
1969 winner.getElementsByClassName('platforms')[0].innerHTML += '<div class=used-platform>' + platform + '</div>';
1970 else {
1971 console.log('No expectations identified for this test. This means ' +
1972 'there is a logic bug in the dashboard for which expectations a ' +
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +01001973 'platform uses or src.chromium.org is giving 5XXs.');
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001974 }
1975 }
1976
1977 consolidateUsedPlatforms(container);
1978}
1979
1980// Consolidate platforms when all sub-platforms for a given platform are represented.
1981// e.g., if all of the WIN- platforms are there, replace them with just WIN.
1982function consolidateUsedPlatforms(container)
1983{
1984 var allPlatforms = Object.keys(g_fallbacksMap);
1985
1986 var platformElements = container.getElementsByClassName('platforms');
1987 for (var i = 0, platformsLength = platformElements.length; i < platformsLength; i++) {
1988 var usedPlatforms = platformElements[i].getElementsByClassName('used-platform');
1989 if (!usedPlatforms.length)
1990 continue;
1991
1992 var platforms = {};
1993 platforms['MAC'] = {};
1994 platforms['WIN'] = {};
1995 platforms['LINUX'] = {};
1996 allPlatforms.forEach(function(platform) {
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001997 if (string.startsWith(platform, 'MAC'))
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001998 platforms['MAC'][platform] = 1;
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00001999 else if (string.startsWith(platform, 'WIN'))
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00002000 platforms['WIN'][platform] = 1;
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00002001 else if (string.startsWith(platform, 'LINUX'))
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00002002 platforms['LINUX'][platform] = 1;
2003 });
2004
2005 for (var j = 0, usedPlatformsLength = usedPlatforms.length; j < usedPlatformsLength; j++) {
2006 for (var platform in platforms)
2007 delete platforms[platform][usedPlatforms[j].textContent];
2008 }
2009
2010 for (var platform in platforms) {
2011 if (!Object.keys(platforms[platform]).length) {
2012 var nodesToRemove = [];
2013 for (var j = 0, usedPlatformsLength = usedPlatforms.length; j < usedPlatformsLength; j++) {
2014 var usedPlatform = usedPlatforms[j];
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00002015 if (string.startsWith(usedPlatform.textContent, platform))
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00002016 nodesToRemove.push(usedPlatform);
2017 }
2018
2019 nodesToRemove.forEach(function(element) { element.parentNode.removeChild(element); });
2020 platformElements[i].insertAdjacentHTML('afterBegin', '<div class=used-platform>' + platform + '</div>');
2021 }
2022 }
2023 }
2024}
2025
2026function addExpectations(expectationsContainers, container, base,
2027 platform, text, png, reftest_html_file, reftest_mismatch_html_file, suite)
2028{
2029 var builder = '';
2030 addExpectationItem(expectationsContainers, container, platform, text, base, builder, suite);
2031 addExpectationItem(expectationsContainers, container, platform, png, base, builder, suite);
2032 addExpectationItem(expectationsContainers, container, platform, reftest_html_file, base, builder, suite);
2033 addExpectationItem(expectationsContainers, container, platform, reftest_mismatch_html_file, base, builder, suite);
2034}
2035
2036function expectationsTitle(platform, path, builder)
2037{
2038 var header = document.createElement('h3');
2039 header.className = 'expectations-title';
2040
2041 var innerHTML;
2042 if (builder) {
2043 var resultsType;
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00002044 if (string.endsWith(path, '-crash-log.txt'))
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00002045 resultsType = 'STACKTRACE';
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00002046 else if (string.endsWith(path, '-actual.txt') || string.endsWith(path, '-actual.png'))
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00002047 resultsType = 'ACTUAL RESULTS';
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00002048 else if (string.endsWith(path, '-wdiff.html'))
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00002049 resultsType = 'WDIFF';
2050 else
2051 resultsType = 'DIFF';
2052
2053 innerHTML = resultsType + ': ' + builder;
2054 } else if (platform === "") {
2055 var parts = path.split('/');
2056 innerHTML = parts[parts.length - 1];
2057 } else
2058 innerHTML = platform || path;
2059
2060 header.innerHTML = '<div class=title>' + innerHTML +
2061 '</div><div style="float:left">&nbsp;</div>' +
2062 '<div class=platforms style="float:right"></div>';
2063 header.platform = platform;
2064 return header;
2065}
2066
2067function loadExpectations(expectationsContainer)
2068{
2069 var test = expectationsContainer.getAttribute('test');
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00002070 if (g_history.isLayoutTestResults())
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00002071 loadExpectationsLayoutTests(test, expectationsContainer);
2072 else {
2073 var results = g_testToResultsMap[test];
2074 for (var i = 0; i < results.length; i++)
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00002075 if (g_history.isGPUTestResults())
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00002076 loadGPUResultsForBuilder(results[i].builder, test, expectationsContainer);
2077 else
2078 loadNonWebKitResultsForBuilder(results[i].builder, test, expectationsContainer);
2079 }
2080}
2081
2082function gpuResultsPath(chromeRevision, builder)
2083{
2084 return chromeRevision + '_' + builder.replace(/[^A-Za-z0-9]+/g, '_');
2085}
2086
2087function loadGPUResultsForBuilder(builder, test, expectationsContainer)
2088{
2089 var container = document.createElement('div');
2090 container.className = 'expectations-container';
2091 container.innerHTML = '<div><b>' + builder + '</b></div>';
2092 expectationsContainer.appendChild(container);
2093
2094 var failureIndex = indexesForFailures(builder, test)[0];
2095
2096 var buildNumber = g_resultsByBuilder[builder].buildNumbers[failureIndex];
2097 var pathToLog = builderMaster(builder).logPath(builder, buildNumber) + pathToFailureLog(test);
2098
2099 var chromeRevision = g_resultsByBuilder[builder].chromeRevision[failureIndex];
2100 var resultsUrl = GPU_RESULTS_BASE_PATH + gpuResultsPath(chromeRevision, builder);
2101 var filename = test.split(/\./)[1] + '.png';
2102
2103 appendNonWebKitResults(container, pathToLog, 'non-webkit-results');
2104 appendNonWebKitResults(container, resultsUrl + '/gen/' + filename, 'gpu-test-results', 'Generated');
2105 appendNonWebKitResults(container, resultsUrl + '/ref/' + filename, 'gpu-test-results', 'Reference');
2106 appendNonWebKitResults(container, resultsUrl + '/diff/' + filename, 'gpu-test-results', 'Diff');
2107}
2108
2109function loadNonWebKitResultsForBuilder(builder, test, expectationsContainer)
2110{
2111 var failureIndexes = indexesForFailures(builder, test);
2112 var container = document.createElement('div');
2113 container.innerHTML = '<div><b>' + builder + '</b></div>';
2114 expectationsContainer.appendChild(container);
2115 for (var i = 0; i < failureIndexes.length; i++) {
2116 // FIXME: This doesn't seem to work anymore. Did the paths change?
2117 // Once that's resolved, see if we need to try each GTEST_MODIFIERS prefix as well.
2118 var buildNumber = g_resultsByBuilder[builder].buildNumbers[failureIndexes[i]];
2119 var pathToLog = builderMaster(builder).logPath(builder, buildNumber) + pathToFailureLog(test);
2120 appendNonWebKitResults(container, pathToLog, 'non-webkit-results');
2121 }
2122}
2123
2124function appendNonWebKitResults(container, url, itemClassName, opt_title)
2125{
2126 // Use a script tag to detect whether the URL 404s.
2127 // Need to use a script tag since the URL is cross-domain.
2128 var dummyNode = document.createElement('script');
2129 dummyNode.src = url;
2130
2131 dummyNode.onload = function() {
2132 var item = document.createElement('iframe');
2133 item.src = dummyNode.src;
2134 item.className = itemClassName;
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00002135 item.style.height = g_history.dashboardSpecificState.resultsHeight + 'px';
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00002136
2137 if (opt_title) {
2138 var childContainer = document.createElement('div');
2139 childContainer.style.display = 'inline-block';
2140 var title = document.createElement('div');
2141 title.textContent = opt_title;
2142 childContainer.appendChild(title);
2143 childContainer.appendChild(item);
2144 container.replaceChild(childContainer, dummyNode);
2145 } else
2146 container.replaceChild(item, dummyNode);
2147 }
2148 dummyNode.onerror = function() {
2149 container.removeChild(dummyNode);
2150 }
2151
2152 container.appendChild(dummyNode);
2153}
2154
2155function buildInfoForRevision(builder, revision)
2156{
2157 var revisions = g_resultsByBuilder[builder].webkitRevision;
2158 var revisionStart = 0, revisionEnd = 0, buildNumber = 0;
2159 for (var i = 0; i < revisions.length; i++) {
2160 if (revision > revisions[i]) {
2161 revisionStart = revisions[i - 1];
2162 revisionEnd = revisions[i];
2163 buildNumber = g_resultsByBuilder[builder].buildNumbers[i - 1];
2164 break;
2165 }
2166 }
2167
2168 if (revisionEnd)
2169 revisionEnd++;
2170 else
2171 revisionEnd = '';
2172
2173 return {revisionStart: revisionStart, revisionEnd: revisionEnd, buildNumber: buildNumber};
2174}
2175
2176function lookupVirtualTestSuite(test) {
2177 for (var suite in VIRTUAL_SUITES) {
2178 if (test.indexOf(suite) != -1)
2179 return suite;
2180 }
2181 return '';
2182}
2183
2184function baseTest(test, suite) {
2185 base = VIRTUAL_SUITES[suite];
2186 return base ? test.replace(suite, base) : test;
2187}
2188
2189function loadBaselinesForTest(expectationsContainers, expectationsContainer, test) {
2190 var testWithoutSuffix = test.substring(0, test.lastIndexOf('.'));
2191 var text = testWithoutSuffix + "-expected.txt";
2192 var png = testWithoutSuffix + "-expected.png";
2193 var reftest_html_file = testWithoutSuffix + "-expected.html";
2194 var reftest_mismatch_html_file = testWithoutSuffix + "-expected-mismatch.html";
2195 var suite = lookupVirtualTestSuite(test);
2196
2197 if (!suite)
2198 addExpectationItem(expectationsContainers, expectationsContainer, null, test, TEST_URL_BASE_PATH);
2199
2200 addExpectations(expectationsContainers, expectationsContainer,
2201 TEST_URL_BASE_PATH, '', text, png, reftest_html_file, reftest_mismatch_html_file, suite);
2202
2203 var fallbacks = allFallbacks();
2204 for (var i = 0; i < fallbacks.length; i++) {
2205 var fallback = 'platform/' + fallbacks[i];
2206 addExpectations(expectationsContainers, expectationsContainer, TEST_URL_BASE_PATH, fallback, text, png,
2207 reftest_html_file, reftest_mismatch_html_file, suite);
2208 }
2209
2210 if (suite)
2211 loadBaselinesForTest(expectationsContainers, expectationsContainer, baseTest(test, suite));
2212}
2213
2214function loadExpectationsLayoutTests(test, expectationsContainer)
2215{
2216 // Map from file extension to container div for expectations of that type.
2217 var expectationsContainers = {};
2218
2219 var revisionContainer = document.createElement('div');
2220 revisionContainer.textContent = "Showing results for: "
2221 expectationsContainer.appendChild(revisionContainer);
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00002222 loadBaselinesForTest(expectationsContainers, expectationsContainer, test);
2223
2224 var testWithoutSuffix = test.substring(0, test.lastIndexOf('.'));
2225 var actualResultSuffixes = ['-actual.txt', '-actual.png', '-crash-log.txt', '-diff.txt', '-wdiff.html', '-diff.png'];
2226
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00002227 for (var builder in currentBuilders()) {
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +01002228 var actualResultsBase = TEST_RESULTS_BASE_PATH + currentBuilders()[builder] + '/results/layout-test-results/';
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00002229
2230 for (var i = 0; i < actualResultSuffixes.length; i++) {
2231 addExpectationItem(expectationsContainers, expectationsContainer, null,
2232 testWithoutSuffix + actualResultSuffixes[i], actualResultsBase, builder);
2233 }
2234 }
2235
2236 // Add a clearing element so floated elements don't bleed out of their
2237 // containing block.
2238 var br = document.createElement('br');
2239 br.style.clear = 'both';
2240 expectationsContainer.appendChild(br);
2241}
2242
2243var g_allFallbacks;
2244
2245// Returns the reverse sorted, deduped list of all platform fallback
2246// directories.
2247function allFallbacks()
2248{
2249 if (!g_allFallbacks) {
2250 var holder = {};
2251 for (var platform in g_fallbacksMap) {
2252 var fallbacks = g_fallbacksMap[platform];
2253 for (var i = 0; i < fallbacks.length; i++)
2254 holder[fallbacks[i]] = 1;
2255 }
2256
2257 g_allFallbacks = [];
2258 for (var fallback in holder)
2259 g_allFallbacks.push(fallback);
2260
2261 g_allFallbacks.sort(function(a, b) {
2262 if (a == b)
2263 return 0;
2264 return a < b;
2265 });
2266 }
2267 return g_allFallbacks;
2268}
2269
2270function appendExpectations()
2271{
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00002272 var expectations = g_history.dashboardSpecificState.showExpectations ? document.getElementsByClassName('expectations') : [];
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00002273 // Loading expectations is *very* slow. Use a large timeout to avoid
2274 // totally hanging the renderer.
2275 performChunkedAction(expectations, function(chunk) {
2276 for (var i = 0, len = chunk.length; i < len; i++)
2277 loadExpectations(chunk[i]);
2278 postHeightChangedMessage();
2279
2280 }, hideLoadingUI, 10000);
2281}
2282
2283function hideLoadingUI()
2284{
2285 var loadingDiv = $('loading-ui');
2286 if (loadingDiv)
2287 loadingDiv.style.display = 'none';
2288 postHeightChangedMessage();
2289}
2290
2291function generatePageForIndividualTests(tests)
2292{
2293 console.log('Number of tests: ' + tests.length);
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00002294 if (g_history.dashboardSpecificState.showChrome)
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00002295 appendHTML(htmlForNavBar());
2296 performChunkedAction(tests, function(chunk) {
2297 appendHTML(htmlForIndividualTests(chunk));
2298 }, appendExpectations, 500);
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00002299 if (g_history.dashboardSpecificState.showChrome)
2300 $('tests-input').value = g_history.dashboardSpecificState.tests;
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00002301}
2302
2303function performChunkedAction(tests, handleChunk, onComplete, timeout, opt_index) {
2304 var index = opt_index || 0;
2305 setTimeout(function() {
2306 var chunk = Array.prototype.slice.call(tests, index * CHUNK_SIZE, (index + 1) * CHUNK_SIZE);
2307 if (chunk.length) {
2308 handleChunk(chunk);
2309 performChunkedAction(tests, handleChunk, onComplete, timeout, ++index);
2310 } else
2311 onComplete();
2312 // No need for a timeout on the first chunked action.
2313 }, index ? timeout : 0);
2314}
2315
2316function htmlForIndividualTests(tests)
2317{
2318 var testsHTML = [];
2319 for (var i = 0; i < tests.length; i++) {
2320 var test = tests[i];
2321 var testNameHtml = '';
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00002322 if (g_history.dashboardSpecificState.showChrome || tests.length > 1) {
2323 if (g_history.isLayoutTestResults()) {
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00002324 var suite = lookupVirtualTestSuite(test);
2325 var base = suite ? baseTest(test, suite) : test;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +01002326 var versionControlUrl = TEST_URL_BASE_PATH_IN_VERSION_CONTROL + base;
2327 testNameHtml += '<h2>' + linkHTMLToOpenWindow(versionControlUrl, test) + '</h2>';
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00002328 } else
2329 testNameHtml += '<h2>' + test + '</h2>';
2330 }
2331
2332 testsHTML.push(testNameHtml + htmlForIndividualTestOnAllBuildersWithResultsLinks(test));
2333 }
2334 return testsHTML.join('<hr>');
2335}
2336
2337function htmlForNavBar()
2338{
2339 var extraHTML = '';
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00002340 var html = ui.html.testTypeSwitcher(false, extraHTML, isCrossBuilderView());
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00002341 html += '<div class=forms><form id=result-form ' +
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00002342 'onsubmit="g_history.setQueryParameter(\'result\', result.value);' +
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00002343 'return false;">Show all tests with result: ' +
2344 '<input name=result placeholder="e.g. CRASH" id=result-input>' +
2345 '</form><form id=tests-form ' +
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00002346 'onsubmit="g_history.setQueryParameter(\'tests\', tests.value);' +
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00002347 'return false;"><span>Show tests on all platforms: </span>' +
2348 '<input name=tests ' +
2349 'placeholder="Comma or space-separated list of tests or partial ' +
2350 'paths to show test results across all builders, e.g., ' +
2351 'foo/bar.html,foo/baz,domstorage" id=tests-input></form>' +
2352 '<span class=link onclick="showLegend()">Show legend [type ?]</span></div>';
2353 return html;
2354}
2355
2356function checkBoxToToggleState(key, text)
2357{
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00002358 var stateEnabled = g_history.dashboardSpecificState[key];
2359 return '<label><input type=checkbox ' + (stateEnabled ? 'checked ' : '') + 'onclick="g_history.setQueryParameter(\'' + key + '\', ' + !stateEnabled + ')">' + text + '</label> ';
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00002360}
2361
2362function linkHTMLToToggleState(key, linkText)
2363{
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00002364 var stateEnabled = g_history.dashboardSpecificState[key];
2365 return '<span class=link onclick="g_history.setQueryParameter(\'' + key + '\', ' + !stateEnabled + ')">' + (stateEnabled ? 'Hide' : 'Show') + ' ' + linkText + '</span>';
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00002366}
2367
2368function headerForTestTableHtml()
2369{
2370 return '<h2 style="display:inline-block">Failing tests</h2>' +
2371 checkBoxToToggleState('showWontFixSkip', 'WONTFIX/SKIP') +
2372 checkBoxToToggleState('showCorrectExpectations', 'tests with correct expectations') +
2373 checkBoxToToggleState('showWrongExpectations', 'tests with wrong expectations') +
2374 checkBoxToToggleState('showFlaky', 'flaky') +
2375 checkBoxToToggleState('showSlow', 'slow');
2376}
2377
2378function generatePageForBuilder(builderName)
2379{
2380 processTestRunsForBuilder(builderName);
2381
2382 var results = g_perBuilderFailures[builderName];
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00002383 sortTests(results, g_history.dashboardSpecificState.sortColumn, g_history.dashboardSpecificState.sortOrder);
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00002384
2385 var testsHTML = '';
2386 if (results.length) {
2387 var tableRowsHTML = '';
2388 for (var i = 0; i < results.length; i++)
2389 tableRowsHTML += htmlForSingleTestRow(results[i])
2390 testsHTML = htmlForTestTable(tableRowsHTML);
2391 } else {
2392 testsHTML = '<div>No tests found. ';
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00002393 if (g_history.isLayoutTestResults())
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00002394 testsHTML += 'Try showing tests with correct expectations.</div>';
2395 else
2396 testsHTML += 'This means no tests have failed!</div>';
2397 }
2398
2399 var html = htmlForNavBar();
2400
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00002401 if (g_history.isLayoutTestResults())
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00002402 html += htmlForTestsWithExpectationsButNoFailures(builderName) + headerForTestTableHtml();
2403
2404 html += '<br>' + testsHTML;
2405 appendHTML(html);
2406
2407 var ths = document.getElementsByTagName('th');
2408 for (var i = 0; i < ths.length; i++) {
2409 ths[i].addEventListener('click', changeSort, false);
2410 ths[i].className = "sortable";
2411 }
2412
2413 hideLoadingUI();
2414}
2415
2416var VALID_KEYS_FOR_CROSS_BUILDER_VIEW = {
2417 tests: 1,
2418 result: 1,
2419 showChrome: 1,
2420 showExpectations: 1,
2421 showLargeExpectations: 1,
2422 legacyExpectationsSemantics: 1,
2423 resultsHeight: 1,
2424 revision: 1
2425};
2426
2427function isInvalidKeyForCrossBuilderView(key)
2428{
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00002429 return !(key in VALID_KEYS_FOR_CROSS_BUILDER_VIEW) && !(key in history.DEFAULT_CROSS_DASHBOARD_STATE_VALUES);
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00002430}
2431
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00002432function hideLegend()
2433{
2434 var legend = $('legend');
2435 if (legend)
2436 legend.parentNode.removeChild(legend);
2437}
2438
2439var g_fallbacksMap = {};
2440g_fallbacksMap['WIN-XP'] = ['chromium-win-xp', 'chromium-win', 'chromium'];
2441g_fallbacksMap['WIN-7'] = ['chromium-win', 'chromium'];
2442g_fallbacksMap['MAC-SNOWLEOPARD'] = ['chromium-mac-snowleopard', 'chromium-mac', 'chromium'];
2443g_fallbacksMap['MAC-LION'] = ['chromium-mac', 'chromium'];
2444g_fallbacksMap['LINUX-32'] = ['chromium-linux-x86', 'chromium-linux', 'chromium-win', 'chromium'];
2445g_fallbacksMap['LINUX-64'] = ['chromium-linux', 'chromium-win', 'chromium'];
2446
2447function htmlForFallbackHelp(fallbacks)
2448{
2449 return '<ol class=fallback-list><li>' + fallbacks.join('</li><li>') + '</li></ol>';
2450}
2451
2452function showLegend()
2453{
2454 var legend = $('legend');
2455 if (!legend) {
2456 legend = document.createElement('div');
2457 legend.id = 'legend';
2458 document.body.appendChild(legend);
2459 }
2460
2461 var html = '<div id=legend-toggle onclick="hideLegend()">Hide ' +
2462 'legend [type esc]</div><div id=legend-contents>';
2463 for (var expectation in expectationsMap())
2464 html += '<div class=' + expectation + '>' + expectationsMap()[expectation] + '</div>';
2465
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00002466 if (g_history.isLayoutTestResults()) {
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00002467 html += '</div><br style="clear:both">' +
2468 '</div><h3>Test expectatons fallback order.</h3>';
2469
2470 for (var platform in g_fallbacksMap)
2471 html += '<div class=fallback-header>' + platform + '</div>' + htmlForFallbackHelp(g_fallbacksMap[platform]);
2472
2473 html += '<div>TIMES:</div>' +
2474 htmlForSlowTimes(MIN_SECONDS_FOR_SLOW_TEST) +
2475 '<div>DEBUG TIMES:</div>' +
2476 htmlForSlowTimes(MIN_SECONDS_FOR_SLOW_TEST_DEBUG);
2477 }
2478
2479 legend.innerHTML = html;
2480}
2481
2482function htmlForSlowTimes(minTime)
2483{
2484 return '<ul><li>&lt;1 second == !SLOW</li><li>&gt;1 second && &lt;' +
2485 minTime + ' seconds == SLOW || !SLOW is fine</li><li>&gt;' +
2486 minTime + ' seconds == SLOW</li></ul>';
2487}
2488
2489function postHeightChangedMessage()
2490{
2491 if (window == parent)
2492 return;
2493
2494 var root = document.documentElement;
2495 var height = root.offsetHeight;
2496 if (root.offsetWidth < root.scrollWidth) {
2497 // We have a horizontal scrollbar. Include it in the height.
2498 var dummyNode = document.createElement('div');
2499 dummyNode.style.overflow = 'scroll';
2500 document.body.appendChild(dummyNode);
2501 var scrollbarWidth = dummyNode.offsetHeight - dummyNode.clientHeight;
2502 document.body.removeChild(dummyNode);
2503 height += scrollbarWidth;
2504 }
2505 parent.postMessage({command: 'heightChanged', height: height}, '*')
2506}
2507
2508if (window != parent)
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00002509 window.addEventListener('blur', ui.popup.hide);
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00002510
2511document.addEventListener('keydown', function(e) {
2512 if (e.keyIdentifier == 'U+003F' || e.keyIdentifier == 'U+00BF') {
2513 // WebKit MAC retursn 3F. WebKit WIN returns BF. This is a bug!
2514 // ? key
2515 showLegend();
2516 } else if (e.keyIdentifier == 'U+001B') {
2517 // escape key
2518 hideLegend();
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00002519 ui.popup.hide();
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00002520 }
2521}, false);
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00002522
2523window.addEventListener('load', function() {
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +01002524 resourceLoader = new loader.Loader();
Torne (Richard Coles)926b0012013-03-28 15:32:48 +00002525 resourceLoader.load();
2526}, false);