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