blob: fedd2d75589198ecc94132ab91528cc534384a66 [file] [log] [blame]
Dan Albert8e1fdd72015-07-24 17:08:33 -07001#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3#
4# Copyright (C) 2015 The Android Open Source Project
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18from __future__ import print_function
19
20import hashlib
21import os
22import posixpath
23import random
24import shlex
25import shutil
26import subprocess
27import tempfile
28import unittest
29
30import mock
31
32import adb
33
34
Dan Alberte2b4a5f2015-07-28 14:53:03 -070035def requires_root(func):
36 def wrapper(self, *args):
37 if self.device.get_prop('ro.debuggable') != '1':
38 raise unittest.SkipTest('requires rootable build')
39
David Pursell606835a2015-09-08 17:17:02 -070040 was_root = self.device.shell(['id', '-un'])[0].strip() == 'root'
Dan Alberte2b4a5f2015-07-28 14:53:03 -070041 if not was_root:
42 self.device.root()
43 self.device.wait()
44
45 try:
46 func(self, *args)
47 finally:
48 if not was_root:
49 self.device.unroot()
50 self.device.wait()
51
52 return wrapper
53
54
Dan Albert8e1fdd72015-07-24 17:08:33 -070055class GetDeviceTest(unittest.TestCase):
56 def setUp(self):
57 self.android_serial = os.getenv('ANDROID_SERIAL')
Spencer Low3e7feda2015-07-30 01:19:52 -070058 if 'ANDROID_SERIAL' in os.environ:
59 del os.environ['ANDROID_SERIAL']
Dan Albert8e1fdd72015-07-24 17:08:33 -070060
61 def tearDown(self):
Spencer Low3e7feda2015-07-30 01:19:52 -070062 if self.android_serial is not None:
63 os.environ['ANDROID_SERIAL'] = self.android_serial
64 else:
65 if 'ANDROID_SERIAL' in os.environ:
66 del os.environ['ANDROID_SERIAL']
Dan Albert8e1fdd72015-07-24 17:08:33 -070067
68 @mock.patch('adb.device.get_devices')
69 def test_explicit(self, mock_get_devices):
70 mock_get_devices.return_value = ['foo', 'bar']
71 device = adb.get_device('foo')
72 self.assertEqual(device.serial, 'foo')
73
74 @mock.patch('adb.device.get_devices')
75 def test_from_env(self, mock_get_devices):
76 mock_get_devices.return_value = ['foo', 'bar']
77 os.environ['ANDROID_SERIAL'] = 'foo'
78 device = adb.get_device()
79 self.assertEqual(device.serial, 'foo')
80
81 @mock.patch('adb.device.get_devices')
82 def test_arg_beats_env(self, mock_get_devices):
83 mock_get_devices.return_value = ['foo', 'bar']
84 os.environ['ANDROID_SERIAL'] = 'bar'
85 device = adb.get_device('foo')
86 self.assertEqual(device.serial, 'foo')
87
88 @mock.patch('adb.device.get_devices')
89 def test_no_such_device(self, mock_get_devices):
90 mock_get_devices.return_value = ['foo', 'bar']
91 self.assertRaises(adb.DeviceNotFoundError, adb.get_device, ['baz'])
92
93 os.environ['ANDROID_SERIAL'] = 'baz'
94 self.assertRaises(adb.DeviceNotFoundError, adb.get_device)
95
96 @mock.patch('adb.device.get_devices')
97 def test_unique_device(self, mock_get_devices):
98 mock_get_devices.return_value = ['foo']
99 device = adb.get_device()
100 self.assertEqual(device.serial, 'foo')
101
102 @mock.patch('adb.device.get_devices')
103 def test_no_unique_device(self, mock_get_devices):
104 mock_get_devices.return_value = ['foo', 'bar']
105 self.assertRaises(adb.NoUniqueDeviceError, adb.get_device)
106
107
108class DeviceTest(unittest.TestCase):
109 def setUp(self):
110 self.device = adb.get_device()
111
112
113class ShellTest(DeviceTest):
114 def test_cat(self):
115 """Check that we can at least cat a file."""
David Pursell606835a2015-09-08 17:17:02 -0700116 out = self.device.shell(['cat', '/proc/uptime'])[0].strip()
Dan Albert8e1fdd72015-07-24 17:08:33 -0700117 elements = out.split()
118 self.assertEqual(len(elements), 2)
119
120 uptime, idle = elements
121 self.assertGreater(float(uptime), 0.0)
122 self.assertGreater(float(idle), 0.0)
123
124 def test_throws_on_failure(self):
David Pursell606835a2015-09-08 17:17:02 -0700125 self.assertRaises(adb.ShellError, self.device.shell, ['false'])
Dan Albert8e1fdd72015-07-24 17:08:33 -0700126
127 def test_output_not_stripped(self):
David Pursell606835a2015-09-08 17:17:02 -0700128 out = self.device.shell(['echo', 'foo'])[0]
Dan Albert8e1fdd72015-07-24 17:08:33 -0700129 self.assertEqual(out, 'foo' + self.device.linesep)
130
131 def test_shell_nocheck_failure(self):
David Pursell606835a2015-09-08 17:17:02 -0700132 rc, out, _ = self.device.shell_nocheck(['false'])
Dan Albert8e1fdd72015-07-24 17:08:33 -0700133 self.assertNotEqual(rc, 0)
134 self.assertEqual(out, '')
135
136 def test_shell_nocheck_output_not_stripped(self):
David Pursell606835a2015-09-08 17:17:02 -0700137 rc, out, _ = self.device.shell_nocheck(['echo', 'foo'])
Dan Albert8e1fdd72015-07-24 17:08:33 -0700138 self.assertEqual(rc, 0)
139 self.assertEqual(out, 'foo' + self.device.linesep)
140
141 def test_can_distinguish_tricky_results(self):
142 # If result checking on ADB shell is naively implemented as
143 # `adb shell <cmd>; echo $?`, we would be unable to distinguish the
144 # output from the result for a cmd of `echo -n 1`.
David Pursell606835a2015-09-08 17:17:02 -0700145 rc, out, _ = self.device.shell_nocheck(['echo', '-n', '1'])
Dan Albert8e1fdd72015-07-24 17:08:33 -0700146 self.assertEqual(rc, 0)
147 self.assertEqual(out, '1')
148
149 def test_line_endings(self):
150 """Ensure that line ending translation is not happening in the pty.
151
152 Bug: http://b/19735063
153 """
David Pursell606835a2015-09-08 17:17:02 -0700154 output = self.device.shell(['uname'])[0]
Dan Albert8e1fdd72015-07-24 17:08:33 -0700155 self.assertEqual(output, 'Linux' + self.device.linesep)
156
David Purselld4093f12015-08-10 12:52:16 -0700157 def test_pty_logic(self):
158 """Verify PTY logic for shells.
159
160 Interactive shells should use a PTY, non-interactive should not.
161
162 Bug: http://b/21215503
163 """
164 proc = subprocess.Popen(
165 self.device.adb_cmd + ['shell'], stdin=subprocess.PIPE,
166 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
167 # [ -t 0 ] is used (rather than `tty`) to provide portability. This
168 # gives an exit code of 0 iff stdin is connected to a terminal.
169 #
170 # Closing host-side stdin doesn't currently trigger the interactive
171 # shell to exit so we need to explicitly add an exit command to
172 # close the session from the device side, and append \n to complete
173 # the interactive command.
174 result = proc.communicate('[ -t 0 ]; echo x$?; exit 0\n')[0]
175 partition = result.rpartition('x')
176 self.assertEqual(partition[1], 'x')
177 self.assertEqual(int(partition[2]), 0)
178
179 exit_code = self.device.shell_nocheck(['[ -t 0 ]'])[0]
180 self.assertEqual(exit_code, 1)
181
David Pursell606835a2015-09-08 17:17:02 -0700182 def test_shell_protocol(self):
183 """Tests the shell protocol on the device.
184
185 If the device supports shell protocol, this gives us the ability
186 to separate stdout/stderr and return the exit code directly.
187
188 Bug: http://b/19734861
189 """
190 if self.device.SHELL_PROTOCOL_FEATURE not in self.device.features:
191 raise unittest.SkipTest('shell protocol unsupported on this device')
192 result = self.device.shell_nocheck(
193 shlex.split('echo foo; echo bar >&2; exit 17'))
194
195 self.assertEqual(17, result[0])
196 self.assertEqual('foo' + self.device.linesep, result[1])
197 self.assertEqual('bar' + self.device.linesep, result[2])
198
Dan Albert8e1fdd72015-07-24 17:08:33 -0700199
200class ArgumentEscapingTest(DeviceTest):
201 def test_shell_escaping(self):
202 """Make sure that argument escaping is somewhat sane."""
203
204 # http://b/19734868
205 # Note that this actually matches ssh(1)'s behavior --- it's
206 # converted to `sh -c echo hello; echo world` which sh interprets
207 # as `sh -c echo` (with an argument to that shell of "hello"),
208 # and then `echo world` back in the first shell.
209 result = self.device.shell(
David Pursell606835a2015-09-08 17:17:02 -0700210 shlex.split("sh -c 'echo hello; echo world'"))[0]
Dan Albert8e1fdd72015-07-24 17:08:33 -0700211 result = result.splitlines()
212 self.assertEqual(['', 'world'], result)
213 # If you really wanted "hello" and "world", here's what you'd do:
214 result = self.device.shell(
David Pursell606835a2015-09-08 17:17:02 -0700215 shlex.split(r'echo hello\;echo world'))[0].splitlines()
Dan Albert8e1fdd72015-07-24 17:08:33 -0700216 self.assertEqual(['hello', 'world'], result)
217
218 # http://b/15479704
David Pursell606835a2015-09-08 17:17:02 -0700219 result = self.device.shell(shlex.split("'true && echo t'"))[0].strip()
Dan Albert8e1fdd72015-07-24 17:08:33 -0700220 self.assertEqual('t', result)
221 result = self.device.shell(
David Pursell606835a2015-09-08 17:17:02 -0700222 shlex.split("sh -c 'true && echo t'"))[0].strip()
Dan Albert8e1fdd72015-07-24 17:08:33 -0700223 self.assertEqual('t', result)
224
225 # http://b/20564385
David Pursell606835a2015-09-08 17:17:02 -0700226 result = self.device.shell(shlex.split('FOO=a BAR=b echo t'))[0].strip()
Dan Albert8e1fdd72015-07-24 17:08:33 -0700227 self.assertEqual('t', result)
David Pursell606835a2015-09-08 17:17:02 -0700228 result = self.device.shell(
229 shlex.split(r'echo -n 123\;uname'))[0].strip()
Dan Albert8e1fdd72015-07-24 17:08:33 -0700230 self.assertEqual('123Linux', result)
231
232 def test_install_argument_escaping(self):
233 """Make sure that install argument escaping works."""
234 # http://b/20323053
Spencer Lowd8cce182015-08-28 01:07:30 -0700235 tf = tempfile.NamedTemporaryFile('wb', suffix='-text;ls;1.apk',
236 delete=False)
237 tf.close()
Dan Albert8e1fdd72015-07-24 17:08:33 -0700238 self.assertIn("-text;ls;1.apk", self.device.install(tf.name))
Spencer Lowd8cce182015-08-28 01:07:30 -0700239 os.remove(tf.name)
Dan Albert8e1fdd72015-07-24 17:08:33 -0700240
241 # http://b/3090932
Spencer Lowd8cce182015-08-28 01:07:30 -0700242 tf = tempfile.NamedTemporaryFile('wb', suffix="-Live Hold'em.apk",
243 delete=False)
244 tf.close()
Dan Albert8e1fdd72015-07-24 17:08:33 -0700245 self.assertIn("-Live Hold'em.apk", self.device.install(tf.name))
Spencer Lowd8cce182015-08-28 01:07:30 -0700246 os.remove(tf.name)
Dan Albert8e1fdd72015-07-24 17:08:33 -0700247
248
249class RootUnrootTest(DeviceTest):
250 def _test_root(self):
251 message = self.device.root()
252 if 'adbd cannot run as root in production builds' in message:
253 return
254 self.device.wait()
David Pursell606835a2015-09-08 17:17:02 -0700255 self.assertEqual('root', self.device.shell(['id', '-un'])[0].strip())
Dan Albert8e1fdd72015-07-24 17:08:33 -0700256
257 def _test_unroot(self):
258 self.device.unroot()
259 self.device.wait()
David Pursell606835a2015-09-08 17:17:02 -0700260 self.assertEqual('shell', self.device.shell(['id', '-un'])[0].strip())
Dan Albert8e1fdd72015-07-24 17:08:33 -0700261
262 def test_root_unroot(self):
263 """Make sure that adb root and adb unroot work, using id(1)."""
Dan Alberte2b4a5f2015-07-28 14:53:03 -0700264 if self.device.get_prop('ro.debuggable') != '1':
265 raise unittest.SkipTest('requires rootable build')
266
David Pursell606835a2015-09-08 17:17:02 -0700267 original_user = self.device.shell(['id', '-un'])[0].strip()
Dan Albert8e1fdd72015-07-24 17:08:33 -0700268 try:
269 if original_user == 'root':
270 self._test_unroot()
271 self._test_root()
272 elif original_user == 'shell':
273 self._test_root()
274 self._test_unroot()
275 finally:
276 if original_user == 'root':
277 self.device.root()
278 else:
279 self.device.unroot()
280 self.device.wait()
281
282
283class TcpIpTest(DeviceTest):
284 def test_tcpip_failure_raises(self):
285 """adb tcpip requires a port.
286
287 Bug: http://b/22636927
288 """
289 self.assertRaises(
290 subprocess.CalledProcessError, self.device.tcpip, '')
291 self.assertRaises(
292 subprocess.CalledProcessError, self.device.tcpip, 'foo')
293
294
Dan Alberte2b4a5f2015-07-28 14:53:03 -0700295class SystemPropertiesTest(DeviceTest):
296 def test_get_prop(self):
297 self.assertEqual(self.device.get_prop('init.svc.adbd'), 'running')
298
299 @requires_root
300 def test_set_prop(self):
301 prop_name = 'foo.bar'
302 self.device.shell(['setprop', prop_name, '""'])
303
304 self.device.set_prop(prop_name, 'qux')
305 self.assertEqual(
David Pursell606835a2015-09-08 17:17:02 -0700306 self.device.shell(['getprop', prop_name])[0].strip(), 'qux')
Dan Alberte2b4a5f2015-07-28 14:53:03 -0700307
308
Dan Albert8e1fdd72015-07-24 17:08:33 -0700309def compute_md5(string):
310 hsh = hashlib.md5()
311 hsh.update(string)
312 return hsh.hexdigest()
313
314
315def get_md5_prog(device):
316 """Older platforms (pre-L) had the name md5 rather than md5sum."""
317 try:
318 device.shell(['md5sum', '/proc/uptime'])
319 return 'md5sum'
320 except subprocess.CalledProcessError:
321 return 'md5'
322
323
324class HostFile(object):
325 def __init__(self, handle, checksum):
326 self.handle = handle
327 self.checksum = checksum
328 self.full_path = handle.name
329 self.base_name = os.path.basename(self.full_path)
330
331
332class DeviceFile(object):
333 def __init__(self, checksum, full_path):
334 self.checksum = checksum
335 self.full_path = full_path
336 self.base_name = posixpath.basename(self.full_path)
337
338
339def make_random_host_files(in_dir, num_files):
340 min_size = 1 * (1 << 10)
341 max_size = 16 * (1 << 10)
342
343 files = []
344 for _ in xrange(num_files):
345 file_handle = tempfile.NamedTemporaryFile(dir=in_dir, delete=False)
346
347 size = random.randrange(min_size, max_size, 1024)
348 rand_str = os.urandom(size)
349 file_handle.write(rand_str)
350 file_handle.flush()
351 file_handle.close()
352
353 md5 = compute_md5(rand_str)
354 files.append(HostFile(file_handle, md5))
355 return files
356
357
358def make_random_device_files(device, in_dir, num_files):
359 min_size = 1 * (1 << 10)
360 max_size = 16 * (1 << 10)
361
362 files = []
363 for file_num in xrange(num_files):
364 size = random.randrange(min_size, max_size, 1024)
365
366 base_name = 'device_tmpfile' + str(file_num)
Spencer Low3e7feda2015-07-30 01:19:52 -0700367 full_path = posixpath.join(in_dir, base_name)
Dan Albert8e1fdd72015-07-24 17:08:33 -0700368
369 device.shell(['dd', 'if=/dev/urandom', 'of={}'.format(full_path),
370 'bs={}'.format(size), 'count=1'])
David Pursell606835a2015-09-08 17:17:02 -0700371 dev_md5, _ = device.shell([get_md5_prog(device), full_path])[0].split()
Dan Albert8e1fdd72015-07-24 17:08:33 -0700372
373 files.append(DeviceFile(dev_md5, full_path))
374 return files
375
376
377class FileOperationsTest(DeviceTest):
378 SCRATCH_DIR = '/data/local/tmp'
379 DEVICE_TEMP_FILE = SCRATCH_DIR + '/adb_test_file'
380 DEVICE_TEMP_DIR = SCRATCH_DIR + '/adb_test_dir'
381
382 def _test_push(self, local_file, checksum):
383 self.device.shell(['rm', '-rf', self.DEVICE_TEMP_FILE])
Elliott Hughes3841a9f2015-08-03 13:58:49 -0700384 self.device.push(local=local_file, remote=self.DEVICE_TEMP_FILE)
385 dev_md5, _ = self.device.shell([get_md5_prog(self.device),
David Pursell606835a2015-09-08 17:17:02 -0700386 self.DEVICE_TEMP_FILE])[0].split()
Elliott Hughes3841a9f2015-08-03 13:58:49 -0700387 self.assertEqual(checksum, dev_md5)
388 self.device.shell(['rm', '-f', self.DEVICE_TEMP_FILE])
Dan Albert8e1fdd72015-07-24 17:08:33 -0700389
390 def test_push(self):
391 """Push a randomly generated file to specified device."""
392 kbytes = 512
393 tmp = tempfile.NamedTemporaryFile(mode='wb', delete=False)
Elliott Hughes3841a9f2015-08-03 13:58:49 -0700394 rand_str = os.urandom(1024 * kbytes)
395 tmp.write(rand_str)
396 tmp.close()
397 self._test_push(tmp.name, compute_md5(rand_str))
398 os.remove(tmp.name)
Dan Albert8e1fdd72015-07-24 17:08:33 -0700399
400 # TODO: write push directory test.
401
402 def _test_pull(self, remote_file, checksum):
403 tmp_write = tempfile.NamedTemporaryFile(mode='wb', delete=False)
Elliott Hughes3841a9f2015-08-03 13:58:49 -0700404 tmp_write.close()
405 self.device.pull(remote=remote_file, local=tmp_write.name)
406 with open(tmp_write.name, 'rb') as tmp_read:
407 host_contents = tmp_read.read()
408 host_md5 = compute_md5(host_contents)
409 self.assertEqual(checksum, host_md5)
410 os.remove(tmp_write.name)
Dan Albert8e1fdd72015-07-24 17:08:33 -0700411
412 def test_pull(self):
413 """Pull a randomly generated file from specified device."""
414 kbytes = 512
415 self.device.shell(['rm', '-rf', self.DEVICE_TEMP_FILE])
Elliott Hughes3841a9f2015-08-03 13:58:49 -0700416 cmd = ['dd', 'if=/dev/urandom',
417 'of={}'.format(self.DEVICE_TEMP_FILE), 'bs=1024',
418 'count={}'.format(kbytes)]
419 self.device.shell(cmd)
420 dev_md5, _ = self.device.shell(
David Pursell606835a2015-09-08 17:17:02 -0700421 [get_md5_prog(self.device), self.DEVICE_TEMP_FILE])[0].split()
Elliott Hughes3841a9f2015-08-03 13:58:49 -0700422 self._test_pull(self.DEVICE_TEMP_FILE, dev_md5)
423 self.device.shell_nocheck(['rm', self.DEVICE_TEMP_FILE])
Dan Albert8e1fdd72015-07-24 17:08:33 -0700424
425 def test_pull_dir(self):
426 """Pull a randomly generated directory of files from the device."""
427 host_dir = tempfile.mkdtemp()
Elliott Hughes3841a9f2015-08-03 13:58:49 -0700428 self.device.shell(['rm', '-rf', self.DEVICE_TEMP_DIR])
429 self.device.shell(['mkdir', '-p', self.DEVICE_TEMP_DIR])
Dan Albert8e1fdd72015-07-24 17:08:33 -0700430
Elliott Hughes3841a9f2015-08-03 13:58:49 -0700431 # Populate device directory with random files.
432 temp_files = make_random_device_files(
433 self.device, in_dir=self.DEVICE_TEMP_DIR, num_files=32)
Dan Albert8e1fdd72015-07-24 17:08:33 -0700434
Elliott Hughes3841a9f2015-08-03 13:58:49 -0700435 self.device.pull(remote=self.DEVICE_TEMP_DIR, local=host_dir)
Dan Albert8e1fdd72015-07-24 17:08:33 -0700436
Elliott Hughes3841a9f2015-08-03 13:58:49 -0700437 for temp_file in temp_files:
438 host_path = os.path.join(host_dir, temp_file.base_name)
439 with open(host_path, 'rb') as host_file:
440 host_md5 = compute_md5(host_file.read())
441 self.assertEqual(host_md5, temp_file.checksum)
442
443 self.device.shell(['rm', '-rf', self.DEVICE_TEMP_DIR])
444 if host_dir is not None:
445 shutil.rmtree(host_dir)
Dan Albert8e1fdd72015-07-24 17:08:33 -0700446
447 def test_sync(self):
448 """Sync a randomly generated directory of files to specified device."""
449 base_dir = tempfile.mkdtemp()
Dan Albert8e1fdd72015-07-24 17:08:33 -0700450
Elliott Hughes3841a9f2015-08-03 13:58:49 -0700451 # Create mirror device directory hierarchy within base_dir.
452 full_dir_path = base_dir + self.DEVICE_TEMP_DIR
453 os.makedirs(full_dir_path)
Dan Albert8e1fdd72015-07-24 17:08:33 -0700454
Elliott Hughes3841a9f2015-08-03 13:58:49 -0700455 # Create 32 random files within the host mirror.
456 temp_files = make_random_host_files(in_dir=full_dir_path, num_files=32)
Dan Albert8e1fdd72015-07-24 17:08:33 -0700457
Elliott Hughes3841a9f2015-08-03 13:58:49 -0700458 # Clean up any trash on the device.
459 device = adb.get_device(product=base_dir)
460 device.shell(['rm', '-rf', self.DEVICE_TEMP_DIR])
Dan Albert8e1fdd72015-07-24 17:08:33 -0700461
Elliott Hughes3841a9f2015-08-03 13:58:49 -0700462 device.sync('data')
463
464 # Confirm that every file on the device mirrors that on the host.
465 for temp_file in temp_files:
466 device_full_path = posixpath.join(self.DEVICE_TEMP_DIR,
467 temp_file.base_name)
468 dev_md5, _ = device.shell(
David Pursell606835a2015-09-08 17:17:02 -0700469 [get_md5_prog(self.device), device_full_path])[0].split()
Elliott Hughes3841a9f2015-08-03 13:58:49 -0700470 self.assertEqual(temp_file.checksum, dev_md5)
471
472 self.device.shell(['rm', '-rf', self.DEVICE_TEMP_DIR])
473 shutil.rmtree(base_dir + self.DEVICE_TEMP_DIR)
Dan Albert8e1fdd72015-07-24 17:08:33 -0700474
Dan Albert8e1fdd72015-07-24 17:08:33 -0700475 def test_unicode_paths(self):
476 """Ensure that we can support non-ASCII paths, even on Windows."""
Spencer Lowde4505f2015-08-27 20:58:29 -0700477 name = u'로보카 폴리'
Dan Albert8e1fdd72015-07-24 17:08:33 -0700478
479 ## push.
Spencer Lowde4505f2015-08-27 20:58:29 -0700480 tf = tempfile.NamedTemporaryFile('wb', suffix=name, delete=False)
481 tf.close()
482 self.device.push(tf.name, u'/data/local/tmp/adb-test-{}'.format(name))
483 os.remove(tf.name)
Dan Albert8e1fdd72015-07-24 17:08:33 -0700484 self.device.shell(['rm', '-f', '/data/local/tmp/adb-test-*'])
485
486 # pull.
Spencer Lowde4505f2015-08-27 20:58:29 -0700487 cmd = ['touch', u'"/data/local/tmp/adb-test-{}"'.format(name)]
Dan Albert8e1fdd72015-07-24 17:08:33 -0700488 self.device.shell(cmd)
489
Spencer Lowde4505f2015-08-27 20:58:29 -0700490 tf = tempfile.NamedTemporaryFile('wb', suffix=name, delete=False)
491 tf.close()
492 self.device.pull(u'/data/local/tmp/adb-test-{}'.format(name), tf.name)
493 os.remove(tf.name)
494 self.device.shell(['rm', '-f', '/data/local/tmp/adb-test-*'])
Dan Albert8e1fdd72015-07-24 17:08:33 -0700495
496
497def main():
498 random.seed(0)
499 if len(adb.get_devices()) > 0:
500 suite = unittest.TestLoader().loadTestsFromName(__name__)
501 unittest.TextTestRunner(verbosity=3).run(suite)
502 else:
503 print('Test suite must be run with attached devices')
504
505
506if __name__ == '__main__':
507 main()