Updating genSIMDZero to only use `xorps` (#21249)
[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                     def additionalOpts = ""
2512                     if (architecture == 'arm') {
2513                         additionalOpts = "-e CAC_ROOTFS_DIR=/crossrootfs/x86"
2514                     }
2515
2516                     // Cross build the Ubuntu/arm product using docker with a docker image that contains the correct
2517                     // Ubuntu cross-compilation toolset (running on a Ubuntu x64 host).
2518                     // For CoreFX testing, we only need the product build; we don't need to generate the layouts. The product
2519                     // build is then copied into the corefx layout by the run-corefx-test.py script. For CoreFX testing, we
2520                     // ZIP up the generated CoreFX runtime and tests.
2521
2522                     def dockerImage = getDockerImageName(architecture, os, true)
2523                     def dockerCmd = "docker run -i --rm -v \${WORKSPACE}:\${WORKSPACE} -w \${WORKSPACE} -e ROOTFS_DIR=/crossrootfs/${architecture} ${additionalOpts} ${dockerImage} "
2524
2525                     buildCommands += "${dockerCmd}\${WORKSPACE}/build.sh ${lowerConfiguration} ${architecture} cross"
2526
2527                     if (doCoreFxTesting) {
2528                         def scriptFileName = "\$WORKSPACE/set_stress_test_env.sh"
2529
2530                         def envScriptCmds = envScriptCreate(os, scriptFileName)
2531                         envScriptCmds += envScriptSetStressModeVariables(os, Constants.jitStressModeScenarios[scenario], scriptFileName)
2532                         envScriptCmds += envScriptFinalize(os, scriptFileName)
2533                         buildCommands += envScriptCmds
2534
2535                         // Build and text corefx
2536                         def workspaceRelativeFxRootLinux = "_/fx"
2537                         def absoluteFxRoot = "\$WORKSPACE/${workspaceRelativeFxRootLinux}"
2538                         def fxBranch = getFxBranch(branch)
2539
2540                         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"
2541
2542                         // Docker creates files with root permission, so we need to zip in docker also, or else we'll get permission errors.
2543                         buildCommands += "${dockerCmd}zip -r ${workspaceRelativeFxRootLinux}/fxruntime.zip ${workspaceRelativeFxRootLinux}/artifacts/bin/testhost/netcoreapp-Linux-Release-${architecture}"
2544                         buildCommands += "${dockerCmd}zip -r ${workspaceRelativeFxRootLinux}/fxtests.zip ${workspaceRelativeFxRootLinux}/artifacts/bin/tests"
2545
2546                         Utilities.addArchival(newJob, "${workspaceRelativeFxRootLinux}/fxruntime.zip")
2547                         Utilities.addArchival(newJob, "${workspaceRelativeFxRootLinux}/fxtests.zip")
2548                     }
2549                     else if (isCrossGenComparisonScenario(scenario)) {
2550                         buildCommands += "${dockerCmd}\${WORKSPACE}/build-test.sh ${lowerConfiguration} ${architecture} cross generatelayoutonly"
2551
2552                         def workspaceRelativeProductBinDir = "bin/Product/${osGroup}.${architecture}.${configuration}"
2553                         def workspaceRelativeCoreLib = "${workspaceRelativeProductBinDir}/IL/System.Private.CoreLib.dll"
2554                         def workspaceRelativeCoreRootDir = "bin/tests/${osGroup}.${architecture}.${configuration}/Tests/Core_Root"
2555                         def workspaceRelativeCrossGenComparisonScript = "tests/scripts/crossgen_comparison.py"
2556                         def workspaceRelativeResultsDir = "_"
2557                         def workspaceRelativeArtifactsArchive = "${os}.${architecture}.${configuration}.${scenario}.zip"
2558                         def crossGenComparisonCmd = "python -u \${WORKSPACE}/${workspaceRelativeCrossGenComparisonScript} "
2559                         def crossArch = "x64"
2560                         def crossGenExecutable = "\${WORKSPACE}/${workspaceRelativeProductBinDir}/${crossArch}/crossgen"
2561                         def workspaceRelativeCrossArchResultDir = "${workspaceRelativeResultsDir}/${osGroup}.${crossArch}_${architecture}.${configuration}"
2562
2563                         buildCommands += "${dockerCmd}mkdir -p \${WORKSPACE}/${workspaceRelativeCrossArchResultDir}"
2564                         buildCommands += "${dockerCmd}${crossGenComparisonCmd}crossgen_corelib --crossgen ${crossGenExecutable} --il_corelib \${WORKSPACE}/${workspaceRelativeCoreLib} --result_dir \${WORKSPACE}/${workspaceRelativeCrossArchResultDir}"
2565                         buildCommands += "${dockerCmd}${crossGenComparisonCmd}crossgen_framework --crossgen ${crossGenExecutable} --core_root \${WORKSPACE}/${workspaceRelativeCoreRootDir} --result_dir \${WORKSPACE}/${workspaceRelativeCrossArchResultDir}"
2566
2567                         buildCommands += "${dockerCmd}zip -r ${workspaceRelativeArtifactsArchive} ${workspaceRelativeCoreLib} ${workspaceRelativeCoreRootDir} ${workspaceRelativeCrossGenComparisonScript} ${workspaceRelativeResultsDir}"
2568                         Utilities.addArchival(newJob, "${workspaceRelativeArtifactsArchive}")
2569                     }
2570                     else if (scenario == 'pmi_asm_diffs') {
2571                         buildCommands += "${dockerCmd}\${WORKSPACE}/build-test.sh ${lowerConfiguration} ${architecture} cross generatelayoutonly"
2572
2573                         // Pass `--skip_diffs` -- the actual diffs will be done on an arm machine in the test job. This is the build job.
2574                         // TODO: Add -target_branch and -commit_hash arguments based on GitHub variables.
2575                         buildCommands += "python -u \${WORKSPACE}/tests/scripts/run-pmi-diffs.py -arch ${architecture} -ci_arch ${architecture} -build_type ${configuration} --skip_diffs"
2576
2577                         // ZIP what we created.
2578                         buildCommands += "zip -r product.${os}.${architecture}.${lowerConfiguration}.zip ./bin/Product/Linux.${architecture}.${configuration}"
2579                         buildCommands += "zip -r product.baseline.${os}.${architecture}.${lowerConfiguration}.zip ./_/pmi/base/bin/Product/Linux.${architecture}.${configuration}"
2580                         buildCommands += "zip -r coreroot.${os}.${architecture}.${lowerConfiguration}.zip ./bin/tests/Linux.${architecture}.${configuration}/Tests/Core_Root"
2581                         buildCommands += "zip -r coreroot.baseline.${os}.${architecture}.${lowerConfiguration}.zip ./_/pmi/base/bin/tests/Linux.${architecture}.${configuration}/Tests/Core_Root"
2582
2583                         // Archive the built artifacts
2584                         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")
2585                     }
2586                     else {
2587                         // Then, using the same docker image, build the tests and generate the CORE_ROOT layout.
2588
2589                         def testBuildOpts = ""
2590                         if (priority == '1') {
2591                             testBuildOpts = "priority1"
2592                         }
2593
2594                         buildCommands += "${dockerCmd}\${WORKSPACE}/build-test.sh ${lowerConfiguration} ${architecture} cross ${testBuildOpts}"
2595
2596                         // 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)
2597                         def testArtifactsTgzFileName = getTestArtifactsTgzFileName(osGroup, architecture, configuration)
2598                         buildCommands += "tar -czf ${testArtifactsTgzFileName} bin/tests/${osGroup}.${architecture}.${configuration}"
2599
2600                         Utilities.addArchival(newJob, "${testArtifactsTgzFileName}", "")
2601                     }
2602
2603                     // Archive the build logs from both product and test builds.
2604                     Utilities.addArchival(newJob, "bin/Logs/*.log,bin/Logs/*.wrn,bin/Logs/*.err", "")
2605
2606                     // We need to clean up the build machines; the docker build leaves newly built files with root permission, which
2607                     // the cleanup task in Jenkins can't remove.
2608                     newJob.with {
2609                         publishers {
2610                             azureVMAgentPostBuildAction {
2611                                 agentPostBuildAction('Delete agent after build execution (when idle).')
2612                             }
2613                         }
2614                     }
2615                     break
2616                 default:
2617                     println("Unknown architecture: ${architecture}");
2618                     assert false
2619                     break
2620             }
2621             break
2622         // editor brace matching: }
2623         default:
2624             println("Unknown os: ${os}");
2625             assert false
2626             break
2627     } // os
2628
2629     return buildCommands
2630 }
2631
2632 // Determine if we should generate a job for the given parameters. This is for non-flow jobs: either build and test, or build only.
2633 // Returns true if the job should be generated.
2634 def static shouldGenerateJob(def scenario, def isPR, def architecture, def configuration, def os, def isBuildOnly)
2635 {
2636     // The various "innerloop" jobs are only available as PR triggered.
2637
2638     if (!isPR) {
2639         if (isInnerloopTestScenario(scenario)) {
2640             return false
2641         }
2642
2643         if (scenario == 'corefx_innerloop') {
2644             return false
2645         }
2646     }
2647
2648     // Tizen is only supported for armem architecture
2649     if (os == 'Tizen' && architecture != 'armem') {
2650         return false
2651     }
2652
2653     // Filter based on architecture.
2654
2655     switch (architecture) {
2656         case 'arm':
2657             if ((os != 'Windows_NT') && (os != 'Ubuntu')) {
2658                 return false
2659             }
2660             break
2661         case 'arm64':
2662             if ((os != 'Windows_NT') && (os != 'Ubuntu16.04')) {
2663                 return false
2664             }
2665             break
2666         case 'armem':
2667             if (os != 'Tizen') {
2668                 return false
2669             }
2670             break
2671         case 'x86_arm_altjit':
2672         case 'x64_arm64_altjit':
2673             if (os != 'Windows_NT') {
2674                 return false
2675             }
2676             break
2677         case 'x86':
2678             if ((os != 'Windows_NT') && (os != 'Ubuntu')) {
2679                 return false
2680             }
2681             break
2682         case 'x64':
2683             // Everything implemented
2684             break
2685         default:
2686             println("Unknown architecture: ${architecture}")
2687             assert false
2688             break
2689     }
2690
2691     // Which (Windows) build only jobs are required?
2692
2693     def isNormalOrInnerloop = (scenario == 'innerloop' || scenario == 'normal')
2694
2695     if (isBuildOnly) {
2696         switch (architecture) {
2697             case 'arm':
2698             case 'arm64':
2699                 // We use build only jobs for Windows arm/arm64 cross-compilation corefx testing, so we need to generate builds for that.
2700                 if (!isCoreFxScenario(scenario)) {
2701                     return false
2702                 }
2703                 break
2704             case 'x64':
2705             case 'x86':
2706                 if (!isNormalOrInnerloop) {
2707                     return false
2708                 }
2709                 break
2710             default:
2711                 return false
2712         }
2713     }
2714
2715     // Filter based on scenario.
2716
2717     if (isJitStressScenario(scenario)) {
2718         if (configuration != 'Checked') {
2719             return false
2720         }
2721
2722         def isEnabledOS = (os == 'Windows_NT') ||
2723                           (os == 'Ubuntu' && (architecture == 'x64') && isCoreFxScenario(scenario)) ||
2724                           (os == 'Ubuntu' && architecture == 'arm') ||
2725                           (os == 'Ubuntu16.04' && architecture == 'arm64')
2726         if (!isEnabledOS) {
2727             return false
2728         }
2729
2730         switch (architecture) {
2731             case 'x64':
2732             case 'x86_arm_altjit':
2733             case 'x64_arm64_altjit':
2734                 break
2735
2736             case 'x86':
2737                 // x86 ubuntu: no stress modes
2738                 if (os == 'Ubuntu') {
2739                     return false
2740                 }
2741                 break
2742
2743             case 'arm':
2744             case 'arm64':
2745                 // We use build only jobs for Windows arm/arm64 cross-compilation corefx testing, so we need to generate builds for that.
2746                 // No "regular" Windows arm corefx jobs, e.g.
2747                 // For Ubuntu arm corefx testing, we use regular jobs (not "build only" since only Windows has "build only", and
2748                 // the Ubuntu arm "regular" jobs don't run tests anyway).
2749                 if (os == 'Windows_NT') {
2750                     if (! (isBuildOnly && isCoreFxScenario(scenario)) ) {
2751                         return false
2752                     }
2753                 }
2754                 else {
2755                     if (!isCoreFxScenario(scenario)) {
2756                         return false
2757                     }
2758                 }
2759                 break
2760
2761             default:
2762                 // armem: no stress jobs for ARM emulator.
2763                 return false
2764         }
2765     }
2766     else if (isR2RScenario(scenario)) {
2767         if (os != 'Windows_NT') {
2768             return false
2769         }
2770
2771         if (isR2RBaselineScenario(scenario)) {
2772             // no need for Debug scenario; Checked is sufficient
2773             if (configuration != 'Checked' && configuration != 'Release') {
2774                 return false
2775             }
2776         }
2777         else if (isR2RStressScenario(scenario)) {
2778             // Stress scenarios only run with Checked builds, not Release (they would work with Debug, but be slow).
2779             if (configuration != 'Checked') {
2780                 return false
2781             }
2782         }
2783
2784         switch (architecture) {
2785             case 'arm':
2786             case 'arm64':
2787                 // Windows arm/arm64 ready-to-run jobs use flow jobs and test jobs, but depend on "normal" (not R2R specific) build jobs.
2788                 return false
2789
2790             default:
2791                 break
2792         }
2793     }
2794     else if (isCrossGenComparisonScenario(scenario)) {
2795         return shouldGenerateCrossGenComparisonJob(os, architecture, configuration, scenario)
2796     }
2797     else {
2798         // Skip scenarios
2799         switch (scenario) {
2800             case 'ilrt':
2801                 // The ilrt build isn't necessary except for Windows_NT2003.  Non-Windows NT uses
2802                 // the default scenario build
2803                 if (os != 'Windows_NT') {
2804                     return false
2805                 }
2806                 // Only x64 for now
2807                 if (architecture != 'x64') {
2808                     return false
2809                 }
2810                 // Release only
2811                 if (configuration != 'Release') {
2812                     return false
2813                 }
2814                 break
2815             case 'jitdiff':
2816                 if (os != 'Windows_NT' && os != 'Ubuntu' && os != 'OSX10.12') {
2817                     return false
2818                 }
2819                 if (architecture != 'x64') {
2820                     return false
2821                 }
2822                 if (configuration != 'Checked') {
2823                     return false
2824                 }
2825                 break
2826             case 'longgc':
2827             case 'gcsimulator':
2828                 if (os != 'Windows_NT' && os != 'Ubuntu' && os != 'OSX10.12') {
2829                     return false
2830                 }
2831                 if (architecture != 'x64') {
2832                     return false
2833                 }
2834                 if (configuration != 'Release') {
2835                     return false
2836                 }
2837                 break
2838             case 'gc_reliability_framework':
2839             case 'standalone_gc':
2840                 if (os != 'Windows_NT' && os != 'Ubuntu' && os != 'OSX10.12') {
2841                     return false
2842                 }
2843
2844                 if (architecture != 'x64') {
2845                     return false
2846                 }
2847
2848                 if (configuration != 'Release' && configuration != 'Checked') {
2849                     return false
2850                 }
2851                 break
2852             // We only run Windows and Ubuntu x64 Checked for formatting right now
2853             case 'formatting':
2854                 if (os != 'Windows_NT' && os != 'Ubuntu') {
2855                     return false
2856                 }
2857                 if (architecture != 'x64') {
2858                     return false
2859                 }
2860                 if (configuration != 'Checked') {
2861                     return false
2862                 }
2863                 break
2864             case 'illink':
2865                 if (os != 'Windows_NT' && (os != 'Ubuntu' || architecture != 'x64')) {
2866                     return false
2867                 }
2868                 if (architecture != 'x64' && architecture != 'x86') {
2869                     return false
2870                 }
2871                 break
2872             case 'normal':
2873                 // Nothing skipped
2874                 break
2875             case 'innerloop':
2876                 if (!isValidPrTriggeredInnerLoopJob(os, architecture, configuration, isBuildOnly)) {
2877                     return false
2878                 }
2879                 break
2880             case 'corefx_innerloop':
2881                 if (os != 'Windows_NT' && os != 'Ubuntu' &&  os != 'OSX10.12') {
2882                     return false
2883                 }
2884                 if (architecture != 'x64') {
2885                     return false
2886                 }
2887                 break
2888             case 'pmi_asm_diffs':
2889                 if (configuration != 'Checked') {
2890                     return false
2891                 }
2892                 if (architecture == 'armem') {
2893                     return false
2894                 }
2895                 // Currently, we don't support pmi_asm_diffs for Windows arm/arm64. We don't have a dotnet CLI available to
2896                 // build jitutils. The jobs are not in validArmWindowsScenarios.
2897                 if ((os == 'Windows_NT') && (architecture == 'arm' || architecture == 'arm64')) {
2898                     return false
2899                 }
2900                 // Currently, no support for Linux x86.
2901                 if ((os != 'Windows_NT') && (architecture == 'x86')) {
2902                     return false
2903                 }
2904                 break
2905             default:
2906                 println("Unknown scenario: ${scenario}")
2907                 assert false
2908                 break
2909         }
2910     }
2911
2912     // For altjit, don't do any scenarios that don't change compilation. That is, scenarios that only change
2913     // runtime behavior, not compile-time behavior, are not interesting.
2914     switch (architecture) {
2915         case 'x86_arm_altjit':
2916         case 'x64_arm64_altjit':
2917             if (isGCStressRelatedTesting(scenario)) {
2918                 return false
2919             }
2920             break
2921         default:
2922             break
2923     }
2924
2925     // The job was not filtered out, so we should generate it!
2926     return true
2927 }
2928
2929 Constants.allScenarios.each { scenario ->
2930     [true, false].each { isPR ->
2931         Constants.architectureList.each { architecture ->
2932             Constants.configurationList.each { configuration ->
2933                 Constants.osList.each { os ->
2934                     // If the OS is Windows_NT_BuildOnly, set the isBuildOnly flag to true
2935                     // and reset the os to Windows_NT
2936                     def isBuildOnly = false
2937                     if (os == 'Windows_NT_BuildOnly') {
2938                         isBuildOnly = true
2939                         os = 'Windows_NT'
2940                     }
2941
2942                     if (!shouldGenerateJob(scenario, isPR, architecture, configuration, os, isBuildOnly)) {
2943                         return
2944                     }
2945
2946                     // Calculate names
2947                     def jobName = getJobName(configuration, architecture, os, scenario, isBuildOnly)
2948                     def folderName = getJobFolder(scenario)
2949
2950                     // Create the new job
2951                     def newJob = job(Utilities.getFullJobName(project, jobName, isPR, folderName)) {}
2952
2953                     addToViews(newJob, false, isPR, architecture, os, configuration, scenario) // isFlowJob == false
2954
2955                     setJobMachineAffinity(architecture, os, true, false, false, newJob) // isBuildJob = true, isTestJob = false, isFlowJob = false
2956
2957                     Utilities.standardJobSetup(newJob, project, isPR, "*/${branch}")
2958                     addTriggers(newJob, branch, isPR, architecture, os, configuration, scenario, false, isBuildOnly) // isFlowJob==false
2959                     setJobTimeout(newJob, isPR, architecture, configuration, scenario, isBuildOnly)
2960
2961                     // Copy Windows build test binaries and corefx build artifacts for Linux cross build for armem.
2962                     // We don't use a flow job for this, but we do depend on there being existing builds with these
2963                     // artifacts produced.
2964                     if ((architecture == 'armem') && (os == 'Tizen')) {
2965                         // Define the Windows Tests and Corefx build job names
2966                         def lowerConfiguration = configuration.toLowerCase()
2967                         def WindowsTestsName = projectFolder + '/' +
2968                                                Utilities.getFullJobName(project,
2969                                                                         getJobName(lowerConfiguration, 'x64' , 'windows_nt', 'normal', true),
2970                                                                         false)
2971                         def fxBranch = getFxBranch(branch)
2972                         def corefxFolder = Utilities.getFolderName('dotnet/corefx') + '/' +
2973                                            Utilities.getFolderName(fxBranch)
2974
2975                         def arm_abi = 'armel'
2976                         def corefx_os = 'tizen'
2977
2978                         // Let's use release CoreFX to test checked CoreCLR,
2979                         // because we do not generate checked CoreFX in CoreFX CI yet.
2980                         def corefx_lowerConfiguration = lowerConfiguration
2981                         if (lowerConfiguration == 'checked') {
2982                             corefx_lowerConfiguration = 'release'
2983                         }
2984
2985                         // Copy the Windows test binaries and the Corefx build binaries
2986                         newJob.with {
2987                             steps {
2988                                 copyArtifacts(WindowsTestsName) {
2989                                     includePatterns('bin/tests/tests.zip')
2990                                     buildSelector {
2991                                         latestSuccessful(true)
2992                                     }
2993                                 }
2994                                 copyArtifacts("${corefxFolder}/${corefx_os}_${arm_abi}_cross_${corefx_lowerConfiguration}") {
2995                                     includePatterns('artifacts/bin/build.tar.gz')
2996                                     buildSelector {
2997                                         latestSuccessful(true)
2998                                     }
2999                                 }
3000                             } // steps
3001                         } // newJob.with
3002                     }
3003
3004                     def buildCommands = calculateBuildCommands(newJob, scenario, branch, isPR, architecture, configuration, os, isBuildOnly)
3005
3006                     newJob.with {
3007                         steps {
3008                             if (os == 'Windows_NT') {
3009                                 buildCommands.each { buildCommand ->
3010                                     batchFile(buildCommand)
3011                                 }
3012                             }
3013                             else {
3014                                 buildCommands.each { buildCommand ->
3015                                     shell(buildCommand)
3016                                 }
3017                             }
3018                         } // steps
3019                     } // newJob.with
3020
3021                 } // os
3022             } // configuration
3023         } // architecture
3024     } // isPR
3025 } // scenario
3026
3027 // Create a Windows ARM/ARM64 test job that will be used by a flow job.
3028 // Returns the newly created job.
3029 def static CreateWindowsArmTestJob(def dslFactory, def project, def architecture, def os, def configuration, def scenario, def isPR, def inputCoreCLRBuildName)
3030 {
3031     def osGroup = getOSGroup(os)
3032     def jobName = getJobName(configuration, architecture, os, scenario, false) + "_tst"
3033
3034     def jobFolder = getJobFolder(scenario)
3035     def newJob = dslFactory.job(Utilities.getFullJobName(project, jobName, isPR, jobFolder)) {
3036         parameters {
3037             stringParam('CORECLR_BUILD', '', "Build number to copy CoreCLR ${osGroup} binaries from")
3038         }
3039
3040         steps {
3041             // Set up the copies
3042
3043             // Coreclr build we are trying to test
3044             //
3045             //  ** NOTE ** This will, correctly, overwrite the CORE_ROOT from the Windows test archive
3046
3047             copyArtifacts(inputCoreCLRBuildName) {
3048                 excludePatterns('**/testResults.xml', '**/*.ni.dll')
3049                 buildSelector {
3050                     buildNumber('${CORECLR_BUILD}')
3051                 }
3052             }
3053
3054             if (isCoreFxScenario(scenario)) {
3055
3056                 // Only arm/arm64 supported for corefx testing now.
3057                 assert architecture == 'arm' || architecture == 'arm64'
3058
3059                 // Unzip CoreFx runtime
3060                 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}')\"")
3061
3062                 // Unzip CoreFx tests.
3063                 batchFile("powershell -NoProfile -Command \"Add-Type -Assembly 'System.IO.Compression.FileSystem'; [System.IO.Compression.ZipFile]::ExtractToDirectory('_\\fx\\fxtests.zip', '_\\fx\\artifacts\\bin\\tests')\"")
3064
3065                 // Add the script to run the corefx tests
3066                 def corefx_runtime_path   = "%WORKSPACE%\\_\\fx\\artifacts\\bin\\testhost\\netcoreapp-Windows_NT-Release-${architecture}"
3067                 def corefx_tests_dir      = "%WORKSPACE%\\_\\fx\\artifacts\\bin\\tests"
3068                 def corefx_exclusion_file = "%WORKSPACE%\\tests\\${architecture}\\corefx_test_exclusions.txt"
3069                 batchFile("call %WORKSPACE%\\tests\\scripts\\run-corefx-tests.bat ${corefx_runtime_path} ${corefx_tests_dir} ${corefx_exclusion_file} ${architecture}")
3070
3071             } else { // !isCoreFxScenario(scenario)
3072
3073                 // Unzip tests.
3074                 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}')\"")
3075
3076                 def buildCommands = ""
3077
3078                 def coreRootLocation = "%WORKSPACE%\\bin\\tests\\Windows_NT.${architecture}.${configuration}\\Tests\\Core_Root"
3079                 def addEnvVariable =  { variable, value -> buildCommands += "set ${variable}=${value}\r\n"}
3080                 def addCommand = { cmd -> buildCommands += "${cmd}\r\n"}
3081
3082                 // Make sure Command Extensions are enabled. Used so %ERRORLEVEL% is available.
3083                 addCommand("SETLOCAL ENABLEEXTENSIONS")
3084
3085                 // For all jobs 
3086                 addEnvVariable("CORE_ROOT", coreRootLocation)
3087                 addEnvVariable("COMPlus_NoGuiOnAssert", "1")
3088                 addEnvVariable("COMPlus_ContinueOnAssert", "0")
3089
3090                 // If we are running a stress mode, we'll set those variables as well
3091                 if (isJitStressScenario(scenario) || isR2RStressScenario(scenario)) {
3092                     def stressValues = null
3093                     if (isJitStressScenario(scenario)) {
3094                         stressValues = Constants.jitStressModeScenarios[scenario]
3095                     }
3096                     else {
3097                         stressValues = Constants.r2rStressScenarios[scenario]
3098                     }
3099
3100                     stressValues.each { key, value -> 
3101                         addEnvVariable(key, value)
3102                     }
3103                 }
3104
3105                 if (isR2RScenario(scenario)) {
3106                     // Crossgen the framework assemblies.
3107                     buildCommands += """
3108 @for %%F in (%CORE_ROOT%\\*.dll) do @call :PrecompileAssembly "%CORE_ROOT%" "%%F" %%~nxF
3109 @goto skip_PrecompileAssembly
3110
3111 :PrecompileAssembly
3112 @REM Skip mscorlib since it is already precompiled.
3113 @if /I "%3" == "mscorlib.dll" exit /b 0
3114 @if /I "%3" == "mscorlib.ni.dll" exit /b 0
3115
3116 "%CORE_ROOT%\\crossgen.exe" /Platform_Assemblies_Paths "%CORE_ROOT%" %2 >nul 2>nul
3117 @if "%errorlevel%" == "-2146230517" (
3118     echo %2 is not a managed assembly.
3119 ) else if "%errorlevel%" == "-2146234344" (
3120     echo %2 is not a managed assembly.
3121 ) else if %errorlevel% neq 0 (
3122     echo Unable to precompile %2
3123 ) else (
3124     echo Precompiled %2
3125 )
3126 @exit /b 0
3127
3128 :skip_PrecompileAssembly
3129 """
3130
3131                     // Set RunCrossGen variable to cause test wrappers to invoke their logic to run
3132                     // crossgen on tests before running them.
3133                     addEnvVariable("RunCrossGen", "true")
3134                 } // isR2RScenario(scenario)
3135
3136                 // Run runtest.cmd
3137                 // Do not run generate layout. It will delete the correct CORE_ROOT, and we do not have a correct product
3138                 // dir to copy from.
3139                 def runtestCommand = "%WORKSPACE%\\tests\\runtest.cmd ${architecture} ${configuration} skipgeneratelayout"
3140
3141                 addCommand("${runtestCommand}")
3142
3143                 // Use the smarty errorlevel as the script errorlevel.
3144                 addCommand("exit /b %errorlevel%")
3145
3146                 batchFile(buildCommands)
3147             } // non-corefx testing
3148         } // steps
3149     } // job
3150
3151     if (!isCoreFxScenario(scenario)) {
3152         Utilities.addXUnitDotNETResults(newJob, 'bin/**/TestRun*.xml', true)
3153     }
3154
3155     return newJob
3156 }
3157
3158 // Create a test job not covered by the "Windows ARM" case that will be used by a flow job.
3159 // E.g., non-Windows tests.
3160 // Returns the newly created job.
3161 def static CreateOtherTestJob(def dslFactory, def project, def branch, def architecture, def os, def configuration, def scenario, def isPR, def inputCoreCLRBuildName)
3162 {
3163     def lowerConfiguration = configuration.toLowerCase()
3164
3165     def isUbuntuArm64Job = ((os == "Ubuntu16.04") && (architecture == 'arm64'))
3166     def isUbuntuArm32Job = ((os == "Ubuntu") && (architecture == 'arm'))
3167     def isUbuntuArmJob = isUbuntuArm32Job || isUbuntuArm64Job
3168
3169     def doCoreFxTesting = isCoreFxScenario(scenario)
3170     def isPmiAsmDiffsScenario = (scenario == 'pmi_asm_diffs')
3171
3172     def workspaceRelativeFxRootLinux = "_/fx" // only used for CoreFX testing
3173
3174     def osGroup = getOSGroup(os)
3175     def jobName = getJobName(configuration, architecture, os, scenario, false) + "_tst"
3176
3177     def testOpts = ''
3178     def useServerGC = false
3179
3180     // Enable Server GC for Ubuntu PR builds
3181     // REVIEW: why? Does this apply to all architectures? Why only PR?
3182     if (os == 'Ubuntu' && isPR) {
3183         testOpts += ' --useServerGC'
3184         useServerGC = true
3185     }
3186
3187     if (isR2RScenario(scenario)) {
3188
3189         testOpts += ' --crossgen --runcrossgentests'
3190
3191         if (scenario == 'r2r_jitstress1') {
3192             testOpts += ' --jitstress=1'
3193         }
3194         else if (scenario == 'r2r_jitstress2') {
3195             testOpts += ' --jitstress=2'
3196         }
3197         else if (scenario == 'r2r_jitstress1_tiered') {
3198             testOpts += ' --jitstress=1'
3199         }
3200         else if (scenario == 'r2r_jitstress2_tiered') {
3201             testOpts += ' --jitstress=2'
3202         }
3203         else if (scenario == 'r2r_jitstressregs1') {
3204             testOpts += ' --jitstressregs=1'
3205         }
3206         else if (scenario == 'r2r_jitstressregs2') {
3207             testOpts += ' --jitstressregs=2'
3208         }
3209         else if (scenario == 'r2r_jitstressregs3') {
3210             testOpts += ' --jitstressregs=3'
3211         }
3212         else if (scenario == 'r2r_jitstressregs4') {
3213             testOpts += ' --jitstressregs=4'
3214         }
3215         else if (scenario == 'r2r_jitstressregs8') {
3216             testOpts += ' --jitstressregs=8'
3217         }
3218         else if (scenario == 'r2r_jitstressregs0x10') {
3219             testOpts += ' --jitstressregs=0x10'
3220         }
3221         else if (scenario == 'r2r_jitstressregs0x80') {
3222             testOpts += ' --jitstressregs=0x80'
3223         }
3224         else if (scenario == 'r2r_jitstressregs0x1000') {
3225             testOpts += ' --jitstressregs=0x1000'
3226         }
3227         else if (scenario == 'r2r_jitminopts') {
3228             testOpts += ' --jitminopts'
3229         }
3230         else if (scenario == 'r2r_jitforcerelocs') {
3231             testOpts += ' --jitforcerelocs'
3232         }
3233         else if (scenario == 'r2r_gcstress15') {
3234             testOpts += ' --gcstresslevel=0xF'
3235         }
3236     }
3237     else if (scenario == 'jitdiff') {
3238         testOpts += ' --jitdisasm --crossgen'
3239     }
3240     else if (scenario == 'illink') {
3241         testOpts += ' --link=\$WORKSPACE/linker/linker/bin/netcore_Release/netcoreapp2.0/ubuntu-x64/publish/illink'
3242     }
3243     else if (isLongGc(scenario)) {
3244         // Long GC tests behave very poorly when they are not
3245         // the only test running (many of them allocate until OOM).
3246         testOpts += ' --sequential'
3247
3248         // A note - runtest.sh does have "--long-gc" and "--gcsimulator" options
3249         // for running long GC and GCSimulator tests, respectively. We don't use them
3250         // here because using a playlist file produces much more readable output on the CI machines
3251         // and reduces running time.
3252         //
3253         // The Long GC playlist contains all of the tests that are
3254         // going to be run. The GCSimulator playlist contains all of
3255         // the GC simulator tests.
3256         if (scenario == 'longgc') {
3257             testOpts += ' --long-gc --playlist=./tests/longRunningGcTests.txt'
3258         }
3259         else if (scenario == 'gcsimulator') {
3260             testOpts += ' --gcsimulator --playlist=./tests/gcSimulatorTests.txt'
3261         }
3262     }
3263     else if (isGcReliabilityFramework(scenario)) {
3264         testOpts += ' --build-overlay-only'
3265     }
3266     else if (scenario == 'standalone_gc') {
3267         if (osGroup == 'OSX') {
3268             testOpts += ' --gcname=libclrgc.dylib'
3269         }
3270         else if (osGroup == 'Linux') {
3271             testOpts += ' --gcname=libclrgc.so'
3272         }
3273         else {
3274             println("Unexpected OS group: ${osGroup} for os ${os}")
3275             assert false
3276         }
3277     }
3278
3279     def jobFolder = getJobFolder(scenario)
3280     def newJob = dslFactory.job(Utilities.getFullJobName(project, jobName, isPR, jobFolder)) {
3281         parameters {
3282             stringParam('CORECLR_BUILD', '', "Build number to copy CoreCLR ${osGroup} binaries from")
3283         }
3284
3285         steps {
3286             // Set up the copies
3287
3288             // Coreclr build we are trying to test
3289             //
3290             // HACK: the Ubuntu arm64 copyArtifacts Jenkins plug-in is ridiculously slow (45 minutes to
3291             // 1.5 hours for this step). Instead, directly use wget, which is fast (1 minute).
3292
3293             if (!isUbuntuArm64Job) {
3294                 copyArtifacts(inputCoreCLRBuildName) {
3295                     excludePatterns('**/testResults.xml', '**/*.ni.dll')
3296                     buildSelector {
3297                         buildNumber('${CORECLR_BUILD}')
3298                     }
3299                 }
3300             }
3301
3302             if (isUbuntuArmJob) {
3303                 // Add some useful information to the log file. Ignore return codes.
3304                 shell("uname -a || true")
3305             }
3306
3307             if (isUbuntuArm64Job) {
3308                 // Copy the required artifacts directly, using wget, e.g.:
3309                 // 
3310                 //  https://ci.dot.net/job/dotnet_coreclr/job/master/job/arm64_cross_checked_ubuntu16.04_innerloop_prtest/16/artifact/testnativebin.checked.zip
3311                 //  https://ci.dot.net/job/dotnet_coreclr/job/master/job/arm64_cross_checked_ubuntu16.04_innerloop_prtest/16/artifact/tests.checked.zip
3312                 // 
3313                 // parameterized as:
3314                 //
3315                 //  https://ci.dot.net/job/${mungedProjectName}/job/${mungedBranchName}/job/${inputJobName}/${CORECLR_BUILD}/artifact/testnativebin.checked.zip
3316                 //  https://ci.dot.net/job/${mungedProjectName}/job/${mungedBranchName}/job/${inputJobName}/${CORECLR_BUILD}/artifact/tests.checked.zip
3317                 //
3318                 // CoreFX example artifact URLs:
3319                 //
3320                 //  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
3321                 //  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
3322                 //
3323                 // Note that the source might be in a "jitstress" folder.
3324                 //
3325                 // Use `--progress=dot:giga` to display some progress output, but limit it in the log file.
3326                 //
3327                 // Use `--directory-prefix=_/fx` to specify where to put the corefx files (to match what other platforms do). Use this instead of `-O`.
3328
3329                 shell("echo \"Using wget instead of the Jenkins copy artifacts plug-in to copy artifacts from ${inputCoreCLRBuildName}\"")
3330
3331                 def mungedProjectName = Utilities.getFolderName(project)
3332                 def mungedBranchName = Utilities.getFolderName(branch)
3333
3334                 def doCrossGenComparison = isCrossGenComparisonScenario(scenario)
3335                 def inputCoreCLRBuildScenario = isInnerloopTestScenario(scenario) ? 'innerloop' : 'normal'
3336                 if (isPmiAsmDiffsScenario || doCoreFxTesting || doCrossGenComparison) {
3337                     // These depend on unique builds for each scenario
3338                     inputCoreCLRBuildScenario = scenario
3339                 }
3340                 def sourceJobName = getJobName(configuration, architecture, os, inputCoreCLRBuildScenario, false)
3341                 def inputJobName = Utilities.getFullJobName(sourceJobName, isPR)
3342
3343                 // Need to add the sub-folder if necessary.
3344                 def inputJobPath = "job/${inputJobName}"
3345                 def folderName = getJobFolder(inputCoreCLRBuildScenario)
3346                 if (folderName != '') {
3347                     inputJobPath = "job/${folderName}/job/${inputJobName}"
3348                 }
3349
3350                 def inputUrlRoot = "https://ci.dot.net/job/${mungedProjectName}/job/${mungedBranchName}/${inputJobPath}/\${CORECLR_BUILD}/artifact"
3351
3352                 if (isPmiAsmDiffsScenario) {
3353                     def workspaceRelativeRootLinux = "_/pmi"
3354                     shell("mkdir -p ${workspaceRelativeRootLinux}")
3355                     shell("wget --progress=dot:giga ${inputUrlRoot}/product.${os}.${architecture}.${lowerConfiguration}.zip")
3356                     shell("wget --progress=dot:giga ${inputUrlRoot}/product.baseline.${os}.${architecture}.${lowerConfiguration}.zip")
3357                     shell("wget --progress=dot:giga ${inputUrlRoot}/coreroot.${os}.${architecture}.${lowerConfiguration}.zip")
3358                     shell("wget --progress=dot:giga ${inputUrlRoot}/coreroot.baseline.${os}.${architecture}.${lowerConfiguration}.zip")
3359                 }
3360                 else if (doCoreFxTesting) {
3361                     shell("mkdir -p ${workspaceRelativeFxRootLinux}")
3362                     shell("wget --progress=dot:giga --directory-prefix=${workspaceRelativeFxRootLinux} ${inputUrlRoot}/${workspaceRelativeFxRootLinux}/fxtests.zip")
3363                     shell("wget --progress=dot:giga --directory-prefix=${workspaceRelativeFxRootLinux} ${inputUrlRoot}/${workspaceRelativeFxRootLinux}/fxruntime.zip")
3364                 }
3365                 else {
3366                     def testArtifactsTgzFileName = getTestArtifactsTgzFileName(osGroup, architecture, configuration)
3367                     shell("wget --progress=dot:giga ${inputUrlRoot}/${testArtifactsTgzFileName}")
3368                 }
3369             }
3370
3371             if (architecture == 'x86') {
3372                 shell("mkdir ./bin/CoreFxNative")
3373
3374                 def fxBranch = getFxBranch(branch)
3375                 def corefxFolder = Utilities.getFolderName('dotnet/corefx') + '/' + Utilities.getFolderName(fxBranch)
3376
3377                 copyArtifacts("${corefxFolder}/ubuntu16.04_x86_release") {
3378                     includePatterns('artifacts/bin/build.tar.gz')
3379                     targetDirectory('bin/CoreFxNative')
3380                     buildSelector {
3381                         latestSuccessful(true)
3382                     }
3383                 }
3384
3385                 shell("mkdir ./bin/CoreFxBinDir")
3386                 shell("tar -xf ./bin/CoreFxNative/artifacts/bin/build.tar.gz -C ./bin/CoreFxBinDir")
3387             }
3388
3389             if (isPmiAsmDiffsScenario) {
3390                 // TODO: add back "-q" when we know it works
3391                 shell("unzip -o ./product.${os}.${architecture}.${lowerConfiguration}.zip || exit 0")
3392                 shell("unzip -o ./product.baseline.${os}.${architecture}.${lowerConfiguration}.zip || exit 0")
3393                 shell("unzip -o ./coreroot.${os}.${architecture}.${lowerConfiguration}.zip || exit 0")
3394                 shell("unzip -o ./coreroot.baseline.${os}.${architecture}.${lowerConfiguration}.zip || exit 0")
3395             }
3396             // CoreFX testing downloads the CoreFX tests, not the coreclr tests. Also, unzip the built CoreFX layout/runtime directories.
3397             else if (doCoreFxTesting) {
3398                 shell("unzip -q -o ${workspaceRelativeFxRootLinux}/fxtests.zip || exit 0")
3399                 shell("unzip -q -o ${workspaceRelativeFxRootLinux}/fxruntime.zip || exit 0")
3400             }
3401             else {
3402                 def testArtifactsTgzFileName = getTestArtifactsTgzFileName(osGroup, architecture, configuration)
3403                 shell("tar -xzf ./${testArtifactsTgzFileName} || exit 0") // extracts to ./bin/tests/${osGroup}.${architecture}.${configuration}
3404             }
3405
3406             // Execute the tests
3407             def runDocker = isNeedDocker(architecture, os, false)
3408             def dockerPrefix = ""
3409             def dockerCmd = ""
3410             if (runDocker) {
3411                 def dockerImage = getDockerImageName(architecture, os, false)
3412                 dockerPrefix = "docker run -i --rm -v \${WORKSPACE}:\${WORKSPACE} -w \${WORKSPACE} "
3413                 dockerCmd = dockerPrefix + "${dockerImage} "
3414             }
3415
3416             // If we are running a stress mode, we'll set those variables first.
3417             // For CoreFX, the stress variables are already built into the CoreFX test build per-test wrappers.
3418             if (!doCoreFxTesting && isJitStressScenario(scenario)) {
3419                 def scriptFileName = "\${WORKSPACE}/set_stress_test_env.sh"
3420                 def envScriptCmds = envScriptCreate(os, scriptFileName)
3421                 envScriptCmds += envScriptSetStressModeVariables(os, Constants.jitStressModeScenarios[scenario], scriptFileName)
3422                 envScriptCmds += envScriptFinalize(os, scriptFileName)
3423                 shell("${envScriptCmds}")
3424                 testOpts += " --test-env=${scriptFileName}"
3425             }
3426
3427             // setup-stress-dependencies.sh, invoked by runtest.sh to download the coredistools package, depends on the "dotnet"
3428             // tool downloaded by the "init-tools.sh" script. However, it only invokes setup-stress-dependencies.sh for x64. The
3429             // coredistools package is used by GCStress on x86 and x64 to disassemble code to determine instruction boundaries.
3430             // On arm/arm64, it is not required as determining instruction boundaries is trivial.
3431             if (isGCStressRelatedTesting(scenario)) {
3432                 if (architecture == 'x64') {
3433                     shell('./init-tools.sh')
3434                 }
3435             }
3436
3437             if (isPmiAsmDiffsScenario) {
3438                 shell("""\
3439 python -u \${WORKSPACE}/tests/scripts/run-pmi-diffs.py -arch ${architecture} -ci_arch ${architecture} -build_type ${configuration} --skip_baseline_build""")
3440
3441                 shell("zip -r dasm.${os}.${architecture}.${configuration}.zip ./_/pmi/asm")
3442             }
3443             else if (doCoreFxTesting) {
3444                 shell("""\
3445 \${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""")
3446             }
3447             else {
3448                 def runScript = "${dockerCmd}./tests/runtest.sh"
3449
3450                 shell("""\
3451 ${runScript} \\
3452     ${lowerConfiguration} \\
3453     --testRootDir=\"\${WORKSPACE}/bin/tests/${osGroup}.${architecture}.${configuration}\" \\
3454     --coreOverlayDir=\"\${WORKSPACE}/bin/tests/${osGroup}.${architecture}.${configuration}/Tests/Core_Root\" \\
3455     --limitedDumpGeneration ${testOpts}""")
3456             }
3457
3458             if (isGcReliabilityFramework(scenario)) {
3459                 // runtest.sh doesn't actually execute the reliability framework - do it here.
3460                 if (useServerGC) {
3461                     if (runDocker) {
3462                         dockerCmd = dockerPrefix + "-e COMPlus_gcServer=1 ${dockerImage} "
3463                     }
3464                     else {
3465                         shell("export COMPlus_gcServer=1")
3466                     }
3467                 }
3468
3469                 shell("${dockerCmd}./tests/scripts/run-gc-reliability-framework.sh ${architecture} ${configuration}")
3470             }
3471         } // steps
3472     } // job
3473
3474     // Experimental: If on Ubuntu 14.04, then attempt to pull in crash dump links
3475     if (os in ['Ubuntu']) {
3476         SummaryBuilder summaries = new SummaryBuilder()
3477         summaries.addLinksSummaryFromFile('Crash dumps from this run:', 'dumplings.txt')
3478         summaries.emit(newJob)
3479     }
3480
3481     if (isPmiAsmDiffsScenario) {
3482         // Archive the asm
3483         Utilities.addArchival(newJob, "dasm.${os}.${architecture}.${configuration}.zip")
3484     }
3485     else if (doCoreFxTesting) {
3486         Utilities.addArchival(newJob, "${workspaceRelativeFxRootLinux}/artifacts/bin/**/testResults.xml")
3487         if ((os == "Ubuntu") && (architecture == 'arm')) {
3488             // We have a problem with the xunit plug-in, where it is consistently failing on Ubuntu arm32 test result uploading with this error:
3489             //
3490             //   [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
3491             //
3492             // We haven't been able to identify the reason. So, do not add xunit parsing of the test data in this scenario.
3493             // This is tracked by: https://github.com/dotnet/coreclr/issues/19447.
3494         }
3495         else {
3496             Utilities.addXUnitDotNETResults(newJob, "${workspaceRelativeFxRootLinux}/artifacts/bin/**/testResults.xml")
3497         }
3498     }
3499     else {
3500         Utilities.addXUnitDotNETResults(newJob, '**/coreclrtests.xml')
3501     }
3502
3503     return newJob
3504 }
3505
3506 def static CreateNonWindowsCrossGenComparisonTestJob(def dslFactory, def project, def architecture, def os, def configuration, def scenario, def isPR, def inputCoreCLRBuildName)
3507 {
3508     assert isCrossGenComparisonScenario(scenario)
3509
3510     def osGroup = getOSGroup(os)
3511     def jobName = getJobName(configuration, architecture, os, scenario, false) + "_tst"
3512
3513     def workspaceRelativeResultsDir = "_"
3514     def workspaceRelativeNativeArchResultDir = "${workspaceRelativeResultsDir}/${osGroup}.${architecture}_${architecture}.${configuration}"
3515
3516     def crossArch = "x64"
3517     def workspaceRelativeCrossArchResultDir = "${workspaceRelativeResultsDir}/${osGroup}.${crossArch}_${architecture}.${configuration}"
3518
3519     def jobFolder = getJobFolder(scenario)
3520     def newJob = dslFactory.job(Utilities.getFullJobName(project, jobName, isPR, jobFolder)) {
3521         parameters {
3522             stringParam('CORECLR_BUILD', '', "Build number to copy CoreCLR ${osGroup} binaries from")
3523         }
3524
3525         def workspaceRelativeArtifactsArchive = "${os}.${architecture}.${configuration}.${scenario}.zip"
3526
3527         steps {
3528             copyArtifacts(inputCoreCLRBuildName) {
3529                 includePatterns("${workspaceRelativeArtifactsArchive}")
3530                 buildSelector {
3531                     buildNumber('${CORECLR_BUILD}')
3532                 }
3533             }
3534
3535             shell("unzip -o ${workspaceRelativeArtifactsArchive} || exit 0")
3536
3537             def workspaceRelativeCoreLib = "bin/Product/${osGroup}.${architecture}.${configuration}/IL/System.Private.CoreLib.dll"
3538             def workspaceRelativeCoreRootDir = "bin/tests/${osGroup}.${architecture}.${configuration}/Tests/Core_Root"
3539             def workspaceRelativeCrossGenComparisonScript = "tests/scripts/crossgen_comparison.py"
3540             def workspaceRelativeCrossGenExecutable = "${workspaceRelativeCoreRootDir}/crossgen"
3541
3542             def crossGenComparisonCmd = "python -u \${WORKSPACE}/${workspaceRelativeCrossGenComparisonScript} "
3543             def crossGenExecutable = "\${WORKSPACE}/${workspaceRelativeCrossGenExecutable}"
3544
3545             shell("mkdir -p ${workspaceRelativeNativeArchResultDir}")
3546             shell("${crossGenComparisonCmd}crossgen_corelib --crossgen ${crossGenExecutable} --il_corelib \${WORKSPACE}/${workspaceRelativeCoreLib} --result_dir \${WORKSPACE}/${workspaceRelativeNativeArchResultDir}")
3547             shell("${crossGenComparisonCmd}crossgen_framework --crossgen ${crossGenExecutable} --core_root \${WORKSPACE}/${workspaceRelativeCoreRootDir} --result_dir \${WORKSPACE}/${workspaceRelativeNativeArchResultDir}")
3548
3549             shell("${crossGenComparisonCmd}compare --base_dir \${WORKSPACE}/${workspaceRelativeNativeArchResultDir} --diff_dir \${WORKSPACE}/${workspaceRelativeCrossArchResultDir}")
3550         } // steps
3551     }  // job
3552
3553     Utilities.addArchival(newJob, "${workspaceRelativeNativeArchResultDir}/**")
3554     Utilities.addArchival(newJob, "${workspaceRelativeCrossArchResultDir}/**")
3555
3556     return newJob
3557 }
3558
3559 // Create a test job that will be used by a flow job.
3560 // Returns the newly created job.
3561 // 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,
3562 // and we want the views to be the minimal set of "top-level" jobs that represent all work.
3563 def static CreateTestJob(def dslFactory, def project, def branch, def architecture, def os, def configuration, def scenario, def isPR, def inputCoreCLRBuildName)
3564 {
3565     def windowsArmJob = ((os == "Windows_NT") && (architecture in Constants.armWindowsCrossArchitectureList))
3566
3567     def newJob = null
3568     if (windowsArmJob) {
3569         newJob = CreateWindowsArmTestJob(dslFactory, project, architecture, os, configuration, scenario, isPR, inputCoreCLRBuildName)
3570     }
3571     else if (isCrossGenComparisonScenario(scenario)) {
3572         newJob = CreateNonWindowsCrossGenComparisonTestJob(dslFactory, project, architecture, os, configuration, scenario, isPR, inputCoreCLRBuildName)
3573     }
3574     else {
3575         newJob = CreateOtherTestJob(dslFactory, project, branch, architecture, os, configuration, scenario, isPR, inputCoreCLRBuildName)
3576     }
3577
3578     setJobMachineAffinity(architecture, os, false, true, false, newJob) // isBuildJob = false, isTestJob = true, isFlowJob = false
3579
3580     if (scenario == 'jitdiff') {
3581         def osGroup = getOSGroup(os)
3582         Utilities.addArchival(newJob, "bin/tests/${osGroup}.${architecture}.${configuration}/dasm/**")
3583     }
3584
3585     Utilities.standardJobSetup(newJob, project, isPR, "*/${branch}")
3586     setJobTimeout(newJob, isPR, architecture, configuration, scenario, false)
3587
3588     return newJob
3589 }
3590
3591 // Create a flow job to tie together a build job with the given test job.
3592 // Returns the new flow job.
3593 def static CreateFlowJob(def dslFactory, def project, def branch, def architecture, def os, def configuration, def scenario, def isPR, def fullTestJobName, def inputCoreCLRBuildName)
3594 {
3595     // Windows CoreCLR build and Linux CoreCLR build (in parallel) ->
3596     // Linux CoreCLR test
3597     def flowJobName = getJobName(configuration, architecture, os, scenario, false) + "_flow"
3598     def jobFolder = getJobFolder(scenario)
3599
3600     def newFlowJob = dslFactory.buildFlowJob(Utilities.getFullJobName(project, flowJobName, isPR, jobFolder)) {
3601         buildFlow("""\
3602 coreclrBuildJob = build(params, '${inputCoreCLRBuildName}')
3603
3604 // And then build the test build
3605 build(params + [CORECLR_BUILD: coreclrBuildJob.build.number], '${fullTestJobName}')
3606 """)
3607     }
3608     JobReport.Report.addReference(inputCoreCLRBuildName)
3609     JobReport.Report.addReference(fullTestJobName)
3610
3611     addToViews(newFlowJob, true, isPR, architecture, os, configuration, scenario) // isFlowJob = true
3612
3613     setJobMachineAffinity(architecture, os, false, false, true, newFlowJob) // isBuildJob = false, isTestJob = false, isFlowJob = true
3614
3615     Utilities.standardJobSetup(newFlowJob, project, isPR, "*/${branch}")
3616     addTriggers(newFlowJob, branch, isPR, architecture, os, configuration, scenario, true, false) // isFlowJob==true, isWindowsBuildOnlyJob==false
3617
3618     return newFlowJob
3619 }
3620
3621 // Determine if we should generate a flow job for the given parameters.
3622 // Returns true if the job should be generated.
3623 def static shouldGenerateFlowJob(def scenario, def isPR, def architecture, def configuration, def os)
3624 {
3625     // The various "innerloop" jobs are only available as PR triggered.
3626
3627     if (!isPR) {
3628         if (isInnerloopTestScenario(scenario)) {
3629             return false
3630         }
3631
3632         if (scenario == 'corefx_innerloop') {
3633             return false
3634         }
3635     }
3636
3637     // Filter based on OS and architecture.
3638
3639     switch (architecture) {
3640         case 'arm':
3641             if (os != "Ubuntu" && os != "Windows_NT") {
3642                 return false
3643             }
3644             break
3645         case 'arm64':
3646             if (os != "Ubuntu16.04" && os != "Windows_NT") {
3647                 return false
3648             }
3649             break
3650         case 'x86':
3651             if (os != "Ubuntu") {
3652                 return false
3653             }
3654             break
3655         case 'x64':
3656             if (!(os in Constants.crossList)) {
3657                 return false
3658             }
3659             if (os == "Windows_NT") {
3660                 return false
3661             }
3662             break
3663         case 'armem':
3664         case 'x86_arm_altjit':
3665         case 'x64_arm64_altjit':
3666             // No flow jobs
3667             return false
3668         default:
3669             println("Unknown architecture: ${architecture}")
3670             assert false
3671             break
3672     }
3673
3674     def isNormalOrInnerloop = (scenario == 'innerloop' || scenario == 'normal')
3675
3676     // Filter based on scenario in OS.
3677
3678     if (os == 'Windows_NT') {
3679         assert architecture == 'arm' || architecture == 'arm64'
3680         if (!isArmWindowsScenario(scenario)) {
3681             return false
3682         }
3683         if (isNormalOrInnerloop && (configuration == 'Debug')) {
3684             // The arm32/arm64 Debug configuration for innerloop/normal scenario is a special case: it does a build only, and no test run.
3685             // To do that, it doesn't require a flow job.
3686             return false
3687         }
3688     }
3689     else {
3690         // Non-Windows
3691         if (architecture == 'arm') {
3692             if (!(scenario in Constants.validLinuxArmScenarios)) {
3693                 return false
3694             }
3695         }
3696         else if (architecture == 'arm64') {
3697             if (!(scenario in Constants.validLinuxArm64Scenarios)) {
3698                 return false
3699             }
3700         }
3701         else if (architecture == 'x86') {
3702             // Linux/x86 only want innerloop and default test
3703             if (!isNormalOrInnerloop) {
3704                 return false
3705             }
3706         }
3707         else if (architecture == 'x64') {
3708             // Linux/x64 corefx testing doesn't need a flow job; the "build" job runs run-corefx-tests.py which
3709             // builds and runs the corefx tests. Other Linux/x64 flow jobs are required to get the test
3710             // build from a Windows machine.
3711             if (isCoreFxScenario(scenario)) {
3712                 return false
3713             }
3714         }
3715     }
3716
3717     // For CentOS, we only want Checked/Release builds.
3718     if (os == 'CentOS7.1') {
3719         if (configuration != 'Checked' && configuration != 'Release') {
3720             return false
3721         }
3722         if (!isNormalOrInnerloop && !isR2RScenario(scenario)) {
3723             return false
3724         }
3725     }
3726
3727     // For RedHat and Debian, we only do Release builds.
3728     else if (os == 'RHEL7.2' || os == 'Debian8.4') {
3729         if (configuration != 'Release') {
3730             return false
3731         }
3732         if (!isNormalOrInnerloop) {
3733             return false
3734         }
3735     }
3736
3737     // Next, filter based on scenario.
3738
3739     if (isJitStressScenario(scenario)) {
3740         if (configuration != 'Checked') {
3741             return false
3742         }
3743     }
3744     else if (isR2RBaselineScenario(scenario)) {
3745         if (configuration != 'Checked' && configuration != 'Release') {
3746             return false
3747         }
3748     }
3749     else if (isR2RStressScenario(scenario)) {
3750         if (configuration != 'Checked') {
3751             return false
3752         }
3753     }
3754     else if (isCrossGenComparisonScenario(scenario)) {
3755         return shouldGenerateCrossGenComparisonJob(os, architecture, configuration, scenario)
3756     }
3757     else {
3758         // Skip scenarios
3759         switch (scenario) {
3760             case 'ilrt':
3761             case 'longgc':
3762             case 'gcsimulator':
3763                 // Long GC tests take a long time on non-Release builds
3764                 // ilrt is also Release only
3765                 if (configuration != 'Release') {
3766                     return false
3767                 }
3768                 break
3769
3770             case 'jitdiff':
3771                 if (configuration != 'Checked') {
3772                     return false
3773                 }
3774                 break
3775
3776             case 'gc_reliability_framework':
3777             case 'standalone_gc':
3778                 if (configuration != 'Release' && configuration != 'Checked') {
3779                     return false
3780                 }
3781                 break
3782
3783             case 'formatting':
3784                 return false
3785
3786             case 'illink':
3787                 if (os != 'Windows_NT' && os != 'Ubuntu') {
3788                     return false
3789                 }
3790                 break
3791
3792             case 'normal':
3793                 // Nothing skipped
3794                 break
3795
3796             case 'innerloop':
3797                 if (!isValidPrTriggeredInnerLoopJob(os, architecture, configuration, false)) {
3798                     return false
3799                 }
3800                 break
3801
3802             case 'pmi_asm_diffs':
3803                 if (configuration != 'Checked') {
3804                     return false
3805                 }
3806                 // No need for flow job except for Linux arm/arm64
3807                 if ((os != 'Windows_NT') && (architecture != 'arm') && (architecture != 'arm64')) {
3808                     return false
3809                 }
3810                 break
3811
3812             case 'corefx_innerloop':
3813                 // No flow job needed
3814                 return false
3815
3816             default:
3817                 println("Unknown scenario: ${scenario}")
3818                 assert false
3819                 break
3820         }
3821     }
3822
3823     // The job was not filtered out, so we should generate it!
3824     return true
3825 }
3826
3827 // Create jobs requiring flow jobs. This includes x64 non-Windows, arm/arm64 Ubuntu, and arm/arm64 Windows.
3828 Constants.allScenarios.each { scenario ->
3829     [true, false].each { isPR ->
3830         Constants.architectureList.each { architecture ->
3831             Constants.configurationList.each { configuration ->
3832                 Constants.osList.each { os ->
3833
3834                     if (!shouldGenerateFlowJob(scenario, isPR, architecture, configuration, os)) {
3835                         return
3836                     }
3837
3838                     def windowsArmJob = ((os == "Windows_NT") && (architecture in Constants.armWindowsCrossArchitectureList))
3839                     def doCoreFxTesting = isCoreFxScenario(scenario)
3840                     def doCrossGenComparison = isCrossGenComparisonScenario(scenario)
3841                     def isPmiAsmDiffsScenario = (scenario == 'pmi_asm_diffs')
3842
3843                     // Figure out the job name of the CoreCLR build the test will depend on.
3844
3845                     def inputCoreCLRBuildScenario = isInnerloopTestScenario(scenario) ? 'innerloop' : 'normal'
3846                     def inputCoreCLRBuildIsBuildOnly = false
3847                     if (doCoreFxTesting || isPmiAsmDiffsScenario) {
3848                         // Every CoreFx test depends on its own unique build.
3849                         inputCoreCLRBuildScenario = scenario
3850                         if (windowsArmJob) {
3851                             // Only Windows ARM corefx jobs use "build only" jobs. Others, such as Ubuntu ARM corefx, use "regular" jobs.
3852                             inputCoreCLRBuildIsBuildOnly = true
3853                         }
3854                     }
3855                     else if (doCrossGenComparison) {
3856                         inputCoreCLRBuildScenario = scenario
3857                     }
3858
3859                     def inputCoreCLRFolderName = getJobFolder(inputCoreCLRBuildScenario)
3860                     def inputCoreCLRBuildName = projectFolder + '/' +
3861                         Utilities.getFullJobName(project, getJobName(configuration, architecture, os, inputCoreCLRBuildScenario, inputCoreCLRBuildIsBuildOnly), isPR, inputCoreCLRFolderName)
3862
3863                     // =============================================================================================
3864                     // Create the test job
3865                     // =============================================================================================
3866
3867                     def testJob = CreateTestJob(this, project, branch, architecture, os, configuration, scenario, isPR, inputCoreCLRBuildName)
3868
3869                     // =============================================================================================
3870                     // Create a build flow to join together the build and tests required to run this test.
3871                     // =============================================================================================
3872
3873                     if (os == 'RHEL7.2' || os == 'Debian8.4') {
3874                         // Do not create the flow job for RHEL jobs.
3875                         return
3876                     }
3877
3878                     def fullTestJobName = projectFolder + '/' + testJob.name
3879                     def flowJob = CreateFlowJob(this, project, branch, architecture, os, configuration, scenario, isPR, fullTestJobName, inputCoreCLRBuildName)
3880
3881                 } // os
3882             } // configuration
3883         } // architecture
3884     } // isPR
3885 } // scenario
3886
3887 JobReport.Report.generateJobReport(out)
3888
3889 // Make the call to generate the help job
3890 Utilities.createHelperJob(this, project, branch,
3891     "Welcome to the ${project} Repository",  // This is prepended to the help message
3892     "Have a nice day!")  // This is appended to the help message.  You might put known issues here.
3893
3894 Utilities.addCROSSCheck(this, project, branch)