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