| Index: build/android/pylib/device/device_utils_test.py
|
| diff --git a/build/android/pylib/device/device_utils_test.py b/build/android/pylib/device/device_utils_test.py
|
| index bc50e6dc3fef3c09af83e3139172f24b6934d670..ef3b2e16bbe3b593c555568edcec64e4931a01de 100755
|
| --- a/build/android/pylib/device/device_utils_test.py
|
| +++ b/build/android/pylib/device/device_utils_test.py
|
| @@ -642,52 +642,40 @@ class DeviceUtilsGetDevicePieWrapper(DeviceUtilsTest):
|
| class DeviceUtilsKillAllTest(DeviceUtilsTest):
|
|
|
| def testKillAll_noMatchingProcesses(self):
|
| - with self.assertCall(self.call.adb.Shell('ps'),
|
| - 'USER PID PPID VSIZE RSS WCHAN PC NAME\n'):
|
| + with self.assertCall(self.call.device.GetPids('test_process'), []):
|
| with self.assertRaises(device_errors.CommandFailedError):
|
| self.device.KillAll('test_process')
|
|
|
| def testKillAll_nonblocking(self):
|
| with self.assertCalls(
|
| - (self.call.adb.Shell('ps'),
|
| - 'USER PID PPID VSIZE RSS WCHAN PC NAME\n'
|
| - 'u0_a1 1234 174 123456 54321 ffffffff 456789ab some.process\n'),
|
| + (self.call.device.GetPids('some.process'), {'some.process': '1234'}),
|
| (self.call.adb.Shell('kill -9 1234'), '')):
|
| - self.assertEquals(1,
|
| - self.device.KillAll('some.process', blocking=False))
|
| + self.assertEquals(
|
| + 1, self.device.KillAll('some.process', blocking=False))
|
|
|
| def testKillAll_blocking(self):
|
| with self.assertCalls(
|
| - (self.call.adb.Shell('ps'),
|
| - 'USER PID PPID VSIZE RSS WCHAN PC NAME\n'
|
| - 'u0_a1 1234 174 123456 54321 ffffffff 456789ab some.process\n'),
|
| + (self.call.device.GetPids('some.process'), {'some.process': '1234'}),
|
| (self.call.adb.Shell('kill -9 1234'), ''),
|
| - (self.call.adb.Shell('ps'),
|
| - 'USER PID PPID VSIZE RSS WCHAN PC NAME\n'
|
| - 'u0_a1 1234 174 123456 54321 ffffffff 456789ab some.process\n'),
|
| - (self.call.adb.Shell('ps'),
|
| - 'USER PID PPID VSIZE RSS WCHAN PC NAME\n')):
|
| - self.assertEquals(1,
|
| - self.device.KillAll('some.process', blocking=True))
|
| + (self.call.device.GetPids('some.process'), {'some.process': '1234'}),
|
| + (self.call.device.GetPids('some.process'), [])):
|
| + self.assertEquals(
|
| + 1, self.device.KillAll('some.process', blocking=True))
|
|
|
| def testKillAll_root(self):
|
| with self.assertCalls(
|
| - (self.call.adb.Shell('ps'),
|
| - 'USER PID PPID VSIZE RSS WCHAN PC NAME\n'
|
| - 'u0_a1 1234 174 123456 54321 ffffffff 456789ab some.process\n'),
|
| + (self.call.device.GetPids('some.process'), {'some.process': '1234'}),
|
| (self.call.device.NeedsSU(), True),
|
| (self.call.adb.Shell("su -c sh -c 'kill -9 1234'"), '')):
|
| - self.assertEquals(1,
|
| - self.device.KillAll('some.process', as_root=True))
|
| + self.assertEquals(
|
| + 1, self.device.KillAll('some.process', as_root=True))
|
|
|
| def testKillAll_sigterm(self):
|
| with self.assertCalls(
|
| - (self.call.adb.Shell('ps'),
|
| - 'USER PID PPID VSIZE RSS WCHAN PC NAME\n'
|
| - 'u0_a1 1234 174 123456 54321 ffffffff 456789ab some.process\n'),
|
| + (self.call.device.GetPids('some.process'), {'some.process': '1234'}),
|
| (self.call.adb.Shell('kill -15 1234'), '')):
|
| - self.assertEquals(1,
|
| - self.device.KillAll('some.process', signum=signal.SIGTERM))
|
| + self.assertEquals(
|
| + 1, self.device.KillAll('some.process', signum=signal.SIGTERM))
|
|
|
|
|
| class DeviceUtilsStartActivityTest(DeviceUtilsTest):
|
| @@ -1115,7 +1103,8 @@ class DeviceUtilsReadFileTest(DeviceUtilsTest):
|
| as_root=False, check_return=True),
|
| ['-rw-rw---- root foo 256 1970-01-01 00:00 file']),
|
| (self.call.device.RunShellCommand(
|
| - ['cat', '/read/this/test/file'], as_root=False, check_return=True),
|
| + ['cat', '/read/this/test/file'],
|
| + as_root=False, check_return=True, large_output=False),
|
| ['this is a test file'])):
|
| self.assertEqual('this is a test file\n',
|
| self.device.ReadFile('/read/this/test/file'))
|
| @@ -1129,6 +1118,19 @@ class DeviceUtilsReadFileTest(DeviceUtilsTest):
|
| with self.assertRaises(device_errors.CommandFailedError):
|
| self.device.ReadFile('/this/file/does.not.exist')
|
|
|
| + def testReadFile_zeroSize(self):
|
| + with self.assertCalls(
|
| + (self.call.device.RunShellCommand(
|
| + ['ls', '-l', '/this/file/has/zero/size'],
|
| + as_root=False, check_return=True),
|
| + ['-r--r--r-- root foo 0 1970-01-01 00:00 zero_size_file']),
|
| + (self.call.device.RunShellCommand(
|
| + ['cat', '/this/file/has/zero/size'],
|
| + as_root=False, check_return=True, large_output=True),
|
| + ['but it has contents'])):
|
| + self.assertEqual('but it has contents\n',
|
| + self.device.ReadFile('/this/file/has/zero/size'))
|
| +
|
| def testReadFile_withSU(self):
|
| with self.assertCalls(
|
| (self.call.device.RunShellCommand(
|
| @@ -1137,7 +1139,7 @@ class DeviceUtilsReadFileTest(DeviceUtilsTest):
|
| ['-rw------- root root 256 1970-01-01 00:00 can.be.read.with.su']),
|
| (self.call.device.RunShellCommand(
|
| ['cat', '/this/file/can.be.read.with.su'],
|
| - as_root=True, check_return=True),
|
| + as_root=True, check_return=True, large_output=False),
|
| ['this is a test file', 'read with su'])):
|
| self.assertEqual(
|
| 'this is a test file\nread with su\n',
|
| @@ -1387,34 +1389,42 @@ class DeviceUtilsSetPropTest(DeviceUtilsTest):
|
| class DeviceUtilsGetPidsTest(DeviceUtilsTest):
|
|
|
| def testGetPids_noMatches(self):
|
| - with self.assertCall(self.call.adb.Shell('ps'),
|
| - 'USER PID PPID VSIZE RSS WCHAN PC NAME\n'
|
| - 'user 1000 100 1024 1024 ffffffff 00000000 no.match\n'):
|
| + with self.assertCall(
|
| + self.call.device.RunShellCommand(
|
| + 'ps', check_return=True, large_output=True),
|
| + ['USER PID PPID VSIZE RSS WCHAN PC NAME',
|
| + 'user 1000 100 1024 1024 ffffffff 00000000 no.match']):
|
| self.assertEqual({}, self.device.GetPids('does.not.match'))
|
|
|
| def testGetPids_oneMatch(self):
|
| - with self.assertCall(self.call.adb.Shell('ps'),
|
| - 'USER PID PPID VSIZE RSS WCHAN PC NAME\n'
|
| - 'user 1000 100 1024 1024 ffffffff 00000000 not.a.match\n'
|
| - 'user 1001 100 1024 1024 ffffffff 00000000 one.match\n'):
|
| + with self.assertCall(
|
| + self.call.device.RunShellCommand(
|
| + 'ps', check_return=True, large_output=True),
|
| + ['USER PID PPID VSIZE RSS WCHAN PC NAME',
|
| + 'user 1000 100 1024 1024 ffffffff 00000000 not.a.match',
|
| + 'user 1001 100 1024 1024 ffffffff 00000000 one.match']):
|
| self.assertEqual({'one.match': '1001'}, self.device.GetPids('one.match'))
|
|
|
| def testGetPids_mutlipleMatches(self):
|
| - with self.assertCall(self.call.adb.Shell('ps'),
|
| - 'USER PID PPID VSIZE RSS WCHAN PC NAME\n'
|
| - 'user 1000 100 1024 1024 ffffffff 00000000 not\n'
|
| - 'user 1001 100 1024 1024 ffffffff 00000000 one.match\n'
|
| - 'user 1002 100 1024 1024 ffffffff 00000000 two.match\n'
|
| - 'user 1003 100 1024 1024 ffffffff 00000000 three.match\n'):
|
| + with self.assertCall(
|
| + self.call.device.RunShellCommand(
|
| + 'ps', check_return=True, large_output=True),
|
| + ['USER PID PPID VSIZE RSS WCHAN PC NAME',
|
| + 'user 1000 100 1024 1024 ffffffff 00000000 not',
|
| + 'user 1001 100 1024 1024 ffffffff 00000000 one.match',
|
| + 'user 1002 100 1024 1024 ffffffff 00000000 two.match',
|
| + 'user 1003 100 1024 1024 ffffffff 00000000 three.match']):
|
| self.assertEqual(
|
| {'one.match': '1001', 'two.match': '1002', 'three.match': '1003'},
|
| self.device.GetPids('match'))
|
|
|
| def testGetPids_exactMatch(self):
|
| - with self.assertCall(self.call.adb.Shell('ps'),
|
| - 'USER PID PPID VSIZE RSS WCHAN PC NAME\n'
|
| - 'user 1000 100 1024 1024 ffffffff 00000000 not.exact.match\n'
|
| - 'user 1234 100 1024 1024 ffffffff 00000000 exact.match\n'):
|
| + with self.assertCall(
|
| + self.call.device.RunShellCommand(
|
| + 'ps', check_return=True, large_output=True),
|
| + ['USER PID PPID VSIZE RSS WCHAN PC NAME',
|
| + 'user 1000 100 1024 1024 ffffffff 00000000 not.exact.match',
|
| + 'user 1234 100 1024 1024 ffffffff 00000000 exact.match']):
|
| self.assertEqual(
|
| {'not.exact.match': '1000', 'exact.match': '1234'},
|
| self.device.GetPids('exact.match'))
|
| @@ -1442,7 +1452,8 @@ class DeviceUtilsGetMemoryUsageForPidTest(DeviceUtilsTest):
|
| def testGetMemoryUsageForPid_validPid(self):
|
| with self.assertCalls(
|
| (self.call.device.RunShellCommand(
|
| - ['showmap', '1234'], as_root=True, check_return=True),
|
| + ['showmap', '1234'],
|
| + as_root=True, check_return=True, large_output=True),
|
| ['100 101 102 103 104 105 106 107 TOTAL']),
|
| (self.call.device.ReadFile('/proc/1234/status', as_root=True),
|
| 'VmHWM: 1024 kB\n')):
|
| @@ -1462,7 +1473,8 @@ class DeviceUtilsGetMemoryUsageForPidTest(DeviceUtilsTest):
|
| def testGetMemoryUsageForPid_noSmaps(self):
|
| with self.assertCalls(
|
| (self.call.device.RunShellCommand(
|
| - ['showmap', '4321'], as_root=True, check_return=True),
|
| + ['showmap', '4321'],
|
| + as_root=True, check_return=True, large_output=True),
|
| ['cannot open /proc/4321/smaps: No such file or directory']),
|
| (self.call.device.ReadFile('/proc/4321/status', as_root=True),
|
| 'VmHWM: 1024 kb\n')):
|
| @@ -1471,7 +1483,8 @@ class DeviceUtilsGetMemoryUsageForPidTest(DeviceUtilsTest):
|
| def testGetMemoryUsageForPid_noStatus(self):
|
| with self.assertCalls(
|
| (self.call.device.RunShellCommand(
|
| - ['showmap', '4321'], as_root=True, check_return=True),
|
| + ['showmap', '4321'],
|
| + as_root=True, check_return=True, large_output=True),
|
| ['100 101 102 103 104 105 106 107 TOTAL']),
|
| (self.call.device.ReadFile('/proc/4321/status', as_root=True),
|
| self.CommandError())):
|
|
|