587
|
1 |
# -*- encoding: latin-1 -*-
|
|
2 |
|
|
3 |
#============================================================================
|
|
4 |
#Name : dropgenerator.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 |
""" Generate test drop zip file for ATS3"""
|
|
23 |
|
|
24 |
|
|
25 |
#W0142 => * and ** were used
|
|
26 |
#C0302 => Too many lines
|
|
27 |
#R* removed when refactored
|
|
28 |
#W => use of global statement
|
|
29 |
|
|
30 |
import codecs
|
628
|
31 |
from xml.parsers.expat import ExpatError
|
587
|
32 |
|
|
33 |
from xml.etree import ElementTree as et
|
|
34 |
import pkg_resources
|
628
|
35 |
from path import path # pylint: disable=F0401
|
587
|
36 |
import logging
|
|
37 |
import os
|
|
38 |
import re
|
|
39 |
import zipfile
|
|
40 |
import amara
|
628
|
41 |
import ats3.atsconfigparser
|
587
|
42 |
|
|
43 |
from ntpath import sep as atssep
|
|
44 |
import ntpath as atspath
|
|
45 |
|
628
|
46 |
import jinja2 # pylint: disable=F0401
|
587
|
47 |
|
|
48 |
_logger = logging.getLogger('ats')
|
|
49 |
|
|
50 |
# Shortcuts
|
|
51 |
E = et.Element
|
|
52 |
SE = et.SubElement
|
|
53 |
|
|
54 |
CTC_PATHS_LIST = []
|
|
55 |
|
|
56 |
class Ats3TestDropGenerator(object):
|
|
57 |
"""
|
|
58 |
Generate test drop zip file for ATS3.
|
|
59 |
|
|
60 |
Generates drom zip files file from a TestPlan instance. The main
|
|
61 |
responsibility of this class is to serialize the plan into a valid XML
|
|
62 |
file and build a zip file for the drop.
|
|
63 |
|
|
64 |
Creates one <set> for each component's tests.
|
|
65 |
|
|
66 |
Stif harness, normal operation
|
|
67 |
------------------------------
|
|
68 |
|
|
69 |
- create logging dir for stif makedir (to C:\logs\TestFramework)
|
|
70 |
- install data files install (to E:\testing\data)
|
|
71 |
- install configuration (.cfg) files " (to E:\testing\conf)
|
|
72 |
- install testmodule (.dll) files " (to C:\sys\bin)
|
|
73 |
- install engine ini (testframework.ini) " (to C:\testframework)
|
|
74 |
- execute cases from the engine ini run-cases
|
|
75 |
- fetch logs fetch-log
|
|
76 |
|
|
77 |
Stif harness, SIS package installation
|
|
78 |
--------------------------------------
|
|
79 |
|
|
80 |
- like above but with data and config files replaced by sis files
|
|
81 |
- install sis to the device install-software
|
|
82 |
|
|
83 |
"""
|
|
84 |
|
|
85 |
STIF_LOG_DIR = r"c:" + os.sep + "logs" + os.sep + "testframework"
|
|
86 |
TEF_LOG_DIR = r"c:" + os.sep + "logs" + os.sep + "testexecute"
|
|
87 |
MTF_LOG_DIR = r"c:" + os.sep + "logs" + os.sep + "testresults"
|
|
88 |
STIFUNIT_LOG_DIR = r"c:" + os.sep + "logs" + os.sep + "testframework"
|
|
89 |
EUNIT_LOG_DIR = r"c:" + os.sep + "Shared" + os.sep + "EUnit" + os.sep + "logs"
|
|
90 |
#QT_LOG_DIR = r"c:" + os.sep + "private" + os.sep + "Qt" + os.sep + "logs"
|
|
91 |
QT_LOG_DIR = r"c:" + os.sep + "shared" + os.sep + "EUnit" + os.sep + "logs"
|
|
92 |
CTC_LOG_DIR = r"c:" + os.sep + "data" + os.sep + "ctc"
|
|
93 |
|
|
94 |
def __init__(self):
|
|
95 |
self.drop_path_root = path("ATS3Drop")
|
|
96 |
self.drop_path = None
|
|
97 |
self.defaults = {}
|
|
98 |
|
|
99 |
def generate(self, test_plan, output_file, config_file=None):
|
|
100 |
"""Generate a test drop file."""
|
|
101 |
xml = self.generate_xml(test_plan)
|
|
102 |
|
|
103 |
if config_file:
|
|
104 |
xmltext = et.tostring(xml.getroot(), "ISO-8859-1")
|
628
|
105 |
xmltext = ats3.atsconfigparser.converttestxml(config_file, xmltext)
|
587
|
106 |
xml = et.ElementTree(et.XML(xmltext))
|
|
107 |
|
|
108 |
return self.generate_drop(test_plan, xml, output_file)
|
|
109 |
|
|
110 |
def generate_drop(self, test_plan, xml, output_file):
|
|
111 |
"""Generate test drop zip file."""
|
|
112 |
zfile = zipfile.ZipFile(output_file, "w", zipfile.ZIP_DEFLATED)
|
|
113 |
try:
|
|
114 |
for drop_file, src_file in self.drop_files(test_plan):
|
|
115 |
if not src_file.startswith('\\\\'):
|
|
116 |
_logger.info(" + Adding: %s" % src_file.strip())
|
|
117 |
try:
|
|
118 |
zfile.write(src_file.strip(), drop_file.encode('utf-8'))
|
|
119 |
except OSError, expr:
|
|
120 |
_logger.error(expr)
|
|
121 |
doc = amara.parse(et.tostring(xml.getroot(), "ISO-8859-1"))
|
|
122 |
_logger.debug("XML output: %s\n" % doc.xml(indent=u"yes", encoding="ISO-8859-1"))
|
|
123 |
zfile.writestr("test.xml", doc.xml(indent="yes", encoding="ISO-8859-1"))
|
|
124 |
finally:
|
|
125 |
zfile.close()
|
|
126 |
|
|
127 |
return zfile
|
|
128 |
|
|
129 |
def generate_xml(self, test_plan):
|
|
130 |
"""Generate test drop XML."""
|
|
131 |
self.defaults = {"enabled": "true",
|
|
132 |
"passrate": "100",
|
|
133 |
"significant": "false"}
|
|
134 |
root = E("test")
|
|
135 |
root.append(et.XML("<name>%(testrun_name)s</name>" % test_plan))
|
|
136 |
if test_plan["diamonds_build_url"]:
|
|
137 |
root.append(
|
|
138 |
et.XML("<buildid>%(diamonds_build_url)s</buildid>" % test_plan))
|
|
139 |
generate_target(test_plan, root)
|
|
140 |
root.append(self.generate_plan(test_plan))
|
|
141 |
for post_action in generate_post_actions(test_plan):
|
|
142 |
root.append(post_action)
|
|
143 |
root.append(self.generate_files(test_plan))
|
|
144 |
etree = et.ElementTree(root)
|
|
145 |
return etree
|
|
146 |
|
|
147 |
def generate_plan(self, test_plan):
|
|
148 |
"""Generate the test <plan> with multiple <set>s."""
|
|
149 |
plan = E("plan", name="%s Plan" % test_plan["testrun_name"],
|
|
150 |
harness=test_plan["harness"], **self.defaults)
|
|
151 |
session = SE(plan, "session", name="session", harness=test_plan["harness"], **self.defaults)
|
|
152 |
|
|
153 |
if not test_plan.custom_dir is None:
|
|
154 |
insert_custom_file(session, test_plan.custom_dir.joinpath("preset_custom.xml"))
|
|
155 |
|
|
156 |
# One set for each component.
|
|
157 |
for setd in test_plan.sets:
|
|
158 |
self.drop_path = self.drop_path_root.joinpath(setd["name"])
|
|
159 |
elem = SE(session, "set", name=setd["name"]+"-"+setd["component_path"], harness=setd["test_harness"], **self.defaults)
|
|
160 |
SE(SE(elem, "target"), "device", rank="master", alias="DEFAULT_%s" % setd["test_harness"])
|
|
161 |
|
|
162 |
if not test_plan.custom_dir is None:
|
|
163 |
insert_custom_file(elem, test_plan.custom_dir.joinpath("precase_custom.xml"))
|
|
164 |
|
|
165 |
case = SE(elem, "case", name="%s case" % setd["name"],
|
|
166 |
harness=setd["test_harness"], **self.defaults)
|
|
167 |
self.generate_steps(setd, case, test_plan)
|
|
168 |
if not test_plan.custom_dir is None:
|
|
169 |
insert_custom_file(elem, test_plan.custom_dir.joinpath("postcase_custom.xml"))
|
|
170 |
|
|
171 |
if not test_plan.custom_dir is None:
|
|
172 |
insert_custom_file(session, test_plan.custom_dir.joinpath("postset_custom.xml"))
|
|
173 |
|
|
174 |
return plan
|
|
175 |
|
|
176 |
def generate_steps_logdir(self, setd, case):
|
|
177 |
"""generates STIF log dir."""
|
|
178 |
|
|
179 |
_qt_test_ = self.check_qt_harness(setd)
|
|
180 |
if _qt_test_:
|
|
181 |
step = SE(case, "step", name="Create QT log dir", harness=setd["test_harness"], **self.defaults)
|
|
182 |
else:
|
|
183 |
step = SE(case, "step", name="Create %s log dir" % setd["test_harness"], harness=setd["test_harness"], **self.defaults)
|
|
184 |
SE(step, "command").text = "makedir"
|
|
185 |
if setd["test_harness"] == "STIF":
|
|
186 |
SE(SE(step, "params"), "param", dir=self.STIF_LOG_DIR)
|
|
187 |
if setd["test_harness"] == "GENERIC":
|
|
188 |
if self.check_mtf_harness(setd):
|
|
189 |
SE(SE(step, "params"), "param", dir=self.MTF_LOG_DIR)
|
|
190 |
else:
|
|
191 |
SE(SE(step, "params"), "param", dir=self.TEF_LOG_DIR)
|
|
192 |
elif setd["test_harness"] == "EUNIT":
|
|
193 |
if _qt_test_:
|
|
194 |
SE(SE(step, "params"), "param", dir=self.QT_LOG_DIR)
|
|
195 |
else:
|
|
196 |
SE(SE(step, "params"), "param", dir=self.EUNIT_LOG_DIR)
|
|
197 |
|
|
198 |
elif setd["test_harness"] == "STIFUNIT":
|
|
199 |
SE(SE(step, "params"), "param", dir=self.STIFUNIT_LOG_DIR)
|
|
200 |
|
|
201 |
if setd.has_key("sis_files") and setd["sis_files"]:
|
|
202 |
setd = dict(setd, src_dst=[]) # Added to pass the Sis tests, if removed - gives KeyError
|
|
203 |
for sis_file in setd["sis_files"]:
|
|
204 |
self.generate_install_step(case, "sis", sis_file.name, "sis",
|
|
205 |
r"c:" + os.sep + "testframework", setd["test_harness"])
|
|
206 |
else:
|
|
207 |
if setd["src_dst"] != []:
|
|
208 |
self.generate_install_step(case, "", "",
|
|
209 |
"", r"", setd["test_harness"], setd["src_dst"])
|
|
210 |
else:
|
|
211 |
# Data file install.
|
|
212 |
for data_file in setd["data_files"]:
|
|
213 |
self.generate_install_step(case, "data", data_file.name, "data",
|
|
214 |
r"e:\testing\data", setd["test_harness"])
|
|
215 |
|
|
216 |
# Configuration file install.
|
|
217 |
for conf_file in setd["config_files"]:
|
|
218 |
self.generate_install_step(case, "conf", conf_file.name, "conf",
|
|
219 |
r"e:\testing\conf", setd["test_harness"])
|
|
220 |
|
|
221 |
# Test module install.
|
|
222 |
for test_file in setd["testmodule_files"]:
|
|
223 |
self.generate_install_step(case, "testmodule", test_file.name,
|
|
224 |
"testmodules", r"c:\sys\bin", setd["test_harness"])
|
|
225 |
return setd
|
|
226 |
|
|
227 |
def generate_steps_engineini(self, setd, case):
|
|
228 |
"""Engine ini install ( if one exists )"""
|
|
229 |
if setd.has_key("sis_files") and setd["sis_files"]:
|
|
230 |
self.generate_install_step(case, "engine_ini",
|
|
231 |
setd["engine_ini_file"].name,
|
|
232 |
"init",
|
|
233 |
r"c:" + os.sep + "testframework", setd["test_harness"])
|
|
234 |
else:
|
|
235 |
if setd["src_dst"] == []:
|
|
236 |
self.generate_install_step(case, "engine_ini",
|
|
237 |
setd["engine_ini_file"].name,
|
|
238 |
"init",
|
|
239 |
r"c:" + os.sep + "testframework", setd["test_harness"])
|
|
240 |
|
|
241 |
def generate_steps_sisfiles(self, setd, case, test_plan):
|
|
242 |
"""generating steps for sis files"""
|
|
243 |
for sis_file in setd["sis_files"]:
|
|
244 |
step = SE(case, "step", name="Install SIS to the device: %s" % \
|
|
245 |
sis_file.name, harness=setd["test_harness"], **self.defaults)
|
|
246 |
SE(step, "command").text = "install-software"
|
|
247 |
params = SE(step, "params")
|
|
248 |
sis_name = path(r"c:" + os.sep + "testframework").joinpath(sis_file.name)
|
|
249 |
for key, value in (("timeout", test_plan["test_timeout"]),
|
|
250 |
("overWriteAllowed", "true"),
|
|
251 |
("upgradeData", "true"),
|
|
252 |
("downloadAllowed", "false"),
|
|
253 |
("packageInfoAllowed", "true"),
|
|
254 |
("untrustedAllowed", "true"),
|
|
255 |
("ignoreOCSPWarnings", "true"),
|
|
256 |
("userCapGranted", "true"),
|
|
257 |
("optionalItemsAllowed", "true"),
|
|
258 |
("killApp", "true"),
|
|
259 |
("installDrive", "C"),
|
|
260 |
("upgradeAllowed", "true"),
|
|
261 |
("OCSP_Done", "true"),
|
|
262 |
("sisPackageName", sis_name.normpath())):
|
|
263 |
SE(params, "param").set(key, value)
|
|
264 |
|
|
265 |
def generate_steps_tracestart(self, setd, case, pmds):
|
|
266 |
"""Tracing steps are added (Trace Start)"""
|
|
267 |
step = SE(case, "step",
|
|
268 |
name="Start tracing", harness=setd["test_harness"],
|
|
269 |
**self.defaults)
|
|
270 |
SE(step, "command").text = "trace-start"
|
|
271 |
params = SE(step, "params")
|
|
272 |
if setd.has_key("trace_activation_files") and setd["trace_activation_files"]:
|
|
273 |
#find out the group to activate
|
|
274 |
trace_group = et.parse(setd["trace_activation_files"][0]).getroot().find("Configurations").find("TraceActivation").find("Configuration").get("Name")
|
|
275 |
SE(params, "param", ta=self.drop_path.joinpath(r"trace_activation", setd["trace_activation_files"][0].name))
|
|
276 |
SE(params, "param", tgrp=trace_group )
|
|
277 |
if setd.has_key("pmd_files") and setd["pmd_files"]:
|
|
278 |
SE(params, "param", pmd=pmds.joinpath(setd["pmd_files"][0].name))
|
|
279 |
SE(params, "param", log=setd["trace_path"])
|
|
280 |
SE(params, "param", timeout="60")
|
|
281 |
elem = SE(params, "param")
|
|
282 |
elem.set('date-format', "yyyyMMdd")
|
|
283 |
elem = SE(params, "param")
|
|
284 |
elem.set('time-format', "HHmmss")
|
|
285 |
|
|
286 |
def generate_steps_createstep(self, setd, case, test_plan):
|
|
287 |
"""generates core steps for a single set"""
|
|
288 |
if setd["test_harness"] == "STIF" or setd["test_harness"] == "STIFUNIT" or setd["test_harness"] == "GENERIC":
|
|
289 |
if setd["src_dst"] == []:
|
|
290 |
# Test case execution. If ini file exists, use that
|
|
291 |
if setd["engine_ini_file"] != None:
|
|
292 |
step = SE(case, "step",
|
|
293 |
name="Execute test: %s" % setd["engine_ini_file"].name,
|
|
294 |
harness=setd["test_harness"], **self.defaults)
|
|
295 |
SE(step, "command").text = "run-cases"
|
|
296 |
params = SE(step, "params")
|
|
297 |
SE(params, "param", filter="*")
|
|
298 |
SE(params, "param", timeout=test_plan["test_timeout"])
|
|
299 |
ini_name = setd["engine_ini_file"].name
|
|
300 |
SE(params, "param", engineini=path(r"c:" + os.sep + "testframework") / ini_name)
|
|
301 |
|
|
302 |
# if no inifile, but cfg files defined, use those
|
628
|
303 |
elif setd["config_files"] != []:
|
587
|
304 |
for config_file in setd["config_files"]:
|
|
305 |
step = SE(case, "step",
|
|
306 |
name="Execute test: %s" % config_file.name,
|
|
307 |
harness=setd["test_harness"], **self.defaults)
|
|
308 |
SE(step, "command").text = "run-cases"
|
|
309 |
params = SE(step, "params")
|
|
310 |
SE(params, "param", module="TESTSCRIPTER")
|
|
311 |
elem = SE(params, "param" )
|
|
312 |
elem.set('testcase-file', path(r"e:\testing\conf") / config_file.name )
|
|
313 |
SE(params, "param", filter="*")
|
|
314 |
SE(params, "param", timeout=test_plan["test_timeout"])
|
|
315 |
|
|
316 |
# if no ini or cfg files, use dll directly
|
|
317 |
else:
|
|
318 |
for testmodule_file in setd["testmodule_files"]:
|
|
319 |
step = SE(case, "step",
|
|
320 |
name="Execute test: %s" % testmodule_file.name, harness=setd["test_harness"],
|
|
321 |
**self.defaults)
|
|
322 |
SE(step, "command").text = "run-cases"
|
|
323 |
params = SE(step, "params")
|
|
324 |
SE(params, "param", module=testmodule_file.name)
|
|
325 |
SE(params, "param", filter="*")
|
|
326 |
SE(params, "param", timeout=test_plan["test_timeout"])
|
|
327 |
elif setd["src_dst"] != []:
|
|
328 |
self.generate_run_steps(case, setd, test_plan["test_timeout"], test_plan["eunitexerunner_flags"])
|
|
329 |
elif setd["test_harness"] == "EUNIT":
|
|
330 |
self.generate_run_steps(case, setd, test_plan["test_timeout"], test_plan["eunitexerunner_flags"])
|
|
331 |
|
|
332 |
def generate_steps_tracestop(self, setd, case, pmds):
|
|
333 |
"""Tracing steps are added (Trace Stop)"""
|
|
334 |
step = SE(case, "step", name="Stop tracing",
|
|
335 |
harness=setd["test_harness"], **self.defaults)
|
|
336 |
SE(step, "command").text = "trace-stop"
|
|
337 |
params = SE(step, "params")
|
|
338 |
SE(params, "param", timeout="60")
|
|
339 |
|
|
340 |
step = SE(case, "step", name="Convert tracing",
|
|
341 |
harness=setd["test_harness"], **self.defaults)
|
|
342 |
SE(step, "command").text = "trace-convert"
|
|
343 |
params = SE(step, "params")
|
|
344 |
if setd.has_key("pmd_files") and setd["pmd_files"]:
|
|
345 |
SE(params, "param", pmd=pmds.joinpath(setd["pmd_files"][0].name))
|
|
346 |
SE(params, "param", log=setd["trace_path"])
|
|
347 |
SE(params, "param", timeout="60")
|
|
348 |
elem = SE(params, "param")
|
|
349 |
elem.set('date-format', "yyyyMMdd")
|
|
350 |
elem = SE(params, "param")
|
|
351 |
elem.set('time-format', "HHmmss")
|
|
352 |
|
|
353 |
def generate_steps_ctcdata(self, setd, case, test_plan):
|
|
354 |
"""generates steps for installing CTC data"""
|
|
355 |
global CTC_PATHS_LIST
|
|
356 |
ctc_helium_path_list = []
|
|
357 |
|
|
358 |
step = SE(case, "step", name="Save CTC data", harness=setd["test_harness"], **self.defaults)
|
|
359 |
SE(step, "command").text = "execute"
|
|
360 |
params = SE(step, "params")
|
|
361 |
SE(params, "param", parameters="writelocal")
|
|
362 |
SE(params, "param", file=path(r"z:\sys\bin\ctcman.exe"))
|
|
363 |
step = SE(case, "step", name="Save CTC data", harness=setd["test_harness"], **self.defaults)
|
|
364 |
SE(step, "command").text = "execute"
|
|
365 |
params = SE(step, "params")
|
|
366 |
SE(params, "param", parameters="writefile")
|
|
367 |
SE(params, "param", file=path(r"z:\sys\bin\ctcman.exe"))
|
|
368 |
|
|
369 |
if test_plan["ctc_run_process_params"].strip() != "":
|
|
370 |
#preparing local-path for CTC step
|
|
371 |
#getting '39865' as diamonds ID out of 'http://diamonds.server.domain.invalid/diamonds/builds/39865/'
|
|
372 |
if not test_plan["diamonds_build_url"]:
|
|
373 |
raise Exception('Diamonds needed for CTC')
|
|
374 |
if test_plan["diamonds_build_url"].rfind("/", 0):
|
|
375 |
diamonds_id = test_plan["diamonds_build_url"].rsplit(r"/", 2)[1]
|
|
376 |
else:
|
|
377 |
diamonds_id = test_plan["diamonds_build_url"].rsplit(r"/", 1)[1]
|
|
378 |
|
|
379 |
#separating network id and drop number from 10.11.3.2\share#ats\drop2.zip#3
|
|
380 |
#'drop2' from the other part of the string conjuncted with a # sign
|
|
381 |
ats_network = r"\\" + test_plan["ctc_run_process_params"].rsplit("#", 2)[0] #network host
|
|
382 |
temp_drop_id = path(test_plan["ctc_run_process_params"].rsplit("#", 2)[1].rsplit(".", 1)[0]).normpath() #drop ID
|
|
383 |
if atssep in temp_drop_id:
|
|
384 |
drop_id = temp_drop_id.rsplit(atssep, 1)[1]
|
|
385 |
else:
|
|
386 |
drop_id = temp_drop_id
|
|
387 |
|
|
388 |
ats_network_path = atspath.join(ats_network, "ctc_helium" , diamonds_id, drop_id, setd["name"], "ctcdata")
|
|
389 |
ctc_helium_path_list.append(ats_network_path)
|
|
390 |
|
|
391 |
step = SE(case, "step", name="Fetch CTC data for post commands execution", harness=setd["test_harness"], **self.defaults)
|
|
392 |
SE(step, "command").text = "fetch-log"
|
|
393 |
params = SE(step, "params")
|
|
394 |
SE(params, "param", delete="false")
|
|
395 |
elem = SE(params, "param")
|
|
396 |
elem.set('local-path', ats_network_path)
|
|
397 |
SE(params, "param", path=path(self.CTC_LOG_DIR).joinpath(r"ctcdata.txt"))
|
|
398 |
|
|
399 |
CTC_PATHS_LIST += ctc_helium_path_list #creating list of ctcdata.txt files for runProcess postaction
|
|
400 |
|
|
401 |
step = SE(case, "step", name="Fetch and clean CTC data", harness=setd["test_harness"], **self.defaults)
|
|
402 |
SE(step, "command").text = "fetch-log"
|
|
403 |
params = SE(step, "params")
|
|
404 |
SE(params, "param", delete="true")
|
|
405 |
SE(params, "param", path=path(self.CTC_LOG_DIR).joinpath(r"ctcdata.txt"))
|
|
406 |
|
|
407 |
def generate_steps_logfetching(self, setd, case):
|
|
408 |
"""generates steps for fetching log file"""
|
|
409 |
step = SE(case, "step", name="Fetch test module logs", harness=setd["test_harness"], **self.defaults)
|
|
410 |
SE(step, "command").text = "fetch-log"
|
|
411 |
params = SE(step, "params")
|
|
412 |
SE(params, "param", type="text")
|
|
413 |
SE(params, "param", delete="true")
|
|
414 |
if setd["test_harness"] == "STIF":
|
|
415 |
SE(params, "param", path=path(self.STIF_LOG_DIR).joinpath(r"*"))
|
|
416 |
if setd["test_harness"] == "GENERIC":
|
|
417 |
if self.check_mtf_harness(setd):
|
|
418 |
SE(params, "param", path=path(self.MTF_LOG_DIR).joinpath(r"*"))
|
|
419 |
else:
|
|
420 |
SE(params, "param", path=path(self.TEF_LOG_DIR).joinpath(r"*"))
|
|
421 |
elif setd["test_harness"] == "STIFUNIT":
|
|
422 |
SE(params, "param", path=path(self.STIFUNIT_LOG_DIR).joinpath(r"*"))
|
|
423 |
elif setd["test_harness"] == "EUNIT":
|
|
424 |
if self.check_qt_harness(setd):
|
|
425 |
SE(params, "param", path=path(self.QT_LOG_DIR).joinpath(r"*"))
|
|
426 |
else:
|
|
427 |
SE(params, "param", path=path(self.EUNIT_LOG_DIR).joinpath(r"*"))
|
|
428 |
|
|
429 |
|
|
430 |
def get_sorted_images(self, setd):
|
|
431 |
"""sort the images """
|
|
432 |
sorted_images = []
|
|
433 |
for image_file in setd["image_files"]:
|
|
434 |
if 'core' in image_file.name:
|
|
435 |
sorted_images.append(image_file)
|
|
436 |
for image_file in setd["image_files"]:
|
|
437 |
if 'rofs2' in image_file.name:
|
|
438 |
sorted_images.append(image_file)
|
|
439 |
for image_file in setd["image_files"]:
|
|
440 |
if 'rofs3' in image_file.name:
|
|
441 |
sorted_images.append(image_file)
|
|
442 |
for image_file in setd["image_files"]:
|
628
|
443 |
if 'core' not in image_file.name and 'rofs2' not in image_file.name and 'rofs3' not in image_file.name and 'udaerase' not in image_file.name.lower():
|
587
|
444 |
sorted_images.append(image_file)
|
|
445 |
if len(sorted_images) > 0 and "rofs" in sorted_images[0]:
|
|
446 |
return setd["image_files"]
|
|
447 |
return sorted_images
|
628
|
448 |
|
|
449 |
def get_udaerase_image(self, setd):
|
|
450 |
for image_file in setd["image_files"]:
|
|
451 |
if 'udaerase' in image_file.name.lower():
|
|
452 |
return image_file
|
|
453 |
return None
|
587
|
454 |
|
|
455 |
def generate_steps(self, setd, case, test_plan):
|
|
456 |
"""Generate the test plan <step>s."""
|
|
457 |
# Flash images.
|
|
458 |
images = self.drop_path_root.joinpath("images")
|
|
459 |
pmds = self.drop_path_root.joinpath("pmds")
|
|
460 |
|
|
461 |
sorted_images = self.get_sorted_images(setd)
|
|
462 |
for image_file in sorted_images:
|
|
463 |
flash = SE(case, "flash", images=images.joinpath(os.path.basename(image_file)))
|
|
464 |
flash.set("target-alias", "DEFAULT_%s" % setd["test_harness"])
|
|
465 |
|
|
466 |
if setd['custom_dir']:
|
|
467 |
insert_custom_file(case, os.path.join(setd['custom_dir'], "prestep_custom.xml"))
|
|
468 |
|
|
469 |
if setd["ctc_enabled"] == "True":
|
|
470 |
step = SE(case, "step", name="Create CTC log dir", harness=setd["test_harness"], **self.defaults)
|
|
471 |
SE(step, "command").text = "makedir"
|
|
472 |
params = SE(step, "params")
|
|
473 |
SE(params, "param", dir=self.CTC_LOG_DIR)
|
|
474 |
step = SE(case, "step", name="CTC start", harness=setd["test_harness"], **self.defaults)
|
|
475 |
SE(step, "command").text = "execute"
|
|
476 |
params = SE(step, "params")
|
|
477 |
SE(params, "param", file=path(r"z:\sys\bin\ctcman.exe"))
|
|
478 |
|
|
479 |
# STIF log dir.
|
|
480 |
setd = self.generate_steps_logdir(setd, case)
|
|
481 |
|
|
482 |
# Engine ini install ( if one exists )
|
|
483 |
if setd["engine_ini_file"] != None:
|
|
484 |
self.generate_steps_engineini(setd, case)
|
|
485 |
|
|
486 |
#If sis files
|
|
487 |
if setd.has_key("sis_files") and setd["sis_files"]:
|
|
488 |
self.generate_steps_sisfiles(setd, case, test_plan)
|
|
489 |
|
|
490 |
# If tracing enabled, Start Tracing:
|
|
491 |
if setd.has_key("trace_path") and setd["trace_path"] != "":
|
|
492 |
self.generate_steps_tracestart(setd, case, pmds)
|
|
493 |
|
|
494 |
#core steps of a step
|
|
495 |
|
|
496 |
if setd['custom_dir']:
|
|
497 |
insert_custom_file(case, os.path.join(setd['custom_dir'], "prerun_custom.xml"))
|
|
498 |
self.generate_steps_createstep(setd, case, test_plan)
|
|
499 |
|
|
500 |
if setd['custom_dir']:
|
|
501 |
insert_custom_file(case, os.path.join(setd['custom_dir'], "postrun_custom.xml"))
|
|
502 |
|
|
503 |
# If tracing enabled, Stop Tracing
|
|
504 |
if setd.has_key("trace_path") and setd["trace_path"] != "":
|
|
505 |
self.generate_steps_tracestop(setd, case, pmds)
|
|
506 |
|
|
507 |
#install CTC data
|
|
508 |
if setd["ctc_enabled"] == "True":
|
|
509 |
self.generate_steps_ctcdata(setd, case, test_plan)
|
|
510 |
|
|
511 |
# Log file fetching.
|
|
512 |
self.generate_steps_logfetching(setd, case)
|
|
513 |
|
|
514 |
if setd['custom_dir']:
|
|
515 |
insert_custom_file(case, os.path.join(setd['custom_dir'], "poststep_custom.xml"))
|
|
516 |
|
|
517 |
|
|
518 |
def generate_runsteps_tef(self, setd, case, src_dst, time_out):
|
|
519 |
"""generates runsteps for tef"""
|
|
520 |
for file1 in src_dst:
|
|
521 |
if 'testscript' in file1[2]:
|
|
522 |
filename = file1[1]
|
|
523 |
filename = filename[file1[1].rfind(os.sep)+1:]
|
|
524 |
harness = "testexecute.exe"
|
628
|
525 |
if "testscript:mtf" in file1[2]:
|
587
|
526 |
harness = "testframework.exe"
|
|
527 |
step = SE(case, "step",
|
|
528 |
name="Execute test: %s" % filename, harness=setd["test_harness"],
|
|
529 |
**self.defaults)
|
|
530 |
SE(step, "command").text = "execute"
|
|
531 |
params = SE(step, "params")
|
|
532 |
SE(params, "param", file=harness)
|
|
533 |
SE(params, "param", parameters=file1[1])
|
|
534 |
|
628
|
535 |
if "testscript:mtf" in file1[2]:
|
587
|
536 |
SE(params, "param", {'result-file': self.MTF_LOG_DIR + os.sep + filename.replace('.script', '.htm')})
|
|
537 |
else:
|
|
538 |
SE(params, "param", {'result-file': self.TEF_LOG_DIR + os.sep + filename.replace('.script', '.htm')})
|
|
539 |
SE(params, "param", timeout=time_out)
|
628
|
540 |
if "testscript:mtf" in file1[2]:
|
587
|
541 |
SE(params, "param", parser="MTFResultParser")
|
|
542 |
else:
|
|
543 |
SE(params, "param", parser="TEFTestResultParser")
|
|
544 |
if file1[2] == 'testmodule:rtest':
|
|
545 |
filename = file1[1]
|
|
546 |
filename = filename[file1[1].rfind(os.sep)+1:]
|
|
547 |
step = SE(case, "step",
|
|
548 |
name="Execute test: %s" % filename, harness=setd["test_harness"],
|
|
549 |
**self.defaults)
|
|
550 |
SE(step, "command").text = "execute"
|
|
551 |
params = SE(step, "params")
|
|
552 |
SE(params, "param", file=file1[1])
|
|
553 |
#SE(params, "param", {'parameters': '-Dtextshell --'})
|
|
554 |
SE(params, "param", {'result-file': self.TEF_LOG_DIR + os.sep + filename.replace(filename.split(".")[-1], 'htm')})
|
|
555 |
SE(params, "param", timeout=time_out)
|
|
556 |
SE(params, "param", parser="RTestResultParser")
|
|
557 |
|
|
558 |
def generate_runsteps_stif(self, setd, case, src_dst, time_out):
|
|
559 |
"""generates runsteps for stif"""
|
|
560 |
ini = cfg = dll = has_tf_ini = False
|
|
561 |
ini_file = None
|
|
562 |
cfg_files = dll_files = []
|
|
563 |
|
|
564 |
for tf_ini in src_dst:
|
|
565 |
if "testframework.ini" in tf_ini[1].lower():
|
|
566 |
has_tf_ini = True
|
|
567 |
|
|
568 |
for file1 in src_dst:
|
|
569 |
|
|
570 |
if "testframework.ini" in file1[1].lower() and file1[2] == "engine_ini" and has_tf_ini:
|
|
571 |
ini = True
|
|
572 |
ini_file = file1
|
|
573 |
|
|
574 |
elif file1[2] == "engine_ini" and not has_tf_ini:
|
|
575 |
pipe_ini = open(file1[0], 'r')
|
|
576 |
if "[engine_defaults]" in str(pipe_ini.readlines()).lower():
|
|
577 |
ini = True
|
|
578 |
ini_file = file1
|
|
579 |
elif file1[2] == "conf":
|
|
580 |
if not ini:
|
|
581 |
cfg = True
|
|
582 |
cfg_files.append(file1)
|
|
583 |
elif file1[2] == "testmodule":
|
|
584 |
if not cfg and not ini:
|
|
585 |
dll = True
|
|
586 |
dll_files.append(file1)
|
|
587 |
if ini:
|
|
588 |
filename = ini_file[1]
|
|
589 |
filename = filename[ini_file[1].rfind(os.sep)+1:]
|
|
590 |
step = SE(case, "step",
|
|
591 |
name="Execute test: %s" % filename,
|
|
592 |
harness=setd["test_harness"], **self.defaults)
|
|
593 |
SE(step, "command").text = "run-cases"
|
|
594 |
params = SE(step, "params")
|
|
595 |
SE(params, "param", filter="*")
|
|
596 |
SE(params, "param", timeout=time_out)
|
|
597 |
SE(params, "param", engineini=ini_file[1])
|
|
598 |
elif cfg:
|
|
599 |
for conf_file in cfg_files:
|
|
600 |
if ".dll" in conf_file[1].lower():
|
|
601 |
continue
|
|
602 |
filename = conf_file[1]
|
|
603 |
filename = filename[conf_file[1].rfind(os.sep)+1:]
|
|
604 |
step = SE(case, "step",
|
|
605 |
name="Execute test: %s" % filename,
|
|
606 |
harness=setd["test_harness"], **self.defaults)
|
|
607 |
SE(step, "command").text = "run-cases"
|
|
608 |
params = SE(step, "params")
|
|
609 |
SE(params, "param", module="TESTSCRIPTER")
|
|
610 |
elem = SE(params, "param" )
|
|
611 |
elem.set('testcase-file', conf_file[1] )
|
|
612 |
SE(params, "param", filter="*")
|
|
613 |
SE(params, "param", timeout=time_out)
|
|
614 |
elif dll:
|
|
615 |
for dll_file in dll_files:
|
|
616 |
filename = dll_file[1]
|
|
617 |
filename = filename[dll_file[1].rfind(os.sep)+1:]
|
|
618 |
step = SE(case, "step",
|
|
619 |
name="Execute test: %s" % filename, harness=setd["test_harness"],
|
|
620 |
**self.defaults)
|
|
621 |
SE(step, "command").text = "run-cases"
|
|
622 |
params = SE(step, "params")
|
|
623 |
SE(params, "param", module=filename)
|
|
624 |
SE(params, "param", filter="*")
|
|
625 |
SE(params, "param", timeout=time_out)
|
|
626 |
|
|
627 |
def generate_runsteps_eunit(self, setd, case, src_dst, time_out, eunit_flags):
|
|
628 |
"""generates runsteps for eunit"""
|
|
629 |
|
|
630 |
for sdst in src_dst:
|
|
631 |
if "." in sdst[1]:
|
|
632 |
fileextension = sdst[1].rsplit(".")[1].lower()
|
|
633 |
filename = sdst[1]
|
|
634 |
filename = filename[filename.rfind(os.sep)+1:]
|
|
635 |
if fileextension == "dll" or fileextension == "exe":
|
|
636 |
re_dll = re.compile(r'[.]+%s' % fileextension, re.IGNORECASE)
|
|
637 |
no_dll = re_dll.sub('', filename)
|
|
638 |
no_dll_xml = ''.join([no_dll, u'_log.xml'])
|
|
639 |
|
|
640 |
|
|
641 |
|
|
642 |
#for EUnit or other executables
|
|
643 |
if sdst[2] == "testmodule":
|
|
644 |
eunit_exe = "EUNITEXERUNNER.EXE"
|
628
|
645 |
# include dll file only if it has some harness defined, else skip execute step, only install
|
|
646 |
if filename.lower() in setd['dll_files']:
|
|
647 |
if setd['dll_files'][filename.lower()] == "":
|
|
648 |
pass
|
|
649 |
else:
|
|
650 |
if re_dll.search(filename):
|
|
651 |
step = SE(case, "step", name = "Execute test: %s" % filename, harness=setd["test_harness"],
|
|
652 |
**self.defaults)
|
|
653 |
SE(step, "command").text = "execute"
|
|
654 |
params = SE(step, "params")
|
|
655 |
SE(params, "param", file=path(r"z:" + os.sep + "sys" + os.sep + "bin") / eunit_exe)
|
|
656 |
elem = SE(params, "param")
|
|
657 |
elem.set('result-file', path(self.EUNIT_LOG_DIR) / no_dll_xml)
|
|
658 |
SE(params, "param", parameters="%s /F %s /l xml %s" % (eunit_flags, no_dll, filename))
|
|
659 |
SE(params, "param", timeout=time_out)
|
|
660 |
|
587
|
661 |
#for QtTest.lib executables
|
|
662 |
elif sdst[2] == "testmodule:qt":
|
628
|
663 |
# include dll file only if it has some harness defined, else skip execute step, only install
|
|
664 |
if filename.lower() in setd['dll_files']:
|
|
665 |
if setd['dll_files'][filename.lower()] == "":
|
|
666 |
pass
|
|
667 |
else:
|
|
668 |
step = SE(case, "step", name = "Execute Qt-test: %s" % filename, harness=setd["test_harness"],
|
|
669 |
**self.defaults)
|
|
670 |
SE(step, "command").text = "execute"
|
|
671 |
params = SE(step, "params")
|
|
672 |
SE(params, "param", file=path(sdst[1]))
|
|
673 |
SE(params, "param", parameters=r"-lightxml -o %s\%s" % (path(self.QT_LOG_DIR), no_dll_xml))
|
|
674 |
elem = SE(params, "param")
|
|
675 |
elem.set('result-file', path(self.QT_LOG_DIR) / no_dll_xml)
|
|
676 |
SE(params, "param", parser="QTestResultParser")
|
|
677 |
elem = SE(params, "param")
|
|
678 |
elem.set('delete-result',"true")
|
|
679 |
SE(params, "param", async="false")
|
|
680 |
SE(params, "param", timeout=time_out)
|
587
|
681 |
|
|
682 |
|
|
683 |
|
|
684 |
def generate_run_steps(self, case, setd, time_out, eunit_flags):
|
|
685 |
"""Generates run-steps"""
|
|
686 |
src_dst = setd["src_dst"]
|
|
687 |
|
|
688 |
if setd["test_harness"] == "STIF":
|
|
689 |
self.generate_runsteps_stif(setd, case, src_dst, time_out)
|
|
690 |
if setd["test_harness"] == "GENERIC":
|
|
691 |
self.generate_runsteps_tef(setd, case, src_dst, time_out)
|
|
692 |
if setd["test_harness"] == "STIFUNIT":
|
|
693 |
self.generate_runsteps_stif(setd, case, src_dst, time_out)
|
|
694 |
|
|
695 |
if setd["test_harness"] == "EUNIT":
|
|
696 |
self.generate_runsteps_eunit(setd, case, src_dst, time_out, eunit_flags)
|
|
697 |
|
|
698 |
def generate_install_step(self, case, step_type, filename, src_dir,
|
|
699 |
dst_dir, case_harness, src_dst=None):
|
|
700 |
"""Generate install <step>."""
|
|
701 |
if src_dst == None or src_dst == []:
|
|
702 |
src_dst = []
|
|
703 |
step = SE(case, "step", name="Install %s: %s" % (step_type, filename),
|
|
704 |
harness=case_harness, **self.defaults)
|
|
705 |
SE(step, "command").text = "install"
|
|
706 |
params = SE(step, "params")
|
|
707 |
SE(params, "param", src=self.drop_path.joinpath(src_dir, filename))
|
|
708 |
SE(params, "param", dst=path(dst_dir).joinpath(filename))
|
|
709 |
else:
|
|
710 |
for sdst in src_dst:
|
|
711 |
dst = sdst[1]
|
|
712 |
type_ = sdst[2]
|
|
713 |
if "testmodule" in type_ or ".dll" in dst:
|
|
714 |
src_dir = dst.replace(":","")
|
|
715 |
src_dir = path(src_dir[:src_dir.rfind(os.sep)])
|
|
716 |
step_type = type_
|
|
717 |
filename = dst[dst.rfind(os.sep)+1:]
|
|
718 |
step = SE(case, "step", name="Install %s: %s" % (step_type, filename),
|
|
719 |
harness=case_harness, **self.defaults)
|
|
720 |
SE(step, "command").text = "install"
|
|
721 |
params = SE(step, "params")
|
|
722 |
SE(params, "param", src=self.drop_path.joinpath(src_dir, filename))
|
|
723 |
SE(params, "param", dst=path(dst))
|
|
724 |
for sdst in src_dst:
|
|
725 |
dst = sdst[1]
|
|
726 |
type_ = sdst[2]
|
|
727 |
if "testmodule" not in type_ and ".dll" not in dst:
|
|
728 |
src_dir = dst.replace(":","")
|
|
729 |
src_dir = path(src_dir[:src_dir.rfind(os.sep)])
|
|
730 |
step_type = type_
|
|
731 |
filename = dst[dst.rfind(os.sep)+1:]
|
|
732 |
step = SE(case, "step", name="Install %s: %s" % (step_type, filename),
|
|
733 |
harness=case_harness, **self.defaults)
|
|
734 |
SE(step, "command").text = "install"
|
|
735 |
params = SE(step, "params")
|
|
736 |
SE(params, "param", src=self.drop_path.joinpath(src_dir, filename))
|
|
737 |
SE(params, "param", dst=path(dst))
|
|
738 |
|
|
739 |
def drop_files(self, test_plan):
|
|
740 |
"""Yield a list of drop files."""
|
|
741 |
drop_set = set()
|
|
742 |
drop_files = []
|
|
743 |
pkg_files = []
|
|
744 |
for setd in test_plan.sets:
|
|
745 |
drop_path = self.drop_path_root.joinpath(setd["name"])
|
|
746 |
if setd.has_key("sis_files") and setd["sis_files"]:
|
|
747 |
if setd.has_key("pmd_files") and setd["pmd_files"]:
|
|
748 |
drop_files = ((drop_path.parent, "images", setd["image_files"]),
|
|
749 |
(drop_path.parent, "pmds", setd["pmd_files"]),
|
|
750 |
(drop_path, "sis", setd["sis_files"]),
|
|
751 |
(drop_path, "init", [setd["engine_ini_file"]]),
|
|
752 |
(drop_path, "trace_init", setd["trace_activation_files"]))
|
|
753 |
else:
|
|
754 |
drop_files = ((drop_path.parent, "images", setd["image_files"]),
|
|
755 |
(drop_path, "sis", setd["sis_files"]),
|
|
756 |
(drop_path, "init", [setd["engine_ini_file"]]))
|
|
757 |
elif setd["src_dst"] == []:
|
|
758 |
if setd.has_key("pmd_files") and setd["pmd_files"]:
|
|
759 |
drop_files = ((drop_path.parent, "images", setd["image_files"]),
|
|
760 |
(drop_path.parent, "pmds", setd["pmd_files"]),
|
|
761 |
(drop_path, "data", setd["data_files"]),
|
|
762 |
(drop_path, "conf", setd["config_files"]),
|
|
763 |
(drop_path, "testmodules", setd["testmodule_files"]),
|
|
764 |
(drop_path, "init", [setd["engine_ini_file"]]),
|
|
765 |
(drop_path, "trace_init", setd["trace_activation_files"]))
|
|
766 |
else:
|
|
767 |
drop_files = ((drop_path.parent, "images", setd["image_files"]),
|
|
768 |
(drop_path, "data", setd["data_files"]),
|
|
769 |
(drop_path, "conf", setd["config_files"]),
|
|
770 |
(drop_path, "testmodules", setd["testmodule_files"]),
|
|
771 |
(drop_path, "init", [setd["engine_ini_file"]]))
|
|
772 |
elif setd["src_dst"] != []:
|
|
773 |
for x_temp in setd["src_dst"]:
|
|
774 |
src = x_temp[0]
|
|
775 |
dst = x_temp[1]
|
|
776 |
dst2 = dst.replace(":","")
|
|
777 |
pkg_files.append((drop_path, dst2, src))
|
|
778 |
if setd.has_key("pmd_files") and setd["pmd_files"]:
|
|
779 |
drop_files = ((drop_path.parent, "images", setd["image_files"]),
|
|
780 |
(drop_path.parent, "pmds", setd["pmd_files"]),
|
|
781 |
(drop_path, "trace_init", setd["trace_activation_files"]))
|
|
782 |
else:
|
|
783 |
drop_files = ((drop_path.parent, "images", setd["image_files"]),)
|
|
784 |
for drop_dir, sub_dir, files in drop_files:
|
|
785 |
for file_path in files:
|
|
786 |
if file_path != None:
|
|
787 |
drop_file = drop_dir.joinpath(sub_dir, file_path.name)
|
|
788 |
drop_file = drop_file.normpath()
|
|
789 |
if drop_file not in drop_set:
|
|
790 |
drop_set.add(drop_file)
|
|
791 |
yield (drop_file, file_path.normpath())
|
|
792 |
for drop_dir, sub_dir, files in pkg_files:
|
|
793 |
drop_file = drop_dir.joinpath(sub_dir.replace('\\', os.sep))
|
|
794 |
drop_file = drop_file.normpath()
|
|
795 |
file_path = path(files)
|
|
796 |
if drop_file not in drop_set:
|
|
797 |
drop_set.add(drop_file)
|
|
798 |
yield (drop_file, file_path.normpath())
|
|
799 |
|
|
800 |
def generate_files(self, test_plan):
|
|
801 |
"""Generate the <files> section."""
|
|
802 |
files_elem = E("files")
|
|
803 |
for drop_file, _ in self.drop_files(test_plan):
|
|
804 |
SE(files_elem, "file").text = drop_file
|
|
805 |
return files_elem
|
|
806 |
|
|
807 |
def check_mtf_harness(self, _setd_):
|
|
808 |
"""check the testscript.mtf file is present"""
|
|
809 |
for _srcdst_ in _setd_['src_dst']:
|
628
|
810 |
if "testscript:mtf" in _srcdst_[2]:
|
|
811 |
return True
|
|
812 |
return False
|
|
813 |
|
|
814 |
def check_sut_harness(self, _setd_):
|
|
815 |
"""check the testscript.sut file is present"""
|
|
816 |
for _srcdst_ in _setd_['src_dst']:
|
|
817 |
if "testmodule:sut" in _srcdst_[2]:
|
587
|
818 |
return True
|
|
819 |
return False
|
|
820 |
|
|
821 |
def check_qt_harness(self, _setd_):
|
|
822 |
""" check the QT harness is OK """
|
|
823 |
_setd_ = _setd_
|
|
824 |
is_qt_test = False
|
|
825 |
if _setd_.has_key("sis_files"):
|
|
826 |
_dict_key_ = "sis_files"
|
|
827 |
else:
|
|
828 |
_dict_key_ = "src_dst"
|
|
829 |
|
|
830 |
for _srcdst_ in _setd_[_dict_key_]:
|
|
831 |
if "testmodule:qt" == _srcdst_[2]:
|
|
832 |
is_qt_test = True
|
|
833 |
return is_qt_test
|
|
834 |
|
|
835 |
def generate_target(test_plan, root):
|
|
836 |
"""Generate targets"""
|
|
837 |
harness = test_plan["harness"]
|
|
838 |
if harness == "MULTI_HARNESS":
|
|
839 |
input_targets(test_plan, root, ["STIF", "EUNIT"])
|
588
|
840 |
elif harness == "MULTI_HARNESS_GENERIC_STIF":
|
|
841 |
input_targets(test_plan, root, ["STIF", "GENERIC"])
|
587
|
842 |
elif harness == "STIF":
|
|
843 |
input_targets(test_plan, root, ["STIF"])
|
|
844 |
elif harness == "EUNIT":
|
|
845 |
input_targets(test_plan, root, ["EUNIT"])
|
|
846 |
elif harness == "STIFUNIT":
|
|
847 |
input_targets(test_plan, root, ["STIFUNIT"])
|
|
848 |
elif harness == "GENERIC":
|
|
849 |
input_targets(test_plan, root, ["GENERIC"])
|
|
850 |
|
|
851 |
def input_targets(test_plan, root, harness_type):
|
|
852 |
"""Append target(s) into the XML"""
|
|
853 |
target = E("target")
|
|
854 |
for har in harness_type:
|
|
855 |
device = SE(target, "device", rank="none", alias="DEFAULT_%s" % har)
|
|
856 |
SE(device, "property", name="HARNESS", value=har)
|
|
857 |
SE(device, "property", name="TYPE", value=test_plan["device_type"])
|
|
858 |
if test_plan["device_hwid"] != "":
|
|
859 |
SE(device, "property", name="HWID", value=test_plan["device_hwid"])
|
|
860 |
if test_plan["trace_enabled"] != "":
|
|
861 |
if test_plan["trace_enabled"].lower() == "true":
|
|
862 |
SE(device, "property", name="TRACE_ENABLED", value=test_plan["trace_enabled"])
|
|
863 |
root.append(target)
|
|
864 |
|
|
865 |
|
|
866 |
def insert_custom_file(xmltree, filename):
|
|
867 |
"""
|
|
868 |
Inserts into the given XML tree the given customization file
|
|
869 |
Broken input XML inserts a comment to the XML tree
|
|
870 |
"""
|
|
871 |
try:
|
|
872 |
custom_action_file = codecs.open(filename, "r", "iso-8859-15")
|
|
873 |
loop = ''
|
|
874 |
cust = unicode(custom_action_file.read(1))
|
|
875 |
try:
|
|
876 |
# try to read the file and addcharacter by character until the
|
|
877 |
# elementtree is happy and then reset the loop and continue until the file is
|
|
878 |
# completely processed. Known issue: file ending in comment will cause a warning.
|
|
879 |
while cust:
|
|
880 |
if loop != '' :
|
|
881 |
# if we have something left from the previous try
|
|
882 |
cust = loop + cust
|
|
883 |
# _logger.debug("what is cust \n %s \n" % cust)
|
|
884 |
try:
|
|
885 |
xmltree.append(et.XML(cust.encode("ISO-8859-15")))
|
|
886 |
except ExpatError, err:
|
|
887 |
# _logger.debug("Error %s in XML when prosessing file %s \n Line and column refer to section:\n%s\n" % ( err, filename, loop))
|
|
888 |
loop = cust
|
|
889 |
else:
|
|
890 |
# clear the loop variable
|
|
891 |
loop = ''
|
|
892 |
cust = unicode(custom_action_file.read(1))
|
628
|
893 |
except UnicodeError, err:
|
587
|
894 |
_logger.error("Error %s in XML when prosessing %s\n" % ( err, filename))
|
|
895 |
xmltree.append(et.Comment("Error in XML file when prosessing %s\n" % ( filename)))
|
|
896 |
|
628
|
897 |
if loop != '':
|
587
|
898 |
# we should have used all the input and cleared loop variable
|
|
899 |
_logger.warning("Issues in customization file %s in XML when prosessing issue %s \n Line and column refer to section:\n%s\n" % ( filename, err, loop))
|
|
900 |
|
|
901 |
custom_action_file.close()
|
|
902 |
except IOError, err:
|
|
903 |
# _logger.debug("This is for debugging only. Do not treat this as anything else. Anything is OK... The data: %s when prosessing %s\n" % (err, filename))
|
|
904 |
pass
|
|
905 |
else:
|
|
906 |
_logger.info("Included file %s" % ( filename))
|
|
907 |
|
|
908 |
def generate_post_actions(test_plan):
|
|
909 |
"""Generate post actions."""
|
|
910 |
actions = []
|
|
911 |
|
|
912 |
if not test_plan.custom_dir is None:
|
|
913 |
insert_custom_file(actions, test_plan.custom_dir.joinpath("prepostaction.xml"))
|
|
914 |
|
|
915 |
for action_type, parameters in test_plan.post_actions:
|
|
916 |
action = E("postAction")
|
|
917 |
SE(action, "type").text = action_type
|
|
918 |
params = SE(action, "params")
|
|
919 |
for name, value in parameters:
|
|
920 |
SE(params, "param", name=name, value=value)
|
|
921 |
actions.append(action)
|
|
922 |
|
|
923 |
if not test_plan.custom_dir is None:
|
|
924 |
insert_custom_file(actions, test_plan.custom_dir.joinpath("postpostaction.xml"))
|
|
925 |
|
|
926 |
return actions
|
|
927 |
|
|
928 |
|
|
929 |
class Ats3TemplateTestDropGenerator(Ats3TestDropGenerator):
|
|
930 |
"""ATS3 template for test drop generator"""
|
|
931 |
STIF_LOG_DIR = r"c:\logs\testframework"
|
|
932 |
TEF_LOG_DIR = r"c:\logs\testexecute"
|
|
933 |
MTF_LOG_DIR = r"c:\logs\testresults"
|
628
|
934 |
SUT_LOG_DIR = r"c:\sut"
|
587
|
935 |
STIFUNIT_LOG_DIR = r"c:\logs\testframework"
|
|
936 |
EUNIT_LOG_DIR = r"c:\Shared\EUnit\logs"
|
|
937 |
#QT_LOG_DIR = r"c:\private\Qt\logs"
|
|
938 |
QT_LOG_DIR = r"c:\shared\EUnit\logs"
|
|
939 |
CTC_LOG_DIR = r"c:\data\ctc"
|
628
|
940 |
AtsInterface_LOG_DIR = r"c:\spd_logs\xml"
|
587
|
941 |
|
|
942 |
def stif_init_file(self, src_dst):
|
|
943 |
"""init the STIF format file"""
|
|
944 |
has_tf_ini = False
|
|
945 |
ini_file = None
|
|
946 |
|
|
947 |
for tf_ini in src_dst:
|
|
948 |
if "testframework.ini" in tf_ini[1].lower():
|
|
949 |
has_tf_ini = True
|
|
950 |
|
|
951 |
for file1 in src_dst:
|
|
952 |
if "testframework.ini" in file1[1].lower() and file1[2] == "engine_ini" and has_tf_ini:
|
|
953 |
ini_file = file1
|
|
954 |
elif file1[2] == "engine_ini" and not has_tf_ini:
|
|
955 |
pipe_ini = open(file1[0], 'r')
|
|
956 |
if "[engine_defaults]" in str(pipe_ini.readlines()).lower():
|
|
957 |
ini_file = file1
|
|
958 |
return ini_file
|
|
959 |
|
|
960 |
def ctcnetworkpath(self, setd, test_plan):
|
|
961 |
"""CTC network path handling"""
|
|
962 |
#preparing local-path for CTC step
|
|
963 |
#getting '39865' as diamonds ID out of 'http://diamonds.server.domain.invalid/diamonds/builds/39865/'
|
|
964 |
if test_plan["diamonds_build_url"].rfind("/", 0):
|
|
965 |
diamonds_id = test_plan["diamonds_build_url"].rsplit(r"/", 2)[1]
|
|
966 |
else:
|
|
967 |
diamonds_id = test_plan["diamonds_build_url"].rsplit(r"/", 1)[1]
|
|
968 |
|
|
969 |
#separating network id and drop number from 10.11.3.2\share#ats\drop2.zip#3
|
|
970 |
#'drop2' from the other part of the string conjuncted with a # sign
|
|
971 |
ats_network = r"\\" + test_plan["ctc_run_process_params"].rsplit("#", 2)[0] #network host
|
|
972 |
temp_drop_id = path(test_plan["ctc_run_process_params"].rsplit("#", 2)[1].rsplit(".", 1)[0]).normpath() #drop ID
|
|
973 |
if atssep in temp_drop_id:
|
|
974 |
drop_id = temp_drop_id.rsplit(atssep, 1)[1]
|
|
975 |
else:
|
|
976 |
drop_id = temp_drop_id
|
|
977 |
|
|
978 |
return atspath.join(ats_network, "ctc_helium" , diamonds_id, drop_id, setd["name"], "ctcdata")
|
628
|
979 |
|
|
980 |
def stifmodulename(self, ini_file):
|
|
981 |
modname = None
|
|
982 |
ini = open(ini_file)
|
|
983 |
for line in ini:
|
|
984 |
if line.startswith('ModuleName'):
|
|
985 |
modname = line.split('=')[1].strip()
|
|
986 |
ini.close()
|
|
987 |
return modname
|
587
|
988 |
|
628
|
989 |
def getlogdir(self, test_plan, setd):
|
587
|
990 |
""" find the logger directory"""
|
628
|
991 |
returnval = None
|
587
|
992 |
if setd["test_harness"] == "STIF":
|
628
|
993 |
if test_plan['hti'] == 'True':
|
|
994 |
returnval = self.STIF_LOG_DIR
|
|
995 |
else:
|
|
996 |
returnval = self.AtsInterface_LOG_DIR
|
587
|
997 |
elif setd["test_harness"] == "STIFUNIT":
|
628
|
998 |
returnval = self.STIFUNIT_LOG_DIR
|
587
|
999 |
elif setd["test_harness"] == "GENERIC":
|
|
1000 |
if self.check_mtf_harness(setd):
|
628
|
1001 |
returnval = self.MTF_LOG_DIR
|
|
1002 |
elif self.check_sut_harness(setd):
|
|
1003 |
returnval = self.SUT_LOG_DIR
|
587
|
1004 |
else:
|
628
|
1005 |
returnval = self.TEF_LOG_DIR
|
587
|
1006 |
elif setd["test_harness"] == "EUNIT":
|
|
1007 |
if self.check_qt_harness(setd):
|
628
|
1008 |
returnval = self.QT_LOG_DIR
|
587
|
1009 |
else:
|
628
|
1010 |
returnval = self.EUNIT_LOG_DIR
|
|
1011 |
return returnval
|
587
|
1012 |
|
|
1013 |
def generate_xml(self, test_plan):
|
|
1014 |
"""generate the XML"""
|
|
1015 |
|
|
1016 |
customdirs = []
|
|
1017 |
if test_plan.custom_dir:
|
|
1018 |
customdirs = [jinja2.FileSystemLoader(test_plan.custom_dir)]
|
|
1019 |
for setd in test_plan.sets:
|
|
1020 |
if setd['custom_dir']:
|
|
1021 |
customdirs.append(jinja2.FileSystemLoader(setd['custom_dir']))
|
|
1022 |
|
|
1023 |
loader = jinja2.ChoiceLoader([jinja2.PackageLoader(__name__, 'templates')] + customdirs)
|
|
1024 |
env = jinja2.Environment(loader=loader)
|
588
|
1025 |
|
|
1026 |
if hasattr(test_plan, 'custom_template'):
|
|
1027 |
template = env.from_string(open(test_plan.custom_template).read())
|
|
1028 |
else:
|
628
|
1029 |
template = env.from_string(pkg_resources.resource_string(__name__, 'ats4_template.xml'))# pylint: disable=E1101
|
587
|
1030 |
|
|
1031 |
xmltext = template.render(test_plan=test_plan, os=os, atspath=atspath, atsself=self).encode('ISO-8859-1')
|
628
|
1032 |
return et.ElementTree(et.XML(xmltext))
|
|
1033 |
|
|
1034 |
def get_template(self, directory, template_name):
|
|
1035 |
if directory:
|
|
1036 |
name = os.path.join(directory, template_name)
|
|
1037 |
if os.path.exists(name):
|
|
1038 |
template_file = open(name)
|
|
1039 |
contents = template_file.read()
|
|
1040 |
template_file.close()
|
|
1041 |
return contents
|
|
1042 |
return ''
|
|
1043 |
|
|
1044 |
|