3
|
1 |
#
|
|
2 |
# Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
# All rights reserved.
|
|
4 |
# This component and the accompanying materials are made available
|
|
5 |
# under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
# which accompanies this distribution, and is available
|
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
#
|
|
9 |
# Initial Contributors:
|
|
10 |
# Nokia Corporation - initial contribution.
|
|
11 |
#
|
|
12 |
# Contributors:
|
|
13 |
#
|
|
14 |
# Description:
|
|
15 |
# raptor_make_unit module
|
|
16 |
# This module tests the classes that write Makefile wrappers.
|
|
17 |
#
|
|
18 |
|
|
19 |
import os
|
|
20 |
import raptor
|
|
21 |
import raptor_data
|
|
22 |
import raptor_make
|
|
23 |
import unittest
|
|
24 |
|
|
25 |
class TestRaptorMake(unittest.TestCase):
|
|
26 |
|
|
27 |
def cleanMakefiles(self, fileList):
|
|
28 |
for file in fileList:
|
|
29 |
name = file.GetLocalString()
|
|
30 |
if os.path.exists(name):
|
|
31 |
os.remove(name)
|
|
32 |
|
|
33 |
def checkMakefiles(self, fileList):
|
|
34 |
for file in fileList:
|
|
35 |
name = file.GetLocalString()
|
|
36 |
if not os.path.exists(name):
|
|
37 |
print "did not find", name
|
|
38 |
return False
|
|
39 |
return True
|
|
40 |
|
|
41 |
def checkNotMakefiles(self, fileList):
|
|
42 |
for file in fileList:
|
|
43 |
name = file.GetLocalString()
|
|
44 |
if os.path.exists(name):
|
|
45 |
print "found unwanted", name
|
|
46 |
return False
|
|
47 |
return True
|
|
48 |
|
|
49 |
def testSimpleMake(self):
|
|
50 |
# use a bare Raptor object
|
|
51 |
aRaptor = raptor.Raptor()
|
|
52 |
aRaptor.ProcessConfig()
|
|
53 |
aRaptor.LoadCache()
|
|
54 |
aRaptor.pruneDuplicateMakefiles = False
|
|
55 |
aRaptor.writeSingleMakefile = False
|
|
56 |
|
|
57 |
# find the test directory
|
|
58 |
testDir = aRaptor.home.Append("test", "tmp")
|
|
59 |
|
|
60 |
# set up a build with a single Specification node
|
|
61 |
spec = raptor_data.Specification("myProject")
|
|
62 |
|
|
63 |
interface = raptor_data.Interface("EXE")
|
|
64 |
interface.SetProperty("flm", "/lib/flm/exe.flm")
|
|
65 |
interface.AddParameter(raptor_data.Parameter("EXEPARAM1"))
|
|
66 |
interface.AddParameter(raptor_data.Parameter("EXEPARAM2"))
|
|
67 |
interface.AddParameter(raptor_data.Parameter("EXEPARAM3"))
|
|
68 |
spec.SetInterface(interface)
|
|
69 |
|
|
70 |
svar = raptor_data.Variant("SVAR")
|
|
71 |
svar.AddOperation(raptor_data.Set("EXEPARAM1", "parameter 1"))
|
|
72 |
svar.AddOperation(raptor_data.Set("EXEPARAM2", "parameter 2"))
|
|
73 |
spec.AddVariant(svar)
|
|
74 |
|
|
75 |
# use a minimal Configuration
|
|
76 |
conf = raptor_data.Variant("myConfig")
|
|
77 |
cvar = raptor_data.Variant("CVAR")
|
|
78 |
cvar.AddOperation(raptor_data.Set("EXEPARAM3", "parameter 3"))
|
|
79 |
bldunit = raptor_data.BuildUnit("myConfig.CVAR",[conf,cvar])
|
|
80 |
|
|
81 |
# delete any old Makefiles
|
|
82 |
m1 = testDir.Append("Makefile")
|
|
83 |
m2 = testDir.Append("myConfig.CVAR", "myProject", "Makefile")
|
|
84 |
makefiles = [m1, m2]
|
|
85 |
self.cleanMakefiles(makefiles)
|
|
86 |
|
|
87 |
# create new Makefiles
|
|
88 |
maker = raptor_make.MakeEngine(aRaptor)
|
|
89 |
maker.Write(m1, [spec], [bldunit])
|
|
90 |
|
|
91 |
# test and clean
|
|
92 |
self.failUnless(self.checkMakefiles(makefiles))
|
|
93 |
self.cleanMakefiles(makefiles)
|
|
94 |
|
|
95 |
|
|
96 |
def testMultiSpecMultiConfigMake(self):
|
|
97 |
# use a bare Raptor object
|
|
98 |
aRaptor = raptor.Raptor()
|
|
99 |
aRaptor.ProcessConfig()
|
|
100 |
aRaptor.LoadCache()
|
|
101 |
aRaptor.pruneDuplicateMakefiles = False
|
|
102 |
aRaptor.writeSingleMakefile = False
|
|
103 |
|
|
104 |
# find the test directory
|
|
105 |
testDir = aRaptor.home.Append("test", "tmp")
|
|
106 |
|
|
107 |
interface = raptor_data.Interface("EXE")
|
|
108 |
interface.SetProperty("flm", "/lib/flm/exe.flm")
|
|
109 |
interface.AddParameter(raptor_data.Parameter("EXEPARAM1"))
|
|
110 |
interface.AddParameter(raptor_data.Parameter("EXEPARAM2"))
|
|
111 |
|
|
112 |
# set up a build with 2 top-level Specification nodes
|
|
113 |
|
|
114 |
# top 1 has 2 sub-nodes
|
|
115 |
top1 = raptor_data.Specification("top1")
|
|
116 |
top1.SetInterface(interface)
|
|
117 |
top1v = raptor_data.Variant()
|
|
118 |
top1v.AddOperation(raptor_data.Set("EXEPARAM1", "top1 p1"))
|
|
119 |
top1.AddVariant(top1v)
|
|
120 |
# top 1 child 1 has 1 sub-node
|
|
121 |
top1c1 = raptor_data.Specification("top1c1")
|
|
122 |
top1c1.SetInterface(interface)
|
|
123 |
top1c1v = raptor_data.Variant()
|
|
124 |
top1c1v.AddOperation(raptor_data.Set("EXEPARAM1", "top1c1 p1"))
|
|
125 |
top1c1.AddVariant(top1c1v)
|
|
126 |
# top 1 child 1 child
|
|
127 |
top1c1c = raptor_data.Specification("top1c1c")
|
|
128 |
top1c1c.SetInterface(interface)
|
|
129 |
top1c1cv = raptor_data.Variant()
|
|
130 |
top1c1cv.AddOperation(raptor_data.Set("EXEPARAM1", "top1c1c p1"))
|
|
131 |
top1c1c.AddVariant(top1c1cv)
|
|
132 |
top1c1.AddChildSpecification(top1c1c)
|
|
133 |
# top 1 child 2 has 1 sub-node
|
|
134 |
top1c2 = raptor_data.Specification("top1c2")
|
|
135 |
top1c2.SetInterface(interface)
|
|
136 |
top1c2v = raptor_data.Variant()
|
|
137 |
top1c2v.AddOperation(raptor_data.Set("EXEPARAM1", "top1c2 p1"))
|
|
138 |
top1c2.AddVariant(top1c2v)
|
|
139 |
# top 1 child 2 child
|
|
140 |
top1c2c = raptor_data.Specification("top1c2c")
|
|
141 |
top1c2c.SetInterface(interface)
|
|
142 |
top1c2cv = raptor_data.Variant()
|
|
143 |
top1c2cv.AddOperation(raptor_data.Set("EXEPARAM1", "top1c2c p1"))
|
|
144 |
top1c2c.AddVariant(top1c2cv)
|
|
145 |
top1c2.AddChildSpecification(top1c2c)
|
|
146 |
#
|
|
147 |
top1.AddChildSpecification(top1c1)
|
|
148 |
top1.AddChildSpecification(top1c2)
|
|
149 |
|
|
150 |
# top 2 has no sub-nodes
|
|
151 |
top2 = raptor_data.Specification("top2")
|
|
152 |
top2.SetInterface(interface)
|
|
153 |
top2v = raptor_data.Variant()
|
|
154 |
top2v.AddOperation(raptor_data.Set("EXEPARAM1", "top2 p1"))
|
|
155 |
top2.AddVariant(top2v)
|
|
156 |
#
|
|
157 |
|
|
158 |
# use a pair of minimal Configurations
|
|
159 |
|
|
160 |
conf1 = raptor_data.Variant("conf1")
|
|
161 |
c1var = raptor_data.Variant()
|
|
162 |
c1var.AddOperation(raptor_data.Set("EXEPARAM2", "conf1 p2"))
|
|
163 |
buildunit1 = raptor_data.BuildUnit("conf1.c1var",[conf1,c1var])
|
|
164 |
|
|
165 |
conf2 = raptor_data.Variant("conf2")
|
|
166 |
c2var = raptor_data.Variant()
|
|
167 |
c2var.AddOperation(raptor_data.Set("EXEPARAM2", "conf2 p2"))
|
|
168 |
buildunit2 = raptor_data.BuildUnit("conf2.c2var",[conf2,c2var])
|
|
169 |
|
|
170 |
# delete any old Makefiles
|
|
171 |
makefiles = [testDir.Append("Makefile")]
|
|
172 |
makefiles.append(testDir.Append("conf1.c1var", "top1", "Makefile"))
|
|
173 |
makefiles.append(testDir.Append("conf1.c1var", "top1", "top1c1", "Makefile"))
|
|
174 |
makefiles.append(testDir.Append("conf1.c1var", "top1", "top1c1", "top1c1c", "Makefile"))
|
|
175 |
makefiles.append(testDir.Append("conf1.c1var", "top1", "top1c2", "Makefile"))
|
|
176 |
makefiles.append(testDir.Append("conf1.c1var", "top1", "top1c2", "top1c2c", "Makefile"))
|
|
177 |
makefiles.append(testDir.Append("conf1.c1var", "top2", "Makefile"))
|
|
178 |
makefiles.append(testDir.Append("conf2.c2var", "top1", "Makefile"))
|
|
179 |
makefiles.append(testDir.Append("conf2.c2var", "top1", "top1c1", "Makefile"))
|
|
180 |
makefiles.append(testDir.Append("conf2.c2var", "top1", "top1c1", "top1c1c", "Makefile"))
|
|
181 |
makefiles.append(testDir.Append("conf2.c2var", "top1", "top1c2", "Makefile"))
|
|
182 |
makefiles.append(testDir.Append("conf2.c2var", "top1", "top1c2", "top1c2c", "Makefile"))
|
|
183 |
makefiles.append(testDir.Append("conf2.c2var", "top2", "Makefile"))
|
|
184 |
self.cleanMakefiles(makefiles)
|
|
185 |
|
|
186 |
# create new Makefiles
|
|
187 |
maker = raptor_make.MakeEngine(aRaptor)
|
|
188 |
maker.Write(makefiles[0], [top1, top2], [buildunit1, buildunit2])
|
|
189 |
|
|
190 |
# test and clean
|
|
191 |
self.failUnless(self.checkMakefiles(makefiles))
|
|
192 |
self.cleanMakefiles(makefiles)
|
|
193 |
|
|
194 |
|
|
195 |
def testFilteredMake(self):
|
|
196 |
# use a bare Raptor object
|
|
197 |
aRaptor = raptor.Raptor()
|
|
198 |
aRaptor.ProcessConfig()
|
|
199 |
aRaptor.LoadCache()
|
|
200 |
aRaptor.pruneDuplicateMakefiles = False
|
|
201 |
aRaptor.writeSingleMakefile = False
|
5
|
202 |
aRaptor.debugOutput = True
|
3
|
203 |
|
|
204 |
# find the test directory
|
|
205 |
testDir = aRaptor.home.Append("test", "tmp")
|
|
206 |
|
|
207 |
# the root Specification is a Filter
|
|
208 |
top = raptor_data.Filter("top")
|
|
209 |
|
|
210 |
# the test condition
|
|
211 |
top.SetVariableCondition("SWITCH", "ARM")
|
|
212 |
top.AddVariableCondition("TOGGLE", ["A", "B", "C"])
|
|
213 |
top.SetConfigCondition("confA.confAv")
|
|
214 |
top.AddConfigCondition("confB.confBv")
|
|
215 |
|
|
216 |
# True part
|
|
217 |
ifaceT = raptor_data.Interface("T.EXE")
|
|
218 |
ifaceT.SetProperty("flm", "/lib/flm/exeT.flm")
|
|
219 |
ifaceT.AddParameter(raptor_data.Parameter("TEXEPARAM"))
|
|
220 |
ifaceT.AddParameter(raptor_data.Parameter("SWITCH"))
|
|
221 |
ifaceT.AddParameter(raptor_data.Parameter("TOGGLE"))
|
|
222 |
top.SetInterface(ifaceT)
|
|
223 |
#
|
|
224 |
varT = raptor_data.Variant()
|
|
225 |
varT.AddOperation(raptor_data.Set("TEXEPARAM", "top True"))
|
|
226 |
top.AddVariant(varT)
|
|
227 |
#
|
|
228 |
childT = raptor_data.Specification("Tchild")
|
|
229 |
childT.SetInterface(ifaceT)
|
|
230 |
childTv = raptor_data.Variant()
|
|
231 |
childTv.AddOperation(raptor_data.Set("TEXEPARAM", "child True"))
|
|
232 |
childT.AddVariant(childTv)
|
|
233 |
#
|
|
234 |
top.AddChildSpecification(childT)
|
|
235 |
|
|
236 |
# False part
|
|
237 |
ifaceF = raptor_data.Interface("F.EXE")
|
|
238 |
ifaceF.SetProperty("flm", "/lib/flm/exeF.flm")
|
|
239 |
ifaceF.AddParameter(raptor_data.Parameter("FEXEPARAM"))
|
|
240 |
ifaceF.AddParameter(raptor_data.Parameter("SWITCH"))
|
|
241 |
ifaceF.AddParameter(raptor_data.Parameter("TOGGLE"))
|
|
242 |
top.Else.SetInterface(ifaceF)
|
|
243 |
#
|
|
244 |
varF = raptor_data.Variant()
|
|
245 |
varF.AddOperation(raptor_data.Set("FEXEPARAM", "top False"))
|
|
246 |
top.Else.AddVariant(varF)
|
|
247 |
#
|
|
248 |
childF = raptor_data.Specification("Fchild")
|
|
249 |
childF.SetInterface(ifaceF)
|
|
250 |
childFv = raptor_data.Variant()
|
|
251 |
childFv.AddOperation(raptor_data.Set("FEXEPARAM", "child False"))
|
|
252 |
childF.AddVariant(childFv)
|
|
253 |
#
|
|
254 |
top.Else.AddChildSpecification(childF)
|
|
255 |
|
|
256 |
|
|
257 |
# Configurations
|
|
258 |
|
|
259 |
confA = raptor_data.Variant("confA") # hit
|
|
260 |
confAv = raptor_data.Variant()
|
|
261 |
confAv.AddOperation(raptor_data.Set("SWITCH", "confA switch"))
|
|
262 |
confAv.AddOperation(raptor_data.Set("TOGGLE", "confA toggle"))
|
|
263 |
b1 = raptor_data.BuildUnit("confA.confAv",[confA,confAv])
|
|
264 |
|
|
265 |
confB = raptor_data.Variant("confB") # hit
|
|
266 |
confBv = raptor_data.Variant()
|
|
267 |
confBv.AddOperation(raptor_data.Set("SWITCH", "confB switch"))
|
|
268 |
confBv.AddOperation(raptor_data.Set("TOGGLE", "confB toggle"))
|
|
269 |
b2 = raptor_data.BuildUnit("confB.confBv",[confB,confBv])
|
|
270 |
|
|
271 |
confC = raptor_data.Variant("confC")
|
|
272 |
confCv = raptor_data.Variant()
|
|
273 |
confCv.AddOperation(raptor_data.Set("SWITCH", "confC switch"))
|
|
274 |
confCv.AddOperation(raptor_data.Set("TOGGLE", "confC toggle"))
|
|
275 |
b3 = raptor_data.BuildUnit("confC.confCv",[confC,confCv])
|
|
276 |
|
|
277 |
confD = raptor_data.Variant("confD")
|
|
278 |
confDv = raptor_data.Variant()
|
|
279 |
confDv.AddOperation(raptor_data.Set("SWITCH", "ARM")) # hit
|
|
280 |
confDv.AddOperation(raptor_data.Set("TOGGLE", "confD toggle"))
|
|
281 |
b4 = raptor_data.BuildUnit("confD.confDv",[confD,confDv])
|
|
282 |
|
|
283 |
confE = raptor_data.Variant("confE")
|
|
284 |
confEv = raptor_data.Variant()
|
|
285 |
confEv.AddOperation(raptor_data.Set("SWITCH", "confE switch"))
|
|
286 |
confEv.AddOperation(raptor_data.Set("TOGGLE", "B")) # hit
|
|
287 |
b5 = raptor_data.BuildUnit("confE.confEv",[confE,confEv])
|
|
288 |
|
|
289 |
confF = raptor_data.Variant("confF")
|
|
290 |
confFv = raptor_data.Variant()
|
|
291 |
confFv.AddOperation(raptor_data.Set("SWITCH", "confF switch"))
|
|
292 |
confFv.AddOperation(raptor_data.Set("TOGGLE", "confF toggle"))
|
|
293 |
b6 = raptor_data.BuildUnit("confF.confFv",[confF,confFv])
|
|
294 |
|
|
295 |
# delete any old Makefiles
|
|
296 |
makefiles = [testDir.Append("Makefile")]
|
|
297 |
makefiles.append(testDir.Append("confA.confAv", "top", "Makefile"))
|
|
298 |
makefiles.append(testDir.Append("confB.confBv", "top", "Makefile"))
|
|
299 |
makefiles.append(testDir.Append("confC.confCv", "top", "Makefile"))
|
|
300 |
makefiles.append(testDir.Append("confD.confDv", "top", "Makefile"))
|
|
301 |
makefiles.append(testDir.Append("confE.confEv", "top", "Makefile"))
|
|
302 |
makefiles.append(testDir.Append("confF.confFv", "top", "Makefile"))
|
|
303 |
makefiles.append(testDir.Append("confA.confAv", "top", "Tchild", "Makefile"))
|
|
304 |
makefiles.append(testDir.Append("confB.confBv", "top", "Tchild", "Makefile"))
|
|
305 |
makefiles.append(testDir.Append("confC.confCv", "top", "Fchild", "Makefile"))
|
|
306 |
makefiles.append(testDir.Append("confD.confDv", "top", "Tchild", "Makefile"))
|
|
307 |
makefiles.append(testDir.Append("confE.confEv", "top", "Tchild", "Makefile"))
|
|
308 |
makefiles.append(testDir.Append("confF.confFv", "top", "Fchild", "Makefile"))
|
|
309 |
self.cleanMakefiles(makefiles)
|
|
310 |
|
|
311 |
# create new Makefiles
|
|
312 |
maker = raptor_make.MakeEngine(aRaptor)
|
5
|
313 |
maker.Write(makefiles[0], specs=[top], configs=[b1,b2,b3,b4,b5,b6])
|
3
|
314 |
|
|
315 |
# test and clean
|
|
316 |
self.failUnless(self.checkMakefiles(makefiles))
|
|
317 |
self.cleanMakefiles(makefiles)
|
|
318 |
|
|
319 |
|
|
320 |
def testPruneDuplicates(self):
|
|
321 |
# use a bare Raptor object
|
|
322 |
aRaptor = raptor.Raptor()
|
|
323 |
aRaptor.ProcessConfig()
|
|
324 |
aRaptor.LoadCache()
|
|
325 |
aRaptor.pruneDuplicateMakefiles = True
|
|
326 |
aRaptor.writeSingleMakefile = False
|
|
327 |
|
|
328 |
# find the test directory
|
|
329 |
testDir = aRaptor.home.Append("test", "tmp")
|
|
330 |
|
|
331 |
# an interface with defaults
|
|
332 |
iface = raptor_data.Interface("I.EXE")
|
|
333 |
iface.SetProperty("flm", "/lib/flm/iexe.flm")
|
|
334 |
iface.AddParameter(raptor_data.Parameter("A", "1"))
|
|
335 |
iface.AddParameter(raptor_data.Parameter("B", "2"))
|
|
336 |
iface.AddParameter(raptor_data.Parameter("C", "3"))
|
|
337 |
|
|
338 |
# each Specification is a Filter
|
|
339 |
# f1 is empty, f2 and f3 are equal
|
|
340 |
# so f2 should be the only Makefile generated
|
|
341 |
|
|
342 |
f1 = raptor_data.Filter("f1")
|
|
343 |
f1.SetConfigCondition("c1")
|
|
344 |
|
|
345 |
f2 = raptor_data.Filter("f2")
|
|
346 |
f2.SetConfigCondition("c2")
|
|
347 |
f2.SetInterface(iface)
|
|
348 |
|
|
349 |
f3 = raptor_data.Filter("f3")
|
|
350 |
f3.SetConfigCondition("c3")
|
|
351 |
f3.SetInterface(iface)
|
|
352 |
|
|
353 |
# Configurations
|
|
354 |
c1 = raptor_data.Variant("c1")
|
|
355 |
c2 = raptor_data.Variant("c2")
|
|
356 |
c3 = raptor_data.Variant("c3")
|
|
357 |
|
|
358 |
# Build Units
|
|
359 |
b1 = raptor_data.BuildUnit("c1",[c1])
|
|
360 |
b2 = raptor_data.BuildUnit("c2",[c2])
|
|
361 |
b3 = raptor_data.BuildUnit("c3",[c3])
|
|
362 |
|
|
363 |
# Makefiles we expect
|
|
364 |
makefiles = [testDir.Append("Makefile")]
|
|
365 |
makefiles.append(testDir.Append("c2", "f2", "Makefile"))
|
|
366 |
self.cleanMakefiles(makefiles)
|
|
367 |
|
|
368 |
# Makefiles we do not expect
|
|
369 |
prunes = []
|
|
370 |
prunes.append(testDir.Append("c1", "f1", "Makefile"))
|
|
371 |
prunes.append(testDir.Append("c1", "f2", "Makefile"))
|
|
372 |
prunes.append(testDir.Append("c1", "f3", "Makefile"))
|
|
373 |
prunes.append(testDir.Append("c2", "f1", "Makefile"))
|
|
374 |
prunes.append(testDir.Append("c2", "f3", "Makefile"))
|
|
375 |
prunes.append(testDir.Append("c3", "f1", "Makefile"))
|
|
376 |
prunes.append(testDir.Append("c3", "f2", "Makefile"))
|
|
377 |
prunes.append(testDir.Append("c3", "f3", "Makefile"))
|
|
378 |
self.cleanMakefiles(prunes)
|
|
379 |
|
|
380 |
# create new Makefiles
|
|
381 |
maker = raptor_make.MakeEngine(aRaptor)
|
|
382 |
maker.Write(makefiles[0], [f1, f2, f3], [b1, b2, b3])
|
|
383 |
|
|
384 |
# test and clean
|
|
385 |
self.failUnless(self.checkMakefiles(makefiles))
|
|
386 |
self.cleanMakefiles(makefiles)
|
|
387 |
self.failUnless(self.checkNotMakefiles(prunes))
|
|
388 |
self.cleanMakefiles(prunes)
|
|
389 |
|
|
390 |
|
|
391 |
# run all the tests
|
|
392 |
|
|
393 |
from raptor_tests import SmokeTest
|
|
394 |
|
|
395 |
def run():
|
|
396 |
t = SmokeTest()
|
|
397 |
t.id = "999"
|
|
398 |
t.name = "raptor_make_unit"
|
|
399 |
|
|
400 |
tests = unittest.makeSuite(TestRaptorMake)
|
|
401 |
result = unittest.TextTestRunner(verbosity=2).run(tests)
|
|
402 |
|
|
403 |
if result.wasSuccessful():
|
|
404 |
t.result = SmokeTest.PASS
|
|
405 |
else:
|
|
406 |
t.result = SmokeTest.FAIL
|
|
407 |
|
|
408 |
return t
|
|
409 |
|