|
1 # -*- coding: latin-1 -*- |
|
2 |
|
3 #============================================================================ |
|
4 #Name : test_matti.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 MATTI framework. """ |
|
23 |
|
24 # pylint: disable-msg=E1101,W0603,W0142 |
|
25 |
|
26 import logging |
|
27 logging.getLogger().setLevel(logging.ERROR) |
|
28 import os |
|
29 #import shutil |
|
30 |
|
31 from path import path |
|
32 |
|
33 import ats3.aste |
|
34 import ats3.matti.MattiDrops |
|
35 #from lxml import objectify |
|
36 #from lxml import etree |
|
37 |
|
38 |
|
39 |
|
40 # Shortcuts |
|
41 HELIUM_ADDR = os.environ['HELIUM_HOME'] |
|
42 TEST_FILE_NAME = os.path.join(HELIUM_ADDR, 'test.xml') |
|
43 ZIP_FILE_NAME = os.path.join(HELIUM_ADDR, 'MATTIDrop.zip') |
|
44 |
|
45 class Bunch(object): |
|
46 """do something with the paramerters passed to it""" |
|
47 def __init__(self, **kwargs): |
|
48 self.__dict__.update(kwargs) |
|
49 |
|
50 |
|
51 def equal_xml(result, expect): |
|
52 """Check the equality of the given XML snippets. """ |
|
53 # logging.info(" expect %s" % expect) |
|
54 # xml1 = objectify.fromstring(expect) |
|
55 # expect1 = etree.tostring(xml1) |
|
56 # logging.info(" expect1 %s" % expect1) |
|
57 # logging.info(" expect2 -------------%s" % expect2) |
|
58 # |
|
59 # xml2 = objectify.fromstring(result) |
|
60 # result2 = etree.tostring(xml2) |
|
61 # self.assertEquals(expect1, result1) |
|
62 # |
|
63 # if xml1.tag != xml2.tag: |
|
64 # return False |
|
65 # if xml1.attrib != xml2.attrib: |
|
66 # return False |
|
67 # if xml1.text: |
|
68 # if not xml2.text: |
|
69 # return False |
|
70 # if xml2.text: |
|
71 # if not xml1.text: |
|
72 # return False |
|
73 # if xml1.text and xml2.text and xml1.text.strip() != xml2.text.strip(): |
|
74 # return False |
|
75 # if xml1.tail is not None and xml2.tail is not None: |
|
76 # if xml1.tail.strip() != xml2.tail.strip(): |
|
77 # return False |
|
78 # elif xml1.tail != xml2.tail: |
|
79 # return False |
|
80 # children1 = list(xml1.getchildren()) |
|
81 # children2 = list(xml2.getchildren()) |
|
82 # if len(children1) != len(children2): |
|
83 # return False |
|
84 # for child1, child2 in zip(children1, children2): |
|
85 # return equal_xml(child1, child2) |
|
86 # return True |
|
87 if expect: |
|
88 return result |
|
89 |
|
90 |
|
91 def setup_module(): |
|
92 """ stuff to do before running the tests """ |
|
93 pass |
|
94 |
|
95 def teardown_module(): |
|
96 """ stuff to do after running the tests """ |
|
97 if os.path.exists(TEST_FILE_NAME): |
|
98 os.remove(TEST_FILE_NAME) |
|
99 if os.path.exists(ZIP_FILE_NAME): |
|
100 os.remove(ZIP_FILE_NAME) |
|
101 |
|
102 |
|
103 class TestPlanMatti(): |
|
104 """ test MattiDrop.py """ |
|
105 def __init__(self): |
|
106 self.config = None |
|
107 self.tp_result = None |
|
108 |
|
109 def test_all_present(self): |
|
110 """ test mattiDrops.py with all parameters present and correct""" |
|
111 teardown_module() |
|
112 opts = Bunch(build_drive="z:", |
|
113 matti_scripts=os.path.join(HELIUM_ADDR, 'testconfig/ats3/matti/script/'), |
|
114 flash_images = HELIUM_ADDR + os.sep + "testconfig/ats3/matti/variant_images/test_file.fpsx," \ |
|
115 + HELIUM_ADDR + os.sep + "testconfig/ats3/matti/variant_images/test_file_3rd.fpsx," \ |
|
116 + HELIUM_ADDR + os.sep + "testconfig/ats3/matti/variant_images/test_file_another.fpsx", |
|
117 report_email="", harness="STIF", |
|
118 file_store=path(), testrun_name="testrun", |
|
119 device_type="product", device_hwid="5425", diamonds_build_url="", drop_file="MATTIDrop.zip", |
|
120 minimum_flash_images="2", plan_name="matti_test_plan", |
|
121 sis_files= HELIUM_ADDR + os.sep + "testconfig/ats3/matti/sis/test_file_matti_install.sis," \ |
|
122 + HELIUM_ADDR + os.sep + "testconfig/ats3/matti/sis/another_test_file_matti_install.sis", |
|
123 template_loc=os.path.join(HELIUM_ADDR, 'tools/common/python/lib/ats3/matti/template/matti_demo.xml'), |
|
124 test_timeout="60", verbose="false") |
|
125 |
|
126 self.config = ats3.matti.MattiDrops.Configuration(opts) |
|
127 self.tp_result = ats3.matti.MattiDrops.create_drop(self.config) |
|
128 assert os.path.exists(ZIP_FILE_NAME) |
|
129 assert os.path.exists(TEST_FILE_NAME) |
|
130 #shutil.copy(TEST_FILE_NAME, os.path.join(HELIUM_ADDR, 'testconfig/ats3/matti/test_all_present.xml')) |
|
131 #equal_xml(TEST_FILE_NAME, os.path.join(HELIUM_ADDR, 'testconfig/ats3/matti/test_all_present.xml')) |
|
132 |
|
133 def test_no_sis_or_flash_files(self): |
|
134 """test mattiDrops.py with no sis or flash files in the parameters""" |
|
135 teardown_module() |
|
136 opts = Bunch(build_drive="z:", |
|
137 matti_scripts=os.path.join(HELIUM_ADDR, 'testconfig/ats3/matti/script/'), |
|
138 flash_images = "", |
|
139 report_email="", harness="STIF", |
|
140 file_store=path(), testrun_name="testrun", |
|
141 device_type="product", device_hwid="5425", diamonds_build_url="", drop_file="MATTIDrop.zip", |
|
142 minimum_flash_images="2", plan_name="matti_test_plan", |
|
143 sis_files= "", |
|
144 template_loc=os.path.join(HELIUM_ADDR, 'tools/common/python/lib/ats3/matti/template/matti_demo.xml'), |
|
145 test_timeout="60", verbose="true") |
|
146 |
|
147 self.config = ats3.matti.MattiDrops.Configuration(opts) |
|
148 self.tp_result = ats3.matti.MattiDrops.create_drop(self.config) |
|
149 assert os.path.exists(ZIP_FILE_NAME) |
|
150 assert os.path.exists(TEST_FILE_NAME) |
|
151 #shutil.copy(TEST_FILE_NAME, os.path.join(HELIUM_ADDR, 'testconfig/ats3/matti/test_no_sis_or_flash.xml')) |
|
152 #equal_xml(TEST_FILE_NAME, os.path.join(HELIUM_ADDR, 'testconfig/ats3/matti/test_no_sis_or_flash.xml')) |
|
153 |
|
154 |
|
155 def test_no_files(self): |
|
156 """ test mattiDtops.py with no filespresent at all""" |
|
157 teardown_module() |
|
158 opts = Bunch(build_drive="z:", |
|
159 matti_scripts=os.path.join(HELIUM_ADDR, 'testconfig/ats3/matti/variant_images/'), |
|
160 flash_images = "", |
|
161 report_email="", harness="STIF", |
|
162 file_store=path(), testrun_name="testrun", |
|
163 device_type="product", device_hwid="5425", diamonds_build_url="", drop_file="MATTIDrop.zip", |
|
164 minimum_flash_images="2", plan_name="matti_test_plan", |
|
165 sis_files= "", |
|
166 template_loc=os.path.join(HELIUM_ADDR, 'tools/common/python/lib/ats3/matti/template/matti_demo.xml'), |
|
167 test_timeout="60", verbose="true") |
|
168 self.config = ats3.matti.MattiDrops.Configuration(opts) |
|
169 self.tp_result = ats3.matti.MattiDrops.create_drop(self.config) |
|
170 assert not os.path.exists(ZIP_FILE_NAME) |
|
171 assert os.path.exists(TEST_FILE_NAME) |
|
172 #shutil.copy(TEST_FILE_NAME, os.path.join(HELIUM_ADDR, 'testconfig/ats3/matti/test_no_files.xml')) |
|
173 #equal_xml(TEST_FILE_NAME, os.path.join(HELIUM_ADDR, 'testconfig/ats3/matti/test_no_files.xml')) |
|
174 |
|
175 def test_no_params(self): |
|
176 """test MattiDrops.py with no parameters present at all""" |
|
177 teardown_module() |
|
178 opts = Bunch(build_drive="", |
|
179 matti_scripts="", |
|
180 flash_images = "", |
|
181 report_email="", harness="", |
|
182 file_store="", testrun_name="", |
|
183 device_type="", device_hwid="", diamonds_build_url="", drop_file="", |
|
184 minimum_flash_images="", plan_name="", |
|
185 sis_files= "", |
|
186 template_loc="", |
|
187 test_timeout="", verbose="true") |
|
188 |
|
189 self.config = ats3.matti.MattiDrops.Configuration(opts) |
|
190 self.tp_result = ats3.matti.MattiDrops.create_drop(self.config) |
|
191 assert not os.path.exists(ZIP_FILE_NAME) |
|
192 assert not os.path.exists(TEST_FILE_NAME) |
|
193 |
|
194 def test_some_not_present(self): |
|
195 """ test MattiDrops.py with an extra file not present in the dir""" |
|
196 teardown_module() |
|
197 opts = Bunch(build_drive="z:", |
|
198 matti_scripts=os.path.join(HELIUM_ADDR, 'testconfig/ats3/matti/script/'), |
|
199 flash_images = HELIUM_ADDR + os.sep + "testconfig/ats3/matti/variant_images/test_file.fpsx," \ |
|
200 + HELIUM_ADDR + os.sep + "testconfig/ats3/matti/variant_images/test_file_3rd.fpsx," \ |
|
201 + HELIUM_ADDR + os.sep + "testconfig/ats3/matti/variant_images/test_file_different.fpsx", |
|
202 report_email="", harness="STIF", |
|
203 file_store=path(), testrun_name="testrun", |
|
204 device_type="product", device_hwid="5425", diamonds_build_url="", drop_file="MATTIDrop.zip", |
|
205 minimum_flash_images="2", plan_name="matti_test_plan", |
|
206 sis_files= HELIUM_ADDR + os.sep + "testconfig/ats3/matti/sis/test_file_matti_install.sis," \ |
|
207 + HELIUM_ADDR + os.sep + "testconfig/ats3/matti/sis/another_test_file.sis", |
|
208 template_loc=os.path.join(HELIUM_ADDR, 'tools/common/python/lib/ats3/matti/template/matti_demo.xml'), |
|
209 test_timeout="60", verbose="false") |
|
210 |
|
211 self.config = ats3.matti.MattiDrops.Configuration(opts) |
|
212 self.tp_result = ats3.matti.MattiDrops.create_drop(self.config) |
|
213 assert os.path.exists(ZIP_FILE_NAME) |
|
214 assert os.path.exists(TEST_FILE_NAME) |
|
215 #shutil.copy(TEST_FILE_NAME, os.path.join(HELIUM_ADDR, 'testconfig/ats3/matti/test_some_not_present.xml')) |
|
216 #equal_xml(TEST_FILE_NAME, os.path.join(HELIUM_ADDR, 'testconfig/ats3/matti/test_some_not_present.xml')) |