Repository navigation
Expand file tree
/
Copy pathJenkinsfile
More file actions
492 lines (459 loc) · 18.2 KB
/
Copy pathJenkinsfile
File metadata and controls
492 lines (459 loc) · 18.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
// This file relates to internal XMOS infrastructure and should be ignored by external users
@Library('xmos_jenkins_shared_library@v0.54.0') _
def runningOn(machine) {
println "Stage running on:"
println machine
}
// Runs a single pytest suite, wrapping the repeated dir/env/junit boilerplate.
// archOpt is "" or "--arch <name>" for suites that support it. postSteps (if given) runs
// after junit reporting, still inside the suite's dir()/env context (e.g. for archiveArtifacts
// or a follow-up python script).
def runSuite(String suiteDir, String archOpt, String pytestArgs, Closure postSteps = null) {
dir(suiteDir) {
def cmd = "pytest ${archOpt} ${pytestArgs} -v --durations=0 --junitxml=pytest_result.xml".replaceAll(/\s+/, ' ').trim()
withEnv(["hydra_audio_PATH=/projects/hydra_audio"]) {
try {
sh cmd
} finally {
junit "pytest_result.xml"
}
if (postSteps) { postSteps() }
}
}
}
// Runs every test suite built for the given architecture ("xs3a", "vx4b" or "native").
// Must be called from within dir("tests") { withTools(...) { withVenv { ... } } }.
// Each suite is individually catchError-wrapped so one failure doesn't skip the rest.
def test_arch(String archName) {
if (archName == 'native') {
sh "cmake -B build_xcommon_cmake" // to fetch lib_xcore_math
// Only suites with an existing native build/execution path are run natively.
catchError(stageResult: 'UNSTABLE', catchInterruptions: false) {
runSuite("lib_vnr/vnr_unit_tests", "--arch native", "-n 2")
}
catchError(stageResult: 'UNSTABLE', catchInterruptions: false) {
runSuite("lib_ic/test_calc_vnr_pred", "--arch native", "-n 2")
}
catchError(stageResult: 'FAILURE', catchInterruptions: false) {
dir("lib_vnr/test_vnr_cffi") {
sh "python build_vnr_cffi.py"
}
runSuite("lib_vnr/test_vnr_cffi", "--arch native", "-n 4")
}
catchError(stageResult: 'FAILURE', catchInterruptions: false) {
dir("lib_ic/test_ic_cffi") {
sh "python build_ic_cffi.py"
}
runSuite("lib_ic/test_ic_cffi", "--arch native", "-s")
}
catchError(stageResult: 'FAILURE', catchInterruptions: false) {
dir("stage_b") {
sh "python build_stage_b_cffi.py"
}
// -n 2: both tests now write to pytest's per-test tmp_path, safe to run concurrently
runSuite("stage_b", "--arch native", "-n 2")
}
return
}
def arch = "--arch ${archName}"
catchError(stageResult: 'FAILURE', catchInterruptions: false) {
runSuite("lib_vnr/vnr_unit_tests", arch, "-n 2")
}
catchError(stageResult: 'FAILURE', catchInterruptions: false) {
runSuite("lib_ns", arch, "-n 2")
}
catchError(stageResult: 'FAILURE', catchInterruptions: false) {
runSuite("lib_ic", arch, "-n 2") {
sh "python test_ic_spec/print_stats.py > ic_spec_summary_${archName}.txt"
}
}
catchError(stageResult: 'FAILURE', catchInterruptions: false) {
runSuite("lib_adec", arch, "-n 2") {
sh "python test_delay_estimator/print_stats.py"
}
}
catchError(stageResult: 'FAILURE', catchInterruptions: false) {
runSuite("lib_aec", arch, "-n 2")
}
catchError(stageResult: 'FAILURE', catchInterruptions: false) {
runSuite("lib_agc", arch, "-n 2")
}
catchError(stageResult: 'FAILURE', catchInterruptions: false) {
runSuite("profile_mips", arch, "-n 2") {
archiveArtifacts artifacts: "lib_voice_mips.json", fingerprint: true, onlyIfSuccessful: true
}
}
if (archName == 'vx4b') {
// fails loading xinterpreters on ubuntu 22
echo "Skipping profile memory test as no memory prints"
} else {
catchError(stageResult: 'FAILURE', catchInterruptions: false) {
runSuite("profile_memory", arch, "-n 2") {
archiveArtifacts artifacts: "lib_voice_memory.json", fingerprint: true, onlyIfSuccessful: true
}
}
}
}
// Runs one architecture's whole Verification stage (Get View, XTAG reset, tests, pipeline,
// artifact archiving, cleanup) - shared by vx4b/native/xs3a instead of 3 near-identical
// declarative stage blocks. `cfg` fields: agentLabel, toolsVersion, archName,
// unstashNames, hwTarget (null skips XTAG reset), build (closure, optional - builds the
// tests on this same node instead of unstashing them), archiveAlways/
// archiveFailure (closures, optional).
def runVerification(Map cfg) {
node(cfg.agentLabel) {
try {
stage('Get View') {
runningOn(env.NODE_NAME)
sh "git clone --depth 1 --branch main git@github.com:xmos/amazon_wwe.git"
sh "git clone --depth 1 --branch master git@github.com:xmos/sensory_sdk.git"
dir("${env.REPO}") {
checkout scm
dir("tests") {
withTools(cfg.toolsVersion) {
createVenv(reqFile: "requirements_test.txt")
}
cfg.unstashNames.each { unstash it }
}
}
} // Get View
if (cfg.build) {
cfg.build()
}
if (cfg.hwTarget) {
stage('Reset XTAGs') {
dir("${env.REPO}/tests") {
sh 'rm -f ~/.xtag/acquired' // Hacky but ensure it always works even when previous failed run left lock file present
withTools(cfg.toolsVersion) {
withVenv {
sh "xtagctl reset_all ${cfg.hwTarget}"
}
}
}
}
}
stage('tests') {
dir("${env.REPO}/tests") {
withTools(cfg.toolsVersion) {
withVenv {
test_arch(cfg.archName)
}
}
}
} // tests
if (cfg.archName != 'native') {
stage('Pipeline tests') {
catchError(stageResult: 'FAILURE', catchInterruptions: false) {
dir("${env.REPO}/tests/pipeline") {
withEnv(["hydra_audio_PATH=/projects/hydra_audio"]) {
withEnv(["PIPELINE_FULL_RUN=${env.PIPELINE_FULL_RUN}", "SENSORY_PATH=${env.WORKSPACE}/sensory_sdk/", "AMAZON_WWE_PATH=${env.WORKSPACE}/amazon_wwe/"]) {
withTools(cfg.toolsVersion) {
withVenv {
echo "PIPELINE_FULL_RUN set as " + env.PIPELINE_FULL_RUN
// NOTE: "--arch ${cfg.archName} python" (space-separated) is required, not
// "--arch=${cfg.archName} python" - with "=", argparse's nargs="+" only
// consumes "${cfg.archName}" and "python" becomes a bogus positional pytest
// path argument ("ERROR: file or directory not found: python").
sh "pytest -n 4 --arch ${cfg.archName} python --junitxml=pytest_result.xml -vv"
junit "pytest_result.xml"
def threshold = (cfg.archName == 'vx4b') ? 3 : 1
sh "python compare_keywords.py results_Avona_aec_ic_ns_agc_prev_arch_${cfg.archName}.csv results_Avona_aec_ic_ns_agc_prev_arch_python.csv --pass-threshold=${threshold}"
}
}
}
}
}
}
} // Pipeline tests
stage('Benchmark Pipeline tests results') {
if (env.PIPELINE_FULL_RUN == "1") {
dir("${env.REPO}/tests/pipeline") {
withTools(cfg.toolsVersion) {
withVenv {
copyArtifacts filter: '**/results_*.csv', fingerprintArtifacts: true, projectName: '../lib_audio_pipelines/master', selector: lastSuccessful()
runPython("python plot_results.py lib_audio_pipelines/tests/pipelines/results_lib_ap_prev_arch_xcore.csv results_Avona_prev_arch_${cfg.archName}.csv --single-plot --ww-column='0_2 1_2' --figname=results_benchmark_prev_arch")
runPython("python plot_results.py lib_audio_pipelines/tests/pipelines/results_lib_ap_alt_arch_xcore.csv results_Avona_alt_arch_${cfg.archName}.csv --single-plot --ww-column='0_2 1_2' --figname=results_benchmark_alt_arch")
}
}
}
}
}
}
} finally {
// Mirrors declarative post{always{}}/post{failure{}}: always archive, and additionally
// archive failure-only debug artifacts if this build's result looks unhealthy. Since
// parallel branches share one build result, a failure in a sibling branch can also trigger
// this - an accepted, harmless over-approximation for a debug-artifact convenience feature.
try {
if (cfg.archiveAlways) {
cfg.archiveAlways()
}
if (cfg.archiveFailure && currentBuild.currentResult in ['FAILURE', 'UNSTABLE']) {
cfg.archiveFailure()
}
} finally {
xcoreCleanSandbox()
}
}
}
}
// Shared archiveAlways/archiveFailure closures for runVerification's vx4b/xs3a branches.
// Filenames/dirs are arch-suffixed (ic_spec_summary_<arch>.txt, keyword_input_<p_arch>_<arch>/...,
// results_..._<arch>.csv) so both branches can archive from these same patterns without collisions.
def archiveResultsAlways() {
archiveArtifacts artifacts: "${env.REPO}/tests/lib_ic/ic_spec_summary_*.txt", fingerprint: true
archiveArtifacts artifacts: "${env.REPO}/tests/pipeline/**/results_*.csv", fingerprint: true
archiveArtifacts artifacts: "${env.REPO}/tests/pipeline/**/results_*.png", fingerprint: true, allowEmptyArchive: true
archiveArtifacts artifacts: "${env.REPO}/tests/pipeline/keyword_input_*/*.npy", fingerprint: true, allowEmptyArchive: true
}
def archiveResultsFailure() {
// archive wavs on failure only
archiveArtifacts artifacts: "${env.REPO}/tests/pipeline/keyword_input_*/*.wav", fingerprint: true, allowEmptyArchive: true
}
// CMake option that shortens tests unless a full test run was requested.
def speedupOpt() {
return (env.FULL_TEST == "1") ? "" : "-DTEST_SPEEDUP_FACTOR=4"
}
// Runs a test build on its own agent: checks out the repo, creates the build venv
// (requirements.txt - needs ai_tools, and numpy to generate aec tests), then runs `body`
// (which should build and stash binaries). Always cleans the sandbox afterwards.
def buildTests(String agentLabel, Closure body) {
node(agentLabel) {
try {
stage('Get View') {
runningOn(env.NODE_NAME)
dir("${env.REPO}") {
checkout scm
createVenv(reqFile: "requirements.txt")
}
}
body()
} finally {
xcoreCleanSandbox()
}
}
}
getApproval()
pipeline {
agent none
parameters {
string(
name: 'TOOLS_VERSION',
defaultValue: '15.3.1',
description: 'The XTC tools version'
)
string(
name: 'TOOLS_VX4_VERSION',
defaultValue: 'slipgate@master:143',
description: 'The XTC Slipgate tools version'
)
string(
name: 'XMOSDOC_VERSION',
defaultValue: 'v8.1.0',
description: 'The xmosdoc version'
)
string(
name: 'INFR_APPS_VERSION',
defaultValue: 'v3.5.0',
description: 'The infr_apps version'
)
booleanParam(name: 'FULL_TEST_OVERRIDE',
defaultValue: false,
description: 'Force a full test. This increases the number of iterations/scope in some tests')
booleanParam(name: 'PIPELINE_FULL_RUN',
defaultValue: false,
description: 'Enables pipelines characterisation test which takes 5.0hrs by itself. Normally run nightly')
}
environment {
REPO = 'lib_voice'
FULL_TEST = """${(params.FULL_TEST_OVERRIDE
|| env.BRANCH_NAME == 'develop'
|| env.BRANCH_NAME == 'main'
|| env.BRANCH_NAME ==~ 'release/.*') ? 1 : 0}"""
PIPELINE_FULL_RUN = """${params.PIPELINE_FULL_RUN ? 1 : 0}"""
}
options {
skipDefaultCheckout()
timestamps()
buildDiscarder(xmosDiscardBuildSettings(onlyArtifacts=false))
}
stages {
stage('Build and test') {
// Every branch is independent: an architecture's tests start as soon as its own build
// finishes, without waiting on other architectures' builds or the docs/repo checks.
parallel {
stage('Examples, docs, repo checks') {
agent {
label "documentation&&x86_64&&linux"
}
stages {
stage("Examples build") {
steps {
runningOn(env.NODE_NAME)
dir("${REPO}") {
checkoutScmShallow()
createVenv(reqFile: "requirements.txt")
}
dir("${REPO}/examples") {
withVenv {
// will use TOOLS_VERSION which is valid for an xs3a build
xcoreBuild(archiveBins: false, buildDir: "build_xs3a")
// setting TOOLS_VERSION to be the vx4b tools
withEnv(["TOOLS_VERSION=${params.TOOLS_VX4_VERSION}"]) {
xcoreBuild(archiveBins: false, buildDir: "build_vx4b", cmakeOpts: "-DAPP_HW_TARGET=XK-EVK-XU416", jobs: 8)
}
}
}
}
} // Examples build
stage("Repo checks") {
steps {
warnError("Repo checks failed") {
runRepoChecks(
repo_dir:"${WORKSPACE}/${REPO}",
reqFile:"${WORKSPACE}/${REPO}/requirements.txt"
)
}
}
} // Repo checks
stage("Docs build") {
steps {
dir("${REPO}") {
warnError("Docs build failed") {
buildDocs()
}
}
}
} // Docs build
stage("Archive Lib") {
steps {
archiveSandbox(REPO)
}
} //stage("Archive Lib")
} // stages
post {
cleanup {
xcoreCleanSandbox()
}
}
} // Examples, docs, repo checks
stage('vx4b') {
when {
expression { !env.GH_LABEL_DOC_ONLY.toBoolean() }
}
steps {
script {
buildTests('x86&&linux') {
stage('Build tests vx4b') {
dir("${env.REPO}") {
withVenv {
withEnv(["TOOLS_VERSION=${params.TOOLS_VX4_VERSION}"]) {
dir("tests") {
xcoreBuild(buildDir: "build_vx4", archiveBins: false, cmakeOpts: "${speedupOpt()} -DAPP_HW_TARGET=XK-EVK-XU416", jobs: 8)
stash name: 'build_vx4', includes: '**/bin/**/*.xe, build_vx4/lib_vnr/vnr_unit_tests/src.autogen/vnr_model/trained_model_xcore.tflite'
}
}
}
}
}
}
runVerification([
agentLabel: 'vx4',
toolsVersion: params.TOOLS_VX4_VERSION,
archName: 'vx4b',
unstashNames: ['build_vx4'],
hwTarget: 'XK-EVK-XU416',
archiveAlways: { archiveResultsAlways() },
archiveFailure: { archiveResultsFailure() },
])
}
}
} // vx4b
stage('native and CFFI') {
when {
expression { !env.GH_LABEL_DOC_ONLY.toBoolean() }
}
steps {
script {
// Build and test on the same node
runVerification([
agentLabel: 'x86_64&&linux&&!noAVX2',
toolsVersion: params.TOOLS_VERSION,
archName: 'native',
unstashNames: [],
hwTarget: null,
build: {
stage('Build tests, xcommon-cmake native build') {
dir("${env.REPO}") {
// need ai_tools for the build, and numpy to generate aec tests
createVenv(reqFile: "requirements.txt")
withTools(params.TOOLS_VERSION) {
withVenv {
dir("tests") {
xcoreBuild(buildDir: "build_native", archiveBins: false, cmakeOpts: "-DBUILD_NATIVE=ON", jobs: 8)
}
}
}
}
}
},
])
}
}
} // native and CFFI
stage('xs3a') {
when {
expression { !env.GH_LABEL_DOC_ONLY.toBoolean() }
}
steps {
script {
buildTests('x86_64&&linux') {
stage('Build tests, xcommon-cmake xcore build') {
dir("${env.REPO}") {
withTools(params.TOOLS_VERSION) {
withVenv {
dir("tests") {
xcoreBuild(buildDir: "build_xs3", archiveBins: false, cmakeOpts: speedupOpt(), jobs: 8)
stash name: 'build_xs3', includes: '**/bin/**/*.xe, build_xs3/lib_vnr/vnr_unit_tests/src.autogen/vnr_model/trained_model_xcore.tflite'
}
}
}
}
}
stage('Custom CMake build') {
sh "git clone git@github.com:xmos/xmos_cmake_toolchain.git --depth 1 --branch v1.0.0"
// Do custom cmake, xcore build, from the tests/custom_cmake_build directory
dir("${env.REPO}/tests/custom_cmake_build") {
withTools(params.TOOLS_VERSION) {
withVenv {
sh 'cmake -B build --toolchain=../../../xmos_cmake_toolchain/xs3a.cmake'
sh 'make -C build -j$(nproc)'
}
}
}
}
}
runVerification([
agentLabel: 'xcore.ai',
toolsVersion: params.TOOLS_VERSION,
archName: 'xs3a',
unstashNames: ['build_xs3'],
hwTarget: 'XCORE-AI-EXPLORER',
archiveAlways: { archiveResultsAlways() },
archiveFailure: { archiveResultsFailure() },
])
}
}
} // xs3a
} // parallel
} // Build and test
stage('🚀 Release') {
when {
expression { triggerRelease.isReleasable() }
}
steps {
triggerRelease()
}
} // stage('🚀 Release')
} // stages
} // pipeline