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