Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Tools / GardeningServer / scripts / builders.js
1 /*
2  * Copyright (C) 2011 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 var builders = builders || {};
27
28 (function() {
29
30 var kUpdateStepName = 'update';
31 var kUpdateScriptsStepName = 'update_scripts';
32 var kCompileStepName = 'compile';
33 var kWebKitTestsStepNames = ['webkit_tests', 'layout-test'];
34
35 var kCrashedOrHungOutputMarker = 'crashed or hung';
36
37 function urlForBuildInfo(builderName, buildNumber)
38 {
39     return config.buildConsoleURL + '/json/builders/' + encodeURIComponent(builderName) + '/builds/' + encodeURIComponent(buildNumber);
40 }
41
42 function didFail(step)
43 {
44     if (kWebKitTestsStepNames.indexOf(step.name) != -1) {
45         // run-webkit-tests fails to generate test coverage when it crashes or hangs.
46         // FIXME: Do build.webkit.org bots output this marker when the tests fail to run?
47         return step.text.indexOf(kCrashedOrHungOutputMarker) != -1;
48     }
49     // The first item in step.results is the success of the step:
50     // 0 == pass, 1 == warning, 2 == fail
51     return step.results[0] == 2;
52 }
53
54 function failingSteps(buildInfo)
55 {
56     return buildInfo.steps.filter(didFail);
57 }
58
59 function mostRecentCompletedBuildNumber(individualBuilderStatus)
60 {
61     if (!individualBuilderStatus)
62         return null;
63
64     for (var i = individualBuilderStatus.cachedBuilds.length - 1; i >= 0; --i) {
65         var buildNumber = individualBuilderStatus.cachedBuilds[i];
66         if (individualBuilderStatus.currentBuilds.indexOf(buildNumber) == -1)
67             return buildNumber;
68     }
69
70     return null;
71 }
72
73 var g_buildInfoCache = new base.AsynchronousCache(function(key, callback) {
74     var explodedKey = key.split('\n');
75     net.json(urlForBuildInfo(explodedKey[0], explodedKey[1]), callback);
76 });
77
78 builders.clearBuildInfoCache = function()
79 {
80     g_buildInfoCache.clear();
81 };
82
83 function fetchMostRecentBuildInfoByBuilder(callback)
84 {
85     net.json(config.buildConsoleURL + '/json/builders', function(builderStatus) {
86         var buildInfoByBuilder = {};
87         var builderNames = Object.keys(builderStatus);
88         var requestTracker = new base.RequestTracker(builderNames.length, callback, [buildInfoByBuilder]);
89         builderNames.forEach(function(builderName) {
90             if (!config.builderApplies(builderName)) {
91                 requestTracker.requestComplete();
92                 return;
93             }
94
95             var buildNumber = mostRecentCompletedBuildNumber(builderStatus[builderName]);
96             if (!buildNumber) {
97                 buildInfoByBuilder[builderName] = null;
98                 requestTracker.requestComplete();
99                 return;
100             }
101
102             g_buildInfoCache.get(builderName + '\n' + buildNumber, function(buildInfo) {
103                 buildInfoByBuilder[builderName] = buildInfo;
104                 requestTracker.requestComplete();
105             });
106         });
107     });
108 }
109
110 builders.buildersFailingNonLayoutTests = function(callback)
111 {
112     fetchMostRecentBuildInfoByBuilder(function(buildInfoByBuilder) {
113         var failureList = {};
114         $.each(buildInfoByBuilder, function(builderName, buildInfo) {
115             if (!buildInfo)
116                 return;
117             var failures = failingSteps(buildInfo);
118             if (failures.length)
119                 failureList[builderName] = failures.map(function(failure) { return failure.name; });
120         });
121         callback(failureList);
122     });
123 };
124
125 builders.mostRecentBuildForBuilder = function(builderName, callback) {
126     net.json(config.buildConsoleURL + '/json/builders/' + builderName, function(builderStatus) {
127         var cachedBuilds = builderStatus.cachedBuilds;
128         var mostRecentBuild = Math.max.apply(Math, cachedBuilds);
129         callback(mostRecentBuild);
130     });
131 };
132
133 })();