|
1 # -*- coding: latin-1 -*- |
|
2 |
|
3 #============================================================================ |
|
4 #Name : test_matti2.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=E1101 |
|
25 |
|
26 import logging |
|
27 logging.getLogger().setLevel(logging.INFO) |
|
28 import os |
|
29 #import shutil |
|
30 from path import path |
|
31 import ats3.matti2 |
|
32 import tempfile |
|
33 import zipfile |
|
34 import platform |
|
35 |
|
36 TEST_PATH = None |
|
37 TEST_FILES = {} |
|
38 MATTI = None |
|
39 OUTPUT = None |
|
40 SISFILES = None |
|
41 TOTAL_TESTS_COUNT = 3 |
|
42 |
|
43 |
|
44 class Bunch(object): |
|
45 """ Configuration object. Argument from constructor are converted into class attributes. """ |
|
46 def __init__(self, **kwargs): |
|
47 self.__dict__.update(kwargs) |
|
48 |
|
49 class SetUp(object): |
|
50 """ Setup the module. """ |
|
51 |
|
52 def __init__(self): |
|
53 """ Setup test environment. """ |
|
54 global TEST_PATH, MATTI, OUTPUT, SISFILES |
|
55 |
|
56 TEST_PATH = path(tempfile.mkdtemp()) |
|
57 component = TEST_PATH |
|
58 component.joinpath("matti").makedirs() |
|
59 for path_parts in (("matti_testcases", "profile", "all.sip"), |
|
60 ("matti_testcases", "profile", "bat.sip"), |
|
61 ("matti_testcases", "profile", "fute.sip"), |
|
62 ("matti_testcases", "hwdata", "paths.pkg"), |
|
63 ("matti_testcases", "hwdata", "file1.txt"), |
|
64 ("matti_testcases", "hwdata", "settings.ini"), |
|
65 ("matti_testcases", "matti_parameters", "matti_parameters.xml"), |
|
66 ("matti_testcases", "unit_test1.rb"), |
|
67 ("matti_testcases", "unit_test2.rb"), |
|
68 ("output", "images", "image1.fpsx"), |
|
69 ("output", "images", "image2.fpsx"), |
|
70 ("sisfiles", "abc.sis"), |
|
71 ("sisfiles", "xyz.sis"), |
|
72 ("output", "ats", "temp.txt")): |
|
73 filepath = component.joinpath(*path_parts) |
|
74 if not filepath.parent.exists(): |
|
75 filepath.parent.makedirs() |
|
76 filepath.touch() |
|
77 TEST_FILES.setdefault(path_parts[1], []).append(filepath) |
|
78 |
|
79 OUTPUT = component.joinpath(r"output") |
|
80 MATTI = component.joinpath("matti_testcases") |
|
81 SISFILES = component.joinpath(r"sisfiles") |
|
82 |
|
83 if not filepath.parent.exists(): |
|
84 filepath.parent.makedirs() |
|
85 filepath.touch() |
|
86 |
|
87 #mtc => matti_testcases |
|
88 mtc = component.joinpath("matti_testcases") |
|
89 mtc.joinpath("unit_test1.rb").write_text("unit_tests") |
|
90 mtc.joinpath("unit_test2.rb").write_text("unit_tests") |
|
91 |
|
92 # profiles |
|
93 profiles = component.joinpath("matti_testcases", "profile") |
|
94 profiles.joinpath("all.sip").write_text("sip profile") |
|
95 profiles.joinpath("bat.sip").write_text("sip profile") |
|
96 profiles.joinpath("fute.sip").write_text("sip profile") |
|
97 |
|
98 #hwdata => hardware data |
|
99 profiles = component.joinpath("matti_testcases", "hwdata") |
|
100 profiles.joinpath("file1.txt").write_text("data file") |
|
101 profiles.joinpath("settings.ini").write_text("settings initialization file") |
|
102 profiles.joinpath("paths.pkg").write_text( |
|
103 r""" |
|
104 ;Language - standard language definitions |
|
105 &EN |
|
106 |
|
107 ; standard SIS file header |
|
108 #{"BTEngTestApp"},(0x04DA27D5),1,0,0 |
|
109 |
|
110 ;Supports Series 60 v 3.0 |
|
111 (0x101F7961), 0, 0, 0, {"Series60ProductID"} |
|
112 |
|
113 ;Localized Vendor Name |
|
114 %{"BTEngTestApp"} |
|
115 |
|
116 ;Unique Vendor name |
|
117 :"Nokia" |
|
118 |
|
119 ; Files to copy |
|
120 |
|
121 "[PKG_LOC]\file1.txt"-"C:\Private\10202BE9\PERSISTS\file1.txt" |
|
122 "[PKG_LOC]\settings.ini"-"c:\sys\settings.ini" |
|
123 """.replace('\\', os.sep)) |
|
124 |
|
125 |
|
126 def teardown_module(test_run_count): |
|
127 """ stuff to do after running the tests """ |
|
128 |
|
129 if test_run_count == 0: |
|
130 path(TEST_PATH).rmtree() |
|
131 |
|
132 class TestMattiTestPlan(SetUp): |
|
133 """ test MattiDrop.py """ |
|
134 global OUTPUT, MATTI, SISFILES |
|
135 |
|
136 def __init__(self): |
|
137 """initialize Matti Tests""" |
|
138 SetUp.__init__(self) |
|
139 self.file_store = OUTPUT |
|
140 self.test_asset_path = MATTI |
|
141 self.matti_sis_files = r"%s/abc.sis#f:\data\abc.sis#c:\abc.sis, %s/xyz.sis#f:\data\abc.sis#f:\xyz.sis" % (SISFILES, SISFILES) |
|
142 self.build_drive = "j:" |
|
143 self.drop_file = path(r"%s/ats/ATSMattiDrop.zip" %OUTPUT).normpath() |
|
144 |
|
145 image_files = r"%s/images/image1.fpsx, %s/images/image2.fpsx " % (OUTPUT, OUTPUT) |
|
146 self.flash_images = image_files |
|
147 |
|
148 self.template_loc = os.path.join(os.environ['TEST_DATA'], 'data/matti/matti_template.xml') |
|
149 self.template_loc = os.path.normpath(self.template_loc) |
|
150 self.matti_parameters = "" |
|
151 self.config = None |
|
152 |
|
153 def read_xml(self, file_location, zip_file=False): |
|
154 """reads test.xml file if a path is given""" |
|
155 |
|
156 xml_text = "" |
|
157 file_location = path(file_location) |
|
158 if zip_file: |
|
159 if zipfile.is_zipfile(file_location): |
|
160 myzip = zipfile.ZipFile(file_location, 'r') |
|
161 xml_text = myzip.read('test.xml') |
|
162 myzip.close() |
|
163 |
|
164 else: |
|
165 hnd = open(file_location, 'r') |
|
166 for line in hnd.readlines(): |
|
167 xml_text = xml_text + line |
|
168 |
|
169 return xml_text |
|
170 |
|
171 def test_xml_with_all_parameters(self): |
|
172 """ test Matti2.py with all parameters present and correct and sierra is enabled""" |
|
173 global TOTAL_TESTS_COUNT |
|
174 opts = Bunch(build_drive=self.build_drive, |
|
175 drop_file=path(r"%s/ats/ATSMattiDrop1.zip" %OUTPUT).normpath(), |
|
176 flash_images=self.flash_images, |
|
177 matti_sis_files=self.matti_sis_files, |
|
178 testasset_location=self.test_asset_path, |
|
179 template_loc=self.template_loc, |
|
180 sierra_enabled="True", |
|
181 test_profiles="bat, fute", |
|
182 matti_parameters="", |
|
183 matti_timeout="1200", |
|
184 sierra_parameters="--teardown", |
|
185 file_store=self.file_store, |
|
186 report_email="firstname.lastname@domain.com", |
|
187 testrun_name="matti test run", |
|
188 alias_name="alias", |
|
189 device_type="new_device", |
|
190 diamonds_build_url="http://diamonds.com/1234", |
|
191 email_format="simplelogger", |
|
192 email_subject="Matti test report", |
|
193 verbode="false") |
|
194 |
|
195 self.config = ats3.matti2.Configuration(opts) |
|
196 ats3.matti2.create_drop(self.config) |
|
197 |
|
198 xml_loc = os.path.join(os.environ['TEST_DATA'], 'data/matti/test_all_present.xml') |
|
199 stored_xml = self.read_xml(xml_loc, False).strip() |
|
200 drop_loc = os.path.join(OUTPUT, 'ats/ATSMattiDrop1.zip') |
|
201 generated_xml = self.read_xml(drop_loc, True).strip() |
|
202 |
|
203 if platform.system().lower() == "linux": |
|
204 assert stored_xml.replace('\r', '') in generated_xml |
|
205 else: |
|
206 assert stored_xml in generated_xml |
|
207 |
|
208 TOTAL_TESTS_COUNT -= 1 |
|
209 teardown_module(TOTAL_TESTS_COUNT) |
|
210 |
|
211 def test_xml_if_sierra_is_not_enabled(self): |
|
212 """ test Matti2.py with all parameters present and correct and sierra is not enabled (or false)""" |
|
213 global TOTAL_TESTS_COUNT |
|
214 opts = Bunch(build_drive=self.build_drive, |
|
215 drop_file=path(r"%s/ats/ATSMattiDrop2.zip" %OUTPUT).normpath(), |
|
216 flash_images=self.flash_images, |
|
217 matti_sis_files=self.matti_sis_files, |
|
218 testasset_location=self.test_asset_path, |
|
219 template_loc=self.template_loc, |
|
220 sierra_enabled="False", |
|
221 test_profiles="bat, fute", |
|
222 matti_parameters="", |
|
223 matti_timeout="1200", |
|
224 sierra_parameters="--teardown", |
|
225 file_store=self.file_store, |
|
226 report_email="firstname.lastname@domain.com", |
|
227 testrun_name="matti test run", |
|
228 alias_name="alias", |
|
229 device_type="new_device", |
|
230 diamonds_build_url="http://diamonds.com/1234", |
|
231 email_format="simplelogger", |
|
232 email_subject="Matti test report", |
|
233 verbode="false") |
|
234 |
|
235 self.config = ats3.matti2.Configuration(opts) |
|
236 ats3.matti2.create_drop(self.config) |
|
237 |
|
238 xml_loc = os.path.join(os.environ['TEST_DATA'], 'data/matti/test_all_present_sierra_disabled.xml') |
|
239 stored_xml = self.read_xml(xml_loc, False).strip() |
|
240 drop_loc = os.path.join(OUTPUT, 'ats/ATSMattiDrop2.zip') |
|
241 generated_xml = self.read_xml(drop_loc, True).strip() |
|
242 |
|
243 if platform.system().lower() == "linux": |
|
244 assert stored_xml.replace('\r', '') in generated_xml |
|
245 else: |
|
246 assert stored_xml in generated_xml |
|
247 |
|
248 TOTAL_TESTS_COUNT -= 1 |
|
249 teardown_module(TOTAL_TESTS_COUNT) |
|
250 |
|
251 def test_xml_if_sierra_is_enabled_template_location_is_missing(self): |
|
252 """ test Matti2.py with all parameters present and correct and if sierra is enabled but template location is used as default one""" |
|
253 global TOTAL_TESTS_COUNT |
|
254 opts = Bunch(build_drive=self.build_drive, |
|
255 drop_file=path(r"%s/ats/ATSMattiDrop3.zip" %OUTPUT).normpath(), |
|
256 flash_images=self.flash_images, |
|
257 matti_sis_files=self.matti_sis_files, |
|
258 testasset_location=self.test_asset_path, |
|
259 template_loc="", |
|
260 sierra_enabled="True", |
|
261 test_profiles="bat, fute", |
|
262 matti_parameters="", |
|
263 matti_timeout="1200", |
|
264 sierra_parameters="--teardown", |
|
265 file_store=self.file_store, |
|
266 report_email="firstname.lastname@domain.com", |
|
267 testrun_name="matti test run", |
|
268 alias_name="alias", |
|
269 device_type="new_device", |
|
270 diamonds_build_url="http://diamonds.com/1234", |
|
271 email_format="simplelogger", |
|
272 email_subject="Matti test report", |
|
273 verbode="false") |
|
274 |
|
275 self.config = ats3.matti2.Configuration(opts) |
|
276 ats3.matti2.create_drop(self.config) |
|
277 |
|
278 xml_loc = os.path.join(os.environ['TEST_DATA'], 'data/matti/test_all_present.xml') |
|
279 stored_xml = self.read_xml(xml_loc, False).strip() |
|
280 drop_loc = os.path.join(OUTPUT, 'ats/ATSMattiDrop3.zip') |
|
281 generated_xml = self.read_xml(drop_loc, True).strip() |
|
282 |
|
283 if platform.system().lower() == "linux": |
|
284 assert stored_xml.replace('\r', '') in generated_xml |
|
285 else: |
|
286 assert stored_xml in generated_xml |
|
287 |
|
288 TOTAL_TESTS_COUNT -= 1 |
|
289 teardown_module(TOTAL_TESTS_COUNT) |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 |