Merge lp:~liuyq0307/lava-android-test/customize-attachments into lp:lava-android-test

Proposed by Yongqin Liu
Status: Merged
Approved by: Senthil Kumaran S
Approved revision: 253
Merged at revision: 252
Proposed branch: lp:~liuyq0307/lava-android-test/customize-attachments
Merge into: lp:lava-android-test
Diff against target: 327 lines (+122/-78)
4 files modified
lava_android_test/commands.py (+11/-62)
lava_android_test/test_definitions/cts.py (+7/-1)
lava_android_test/test_definitions/cts/cts_wrapper.py (+6/-1)
lava_android_test/testdef.py (+98/-14)
To merge this branch: bzr merge lp:~liuyq0307/lava-android-test/customize-attachments
Reviewer Review Type Date Requested Status
Senthil Kumaran S Approve
vishal Pending
Review via email: mp+164577@code.launchpad.net

Description of the change

Add support to adding customized attachment to the bundle.
Like the result.zip of cts test

have tested it locally.

To post a comment you must log in.
Revision history for this message
Senthil Kumaran S (stylesen) wrote :

Looks good +1 to merge.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lava_android_test/commands.py'
2--- lava_android_test/commands.py 2013-04-11 20:22:18 +0000
3+++ lava_android_test/commands.py 2013-05-18 08:57:37 +0000
4@@ -816,22 +816,17 @@
5 stderr_text = ''
6 bundle['test_runs'][0]["test_results"] = test_tmp.parser.results[
7 "test_results"]
8- bundle['test_runs'][0]["attachments"] = [
9- {
10- "pathname": test_tmp.org_ouput_file,
11- "mime_type": "text/plain",
12- "content": base64.standard_b64encode(stdout_text)
13- },
14- {
15- "pathname": 'stderr.log',
16- "mime_type": "text/plain",
17- "content": base64.standard_b64encode(stderr_text)
18- }
19- ]
20-
21- _gather_screencaps(resultdir, adb, bundle, config)
22- _gather_tombstones(adb, bundle, config)
23-
24+
25+ ## following part is used for generating the attachment for normal test
26+ attachment_bundles = []
27+ for attachment in test_tmp.attachments:
28+ data_bundle = attachment.generate_bundle(adb=adb, resultsdir=resultdir)
29+ if data_bundle:
30+ attachment_bundles.append(data_bundle)
31+
32+ bundle['test_runs'][0]["attachments"] = attachment_bundles
33+
34+ ##following used for the attachment for monkeyrunner test
35 for attach in attachments:
36 if os.path.exists(attach):
37 with open(attach, 'rb') as stream:
38@@ -843,52 +838,6 @@
39 "content": base64.standard_b64encode(data)})
40 return bundle
41
42-def _gather_screencaps(resultdir, adb, bundle, config):
43- """
44- Extension of the generate bundle function.
45- Grabs the screencaps and appends them to the bundle.
46- """
47- screencap_path = os.path.join(resultdir, 'screencap.png')
48- if adb.exists(screencap_path):
49- tmp_path = os.path.join(config.tempdir_host, 'screencap.png')
50- adb.pull(screencap_path, tmp_path)
51- with open(tmp_path, 'rb') as stream:
52- data = stream.read()
53- if data:
54- bundle['test_runs'][0]["attachments"].append({
55- "pathname": 'screencap.png',
56- "mime_type": 'image/png',
57- "content": base64.standard_b64encode(data)})
58- os.unlink(tmp_path)
59-
60-
61-def _gather_tombstones(adb , bundle, config):
62- """
63- Extension of the generate bundle function.
64- Grabs the tombstones and appends them to the bundle.
65- """
66- tombstone_path = '/data/tombstones'
67- tombstone_zip = os.path.join(config.tempdir_host,'tombstones.zip')
68- if adb.exists(tombstone_path):
69- tmp_path = os.path.join(config.tempdir_host, 'tombstones')
70- adb.pull(tombstone_path, tmp_path)
71- adb.shell("rm -R " + tombstone_path)
72- zipf = zipfile.ZipFile(tombstone_zip, mode='w')
73- for rootdir, dirs, files in os.walk(tmp_path):
74- for f in files:
75- zipf.write(os.path.join(rootdir, f), arcname=f)
76- zipf.close()
77-
78- with open(tombstone_zip, 'rb') as stream:
79- data = stream.read()
80- if data:
81- bundle['test_runs'][0]["attachments"].append({
82- "pathname": 'tombstones.zip',
83- "mime_type": 'application/zip',
84- "content": base64.standard_b64encode(data)})
85- os.unlink(tombstone_zip)
86-
87-
88 class show(AndroidResultCommand):
89 """
90 Display the output from a previous test that run on the specified device
91
92
93=== modified file 'lava_android_test/test_definitions/cts.py'
94--- lava_android_test/test_definitions/cts.py 2013-03-20 08:20:57 +0000
95+++ lava_android_test/test_definitions/cts.py 2013-05-18 08:57:37 +0000
96@@ -45,7 +45,13 @@
97 "\s+(?P<result>\S+)\s*$")
98 parser = lava_android_test.testdef.AndroidTestParser(pattern=pattern,
99 fixupdict={'PASS': 'pass', 'FAIL': 'fail'})
100+
101+attachments = [lava_android_test.testdef.Attachment(
102+ pathname="/data/local/tmp/cts-results.zip",
103+ mime_type="application/zip")
104+ ]
105 testobj = lava_android_test.testdef.AndroidTest(testname=test_name,
106 installer=inst,
107 runner=run,
108- parser=parser)
109+ parser=parser,
110+ attachments=attachments)
111
112=== modified file 'lava_android_test/test_definitions/cts/cts_wrapper.py'
113--- lava_android_test/test_definitions/cts/cts_wrapper.py 2013-05-06 08:26:27 +0000
114+++ lava_android_test/test_definitions/cts/cts_wrapper.py 2013-05-18 08:57:37 +0000
115@@ -27,6 +27,7 @@
116 import xml.dom.minidom
117 from lava_android_test.adb import ADB
118 from lava_android_test.utils import stop_at_pattern
119+from lava_android_test.utils import find_files
120
121 adb = ADB(sys.argv[1])
122 curdir = os.path.realpath(os.path.dirname(__file__))
123@@ -53,6 +54,10 @@
124 finally:
125 proc_cts.sendcontrol('C')
126 proc_cts.sendline('')
127+ target_dir = os.path.join(os.getcwd(),
128+ './android-cts/repository/results/')
129+ for zip_f in find_files(target_dir, '.zip'):
130+ adb.push(zip_f, '/data/local/tmp/cts-results.zip')
131
132 return result
133
134@@ -247,7 +252,7 @@
135
136 package_name = None
137 plan_name = 'CTS'
138- class_name= None
139+ class_name = None
140 method_name = None
141 timeout = 36000
142 #--cts_pkg cts_package_file --package package_name --timeout 36000
143
144=== modified file 'lava_android_test/testdef.py'
145--- lava_android_test/testdef.py 2013-04-08 06:35:17 +0000
146+++ lava_android_test/testdef.py 2013-05-18 08:57:37 +0000
147@@ -17,13 +17,17 @@
148 # You should have received a copy of the GNU General Public License
149 # along with this program. If not, see <http://www.gnu.org/licenses/>.
150
151+import base64
152 import hashlib
153+import logging
154 import os
155 import re
156 import string
157 import time
158 import tempfile
159 import decimal
160+import zipfile
161+
162 from datetime import datetime
163 from uuid import uuid4
164
165@@ -35,6 +39,57 @@
166 from linaro_dashboard_bundle.io import DocumentIO
167
168
169+class Attachment(object):
170+
171+ def __init__(self, pathname=None, mime_type=None):
172+ self.pathname = pathname
173+ self.mime_type = mime_type
174+
175+ def copy_to_result_dir(self, adb=None, resultsdir=None):
176+ """
177+ Copy the file specified by the pathname to result
178+ directory of this time test, beacuse some test will
179+ generate the result to the same path file.
180+ And Please Note that pathname must be the absolute
181+ path in the device.
182+ """
183+ if (not self.pathname) or (not self.pathname.startswith('/')):
184+ return
185+ if not resultsdir:
186+ return
187+ if not adb:
188+ adb = ADB()
189+ if not adb.exists(resultsdir):
190+ adb.makedirs(resultsdir)
191+ ret_code = adb.copy(self.pathname, os.path.join(resultsdir,
192+ os.path.basename(self.pathname)))
193+ if ret_code != 0:
194+ raise RuntimeError(
195+ "Failed to copy file '%s' to '%s' on device(%s)" %
196+ (self.pathname, resultsdir, adb.get_serial()))
197+
198+ def generate_bundle(self, adb=None, resultsdir=None):
199+ data_bundle = {}
200+ if not self.pathname:
201+ return data_bundle
202+ if not adb:
203+ adb = ADB()
204+ config = get_config()
205+ basename = os.path.basename(self.pathname)
206+ android_path = os.path.join(resultsdir, basename)
207+ if adb.exists(android_path):
208+ tmp_path = os.path.join(config.tempdir_host, basename)
209+ adb.pull(android_path, tmp_path)
210+ with open(tmp_path, 'rb') as stream:
211+ data = stream.read()
212+ if data:
213+ data_bundle = {"pathname": basename,
214+ "mime_type": self.mime_type,
215+ "content": base64.standard_b64encode(data)}
216+ os.unlink(tmp_path)
217+ return data_bundle
218+
219+
220 class AndroidTest(ITest):
221 """Base class for defining tests.
222
223@@ -49,6 +104,12 @@
224 parser - AbrekParser instance to use
225 """
226 adb = ADB()
227+ default_attachments = [
228+ Attachment(pathname="stderr.log", mime_type="text/plain"),
229+ Attachment(pathname="stdout.log", mime_type="text/plain"),
230+ Attachment(pathname="screencap.png", mime_type="image/png"),
231+ Attachment(pathname="tombstones.zip", mime_type="application/zip")
232+ ]
233
234 def setadb(self, adb=None):
235 self.adb = adb
236@@ -58,7 +119,8 @@
237
238 def __init__(self, testname, version="", installer=None, runner=None,
239 parser=None, default_options=None,
240- org_ouput_file='stdout.log'):
241+ org_ouput_file='stdout.log',
242+ attachments=[]):
243 self.testname = testname
244 self.version = version
245 self.installer = installer
246@@ -67,6 +129,13 @@
247 self.default_options = default_options
248 self.org_ouput_file = org_ouput_file
249 self.origdir = os.path.abspath(os.curdir)
250+ self.attachments = self.default_attachments
251+ if self.org_ouput_file and (self.org_ouput_file != "stdout.log"):
252+ self.attachments.append(
253+ Attachment(pathname=self.org_ouput_file,
254+ mime_type="text/plain"))
255+ if attachments:
256+ self.attachments.extend(attachments)
257
258 def set_runner(self, runner=None):
259 self.runner = runner
260@@ -153,7 +222,7 @@
261 ]
262 }
263 if run_options:
264- bundle['test_runs'][0]['attributes']['run_options'] = run_options
265+ bundle['test_runs'][0]['attributes']['run_options'] = run_options
266 self._add_install_options(bundle, config)
267 filename_host = os.path.join(config.tempdir_host, 'testdata.json')
268 write_file(DocumentIO.dumps(bundle), filename_host)
269@@ -177,7 +246,8 @@
270 self.resultsdir = os.path.join(config.resultsdir_android, resultname)
271 self.adb.makedirs(self.resultsdir)
272 self.runner.run(self.resultsdir, run_options=run_options)
273- self._copyorgoutputfile(self.resultsdir)
274+ self._gather_tombstones(self.resultsdir)
275+ self._copyattachments(self.resultsdir)
276 self._screencap(self.resultsdir)
277 self._savetestdata(str(uuid4()), run_options=run_options)
278 result_id = os.path.basename(self.resultsdir)
279@@ -190,17 +260,30 @@
280 self.adb.shell('%s %s' % (target_path, os.path.join(resultsdir,
281 'screencap.png')))
282
283- def _copyorgoutputfile(self, resultsdir):
284- if self.org_ouput_file == 'stdout.log':
285- return
286- if not self.adb.exists(resultsdir):
287- self.adb.makedirs(resultsdir)
288- ret_code = self.adb.copy(self.org_ouput_file, os.path.join(resultsdir,
289- os.path.basename(self.org_ouput_file)))
290- if ret_code != 0:
291- raise RuntimeError(
292- "Failed to copy file '%s' to '%s' for test(%s)" %
293- (self.org_ouput_file, resultsdir, self.testname))
294+ def _gather_tombstones(self, resultsdir):
295+ """
296+ Extension of the generate bundle function.
297+ Grabs the tombstones and appends them to the bundle.
298+ """
299+ config = get_config()
300+ tombstone_path = '/data/tombstones'
301+ tombstone_zip = os.path.join(config.tempdir_host, 'tombstones.zip')
302+ if self.adb.exists(tombstone_path):
303+ tmp_path = os.path.join(config.tempdir_host, 'tombstones')
304+ self.adb.pull(tombstone_path, tmp_path)
305+ self.adb.shell("rm -R " + tombstone_path)
306+ zipf = zipfile.ZipFile(tombstone_zip, mode='w')
307+ for rootdir, dirs, files in os.walk(tmp_path):
308+ for f in files:
309+ zipf.write(os.path.join(rootdir, f), arcname=f)
310+ zipf.close()
311+ self.adb.push(tombstone_zip, os.path.join(resultsdir,
312+ 'tombstones.zip'))
313+ os.unlink(tombstone_zip)
314+
315+ def _copyattachments(self, resultsdir):
316+ for attachment in self.attachments:
317+ attachment.copy_to_result_dir(adb=self.adb, resultsdir=resultsdir)
318
319 def parse(self, resultname):
320 if not self.parser:
321@@ -607,6 +690,7 @@
322 self.fixmeasurements()
323 self.fixids()
324
325+
326 class AndroidSimpleTestParser(AndroidTestParser):
327
328 def real_parse(self, result_filename='stdout.log',

Subscribers

People subscribed via source and target branches