Package ats3 :: Module testconfigurator
[hide private]
[frames] | no frames]

Source Code for Module ats3.testconfigurator

  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   
 23  from path import path 
 24  import ats3.parsers as parser 
 25  import logging 
 26  import os 
 27  import re 
 28  import subprocess 
 29   
 30  _logger = logging.getLogger('ats3') 
 31   
32 -class Ats3ComponentParser(object):
33 """ 34 Parse Symbian SW component for ATS3 testing related information. 35 36 Parses a component's source directories for testing related settings and 37 files, and generates a TestPlan out of the findings. 38 39 """ 40
41 - def __init__(self, config):
42 43 self.target_platform = config.target_platform 44 self.pkg_parser = parser.PkgFileParser(self.target_platform.replace(" ", "_")+".pkg") 45 46 self.bld_parser = parser.BldFileParser() 47 self.mmp_parser = parser.MmpFileParser() 48 49 self.data_dirs = config.data_dir 50 self.flash_images = [path(p) for p in config.flash_images] 51 self.tsrc_dir = None 52 self.build_drive = config.build_drive 53 self.target_platform = config.target_platform 54 self.sis_files = config.sis_files 55 self.cfg_harness = config.harness 56 self.test_timeout = config.test_timeout 57 self.trace_enabled = config.trace_enabled 58 self.excludable_dlls = [] 59 self.custom_dir = None
60
61 - def insert_testset_stif(self, src_dst, pkg_paths):
62 """Inserts test set data to test plan for stif""" 63 if not pkg_paths: 64 try: 65 66 tsrc_testdata_files = self.tsrc_data_files() 67 for data_file in tsrc_testdata_files: 68 if "\\mmc\\" in data_file.lower(): 69 src_dst.append((data_file, path(r"e:\testing\data").joinpath(data_file.name), "data")) 70 elif "\\c\\" in data_file.lower(): 71 src_dst.append((data_file, path(r"c:\testing\data").joinpath(data_file.name), "data")) 72 else: 73 src_dst.append((data_file, path(r"c:\testing\data").joinpath(data_file.name), "data")) 74 except OSError: 75 _logger.warning("No testdata folder" ) 76 tsrc_testdata_files = None 77 78 else: 79 try: 80 src_dst = pkg_paths 81 except OSError: 82 _logger.warning("No pkg file in tsrc/group directory ( %s )" % self.tsrc_pkg_dir) 83 src_dst = [] 84 except IndexError: 85 _logger.warning("No pkg file in tsrc/group directory ( %s )" % self.tsrc_pkg_dir) 86 src_dst = [] 87 88 return src_dst
89
90 - def insert_test_set(self, test_plan, tsrc_dir, _paths_dict_):
91 """Parse tsrc directory, storing data into the test plan.""" 92 self.tsrc_dir = path(tsrc_dir) # Store current test source dir. 93 tsrc_testdata_files = [] 94 tsrc_config_files = [] 95 self.custom_dir = None 96 engine_ini_file = None 97 test_harness = self.cfg_harness 98 src_dst = [] 99 pmd_files = [] 100 trace_activation_files = [] 101 if not os.path.exists( self.tsrc_dir ): 102 _logger.error("Missing tsrc directory: %s", self.tsrc_dir) 103 else: 104 self.custom_dir = self.tsrc_dir.joinpath("custom") 105 _logger.debug("using customized testing from %s" % self.custom_dir) 106 if os.path.exists(self.tsrc_bld_dir.joinpath("group","bld.inf")): 107 mmp_files = self.bld_parser.get_test_mmp_files(self.tsrc_bld_dir.joinpath("group","bld.inf")) 108 else: 109 mmp_files = self.bld_parser.get_test_mmp_files(self.tsrc_bld_dir.joinpath("bld.inf")) 110 111 for mmp in mmp_files: 112 test_harness = self.mmp_parser.get_harness(mmp) 113 114 pkg_paths = self.pkg_parser.get_data_files(self.tsrc_pkg_files(_paths_dict_), self.build_drive) 115 if self.trace_enabled == "True": 116 try: 117 pmd_files = self.tsrc_pmd_files() 118 except OSError: 119 _logger.warning("No pmd file in output-folder.") 120 try: 121 trace_activation_files = self.tsrc_trace_activation_files() 122 except OSError: 123 _logger.warning("No trace activation files in trace init folder") 124 if trace_activation_files and not pmd_files: 125 _logger.warning("Trace activation files available but NOT pmd file.") 126 elif pmd_files and not trace_activation_files: 127 _logger.warning("Pmd file available but NO trace activation files.") 128 129 if test_harness == "STIF": 130 src_dst = self.insert_testset_stif(src_dst, pkg_paths) 131 132 if test_harness == "STIFUNIT": 133 src_dst = self.insert_testset_stif(src_dst, pkg_paths) 134 135 elif test_harness == "EUNIT": 136 try: 137 src_dst = self.pkg_parser.get_data_files(self.tsrc_pkg_files(_paths_dict_), self.build_drive) 138 139 except OSError: 140 _logger.warning("No pkg file in tsrc/group directory ( %s )" % self.tsrc_pkg_dir) 141 src_dst = [] 142 except IndexError: 143 _logger.warning("No pkg file in tsrc/group directory ( %s )" % self.tsrc_pkg_dir) 144 src_dst = [] 145 try: 146 testmodule_files = self.tsrc_dll_files() 147 148 for dll_file in testmodule_files: 149 if not self.check_dll_duplication(dll_file.name, src_dst): 150 _dll_type_ = self.mmp_parser.get_dll_type(self.tsrc_bld_dir) 151 152 if dll_file.name in self.excludable_dlls: 153 src_dst.append((dll_file, path(r"c:\sys\bin").joinpath(dll_file.name), "data:%s" % _dll_type_)) 154 else: 155 src_dst.append((dll_file, path(r"c:\sys\bin").joinpath(dll_file.name), "testmodule")) 156 157 except OSError: 158 _logger.warning("No dll files in dll folders" ) 159 tsrc_testdata_files = None 160 temp_list = [] 161 if self.trace_enabled == "True": 162 test_plan.insert_set(data_files=tsrc_testdata_files, 163 config_files=tsrc_config_files, 164 engine_ini_file=engine_ini_file, 165 image_files=self.flash_images, 166 sis_files=self.sis_files, 167 #testmodule_files=self.tsrc_dll_files(), 168 test_timeout=list(self.test_timeout), 169 test_harness=test_harness, 170 src_dst=src_dst, 171 pmd_files=pmd_files, 172 trace_activation_files=trace_activation_files, 173 custom_dir=self.custom_dir, 174 component_path=tsrc_dir) 175 else: 176 test_plan.insert_set(image_files=self.flash_images, 177 sis_files=self.sis_files, 178 test_timeout=list(self.test_timeout), 179 test_harness=test_harness, 180 src_dst=src_dst, 181 custom_dir=self.custom_dir, 182 component_path=tsrc_dir)
183
184 - def check_dll_duplication(self, _dll_file_, _src_dst_ ):
185 """Checks if the dll is already in the dictionary, created by pkg file""" 186 for item in _src_dst_: 187 first, second, _ = item 188 return _dll_file_.lower() in first.lower()
189 190 @property
191 - def tsrc_bld_dir(self):
192 """Component's build directory.""" 193 return self.tsrc_dir
194 195 @property
196 - def tsrc_conf_dir(self):
197 """Component's configuration file directory.""" 198 return self.tsrc_dir.joinpath("conf")
199 200 @property
201 - def tsrc_custom_dir(self):
202 """Component's test customization directory.""" 203 return self.tsrc_dir.joinpath("custom")
204 205 206 @property
207 - def tsrc_data_dirs(self):
208 """Component's data directories.""" 209 return [self.tsrc_dir.joinpath(d) for d in self.data_dirs]
210 211 @property
212 - def tsrc_init_dir(self):
213 """Component's initialization file directory.""" 214 return self.tsrc_dir.joinpath("init")
215 216 @property
217 - def tsrc_pkg_dir(self):
218 """Component's .pkg -file directory""" 219 return self.tsrc_dir
220 221 @property
223 """Component's trace activation file directory""" 224 return self.tsrc_dir.joinpath("trace_init")
225 226 @property
227 - def tsrc_pmd_dir(self):
228 """Component's pmd file directory""" 229 pmd_dir = self.build_drive + os.sep 230 return pmd_dir.joinpath("output", "pmd")
231
232 - def tsrc_pmd_files(self):
233 """Component's trace pmd files from the {build_drive}\output directory""" 234 return list(self.tsrc_pmd_dir.walkfiles("*.pmd"))
235
237 """Component's trace activation files, from the rtace_init directory.""" 238 return list(self.tsrc_trace_activation_dir.walkfiles("*.xml"))
239
240 - def tsrc_config_files(self):
241 """Component's configuration files, from the conf directory.""" 242 return list(self.tsrc_conf_dir.walkfiles("*.cfg"))
243
244 - def tsrc_ini_files(self):
245 """Component's initialiation files, from the ini directory.""" 246 return list(self.tsrc_init_dir.walkfiles("*.ini"))
247
248 - def tsrc_data_files(self):
249 """Component's data files, from data directories.""" 250 files = [] 251 files2 = [] 252 for data_dir in self.tsrc_data_dirs: 253 if data_dir.exists(): 254 files.extend(list(data_dir.walkfiles())) 255 256 #Remove dist policy files 257 for data_file in files: 258 if data_file.name.lower() != "distribution.policy.s60": 259 files2.append(data_file) 260 return files2
261
262 - def tsrc_dll_files(self):
263 """Component's DLL files, reported by ABLD BUILD.""" 264 265 dlls = [] 266 orig_dir = os.getcwd() 267 try: 268 os.chdir(self.tsrc_bld_dir) 269 os.system("bldmake bldfiles") 270 #os.system("abld test build %s" % self.target_platform) 271 process = subprocess.Popen("abld -w test build %s" % self.target_platform, shell=True, stdout=subprocess.PIPE) 272 pipe = process.communicate()[0] 273 for line in pipe.split('\n'): 274 _logger.debug(line.strip()) 275 target = path(line.strip()) 276 if target.ext == ".dll": 277 278 build_target = self.build_drive.joinpath(target).normpath() 279 if not build_target.exists(): 280 _logger.warning("not found: %s" % build_target) 281 else: 282 dlls.append(build_target) 283 finally: 284 os.chdir(orig_dir) 285 return dlls
286
287 - def tsrc_pkg_files(self, _dict_):
288 """Component's package files, from the group directory""" 289 pkg_dirs = [] 290 for sub_component in _dict_[self.tsrc_pkg_dir]['content'].keys(): 291 pkg_dirs.append(sub_component) 292 return pkg_dirs
293