|
1 #============================================================================ |
|
2 #Name : test_packager_datasources.py |
|
3 #Part of : Helium |
|
4 |
|
5 #Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
6 #All rights reserved. |
|
7 #This component and the accompanying materials are made available |
|
8 #under the terms of the License "Eclipse Public License v1.0" |
|
9 #which accompanies this distribution, and is available |
|
10 #at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
11 # |
|
12 #Initial Contributors: |
|
13 #Nokia Corporation - initial contribution. |
|
14 # |
|
15 #Contributors: |
|
16 # |
|
17 #Description: |
|
18 #=============================================================================== |
|
19 import unittest |
|
20 from unittestadditions import skip |
|
21 skipTest = False |
|
22 try: |
|
23 import packager.datasources |
|
24 except ImportError: |
|
25 skipTest = True |
|
26 import os |
|
27 from StringIO import StringIO |
|
28 import tempfile |
|
29 import xml.sax |
|
30 import logging |
|
31 import sys |
|
32 |
|
33 #logging.basicConfig(level=logging.DEBUG) |
|
34 logger = logging.getLogger('nokiatest.datasources') |
|
35 |
|
36 class DataSourceInterfaceTest(unittest.TestCase): |
|
37 """ Verifying the datasource interface. """ |
|
38 |
|
39 @skip(skipTest) |
|
40 def test_datasource_getComponent(self): |
|
41 """ Check that getComponent is not implemented. """ |
|
42 ds = packager.datasources.DataSource('/') |
|
43 self.assertRaises(NotImplementedError, ds.getComponents) |
|
44 |
|
45 @skip(skipTest) |
|
46 def test_datasource_getHelp(self): |
|
47 """ Check that no help is defined. """ |
|
48 ds = packager.datasources.DataSource('/') |
|
49 self.assertEqual(None, ds.getHelp()) |
|
50 self.assertEqual(ds.help, ds.getHelp()) |
|
51 |
|
52 class CMakerDataSourceTest(unittest.TestCase): |
|
53 """ Unit test for CMakerDataSource """ |
|
54 @skip(skipTest) |
|
55 def test_whatlog_missing(self): |
|
56 """ getComponent should fail if whatlog is missing. """ |
|
57 data = {} |
|
58 ds = packager.datasources.CMakerDataSource('/', data) |
|
59 self.assertRaises(packager.datasources.MissingProperty, ds.getComponents) |
|
60 |
|
61 @skip(skipTest) |
|
62 def test_configdir_missing(self): |
|
63 """ getComponent should fail if configdir is missing. """ |
|
64 data = {'whatlog': 'somevalue'} |
|
65 ds = packager.datasources.CMakerDataSource('/', data) |
|
66 self.assertRaises(packager.datasources.MissingProperty, ds.getComponents) |
|
67 |
|
68 @skip(skipTest) |
|
69 def test_invalid_whatlog_invalid_configdir(self): |
|
70 """ getComponent should fail because whatlog doesn't exists. """ |
|
71 data = {'whatlog': 'somevalue', 'configdir': 'somevalue'} |
|
72 ds = packager.datasources.CMakerDataSource('/', data) |
|
73 self.assertRaises(Exception, ds.getComponents) |
|
74 |
|
75 @skip(skipTest) |
|
76 def test_valid_whatlog_invalid_configdir(self): |
|
77 """ getComponent should fail because configdir doesn't exists. """ |
|
78 data = {'whatlog': __file__, 'configdir': 'somevalue'} |
|
79 ds = packager.datasources.CMakerDataSource('/', data) |
|
80 self.assertRaises(Exception, ds.getComponents) |
|
81 |
|
82 @skip(skipTest) |
|
83 def test_install_log_parsing(self): |
|
84 """ Test the parsing of a regular cmaker install log. """ |
|
85 log = r"""C:\APPS\actperl\bin\perl.exe -e 'use File::Copy; copy(q(src/env.mk),q(/epoc32/tools/cmaker/env.mk))' |
|
86 C:\APPS\actperl\bin\perl.exe -e 'use File::Copy; copy(q(src/functions.mk),q(/epoc32/tools/cmaker/functions.mk))' |
|
87 C:\APPS\actperl\bin\perl.exe -e 'use File::Copy; copy(q(src/include_template.mk),q(/epoc32/tools/cmaker/include_template.mk))' |
|
88 C:\APPS\actperl\bin\perl.exe -e 'use File::Copy; copy(q(src/settings.mk),q(/epoc32/tools/cmaker/settings.mk))' |
|
89 C:\APPS\actperl\bin\perl.exe -e 'use File::Copy; copy(q(src/tools.mk),q(/epoc32/tools/cmaker/tools.mk))' |
|
90 C:\APPS\actperl\bin\perl.exe -e 'use File::Copy; copy(q(src/utils.mk),q(/epoc32/tools/cmaker/utils.mk))' |
|
91 C:\APPS\actperl\bin\perl.exe -e 'use File::Copy; copy(q(bin/mingw_make.exe),q(/epoc32/tools/rom/mingw_make.exe))' |
|
92 C:\APPS\actperl\bin\perl.exe -e 'use File::Copy; copy(q(src/cmaker.cmd),q(/epoc32/tools/cmaker.cmd))' |
|
93 """ |
|
94 (handle, filename) = tempfile.mkstemp() |
|
95 os.write(handle, log) |
|
96 os.close(handle) |
|
97 |
|
98 data = {'whatlog': filename, 'configdir': os.path.dirname(__file__)} |
|
99 ds = packager.datasources.CMakerDataSource('/', data) |
|
100 components = ds.getComponents() |
|
101 assert len(components) == 1 |
|
102 assert len(components[0].getTargetFiles()) == 8 |
|
103 assert 'epoc32/tools/rom/mingw_make.exe' in components[0].getTargetFiles() |
|
104 |
|
105 os.remove(filename) |
|
106 |
|
107 |
|
108 @skip(skipTest) |
|
109 def test_what_log_parsing_windows(self): |
|
110 """ Test the parsing of a regular cmaker what log (windows). """ |
|
111 if sys.platform == 'win32': |
|
112 log = r"""\epoc32\tools\rom\image.txt |
|
113 \CreateImage.cmd |
|
114 cd \config\overlay && xcopy *.* \ /F /R /Y /S |
|
115 0 File(s) copied |
|
116 cd \tools\toolsmodTB92 && xcopy *.* \ /F /R /Y /S |
|
117 Y:\tools\toolsmodTB92\epoc32\tools\abld.pl -> Y:\epoc32\tools\abld.pl |
|
118 Y:\tools\toolsmodTB92\epoc32\tools\bldmake.pl -> Y:\epoc32\tools\bldmake.pl |
|
119 """ |
|
120 (handle, filename) = tempfile.mkstemp() |
|
121 os.write(handle, log) |
|
122 os.close(handle) |
|
123 |
|
124 data = {'whatlog': filename, 'configdir': os.path.dirname(__file__)} |
|
125 ds = packager.datasources.CMakerDataSource('/', data) |
|
126 components = ds.getComponents() |
|
127 assert len(components) == 1 |
|
128 assert len(components[0].getTargetFiles()) == 2 |
|
129 print components[0].getTargetFiles() |
|
130 assert 'CreateImage.cmd' in components[0].getTargetFiles() |
|
131 assert 'epoc32/tools/rom/image.txt' in components[0].getTargetFiles() |
|
132 assert 'epoc32/tools/abld.pl' not in components[0].getTargetFiles() |
|
133 assert 'epoc32/tools/bldmake.pl' not in components[0].getTargetFiles() |
|
134 |
|
135 os.remove(filename) |
|
136 |
|
137 @skip(skipTest) |
|
138 def test_what_log_parsing_linux(self): |
|
139 """ Test the parsing of a regular cmaker what log (linux). """ |
|
140 if sys.platform != 'win32': |
|
141 log = r"""/epoc32/tools/rom/image.txt |
|
142 /CreateImage.cmd |
|
143 """ |
|
144 (handle, filename) = tempfile.mkstemp() |
|
145 os.write(handle, log) |
|
146 os.close(handle) |
|
147 |
|
148 data = {'whatlog': filename, 'configdir': os.path.dirname(__file__)} |
|
149 ds = packager.datasources.CMakerDataSource('/', data) |
|
150 components = ds.getComponents() |
|
151 assert len(components) == 1 |
|
152 assert len(components[0].getTargetFiles()) == 2 |
|
153 print components[0].getTargetFiles() |
|
154 assert 'CreateImage.cmd' in components[0].getTargetFiles() |
|
155 assert 'epoc32/tools/rom/image.txt' in components[0].getTargetFiles() |
|
156 |
|
157 os.remove(filename) |
|
158 |
|
159 |
|
160 @skip(skipTest) |
|
161 def test_getHelp(self): |
|
162 """ Check that help is defined for CMakerDataSource. """ |
|
163 ds = packager.datasources.CMakerDataSource('/', {}) |
|
164 self.assertNotEqual(None, ds.getHelp()) |
|
165 self.assertEqual(ds.help, ds.getHelp()) |
|
166 |
|
167 |
|
168 class SBSDataSourceTest(unittest.TestCase): |
|
169 """ Unit test case for SBSDataSource """ |
|
170 @skip(skipTest) |
|
171 def test_getHelp(self): |
|
172 """ Check that help is defined for SBSDataSource. """ |
|
173 ds = packager.datasources.SBSDataSource('/', {}) |
|
174 self.assertNotEqual(None, ds.getHelp()) |
|
175 self.assertEqual(ds.help, ds.getHelp()) |
|
176 |
|
177 |
|
178 class SysdefComponentListTest(unittest.TestCase): |
|
179 """ Unit test case for packager.datasources.sbs.SysdefComponentList """ |
|
180 sysdef = None |
|
181 |
|
182 def setUp(self): |
|
183 self.sysdef = StringIO("""<?xml version=\"1.0\" encoding=\"UTF-8\"?> |
|
184 <SystemDefinition name="main" schema="1.4.0"> |
|
185 <systemModel> |
|
186 <layer name="layer1"> |
|
187 <module name="module1"> |
|
188 <component name="cmp1"> |
|
189 <unit unitID="unit1" name="unit1.name" mrp="" filter="" bldFile="path/to/component1"/> |
|
190 </component> |
|
191 </module> |
|
192 </layer> |
|
193 <layer name="layer2"> |
|
194 <module name="module2"> |
|
195 <component name="cmp2"> |
|
196 <unit unitID="unit2" name="unit2.name" mrp="" filter="" bldFile="path\\to\\Component2"/> |
|
197 </component> |
|
198 </module> |
|
199 </layer> |
|
200 </systemModel> |
|
201 </SystemDefinition> |
|
202 """) |
|
203 |
|
204 @skip(skipTest) |
|
205 def test_unit_parsing(self): |
|
206 """ SysdefComponentList extract correctly the units... """ |
|
207 cl = packager.datasources.sbs.SysdefComponentList('/') |
|
208 p = xml.sax.make_parser() |
|
209 p.setContentHandler(cl) |
|
210 p.parse(self.sysdef) |
|
211 assert len(cl) == 2 |
|
212 assert cl['unit1_name']['path'] == os.path.normpath('/path/to/component1') |
|
213 assert cl['unit2_name']['path'] == os.path.normpath('/path/to/Component2') |
|
214 assert cl['unit2_name']['name'] == 'unit2_name' |
|
215 |
|
216 @skip(skipTest) |
|
217 def test_get_component_name_by_path(self): |
|
218 """ Check if get_component_name_by_path is case unsensitive. """ |
|
219 cl = packager.datasources.sbs.SysdefComponentList('/') |
|
220 p = xml.sax.make_parser() |
|
221 p.setContentHandler(cl) |
|
222 p.parse(self.sysdef) |
|
223 |
|
224 # reading path should be case independent. |
|
225 assert cl.get_component_name_by_path(os.path.normpath('/path/to/Component2')) == 'unit2_name' |
|
226 assert cl.get_component_name_by_path(os.path.normpath('/path/to/component2')) == 'unit2_name' |
|
227 |
|
228 @skip(skipTest) |
|
229 def test_get_component_name_by_path_invalid(self): |
|
230 """ Check that get_component_name_by_path is raising an exception if """ |
|
231 cl = packager.datasources.sbs.SysdefComponentList('/') |
|
232 p = xml.sax.make_parser() |
|
233 p.setContentHandler(cl) |
|
234 p.parse(self.sysdef) |
|
235 |
|
236 # reading path should be case independent. |
|
237 try: |
|
238 cl.get_component_name_by_path(os.path.normpath('/path/to/invalid')) |
|
239 except packager.datasources.sbs.ComponentNotFound: |
|
240 pass |
|
241 else: |
|
242 self.fail("Expected get_component_name_by_path to raise an exception in case of non-existing component definition.") |
|
243 |
|
244 |
|
245 class SysdefComponentListSysdef3ParsingTest(unittest.TestCase): |
|
246 """ Unit test case for packager.datasources.sbs.SysdefComponentList """ |
|
247 sysdef = None |
|
248 |
|
249 def setUp(self): |
|
250 self.sysdef = StringIO("""<?xml version="1.0" encoding="UTF-8"?> |
|
251 <SystemDefinition schema="3.0.0" id-namespace="http://www.symbian.org/system-definition"> |
|
252 <systemModel name="sf_"> |
|
253 <layer id="app" name="app"> |
|
254 <package id="helloworldcons" name="helloworldcons" levels="demo"> |
|
255 <collection id="helloworldcons_apps" name="helloworldcons_apps" level="demo"> |
|
256 <component id="helloworldcons_app" name="helloworldcons app" purpose="development"> |
|
257 <unit bldFile="/sf/app/helloworldcons/group" mrp="/sf/app/helloworldcons/"/> |
|
258 </component> |
|
259 </collection> |
|
260 </package> |
|
261 </layer> |
|
262 <layer id="mw" name="mw"> |
|
263 <package id="helloworldapi" name="helloworldapi" levels="demo"> |
|
264 <collection id="helloworld_apis" name="helloworlds APIs" level="demo"> |
|
265 <component id="helloworld_api" name="Hello World API" purpose="development"> |
|
266 <unit bldFile="/sf/mw/helloworldapi/group" mrp="/sf/mw/helloworldapi/"/> |
|
267 </component> |
|
268 </collection> |
|
269 </package> |
|
270 </layer> |
|
271 </systemModel> |
|
272 </SystemDefinition> |
|
273 """) |
|
274 |
|
275 @skip(skipTest) |
|
276 def test_unit_parsing(self): |
|
277 """ SysdefComponentList extract correctly the units... """ |
|
278 cl = packager.datasources.sbs.SysdefComponentList('/') |
|
279 p = xml.sax.make_parser() |
|
280 p.setContentHandler(cl) |
|
281 p.parse(self.sysdef) |
|
282 assert len(cl) == 2 |
|
283 print cl |
|
284 assert cl['helloworldcons_app_sf_app_helloworldcons_group']['path'] == os.path.normpath('/sf/app/helloworldcons/group') |
|
285 assert cl['helloworld_api_sf_mw_helloworldapi_group']['path'] == os.path.normpath('/sf/mw/helloworldapi/group') |
|
286 assert cl['helloworld_api_sf_mw_helloworldapi_group']['name'] == 'helloworld_api' |
|
287 |
|
288 @skip(skipTest) |
|
289 def test_get_component_name_by_path(self): |
|
290 """ Check if get_component_name_by_path is case unsensitive. """ |
|
291 cl = packager.datasources.sbs.SysdefComponentList('/') |
|
292 p = xml.sax.make_parser() |
|
293 p.setContentHandler(cl) |
|
294 p.parse(self.sysdef) |
|
295 |
|
296 # reading path should be case independent. |
|
297 assert cl.get_component_name_by_path(os.path.normpath('/sf/app/helloworldcons/group')) == 'helloworldcons_app_sf_app_helloworldcons_group' |
|
298 assert cl.get_component_name_by_path(os.path.normpath('/sf/mw/helloworldapi/group')) == 'helloworld_api_sf_mw_helloworldapi_group' |
|
299 |
|
300 @skip(skipTest) |
|
301 def test_get_component_name_by_path_invalid(self): |
|
302 """ Check that get_component_name_by_path is raising an exception if """ |
|
303 cl = packager.datasources.sbs.SysdefComponentList('/') |
|
304 p = xml.sax.make_parser() |
|
305 p.setContentHandler(cl) |
|
306 p.parse(self.sysdef) |
|
307 |
|
308 # reading path should be case independent. |
|
309 try: |
|
310 cl.get_component_name_by_path(os.path.normpath('/path/to/invalid')) |
|
311 except packager.datasources.sbs.ComponentNotFound: |
|
312 pass |
|
313 else: |
|
314 self.fail("Expected get_component_name_by_path to raise an exception in case of non-existing component definition.") |
|
315 |
|
316 |
|
317 class ObyParserTest(unittest.TestCase): |
|
318 """ Unit test case for packager.datasources.imaker.ObyParser """ |
|
319 oby = None |
|
320 |
|
321 def setUp(self): |
|
322 (hld, filename) = tempfile.mkstemp(".oby", "datasource_test") |
|
323 os.write(hld, """ |
|
324 rofssize=0x10000000 |
|
325 # file=\\epoc32\\release\\ARMV5\\urel\\COMMENT.DLL "Sys\\Bin\\EDISP.DLL" |
|
326 file=\\epoc32\\release\\ARMV5\\urel\\edisp.dll "Sys\\Bin\\EDISP.DLL" |
|
327 data=\\epoc32\\data\\Z\\Private\\10202BE9\\20000585.txt "Private\\10202BE9\\20000585.txt" |
|
328 extension[0x09080004]=\\epoc32\\release\ARMV5\urel\power_resources.dll "Sys\\Bin\\power_resources.dll" |
|
329 variant[0x09080004]=\\epoc32\\release\\ARMV5\\urel\\ecust.b23b7726cf4b5801b0dc14102b245fb8.dll "Sys\\Bin\\ecust.dll" |
|
330 # file="\\epoc32\\release\\ARMV5\\urel\\edisp.dll" "Sys\\Bin\\EDISP.DLL" |
|
331 data="/output/release_flash_images/langpack_01/rofs2/variant/private/10202be9/10281872.txt" "private\10202be9\10281872.txt" |
|
332 """) |
|
333 os.close(hld) |
|
334 self.oby = filename |
|
335 |
|
336 def tearDown(self): |
|
337 os.remove(self.oby) |
|
338 |
|
339 @skip(skipTest) |
|
340 def test_oby(self): |
|
341 """ Testing the extraction of source files from an processed Oby file. """ |
|
342 print self.oby |
|
343 p = packager.datasources.imaker.ObyParser('/', self.oby) |
|
344 files = p.getSourceFiles() |
|
345 print files |
|
346 assert len(files) == 5 |
|
347 assert os.path.normpath(r'\epoc32\release\ARMV5\urel\edisp.dll'.replace('\\', os.sep).replace('/', os.sep)) in files |
|
348 assert os.path.normpath(r'\epoc32\data\Z\Private\10202BE9\20000585.txt'.replace('\\', os.sep).replace('/', os.sep)) in files |
|
349 assert os.path.normpath(r'\epoc32\release\ARMV5\urel\power_resources.dll'.replace('\\', os.sep).replace('/', os.sep)) in files |
|
350 assert os.path.normpath(r'\epoc32\release\ARMV5\urel\ecust.b23b7726cf4b5801b0dc14102b245fb8.dll'.replace('\\', os.sep).replace('/', os.sep)) in files |
|
351 assert os.path.normpath(r'/output/release_flash_images/langpack_01/rofs2/variant/private/10202be9/10281872.txt'.replace('\\', os.sep).replace('/', os.sep)) in files |
|
352 |
|
353 |
|
354 class ConEDataSourceTest(unittest.TestCase): |
|
355 """ ConfToolDataSource unittest. """ |
|
356 |
|
357 @skip(skipTest) |
|
358 def test_cone_input(self): |
|
359 """ Testing ConE output log parsing. """ |
|
360 log = """ Generating file '\\epoc32\\release\\winscw\\urel\\z\\private\\10202BE9\\10208dd7.txt'... |
|
361 DEBUG : cone.crml(assets/symbianos/implml/usbmanager_10285c46.crml) |
|
362 Generating file '\\epoc32\\release\\winscw\\urel\\z\\private\\10202BE9\\10285c46.txt'... |
|
363 DEBUG : cone.crml(assets/symbianos/implml/usbmanager_10286a43.crml) |
|
364 Generating file '\\epoc32\\release\\winscw\\urel\\z\\private\\10202BE9\\10286a43.txt'... |
|
365 INFO : cone |
|
366 Adding impl CrmlImpl(ref='assets/symbianos/implml/apputils_100048aa.crml', type='crml', index=0) |
|
367 INFO : cone |
|
368 """ |
|
369 (handle, filename) = tempfile.mkstemp() |
|
370 os.write(handle, log) |
|
371 os.close(handle) |
|
372 data = {'filename': filename, 'name': 'cone', 'version': '1.0'} |
|
373 ds = packager.datasources.ConEDataSource('/', data) |
|
374 components = ds.getComponents() |
|
375 assert len(components) == 1 |
|
376 print components[0].getTargetFiles() |
|
377 assert len(components[0].getTargetFiles()) == 3 |
|
378 |