Merge lp:~liuyq0307/lava-android-test/command-file into lp:lava-android-test

Proposed by Yongqin Liu
Status: Superseded
Proposed branch: lp:~liuyq0307/lava-android-test/command-file
Merge into: lp:lava-android-test
Diff against target: 240 lines (+91/-19)
2 files modified
lava_android_test/commands.py (+54/-16)
lava_android_test/testdef.py (+37/-3)
To merge this branch: bzr merge lp:~liuyq0307/lava-android-test/command-file
Reviewer Review Type Date Requested Status
Linaro Validation Team Pending
Review via email: mp+97870@code.launchpad.net

This proposal supersedes a proposal from 2012-03-15.

This proposal has been superseded by a proposal from 2012-03-18.

Description of the change

1. Add support to push a specified android command file to android and run it on android.
2. Add some process for deal with the test result
3. Modify to use add_mutually_exclusive_group according review comment
4. Change result patterns to Parser member, so that we can change them out of the class

To post a comment you must log in.
Revision history for this message
Zygmunt Krynicki (zyga) wrote : Posted in a previous version of this proposal

32 + if self.args.android_command and self.args.command_file:
33 + raise LavaCommandError("Please specified one option of -c and -f")
34 + if not self.args.android_command and not self.args.command_file:
35 + raise LavaCommandError("Please specified one option of -c and -f")

You should use mutex group instead:

group = parser.add_mutually_exclusive_group()
group.add_argument('-f', ...)
group.add_argument('-c', ...)

Then argparse will this check for you.

53 + STEPS_HOST_PRE = ["wget %s -O %s" % (file_url, file_name)]

I'd like us to use python on the host if possible. Downloading stuff with wget eventually means we have no error handling. This can stay as-is but we should look at the problem of how we download anything throughout lava and fix it.

Revision history for this message
Zygmunt Krynicki (zyga) wrote :

+ if self.args.android_command and self.args.command_file:
39 + raise LavaCommandError("Please specified one option of -c and -f")
40 + if not self.args.android_command and not self.args.command_file:
41 + raise LavaCommandError("Please specified one option of -c and -f")

This won't be need if you indicate that both -c and -f are required

add_argument( ..., required=True)

Otherwise looks okay

148. By Yongqin Liu

modify to use the required option according to review comment

