Merge pull request #10823 from adityamandaleeka/move_variable_handle_creation
[platform/upstream/coreclr.git] / netci.groovy
1 // Import the utility functionality.
2
3 import jobs.generation.*
4
5 // The input project name (e.g. dotnet/coreclr)
6 def project = GithubProject
7 // The input branch name (e.g. master)
8 def branch = GithubBranchName
9 def projectFolder = Utilities.getFolderName(project) + '/' + Utilities.getFolderName(branch)
10
11 // Create a folder for JIT stress jobs and associated folder views
12 folder('jitstress')
13 Utilities.addStandardFolderView(this, 'jitstress', project)
14
15 // Create a folder for testing via illink
16 folder('illink')
17 Utilities.addStandardFolderView(this, 'illink', project)
18
19 def static getOSGroup(def os) {
20     def osGroupMap = ['Ubuntu':'Linux',
21         'RHEL7.2': 'Linux',
22         'Ubuntu16.04': 'Linux',
23         'Ubuntu16.10': 'Linux',
24         'Debian8.4':'Linux',
25         'Fedora24':'Linux',
26         'OSX10.12':'OSX',
27         'Windows_NT':'Windows_NT',
28         'FreeBSD':'FreeBSD',
29         'CentOS7.1': 'Linux',
30         'OpenSUSE42.1': 'Linux',
31         'Tizen': 'Linux']
32     def osGroup = osGroupMap.get(os, null)
33     assert osGroup != null : "Could not find os group for ${os}"
34     return osGroupMap[os]
35 }
36
37 // We use this class (vs variables) so that the static functions can access data here.
38 class Constants {
39
40     // Innerloop build OS's
41     // The Windows_NT_BuildOnly OS is a way to speed up the Non-NT builds temporarily by avoiding
42     // test execution in the build flow runs.  It generates the exact same build
43     // as Windows_NT but without the tests.
44     def static osList = [
45                'Ubuntu',
46                'Debian8.4',
47                'OSX10.12',
48                'Windows_NT',
49                'Windows_NT_BuildOnly',
50                'FreeBSD',
51                'CentOS7.1',
52                'OpenSUSE42.1',
53                'RHEL7.2',
54                'Ubuntu16.04',
55                'Ubuntu16.10',
56                'Fedora24',
57                'Tizen']
58
59     def static crossList = ['Ubuntu', 'OSX10.12', 'CentOS7.1', 'RHEL7.2', 'Debian8.4']
60
61     // This is a set of JIT stress modes combined with the set of variables that
62     // need to be set to actually enable that stress mode.  The key of the map is the stress mode and
63     // the values are the environment variables
64     def static jitStressModeScenarios = [
65                'minopts'                        : ['COMPlus_JITMinOpts' : '1'],
66                'forcerelocs'                    : ['COMPlus_ForceRelocs' : '1'],
67                'jitstress1'                     : ['COMPlus_JitStress' : '1'],
68                'jitstress2'                     : ['COMPlus_JitStress' : '2'],
69                'jitstressregs1'                 : ['COMPlus_JitStressRegs' : '1'],
70                'jitstressregs2'                 : ['COMPlus_JitStressRegs' : '2'],
71                'jitstressregs3'                 : ['COMPlus_JitStressRegs' : '3'],
72                'jitstressregs4'                 : ['COMPlus_JitStressRegs' : '4'],
73                'jitstressregs8'                 : ['COMPlus_JitStressRegs' : '8'],
74                'jitstressregs0x10'              : ['COMPlus_JitStressRegs' : '0x10'],
75                'jitstressregs0x80'              : ['COMPlus_JitStressRegs' : '0x80'],
76                'jitstressregs0x1000'            : ['COMPlus_JitStressRegs' : '0x1000'],
77                'jitstress2_jitstressregs1'      : ['COMPlus_JitStress' : '2', 'COMPlus_JitStressRegs' : '1'],
78                'jitstress2_jitstressregs2'      : ['COMPlus_JitStress' : '2', 'COMPlus_JitStressRegs' : '2'],
79                'jitstress2_jitstressregs3'      : ['COMPlus_JitStress' : '2', 'COMPlus_JitStressRegs' : '3'],
80                'jitstress2_jitstressregs4'      : ['COMPlus_JitStress' : '2', 'COMPlus_JitStressRegs' : '4'],
81                'jitstress2_jitstressregs8'      : ['COMPlus_JitStress' : '2', 'COMPlus_JitStressRegs' : '8'],
82                'jitstress2_jitstressregs0x10'   : ['COMPlus_JitStress' : '2', 'COMPlus_JitStressRegs' : '0x10'],
83                'jitstress2_jitstressregs0x80'   : ['COMPlus_JitStress' : '2', 'COMPlus_JitStressRegs' : '0x80'],
84                'jitstress2_jitstressregs0x1000' : ['COMPlus_JitStress' : '2', 'COMPlus_JitStressRegs' : '0x1000'],
85                'tailcallstress'                 : ['COMPlus_TailcallStress' : '1'],
86                'jitsse2only'                    : ['COMPlus_EnableAVX' : '0', 'COMPlus_EnableSSE3_4' : '0'],
87                'corefx_baseline'                : [ : ], // corefx baseline
88                'corefx_minopts'                 : ['COMPlus_JITMinOpts' : '1'],
89                'corefx_jitstress1'              : ['COMPlus_JitStress' : '1'],
90                'corefx_jitstress2'              : ['COMPlus_JitStress' : '2'],
91                'corefx_jitstressregs1'          : ['COMPlus_JitStressRegs' : '1'],
92                'corefx_jitstressregs2'          : ['COMPlus_JitStressRegs' : '2'],
93                'corefx_jitstressregs3'          : ['COMPlus_JitStressRegs' : '3'],
94                'corefx_jitstressregs4'          : ['COMPlus_JitStressRegs' : '4'],
95                'corefx_jitstressregs8'          : ['COMPlus_JitStressRegs' : '8'],
96                'corefx_jitstressregs0x10'       : ['COMPlus_JitStressRegs' : '0x10'],
97                'corefx_jitstressregs0x80'       : ['COMPlus_JitStressRegs' : '0x80'],
98                'corefx_jitstressregs0x1000'     : ['COMPlus_JitStressRegs' : '0x1000'],
99                'gcstress0x3'                    : ['COMPlus_GCStress' : '0x3'],
100                'gcstress0xc'                    : ['COMPlus_GCStress' : '0xC'],
101                'zapdisable'                     : ['COMPlus_ZapDisable' : '1', 'COMPlus_ReadyToRun' : '0'],
102                'heapverify1'                    : ['COMPlus_HeapVerify' : '1'],
103                'gcstress0xc_zapdisable'             : ['COMPlus_GCStress' : '0xC', 'COMPlus_ZapDisable' : '1', 'COMPlus_ReadyToRun' : '0'],
104                'gcstress0xc_zapdisable_jitstress2'  : ['COMPlus_GCStress' : '0xC', 'COMPlus_ZapDisable' : '1', 'COMPlus_ReadyToRun' : '0', 'COMPlus_JitStress'  : '2'],
105                'gcstress0xc_zapdisable_heapverify1' : ['COMPlus_GCStress' : '0xC', 'COMPlus_ZapDisable' : '1', 'COMPlus_ReadyToRun' : '0', 'COMPlus_HeapVerify' : '1'],
106                'gcstress0xc_jitstress1'             : ['COMPlus_GCStress' : '0xC', 'COMPlus_JitStress'  : '1'],
107                'gcstress0xc_jitstress2'             : ['COMPlus_GCStress' : '0xC', 'COMPlus_JitStress'  : '2'],
108                'gcstress0xc_minopts_heapverify1'    : ['COMPlus_GCStress' : '0xC', 'COMPlus_JITMinOpts' : '1', 'COMPlus_HeapVerify' : '1']
109                ]
110
111     // This is a set of r2r jit stress scenarios
112     def static r2rJitStressScenarios = [
113                'r2r_jitstress1',
114                'r2r_jitstress2',
115                'r2r_jitstressregs1',
116                'r2r_jitstressregs2',
117                'r2r_jitstressregs3',
118                'r2r_jitstressregs4',
119                'r2r_jitstressregs8',
120                'r2r_jitstressregs0x10',
121                'r2r_jitstressregs0x80',
122                'r2r_jitstressregs0x1000',
123                'r2r_jitminopts',
124                'r2r_jitforcerelocs']
125
126     // This is the basic set of scenarios
127     def static basicScenarios = [
128                'default',
129                'pri1',
130                'ilrt',
131                'r2r',
132                'pri1r2r',
133                'gcstress15_pri1r2r',
134                'longgc',
135                'coverage',
136                'formatting',
137                'gcsimulator',
138                'jitdiff',              
139                'standalone_gc',
140                'illink'] + r2rJitStressScenarios
141
142     def static configurationList = ['Debug', 'Checked', 'Release']
143
144     // This is the set of architectures
145     def static architectureList = ['arm', 'arm64', 'x64', 'x86']
146 }
147
148 def static setMachineAffinity(def job, def os, def architecture) {
149     if (architecture == 'arm64' && os == 'Windows_NT') {
150         Utilities.setMachineAffinity(job, os, 'latest-arm64');
151     } else if (architecture == 'arm64' && os == 'Ubuntu') {
152         Utilities.setMachineAffinity(job, os, 'arm-cross-latest');
153     } else if ((architecture == 'arm') && (os == 'Ubuntu' || os == 'Ubuntu16.04' || os == 'Tizen')) {
154         Utilities.setMachineAffinity(job, 'Ubuntu', 'arm-cross-latest');
155     } else {
156         Utilities.setMachineAffinity(job, os, 'latest-or-auto');
157     }
158 }
159
160 def static isJITStressJob(def scenario) {
161     return Constants.jitStressModeScenarios.containsKey(scenario) ||
162            (Constants.r2rJitStressScenarios.indexOf(scenario) != -1)
163 }
164
165 def static isGCStressRelatedTesting(def scenario) {
166     // The 'gcstress15_pri1r2r' scenario is a basic scenario.
167     // Detect it and make it a GCStress related.
168     if (scenario == 'gcstress15_pri1r2r')
169     {
170         return true;
171     }
172
173     def gcStressTestEnvVars = [ 'COMPlus_GCStress', 'COMPlus_ZapDisable', 'COMPlus_HeapVerify']
174     def scenarioName = scenario.toLowerCase()
175     def isGCStressTesting = false
176     Constants.jitStressModeScenarios[scenario].each{ k, v ->
177         if (k in gcStressTestEnvVars) {
178             isGCStressTesting = true;
179         }
180     }
181     return isGCStressTesting
182 }
183
184 def static isCorefxTesting(def scenario) {
185     def corefx_prefix = 'corefx_'
186     if (scenario.length() < corefx_prefix.length()) {
187         return false
188     }
189     return scenario.substring(0,corefx_prefix.length()) == corefx_prefix
190 }
191
192 def static isR2R(def scenario) {
193     return (scenario == 'r2r' || scenario == 'pri1r2r')
194 }
195
196 def static isCoverage(def scenario) {
197     return (scenario == 'coverage')
198 }
199
200 def static isLongGc(def scenario) {
201     return (scenario == 'longgc' || scenario == 'gcsimulator')
202 }
203
204 def static isJitDiff(def scenario) {
205     return (scenario == 'jitdiff')
206 }
207
208 def static setTestJobTimeOut(newJob, scenario) {
209     if (isGCStressRelatedTesting(scenario)) {
210         Utilities.setJobTimeout(newJob, 4320)
211     }
212     else if (isCorefxTesting(scenario)) {
213         Utilities.setJobTimeout(newJob, 360)
214     }
215     else if (Constants.jitStressModeScenarios.containsKey(scenario)) {
216         Utilities.setJobTimeout(newJob, 240)
217     }
218     else if (isR2R(scenario)) {
219         Utilities.setJobTimeout(newJob, 240)
220     }
221     else if (isCoverage(scenario)) {
222         Utilities.setJobTimeout(newJob, 1440)
223     }
224     else if (isLongGc(scenario)) {
225         Utilities.setJobTimeout(newJob, 1440)
226     }
227     else if (isJitDiff(scenario)) {
228         Utilities.setJobTimeout(newJob, 240)
229     }
230     // Non-test jobs use the default timeout value.
231 }
232
233 def static getJobFolder(def scenario) {
234     if (isJITStressJob(scenario)) {
235         return 'jitstress'
236     }
237     if (scenario == 'illink') {
238         return 'illink'
239     }
240     return ''
241 }
242
243 def static getStressModeDisplayName(def scenario) {
244     def displayStr = ''
245     Constants.jitStressModeScenarios[scenario].each{ k, v ->
246         def prefixLength = 'COMPlus_'.length()
247         if (k.length() >= prefixLength) {
248             def modeName = k.substring(prefixLength, k.length())
249             displayStr += ' ' + modeName + '=' + v
250         }
251     }
252     return displayStr
253 }
254
255 def static getR2RStressModeDisplayName(def scenario) {
256     // Assume the scenario name is one from the r2rJitStressScenarios list, and remove its
257     // "r2r_" prefix.
258     def displayStr = scenario
259     def prefixLength = 'r2r_'.length()
260     if (displayStr.length() >= prefixLength) {
261         displayStr = displayStr.substring(prefixLength, displayStr.length())
262     }
263     return displayStr
264 }
265
266 // Generates the string for creating a file that sets environment variables
267 // that makes it possible to run stress modes.  Writes the script to the file
268 // specified by the stepScriptLocation parameter.
269 def static genStressModeScriptStep(def os, def stressModeName, def stressModeVars, def stepScriptLocation) {
270     def stepScript = ''
271     if (os == 'Windows_NT') {
272         stepScript += "echo Creating TestEnv Script for ${stressModeName}\r\n"
273         stepScript += "del ${stepScriptLocation}\r\n"
274
275         // Timeout in ms, default is 10 minutes. For stress
276         // modes up this to 30 minutes
277         def timeout = 1800000
278
279         // Set the Timeout
280         stepScript += "set __TestTimeout=${timeout}\r\n"
281         stepScript += "echo. > ${stepScriptLocation}\r\n"
282         stressModeVars.each{ k, v ->
283             // Write out what we are writing to the script file
284             stepScript += "echo Setting ${k}=${v}\r\n"
285             // Write out the set itself to the script file`
286             stepScript += "echo set ${k}=${v} >> ${stepScriptLocation}\r\n"
287         }
288     }
289     else {
290         stepScript += "echo Setting variables for ${stressModeName}\n"
291         stepScript += "echo \\#\\!/usr/bin/env bash > ${stepScriptLocation}\n"
292         stressModeVars.each{ k, v ->
293             // Write out what we are writing to the script file
294             stepScript += "echo Setting ${k}=${v}\n"
295             // Write out the set itself to the script file`
296             stepScript += "echo export ${k}=${v} >> ${stepScriptLocation}\n"
297         }
298         stepScript += "chmod +x ${stepScriptLocation}\n"
299     }
300     return stepScript
301 }
302
303 // Calculates the name of the build job based on some typical parameters.
304 //
305 def static getJobName(def configuration, def architecture, def os, def scenario, def isBuildOnly) {
306     // If the architecture is x64, do not add that info into the build name.
307     // Need to change around some systems and other builds to pick up the right builds
308     // to do that.
309
310     def suffix = scenario != 'default' ? "_${scenario}" : '';
311     if (isBuildOnly) {
312         suffix += '_bld'
313     }
314     def baseName = ''
315     switch (architecture) {
316         case 'x64':
317             if (scenario == 'default') {
318                 // For now we leave x64 off of the name for compatibility with other jobs
319                 baseName = configuration.toLowerCase() + '_' + os.toLowerCase()
320             }
321             else if (scenario == 'formatting') {
322                 // we don't care about the configuration for the formatting job. It runs all configs
323                 baseName = architecture.toLowerCase() + '_' + os.toLowerCase()
324             }
325             else {
326                 baseName = architecture.toLowerCase() + '_' + configuration.toLowerCase() + '_' + os.toLowerCase()
327             }
328             break
329         case 'arm64':
330             // These are cross builds
331             baseName = architecture.toLowerCase() + '_cross_' + configuration.toLowerCase() + '_' + os.toLowerCase()
332             break
333         case 'arm':
334             // These are cross builds
335             if (os == 'Tizen') {
336                 // ABI: softfp
337                 baseName = 'armel_cross_' + configuration.toLowerCase() + '_' + os.toLowerCase()
338             }
339             else {
340                 baseName = architecture.toLowerCase() + '_cross_' + configuration.toLowerCase() + '_' + os.toLowerCase()
341             }
342             break
343         case 'x86':
344             baseName = architecture.toLowerCase() + '_' + configuration.toLowerCase() + '_' + os.toLowerCase()
345             break
346         default:
347             println("Unknown architecture: ${architecture}");
348             assert false
349             break
350     }
351
352     return baseName + suffix
353 }
354
355 def static addNonPRTriggers(def job, def branch, def isPR, def architecture, def os, def configuration, def scenario, def isFlowJob, def isWindowsBuildOnlyJob, def bidailyCrossList) {
356     // Check scenario.
357     switch (scenario) {
358         case 'default':
359             switch (architecture) {
360                 case 'x64':
361                 case 'x86':
362                     if (architecture == 'x86' && os == 'Ubuntu') {
363                         Utilities.addPeriodicTrigger(job, '@daily')
364                     }
365                     else if (isFlowJob || os == 'Windows_NT' || !(os in Constants.crossList)) {
366                         Utilities.addGithubPushTrigger(job)
367                     }
368                     break
369                 case 'arm':
370                     Utilities.addGithubPushTrigger(job)
371                     break
372                 case 'arm64':
373                     if (os == 'Windows_NT') {
374                         Utilities.addGithubPushTrigger(job)
375                         // TODO: Add once external email sending is available again
376                         // addEmailPublisher(job, 'dotnetonarm64@microsoft.com')
377                     }
378                     break
379                 default:
380                     println("Unknown architecture: ${architecture}");
381                     assert false
382                     break
383             }
384             break
385         case 'pri1':
386             // Pri one gets a push trigger, and only for release
387             if (architecture == 'x64') {
388                 if (configuration == 'Release') {
389                     // We expect release jobs to be Windows, or in the cross list
390                     assert (os == 'Windows_NT') || (os in Constants.crossList)
391                     if (!os in bidailyCrossList) {
392                         if (isFlowJob || os == 'Windows_NT') {
393                             Utilities.addGithubPushTrigger(job)
394                         }
395                     }
396                     else {
397                         if (isFlowJob) {
398                             Utilities.addPeriodicTrigger(job, 'H H/12 * * *')
399                         }
400                     }
401                 }
402             }
403             break
404         case 'r2r':
405             //r2r jobs that aren't pri1 can only be triggered by phrase
406             break
407         case 'pri1r2r':
408             assert !(os in bidailyCrossList)
409             //pri1 r2r gets a push trigger for checked/release
410             if (configuration == 'Checked' || configuration == 'Release') {
411                 assert (os == 'Windows_NT') || (os in Constants.crossList)
412                 if (architecture == 'x64' && os != 'OSX10.12') {
413                     //Flow jobs should be Windows, Ubuntu, OSX0.12, or CentOS
414                     if (isFlowJob || os == 'Windows_NT') {
415                         Utilities.addGithubPushTrigger(job)
416                     }
417                 // OSX10.12 pri1r2r jobs should only run every 12 hours, not daily.
418                 } else if (architecture == 'x64' && os == 'OSX10.12'){
419                     if (isFlowJob) {
420                         Utilities.addPeriodicTrigger(job, 'H H/12 * * *')
421                     }
422                 }
423                 // For x86, only add per-commit jobs for Windows
424                 else if (architecture == 'x86') {
425                     if (os == 'Windows_NT') {
426                         Utilities.addGithubPushTrigger(job)
427                     }
428                 }
429                 // arm64 pri1r2r jobs should only run every 12 hours.
430                 else if (architecture == 'arm64') {
431                     if (os == 'Windows_NT') {
432                         Utilities.addPeriodicTrigger(job, 'H H/12 * * *')
433                         // TODO: Add once external email sending is available again
434                         // addEmailPublisher(job, 'dotnetonarm64@microsoft.com')
435                     }
436                 }
437             }
438             break
439         case 'r2r_jitstress1':
440         case 'r2r_jitstress2':
441         case 'r2r_jitstressregs1':
442         case 'r2r_jitstressregs2':
443         case 'r2r_jitstressregs3':
444         case 'r2r_jitstressregs4':
445         case 'r2r_jitstressregs8':
446         case 'r2r_jitstressregs0x10':
447         case 'r2r_jitstressregs0x80':
448         case 'r2r_jitstressregs0x1000':
449         case 'r2r_jitminopts':
450         case 'r2r_jitforcerelocs':
451         case 'gcstress15_pri1r2r':
452             assert !(os in bidailyCrossList)
453
454             // GCStress=C is currently not supported on OS X
455             if (os == 'OSX10.12' && isGCStressRelatedTesting(scenario)) {
456                 break
457             }
458
459             //GC Stress 15 pri1 r2r gets a push trigger for checked/release
460             if (configuration == 'Checked' || configuration == 'Release') {
461                 assert (os == 'Windows_NT') || (os in Constants.crossList)
462                 if (architecture == 'x64') {
463                     //Flow jobs should be Windows, Ubuntu, OSX10.12, or CentOS
464                     if (isFlowJob || os == 'Windows_NT') {
465                         // Add a weekly periodic trigger
466                         Utilities.addPeriodicTrigger(job, 'H H * * 3,6') // some time every Wednesday and Saturday
467                     }
468                 }
469                 // For x86, only add per-commit jobs for Windows
470                 else if (architecture == 'x86') {
471                     if (os == 'Windows_NT') {
472                         Utilities.addPeriodicTrigger(job, 'H H * * 3,6') // some time every Wednesday and Saturday
473                     }
474                 }
475             }
476             break
477         case 'longgc':
478             assert (os == 'Ubuntu' || os == 'Windows_NT' || os == 'OSX10.12')
479             assert configuration == 'Release'
480             assert architecture == 'x64'
481             Utilities.addPeriodicTrigger(job, '@daily')
482             // TODO: Add once external email sending is available again
483             // addEmailPublisher(job, 'dotnetgctests@microsoft.com')
484             break
485         case 'gcsimulator':
486             assert (os == 'Ubuntu' || os == 'Windows_NT' || os == 'OSX10.12')
487             assert configuration == 'Release'
488             assert architecture == 'x64'
489             Utilities.addPeriodicTrigger(job, 'H H * * 3,6') // some time every Wednesday and Saturday
490             // TODO: Add once external email sending is available again
491             // addEmailPublisher(job, 'dotnetgctests@microsoft.com')
492             break
493         case 'standalone_gc':
494             assert (os == 'Ubuntu' || os == 'Windows_NT' || os == 'OSX10.12')
495             assert (configuration == 'Release' || configuration == 'Checked')
496             // TODO: Add once external email sending is available again
497             // addEmailPublisher(job, 'dotnetgctests@microsoft.com')
498             Utilities.addPeriodicTrigger(job, '@weekly')
499             break
500         case 'ilrt':
501             assert !(os in bidailyCrossList)
502             // ILASM/ILDASM roundtrip one gets a daily build, and only for release
503             if (architecture == 'x64' && configuration == 'Release') {
504                 // We don't expect to see a job generated except in these scenarios
505                 assert (os == 'Windows_NT') || (os in Constants.crossList)
506                 if (isFlowJob || os == 'Windows_NT') {
507                     Utilities.addPeriodicTrigger(job, '@daily')
508                 }
509             }
510             break
511         case 'jitdiff':
512             assert (os == 'Ubuntu' || os == 'Windows_NT' || os == 'OSX10.12')
513             assert configuration == 'Checked'
514             assert (architecture == 'x64' || architecture == 'x86')
515             Utilities.addGithubPushTrigger(job)
516             break
517         case 'coverage':
518             assert (os == 'Ubuntu' || os == 'Windows_NT')
519             assert configuration == 'Release'
520             assert architecture == 'x64'
521             Utilities.addPeriodicTrigger(job, '@weekly')
522             break
523         case 'formatting':
524             assert (os == 'Windows_NT' || os == "Ubuntu")
525             assert architecture == 'x64'
526             Utilities.addGithubPushTrigger(job)
527             break
528         case 'jitstressregs1':
529         case 'jitstressregs2':
530         case 'jitstressregs3':
531         case 'jitstressregs4':
532         case 'jitstressregs8':
533         case 'jitstressregs0x10':
534         case 'jitstressregs0x80':
535         case 'jitstressregs0x1000':
536         case 'minopts':
537         case 'forcerelocs':
538         case 'jitstress1':
539         case 'jitstress2':
540         case 'jitstress2_jitstressregs1':
541         case 'jitstress2_jitstressregs2':
542         case 'jitstress2_jitstressregs3':
543         case 'jitstress2_jitstressregs4':
544         case 'jitstress2_jitstressregs8':
545         case 'jitstress2_jitstressregs0x10':
546         case 'jitstress2_jitstressregs0x80':
547         case 'jitstress2_jitstressregs0x1000':
548         case 'tailcallstress':
549         case 'jitsse2only':
550         case 'corefx_baseline':
551         case 'corefx_minopts':
552         case 'corefx_jitstress1':
553         case 'corefx_jitstress2':
554         case 'corefx_jitstressregs1':
555         case 'corefx_jitstressregs2':
556         case 'corefx_jitstressregs3':
557         case 'corefx_jitstressregs4':
558         case 'corefx_jitstressregs8':
559         case 'corefx_jitstressregs0x10':
560         case 'corefx_jitstressregs0x80':
561         case 'corefx_jitstressregs0x1000':
562         case 'zapdisable':
563             if (os != 'CentOS7.1' && !(os in bidailyCrossList)) {
564             assert (os == 'Windows_NT') || (os in Constants.crossList)
565             Utilities.addPeriodicTrigger(job, '@daily')
566         }
567         break
568         case 'heapverify1':
569         case 'gcstress0x3':
570             if (os != 'CentOS7.1' && !(os in bidailyCrossList)) {
571                 assert (os == 'Windows_NT') || (os in Constants.crossList)
572                 if (architecture == 'arm64') {
573                     assert (os == 'Windows_NT')
574                     Utilities.addPeriodicTrigger(job, '@daily')
575                     // TODO: Add once external email sending is available again
576                     // addEmailPublisher(job, 'dotnetonarm64@microsoft.com')
577                 }
578                 else {
579                     Utilities.addPeriodicTrigger(job, '@weekly')
580                 }
581             }
582             break
583         case 'gcstress0xc':
584         case 'gcstress0xc_zapdisable':
585         case 'gcstress0xc_zapdisable_jitstress2':
586         case 'gcstress0xc_zapdisable_heapverify1':
587         case 'gcstress0xc_jitstress1':
588         case 'gcstress0xc_jitstress2':
589         case 'gcstress0xc_minopts_heapverify1':
590             // GCStress=C is currently not supported on OS X
591             if (os != 'CentOS7.1' && os != 'OSX10.12' && !(os in bidailyCrossList)) {
592                 assert (os == 'Windows_NT') || (os in Constants.crossList)
593                 if (architecture == 'arm64') {
594                     assert (os == 'Windows_NT')
595                     // TODO: Enable a periodic trigger after tests are updated.
596                     // Utilities.addPeriodicTrigger(job, '@daily')
597                     // TODO: Add once external email sending is available again
598                     // addEmailPublisher(job, 'dotnetonarm64@microsoft.com')
599                 }
600                 else {
601                     Utilities.addPeriodicTrigger(job, '@weekly')
602                 }
603             }
604             break
605
606         case 'illink':
607             // Testing on other operating systems TBD
608             assert (os == 'Windows_NT' || os == 'Ubuntu')
609             if (architecture == 'x64' || architecture == 'x86') {
610                 if (configuration == 'Checked') {
611                     Utilities.addPeriodicTrigger(job, '@daily')
612                 }
613             }
614             break
615
616         default:
617             println("Unknown scenario: ${scenario}");
618             assert false
619             break
620     }
621     return
622 }
623
624 // **************************
625 // Define the basic inner loop builds for PR and commit.  This is basically just the set
626 // of coreclr builds over linux/osx 10.12/freebsd/windows and debug/release/checked.  In addition, the windows
627 // builds will do a couple extra steps.
628 // **************************
629
630 // Adds a trigger for the PR build if one is needed.  If isFlowJob is true, then this is the
631 // flow job that rolls up the build and test for non-windows OS's.  // If the job is a windows build only job,
632 // it's just used for internal builds
633 // If you add a job with a trigger phrase, please add that phrase to coreclr/Documentation/project-docs/ci-trigger-phrases.md
634 def static addTriggers(def job, def branch, def isPR, def architecture, def os, def configuration, def scenario, def isFlowJob, def isWindowsBuildOnlyJob) {
635     if (isWindowsBuildOnlyJob) {
636         return
637     }
638
639     def bidailyCrossList = ['RHEL7.2', 'Debian8.4']
640     // Non pull request builds.
641     if (!isPR) {
642         addNonPRTriggers(job, branch, isPR, architecture, os, configuration, scenario, isFlowJob, isWindowsBuildOnlyJob, bidailyCrossList)
643         return
644     }
645     // Pull request builds.  Generally these fall into two categories: default triggers and on-demand triggers
646     // We generally only have a distinct set of default triggers but a bunch of on-demand ones.
647     def osGroup = getOSGroup(os)
648     switch (architecture) {
649         case 'x64': // editor brace matching: {
650             if (scenario == 'coverage') {
651                 assert configuration == 'Release'
652                 if (os == 'Ubuntu') {
653                     Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Coverage Build & Test", "(?i).*test\\W+coverage.*")
654                 }
655                 break
656             }
657
658             if (scenario == 'formatting') {
659                 assert configuration == 'Checked'
660                 if (os == 'Windows_NT' || os == 'Ubuntu') {
661                     Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} Formatting")
662                 }
663                 break
664             }
665
666             switch (os) {
667                 // OpenSUSE, Debian & RedHat get trigger phrases for pri 0 build, and pri 1 build & test
668                 case 'Debian8.4':
669                 case 'RHEL7.2':
670                     if (scenario == 'default') {
671                         assert !isFlowJob
672                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build", "(?i).*test\\W+${os}.*")
673                     }
674                     else if (scenario == 'pri1' && isFlowJob) {
675                         assert (configuration == 'Release')
676                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Pri 1 Build & Test", "(?i).*test\\W+${os}\\W+${scenario}.*")
677                     }
678                     break
679                 case 'Ubuntu16.04':
680                     assert !isFlowJob
681                     assert scenario == 'default'
682                     // Distinguish with the other architectures (arm and x86)
683                     Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build", "(?i).*test\\W+${os}\\W+${architecture}.*")
684                     break
685                 case 'Fedora24':
686                 case 'Ubuntu16.10':
687                 case 'OpenSUSE42.1':
688                     assert !isFlowJob
689                     assert scenario == 'default'
690                     Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build", "(?i).*test\\W+${os}\\W+.*")
691                     break
692                 case 'Ubuntu':
693                     if (scenario == 'illink') {
694                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} via ILLink", "(?i).*test\\W+${os}\\W+${architecture}\\W+${configuration}\\W+${scenario}.*")
695                         break
696                     }
697                     // fall through
698                 case 'OSX10.12':
699                     // Triggers on the non-flow jobs aren't necessary here
700                     // Corefx testing uses non-flow jobs.
701                     if (!isFlowJob && !isCorefxTesting(scenario)) {
702                         break
703                     }
704                     switch (scenario) {
705                         case 'default':
706                             // Ubuntu uses checked for default PR tests
707                             if (configuration == 'Checked') {
708                                 // Default trigger
709                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test")
710                             }
711                             break
712                         case 'pri1':
713                             if (configuration == 'Release') {
714                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Priority 1 Build and Test", "(?i).*test\\W+${os}\\W+${scenario}.*")
715                             }
716                             break
717                         case 'jitdiff':
718                             if (configuration == 'Checked') {
719                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Jit Diff Build and Test", "(?i).*test\\W+${os}\\W+${scenario}.*")
720                             }
721                             break
722                         case 'ilrt':
723                             if (configuration == 'Release') {
724                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} IL RoundTrip Build and Test", "(?i).*test\\W+${os}\\W+${scenario}.*")
725                             }
726                             break
727                         case 'r2r':
728                             if (configuration == 'Release' || configuration == 'Checked') {
729                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} R2R pri0 Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")
730                             }
731                             break
732                         case 'pri1r2r':
733                             if (configuration == 'Release' || configuration == 'Checked') {
734                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} R2R pri1 Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")
735                             }
736                             break
737                         case 'gcstress15_pri1r2r':
738                             if (configuration == 'Release' || configuration == 'Checked') {
739                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} GCStress 15 R2R pri1 Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")
740                             }
741                             break
742                         case 'r2r_jitstress1':
743                         case 'r2r_jitstress2':
744                         case 'r2r_jitstressregs1':
745                         case 'r2r_jitstressregs2':
746                         case 'r2r_jitstressregs3':
747                         case 'r2r_jitstressregs4':
748                         case 'r2r_jitstressregs8':
749                         case 'r2r_jitstressregs0x10':
750                         case 'r2r_jitstressregs0x80':
751                         case 'r2r_jitstressregs0x1000':
752                         case 'r2r_jitminopts':
753                         case 'r2r_jitforcerelocs':
754                             if (configuration == 'Release' || configuration == 'Checked') {
755                                 def displayStr = getR2RStressModeDisplayName(scenario)
756                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} ${displayStr} R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")
757                             }
758                             break
759                         case 'longgc':
760                             if (configuration == 'Release') {
761                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Long-Running GC Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")
762                             }
763                             break
764                         case 'gcsimulator':
765                             if (configuration == 'Release') {
766                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} GC Simulator", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")
767                             }
768                             break
769                         case 'minopts':
770                         case 'forcerelocs':
771                         case 'jitstress1':
772                         case 'jitstress2':
773                         case 'jitstressregs1':
774                         case 'jitstressregs2':
775                         case 'jitstressregs3':
776                         case 'jitstressregs4':
777                         case 'jitstressregs8':
778                         case 'jitstressregs0x10':
779                         case 'jitstressregs0x80':
780                         case 'jitstressregs0x1000':
781                         case 'jitstress2_jitstressregs1':
782                         case 'jitstress2_jitstressregs2':
783                         case 'jitstress2_jitstressregs3':
784                         case 'jitstress2_jitstressregs4':
785                         case 'jitstress2_jitstressregs8':
786                         case 'jitstress2_jitstressregs0x10':
787                         case 'jitstress2_jitstressregs0x80':
788                         case 'jitstress2_jitstressregs0x1000':
789                         case 'tailcallstress':
790                         case 'jitsse2only':
791                         case 'gcstress0x3':
792                         case 'gcstress0xc':
793                         case 'zapdisable':
794                         case 'heapverify1':
795                         case 'gcstress0xc_zapdisable':
796                         case 'gcstress0xc_zapdisable_jitstress2':
797                         case 'gcstress0xc_zapdisable_heapverify1':
798                         case 'gcstress0xc_jitstress1':
799                         case 'gcstress0xc_jitstress2':
800                         case 'gcstress0xc_minopts_heapverify1':
801                             def displayStr = getStressModeDisplayName(scenario)
802                             assert (os == 'Windows_NT') || (os in Constants.crossList)
803                             Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test (Jit - ${displayStr})",
804                                "(?i).*test\\W+${os}\\W+${scenario}.*")
805                             break
806                         case 'corefx_baseline':
807                         case 'corefx_minopts':
808                         case 'corefx_jitstress1':
809                         case 'corefx_jitstress2':
810                         case 'corefx_jitstressregs1':
811                         case 'corefx_jitstressregs2':
812                         case 'corefx_jitstressregs3':
813                         case 'corefx_jitstressregs4':
814                         case 'corefx_jitstressregs8':
815                         case 'corefx_jitstressregs0x10':
816                         case 'corefx_jitstressregs0x80':
817                         case 'corefx_jitstressregs0x1000':
818                             def displayName = ('CoreFx ' + getStressModeDisplayName(scenario)).trim()
819                             assert (os == 'Windows_NT') || (os in Constants.crossList)
820                             Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test (Jit - ${displayName})",
821                                "(?i).*test\\W+${os}\\W+${architecture}\\W+${scenario}.*")
822                             break
823                         default:
824                             println("Unknown scenario: ${scenario}");
825                             assert false
826                             break
827                     }
828                     break
829                 case 'CentOS7.1':
830                     switch (scenario) {
831                         case 'pri1':
832                             if (configuration == 'Release') {
833                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Priority 1 Build and Test", "(?i).*test\\W+${os}\\W+${scenario}.*")
834                             }
835                             break
836                         case 'r2r':
837                             if (configuration == 'Checked' || configuration == 'Release') {
838                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} R2R pri0 Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")
839                             }
840                             break
841                         case 'pri1r2r':
842                             if (configuration == 'Checked' || configuration == 'Release') {
843                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} R2R pri1 Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")
844                             }
845                             break
846                         case 'gcstress15_pri1r2r':
847                             if (configuration == 'Release' || configuration == 'Checked') {
848                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} GCStress 15 R2R pri1 Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")
849                             }
850                             break
851                         case 'r2r_jitstress1':
852                         case 'r2r_jitstress2':
853                         case 'r2r_jitstressregs1':
854                         case 'r2r_jitstressregs2':
855                         case 'r2r_jitstressregs3':
856                         case 'r2r_jitstressregs4':
857                         case 'r2r_jitstressregs8':
858                         case 'r2r_jitstressregs0x10':
859                         case 'r2r_jitstressregs0x80':
860                         case 'r2r_jitstressregs0x1000':
861                         case 'r2r_jitminopts':
862                         case 'r2r_jitforcerelocs':
863                             if (configuration == 'Release' || configuration == 'Checked') {
864                                 def displayStr = getR2RStressModeDisplayName(scenario)
865                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} ${displayStr} R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")
866                             }
867                             break
868                         default:
869                             break
870                     }
871                 case 'Windows_NT':
872                     switch (scenario) {
873                         case 'default':
874                             // Default trigger
875                             if (configuration == 'Debug') {
876                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test")
877                             }
878                             break
879                         case 'pri1':
880                             // Default trigger
881                             if (configuration == 'Release') {
882                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Priority 1 Build and Test")
883                             }
884                             break
885                         case 'jitdiff':
886                             if (configuration == 'Checked') {
887                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Jit Diff Build and Test", "(?i).*test\\W+${os}\\W+${scenario}.*")
888                             }
889                             break
890                         case 'ilrt':
891                             if (configuration == 'Release') {
892                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} IL RoundTrip Build and Test", "(?i).*test\\W+${os}\\W+${scenario}.*")
893                             }
894                             break
895                         case 'r2r':
896                             if (configuration == 'Checked' || configuration == 'Release') {
897                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} R2R pri0 Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")
898                             }
899                             break
900                         case 'pri1r2r':
901                             if (configuration == 'Checked' || configuration == 'Release') {
902                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} R2R pri1 Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")
903                             }
904                             break
905                         case 'gcstress15_pri1r2r':
906                             if (configuration == 'Release' || configuration == 'Checked') {
907                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} GCStress 15 R2R pri1 Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")
908                             }
909                             break
910                         case 'r2r_jitstress1':
911                         case 'r2r_jitstress2':
912                         case 'r2r_jitstressregs1':
913                         case 'r2r_jitstressregs2':
914                         case 'r2r_jitstressregs3':
915                         case 'r2r_jitstressregs4':
916                         case 'r2r_jitstressregs8':
917                         case 'r2r_jitstressregs0x10':
918                         case 'r2r_jitstressregs0x80':
919                         case 'r2r_jitstressregs0x1000':
920                         case 'r2r_jitminopts':
921                         case 'r2r_jitforcerelocs':
922                             if (configuration == 'Release' || configuration == 'Checked') {
923                                 def displayStr = getR2RStressModeDisplayName(scenario)
924                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} ${displayStr} R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")
925                             }
926                             break
927                         case 'longgc':
928                             if (configuration == 'Release') {
929                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Long-Running GC Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")
930                             }
931                             break
932                         case 'gcsimulator':
933                             if (configuration == 'Release') {
934                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} GC Simulator", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")
935                             }
936                             break
937                         case 'standalone_gc':
938                             if (configuration == 'Release' || configuration == 'Checked') {
939                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Standalone GC", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")
940                             }
941                             break
942                         case 'minopts':
943                         case 'forcerelocs':
944                         case 'jitstress1':
945                         case 'jitstress2':
946                         case 'jitstressregs1':
947                         case 'jitstressregs2':
948                         case 'jitstressregs3':
949                         case 'jitstressregs4':
950                         case 'jitstressregs8':
951                         case 'jitstressregs0x10':
952                         case 'jitstressregs0x80':
953                         case 'jitstressregs0x1000':
954                         case 'jitstress2_jitstressregs1':
955                         case 'jitstress2_jitstressregs2':
956                         case 'jitstress2_jitstressregs3':
957                         case 'jitstress2_jitstressregs4':
958                         case 'jitstress2_jitstressregs8':
959                         case 'jitstress2_jitstressregs0x10':
960                         case 'jitstress2_jitstressregs0x80':
961                         case 'jitstress2_jitstressregs0x1000':
962                         case 'tailcallstress':
963                         case 'jitsse2only':
964                         case 'gcstress0x3':
965                         case 'gcstress0xc':
966                         case 'zapdisable':
967                         case 'heapverify1':
968                         case 'gcstress0xc_zapdisable':
969                         case 'gcstress0xc_zapdisable_jitstress2':
970                         case 'gcstress0xc_zapdisable_heapverify1':
971                         case 'gcstress0xc_jitstress1':
972                         case 'gcstress0xc_jitstress2':
973                         case 'gcstress0xc_minopts_heapverify1':
974                             def displayStr = getStressModeDisplayName(scenario)
975                             assert (os == 'Windows_NT') || (os in Constants.crossList)
976                             Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test (Jit - ${displayStr})",
977                                "(?i).*test\\W+${os}\\W+${scenario}.*")
978                             break
979                         case 'corefx_baseline':
980                         case 'corefx_minopts':
981                         case 'corefx_jitstress1':
982                         case 'corefx_jitstress2':
983                         case 'corefx_jitstressregs1':
984                         case 'corefx_jitstressregs2':
985                         case 'corefx_jitstressregs3':
986                         case 'corefx_jitstressregs4':
987                         case 'corefx_jitstressregs8':
988                         case 'corefx_jitstressregs0x10':
989                         case 'corefx_jitstressregs0x80':
990                         case 'corefx_jitstressregs0x1000':
991                             def displayName = ('CoreFx ' + getStressModeDisplayName(scenario)).trim()
992                             assert (os == 'Windows_NT') || (os in Constants.crossList)
993                             Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test (Jit - ${displayName})",
994                                "(?i).*test\\W+${os}\\W+${architecture}\\W+${scenario}.*")
995                             break
996                         case 'illink':
997                             Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} via ILLink", "(?i).*test\\W+${os}\\W+${architecture}\\W+${configuration}\\W+${scenario}.*")
998                                     break
999                         default:
1000                             println("Unknown scenario: ${scenario}");
1001                             assert false
1002                             break
1003                     }
1004                     break
1005                 case 'FreeBSD':
1006                     assert scenario == 'default'
1007                     if (configuration == 'Checked') {
1008                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build")
1009                     }
1010                     break
1011                 default:
1012                     println("Unknown os: ${os}");
1013                     assert false
1014                     break
1015             }
1016             break
1017         // editor brace matching: }
1018         case 'arm': // editor brace matching: {
1019             assert scenario == 'default'
1020             switch (os) {
1021                 case 'Ubuntu':
1022                 case 'Ubuntu16.04':
1023                     if ((os == 'Ubuntu' && configuration == 'Release') || (os == 'Ubuntu16.04' && configuration == 'Debug')) {
1024                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} Cross ${configuration} Build")
1025                     }
1026                     else {
1027                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} Cross ${configuration} Build", "(?i).*test\\W+${os}\\W+${architecture}\\W+Cross\\W+${configuration}\\W+Build.*")
1028                     }
1029                     break;
1030                 case 'Tizen':
1031                     architecture='armel'
1032                     // Removing the regex will cause this to run on each PR.
1033                     if (configuration == 'Release' || configuration == 'Debug') {
1034                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} Cross ${configuration} Build")
1035                     }
1036                     else {
1037                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} Cross ${configuration} Build", "(?i).*test\\W+${os}\\W+${architecture}\\W+Cross\\W+${configuration}\\W+Build.*")
1038                     }
1039                     break;
1040                 case 'Windows_NT':
1041                     if (configuration == 'Debug' || configuration == 'Release')
1042                     {
1043                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} Cross ${configuration} Build")
1044                     }
1045                     break
1046                 default:
1047                     println("NYI os: ${os}");
1048                     assert false
1049                     break
1050             }
1051             break
1052         // editor brace matching: }
1053         case 'arm64': // editor brace matching: {
1054             assert (scenario == 'default') || (scenario == 'pri1r2r') || (scenario == 'gcstress0x3') || (scenario == 'gcstress0xc')
1055
1056             // Set up a private trigger
1057             def contextString = "${os} ${architecture} Cross ${configuration}"
1058             if (scenario != 'default')
1059                 contextString += " ${scenario}"
1060             contextString += " Build"
1061             // Debug builds only.
1062             if (configuration != 'Debug') {
1063                contextString += " and Test"
1064             }
1065
1066             def arm64Users = [
1067                 'adiaaida',
1068                 'AndyAyersMS',
1069                 'briansull',
1070                 'BruceForstall',
1071                 'CarolEidt',
1072                 'cmckinsey',
1073                 'erozenfeld',
1074                 'jashook',
1075                 'JosephTremoulet',
1076                 'pgavlin',
1077                 'pkukol',
1078                 'russellhadley',
1079                 'RussKeldorph',
1080                 'sandreenko',
1081                 'sivarv',
1082                 'swaroop-sridhar',
1083                 'gkhanna79',
1084                 'jkotas',
1085                 'markwilkie',
1086                 'rahku',
1087                 'ramarag',
1088                 'tzwlai',
1089                 'weshaggard'
1090             ]
1091
1092             switch (os) {
1093                 case 'Windows_NT':
1094                     switch (scenario) {
1095                         case 'default':
1096                             // For now only run Debug jobs on PR Trigger.
1097                             if (configuration != 'Debug') {
1098                                 Utilities.addPrivateGithubPRTriggerForBranch(job, branch, contextString,
1099                                 "(?i).*test\\W+${os}\\W+${architecture}\\W+${configuration}.*", null, arm64Users)
1100                             }
1101                             else {
1102                                 // Add "Checked Build And Test" and "Debug Build" to the above users' PRs since many of them
1103                                 // are at higher risk of ARM64-breaking changes.
1104                                 Utilities.addDefaultPrivateGithubPRTriggerForBranch(job, branch, contextString, null, arm64Users)
1105                             }
1106                             break
1107                         case 'pri1r2r':
1108                         case 'gcstress0x3':
1109                         case 'gcstress0xc':
1110                             Utilities.addPrivateGithubPRTriggerForBranch(job, branch, contextString,
1111                             "(?i).*test\\W+${os}\\W+${architecture}\\W+${configuration}\\W+${scenario}.*", null, arm64Users)
1112                             break
1113                     }
1114                     break
1115                 default:
1116                     println("NYI os: ${os}");
1117                     assert false
1118                     break
1119             }
1120             break
1121         // editor brace matching: }
1122         case 'x86': // editor brace matching: {
1123             assert ((os == 'Windows_NT') || ((os == 'Ubuntu') && (scenario == 'default')))
1124             if (os == 'Ubuntu') {
1125                 // on-demand only for ubuntu x86
1126                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build",
1127                     "(?i).*test\\W+${os}\\W+${architecture}\\W+${configuration}.*")
1128                 break
1129             }
1130             switch (scenario) {
1131                 case 'default':
1132                     if (configuration == 'Checked') {
1133                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test")
1134                     }
1135                     else if (configuration == 'Release') {
1136                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test",
1137                             "(?i).*test\\W+${os}\\W+${architecture}\\W+${configuration}.*")
1138                     }
1139                     break
1140                 case 'pri1':
1141                     if (configuration == 'Release') {
1142                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Priority 1 Build and Test")
1143                     }
1144                     break
1145                 case 'ilrt':
1146                     if (configuration == 'Release') {
1147                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} IL RoundTrip Build and Test",
1148                             "(?i).*test\\W+${os}\\W+${architecture}\\W+${configuration}\\W+${scenario}.*")
1149                     }
1150                     break
1151                 case 'r2r':
1152                     if (configuration == 'Checked' || configuration == 'Release') {
1153                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} R2R pri0 Build & Test",
1154                             "(?i).*test\\W+${os}\\W+${architecture}\\W+${configuration}\\W+${scenario}.*")
1155                     }
1156                     break
1157                 case 'pri1r2r':
1158                     if (configuration == 'Checked' || configuration == 'Release') {
1159                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} R2R pri1 Build & Test",
1160                             "(?i).*test\\W+${os}\\W+${architecture}\\W+${configuration}\\W+${scenario}.*")
1161                     }
1162                     break
1163                 case 'gcstress15_pri1r2r':
1164                     if (configuration == 'Release' || configuration == 'Checked') {
1165                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} GCStress 15 R2R pri1 Build & Test",
1166                             "(?i).*test\\W+${os}\\W+${architecture}\\W+${configuration}\\W+${scenario}.*")
1167                     }
1168                     break
1169                 case 'r2r_jitstress1':
1170                 case 'r2r_jitstress2':
1171                 case 'r2r_jitstressregs1':
1172                 case 'r2r_jitstressregs2':
1173                 case 'r2r_jitstressregs3':
1174                 case 'r2r_jitstressregs4':
1175                 case 'r2r_jitstressregs8':
1176                 case 'r2r_jitstressregs0x10':
1177                 case 'r2r_jitstressregs0x80':
1178                 case 'r2r_jitstressregs0x1000':
1179                 case 'r2r_jitminopts':
1180                 case 'r2r_jitforcerelocs':
1181                     if (configuration == 'Release' || configuration == 'Checked') {
1182                         def displayStr = getR2RStressModeDisplayName(scenario)
1183                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} ${displayStr} R2R Build & Test",
1184                             "(?i).*test\\W+${os}\\W+${architecture}\\W+${configuration}\\W+${scenario}.*")
1185                     }
1186                     break
1187                 case 'longgc':
1188                     if (configuration == 'Release') {
1189                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Long-Running GC Build & Test",
1190                             "(?i).*test\\W+${os}\\W+${architecture}\\W+${configuration}\\W+${scenario}.*")
1191                     }
1192                     break
1193                 case 'gcsimulator':
1194                     if (configuration == 'Release') {
1195                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} GC Simulator",
1196                             "(?i).*test\\W+${os}\\W+${architecture}\\W+${configuration}\\W+${scenario}.*")
1197                     }
1198                     break
1199                 case 'standalone_gc':
1200                     if (configuration == 'Release' || configuration == 'Checked') {
1201                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Standalone GC",
1202                             "(?i).*test\\W+${os}\\W+${architecture}\\W+${configuration}\\W+${scenario}.*")
1203                     }
1204                     break
1205                 case 'minopts':
1206                 case 'forcerelocs':
1207                 case 'jitstress1':
1208                 case 'jitstress2':
1209                 case 'jitstressregs1':
1210                 case 'jitstressregs2':
1211                 case 'jitstressregs3':
1212                 case 'jitstressregs4':
1213                 case 'jitstressregs8':
1214                 case 'jitstressregs0x10':
1215                 case 'jitstressregs0x80':
1216                 case 'jitstressregs0x1000':
1217                 case 'jitstress2_jitstressregs1':
1218                 case 'jitstress2_jitstressregs2':
1219                 case 'jitstress2_jitstressregs3':
1220                 case 'jitstress2_jitstressregs4':
1221                 case 'jitstress2_jitstressregs8':
1222                 case 'jitstress2_jitstressregs0x10':
1223                 case 'jitstress2_jitstressregs0x80':
1224                 case 'jitstress2_jitstressregs0x1000':
1225                 case 'tailcallstress':
1226                 case 'jitsse2only':
1227                 case 'gcstress0x3':
1228                 case 'gcstress0xc':
1229                 case 'zapdisable':
1230                 case 'heapverify1':
1231                 case 'gcstress0xc_zapdisable':
1232                 case 'gcstress0xc_zapdisable_jitstress2':
1233                 case 'gcstress0xc_zapdisable_heapverify1':
1234                 case 'gcstress0xc_jitstress1':
1235                 case 'gcstress0xc_jitstress2':
1236                 case 'gcstress0xc_minopts_heapverify1':
1237                     def displayStr = getStressModeDisplayName(scenario)
1238                     Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test (Jit - ${displayStr})",
1239                        "(?i).*test\\W+${os}\\W+${architecture}\\W+${configuration}\\W+${scenario}.*")
1240                     break
1241                 case 'corefx_baseline':
1242                 case 'corefx_minopts':
1243                 case 'corefx_jitstress1':
1244                 case 'corefx_jitstress2':
1245                 case 'corefx_jitstressregs1':
1246                 case 'corefx_jitstressregs2':
1247                 case 'corefx_jitstressregs3':
1248                 case 'corefx_jitstressregs4':
1249                 case 'corefx_jitstressregs8':
1250                 case 'corefx_jitstressregs0x10':
1251                 case 'corefx_jitstressregs0x80':
1252                 case 'corefx_jitstressregs0x1000':
1253                     def displayName = ('CoreFx ' + getStressModeDisplayName(scenario)).trim()
1254                     assert (os == 'Windows_NT') || (os in Constants.crossList)
1255                     Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test (Jit - ${displayName})",
1256                        "(?i).*test\\W+${os}\\W+${architecture}\\W+${scenario}.*")
1257                     break
1258                 case 'illink':
1259                     Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} via ILLink", "(?i).*test\\W+${os}\\W+${architecture}\\W+${configuration}\\W+${scenario}.*")
1260                     break
1261                 default:
1262                     println("Unknown scenario: ${os} ${architecture} ${scenario}");
1263                     assert false
1264                     break
1265             }
1266             break
1267         // editor brace matching: }
1268         default:
1269             println("Unknown architecture: ${architecture}");
1270             assert false
1271             break
1272     }
1273 }
1274
1275 def static calculateBuildCommands(def newJob, def scenario, def branch, def isPR, def architecture, def configuration, def os, def enableCorefxTesting, def isBuildOnly) {
1276     def buildCommands = [];
1277     def osGroup = getOSGroup(os)
1278     def lowerConfiguration = configuration.toLowerCase()
1279
1280     // Calculate the build steps, archival, and xunit results
1281     switch (os) {
1282         case 'Windows_NT': // editor brace matching: {
1283             switch (architecture) {
1284                 case 'x64':
1285                 case 'x86':
1286                     def arch = architecture
1287                     def buildOpts = ''
1288
1289                     if (scenario == 'illink') {
1290                         buildCommands += "tests\\scripts\\build_illink.cmd clone ${arch}"
1291                     }
1292
1293                     if (Constants.jitStressModeScenarios.containsKey(scenario) ||
1294                             scenario == 'default' ||
1295                             scenario == 'r2r' ||
1296                             scenario == 'jitdiff' ||
1297                             scenario == 'illink' ||
1298                             Constants.r2rJitStressScenarios.indexOf(scenario) != -1) {
1299                         buildOpts += enableCorefxTesting ? ' skiptests' : ''
1300                         buildCommands += "set __TestIntermediateDir=int&&build.cmd ${lowerConfiguration} ${arch} ${buildOpts}"
1301                     }
1302
1303                     // For Pri 1 tests, we must shorten the output test binary path names.
1304                     // if __TestIntermediateDir is already set, build-test.cmd will
1305                     // output test binaries to that directory. If it is not set, the
1306                     // binaries are sent to a default directory whose name is about
1307                     // 35 characters long.
1308
1309                     else if (scenario == 'pri1' || scenario == 'pri1r2r' || scenario == 'gcstress15_pri1r2r'|| scenario == 'coverage') {
1310                         buildCommands += "set __TestIntermediateDir=int&&build.cmd ${lowerConfiguration} ${arch} ${buildOpts} -priority=1"
1311                     }
1312                     else if (scenario == 'ilrt') {
1313                         // First do the build with skiptests and then build the tests with ilasm roundtrip
1314                         buildCommands += "build.cmd ${lowerConfiguration} ${arch} ${buildOpts} skiptests"
1315                         buildCommands += "set __TestIntermediateDir=int&&build-test.cmd ${lowerConfiguration} ${arch} -ilasmroundtrip"
1316                     }
1317                     else if (isLongGc(scenario)) {
1318                         buildCommands += "build.cmd ${lowerConfiguration} ${arch} ${buildOpts} skiptests"
1319                         buildCommands += "set __TestIntermediateDir=int&&build-test.cmd ${lowerConfiguration} ${arch}"
1320                     }
1321                     else if (scenario == 'standalone_gc') {
1322                         buildCommands += "build.cmd ${lowerConfiguration} ${arch} ${buildOpts} buildstandalonegc"
1323                     }
1324                     else if (scenario == 'formatting') {
1325                         buildCommands += "python -u tests\\scripts\\format.py -c %WORKSPACE% -o Windows_NT -a ${arch}"
1326                         Utilities.addArchival(newJob, "format.patch", "", true, false)
1327                         break
1328                     }
1329                     else {
1330                         println("Unknown scenario: ${scenario}")
1331                         assert false
1332                     }
1333
1334                     // If we are running a stress mode, we should write out the set of key
1335                     // value env pairs to a file at this point and then we'll pass that to runtest.cmd
1336
1337                     if (!isBuildOnly) {
1338                         //If this is a crossgen build, pass 'crossgen' to runtest.cmd
1339                         def crossgenStr = ''
1340                         def runcrossgentestsStr = ''
1341                         def runjitstressStr = ''
1342                         def runjitstressregsStr = ''
1343                         def runjitmioptsStr = ''
1344                         def runjitforcerelocsStr = ''
1345                         def runjitdisasmStr = ''
1346                         def gcstressStr = ''
1347                         def runtestArguments = ''
1348                         def gcTestArguments = ''
1349                         def illinkArguments = ''
1350
1351                         if (scenario == 'r2r' ||
1352                             scenario == 'pri1r2r' ||
1353                             scenario == 'gcstress15_pri1r2r' ||
1354                             Constants.r2rJitStressScenarios.indexOf(scenario) != -1) {
1355                                 crossgenStr = 'crossgen'
1356                                 runcrossgentestsStr = 'runcrossgentests'
1357
1358                                 if (scenario == 'r2r_jitstress1'){
1359                                     runjitstressStr = 'jitstress 1'
1360                                 }
1361                                 else if (scenario == 'r2r_jitstress2') {
1362                                     runjitstressStr = 'jitstress 2'
1363                                 }
1364                                 else if (scenario == 'r2r_jitstressregs1'){
1365                                     runjitstressregsStr = 'jitstressregs 1'
1366                                 }
1367                                 else if (scenario == 'r2r_jitstressregs2') {
1368                                     runjitstressregsStr = 'jitstressregs 2'
1369                                 }
1370                                 else if (scenario == 'r2r_jitstressregs3') {
1371                                     runjitstressregsStr = 'jitstressregs 3'
1372                                 }
1373                                 else if (scenario == 'r2r_jitstressregs4') {
1374                                     runjitstressregsStr = 'jitstressregs 4'
1375                                 }
1376                                 else if (scenario == 'r2r_jitstressregs8') {
1377                                     runjitstressregsStr = 'jitstressregs 8'
1378                                 }
1379                                 else if (scenario == 'r2r_jitstressregs0x10') {
1380                                     runjitstressregsStr = 'jitstressregs 0x10'
1381                                 }
1382                                 else if (scenario == 'r2r_jitstressregs0x80') {
1383                                     runjitstressregsStr = 'jitstressregs 0x80'
1384                                 }
1385                                 else if (scenario == 'r2r_jitstressregs0x1000') {
1386                                     runjitstressregsStr = 'jitstressregs 0x1000'
1387                                 }
1388                                 else if (scenario == 'r2r_jitminopts') {
1389                                     runjitmioptsStr = 'jitminopts'
1390                                 }
1391                                 else if (scenario == 'r2r_jitforcerelocs') {
1392                                     runjitforcerelocsStr = 'jitforcerelocs'
1393                                 }
1394                         }
1395                         if (scenario == 'gcstress15_pri1r2r')
1396                         {
1397                             gcstressStr = 'gcstresslevel 0xF'
1398                         }
1399
1400                         if (scenario == 'jitdiff')
1401                         {
1402                             runjitdisasmStr = 'jitdisasm crossgen'
1403                         }
1404
1405                         if (isLongGc(scenario)) {
1406                             gcTestArguments = "${scenario} sequential"
1407                         }
1408
1409                         if (scenario == 'illink')
1410                         {
1411                             illinkArguments = "link %WORKSPACE%\\linker\\linker\\bin\\netcore_Release\\netcoreapp2.0\\win10-${arch}\\publish\\illink.exe"
1412                         }
1413
1414                         runtestArguments = "${lowerConfiguration} ${arch} ${gcstressStr} ${crossgenStr} ${runcrossgentestsStr} ${runjitstressStr} ${runjitstressregsStr} ${runjitmioptsStr} ${runjitforcerelocsStr} ${runjitdisasmStr} ${gcTestArguments} ${illinkArguments} collectdumps"
1415
1416                         if (Constants.jitStressModeScenarios.containsKey(scenario)) {
1417                             def stepScriptLocation = "%WORKSPACE%\\SetStressModes.bat"
1418                             buildCommands += genStressModeScriptStep(os, scenario, Constants.jitStressModeScenarios[scenario], stepScriptLocation)
1419
1420                             if (enableCorefxTesting) {
1421                                 def workspaceRelativeFxRoot = "_/fx"
1422                                 def absoluteFxRoot = "%WORKSPACE%\\_\\fx"
1423
1424                                 buildCommands += "python -u %WORKSPACE%\\tests\\scripts\\run-corefx-tests.py -arch ${arch} -build_type ${configuration} -fx_root ${absoluteFxRoot} -fx_branch ${branch} -env_script ${stepScriptLocation}"
1425
1426                                 setTestJobTimeOut(newJob, scenario)
1427
1428                                 // Archive and process (only) the test results
1429                                 Utilities.addArchival(newJob, "${workspaceRelativeFxRoot}/bin/**/testResults.xml")
1430                                 Utilities.addXUnitDotNETResults(newJob, "${workspaceRelativeFxRoot}/bin/**/testResults.xml")
1431                             }
1432                             else {
1433                                 buildCommands += "%WORKSPACE%\\tests\\runtest.cmd ${runtestArguments} TestEnv ${stepScriptLocation}"
1434                             }
1435                         }
1436                         else if (architecture == 'x64' || architecture == 'x86') {
1437                             buildCommands += "tests\\runtest.cmd ${runtestArguments}"
1438                         }
1439                     }
1440
1441                     if (!enableCorefxTesting) {
1442                         // Run the rest of the build
1443                         // Build the mscorlib for the other OS's
1444                         buildCommands += "build.cmd ${lowerConfiguration} ${arch} linuxmscorlib"
1445                         buildCommands += "build.cmd ${lowerConfiguration} ${arch} freebsdmscorlib"
1446                         buildCommands += "build.cmd ${lowerConfiguration} ${arch} osxmscorlib"
1447
1448                         // Zip up the tests directory so that we don't use so much space/time copying
1449                         // 10s of thousands of files around.
1450                         buildCommands += "powershell -Command \"Add-Type -Assembly 'System.IO.Compression.FileSystem'; [System.IO.Compression.ZipFile]::CreateFromDirectory('.\\bin\\tests\\${osGroup}.${arch}.${configuration}', '.\\bin\\tests\\tests.zip')\"";
1451
1452                         if (!Constants.jitStressModeScenarios.containsKey(scenario)) {
1453                             // For windows, pull full test results and test drops for x86/x64.
1454                             // No need to pull for stress mode scenarios (downstream builds use the default scenario)
1455                             Utilities.addArchival(newJob, "bin/Product/**,bin/tests/tests.zip", "bin/Product/**/.nuget/**")
1456                         }
1457
1458                         if (scenario == 'jitdiff') {
1459                             // retrive jit-dasm output for base commit, and run jit-diff
1460                             if (!isBuildOnly) {
1461                                 // if this is a build only job, we want to keep the default (build) artifacts for the flow job
1462                                 Utilities.addArchival(newJob, "bin/tests/${osGroup}.${arch}.${configuration}/dasm/**")
1463                             }
1464                         }
1465
1466                         if (!isBuildOnly) {
1467                             if (architecture == 'x64' || !isPR) {
1468                                 Utilities.addXUnitDotNETResults(newJob, 'bin/**/TestRun*.xml')
1469                             }
1470                             setTestJobTimeOut(newJob, scenario)
1471                         }
1472                     }
1473                     break
1474                 case 'arm':
1475                     assert (scenario == 'default')
1476
1477                     // Set time out
1478                     setTestJobTimeOut(newJob, scenario)
1479
1480                     if ( lowerConfiguration == "debug" ) {
1481                         // For Debug builds, we will do a P1 test build
1482                         buildCommands += "set __TestIntermediateDir=int&&build.cmd ${lowerConfiguration} ${architecture} -priority=1"
1483                     }
1484                     else {
1485                         buildCommands += "set __TestIntermediateDir=int&&build.cmd ${lowerConfiguration} ${architecture}"
1486                     }
1487                     // Add archival.
1488                     Utilities.addArchival(newJob, "bin/Product/**", "bin/Product/**/.nuget/**")
1489                     break
1490                 case 'arm64':
1491                     assert (scenario == 'default') || (scenario == 'pri1r2r') || (scenario == 'gcstress0x3') || (scenario == 'gcstress0xc')
1492                    
1493                     // Set time out
1494                     setTestJobTimeOut(newJob, scenario)
1495
1496                     // Debug runs take too long to run. So build job only.
1497                     if (lowerConfiguration == "debug") {
1498                        buildCommands += "set __TestIntermediateDir=int&&build.cmd ${lowerConfiguration} ${architecture} toolset_dir C:\\ats2"
1499                     }
1500                     else {
1501                        if ((scenario != 'gcstress0x3') && (scenario != 'gcstress0xc'))
1502                        {
1503                            // Up the timeout for arm64 checked testing only.
1504                            // Keep the longer timeout for gcstress.
1505                            Utilities.setJobTimeout(newJob, 240)
1506                        }
1507
1508                        buildCommands += "set __TestIntermediateDir=int&&build.cmd skiptests ${lowerConfiguration} ${architecture} toolset_dir C:\\ats2"
1509                        // Test build and run are launched together.
1510                        buildCommands += "python tests\\scripts\\arm64_post_build.py -repo_root %WORKSPACE% -arch ${architecture} -build_type ${lowerConfiguration} -scenario ${scenario} -key_location C:\\tools\\key.txt"
1511                        //Utilities.addXUnitDotNETResults(newJob, 'bin/tests/testResults.xml')
1512                     }
1513
1514                     // Add archival.
1515                     Utilities.addArchival(newJob, "bin/Product/**", "bin/Product/**/.nuget/**")
1516                     break
1517                 default:
1518                     println("Unknown architecture: ${architecture}");
1519                     assert false
1520                     break
1521             }
1522             break
1523         // editor brace matching: }
1524         case 'Ubuntu':
1525         case 'Ubuntu16.04':
1526         case 'Ubuntu16.10':
1527         case 'Debian8.4':
1528         case 'OSX10.12':
1529         case 'FreeBSD':
1530         case 'CentOS7.1':
1531         case 'RHEL7.2':
1532         case 'OpenSUSE42.1':
1533         case 'Tizen':
1534         case 'Fedora24': // editor brace matching: {
1535             switch (architecture) {
1536                 case 'x64':
1537                 case 'x86':
1538                     if (architecture == 'x86' && os == 'Ubuntu') {
1539                         // build and PAL test
1540                         buildCommands += "./tests/scripts/x86_ci_script.sh --buildConfig=${lowerConfiguration}"
1541                         Utilities.addXUnitDotNETResults(newJob, '**/pal_tests.xml')
1542                         break;
1543                     }
1544
1545                     if (scenario == 'formatting') {
1546                         buildCommands += "python tests/scripts/format.py -c \${WORKSPACE} -o Linux -a ${architecture}"
1547                         Utilities.addArchival(newJob, "format.patch", "", true, false)
1548                         break
1549                     }
1550
1551                     if (scenario == 'illink') {
1552                         assert(os == 'Ubuntu')
1553                         buildCommands += "./tests/scripts/build_illink.sh --clone --arch=${architecture}"
1554                     }
1555
1556                     def standaloneGc = ''
1557                     if (scenario == 'standalone_gc') {
1558                         standaloneGc = 'buildstandalonegc'
1559                     }
1560
1561                     if (!enableCorefxTesting) {
1562                         // We run pal tests on all OS but generate mscorlib (and thus, nuget packages)
1563                         // only on supported OS platforms.
1564                         if (os == 'FreeBSD')
1565                         {
1566                             buildCommands += "./build.sh skipmscorlib verbose ${lowerConfiguration} ${architecture} ${standaloneGc}"
1567                         }
1568                         else
1569                         {
1570                             def bootstrapRid = Utilities.getBoostrapPublishRid(os)
1571                             def bootstrapRidEnv = bootstrapRid != null ? "__PUBLISH_RID=${bootstrapRid} " : ''
1572                             buildCommands += "${bootstrapRidEnv}./build.sh verbose ${lowerConfiguration} ${architecture} ${standaloneGc}"
1573                         }
1574                         buildCommands += "src/pal/tests/palsuite/runpaltests.sh \${WORKSPACE}/bin/obj/${osGroup}.${architecture}.${configuration} \${WORKSPACE}/bin/paltestout"
1575
1576                         // Set time out
1577                         setTestJobTimeOut(newJob, scenario)
1578                         // Basic archiving of the build
1579                         Utilities.addArchival(newJob, "bin/Product/**,bin/obj/*/tests/**/*.dylib,bin/obj/*/tests/**/*.so", "bin/Product/**/.nuget/**")
1580                         // And pal tests
1581                         Utilities.addXUnitDotNETResults(newJob, '**/pal_tests.xml')
1582                     }
1583                     else {
1584                         // Corefx stress testing
1585                         assert os == 'Ubuntu'
1586                         assert architecture == 'x64'
1587                         assert lowerConfiguration == 'checked'
1588                         assert Constants.jitStressModeScenarios.containsKey(scenario)
1589
1590                         // Build coreclr
1591                         buildCommands += "./build.sh verbose ${lowerConfiguration} ${architecture}"
1592
1593                         def scriptFileName = "\$WORKSPACE/set_stress_test_env.sh"
1594                         buildCommands += genStressModeScriptStep(os, scenario, Constants.jitStressModeScenarios[scenario], scriptFileName)
1595
1596                         // Build and text corefx
1597                         def workspaceRelativeFxRoot = "_/fx"
1598                         def absoluteFxRoot = "\$WORKSPACE/${workspaceRelativeFxRoot}"
1599
1600                         buildCommands += "python -u \$WORKSPACE/tests/scripts/run-corefx-tests.py -arch ${architecture} -build_type ${configuration} -fx_root ${absoluteFxRoot} -fx_branch ${branch} -env_script ${scriptFileName}"
1601
1602                         setTestJobTimeOut(newJob, scenario)
1603
1604                         // Archive and process (only) the test results
1605                         Utilities.addArchival(newJob, "${workspaceRelativeFxRoot}/bin/**/testResults.xml")
1606                         Utilities.addXUnitDotNETResults(newJob, "${workspaceRelativeFxRoot}/bin/**/testResults.xml")
1607                     }
1608                     break
1609                 case 'arm64':
1610                     // We don't run the cross build except on Ubuntu
1611                     assert os == 'Ubuntu'
1612
1613                     buildCommands += """echo \"Using rootfs in /opt/aarch64-linux-gnu-root\"
1614                         ROOTFS_DIR=/opt/aarch64-linux-gnu-root ./build.sh skipmscorlib arm64 cross verbose ${lowerConfiguration}"""
1615
1616                     // Basic archiving of the build, no pal tests
1617                     Utilities.addArchival(newJob, "bin/Product/**", "bin/Product/**/.nuget/**")
1618                     break
1619                 case 'arm':
1620                     // Cross builds for ARM runs on Ubuntu, Ubuntu16.04 and Tizen currently
1621                     assert (os == 'Ubuntu') || (os == 'Ubuntu16.04') || (os == 'Tizen')
1622
1623                     // default values for Ubuntu
1624                     def arm_abi="arm"
1625                     def linuxCodeName="trusty"
1626                     if (os == 'Ubuntu16.04') {
1627                         linuxCodeName="xenial"
1628                     }
1629                     else if (os == 'Tizen') {
1630                         arm_abi="armel"
1631                         linuxCodeName="tizen"
1632                     }
1633
1634                     // Unzip the Windows test binaries first. Exit with 0
1635                     buildCommands += "unzip -q -o ./bin/tests/tests.zip -d ./bin/tests/Windows_NT.x64.${configuration} || exit 0"
1636
1637                     // Unpack the corefx binaries
1638                     buildCommands += "mkdir ./bin/CoreFxBinDir"
1639                     buildCommands += "tar -xf ./bin/build.tar.gz -C ./bin/CoreFxBinDir"
1640
1641                     // Call the ARM CI script to cross build and test using docker
1642                     buildCommands += """./tests/scripts/arm32_ci_script.sh \\
1643                     --mode=docker \\
1644                     --${arm_abi} \\
1645                     --linuxCodeName=${linuxCodeName} \\
1646                     --buildConfig=${lowerConfiguration} \\
1647                     --testRootDir=./bin/tests/Windows_NT.x64.${configuration} \\
1648                     --coreFxBinDir=./bin/CoreFxBinDir \\
1649                     --testDirFile=./tests/testsRunningInsideARM.txt"""
1650
1651                     // Basic archiving of the build, no pal tests
1652                     Utilities.addArchival(newJob, "bin/Product/**", "bin/Product/**/.nuget/**")
1653                     break
1654                 default:
1655                     println("Unknown architecture: ${architecture}");
1656                     assert false
1657                     break
1658             }
1659             break
1660         // editor brace matching: }
1661         default:
1662             println("Unknown os: ${os}");
1663             assert false
1664             break
1665     } // os
1666
1667     return buildCommands
1668 }
1669
1670 // Additional scenario which can alter behavior
1671
1672 def combinedScenarios = Constants.basicScenarios + Constants.jitStressModeScenarios.keySet()
1673 combinedScenarios.each { scenario ->
1674     [true, false].each { isPR ->
1675         Constants.architectureList.each { architecture ->
1676             Constants.configurationList.each { configuration ->
1677                 Constants.osList.each { os ->
1678                     // If the OS is Windows_NT_BuildOnly, set the isBuildOnly flag to true
1679                     // and reset the os to Windows_NT
1680                     def isBuildOnly = false
1681                     if (os == 'Windows_NT_BuildOnly') {
1682                         isBuildOnly = true
1683                         os = 'Windows_NT'
1684                     }
1685
1686                     // WinArm32 is only built for Debug and Release
1687                     if (os == 'Windows_NT' && architecture == 'arm')
1688                     {
1689                         if (configuration == 'Checked')
1690                         {
1691                             return
1692                         }
1693                     }
1694                     // Tizen is only supported for arm architecture
1695                     if (os == 'Tizen' && architecture != 'arm') {
1696                         return
1697                     }
1698
1699                     // Skip totally unimplemented (in CI) configurations.
1700                     switch (architecture) {
1701                         case 'arm64':
1702                             // Windows only
1703                             if (os != 'Windows_NT' || isBuildOnly) {
1704                                 return
1705                             }
1706                             break
1707                         case 'arm':
1708                             if ((os != 'Ubuntu') && (os != 'Ubuntu16.04') && (os != 'Tizen') && (os != 'Windows_NT')) {
1709                                 return
1710                             }
1711                             break
1712                         case 'x86':
1713                             if ((os != 'Ubuntu') && (os != 'Windows_NT')) {
1714                                 return
1715                             }
1716                             break
1717                         case 'x64':
1718                             // Everything implemented
1719                             break
1720                         default:
1721                             println("Unknown architecture: ${architecture}")
1722                             assert false
1723                             break
1724                     }
1725
1726                     // Skip scenarios (blanket skipping for jit stress modes, which are good most everywhere
1727                     // with checked builds
1728                     def enableCorefxTesting = false
1729                     if (Constants.jitStressModeScenarios.containsKey(scenario)) {
1730                         if (configuration != 'Checked') {
1731                             return
1732                         }
1733
1734                         enableCorefxTesting = isCorefxTesting(scenario)
1735
1736                         // Since these are just execution time differences,
1737                         // skip platforms that don't execute the tests here (Windows_NT only)
1738                         def isEnabledOS = (os == 'Windows_NT') || (os == 'Ubuntu' && enableCorefxTesting)
1739                         if (!isEnabledOS || isBuildOnly) {
1740                             return
1741                         }
1742
1743                         switch (architecture) {
1744                             case 'arm64':
1745                                 if ((scenario != 'gcstress0x3') && (scenario != 'gcstress0xc')) {
1746                                     return
1747                                 }
1748                                 break
1749                             case 'x64':
1750                             case 'x86':
1751                                 // x86 ubuntu: default only
1752                                 if ((os == 'Ubuntu') && (architecture == 'x86')) {
1753                                     return
1754                                 }
1755                                 // Windows: Everything implemented
1756                                 break
1757                             default:
1758                                 return
1759                         }
1760                     }
1761                     else {
1762                         // If this is a r2r jitstress, jitstressregs, jitminopts, or forcerelocs scenario
1763                         // and configuration is not Checked, bail out.
1764                         if (configuration != 'Checked' && Constants.r2rJitStressScenarios.indexOf(scenario) != -1) {
1765                             return;
1766                         }
1767
1768                         // Skip scenarios
1769                         switch (scenario) {
1770                             case 'pri1':
1771                                 // The pri1 build isn't necessary except for Windows_NT.  Non-Windows NT uses
1772                                 // the default scenario build
1773                                 if (os != 'Windows_NT') {
1774                                     return
1775                                 }
1776                                 // Only x64 for now
1777                                 if (architecture != 'x64') {
1778                                     return
1779                                 }
1780                                 break
1781                             case 'ilrt':
1782                                 // The ilrt build isn't necessary except for Windows_NT.  Non-Windows NT uses
1783                                 // the default scenario build
1784                                 if (os != 'Windows_NT') {
1785                                     return
1786                                 }
1787                                 // Only x64 for now
1788                                 if (architecture != 'x64') {
1789                                     return
1790                                 }
1791                                 // Release only
1792                                 if (configuration != 'Release') {
1793                                     return
1794                                 }
1795                                 break
1796                             case 'jitdiff':
1797                                 if (os != 'Windows_NT' && os != 'Ubuntu' && os != 'OSX10.12') {
1798                                     return
1799                                 }
1800                                 if (architecture != 'x64') {
1801                                     return
1802                                 }
1803                                 if (configuration != 'Checked') {
1804                                     return
1805                                 }
1806                                 break
1807                             case 'r2r':
1808                                 // The r2r build isn't necessary except for Windows_NT.  Non-Windows NT uses
1809                                 // the default scenario build
1810                                 if (os != 'Windows_NT') {
1811                                     return
1812                                 }
1813                                 if (architecture != 'x64') {
1814                                     return
1815                                 }
1816                                 break
1817                             case 'pri1r2r':
1818                                 // The pri1r2r build isn't necessary except for Windows_NT.  Non-Windows NT uses
1819                                 // the default scenario build
1820                                 if (os != 'Windows_NT') {
1821                                     return
1822                                 }
1823                                 if (architecture != 'x64') {
1824                                     if (architecture != 'arm64' || configuration == 'Debug') {
1825                                         return
1826                                     }
1827                                 }
1828                                 break
1829                             case 'gcstress15_pri1r2r':
1830                             case 'r2r_jitstress1':
1831                             case 'r2r_jitstress2':
1832                             case 'r2r_jitstressregs1':
1833                             case 'r2r_jitstressregs2':
1834                             case 'r2r_jitstressregs3':
1835                             case 'r2r_jitstressregs4':
1836                             case 'r2r_jitstressregs8':
1837                             case 'r2r_jitstressregs0x10':
1838                             case 'r2r_jitstressregs0x80':
1839                             case 'r2r_jitstressregs0x1000':
1840                             case 'r2r_jitminopts':
1841                             case 'r2r_jitforcerelocs':
1842                                 // The above builds are not necessary except for Windows_NT.  Non-Windows NT uses
1843                                 // the default scenario build
1844                                 if (os != 'Windows_NT') {
1845                                     return
1846                                 }
1847                                 if (architecture != 'x64') {
1848                                     return
1849                                 }
1850                                 break
1851                             case 'longgc':
1852                             case 'gcsimulator':
1853                                 if (os != 'Windows_NT' && os != 'Ubuntu' && os != 'OSX10.12') {
1854                                     return
1855                                 }
1856                                 if (architecture != 'x64') {
1857                                     return
1858                                 }
1859                                 if (configuration != 'Release') {
1860                                     return
1861                                 }
1862                                 break
1863                             case 'standalone_gc':
1864                                 if (os != 'Windows_NT' && os != 'Ubuntu' && os != 'OSX10.12') {
1865                                     return
1866                                 }
1867
1868                                 if (architecture != 'x64') {
1869                                     return
1870                                 }
1871
1872                                 if (configuration != 'Release' && configuration != 'Checked') {
1873                                     return
1874                                 }
1875                                 break
1876                             // We need Windows x64 Release bits for the code coverage build
1877                             case 'coverage':
1878                                 if (os != 'Windows_NT') {
1879                                     return
1880                                 }
1881                                 if (architecture != 'x64') {
1882                                     return
1883                                 }
1884                                 if (configuration != 'Release') {
1885                                     return
1886                                 }
1887                                 break
1888                             // We only run Windows and Ubuntu x64 Checked for formatting right now
1889                             case 'formatting':
1890                                 if (os != 'Windows_NT' && os != 'Ubuntu') {
1891                                     return
1892                                 }
1893                                 if (architecture != 'x64') {
1894                                     return
1895                                 }
1896                                 if (configuration != 'Checked') {
1897                                     return
1898                                 }
1899                                 if (isBuildOnly) {
1900                                     return
1901                                 }
1902                                 break
1903                             case 'illink':
1904                                 if (os != 'Windows_NT' && (os != 'Ubuntu' || architecture != 'x64')) {
1905                                     return
1906                                 }
1907                                 if (architecture != 'x64' && architecture != 'x86') {
1908                                     return
1909                                 }
1910                                 if (isBuildOnly) {
1911                                     return
1912                                 }
1913                                 break
1914                             case 'default':
1915                                 // Nothing skipped
1916                                 break
1917                             default:
1918                                 println("Unknown scenario: ${scenario}")
1919                                 assert false
1920                                 break
1921                         }
1922                     }
1923
1924                     // Calculate names
1925                     def lowerConfiguration = configuration.toLowerCase()
1926                     def jobName = getJobName(configuration, architecture, os, scenario, isBuildOnly)
1927                     def folderName = getJobFolder(scenario)
1928
1929                     // Create the new job
1930                     def newJob = job(Utilities.getFullJobName(project, jobName, isPR, folderName)) {}
1931
1932                     setMachineAffinity(newJob, os, architecture)
1933
1934                     // Add all the standard options
1935                     Utilities.standardJobSetup(newJob, project, isPR, "*/${branch}")
1936                     addTriggers(newJob, branch, isPR, architecture, os, configuration, scenario, false, isBuildOnly)
1937
1938                     def buildCommands = calculateBuildCommands(newJob, scenario, branch, isPR, architecture, configuration, os, enableCorefxTesting, isBuildOnly)
1939                     def osGroup = getOSGroup(os)
1940
1941                     newJob.with {
1942                         steps {
1943                             if (os == 'Windows_NT') {
1944                                 buildCommands.each { buildCommand ->
1945                                     batchFile(buildCommand)
1946                                 }
1947                             }
1948                             else {
1949                                 // Setup corefx and Windows test binaries for Linux cross build for ubuntu-arm, ubuntu16.04-arm and tizen-armel
1950                                 if ( architecture == 'arm' && ( os == 'Ubuntu' || os == 'Ubuntu16.04' || os == 'Tizen')) {
1951                                     // Cross build for ubuntu-arm, ubuntu16.04-arm and tizen-armel
1952                                     // Define the Windows Tests and Corefx build job names
1953                                     def WindowTestsName = projectFolder + '/' +
1954                                                           Utilities.getFullJobName(project,
1955                                                                                    getJobName(lowerConfiguration,
1956                                                                                               'x64' ,
1957                                                                                               'windows_nt',
1958                                                                                               'default',
1959                                                                                               true),
1960                                                                                    false)
1961                                     def corefxFolder = Utilities.getFolderName('dotnet/corefx') + '/' +
1962                                                        Utilities.getFolderName(branch)
1963
1964                                     // Copy the Windows test binaries and the Corefx build binaries
1965                                     copyArtifacts(WindowTestsName) {
1966                                         excludePatterns('**/testResults.xml', '**/*.ni.dll')
1967                                         buildSelector {
1968                                             latestSuccessful(true)
1969                                         }
1970                                     }
1971
1972                                     // Defaults for Ubuntu
1973                                     def arm_abi = 'arm'
1974                                     def corefx_os = 'ubuntu14.04'
1975                                     if (os == 'Ubuntu16.04') {
1976                                         arm_abi = 'arm'
1977                                         corefx_os = 'ubuntu16.04'
1978                                     }
1979                                     else if (os == 'Tizen') {
1980                                         arm_abi = 'armel'
1981                                         corefx_os = 'tizen'
1982                                     }
1983
1984                                     // Let's use release CoreFX to test checked CoreCLR,
1985                                     // because we do not generate checked CoreFX in CoreFX CI yet.
1986                                     def corefx_lowerConfiguration = lowerConfiguration
1987                                     if ( lowerConfiguration == 'checked' ) {
1988                                         corefx_lowerConfiguration='release'
1989                                     }
1990                                     copyArtifacts("${corefxFolder}/${corefx_os}_${arm_abi}_cross_${corefx_lowerConfiguration}") {
1991                                         includePatterns('bin/build.tar.gz')
1992                                         buildSelector {
1993                                             latestSuccessful(true)
1994                                         }
1995                                     }
1996                                 }
1997
1998                                 buildCommands.each { buildCommand ->
1999                                     shell(buildCommand)
2000                                 }
2001                             }
2002                         }
2003                     } // newJob.with
2004
2005                 } // os
2006             } // configuration
2007         } // architecture
2008     } // isPR
2009 } // scenario
2010
2011
2012 // Create the Linux/OSX/CentOS coreclr test leg for debug and release and each scenario
2013 combinedScenarios.each { scenario ->
2014     [true, false].each { isPR ->
2015         // Architectures.  x64 only at this point
2016         ['x64'].each { architecture ->
2017             // Put the OS's supported for coreclr cross testing here
2018             Constants.crossList.each { os ->
2019                 Constants.configurationList.each { configuration ->
2020
2021                     if (Constants.jitStressModeScenarios.containsKey(scenario)) {
2022                         if (configuration != 'Checked') {
2023                             return
2024                         }
2025                         if (isCorefxTesting(scenario)) {
2026                             return
2027                         }
2028                         //Skip stress modes for these scenarios
2029                         if (os == 'RHEL7.2' || os == 'Debian8.4') {
2030                             return
2031                         }
2032                     }
2033                     // If this is a r2r jitstress, jitstressregs, jitminopts or forcerelocs scenario
2034                     // and configuration is not Checked, bail out.
2035                     else if (configuration != 'Checked' && Constants.r2rJitStressScenarios.indexOf(scenario) != -1) {
2036                         return;
2037                     }
2038                     // For CentOS, we only want Checked/Release pri1 builds.
2039                     else if (os == 'CentOS7.1') {
2040                         if (scenario != 'pri1' &&
2041                             scenario != 'r2r' &&
2042                             scenario != 'pri1r2r' &&
2043                             scenario != 'gcstress15_pri1r2r' &&
2044                             Constants.r2rJitStressScenarios.indexOf(scenario) == -1) {
2045                             return
2046                         }
2047                         if (configuration != 'Checked' && configuration != 'Release') {
2048                             return
2049                         }
2050                     }
2051                     // For RedHat and Debian, we only do Release pri1 builds.
2052                     else if (os == 'RHEL7.2' || os == 'Debian8.4') {
2053                         if (scenario != 'pri1') {
2054                             return
2055                         }
2056                         if (configuration != 'Release') {
2057                             return
2058                         }
2059                     }
2060                     else {
2061                         // Skip scenarios
2062                         switch (scenario) {
2063                             case 'pri1':
2064                                 // Nothing skipped
2065                                 break
2066                             case 'ilrt':
2067                                 // Release only
2068                                 if (configuration != 'Release') {
2069                                     return
2070                                 }
2071                                 break
2072                             case 'jitdiff':
2073                                 if (configuration != 'Checked') {
2074                                     return;
2075                                 }
2076                             case 'r2r':
2077                                 //Skip configs that aren't Checked or Release (so just Debug, for now)
2078                                 if (configuration != 'Checked' && configuration != 'Release') {
2079                                     return
2080                                 }
2081                                 break
2082                             case 'pri1r2r':
2083                                 //Skip configs that aren't Checked or Release (so just Debug, for now)
2084                                 if (configuration != 'Checked' && configuration != 'Release') {
2085                                     return
2086                                 }
2087                                 break
2088                             case 'gcstress15_pri1r2r':
2089                             case 'r2r_jitstress1':
2090                             case 'r2r_jitstress2':
2091                             case 'r2r_jitstressregs1':
2092                             case 'r2r_jitstressregs2':
2093                             case 'r2r_jitstressregs3':
2094                             case 'r2r_jitstressregs4':
2095                             case 'r2r_jitstressregs8':
2096                             case 'r2r_jitstressregs0x10':
2097                             case 'r2r_jitstressregs0x80':
2098                             case 'r2r_jitstressregs0x1000':
2099                             case 'r2r_jitminopts':
2100                             case 'r2r_jitforcerelocs':
2101                                 //Skip configs that aren't Checked or Release (so just Debug, for now)
2102                                 if (configuration != 'Checked' && configuration != 'Release') {
2103                                     return
2104                                 }
2105                                 break
2106                             case 'longgc':
2107                             case 'gcsimulator':
2108                                 // Long GC tests take a long time on non-Release builds
2109                                 if (configuration != 'Release') {
2110                                     return
2111                                 }
2112                                 break
2113                             case 'standalone_gc':
2114                                 if (configuration != 'Release' && configuration != 'Checked') {
2115                                     return
2116                                 }
2117                             case 'coverage':
2118                                 //We only want Ubuntu Release for coverage
2119                                 if (os != 'Ubuntu') {
2120                                     return
2121                                 }
2122                                 if (configuration != 'Release') {
2123                                     return
2124                                 }
2125                             case 'formatting':
2126                                 return
2127                             case 'illink':
2128                                 if (os != 'Windows_NT' && os != 'Ubuntu') {
2129                                     return
2130                                 }
2131                                 break
2132                             case 'default':
2133                                 // Nothing skipped
2134                                 break
2135                             default:
2136                                 println("Unknown scenario: ${scenario}")
2137                                 assert false
2138                                 break
2139                         }
2140                     }
2141
2142                     def lowerConfiguration = configuration.toLowerCase()
2143                     def osGroup = getOSGroup(os)
2144                     def jobName = getJobName(configuration, architecture, os, scenario, false) + "_tst"
2145
2146                     // Unless this is a coverage test run, we want to copy over the default build of coreclr.
2147                     def inputScenario = 'default'
2148                     if (scenario == 'coverage') {
2149                         inputScenario = 'coverage'
2150                     }
2151                     def inputCoreCLRBuildName = projectFolder + '/' +
2152                         Utilities.getFullJobName(project, getJobName(configuration, architecture, os, inputScenario, false), isPR)
2153                     // If this is a stress scenario, there isn't any difference in the build job
2154                     // so we didn't create a build only job for windows_nt specific to that stress mode.  Just copy
2155                     // from the default scenario
2156                     def testBuildScenario = scenario
2157                     if (testBuildScenario == 'coverage' || testBuildScenario == 'pri1r2r'|| testBuildScenario == 'gcstress15_pri1r2r') {
2158                         testBuildScenario = 'pri1'
2159                     }
2160                     else if ( testBuildScenario == 'r2r' || isLongGc(testBuildScenario)) {
2161                         testBuildScenario = 'default'
2162                     }
2163                     def inputWindowTestsBuildName = ''
2164                     if (Constants.jitStressModeScenarios.containsKey(testBuildScenario)) {
2165                         inputWindowTestsBuildName = projectFolder + '/' +
2166                             Utilities.getFullJobName(project, getJobName(configuration, architecture, 'windows_nt', 'default', true), isPR)
2167                     }
2168                     else {
2169                         inputWindowTestsBuildName = projectFolder + '/' +
2170                             Utilities.getFullJobName(project, getJobName(configuration, architecture, 'windows_nt', testBuildScenario, true), isPR)
2171                     }
2172                     // Enable Server GC for Ubuntu PR builds
2173                     def serverGCString = ''
2174
2175                     // Whether or not this test run should be run sequentially instead
2176                     // of in parallel. Only used for long GC tests.
2177                     def sequentialString = ''
2178
2179                     // Whether or not this test run should run a specific playlist.
2180                     // Only used for long GC tests.
2181
2182                     // A note - runtest.sh does have "--long-gc" and "--gcsimulator" options
2183                     // for running long GC and GCSimulator tests, respectively. We don't use them
2184                     // here because using a playlist file produces much more readable output on the CI machines
2185                     // and reduces running time.
2186                     def playlistString = ''
2187
2188                     if (os == 'Ubuntu' && isPR){
2189                         serverGCString = '--useServerGC'
2190                     }
2191
2192                     // pass --crossgen to runtest.sh for crossgen builds
2193                     def crossgenStr = ''
2194                     def runcrossgentestsStr = ''
2195                     def runjitstressStr = ''
2196                     def runjitstressregsStr = ''
2197                     def runjitmioptsStr = ''
2198                     def runjitforcerelocsStr = ''
2199                     def runjitdisasmStr = ''
2200                     def gcstressStr = ''
2201                     def illinkStr = ''
2202
2203                     if (scenario == 'r2r' ||
2204                         scenario == 'pri1r2r' ||
2205                         scenario == 'gcstress15_pri1r2r' ||
2206                         Constants.r2rJitStressScenarios.indexOf(scenario) != -1) {
2207                             crossgenStr = '--crossgen'
2208                             runcrossgentestsStr = '--runcrossgentests'
2209
2210                             if (scenario == 'r2r_jitstress1'){
2211                                 runjitstressStr = '--jitstress=1'
2212                             }
2213                             else if (scenario == 'r2r_jitstress2') {
2214                                 runjitstressStr = '--jitstress=2'
2215                             }
2216                             else if (scenario == 'r2r_jitstressregs1'){
2217                                 runjitstressregsStr = '--jitstressregs=1'
2218                             }
2219                             else if (scenario == 'r2r_jitstressregs2') {
2220                                 runjitstressregsStr = '--jitstressregs=2'
2221                             }
2222                             else if (scenario == 'r2r_jitstressregs3') {
2223                                 runjitstressregsStr = '--jitstressregs=3'
2224                             }
2225                             else if (scenario == 'r2r_jitstressregs4') {
2226                                 runjitstressregsStr = '--jitstressregs=4'
2227                             }
2228                             else if (scenario == 'r2r_jitstressregs8') {
2229                                 runjitstressregsStr = '--jitstressregs=8'
2230                             }
2231                             else if (scenario == 'r2r_jitstressregs0x10') {
2232                                 runjitstressregsStr = '--jitstressregs=0x10'
2233                             }
2234                             else if (scenario == 'r2r_jitstressregs0x80') {
2235                                 runjitstressregsStr = '--jitstressregs=0x80'
2236                             }
2237                             else if (scenario == 'r2r_jitstressregs0x1000') {
2238                                 runjitstressregsStr = '--jitstressregs=0x1000'
2239                             }
2240                             else if (scenario == 'r2r_jitminopts') {
2241                                 runjitmioptsStr = '--jitminopts'
2242                             }
2243                             else if (scenario == 'r2r_jitforcerelocs') {
2244                                 runjitforcerelocsStr = '--jitforcerelocs'
2245                             }
2246                     }
2247                     if  (scenario == 'gcstress15_pri1r2r')
2248                     {
2249                         gcstressStr = '--gcstresslevel=0xF'
2250                     }
2251
2252                     if (scenario == 'jitdiff')
2253                     {
2254                         runjitdisasmStr = '--jitdisasm --crossgen'
2255                     }
2256
2257                     if (scenario == 'illink')
2258                     {
2259                         illinkStr = '--link=\$WORKSPACE/linker/linker/bin/netcore_Release/netcoreapp2.0/ubuntu-x64/publish/illink'
2260                     }
2261
2262                     if (isLongGc(scenario)) {
2263                         // Long GC tests behave very poorly when they are not
2264                         // the only test running (many of them allocate until OOM).
2265                         sequentialString = '--sequential'
2266
2267                         // The Long GC playlist contains all of the tests that are
2268                         // going to be run. The GCSimulator playlist contains all of
2269                         // the GC simulator tests.
2270                         if (scenario == 'longgc') {
2271                             playlistString = '--long-gc --playlist=./tests/longRunningGcTests.txt'
2272                         }
2273                         else if (scenario == 'gcsimulator') {
2274                             playlistString = '--gcsimulator --playlist=./tests/gcSimulatorTests.txt'
2275                         }
2276                     }
2277
2278                     def folder = getJobFolder(scenario)
2279                     def newJob = job(Utilities.getFullJobName(project, jobName, isPR, folder)) {
2280                         // Add parameters for the inputs
2281
2282                         parameters {
2283                             stringParam('CORECLR_WINDOWS_BUILD', '', 'Build number to copy CoreCLR windows test binaries from')
2284                             stringParam('CORECLR_BUILD', '', "Build number to copy CoreCLR ${osGroup} binaries from")
2285                         }
2286
2287                         steps {
2288                             // Set up the copies
2289
2290                             // Coreclr build containing the tests and mscorlib
2291
2292                             copyArtifacts(inputWindowTestsBuildName) {
2293                                 excludePatterns('**/testResults.xml', '**/*.ni.dll')
2294                                 buildSelector {
2295                                     buildNumber('${CORECLR_WINDOWS_BUILD}')
2296                                 }
2297                             }
2298
2299                             if (scenario == 'coverage') {
2300
2301                                 // Move coreclr to clr directory
2302                                 shell("rm -rf .clr; mkdir .clr; mv * .clr; mv .git .clr; mv .clr clr")
2303
2304                                 // Build coreclr
2305                                 shell("./clr/build.sh coverage verbose ${lowerConfiguration} ${architecture}")
2306
2307                                 // Remove folders from obj that we don't expect to be covered. May update this later.
2308                                 shell("rm -rf ./clr/bin/obj/Linux.x64.Release/src/ToolBox")
2309                                 shell("rm -rf ./clr/bin/obj/Linux.x64.Release/src/debug")
2310                                 shell("rm -rf ./clr/bin/obj/Linux.x64.Release/src/ilasm")
2311                                 shell("rm -rf ./clr/bin/obj/Linux.x64.Release/src/ildasm")
2312                                 shell("rm -rf ./clr/bin/obj/Linux.x64.Release/src/dlls/dbgshim")
2313                                 shell("rm -rf ./clr/bin/obj/Linux.x64.Release/src/dlls/mscordac")
2314                                 shell("rm -rf ./clr/bin/obj/Linux.x64.Release/src/dlls/mscordbi")
2315
2316                                 // Run PAL tests
2317                                 shell("./clr/src/pal/tests/palsuite/runpaltests.sh \$(pwd)/clr/bin/obj/${osGroup}.${architecture}.${configuration} \$(pwd)/clr/bin/paltestout")
2318
2319                                 // Remove obj files for PAL tests so they're not included in coverage results
2320                                 shell("rm -rf ./clr/bin/obj/Linux.x64.Release/src/pal/tests")
2321
2322                                 // Unzip the tests first.  Exit with 0
2323                                 shell("unzip -q -o ./clr/bin/tests/tests.zip -d ./clr/bin/tests/Windows_NT.${architecture}.${configuration} || exit 0")
2324
2325                                 // Get corefx
2326                                 shell("git clone https://github.com/dotnet/corefx fx")
2327
2328                                 // Build Linux corefx
2329                                 shell("./fx/build-native.sh -release -buildArch=x64 -os=Linux")
2330                                 shell("./fx/build-managed.sh -release -buildArch=x64 -osgroup=Linux -skiptests")
2331
2332                                 def testEnvOpt = ""
2333                                 def scriptFileName = "\$WORKSPACE/set_stress_test_env.sh"
2334                                 def createScriptCmds = genStressModeScriptStep(os, scenario, Constants.jitStressModeScenarios['heapverify1'], scriptFileName)
2335                                 shell("${createScriptCmds}")
2336                                 testEnvOpt = "--test-env=" + scriptFileName
2337
2338                                 // Run corefx tests
2339                                 shell("""./fx/run-test.sh \\
2340                 --coreclr-bins \$(pwd)/clr/bin/Product/${osGroup}.${architecture}.${configuration} \\
2341                 --mscorlib-bins \$(pwd)/clr/bin/Product/${osGroup}.${architecture}.${configuration} \\
2342                 --corefx-tests \$(pwd)/fx/bin/tests/${osGroup}.AnyCPU.${configuration} \\
2343                 --corefx-native-bins \$(pwd)/fx/bin/${osGroup}.${architecture}.${configuration} \\
2344                 --configurationGroup Release""")
2345
2346
2347                                 // Run coreclr tests w/ workstation GC
2348                                 shell("""./clr/tests/runtest.sh \\
2349                 --testRootDir=\"\$(pwd)/clr/bin/tests/Windows_NT.${architecture}.${configuration}\" \\
2350                 --testNativeBinDir=\"\$(pwd)/clr/bin/obj/${osGroup}.${architecture}.${configuration}/tests\" \\
2351                 --coreClrBinDir=\"\$(pwd)/clr/bin/Product/${osGroup}.${architecture}.${configuration}\" \\
2352                 --mscorlibDir=\"\$(pwd)/clr/bin/Product/${osGroup}.${architecture}.${configuration}\" \\
2353                 --coreFxBinDir=\"\$(pwd)/fx/bin/runtime/netcoreapp-${osGroup}-Release-${architecture}\" \\
2354                 --crossgen --runcrossgentests""")
2355
2356                                 // Run coreclr tests w/ server GC & HeapVerify enabled
2357                                 shell("""./clr/tests/runtest.sh \\
2358                 --testRootDir=\"\$(pwd)/clr/bin/tests/Windows_NT.${architecture}.${configuration}\" \\
2359                 --testNativeBinDir=\"\$(pwd)/clr/bin/obj/${osGroup}.${architecture}.${configuration}/tests\" \\
2360                 --coreOverlayDir=\"\$(pwd)/clr/bin/tests/Windows_NT.${architecture}.${configuration}/Tests/coreoverlay\" \\
2361                 --useServerGC ${testEnvOpt}""")
2362
2363                                  // Run long-running coreclr GC tests & produce coverage reports
2364                                 shell("""./clr/tests/runtest.sh \\
2365                 --testRootDir=\"\$(pwd)/clr/bin/tests/Windows_NT.${architecture}.${configuration}\" \\
2366                 --testNativeBinDir=\"\$(pwd)/clr/bin/obj/${osGroup}.${architecture}.${configuration}/tests\" \\
2367                 --coreOverlayDir=\"\$(pwd)/clr/bin/tests/Windows_NT.${architecture}.${configuration}/Tests/coreoverlay\" \\
2368                 --long-gc --playlist=\"\$(pwd)/clr/tests/longRunningGcTests.txt\" --coreclr-coverage\\
2369                 --coreclr-objs=\"\$(pwd)/clr/bin/obj/${osGroup}.${architecture}.${configuration}\" \\
2370                 --coreclr-src=\"\$(pwd)/clr/src\" \\
2371                 --coverage-output-dir=\"\${WORKSPACE}/coverage\" """)
2372
2373                             }
2374                             else {
2375
2376                                 // Coreclr build we are trying to test
2377
2378                                 copyArtifacts(inputCoreCLRBuildName) {
2379                                     excludePatterns('**/testResults.xml', '**/*.ni.dll')
2380                                     buildSelector {
2381                                         buildNumber('${CORECLR_BUILD}')
2382                                     }
2383                                 }
2384
2385                                 def corefxFolder = Utilities.getFolderName('dotnet/corefx') + '/' + Utilities.getFolderName(branch)
2386
2387                                 // Corefx components.  We now have full stack builds on all distros we test here, so we can copy straight from CoreFX jobs.
2388                                 def osJobName
2389                                 if (os == 'Ubuntu') {
2390                                     osJobName = 'ubuntu14.04'
2391                                 }
2392                                 else {
2393                                     osJobName = os.toLowerCase()
2394                                 }
2395                                 copyArtifacts("${corefxFolder}/${osJobName}_release") {
2396                                     includePatterns('bin/build.tar.gz')
2397                                     buildSelector {
2398                                         latestSuccessful(true)
2399                                     }
2400                                 }
2401
2402                                 shell ("mkdir ./bin/CoreFxBinDir")
2403                                 // Unpack the corefx binaries
2404                                 shell("tar -xf ./bin/build.tar.gz -C ./bin/CoreFxBinDir")
2405
2406                                 // Unzip the tests first.  Exit with 0
2407                                 shell("unzip -q -o ./bin/tests/tests.zip -d ./bin/tests/Windows_NT.${architecture}.${configuration} || exit 0")
2408
2409                                 // Execute the tests
2410                                 // If we are running a stress mode, we'll set those variables first
2411                                 def testEnvOpt = ""
2412                                 if (Constants.jitStressModeScenarios.containsKey(scenario)) {
2413                                     def scriptFileName = "\$WORKSPACE/set_stress_test_env.sh"
2414                                     def createScriptCmds = genStressModeScriptStep(os, scenario, Constants.jitStressModeScenarios[scenario], scriptFileName)
2415                                     shell("${createScriptCmds}")
2416                                     testEnvOpt = "--test-env=" + scriptFileName
2417                                 }
2418
2419                                 if (isGCStressRelatedTesting(scenario)) {
2420                                     shell('./init-tools.sh')
2421                                 }
2422
2423                                 shell("""./tests/runtest.sh \\
2424                 --testRootDir=\"\${WORKSPACE}/bin/tests/Windows_NT.${architecture}.${configuration}\" \\
2425                 --testNativeBinDir=\"\${WORKSPACE}/bin/obj/${osGroup}.${architecture}.${configuration}/tests\" \\
2426                 --coreClrBinDir=\"\${WORKSPACE}/bin/Product/${osGroup}.${architecture}.${configuration}\" \\
2427                 --mscorlibDir=\"\${WORKSPACE}/bin/Product/${osGroup}.${architecture}.${configuration}\" \\
2428                 --coreFxBinDir=\"\${WORKSPACE}/bin/CoreFxBinDir\" \\
2429                 --limitedDumpGeneration \\
2430                 ${testEnvOpt} ${serverGCString} ${gcstressStr} ${crossgenStr} ${runcrossgentestsStr} ${runjitstressStr} ${runjitstressregsStr} ${runjitmioptsStr} ${runjitforcerelocsStr} ${runjitdisasmStr} ${illinkStr} ${sequentialString} ${playlistString}""")
2431                             }
2432                         }
2433                     }
2434
2435                     if (scenario == 'coverage') {
2436                         // Publish coverage reports
2437                         Utilities.addHtmlPublisher(newJob, '${WORKSPACE}/coverage/Coverage/reports', 'Code Coverage Report', 'coreclr.html')
2438                         // TODO: Add once external email sending is available again
2439                         // addEmailPublisher(newJob, 'clrcoverage@microsoft.com')
2440                     }
2441
2442                     if (scenario == 'jitdiff') {
2443                         Utilities.addArchival(newJob, "bin/tests/${osGroup}.${architecture}.${configuration}/dasm/**")
2444                     }
2445
2446                     // Experimental: If on Ubuntu 14.04, then attempt to pull in crash dump links
2447                     if (os in ['Ubuntu']) {
2448                         SummaryBuilder summaries = new SummaryBuilder()
2449                         summaries.addLinksSummaryFromFile('Crash dumps from this run:', 'dumplings.txt')
2450                         summaries.emit(newJob)
2451                     }
2452
2453                     setMachineAffinity(newJob, os, architecture)
2454                     Utilities.standardJobSetup(newJob, project, isPR, "*/${branch}")
2455                     // Set timeouts to 240.
2456                     setTestJobTimeOut(newJob, scenario)
2457                     Utilities.addXUnitDotNETResults(newJob, '**/coreclrtests.xml')
2458
2459                     // Create a build flow to join together the build and tests required to run this
2460                     // test.
2461                     // Windows CoreCLR build and Linux CoreCLR build (in parallel) ->
2462                     // Linux CoreCLR test
2463                     def flowJobName = getJobName(configuration, architecture, os, scenario, false) + "_flow"
2464                     def fullTestJobName = projectFolder + '/' + newJob.name
2465                     // Add a reference to the input jobs for report purposes
2466                     JobReport.Report.addReference(inputCoreCLRBuildName)
2467                     JobReport.Report.addReference(inputWindowTestsBuildName)
2468                     JobReport.Report.addReference(fullTestJobName)
2469                     def newFlowJob;
2470
2471                     // If this is a coverage job, we don't copy any input coreCLR build - instead, we build it as part of the flow job,
2472                     // so that coverage data can be preserved.
2473                     if (scenario == 'coverage') {
2474                         newFlowJob = buildFlowJob(Utilities.getFullJobName(project, flowJobName, isPR, folder)) {
2475                         buildFlow("""
2476 // Build the input Windows job
2477 windowsBuildJob = build(params, '${inputWindowTestsBuildName}')
2478
2479 // And then build the test build
2480 build(params + [CORECLR_WINDOWS_BUILD: windowsBuildJob.build.number], '${fullTestJobName}')
2481 """)
2482                         }
2483                     // Normal jobs copy a Windows build & a non-Windows build
2484                     } else {
2485                         newFlowJob = buildFlowJob(Utilities.getFullJobName(project, flowJobName, isPR, folder)) {
2486                         buildFlow("""
2487 // Build the input jobs in parallel
2488 parallel (
2489     { coreclrBuildJob = build(params, '${inputCoreCLRBuildName}') },
2490     { windowsBuildJob = build(params, '${inputWindowTestsBuildName}') }
2491 )
2492
2493 // And then build the test build
2494 build(params + [CORECLR_BUILD: coreclrBuildJob.build.number,
2495                 CORECLR_WINDOWS_BUILD: windowsBuildJob.build.number], '${fullTestJobName}')
2496 """)
2497                         }
2498                     }
2499
2500                     setMachineAffinity(newFlowJob, os, architecture)
2501                     Utilities.standardJobSetup(newFlowJob, project, isPR, "*/${branch}")
2502                     addTriggers(newFlowJob, branch, isPR, architecture, os, configuration, scenario, true, false)
2503                 } // configuration
2504             } // os
2505         } // architecture
2506     } // isPR
2507 } // scenario
2508
2509 JobReport.Report.generateJobReport(out)
2510
2511 // Make the call to generate the help job
2512 Utilities.createHelperJob(this, project, branch,
2513     "Welcome to the ${project} Repository",  // This is prepended to the help message
2514     "Have a nice day!")  // This is appended to the help message.  You might put known issues here.
2515
2516 Utilities.addCROSSCheck(this, project, branch)