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