Unmerged revisions

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 2012-03-09 11:58:12 +0000
3+++ lava_android_test/commands.py 2012-03-18 08:48:17 +0000
4@@ -1,4 +1,4 @@
5-# Copyright (c) 2011, 2011 Linaro
6+# Copyright (c) 2011, 2012 Linaro
7 #
8 # Author: Linaro Validation Team <linaro-dev@lists.linaro.org>
9 #
10@@ -18,6 +18,7 @@
11 # along with this program. If not, see <http://www.gnu.org/licenses/>.
12 import os
13 import base64
14+import urlparse
15 import versiontools
16
17 from lava_tool.interface import Command as LAVACommand
18@@ -334,10 +335,14 @@
19 @classmethod
20 def register_arguments(cls, parser):
21 super(run_custom, cls).register_arguments(parser)
22- parser.add_argument('-c', '--android-command', action='append',
23+ group = parser.add_mutually_exclusive_group(required=True)
24+ group.add_argument('-c', '--android-command', action='append',
25 help=("Specified in the job file for using"
26 " in the real test action, so that "
27 "we can customize some test when need"))
28+ group.add_argument('-f', '--command-file',
29+ help=("Specified the command file that will be "
30+ "pushed into android and run."))
31 parser.add_argument('-p', '--parse-regex',
32 help=("Specified the regular expression used"
33 " for analyzing command output"))
34@@ -351,29 +356,58 @@
35 " to the specified FILE."))
36
37 def invoke(self):
38+
39+ config = get_config()
40 self.adb = ADB(self.args.serial)
41 test_name = 'custom'
42 ADB_SHELL_STEPS = []
43+ STEPS_HOST_PRE = []
44+ STEPS_ADB_PRE = []
45+ file_name = None
46 if self.args.android_command:
47 ADB_SHELL_STEPS = self.args.android_command
48+ test_name_suffix = 'command=[%s]' % (','.join(ADB_SHELL_STEPS))
49+ elif self.args.command_file:
50+ file_url = self.args.command_file
51+ urlpath = urlparse.urlsplit(file_url).path
52+ file_name = os.path.basename(urlpath)
53+ target_path = os.path.join(config.installdir_android,
54+ test_name, file_name)
55+ STEPS_HOST_PRE = ["wget %s -O %s" % (file_url, file_name)]
56+ STEPS_ADB_PRE = ["push %s %s" % (file_name, target_path)]
57+ ADB_SHELL_STEPS = ["chmod 777 %s" % target_path,
58+ target_path]
59+ test_name_suffix = 'command_file=%s' % file_name
60+
61 PATTERN = None
62 if self.args.parse_regex:
63 PATTERN = self.args.parse_regex
64
65 tip_msg = ''
66 if self.args.serial:
67- tip_msg = "Run following custom test(s) on device(%s):\n\t\t%s" % (
68- self.args.serial, '\n\t\t'.join(ADB_SHELL_STEPS))
69+ tip_msg = ("Run following custom test(s) on device(%s):"
70+ "\n\tcommands=%s"
71+ "\n\tcommand-file=%s\n") % (
72+ self.args.serial,
73+ '\n\t\t'.join(ADB_SHELL_STEPS),
74+ file_name)
75 else:
76- tip_msg = "Run following custom test(s):\n\t\t%s" % (
77- '\n\t\t'.join(ADB_SHELL_STEPS))
78+ tip_msg = ("Run following custom test(s):"
79+ "\n\t\tcommands=%s"
80+ "\n\tcommand-file=%s\n") % (
81+ '\n\t\t'.join(ADB_SHELL_STEPS),
82+ file_name)
83+
84 self.say_begin(tip_msg)
85
86 inst = AndroidTestInstaller()
87- run = AndroidTestRunner(adbshell_steps=ADB_SHELL_STEPS)
88+
89+ run = AndroidTestRunner(steps_host_pre=STEPS_HOST_PRE,
90+ steps_adb_pre=STEPS_ADB_PRE,
91+ adbshell_steps=ADB_SHELL_STEPS)
92 parser = AndroidTestParser(pattern=PATTERN)
93- test = AndroidTest(testname=test_name, installer=inst,
94- runner=run, parser=parser)
95+ test = AndroidTest(testname=test_name,
96+ installer=inst, runner=run, parser=parser)
97 test.parser.results = {'test_results': []}
98 test.setadb(self.adb)
99
100@@ -387,7 +421,8 @@
101 if not os.path.exists(output_dir):
102 os.makedirs(output_dir)
103 bundle = generate_bundle(self.args.serial,
104- result_id, test=test)
105+ result_id, test=test,
106+ test_id='%s(%s)' % (test_name, test_name_suffix))
107 with open(self.args.output, "wt") as stream:
108 DocumentIO.dump(stream, bundle)
109
110@@ -444,14 +479,14 @@
111 pass
112
113
114-def generate_combined_bundle(serial=None, result_ids=None, test=None):
115+def generate_combined_bundle(serial=None, result_ids=None, test=None, test_id=None):
116 if result_ids is None:
117 return {}
118
119 bundle = None
120
121 for rid in result_ids:
122- b = generate_bundle(serial, rid, test=None)
123+ b = generate_bundle(serial, rid, test, test_id)
124 if rid == result_ids[0]:
125 bundle = b
126 else:
127@@ -460,7 +495,7 @@
128 return bundle
129
130
131-def generate_bundle(serial=None, result_id=None, test=None):
132+def generate_bundle(serial=None, result_id=None, test=None, test_id=None):
133 if result_id is None:
134 return {}
135 config = get_config()
136@@ -477,19 +512,22 @@
137 else:
138 test_tmp = testloader(bundle['test_runs'][0]['test_id'], serial)
139
140+ if test_id:
141+ bundle['test_runs'][0]['test_id'] = test_id
142+
143 test_tmp.parse(result_id)
144 stdout_text = adb.read_file(os.path.join(resultdir,
145- os.path.basename(test.org_ouput_file)))
146+ os.path.basename(test_tmp.org_ouput_file)))
147 if stdout_text is None:
148 stdout_text = ''
149 stderr_text = adb.read_file(os.path.join(resultdir, 'stderr.log'))
150 if stderr_text is None:
151 stderr_text = ''
152- bundle['test_runs'][0]["test_results"] = test.parser.results[
153+ bundle['test_runs'][0]["test_results"] = test_tmp.parser.results[
154 "test_results"]
155 bundle['test_runs'][0]["attachments"] = [
156 {
157- "pathname": test.org_ouput_file,
158+ "pathname": test_tmp.org_ouput_file,
159 "mime_type": "text/plain",
160 "content": base64.standard_b64encode(stdout_text)
161 },
162
163=== modified file 'lava_android_test/testdef.py'
164--- lava_android_test/testdef.py 2012-03-09 11:58:12 +0000
165+++ lava_android_test/testdef.py 2012-03-18 08:48:17 +0000
166@@ -20,6 +20,7 @@
167 import hashlib
168 import os
169 import re
170+import string
171 import sys
172 import time
173 import tempfile
174@@ -348,6 +349,10 @@
175
176 class AndroidTestParser(object):
177 adb = ADB()
178+ PASS_PATS = ['PASS', 'OK', 'TRUE', 'DONE']
179+ FAIL_PATS = ['FAIL', 'NG', 'FALSE']
180+ SKIP_PATS = ['SKIP']
181+
182 """Base class for defining a test parser
183
184 This class can be used as-is for simple results parsers, but will
185@@ -434,8 +439,7 @@
186 if data.get('result') is None:
187 data['result'] = test_ok and 'pass' or 'fail'
188 self.results['test_results'].append(data)
189- if self.fixupdict:
190- self.fixresults(self.fixupdict)
191+ self.fixresults(self.fixupdict)
192 if self.appendall:
193 self.appendtoall(self.appendall)
194 self.fixmeasurements()
195@@ -469,7 +473,29 @@
196 """
197 for t in self.results['test_results']:
198 if "result" in t:
199- t['result'] = fixupdict[t['result']]
200+ if not fixupdict:
201+ if self.is_result_match(t['result'], self.PASS_PATS):
202+ t['result'] = 'pass'
203+ elif self.is_result_match(t['result'], self.FAIL_PATS):
204+ t['result'] = 'fail'
205+ elif self.is_result_match(t['result'], self.SKIP_PATS):
206+ t['result'] = 'skip'
207+ else:
208+ t['result'] = 'unknown'
209+ elif t['result'] in fixupdict:
210+ t['result'] = fixupdict[t['result']]
211+ else:
212+ t['result'] = 'unknown'
213+
214+ def is_result_match(self, result, patterns=[]):
215+ cap_result = string.upper(result)
216+ for pattern in patterns:
217+ cap_pattern = string.upper(pattern)
218+ pat_index = string.find(cap_result, cap_pattern)
219+ if pat_index > -1:
220+ return True
221+
222+ return False
223
224 def fixmeasurements(self):
225 """Measurements are often read as strings, but need to be float
226@@ -495,6 +521,14 @@
227 def setadb(self, adb=None):
228 self.adb = adb
229
230+ def set_result_patterns(self, pass_pat=[], fail_pat=[], skip_pat=[]):
231+ if pass_pat:
232+ self.PASS_PATS = pass_pat
233+ if fail_pat:
234+ self.FAIL_PATS = fail_pat
235+ if skip_pat:
236+ self.SKIP_PATS = skip_pat
237+
238
239 def _run_steps_host(steps=[], serial=None, option=None, resultsdir=None):
240 adb = ADB(serial)

Subscribers

People subscribed via source and target branches