|
1 # -*- encoding: latin-1 -*- |
|
2 |
|
3 #============================================================================ |
|
4 #Name : test_ats4.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 """ Testing ats4 framework. """ |
|
23 # pylint: disable-msg=E1101, C0302, W0142, W0603, R0902,R0903,R0912,R0915 |
|
24 #E1101 => Mocker shows mockery |
|
25 #C0302 => too many lines |
|
26 #W0142 => used * or ** magic |
|
27 #W0603 => used global |
|
28 #R* during refactoring |
|
29 |
|
30 from cStringIO import StringIO |
|
31 from xml.etree.ElementTree import fromstring |
|
32 from xml.etree import ElementTree as et |
|
33 import difflib |
|
34 import logging |
|
35 logging.getLogger().setLevel(logging.ERROR) |
|
36 import tempfile |
|
37 import zipfile |
|
38 import os |
|
39 import re |
|
40 import subprocess |
|
41 import fileutils |
|
42 |
|
43 from path import path # pylint: disable-msg=F0401 |
|
44 import amara |
|
45 import mocker # pylint: disable-msg=F0401 |
|
46 |
|
47 import ntpath |
|
48 |
|
49 import ats3 |
|
50 import ats3.testconfigurator as atc |
|
51 import ats3.dropgenerator as adg |
|
52 import ats3.parsers as parser |
|
53 |
|
54 |
|
55 TEST_PATH = None |
|
56 TEST_FILES = {} |
|
57 TSRC = None |
|
58 OUTPUT = None |
|
59 |
|
60 # Shortcuts |
|
61 E = et.Element |
|
62 SE = et.SubElement |
|
63 |
|
64 class Bunch(object): |
|
65 """ Configuration object. Argument from constructor are converted into class attributes. """ |
|
66 def __init__(self, **kwargs): |
|
67 self.__dict__.update(kwargs) |
|
68 |
|
69 def equal_xml(xml1, xml2): |
|
70 """Check the equality of the given XML snippets. |
|
71 |
|
72 Tag name equality: |
|
73 |
|
74 >>> equal_xml('<a/>', '<a/>') |
|
75 True |
|
76 >>> equal_xml('<a/>', '<b/>') |
|
77 False |
|
78 |
|
79 Attribute equality: |
|
80 |
|
81 >>> equal_xml('<a k="v"/>', '<a k="v"/>') |
|
82 True |
|
83 >>> equal_xml('<a k="v"/>', '<a k="w"/>') |
|
84 False |
|
85 |
|
86 Text content equality: |
|
87 |
|
88 >>> equal_xml('<a>v</a>', '<a>v</a>') |
|
89 True |
|
90 >>> equal_xml('<a>v</a>', '<a>w</a>') |
|
91 False |
|
92 >>> equal_xml('<a>v</a>', '<a></a>') |
|
93 False |
|
94 |
|
95 Text content equality when whitespace differs: |
|
96 >>> equal_xml('<a>v</a>', '<a>v </a>') |
|
97 True |
|
98 |
|
99 Equality of child elements: |
|
100 |
|
101 >>> equal_xml('<a><b><c k="v"/></b></a>', '<a><b><c k="v"/></b></a>') |
|
102 True |
|
103 >>> equal_xml('<a><b><c k="v"/></b></a>', '<a><b><c k="w"/></b></a>') |
|
104 False |
|
105 >>> equal_xml('<a><b><c k="v"/>v</b></a>', '<a><b><c k="v"/>w</b></a>') |
|
106 False |
|
107 >>> equal_xml('<a><b><c k="v"/>v</b></a>', '<a><b><c k="v"/>v </b></a>') |
|
108 True |
|
109 |
|
110 """ |
|
111 def __init__(): |
|
112 check_instance(xml1, xml2) |
|
113 |
|
114 def check_instance(xml1, xml2): |
|
115 """if xml1 and xml2 are instances, converts to strings""" |
|
116 if isinstance(xml1, basestring): |
|
117 xml1 = fromstring(xml1) |
|
118 if isinstance(xml2, basestring): |
|
119 xml2 = fromstring(xml2) |
|
120 check_tags(xml1, xml2) |
|
121 |
|
122 def check_tags(xml1, xml2): |
|
123 """check xml tags and text equality""" |
|
124 if xml1.tag != xml2.tag: |
|
125 return False |
|
126 if xml1.attrib != xml2.attrib: |
|
127 return False |
|
128 if xml1.text: |
|
129 if not xml2.text: |
|
130 return False |
|
131 if xml2.text: |
|
132 if not xml1.text: |
|
133 return False |
|
134 |
|
135 produce_xml_children(xml1, xml2) |
|
136 |
|
137 def produce_xml_children(xml1, xml2): |
|
138 """checks if xml children are of same length and are equal?""" |
|
139 if xml1.text and xml2.text and xml1.text.strip() != xml2.text.strip(): |
|
140 return False |
|
141 if xml1.tail is not None and xml2.tail is not None: |
|
142 if xml1.tail.strip() != xml2.tail.strip(): |
|
143 return False |
|
144 elif xml1.tail != xml2.tail: |
|
145 return False |
|
146 |
|
147 children1 = list(xml1.getchildren()) |
|
148 children2 = list(xml2.getchildren()) |
|
149 if len(children1) != len(children2): |
|
150 return False |
|
151 for child1, child2 in zip(children1, children2): |
|
152 return equal_xml(child1, child2) |
|
153 return True |
|
154 |
|
155 |
|
156 def setup_module(): |
|
157 """ Setup test environment. """ |
|
158 global TEST_PATH, TSRC, OUTPUT |
|
159 TEST_PATH = path(tempfile.mkdtemp()) |
|
160 OUTPUT = TEST_PATH.joinpath(r"output") |
|
161 component = TEST_PATH |
|
162 component.joinpath("group").makedirs() |
|
163 for path_parts in (("tsrc", "group", "bld.inf"), |
|
164 ("tsrc", "group", "test.pkg"), |
|
165 ("tsrc", "testmodules", "file1.dll"), |
|
166 ("tsrc", "testmodules", "file2.dll"), |
|
167 ("tsrc", "data", "file1"), |
|
168 ("tsrc", "data", "file2"), |
|
169 ("tsrc", "data", "file3"), |
|
170 ("tsrc", "data", "mmc", "file4"), |
|
171 ("tsrc", "data", "c", "file5"), |
|
172 ("tsrc", "conf", "file1.cfg"), |
|
173 ("tsrc", "conf", "file2.cfg"), |
|
174 ("tsrc", "init", "TestFramework.ini"), |
|
175 ("tsrc", "custom", "prepostaction.xml"), |
|
176 ("tsrc", "custom", "postpostaction.xml"), |
|
177 # These do not have to be under 'tsrc': |
|
178 ("tsrc", "output", "images", "file1.fpsx"), |
|
179 ("tsrc", "output", "images", "file2.fpsx"), |
|
180 ("tsrc", "sis", "file1.sisx"), |
|
181 ("tsrc", "sis", "file2.sisx"), |
|
182 ("tsrc", "sis", "file3.sisx"), |
|
183 ("tsrc", "trace_init", "trace_activation_1.xml")): |
|
184 filepath = component.joinpath(*path_parts) |
|
185 if not filepath.parent.exists(): |
|
186 filepath.parent.makedirs() |
|
187 filepath.touch() |
|
188 TEST_FILES.setdefault(path_parts[1], []).append(filepath) |
|
189 TSRC = component.joinpath("tsrc") |
|
190 filepath = OUTPUT.joinpath("pmd", "pmd_file.pmd") |
|
191 if not filepath.parent.exists(): |
|
192 filepath.parent.makedirs() |
|
193 filepath.touch() |
|
194 TEST_FILES.setdefault("pmd_file", []).append(filepath) |
|
195 tracing = component.joinpath("tsrc", "trace_init") |
|
196 root = E('ConfigurationFile') |
|
197 confs = E("Configurations") |
|
198 trace_act = SE(confs, "TraceActivation") |
|
199 conf = SE(trace_act, "Configuration") |
|
200 conf.set('Name', 'MCU') |
|
201 mcu = SE(conf, "MCU") |
|
202 sett = SE(mcu, "settings") |
|
203 SE(sett, "timestamp") |
|
204 root.append(confs) |
|
205 ettree = et.ElementTree(root) |
|
206 doc = amara.parse(et.tostring(ettree.getroot())) |
|
207 handle = open(tracing.joinpath("trace_activation_1.xml"), "w") |
|
208 handle.write(doc.xml(indent="yes")) |
|
209 handle.close() |
|
210 # tracing.writestr("trace_activation_1.xml", doc.xml(indent=u"yes")) |
|
211 group = component.joinpath("tsrc", "group") |
|
212 group.joinpath("bld.inf").write_text( |
|
213 r""" |
|
214 PRJ_TESTMMPFILES |
|
215 stif.mmp /* xyz.mmp */ abcd.mmp |
|
216 /*xyz.mmp*/ |
|
217 eunit.mmp /* xyz.mmp */ |
|
218 both.mmp |
|
219 ..\sub-component\group\sub-component.mmp |
|
220 """.replace('\\', os.sep)) |
|
221 |
|
222 group.joinpath("test.pkg").write_text( |
|
223 r""" |
|
224 ;Language - standard language definitions |
|
225 &EN |
|
226 |
|
227 ; standard SIS file header |
|
228 #{"BTEngTestApp"},(0x04DA27D5),1,0,0 |
|
229 |
|
230 ;Supports Series 60 v 3.0 |
|
231 (0x101F7961), 0, 0, 0, {"Series60ProductID"} |
|
232 |
|
233 ;Localized Vendor Name |
|
234 %{"BTEngTestApp"} |
|
235 |
|
236 ;Unique Vendor name |
|
237 :"Nokia" |
|
238 |
|
239 ; Files to copy |
|
240 "\tsrc\testmodules\file1.dll"-"c:\sys\bin\file1.dll" |
|
241 "\tsrc\testmodules\file2.dll"-"c:\sys\bin\file2.dll" |
|
242 "\tsrc\data\file1"-"e:\sys\bin\file1" |
|
243 "\tsrc\data\file2"-"e:\sys\bin\file2" |
|
244 "\tsrc\data\file3"-"e:\sys\bin\file3" |
|
245 "\tsrc\conf\file1.cfg"-"!:\sys\bin\file1.cfg" |
|
246 "\tsrc\conf\file2.cfg"-"!:\sys\bin\file2.cfg" |
|
247 "\tsrc\init\TestFramework.ini"-"!:\sys\bin\TestFramework.ini" |
|
248 "\tsrc\sis\file1.sisx"-"!:\sys\bin\file1.sisx" |
|
249 "\tsrc\sis\file2.sisx"-"!:\sys\bin\file2.sisx" |
|
250 """.replace('\\', os.sep)) |
|
251 group.joinpath("stif.mmp").write_text("LIBRARY stiftestinterface.lib") |
|
252 group.joinpath("eunit.mmp").write_text("LIBRARY eunit.lib") |
|
253 group.joinpath("both.mmp").write_text("LIBRARY stiftestinterface.lib eunit.lib") |
|
254 init = component.joinpath("tsrc", "init") |
|
255 |
|
256 init.joinpath("TestFramework.ini").write_text( |
|
257 r""" |
|
258 # - Sets a device reset module's dll name(Reboot). |
|
259 # + If Nokia specific reset module is not available or it is not correct one |
|
260 # StifHWResetStub module may use as a template for user specific reset |
|
261 # module. |
|
262 |
|
263 [Engine_Defaults] |
|
264 |
|
265 TestReportMode= FullReport # Possible values are: 'Empty', 'Summary', 'Environment', |
|
266 'TestCases' or 'FullReport' |
|
267 |
|
268 CreateTestReport= YES # Possible values: YES or NO |
|
269 |
|
270 TestReportFilePath= C:\LOGS\TestFramework\ |
|
271 TestReportFileName= TestReport |
|
272 |
|
273 TestReportFormat= TXT # Possible values: TXT or HTML |
|
274 |
|
275 """) |
|
276 |
|
277 |
|
278 def teardown_module(): |
|
279 """ Cleanup environment after testing. """ |
|
280 def __init__(): |
|
281 path(TEST_PATH).rmtree() |
|
282 |
|
283 # CTC related functions |
|
284 def check_ctc_write(steps): |
|
285 """Checks if CTC data is written on the CTC log""" |
|
286 step = steps.next() |
|
287 assert step.findtext("./type") == "NonTestExecuteTask" |
|
288 params = step.findall("./parameters/parameter") |
|
289 assert params[0].get("value") == "writelocal" |
|
290 assert params[1].get("value") == path(r"z:\sys\bin\ctcman.exe") |
|
291 step = steps.next() |
|
292 assert step.findtext("./type") == "NonTestExecuteTask" |
|
293 params = step.findall("./parameters/parameter") |
|
294 assert params[0].get("value") == "writefile" |
|
295 assert params[1].get("value") == path(r"z:\sys\bin\ctcman.exe") |
|
296 |
|
297 def check_ctc_log(steps, testtype=""): |
|
298 """Fetches CTC Log""" |
|
299 #For the ctcdata.txt to be published on the ATS network drive |
|
300 step = steps.next() |
|
301 assert step.findtext("./type") == "FileDownloadTask" |
|
302 params = step.findall("./parameters/parameter") |
|
303 #assert params[0].get("value") == "false" |
|
304 assert params[0].get("value") == path(r"c:\data\ctc\ctcdata.txt") |
|
305 if testtype == "withpkgfiles": |
|
306 assert params[1].get("value") == r"\\10.0.0.1\ctc_helium\builds\drop0\set1\ctcdata" |
|
307 else: |
|
308 assert params[1].get("value") == r"\\10.0.0.1\ctc_helium\builds\drop0\set0\ctcdata" |
|
309 |
|
310 #For the ctcdata.txt to be published on the build network drive |
|
311 step = steps.next() |
|
312 assert step.findtext("./type") == "FileDownloadTask" |
|
313 params = step.findall("./parameters/parameter") |
|
314 #assert params[0].get("value") == "true" |
|
315 assert params[0].get("value") == path(r"c:\data\ctc\ctcdata.txt") |
|
316 |
|
317 def check_ctc_start(steps): |
|
318 """Checks if CTC starts in ATS""" |
|
319 step = steps.next() |
|
320 assert step.findtext("./type") == "CreateDirTask" |
|
321 params = step.findall("./parameters/parameter") |
|
322 assert params[0].get("value") == path(r"c:\data\ctc") |
|
323 step = steps.next() |
|
324 assert step.findtext("./type") == "NonTestExecuteTask" |
|
325 params = step.findall("./parameters/parameter") |
|
326 assert params[0].get("value") == path(r"z:\sys\bin\ctcman.exe") |
|
327 |
|
328 def check_fetch_logs(steps, harness="STIF"): |
|
329 """Checks fetching log directory is created""" |
|
330 step = steps.next() |
|
331 assert step.findtext("./type") == "FileDownloadTask" |
|
332 params = step.findall("./parameters/parameter") |
|
333 if harness == "STIF": |
|
334 assert params[0].get("value") == path(r"c:\logs\testframework\*") |
|
335 else: |
|
336 assert params[0].get("value") == path(r"c:\Shared\EUnit\logs\*") |
|
337 |
|
338 def check_diamonds_action(action): |
|
339 """ Testing Diamonds action. """ |
|
340 assert action.findtext("./type") == "DiamondsAction" |
|
341 assert not action.findall("./parameters/parameter") |
|
342 |
|
343 def check_send_email_action(action, reportemail): |
|
344 """verifies if sening email option works""" |
|
345 assert action.findtext("./type") == "EmailAction" |
|
346 params = action.findall("./parameters/parameter") |
|
347 assert params[0].get("name") == "subject" |
|
348 #assert params[0].get("value") == "email subject" |
|
349 assert params[1].get("name") == "to" |
|
350 assert params[1].get("value") == reportemail |
|
351 |
|
352 def check_ctc_run_process_action(action): |
|
353 """verifies if CTC run process action works""" |
|
354 #The parameters for this test are intended to execute on a windows machine |
|
355 assert action.findtext("./type") == "RunProcessAction" |
|
356 params = action.findall("./parameters/parameter") |
|
357 assert params[0].get("name") == "file" |
|
358 assert params[0].get("value") == "catsctc2html/catsctc2html.exe" |
|
359 assert params[1].get("name") == "parameters" |
|
360 assert params[1].get("value") == r"--ctcdata_files=\\10.0.0.1\ctc_helium\1234\drop0\set0\ctcdata --monsym_files=\\10.0.0.1\ctc_helium\1234\mon_syms\1\MON.sym --diamonds_build_id=1234 --drop_id=0 --total_amount_of_drops=1" |
|
361 |
|
362 def check_ats_report_action(action, filestore): |
|
363 """verifies if sening ATS report option works""" |
|
364 assert action.findtext("./type") == "FileStoreAction" |
|
365 params = action.findall("./parameters/parameter") |
|
366 assert params[0].get("name") == "to-folder" |
|
367 assert params[0].get("value") == filestore |
|
368 assert params[1].get("name") == "report-type" |
|
369 assert params[1].get("value") == "ATS_REPORT" |
|
370 assert params[2].get("name") == "date-format" |
|
371 assert params[2].get("value") == "yyyyMMdd" |
|
372 assert params[3].get("name") == "time-format" |
|
373 assert params[3].get("value") == "HHmmss" |
|
374 |
|
375 def check_stif_report_action(action, filestore): |
|
376 """verifies if sening STIF report option works""" |
|
377 assert action.findtext("./type") == "FileStoreAction" |
|
378 params = action.findall("./parameters/parameter") |
|
379 assert params[0].get("name") == "to-folder" |
|
380 assert params[0].get("value") == filestore |
|
381 assert params[1].get("name") == "report-type" |
|
382 assert params[1].get("value") == "STIF_COMPONENT_REPORT_ALL_CASES" |
|
383 assert params[2].get("name") == "run-log" |
|
384 assert params[2].get("value") == "true" |
|
385 assert params[3].get("name") == "date-format" |
|
386 assert params[3].get("value") == "yyyyMMdd" |
|
387 assert params[4].get("name") == "time-format" |
|
388 assert params[4].get("value") == "HHmmss" |
|
389 |
|
390 def check_log_dir(steps): |
|
391 """ Test the log dir. """ |
|
392 step = steps.next() |
|
393 assert step.findtext("./type") == "CreateDirTask" |
|
394 |
|
395 def check_trace_start(steps, filestore): |
|
396 """Checks if tracing is started on the ATS""" |
|
397 step = steps.next() |
|
398 assert step.findtext("./type") == "trace-start" |
|
399 params = step.findall("./parameters/parameter") |
|
400 assert params[0].get("value") == path(r"ATS3Drop\set0\trace_activation\trace_activation_1.xml") |
|
401 assert params[1].get("value") == "MCU" |
|
402 assert params[2].get("value") == path(r"ATS3Drop\pmds\pmd_file.pmd") |
|
403 assert params[3].get("value") == filestore.joinpath("traces", "set0", "tracelog.blx") |
|
404 assert params[4].get("value") == "60" |
|
405 assert params[5].get("value") == "yyyyMMdd" |
|
406 assert params[6].get("value") == "HHmmss" |
|
407 |
|
408 def check_trace_end_steps(steps, filestore): |
|
409 """ Test trace end step. """ |
|
410 step = steps.next() |
|
411 assert step.findtext("./type") == "trace-stop" |
|
412 params = step.findall("./parameters/parameter") |
|
413 assert params[0].get("value") == "60" |
|
414 step = steps.next() |
|
415 assert step.findtext("./type") == "trace-convert" |
|
416 params = step.findall("./parameters/parameter") |
|
417 assert params[0].get("value") == path(r"ATS3Drop\pmds\pmd_file.pmd") |
|
418 assert params[1].get("value") == filestore.joinpath("traces", "set0", "tracelog.blx") |
|
419 assert params[2].get("value") == "60" |
|
420 assert params[3].get("value") == "yyyyMMdd" |
|
421 assert params[4].get("value") == "HHmmss" |
|
422 |
|
423 class TestTestPlan(mocker.MockerTestCase): |
|
424 """Creates TestPlan mocker setup""" |
|
425 def __init__(self, methodName="runTest"): |
|
426 mocker.MockerTestCase.__init__(self, methodName) |
|
427 |
|
428 def setUp(self): |
|
429 """ Setup TestTestPlan testsuite. """ |
|
430 opts = Bunch(testrun_name="testrun", harness="STIF", |
|
431 device_type="product", plan_name="ats3_test_plan", |
|
432 diamonds_build_url="", report_email="", file_store=path(), test_timeout="60", |
|
433 device_hwid="5425", trace_enabled="True", ctc_enabled="True", eunitexerunner_flags="/E S60AppEnv /R Off", |
|
434 multiset_enabled=False, ctc_run_process_params=r"10.0.0.1#x:\ats\drop0.zip#1", monsym_files="", hti="True") |
|
435 self.atp = ats3.Ats3TestPlan(opts) |
|
436 self.config_files = TEST_FILES["conf"] |
|
437 self.data_files = TEST_FILES["data"] |
|
438 self.engine_ini_file = TEST_FILES["init"][0] |
|
439 self.image_files = TEST_FILES["output"] |
|
440 self.sis_files = TEST_FILES["sis"] |
|
441 self.testmodule_files = TEST_FILES["testmodules"] |
|
442 self.ctc_enabled = self.atp["ctc_enabled"] |
|
443 self.custom_dir = "CustomD" |
|
444 self.eunitexerunner_flags = self.atp["eunitexerunner_flags"] |
|
445 if self.atp["trace_enabled"].lower() == "true": |
|
446 self.trace_activation_files = TEST_FILES["trace_init"] |
|
447 self.pmd_files = TEST_FILES["pmd_file"] |
|
448 else: |
|
449 self.trace_activation_files = [] |
|
450 self.pmd_files = [] |
|
451 self.test_timeout = self.atp["test_timeout"] |
|
452 self.eunitexerunner_flags = self.atp["eunitexerunner_flags"] |
|
453 self.device_hwid = self.atp["device_hwid"] |
|
454 self.test_harness = self.atp["harness"] |
|
455 self.src_dst = [("" + os.sep + "tsrc" + os.sep + "testmodules" + os.sep + "file1.dll", "c:\sys\bin\file1.dll", "testmodule"), |
|
456 ("" + os.sep + "tsrc" + os.sep + "testmodules" + os.sep + "file2.dll", "c:\sys\bin\file2.dll", "testmodule"), |
|
457 ("" + os.sep + "tsrc" + os.sep + "data" + os.sep + "file1", "e:\sys\bin\file1", "data"), |
|
458 ("" + os.sep + "tsrc" + os.sep + "data" + os.sep + "file2", "e:\sys\bin\file2", "data"), |
|
459 ("" + os.sep + "tsrc" + os.sep + "data" + os.sep + "file3", "e:\sys\bin\file3", "data"), |
|
460 ("" + os.sep + "tsrc" + os.sep + "conf" + os.sep + "file1.cfg", "c:\sys\bin\file1.cfg", "conf"), |
|
461 ("" + os.sep + "tsrc" + os.sep + "conf" + os.sep + "file2.cfg", "c:\sys\bin\file2.cfg", "conf"), |
|
462 ("" + os.sep + "tsrc" + os.sep + "init" + os.sep + "TestFramework.ini", "c:\sys\bin\TestFramework.ini", "engine_ini"), |
|
463 ("" + os.sep + "tsrc" + os.sep + "sis" + os.sep + "file1.sisx", "c:\sys\bin\file1.sisx", ""), |
|
464 ("" + os.sep + "tsrc" + os.sep + "sis" + os.sep + "file2.sisx", "c:\sys\bin\file2.sisx", ""),] |
|
465 self.component_path = str(TEST_PATH.joinpath("tsrc", "group")) |
|
466 |
|
467 def test_creation(self): |
|
468 """ Testing creation. """ |
|
469 assert self.atp["testrun_name"] == "testrun" |
|
470 assert self.atp["harness"] == "STIF" |
|
471 assert self.atp["device_type"] == "product" |
|
472 |
|
473 def test_insert_set(self): |
|
474 """ Inserting a set of file. """ |
|
475 self.atp.insert_set(data_files=self.data_files, |
|
476 config_files=self.config_files, |
|
477 engine_ini_file=self.engine_ini_file, |
|
478 image_files=self.image_files, |
|
479 testmodule_files=self.testmodule_files, |
|
480 test_timeout=self.test_timeout, |
|
481 eunitexerunner_flags=self.eunitexerunner_flags, |
|
482 pmd_files=self.pmd_files, |
|
483 trace_activation_files=self.trace_activation_files, |
|
484 component_path=self.component_path) |
|
485 self.atp.insert_set(image_files=self.image_files, |
|
486 engine_ini_file=self.engine_ini_file, |
|
487 sis_files=self.sis_files, |
|
488 test_timeout=self.test_timeout, |
|
489 eunitexerunner_flags=self.eunitexerunner_flags, |
|
490 pmd_files=self.pmd_files, |
|
491 trace_activation_files=self.trace_activation_files, |
|
492 component_path=self.component_path) |
|
493 self.atp.insert_set(data_files=self.data_files, |
|
494 config_files=self.config_files, |
|
495 engine_ini_file=self.engine_ini_file, |
|
496 image_files=self.image_files, |
|
497 testmodule_files=self.testmodule_files, |
|
498 test_timeout=self.test_timeout, |
|
499 eunitexerunner_flags=self.eunitexerunner_flags, |
|
500 src_dst=self.src_dst, |
|
501 pmd_files=self.pmd_files, |
|
502 trace_activation_files=self.trace_activation_files, |
|
503 component_path=self.component_path) |
|
504 self.atp.insert_set(engine_ini_file=self.engine_ini_file, |
|
505 test_timeout=self.test_timeout, |
|
506 eunitexerunner_flags=self.eunitexerunner_flags, |
|
507 image_files=self.image_files, |
|
508 test_harness=self.test_harness, |
|
509 src_dst=self.src_dst, |
|
510 pmd_files=self.pmd_files, |
|
511 trace_activation_files=self.trace_activation_files, |
|
512 component_path=self.component_path) |
|
513 self.atp.insert_set(test_timeout=self.test_timeout, |
|
514 eunitexerunner_flags=self.eunitexerunner_flags, |
|
515 image_files=self.image_files, |
|
516 test_harness=self.test_harness, |
|
517 src_dst=self.src_dst, |
|
518 pmd_files=self.pmd_files, |
|
519 trace_activation_files=self.trace_activation_files, |
|
520 component_path=self.component_path) |
|
521 |
|
522 assert self.atp.sets[0] == dict(name="set0", |
|
523 data_files=self.data_files, |
|
524 config_files=self.config_files, |
|
525 engine_ini_file=self.engine_ini_file, |
|
526 image_files=self.image_files, |
|
527 testmodule_files=self.testmodule_files, |
|
528 test_timeout=self.test_timeout, |
|
529 eunitexerunner_flags=self.eunitexerunner_flags, |
|
530 test_harness=self.test_harness, |
|
531 src_dst=[], |
|
532 pmd_files=self.pmd_files, |
|
533 trace_path=self.atp.file_store.joinpath(u"§RUN_NAME§" + os.sep + u"§RUN_START_DATE§_§RUN_START_TIME§", "traces", "set0", "tracelog.blx"), |
|
534 trace_activation_files=self.trace_activation_files, |
|
535 ctc_enabled=self.atp["ctc_enabled"], |
|
536 custom_dir=None, |
|
537 component_path=self.component_path) |
|
538 assert self.atp.sets[1] == dict(name="set1", |
|
539 image_files=self.image_files, |
|
540 engine_ini_file=self.engine_ini_file, |
|
541 sis_files=self.sis_files, |
|
542 test_timeout=self.test_timeout, |
|
543 eunitexerunner_flags=self.eunitexerunner_flags, |
|
544 test_harness=self.test_harness, |
|
545 pmd_files=self.pmd_files, |
|
546 trace_path=self.atp.file_store.joinpath(u"§RUN_NAME§" + os.sep + u"§RUN_START_DATE§_§RUN_START_TIME§", "traces", "set1", "tracelog.blx"), |
|
547 trace_activation_files=self.trace_activation_files, |
|
548 ctc_enabled=self.atp["ctc_enabled"], |
|
549 custom_dir=None, |
|
550 component_path=self.component_path) |
|
551 |
|
552 assert self.atp.sets[2] == dict(name="set2", |
|
553 data_files=self.data_files, |
|
554 config_files=self.config_files, |
|
555 engine_ini_file=self.engine_ini_file, |
|
556 image_files=self.image_files, |
|
557 testmodule_files=self.testmodule_files, |
|
558 test_timeout=self.test_timeout, |
|
559 eunitexerunner_flags=self.eunitexerunner_flags, |
|
560 test_harness=self.test_harness, |
|
561 src_dst=self.src_dst, |
|
562 pmd_files=self.pmd_files, |
|
563 trace_path=self.atp.file_store.joinpath(u"§RUN_NAME§" + os.sep + u"§RUN_START_DATE§_§RUN_START_TIME§", "traces", "set2", "tracelog.blx"), |
|
564 trace_activation_files=self.trace_activation_files, |
|
565 ctc_enabled=self.atp["ctc_enabled"], |
|
566 custom_dir=None, |
|
567 component_path=self.component_path) |
|
568 assert self.atp.sets[3] == dict(name="set3", |
|
569 data_files=[], |
|
570 config_files=[], |
|
571 engine_ini_file=self.engine_ini_file, |
|
572 image_files=self.image_files, |
|
573 testmodule_files=[], |
|
574 test_timeout=self.test_timeout, |
|
575 eunitexerunner_flags=self.eunitexerunner_flags, |
|
576 test_harness=self.test_harness, |
|
577 src_dst=self.src_dst, |
|
578 pmd_files=self.pmd_files, |
|
579 trace_path=self.atp.file_store.joinpath(u"§RUN_NAME§" + os.sep + u"§RUN_START_DATE§_§RUN_START_TIME§", "traces", "set3", "tracelog.blx"), |
|
580 trace_activation_files=self.trace_activation_files, |
|
581 ctc_enabled=self.atp["ctc_enabled"], |
|
582 custom_dir=None, |
|
583 component_path=self.component_path) |
|
584 |
|
585 assert self.atp.sets[4] == dict(name="set4", |
|
586 data_files=[], |
|
587 config_files=[], |
|
588 engine_ini_file=None, |
|
589 image_files=self.image_files, |
|
590 testmodule_files=[], |
|
591 test_timeout=self.test_timeout, |
|
592 eunitexerunner_flags=self.eunitexerunner_flags, |
|
593 test_harness=self.test_harness, |
|
594 src_dst=self.src_dst, |
|
595 pmd_files=self.pmd_files, |
|
596 trace_path=self.atp.file_store.joinpath(u"§RUN_NAME§" + os.sep + u"§RUN_START_DATE§_§RUN_START_TIME§", "traces", "set4", "tracelog.blx"), |
|
597 trace_activation_files=self.trace_activation_files, |
|
598 ctc_enabled=self.atp["ctc_enabled"], |
|
599 custom_dir=None, |
|
600 component_path=self.component_path) |
|
601 |
|
602 def test_post_actions_email(self): |
|
603 """ Testing the send email post-action. """ |
|
604 assert not self.atp.post_actions |
|
605 receiver = "joe.average@example.com" |
|
606 self.atp.report_email = receiver |
|
607 assert len(self.atp.post_actions) == 1 |
|
608 _, items = self.atp.post_actions[0] |
|
609 items = dict(items) |
|
610 #assert action == "EmailAction" |
|
611 assert items["to"] == receiver |
|
612 |
|
613 def test_post_actions_ats4_report_only(self): |
|
614 """ Testing the ats4 report only post-action. """ |
|
615 file_store = path("path/to/files") |
|
616 self.atp.file_store = file_store |
|
617 self.atp.harness = "EUNIT" |
|
618 assert len(self.atp.post_actions) == 2 |
|
619 action, items = self.atp.post_actions[0] |
|
620 items = dict(items) |
|
621 assert action == "FileStoreAction" |
|
622 assert items["report-type"] == "ATS3_REPORT" |
|
623 assert items["to-folder"].startswith(file_store) |
|
624 assert items["to-folder"].endswith("ATS3_REPORT") |
|
625 |
|
626 def test_post_actions_stif(self): |
|
627 """ Testing STIF post-actions. """ |
|
628 file_store = path("path/to/files") |
|
629 self.atp.file_store = file_store |
|
630 assert len(self.atp.post_actions) == 2 |
|
631 action, items = self.atp.post_actions[1] |
|
632 items = dict(items) |
|
633 assert action == "FileStoreAction" |
|
634 assert items["report-type"] == "STIF_COMPONENT_REPORT_ALL_CASES" |
|
635 assert items["to-folder"].startswith(file_store) |
|
636 assert items["to-folder"].endswith("STIF_REPORT") |
|
637 |
|
638 def test_post_actions_diamonds(self): |
|
639 """ Testing Diamonds post-actions. """ |
|
640 self.atp.diamonds_build_url = "http://diamonds.nmp.company.com/diamonds/builds/1234" |
|
641 assert len(self.atp.post_actions) == 1 |
|
642 action, items = self.atp.post_actions[0] |
|
643 assert action == "DiamondsAction" |
|
644 assert not items |
|
645 |
|
646 |
|
647 class TestComponentParser(mocker.MockerTestCase): |
|
648 """ Testing the Ats3ComponentParser component parser. """ |
|
649 |
|
650 def __init__(self, methodName="runTest"): |
|
651 mocker.MockerTestCase.__init__(self, methodName) |
|
652 |
|
653 def assert_paths(self, path1, path2): |
|
654 """ Checking the path. Validates that path1 and path2 are instance of path and they are equals. """ |
|
655 if not isinstance(path1, path): |
|
656 path1 = path(path1) |
|
657 if not isinstance(path2, path): |
|
658 path2 = path(path2) |
|
659 return self.assertEqual(path1.normpath(), path2.normpath()) |
|
660 |
|
661 def setUp(self): |
|
662 """ Setting up TestComponentParser testsuite.""" |
|
663 opts = Bunch(build_drive=path(TEST_PATH+os.sep), target_platform="target platform", eunitexerunner_flags="/E S60AppEnv /R Off", |
|
664 data_dir=["data"], flash_images=[], sis_files=[], test_timeout="60", harness="STIF", trace_enabled="True", specific_pkg='', hti="True") |
|
665 self.acp = atc.Ats3ComponentParser(opts) |
|
666 self.acp.tsrc_dir = TSRC |
|
667 |
|
668 def test_detect_dlls(self): |
|
669 """ Testing dlls detection. """ |
|
670 open(os.path.join(TEST_PATH, 'lib1.dll'), 'w').close() |
|
671 os.makedirs(os.path.join(TEST_PATH, 'path', 'to', 'another')) |
|
672 open(os.path.join(TEST_PATH, 'path', 'to', 'another', 'library.dll'), 'w').close() |
|
673 open(os.path.join(TEST_PATH, 'lib2.dll'), 'w').close() |
|
674 |
|
675 # Setup mock objects. |
|
676 process = self.mocker.mock() |
|
677 process.communicate() |
|
678 self.mocker.result(["lib1.dll\npath/to/another/library.dll\nsome/other/file.txt\nlib2.dll\nlib3.dll\n"]) |
|
679 obj = self.mocker.replace("subprocess.Popen") |
|
680 |
|
681 if os.sep == '\\': |
|
682 raptor_cmd = fileutils.which("sbs.bat") |
|
683 else: |
|
684 raptor_cmd = fileutils.which("sbs") |
|
685 if raptor_cmd: |
|
686 obj("sbs --what -c target_platform.test", shell=True, stdout=subprocess.PIPE) |
|
687 else: |
|
688 obj("abld -w test build target platform", shell=True, stdout=subprocess.PIPE) |
|
689 self.mocker.result(process) |
|
690 |
|
691 self.mocker.replay() |
|
692 |
|
693 self.assertEqual([u"lib1.dll", u"library.dll", u"lib2.dll"], |
|
694 [dll.name for dll in self.acp.tsrc_dll_files()]) |
|
695 |
|
696 def test_harness(self): |
|
697 """ Detect test harness.""" |
|
698 mmp_parser = parser.MmpFileParser() |
|
699 group = TSRC.joinpath("group") |
|
700 for harness, mmp in [ |
|
701 ("STIF", group / "stif.mmp"), |
|
702 ("EUNIT", group / "eunit.mmp"), |
|
703 ("STIF", group / "both.mmp"), |
|
704 ]: |
|
705 self.assertEqual(harness, mmp_parser.get_harness(mmp)) |
|
706 |
|
707 class TestXMLGeneration(mocker.MockerTestCase): |
|
708 """Unit tests for the test.xml generation.""" |
|
709 def __init__(self, methodName="runTest"): |
|
710 mocker.MockerTestCase.__init__(self, methodName) |
|
711 self.data_files = None |
|
712 self.config_files = None |
|
713 self.testmodule_files = None |
|
714 self.image_files = None |
|
715 self.engine_ini_file = None |
|
716 self.report_email = None |
|
717 self.file_store = None |
|
718 self.diamonds_build_url = None |
|
719 self.test_harness = None |
|
720 self.src_dst = [] |
|
721 self.trace_enabled = None |
|
722 self.pmd_files = None |
|
723 self.trace_activation_files = None |
|
724 self.ctc_enabled = None |
|
725 self.eunitexerunner_flags = None |
|
726 self.test_plan = None |
|
727 self.gen = None |
|
728 self.custom_dir = None |
|
729 self.diamonds_id = None |
|
730 self.ctc_run_process_params = None |
|
731 self.drop_count = None |
|
732 self.ctc_test_data = None |
|
733 self.ctc_network = None |
|
734 self.component_path = None |
|
735 self.drop_id = None |
|
736 |
|
737 def generate_xml(self, trace_enabled="False"): |
|
738 """ Generating the XML. """ |
|
739 def files(*paths): |
|
740 """creating tsrc path list""" |
|
741 return [TEST_PATH.joinpath("tsrc", tpath) for tpath in paths] |
|
742 self.testmodule_files = files("testmodules/file1.dll", "testmodules/file2.dll") |
|
743 self.data_files = files("data/file1", "data/file2", "data/file3") |
|
744 self.config_files = files("conf/file1.cfg", "conf/file2.cfg") |
|
745 self.image_files = files("output/images/file1.fpsx", "output/images/file2.fpsx") |
|
746 self.engine_ini_file = files("init/TestFramework.ini")[0] |
|
747 self.report_email = "test.receiver@company.com" |
|
748 self.file_store = path(r"path/to/reports") |
|
749 self.diamonds_build_url = "http://diamonds.nmp.company.com/diamonds/builds/1234" |
|
750 self.test_harness = "STIF" |
|
751 self.src_dst = [] |
|
752 self.trace_enabled = trace_enabled |
|
753 self.pmd_files = TEST_FILES["pmd_file"] |
|
754 self.trace_activation_files = files("trace_init/trace_activation_1.xml") |
|
755 self.ctc_enabled = "True" |
|
756 self.eunitexerunner_flags = "/E S60AppEnv /R Off" |
|
757 self.custom_dir = "CustomB" |
|
758 self.component_path = str(TEST_PATH.joinpath("tsrc", "group")) |
|
759 self.ctc_run_process_params = r"10.0.0.1#x:\ats\drop0.zip#1" |
|
760 |
|
761 self.ctc_network = self.ctc_run_process_params.rsplit("#", 2)[0] |
|
762 self.drop_id = re.findall(".*drop(\d*).zip.*", self.ctc_run_process_params.lower())[0] #extracting int part of drop name |
|
763 self.drop_count = self.ctc_run_process_params.rsplit("#", 1)[1] |
|
764 self.diamonds_id = self.diamonds_build_url.rsplit(r"/", 1)[1] |
|
765 |
|
766 self.mocker.restore() |
|
767 test_plan = self.mocker.mock(count=False) |
|
768 mocker.expect(test_plan["testrun_name"]).result("test") |
|
769 mocker.expect(test_plan["harness"]).result("STIF") |
|
770 mocker.expect(test_plan["device_type"]).result("product") |
|
771 mocker.expect(test_plan["hti"]).result("True") |
|
772 mocker.expect(test_plan["plan_name"]).result("test plan") |
|
773 mocker.expect(test_plan["diamonds_build_url"]).result(self.diamonds_build_url) |
|
774 mocker.expect(test_plan["test_timeout"]).result("60") |
|
775 mocker.expect(test_plan["eunitexerunner_flags"]).result("/E S60AppEnv /R Off") |
|
776 mocker.expect(test_plan["device_hwid"]).result("5425") |
|
777 mocker.expect(test_plan["custom_dir"]).result("custom") |
|
778 mocker.expect(test_plan.custom_dir).result(path(r"self.custom_dir")) |
|
779 mocker.expect(test_plan["report_email"]).result(self.report_email) |
|
780 mocker.expect(test_plan["ctc_run_process_params"]).result(self.ctc_run_process_params) |
|
781 |
|
782 if self.trace_enabled.lower() == "true": |
|
783 mocker.expect(test_plan["trace_enabled"]).result("True") |
|
784 else: |
|
785 mocker.expect(test_plan["trace_enabled"]).result("False") |
|
786 if self.trace_enabled == "False": |
|
787 mocker.expect(test_plan.sets).result([ |
|
788 dict(name="set0", image_files=self.image_files, data_files=self.data_files, |
|
789 config_files=self.config_files, testmodule_files=self.testmodule_files, |
|
790 engine_ini_file=self.engine_ini_file, test_harness="STIF", src_dst=self.src_dst, |
|
791 ctc_enabled=self.ctc_enabled, eunitexerunner_flags=self.eunitexerunner_flags, |
|
792 custom_dir=self.custom_dir, component_path=self.component_path, hti="True"), |
|
793 dict(name="set1", image_files=self.image_files, data_files=self.data_files, |
|
794 config_files=self.config_files, testmodule_files=self.testmodule_files, |
|
795 engine_ini_file=self.engine_ini_file,test_harness="STIF", src_dst=self.src_dst, |
|
796 ctc_enabled=self.ctc_enabled, eunitexerunner_flags=self.eunitexerunner_flags, |
|
797 custom_dir=self.custom_dir, component_path=self.component_path, hti="True"),]) |
|
798 elif self.trace_enabled == "True": |
|
799 mocker.expect(test_plan.sets).result([ |
|
800 dict(name="set0", image_files=self.image_files, data_files=self.data_files, |
|
801 config_files=self.config_files, testmodule_files=self.testmodule_files, |
|
802 engine_ini_file=self.engine_ini_file, test_harness="STIF", src_dst=self.src_dst, |
|
803 pmd_files=self.pmd_files, trace_activation_files=self.trace_activation_files, |
|
804 trace_path=self.file_store.joinpath("traces", "set0", "tracelog.blx"), |
|
805 ctc_enabled=self.ctc_enabled, eunitexerunner_flags=self.eunitexerunner_flags, component_path=self.component_path, custom_dir=None, hti="True"), |
|
806 dict(name="set1", image_files=self.image_files, data_files=self.data_files, |
|
807 config_files=self.config_files, testmodule_files=self.testmodule_files, |
|
808 engine_ini_file=self.engine_ini_file,test_harness="STIF", src_dst=self.src_dst, |
|
809 pmd_files=self.pmd_files, trace_activation_files=self.trace_activation_files, |
|
810 trace_path=self.file_store.joinpath("traces", "set1", "tracelog.blx"), |
|
811 ctc_enabled=self.ctc_enabled, eunitexerunner_flags=self.eunitexerunner_flags, component_path=self.component_path, custom_dir=None, hti="True"), |
|
812 ]) |
|
813 |
|
814 ctc_file_name = "catsctc2html/catsctc2html.exe" |
|
815 ctc_data_path = str(os.path.normpath(r"\\%s\ctc_helium\%s\drop0\set0\ctcdata" % (self.ctc_network, self.diamonds_id))) |
|
816 mon_files = str(os.path.normpath(r"\\%s\ctc_helium\%s\mon_syms\1\MON.sym" % (self.ctc_network, self.diamonds_id))) |
|
817 self.ctc_test_data = [ctc_file_name, self.ctc_network, self.drop_id, self.drop_count, self.diamonds_id, ctc_data_path, mon_files] |
|
818 |
|
819 mocker.expect(test_plan.post_actions).result([ |
|
820 ("RunProcessAction", (("file", ctc_file_name ), |
|
821 ("parameters", r"--ctcdata_files=" + ctc_data_path + " --monsym_files=" + mon_files + " --diamonds_build_id=" + self.diamonds_id + " --drop_id=" + self.drop_id + " --total_amount_of_drops=" + self.drop_count ))), |
|
822 ("EmailAction", (("subject", "Release testing"), |
|
823 ("to", self.report_email))), |
|
824 # ("FileStoreAction", (("to-folder", self.file_store), |
|
825 # ("report-type", "ATS_REPORT"), |
|
826 # ("date-format", "yyyyMMdd"), |
|
827 # ("time-format", "HHmmss"))), |
|
828 # ("FileStoreAction", (("to-folder", self.file_store), |
|
829 # ("report-type", "STIF_COMPONENT_REPORT_ALL_CASES"), |
|
830 # ("run-log", "true"), |
|
831 # ("date-format", "yyyyMMdd"), |
|
832 # ("time-format", "HHmmss"))), |
|
833 ("DiamondsAction", ())]) |
|
834 self.mocker.replay() |
|
835 self.test_plan = test_plan |
|
836 self.gen = adg.Ats3TemplateTestDropGenerator() |
|
837 return self.gen.generate_xml(test_plan) |
|
838 |
|
839 def test_basic_structure(self): |
|
840 """ Check that the overall test.xml structure is valid. """ |
|
841 xml = self.generate_xml() |
|
842 # Check basics. |
|
843 # assert xml.find(".").tag == "test" |
|
844 # assert xml.find("./name").text == "test" |
|
845 # assert xml.find("./buildid").text == self.diamonds_build_url |
|
846 # assert xml.find("./target").tag |
|
847 # assert xml.find("./target/device").tag |
|
848 # harness, type_, device_hwid = xml.findall("./target/device/property") |
|
849 # assert harness.get("value") == "STIF" |
|
850 # assert type_.get("value") == "product" |
|
851 # assert device_hwid.get("value") == "5425" |
|
852 # |
|
853 # # Check generation of the test plan. |
|
854 # assert xml.find("./plan").get("name") == "test Plan" |
|
855 # assert xml.find("./plan/session").tag |
|
856 # sets = xml.findall("./execution") |
|
857 # assert len(sets) == 2 |
|
858 # assert sets[0].get("name") == "set0-"+str(TEST_PATH.joinpath("tsrc", "group")) |
|
859 # assert sets[0].find("./target/device").tag |
|
860 |
|
861 def test_set_structure(self): |
|
862 """ Check that a <set> element's structure is valid. """ |
|
863 xml = self.generate_xml() |
|
864 tstset = xml.find("./execution") |
|
865 assert tstset.tag |
|
866 |
|
867 def test_case_flash_elems(self): |
|
868 """ Test case flash elems. """ |
|
869 xml = self.generate_xml() |
|
870 found = False |
|
871 for case in xml.findall(".//task"): |
|
872 if case.find('type').text == 'FlashTask': |
|
873 found = True |
|
874 flashes = case.findall("./parameters/parameter") |
|
875 assert len(flashes) == len(self.image_files) |
|
876 for i, flash_file in enumerate(self.image_files): |
|
877 assert flashes[i].get("name") == "image-" + str(i + 1) |
|
878 assert flashes[i].get("value") == "ATS3Drop\\images\\" + flash_file.name |
|
879 assert found |
|
880 |
|
881 def test_case_steps(self): |
|
882 """ Test case steps. """ |
|
883 xml = self.generate_xml() |
|
884 steps = iter(xml.findall(".//task")) |
|
885 steps.next() # Flash images |
|
886 check_ctc_start(steps) |
|
887 check_log_dir(steps) |
|
888 self.check_install_data(steps) |
|
889 self.check_install_configuration(steps) |
|
890 self.check_install_tmodules(steps) |
|
891 self.check_install_engine_ini(steps) |
|
892 self.check_run_cases(steps) |
|
893 check_ctc_write(steps) |
|
894 check_ctc_log(steps) |
|
895 check_fetch_logs(steps) |
|
896 |
|
897 def check_install_data(self, steps): |
|
898 """ Test install data. """ |
|
899 for filename in self.data_files: |
|
900 step = steps.next() |
|
901 assert step.findtext("./type") == "FileUploadTask" |
|
902 params = step.findall("./parameters/parameter") |
|
903 src = params[0].get("value") |
|
904 assert ntpath.basename(src) == ntpath.basename(filename) |
|
905 assert ntpath.dirname(src) == "ATS3Drop\\set0\\data" |
|
906 dst = params[1].get("value") |
|
907 assert ntpath.basename(dst) == ntpath.basename(filename) |
|
908 assert ntpath.dirname(dst) == r"e:\testing\data" |
|
909 |
|
910 def check_install_configuration(self, steps): |
|
911 """ Test install configuration. """ |
|
912 for filepath in self.config_files: |
|
913 step = steps.next() |
|
914 assert step.findtext("./type") == "FileUploadTask" |
|
915 params = step.findall("./parameters/parameter") |
|
916 assert params[0].get("value") == "ATS3Drop\\set0\\conf\\" + ntpath.basename(filepath) |
|
917 assert params[1].get("value") == "e:\\testing\\conf\\" + ntpath.basename(filepath) |
|
918 |
|
919 def check_install_tmodules(self, steps): |
|
920 """ Test install tmodules. """ |
|
921 for filepath in self.testmodule_files: |
|
922 step = steps.next() |
|
923 assert step.findtext("./type") == "FileUploadTask" |
|
924 params = step.findall("./parameters/parameter") |
|
925 assert params[0].get("value") == "ATS3Drop\\set0\\testmodules\\" + ntpath.basename(filepath) |
|
926 assert params[1].get("value") == "c:\\sys\\bin\\" + ntpath.basename(filepath) |
|
927 |
|
928 def check_install_engine_ini(self, steps): |
|
929 """ Test install engine ini. """ |
|
930 filepath = self.engine_ini_file |
|
931 step = steps.next() |
|
932 assert step.findtext("./type") == "FileUploadTask" |
|
933 params = step.findall("./parameters/parameter") |
|
934 assert params[0].get("value") == "ATS3Drop\\set0\\init\\" + ntpath.basename(filepath) |
|
935 assert params[1].get("value") == "c:\\testframework\\" + ntpath.basename(filepath) |
|
936 |
|
937 def check_run_cases(self, steps): |
|
938 """ Test run cases. """ |
|
939 step = steps.next() |
|
940 assert step.findtext("./type") == "StifRunCasesTask" |
|
941 params = step.findall("./parameters/parameter") |
|
942 assert params[0].get("value") == "*" |
|
943 assert params[1].get("value") == "60" |
|
944 assert params[2].get("value") == "c:\\testframework\\" + ntpath.basename(self.engine_ini_file) |
|
945 |
|
946 def test_steps_trace_enabled(self): |
|
947 """ Test steps trace enabled. """ |
|
948 xml = self.generate_xml(trace_enabled="True") |
|
949 steps = iter(xml.findall(".//task")) |
|
950 steps.next() # Flash images |
|
951 check_ctc_start(steps) |
|
952 check_log_dir(steps) |
|
953 self.check_install_data(steps) |
|
954 self.check_install_configuration(steps) |
|
955 self.check_install_tmodules(steps) |
|
956 self.check_install_engine_ini(steps) |
|
957 #check_trace_start(steps, self.file_store) |
|
958 self.check_run_cases(steps) |
|
959 #check_trace_end_steps(steps, self.file_store) |
|
960 check_ctc_write(steps) |
|
961 check_ctc_log(steps) |
|
962 check_fetch_logs(steps) |
|
963 |
|
964 def test_post_actions(self): |
|
965 """ Post actions are inserted into XML. """ |
|
966 xml = self.generate_xml() |
|
967 post_actions = xml.findall(".//action") |
|
968 check_ctc_run_process_action(post_actions[0]) |
|
969 check_send_email_action(post_actions[1], self.report_email) |
|
970 #check_ats_report_action(post_actions[2], self.file_store) |
|
971 #check_stif_report_action(post_actions[3], self.file_store) |
|
972 check_diamonds_action(post_actions[2]) |
|
973 |
|
974 # def test_files(self): |
|
975 # """ Testing files. """ |
|
976 # xml = self.generate_xml() |
|
977 # files = iter(xml.findall("./files/file")) |
|
978 # assert files.next().text == r"ATS3Drop/images/file1.fpsx" |
|
979 # assert files.next().text == r"ATS3Drop/images/file2.fpsx" |
|
980 # assert files.next().text == r"ATS3Drop/set0/data/file1" |
|
981 # assert files.next().text == r"ATS3Drop/set0/data/file2" |
|
982 # assert files.next().text == r"ATS3Drop/set0/data/file3" |
|
983 # assert files.next().text == r"ATS3Drop/set0/conf/file1.cfg" |
|
984 # assert files.next().text == r"ATS3Drop/set0/conf/file2.cfg" |
|
985 # assert files.next().text == r"ATS3Drop/set0/testmodules/file1.dll" |
|
986 # assert files.next().text == r"ATS3Drop/set0/testmodules/file2.dll" |
|
987 # assert files.next().text == r"ATS3Drop/set0/init/TestFramework.ini" |
|
988 # assert files.next().text == r"ATS3Drop/set1/data/file1" |
|
989 # assert files.next().text == r"ATS3Drop/set1/data/file2" |
|
990 # assert files.next().text == r"ATS3Drop/set1/data/file3" |
|
991 # assert files.next().text == r"ATS3Drop/set1/conf/file1.cfg" |
|
992 # assert files.next().text == r"ATS3Drop/set1/conf/file2.cfg" |
|
993 # assert files.next().text == r"ATS3Drop/set1/testmodules/file1.dll" |
|
994 # assert files.next().text == r"ATS3Drop/set1/testmodules/file2.dll" |
|
995 # assert files.next().text == r"ATS3Drop/set1/init/TestFramework.ini" |
|
996 # self.assertRaises(StopIteration, files.next) |
|
997 # xml = self.generate_xml(trace_enabled="True") |
|
998 # files = iter(xml.findall("./files/file")) |
|
999 # assert files.next().text == r"ATS3Drop/images/file1.fpsx" |
|
1000 # assert files.next().text == r"ATS3Drop/images/file2.fpsx" |
|
1001 # assert files.next().text == r"ATS3Drop/pmds/pmd_file.pmd" |
|
1002 # assert files.next().text == r"ATS3Drop/set0/data/file1" |
|
1003 # assert files.next().text == r"ATS3Drop/set0/data/file2" |
|
1004 # assert files.next().text == r"ATS3Drop/set0/data/file3" |
|
1005 # assert files.next().text == r"ATS3Drop/set0/conf/file1.cfg" |
|
1006 # assert files.next().text == r"ATS3Drop/set0/conf/file2.cfg" |
|
1007 # assert files.next().text == r"ATS3Drop/set0/testmodules/file1.dll" |
|
1008 # assert files.next().text == r"ATS3Drop/set0/testmodules/file2.dll" |
|
1009 # assert files.next().text == r"ATS3Drop/set0/init/TestFramework.ini" |
|
1010 # assert files.next().text == r"ATS3Drop/set0/trace_init/trace_activation_1.xml" |
|
1011 # assert files.next().text == r"ATS3Drop/set1/data/file1" |
|
1012 # assert files.next().text == r"ATS3Drop/set1/data/file2" |
|
1013 # assert files.next().text == r"ATS3Drop/set1/data/file3" |
|
1014 # assert files.next().text == r"ATS3Drop/set1/conf/file1.cfg" |
|
1015 # assert files.next().text == r"ATS3Drop/set1/conf/file2.cfg" |
|
1016 # assert files.next().text == r"ATS3Drop/set1/testmodules/file1.dll" |
|
1017 # assert files.next().text == r"ATS3Drop/set1/testmodules/file2.dll" |
|
1018 # assert files.next().text == r"ATS3Drop/set1/init/TestFramework.ini" |
|
1019 # assert files.next().text == r"ATS3Drop/set1/trace_init/trace_activation_1.xml" |
|
1020 # self.assertRaises(StopIteration, files.next) |
|
1021 |
|
1022 def test_generate_drop(self): |
|
1023 """ Manifest for ATS3Drop directory structure is generated. """ |
|
1024 xml = self.generate_xml() |
|
1025 strbuffer = StringIO() |
|
1026 |
|
1027 self.gen.generate_drop(self.test_plan, xml, strbuffer) |
|
1028 zfile = zipfile.ZipFile(strbuffer, "r") |
|
1029 try: |
|
1030 contents = sorted(path(tpath).normpath() for tpath in zfile.namelist()) |
|
1031 expected = sorted(path(tpath).normpath() |
|
1032 for tpath in [r"ATS3Drop" + os.sep + "set0" + os.sep + "conf" + os.sep + "file1.cfg", |
|
1033 r"ATS3Drop" + os.sep + "set0" + os.sep + "conf" + os.sep + "file2.cfg", |
|
1034 r"ATS3Drop" + os.sep + "set0" + os.sep + "data" + os.sep + "file1", |
|
1035 r"ATS3Drop" + os.sep + "set0" + os.sep + "data" + os.sep + "file2", |
|
1036 r"ATS3Drop" + os.sep + "set0" + os.sep + "data" + os.sep + "file3", |
|
1037 r"ATS3Drop" + os.sep + "images" + os.sep + "file1.fpsx", |
|
1038 r"ATS3Drop" + os.sep + "images" + os.sep + "file2.fpsx", |
|
1039 r"ATS3Drop" + os.sep + "set0" + os.sep + "init" + os.sep + "TestFramework.ini", |
|
1040 r"ATS3Drop" + os.sep + "set0" + os.sep + "testmodules" + os.sep + "file1.dll", |
|
1041 r"ATS3Drop" + os.sep + "set0" + os.sep + "testmodules" + os.sep + "file2.dll", |
|
1042 r"ATS3Drop" + os.sep + "set1" + os.sep + "conf" + os.sep + "file1.cfg", |
|
1043 r"ATS3Drop" + os.sep + "set1" + os.sep + "conf" + os.sep + "file2.cfg", |
|
1044 r"ATS3Drop" + os.sep + "set1" + os.sep + "data" + os.sep + "file1", |
|
1045 r"ATS3Drop" + os.sep + "set1" + os.sep + "data" + os.sep + "file2", |
|
1046 r"ATS3Drop" + os.sep + "set1" + os.sep + "data" + os.sep + "file3", |
|
1047 r"ATS3Drop" + os.sep + "set1" + os.sep + "init" + os.sep + "TestFramework.ini", |
|
1048 r"ATS3Drop" + os.sep + "set1" + os.sep + "testmodules" + os.sep + "file1.dll", |
|
1049 r"ATS3Drop" + os.sep + "set1" + os.sep + "testmodules" + os.sep + "file2.dll", |
|
1050 r"test.xml"]) |
|
1051 diff = difflib.context_diff(expected, contents) |
|
1052 assert contents == expected, "\n".join(diff) |
|
1053 finally: |
|
1054 zfile.close() |
|
1055 |
|
1056 def test_generate_drop_trace (self): |
|
1057 "Manifest for ATS3Drop directory structure is generated when trace enabled." |
|
1058 xml = self.generate_xml(trace_enabled="True") |
|
1059 strbuffer = StringIO() |
|
1060 |
|
1061 self.gen.generate_drop(self.test_plan, xml, strbuffer) |
|
1062 zfile = zipfile.ZipFile(strbuffer, "r") |
|
1063 try: |
|
1064 contents = sorted(path(tpath).normpath() for tpath in zfile.namelist()) |
|
1065 expected = sorted(path(tpath).normpath() |
|
1066 for tpath in [r"ATS3Drop" + os.sep + "set0" + os.sep + "conf" + os.sep + "file1.cfg", |
|
1067 r"ATS3Drop" + os.sep + "set0" + os.sep + "conf" + os.sep + "file2.cfg", |
|
1068 r"ATS3Drop" + os.sep + "set0" + os.sep + "data" + os.sep + "file1", |
|
1069 r"ATS3Drop" + os.sep + "set0" + os.sep + "data" + os.sep + "file2", |
|
1070 r"ATS3Drop" + os.sep + "set0" + os.sep + "data" + os.sep + "file3", |
|
1071 r"ATS3Drop" + os.sep + "set0" + os.sep + "trace_init" + os.sep + "trace_activation_1.xml", |
|
1072 r"ATS3Drop" + os.sep + "images" + os.sep + "file1.fpsx", |
|
1073 r"ATS3Drop" + os.sep + "images" + os.sep + "file2.fpsx", |
|
1074 r"ATS3Drop" + os.sep + "set0" + os.sep + "init" + os.sep + "TestFramework.ini", |
|
1075 r"ATS3Drop" + os.sep + "pmds" + os.sep + "pmd_file.pmd", |
|
1076 r"ATS3Drop" + os.sep + "set0" + os.sep + "testmodules" + os.sep + "file1.dll", |
|
1077 r"ATS3Drop" + os.sep + "set0" + os.sep + "testmodules" + os.sep + "file2.dll", |
|
1078 r"ATS3Drop" + os.sep + "set1" + os.sep + "conf" + os.sep + "file1.cfg", |
|
1079 r"ATS3Drop" + os.sep + "set1" + os.sep + "conf" + os.sep + "file2.cfg", |
|
1080 r"ATS3Drop" + os.sep + "set1" + os.sep + "data" + os.sep + "file1", |
|
1081 r"ATS3Drop" + os.sep + "set1" + os.sep + "data" + os.sep + "file2", |
|
1082 r"ATS3Drop" + os.sep + "set1" + os.sep + "data" + os.sep + "file3", |
|
1083 r"ATS3Drop" + os.sep + "set1" + os.sep + "trace_init" + os.sep + "trace_activation_1.xml", |
|
1084 r"ATS3Drop" + os.sep + "set1" + os.sep + "init" + os.sep + "TestFramework.ini", |
|
1085 r"ATS3Drop" + os.sep + "set1" + os.sep + "testmodules" + os.sep + "file1.dll", |
|
1086 r"ATS3Drop" + os.sep + "set1" + os.sep + "testmodules" + os.sep + "file2.dll", |
|
1087 r"test.xml"]) |
|
1088 diff = difflib.context_diff(expected, contents) |
|
1089 assert contents == expected, "\n".join(diff) |
|
1090 finally: |
|
1091 zfile.close() |
|
1092 |
|
1093 |
|
1094 class TestXMLGenerationWithPKG(mocker.MockerTestCase): |
|
1095 """ |
|
1096 Unit tests for the test.xml generation. |
|
1097 """ |
|
1098 def __init__(self, methodName="runTest"): |
|
1099 mocker.MockerTestCase.__init__(self, methodName) |
|
1100 self.src_dst1 = [] |
|
1101 self.data_files = None |
|
1102 self.config_files = None |
|
1103 self.testmodule_files = None |
|
1104 self.image_files = None |
|
1105 self.engine_ini_file = None |
|
1106 self.report_email = None |
|
1107 self.file_store = None |
|
1108 self.diamonds_build_url = None |
|
1109 self.trace_enabled = None |
|
1110 self.pmd_files = None |
|
1111 self.trace_activation_files = None |
|
1112 self.ctc_enabled = None |
|
1113 self.eunitexerunner_flags = None |
|
1114 self.test_plan = None |
|
1115 self.gen = None |
|
1116 self.src_dst0 = [] |
|
1117 self.custom_dir = None |
|
1118 self.custom_files = None |
|
1119 self.component_path = None |
|
1120 self.ctc_run_process_params = None |
|
1121 |
|
1122 def generate_xml(self, harness, trace_enabled="False"): |
|
1123 """Generates XML""" |
|
1124 def files(*paths): |
|
1125 """generates paths for the files""" |
|
1126 return [TEST_PATH.joinpath("tsrc", tpath) for tpath in paths] |
|
1127 |
|
1128 self.src_dst1 = [] |
|
1129 self.data_files = files("data/file1", "data/file2", "data/file3") |
|
1130 self.config_files = files("conf/file1.cfg", "conf/file2.cfg") |
|
1131 self.testmodule_files = files("testmodules/file1.dll", "testmodules/file2.dll") |
|
1132 self.image_files = files("output/images/file1.fpsx", "output/images/file2.fpsx") |
|
1133 self.engine_ini_file = files("init/TestFramework.ini")[0] |
|
1134 self.report_email = "test.receiver@company.com" |
|
1135 self.file_store = path("path/to/reports") |
|
1136 self.diamonds_build_url = "http://diamonds.nmp.company.com/diamonds/builds/1234" |
|
1137 self.trace_enabled = trace_enabled |
|
1138 self.pmd_files = TEST_FILES["pmd_file"] |
|
1139 self.trace_activation_files = files("trace_init/trace_activation_1.xml") |
|
1140 self.ctc_enabled = "True" |
|
1141 self.eunitexerunner_flags = "/E S60AppEnv /R Off" |
|
1142 self.custom_dir = "custom" |
|
1143 self.custom_files = files("custom/postpostaction.xml", "custom/prepostaction.xml") |
|
1144 self.component_path = str(TEST_PATH.joinpath("tsrc", "group")) |
|
1145 self.ctc_run_process_params = r"10.0.0.1#x:\ats\drop0.zip#1" |
|
1146 self.src_dst0 = [ |
|
1147 (TEST_PATH.joinpath(r"tsrc" + os.sep + "testmodules" + os.sep + "file1.dll"), path(r"c:\sys\bin\file1.dll"), "testmodule"), |
|
1148 (TEST_PATH.joinpath(r"tsrc" + os.sep + "testmodules" + os.sep + "file2.dll"), path(r"c:\sys\bin\file2.dll"), "testmodule"), |
|
1149 (TEST_PATH.joinpath(r"tsrc" + os.sep + "data" + os.sep + "file1"), path(r"e:\sys\bin\file1"), "data"), |
|
1150 (TEST_PATH.joinpath(r"tsrc" + os.sep + "data" + os.sep + "file2"), path(r"e:\sys\bin\file2"), "data"), |
|
1151 (TEST_PATH.joinpath(r"tsrc" + os.sep + "data" + os.sep + "file3"), path(r"e:\sys\bin\file3"), "data"),] |
|
1152 if harness == "STIF" or harness == "MULTI_HARNESS": |
|
1153 harness0 = harness1 = "STIF" |
|
1154 if "MULTI_HARNESS" in harness: |
|
1155 harness1 = "EUNIT" |
|
1156 self.src_dst1 = [ |
|
1157 (TEST_PATH.joinpath(r"tsrc" + os.sep + "testmodules" + os.sep + "file1.dll"), path(r"c:\sys\bin\file1.dll"), "testmodule"), |
|
1158 (TEST_PATH.joinpath(r"tsrc" + os.sep + "testmodules" + os.sep + "file2.dll"), path(r"c:\sys\bin\file2.dll"), "testmodule"), |
|
1159 (TEST_PATH.joinpath(r"tsrc" + os.sep + "data" + os.sep + "file1"), path(r"e:\sys\bin\file1"), "data"), |
|
1160 (TEST_PATH.joinpath(r"tsrc" + os.sep + "data" + os.sep + "file2"), path(r"e:\sys\bin\file2"), "data"), |
|
1161 (TEST_PATH.joinpath(r"tsrc" + os.sep + "data" + os.sep + "file3"), path(r"e:\sys\bin\file3"), "data"),] |
|
1162 self.src_dst0 = [ |
|
1163 (TEST_PATH.joinpath(r"tsrc" + os.sep + "testmodules" + os.sep + "file1.dll"), path(r"c:\sys\bin\file1.dll"), "testmodule"), |
|
1164 (TEST_PATH.joinpath(r"tsrc" + os.sep + "testmodules" + os.sep + "file2.dll"), path(r"c:\sys\bin\file2.dll"), "testmodule"), |
|
1165 (TEST_PATH.joinpath(r"tsrc" + os.sep + "data" + os.sep + "file1"), path(r"e:\sys\bin\file1"), "data"), |
|
1166 (TEST_PATH.joinpath(r"tsrc" + os.sep + "data" + os.sep + "file2"), path(r"e:\sys\bin\file2"), "data"), |
|
1167 (TEST_PATH.joinpath(r"tsrc" + os.sep + "data" + os.sep + "file3"), path(r"e:\sys\bin\file3"), "data"), |
|
1168 (TEST_PATH.joinpath(r"tsrc" + os.sep + "conf" + os.sep + "file1.cfg"), path(r"c:\sys\bin\file1.cfg"), "conf"), |
|
1169 (TEST_PATH.joinpath(r"tsrc" + os.sep + "conf" + os.sep + "file2.cfg"), path(r"c:\sys\bin\file2.cfg"), "conf"), |
|
1170 (TEST_PATH.joinpath(r"tsrc" + os.sep + "init" + os.sep + "TestFramework.ini"), path(r"c:\sys\bin\TestFramework.ini"), "engine_ini"),] |
|
1171 if "STIF" in harness: |
|
1172 self.src_dst1 = self.src_dst0 |
|
1173 |
|
1174 elif harness == "EUNIT": |
|
1175 harness0 = harness1 = harness |
|
1176 self.src_dst1 = self.src_dst0 |
|
1177 |
|
1178 self.mocker.restore() |
|
1179 test_plan = self.mocker.mock(count=False) |
|
1180 mocker.expect(test_plan["testrun_name"]).result("test") |
|
1181 mocker.expect(test_plan["harness"]).result(harness) |
|
1182 mocker.expect(test_plan["device_type"]).result("product") |
|
1183 mocker.expect(test_plan["hti"]).result("True") |
|
1184 mocker.expect(test_plan["plan_name"]).result("test plan") |
|
1185 mocker.expect(test_plan["diamonds_build_url"]).result(self.diamonds_build_url) |
|
1186 mocker.expect(test_plan["test_timeout"]).result("60") |
|
1187 mocker.expect(test_plan["eunitexerunner_flags"]).result("/E S60AppEnv /R Off") |
|
1188 mocker.expect(test_plan["eunitexerunner?flags"]).result(self.eunitexerunner_flags) |
|
1189 mocker.expect(test_plan["device_hwid"]).result("5425") |
|
1190 mocker.expect(test_plan["trace_enabled"]).result(self.trace_enabled) |
|
1191 mocker.expect(test_plan["ctc_enabled"]).result(self.ctc_enabled) |
|
1192 mocker.expect(test_plan["custom_dir"]).result("custom1A") |
|
1193 mocker.expect(test_plan.custom_dir).result(path(r"self.custom_dir")) |
|
1194 mocker.expect(test_plan["ctc_run_process_params"]).result(self.ctc_run_process_params) |
|
1195 mocker.expect(test_plan["report_email"]).result(self.report_email) |
|
1196 if self.trace_enabled == "False": |
|
1197 mocker.expect(test_plan.sets).result([ |
|
1198 dict(name="set0", image_files=self.image_files, data_files=self.data_files, |
|
1199 config_files=self.config_files, testmodule_files=self.testmodule_files, |
|
1200 engine_ini_file=self.engine_ini_file, test_harness=harness0,src_dst=self.src_dst0, |
|
1201 ctc_enabled=self.ctc_enabled, eunitexerunner_flags=self.eunitexerunner_flags, |
|
1202 custom_dir = self.custom_dir, component_path=self.component_path, hti="True"), |
|
1203 dict(name="set1", image_files=self.image_files, data_files=self.data_files, |
|
1204 config_files=self.config_files, testmodule_files=self.testmodule_files, |
|
1205 engine_ini_file=self.engine_ini_file, test_harness=harness1, src_dst=self.src_dst1, |
|
1206 ctc_enabled=self.ctc_enabled, eunitexerunner_flags=self.eunitexerunner_flags, |
|
1207 custom_dir = self.custom_dir, component_path=self.component_path, hti="True"), |
|
1208 ]) |
|
1209 else: |
|
1210 mocker.expect(test_plan.sets).result([ |
|
1211 dict(name="set0", image_files=self.image_files, data_files=self.data_files, |
|
1212 config_files=self.config_files, testmodule_files=self.testmodule_files, |
|
1213 engine_ini_file=self.engine_ini_file, test_harness=harness0, src_dst=self.src_dst0, |
|
1214 pmd_files=self.pmd_files, trace_activation_files=self.trace_activation_files, |
|
1215 trace_path=self.file_store.joinpath("traces", "set0", "tracelog.blx"), |
|
1216 ctc_enabled=self.ctc_enabled, eunitexerunner_flags=self.eunitexerunner_flags, |
|
1217 custom_dir = self.custom_dir, component_path=self.component_path, hti="True"), |
|
1218 dict(name="set1", image_files=self.image_files, data_files=self.data_files, |
|
1219 config_files=self.config_files, testmodule_files=self.testmodule_files, |
|
1220 engine_ini_file=self.engine_ini_file, test_harness=harness1, src_dst=self.src_dst1, |
|
1221 pmd_files=self.pmd_files, trace_activation_files=self.trace_activation_files, |
|
1222 trace_path=self.file_store.joinpath("traces", "set1", "tracelog.blx"), |
|
1223 ctc_enabled=self.ctc_enabled, eunitexerunner_flags=self.eunitexerunner_flags, |
|
1224 custom_dir = self.custom_dir, component_path=self.component_path, hti="True"),]) |
|
1225 mocker.expect(test_plan.post_actions).result([ |
|
1226 ("EmailAction", (("subject", "Release testing"), |
|
1227 ("to", self.report_email))), |
|
1228 # ("FileStoreAction", (("to-folder", self.file_store), |
|
1229 # ("report-type", "ATS_REPORT"), |
|
1230 # ("date-format", "yyyyMMdd"), |
|
1231 # ("time-format", "HHmmss"))), |
|
1232 # ("FileStoreAction", (("to-folder", self.file_store), |
|
1233 # ("report-type", "STIF_COMPONENT_REPORT_ALL_CASES"), |
|
1234 # ("run-log", "true"), |
|
1235 # ("date-format", "yyyyMMdd"), |
|
1236 # ("time-format", "HHmmss"))), |
|
1237 ("DiamondsAction", ())]) |
|
1238 |
|
1239 self.mocker.replay() |
|
1240 self.test_plan = test_plan |
|
1241 |
|
1242 self.gen = adg.Ats3TemplateTestDropGenerator() |
|
1243 return self.gen.generate_xml(test_plan) |
|
1244 # for thar in test_harness: |
|
1245 # xml = self.generate_xml(thar) |
|
1246 # # Check basics. |
|
1247 # assert xml.find(".").tag == "test" |
|
1248 # assert xml.find("./name").text == "test" |
|
1249 # assert xml.find("./buildid").text == self.diamonds_build_url |
|
1250 # assert xml.find("./target").tag |
|
1251 # assert xml.find("./target/device").tag |
|
1252 # if self.test_plan["harness"] == "MULTI_HARNESS": |
|
1253 # harness_1, type_1, device_hwid_1, harness_2, type_2, device_hwid_2 = xml.findall("./target/device/property") |
|
1254 # else: |
|
1255 # harness_1, type_1, device_hwid_1 = xml.findall("./target/device/property") |
|
1256 # |
|
1257 # if self.test_plan["harness"] == "MULTI_HARNESS": |
|
1258 # assert harness_1.get("value") == "STIF" |
|
1259 # assert type_1.get("value") == "product" |
|
1260 # assert device_hwid_1.get("value") == "5425" |
|
1261 # assert harness_2.get("value") == "EUNIT" |
|
1262 # assert type_2.get("value") == "product" |
|
1263 # assert device_hwid_2.get("value") == "5425" |
|
1264 # else: |
|
1265 # assert harness_1.get("value") == thar |
|
1266 # assert type_1.get("value") == "product" |
|
1267 # assert device_hwid_1.get("value") == "5425" |
|
1268 # |
|
1269 # # Check generation of the test plan. |
|
1270 # assert xml.find("./plan").get("name") == "test Plan" |
|
1271 # assert xml.find("./plan/session").tag |
|
1272 # sets = xml.findall("./execution") |
|
1273 # assert len(sets) == 2 |
|
1274 # assert sets[0].get("name") == "set0-"+str(TEST_PATH.joinpath("tsrc", "group")) |
|
1275 # assert sets[0].find("./target/device").tag |
|
1276 |
|
1277 def test_set_structure(self): |
|
1278 """Check that a <set> element's structure is valid.""" |
|
1279 xml = self.generate_xml("STIF") |
|
1280 tstset = xml.find("./execution") |
|
1281 assert tstset.tag |
|
1282 |
|
1283 def test_case_flash_elems(self): |
|
1284 """Checks flash target element in the test.xml file""" |
|
1285 xml = self.generate_xml("STIF") |
|
1286 found = False |
|
1287 for case in xml.findall(".//task"): |
|
1288 if case.find('type').text == 'FlashTask': |
|
1289 found = True |
|
1290 flashes = case.findall("./parameters/parameter") |
|
1291 assert len(flashes) == len(self.image_files) |
|
1292 for i, flash_file in enumerate(self.image_files): |
|
1293 assert flashes[i].get("name") == "image-" + str(i + 1) |
|
1294 assert flashes[i].get("value") == "ATS3Drop\\images\\" + flash_file.name |
|
1295 assert found |
|
1296 |
|
1297 def test_case_steps(self): |
|
1298 """Checks cases in steps in the test.xml file""" |
|
1299 test_harness = ["STIF", "EUNIT", "MULTI_HARNESS"] |
|
1300 for thar in test_harness: |
|
1301 xml = self.generate_xml(thar) |
|
1302 #print et.tostring(xml.getroot()) |
|
1303 steps = iter(xml.findall(".//task")) |
|
1304 steps.next() # Flash images |
|
1305 check_ctc_start(steps) |
|
1306 check_log_dir(steps) |
|
1307 if "MULTI_HARNESS" in thar: |
|
1308 self.check_install_step(steps, "STIF") |
|
1309 self.check_run_cases(steps, "STIF") |
|
1310 check_ctc_write(steps) |
|
1311 check_ctc_log(steps) |
|
1312 check_fetch_logs(steps, "STIF") |
|
1313 |
|
1314 steps.next() # Flash images |
|
1315 check_ctc_start(steps) |
|
1316 check_log_dir(steps) |
|
1317 self.check_install_step(steps, "EUNIT", set_count="1") |
|
1318 self.check_run_cases(steps, "EUNIT") |
|
1319 check_ctc_write(steps) |
|
1320 check_ctc_log(steps, "withpkgfiles") |
|
1321 check_fetch_logs(steps, "EUNIT") |
|
1322 else: |
|
1323 self.check_install_step(steps, thar) |
|
1324 self.check_run_cases(steps, thar) |
|
1325 check_ctc_write(steps) |
|
1326 check_ctc_log(steps) |
|
1327 check_fetch_logs(steps, thar) |
|
1328 |
|
1329 def check_install_step(self, steps, harness, set_count="0"): |
|
1330 """Checks install steps in the test.xml file""" |
|
1331 if harness == "MULTI_HARNESS": |
|
1332 dst = [self.src_dst0, self.src_dst1] |
|
1333 else: |
|
1334 dst = [self.src_dst0] |
|
1335 if set_count == "1": |
|
1336 dst = [self.src_dst1] |
|
1337 |
|
1338 for dest in dst: |
|
1339 for file1 in dest: |
|
1340 step = steps.next() |
|
1341 (drive, _) = ntpath.splitdrive(file1[1]) |
|
1342 filename = ntpath.basename(file1[1]) |
|
1343 letter = drive[0] |
|
1344 #if "FileUploadTask" in step.get("type"): |
|
1345 assert step.findtext("./type") == "FileUploadTask" |
|
1346 params = step.findall("./parameters/parameter") |
|
1347 src = params[0].get("value") |
|
1348 assert ntpath.basename(src) == filename |
|
1349 assert ntpath.dirname(src) == "ATS3Drop\\set" + set_count + '\\' + letter + '\\' + "sys\\bin" |
|
1350 dst = params[1].get("value") |
|
1351 assert ntpath.basename(dst) == filename |
|
1352 assert ntpath.dirname(dst) == drive + "\\sys\\bin" |
|
1353 |
|
1354 def check_run_cases(self, steps, harness="STIF"): |
|
1355 """Checks run cases in the test.xml file""" |
|
1356 step = steps.next() |
|
1357 if harness == "STIF": |
|
1358 _ = self.engine_ini_file |
|
1359 assert step.findtext("./type") == "StifRunCasesTask" |
|
1360 params = step.findall("./parameters/parameter") |
|
1361 assert params[0].get("value") == "*" |
|
1362 assert params[1].get("value") == "60" |
|
1363 assert params[2].get("value") == "c:\\sys\\bin\\" + ntpath.basename(self.engine_ini_file) |
|
1364 elif harness == "EUNIT": |
|
1365 _ = self.testmodule_files[0] |
|
1366 assert step.findtext("./type") == "EUnitTask" |
|
1367 params = step.findall("./parameters/parameter") |
|
1368 assert params[0].get("value") == path(r"z:\sys\bin\EUNITEXERUNNER.EXE") |
|
1369 assert params[1].get("value") == path(r"c:\Shared\EUnit\logs\file1_log.xml") |
|
1370 assert params[2].get("value") == "/E S60AppEnv /R Off /F file1 /l xml file1.dll" |
|
1371 assert params[3].get("value") == "60" |
|
1372 step = steps.next() |
|
1373 _ = self.testmodule_files[1] |
|
1374 assert step.findtext("./type") == "EUnitTask" |
|
1375 params = step.findall("./parameters/parameter") |
|
1376 assert params[0].get("value") == path(r"z:\sys\bin\EUNITEXERUNNER.EXE") |
|
1377 assert params[1].get("value") == path(r"c:\Shared\EUnit\logs\file2_log.xml") |
|
1378 assert params[2].get("value") == "/E S60AppEnv /R Off /F file2 /l xml file2.dll" |
|
1379 assert params[3].get("value") == "60" |
|
1380 |
|
1381 def test_steps_trace_enabled(self): |
|
1382 """checks if traing is enabled""" |
|
1383 test_harness = ["STIF"] |
|
1384 for thar in test_harness: |
|
1385 xml = self.generate_xml(thar, trace_enabled="True") |
|
1386 steps = iter(xml.findall(".//task")) |
|
1387 steps.next() # Flash images |
|
1388 check_ctc_start(steps) |
|
1389 check_log_dir(steps) |
|
1390 self.check_install_step(steps, thar) |
|
1391 #check_trace_start(steps, self.file_store) |
|
1392 self.check_run_cases(steps) |
|
1393 #check_trace_end_steps(steps, self.file_store) |
|
1394 check_ctc_write(steps) |
|
1395 check_ctc_log(steps) |
|
1396 check_fetch_logs(steps) |
|
1397 |
|
1398 def test_post_actions(self): |
|
1399 "Post actions are inserted into XML." |
|
1400 xml = self.generate_xml("STIF") |
|
1401 post_actions = xml.findall(".//action") |
|
1402 check_send_email_action(post_actions[0], self.report_email) |
|
1403 #check_ats_report_action(post_actions[1], self.file_store) |
|
1404 #check_stif_report_action(post_actions[2], self.file_store) |
|
1405 check_diamonds_action(post_actions[1]) |
|
1406 # def test_files(self): |
|
1407 # """Tests if the files are created for mock""" |
|
1408 # xml = self.generate_xml("STIF") |
|
1409 # files = iter(xml.findall("./files/file")) |
|
1410 # assert files.next().text == r"ATS3Drop/images/file1.fpsx" |
|
1411 # assert files.next().text == r"ATS3Drop/images/file2.fpsx" |
|
1412 # assert files.next().text == r"ATS3Drop/set0/c/sys/bin/file1.dll" |
|
1413 # assert files.next().text == r"ATS3Drop/set0/c/sys/bin/file2.dll" |
|
1414 # assert files.next().text == r"ATS3Drop/set0/e/sys/bin/file1" |
|
1415 # assert files.next().text == r"ATS3Drop/set0/e/sys/bin/file2" |
|
1416 # assert files.next().text == r"ATS3Drop/set0/e/sys/bin/file3" |
|
1417 # assert files.next().text == r"ATS3Drop/set0/c/sys/bin/file1.cfg" |
|
1418 # assert files.next().text == r"ATS3Drop/set0/c/sys/bin/file2.cfg" |
|
1419 # assert files.next().text == r"ATS3Drop/set0/c/sys/bin/TestFramework.ini" |
|
1420 # assert files.next().text == r"ATS3Drop/set1/c/sys/bin/file1.dll" |
|
1421 # assert files.next().text == r"ATS3Drop/set1/c/sys/bin/file2.dll" |
|
1422 # assert files.next().text == r"ATS3Drop/set1/e/sys/bin/file1" |
|
1423 # assert files.next().text == r"ATS3Drop/set1/e/sys/bin/file2" |
|
1424 # assert files.next().text == r"ATS3Drop/set1/e/sys/bin/file3" |
|
1425 # assert files.next().text == r"ATS3Drop/set1/c/sys/bin/file1.cfg" |
|
1426 # assert files.next().text == r"ATS3Drop/set1/c/sys/bin/file2.cfg" |
|
1427 # assert files.next().text == r"ATS3Drop/set1/c/sys/bin/TestFramework.ini" |
|
1428 # self.assertRaises(StopIteration, files.next) |
|
1429 # xml = self.generate_xml(harness="STIF", trace_enabled="True") |
|
1430 # files = iter(xml.findall("./files/file")) |
|
1431 # assert files.next().text == r"ATS3Drop/images/file1.fpsx" |
|
1432 # assert files.next().text == r"ATS3Drop/images/file2.fpsx" |
|
1433 # assert files.next().text == r"ATS3Drop/pmds/pmd_file.pmd" |
|
1434 # assert files.next().text == r"ATS3Drop/set0/trace_init/trace_activation_1.xml" |
|
1435 # assert files.next().text == r"ATS3Drop/set0/c/sys/bin/file1.dll" |
|
1436 # assert files.next().text == r"ATS3Drop/set0/c/sys/bin/file2.dll" |
|
1437 # assert files.next().text == r"ATS3Drop/set0/e/sys/bin/file1" |
|
1438 # assert files.next().text == r"ATS3Drop/set0/e/sys/bin/file2" |
|
1439 # assert files.next().text == r"ATS3Drop/set0/e/sys/bin/file3" |
|
1440 # assert files.next().text == r"ATS3Drop/set0/c/sys/bin/file1.cfg" |
|
1441 # assert files.next().text == r"ATS3Drop/set0/c/sys/bin/file2.cfg" |
|
1442 # assert files.next().text == r"ATS3Drop/set0/c/sys/bin/TestFramework.ini" |
|
1443 # assert files.next().text == r"ATS3Drop/set1/trace_init/trace_activation_1.xml" |
|
1444 # assert files.next().text == r"ATS3Drop/set1/c/sys/bin/file1.dll" |
|
1445 # assert files.next().text == r"ATS3Drop/set1/c/sys/bin/file2.dll" |
|
1446 # assert files.next().text == r"ATS3Drop/set1/e/sys/bin/file1" |
|
1447 # assert files.next().text == r"ATS3Drop/set1/e/sys/bin/file2" |
|
1448 # assert files.next().text == r"ATS3Drop/set1/e/sys/bin/file3" |
|
1449 # assert files.next().text == r"ATS3Drop/set1/c/sys/bin/file1.cfg" |
|
1450 # assert files.next().text == r"ATS3Drop/set1/c/sys/bin/file2.cfg" |
|
1451 # assert files.next().text == r"ATS3Drop/set1/c/sys/bin/TestFramework.ini" |
|
1452 # |
|
1453 # self.assertRaises(StopIteration, files.next) |
|
1454 def test_generate_drop(self): |
|
1455 """Manifest for ATS3Drop directory structure is generated.""" |
|
1456 xml = self.generate_xml("STIF") |
|
1457 strbuffer = StringIO() |
|
1458 self.gen.generate_drop(self.test_plan, xml, strbuffer) |
|
1459 |
|
1460 zfile = zipfile.ZipFile(strbuffer, "r") |
|
1461 try: |
|
1462 contents = sorted(tpath for tpath in zfile.namelist()) |
|
1463 expected = sorted(tpath |
|
1464 for tpath in [r"ATS3Drop/set0/c/sys/bin/file1.cfg", |
|
1465 r"ATS3Drop/set0/c/sys/bin/file2.cfg", |
|
1466 r"ATS3Drop/set0/e/sys/bin/file1", |
|
1467 r"ATS3Drop/set0/e/sys/bin/file2", |
|
1468 r"ATS3Drop/set0/e/sys/bin/file3", |
|
1469 r"ATS3Drop/images/file1.fpsx", |
|
1470 r"ATS3Drop/images/file2.fpsx", |
|
1471 r"ATS3Drop/set0/c/sys/bin/TestFramework.ini", |
|
1472 r"ATS3Drop/set0/c/sys/bin/file1.dll", |
|
1473 r"ATS3Drop/set0/c/sys/bin/file2.dll", |
|
1474 r"ATS3Drop/set1/c/sys/bin/file1.cfg", |
|
1475 r"ATS3Drop/set1/c/sys/bin/file2.cfg", |
|
1476 r"ATS3Drop/set1/e/sys/bin/file1", |
|
1477 r"ATS3Drop/set1/e/sys/bin/file2", |
|
1478 r"ATS3Drop/set1/e/sys/bin/file3", |
|
1479 r"ATS3Drop/set1/c/sys/bin/TestFramework.ini", |
|
1480 r"ATS3Drop/set1/c/sys/bin/file1.dll", |
|
1481 r"ATS3Drop/set1/c/sys/bin/file2.dll", |
|
1482 r"test.xml"]) |
|
1483 diff = difflib.context_diff(expected, contents) |
|
1484 assert contents == expected, "\n".join(diff) |
|
1485 finally: |
|
1486 zfile.close() |
|
1487 |
|
1488 def test_generate_drop_trace_enabled(self): |
|
1489 "Manifest for ATS3Drop directory structure is generated when trace enabled." |
|
1490 xml = self.generate_xml(harness="STIF", trace_enabled="True") |
|
1491 strbuffer = StringIO() |
|
1492 |
|
1493 self.gen.generate_drop(self.test_plan, xml, strbuffer) |
|
1494 zfile = zipfile.ZipFile(strbuffer, "r") |
|
1495 try: |
|
1496 contents = sorted(tpath for tpath in zfile.namelist()) |
|
1497 expected = sorted(tpath |
|
1498 for tpath in [r"ATS3Drop/set0/c/sys/bin/file1.cfg", |
|
1499 r"ATS3Drop/set0/c/sys/bin/file2.cfg", |
|
1500 r"ATS3Drop/set0/e/sys/bin/file1", |
|
1501 r"ATS3Drop/set0/e/sys/bin/file2", |
|
1502 r"ATS3Drop/set0/e/sys/bin/file3", |
|
1503 r"ATS3Drop/set0/trace_init/trace_activation_1.xml", |
|
1504 r"ATS3Drop/images/file1.fpsx", |
|
1505 r"ATS3Drop/images/file2.fpsx", |
|
1506 r"ATS3Drop/pmds/pmd_file.pmd", |
|
1507 r"ATS3Drop/set0/c/sys/bin/TestFramework.ini", |
|
1508 r"ATS3Drop/set0/c/sys/bin/file1.dll", |
|
1509 r"ATS3Drop/set0/c/sys/bin/file2.dll", |
|
1510 r"ATS3Drop/set1/c/sys/bin/file1.cfg", |
|
1511 r"ATS3Drop/set1/c/sys/bin/file2.cfg", |
|
1512 r"ATS3Drop/set1/e/sys/bin/file1", |
|
1513 r"ATS3Drop/set1/e/sys/bin/file2", |
|
1514 r"ATS3Drop/set1/e/sys/bin/file3", |
|
1515 r"ATS3Drop/set1/trace_init/trace_activation_1.xml", |
|
1516 r"ATS3Drop/set1/c/sys/bin/TestFramework.ini", |
|
1517 r"ATS3Drop/set1/c/sys/bin/file1.dll", |
|
1518 r"ATS3Drop/set1/c/sys/bin/file2.dll", |
|
1519 r"test.xml"]) |
|
1520 diff = difflib.context_diff(expected, contents) |
|
1521 assert contents == expected, "\n".join(diff) |
|
1522 finally: |
|
1523 zfile.close() |
|
1524 |
|
1525 class TestDropGenerationWithSis(mocker.MockerTestCase): |
|
1526 """ |
|
1527 Unit tests for the test.xml generation with sis files. |
|
1528 """ |
|
1529 def __init__(self, methodName="runTest"): |
|
1530 mocker.MockerTestCase.__init__(self, methodName) |
|
1531 self.sis_files = None |
|
1532 self.image_files = None |
|
1533 self.engine_ini_file = None |
|
1534 self.report_email = None |
|
1535 self.file_store = None |
|
1536 self.diamonds_build_url = None |
|
1537 self.harness = None |
|
1538 self.test_plan = None |
|
1539 self.gen = None |
|
1540 self.src_dst = [] |
|
1541 self.component_path = None |
|
1542 self.ctc_run_process_params = None |
|
1543 |
|
1544 def generate_xml(self): |
|
1545 """Geberates XML if sis files""" |
|
1546 def files(*paths): |
|
1547 """generates paths for the files""" |
|
1548 return [TEST_PATH.joinpath("tsrc", tpath) for tpath in paths] |
|
1549 self.sis_files = files("sis/file1.sisx", "sis/file2.sisx", "sis/file3.sisx") |
|
1550 self.image_files = files("output/images/file1.fpsx", "output/images/file2.fpsx") |
|
1551 self.engine_ini_file = files("init/TestFramework.ini")[0] |
|
1552 self.report_email = "test.receiver@company.com" |
|
1553 self.file_store = path("path/to/reports") |
|
1554 self.diamonds_build_url = "http://diamonds.nmp.company.com/diamonds/builds/1234" |
|
1555 self.harness = "STIF" |
|
1556 self.component_path = str(TEST_PATH.joinpath("tsrc", "group")) |
|
1557 self.ctc_run_process_params = r"10.0.0.1#x:\ats\drop0.zip#1" |
|
1558 |
|
1559 test_plan = self.mocker.mock(count=False) |
|
1560 mocker.expect(test_plan["testrun_name"]).result("test") |
|
1561 mocker.expect(test_plan["harness"]).result("STIF") |
|
1562 mocker.expect(test_plan["device_type"]).result("product") |
|
1563 mocker.expect(test_plan["hti"]).result("True") |
|
1564 mocker.expect(test_plan["plan_name"]).result("test plan") |
|
1565 mocker.expect(test_plan["diamonds_build_url"]).result(self.diamonds_build_url) |
|
1566 mocker.expect(test_plan["test_timeout"]).result("60") |
|
1567 mocker.expect(test_plan["device_hwid"]).result("5425") |
|
1568 mocker.expect(test_plan["ctc_enabled"]).result("False") |
|
1569 mocker.expect(test_plan["trace_enabled"]).result("False") |
|
1570 mocker.expect(test_plan["custom_dir"]).result("CustomC") |
|
1571 mocker.expect(test_plan.custom_dir).result(path(r"self.custom_dir")) |
|
1572 mocker.expect(test_plan["ctc_run_process_params"]).result(self.ctc_run_process_params) |
|
1573 mocker.expect(test_plan["report_email"]).result(self.report_email) |
|
1574 mocker.expect(test_plan.sets).result([ |
|
1575 dict(name="set0", image_files=self.image_files, sis_files=self.sis_files, |
|
1576 engine_ini_file=self.engine_ini_file, test_harness=self.harness, ctc_enabled="False", component_path=self.component_path, custom_dir=None), |
|
1577 ]) |
|
1578 mocker.expect(test_plan.post_actions).result([]) |
|
1579 self.mocker.replay() |
|
1580 self.test_plan = test_plan |
|
1581 |
|
1582 self.gen = adg.Ats3TemplateTestDropGenerator() |
|
1583 return self.gen.generate_xml(test_plan) |
|
1584 |
|
1585 def test_case_steps(self): |
|
1586 """Checks cases in steps in the test.xml file""" |
|
1587 xml = self.generate_xml() |
|
1588 steps = iter(xml.findall(".//task")) |
|
1589 steps.next() # Flash images |
|
1590 steps.next() # Stif log dir creation. |
|
1591 self.check_install_sis_files(steps) |
|
1592 steps.next() # Install engine ini. |
|
1593 self.check_install_sis_to_device(steps) |
|
1594 steps.next() # Run cases. |
|
1595 steps.next() # Fetch logs. |
|
1596 self.assertRaises(StopIteration, steps.next) |
|
1597 |
|
1598 def check_install_sis_files(self, steps): |
|
1599 """Checks sis files install steps in the test.xml file""" |
|
1600 for filename in self.sis_files: |
|
1601 step = steps.next() |
|
1602 assert step.findtext("./type") == "FileUploadTask" |
|
1603 params = step.findall("./parameters/parameter") |
|
1604 # TO DO: Should sis files be specified outside of the set? |
|
1605 assert params[0].get("value") == "ATS3Drop\\set0\\sis\\" + ntpath.basename(filename) |
|
1606 assert params[1].get("value") == "c:\\testframework\\" + ntpath.basename(filename) |
|
1607 |
|
1608 def check_install_sis_to_device(self, steps): |
|
1609 """Checks sis files installation on the device""" |
|
1610 for filename in self.sis_files: |
|
1611 step = steps.next() |
|
1612 assert step.findtext("./type") == "InstallSisTask" |
|
1613 params = step.findall("./parameters/parameter") |
|
1614 assert params[-1].get("value") == "c:\\testframework\\" + ntpath.basename(filename) |