Upstream version 10.38.222.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Tools / TestResultServer / static-dashboards / builders.js
1 // 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 function LOAD_BUILDBOT_DATA(builderData)
30 {
31     builders.masters = {};
32     builders.urlNameToMasterName = {};
33     var groups = {};
34     var testTypes = {};
35     var testTypesThatDoNotUpload = {};
36     builders.noUploadTestTypes = builderData['no_upload_test_types']
37     builderData['masters'].forEach(function(master) {
38         builders.urlNameToMasterName[master.url_name] = master.name;
39         builders.masters[master.name] = new builders.BuilderMaster(master);
40
41         master.groups.forEach(function(group) { groups[group] = true; });
42
43         Object.keys(master.tests).forEach(function(testType) {
44             if (builders.testTypeUploadsToFlakinessDashboardServer(testType))
45                 testTypes[testType] = true;
46             else
47                 testTypesThatDoNotUpload[testType] = true;
48         });
49     });
50     builders.groups = Object.keys(groups);
51     builders.groups.sort();
52     builders.testTypes = Object.keys(testTypes);
53     builders.testTypes.sort();
54     // FIXME: Expose this in the flakiness dashboard UI and give a clear error message
55     // pointing to a bug about getting the test type in question uploading results.
56     builders.testTypesThatDoNotUpload = Object.keys(testTypesThatDoNotUpload);
57     builders.testTypesThatDoNotUpload.sort();
58 }
59
60 var builders = builders || {};
61
62 (function() {
63
64 builders.testTypeUploadsToFlakinessDashboardServer = function(testType)
65 {
66     for (var i = 0; i < builders.noUploadTestTypes.length; i++) {
67         if (string.contains(testType, builders.noUploadTestTypes[i]))
68             return false;
69     }
70     return true;
71 }
72
73 var currentBuilderGroup = {};
74 var testTypesThatRunToTBlinkBots = ['layout-tests', 'webkit_unit_tests'];
75
76 builders.getBuilderGroup = function(groupName, testType)
77 {
78     if (!builders in currentBuilderGroup) {
79         currentBuilderGroup = builders.loadBuildersList(groupName, testType);
80     }
81     return currentBuilderGroup;
82 }
83
84 function isChromiumWebkitTipOfTreeTestRunner(builder)
85 {
86     return !isChromiumWebkitDepsTestRunner(builder);
87 }
88
89 function isChromiumWebkitDepsTestRunner(builder)
90 {
91     return builder.indexOf('(deps)') != -1;
92 }
93
94 builders._builderFilter = function(groupName, masterName, testType)
95 {
96     if (testTypesThatRunToTBlinkBots.indexOf(testType) == -1) {
97         if (masterName == 'ChromiumWebkit' && groupName != '@ToT Blink')
98             return function() { return false };
99         return null;
100     }
101
102     if (groupName == '@ToT Blink')
103         return isChromiumWebkitTipOfTreeTestRunner;
104
105     if (groupName == '@ToT Chromium')
106         return isChromiumWebkitDepsTestRunner;
107
108     return null;
109 }
110
111 // FIXME: When we change to show multiple groups at once, this will need to
112 // change to key off groupName and builderName.
113 builders.master = function(builderName)
114 {
115     return builders.builderToMaster[builderName];
116 }
117
118 builders.loadBuildersList = function(groupName, testType)
119 {
120     if (!groupName || !testType) {
121         console.warn("Group name and/or test type were empty.");
122         return new builders.BuilderGroup(false);
123     }
124     var builderGroup = new builders.BuilderGroup(groupName == '@ToT Blink');
125     builders.builderToMaster = {};
126
127     for (masterName in builders.masters) {
128         if (!builders.masters[masterName])
129             continue;
130
131         var master = builders.masters[masterName];
132         var hasTest = testType in master.tests;
133         var isInGroup = master.groups.indexOf(groupName) != -1;
134
135         if (hasTest && isInGroup) {
136             var builderList = master.tests[testType].builders;
137             var builderFilter = builders._builderFilter(groupName, masterName, testType);
138             if (builderFilter)
139                 builderList = builderList.filter(builderFilter);
140             builderGroup.append(builderList);
141
142             builderList.forEach(function (builderName) {
143                 builders.builderToMaster[builderName] = master;
144             });
145         }
146     }
147
148     currentBuilderGroup = builderGroup;
149     return currentBuilderGroup;
150 }
151
152 builders.getAllGroupNames = function()
153 {
154     return builders.groups;
155 }
156
157 builders.BuilderMaster = function(master_data)
158 {
159     this.name = master_data.name;
160     this.basePath = 'http://build.chromium.org/p/' + master_data.url_name;
161     this.tests = master_data.tests;
162     this.groups = master_data.groups;
163 }
164
165 builders.BuilderMaster.prototype = {
166     logPath: function(builder, buildNumber)
167     {
168         return this.builderPath(builder) + '/builds/' + buildNumber;
169     },
170     builderPath: function(builder)
171     {
172         return this.basePath + '/builders/' + builder;
173     },
174     builderJsonPath: function()
175     {
176         return this.basePath + '/json/builders';
177     },
178 }
179
180 builders.BuilderGroup = function(isToTBlink)
181 {
182     this.isToTBlink = isToTBlink;
183     // Map of builderName (the name shown in the waterfall) to builderPath (the
184     // path used in the builder's URL)
185     this.builders = {};
186 }
187
188 builders.BuilderGroup.prototype = {
189     append: function(builders) {
190         builders.forEach(function(builderName) {
191             this.builders[builderName] = builderName.replace(/[ .()]/g, '_');
192         }, this);
193     },
194     defaultBuilder: function()
195     {
196         for (var builder in this.builders)
197             return builder;
198         console.error('There are no builders in this builder group.');
199     },
200     master: function()
201     {
202         return builders.master(this.defaultBuilder());
203     },
204 }
205
206 builders.groupNamesForTestType = function(testType)
207 {
208     var groupNames = [];
209     for (masterName in builders.masters) {
210         var master = builders.masters[masterName];
211         if (testType in master.tests) {
212             groupNames = groupNames.concat(master.groups);
213         }
214     }
215
216     if (groupNames.length == 0) {
217         console.error("The current test type wasn't present in any groups:", testType);
218         return groupNames;
219     }
220
221     var groupNames = groupNames.reduce(function(prev, curr) {
222         if (prev.indexOf(curr) == -1) {
223             prev.push(curr);
224         }
225         return prev;
226     }, []);
227
228     return groupNames;
229 }
230
231 })();