Add support for loading registered TLBs (#21430)
[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                       'Ubuntu16.04' : 'Linux',
22                       'Ubuntu16.10' : 'Linux',
23                       'RHEL7.2'     : 'Linux',
24                       'Debian8.4'   : 'Linux',
25                       'Fedora24'    : 'Linux',
26                       'CentOS7.1'   : 'Linux',
27                       'Tizen'       : 'Linux',
28                       'OSX10.12'    : 'OSX',
29                       'Windows_NT'  : 'Windows_NT']
30     def osGroup = osGroupMap.get(os, null)
31     assert osGroup != null : "Could not find os group for ${os}"
32     return osGroupMap[os]
33 }
34
35 // We use this class (vs variables) so that the static functions can access data here.
36 class Constants {
37
38     // We have very limited Windows ARM64 hardware (used for ARM/ARM64 testing) and Linux/arm32 and Linux/arm64 hardware.
39     // So only allow certain branches to use it.
40     def static LimitedHardwareBranches = [
41                'master']
42
43     // Innerloop build OS's
44     // The Windows_NT_BuildOnly OS is a way to speed up the Non-Windows builds by avoiding
45     // test execution in the build flow runs.  It generates the exact same build
46     // as Windows_NT but without running the tests.
47     def static osList = [
48                'Ubuntu',
49                'Debian8.4',
50                'OSX10.12',
51                'Windows_NT',
52                'Windows_NT_BuildOnly',
53                'CentOS7.1',
54                'RHEL7.2',
55                'Ubuntu16.04',
56                'Ubuntu16.10',
57                'Fedora24',
58                'Tizen']
59
60     def static crossList = [
61                'Ubuntu',
62                'Debian8.4',
63                'OSX10.12',
64                'Windows_NT',
65                'CentOS7.1',
66                'RHEL7.2']
67
68     // This is a set of JIT stress modes combined with the set of variables that
69     // need to be set to actually enable that stress mode.  The key of the map is the stress mode and
70     // the values are the environment variables
71     def static jitStressModeScenarios = [
72                'minopts'                        : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JITMinOpts' : '1'],
73                'tieredcompilation'              : ['COMPlus_TieredCompilation' : '1'], // this can be removed once tiered compilation is on by default
74                'no_tiered_compilation'          : ['COMPlus_TieredCompilation' : '0'],
75                'no_tiered_compilation_innerloop': ['COMPlus_TieredCompilation' : '0'],
76                'forcerelocs'                    : ['COMPlus_TieredCompilation' : '0', 'COMPlus_ForceRelocs' : '1'],
77                'jitstress1'                     : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStress' : '1'],
78                'jitstress2'                     : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStress' : '2'],
79                'jitstress1_tiered'              : ['COMPlus_TieredCompilation' : '1', 'COMPlus_JitStress' : '1'],
80                'jitstress2_tiered'              : ['COMPlus_TieredCompilation' : '1', 'COMPlus_JitStress' : '2'],
81                'jitstressregs1'                 : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStressRegs' : '1'],
82                'jitstressregs2'                 : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStressRegs' : '2'],
83                'jitstressregs3'                 : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStressRegs' : '3'],
84                'jitstressregs4'                 : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStressRegs' : '4'],
85                'jitstressregs8'                 : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStressRegs' : '8'],
86                'jitstressregs0x10'              : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStressRegs' : '0x10'],
87                'jitstressregs0x80'              : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStressRegs' : '0x80'],
88                'jitstressregs0x1000'            : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStressRegs' : '0x1000'],
89                'jitstress2_jitstressregs1'      : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStress' : '2', 'COMPlus_JitStressRegs' : '1'],
90                'jitstress2_jitstressregs2'      : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStress' : '2', 'COMPlus_JitStressRegs' : '2'],
91                'jitstress2_jitstressregs3'      : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStress' : '2', 'COMPlus_JitStressRegs' : '3'],
92                'jitstress2_jitstressregs4'      : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStress' : '2', 'COMPlus_JitStressRegs' : '4'],
93                'jitstress2_jitstressregs8'      : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStress' : '2', 'COMPlus_JitStressRegs' : '8'],
94                'jitstress2_jitstressregs0x10'   : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStress' : '2', 'COMPlus_JitStressRegs' : '0x10'],
95                'jitstress2_jitstressregs0x80'   : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStress' : '2', 'COMPlus_JitStressRegs' : '0x80'],
96                'jitstress2_jitstressregs0x1000' : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStress' : '2', 'COMPlus_JitStressRegs' : '0x1000'],
97                'tailcallstress'                 : ['COMPlus_TieredCompilation' : '0', 'COMPlus_TailcallStress' : '1'],
98                'jitsse2only'                    : ['COMPlus_TieredCompilation' : '0', 'COMPlus_EnableAVX' : '0', 'COMPlus_EnableSSE3_4' : '0'],
99                'jitnosimd'                      : ['COMPlus_TieredCompilation' : '0', 'COMPlus_FeatureSIMD' : '0'],
100                'jitincompletehwintrinsic'       : ['COMPlus_TieredCompilation' : '0', 'COMPlus_EnableIncompleteISAClass' : '1'],
101                'jitx86hwintrinsicnoavx'         : ['COMPlus_TieredCompilation' : '0', 'COMPlus_EnableIncompleteISAClass' : '1', 'COMPlus_EnableAVX' : '0'], // testing the legacy SSE encoding
102                'jitx86hwintrinsicnoavx2'        : ['COMPlus_TieredCompilation' : '0', 'COMPlus_EnableIncompleteISAClass' : '1', 'COMPlus_EnableAVX2' : '0'], // testing SNB/IVB
103                'jitx86hwintrinsicnosimd'        : ['COMPlus_TieredCompilation' : '0', 'COMPlus_EnableIncompleteISAClass' : '1', 'COMPlus_FeatureSIMD' : '0'], // match "jitnosimd", may need to remove after decoupling HW intrinsic from FeatureSIMD
104                'jitnox86hwintrinsic'            : ['COMPlus_TieredCompilation' : '0', 'COMPlus_EnableIncompleteISAClass' : '1', 'COMPlus_EnableSSE' : '0' , 'COMPlus_EnableSSE2' : '0' , 'COMPlus_EnableSSE3' : '0' , 'COMPlus_EnableSSSE3' : '0' , 'COMPlus_EnableSSE41' : '0' , 'COMPlus_EnableSSE42' : '0' , 'COMPlus_EnableAVX' : '0' , 'COMPlus_EnableAVX2' : '0' , 'COMPlus_EnableAES' : '0' , 'COMPlus_EnableBMI1' : '0' , 'COMPlus_EnableBMI2' : '0' , 'COMPlus_EnableFMA' : '0' , 'COMPlus_EnableLZCNT' : '0' , 'COMPlus_EnablePCLMULQDQ' : '0' , 'COMPlus_EnablePOPCNT' : '0'],
105                'corefx_baseline'                : ['COMPlus_TieredCompilation' : '0'], // corefx baseline
106                'corefx_minopts'                 : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JITMinOpts' : '1'],
107                'corefx_tieredcompilation'       : ['COMPlus_TieredCompilation' : '1'],  // this can be removed once tiered compilation is on by default
108                'corefx_jitstress1'              : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStress' : '1'],
109                'corefx_jitstress2'              : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStress' : '2'],
110                'corefx_jitstressregs1'          : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStressRegs' : '1'],
111                'corefx_jitstressregs2'          : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStressRegs' : '2'],
112                'corefx_jitstressregs3'          : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStressRegs' : '3'],
113                'corefx_jitstressregs4'          : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStressRegs' : '4'],
114                'corefx_jitstressregs8'          : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStressRegs' : '8'],
115                'corefx_jitstressregs0x10'       : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStressRegs' : '0x10'],
116                'corefx_jitstressregs0x80'       : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStressRegs' : '0x80'],
117                'corefx_jitstressregs0x1000'     : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStressRegs' : '0x1000'],
118                'gcstress0x3'                    : ['COMPlus_TieredCompilation' : '0', 'COMPlus_GCStress' : '0x3'],
119                'gcstress0xc'                    : ['COMPlus_TieredCompilation' : '0', 'COMPlus_GCStress' : '0xC'],
120                'zapdisable'                     : ['COMPlus_TieredCompilation' : '0', 'COMPlus_ZapDisable' : '1', 'COMPlus_ReadyToRun' : '0'],
121                'heapverify1'                    : ['COMPlus_TieredCompilation' : '0', 'COMPlus_HeapVerify' : '1'],
122                'gcstress0xc_zapdisable'             : ['COMPlus_TieredCompilation' : '0', 'COMPlus_GCStress' : '0xC', 'COMPlus_ZapDisable' : '1', 'COMPlus_ReadyToRun' : '0'],
123                'gcstress0xc_zapdisable_jitstress2'  : ['COMPlus_TieredCompilation' : '0', 'COMPlus_GCStress' : '0xC', 'COMPlus_ZapDisable' : '1', 'COMPlus_ReadyToRun' : '0', 'COMPlus_JitStress'  : '2'],
124                'gcstress0xc_zapdisable_heapverify1' : ['COMPlus_TieredCompilation' : '0', 'COMPlus_GCStress' : '0xC', 'COMPlus_ZapDisable' : '1', 'COMPlus_ReadyToRun' : '0', 'COMPlus_HeapVerify' : '1'],
125                'gcstress0xc_jitstress1'             : ['COMPlus_TieredCompilation' : '0', 'COMPlus_GCStress' : '0xC', 'COMPlus_JitStress'  : '1'],
126                'gcstress0xc_jitstress2'             : ['COMPlus_TieredCompilation' : '0', 'COMPlus_GCStress' : '0xC', 'COMPlus_JitStress'  : '2'],
127                'gcstress0xc_minopts_heapverify1'    : ['COMPlus_TieredCompilation' : '0', 'COMPlus_GCStress' : '0xC', 'COMPlus_JITMinOpts' : '1', 'COMPlus_HeapVerify' : '1']
128     ]
129
130     // This is a set of ReadyToRun stress scenarios
131     def static r2rStressScenarios = [
132                'r2r_jitstress1'             : ['COMPlus_TieredCompilation' : '0', "COMPlus_JitStress": "1"],
133                'r2r_jitstress2'             : ['COMPlus_TieredCompilation' : '0', "COMPlus_JitStress": "2"],
134                'r2r_jitstress1_tiered'      : ['COMPlus_TieredCompilation' : '1', "COMPlus_JitStress": "1"],
135                'r2r_jitstress2_tiered'      : ['COMPlus_TieredCompilation' : '1', "COMPlus_JitStress": "2"],
136                'r2r_jitstressregs1'         : ['COMPlus_TieredCompilation' : '0', "COMPlus_JitStressRegs": "1"],
137                'r2r_jitstressregs2'         : ['COMPlus_TieredCompilation' : '0', "COMPlus_JitStressRegs": "2"],
138                'r2r_jitstressregs3'         : ['COMPlus_TieredCompilation' : '0', "COMPlus_JitStressRegs": "3"],
139                'r2r_jitstressregs4'         : ['COMPlus_TieredCompilation' : '0', "COMPlus_JitStressRegs": "4"],
140                'r2r_jitstressregs8'         : ['COMPlus_TieredCompilation' : '0', "COMPlus_JitStressRegs": "8"],
141                'r2r_jitstressregs0x10'      : ['COMPlus_TieredCompilation' : '0', "COMPlus_JitStressRegs": "0x10"],
142                'r2r_jitstressregs0x80'      : ['COMPlus_TieredCompilation' : '0', "COMPlus_JitStressRegs": "0x80"],
143                'r2r_jitstressregs0x1000'    : ['COMPlus_TieredCompilation' : '0', "COMPlus_JitStressRegs": "0x1000"],
144                'r2r_jitminopts'             : ['COMPlus_TieredCompilation' : '0', "COMPlus_JITMinOpts": "1"], 
145                'r2r_jitforcerelocs'         : ['COMPlus_TieredCompilation' : '0', "COMPlus_ForceRelocs": "1"],
146                'r2r_gcstress15'             : ['COMPlus_TieredCompilation' : '0', "COMPlus_GCStress": "0xF"],
147                'r2r_no_tiered_compilation'  : ['COMPlus_TieredCompilation' : '0'],
148     ]
149
150     // This is the basic set of scenarios
151     def static basicScenarios = [
152                'innerloop',
153                'normal',
154                'ilrt',
155                'r2r',
156                'longgc',
157                'formatting',
158                'gcsimulator',
159                // 'jitdiff', // jitdiff is currently disabled, until someone spends the effort to make it fully work
160                'standalone_gc',
161                'gc_reliability_framework',
162                'illink',
163                'corefx_innerloop',
164                'crossgen_comparison',
165                'pmi_asm_diffs']
166
167     def static allScenarios = basicScenarios + r2rStressScenarios.keySet() + jitStressModeScenarios.keySet()
168
169     // Valid PR trigger combinations.
170     def static prTriggeredValidInnerLoopCombos = [
171         'Windows_NT': [
172             'x64': [
173                 'Checked'
174             ], 
175             'x86': [
176                 'Checked',
177                 'Release'
178             ], 
179             'arm': [
180                 'Debug',
181                 'Checked'
182             ],
183             'arm64': [
184                 'Debug',
185                 'Checked'
186             ]
187         ],
188         'Windows_NT_BuildOnly': [
189             'x64': [
190                 'Checked',
191                 'Release'
192             ],
193             'x86': [
194                 'Checked',
195                 'Release'
196             ], 
197             'arm': [
198                 'Checked'
199             ], 
200         ],
201         'Ubuntu': [
202             'x64': [
203                 'Checked'
204             ],
205             'arm': [
206                 'Checked'
207             ]
208         ],
209         'Ubuntu16.04': [
210             'arm64': [
211                 'Checked'
212             ]
213         ],
214         'CentOS7.1': [
215             'x64': [
216                 'Debug',
217                 'Checked'
218             ]
219         ],
220         'OSX10.12': [
221             'x64': [
222                 'Checked'
223             ]
224         ],
225         'Tizen': [
226             'armem': [
227                 'Checked'
228             ]
229         ]
230     ]
231
232     // A set of scenarios that are valid for arm/arm64 tests run on hardware. This is a map from valid scenario name
233     // to Tests.lst file categories to exclude.
234     //
235     // This list should contain a subset of the scenarios from `allScenarios`. Please keep this in the same order as that,
236     // and with the same values, with some commented out, for easier maintenance.
237     //
238     // Note that some scenarios that are commented out should be enabled, but haven't yet been.
239     //
240     def static validArmWindowsScenarios = [
241                'innerloop',
242                'normal',
243                // 'ilrt'
244                'r2r',
245                // 'longgc'
246                // 'formatting'
247                // 'gcsimulator'
248                // 'jitdiff'
249                // 'standalone_gc'
250                // 'gc_reliability_framework'
251                // 'illink'
252                // 'corefx_innerloop'
253                // 'crossgen_comparison'
254                // 'pmi_asm_diffs'
255                'r2r_jitstress1',
256                'r2r_jitstress2',
257                'r2r_jitstress1_tiered',
258                'r2r_jitstress2_tiered',
259                'r2r_jitstressregs1',
260                'r2r_jitstressregs2',
261                'r2r_jitstressregs3',
262                'r2r_jitstressregs4',
263                'r2r_jitstressregs8',
264                'r2r_jitstressregs0x10',
265                'r2r_jitstressregs0x80',
266                'r2r_jitstressregs0x1000',
267                'r2r_jitminopts',
268                'r2r_jitforcerelocs',
269                'r2r_gcstress15',
270                'r2r_no_tiered_compilation',
271                'minopts',
272                'tieredcompilation',
273                'no_tiered_compilation',
274                'no_tiered_compilation_innerloop',
275                'forcerelocs',
276                'jitstress1',
277                'jitstress2',
278                'jitstress1_tiered',
279                'jitstress2_tiered',
280                'jitstressregs1',
281                'jitstressregs2',
282                'jitstressregs3',
283                'jitstressregs4',
284                'jitstressregs8',
285                'jitstressregs0x10',
286                'jitstressregs0x80',
287                'jitstressregs0x1000',
288                'jitstress2_jitstressregs1',
289                'jitstress2_jitstressregs2',
290                'jitstress2_jitstressregs3',
291                'jitstress2_jitstressregs4',
292                'jitstress2_jitstressregs8',
293                'jitstress2_jitstressregs0x10',
294                'jitstress2_jitstressregs0x80',
295                'jitstress2_jitstressregs0x1000',
296                'tailcallstress',
297                // 'jitsse2only'                     // Only relevant to xarch
298                'jitnosimd',                         // Only interesting on platforms where SIMD support exists.
299                // 'jitincompletehwintrinsic'
300                // 'jitx86hwintrinsicnoavx'
301                // 'jitx86hwintrinsicnoavx2'
302                // 'jitx86hwintrinsicnosimd'
303                // 'jitnox86hwintrinsic'
304                'corefx_baseline',                   // corefx tests don't use smarty
305                'corefx_minopts',                    // corefx tests don't use smarty
306                'corefx_tieredcompilation',          // corefx tests don't use smarty
307                'corefx_jitstress1',                 // corefx tests don't use smarty
308                'corefx_jitstress2',                 // corefx tests don't use smarty
309                'corefx_jitstressregs1',             // corefx tests don't use smarty
310                'corefx_jitstressregs2',             // corefx tests don't use smarty
311                'corefx_jitstressregs3',             // corefx tests don't use smarty
312                'corefx_jitstressregs4',             // corefx tests don't use smarty
313                'corefx_jitstressregs8',             // corefx tests don't use smarty
314                'corefx_jitstressregs0x10',          // corefx tests don't use smarty
315                'corefx_jitstressregs0x80',          // corefx tests don't use smarty
316                'corefx_jitstressregs0x1000',        // corefx tests don't use smarty
317                'gcstress0x3',
318                'gcstress0xc',
319                'zapdisable',
320                'heapverify1',
321                'gcstress0xc_zapdisable',
322                'gcstress0xc_zapdisable_jitstress2',
323                'gcstress0xc_zapdisable_heapverify1',
324                'gcstress0xc_jitstress1',
325                'gcstress0xc_jitstress2',
326                'gcstress0xc_minopts_heapverify1',
327
328                //
329                // NOTE: the following scenarios are not defined in the 'allScenarios' list! Is this a bug?
330                //
331
332                'minopts_zapdisable',
333                'gcstress0x3_jitstress1',
334                'gcstress0x3_jitstress2',
335                'gcstress0x3_jitstressregs1',
336                'gcstress0x3_jitstressregs2',
337                'gcstress0x3_jitstressregs3',
338                'gcstress0x3_jitstressregs4',
339                'gcstress0x3_jitstressregs8',
340                'gcstress0x3_jitstressregs0x10',
341                'gcstress0x3_jitstressregs0x80',
342                'gcstress0x3_jitstressregs0x1000',
343                'gcstress0xc_jitstressregs1',
344                'gcstress0xc_jitstressregs2',
345                'gcstress0xc_jitstressregs3',
346                'gcstress0xc_jitstressregs4',
347                'gcstress0xc_jitstressregs8',
348                'gcstress0xc_jitstressregs0x10',
349                'gcstress0xc_jitstressregs0x80',
350                'gcstress0xc_jitstressregs0x1000'
351     ]
352   
353     def static validLinuxArmScenarios = [
354                'innerloop',
355                'normal',
356                // 'ilrt'
357                'r2r',
358                // 'longgc'
359                // 'formatting'
360                // 'gcsimulator'
361                // 'jitdiff'
362                // 'standalone_gc'
363                // 'gc_reliability_framework'
364                // 'illink'
365                // 'corefx_innerloop'
366                'crossgen_comparison',
367                'pmi_asm_diffs',
368                'r2r_jitstress1',
369                'r2r_jitstress2',
370                'r2r_jitstress1_tiered',
371                'r2r_jitstress2_tiered',
372                'r2r_jitstressregs1',
373                'r2r_jitstressregs2',
374                'r2r_jitstressregs3',
375                'r2r_jitstressregs4',
376                'r2r_jitstressregs8',
377                'r2r_jitstressregs0x10',
378                'r2r_jitstressregs0x80',
379                'r2r_jitstressregs0x1000',
380                'r2r_jitminopts',
381                'r2r_jitforcerelocs',
382                'r2r_gcstress15',
383                'r2r_no_tiered_compilation',
384                'minopts',
385                'tieredcompilation',
386                'no_tiered_compilation',
387                'no_tiered_compilation_innerloop',
388                'forcerelocs',
389                'jitstress1',
390                'jitstress2',
391                'jitstress1_tiered',
392                'jitstress2_tiered',
393                'jitstressregs1',
394                'jitstressregs2',
395                'jitstressregs3',
396                'jitstressregs4',
397                'jitstressregs8',
398                'jitstressregs0x10',
399                'jitstressregs0x80',
400                'jitstressregs0x1000',
401                'jitstress2_jitstressregs1',
402                'jitstress2_jitstressregs2',
403                'jitstress2_jitstressregs3',
404                'jitstress2_jitstressregs4',
405                'jitstress2_jitstressregs8',
406                'jitstress2_jitstressregs0x10',
407                'jitstress2_jitstressregs0x80',
408                'jitstress2_jitstressregs0x1000',
409                'tailcallstress',
410                // 'jitsse2only'                          // Only relevant to xarch
411                // 'jitnosimd'                            // Only interesting on platforms where SIMD support exists.
412                // 'jitincompletehwintrinsic'
413                // 'jitx86hwintrinsicnoavx'
414                // 'jitx86hwintrinsicnoavx2'
415                // 'jitx86hwintrinsicnosimd'
416                // 'jitnox86hwintrinsic'
417                'corefx_baseline',
418                'corefx_minopts',
419                'corefx_tieredcompilation',
420                'corefx_jitstress1',
421                'corefx_jitstress2',
422                'corefx_jitstressregs1',
423                'corefx_jitstressregs2',
424                'corefx_jitstressregs3',
425                'corefx_jitstressregs4',
426                'corefx_jitstressregs8',
427                'corefx_jitstressregs0x10',
428                'corefx_jitstressregs0x80',
429                'corefx_jitstressregs0x1000',
430                'gcstress0x3',
431                'gcstress0xc',
432                'zapdisable',
433                'heapverify1',
434                'gcstress0xc_zapdisable',
435                'gcstress0xc_zapdisable_jitstress2',
436                'gcstress0xc_zapdisable_heapverify1',
437                'gcstress0xc_jitstress1',
438                'gcstress0xc_jitstress2',
439                'gcstress0xc_minopts_heapverify1'
440     ]
441
442     def static validLinuxArm64Scenarios = [
443                'innerloop',
444                'normal',
445                // 'ilrt'
446                'r2r',
447                // 'longgc'
448                // 'formatting'
449                // 'gcsimulator'
450                // 'jitdiff'
451                // 'standalone_gc'
452                // 'gc_reliability_framework'
453                // 'illink'
454                // 'corefx_innerloop'
455                'crossgen_comparison',
456                'pmi_asm_diffs',
457                'r2r_jitstress1',
458                'r2r_jitstress2',
459                'r2r_jitstress1_tiered',
460                'r2r_jitstress2_tiered',
461                'r2r_jitstressregs1',
462                'r2r_jitstressregs2',
463                'r2r_jitstressregs3',
464                'r2r_jitstressregs4',
465                'r2r_jitstressregs8',
466                'r2r_jitstressregs0x10',
467                'r2r_jitstressregs0x80',
468                'r2r_jitstressregs0x1000',
469                'r2r_jitminopts',
470                'r2r_jitforcerelocs',
471                'r2r_gcstress15',
472                'r2r_no_tiered_compilation',
473                'minopts',
474                'tieredcompilation',
475                'no_tiered_compilation',
476                'no_tiered_compilation_innerloop',
477                'forcerelocs',
478                'jitstress1',
479                'jitstress2',
480                'jitstress1_tiered',
481                'jitstress2_tiered',
482                'jitstressregs1',
483                'jitstressregs2',
484                'jitstressregs3',
485                'jitstressregs4',
486                'jitstressregs8',
487                'jitstressregs0x10',
488                'jitstressregs0x80',
489                'jitstressregs0x1000',
490                'jitstress2_jitstressregs1',
491                'jitstress2_jitstressregs2',
492                'jitstress2_jitstressregs3',
493                'jitstress2_jitstressregs4',
494                'jitstress2_jitstressregs8',
495                'jitstress2_jitstressregs0x10',
496                'jitstress2_jitstressregs0x80',
497                'jitstress2_jitstressregs0x1000',
498                'tailcallstress',
499                // 'jitsse2only'                         // Only relevant to xarch
500                'jitnosimd',                             // Only interesting on platforms where SIMD support exists.
501                // 'jitincompletehwintrinsic'
502                // 'jitx86hwintrinsicnoavx'
503                // 'jitx86hwintrinsicnoavx2'
504                // 'jitx86hwintrinsicnosimd'
505                // 'jitnox86hwintrinsic'
506                'corefx_baseline',
507                'corefx_minopts',
508                'corefx_tieredcompilation',
509                'corefx_jitstress1',
510                'corefx_jitstress2',
511                'corefx_jitstressregs1',
512                'corefx_jitstressregs2',
513                'corefx_jitstressregs3',
514                'corefx_jitstressregs4',
515                'corefx_jitstressregs8',
516                'corefx_jitstressregs0x10',
517                'corefx_jitstressregs0x80',
518                'corefx_jitstressregs0x1000',
519                'gcstress0x3',
520                'gcstress0xc',
521                'zapdisable',
522                'heapverify1',
523                'gcstress0xc_zapdisable',
524                'gcstress0xc_zapdisable_jitstress2',
525                'gcstress0xc_zapdisable_heapverify1',
526                'gcstress0xc_jitstress1',
527                'gcstress0xc_jitstress2',
528                'gcstress0xc_minopts_heapverify1'
529     ]
530
531     def static configurationList = ['Debug', 'Checked', 'Release']
532
533     // This is the set of architectures
534     // Some of these are pseudo-architectures:
535     //    armem -- ARM builds/runs using an emulator. Used for Tizen runs.
536     //    x86_arm_altjit -- ARM runs on x86 using the ARM altjit
537     //    x64_arm64_altjit -- ARM64 runs on x64 using the ARM64 altjit
538     def static architectureList = ['arm', 'armem', 'x86_arm_altjit', 'x64_arm64_altjit', 'arm64', 'x64', 'x86']
539
540     // This set of architectures that cross build on Windows and run on Windows ARM64 hardware.
541     def static armWindowsCrossArchitectureList = ['arm', 'arm64']
542 }
543
544 // **************************************************************
545 // Create some specific views
546 // 
547 // These aren't using the Utilities.addStandardFolderView() function, because that creates
548 // views based on a single regular expression. These views will be generated by adding a
549 // specific set of jobs to them.
550 //
551 // Utilities.addStandardFolderView() also creates a lot of additional stuff around the
552 // view, like "Build Statistics", "Job Statistics", "Unstable Jobs". Until it is determined
553 // those are required, don't add them (which simplifies the view pages, as well).
554 // **************************************************************
555
556 class Views {
557     def static MergeJobView = null
558     def static PeriodicJobView = null
559     def static ArchitectureViews = [:]
560     def static OSViews = [:]
561 }
562
563 // MergeJobView: include all jobs that execute when a PR change is merged.
564 Views.MergeJobView = listView('Merge') {
565     recurse()
566     columns {
567         status()
568         weather()
569         name()
570         lastSuccess()
571         lastFailure()
572         lastDuration()
573         buildButton()
574     }
575 }
576
577 // PeriodicJobView: include all jobs that execute on a schedule
578 Views.PeriodicJobView = listView('Periodic') {
579     recurse()
580     columns {
581         status()
582         weather()
583         name()
584         lastSuccess()
585         lastFailure()
586         lastDuration()
587         buildButton()
588     }
589 }
590
591 // Create a view for non-PR jobs for each architecture.
592 Constants.architectureList.each { architecture ->
593     Views.ArchitectureViews[architecture] = listView(architecture) {
594         recurse()
595         columns {
596             status()
597             weather()
598             name()
599             lastSuccess()
600             lastFailure()
601             lastDuration()
602             buildButton()
603         }
604     }
605 }
606
607 // Create a view for non-PR jobs for each OS.
608 Constants.osList.each { os ->
609     // Don't create one for the special 'Windows_NT_BuildOnly'
610     if (os == 'Windows_NT_BuildOnly') {
611         return
612     }
613     Views.OSViews[os] = listView(os) {
614         recurse()
615         columns {
616             status()
617             weather()
618             name()
619             lastSuccess()
620             lastFailure()
621             lastDuration()
622             buildButton()
623         }
624     }
625 }
626
627 def static addToMergeView(def job) {
628     Views.MergeJobView.with {
629         jobs {
630             name(job.name)
631         }
632     }
633 }
634
635 def static addToPeriodicView(def job) {
636     Views.PeriodicJobView.with {
637         jobs {
638             name(job.name)
639         }
640     }
641 }
642
643 def static addToViews(def job, def isFlowJob, def isPR, def architecture, def os, def configuration, def scenario) {
644     if (isPR) {
645         // No views want PR jobs currently.
646         return
647     }
648
649     // We don't want to include in view any job that is only used by a flow job (because we want the views to have only the
650     // "top-level" jobs. Build only jobs are such jobs.
651     if (os == 'Windows_NT_BuildOnly') {
652         return
653     }
654
655     if (!isFlowJob) {
656         // For non-flow jobs, which ones are only used by flow jobs?
657         if ((architecture == 'arm') || (architecture == 'arm64')) {
658             if (isCoreFxScenario(scenario)) {
659                 // We have corefx-specific scenario builds for each of the runs, but these are driven by flow jobs.
660                 return
661             }
662
663             // We're left with the basic normal/innerloop builds. We might want to remove these from the views also, if desired.
664             // However, there are a few, like the Debug Build, that is build only, not "Build and Test", that we should leave.
665         }
666     }
667
668     // Add to architecture view.
669     Views.ArchitectureViews[architecture].with {
670         jobs {
671             name(job.name)
672         }
673     }
674
675     // Add to OS view.
676     Views.OSViews[os].with {
677         jobs {
678             name(job.name)
679         }
680     }
681 }
682
683 def static addPeriodicTriggerHelper(def job, String cronString, boolean alwaysRuns = false) {
684     addToPeriodicView(job)
685     Utilities.addPeriodicTrigger(job, cronString, alwaysRuns)
686 }
687
688 def static addGithubPushTriggerHelper(def job) {
689     addToMergeView(job)
690     Utilities.addGithubPushTrigger(job)
691 }
692
693
694 def static setMachineAffinity(def job, def os, def architecture, def options = null) {
695     assert os instanceof String
696     assert architecture instanceof String
697
698     def armArches = ['arm', 'armem', 'arm64']
699
700     if (!(architecture in armArches)) {
701         assert options == null
702         Utilities.setMachineAffinity(job, os, 'latest-or-auto')
703
704         return
705     }
706
707     // This is an arm(64) job.
708     //
709     // There are several options.
710     //
711     // Windows_NT
712     // 
713     // Arm32 (Build) -> latest-arm64
714     //       |-> os == "Windows_NT" && (architecture == "arm") && options['use_arm64_build_machine'] == true
715     // Arm32 (Test)  -> arm64-windows_nt
716     //       |-> os == "Windows_NT" && (architecture == "arm") && options['use_arm64_build_machine'] == false
717     //
718     // Arm64 (Build) -> latest-arm64
719     //       |-> os == "Windows_NT" && architecture == "arm64" && options['use_arm64_build_machine'] == true
720     // Arm64 (Test)  -> arm64-windows_nt
721     //       |-> os == "Windows_NT" && architecture == "arm64" && options['use_arm64_build_machine'] == false
722     //
723     // Ubuntu
724     //
725     // Arm32 emulator (Build, Test) -> arm-cross-latest
726     //       |-> os == "Tizen" && (architecture == "armem")
727     //
728     // Arm32 hardware (Flow) -> Ubuntu 16.04 latest-or-auto (don't use limited arm hardware)
729     //       |-> os == "Ubuntu" && (architecture == "arm") && options['is_flow_job'] == true
730     // Arm32 hardware (Build) -> Ubuntu 16.04 latest-or-auto
731     //       |-> os == "Ubuntu" && (architecture == "arm") && options['is_build_job'] == true
732     // Arm32 hardware (Test) -> Helix ubuntu.1404.arm32.open queue
733     //       |-> os == "Ubuntu" && (architecture == "arm")
734     //
735     // Arm64 (Build) -> arm64-cross-latest
736     //       |-> os != "Windows_NT" && architecture == "arm64" && options['is_build_job'] == true
737     // Arm64 (Test) -> Helix Ubuntu.1604.Arm64.Open queue
738     //       |-> os != "Windows_NT" && architecture == "arm64"
739     //
740     // Note: we are no longer using Jenkins tags "arm64-huge-page-size", "arm64-small-page-size".
741     // Support for Linux arm64 large page size has been removed for now, as it wasn't being used.
742     //
743     // Note: we are no longer using Jenkins tag 'latest-arm64' for arm/arm64 Windows build machines. Instead,
744     // we are using public VS2017 arm/arm64 tools in a VM from Helix.
745
746     // This has to be a arm arch
747     assert architecture in armArches
748     if (os == "Windows_NT") {
749         // arm32/arm64 Windows jobs share the same machines for now
750         def isBuild = options['use_arm64_build_machine'] == true
751
752         if (isBuild == true) {
753             job.with {
754                 label('Windows.10.Amd64.ClientRS4.DevEx.Open')
755             }
756         } else {
757             Utilities.setMachineAffinity(job, 'windows.10.arm64.open')
758         }
759     } else {
760         assert os != 'Windows_NT'
761
762         if (architecture == 'armem') {
763             // arm emulator (Tizen). Build and test on same machine,
764             // using Docker.
765             assert os == 'Tizen'
766             Utilities.setMachineAffinity(job, 'Ubuntu', 'arm-cross-latest')
767         }
768         else {
769             // arm/arm64 Ubuntu on hardware.
770             assert architecture == 'arm' || architecture == 'arm64'
771             def isFlow  = (options != null) && (options['is_flow_job'] == true)
772             def isBuild = (options != null) && (options['is_build_job'] == true)
773             if (isFlow || isBuild) {
774                 // arm/arm64 Ubuntu build machine. Build uses docker, so the actual host OS is not
775                 // very important. Therefore, use latest or auto. Flow jobs don't need to use arm hardware.
776                 Utilities.setMachineAffinity(job, 'Ubuntu16.04', 'latest-or-auto')
777             } else {
778                 // arm/arm64 Ubuntu test machine. Specify the Helix queue name here.
779                 if (architecture == 'arm64') {
780                     assert os == 'Ubuntu16.04'
781                     job.with {
782                         label('Ubuntu.1604.Arm64.Open')
783                     }
784                 }
785                 else {
786                     assert os == 'Ubuntu'
787                     job.with {
788                         label('ubuntu.1404.arm32.open')
789                     }
790                 }
791             }
792         }
793     }
794 }
795
796 // setJobMachineAffinity: compute the machine affinity options for a job,
797 // then set the job with those affinity options.
798 def static setJobMachineAffinity(def architecture, def os, def isBuildJob, def isTestJob, def isFlowJob, def job)
799 {
800     assert (isBuildJob  && !isTestJob && !isFlowJob) ||
801            (!isBuildJob && isTestJob  && !isFlowJob) ||
802            (!isBuildJob && !isTestJob && isFlowJob)
803
804     def affinityOptions = null
805     def affinityArchitecture = architecture
806
807     if (os == "Windows_NT") {
808         if (architecture in Constants.armWindowsCrossArchitectureList) {
809             if (isBuildJob) {
810                 affinityOptions = [ "use_arm64_build_machine" : true ]
811             } else if (isTestJob) {
812                 affinityOptions = [ "use_arm64_build_machine" : false ]
813             } else if (isFlowJob) {
814                 // For the flow jobs set the machine affinity as x64
815                 affinityArchitecture = 'x64'
816             }
817         }
818     }
819     else {
820         if ((architecture == 'arm64') || (architecture == 'arm')) {
821             if (isBuildJob) {
822                 affinityOptions = ['is_build_job': true]
823             } else if (isFlowJob) {
824                 affinityOptions = ['is_flow_job': true]
825             }
826         }
827     }
828
829     setMachineAffinity(job, os, affinityArchitecture, affinityOptions)
830 }
831
832 def static isGCStressRelatedTesting(def scenario) {
833     // The 'r2r_gcstress15' scenario is a basic scenario.
834     // Detect it and make it a GCStress related.
835     if (scenario == 'r2r_gcstress15')
836     {
837         return true;
838     }
839
840     def gcStressTestEnvVars = [ 'COMPlus_GCStress', 'COMPlus_ZapDisable', 'COMPlus_HeapVerify']
841     def scenarioName = scenario.toLowerCase()
842     def isGCStressTesting = false
843     Constants.jitStressModeScenarios[scenario].each{ k, v ->
844         if (k in gcStressTestEnvVars) {
845             isGCStressTesting = true;
846         }
847     }
848     return isGCStressTesting
849 }
850
851 def static isCoreFxScenario(def scenario) {
852     def corefx_prefix = 'corefx_'
853     if (scenario.length() < corefx_prefix.length()) {
854         return false
855     }
856     return scenario.substring(0,corefx_prefix.length()) == corefx_prefix
857 }
858
859 def static isR2RBaselineScenario(def scenario) {
860     return (scenario == 'r2r')
861 }
862
863 def static isR2RStressScenario(def scenario) {
864     return Constants.r2rStressScenarios.containsKey(scenario)
865 }
866
867 def static isR2RScenario(def scenario) {
868     return isR2RBaselineScenario(scenario) || isR2RStressScenario(scenario)
869 }
870
871 def static isJitStressScenario(def scenario) {
872     return Constants.jitStressModeScenarios.containsKey(scenario)
873 }
874
875 def static isLongGc(def scenario) {
876     return (scenario == 'longgc' || scenario == 'gcsimulator')
877 }
878
879 def static isJitDiff(def scenario) {
880     return (scenario == 'jitdiff')
881 }
882
883 def static isGcReliabilityFramework(def scenario) {
884     return (scenario == 'gc_reliability_framework')
885 }
886
887 def static isArmWindowsScenario(def scenario) {
888     return Constants.validArmWindowsScenarios.contains(scenario)
889 }
890
891 def static isValidPrTriggeredInnerLoopJob(os, architecture, configuration, isBuildOnly) {
892     if (isBuildOnly == true) {
893         os = 'Windows_NT_BuildOnly'
894     }
895
896     def validOsPrTriggerArchConfigs = Constants.prTriggeredValidInnerLoopCombos[os]
897     if (validOsPrTriggerArchConfigs != null) {
898         def validOsPrTriggerConfigs = validOsPrTriggerArchConfigs[architecture]
899         if (validOsPrTriggerConfigs != null) {
900             if (configuration in validOsPrTriggerConfigs) {
901                 return true
902             }
903         }
904     }
905
906     return false
907 }
908
909 // This means the job builds and runs the 'innerloop' test set. This does not mean the job is 
910 // scheduled with a default PR trigger despite the correlation being true at the moment.
911 def static isInnerloopTestScenario(def scenario) {
912     return (scenario == 'innerloop' || scenario == 'no_tiered_compilation_innerloop')
913 }
914
915 def static isCrossGenComparisonScenario(def scenario) {
916     return (scenario == 'crossgen_comparison')
917 }
918
919 def static shouldGenerateCrossGenComparisonJob(def os, def architecture, def configuration, def scenario) {
920     assert isCrossGenComparisonScenario(scenario)
921     return ((os == 'Ubuntu' && architecture == 'arm') || (os == 'Ubuntu16.04' && architecture == 'arm64')) && (configuration == 'Checked' || configuration == 'Release')
922 }
923
924 def static getFxBranch(def branch) {
925     def fxBranch = branch
926     // Map 'dev/unix_test_workflow' to 'master' so we can test CoreFX jobs in the CoreCLR dev/unix_test_workflow
927     // branch even though CoreFX doesn't have such a branch.
928     if (branch == 'dev/unix_test_workflow') {
929         fxBranch = 'master'
930     }
931     return fxBranch
932 }
933
934 def static setJobTimeout(newJob, isPR, architecture, configuration, scenario, isBuildOnly) {
935     // 2 hours (120 minutes) is the default timeout
936     def timeout = 120
937
938     if (!isInnerloopTestScenario(scenario)) {
939         // Pri-1 test builds take a long time (see calculateBuildCommands()). So up the Pri-1 build jobs timeout.
940         timeout = 240
941     }
942
943     if (!isBuildOnly) {
944         // Note that these can only increase, never decrease, the Pri-1 timeout possibly set above.
945         if (isGCStressRelatedTesting(scenario)) {
946             timeout = 4320
947         }
948         else if (isCoreFxScenario(scenario)) {
949             timeout = 360
950         }
951         else if (isJitStressScenario(scenario)) {
952             timeout = 300
953         }
954         else if (isR2RBaselineScenario(scenario)) {
955             timeout = 240
956         }
957         else if (isLongGc(scenario)) {
958             timeout = 1440
959         }
960         else if (isJitDiff(scenario)) {
961             timeout = 240
962         }
963         else if (isGcReliabilityFramework(scenario)) {
964             timeout = 1440
965         }
966         else if (architecture == 'armem' || architecture == 'arm64') {
967             timeout = 240
968         }
969
970         if (architecture == 'arm') {
971             // ARM32 machines are particularly slow.
972             timeout += 120
973         }
974     }
975
976     if (configuration == 'Debug') {
977         // Debug runs can be very slow. Add an hour.
978         timeout += 60
979     }
980
981     if (architecture == 'x86_arm_altjit' || architecture == 'x64_arm64_altjit') {
982         // AltJit runs compile all methods twice.
983         timeout *= 2
984     }
985
986     // If we've changed the timeout from the default, set it in the job.
987
988     if (timeout != 120) {
989         Utilities.setJobTimeout(newJob, timeout)
990     }
991 }
992
993 def static getJobFolder(def scenario) {
994     if (isJitStressScenario(scenario) || isR2RStressScenario(scenario)) {
995         return 'jitstress'
996     }
997     if (scenario == 'illink') {
998         return 'illink'
999     }
1000     return ''
1001 }
1002
1003 def static getStressModeDisplayName(def scenario) {
1004     def displayStr = ''
1005     Constants.jitStressModeScenarios[scenario].each{ k, v ->
1006         def prefixLength = 'COMPlus_'.length()
1007         if (k.length() >= prefixLength) {
1008             def modeName = k.substring(prefixLength, k.length())
1009             if (displayStr != '') {
1010                 // Separate multiple variables with a space.
1011                 displayStr += ' '
1012             }
1013             displayStr += modeName + '=' + v
1014         }
1015     }
1016
1017     if (isCoreFxScenario(scenario)) {
1018         displayStr = ('CoreFx ' + displayStr).trim()
1019     }
1020
1021     return displayStr
1022 }
1023
1024 def static getR2RDisplayName(def scenario) {
1025     // Assume the scenario name is one from the r2rStressScenarios dict, and remove its "r2r_" prefix.
1026     def displayStr = scenario
1027     def prefixLength = 'r2r_'.length()
1028     if (displayStr.length() >= prefixLength) {
1029         displayStr = "R2R " + displayStr.substring(prefixLength, displayStr.length())
1030     } else if (scenario == 'r2r') {
1031         displayStr = "R2R"
1032     }
1033     return displayStr
1034 }
1035
1036 def static getScenarioDisplayString(def scenario) {
1037     switch (scenario) {
1038         case 'innerloop':
1039             return "Innerloop Build and Test"
1040
1041         case 'no_tiered_compilation_innerloop':
1042             def displayStr = getStressModeDisplayName(scenario)
1043             return "Innerloop Build and Test (Jit - ${displayStr})"
1044
1045         case 'corefx_innerloop':
1046             return "CoreFX Tests"
1047
1048         case 'normal':
1049             return "Build and Test"
1050
1051         case 'jitdiff':
1052             return "Jit Diff Build and Test"
1053
1054         case 'ilrt':
1055             return "IL RoundTrip Build and Test"
1056
1057         case 'longgc':
1058             return "Long-Running GC Build & Test"
1059
1060         case 'gcsimulator':
1061             return "GC Simulator"
1062
1063         case 'standalone_gc':
1064             return "Standalone GC"
1065
1066         case 'gc_reliability_framework':
1067             return "GC Reliability Framework"
1068
1069         case 'illink':
1070             return "via ILLink"
1071
1072         default:
1073             if (isJitStressScenario(scenario)) {
1074                 def displayStr = getStressModeDisplayName(scenario)
1075                 return "Build and Test (Jit - ${displayStr})"
1076             }
1077             else if (isR2RScenario(scenario)) {
1078                 def displayStr = getR2RDisplayName(scenario)
1079                 return "${displayStr} Build and Test"
1080             }
1081             else {
1082                 return "${scenario}"
1083             }
1084             break
1085     }
1086
1087     println("Unknown scenario: ${scenario}");
1088     assert false
1089 }
1090
1091 //
1092 // Functions to create an environment script.
1093 //      envScriptCreate -- initialize the script (call first)
1094 //      envScriptFinalize -- finalize the script (call last)
1095 //      envScriptSetStressModeVariables -- set stress mode variables in the env script
1096 //      envScriptAppendExistingScript -- append an existing script to the generated script
1097 //
1098 // Each script returns a string of commands. Concatenate all the strings together before
1099 // adding them to the builds commands, to make sure they get executed as one Jenkins script.
1100 //
1101
1102 // Initialize the environment setting script.
1103 def static envScriptCreate(def os, def stepScriptLocation) {
1104     def stepScript = ''
1105     if (os == 'Windows_NT') {
1106         stepScript += "echo Creating TestEnv script\r\n"
1107         stepScript += "if exist ${stepScriptLocation} del ${stepScriptLocation}\r\n"
1108
1109         // Create at least an empty script.
1110         stepScript += "echo. > ${stepScriptLocation}\r\n"
1111     }
1112     else {
1113         stepScript += "echo Creating environment setting script\n"
1114         stepScript += "echo \\#\\!/usr/bin/env bash > ${stepScriptLocation}\n"
1115     }
1116
1117     return stepScript
1118 }
1119
1120 // Generates the string for setting stress mode variables.
1121 def static envScriptSetStressModeVariables(def os, def stressModeVars, def stepScriptLocation) {
1122     def stepScript = ''
1123     if (os == 'Windows_NT') {
1124         stressModeVars.each{ k, v ->
1125             // Write out what we are writing to the script file
1126             stepScript += "echo Setting ${k}=${v}\r\n"
1127             // Write out the set itself to the script file`
1128             stepScript += "echo set ${k}=${v} >> ${stepScriptLocation}\r\n"
1129         }
1130     }
1131     else {
1132         stressModeVars.each{ k, v ->
1133             // Write out what we are writing to the script file
1134             stepScript += "echo Setting ${k}=${v}\n"
1135             // Write out the set itself to the script file`
1136             stepScript += "echo export ${k}=${v} >> ${stepScriptLocation}\n"
1137         }
1138     }
1139
1140     return stepScript
1141 }
1142
1143 // Append an existing script to an environment script.
1144 // Returns string of commands to do this.
1145 def static envScriptAppendExistingScript(def os, def appendScript, def stepScriptLocation) {
1146     assert (os == 'Windows_NT')
1147     def stepScript = ''
1148
1149     stepScript += "echo Appending ${appendScript} to ${stepScriptLocation}\r\n"
1150     stepScript += "type ${appendScript} >> ${stepScriptLocation}\r\n"
1151
1152     return stepScript
1153 }
1154
1155 // Finalize an environment setting script.
1156 // Returns string of commands to do this.
1157 def static envScriptFinalize(def os, def stepScriptLocation) {
1158     def stepScript = ''
1159
1160     if (os == 'Windows_NT') {
1161         // Display the resulting script. This is useful when looking at the output log file.
1162         stepScript += "echo Display the total script ${stepScriptLocation}\r\n"
1163         stepScript += "type ${stepScriptLocation}\r\n"
1164     }
1165     else {
1166         stepScript += "chmod +x ${stepScriptLocation}\n"
1167     }
1168
1169     return stepScript
1170 }
1171
1172 def static isNeedDocker(def architecture, def os, def isBuild) {
1173     if (isBuild) {
1174         if (architecture == 'x86' && os == 'Ubuntu') {
1175             return true
1176         }
1177         else if (architecture == 'armem') {
1178             return true
1179         }
1180         else if (architecture == 'arm') {
1181             if (os == 'Ubuntu') {
1182                 return true
1183             }
1184         }
1185         else if (architecture == 'arm64') {
1186             if (os == 'Ubuntu16.04') {
1187                 return true
1188             }
1189         }
1190     }
1191     else {
1192         if (architecture == 'x86' && os == 'Ubuntu') {
1193             return true
1194         }
1195     }
1196     return false
1197 }
1198
1199 def static getDockerImageName(def architecture, def os, def isBuild) {
1200     // We must change some docker private images to official later
1201     if (isBuild) {
1202         if (architecture == 'x86' && os == 'Ubuntu') {
1203             return "hseok82/dotnet-buildtools-prereqs:ubuntu-16.04-crossx86-ef0ac75-20175511035548"
1204         }
1205         else if (architecture == 'armem') {
1206             if (os == 'Tizen') {
1207                 return "tizendotnet/dotnet-buildtools-prereqs:ubuntu-16.04-cross-e435274-20180426002255-tizen-rootfs-5.0m1"
1208             }
1209         }
1210         else if (architecture == 'arm') {
1211             if (os == 'Ubuntu') {
1212                 return "microsoft/dotnet-buildtools-prereqs:ubuntu-14.04-cross-e435274-20180426002420"
1213             }
1214         }
1215         else if (architecture == 'arm64') {
1216             if (os == 'Ubuntu16.04') {
1217                 return "microsoft/dotnet-buildtools-prereqs:ubuntu-16.04-cross-arm64-a3ae44b-20180315221921"
1218             }
1219         }
1220     }
1221     else {
1222         if (architecture == 'x86' && os == 'Ubuntu') {
1223             return "hseok82/dotnet-buildtools-prereqs:ubuntu1604_x86_test"
1224         }
1225     }
1226     println("Unknown architecture to use docker: ${architecture} ${os}");
1227     assert false
1228 }
1229
1230 def static getTestArtifactsTgzFileName(def osGroup, def architecture, def configuration) {
1231     return "bin-tests-${osGroup}.${architecture}.${configuration}.tgz"
1232 }
1233
1234 // We have a limited amount of some hardware. For these, scale back the periodic testing we do,
1235 // and only allowing using this hardware in some specific branches.
1236 def static jobRequiresLimitedHardware(def architecture, def os) {
1237     if (architecture == 'arm') {
1238         // arm Windows and Linux hardware is limited.
1239         return true
1240     }
1241     else if (architecture == 'arm64') {
1242         // arm64 Windows and Linux hardware is limited.
1243         return true
1244     }
1245     else {
1246         return false
1247     }
1248 }
1249
1250 // Calculates the name of the build job based on some typical parameters.
1251 //
1252 def static getJobName(def configuration, def architecture, def os, def scenario, def isBuildOnly) {
1253     // If the architecture is x64, do not add that info into the build name.
1254     // Need to change around some systems and other builds to pick up the right builds
1255     // to do that.
1256
1257     def suffix = scenario != 'normal' ? "_${scenario}" : '';
1258     if (isBuildOnly) {
1259         suffix += '_bld'
1260     }
1261     def baseName = ''
1262     switch (architecture) {
1263         case 'x64':
1264             if (scenario == 'normal') {
1265                 // For now we leave x64 off of the name for compatibility with other jobs
1266                 baseName = configuration.toLowerCase() + '_' + os.toLowerCase()
1267             }
1268             else if (scenario == 'formatting') {
1269                 // we don't care about the configuration for the formatting job. It runs all configs
1270                 baseName = architecture.toLowerCase() + '_' + os.toLowerCase()
1271             }
1272             else {
1273                 baseName = architecture.toLowerCase() + '_' + configuration.toLowerCase() + '_' + os.toLowerCase()
1274             }
1275             break
1276         case 'armem':
1277             // These are cross builds
1278             assert os == 'Tizen'
1279             baseName = 'armel_cross_' + configuration.toLowerCase() + '_' + os.toLowerCase()
1280             break
1281         case 'arm':
1282         case 'arm64':
1283             // These are cross builds
1284             baseName = architecture.toLowerCase() + '_cross_' + configuration.toLowerCase() + '_' + os.toLowerCase()
1285             break
1286         case 'x86':
1287         case 'x86_arm_altjit':
1288         case 'x64_arm64_altjit':
1289             baseName = architecture.toLowerCase() + '_' + configuration.toLowerCase() + '_' + os.toLowerCase()
1290             break
1291         default:
1292             println("Unknown architecture: ${architecture}");
1293             assert false
1294             break
1295     }
1296
1297     return baseName + suffix
1298 }
1299
1300 def static addNonPRTriggers(def job, def branch, def isPR, def architecture, def os, def configuration, def scenario, def isFlowJob, def isWindowsBuildOnlyJob, def bidailyCrossList) {
1301
1302     // The dev/unix_test_workflow branch is used for Jenkins CI testing. We generally do not need any non-PR
1303     // triggers in the branch, because that would use machine resources unnecessarily.
1304     if (branch == 'dev/unix_test_workflow') {
1305         return
1306     }
1307
1308     // Limited hardware is restricted for non-PR triggers to certain branches.
1309     if (jobRequiresLimitedHardware(architecture, os) && (!(branch in Constants.LimitedHardwareBranches))) {
1310         return
1311     }
1312
1313     // Ubuntu x86 CI jobs are failing. Disable non-PR triggered jobs to avoid these constant failures
1314     // until this is fixed. Tracked by https://github.com/dotnet/coreclr/issues/19003.
1315     if (architecture == 'x86' && os == 'Ubuntu') {
1316         return
1317     }
1318
1319     def isNormalOrInnerloop = (scenario == "normal" || scenario == "innerloop")
1320
1321     // Check scenario.
1322     switch (scenario) {
1323         case 'crossgen_comparison':
1324             if (isFlowJob && ((os == 'Ubuntu' && architecture == 'arm') || (os == 'Ubuntu16.04' && architecture == 'arm64')) && (configuration == 'Checked' || configuration == 'Release')) {
1325                 addPeriodicTriggerHelper(job, '@daily')
1326             }
1327             break
1328
1329         case 'pmi_asm_diffs':
1330             // No non-PR triggers for now.
1331             break
1332
1333         case 'normal':
1334             switch (architecture) {
1335                 case 'x64':
1336                 case 'x86':
1337                     if (isFlowJob && architecture == 'x86' && os == 'Ubuntu') {
1338                         addPeriodicTriggerHelper(job, '@daily')
1339                     }
1340                     else if (isFlowJob || os == 'Windows_NT' || (architecture == 'x64' && !(os in Constants.crossList))) {
1341                         addGithubPushTriggerHelper(job)
1342                     }
1343                     break
1344                 case 'arm64':
1345                     if (os == 'Windows_NT') {
1346                         if (isFlowJob || (isNormalOrInnerloop && (configuration == 'Debug'))) {
1347                             // We would normally want a per-push trigger, but with limited hardware we can't keep up.
1348                             // Do the builds daily.
1349                             addPeriodicTriggerHelper(job, '@daily')
1350                         }
1351                     }
1352                     else {
1353                         // Only the flow jobs get push triggers; the build and test jobs are triggered by the flow job.
1354                         if (isFlowJob) {
1355                             addPeriodicTriggerHelper(job, '@daily')
1356                         }
1357                     }
1358                     break
1359                 case 'arm':
1360                     if (os == 'Windows_NT') {
1361                         if (isFlowJob || (isNormalOrInnerloop && (configuration == 'Debug'))) {
1362                             // We would normally want a push trigger, but with limited hardware we can't keep up.
1363                             // Do the builds daily.
1364                             addPeriodicTriggerHelper(job, '@daily')
1365                         }
1366                     }
1367                     else {
1368                         assert os == 'Ubuntu'
1369                         // Only the flow jobs get push triggers; the build and test jobs are triggered by the flow job.
1370                         if (isFlowJob) {
1371                             // Currently no push triggers, with limited arm Linux hardware.
1372                             // TODO: If we have enough machine capacity, add some arm Linux push triggers.
1373                             addPeriodicTriggerHelper(job, '@daily')
1374                         }
1375                     }
1376                     break
1377                 case 'armem':
1378                     addGithubPushTriggerHelper(job)
1379                     break
1380                 case 'x86_arm_altjit':
1381                 case 'x64_arm64_altjit':
1382                     // Only do altjit push triggers for Checked; don't waste time on Debug or Release.
1383                     if (configuration == 'Checked') {
1384                         addGithubPushTriggerHelper(job)
1385                     }
1386                     break
1387                 default:
1388                     println("Unknown architecture: ${architecture}");
1389                     assert false
1390                     break
1391             }
1392             break
1393         case 'r2r':
1394             assert !(os in bidailyCrossList)
1395             // r2r gets a push trigger for checked/release
1396             if (configuration == 'Checked' || configuration == 'Release') {
1397                 if (architecture == 'x64' && os != 'OSX10.12') {
1398                     //Flow jobs should be Windows, Ubuntu, OSX0.12, or CentOS
1399                     if (isFlowJob || os == 'Windows_NT') {
1400                         addGithubPushTriggerHelper(job)
1401                     }
1402                 // OSX10.12 r2r jobs should only run every 12 hours, not daily.
1403                 } else if (architecture == 'x64' && os == 'OSX10.12'){
1404                     if (isFlowJob) {
1405                         addPeriodicTriggerHelper(job, 'H H/12 * * *')
1406                     }
1407                 }
1408                 // For x86, only add per-commit jobs for Windows
1409                 else if (architecture == 'x86') {
1410                     if (os == 'Windows_NT') {
1411                         addGithubPushTriggerHelper(job)
1412                     }
1413                 }
1414                 // arm r2r jobs should only run weekly.
1415                 else if (architecture == 'arm') {
1416                     if (isFlowJob) {
1417                         addPeriodicTriggerHelper(job, '@weekly')
1418                     }
1419                 }
1420                 // arm64 r2r jobs should only run weekly.
1421                 else if (architecture == 'arm64') {
1422                     if (isFlowJob) {
1423                         addPeriodicTriggerHelper(job, '@weekly')
1424                     }
1425                 }
1426             }
1427             break
1428         case 'r2r_jitstress1':
1429         case 'r2r_jitstress2':
1430         case 'r2r_jitstress1_tiered':
1431         case 'r2r_jitstress2_tiered':
1432         case 'r2r_jitstressregs1':
1433         case 'r2r_jitstressregs2':
1434         case 'r2r_jitstressregs3':
1435         case 'r2r_jitstressregs4':
1436         case 'r2r_jitstressregs8':
1437         case 'r2r_jitstressregs0x10':
1438         case 'r2r_jitstressregs0x80':
1439         case 'r2r_jitstressregs0x1000':
1440         case 'r2r_jitminopts':
1441         case 'r2r_jitforcerelocs':
1442         case 'r2r_gcstress15':
1443         case 'r2r_no_tiered_compilation':
1444             assert !(os in bidailyCrossList)
1445
1446             // GCStress=C is currently not supported on OS X
1447             if (os == 'OSX10.12' && isGCStressRelatedTesting(scenario)) {
1448                 break
1449             }
1450
1451             if (configuration == 'Checked' || configuration == 'Release') {
1452                 if (architecture == 'x64') {
1453                     //Flow jobs should be Windows, Ubuntu, OSX10.12, or CentOS
1454                     if (isFlowJob || os == 'Windows_NT') {
1455                         addPeriodicTriggerHelper(job, 'H H * * 3,6') // some time every Wednesday and Saturday
1456                     }
1457                 }
1458                 // For x86, only add periodic jobs for Windows
1459                 else if (architecture == 'x86') {
1460                     if (os == 'Windows_NT') {
1461                         addPeriodicTriggerHelper(job, 'H H * * 3,6') // some time every Wednesday and Saturday
1462                     }
1463                 }
1464                 else if (architecture == 'arm') {
1465                     if (isFlowJob) {
1466                         addPeriodicTriggerHelper(job, '@weekly')
1467                     }
1468                 }
1469                 else if (architecture == 'arm64') {
1470                     if (isFlowJob) {
1471                         addPeriodicTriggerHelper(job, '@weekly')
1472                     }
1473                 }
1474             }
1475             break
1476         case 'longgc':
1477             assert (os == 'Ubuntu' || os == 'Windows_NT' || os == 'OSX10.12')
1478             assert configuration == 'Release'
1479             assert architecture == 'x64'
1480             addPeriodicTriggerHelper(job, '@daily')
1481             // TODO: Add once external email sending is available again
1482             // addEmailPublisher(job, 'dotnetgctests@microsoft.com')
1483             break
1484         case 'gcsimulator':
1485             assert (os == 'Ubuntu' || os == 'Windows_NT' || os == 'OSX10.12')
1486             assert configuration == 'Release'
1487             assert architecture == 'x64'
1488             addPeriodicTriggerHelper(job, 'H H * * 3,6') // some time every Wednesday and Saturday
1489             // TODO: Add once external email sending is available again
1490             // addEmailPublisher(job, 'dotnetgctests@microsoft.com')
1491             break
1492         case 'standalone_gc':
1493             assert (os == 'Ubuntu' || os == 'Windows_NT' || os == 'OSX10.12')
1494             assert (configuration == 'Release' || configuration == 'Checked')
1495             // TODO: Add once external email sending is available again
1496             // addEmailPublisher(job, 'dotnetgctests@microsoft.com')
1497             addPeriodicTriggerHelper(job, '@daily')
1498             break
1499         case 'gc_reliability_framework':
1500             assert (os == 'Ubuntu' || os == 'Windows_NT' || os == 'OSX10.12')
1501             assert (configuration == 'Release' || configuration == 'Checked')
1502             // Only triggered by phrase.
1503             break
1504         case 'ilrt':
1505             assert !(os in bidailyCrossList)
1506             // ILASM/ILDASM roundtrip one gets a daily build, and only for release
1507             if (architecture == 'x64' && configuration == 'Release') {
1508                 if (isFlowJob || os == 'Windows_NT') {
1509                     addPeriodicTriggerHelper(job, '@daily')
1510                 }
1511             }
1512             break
1513         case 'jitdiff':
1514             assert (os == 'Ubuntu' || os == 'Windows_NT' || os == 'OSX10.12')
1515             assert configuration == 'Checked'
1516             assert (architecture == 'x64' || architecture == 'x86')
1517             addGithubPushTriggerHelper(job)
1518             break
1519         case 'formatting':
1520             assert (os == 'Windows_NT' || os == "Ubuntu")
1521             assert architecture == 'x64'
1522             addGithubPushTriggerHelper(job)
1523             break
1524         case 'jitstressregs1':
1525         case 'jitstressregs2':
1526         case 'jitstressregs3':
1527         case 'jitstressregs4':
1528         case 'jitstressregs8':
1529         case 'jitstressregs0x10':
1530         case 'jitstressregs0x80':
1531         case 'jitstressregs0x1000':
1532         case 'minopts':
1533         case 'tieredcompilation':
1534         case 'no_tiered_compilation':
1535         case 'forcerelocs':
1536         case 'jitstress1':
1537         case 'jitstress2':
1538         case 'jitstress1_tiered':
1539         case 'jitstress2_tiered':
1540         case 'jitstress2_jitstressregs1':
1541         case 'jitstress2_jitstressregs2':
1542         case 'jitstress2_jitstressregs3':
1543         case 'jitstress2_jitstressregs4':
1544         case 'jitstress2_jitstressregs8':
1545         case 'jitstress2_jitstressregs0x10':
1546         case 'jitstress2_jitstressregs0x80':
1547         case 'jitstress2_jitstressregs0x1000':
1548         case 'tailcallstress':
1549         case 'jitsse2only':
1550         case 'jitnosimd':
1551         case 'jitnox86hwintrinsic':
1552         case 'jitincompletehwintrinsic':
1553         case 'jitx86hwintrinsicnoavx':
1554         case 'jitx86hwintrinsicnoavx2':
1555         case 'jitx86hwintrinsicnosimd':
1556         case 'corefx_baseline':
1557         case 'corefx_minopts':
1558         case 'corefx_tieredcompilation':
1559         case 'corefx_jitstress1':
1560         case 'corefx_jitstress2':
1561         case 'corefx_jitstressregs1':
1562         case 'corefx_jitstressregs2':
1563         case 'corefx_jitstressregs3':
1564         case 'corefx_jitstressregs4':
1565         case 'corefx_jitstressregs8':
1566         case 'corefx_jitstressregs0x10':
1567         case 'corefx_jitstressregs0x80':
1568         case 'corefx_jitstressregs0x1000':
1569         case 'zapdisable':
1570             if (os == 'CentOS7.1') {
1571                 break
1572             }
1573             if (os in bidailyCrossList) {
1574                 break
1575             }
1576             // ARM corefx testing uses non-flow jobs to provide the configuration-specific
1577             // build for the flow job. We don't need cron jobs for these. Note that the
1578             // Windows ARM jobs depend on a Windows "build only" job that exits the trigger
1579             // function very early, so only non-Windows gets here.
1580             if ((architecture == 'arm') && isCoreFxScenario(scenario) && !isFlowJob) {
1581                 break
1582             }
1583             if ((architecture == 'arm64') && isCoreFxScenario(scenario) && !isFlowJob) {
1584                 break
1585             }
1586             if (jobRequiresLimitedHardware(architecture, os)) {
1587                 if ((architecture == 'arm64') && (os == 'Ubuntu16.04')) {
1588                     // These jobs are very fast on Linux/arm64 hardware, so run them daily.
1589                     addPeriodicTriggerHelper(job, '@daily')
1590                 }
1591                 else {
1592                     addPeriodicTriggerHelper(job, '@weekly')
1593                 }
1594             }
1595             else {
1596                 addPeriodicTriggerHelper(job, '@daily')
1597             }
1598             break
1599         case 'heapverify1':
1600         case 'gcstress0x3':
1601             if (os == 'CentOS7.1') {
1602                 break
1603             }
1604             if (os in bidailyCrossList) {
1605                 break
1606             }
1607             addPeriodicTriggerHelper(job, '@weekly')
1608             break
1609         case 'gcstress0xc':
1610         case 'gcstress0xc_zapdisable':
1611         case 'gcstress0xc_zapdisable_jitstress2':
1612         case 'gcstress0xc_zapdisable_heapverify1':
1613         case 'gcstress0xc_jitstress1':
1614         case 'gcstress0xc_jitstress2':
1615         case 'gcstress0xc_minopts_heapverify1':
1616             if (os == 'OSX10.12') {
1617                 // GCStress=C is currently not supported on OS X
1618                 break
1619             }
1620             if (os == 'CentOS7.1') {
1621                 break
1622             }
1623             if (os in bidailyCrossList) {
1624                 break
1625             }
1626             addPeriodicTriggerHelper(job, '@weekly')
1627             break
1628
1629         case 'illink':
1630             // Testing on other operating systems TBD
1631             assert (os == 'Windows_NT' || os == 'Ubuntu')
1632             if (architecture == 'x64' || architecture == 'x86') {
1633                 if (configuration == 'Checked') {
1634                     addPeriodicTriggerHelper(job, '@daily')
1635                 }
1636             }
1637             break
1638
1639         default:
1640             println("Unknown scenario: ${scenario}");
1641             assert false
1642             break
1643     }
1644     return
1645 }
1646
1647 // **************************
1648 // Define the basic inner loop builds for PR and commit.  This is basically just the set
1649 // of coreclr builds over linux/osx 10.12/windows and debug/release/checked.  In addition, the windows
1650 // builds will do a couple extra steps.
1651 // **************************
1652
1653 // Adds a trigger for the PR build if one is needed.  If isFlowJob is true, then this is the
1654 // flow job that rolls up the build and test for non-windows OS's.  // If the job is a windows build only job,
1655 // it's just used for internal builds
1656 // If you add a job with a trigger phrase, please add that phrase to coreclr/Documentation/project-docs/ci-trigger-phrases.md
1657 def static addTriggers(def job, def branch, def isPR, def architecture, def os, def configuration, def scenario, def isFlowJob, def isWindowsBuildOnlyJob) {
1658     def isNormalOrInnerloop = (scenario == "normal" || scenario == "innerloop")
1659     
1660     if (isWindowsBuildOnlyJob) {
1661         return
1662     }
1663
1664     def bidailyCrossList = ['RHEL7.2', 'Debian8.4']
1665     // Non pull request builds.
1666     if (!isPR) {
1667         addNonPRTriggers(job, branch, isPR, architecture, os, configuration, scenario, isFlowJob, isWindowsBuildOnlyJob, bidailyCrossList)
1668         return
1669     }
1670
1671     def arm64Users = [
1672         'adityamandaleeka',
1673         'AndyAyersMS',
1674         'briansull',
1675         'BruceForstall',
1676         'CarolEidt',
1677         'davidwrighton',
1678         'echesakovMSFT',
1679         'erozenfeld',
1680         'janvorli',
1681         'jashook',
1682         'pgodeq',
1683         'RussKeldorph',
1684         'sandreenko',
1685         'sdmaclea',
1686         'swaroop-sridhar',
1687         'jkotas',
1688         'markwilkie',
1689         'weshaggard'
1690     ]
1691
1692     // Pull request builds.  Generally these fall into two categories: default triggers and on-demand triggers
1693     // We generally only have a distinct set of default triggers but a bunch of on-demand ones.
1694
1695     def contextString = ""
1696     def triggerString = ""
1697     def needsTrigger = true
1698     def isDefaultTrigger = false
1699     def isArm64PrivateJob = false
1700     def scenarioString = ""
1701
1702     // Set up default context string and trigger phrases. This is overridden in places, sometimes just to keep
1703     // the existing non-standard descriptions and phrases. In some cases, the scenarios are asymmetric, as for
1704     // some jobs where the Debug configuration just does builds, no tests.
1705     //
1706     // Some configurations, like arm32/arm64, always use the exact scenario name as part of the context string.
1707     // This makes it possible to copy/paste the displayed context string as "@dotnet-bot test <context-string>"
1708     // to invoke the trigger. Any "fancy" context string makes that impossible, requiring the user to either 
1709     // remember the mapping from context string to trigger string, or use "@dotnet-bot help" to look it up.
1710
1711     if (architecture == 'armem') {
1712         assert os == 'Tizen'
1713         architecture = 'armel'
1714     }
1715
1716     switch (architecture) {
1717         case 'x64_arm64_altjit':
1718         case 'x86_arm_altjit':
1719             // TODO: for consistency, add "Build and Test" at end.
1720             contextString = "${os} ${architecture} ${configuration} ${scenario}"
1721             triggerString = "(?i).*test\\W+${os}\\W+${architecture}\\W+${configuration}\\W+${scenario}.*"
1722             break
1723
1724         case 'armel':
1725         case 'arm':
1726         case 'arm64':
1727             contextString = "${os} ${architecture} Cross ${configuration}"
1728             triggerString = "(?i).*test\\W+${os}\\W+${architecture}\\W+Cross\\W+${configuration}"
1729
1730             if (scenario == 'innerloop') {
1731                 contextString += " Innerloop"
1732                 triggerString += "\\W+Innerloop"
1733             }
1734             else {
1735                 contextString += " ${scenario}"
1736                 triggerString += "\\W+${scenario}"
1737             }
1738
1739             if (scenario == 'pmi_asm_diffs') {
1740                 // Don't add the "Build and Test" part
1741             }
1742             else if (configuration == 'Debug') {
1743                 contextString += " Build"
1744                 triggerString += "\\W+Build"
1745             }
1746             else {
1747                 contextString += " Build and Test"
1748                 triggerString += "\\W+Build and Test"
1749             }
1750
1751             triggerString += ".*"
1752             break
1753
1754         default:
1755             scenarioString = getScenarioDisplayString(scenario)
1756             contextString = "${os} ${architecture} ${configuration} ${scenarioString}"
1757             triggerString = "(?i).*test\\W+${os}\\W+${architecture}\\W+${configuration}"
1758
1759             switch (scenario) {
1760                 case 'normal':
1761                     triggerString += "\\W+Build and Test.*"
1762                     break
1763
1764                 case 'corefx_innerloop': // maintain this asymmetry
1765                     triggerString += "\\W+CoreFX Tests.*"
1766                     break
1767
1768                 default:
1769                     triggerString += "\\W+${scenario}.*"
1770                     break
1771             }
1772
1773             triggerString += ".*"
1774             break
1775     }
1776
1777     // Now determine what kind of trigger this job needs, if any. Any job should be triggerable, except for
1778     // non-flow jobs that are only used as part of flow jobs.
1779
1780     switch (architecture) {
1781         case 'x64': // editor brace matching: {
1782             if (scenario == 'formatting') {
1783                 assert configuration == 'Checked'
1784                 if (os == 'Windows_NT' || os == 'Ubuntu') {
1785                     isDefaultTrigger = true
1786                     contextString = "${os} ${architecture} Formatting"
1787                 }
1788                 break
1789             }
1790
1791             if (scenario == 'pmi_asm_diffs') {
1792                 // Everything is already set.
1793                 // No default triggers.
1794                 break
1795             }
1796
1797             switch (os) {
1798                 // OpenSUSE, Debian & RedHat get trigger phrases for pri 0 build, and pri 1 build & test
1799                 case 'Debian8.4':
1800                 case 'RHEL7.2':
1801                     if (scenario == 'innerloop') {
1802                         assert !isFlowJob
1803                         contextString = "${os} ${architecture} ${configuration} Innerloop Build"
1804                         isDefaultTrigger = true
1805                         break
1806                     }
1807
1808                     // fall through
1809
1810                 case 'Fedora24':
1811                 case 'Ubuntu16.04':
1812                 case 'Ubuntu16.10':
1813                     assert !isFlowJob
1814                     assert scenario != 'innerloop'
1815                     contextString = "${os} ${architecture} ${configuration} Build"
1816                     triggerString = "(?i).*test\\W+${os}\\W+${architecture}\\W+${configuration}\\W+Build.*"
1817                     break
1818
1819                 case 'Ubuntu':
1820                     if (scenario == 'illink') {
1821                         break
1822                     }
1823                     else if (scenario == 'corefx_innerloop') {
1824                         if (configuration == 'Checked') {
1825                             isDefaultTrigger = true
1826                         }
1827                         break
1828                     }
1829
1830                     // fall through
1831
1832                 case 'OSX10.12':
1833                     // Triggers on the non-flow jobs aren't necessary here
1834                     // Corefx testing uses non-flow jobs.
1835                     if (!isFlowJob && !isCoreFxScenario(scenario)) {
1836                         needsTrigger = false
1837                         break
1838                     }
1839                     switch (scenario) {
1840                         case 'innerloop':
1841                             isDefaultTrigger = true
1842                             break
1843
1844                         case 'no_tiered_compilation_innerloop':
1845                             if (os == 'Ubuntu') {
1846                                 isDefaultTrigger = true
1847                             }
1848                             break
1849
1850                         default:
1851                             break
1852                     }
1853                     break
1854
1855                 case 'CentOS7.1':
1856                     switch (scenario) {
1857                         case 'innerloop':
1858                             // CentOS uses checked for default PR tests while debug is build only
1859                             if (configuration == 'Debug') {
1860                                 isDefaultTrigger = true
1861                                 contextString = "${os} ${architecture} ${configuration} Innerloop Build"
1862                                 break
1863                             }
1864                             
1865                             // Make sure this is a flow job to get build and test.
1866                             if (!isFlowJob) {
1867                                 needsTrigger = false
1868                                 break
1869                             }
1870
1871                             if (configuration == 'Checked') {
1872                                 assert job.name.contains("flow")
1873                                 isDefaultTrigger = true
1874                                 contextString = "${os} ${architecture} ${configuration} Innerloop Build and Test"
1875                             }
1876                             break
1877
1878                         case 'normal':
1879                             // Make sure this is a flow job to get build and test.
1880                             if (!isFlowJob) {
1881                                 needsTrigger = false
1882                                 break
1883                             }
1884                             break
1885
1886                         default:
1887                             break
1888                     }
1889                     break
1890
1891                 case 'Windows_NT':
1892                     switch (scenario) {
1893                         case 'innerloop':
1894                         case 'no_tiered_compilation_innerloop':
1895                             isDefaultTrigger = true
1896                             break
1897
1898                         case 'corefx_innerloop':
1899                             if (configuration == 'Checked' || configuration == 'Release') {
1900                                 isDefaultTrigger = true
1901                             }
1902                             break
1903
1904                         default:
1905                             break
1906                     }
1907                     break
1908
1909                 default:
1910                     println("Unknown os: ${os}");
1911                     assert false
1912                     break
1913
1914             } // switch (os)
1915
1916             break
1917         // editor brace matching: }
1918
1919         case 'armel': // editor brace matching: {
1920             job.with {
1921                 publishers {
1922                     azureVMAgentPostBuildAction {
1923                         agentPostBuildAction('Delete agent if the build was not successful (when idle).')
1924                     }
1925                 }
1926             }
1927
1928             switch (os) {
1929                 case 'Tizen':
1930                     if (scenario == 'innerloop') {
1931                         if (configuration == 'Checked') {
1932                             isDefaultTrigger = true
1933                         }
1934                     }
1935                     break
1936             }
1937
1938             break
1939         // editor brace matching: }
1940
1941         case 'arm':
1942         case 'arm64': // editor brace matching: {
1943
1944             switch (os) {
1945                 case 'Ubuntu':
1946                 case 'Ubuntu16.04':
1947
1948                     // Triggers on the non-flow jobs aren't necessary
1949                     if (!isFlowJob) {
1950                         needsTrigger = false
1951                         break
1952                     }
1953
1954                     switch (scenario) {
1955                         case 'innerloop':
1956                         case 'no_tiered_compilation_innerloop':
1957                             if (configuration == 'Checked') {
1958                                 isDefaultTrigger = true
1959                             }
1960                             break
1961                          case 'crossgen_comparison':
1962                             if (os == 'Ubuntu' && architecture == 'arm' && (configuration == 'Checked' || configuration == 'Release')) {
1963                                 isDefaultTrigger = true
1964                             }
1965                             break
1966                     }
1967                     break
1968
1969                 case 'Windows_NT':
1970                     assert isArmWindowsScenario(scenario)
1971
1972                     // For Debug normal/innerloop scenario, we don't do test runs, so we don't use flow jobs. That means we need a trigger for
1973                     // the non-flow Build job. All others need a trigger on the flow job.
1974                     def needsFlowJobTrigger = !(isNormalOrInnerloop && (configuration == 'Debug'))
1975                     if (isFlowJob != needsFlowJobTrigger) {
1976                         needsTrigger = false
1977                         break
1978                     }
1979
1980                     switch (scenario) {
1981                         case 'innerloop':
1982                             if (configuration == 'Debug') {
1983                                 // Add default PR trigger for Windows arm64 Debug builds. This is a build only -- no tests are run --
1984                                 // so the private test hardware is not used. Thus, it can be run by all users, not just arm64Users.
1985                                 // People in arm64Users will get both this and the Checked Build and Test job.
1986                                 isDefaultTrigger = true
1987                             } else if (configuration == 'Checked') {
1988                                 isDefaultTrigger = true
1989                                 isArm64PrivateJob = true
1990                             }
1991                             break
1992                         default:
1993                             isArm64PrivateJob = true
1994                             break
1995                     }
1996                     break
1997                 default:
1998                     println("NYI os: ${os}");
1999                     assert false
2000                     break
2001             }
2002             break
2003
2004         // editor brace matching: }
2005         case 'x86': // editor brace matching: {
2006             assert ((os == 'Windows_NT') || ((os == 'Ubuntu') && isNormalOrInnerloop))
2007             if (os == 'Ubuntu') {
2008                 // Triggers on the non-flow jobs aren't necessary here
2009                 if (!isFlowJob) {
2010                     needsTrigger = false
2011                     break
2012                 }
2013                 
2014                 // on-demand only for ubuntu x86
2015                 contextString = "${os} ${architecture} ${configuration} Build"
2016                 triggerString = "(?i).*test\\W+${os}\\W+${architecture}\\W+${configuration}.*"
2017                 break
2018             }
2019             switch (scenario) {
2020                 case 'innerloop':
2021                 case 'no_tiered_compilation_innerloop':
2022                     isDefaultTrigger = true
2023                     break
2024                 default:
2025                     break
2026             }
2027             break
2028
2029         // editor brace matching: }
2030         case 'x64_arm64_altjit':
2031         case 'x86_arm_altjit':
2032             // Everything default
2033             break
2034
2035         default:
2036             println("Unknown architecture: ${architecture}");
2037             assert false
2038             break
2039     }
2040
2041     if (needsTrigger) {
2042         if (isArm64PrivateJob) {
2043             if (isDefaultTrigger) {
2044                 Utilities.addDefaultPrivateGithubPRTriggerForBranch(job, branch, contextString, null, arm64Users)
2045             }
2046             else {
2047                 Utilities.addPrivateGithubPRTriggerForBranch(job, branch, contextString, triggerString, null, arm64Users)
2048             }
2049         }
2050         else {
2051             if (isDefaultTrigger) {
2052                 Utilities.addGithubPRTriggerForBranch(job, branch, contextString)
2053             }
2054             else {
2055                 Utilities.addGithubPRTriggerForBranch(job, branch, contextString, triggerString)
2056             }
2057         }
2058     }
2059 }
2060
2061 def static calculateBuildCommands(def newJob, def scenario, def branch, def isPR, def architecture, def configuration, def os, def isBuildOnly) {
2062     def buildCommands = []
2063     def osGroup = getOSGroup(os)
2064     def lowerConfiguration = configuration.toLowerCase()
2065
2066     // Which set of tests to build? Innerloop tests build Pri-0.
2067     // Currently, we only generate asm diffs on Pri-0 tests, if we generate asm diffs on tests at all.
2068     // CoreFX testing skipts building tests altogether (done below).
2069     // All other scenarios build Pri-1 tests.
2070     def priority = '1'
2071     if (isInnerloopTestScenario(scenario)) {
2072         priority = '0'
2073     }
2074
2075     def doCoreFxTesting = isCoreFxScenario(scenario)
2076
2077     def buildCoreclrTests = true
2078     if (doCoreFxTesting || (scenario == 'pmi_asm_diffs')) {
2079         // These scenarios don't need the coreclr tests build.
2080         buildCoreclrTests = false
2081     }
2082
2083     // Calculate the build steps, archival, and xunit results
2084     switch (os) {
2085         case 'Windows_NT': // editor brace matching: {
2086             switch (architecture) {
2087                 case 'x64':
2088                 case 'x86':
2089                 case 'x86_arm_altjit':
2090                 case 'x64_arm64_altjit':
2091                     def arch = architecture
2092                     def buildOpts = ''
2093                     if (architecture == 'x86_arm_altjit') {
2094                         arch = 'x86'
2095                     }
2096                     else if (architecture == 'x64_arm64_altjit') {
2097                         arch = 'x64'
2098                     }
2099
2100                     if (scenario == 'formatting') {
2101                         buildCommands += "python -u tests\\scripts\\format.py -c %WORKSPACE% -o Windows_NT -a ${arch}"
2102                         Utilities.addArchival(newJob, "format.patch", "", true, false)
2103                         break
2104                     }
2105
2106                     if (scenario == 'illink') {
2107                         buildCommands += "tests\\scripts\\build_illink.cmd clone ${arch}"
2108                     }
2109
2110                     // If it is a release build for Windows, ensure PGO is used, else fail the build.
2111                     if ((lowerConfiguration == 'release') &&
2112                         (scenario in Constants.basicScenarios) &&
2113                         (architecture != 'x86_arm_altjit') &&
2114                         (architecture != 'x64_arm64_altjit')) {
2115
2116                         buildOpts += ' -enforcepgo'
2117                     }
2118
2119                     if (buildCoreclrTests) {
2120                         buildOpts += " -priority=${priority}"
2121                     } else {
2122                         buildOpts += ' skiptests';
2123                     }
2124
2125                     // Set __TestIntermediateDir to something short. If __TestIntermediateDir is already set, build-test.cmd will
2126                     // output test binaries to that directory. If it is not set, the binaries are sent to a default directory whose name is about
2127                     // 35 characters long.
2128
2129                     buildCommands += "set __TestIntermediateDir=int&&build.cmd ${lowerConfiguration} ${arch} ${buildOpts}"
2130
2131                     if (scenario == 'pmi_asm_diffs') {
2132                         // Now, generate the layout. We don't have any tests, but we need to restore the packages before calling runtest.cmd.
2133                         // Call build-test.cmd to do this. It will do a little more than we need, but that's ok.
2134                         buildCommands += "build-test.cmd ${lowerConfiguration} ${arch} skipmanaged skipnative"
2135                         buildCommands += "tests\\runtest.cmd ${lowerConfiguration} ${arch} GenerateLayoutOnly"
2136
2137                         // TODO: Add -target_branch and -commit_hash arguments based on GitHub variables.
2138                         buildCommands += "python -u %WORKSPACE%\\tests\\scripts\\run-pmi-diffs.py -arch ${arch} -ci_arch ${architecture} -build_type ${configuration}"
2139
2140                         // ZIP up the asm
2141                         buildCommands += "powershell -NoProfile -Command \"Add-Type -Assembly 'System.IO.Compression.FileSystem'; [System.IO.Compression.ZipFile]::CreateFromDirectory('_\\pmi\\asm', '.\\dasm.${os}.${architecture}.${configuration}.zip')\"";
2142
2143                         // Archive the asm
2144                         Utilities.addArchival(newJob, "dasm.${os}.${architecture}.${configuration}.zip")
2145                         break
2146                     }
2147
2148                     if (!isBuildOnly) {
2149                         def runtestArguments = ''
2150                         def testOpts = 'collectdumps'
2151
2152                         if (isR2RScenario(scenario)) {
2153
2154                             // If this is a ReadyToRun scenario, pass 'crossgen' or 'crossgenaltjit'
2155                             // to cause framework assemblies to be crossgen'ed. Pass 'runcrossgentests'
2156                             // to cause the tests to be crossgen'ed.
2157
2158                             if ((architecture == 'x86_arm_altjit') || (architecture == 'x64_arm64_altjit')) {
2159                                 testOpts += ' crossgenaltjit protononjit.dll'
2160                             } else {
2161                                 testOpts += ' crossgen'
2162                             }
2163
2164                             testOpts += ' runcrossgentests'
2165                         }
2166                         else if (scenario == 'jitdiff') {
2167                             testOpts += ' jitdisasm crossgen'
2168                         }
2169                         else if (scenario == 'ilrt') {
2170                             testOpts += ' ilasmroundtrip'
2171                         }
2172                         else if (isLongGc(scenario)) {
2173                             testOpts += " ${scenario} sequential"
2174                         }
2175                         else if (scenario == 'standalone_gc') {
2176                             testOpts += ' gcname clrgc.dll'
2177                         }
2178                         else if (scenario == 'illink') {
2179                             testOpts += " link %WORKSPACE%\\linker\\linker\\bin\\netcore_Release\\netcoreapp2.0\\win10-${arch}\\publish\\illink.exe"
2180                         }
2181
2182                         // Default per-test timeout is 10 minutes. For stress modes and Debug scenarios, increase this
2183                         // to 30 minutes (30 * 60 * 1000 = 180000). The "timeout" argument to runtest.cmd sets this, by
2184                         // taking a timeout value in milliseconds. (Note that it sets the __TestTimeout environment variable,
2185                         // which is read by the xunit harness.)
2186                         if (isJitStressScenario(scenario) || isR2RStressScenario(scenario) || (lowerConfiguration == 'debug'))
2187                         {
2188                             def timeout = 1800000
2189                             testOpts += " timeout ${timeout}"
2190                         }
2191
2192                         // If we are running a stress mode, we should write out the set of key
2193                         // value env pairs to a file at this point and then we'll pass that to runtest.cmd
2194
2195                         def envScriptPath = ''
2196                         if (isJitStressScenario(scenario) || isR2RStressScenario(scenario)) {
2197                             def buildCommandsStr = ''
2198                             envScriptPath = "%WORKSPACE%\\SetStressModes.bat"
2199                             buildCommandsStr += envScriptCreate(os, envScriptPath)
2200
2201                             if (isJitStressScenario(scenario)) {
2202                                 buildCommandsStr += envScriptSetStressModeVariables(os, Constants.jitStressModeScenarios[scenario], envScriptPath)
2203                             }
2204                             else if (isR2RStressScenario(scenario)) {
2205                                 buildCommandsStr += envScriptSetStressModeVariables(os, Constants.r2rStressScenarios[scenario], envScriptPath)
2206                             }
2207
2208                             if (architecture == 'x86_arm_altjit') {
2209                                 buildCommandsStr += envScriptAppendExistingScript(os, "%WORKSPACE%\\tests\\x86_arm_altjit.cmd", envScriptPath)
2210                                 testOpts += " altjitarch arm"
2211                             }
2212                             else if (architecture == 'x64_arm64_altjit') {
2213                                 buildCommandsStr += envScriptAppendExistingScript(os, "%WORKSPACE%\\tests\\x64_arm64_altjit.cmd", envScriptPath)
2214                                 testOpts += " altjitarch arm64"
2215                             }
2216
2217                             envScriptFinalize(os, envScriptPath)
2218
2219                             // Note that buildCommands is an array of individually executed commands; we want all the commands used to 
2220                             // create the SetStressModes.bat script to be executed together, hence we accumulate them as strings
2221                             // into a single script.
2222                             buildCommands += buildCommandsStr
2223                         }
2224                         else if (architecture == 'x86_arm_altjit') {
2225                             envScriptPath = "%WORKSPACE%\\tests\\x86_arm_altjit.cmd"
2226                             testOpts += " altjitarch arm"
2227                         }
2228                         else if (architecture == 'x64_arm64_altjit') {
2229                             envScriptPath = "%WORKSPACE%\\tests\\x64_arm64_altjit.cmd"
2230                             testOpts += " altjitarch arm64"
2231                         }
2232                         if (envScriptPath != '') {
2233                             testOpts += " TestEnv ${envScriptPath}"
2234                         }
2235
2236                         runtestArguments = "${lowerConfiguration} ${arch} ${testOpts}"
2237
2238                         if (doCoreFxTesting) {
2239                             if (scenario == 'corefx_innerloop') {
2240                                 // Create CORE_ROOT and testhost
2241                                 buildCommands += "build-test.cmd ${lowerConfiguration} ${arch} buildtesthostonly"                                
2242                                 buildCommands += "tests\\runtest.cmd ${runtestArguments} CoreFXTestsAll"
2243
2244                                 // Archive and process (only) the test results
2245                                 Utilities.addArchival(newJob, "bin/Logs/**/testResults.xml")
2246                                 Utilities.addXUnitDotNETResults(newJob, "bin/Logs/**/testResults.xml")
2247                             }
2248                             else {
2249                                 def workspaceRelativeFxRoot = "_/fx"
2250                                 def absoluteFxRoot = "%WORKSPACE%\\_\\fx"
2251                                 def fxBranch = getFxBranch(branch)
2252
2253                                 buildCommands += "python -u %WORKSPACE%\\tests\\scripts\\run-corefx-tests.py -arch ${arch} -ci_arch ${architecture} -build_type ${configuration} -fx_root ${absoluteFxRoot} -fx_branch ${fxBranch} -env_script ${envScriptPath}"
2254
2255                                 // Archive and process (only) the test results
2256                                 Utilities.addArchival(newJob, "${workspaceRelativeFxRoot}/artifacts/bin/**/testResults.xml")
2257                                 Utilities.addXUnitDotNETResults(newJob, "${workspaceRelativeFxRoot}/artifacts/bin/**/testResults.xml")
2258
2259                                 //Archive additional build stuff to diagnose why my attempt at fault injection isn't causing CI to fail
2260                                 Utilities.addArchival(newJob, "SetStressModes.bat", "", true, false)
2261                                 Utilities.addArchival(newJob, "${workspaceRelativeFxRoot}/artifacts/bin/testhost/**", "", true, false)
2262                             }
2263                         }
2264                         else if (isGcReliabilityFramework(scenario)) {
2265                             buildCommands += "tests\\runtest.cmd ${runtestArguments} GenerateLayoutOnly"
2266                             buildCommands += "tests\\scripts\\run-gc-reliability-framework.cmd ${arch} ${configuration}"
2267                         }
2268                         else {
2269                             buildCommands += "tests\\runtest.cmd ${runtestArguments}"
2270                         }
2271                     } // end if (!isBuildOnly)
2272
2273                     if (!doCoreFxTesting) {
2274                         // Run the rest of the build
2275                         // Build the mscorlib for the other OS's
2276                         buildCommands += "build.cmd ${lowerConfiguration} ${arch} linuxmscorlib"
2277                         buildCommands += "build.cmd ${lowerConfiguration} ${arch} osxmscorlib"
2278                        
2279                         if (arch == 'x64') {
2280                             buildCommands += "build.cmd ${lowerConfiguration} arm64 linuxmscorlib"
2281                         }
2282
2283                         // Zip up the tests directory so that we don't use so much space/time copying
2284                         // 10s of thousands of files around.
2285                         buildCommands += "powershell -NoProfile -Command \"Add-Type -Assembly 'System.IO.Compression.FileSystem'; [System.IO.Compression.ZipFile]::CreateFromDirectory('.\\bin\\tests\\${osGroup}.${arch}.${configuration}', '.\\bin\\tests\\tests.zip')\"";
2286
2287                         if (!isJitStressScenario(scenario)) {
2288                             // For Windows, pull full test results and test drops for x86/x64.
2289                             // No need to pull for stress mode scenarios (downstream builds use the default scenario)
2290                             Utilities.addArchival(newJob, "bin/Product/**,bin/tests/tests.zip", "bin/Product/**/.nuget/**")
2291                         }
2292
2293                         if (scenario == 'jitdiff') {
2294                             // retrieve jit-dasm output for base commit, and run jit-diff
2295                             if (!isBuildOnly) {
2296                                 // if this is a build only job, we want to keep the default (build) artifacts for the flow job
2297                                 Utilities.addArchival(newJob, "bin/tests/${osGroup}.${arch}.${configuration}/dasm/**")
2298                             }
2299                         }
2300
2301                         if (!isBuildOnly) {
2302                             Utilities.addXUnitDotNETResults(newJob, 'bin/**/TestRun*.xml', true)
2303                         }
2304                     }
2305                     break
2306                 case 'arm':
2307                 case 'arm64':
2308                     assert isArmWindowsScenario(scenario)
2309
2310                     def buildOpts = ''
2311
2312                     if (buildCoreclrTests) {
2313                         buildOpts += " -priority=${priority}"
2314                     } else {
2315                         buildOpts += ' skiptests'
2316                     }
2317
2318                     // This is now a build only job. Do not run tests. Use the flow job.
2319                     buildCommands += "set __TestIntermediateDir=int&&build.cmd ${lowerConfiguration} ${architecture} ${buildOpts}"
2320
2321                     if (doCoreFxTesting) {
2322                         assert isBuildOnly
2323
2324                         // Set the stress mode variables; this is incorporated into the generated CoreFx RunTests.cmd files.
2325                         def envScriptPath = ''
2326                         def buildCommandsStr = ''
2327                         envScriptPath = "%WORKSPACE%\\SetStressModes.bat"
2328                         buildCommandsStr += envScriptCreate(os, envScriptPath)
2329                         buildCommandsStr += envScriptSetStressModeVariables(os, Constants.jitStressModeScenarios[scenario], envScriptPath)
2330                         envScriptFinalize(os, envScriptPath)
2331                         buildCommands += buildCommandsStr
2332
2333                         def workspaceRelativeFxRootLinux = "_/fx"
2334                         def workspaceRelativeFxRootWin = "_\\fx"
2335                         def absoluteFxRoot = "%WORKSPACE%\\_\\fx"
2336                         def fxBranch = getFxBranch(branch)
2337
2338                         buildCommands += "python -u %WORKSPACE%\\tests\\scripts\\run-corefx-tests.py -arch ${architecture} -ci_arch ${architecture} -build_type ${configuration} -fx_root ${absoluteFxRoot} -fx_branch ${fxBranch} -env_script ${envScriptPath} -no_run_tests"
2339
2340                         // Zip up the CoreFx runtime and tests. We don't need the CoreCLR binaries; they have been copied to the CoreFX tree.
2341                         buildCommands += "powershell -NoProfile -Command \"Add-Type -Assembly 'System.IO.Compression.FileSystem'; [System.IO.Compression.ZipFile]::CreateFromDirectory('${workspaceRelativeFxRootWin}\\artifacts\\bin\\testhost\\netcoreapp-Windows_NT-Release-${architecture}', '${workspaceRelativeFxRootWin}\\fxruntime.zip')\"";
2342                         buildCommands += "powershell -NoProfile -Command \"Add-Type -Assembly 'System.IO.Compression.FileSystem'; [System.IO.Compression.ZipFile]::CreateFromDirectory('${workspaceRelativeFxRootWin}\\artifacts\\bin\\tests', '${workspaceRelativeFxRootWin}\\fxtests.zip')\"";
2343
2344                         Utilities.addArchival(newJob, "${workspaceRelativeFxRootLinux}/fxruntime.zip")
2345                         Utilities.addArchival(newJob, "${workspaceRelativeFxRootLinux}/fxtests.zip")
2346                     } else {
2347                         // Zip up the tests directory so that we don't use so much space/time copying
2348                         // 10s of thousands of files around.
2349                         buildCommands += "powershell -NoProfile -Command \"Add-Type -Assembly 'System.IO.Compression.FileSystem'; [System.IO.Compression.ZipFile]::CreateFromDirectory('.\\bin\\tests\\${osGroup}.${architecture}.${configuration}', '.\\bin\\tests\\tests.zip')\"";
2350
2351                         // Add archival.
2352                         Utilities.addArchival(newJob, "bin/Product/**,bin/tests/tests.zip", "bin/Product/**/.nuget/**")
2353                     }
2354                     break
2355                 default:
2356                     println("Unknown architecture: ${architecture}");
2357                     assert false
2358                     break
2359             }
2360             break
2361         // end case 'Windows_NT'; editor brace matching: }
2362         case 'Ubuntu':
2363         case 'Ubuntu16.04':
2364         case 'Ubuntu16.10':
2365         case 'Debian8.4':
2366         case 'OSX10.12':
2367         case 'CentOS7.1':
2368         case 'RHEL7.2':
2369         case 'Tizen':
2370         case 'Fedora24': // editor brace matching: {
2371             switch (architecture) {
2372                 case 'x86':
2373                     if (os == 'Ubuntu') {
2374                         // build and PAL test
2375                         def dockerImage = getDockerImageName(architecture, os, true)
2376                         buildCommands += "docker run -i --rm -v \${WORKSPACE}:/opt/code -w /opt/code -e ROOTFS_DIR=/crossrootfs/x86 ${dockerImage} ./build.sh ${architecture} cross ${lowerConfiguration}"
2377                         dockerImage = getDockerImageName(architecture, os, false)
2378                         buildCommands += "docker run -i --rm -v \${WORKSPACE}:/opt/code -w /opt/code ${dockerImage} ./src/pal/tests/palsuite/runpaltests.sh /opt/code/bin/obj/${osGroup}.${architecture}.${configuration} /opt/code/bin/paltestout"
2379                         Utilities.addArchival(newJob, "bin/Product/**,bin/obj/*/tests/**/*.so", "bin/Product/**/.nuget/**")
2380                         Utilities.addXUnitDotNETResults(newJob, '**/pal_tests.xml')
2381                     }
2382                     break
2383
2384                 case 'x64':
2385                     if (scenario == 'formatting') {
2386                         buildCommands += "python tests/scripts/format.py -c \${WORKSPACE} -o Linux -a ${architecture}"
2387                         Utilities.addArchival(newJob, "format.patch", "", true, false)
2388                         break
2389                     }
2390
2391                     if (scenario == 'pmi_asm_diffs') {
2392                         buildCommands += "./build.sh ${lowerConfiguration} ${architecture} skiptests skipbuildpackages"
2393                         buildCommands += "./build-test.sh ${lowerConfiguration} ${architecture} generatelayoutonly"
2394
2395                         // TODO: Add -target_branch and -commit_hash arguments based on GitHub variables.
2396                         buildCommands += "python -u \${WORKSPACE}/tests/scripts/run-pmi-diffs.py -arch ${architecture} -ci_arch ${architecture} -build_type ${configuration}"
2397
2398                         // Archive the asm
2399                         buildCommands += "tar -czf dasm.${os}.${architecture}.${configuration}.tgz ./_/pmi/asm"
2400                         Utilities.addArchival(newJob, "dasm.${os}.${architecture}.${configuration}.tgz")
2401                         break
2402                     }
2403
2404                     if (scenario == 'illink') {
2405                         assert(os == 'Ubuntu')
2406                         buildCommands += "./tests/scripts/build_illink.sh --clone --arch=${architecture}"
2407                     }
2408
2409                     if (!doCoreFxTesting) {
2410                         // We run pal tests on all OS but generate mscorlib (and thus, nuget packages)
2411                         // only on supported OS platforms.
2412                         def bootstrapRid = Utilities.getBoostrapPublishRid(os)
2413                         def bootstrapRidEnv = bootstrapRid != null ? "__PUBLISH_RID=${bootstrapRid} " : ''
2414
2415                         buildCommands += "${bootstrapRidEnv}./build.sh ${lowerConfiguration} ${architecture}"
2416
2417                         def testBuildOpts = ""
2418                         if (priority == '1') {
2419                             testBuildOpts = "priority1"
2420                         }
2421
2422                         buildCommands += "./build-test.sh ${lowerConfiguration} ${architecture} ${testBuildOpts}"
2423                         buildCommands += "src/pal/tests/palsuite/runpaltests.sh \${WORKSPACE}/bin/obj/${osGroup}.${architecture}.${configuration} \${WORKSPACE}/bin/paltestout"
2424
2425                         // Archive the bin/tests folder for *_tst jobs
2426                         def testArtifactsTgzFileName = getTestArtifactsTgzFileName(osGroup, architecture, configuration)
2427                         buildCommands += "tar -czf ${testArtifactsTgzFileName} bin/tests/${osGroup}.${architecture}.${configuration}"
2428                         Utilities.addArchival(newJob, "${testArtifactsTgzFileName}", "")
2429                         // And pal tests
2430                         Utilities.addXUnitDotNETResults(newJob, '**/pal_tests.xml')
2431                     }
2432                     else {
2433                         if (scenario == 'corefx_innerloop') {
2434                             assert os == 'Ubuntu' || 'OSX10.12'
2435                             assert architecture == 'x64'
2436
2437                             buildCommands += "./build.sh ${lowerConfiguration} ${architecture} skiptests"
2438                             buildCommands += "./build-test.sh ${lowerConfiguration} ${architecture} generatetesthostonly"
2439                             buildCommands += "./tests/runtest.sh ${lowerConfiguration} --corefxtestsall --testHostDir=\${WORKSPACE}/bin/tests/${osGroup}.${architecture}.${configuration}/testhost/ --coreclr-src=\${WORKSPACE}"
2440                             
2441                             break
2442                             // Archive and process (only) the test results
2443                             Utilities.addArchival(newJob, "bin/Logs/**/testResults.xml")
2444                             Utilities.addXUnitDotNETResults(newJob, "bin/Logs/**/testResults.xml")
2445                         }
2446                         else {
2447                             // Corefx stress testing
2448                             assert os == 'Ubuntu'
2449                             assert architecture == 'x64'
2450                             assert lowerConfiguration == 'checked'
2451                             assert isJitStressScenario(scenario)
2452
2453                             // Build coreclr
2454                             buildCommands += "./build.sh ${lowerConfiguration} ${architecture}"
2455
2456                             def scriptFileName = "\$WORKSPACE/set_stress_test_env.sh"
2457
2458                             def envScriptCmds = envScriptCreate(os, scriptFileName)
2459                             envScriptCmds += envScriptSetStressModeVariables(os, Constants.jitStressModeScenarios[scenario], scriptFileName)
2460                             envScriptCmds += envScriptFinalize(os, scriptFileName)
2461                             buildCommands += envScriptCmds
2462
2463                             // Build and text corefx
2464                             def workspaceRelativeFxRoot = "_/fx"
2465                             def absoluteFxRoot = "\$WORKSPACE/${workspaceRelativeFxRoot}"
2466                             def fxBranch = getFxBranch(branch)
2467
2468                             buildCommands += "python -u \$WORKSPACE/tests/scripts/run-corefx-tests.py -arch ${architecture} -ci_arch ${architecture} -build_type ${configuration} -fx_root ${absoluteFxRoot} -fx_branch ${fxBranch} -env_script ${scriptFileName}"
2469
2470                             // Archive and process (only) the test results
2471                             Utilities.addArchival(newJob, "${workspaceRelativeFxRoot}/artifacts/bin/**/testResults.xml")
2472                             Utilities.addXUnitDotNETResults(newJob, "${workspaceRelativeFxRoot}/artifacts/bin/**/testResults.xml")
2473                         }
2474                     }
2475                     break
2476                 case 'armem':
2477                     // Emulator cross builds for ARM runs on Tizen currently
2478                     assert os == 'Tizen'
2479
2480                     def arm_abi = "armel"
2481                     def linuxCodeName = "tizen"
2482
2483                     // Unzip the Windows test binaries first. Exit with 0
2484                     buildCommands += "unzip -q -o ./bin/tests/tests.zip -d ./bin/tests/Windows_NT.x64.${configuration} || exit 0"
2485
2486                     // Unpack the corefx binaries
2487                     buildCommands += "mkdir ./bin/CoreFxBinDir"
2488                     buildCommands += "tar -xf ./artifacts/bin/build.tar.gz -C ./bin/CoreFxBinDir"
2489
2490                     // Call the ARM CI script to cross build and test using docker
2491                     buildCommands += """./tests/scripts/arm32_ci_script.sh \\
2492                     --mode=docker \\
2493                     --${arm_abi} \\
2494                     --linuxCodeName=${linuxCodeName} \\
2495                     --buildConfig=${lowerConfiguration} \\
2496                     --testRootDir=./bin/tests/Windows_NT.x64.${configuration} \\
2497                     --coreFxBinDir=./bin/CoreFxBinDir \\
2498                     --testDirFile=./tests/testsRunningInsideARM.txt"""
2499
2500                     // Basic archiving of the build, no pal tests
2501                     Utilities.addArchival(newJob, "bin/Product/**,bin/obj/*/tests/**/*.dylib,bin/obj/*/tests/**/*.so", "bin/Product/**/.nuget/**")
2502                     break
2503                 case 'arm64':
2504                 case 'arm':
2505                     // Non-Windows ARM cross builds on hardware run on Ubuntu only
2506                     assert (os == 'Ubuntu') || (os == 'Ubuntu16.04')
2507
2508                     // Add some useful information to the log file. Ignore return codes.
2509                     buildCommands += "uname -a || true"
2510
2511                     // Cross build the Ubuntu/arm product using docker with a docker image that contains the correct
2512                     // Ubuntu cross-compilation toolset (running on a Ubuntu x64 host).
2513                     // For CoreFX testing, we only need the product build; we don't need to generate the layouts. The product
2514                     // build is then copied into the corefx layout by the run-corefx-test.py script. For CoreFX testing, we
2515                     // ZIP up the generated CoreFX runtime and tests.
2516
2517                     def dockerImage = getDockerImageName(architecture, os, true)
2518                     def dockerCmd = "docker run -i --rm -v \${WORKSPACE}:\${WORKSPACE} -w \${WORKSPACE} -e ROOTFS_DIR=/crossrootfs/${architecture} ${dockerImage} "
2519
2520                     buildCommands += "${dockerCmd}\${WORKSPACE}/build.sh ${lowerConfiguration} ${architecture} cross"
2521
2522                     if (doCoreFxTesting) {
2523                         def scriptFileName = "\$WORKSPACE/set_stress_test_env.sh"
2524
2525                         def envScriptCmds = envScriptCreate(os, scriptFileName)
2526                         envScriptCmds += envScriptSetStressModeVariables(os, Constants.jitStressModeScenarios[scenario], scriptFileName)
2527                         envScriptCmds += envScriptFinalize(os, scriptFileName)
2528                         buildCommands += envScriptCmds
2529
2530                         // Build and text corefx
2531                         def workspaceRelativeFxRootLinux = "_/fx"
2532                         def absoluteFxRoot = "\$WORKSPACE/${workspaceRelativeFxRootLinux}"
2533                         def fxBranch = getFxBranch(branch)
2534
2535                         buildCommands += "${dockerCmd}python -u \$WORKSPACE/tests/scripts/run-corefx-tests.py -arch ${architecture} -ci_arch ${architecture} -build_type ${configuration} -fx_root ${absoluteFxRoot} -fx_branch ${fxBranch} -env_script ${scriptFileName} -no_run_tests"
2536
2537                         // Docker creates files with root permission, so we need to zip in docker also, or else we'll get permission errors.
2538                         buildCommands += "${dockerCmd}zip -r ${workspaceRelativeFxRootLinux}/fxruntime.zip ${workspaceRelativeFxRootLinux}/artifacts/bin/testhost/netcoreapp-Linux-Release-${architecture}"
2539                         buildCommands += "${dockerCmd}zip -r ${workspaceRelativeFxRootLinux}/fxtests.zip ${workspaceRelativeFxRootLinux}/artifacts/bin/tests"
2540
2541                         Utilities.addArchival(newJob, "${workspaceRelativeFxRootLinux}/fxruntime.zip")
2542                         Utilities.addArchival(newJob, "${workspaceRelativeFxRootLinux}/fxtests.zip")
2543                     }
2544                     else if (isCrossGenComparisonScenario(scenario)) {
2545                         buildCommands += "${dockerCmd}\${WORKSPACE}/build-test.sh ${lowerConfiguration} ${architecture} cross generatelayoutonly"
2546
2547                         def workspaceRelativeProductBinDir = "bin/Product/${osGroup}.${architecture}.${configuration}"
2548                         def workspaceRelativeCoreLib = "${workspaceRelativeProductBinDir}/IL/System.Private.CoreLib.dll"
2549                         def workspaceRelativeCoreRootDir = "bin/tests/${osGroup}.${architecture}.${configuration}/Tests/Core_Root"
2550                         def workspaceRelativeCrossGenComparisonScript = "tests/scripts/crossgen_comparison.py"
2551                         def workspaceRelativeResultsDir = "_"
2552                         def workspaceRelativeArtifactsArchive = "${os}.${architecture}.${configuration}.${scenario}.zip"
2553                         def crossGenComparisonCmd = "python -u \${WORKSPACE}/${workspaceRelativeCrossGenComparisonScript} "
2554                         def crossArch = "x64"
2555                         def crossGenExecutable = "\${WORKSPACE}/${workspaceRelativeProductBinDir}/${crossArch}/crossgen"
2556                         def workspaceRelativeCrossArchResultDir = "${workspaceRelativeResultsDir}/${osGroup}.${crossArch}_${architecture}.${configuration}"
2557
2558                         buildCommands += "${dockerCmd}mkdir -p \${WORKSPACE}/${workspaceRelativeCrossArchResultDir}"
2559                         buildCommands += "${dockerCmd}${crossGenComparisonCmd}crossgen_corelib --crossgen ${crossGenExecutable} --il_corelib \${WORKSPACE}/${workspaceRelativeCoreLib} --result_dir \${WORKSPACE}/${workspaceRelativeCrossArchResultDir}"
2560                         buildCommands += "${dockerCmd}${crossGenComparisonCmd}crossgen_framework --crossgen ${crossGenExecutable} --core_root \${WORKSPACE}/${workspaceRelativeCoreRootDir} --result_dir \${WORKSPACE}/${workspaceRelativeCrossArchResultDir}"
2561
2562                         buildCommands += "${dockerCmd}zip -r ${workspaceRelativeArtifactsArchive} ${workspaceRelativeCoreLib} ${workspaceRelativeCoreRootDir} ${workspaceRelativeCrossGenComparisonScript} ${workspaceRelativeResultsDir}"
2563                         Utilities.addArchival(newJob, "${workspaceRelativeArtifactsArchive}")
2564                     }
2565                     else if (scenario == 'pmi_asm_diffs') {
2566                         buildCommands += "${dockerCmd}\${WORKSPACE}/build-test.sh ${lowerConfiguration} ${architecture} cross generatelayoutonly"
2567
2568                         // Pass `--skip_diffs` -- the actual diffs will be done on an arm machine in the test job. This is the build job.
2569                         // TODO: Add -target_branch and -commit_hash arguments based on GitHub variables.
2570                         buildCommands += "python -u \${WORKSPACE}/tests/scripts/run-pmi-diffs.py -arch ${architecture} -ci_arch ${architecture} -build_type ${configuration} --skip_diffs"
2571
2572                         // ZIP what we created.
2573                         buildCommands += "zip -r product.${os}.${architecture}.${lowerConfiguration}.zip ./bin/Product/Linux.${architecture}.${configuration}"
2574                         buildCommands += "zip -r product.baseline.${os}.${architecture}.${lowerConfiguration}.zip ./_/pmi/base/bin/Product/Linux.${architecture}.${configuration}"
2575                         buildCommands += "zip -r coreroot.${os}.${architecture}.${lowerConfiguration}.zip ./bin/tests/Linux.${architecture}.${configuration}/Tests/Core_Root"
2576                         buildCommands += "zip -r coreroot.baseline.${os}.${architecture}.${lowerConfiguration}.zip ./_/pmi/base/bin/tests/Linux.${architecture}.${configuration}/Tests/Core_Root"
2577
2578                         // Archive the built artifacts
2579                         Utilities.addArchival(newJob, "product.${os}.${architecture}.${lowerConfiguration}.zip,product.baseline.${os}.${architecture}.${lowerConfiguration}.zip,coreroot.${os}.${architecture}.${lowerConfiguration}.zip,coreroot.baseline.${os}.${architecture}.${lowerConfiguration}.zip")
2580                     }
2581                     else {
2582                         // Then, using the same docker image, build the tests and generate the CORE_ROOT layout.
2583
2584                         def testBuildOpts = ""
2585                         if (priority == '1') {
2586                             testBuildOpts = "priority1"
2587                         }
2588
2589                         buildCommands += "${dockerCmd}\${WORKSPACE}/build-test.sh ${lowerConfiguration} ${architecture} cross ${testBuildOpts}"
2590
2591                         // ZIP up the built tests (including CORE_ROOT and native test components copied to the CORE_ROOT) for the test job (created in the flow job code)
2592                         def testArtifactsTgzFileName = getTestArtifactsTgzFileName(osGroup, architecture, configuration)
2593                         buildCommands += "tar -czf ${testArtifactsTgzFileName} bin/tests/${osGroup}.${architecture}.${configuration}"
2594
2595                         Utilities.addArchival(newJob, "${testArtifactsTgzFileName}", "")
2596                     }
2597
2598                     // Archive the build logs from both product and test builds.
2599                     Utilities.addArchival(newJob, "bin/Logs/*.log,bin/Logs/*.wrn,bin/Logs/*.err", "")
2600
2601                     // We need to clean up the build machines; the docker build leaves newly built files with root permission, which
2602                     // the cleanup task in Jenkins can't remove.
2603                     newJob.with {
2604                         publishers {
2605                             azureVMAgentPostBuildAction {
2606                                 agentPostBuildAction('Delete agent after build execution (when idle).')
2607                             }
2608                         }
2609                     }
2610                     break
2611                 default:
2612                     println("Unknown architecture: ${architecture}");
2613                     assert false
2614                     break
2615             }
2616             break
2617         // editor brace matching: }
2618         default:
2619             println("Unknown os: ${os}");
2620             assert false
2621             break
2622     } // os
2623
2624     return buildCommands
2625 }
2626
2627 // Determine if we should generate a job for the given parameters. This is for non-flow jobs: either build and test, or build only.
2628 // Returns true if the job should be generated.
2629 def static shouldGenerateJob(def scenario, def isPR, def architecture, def configuration, def os, def isBuildOnly)
2630 {
2631     // The various "innerloop" jobs are only available as PR triggered.
2632
2633     if (!isPR) {
2634         if (isInnerloopTestScenario(scenario)) {
2635             return false
2636         }
2637
2638         if (scenario == 'corefx_innerloop') {
2639             return false
2640         }
2641     }
2642
2643     // Tizen is only supported for armem architecture
2644     if (os == 'Tizen' && architecture != 'armem') {
2645         return false
2646     }
2647
2648     // Filter based on architecture.
2649
2650     switch (architecture) {
2651         case 'arm':
2652             if ((os != 'Windows_NT') && (os != 'Ubuntu')) {
2653                 return false
2654             }
2655             break
2656         case 'arm64':
2657             if ((os != 'Windows_NT') && (os != 'Ubuntu16.04')) {
2658                 return false
2659             }
2660             break
2661         case 'armem':
2662             if (os != 'Tizen') {
2663                 return false
2664             }
2665             break
2666         case 'x86_arm_altjit':
2667         case 'x64_arm64_altjit':
2668             if (os != 'Windows_NT') {
2669                 return false
2670             }
2671             break
2672         case 'x86':
2673             if ((os != 'Windows_NT') && (os != 'Ubuntu')) {
2674                 return false
2675             }
2676             break
2677         case 'x64':
2678             // Everything implemented
2679             break
2680         default:
2681             println("Unknown architecture: ${architecture}")
2682             assert false
2683             break
2684     }
2685
2686     // Which (Windows) build only jobs are required?
2687
2688     def isNormalOrInnerloop = (scenario == 'innerloop' || scenario == 'normal')
2689
2690     if (isBuildOnly) {
2691         switch (architecture) {
2692             case 'arm':
2693             case 'arm64':
2694                 // We use build only jobs for Windows arm/arm64 cross-compilation corefx testing, so we need to generate builds for that.
2695                 if (!isCoreFxScenario(scenario)) {
2696                     return false
2697                 }
2698                 break
2699             case 'x64':
2700             case 'x86':
2701                 if (!isNormalOrInnerloop) {
2702                     return false
2703                 }
2704                 break
2705             default:
2706                 return false
2707         }
2708     }
2709
2710     // Filter based on scenario.
2711
2712     if (isJitStressScenario(scenario)) {
2713         if (configuration != 'Checked') {
2714             return false
2715         }
2716
2717         def isEnabledOS = (os == 'Windows_NT') ||
2718                           (os == 'Ubuntu' && (architecture == 'x64') && isCoreFxScenario(scenario)) ||
2719                           (os == 'Ubuntu' && architecture == 'arm') ||
2720                           (os == 'Ubuntu16.04' && architecture == 'arm64')
2721         if (!isEnabledOS) {
2722             return false
2723         }
2724
2725         switch (architecture) {
2726             case 'x64':
2727             case 'x86_arm_altjit':
2728             case 'x64_arm64_altjit':
2729                 break
2730
2731             case 'x86':
2732                 // x86 ubuntu: no stress modes
2733                 if (os == 'Ubuntu') {
2734                     return false
2735                 }
2736                 break
2737
2738             case 'arm':
2739             case 'arm64':
2740                 // We use build only jobs for Windows arm/arm64 cross-compilation corefx testing, so we need to generate builds for that.
2741                 // No "regular" Windows arm corefx jobs, e.g.
2742                 // For Ubuntu arm corefx testing, we use regular jobs (not "build only" since only Windows has "build only", and
2743                 // the Ubuntu arm "regular" jobs don't run tests anyway).
2744                 if (os == 'Windows_NT') {
2745                     if (! (isBuildOnly && isCoreFxScenario(scenario)) ) {
2746                         return false
2747                     }
2748                 }
2749                 else {
2750                     if (!isCoreFxScenario(scenario)) {
2751                         return false
2752                     }
2753                 }
2754                 break
2755
2756             default:
2757                 // armem: no stress jobs for ARM emulator.
2758                 return false
2759         }
2760     }
2761     else if (isR2RScenario(scenario)) {
2762         if (os != 'Windows_NT') {
2763             return false
2764         }
2765
2766         if (isR2RBaselineScenario(scenario)) {
2767             // no need for Debug scenario; Checked is sufficient
2768             if (configuration != 'Checked' && configuration != 'Release') {
2769                 return false
2770             }
2771         }
2772         else if (isR2RStressScenario(scenario)) {
2773             // Stress scenarios only run with Checked builds, not Release (they would work with Debug, but be slow).
2774             if (configuration != 'Checked') {
2775                 return false
2776             }
2777         }
2778
2779         switch (architecture) {
2780             case 'arm':
2781             case 'arm64':
2782                 // Windows arm/arm64 ready-to-run jobs use flow jobs and test jobs, but depend on "normal" (not R2R specific) build jobs.
2783                 return false
2784
2785             default:
2786                 break
2787         }
2788     }
2789     else if (isCrossGenComparisonScenario(scenario)) {
2790         return shouldGenerateCrossGenComparisonJob(os, architecture, configuration, scenario)
2791     }
2792     else {
2793         // Skip scenarios
2794         switch (scenario) {
2795             case 'ilrt':
2796                 // The ilrt build isn't necessary except for Windows_NT2003.  Non-Windows NT uses
2797                 // the default scenario build
2798                 if (os != 'Windows_NT') {
2799                     return false
2800                 }
2801                 // Only x64 for now
2802                 if (architecture != 'x64') {
2803                     return false
2804                 }
2805                 // Release only
2806                 if (configuration != 'Release') {
2807                     return false
2808                 }
2809                 break
2810             case 'jitdiff':
2811                 if (os != 'Windows_NT' && os != 'Ubuntu' && os != 'OSX10.12') {
2812                     return false
2813                 }
2814                 if (architecture != 'x64') {
2815                     return false
2816                 }
2817                 if (configuration != 'Checked') {
2818                     return false
2819                 }
2820                 break
2821             case 'longgc':
2822             case 'gcsimulator':
2823                 if (os != 'Windows_NT' && os != 'Ubuntu' && os != 'OSX10.12') {
2824                     return false
2825                 }
2826                 if (architecture != 'x64') {
2827                     return false
2828                 }
2829                 if (configuration != 'Release') {
2830                     return false
2831                 }
2832                 break
2833             case 'gc_reliability_framework':
2834             case 'standalone_gc':
2835                 if (os != 'Windows_NT' && os != 'Ubuntu' && os != 'OSX10.12') {
2836                     return false
2837                 }
2838
2839                 if (architecture != 'x64') {
2840                     return false
2841                 }
2842
2843                 if (configuration != 'Release' && configuration != 'Checked') {
2844                     return false
2845                 }
2846                 break
2847             // We only run Windows and Ubuntu x64 Checked for formatting right now
2848             case 'formatting':
2849                 if (os != 'Windows_NT' && os != 'Ubuntu') {
2850                     return false
2851                 }
2852                 if (architecture != 'x64') {
2853                     return false
2854                 }
2855                 if (configuration != 'Checked') {
2856                     return false
2857                 }
2858                 break
2859             case 'illink':
2860                 if (os != 'Windows_NT' && (os != 'Ubuntu' || architecture != 'x64')) {
2861                     return false
2862                 }
2863                 if (architecture != 'x64' && architecture != 'x86') {
2864                     return false
2865                 }
2866                 break
2867             case 'normal':
2868                 // Nothing skipped
2869                 break
2870             case 'innerloop':
2871                 if (!isValidPrTriggeredInnerLoopJob(os, architecture, configuration, isBuildOnly)) {
2872                     return false
2873                 }
2874                 break
2875             case 'corefx_innerloop':
2876                 if (os != 'Windows_NT' && os != 'Ubuntu' &&  os != 'OSX10.12') {
2877                     return false
2878                 }
2879                 if (architecture != 'x64') {
2880                     return false
2881                 }
2882                 break
2883             case 'pmi_asm_diffs':
2884                 if (configuration != 'Checked') {
2885                     return false
2886                 }
2887                 if (architecture == 'armem') {
2888                     return false
2889                 }
2890                 // Currently, we don't support pmi_asm_diffs for Windows arm/arm64. We don't have a dotnet CLI available to
2891                 // build jitutils. The jobs are not in validArmWindowsScenarios.
2892                 if ((os == 'Windows_NT') && (architecture == 'arm' || architecture == 'arm64')) {
2893                     return false
2894                 }
2895                 // Currently, no support for Linux x86.
2896                 if ((os != 'Windows_NT') && (architecture == 'x86')) {
2897                     return false
2898                 }
2899                 break
2900             default:
2901                 println("Unknown scenario: ${scenario}")
2902                 assert false
2903                 break
2904         }
2905     }
2906
2907     // For altjit, don't do any scenarios that don't change compilation. That is, scenarios that only change
2908     // runtime behavior, not compile-time behavior, are not interesting.
2909     switch (architecture) {
2910         case 'x86_arm_altjit':
2911         case 'x64_arm64_altjit':
2912             if (isGCStressRelatedTesting(scenario)) {
2913                 return false
2914             }
2915             break
2916         default:
2917             break
2918     }
2919
2920     // The job was not filtered out, so we should generate it!
2921     return true
2922 }
2923
2924 Constants.allScenarios.each { scenario ->
2925     [true, false].each { isPR ->
2926         Constants.architectureList.each { architecture ->
2927             Constants.configurationList.each { configuration ->
2928                 Constants.osList.each { os ->
2929                     // If the OS is Windows_NT_BuildOnly, set the isBuildOnly flag to true
2930                     // and reset the os to Windows_NT
2931                     def isBuildOnly = false
2932                     if (os == 'Windows_NT_BuildOnly') {
2933                         isBuildOnly = true
2934                         os = 'Windows_NT'
2935                     }
2936
2937                     if (!shouldGenerateJob(scenario, isPR, architecture, configuration, os, isBuildOnly)) {
2938                         return
2939                     }
2940
2941                     // Calculate names
2942                     def jobName = getJobName(configuration, architecture, os, scenario, isBuildOnly)
2943                     def folderName = getJobFolder(scenario)
2944
2945                     // Create the new job
2946                     def newJob = job(Utilities.getFullJobName(project, jobName, isPR, folderName)) {}
2947
2948                     addToViews(newJob, false, isPR, architecture, os, configuration, scenario) // isFlowJob == false
2949
2950                     setJobMachineAffinity(architecture, os, true, false, false, newJob) // isBuildJob = true, isTestJob = false, isFlowJob = false
2951
2952                     Utilities.standardJobSetup(newJob, project, isPR, "*/${branch}")
2953                     addTriggers(newJob, branch, isPR, architecture, os, configuration, scenario, false, isBuildOnly) // isFlowJob==false
2954                     setJobTimeout(newJob, isPR, architecture, configuration, scenario, isBuildOnly)
2955
2956                     // Copy Windows build test binaries and corefx build artifacts for Linux cross build for armem.
2957                     // We don't use a flow job for this, but we do depend on there being existing builds with these
2958                     // artifacts produced.
2959                     if ((architecture == 'armem') && (os == 'Tizen')) {
2960                         // Define the Windows Tests and Corefx build job names
2961                         def lowerConfiguration = configuration.toLowerCase()
2962                         def WindowsTestsName = projectFolder + '/' +
2963                                                Utilities.getFullJobName(project,
2964                                                                         getJobName(lowerConfiguration, 'x64' , 'windows_nt', 'normal', true),
2965                                                                         false)
2966                         def fxBranch = getFxBranch(branch)
2967                         def corefxFolder = Utilities.getFolderName('dotnet/corefx') + '/' +
2968                                            Utilities.getFolderName(fxBranch)
2969
2970                         def arm_abi = 'armel'
2971                         def corefx_os = 'tizen'
2972
2973                         // Let's use release CoreFX to test checked CoreCLR,
2974                         // because we do not generate checked CoreFX in CoreFX CI yet.
2975                         def corefx_lowerConfiguration = lowerConfiguration
2976                         if (lowerConfiguration == 'checked') {
2977                             corefx_lowerConfiguration = 'release'
2978                         }
2979
2980                         // Copy the Windows test binaries and the Corefx build binaries
2981                         newJob.with {
2982                             steps {
2983                                 copyArtifacts(WindowsTestsName) {
2984                                     includePatterns('bin/tests/tests.zip')
2985                                     buildSelector {
2986                                         latestSuccessful(true)
2987                                     }
2988                                 }
2989                                 copyArtifacts("${corefxFolder}/${corefx_os}_${arm_abi}_cross_${corefx_lowerConfiguration}") {
2990                                     includePatterns('artifacts/bin/build.tar.gz')
2991                                     buildSelector {
2992                                         latestSuccessful(true)
2993                                     }
2994                                 }
2995                             } // steps
2996                         } // newJob.with
2997                     }
2998
2999                     def buildCommands = calculateBuildCommands(newJob, scenario, branch, isPR, architecture, configuration, os, isBuildOnly)
3000
3001                     newJob.with {
3002                         steps {
3003                             if (os == 'Windows_NT') {
3004                                 buildCommands.each { buildCommand ->
3005                                     batchFile(buildCommand)
3006                                 }
3007                             }
3008                             else {
3009                                 buildCommands.each { buildCommand ->
3010                                     shell(buildCommand)
3011                                 }
3012                             }
3013                         } // steps
3014                     } // newJob.with
3015
3016                 } // os
3017             } // configuration
3018         } // architecture
3019     } // isPR
3020 } // scenario
3021
3022 // Create a Windows ARM/ARM64 test job that will be used by a flow job.
3023 // Returns the newly created job.
3024 def static CreateWindowsArmTestJob(def dslFactory, def project, def architecture, def os, def configuration, def scenario, def isPR, def inputCoreCLRBuildName)
3025 {
3026     def osGroup = getOSGroup(os)
3027     def jobName = getJobName(configuration, architecture, os, scenario, false) + "_tst"
3028
3029     def jobFolder = getJobFolder(scenario)
3030     def newJob = dslFactory.job(Utilities.getFullJobName(project, jobName, isPR, jobFolder)) {
3031         parameters {
3032             stringParam('CORECLR_BUILD', '', "Build number to copy CoreCLR ${osGroup} binaries from")
3033         }
3034
3035         steps {
3036             // Set up the copies
3037
3038             // Coreclr build we are trying to test
3039             //
3040             //  ** NOTE ** This will, correctly, overwrite the CORE_ROOT from the Windows test archive
3041
3042             copyArtifacts(inputCoreCLRBuildName) {
3043                 excludePatterns('**/testResults.xml', '**/*.ni.dll')
3044                 buildSelector {
3045                     buildNumber('${CORECLR_BUILD}')
3046                 }
3047             }
3048
3049             if (isCoreFxScenario(scenario)) {
3050
3051                 // Only arm/arm64 supported for corefx testing now.
3052                 assert architecture == 'arm' || architecture == 'arm64'
3053
3054                 // Unzip CoreFx runtime
3055                 batchFile("powershell -NoProfile -Command \"Add-Type -Assembly 'System.IO.Compression.FileSystem'; [System.IO.Compression.ZipFile]::ExtractToDirectory('_\\fx\\fxruntime.zip', '_\\fx\\artifacts\\bin\\testhost\\netcoreapp-Windows_NT-Release-${architecture}')\"")
3056
3057                 // Unzip CoreFx tests.
3058                 batchFile("powershell -NoProfile -Command \"Add-Type -Assembly 'System.IO.Compression.FileSystem'; [System.IO.Compression.ZipFile]::ExtractToDirectory('_\\fx\\fxtests.zip', '_\\fx\\artifacts\\bin\\tests')\"")
3059
3060                 // Add the script to run the corefx tests
3061                 def corefx_runtime_path   = "%WORKSPACE%\\_\\fx\\artifacts\\bin\\testhost\\netcoreapp-Windows_NT-Release-${architecture}"
3062                 def corefx_tests_dir      = "%WORKSPACE%\\_\\fx\\artifacts\\bin\\tests"
3063                 def corefx_exclusion_file = "%WORKSPACE%\\tests\\${architecture}\\corefx_test_exclusions.txt"
3064                 batchFile("call %WORKSPACE%\\tests\\scripts\\run-corefx-tests.bat ${corefx_runtime_path} ${corefx_tests_dir} ${corefx_exclusion_file} ${architecture}")
3065
3066             } else { // !isCoreFxScenario(scenario)
3067
3068                 // Unzip tests.
3069                 batchFile("powershell -NoProfile -Command \"Add-Type -Assembly 'System.IO.Compression.FileSystem'; [System.IO.Compression.ZipFile]::ExtractToDirectory('bin\\tests\\tests.zip', 'bin\\tests\\${osGroup}.${architecture}.${configuration}')\"")
3070
3071                 def buildCommands = ""
3072
3073                 def coreRootLocation = "%WORKSPACE%\\bin\\tests\\Windows_NT.${architecture}.${configuration}\\Tests\\Core_Root"
3074                 def addEnvVariable =  { variable, value -> buildCommands += "set ${variable}=${value}\r\n"}
3075                 def addCommand = { cmd -> buildCommands += "${cmd}\r\n"}
3076
3077                 // Make sure Command Extensions are enabled. Used so %ERRORLEVEL% is available.
3078                 addCommand("SETLOCAL ENABLEEXTENSIONS")
3079
3080                 // For all jobs 
3081                 addEnvVariable("CORE_ROOT", coreRootLocation)
3082                 addEnvVariable("COMPlus_NoGuiOnAssert", "1")
3083                 addEnvVariable("COMPlus_ContinueOnAssert", "0")
3084
3085                 // If we are running a stress mode, we'll set those variables as well
3086                 if (isJitStressScenario(scenario) || isR2RStressScenario(scenario)) {
3087                     def stressValues = null
3088                     if (isJitStressScenario(scenario)) {
3089                         stressValues = Constants.jitStressModeScenarios[scenario]
3090                     }
3091                     else {
3092                         stressValues = Constants.r2rStressScenarios[scenario]
3093                     }
3094
3095                     stressValues.each { key, value -> 
3096                         addEnvVariable(key, value)
3097                     }
3098                 }
3099
3100                 if (isR2RScenario(scenario)) {
3101                     // Crossgen the framework assemblies.
3102                     buildCommands += """
3103 @for %%F in (%CORE_ROOT%\\*.dll) do @call :PrecompileAssembly "%CORE_ROOT%" "%%F" %%~nxF
3104 @goto skip_PrecompileAssembly
3105
3106 :PrecompileAssembly
3107 @REM Skip mscorlib since it is already precompiled.
3108 @if /I "%3" == "mscorlib.dll" exit /b 0
3109 @if /I "%3" == "mscorlib.ni.dll" exit /b 0
3110
3111 "%CORE_ROOT%\\crossgen.exe" /Platform_Assemblies_Paths "%CORE_ROOT%" %2 >nul 2>nul
3112 @if "%errorlevel%" == "-2146230517" (
3113     echo %2 is not a managed assembly.
3114 ) else if "%errorlevel%" == "-2146234344" (
3115     echo %2 is not a managed assembly.
3116 ) else if %errorlevel% neq 0 (
3117     echo Unable to precompile %2
3118 ) else (
3119     echo Precompiled %2
3120 )
3121 @exit /b 0
3122
3123 :skip_PrecompileAssembly
3124 """
3125
3126                     // Set RunCrossGen variable to cause test wrappers to invoke their logic to run
3127                     // crossgen on tests before running them.
3128                     addEnvVariable("RunCrossGen", "true")
3129                 } // isR2RScenario(scenario)
3130
3131                 // Run runtest.cmd
3132                 // Do not run generate layout. It will delete the correct CORE_ROOT, and we do not have a correct product
3133                 // dir to copy from.
3134                 def runtestCommand = "%WORKSPACE%\\tests\\runtest.cmd ${architecture} ${configuration} skipgeneratelayout"
3135
3136                 addCommand("${runtestCommand}")
3137
3138                 // Use the smarty errorlevel as the script errorlevel.
3139                 addCommand("exit /b %errorlevel%")
3140
3141                 batchFile(buildCommands)
3142             } // non-corefx testing
3143         } // steps
3144     } // job
3145
3146     if (!isCoreFxScenario(scenario)) {
3147         Utilities.addXUnitDotNETResults(newJob, 'bin/**/TestRun*.xml', true)
3148     }
3149
3150     return newJob
3151 }
3152
3153 // Create a test job not covered by the "Windows ARM" case that will be used by a flow job.
3154 // E.g., non-Windows tests.
3155 // Returns the newly created job.
3156 def static CreateOtherTestJob(def dslFactory, def project, def branch, def architecture, def os, def configuration, def scenario, def isPR, def inputCoreCLRBuildName)
3157 {
3158     def lowerConfiguration = configuration.toLowerCase()
3159
3160     def isUbuntuArm64Job = ((os == "Ubuntu16.04") && (architecture == 'arm64'))
3161     def isUbuntuArm32Job = ((os == "Ubuntu") && (architecture == 'arm'))
3162     def isUbuntuArmJob = isUbuntuArm32Job || isUbuntuArm64Job
3163
3164     def doCoreFxTesting = isCoreFxScenario(scenario)
3165     def isPmiAsmDiffsScenario = (scenario == 'pmi_asm_diffs')
3166
3167     def workspaceRelativeFxRootLinux = "_/fx" // only used for CoreFX testing
3168
3169     def osGroup = getOSGroup(os)
3170     def jobName = getJobName(configuration, architecture, os, scenario, false) + "_tst"
3171
3172     def testOpts = ''
3173     def useServerGC = false
3174
3175     // Enable Server GC for Ubuntu PR builds
3176     // REVIEW: why? Does this apply to all architectures? Why only PR?
3177     if (os == 'Ubuntu' && isPR) {
3178         testOpts += ' --useServerGC'
3179         useServerGC = true
3180     }
3181
3182     if (isR2RScenario(scenario)) {
3183
3184         testOpts += ' --crossgen --runcrossgentests'
3185
3186         if (scenario == 'r2r_jitstress1') {
3187             testOpts += ' --jitstress=1'
3188         }
3189         else if (scenario == 'r2r_jitstress2') {
3190             testOpts += ' --jitstress=2'
3191         }
3192         else if (scenario == 'r2r_jitstress1_tiered') {
3193             testOpts += ' --jitstress=1'
3194         }
3195         else if (scenario == 'r2r_jitstress2_tiered') {
3196             testOpts += ' --jitstress=2'
3197         }
3198         else if (scenario == 'r2r_jitstressregs1') {
3199             testOpts += ' --jitstressregs=1'
3200         }
3201         else if (scenario == 'r2r_jitstressregs2') {
3202             testOpts += ' --jitstressregs=2'
3203         }
3204         else if (scenario == 'r2r_jitstressregs3') {
3205             testOpts += ' --jitstressregs=3'
3206         }
3207         else if (scenario == 'r2r_jitstressregs4') {
3208             testOpts += ' --jitstressregs=4'
3209         }
3210         else if (scenario == 'r2r_jitstressregs8') {
3211             testOpts += ' --jitstressregs=8'
3212         }
3213         else if (scenario == 'r2r_jitstressregs0x10') {
3214             testOpts += ' --jitstressregs=0x10'
3215         }
3216         else if (scenario == 'r2r_jitstressregs0x80') {
3217             testOpts += ' --jitstressregs=0x80'
3218         }
3219         else if (scenario == 'r2r_jitstressregs0x1000') {
3220             testOpts += ' --jitstressregs=0x1000'
3221         }
3222         else if (scenario == 'r2r_jitminopts') {
3223             testOpts += ' --jitminopts'
3224         }
3225         else if (scenario == 'r2r_jitforcerelocs') {
3226             testOpts += ' --jitforcerelocs'
3227         }
3228         else if (scenario == 'r2r_gcstress15') {
3229             testOpts += ' --gcstresslevel=0xF'
3230         }
3231     }
3232     else if (scenario == 'jitdiff') {
3233         testOpts += ' --jitdisasm --crossgen'
3234     }
3235     else if (scenario == 'illink') {
3236         testOpts += ' --link=\$WORKSPACE/linker/linker/bin/netcore_Release/netcoreapp2.0/ubuntu-x64/publish/illink'
3237     }
3238     else if (isLongGc(scenario)) {
3239         // Long GC tests behave very poorly when they are not
3240         // the only test running (many of them allocate until OOM).
3241         testOpts += ' --sequential'
3242
3243         // A note - runtest.sh does have "--long-gc" and "--gcsimulator" options
3244         // for running long GC and GCSimulator tests, respectively. We don't use them
3245         // here because using a playlist file produces much more readable output on the CI machines
3246         // and reduces running time.
3247         //
3248         // The Long GC playlist contains all of the tests that are
3249         // going to be run. The GCSimulator playlist contains all of
3250         // the GC simulator tests.
3251         if (scenario == 'longgc') {
3252             testOpts += ' --long-gc --playlist=./tests/longRunningGcTests.txt'
3253         }
3254         else if (scenario == 'gcsimulator') {
3255             testOpts += ' --gcsimulator --playlist=./tests/gcSimulatorTests.txt'
3256         }
3257     }
3258     else if (isGcReliabilityFramework(scenario)) {
3259         testOpts += ' --build-overlay-only'
3260     }
3261     else if (scenario == 'standalone_gc') {
3262         if (osGroup == 'OSX') {
3263             testOpts += ' --gcname=libclrgc.dylib'
3264         }
3265         else if (osGroup == 'Linux') {
3266             testOpts += ' --gcname=libclrgc.so'
3267         }
3268         else {
3269             println("Unexpected OS group: ${osGroup} for os ${os}")
3270             assert false
3271         }
3272     }
3273
3274     def jobFolder = getJobFolder(scenario)
3275     def newJob = dslFactory.job(Utilities.getFullJobName(project, jobName, isPR, jobFolder)) {
3276         parameters {
3277             stringParam('CORECLR_BUILD', '', "Build number to copy CoreCLR ${osGroup} binaries from")
3278         }
3279
3280         steps {
3281             // Set up the copies
3282
3283             // Coreclr build we are trying to test
3284             //
3285             // HACK: the Ubuntu arm64 copyArtifacts Jenkins plug-in is ridiculously slow (45 minutes to
3286             // 1.5 hours for this step). Instead, directly use wget, which is fast (1 minute).
3287
3288             if (!isUbuntuArm64Job) {
3289                 copyArtifacts(inputCoreCLRBuildName) {
3290                     excludePatterns('**/testResults.xml', '**/*.ni.dll')
3291                     buildSelector {
3292                         buildNumber('${CORECLR_BUILD}')
3293                     }
3294                 }
3295             }
3296
3297             if (isUbuntuArmJob) {
3298                 // Add some useful information to the log file. Ignore return codes.
3299                 shell("uname -a || true")
3300             }
3301
3302             if (isUbuntuArm64Job) {
3303                 // Copy the required artifacts directly, using wget, e.g.:
3304                 // 
3305                 //  https://ci.dot.net/job/dotnet_coreclr/job/master/job/arm64_cross_checked_ubuntu16.04_innerloop_prtest/16/artifact/testnativebin.checked.zip
3306                 //  https://ci.dot.net/job/dotnet_coreclr/job/master/job/arm64_cross_checked_ubuntu16.04_innerloop_prtest/16/artifact/tests.checked.zip
3307                 // 
3308                 // parameterized as:
3309                 //
3310                 //  https://ci.dot.net/job/${mungedProjectName}/job/${mungedBranchName}/job/${inputJobName}/${CORECLR_BUILD}/artifact/testnativebin.checked.zip
3311                 //  https://ci.dot.net/job/${mungedProjectName}/job/${mungedBranchName}/job/${inputJobName}/${CORECLR_BUILD}/artifact/tests.checked.zip
3312                 //
3313                 // CoreFX example artifact URLs:
3314                 //
3315                 //  https://ci.dot.net/job/dotnet_coreclr/job/dev_unix_test_workflow/job/jitstress/job/arm64_cross_checked_ubuntu16.04_corefx_baseline_prtest/1/artifact/_/fx/fxruntime.zip
3316                 //  https://ci.dot.net/job/dotnet_coreclr/job/dev_unix_test_workflow/job/jitstress/job/arm64_cross_checked_ubuntu16.04_corefx_baseline_prtest/1/artifact/_/fx/fxtests.zip
3317                 //
3318                 // Note that the source might be in a "jitstress" folder.
3319                 //
3320                 // Use `--progress=dot:giga` to display some progress output, but limit it in the log file.
3321                 //
3322                 // Use `--directory-prefix=_/fx` to specify where to put the corefx files (to match what other platforms do). Use this instead of `-O`.
3323
3324                 shell("echo \"Using wget instead of the Jenkins copy artifacts plug-in to copy artifacts from ${inputCoreCLRBuildName}\"")
3325
3326                 def mungedProjectName = Utilities.getFolderName(project)
3327                 def mungedBranchName = Utilities.getFolderName(branch)
3328
3329                 def doCrossGenComparison = isCrossGenComparisonScenario(scenario)
3330                 def inputCoreCLRBuildScenario = isInnerloopTestScenario(scenario) ? 'innerloop' : 'normal'
3331                 if (isPmiAsmDiffsScenario || doCoreFxTesting || doCrossGenComparison) {
3332                     // These depend on unique builds for each scenario
3333                     inputCoreCLRBuildScenario = scenario
3334                 }
3335                 def sourceJobName = getJobName(configuration, architecture, os, inputCoreCLRBuildScenario, false)
3336                 def inputJobName = Utilities.getFullJobName(sourceJobName, isPR)
3337
3338                 // Need to add the sub-folder if necessary.
3339                 def inputJobPath = "job/${inputJobName}"
3340                 def folderName = getJobFolder(inputCoreCLRBuildScenario)
3341                 if (folderName != '') {
3342                     inputJobPath = "job/${folderName}/job/${inputJobName}"
3343                 }
3344
3345                 def inputUrlRoot = "https://ci.dot.net/job/${mungedProjectName}/job/${mungedBranchName}/${inputJobPath}/\${CORECLR_BUILD}/artifact"
3346
3347                 if (isPmiAsmDiffsScenario) {
3348                     def workspaceRelativeRootLinux = "_/pmi"
3349                     shell("mkdir -p ${workspaceRelativeRootLinux}")
3350                     shell("wget --progress=dot:giga ${inputUrlRoot}/product.${os}.${architecture}.${lowerConfiguration}.zip")
3351                     shell("wget --progress=dot:giga ${inputUrlRoot}/product.baseline.${os}.${architecture}.${lowerConfiguration}.zip")
3352                     shell("wget --progress=dot:giga ${inputUrlRoot}/coreroot.${os}.${architecture}.${lowerConfiguration}.zip")
3353                     shell("wget --progress=dot:giga ${inputUrlRoot}/coreroot.baseline.${os}.${architecture}.${lowerConfiguration}.zip")
3354                 }
3355                 else if (doCoreFxTesting) {
3356                     shell("mkdir -p ${workspaceRelativeFxRootLinux}")
3357                     shell("wget --progress=dot:giga --directory-prefix=${workspaceRelativeFxRootLinux} ${inputUrlRoot}/${workspaceRelativeFxRootLinux}/fxtests.zip")
3358                     shell("wget --progress=dot:giga --directory-prefix=${workspaceRelativeFxRootLinux} ${inputUrlRoot}/${workspaceRelativeFxRootLinux}/fxruntime.zip")
3359                 }
3360                 else {
3361                     def testArtifactsTgzFileName = getTestArtifactsTgzFileName(osGroup, architecture, configuration)
3362                     shell("wget --progress=dot:giga ${inputUrlRoot}/${testArtifactsTgzFileName}")
3363                 }
3364             }
3365
3366             if (architecture == 'x86') {
3367                 shell("mkdir ./bin/CoreFxNative")
3368
3369                 def fxBranch = getFxBranch(branch)
3370                 def corefxFolder = Utilities.getFolderName('dotnet/corefx') + '/' + Utilities.getFolderName(fxBranch)
3371
3372                 copyArtifacts("${corefxFolder}/ubuntu16.04_x86_release") {
3373                     includePatterns('artifacts/bin/build.tar.gz')
3374                     targetDirectory('bin/CoreFxNative')
3375                     buildSelector {
3376                         latestSuccessful(true)
3377                     }
3378                 }
3379
3380                 shell("mkdir ./bin/CoreFxBinDir")
3381                 shell("tar -xf ./bin/CoreFxNative/artifacts/bin/build.tar.gz -C ./bin/CoreFxBinDir")
3382             }
3383
3384             if (isPmiAsmDiffsScenario) {
3385                 // TODO: add back "-q" when we know it works
3386                 shell("unzip -o ./product.${os}.${architecture}.${lowerConfiguration}.zip || exit 0")
3387                 shell("unzip -o ./product.baseline.${os}.${architecture}.${lowerConfiguration}.zip || exit 0")
3388                 shell("unzip -o ./coreroot.${os}.${architecture}.${lowerConfiguration}.zip || exit 0")
3389                 shell("unzip -o ./coreroot.baseline.${os}.${architecture}.${lowerConfiguration}.zip || exit 0")
3390             }
3391             // CoreFX testing downloads the CoreFX tests, not the coreclr tests. Also, unzip the built CoreFX layout/runtime directories.
3392             else if (doCoreFxTesting) {
3393                 shell("unzip -q -o ${workspaceRelativeFxRootLinux}/fxtests.zip || exit 0")
3394                 shell("unzip -q -o ${workspaceRelativeFxRootLinux}/fxruntime.zip || exit 0")
3395             }
3396             else {
3397                 def testArtifactsTgzFileName = getTestArtifactsTgzFileName(osGroup, architecture, configuration)
3398                 shell("tar -xzf ./${testArtifactsTgzFileName} || exit 0") // extracts to ./bin/tests/${osGroup}.${architecture}.${configuration}
3399             }
3400
3401             // Execute the tests
3402             def runDocker = isNeedDocker(architecture, os, false)
3403             def dockerPrefix = ""
3404             def dockerCmd = ""
3405             if (runDocker) {
3406                 def dockerImage = getDockerImageName(architecture, os, false)
3407                 dockerPrefix = "docker run -i --rm -v \${WORKSPACE}:\${WORKSPACE} -w \${WORKSPACE} "
3408                 dockerCmd = dockerPrefix + "${dockerImage} "
3409             }
3410
3411             // If we are running a stress mode, we'll set those variables first.
3412             // For CoreFX, the stress variables are already built into the CoreFX test build per-test wrappers.
3413             if (!doCoreFxTesting && isJitStressScenario(scenario)) {
3414                 def scriptFileName = "\${WORKSPACE}/set_stress_test_env.sh"
3415                 def envScriptCmds = envScriptCreate(os, scriptFileName)
3416                 envScriptCmds += envScriptSetStressModeVariables(os, Constants.jitStressModeScenarios[scenario], scriptFileName)
3417                 envScriptCmds += envScriptFinalize(os, scriptFileName)
3418                 shell("${envScriptCmds}")
3419                 testOpts += " --test-env=${scriptFileName}"
3420             }
3421
3422             // setup-stress-dependencies.sh, invoked by runtest.sh to download the coredistools package, depends on the "dotnet"
3423             // tool downloaded by the "init-tools.sh" script. However, it only invokes setup-stress-dependencies.sh for x64. The
3424             // coredistools package is used by GCStress on x86 and x64 to disassemble code to determine instruction boundaries.
3425             // On arm/arm64, it is not required as determining instruction boundaries is trivial.
3426             if (isGCStressRelatedTesting(scenario)) {
3427                 if (architecture == 'x64') {
3428                     shell('./init-tools.sh')
3429                 }
3430             }
3431
3432             if (isPmiAsmDiffsScenario) {
3433                 shell("""\
3434 python -u \${WORKSPACE}/tests/scripts/run-pmi-diffs.py -arch ${architecture} -ci_arch ${architecture} -build_type ${configuration} --skip_baseline_build""")
3435
3436                 shell("zip -r dasm.${os}.${architecture}.${configuration}.zip ./_/pmi/asm")
3437             }
3438             else if (doCoreFxTesting) {
3439                 shell("""\
3440 \${WORKSPACE}/tests/scripts/run-corefx-tests.sh --test-exclude-file \${WORKSPACE}/tests/${architecture}/corefx_linux_test_exclusions.txt --runtime \${WORKSPACE}/${workspaceRelativeFxRootLinux}/artifacts/bin/testhost/netcoreapp-Linux-Release-${architecture} --arch ${architecture} --corefx-tests \${WORKSPACE}/${workspaceRelativeFxRootLinux}/artifacts/bin --configurationGroup Release""")
3441             }
3442             else {
3443                 def runScript = "${dockerCmd}./tests/runtest.sh"
3444
3445                 shell("""\
3446 ${runScript} \\
3447     ${lowerConfiguration} \\
3448     --testRootDir=\"\${WORKSPACE}/bin/tests/${osGroup}.${architecture}.${configuration}\" \\
3449     --coreOverlayDir=\"\${WORKSPACE}/bin/tests/${osGroup}.${architecture}.${configuration}/Tests/Core_Root\" \\
3450     --limitedDumpGeneration ${testOpts}""")
3451             }
3452
3453             if (isGcReliabilityFramework(scenario)) {
3454                 // runtest.sh doesn't actually execute the reliability framework - do it here.
3455                 if (useServerGC) {
3456                     if (runDocker) {
3457                         dockerCmd = dockerPrefix + "-e COMPlus_gcServer=1 ${dockerImage} "
3458                     }
3459                     else {
3460                         shell("export COMPlus_gcServer=1")
3461                     }
3462                 }
3463
3464                 shell("${dockerCmd}./tests/scripts/run-gc-reliability-framework.sh ${architecture} ${configuration}")
3465             }
3466         } // steps
3467     } // job
3468
3469     // Experimental: If on Ubuntu 14.04, then attempt to pull in crash dump links
3470     if (os in ['Ubuntu']) {
3471         SummaryBuilder summaries = new SummaryBuilder()
3472         summaries.addLinksSummaryFromFile('Crash dumps from this run:', 'dumplings.txt')
3473         summaries.emit(newJob)
3474     }
3475
3476     if (isPmiAsmDiffsScenario) {
3477         // Archive the asm
3478         Utilities.addArchival(newJob, "dasm.${os}.${architecture}.${configuration}.zip")
3479     }
3480     else if (doCoreFxTesting) {
3481         Utilities.addArchival(newJob, "${workspaceRelativeFxRootLinux}/artifacts/bin/**/testResults.xml")
3482         if ((os == "Ubuntu") && (architecture == 'arm')) {
3483             // We have a problem with the xunit plug-in, where it is consistently failing on Ubuntu arm32 test result uploading with this error:
3484             //
3485             //   [xUnit] [ERROR] - The plugin hasn't been performed correctly: remote file operation failed: /ssd/j/workspace/dotnet_coreclr/master/jitstress/arm_cross_checked_ubuntu_corefx_baseline_tst at hudson.remoting.Channel@3697f46d:JNLP4-connect connection from 131.107.159.149/131.107.159.149:58529: java.io.IOException: Remote call on JNLP4-connect connection from 131.107.159.149/131.107.159.149:58529 failed
3486             //
3487             // We haven't been able to identify the reason. So, do not add xunit parsing of the test data in this scenario.
3488             // This is tracked by: https://github.com/dotnet/coreclr/issues/19447.
3489         }
3490         else {
3491             Utilities.addXUnitDotNETResults(newJob, "${workspaceRelativeFxRootLinux}/artifacts/bin/**/testResults.xml")
3492         }
3493     }
3494     else {
3495         Utilities.addXUnitDotNETResults(newJob, '**/coreclrtests.xml')
3496     }
3497
3498     return newJob
3499 }
3500
3501 def static CreateNonWindowsCrossGenComparisonTestJob(def dslFactory, def project, def architecture, def os, def configuration, def scenario, def isPR, def inputCoreCLRBuildName)
3502 {
3503     assert isCrossGenComparisonScenario(scenario)
3504
3505     def osGroup = getOSGroup(os)
3506     def jobName = getJobName(configuration, architecture, os, scenario, false) + "_tst"
3507
3508     def workspaceRelativeResultsDir = "_"
3509     def workspaceRelativeNativeArchResultDir = "${workspaceRelativeResultsDir}/${osGroup}.${architecture}_${architecture}.${configuration}"
3510
3511     def crossArch = "x64"
3512     def workspaceRelativeCrossArchResultDir = "${workspaceRelativeResultsDir}/${osGroup}.${crossArch}_${architecture}.${configuration}"
3513
3514     def jobFolder = getJobFolder(scenario)
3515     def newJob = dslFactory.job(Utilities.getFullJobName(project, jobName, isPR, jobFolder)) {
3516         parameters {
3517             stringParam('CORECLR_BUILD', '', "Build number to copy CoreCLR ${osGroup} binaries from")
3518         }
3519
3520         def workspaceRelativeArtifactsArchive = "${os}.${architecture}.${configuration}.${scenario}.zip"
3521
3522         steps {
3523             copyArtifacts(inputCoreCLRBuildName) {
3524                 includePatterns("${workspaceRelativeArtifactsArchive}")
3525                 buildSelector {
3526                     buildNumber('${CORECLR_BUILD}')
3527                 }
3528             }
3529
3530             shell("unzip -o ${workspaceRelativeArtifactsArchive} || exit 0")
3531
3532             def workspaceRelativeCoreLib = "bin/Product/${osGroup}.${architecture}.${configuration}/IL/System.Private.CoreLib.dll"
3533             def workspaceRelativeCoreRootDir = "bin/tests/${osGroup}.${architecture}.${configuration}/Tests/Core_Root"
3534             def workspaceRelativeCrossGenComparisonScript = "tests/scripts/crossgen_comparison.py"
3535             def workspaceRelativeCrossGenExecutable = "${workspaceRelativeCoreRootDir}/crossgen"
3536
3537             def crossGenComparisonCmd = "python -u \${WORKSPACE}/${workspaceRelativeCrossGenComparisonScript} "
3538             def crossGenExecutable = "\${WORKSPACE}/${workspaceRelativeCrossGenExecutable}"
3539
3540             shell("mkdir -p ${workspaceRelativeNativeArchResultDir}")
3541             shell("${crossGenComparisonCmd}crossgen_corelib --crossgen ${crossGenExecutable} --il_corelib \${WORKSPACE}/${workspaceRelativeCoreLib} --result_dir \${WORKSPACE}/${workspaceRelativeNativeArchResultDir}")
3542             shell("${crossGenComparisonCmd}crossgen_framework --crossgen ${crossGenExecutable} --core_root \${WORKSPACE}/${workspaceRelativeCoreRootDir} --result_dir \${WORKSPACE}/${workspaceRelativeNativeArchResultDir}")
3543
3544             shell("${crossGenComparisonCmd}compare --base_dir \${WORKSPACE}/${workspaceRelativeNativeArchResultDir} --diff_dir \${WORKSPACE}/${workspaceRelativeCrossArchResultDir}")
3545         } // steps
3546     }  // job
3547
3548     Utilities.addArchival(newJob, "${workspaceRelativeNativeArchResultDir}/**")
3549     Utilities.addArchival(newJob, "${workspaceRelativeCrossArchResultDir}/**")
3550
3551     return newJob
3552 }
3553
3554 // Create a test job that will be used by a flow job.
3555 // Returns the newly created job.
3556 // Note that we don't add tests jobs to the various views, since they are always used by a flow job, which is in the views,
3557 // and we want the views to be the minimal set of "top-level" jobs that represent all work.
3558 def static CreateTestJob(def dslFactory, def project, def branch, def architecture, def os, def configuration, def scenario, def isPR, def inputCoreCLRBuildName)
3559 {
3560     def windowsArmJob = ((os == "Windows_NT") && (architecture in Constants.armWindowsCrossArchitectureList))
3561
3562     def newJob = null
3563     if (windowsArmJob) {
3564         newJob = CreateWindowsArmTestJob(dslFactory, project, architecture, os, configuration, scenario, isPR, inputCoreCLRBuildName)
3565     }
3566     else if (isCrossGenComparisonScenario(scenario)) {
3567         newJob = CreateNonWindowsCrossGenComparisonTestJob(dslFactory, project, architecture, os, configuration, scenario, isPR, inputCoreCLRBuildName)
3568     }
3569     else {
3570         newJob = CreateOtherTestJob(dslFactory, project, branch, architecture, os, configuration, scenario, isPR, inputCoreCLRBuildName)
3571     }
3572
3573     setJobMachineAffinity(architecture, os, false, true, false, newJob) // isBuildJob = false, isTestJob = true, isFlowJob = false
3574
3575     if (scenario == 'jitdiff') {
3576         def osGroup = getOSGroup(os)
3577         Utilities.addArchival(newJob, "bin/tests/${osGroup}.${architecture}.${configuration}/dasm/**")
3578     }
3579
3580     Utilities.standardJobSetup(newJob, project, isPR, "*/${branch}")
3581     setJobTimeout(newJob, isPR, architecture, configuration, scenario, false)
3582
3583     return newJob
3584 }
3585
3586 // Create a flow job to tie together a build job with the given test job.
3587 // Returns the new flow job.
3588 def static CreateFlowJob(def dslFactory, def project, def branch, def architecture, def os, def configuration, def scenario, def isPR, def fullTestJobName, def inputCoreCLRBuildName)
3589 {
3590     // Windows CoreCLR build and Linux CoreCLR build (in parallel) ->
3591     // Linux CoreCLR test
3592     def flowJobName = getJobName(configuration, architecture, os, scenario, false) + "_flow"
3593     def jobFolder = getJobFolder(scenario)
3594
3595     def newFlowJob = dslFactory.buildFlowJob(Utilities.getFullJobName(project, flowJobName, isPR, jobFolder)) {
3596         buildFlow("""\
3597 coreclrBuildJob = build(params, '${inputCoreCLRBuildName}')
3598
3599 // And then build the test build
3600 build(params + [CORECLR_BUILD: coreclrBuildJob.build.number], '${fullTestJobName}')
3601 """)
3602     }
3603     JobReport.Report.addReference(inputCoreCLRBuildName)
3604     JobReport.Report.addReference(fullTestJobName)
3605
3606     addToViews(newFlowJob, true, isPR, architecture, os, configuration, scenario) // isFlowJob = true
3607
3608     setJobMachineAffinity(architecture, os, false, false, true, newFlowJob) // isBuildJob = false, isTestJob = false, isFlowJob = true
3609
3610     Utilities.standardJobSetup(newFlowJob, project, isPR, "*/${branch}")
3611     addTriggers(newFlowJob, branch, isPR, architecture, os, configuration, scenario, true, false) // isFlowJob==true, isWindowsBuildOnlyJob==false
3612
3613     return newFlowJob
3614 }
3615
3616 // Determine if we should generate a flow job for the given parameters.
3617 // Returns true if the job should be generated.
3618 def static shouldGenerateFlowJob(def scenario, def isPR, def architecture, def configuration, def os)
3619 {
3620     // The various "innerloop" jobs are only available as PR triggered.
3621
3622     if (!isPR) {
3623         if (isInnerloopTestScenario(scenario)) {
3624             return false
3625         }
3626
3627         if (scenario == 'corefx_innerloop') {
3628             return false
3629         }
3630     }
3631
3632     // Filter based on OS and architecture.
3633
3634     switch (architecture) {
3635         case 'arm':
3636             if (os != "Ubuntu" && os != "Windows_NT") {
3637                 return false
3638             }
3639             break
3640         case 'arm64':
3641             if (os != "Ubuntu16.04" && os != "Windows_NT") {
3642                 return false
3643             }
3644             break
3645         case 'x86':
3646             if (os != "Ubuntu") {
3647                 return false
3648             }
3649             break
3650         case 'x64':
3651             if (!(os in Constants.crossList)) {
3652                 return false
3653             }
3654             if (os == "Windows_NT") {
3655                 return false
3656             }
3657             break
3658         case 'armem':
3659         case 'x86_arm_altjit':
3660         case 'x64_arm64_altjit':
3661             // No flow jobs
3662             return false
3663         default:
3664             println("Unknown architecture: ${architecture}")
3665             assert false
3666             break
3667     }
3668
3669     def isNormalOrInnerloop = (scenario == 'innerloop' || scenario == 'normal')
3670
3671     // Filter based on scenario in OS.
3672
3673     if (os == 'Windows_NT') {
3674         assert architecture == 'arm' || architecture == 'arm64'
3675         if (!isArmWindowsScenario(scenario)) {
3676             return false
3677         }
3678         if (isNormalOrInnerloop && (configuration == 'Debug')) {
3679             // The arm32/arm64 Debug configuration for innerloop/normal scenario is a special case: it does a build only, and no test run.
3680             // To do that, it doesn't require a flow job.
3681             return false
3682         }
3683     }
3684     else {
3685         // Non-Windows
3686         if (architecture == 'arm') {
3687             if (!(scenario in Constants.validLinuxArmScenarios)) {
3688                 return false
3689             }
3690         }
3691         else if (architecture == 'arm64') {
3692             if (!(scenario in Constants.validLinuxArm64Scenarios)) {
3693                 return false
3694             }
3695         }
3696         else if (architecture == 'x86') {
3697             // Linux/x86 only want innerloop and default test
3698             if (!isNormalOrInnerloop) {
3699                 return false
3700             }
3701         }
3702         else if (architecture == 'x64') {
3703             // Linux/x64 corefx testing doesn't need a flow job; the "build" job runs run-corefx-tests.py which
3704             // builds and runs the corefx tests. Other Linux/x64 flow jobs are required to get the test
3705             // build from a Windows machine.
3706             if (isCoreFxScenario(scenario)) {
3707                 return false
3708             }
3709         }
3710     }
3711
3712     // For CentOS, we only want Checked/Release builds.
3713     if (os == 'CentOS7.1') {
3714         if (configuration != 'Checked' && configuration != 'Release') {
3715             return false
3716         }
3717         if (!isNormalOrInnerloop && !isR2RScenario(scenario)) {
3718             return false
3719         }
3720     }
3721
3722     // For RedHat and Debian, we only do Release builds.
3723     else if (os == 'RHEL7.2' || os == 'Debian8.4') {
3724         if (configuration != 'Release') {
3725             return false
3726         }
3727         if (!isNormalOrInnerloop) {
3728             return false
3729         }
3730     }
3731
3732     // Next, filter based on scenario.
3733
3734     if (isJitStressScenario(scenario)) {
3735         if (configuration != 'Checked') {
3736             return false
3737         }
3738     }
3739     else if (isR2RBaselineScenario(scenario)) {
3740         if (configuration != 'Checked' && configuration != 'Release') {
3741             return false
3742         }
3743     }
3744     else if (isR2RStressScenario(scenario)) {
3745         if (configuration != 'Checked') {
3746             return false
3747         }
3748     }
3749     else if (isCrossGenComparisonScenario(scenario)) {
3750         return shouldGenerateCrossGenComparisonJob(os, architecture, configuration, scenario)
3751     }
3752     else {
3753         // Skip scenarios
3754         switch (scenario) {
3755             case 'ilrt':
3756             case 'longgc':
3757             case 'gcsimulator':
3758                 // Long GC tests take a long time on non-Release builds
3759                 // ilrt is also Release only
3760                 if (configuration != 'Release') {
3761                     return false
3762                 }
3763                 break
3764
3765             case 'jitdiff':
3766                 if (configuration != 'Checked') {
3767                     return false
3768                 }
3769                 break
3770
3771             case 'gc_reliability_framework':
3772             case 'standalone_gc':
3773                 if (configuration != 'Release' && configuration != 'Checked') {
3774                     return false
3775                 }
3776                 break
3777
3778             case 'formatting':
3779                 return false
3780
3781             case 'illink':
3782                 if (os != 'Windows_NT' && os != 'Ubuntu') {
3783                     return false
3784                 }
3785                 break
3786
3787             case 'normal':
3788                 // Nothing skipped
3789                 break
3790
3791             case 'innerloop':
3792                 if (!isValidPrTriggeredInnerLoopJob(os, architecture, configuration, false)) {
3793                     return false
3794                 }
3795                 break
3796
3797             case 'pmi_asm_diffs':
3798                 if (configuration != 'Checked') {
3799                     return false
3800                 }
3801                 // No need for flow job except for Linux arm/arm64
3802                 if ((os != 'Windows_NT') && (architecture != 'arm') && (architecture != 'arm64')) {
3803                     return false
3804                 }
3805                 break
3806
3807             case 'corefx_innerloop':
3808                 // No flow job needed
3809                 return false
3810
3811             default:
3812                 println("Unknown scenario: ${scenario}")
3813                 assert false
3814                 break
3815         }
3816     }
3817
3818     // The job was not filtered out, so we should generate it!
3819     return true
3820 }
3821
3822 // Create jobs requiring flow jobs. This includes x64 non-Windows, arm/arm64 Ubuntu, and arm/arm64 Windows.
3823 Constants.allScenarios.each { scenario ->
3824     [true, false].each { isPR ->
3825         Constants.architectureList.each { architecture ->
3826             Constants.configurationList.each { configuration ->
3827                 Constants.osList.each { os ->
3828
3829                     if (!shouldGenerateFlowJob(scenario, isPR, architecture, configuration, os)) {
3830                         return
3831                     }
3832
3833                     def windowsArmJob = ((os == "Windows_NT") && (architecture in Constants.armWindowsCrossArchitectureList))
3834                     def doCoreFxTesting = isCoreFxScenario(scenario)
3835                     def doCrossGenComparison = isCrossGenComparisonScenario(scenario)
3836                     def isPmiAsmDiffsScenario = (scenario == 'pmi_asm_diffs')
3837
3838                     // Figure out the job name of the CoreCLR build the test will depend on.
3839
3840                     def inputCoreCLRBuildScenario = isInnerloopTestScenario(scenario) ? 'innerloop' : 'normal'
3841                     def inputCoreCLRBuildIsBuildOnly = false
3842                     if (doCoreFxTesting || isPmiAsmDiffsScenario) {
3843                         // Every CoreFx test depends on its own unique build.
3844                         inputCoreCLRBuildScenario = scenario
3845                         if (windowsArmJob) {
3846                             // Only Windows ARM corefx jobs use "build only" jobs. Others, such as Ubuntu ARM corefx, use "regular" jobs.
3847                             inputCoreCLRBuildIsBuildOnly = true
3848                         }
3849                     }
3850                     else if (doCrossGenComparison) {
3851                         inputCoreCLRBuildScenario = scenario
3852                     }
3853
3854                     def inputCoreCLRFolderName = getJobFolder(inputCoreCLRBuildScenario)
3855                     def inputCoreCLRBuildName = projectFolder + '/' +
3856                         Utilities.getFullJobName(project, getJobName(configuration, architecture, os, inputCoreCLRBuildScenario, inputCoreCLRBuildIsBuildOnly), isPR, inputCoreCLRFolderName)
3857
3858                     // =============================================================================================
3859                     // Create the test job
3860                     // =============================================================================================
3861
3862                     def testJob = CreateTestJob(this, project, branch, architecture, os, configuration, scenario, isPR, inputCoreCLRBuildName)
3863
3864                     // =============================================================================================
3865                     // Create a build flow to join together the build and tests required to run this test.
3866                     // =============================================================================================
3867
3868                     if (os == 'RHEL7.2' || os == 'Debian8.4') {
3869                         // Do not create the flow job for RHEL jobs.
3870                         return
3871                     }
3872
3873                     def fullTestJobName = projectFolder + '/' + testJob.name
3874                     def flowJob = CreateFlowJob(this, project, branch, architecture, os, configuration, scenario, isPR, fullTestJobName, inputCoreCLRBuildName)
3875
3876                 } // os
3877             } // configuration
3878         } // architecture
3879     } // isPR
3880 } // scenario
3881
3882 JobReport.Report.generateJobReport(out)
3883
3884 // Make the call to generate the help job
3885 Utilities.createHelperJob(this, project, branch,
3886     "Welcome to the ${project} Repository",  // This is prepended to the help message
3887     "Have a nice day!")  // This is appended to the help message.  You might put known issues here.
3888
3889 Utilities.addCROSSCheck(this, project, branch)