Package ats3
[hide private]
[frames] | no frames]

Source Code for Package ats3

  1  # -*- encoding: latin-1 -*- 
  2   
  3  #============================================================================  
  4  #Name        : __init__.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  """ATS3 test drop generation.""" 
 23   
 24  #w0142 => * and ** were used 
 25  #R*    => will be fixed while refactoring 
 26  #F0401 => pylint didn't find "path" module 
 27  #C0302 => Too many lines 
 28   
 29   
 30  from optparse import OptionParser 
 31  from xml.etree import ElementTree as et 
 32  from xml.sax.saxutils import quoteattr 
 33  import ats3.testconfigurator as acp 
 34  import ats3.dropgenerator as adg 
 35  import logging 
 36  import os 
 37  import re 
 38  import zipfile 
 39   
 40  import ats3.parsers as parser 
 41  from path import path 
 42   
 43  _logger = logging.getLogger('ats3') 
 44   
45 -class Configuration(object):
46 """ 47 ATS3 drop generation configuration. 48 """ 49
50 - def __init__(self, opts, tsrc_paths):
51 """ 52 Initialize from optparse configuration options. 53 """ 54 self._opts = opts 55 CParser = parser.CppParser() 56 temp_dict = {} 57 mmp_parser = parser.MmpFileParser() 58 59 # Customize some attributes from how optparse leaves them. 60 self.build_drive = path(self._opts.build_drive) 61 self.file_store = path(self._opts.file_store) 62 self.flash_images = split_paths(self._opts.flash_images) 63 self.sis_files = split_paths(self._opts.sis_files) 64 self.config_file = self._opts.config 65 self.tsrc_paths_dict = {} 66 main_comps = [] 67 68 for tsrc in tsrc_paths: 69 temp_dict = CParser.get_cpp_output(path(tsrc), "d") 70 for t_key, t_value in temp_dict.items(): 71 self.tsrc_paths_dict[t_key] = t_value 72 73 #preparing a list of main components 74 for main_component in self.tsrc_paths_dict.keys(): 75 main_comps.append(main_component) 76 77 self.tsrc_paths = main_comps
78
79 - def __getattr__(self, attr):
80 return getattr(self._opts, attr)
81
82 - def __str__(self):
83 dump = "Configuration:\n" 84 seen = set() 85 for key, value in vars(self).items(): 86 if not key.startswith("_"): 87 dump += "\t%s = %s\n" % (key, value) 88 seen.add(key) 89 for key, value in vars(self._opts).items(): 90 if key not in seen: 91 dump += "\t%s = %s\n" % (key, value) 92 seen.add(key) 93 return dump
94 95
96 -class Ats3TestPlan(object):
97 """ 98 Tells ATS3 server what to test and how. 99 100 The ATS3 test plan from which the test.xml file can be written. The test 101 plan captures all the data related to a test run: flashing, installation 102 of data files and configuration files, test cases, and the notifications. 103 104 """ 105 106 EMAIL_SUBJECT = (u"ATS3 report for §RUN_NAME§ §RUN_START_DATE§ " 107 u"§RUN_START_TIME§") 108 REPORT_PATH = u"§RUN_NAME§" + os.sep + u"§RUN_START_DATE§_§RUN_START_TIME§" 109
110 - def __init__(self, config):
111 self.diamonds_build_url = config.diamonds_build_url 112 self.testrun_name = config.testrun_name 113 self.harness = config.harness 114 self.device_type = config.device_type 115 self.device_hwid = config.device_hwid 116 self.plan_name = config.plan_name 117 self.report_email = config.report_email 118 self.file_store = config.file_store 119 self.test_timeout = config.test_timeout 120 self.eunitexerunner_flags = config.eunitexerunner_flags 121 self.sets = [] 122 self.src_dst = [] 123 self.pmd_files = [] 124 self.trace_activation_files = [] 125 self.trace_enabled = self.to_bool(config.trace_enabled) 126 self.ctc_enabled = self.to_bool(config.ctc_enabled) 127 self.component_path = "" 128 self.custom_dir = None
129
130 - def to_bool(self, param):
131 param = str(param).lower() 132 if "true" == param or "t" == param or "1" == param: 133 return "True" 134 else: 135 return "False"
136
137 - def insert_set(self, data_files=None, config_files=None, 138 engine_ini_file=None, image_files=None, sis_files=None, 139 testmodule_files=None, test_timeout=None,eunitexerunner_flags=None , test_harness=None, 140 src_dst=None, pmd_files=None, trace_activation_files=None, custom_dir=None, component_path=None):
141 """ 142 Insert a test set into the test plan. 143 """ 144 145 if not custom_dir is None: 146 self.custom_dir = custom_dir 147 if data_files is None: 148 data_files = [] 149 if config_files is None: 150 config_files = [] 151 if image_files is None: 152 image_files = [] 153 if sis_files is None: 154 sis_files = [] 155 if testmodule_files is None: 156 testmodule_files = [] 157 if test_timeout is None: 158 test_timeout = [] 159 if eunitexerunner_flags is None: 160 eunitexeruner_flags = [] 161 if test_harness is None: 162 test_harness = self.harness 163 if src_dst is None: 164 src_dst = [] 165 if pmd_files is None: 166 pmd_files = [] 167 if trace_activation_files is None: 168 trace_activation_files = [] 169 if component_path is None: 170 component_path = self.component_path 171 172 setd = dict(name="set%d" % len(self.sets), 173 image_files=image_files, engine_ini_file=engine_ini_file, ctc_enabled=self.ctc_enabled, component_path=component_path) 174 175 setd = dict(setd, custom_dir=custom_dir) 176 if sis_files: 177 setd = dict(setd, sis_files=sis_files, test_timeout=test_timeout, eunitexerunner_flags=eunitexerunner_flags, test_harness=test_harness, ) 178 else: 179 setd = dict(setd, data_files=data_files, config_files=config_files, 180 testmodule_files=testmodule_files, test_timeout=test_timeout, eunitexerunner_flags=eunitexerunner_flags, test_harness=test_harness, 181 src_dst=src_dst) 182 if self.trace_enabled != "": 183 if self.trace_enabled.lower() == "true": 184 setd = dict(setd, pmd_files=pmd_files, 185 trace_path=self.file_store.joinpath(self.REPORT_PATH, "traces", setd["name"], "tracelog.blx"), 186 trace_activation_files=trace_activation_files) 187 else: 188 setd = dict(setd, pmd_files=[], 189 trace_path="",trace_activation_files=[]) 190 self.sets.append(setd)
191
192 - def set_plan_harness(self):
193 """setting up test harness for a plan""" 194 eunit = False 195 stif = False 196 stifunit = False 197 for setd in self.sets: 198 if setd["test_harness"] == "STIF": 199 stif = True 200 elif setd["test_harness"] == "EUNIT": 201 eunit = True 202 elif setd["test_harness"] == "STIFUNIT": 203 stifunit = True 204 205 if eunit and stif: 206 self.harness = "MULTI_HARNESS" 207 elif eunit: 208 self.harness = "EUNIT" 209 elif stif: 210 self.harness = "STIF" 211 elif stifunit: 212 self.harness = "STIFUNIT"
213 214 @property
215 - def post_actions(self):
216 """ATS3 post actions.""" 217 actions = [] 218 report_path = self.file_store.joinpath(self.REPORT_PATH) 219 email_action = ("SendEmailAction", 220 (("subject", self.EMAIL_SUBJECT), 221 ("type", "ATS3_REPORT"), 222 ("send-files", "true"), 223 ("to", self.report_email))) 224 ats3_report = ("FileStoreAction", 225 (("to-folder", report_path.joinpath("ATS3_REPORT")), 226 ("report-type", "ATS3_REPORT"), 227 ("date-format", "yyyyMMdd"), 228 ("time-format", "HHmmss"))) 229 stif_report = ("FileStoreAction", 230 (("to-folder", report_path.joinpath("STIF_REPORT")), 231 ("report-type", "STIF_COMPONENT_REPORT_ALL_CASES"), 232 ("run-log", "true"), 233 ("date-format", "yyyyMMdd"), 234 ("time-format", "HHmmss"))) 235 eunit_report = ("FileStoreAction", 236 (("to-folder", report_path.joinpath("EUNIT_REPORT")), 237 ("report-type", "EUNIT_COMPONENT_REPORT_ALL_CASES"), 238 ("run-log", "true"), 239 ("date-format", "yyyyMMdd"), 240 ("time-format", "HHmmss"))) 241 diamonds_action = ("DiamondsAction", ()) 242 if self.diamonds_build_url: 243 actions.append(diamonds_action) 244 if self.file_store: 245 actions.append(ats3_report) 246 if self.harness == "STIF": 247 actions.append(stif_report) 248 elif self.harness == "EUNIT": 249 actions.append(eunit_report) 250 if self.report_email: 251 actions.append(email_action) 252 return actions
253
254 - def __getitem__(self, key):
255 return self.__dict__[key]
256 257
258 -def create_drop(config):
259 """Create a test drop.""" 260 _logger.debug("initialize test plan") 261 262 test_plan = Ats3TestPlan(config) 263 parser = acp.Ats3ComponentParser(config) 264 265 for tsrc in config.tsrc_paths: 266 lst_check_harness = [] 267 _logger.info("inspecting tsrc path: %s" % tsrc) 268 #cehcking if there are components without harness 269 for sub_component in config.tsrc_paths_dict[tsrc]['content'].keys(): 270 _harness_ = config.tsrc_paths_dict[tsrc]['content'][sub_component]['harness'] 271 if _harness_ != "": 272 lst_check_harness.append(_harness_) 273 274 #if component has harness then insert to test set 275 if len(lst_check_harness) > 0: 276 parser.insert_test_set(test_plan, path(tsrc), config.tsrc_paths_dict) 277 278 test_plan.set_plan_harness() 279 280 generator = adg.Ats3TestDropGenerator() 281 _logger.info("generating drop file: %s" % config.drop_file) 282 generator.generate(test_plan, output_file=config.drop_file, config_file=config.config_file)
283
284 -def split_paths(arg, delim=","):
285 """ 286 Split the string by delim, removing extra whitespace. 287 """ 288 return [path(part.strip()) 289 for part in arg.split(delim) if part.strip()]
290 291 292
293 -def main():
294 """Main entry point.""" 295 cli = OptionParser(usage="%prog [options] TSRC1 [TSRC2 [TSRC3 ...]]") 296 cli.add_option("--build-drive", help="Build area root drive") 297 cli.add_option("--data-dir", help="Data directory name", action="append", 298 default=[]) 299 cli.add_option("--device-type", help="Device type (e.g. 'PRODUCT')", 300 default="unknown") 301 cli.add_option("--device-hwid", help="Device hwid", 302 default="") 303 cli.add_option("--trace-enabled", help="Tracing enabled", default="False") 304 cli.add_option("--ctc-enabled", help="CTC enabled", default="False") 305 cli.add_option("--diamonds-build-url", help="Diamonds build url") 306 cli.add_option("--drop-file", help="Name for the final drop zip file", 307 default="ATS3Drop.zip") 308 cli.add_option("--file-store", help="Destination path for reports.", 309 default="") 310 cli.add_option("--flash-images", help="Paths to the flash image files", 311 default="") 312 cli.add_option("--minimum-flash-images", help="Minimum amount of flash images", 313 default=2) 314 cli.add_option("--harness", help="Test harness (default: %default)", 315 default="") 316 cli.add_option("--report-email", help="Email notification receivers", 317 default="") 318 cli.add_option("--plan-name", help="Name of the test plan", 319 default="plan") 320 cli.add_option("--sis-files", help="Paths to the sis files", 321 default="") 322 cli.add_option("--target-platform", help="Target platform (default: %default)", 323 default="armv5 urel") 324 cli.add_option("--test-timeout", help="Test execution timeout value (default: %default)", 325 default="60") 326 cli.add_option("--eunitexerunner-flags", help="Eunitexerunner flags", 327 default="") 328 cli.add_option("--testrun-name", help="Name of the test run", 329 default="run") 330 cli.add_option("--config", help="Path to the config file", 331 default="") 332 cli.add_option("--verbose", help="Increase output verbosity", 333 action="store_true", default=False) 334 335 opts, tsrc_paths = cli.parse_args() 336 337 if not tsrc_paths: 338 cli.error("no tsrc directories given") 339 if not opts.flash_images: 340 cli.error("no flash image files given") 341 if not opts.build_drive: 342 cli.error("no build drive given") 343 if len(opts.flash_images.split(",")) < int(opts.minimum_flash_images): 344 cli.error("Not enough flash files: %i defined, %i needed" % (len(opts.flash_images.split(",")), int(opts.minimum_flash_images) )) 345 346 if opts.verbose: 347 _logger.setLevel(logging.DEBUG) 348 logging.basicConfig(level=logging.DEBUG) 349 350 config = Configuration(opts, tsrc_paths) 351 create_drop(config)
352 353 354 if __name__ == "__main__": 355 main() 356