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