Merge pull request #19 from frdeso/kprobe_fuzzing_pr
[lttng-ci.git] / scripts / lttng-modules / master-rt.groovy
1 /**
2 * Copyright (C) 2016 - Michael Jeanson <mjeanson@efficios.com>
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 import hudson.model.*
19 import hudson.AbortException
20 import hudson.console.HyperlinkNote
21 import java.util.concurrent.CancellationException
22 import org.eclipse.jgit.api.Git
23 import org.eclipse.jgit.lib.Ref
24
25
26 class kVersion implements Comparable<kVersion> {
27
28 Integer major = 0;
29 Integer majorB = 0;
30 Integer minor = 0;
31 Integer patch = 0;
32 Integer rt = 0;
33
34 kVersion() {}
35
36 kVersion(version) {
37 this.parse(version)
38 }
39
40 def parse(version) {
41 this.major = 0
42 this.majorB = 0
43 this.minor = 0
44 this.patch = 0
45 this.rt = 0
46
47 def match = version =~ /^v(\d+)\.(\d+)(\.(\d+))?(\.(\d+))?(-rt(\d+)-rebase)$/
48 if (!match) {
49 throw new Exception("Invalid kernel version: ${version}")
50 }
51
52 Integer offset = 0;
53
54 // Major
55 this.major = Integer.parseInt(match.group(1))
56 if (this.major <= 2) {
57 offset = 2
58 this.majorB = Integer.parseInt(match.group(2))
59 }
60
61 // Minor
62 if (match.group(2 + offset) != null) {
63 this.minor = Integer.parseInt(match.group(2 + offset))
64 }
65
66 // Patch level
67 if (match.group(4 + offset) != null) {
68 this.patch = Integer.parseInt(match.group(4 + offset))
69 }
70
71 // RT
72 this.rt = Integer.parseInt(match.group(8))
73 }
74
75 @Override int compareTo(kVersion o) {
76 if (this.major != o.major) {
77 return Integer.compare(this.major, o.major);
78 }
79 if (this.majorB != o.majorB) {
80 return Integer.compare(this.majorB, o.majorB);
81 }
82 if (this.minor != o.minor) {
83 return Integer.compare(this.minor, o.minor);
84 }
85 if (this.patch != o.patch) {
86 return Integer.compare(this.patch, o.patch);
87 }
88 if (this.rt != o.rc) {
89 return Integer.compare(this.rt, o.rt);
90 }
91
92 // Same version
93 return 0;
94 }
95
96 String toString() {
97 String vString = "v${this.major}"
98
99 if (this.majorB > 0) {
100 vString = vString.concat(".${this.majorB}")
101 }
102
103 vString = vString.concat(".${this.minor}")
104
105 if (this.patch > 0) {
106 vString = vString.concat(".${this.patch}")
107 }
108
109 if (this.rt > 0) {
110 vString = vString.concat("-rt${this.rt}-rebase")
111 }
112 return vString
113 }
114 }
115
116
117 // Retrieve parameters of the current build
118 def mversion = build.buildVariableResolver.resolve('mversion')
119 def maxConcurrentBuild = build.buildVariableResolver.resolve('maxConcurrentBuild')
120 def kgitrepo = build.buildVariableResolver.resolve('kgitrepo')
121 def kverfloor = new kVersion(build.buildVariableResolver.resolve('kverfloor'))
122 def job = Hudson.instance.getJob(build.buildVariableResolver.resolve('kbuildjob'))
123 def currentJobName = build.project.getFullDisplayName()
124
125 // Get the out variable
126 def config = new HashMap()
127 def bindings = getBinding()
128 config.putAll(bindings.getVariables())
129 def out = config['out']
130
131 def jlc = new jenkins.model.JenkinsLocationConfiguration()
132 def jenkinsUrl = jlc.url
133
134 // Get tags from git repository
135 def refs = Git.lsRemoteRepository().setTags(true).setRemote(kgitrepo).call();
136
137 // Get kernel versions to build
138 def kversions = []
139 for (ref in refs) {
140 def match = ref.getName() =~ /^refs\/tags\/(v[\d\.]+(-rt(\d+)-rebase))$/
141
142 if (match) {
143 def v = new kVersion(match.group(1))
144
145 if (v >= kverfloor) {
146 kversions.add(v)
147 }
148 }
149 }
150
151 kversions.sort()
152
153 // Debug
154 println "Building the following kernel versions:"
155 for (k in kversions) {
156 println k
157 }
158
159 // Debug: Stop build here
160 //throw new InterruptedException()
161
162 def joburl = HyperlinkNote.encodeTo('/' + job.url, job.fullDisplayName)
163
164 def allBuilds = []
165 def ongoingBuild = []
166 def failedRuns = []
167 def isFailed = false
168
169 // Loop while we have kernel versions remaining or jobs running
170 while ( kversions.size() != 0 || ongoingBuild.size() != 0 ) {
171
172 if(ongoingBuild.size() < maxConcurrentBuild.toInteger() && kversions.size() != 0) {
173 def kversion = kversions.pop()
174 def job_params = [
175 new StringParameterValue('mversion', mversion),
176 new StringParameterValue('ktag', kversion.toString()),
177 new StringParameterValue('kgitrepo', kgitrepo),
178 ]
179
180 // Launch the parametrized build
181 def param_build = job.scheduleBuild2(0, new Cause.UpstreamCause(build), new ParametersAction(job_params))
182 println "triggering ${joburl} for the ${mversion} branch on kernel ${kversion}"
183
184 // Add it to the ongoing build queue
185 ongoingBuild.push(param_build)
186
187 } else {
188
189 println "Waiting... Queued: " + kversions.size() + " Running: " + ongoingBuild.size()
190 try {
191 Thread.sleep(5000)
192 } catch(e) {
193 if (e in InterruptedException) {
194 build.setResult(hudson.model.Result.ABORTED)
195 throw new InterruptedException()
196 } else {
197 throw(e)
198 }
199 }
200
201 // Check for queued similar job since we only want to run latest
202 // as Mathieu Desnoyers requirement
203 similarJobQueued = Hudson.instance.queue.items.count{it.task.getFullDisplayName() == currentJobName}
204 if ( similarJobQueued > 0 ) {
205 // Abort since new build is queued
206 build.setResult(hudson.model.Result.ABORTED)
207 throw new InterruptedException()
208 }
209
210 def i = ongoingBuild.iterator()
211 while ( i.hasNext() ) {
212 currentBuild = i.next()
213 if ( currentBuild.isCancelled() || currentBuild.isDone() ) {
214 // Remove from queue
215 i.remove()
216
217 // Print results
218 def matrixParent = currentBuild.get()
219 allBuilds.add(matrixParent)
220 def kernelStr = matrixParent.buildVariableResolver.resolve("ktag")
221 println "${matrixParent.fullDisplayName} (${kernelStr}) completed with status ${matrixParent.result}"
222
223 // Process child runs of matrixBuild
224 def childRuns = matrixParent.getRuns()
225 for ( childRun in childRuns ) {
226 println "\t${childRun.fullDisplayName} (${kernelStr}) completed with status ${childRun.result}"
227 if (childRun.result != Result.SUCCESS) {
228 failedRuns.add(childRun)
229 isFailed = true
230 }
231 }
232 }
233 }
234 }
235 }
236
237 // Get log of failed runs
238 for (failedRun in failedRuns) {
239 println "---START---"
240 failedRun.writeWholeLogTo(out)
241 println "---END---"
242 }
243
244 println "---Build report---"
245 for (b in allBuilds) {
246 def kernelStr = b.buildVariableResolver.resolve("ktag")
247 println "${b.fullDisplayName} (${kernelStr}) completed with status ${b.result}"
248 // Cleanup builds
249 try {
250 b.delete()
251 } catch (all) {}
252 }
253
254 // Mark this build failed if any child build has failed
255 if (isFailed) {
256 build.getExecutor().interrupt(Result.FAILURE)
257 }
258
259 // EOF
This page took 0.038827 seconds and 5 git commands to generate.