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
=== modified file 'lava_android_test/commands.py'
--- lava_android_test/commands.py 2013-04-11 20:22:18 +0000
+++ lava_android_test/commands.py 2013-05-18 08:57:37 +0000
@@ -816,22 +816,17 @@
816 stderr_text = ''816 stderr_text = ''
817 bundle['test_runs'][0]["test_results"] = test_tmp.parser.results[817 bundle['test_runs'][0]["test_results"] = test_tmp.parser.results[
818 "test_results"]818 "test_results"]
819 bundle['test_runs'][0]["attachments"] = [819
820 {820 ## following part is used for generating the attachment for normal test
821 "pathname": test_tmp.org_ouput_file,821 attachment_bundles = []
822 "mime_type": "text/plain",822 for attachment in test_tmp.attachments:
823 "content": base64.standard_b64encode(stdout_text)823 data_bundle = attachment.generate_bundle(adb=adb, resultsdir=resultdir)
824 },824 if data_bundle:
825 {825 attachment_bundles.append(data_bundle)
826 "pathname": 'stderr.log',826
827 "mime_type": "text/plain",827 bundle['test_runs'][0]["attachments"] = attachment_bundles
828 "content": base64.standard_b64encode(stderr_text)828
829 }829 ##following used for the attachment for monkeyrunner test
830 ]
831
832 _gather_screencaps(resultdir, adb, bundle, config)
833 _gather_tombstones(adb, bundle, config)
834
835 for attach in attachments:830 for attach in attachments:
836 if os.path.exists(attach):831 if os.path.exists(attach):
837 with open(attach, 'rb') as stream:832 with open(attach, 'rb') as stream:
@@ -843,52 +838,6 @@
843 "content": base64.standard_b64encode(data)})838 "content": base64.standard_b64encode(data)})
844 return bundle839 return bundle
845840
846def _gather_screencaps(resultdir, adb, bundle, config):
847 """
848 Extension of the generate bundle function.
849 Grabs the screencaps and appends them to the bundle.
850 """
851 screencap_path = os.path.join(resultdir, 'screencap.png')
852 if adb.exists(screencap_path):
853 tmp_path = os.path.join(config.tempdir_host, 'screencap.png')
854 adb.pull(screencap_path, tmp_path)
855 with open(tmp_path, 'rb') as stream:
856 data = stream.read()
857 if data:
858 bundle['test_runs'][0]["attachments"].append({
859 "pathname": 'screencap.png',
860 "mime_type": 'image/png',
861 "content": base64.standard_b64encode(data)})
862 os.unlink(tmp_path)
863
864
865def _gather_tombstones(adb , bundle, config):
866 """
867 Extension of the generate bundle function.
868 Grabs the tombstones and appends them to the bundle.
869 """
870 tombstone_path = '/data/tombstones'
871 tombstone_zip = os.path.join(config.tempdir_host,'tombstones.zip')
872 if adb.exists(tombstone_path):
873 tmp_path = os.path.join(config.tempdir_host, 'tombstones')
874 adb.pull(tombstone_path, tmp_path)
875 adb.shell("rm -R " + tombstone_path)
876 zipf = zipfile.ZipFile(tombstone_zip, mode='w')
877 for rootdir, dirs, files in os.walk(tmp_path):
878 for f in files:
879 zipf.write(os.path.join(rootdir, f), arcname=f)
880 zipf.close()
881
882 with open(tombstone_zip, 'rb') as stream:
883 data = stream.read()
884 if data:
885 bundle['test_runs'][0]["attachments"].append({
886 "pathname": 'tombstones.zip',
887 "mime_type": 'application/zip',
888 "content": base64.standard_b64encode(data)})
889 os.unlink(tombstone_zip)
890
891
892class show(AndroidResultCommand):841class show(AndroidResultCommand):
893 """842 """
894 Display the output from a previous test that run on the specified device843 Display the output from a previous test that run on the specified device
895844
896845
=== modified file 'lava_android_test/test_definitions/cts.py'
--- lava_android_test/test_definitions/cts.py 2013-03-20 08:20:57 +0000
+++ lava_android_test/test_definitions/cts.py 2013-05-18 08:57:37 +0000
@@ -45,7 +45,13 @@
45 "\s+(?P<result>\S+)\s*$")45 "\s+(?P<result>\S+)\s*$")
46parser = lava_android_test.testdef.AndroidTestParser(pattern=pattern,46parser = lava_android_test.testdef.AndroidTestParser(pattern=pattern,
47 fixupdict={'PASS': 'pass', 'FAIL': 'fail'})47 fixupdict={'PASS': 'pass', 'FAIL': 'fail'})
48
49attachments = [lava_android_test.testdef.Attachment(
50 pathname="/data/local/tmp/cts-results.zip",
51 mime_type="application/zip")
52 ]
48testobj = lava_android_test.testdef.AndroidTest(testname=test_name,53testobj = lava_android_test.testdef.AndroidTest(testname=test_name,
49 installer=inst,54 installer=inst,
50 runner=run,55 runner=run,
51 parser=parser)56 parser=parser,
57 attachments=attachments)
5258
=== modified file 'lava_android_test/test_definitions/cts/cts_wrapper.py'
--- lava_android_test/test_definitions/cts/cts_wrapper.py 2013-05-06 08:26:27 +0000
+++ lava_android_test/test_definitions/cts/cts_wrapper.py 2013-05-18 08:57:37 +0000
@@ -27,6 +27,7 @@
27import xml.dom.minidom27import xml.dom.minidom
28from lava_android_test.adb import ADB28from lava_android_test.adb import ADB
29from lava_android_test.utils import stop_at_pattern29from lava_android_test.utils import stop_at_pattern
30from lava_android_test.utils import find_files
3031
31adb = ADB(sys.argv[1])32adb = ADB(sys.argv[1])
32curdir = os.path.realpath(os.path.dirname(__file__))33curdir = os.path.realpath(os.path.dirname(__file__))
@@ -53,6 +54,10 @@
53 finally:54 finally:
54 proc_cts.sendcontrol('C')55 proc_cts.sendcontrol('C')
55 proc_cts.sendline('')56 proc_cts.sendline('')
57 target_dir = os.path.join(os.getcwd(),
58 './android-cts/repository/results/')
59 for zip_f in find_files(target_dir, '.zip'):
60 adb.push(zip_f, '/data/local/tmp/cts-results.zip')
5661
57 return result62 return result
5863
@@ -247,7 +252,7 @@
247252
248 package_name = None253 package_name = None
249 plan_name = 'CTS'254 plan_name = 'CTS'
250 class_name= None255 class_name = None
251 method_name = None256 method_name = None
252 timeout = 36000257 timeout = 36000
253 #--cts_pkg cts_package_file --package package_name --timeout 36000258 #--cts_pkg cts_package_file --package package_name --timeout 36000
254259
=== modified file 'lava_android_test/testdef.py'
--- lava_android_test/testdef.py 2013-04-08 06:35:17 +0000
+++ lava_android_test/testdef.py 2013-05-18 08:57:37 +0000
@@ -17,13 +17,17 @@
17# You should have received a copy of the GNU General Public License17# You should have received a copy of the GNU General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.18# along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
20import base64
20import hashlib21import hashlib
22import logging
21import os23import os
22import re24import re
23import string25import string
24import time26import time
25import tempfile27import tempfile
26import decimal28import decimal
29import zipfile
30
27from datetime import datetime31from datetime import datetime
28from uuid import uuid432from uuid import uuid4
2933
@@ -35,6 +39,57 @@
35from linaro_dashboard_bundle.io import DocumentIO39from linaro_dashboard_bundle.io import DocumentIO
3640
3741
42class Attachment(object):
43
44 def __init__(self, pathname=None, mime_type=None):
45 self.pathname = pathname
46 self.mime_type = mime_type
47
48 def copy_to_result_dir(self, adb=None, resultsdir=None):
49 """
50 Copy the file specified by the pathname to result
51 directory of this time test, beacuse some test will
52 generate the result to the same path file.
53 And Please Note that pathname must be the absolute
54 path in the device.
55 """
56 if (not self.pathname) or (not self.pathname.startswith('/')):
57 return
58 if not resultsdir:
59 return
60 if not adb:
61 adb = ADB()
62 if not adb.exists(resultsdir):
63 adb.makedirs(resultsdir)
64 ret_code = adb.copy(self.pathname, os.path.join(resultsdir,
65 os.path.basename(self.pathname)))
66 if ret_code != 0:
67 raise RuntimeError(
68 "Failed to copy file '%s' to '%s' on device(%s)" %
69 (self.pathname, resultsdir, adb.get_serial()))
70
71 def generate_bundle(self, adb=None, resultsdir=None):
72 data_bundle = {}
73 if not self.pathname:
74 return data_bundle
75 if not adb:
76 adb = ADB()
77 config = get_config()
78 basename = os.path.basename(self.pathname)
79 android_path = os.path.join(resultsdir, basename)
80 if adb.exists(android_path):
81 tmp_path = os.path.join(config.tempdir_host, basename)
82 adb.pull(android_path, tmp_path)
83 with open(tmp_path, 'rb') as stream:
84 data = stream.read()
85 if data:
86 data_bundle = {"pathname": basename,
87 "mime_type": self.mime_type,
88 "content": base64.standard_b64encode(data)}
89 os.unlink(tmp_path)
90 return data_bundle
91
92
38class AndroidTest(ITest):93class AndroidTest(ITest):
39 """Base class for defining tests.94 """Base class for defining tests.
4095
@@ -49,6 +104,12 @@
49 parser - AbrekParser instance to use104 parser - AbrekParser instance to use
50 """105 """
51 adb = ADB()106 adb = ADB()
107 default_attachments = [
108 Attachment(pathname="stderr.log", mime_type="text/plain"),
109 Attachment(pathname="stdout.log", mime_type="text/plain"),
110 Attachment(pathname="screencap.png", mime_type="image/png"),
111 Attachment(pathname="tombstones.zip", mime_type="application/zip")
112 ]
52113
53 def setadb(self, adb=None):114 def setadb(self, adb=None):
54 self.adb = adb115 self.adb = adb
@@ -58,7 +119,8 @@
58119
59 def __init__(self, testname, version="", installer=None, runner=None,120 def __init__(self, testname, version="", installer=None, runner=None,
60 parser=None, default_options=None,121 parser=None, default_options=None,
61 org_ouput_file='stdout.log'):122 org_ouput_file='stdout.log',
123 attachments=[]):
62 self.testname = testname124 self.testname = testname
63 self.version = version125 self.version = version
64 self.installer = installer126 self.installer = installer
@@ -67,6 +129,13 @@
67 self.default_options = default_options129 self.default_options = default_options
68 self.org_ouput_file = org_ouput_file130 self.org_ouput_file = org_ouput_file
69 self.origdir = os.path.abspath(os.curdir)131 self.origdir = os.path.abspath(os.curdir)
132 self.attachments = self.default_attachments
133 if self.org_ouput_file and (self.org_ouput_file != "stdout.log"):
134 self.attachments.append(
135 Attachment(pathname=self.org_ouput_file,
136 mime_type="text/plain"))
137 if attachments:
138 self.attachments.extend(attachments)
70139
71 def set_runner(self, runner=None):140 def set_runner(self, runner=None):
72 self.runner = runner141 self.runner = runner
@@ -153,7 +222,7 @@
153 ]222 ]
154 }223 }
155 if run_options:224 if run_options:
156 bundle['test_runs'][0]['attributes']['run_options'] = run_options225 bundle['test_runs'][0]['attributes']['run_options'] = run_options
157 self._add_install_options(bundle, config)226 self._add_install_options(bundle, config)
158 filename_host = os.path.join(config.tempdir_host, 'testdata.json')227 filename_host = os.path.join(config.tempdir_host, 'testdata.json')
159 write_file(DocumentIO.dumps(bundle), filename_host)228 write_file(DocumentIO.dumps(bundle), filename_host)
@@ -177,7 +246,8 @@
177 self.resultsdir = os.path.join(config.resultsdir_android, resultname)246 self.resultsdir = os.path.join(config.resultsdir_android, resultname)
178 self.adb.makedirs(self.resultsdir)247 self.adb.makedirs(self.resultsdir)
179 self.runner.run(self.resultsdir, run_options=run_options)248 self.runner.run(self.resultsdir, run_options=run_options)
180 self._copyorgoutputfile(self.resultsdir)249 self._gather_tombstones(self.resultsdir)
250 self._copyattachments(self.resultsdir)
181 self._screencap(self.resultsdir)251 self._screencap(self.resultsdir)
182 self._savetestdata(str(uuid4()), run_options=run_options)252 self._savetestdata(str(uuid4()), run_options=run_options)
183 result_id = os.path.basename(self.resultsdir)253 result_id = os.path.basename(self.resultsdir)
@@ -190,17 +260,30 @@
190 self.adb.shell('%s %s' % (target_path, os.path.join(resultsdir,260 self.adb.shell('%s %s' % (target_path, os.path.join(resultsdir,
191 'screencap.png')))261 'screencap.png')))
192262
193 def _copyorgoutputfile(self, resultsdir):263 def _gather_tombstones(self, resultsdir):
194 if self.org_ouput_file == 'stdout.log':264 """
195 return265 Extension of the generate bundle function.
196 if not self.adb.exists(resultsdir):266 Grabs the tombstones and appends them to the bundle.
197 self.adb.makedirs(resultsdir)267 """
198 ret_code = self.adb.copy(self.org_ouput_file, os.path.join(resultsdir,268 config = get_config()
199 os.path.basename(self.org_ouput_file)))269 tombstone_path = '/data/tombstones'
200 if ret_code != 0:270 tombstone_zip = os.path.join(config.tempdir_host, 'tombstones.zip')
201 raise RuntimeError(271 if self.adb.exists(tombstone_path):
202 "Failed to copy file '%s' to '%s' for test(%s)" %272 tmp_path = os.path.join(config.tempdir_host, 'tombstones')
203 (self.org_ouput_file, resultsdir, self.testname))273 self.adb.pull(tombstone_path, tmp_path)
274 self.adb.shell("rm -R " + tombstone_path)
275 zipf = zipfile.ZipFile(tombstone_zip, mode='w')
276 for rootdir, dirs, files in os.walk(tmp_path):
277 for f in files:
278 zipf.write(os.path.join(rootdir, f), arcname=f)
279 zipf.close()
280 self.adb.push(tombstone_zip, os.path.join(resultsdir,
281 'tombstones.zip'))
282 os.unlink(tombstone_zip)
283
284 def _copyattachments(self, resultsdir):
285 for attachment in self.attachments:
286 attachment.copy_to_result_dir(adb=self.adb, resultsdir=resultsdir)
204287
205 def parse(self, resultname):288 def parse(self, resultname):
206 if not self.parser:289 if not self.parser:
@@ -607,6 +690,7 @@
607 self.fixmeasurements()690 self.fixmeasurements()
608 self.fixids()691 self.fixids()
609692
693
610class AndroidSimpleTestParser(AndroidTestParser):694class AndroidSimpleTestParser(AndroidTestParser):
611695
612 def real_parse(self, result_filename='stdout.log',696 def real_parse(self, result_filename='stdout.log',

Subscribers

People subscribed via source and target branches