|
1 # -*- encoding: latin-1 -*- |
|
2 |
|
3 #============================================================================ |
|
4 #Name : testconfigurator.py |
|
5 #Part of : Helium |
|
6 |
|
7 #Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
8 #All rights reserved. |
|
9 #This component and the accompanying materials are made available |
|
10 #under the terms of the License "Eclipse Public License v1.0" |
|
11 #which accompanies this distribution, and is available |
|
12 #at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
13 # |
|
14 #Initial Contributors: |
|
15 #Nokia Corporation - initial contribution. |
|
16 # |
|
17 #Contributors: |
|
18 # |
|
19 #Description: |
|
20 #=============================================================================== |
|
21 |
|
22 """Parse Symbian SW component for ATS3 testing related information""" |
|
23 |
|
24 # pylint: disable-msg=R0902,R0912,R0901,R0915,R0201 |
|
25 #R* remove during refactoring |
|
26 |
|
27 from path import path # pylint: disable-msg=F0401 |
|
28 import ats3.parsers as parser |
|
29 import logging |
|
30 import os |
|
31 import subprocess |
|
32 import fileutils |
|
33 |
|
34 _logger = logging.getLogger('ats') |
|
35 |
|
36 class Ats3ComponentParser(object): |
|
37 """ |
|
38 Parse Symbian SW component for ATS3 testing related information. |
|
39 |
|
40 Parses a component's source directories for testing related settings and |
|
41 files, and generates a TestPlan out of the findings. |
|
42 |
|
43 """ |
|
44 |
|
45 def __init__(self, config): |
|
46 |
|
47 self.target_platform = config.target_platform |
|
48 self.pkg_parser = parser.PkgFileParser(self.target_platform.replace(" ", "_")+".pkg", config.specific_pkg) |
|
49 |
|
50 self.bld_parser = parser.BldFileParser() |
|
51 self.mmp_parser = parser.MmpFileParser() |
|
52 |
|
53 self.data_dirs = config.data_dir |
|
54 self.flash_images = [path(p) for p in config.flash_images] |
|
55 self.tsrc_dir = None |
|
56 self.build_drive = config.build_drive |
|
57 self.target_platform = config.target_platform |
|
58 self.sis_files = config.sis_files |
|
59 self.cfg_harness = config.harness |
|
60 self.test_timeout = config.test_timeout |
|
61 self.trace_enabled = config.trace_enabled |
|
62 self.excludable_dlls = [] |
|
63 self.custom_dir = None |
|
64 |
|
65 def insert_testset_stif(self, src_dst, pkg_paths): |
|
66 """Inserts test set data to test plan for stif""" |
|
67 if not pkg_paths: |
|
68 try: |
|
69 |
|
70 tsrc_testdata_files = self.tsrc_data_files() |
|
71 for data_file in tsrc_testdata_files: |
|
72 if "\\mmc\\" in data_file.lower(): |
|
73 src_dst.append((data_file, path(r"e:\testing\data").joinpath(data_file.name), "data")) |
|
74 elif "\\c\\" in data_file.lower(): |
|
75 src_dst.append((data_file, path(r"c:\testing\data").joinpath(data_file.name), "data")) |
|
76 else: |
|
77 src_dst.append((data_file, path(r"c:\testing\data").joinpath(data_file.name), "data")) |
|
78 except OSError: |
|
79 _logger.warning("No testdata folder" ) |
|
80 tsrc_testdata_files = None |
|
81 |
|
82 else: |
|
83 try: |
|
84 src_dst = pkg_paths |
|
85 except OSError: |
|
86 _logger.warning("No pkg file found in the directory ( %s )" % self.tsrc_pkg_dir) |
|
87 src_dst = [] |
|
88 except IndexError: |
|
89 _logger.warning("No pkg file found in the directory ( %s )" % self.tsrc_pkg_dir) |
|
90 src_dst = [] |
|
91 |
|
92 return src_dst |
|
93 |
|
94 def insert_test_set(self, test_plan, tsrc_dir, _paths_dict_): |
|
95 """Parse tsrc directory, storing data into the test plan.""" |
|
96 self.tsrc_dir = path(tsrc_dir) # Store current test source dir. |
|
97 tsrc_testdata_files = [] |
|
98 tsrc_config_files = [] |
|
99 self.custom_dir = None |
|
100 engine_ini_file = None |
|
101 test_harness = self.cfg_harness |
|
102 src_dst = [] |
|
103 pmd_files = [] |
|
104 trace_activation_files = [] |
|
105 |
|
106 if not os.path.exists( self.tsrc_dir ): |
|
107 _logger.error("Missing test source directory: %s", self.tsrc_dir) |
|
108 else: |
|
109 self.custom_dir = self.tsrc_dir.joinpath("custom") |
|
110 _logger.debug("using customized testing from %s" % self.custom_dir) |
|
111 if os.path.exists(self.tsrc_bld_dir.joinpath("group","bld.inf")): |
|
112 mmp_files = self.bld_parser.get_test_mmp_files(self.tsrc_bld_dir.joinpath("group","bld.inf")) |
|
113 else: |
|
114 mmp_files = self.bld_parser.get_test_mmp_files(self.tsrc_bld_dir.joinpath("bld.inf")) |
|
115 |
|
116 test_harness = self.mmp_parser.get_harness(mmp_files) |
|
117 |
|
118 pkg_paths = self.pkg_parser.get_data_files(self.tsrc_pkg_files(_paths_dict_), self.build_drive) |
|
119 if self.trace_enabled == "True": |
|
120 try: |
|
121 pmd_files = self.tsrc_pmd_files() |
|
122 except OSError: |
|
123 _logger.warning("No pmd file in output-folder.") |
|
124 try: |
|
125 trace_activation_files = self.tsrc_trace_activation_files() |
|
126 except OSError: |
|
127 _logger.warning("No trace activation files in trace init folder") |
|
128 if trace_activation_files and not pmd_files: |
|
129 _logger.warning("Trace activation files available but NOT pmd file.") |
|
130 elif pmd_files and not trace_activation_files: |
|
131 _logger.warning("Pmd file available but NO trace activation files.") |
|
132 |
|
133 if test_harness == "STIF" or test_harness == "STIFUNIT" or test_harness == "GENERIC": |
|
134 src_dst = self.insert_testset_stif(src_dst, pkg_paths) |
|
135 |
|
136 elif test_harness == "EUNIT": |
|
137 try: |
|
138 src_dst = self.pkg_parser.get_data_files(self.tsrc_pkg_files(_paths_dict_), self.build_drive) |
|
139 |
|
140 except OSError: |
|
141 _logger.warning("No pkg file found in the directory ( %s )" % self.tsrc_pkg_dir) |
|
142 src_dst = [] |
|
143 except IndexError: |
|
144 _logger.warning("No pkg file found in the directory ( %s )" % self.tsrc_pkg_dir) |
|
145 src_dst = [] |
|
146 try: |
|
147 testmodule_files = self.tsrc_dll_files() |
|
148 |
|
149 for dll_file in testmodule_files: |
|
150 if not self.check_dll_duplication(dll_file.name, src_dst): |
|
151 _dll_type_ = self.mmp_parser.get_dll_type(self.tsrc_bld_dir) |
|
152 |
|
153 if dll_file.name in self.excludable_dlls: |
|
154 src_dst.append((dll_file, path(r"c:\sys\bin").joinpath(dll_file.name), "data:%s" % _dll_type_)) |
|
155 else: |
|
156 src_dst.append((dll_file, path(r"c:\sys\bin").joinpath(dll_file.name), "testmodule")) |
|
157 |
|
158 except OSError: |
|
159 _logger.warning("No dll files in dll folders" ) |
|
160 tsrc_testdata_files = None |
|
161 |
|
162 if test_plan['multiset_enabled'] == 'True': |
|
163 backup = [] |
|
164 temp_src_dst = {} |
|
165 for x_temp in src_dst: |
|
166 if len(x_temp) < 4: |
|
167 backup.append(x_temp) |
|
168 for x_temp in src_dst: |
|
169 if len(x_temp) > 3: |
|
170 if temp_src_dst.has_key(x_temp[3]): |
|
171 temp_src_dst[x_temp[3]].append(x_temp) |
|
172 else: |
|
173 temp_src_dst[x_temp[3]] = [x_temp] + backup |
|
174 |
|
175 for pkg in temp_src_dst.keys(): |
|
176 src_dst = temp_src_dst[pkg] |
|
177 |
|
178 if self.trace_enabled == "True": |
|
179 test_plan.insert_set(data_files=tsrc_testdata_files, |
|
180 config_files=tsrc_config_files, |
|
181 engine_ini_file=engine_ini_file, |
|
182 image_files=self.flash_images, |
|
183 sis_files=self.sis_files, |
|
184 #testmodule_files=self.tsrc_dll_files(), |
|
185 test_timeout=list(self.test_timeout), |
|
186 test_harness=test_harness, |
|
187 src_dst=src_dst, |
|
188 pmd_files=pmd_files, |
|
189 trace_activation_files=trace_activation_files, |
|
190 custom_dir=self.custom_dir, |
|
191 component_path=tsrc_dir) |
|
192 else: |
|
193 test_plan.insert_set(image_files=self.flash_images, |
|
194 sis_files=self.sis_files, |
|
195 test_timeout=list(self.test_timeout), |
|
196 test_harness=test_harness, |
|
197 src_dst=src_dst, |
|
198 custom_dir=self.custom_dir, |
|
199 component_path=tsrc_dir) |
|
200 else: |
|
201 if self.trace_enabled == "True": |
|
202 test_plan.insert_set(data_files=tsrc_testdata_files, |
|
203 config_files=tsrc_config_files, |
|
204 engine_ini_file=engine_ini_file, |
|
205 image_files=self.flash_images, |
|
206 sis_files=self.sis_files, |
|
207 #testmodule_files=self.tsrc_dll_files(), |
|
208 test_timeout=list(self.test_timeout), |
|
209 test_harness=test_harness, |
|
210 src_dst=src_dst, |
|
211 pmd_files=pmd_files, |
|
212 trace_activation_files=trace_activation_files, |
|
213 custom_dir=self.custom_dir, |
|
214 component_path=tsrc_dir) |
|
215 else: |
|
216 test_plan.insert_set(image_files=self.flash_images, |
|
217 sis_files=self.sis_files, |
|
218 test_timeout=list(self.test_timeout), |
|
219 test_harness=test_harness, |
|
220 src_dst=src_dst, |
|
221 custom_dir=self.custom_dir, |
|
222 component_path=tsrc_dir) |
|
223 |
|
224 def check_dll_duplication(self, _dll_file_, _src_dst_ ): |
|
225 """Checks if the dll is already in the dictionary, created by pkg file""" |
|
226 for item in _src_dst_: |
|
227 first = item[0] |
|
228 return _dll_file_.lower() in first.lower() |
|
229 |
|
230 @property |
|
231 def tsrc_bld_dir(self): |
|
232 """Component's build directory.""" |
|
233 return self.tsrc_dir |
|
234 |
|
235 @property |
|
236 def tsrc_conf_dir(self): |
|
237 """Component's configuration file directory.""" |
|
238 return self.tsrc_dir.joinpath("conf") |
|
239 |
|
240 @property |
|
241 def tsrc_custom_dir(self): |
|
242 """Component's test customization directory.""" |
|
243 return self.tsrc_dir.joinpath("custom") |
|
244 |
|
245 |
|
246 @property |
|
247 def tsrc_data_dirs(self): |
|
248 """Component's data directories.""" |
|
249 return [self.tsrc_dir.joinpath(d) for d in self.data_dirs] |
|
250 |
|
251 @property |
|
252 def tsrc_init_dir(self): |
|
253 """Component's initialization file directory.""" |
|
254 return self.tsrc_dir.joinpath("init") |
|
255 |
|
256 @property |
|
257 def tsrc_pkg_dir(self): |
|
258 """Component's .pkg -file directory""" |
|
259 return self.tsrc_dir |
|
260 |
|
261 @property |
|
262 def tsrc_trace_activation_dir(self): |
|
263 """Component's trace activation file directory""" |
|
264 return self.tsrc_dir.joinpath("trace_init") |
|
265 |
|
266 @property |
|
267 def tsrc_pmd_dir(self): |
|
268 """Component's pmd file directory""" |
|
269 pmd_dir = self.build_drive + os.sep |
|
270 return pmd_dir.joinpath("output", "pmd") |
|
271 |
|
272 def tsrc_pmd_files(self): |
|
273 """Component's trace pmd files from the {build_drive}\output directory""" |
|
274 return list(self.tsrc_pmd_dir.walkfiles("*.pmd")) |
|
275 |
|
276 def tsrc_trace_activation_files(self): |
|
277 """Component's trace activation files, from the rtace_init directory.""" |
|
278 return list(self.tsrc_trace_activation_dir.walkfiles("*.xml")) |
|
279 |
|
280 def tsrc_config_files(self): |
|
281 """Component's configuration files, from the conf directory.""" |
|
282 return list(self.tsrc_conf_dir.walkfiles("*.cfg")) |
|
283 |
|
284 def tsrc_ini_files(self): |
|
285 """Component's initialiation files, from the ini directory.""" |
|
286 return list(self.tsrc_init_dir.walkfiles("*.ini")) |
|
287 |
|
288 def tsrc_data_files(self): |
|
289 """Component's data files, from data directories.""" |
|
290 files = [] |
|
291 files2 = [] |
|
292 for data_dir in self.tsrc_data_dirs: |
|
293 if data_dir.exists(): |
|
294 files.extend(list(data_dir.walkfiles())) |
|
295 |
|
296 #Remove dist policy files |
|
297 for data_file in files: |
|
298 if data_file.name.lower() != "distribution.policy.s60": |
|
299 files2.append(data_file) |
|
300 return files2 |
|
301 |
|
302 def tsrc_dll_files(self): |
|
303 """Component's DLL files, reported by ABLD BUILD.""" |
|
304 |
|
305 dlls = [] |
|
306 orig_dir = os.getcwd() |
|
307 try: |
|
308 os.chdir(self.tsrc_bld_dir) |
|
309 #os.system("abld test build %s" % self.target_platform) |
|
310 |
|
311 if os.sep == '\\': |
|
312 raptor_cmd = fileutils.which("sbs.bat") |
|
313 else: |
|
314 raptor_cmd = fileutils.which("sbs") |
|
315 if raptor_cmd: |
|
316 process = subprocess.Popen("sbs --what -c %s.test" % self.target_platform.replace(' ', '_'), shell=True, stdout=subprocess.PIPE) |
|
317 else: |
|
318 os.system("bldmake bldfiles") |
|
319 process = subprocess.Popen("abld -w test build %s" % self.target_platform, shell=True, stdout=subprocess.PIPE) |
|
320 pipe = process.communicate()[0] |
|
321 |
|
322 for line in pipe.split('\n'): |
|
323 _logger.debug(line.strip()) |
|
324 target = path(line.strip()) |
|
325 if target.ext == ".dll": |
|
326 |
|
327 build_target = self.build_drive.joinpath(target).normpath() |
|
328 if not build_target.exists(): |
|
329 _logger.warning("not found: %s" % build_target) |
|
330 else: |
|
331 dlls.append(build_target) |
|
332 finally: |
|
333 os.chdir(orig_dir) |
|
334 return dlls |
|
335 |
|
336 def tsrc_pkg_files(self, _dict_): |
|
337 """Component's package files, from the group directory""" |
|
338 pkg_dirs = [] |
|
339 for sub_component in _dict_[self.tsrc_pkg_dir]['content'].keys(): |
|
340 pkg_dirs.append(sub_component) |
|
341 return pkg_dirs |