Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(851)

Side by Side Diff: build/android/pylib/device/device_utils_test.py

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « build/android/pylib/device/device_utils.py ('k') | build/android/pylib/gtest/setup.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """ 6 """
7 Unit tests for the contents of device_utils.py (mostly DeviceUtils). 7 Unit tests for the contents of device_utils.py (mostly DeviceUtils).
8 """ 8 """
9 9
10 # pylint: disable=C0321 10 # pylint: disable=C0321
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 self.device.RunShellCommand(cmd, check_return=True) 649 self.device.RunShellCommand(cmd, check_return=True)
650 650
651 def testRunShellCommand_checkReturn_disabled(self): 651 def testRunShellCommand_checkReturn_disabled(self):
652 cmd = 'ls /root' 652 cmd = 'ls /root'
653 output = 'opendir failed, Permission denied\n' 653 output = 'opendir failed, Permission denied\n'
654 with self.assertCall(self.call.adb.Shell(cmd), self.ShellError(output)): 654 with self.assertCall(self.call.adb.Shell(cmd), self.ShellError(output)):
655 self.assertEquals([output.rstrip()], 655 self.assertEquals([output.rstrip()],
656 self.device.RunShellCommand(cmd, check_return=False)) 656 self.device.RunShellCommand(cmd, check_return=False))
657 657
658 658
659 class DeviceUtilsGetDevicePieWrapper(DeviceUtilsNewImplTest):
660
661 def testGetDevicePieWrapper_jb(self):
662 with self.assertCall(
663 self.call.device.build_version_sdk(),
664 constants.ANDROID_SDK_VERSION_CODES.JELLY_BEAN):
665 self.assertEqual('', self.device.GetDevicePieWrapper())
666
667 def testGetDevicePieWrapper_ics(self):
668 with self.assertCalls(
669 (self.call.device.build_version_sdk(),
670 constants.ANDROID_SDK_VERSION_CODES.ICE_CREAM_SANDWICH),
671 (mock.call.pylib.constants.GetOutDirectory(), '/foo/bar'),
672 (mock.call.os.path.exists(mock.ANY), True),
673 (self.call.adb.Push(mock.ANY, mock.ANY), '')):
674 self.assertNotEqual('', self.device.GetDevicePieWrapper())
675
676
659 @mock.patch('time.sleep', mock.Mock()) 677 @mock.patch('time.sleep', mock.Mock())
660 class DeviceUtilsKillAllTest(DeviceUtilsNewImplTest): 678 class DeviceUtilsKillAllTest(DeviceUtilsNewImplTest):
661 679
662 def testKillAll_noMatchingProcesses(self): 680 def testKillAll_noMatchingProcesses(self):
663 with self.assertCall(self.call.adb.Shell('ps'), 681 with self.assertCall(self.call.adb.Shell('ps'),
664 'USER PID PPID VSIZE RSS WCHAN PC NAME\n'): 682 'USER PID PPID VSIZE RSS WCHAN PC NAME\n'):
665 with self.assertRaises(device_errors.CommandFailedError): 683 with self.assertRaises(device_errors.CommandFailedError):
666 self.device.KillAll('test_process') 684 self.device.KillAll('test_process')
667 685
668 def testKillAll_nonblocking(self): 686 def testKillAll_nonblocking(self):
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 (mock.call.multiprocessing.Process( 1056 (mock.call.multiprocessing.Process(
1039 target=device_utils.DeviceUtils._CreateDeviceZip, 1057 target=device_utils.DeviceUtils._CreateDeviceZip,
1040 args=('/test/temp/file/tmp.zip', test_files)), mock.Mock()), 1058 args=('/test/temp/file/tmp.zip', test_files)), mock.Mock()),
1041 (self.call.device.GetExternalStoragePath(), 1059 (self.call.device.GetExternalStoragePath(),
1042 '/test/device/external_dir'), 1060 '/test/device/external_dir'),
1043 self.call.adb.Push( 1061 self.call.adb.Push(
1044 '/test/temp/file/tmp.zip', '/test/device/external_dir/tmp.zip'), 1062 '/test/temp/file/tmp.zip', '/test/device/external_dir/tmp.zip'),
1045 self.call.device.RunShellCommand( 1063 self.call.device.RunShellCommand(
1046 ['unzip', '/test/device/external_dir/tmp.zip'], 1064 ['unzip', '/test/device/external_dir/tmp.zip'],
1047 as_root=True, 1065 as_root=True,
1048 env={'PATH': '$PATH:/data/local/tmp/bin'}, 1066 env={'PATH': '/data/local/tmp/bin:$PATH'},
1049 check_return=True), 1067 check_return=True),
1050 (self.call.device.IsOnline(), True), 1068 (self.call.device.IsOnline(), True),
1051 self.call.device.RunShellCommand( 1069 self.call.device.RunShellCommand(
1052 ['rm', '/test/device/external_dir/tmp.zip'], check_return=True)): 1070 ['rm', '/test/device/external_dir/tmp.zip'], check_return=True)):
1053 self.device._PushChangedFilesZipped(test_files) 1071 self.device._PushChangedFilesZipped(test_files)
1054 1072
1055 def testPushChangedFilesZipped_single(self): 1073 def testPushChangedFilesZipped_single(self):
1056 self._testPushChangedFilesZipped_spec( 1074 self._testPushChangedFilesZipped_spec(
1057 [('/test/host/path/file1', '/test/device/path/file1')]) 1075 [('/test/host/path/file1', '/test/device/path/file1')])
1058 1076
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
1376 (mock.call.pylib.utils.device_temp_file.DeviceTempFile( 1394 (mock.call.pylib.utils.device_temp_file.DeviceTempFile(
1377 self.adb, suffix='.png'), 1395 self.adb, suffix='.png'),
1378 MockTempFile('/tmp/path/temp-123.png')), 1396 MockTempFile('/tmp/path/temp-123.png')),
1379 (self.call.adb.Shell('/system/bin/screencap -p /tmp/path/temp-123.png'), 1397 (self.call.adb.Shell('/system/bin/screencap -p /tmp/path/temp-123.png'),
1380 ''), 1398 ''),
1381 self.call.device.PullFile('/tmp/path/temp-123.png', 1399 self.call.device.PullFile('/tmp/path/temp-123.png',
1382 '/test/host/screenshot.png')): 1400 '/test/host/screenshot.png')):
1383 self.device.TakeScreenshot('/test/host/screenshot.png') 1401 self.device.TakeScreenshot('/test/host/screenshot.png')
1384 1402
1385 1403
1386 class DeviceUtilsGetIOStatsTest(DeviceUtilsOldImplTest):
1387
1388 def testGetIOStats(self):
1389 with self.assertCalls(
1390 "adb -s 0123456789abcdef shell 'cat \"/proc/diskstats\" 2>/dev/null'",
1391 '179 0 mmcblk0 1 2 3 4 5 6 7 8 9 10 11\r\n'):
1392 self.assertEqual(
1393 {
1394 'num_reads': 1,
1395 'num_writes': 5,
1396 'read_ms': 4,
1397 'write_ms': 8,
1398 },
1399 self.device.GetIOStats())
1400
1401
1402 class DeviceUtilsGetMemoryUsageForPidTest(DeviceUtilsOldImplTest): 1404 class DeviceUtilsGetMemoryUsageForPidTest(DeviceUtilsOldImplTest):
1403 1405
1404 def setUp(self): 1406 def setUp(self):
1405 super(DeviceUtilsGetMemoryUsageForPidTest, self).setUp() 1407 super(DeviceUtilsGetMemoryUsageForPidTest, self).setUp()
1406 self.device.old_interface._privileged_command_runner = ( 1408 self.device.old_interface._privileged_command_runner = (
1407 self.device.old_interface.RunShellCommand) 1409 self.device.old_interface.RunShellCommand)
1408 self.device.old_interface._protected_file_access_method_initialized = True 1410 self.device.old_interface._protected_file_access_method_initialized = True
1409 1411
1410 def testGetMemoryUsageForPid_validPid(self): 1412 def testGetMemoryUsageForPid_validPid(self):
1411 with self.assertCallsSequence([ 1413 with self.assertCallsSequence([
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1455 self.assertTrue( 1457 self.assertTrue(
1456 isinstance(device, device_utils.DeviceUtils) 1458 isinstance(device, device_utils.DeviceUtils)
1457 and serial == str(device), 1459 and serial == str(device),
1458 'Expected a DeviceUtils object with serial %s' % serial) 1460 'Expected a DeviceUtils object with serial %s' % serial)
1459 1461
1460 1462
1461 if __name__ == '__main__': 1463 if __name__ == '__main__':
1462 logging.getLogger().setLevel(logging.DEBUG) 1464 logging.getLogger().setLevel(logging.DEBUG)
1463 unittest.main(verbosity=2) 1465 unittest.main(verbosity=2)
1464 1466
OLDNEW
« no previous file with comments | « build/android/pylib/device/device_utils.py ('k') | build/android/pylib/gtest/setup.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698