Merge pull request #11187 from wtgodbe/NonWindowsR2R
[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                     if (os != 'Tizen') {
1641                         buildCommands += "chmod a+x ./bin/CoreFxBinDir/corerun"
1642                     }
1643                     // Test environment emulation using docker and qemu has some problem to use lttng library.
1644                     // We should remove libcoreclrtraceptprovider.so to avoid test hang.
1645                     if (os == 'Ubuntu') {
1646                         buildCommands += "rm -f -v ./bin/CoreFxBinDir/libcoreclrtraceptprovider.so"
1647                     }
1648
1649                     // Call the ARM CI script to cross build and test using docker
1650                     buildCommands += """./tests/scripts/arm32_ci_script.sh \\
1651                     --mode=docker \\
1652                     --${arm_abi} \\
1653                     --linuxCodeName=${linuxCodeName} \\
1654                     --buildConfig=${lowerConfiguration} \\
1655                     --testRootDir=./bin/tests/Windows_NT.x64.${configuration} \\
1656                     --coreFxBinDir=./bin/CoreFxBinDir \\
1657                     --testDirFile=./tests/testsRunningInsideARM.txt"""
1658
1659                     // Basic archiving of the build, no pal tests
1660                     Utilities.addArchival(newJob, "bin/Product/**", "bin/Product/**/.nuget/**")
1661                     break
1662                 default:
1663                     println("Unknown architecture: ${architecture}");
1664                     assert false
1665                     break
1666             }
1667             break
1668         // editor brace matching: }
1669         default:
1670             println("Unknown os: ${os}");
1671             assert false
1672             break
1673     } // os
1674
1675     return buildCommands
1676 }
1677
1678 // Additional scenario which can alter behavior
1679
1680 def combinedScenarios = Constants.basicScenarios + Constants.jitStressModeScenarios.keySet()
1681 combinedScenarios.each { scenario ->
1682     [true, false].each { isPR ->
1683         Constants.architectureList.each { architecture ->
1684             Constants.configurationList.each { configuration ->
1685                 Constants.osList.each { os ->
1686                     // If the OS is Windows_NT_BuildOnly, set the isBuildOnly flag to true
1687                     // and reset the os to Windows_NT
1688                     def isBuildOnly = false
1689                     if (os == 'Windows_NT_BuildOnly') {
1690                         isBuildOnly = true
1691                         os = 'Windows_NT'
1692                     }
1693
1694                     // WinArm32 is only built for Debug and Release
1695                     if (os == 'Windows_NT' && architecture == 'arm')
1696                     {
1697                         if (configuration == 'Checked')
1698                         {
1699                             return
1700                         }
1701                     }
1702                     // Tizen is only supported for arm architecture
1703                     if (os == 'Tizen' && architecture != 'arm') {
1704                         return
1705                     }
1706
1707                     // Skip totally unimplemented (in CI) configurations.
1708                     switch (architecture) {
1709                         case 'arm64':
1710                             // Windows only
1711                             if (os != 'Windows_NT' || isBuildOnly) {
1712                                 return
1713                             }
1714                             break
1715                         case 'arm':
1716                             if ((os != 'Ubuntu') && (os != 'Ubuntu16.04') && (os != 'Tizen') && (os != 'Windows_NT')) {
1717                                 return
1718                             }
1719                             break
1720                         case 'x86':
1721                             if ((os != 'Ubuntu') && (os != 'Windows_NT')) {
1722                                 return
1723                             }
1724                             break
1725                         case 'x64':
1726                             // Everything implemented
1727                             break
1728                         default:
1729                             println("Unknown architecture: ${architecture}")
1730                             assert false
1731                             break
1732                     }
1733
1734                     // Skip scenarios (blanket skipping for jit stress modes, which are good most everywhere
1735                     // with checked builds
1736                     def enableCorefxTesting = false
1737                     if (Constants.jitStressModeScenarios.containsKey(scenario)) {
1738                         if (configuration != 'Checked') {
1739                             return
1740                         }
1741
1742                         enableCorefxTesting = isCorefxTesting(scenario)
1743
1744                         // Since these are just execution time differences,
1745                         // skip platforms that don't execute the tests here (Windows_NT only)
1746                         def isEnabledOS = (os == 'Windows_NT') || (os == 'Ubuntu' && enableCorefxTesting)
1747                         if (!isEnabledOS || isBuildOnly) {
1748                             return
1749                         }
1750
1751                         switch (architecture) {
1752                             case 'arm64':
1753                                 if ((scenario != 'gcstress0x3') && (scenario != 'gcstress0xc')) {
1754                                     return
1755                                 }
1756                                 break
1757                             case 'x64':
1758                             case 'x86':
1759                                 // x86 ubuntu: default only
1760                                 if ((os == 'Ubuntu') && (architecture == 'x86')) {
1761                                     return
1762                                 }
1763                                 // Windows: Everything implemented
1764                                 break
1765                             default:
1766                                 return
1767                         }
1768                     }
1769                     else {
1770                         // If this is a r2r jitstress, jitstressregs, jitminopts, or forcerelocs scenario
1771                         // and configuration is not Checked, bail out.
1772                         if (configuration != 'Checked' && Constants.r2rJitStressScenarios.indexOf(scenario) != -1) {
1773                             return;
1774                         }
1775
1776                         // Skip scenarios
1777                         switch (scenario) {
1778                             case 'pri1':
1779                                 // The pri1 build isn't necessary except for Windows_NT.  Non-Windows NT uses
1780                                 // the default scenario build
1781                                 if (os != 'Windows_NT') {
1782                                     return
1783                                 }
1784                                 // Only x64 for now
1785                                 if (architecture != 'x64') {
1786                                     return
1787                                 }
1788                                 break
1789                             case 'ilrt':
1790                                 // The ilrt build isn't necessary except for Windows_NT.  Non-Windows NT uses
1791                                 // the default scenario build
1792                                 if (os != 'Windows_NT') {
1793                                     return
1794                                 }
1795                                 // Only x64 for now
1796                                 if (architecture != 'x64') {
1797                                     return
1798                                 }
1799                                 // Release only
1800                                 if (configuration != 'Release') {
1801                                     return
1802                                 }
1803                                 break
1804                             case 'jitdiff':
1805                                 if (os != 'Windows_NT' && os != 'Ubuntu' && os != 'OSX10.12') {
1806                                     return
1807                                 }
1808                                 if (architecture != 'x64') {
1809                                     return
1810                                 }
1811                                 if (configuration != 'Checked') {
1812                                     return
1813                                 }
1814                                 break
1815                             case 'r2r':
1816                                 // The r2r build isn't necessary except for Windows_NT.  Non-Windows NT uses
1817                                 // the default scenario build
1818                                 if (os != 'Windows_NT') {
1819                                     return
1820                                 }
1821                                 if (architecture != 'x64') {
1822                                     return
1823                                 }
1824                                 break
1825                             case 'pri1r2r':
1826                                 // The pri1r2r build isn't necessary except for Windows_NT.  Non-Windows NT uses
1827                                 // the default scenario build
1828                                 if (os != 'Windows_NT') {
1829                                     return
1830                                 }
1831                                 if (architecture != 'x64') {
1832                                     if (architecture != 'arm64' || configuration == 'Debug') {
1833                                         return
1834                                     }
1835                                 }
1836                                 break
1837                             case 'gcstress15_pri1r2r':
1838                             case 'r2r_jitstress1':
1839                             case 'r2r_jitstress2':
1840                             case 'r2r_jitstressregs1':
1841                             case 'r2r_jitstressregs2':
1842                             case 'r2r_jitstressregs3':
1843                             case 'r2r_jitstressregs4':
1844                             case 'r2r_jitstressregs8':
1845                             case 'r2r_jitstressregs0x10':
1846                             case 'r2r_jitstressregs0x80':
1847                             case 'r2r_jitstressregs0x1000':
1848                             case 'r2r_jitminopts':
1849                             case 'r2r_jitforcerelocs':
1850                                 // The above builds are not necessary except for Windows_NT.  Non-Windows NT uses
1851                                 // the default scenario build
1852                                 if (os != 'Windows_NT') {
1853                                     return
1854                                 }
1855                                 if (architecture != 'x64') {
1856                                     return
1857                                 }
1858                                 break
1859                             case 'longgc':
1860                             case 'gcsimulator':
1861                                 if (os != 'Windows_NT' && os != 'Ubuntu' && os != 'OSX10.12') {
1862                                     return
1863                                 }
1864                                 if (architecture != 'x64') {
1865                                     return
1866                                 }
1867                                 if (configuration != 'Release') {
1868                                     return
1869                                 }
1870                                 break
1871                             case 'standalone_gc':
1872                                 if (os != 'Windows_NT' && os != 'Ubuntu' && os != 'OSX10.12') {
1873                                     return
1874                                 }
1875
1876                                 if (architecture != 'x64') {
1877                                     return
1878                                 }
1879
1880                                 if (configuration != 'Release' && configuration != 'Checked') {
1881                                     return
1882                                 }
1883                                 break
1884                             // We need Windows x64 Release bits for the code coverage build
1885                             case 'coverage':
1886                                 if (os != 'Windows_NT') {
1887                                     return
1888                                 }
1889                                 if (architecture != 'x64') {
1890                                     return
1891                                 }
1892                                 if (configuration != 'Release') {
1893                                     return
1894                                 }
1895                                 break
1896                             // We only run Windows and Ubuntu x64 Checked for formatting right now
1897                             case 'formatting':
1898                                 if (os != 'Windows_NT' && os != 'Ubuntu') {
1899                                     return
1900                                 }
1901                                 if (architecture != 'x64') {
1902                                     return
1903                                 }
1904                                 if (configuration != 'Checked') {
1905                                     return
1906                                 }
1907                                 if (isBuildOnly) {
1908                                     return
1909                                 }
1910                                 break
1911                             case 'illink':
1912                                 if (os != 'Windows_NT' && (os != 'Ubuntu' || architecture != 'x64')) {
1913                                     return
1914                                 }
1915                                 if (architecture != 'x64' && architecture != 'x86') {
1916                                     return
1917                                 }
1918                                 if (isBuildOnly) {
1919                                     return
1920                                 }
1921                                 break
1922                             case 'default':
1923                                 // Nothing skipped
1924                                 break
1925                             default:
1926                                 println("Unknown scenario: ${scenario}")
1927                                 assert false
1928                                 break
1929                         }
1930                     }
1931
1932                     // Calculate names
1933                     def lowerConfiguration = configuration.toLowerCase()
1934                     def jobName = getJobName(configuration, architecture, os, scenario, isBuildOnly)
1935                     def folderName = getJobFolder(scenario)
1936
1937                     // Create the new job
1938                     def newJob = job(Utilities.getFullJobName(project, jobName, isPR, folderName)) {}
1939
1940                     setMachineAffinity(newJob, os, architecture)
1941
1942                     // Add all the standard options
1943                     Utilities.standardJobSetup(newJob, project, isPR, "*/${branch}")
1944                     addTriggers(newJob, branch, isPR, architecture, os, configuration, scenario, false, isBuildOnly)
1945
1946                     def buildCommands = calculateBuildCommands(newJob, scenario, branch, isPR, architecture, configuration, os, enableCorefxTesting, isBuildOnly)
1947                     def osGroup = getOSGroup(os)
1948
1949                     newJob.with {
1950                         steps {
1951                             if (os == 'Windows_NT') {
1952                                 buildCommands.each { buildCommand ->
1953                                     batchFile(buildCommand)
1954                                 }
1955                             }
1956                             else {
1957                                 // Setup corefx and Windows test binaries for Linux cross build for ubuntu-arm, ubuntu16.04-arm and tizen-armel
1958                                 if ( architecture == 'arm' && ( os == 'Ubuntu' || os == 'Ubuntu16.04' || os == 'Tizen')) {
1959                                     // Cross build for ubuntu-arm, ubuntu16.04-arm and tizen-armel
1960                                     // Define the Windows Tests and Corefx build job names
1961                                     def WindowTestsName = projectFolder + '/' +
1962                                                           Utilities.getFullJobName(project,
1963                                                                                    getJobName(lowerConfiguration,
1964                                                                                               'x64' ,
1965                                                                                               'windows_nt',
1966                                                                                               'default',
1967                                                                                               true),
1968                                                                                    false)
1969                                     def corefxFolder = Utilities.getFolderName('dotnet/corefx') + '/' +
1970                                                        Utilities.getFolderName(branch)
1971
1972                                     // Copy the Windows test binaries and the Corefx build binaries
1973                                     copyArtifacts(WindowTestsName) {
1974                                         excludePatterns('**/testResults.xml', '**/*.ni.dll')
1975                                         buildSelector {
1976                                             latestSuccessful(true)
1977                                         }
1978                                     }
1979
1980                                     // Defaults for Ubuntu
1981                                     def arm_abi = 'arm'
1982                                     def corefx_os = 'ubuntu14.04'
1983                                     if (os == 'Ubuntu16.04') {
1984                                         arm_abi = 'arm'
1985                                         corefx_os = 'ubuntu16.04'
1986                                     }
1987                                     else if (os == 'Tizen') {
1988                                         arm_abi = 'armel'
1989                                         corefx_os = 'tizen'
1990                                     }
1991
1992                                     // Let's use release CoreFX to test checked CoreCLR,
1993                                     // because we do not generate checked CoreFX in CoreFX CI yet.
1994                                     def corefx_lowerConfiguration = lowerConfiguration
1995                                     if ( lowerConfiguration == 'checked' ) {
1996                                         corefx_lowerConfiguration='release'
1997                                     }
1998                                     copyArtifacts("${corefxFolder}/${corefx_os}_${arm_abi}_cross_${corefx_lowerConfiguration}") {
1999                                         includePatterns('bin/build.tar.gz')
2000                                         buildSelector {
2001                                             latestSuccessful(true)
2002                                         }
2003                                     }
2004                                 }
2005
2006                                 buildCommands.each { buildCommand ->
2007                                     shell(buildCommand)
2008                                 }
2009                             }
2010                         }
2011                     } // newJob.with
2012
2013                 } // os
2014             } // configuration
2015         } // architecture
2016     } // isPR
2017 } // scenario
2018
2019
2020 // Create the Linux/OSX/CentOS coreclr test leg for debug and release and each scenario
2021 combinedScenarios.each { scenario ->
2022     [true, false].each { isPR ->
2023         // Architectures.  x64 only at this point
2024         ['x64'].each { architecture ->
2025             // Put the OS's supported for coreclr cross testing here
2026             Constants.crossList.each { os ->
2027                 Constants.configurationList.each { configuration ->
2028
2029                     if (Constants.jitStressModeScenarios.containsKey(scenario)) {
2030                         if (configuration != 'Checked') {
2031                             return
2032                         }
2033                         if (isCorefxTesting(scenario)) {
2034                             return
2035                         }
2036                         //Skip stress modes for these scenarios
2037                         if (os == 'RHEL7.2' || os == 'Debian8.4') {
2038                             return
2039                         }
2040                     }
2041                     // If this is a r2r jitstress, jitstressregs, jitminopts or forcerelocs scenario
2042                     // and configuration is not Checked, bail out.
2043                     else if (configuration != 'Checked' && Constants.r2rJitStressScenarios.indexOf(scenario) != -1) {
2044                         return;
2045                     }
2046                     // For CentOS, we only want Checked/Release pri1 builds.
2047                     else if (os == 'CentOS7.1') {
2048                         if (scenario != 'pri1' &&
2049                             scenario != 'r2r' &&
2050                             scenario != 'pri1r2r' &&
2051                             scenario != 'gcstress15_pri1r2r' &&
2052                             Constants.r2rJitStressScenarios.indexOf(scenario) == -1) {
2053                             return
2054                         }
2055                         if (configuration != 'Checked' && configuration != 'Release') {
2056                             return
2057                         }
2058                     }
2059                     // For RedHat and Debian, we only do Release pri1 builds.
2060                     else if (os == 'RHEL7.2' || os == 'Debian8.4') {
2061                         if (scenario != 'pri1') {
2062                             return
2063                         }
2064                         if (configuration != 'Release') {
2065                             return
2066                         }
2067                     }
2068                     else {
2069                         // Skip scenarios
2070                         switch (scenario) {
2071                             case 'pri1':
2072                                 // Nothing skipped
2073                                 break
2074                             case 'ilrt':
2075                                 // Release only
2076                                 if (configuration != 'Release') {
2077                                     return
2078                                 }
2079                                 break
2080                             case 'jitdiff':
2081                                 if (configuration != 'Checked') {
2082                                     return;
2083                                 }
2084                             case 'r2r':
2085                                 //Skip configs that aren't Checked or Release (so just Debug, for now)
2086                                 if (configuration != 'Checked' && configuration != 'Release') {
2087                                     return
2088                                 }
2089                                 break
2090                             case 'pri1r2r':
2091                                 //Skip configs that aren't Checked or Release (so just Debug, for now)
2092                                 if (configuration != 'Checked' && configuration != 'Release') {
2093                                     return
2094                                 }
2095                                 break
2096                             case 'gcstress15_pri1r2r':
2097                             case 'r2r_jitstress1':
2098                             case 'r2r_jitstress2':
2099                             case 'r2r_jitstressregs1':
2100                             case 'r2r_jitstressregs2':
2101                             case 'r2r_jitstressregs3':
2102                             case 'r2r_jitstressregs4':
2103                             case 'r2r_jitstressregs8':
2104                             case 'r2r_jitstressregs0x10':
2105                             case 'r2r_jitstressregs0x80':
2106                             case 'r2r_jitstressregs0x1000':
2107                             case 'r2r_jitminopts':
2108                             case 'r2r_jitforcerelocs':
2109                                 //Skip configs that aren't Checked or Release (so just Debug, for now)
2110                                 if (configuration != 'Checked' && configuration != 'Release') {
2111                                     return
2112                                 }
2113                                 break
2114                             case 'longgc':
2115                             case 'gcsimulator':
2116                                 // Long GC tests take a long time on non-Release builds
2117                                 if (configuration != 'Release') {
2118                                     return
2119                                 }
2120                                 break
2121                             case 'standalone_gc':
2122                                 if (configuration != 'Release' && configuration != 'Checked') {
2123                                     return
2124                                 }
2125                             case 'coverage':
2126                                 //We only want Ubuntu Release for coverage
2127                                 if (os != 'Ubuntu') {
2128                                     return
2129                                 }
2130                                 if (configuration != 'Release') {
2131                                     return
2132                                 }
2133                             case 'formatting':
2134                                 return
2135                             case 'illink':
2136                                 if (os != 'Windows_NT' && os != 'Ubuntu') {
2137                                     return
2138                                 }
2139                                 break
2140                             case 'default':
2141                                 // Nothing skipped
2142                                 break
2143                             default:
2144                                 println("Unknown scenario: ${scenario}")
2145                                 assert false
2146                                 break
2147                         }
2148                     }
2149
2150                     def lowerConfiguration = configuration.toLowerCase()
2151                     def osGroup = getOSGroup(os)
2152                     def jobName = getJobName(configuration, architecture, os, scenario, false) + "_tst"
2153
2154                     // Unless this is a coverage test run, we want to copy over the default build of coreclr.
2155                     def inputScenario = 'default'
2156                     if (scenario == 'coverage') {
2157                         inputScenario = 'coverage'
2158                     }
2159                     def inputCoreCLRBuildName = projectFolder + '/' +
2160                         Utilities.getFullJobName(project, getJobName(configuration, architecture, os, inputScenario, false), isPR)
2161                     // If this is a stress scenario, there isn't any difference in the build job
2162                     // so we didn't create a build only job for windows_nt specific to that stress mode.  Just copy
2163                     // from the default scenario
2164                     def testBuildScenario = scenario
2165                     if (testBuildScenario == 'coverage' || testBuildScenario == 'pri1r2r'|| testBuildScenario == 'gcstress15_pri1r2r') {
2166                         testBuildScenario = 'pri1'
2167                     }
2168                     else if ( testBuildScenario == 'r2r' || isLongGc(testBuildScenario)) {
2169                         testBuildScenario = 'default'
2170                     }
2171                     def inputWindowTestsBuildName = ''
2172                     if (Constants.jitStressModeScenarios.containsKey(testBuildScenario)) {
2173                         inputWindowTestsBuildName = projectFolder + '/' +
2174                             Utilities.getFullJobName(project, getJobName(configuration, architecture, 'windows_nt', 'default', true), isPR)
2175                     }
2176                     else {
2177                         inputWindowTestsBuildName = projectFolder + '/' +
2178                             Utilities.getFullJobName(project, getJobName(configuration, architecture, 'windows_nt', testBuildScenario, true), isPR)
2179                     }
2180                     // Enable Server GC for Ubuntu PR builds
2181                     def serverGCString = ''
2182
2183                     // Whether or not this test run should be run sequentially instead
2184                     // of in parallel. Only used for long GC tests.
2185                     def sequentialString = ''
2186
2187                     // Whether or not this test run should run a specific playlist.
2188                     // Only used for long GC tests.
2189
2190                     // A note - runtest.sh does have "--long-gc" and "--gcsimulator" options
2191                     // for running long GC and GCSimulator tests, respectively. We don't use them
2192                     // here because using a playlist file produces much more readable output on the CI machines
2193                     // and reduces running time.
2194                     def playlistString = ''
2195
2196                     if (os == 'Ubuntu' && isPR){
2197                         serverGCString = '--useServerGC'
2198                     }
2199
2200                     // pass --crossgen to runtest.sh for crossgen builds
2201                     def crossgenStr = ''
2202                     def runcrossgentestsStr = ''
2203                     def runjitstressStr = ''
2204                     def runjitstressregsStr = ''
2205                     def runjitmioptsStr = ''
2206                     def runjitforcerelocsStr = ''
2207                     def runjitdisasmStr = ''
2208                     def gcstressStr = ''
2209                     def illinkStr = ''
2210
2211                     if (scenario == 'r2r' ||
2212                         scenario == 'pri1r2r' ||
2213                         scenario == 'gcstress15_pri1r2r' ||
2214                         Constants.r2rJitStressScenarios.indexOf(scenario) != -1) {
2215                             crossgenStr = '--crossgen'
2216                             runcrossgentestsStr = '--runcrossgentests'
2217
2218                             if (scenario == 'r2r_jitstress1'){
2219                                 runjitstressStr = '--jitstress=1'
2220                             }
2221                             else if (scenario == 'r2r_jitstress2') {
2222                                 runjitstressStr = '--jitstress=2'
2223                             }
2224                             else if (scenario == 'r2r_jitstressregs1'){
2225                                 runjitstressregsStr = '--jitstressregs=1'
2226                             }
2227                             else if (scenario == 'r2r_jitstressregs2') {
2228                                 runjitstressregsStr = '--jitstressregs=2'
2229                             }
2230                             else if (scenario == 'r2r_jitstressregs3') {
2231                                 runjitstressregsStr = '--jitstressregs=3'
2232                             }
2233                             else if (scenario == 'r2r_jitstressregs4') {
2234                                 runjitstressregsStr = '--jitstressregs=4'
2235                             }
2236                             else if (scenario == 'r2r_jitstressregs8') {
2237                                 runjitstressregsStr = '--jitstressregs=8'
2238                             }
2239                             else if (scenario == 'r2r_jitstressregs0x10') {
2240                                 runjitstressregsStr = '--jitstressregs=0x10'
2241                             }
2242                             else if (scenario == 'r2r_jitstressregs0x80') {
2243                                 runjitstressregsStr = '--jitstressregs=0x80'
2244                             }
2245                             else if (scenario == 'r2r_jitstressregs0x1000') {
2246                                 runjitstressregsStr = '--jitstressregs=0x1000'
2247                             }
2248                             else if (scenario == 'r2r_jitminopts') {
2249                                 runjitmioptsStr = '--jitminopts'
2250                             }
2251                             else if (scenario == 'r2r_jitforcerelocs') {
2252                                 runjitforcerelocsStr = '--jitforcerelocs'
2253                             }
2254                     }
2255                     if  (scenario == 'gcstress15_pri1r2r')
2256                     {
2257                         gcstressStr = '--gcstresslevel=0xF'
2258                     }
2259
2260                     if (scenario == 'jitdiff')
2261                     {
2262                         runjitdisasmStr = '--jitdisasm --crossgen'
2263                     }
2264
2265                     if (scenario == 'illink')
2266                     {
2267                         illinkStr = '--link=\$WORKSPACE/linker/linker/bin/netcore_Release/netcoreapp2.0/ubuntu-x64/publish/illink'
2268                     }
2269
2270                     if (isLongGc(scenario)) {
2271                         // Long GC tests behave very poorly when they are not
2272                         // the only test running (many of them allocate until OOM).
2273                         sequentialString = '--sequential'
2274
2275                         // The Long GC playlist contains all of the tests that are
2276                         // going to be run. The GCSimulator playlist contains all of
2277                         // the GC simulator tests.
2278                         if (scenario == 'longgc') {
2279                             playlistString = '--long-gc --playlist=./tests/longRunningGcTests.txt'
2280                         }
2281                         else if (scenario == 'gcsimulator') {
2282                             playlistString = '--gcsimulator --playlist=./tests/gcSimulatorTests.txt'
2283                         }
2284                     }
2285
2286                     def folder = getJobFolder(scenario)
2287                     def newJob = job(Utilities.getFullJobName(project, jobName, isPR, folder)) {
2288                         // Add parameters for the inputs
2289
2290                         parameters {
2291                             stringParam('CORECLR_WINDOWS_BUILD', '', 'Build number to copy CoreCLR windows test binaries from')
2292                             stringParam('CORECLR_BUILD', '', "Build number to copy CoreCLR ${osGroup} binaries from")
2293                         }
2294
2295                         steps {
2296                             // Set up the copies
2297
2298                             // Coreclr build containing the tests and mscorlib
2299
2300                             copyArtifacts(inputWindowTestsBuildName) {
2301                                 excludePatterns('**/testResults.xml', '**/*.ni.dll')
2302                                 buildSelector {
2303                                     buildNumber('${CORECLR_WINDOWS_BUILD}')
2304                                 }
2305                             }
2306
2307                             if (scenario == 'coverage') {
2308
2309                                 // Move coreclr to clr directory
2310                                 shell("rm -rf .clr; mkdir .clr; mv * .clr; mv .git .clr; mv .clr clr")
2311
2312                                 // Build coreclr
2313                                 shell("./clr/build.sh coverage verbose ${lowerConfiguration} ${architecture}")
2314
2315                                 // Remove folders from obj that we don't expect to be covered. May update this later.
2316                                 shell("rm -rf ./clr/bin/obj/Linux.x64.Release/src/ToolBox")
2317                                 shell("rm -rf ./clr/bin/obj/Linux.x64.Release/src/debug")
2318                                 shell("rm -rf ./clr/bin/obj/Linux.x64.Release/src/ilasm")
2319                                 shell("rm -rf ./clr/bin/obj/Linux.x64.Release/src/ildasm")
2320                                 shell("rm -rf ./clr/bin/obj/Linux.x64.Release/src/dlls/dbgshim")
2321                                 shell("rm -rf ./clr/bin/obj/Linux.x64.Release/src/dlls/mscordac")
2322                                 shell("rm -rf ./clr/bin/obj/Linux.x64.Release/src/dlls/mscordbi")
2323
2324                                 // Run PAL tests
2325                                 shell("./clr/src/pal/tests/palsuite/runpaltests.sh \$(pwd)/clr/bin/obj/${osGroup}.${architecture}.${configuration} \$(pwd)/clr/bin/paltestout")
2326
2327                                 // Remove obj files for PAL tests so they're not included in coverage results
2328                                 shell("rm -rf ./clr/bin/obj/Linux.x64.Release/src/pal/tests")
2329
2330                                 // Unzip the tests first.  Exit with 0
2331                                 shell("unzip -q -o ./clr/bin/tests/tests.zip -d ./clr/bin/tests/Windows_NT.${architecture}.${configuration} || exit 0")
2332
2333                                 // Get corefx
2334                                 shell("git clone https://github.com/dotnet/corefx fx")
2335
2336                                 // Build Linux corefx
2337                                 shell("./fx/build-native.sh -release -buildArch=x64 -os=Linux")
2338                                 shell("./fx/build-managed.sh -release -buildArch=x64 -osgroup=Linux -skiptests")
2339
2340                                 def testEnvOpt = ""
2341                                 def scriptFileName = "\$WORKSPACE/set_stress_test_env.sh"
2342                                 def createScriptCmds = genStressModeScriptStep(os, scenario, Constants.jitStressModeScenarios['heapverify1'], scriptFileName)
2343                                 shell("${createScriptCmds}")
2344                                 testEnvOpt = "--test-env=" + scriptFileName
2345
2346                                 // Run corefx tests
2347                                 shell("""./fx/run-test.sh \\
2348                 --coreclr-bins \$(pwd)/clr/bin/Product/${osGroup}.${architecture}.${configuration} \\
2349                 --mscorlib-bins \$(pwd)/clr/bin/Product/${osGroup}.${architecture}.${configuration} \\
2350                 --corefx-tests \$(pwd)/fx/bin/tests/${osGroup}.AnyCPU.${configuration} \\
2351                 --corefx-native-bins \$(pwd)/fx/bin/${osGroup}.${architecture}.${configuration} \\
2352                 --configurationGroup Release""")
2353
2354
2355                                 // Run coreclr tests w/ workstation GC
2356                                 shell("""./clr/tests/runtest.sh \\
2357                 --testRootDir=\"\$(pwd)/clr/bin/tests/Windows_NT.${architecture}.${configuration}\" \\
2358                 --testNativeBinDir=\"\$(pwd)/clr/bin/obj/${osGroup}.${architecture}.${configuration}/tests\" \\
2359                 --coreClrBinDir=\"\$(pwd)/clr/bin/Product/${osGroup}.${architecture}.${configuration}\" \\
2360                 --mscorlibDir=\"\$(pwd)/clr/bin/Product/${osGroup}.${architecture}.${configuration}\" \\
2361                 --coreFxBinDir=\"\$(pwd)/fx/bin/runtime/netcoreapp-${osGroup}-Release-${architecture}\" \\
2362                 --crossgen --runcrossgentests""")
2363
2364                                 // Run coreclr tests w/ server GC & HeapVerify enabled
2365                                 shell("""./clr/tests/runtest.sh \\
2366                 --testRootDir=\"\$(pwd)/clr/bin/tests/Windows_NT.${architecture}.${configuration}\" \\
2367                 --testNativeBinDir=\"\$(pwd)/clr/bin/obj/${osGroup}.${architecture}.${configuration}/tests\" \\
2368                 --coreOverlayDir=\"\$(pwd)/clr/bin/tests/Windows_NT.${architecture}.${configuration}/Tests/coreoverlay\" \\
2369                 --useServerGC ${testEnvOpt}""")
2370
2371                                  // Run long-running coreclr GC tests & produce coverage reports
2372                                 shell("""./clr/tests/runtest.sh \\
2373                 --testRootDir=\"\$(pwd)/clr/bin/tests/Windows_NT.${architecture}.${configuration}\" \\
2374                 --testNativeBinDir=\"\$(pwd)/clr/bin/obj/${osGroup}.${architecture}.${configuration}/tests\" \\
2375                 --coreOverlayDir=\"\$(pwd)/clr/bin/tests/Windows_NT.${architecture}.${configuration}/Tests/coreoverlay\" \\
2376                 --long-gc --playlist=\"\$(pwd)/clr/tests/longRunningGcTests.txt\" --coreclr-coverage\\
2377                 --coreclr-objs=\"\$(pwd)/clr/bin/obj/${osGroup}.${architecture}.${configuration}\" \\
2378                 --coreclr-src=\"\$(pwd)/clr/src\" \\
2379                 --coverage-output-dir=\"\${WORKSPACE}/coverage\" """)
2380
2381                             }
2382                             else {
2383
2384                                 // Coreclr build we are trying to test
2385
2386                                 copyArtifacts(inputCoreCLRBuildName) {
2387                                     excludePatterns('**/testResults.xml', '**/*.ni.dll')
2388                                     buildSelector {
2389                                         buildNumber('${CORECLR_BUILD}')
2390                                     }
2391                                 }
2392
2393                                 def corefxFolder = Utilities.getFolderName('dotnet/corefx') + '/' + Utilities.getFolderName(branch)
2394
2395                                 // Corefx components.  We now have full stack builds on all distros we test here, so we can copy straight from CoreFX jobs.
2396                                 def osJobName
2397                                 if (os == 'Ubuntu') {
2398                                     osJobName = 'ubuntu14.04'
2399                                 }
2400                                 else {
2401                                     osJobName = os.toLowerCase()
2402                                 }
2403                                 copyArtifacts("${corefxFolder}/${osJobName}_release") {
2404                                     includePatterns('bin/build.tar.gz')
2405                                     buildSelector {
2406                                         latestSuccessful(true)
2407                                     }
2408                                 }
2409
2410                                 shell ("mkdir ./bin/CoreFxBinDir")
2411                                 // Unpack the corefx binaries
2412                                 shell("tar -xf ./bin/build.tar.gz -C ./bin/CoreFxBinDir")
2413
2414                                 // Unzip the tests first.  Exit with 0
2415                                 shell("unzip -q -o ./bin/tests/tests.zip -d ./bin/tests/Windows_NT.${architecture}.${configuration} || exit 0")
2416
2417                                 // Execute the tests
2418                                 // If we are running a stress mode, we'll set those variables first
2419                                 def testEnvOpt = ""
2420                                 if (Constants.jitStressModeScenarios.containsKey(scenario)) {
2421                                     def scriptFileName = "\$WORKSPACE/set_stress_test_env.sh"
2422                                     def createScriptCmds = genStressModeScriptStep(os, scenario, Constants.jitStressModeScenarios[scenario], scriptFileName)
2423                                     shell("${createScriptCmds}")
2424                                     testEnvOpt = "--test-env=" + scriptFileName
2425                                 }
2426
2427                                 if (isGCStressRelatedTesting(scenario)) {
2428                                     shell('./init-tools.sh')
2429                                 }
2430
2431                                 shell("""./tests/runtest.sh \\
2432                 --testRootDir=\"\${WORKSPACE}/bin/tests/Windows_NT.${architecture}.${configuration}\" \\
2433                 --testNativeBinDir=\"\${WORKSPACE}/bin/obj/${osGroup}.${architecture}.${configuration}/tests\" \\
2434                 --coreClrBinDir=\"\${WORKSPACE}/bin/Product/${osGroup}.${architecture}.${configuration}\" \\
2435                 --mscorlibDir=\"\${WORKSPACE}/bin/Product/${osGroup}.${architecture}.${configuration}\" \\
2436                 --coreFxBinDir=\"\${WORKSPACE}/bin/CoreFxBinDir\" \\
2437                 --limitedDumpGeneration \\
2438                 ${testEnvOpt} ${serverGCString} ${gcstressStr} ${crossgenStr} ${runcrossgentestsStr} ${runjitstressStr} ${runjitstressregsStr} ${runjitmioptsStr} ${runjitforcerelocsStr} ${runjitdisasmStr} ${illinkStr} ${sequentialString} ${playlistString}""")
2439                             }
2440                         }
2441                     }
2442
2443                     if (scenario == 'coverage') {
2444                         // Publish coverage reports
2445                         Utilities.addHtmlPublisher(newJob, '${WORKSPACE}/coverage/Coverage/reports', 'Code Coverage Report', 'coreclr.html')
2446                         // TODO: Add once external email sending is available again
2447                         // addEmailPublisher(newJob, 'clrcoverage@microsoft.com')
2448                     }
2449
2450                     if (scenario == 'jitdiff') {
2451                         Utilities.addArchival(newJob, "bin/tests/${osGroup}.${architecture}.${configuration}/dasm/**")
2452                     }
2453
2454                     // Experimental: If on Ubuntu 14.04, then attempt to pull in crash dump links
2455                     if (os in ['Ubuntu']) {
2456                         SummaryBuilder summaries = new SummaryBuilder()
2457                         summaries.addLinksSummaryFromFile('Crash dumps from this run:', 'dumplings.txt')
2458                         summaries.emit(newJob)
2459                     }
2460
2461                     setMachineAffinity(newJob, os, architecture)
2462                     Utilities.standardJobSetup(newJob, project, isPR, "*/${branch}")
2463                     // Set timeouts to 240.
2464                     setTestJobTimeOut(newJob, scenario)
2465                     Utilities.addXUnitDotNETResults(newJob, '**/coreclrtests.xml')
2466
2467                     // Create a build flow to join together the build and tests required to run this
2468                     // test.
2469                     // Windows CoreCLR build and Linux CoreCLR build (in parallel) ->
2470                     // Linux CoreCLR test
2471                     def flowJobName = getJobName(configuration, architecture, os, scenario, false) + "_flow"
2472                     def fullTestJobName = projectFolder + '/' + newJob.name
2473                     // Add a reference to the input jobs for report purposes
2474                     JobReport.Report.addReference(inputCoreCLRBuildName)
2475                     JobReport.Report.addReference(inputWindowTestsBuildName)
2476                     JobReport.Report.addReference(fullTestJobName)
2477                     def newFlowJob;
2478
2479                     // If this is a coverage job, we don't copy any input coreCLR build - instead, we build it as part of the flow job,
2480                     // so that coverage data can be preserved.
2481                     if (scenario == 'coverage') {
2482                         newFlowJob = buildFlowJob(Utilities.getFullJobName(project, flowJobName, isPR, folder)) {
2483                         buildFlow("""
2484 // Build the input Windows job
2485 windowsBuildJob = build(params, '${inputWindowTestsBuildName}')
2486
2487 // And then build the test build
2488 build(params + [CORECLR_WINDOWS_BUILD: windowsBuildJob.build.number], '${fullTestJobName}')
2489 """)
2490                         }
2491                     // Normal jobs copy a Windows build & a non-Windows build
2492                     } else {
2493                         newFlowJob = buildFlowJob(Utilities.getFullJobName(project, flowJobName, isPR, folder)) {
2494                         buildFlow("""
2495 // Build the input jobs in parallel
2496 parallel (
2497     { coreclrBuildJob = build(params, '${inputCoreCLRBuildName}') },
2498     { windowsBuildJob = build(params, '${inputWindowTestsBuildName}') }
2499 )
2500
2501 // And then build the test build
2502 build(params + [CORECLR_BUILD: coreclrBuildJob.build.number,
2503                 CORECLR_WINDOWS_BUILD: windowsBuildJob.build.number], '${fullTestJobName}')
2504 """)
2505                         }
2506                     }
2507
2508                     setMachineAffinity(newFlowJob, os, architecture)
2509                     Utilities.standardJobSetup(newFlowJob, project, isPR, "*/${branch}")
2510                     addTriggers(newFlowJob, branch, isPR, architecture, os, configuration, scenario, true, false)
2511                 } // configuration
2512             } // os
2513         } // architecture
2514     } // isPR
2515 } // scenario
2516
2517 JobReport.Report.generateJobReport(out)
2518
2519 // Make the call to generate the help job
2520 Utilities.createHelperJob(this, project, branch,
2521     "Welcome to the ${project} Repository",  // This is prepended to the help message
2522     "Have a nice day!")  // This is appended to the help message.  You might put known issues here.
2523
2524 Utilities.addCROSSCheck(this, project, branch)