initial import
[vuplus_webkit] / Tools / BuildSlaveSupport / build.webkit.org-config / public_html / TestFailures / 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 kChromiumBuildBotURL = 'http://build.chromium.org/p/chromium.webkit';
31
32 var kUpdateStepName = 'update';
33 var kUpdateScriptsStepName = 'update_scripts';
34 var kCompileStepName = 'compile';
35
36 function urlForBuildInfo(builderName, buildNumber)
37 {
38     return kChromiumBuildBotURL + '/json/builders/' + encodeURIComponent(builderName) + '/builds/' + encodeURIComponent(buildNumber);
39 }
40
41 function isStepRequredForTestCoverage(step)
42 {
43     switch(step.name) {
44     case kUpdateStepName:
45     case kUpdateScriptsStepName:
46     case kCompileStepName:
47         return true;
48     default:
49         return false;
50     }
51 }
52
53 function didFail(step)
54 {
55     // FIXME: Is this the correct way to test for failure?
56     return step.results[0] > 0;
57 }
58
59 function didFailStepRequredForTestCoverage(buildInfo)
60 {
61     return buildInfo.steps.filter(isStepRequredForTestCoverage).filter(didFail).length > 0;
62 }
63
64 function mostRecentCompletedBuildNumber(individualBuilderStatus)
65 {
66     if (!individualBuilderStatus)
67         return null;
68
69     for (var i = individualBuilderStatus.cachedBuilds.length - 1; i >= 0; --i) {
70         var buildNumber = individualBuilderStatus.cachedBuilds[i];
71         if (individualBuilderStatus.currentBuilds.indexOf(buildNumber) == -1)
72             return buildNumber;
73     }
74
75     return null;
76 }
77
78 var g_buildInfoCache = new base.AsynchronousCache(function(key, callback) {
79     var explodedKey = key.split('\n');
80     net.get(urlForBuildInfo(explodedKey[0], explodedKey[1]), callback);
81 });
82
83 function fetchMostRecentBuildInfoByBuilder(callback)
84 {
85     var buildInfoByBuilder = {};
86     var builderNames = Object.keys(config.kBuilders);
87     var requestTracker = new base.RequestTracker(builderNames.length, callback, [buildInfoByBuilder]);
88     net.get(kChromiumBuildBotURL + '/json/builders', function(builderStatus) {
89         $.each(builderNames, function(index, builderName) {
90             var buildNumber = mostRecentCompletedBuildNumber(builderStatus[builderName]);
91             if (!buildNumber) {
92                 buildInfoByBuilder[builderName] = null;
93                 requestTracker.requestComplete();
94                 return;
95             }
96
97             g_buildInfoCache.get(builderName + '\n' + buildNumber, function(buildInfo) {
98                 buildInfoByBuilder[builderName] = buildInfo;
99                 requestTracker.requestComplete();
100             });
101         });
102     });
103 }
104
105 builders.buildersFailingStepRequredForTestCoverage = function(callback)
106 {
107     fetchMostRecentBuildInfoByBuilder(function(buildInfoByBuilder) {
108         var builderNameList = [];
109         $.each(buildInfoByBuilder, function(builderName, buildInfo) {
110             if (!buildInfo)
111                 return;
112             if (didFailStepRequredForTestCoverage(buildInfo))
113                 builderNameList.push(builderName);
114         });
115         callback(builderNameList);
116     });
117 };
118
119 })();