Merge lp:~liuyq0307/lava-android-test/cts-update into lp:lava-android-test
- cts-update
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Michael Hudson-Doyle |
Approved revision: | 200 |
Merged at revision: | 183 |
Proposed branch: | lp:~liuyq0307/lava-android-test/cts-update |
Merge into: | lp:lava-android-test |
Diff against target: |
832 lines (+492/-125) 10 files modified
lava_android_test/adb.py (+89/-27) lava_android_test/commands.py (+14/-29) lava_android_test/test_definitions/android-0xbenchmark/android_0xbenchmark_wait.py (+4/-9) lava_android_test/test_definitions/cts.py (+1/-1) lava_android_test/test_definitions/cts/cts_list_result_wrapper.sh (+26/-0) lava_android_test/test_definitions/cts/cts_prepare.sh (+130/-0) lava_android_test/test_definitions/cts/cts_redirect.sh (+24/-0) lava_android_test/test_definitions/cts/cts_run_wrapper.sh (+4/-59) lava_android_test/test_definitions/cts/cts_wrapper.py (+174/-0) lava_android_test/utils.py (+26/-0) |
To merge this branch: | bzr merge lp:~liuyq0307/lava-android-test/cts-update |
Related bugs: | |
Related blueprints: |
Investigate Failed Android Jobs
(Essential)
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Linaro Validation Team | Pending | ||
Review via email: mp+112491@code.launchpad.net |
Commit message
Description of the change
Update the CTS test packages
In cts_prepare.sh there are some steps need to be done before the CTS test.
But have not found the right method to do this.
And it seems not affect the execution of CTS test.
There are the possibilities that some test cases will fail because of the lack of these settings.
If this is ture, then let first keep this information in some place.
When we find the ways to do the settings, delete the related information that time.
From now the possible methods I can think is to do the automatic settings by monkeyrunner script or instruments, but it seems not much flexible. When we add other settings later, these scripts will need update again.:(
But here first please review the entire follow of CTS test, the above problem should only be limited to the cts_prepare.sh file.
- 195. By Yongqin Liu
-
add adb reconnect for adb command
- 196. By Yongqin Liu
-
modify the bug that not pass quiet parameter
- 197. By Yongqin Liu
-
decrease the sleep time after disconnect, and add status before the reconnect
- 198. By Yongqin Liu
-
modify the bug about return value
- 199. By Yongqin Liu
-
merge with trunk
Andy Doan (doanac) wrote : | # |
- 200. By Yongqin Liu
-
modify the type conncect of connect
Yongqin Liu (liuyq0307) wrote : | # |
> adb.py:
>
> 149 + def conncect(self):
>
> can we fix the spelling to "connect"
Sorry, have updated.
Please review again.
Andy Doan (doanac) wrote : | # |
A question on cts.py:
338 +RUN_STEPS_HOST_PRE = ['python %s/cts/
The "python" command should work as expected in our old pip/virtualenv style deployment. Will this work in our new buildout style? In other words, when I run:
. /srv/lava/
which python
I get "/usr/bin/python". I don't know for sure if this will pick up the lava-android-test python path. It via inheriting an envionrment from the parent process. You may want to double-check though.
Other wise, seems good.
Michael Hudson-Doyle (mwhudson) wrote : | # |
Andy Doan <email address hidden> writes:
> A question on cts.py:
>
> 338 +RUN_STEPS_HOST_PRE = ['python %s/cts/
>
> The "python" command should work as expected in our old pip/virtualenv style deployment. Will this work in our new buildout style? In other words, when I run:
>
> . /srv/lava/
> which python
>
> I get "/usr/bin/python". I don't know for sure if this will pick up
> the lava-android-test python path.
I don't think it will. We can get buildout to create a 'python'
interpreter in the style of virtualenv though.
> It via inheriting an envionrment from the parent process. You may want
> to double-check though.
>
> Other wise, seems good.
Michael Hudson-Doyle (mwhudson) wrote : | # |
> I don't think it will. We can get buildout to create a 'python'
> interpreter in the style of virtualenv though.
I've done this now.
Preview Diff
1 | === modified file 'lava_android_test/adb.py' |
2 | --- lava_android_test/adb.py 2012-05-23 03:50:55 +0000 |
3 | +++ lava_android_test/adb.py 2012-07-02 01:59:17 +0000 |
4 | @@ -17,11 +17,12 @@ |
5 | # You should have received a copy of the GNU General Public License |
6 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
7 | |
8 | -import threading |
9 | import os |
10 | import re |
11 | import subprocess |
12 | import tempfile |
13 | +import threading |
14 | +import time |
15 | |
16 | from Queue import Queue |
17 | from lava_android_test.config import get_config |
18 | @@ -42,10 +43,23 @@ |
19 | target_dir = config.tempdir_android |
20 | |
21 | def __init__(self, serial=None, quiet=True): |
22 | + self.cmdExecutor = CommandExecutor(quiet) |
23 | if serial is not None: |
24 | self.serial = serial |
25 | self.adb = 'adb -s %s' % serial |
26 | - self.cmdExecutor = CommandExecutor(quiet) |
27 | + else: |
28 | + self.serial = self.get_serial() |
29 | + |
30 | + def get_serial(self): |
31 | + if not self.serial: |
32 | + serial_ary = self.run_cmd_host('adb get-serialno')[1] |
33 | + serial = serial_ary[0].strip() |
34 | + if not serial or serial == 'unknown': |
35 | + return '' |
36 | + else: |
37 | + return serial |
38 | + else: |
39 | + return self.serial |
40 | |
41 | def push(self, source=None, target=None): |
42 | if source is None: |
43 | @@ -209,58 +223,106 @@ |
44 | os.remove(tmpfile_name) |
45 | return data |
46 | |
47 | - def get_shellcmdoutput(self, cmd=None): |
48 | + def get_shellcmdoutput(self, cmd=None, quiet=True): |
49 | + return self.get_shellcmdoutput_with_stderr(cmd=cmd, quiet=True)[0:2] |
50 | + |
51 | + def run_adb_cmd(self, cmd, quiet=True): |
52 | + return self.run_adb_cmd_with_stderr(cmd=cmd, quiet=quiet)[0:2] |
53 | + |
54 | + def run_cmd_host(self, cmd, quiet=True): |
55 | + return self.run_cmd_host_with_stderr(cmd, quiet=quiet)[0:2] |
56 | + |
57 | + def get_shellcmdoutput_with_stderr(self, cmd=None, quiet=True): |
58 | if cmd is None: |
59 | return None |
60 | - cmd = '%s shell %s' % (self.adb, cmd) |
61 | - return self.run_cmd_host(cmd) |
62 | - |
63 | - def run_cmd_host(self, cmd, quiet=True): |
64 | - result = self.cmdExecutor.run(cmd, quiet) |
65 | - return (result.returncode, result.stdout) |
66 | - |
67 | - def run_adb_cmd(self, cmd, quiet=True): |
68 | - cmd = '%s %s' % (self.adb, cmd) |
69 | - result = self.cmdExecutor.run(cmd, quiet) |
70 | - return (result.returncode, result.stdout) |
71 | - |
72 | - def devices(self): |
73 | - return self.run_cmd_host('%s devices' % self.adb) |
74 | + return self.run_adb_cmd_with_stderr(cmd='shell %s' % cmd, quiet=quiet) |
75 | + |
76 | + def run_adb_cmd_with_stderr(self, cmd, quiet=True): |
77 | + if not self.isDeviceConnected(): |
78 | + print ("Reconnect adb connection of device(%s) " |
79 | + "for running command[%s]") % (self.get_serial(), cmd) |
80 | + if not self.reconnect(): |
81 | + raise Exception('Failed to connect the device(%s)' % ( |
82 | + self.get_serial())) |
83 | + return self.run_cmd_host_with_stderr(cmd='%s %s' % (self.adb, cmd), |
84 | + quiet=quiet) |
85 | + |
86 | + def run_cmd_host_with_stderr(self, cmd, quiet=True): |
87 | + result = self.cmdExecutor.run(cmd, quiet=quiet) |
88 | + return (result.returncode, result.stdout, result.stderr) |
89 | |
90 | def run_adb_shell_for_test(self, cmd, stdoutlog=None, |
91 | stderrlog=None, quiet=False): |
92 | - cmd = '%s shell %s' % (self.adb, cmd) |
93 | - result = self.cmdExecutor.run(cmd, quiet) |
94 | - if result.returncode != 0: |
95 | - return result.returncode |
96 | - self.push_stream_to_device(result.stdout, stdoutlog) |
97 | - self.push_stream_to_device(result.stderr, stderrlog) |
98 | - return result.returncode |
99 | + (ret_code, stdout, stderr) = self.get_shellcmdoutput_with_stderr( |
100 | + cmd=cmd, |
101 | + quiet=quiet) |
102 | + if ret_code != 0: |
103 | + return ret_code |
104 | + self.push_stream_to_device(stdout, stdoutlog) |
105 | + self.push_stream_to_device(stderr, stderrlog) |
106 | + return ret_code |
107 | |
108 | def push_stream_to_device(self, stream_lines, path): |
109 | + if self.serial: |
110 | + android_info = 'android(%s)' % self.serial |
111 | + else: |
112 | + android_info = 'android' |
113 | + |
114 | + if not self.isDeviceConnected(): |
115 | + if not self.reconnect(): |
116 | + raise Exception('Failed to pull file(%s) to %s, ' |
117 | + 'because the device is not connected' % ( |
118 | + path, android_info)) |
119 | basename = os.path.basename(path) |
120 | tmp_path = os.path.join(config.tempdir_host, basename) |
121 | if self.exists(path): |
122 | retcode = self.pull(path, tmp_path) |
123 | if retcode != 0: |
124 | raise Exception( |
125 | - 'Failed to pull file(%s)stdout to android %s' % path) |
126 | + 'Failed to pull file(%s) to %s' % (path, android_info)) |
127 | |
128 | with open(tmp_path, 'a') as tmp_fd: |
129 | tmp_fd.writelines(stream_lines) |
130 | tmp_fd.close() |
131 | |
132 | if self.push(tmp_path, path)[1] is None: |
133 | - raise Exception('Failed to push stdout to android %s' % path) |
134 | + raise Exception( |
135 | + 'Failed to pull file(%s) to %s' % (path, android_info)) |
136 | os.remove(tmp_path) |
137 | |
138 | + def devices(self): |
139 | + return self.run_cmd_host('%s devices' % self.adb) |
140 | + |
141 | def isDeviceConnected(self): |
142 | - status, lines = self.run_cmd_host('%s get-state' % self.adb) |
143 | + lines = self.run_cmd_host('%s get-state' % self.adb)[1] |
144 | for line in lines: |
145 | if 'device' in line: |
146 | return True |
147 | return False |
148 | |
149 | + def connect(self): |
150 | + if self.serial: |
151 | + self.run_cmd_host('adb connect %s' % self.serial, quiet=False) |
152 | + return self.isDeviceConnected() |
153 | + return False |
154 | + |
155 | + def disconnect(self): |
156 | + if self.serial: |
157 | + self.run_cmd_host('adb disconnect %s' % self.serial, quiet=False) |
158 | + return not self.isDeviceConnected() |
159 | + return False |
160 | + |
161 | + def reconnect(self): |
162 | + for i in range(1, 5): |
163 | + print "LAVA: try to reconnect the device(%s) %i/5 times" % ( |
164 | + self.serial, i) |
165 | + if self.disconnect(): |
166 | + time.sleep(2) |
167 | + if self.connect(): |
168 | + return True |
169 | + time.sleep(5) |
170 | + return False |
171 | + |
172 | |
173 | class CommandExecutor(object): |
174 | def __init__(self, quiet=True): |
175 | |
176 | === modified file 'lava_android_test/commands.py' |
177 | --- lava_android_test/commands.py 2012-06-28 09:52:29 +0000 |
178 | +++ lava_android_test/commands.py 2012-07-02 01:59:17 +0000 |
179 | @@ -152,13 +152,7 @@ |
180 | return self.adb.exists(test_dir) |
181 | |
182 | def get_device_serial(self): |
183 | - if not self.args.serial: |
184 | - serial_ary = ADB().run_cmd_host('adb get-serialno')[1] |
185 | - serial = serial_ary[0].strip() |
186 | - if not serial or serial == 'unknown': |
187 | - return '' |
188 | - else: |
189 | - return serial |
190 | + return ADB(self.args.serial).get_serial() |
191 | |
192 | def assertDeviceIsConnected(self): |
193 | if not self.adb.isDeviceConnected(): |
194 | @@ -169,7 +163,12 @@ |
195 | raise Exception("No device found") |
196 | |
197 | def invoke(self): |
198 | - self.adb = ADB(self.args.serial) |
199 | + serial = self.get_device_serial() |
200 | + if not serial: |
201 | + raise LavaCommandError("No device attached") |
202 | + self.serial = serial |
203 | + self.adb = ADB(self.serial) |
204 | + |
205 | try: |
206 | self.assertDeviceIsConnected() |
207 | except Exception as err: |
208 | @@ -388,7 +387,6 @@ |
209 | |
210 | def invoke_sub(self): |
211 | |
212 | - config = get_config() |
213 | test_name = 'custom' |
214 | ADB_SHELL_STEPS = [] |
215 | STEPS_HOST_PRE = [] |
216 | @@ -404,7 +402,7 @@ |
217 | file_url = self.args.command_file |
218 | urlpath = urlparse.urlsplit(file_url).path |
219 | file_name = os.path.basename(urlpath) |
220 | - target_path = os.path.join(config.installdir_android, |
221 | + target_path = os.path.join(self.config.installdir_android, |
222 | test_name, file_name) |
223 | STEPS_HOST_PRE = ["wget %s -O %s" % (file_url, file_name)] |
224 | STEPS_ADB_PRE = ["push %s %s" % (file_name, target_path)] |
225 | @@ -490,25 +488,13 @@ |
226 | " bundle and finally save the complete bundle" |
227 | " to the specified FILE.")) |
228 | |
229 | - def invoke(self): |
230 | - config = get_config() |
231 | - if self.args.serial: |
232 | - serial = self.args.serial |
233 | - else: |
234 | - serial = self.get_device_serial() |
235 | - if not serial: |
236 | - raise LavaCommandError("No device attached") |
237 | - self.adb = ADB(serial) |
238 | - try: |
239 | - self.assertDeviceIsConnected() |
240 | - except Exception as err: |
241 | - raise LavaCommandError(err) |
242 | + def invoke_sub(self): |
243 | |
244 | if not utils.check_command_exist('monkeyrunner'): |
245 | raise LavaCommandError('The command monkeyrunner can not be found') |
246 | |
247 | if self.args.repo_type == 'git': |
248 | - target_dir = mkdtemp(prefix='git_repo', dir=config.tempdir_host) |
249 | + target_dir = mkdtemp(prefix='git_repo', dir=self.config.tempdir_host) |
250 | os.chmod(target_dir, 0755) |
251 | GitRepository(self.args.url).checkout(target_dir) |
252 | else: |
253 | @@ -524,7 +510,7 @@ |
254 | |
255 | tip_msg = ("Run monkeyrunner scripts in following url on device(%s):" |
256 | "\n\turl=%s") % ( |
257 | - self.args.serial, |
258 | + self.serial, |
259 | self.args.url) |
260 | |
261 | self.say_begin(tip_msg) |
262 | @@ -537,7 +523,7 @@ |
263 | if len(test_case_id) > 50: |
264 | test_case_id = '%s...' % (test_case_id[:50]) |
265 | try: |
266 | - sub_bundle = self.run_monkeyrunner_test(script, serial, |
267 | + sub_bundle = self.run_monkeyrunner_test(script, self.serial, |
268 | test_case_id) |
269 | test_result = {"test_case_id": test_case_id, |
270 | "result": 'pass'} |
271 | @@ -570,7 +556,6 @@ |
272 | self.say_end(tip_msg) |
273 | |
274 | def run_monkeyrunner_test(self, script, serial, test_case_id=None): |
275 | - config = get_config() |
276 | |
277 | inst = AndroidTestInstaller() |
278 | run = AndroidTestRunner(steps_host_pre=[ |
279 | @@ -590,11 +575,11 @@ |
280 | ##The png files here are generated to the host by the monkeyrunner |
281 | ##monkeyrunner is run on host, not on the target |
282 | bundle = {} |
283 | - org_png_file_list = utils.find_files(config.tempdir_host, |
284 | + org_png_file_list = utils.find_files(self.config.tempdir_host, |
285 | '.%s' % 'png') |
286 | result_id = test.run(quiet=self.args.quiet) |
287 | if self.args.output: |
288 | - cur_all_png_list = utils.find_files(config.tempdir_host, |
289 | + cur_all_png_list = utils.find_files(self.config.tempdir_host, |
290 | '.%s' % 'png') |
291 | new_png_list = set(cur_all_png_list).difference(org_png_file_list) |
292 | test_id = 'monkeyrunner(%s)' % (test_case_id) |
293 | |
294 | === modified file 'lava_android_test/test_definitions/android-0xbenchmark/android_0xbenchmark_wait.py' |
295 | --- lava_android_test/test_definitions/android-0xbenchmark/android_0xbenchmark_wait.py 2011-10-31 06:40:33 +0000 |
296 | +++ lava_android_test/test_definitions/android-0xbenchmark/android_0xbenchmark_wait.py 2012-07-02 01:59:17 +0000 |
297 | @@ -19,10 +19,11 @@ |
298 | # |
299 | # You should have received a copy of the GNU General Public License |
300 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
301 | -import pexpect |
302 | import sys |
303 | import time |
304 | |
305 | +from lava_android_test.utils import stop_at_pattern |
306 | + |
307 | if len(sys.argv) == 1: |
308 | adb_cmd = "adb" |
309 | else: |
310 | @@ -30,16 +31,10 @@ |
311 | |
312 | logcat_cmd = '%s logcat' % (adb_cmd) |
313 | pattern = "Displayed org.zeroxlab.zeroxbenchmark/.Report" |
314 | -try: |
315 | - proc = pexpect.spawn(logcat_cmd, logfile=sys.stdout) |
316 | - id = proc.expect([pattern, pexpect.EOF], timeout=2400) |
317 | - if id == 0: |
318 | - proc.sendcontrol('C') |
319 | -except pexpect.TIMEOUT: |
320 | + |
321 | +if not stop_at_pattern(command=logcat_cmd, pattern=pattern, timeout=2400): |
322 | print "0xbench Test: TIMEOUT Fail" |
323 | sys.exit(1) |
324 | -finally: |
325 | - proc.sendcontrol('C') |
326 | |
327 | time.sleep(3) |
328 | sys.exit(0) |
329 | |
330 | === modified file 'lava_android_test/test_definitions/cts.py' |
331 | --- lava_android_test/test_definitions/cts.py 2012-06-25 17:23:05 +0000 |
332 | +++ lava_android_test/test_definitions/cts.py 2012-07-02 01:59:17 +0000 |
333 | @@ -33,7 +33,7 @@ |
334 | |
335 | curdir = os.path.realpath(os.path.dirname(__file__)) |
336 | |
337 | -RUN_STEPS_HOST_PRE = ['/bin/bash %s/cts/cts_wrapper.sh $(SERIAL)' % curdir] |
338 | +RUN_STEPS_HOST_PRE = ['python %s/cts/cts_wrapper.py $(SERIAL)' % curdir] |
339 | |
340 | inst = lava_android_test.testdef.AndroidTestInstaller() |
341 | run = lava_android_test.testdef.AndroidTestRunner( |
342 | |
343 | === added file 'lava_android_test/test_definitions/cts/cts_list_result_wrapper.sh' |
344 | --- lava_android_test/test_definitions/cts/cts_list_result_wrapper.sh 1970-01-01 00:00:00 +0000 |
345 | +++ lava_android_test/test_definitions/cts/cts_list_result_wrapper.sh 2012-07-02 01:59:17 +0000 |
346 | @@ -0,0 +1,26 @@ |
347 | +#!/bin/bash |
348 | +# Copyright (C) 2012 Linaro Limited |
349 | + |
350 | +# Author: Linaro Validation Team <linaro-dev@lists.linaro.org> |
351 | +# |
352 | +# This file is part of LAVA Android Test. |
353 | +# |
354 | +# This program is free software: you can redistribute it and/or modify |
355 | +# it under the terms of the GNU General Public License as published by |
356 | +# the Free Software Foundation, either version 3 of the License, or |
357 | +# (at your option) any later version. |
358 | +# |
359 | +# This program is distributed in the hope that it will be useful, |
360 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
361 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
362 | +# GNU General Public License for more details. |
363 | +# |
364 | +# You should have received a copy of the GNU General Public License |
365 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
366 | + |
367 | +#http://source.android.com/compatibility/downloads.html |
368 | + |
369 | +echo "./android-cts/tools/cts-tradefed l r" |
370 | +./android-cts/tools/cts-tradefed l r |tee cts_list_results.log |
371 | + |
372 | +exit 0 |
373 | \ No newline at end of file |
374 | |
375 | === added file 'lava_android_test/test_definitions/cts/cts_prepare.sh' |
376 | --- lava_android_test/test_definitions/cts/cts_prepare.sh 1970-01-01 00:00:00 +0000 |
377 | +++ lava_android_test/test_definitions/cts/cts_prepare.sh 2012-07-02 01:59:17 +0000 |
378 | @@ -0,0 +1,130 @@ |
379 | +#!/bin/bash |
380 | +# Copyright (C) 2012 Linaro Limited |
381 | + |
382 | +# Author: Linaro Validation Team <linaro-dev@lists.linaro.org> |
383 | +# |
384 | +# This file is part of LAVA Android Test. |
385 | +# |
386 | +# This program is free software: you can redistribute it and/or modify |
387 | +# it under the terms of the GNU General Public License as published by |
388 | +# the Free Software Foundation, either version 3 of the License, or |
389 | +# (at your option) any later version. |
390 | +# |
391 | +# This program is distributed in the hope that it will be useful, |
392 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
393 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
394 | +# GNU General Public License for more details. |
395 | +# |
396 | +# You should have received a copy of the GNU General Public License |
397 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
398 | + |
399 | +#http://source.android.com/compatibility/downloads.html |
400 | + |
401 | +cts_pkg="android-cts-4.0.3_r3-linux_x86-arm.zip" |
402 | +media_pkg="android-cts-media-1.0.zip" |
403 | +site_url="https://dl.google.com/dl/android/cts/" |
404 | +#site_url="http://192.168.1.127/images/cts/" |
405 | +#export http_proxy=http://localhost:3128 |
406 | + |
407 | +cts_pkg_url="${site_url}${cts_pkg}" |
408 | +media_pkg_url="${site_url}${media_pkg}" |
409 | + |
410 | +ADB_OPTION="" |
411 | +SERIAL="" |
412 | +if [ "x${1}" != "x" ]; then |
413 | + ADB_OPTION="-s ${1}" |
414 | + SERIAL="${1}" |
415 | +fi |
416 | +ADB_CMD="adb ${ADB_OPTION}" |
417 | + |
418 | + |
419 | +function download_unzip(){ |
420 | + if [ -z "$1" ] || [ -z "$2" ]; then |
421 | + return |
422 | + fi |
423 | + url="${1}" |
424 | + pkg="${2}" |
425 | + |
426 | + echo "wget --connect-timeout=30 -S --progress=dot -e dotbytes=2M ${url} -O ${pkg}" |
427 | + wget -c -t 20 --connect-timeout=30 -S --progress=dot -e dotbytes=2M "${url}" -O ${pkg} |
428 | + if [ $? -ne 0 ]; then |
429 | + echo "Failed to get the package ${url}" |
430 | + exit 1 |
431 | + fi |
432 | + echo "unzip ${pkg}" |
433 | + unzip ${pkg} |
434 | + if [ $? -ne 0 ]; then |
435 | + echo "Faild to unzip the package " |
436 | + exit 1 |
437 | + fi |
438 | +} |
439 | + |
440 | +function main(){ |
441 | + rm -fr ${cts_pkg} ${media_pkg} android-cts |
442 | + download_unzip "${cts_pkg_url}" ${cts_pkg} |
443 | + download_unzip "${media_pkg_url}" ${media_pkg} |
444 | + |
445 | + echo "${ADB_CMD} shell mkdir /mnt/sdcard/test" |
446 | + ${ADB_CMD} shell mkdir /mnt/sdcard/test |
447 | + chmod +x copy_media.sh |
448 | + echo "copy_media.sh all ${ADB_OPTION}" |
449 | + /bin/bash ./copy_media.sh all ${ADB_OPTION} |
450 | + |
451 | + #1. Your phone should be running a user build (Android 4.0 and later) from source.android.com |
452 | + #2. Please refer to this link on the Android developer site and set up your device accordingly. |
453 | + #3. Make sure that your device has been flashed with a user build (Android 4.0and later) before you run CTS. |
454 | + ####Step 1~3 is done by deployment |
455 | + |
456 | + #4. You need to ensure the Text To Speech files are installed on the device. |
457 | + # You can check via Settings > Speech synthesis > Install voice data |
458 | + # before running CTS tests. |
459 | + # (Note that this assumes you have Android Market installed on the device, |
460 | + # if not you will need to install the files manually via adb) |
461 | + ##TODO don't know how to do this yet |
462 | + |
463 | + #5. Make sure the device has a SD card plugged in and the card is empty. |
464 | + # Warning: CTS may modify/erase data on the SD card plugged in to the device. |
465 | + #6. Do a factory data reset on the device (Settings > SD Card & phone storage >Factory data reset). |
466 | + # Warning: This will erase all user data from the phone. |
467 | + #7. Make sure no lock pattern is set on the device (Settings > Security > Screen Lock should be 'None'). |
468 | + #8. Make sure the "USB Debugging" development option is checked (Settings >Developer options > USB debugging). |
469 | + #9. Make sure Settings > Developer options > Stay Awake is checked |
470 | + #10. Make sure Settings > Developer options > Allow mock locations is checked |
471 | + ####Step 5~10 is done by deployment |
472 | + |
473 | + #11. Make sure device is connected to a functioning Wi-Fi network (Settings > WiFi) |
474 | + ${ADB_CMD} shell am start -a android.intent.action.MAIN -n com.android.settings/.Settings |
475 | + ${ADB_CMD} shell service call wifi 13 i32 1 |
476 | + sleep 5 |
477 | + |
478 | + #12. Make sure the device is at the home screen at the start of CTS (Press the home button). |
479 | + ${ADB_CMD} shell input keyevent 3 |
480 | + sleep 3 |
481 | + |
482 | + #13. While a device is running tests, it must not be used for any other tasks. |
483 | + #14. Do not press any keys on the device while CTS is running. |
484 | + # Pressing keys or touching the screen of a test device will interfere with the running tests and may lead to test failures. |
485 | + #####Steps 13~14 should be the ok because nobody will operation the test target. |
486 | + |
487 | + #15. Set up accessibility tests: |
488 | + echo "${ADB_CMD} install -r android-cts/repository/testcases/CtsDelegatingAccessibilityService.apk" |
489 | + ${ADB_CMD} install -r android-cts/repository/testcases/CtsDelegatingAccessibilityService.apk |
490 | + if [ $? -ne 0 ]; then |
491 | + echo "Faild to install CtsDelegatingAccessibilityService.apk" |
492 | + exit 1 |
493 | + fi |
494 | + ##TODO On the device, enable Settings > Accessibility > DelegatingAccessibility Service |
495 | + |
496 | + #16. Set up device administration tests: |
497 | + echo "${ADB_CMD} install -r android-cts/repository/testcases/CtsDeviceAdmin.apk" |
498 | + ${ADB_CMD} install -r android-cts/repository/testcases/CtsDeviceAdmin.apk |
499 | + if [ $? -ne 0 ]; then |
500 | + echo "Faild to install CtsDeviceAdmin.apk" |
501 | + exit 1 |
502 | + fi |
503 | + ##TODO On the device, enable Settings > Security > Device Administrators >android.deviceadmin.cts.CtsDeviceAdmin* settings |
504 | + |
505 | + exit 0 |
506 | +} |
507 | + |
508 | +main "$@" |
509 | |
510 | === added file 'lava_android_test/test_definitions/cts/cts_redirect.sh' |
511 | --- lava_android_test/test_definitions/cts/cts_redirect.sh 1970-01-01 00:00:00 +0000 |
512 | +++ lava_android_test/test_definitions/cts/cts_redirect.sh 2012-07-02 01:59:17 +0000 |
513 | @@ -0,0 +1,24 @@ |
514 | +#!/bin/bash |
515 | +# Copyright (C) 2012 Linaro Limited |
516 | + |
517 | +# Author: Linaro Validation Team <linaro-dev@lists.linaro.org> |
518 | +# |
519 | +# This file is part of LAVA Android Test. |
520 | +# |
521 | +# This program is free software: you can redistribute it and/or modify |
522 | +# it under the terms of the GNU General Public License as published by |
523 | +# the Free Software Foundation, either version 3 of the License, or |
524 | +# (at your option) any later version. |
525 | +# |
526 | +# This program is distributed in the hope that it will be useful, |
527 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
528 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
529 | +# GNU General Public License for more details. |
530 | +# |
531 | +# You should have received a copy of the GNU General Public License |
532 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
533 | + |
534 | +output_file=${1} && shift |
535 | +eval "$@" &> ${output_file} & |
536 | +echo $! |
537 | +exit 0 |
538 | |
539 | === renamed file 'lava_android_test/test_definitions/cts/cts_wrapper.sh' => 'lava_android_test/test_definitions/cts/cts_run_wrapper.sh' |
540 | --- lava_android_test/test_definitions/cts/cts_wrapper.sh 2012-02-10 18:16:42 +0000 |
541 | +++ lava_android_test/test_definitions/cts/cts_run_wrapper.sh 2012-07-02 01:59:17 +0000 |
542 | @@ -20,62 +20,7 @@ |
543 | |
544 | #http://source.android.com/compatibility/downloads.html |
545 | |
546 | -ADB_CMD="adb" |
547 | -if [ "x${1}" != "x" ]; then |
548 | - ADB_CMD="${ADB_CMD} -s ${1}" |
549 | -fi |
550 | - |
551 | -cts_url_txt='https://wiki.linaro.org/TestDataLinkPage?action=AttachFile&do=get&target=android-cts-url.txt' |
552 | -mix_zip_name='mix.zip' |
553 | -android_cts_name='android-cts.zip' |
554 | - |
555 | -rm -fr android-cts.zip android-cts |
556 | - |
557 | -echo "wget -i ${cts_url_txt} -O ${mix_zip_name}" |
558 | -wget -i "${cts_url_txt}" -O ${mix_zip_name} |
559 | -if [ $? -ne 0 ]; then |
560 | - echo "Failed to get the android-cts packages" |
561 | - exit 1 |
562 | -fi |
563 | -echo "tail --lines=+2 ${mix_zip_name}>${android_cts_name}" |
564 | -tail --lines=+2 ${mix_zip_name}>${android_cts_name} |
565 | -if [ $? -ne 0 ]; then |
566 | - echo "Failed to get the android-cts packages from downloaded packages" |
567 | - exit 1 |
568 | -fi |
569 | - |
570 | -echo "unzip ${android_cts_name}" |
571 | -unzip ${android_cts_name} |
572 | -if [ $? -ne 0 ]; then |
573 | - echo "Faild to unzip the android-cts packages" |
574 | - exit 1 |
575 | -fi |
576 | - |
577 | -echo "${ADB_CMD} install -r android-cts/repository/testcases/CtsDeviceAdmin.apk" |
578 | -${ADB_CMD} install -r android-cts/repository/testcases/CtsDeviceAdmin.apk |
579 | -if [ $? -ne 0 ]; then |
580 | - echo "Faild to install CtsDeviceAdmin.apk" |
581 | - exit 1 |
582 | -fi |
583 | - |
584 | -RET_CODE=0 |
585 | -#test_str='--package android.admin' |
586 | -test_str='--plan AppSecurity' |
587 | -test_str='--plan CTS' |
588 | -if [ "x${1}" != "x" ]; then |
589 | - echo "./android-cts/tools/cts-tradefed run cts --serial ${1} ${test_str}|tee cts_output.log" |
590 | - ./android-cts/tools/cts-tradefed run cts --serial ${1} ${test_str}|tee cts_output.log |
591 | - RET_CODE=$? |
592 | -else |
593 | - echo "./android-cts/tools/cts-tradefed run cts ${test_str}|tee cts_output.log" |
594 | - ./android-cts/tools/cts-tradefed run cts ${test_str}|tee cts_output.log |
595 | - RET_CODE=$? |
596 | -fi |
597 | -rm -f tee cts_output.log |
598 | -if [ ${RET_CODE} -ne 0 ]; then |
599 | - echo "Faild to run cts for test (${test_str})" |
600 | -### comment it so that we can get the test result that has been executed |
601 | -### otherwise we won't get any test result about cts |
602 | -# exit 1 |
603 | -fi |
604 | -exit 0 |
605 | +echo ./android-cts/tools/cts-tradefed "$@" |
606 | +./android-cts/tools/cts-tradefed "$@" |tee -a cts_output.log |
607 | + |
608 | +exit 0 |
609 | \ No newline at end of file |
610 | |
611 | === added file 'lava_android_test/test_definitions/cts/cts_wrapper.py' |
612 | --- lava_android_test/test_definitions/cts/cts_wrapper.py 1970-01-01 00:00:00 +0000 |
613 | +++ lava_android_test/test_definitions/cts/cts_wrapper.py 2012-07-02 01:59:17 +0000 |
614 | @@ -0,0 +1,174 @@ |
615 | +#!/usr/bin/python |
616 | + |
617 | +# Copyright (c) 2012 Linaro |
618 | + |
619 | +# Author: Linaro Validation Team <linaro-dev@lists.linaro.org> |
620 | +# |
621 | +# This file is part of LAVA Android Test. |
622 | +# |
623 | +# This program is free software: you can redistribute it and/or modify |
624 | +# it under the terms of the GNU General Public License as published by |
625 | +# the Free Software Foundation, either version 3 of the License, or |
626 | +# (at your option) any later version. |
627 | +# |
628 | +# This program is distributed in the hope that it will be useful, |
629 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
630 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
631 | +# GNU General Public License for more details. |
632 | +# |
633 | +# You should have received a copy of the GNU General Public License |
634 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
635 | + |
636 | +import os |
637 | +import re |
638 | +import sys |
639 | +from lava_android_test.adb import ADB |
640 | +from lava_android_test.utils import stop_at_pattern |
641 | + |
642 | +adb = ADB(sys.argv[1]) |
643 | +curdir = os.path.realpath(os.path.dirname(__file__)) |
644 | + |
645 | + |
646 | +def get_not_executed(): |
647 | + list_result_path = os.path.join(curdir, 'cts_list_result_wrapper.sh') |
648 | + list_result_cmd = "bash %s" % list_result_path |
649 | + |
650 | + pattern = 'CTS unknown' |
651 | + if not stop_at_pattern(command=list_result_cmd, |
652 | + pattern=pattern, timeout=5): |
653 | + print "Failed to list the cts result for device(%s)" % adb.get_serial() |
654 | + |
655 | + with open('cts_list_results.log') as fd: |
656 | + #0 17237 126 0 2012.06.23_03.31.49 CTS unknown |
657 | + pattern = ("\s*\d+\s+\d+\s+\d+\s+(?P<no_executed>\d+)" |
658 | + "\s+.+CTS\s+unknown\s*$") |
659 | + pat = re.compile(pattern) |
660 | + for line in fd.readlines(): |
661 | + match = pat.search(line) |
662 | + if not match: |
663 | + continue |
664 | + return match.groupdict()['no_executed'] |
665 | + return 0 |
666 | + |
667 | + |
668 | +def prepare_cts(): |
669 | + cts_prepare_path = os.path.join(curdir, 'cts_prepare.sh') |
670 | + cts_prepare_cmd = "bash %s" % cts_prepare_path |
671 | + if not stop_at_pattern(command="%s %s" % (cts_prepare_cmd, |
672 | + adb.get_serial()), |
673 | + timeout=18000): |
674 | + print "Preapration for CTS test times out" |
675 | + return False |
676 | + return True |
677 | + |
678 | + |
679 | +def run_cts_with_plan(cts_cmd=None): |
680 | + pattern = "Time:" |
681 | + plan_command = '--plan CTS' |
682 | + if cts_cmd: |
683 | + plan_command = "%s %s" % (cts_cmd, plan_command) |
684 | + if not stop_at_pattern(command=plan_command, pattern=pattern, |
685 | + timeout=36000): |
686 | + print "CTS test times out" |
687 | + return False |
688 | + |
689 | + return True |
690 | + |
691 | + |
692 | +def run_cts_continue(cts_cmd=None): |
693 | + pattern = "Time:" |
694 | + continue_command = '--continue-session 0' |
695 | + if cts_cmd: |
696 | + continue_command = "%s %s" % (cts_cmd, continue_command) |
697 | + |
698 | + while True: |
699 | + number_of_not_executed = get_not_executed() |
700 | + if number_of_not_executed and int(number_of_not_executed) > 0: |
701 | + print ('Reconnect the adb connection before continuing ' |
702 | + 'the CTS on device(%s)') % adb.get_serial() |
703 | + if not adb.reconnect(): |
704 | + print "Faile to reconnect the adb connection of device(%s)" % ( |
705 | + adb.get_serial()) |
706 | + break |
707 | + |
708 | + print "Continue the uncompleted CTS test on device(%s)" % ( |
709 | + adb.get_serial()) |
710 | + |
711 | + if not stop_at_pattern(command=continue_command, |
712 | + pattern=pattern, |
713 | + timeout=36000): |
714 | + print "CTS test times out" |
715 | + else: |
716 | + break |
717 | + |
718 | + |
719 | +def collect_log(command=None, output_file=None): |
720 | + if command and output_file: |
721 | + print 'Redirect the output of command[%s] to file[%s]' % (command, |
722 | + output_file) |
723 | + cmd = 'bash %s %s "%s"' % (os.path.join(curdir, 'cts_redirect.sh'), |
724 | + output_file, command) |
725 | + stdout = adb.run_cmd_host(cmd)[1] |
726 | + if stdout: |
727 | + return stdout[0].strip() |
728 | + |
729 | + return None |
730 | + |
731 | + |
732 | +def collect_logs(): |
733 | + |
734 | + kmsg = {'command': |
735 | + 'adb -s %s shell cat /proc/kmsg' % (adb.get_serial()), |
736 | + 'output_file': 'kmsg.log'} |
737 | + |
738 | + logcat = {'command': |
739 | + 'adb -s %s logcat -c; adb -s %s logcat -v time' % ( |
740 | + adb.get_serial(), adb.get_serial()), |
741 | + 'output_file': 'logcat.log'} |
742 | + |
743 | + ## define all the logs need to be collected |
744 | + logs = [kmsg, logcat] |
745 | + for log in logs: |
746 | + pid = collect_log(command=log.get('command'), |
747 | + output_file=log.get('output_file')) |
748 | + if pid: |
749 | + log['pid'] = pid |
750 | + return logs |
751 | + |
752 | + |
753 | +def print_log(logs=[]): |
754 | + for log in logs: |
755 | + log_file = log.get('output_file') |
756 | + if log_file: |
757 | + with open(log_file) as log_fd: |
758 | + print '=========Log file [%s] starts=========>>>>>' % log_file |
759 | + for line in log_fd.readlines(): |
760 | + print line.rstrip() |
761 | + print '<<<<<=========Log file [%s] ends=========' % log_file |
762 | + |
763 | + |
764 | +def main(): |
765 | + run_wrapper_path = os.path.join(curdir, 'cts_run_wrapper.sh') |
766 | + run_wrapper_cmd = "bash %s" % run_wrapper_path |
767 | + run_wrapper_cmd = '%s run cts --serial %s' % (run_wrapper_cmd, |
768 | + adb.get_serial()) |
769 | + |
770 | + logs = collect_logs() |
771 | + if not prepare_cts(): |
772 | + sys.exit(1) |
773 | + try: |
774 | + run_cts_with_plan(run_wrapper_cmd) |
775 | + run_cts_continue(run_wrapper_cmd) |
776 | + finally: |
777 | + for log in logs: |
778 | + pid = log.get('pid') |
779 | + if pid: |
780 | + adb.run_cmd_host('kill -9 %s' % pid) |
781 | + |
782 | + print_log(logs) |
783 | + |
784 | + sys.exit(0) |
785 | + |
786 | + |
787 | +if __name__ == '__main__': |
788 | + main() |
789 | |
790 | === modified file 'lava_android_test/utils.py' |
791 | --- lava_android_test/utils.py 2012-05-23 06:46:47 +0000 |
792 | +++ lava_android_test/utils.py 2012-07-02 01:59:17 +0000 |
793 | @@ -14,9 +14,11 @@ |
794 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
795 | import re |
796 | import os |
797 | +import pexpect |
798 | import shutil |
799 | import subprocess |
800 | import sys |
801 | +import time |
802 | import urllib2 |
803 | import urlparse |
804 | |
805 | @@ -174,3 +176,27 @@ |
806 | for f in flist: |
807 | if os.path.exists(f): |
808 | os.unlink(f) |
809 | + |
810 | + |
811 | +def stop_at_pattern(command=None, pattern=None, timeout=-1): |
812 | + if not command: |
813 | + return |
814 | + |
815 | + if not pattern: |
816 | + response = [pexpect.EOF] |
817 | + else: |
818 | + response = [pattern, pexpect.EOF] |
819 | + |
820 | + result = True |
821 | + proc = pexpect.spawn(command, logfile=sys.stdout) |
822 | + try: |
823 | + match_id = proc.expect(response, timeout=timeout) |
824 | + if match_id == 0: |
825 | + time.sleep(5) |
826 | + except pexpect.TIMEOUT: |
827 | + result = False |
828 | + finally: |
829 | + proc.sendcontrol('C') |
830 | + proc.sendline('') |
831 | + |
832 | + return result |
adb.py:
149 + def conncect(self):
can we fix the spelling to "connect"