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

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

Issue 1254843002: telemetry: Fix killing the perf profiler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change GetPids instead. Created 5 years, 5 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
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 815 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 with self.assertCall(self.call.device.GetPids('test_process'), {}): 826 with self.assertCall(self.call.device.GetPids('test_process'), {}):
827 with self.assertRaises(device_errors.CommandFailedError): 827 with self.assertRaises(device_errors.CommandFailedError):
828 self.device.KillAll('test_process') 828 self.device.KillAll('test_process')
829 829
830 def testKillAll_noMatchingProcessesQuiet(self): 830 def testKillAll_noMatchingProcessesQuiet(self):
831 with self.assertCall(self.call.device.GetPids('test_process'), {}): 831 with self.assertCall(self.call.device.GetPids('test_process'), {}):
832 self.assertEqual(0, self.device.KillAll('test_process', quiet=True)) 832 self.assertEqual(0, self.device.KillAll('test_process', quiet=True))
833 833
834 def testKillAll_nonblocking(self): 834 def testKillAll_nonblocking(self):
835 with self.assertCalls( 835 with self.assertCalls(
836 (self.call.device.GetPids('some.process'), {'some.process': '1234'}), 836 (self.call.device.GetPids('some.process'), {'some.process': ['1234']}),
837 (self.call.adb.Shell('kill -9 1234'), '')): 837 (self.call.adb.Shell('kill -9 1234'), '')):
838 self.assertEquals( 838 self.assertEquals(
839 1, self.device.KillAll('some.process', blocking=False)) 839 1, self.device.KillAll('some.process', blocking=False))
840 840
841 def testKillAll_blocking(self): 841 def testKillAll_blocking(self):
842 with self.assertCalls( 842 with self.assertCalls(
843 (self.call.device.GetPids('some.process'), {'some.process': '1234'}), 843 (self.call.device.GetPids('some.process'), {'some.process': ['1234']}),
844 (self.call.adb.Shell('kill -9 1234'), ''), 844 (self.call.adb.Shell('kill -9 1234'), ''),
845 (self.call.device.GetPids('some.process'), {'some.process': '1234'}), 845 (self.call.device.GetPids('some.process'), {'some.process': ['1234']}),
846 (self.call.device.GetPids('some.process'), [])): 846 (self.call.device.GetPids('some.process'), [])):
847 self.assertEquals( 847 self.assertEquals(
848 1, self.device.KillAll('some.process', blocking=True)) 848 1, self.device.KillAll('some.process', blocking=True))
849 849
850 def testKillAll_root(self): 850 def testKillAll_root(self):
851 with self.assertCalls( 851 with self.assertCalls(
852 (self.call.device.GetPids('some.process'), {'some.process': '1234'}), 852 (self.call.device.GetPids('some.process'), {'some.process': ['1234']}),
853 (self.call.device.NeedsSU(), True), 853 (self.call.device.NeedsSU(), True),
854 (self.call.adb.Shell("su -c sh -c 'kill -9 1234'"), '')): 854 (self.call.adb.Shell("su -c sh -c 'kill -9 1234'"), '')):
855 self.assertEquals( 855 self.assertEquals(
856 1, self.device.KillAll('some.process', as_root=True)) 856 1, self.device.KillAll('some.process', as_root=True))
857 857
858 def testKillAll_sigterm(self): 858 def testKillAll_sigterm(self):
859 with self.assertCalls( 859 with self.assertCalls(
860 (self.call.device.GetPids('some.process'), {'some.process': '1234'}), 860 (self.call.device.GetPids('some.process'),
861 {'some.process': ['1234']}),
861 (self.call.adb.Shell('kill -15 1234'), '')): 862 (self.call.adb.Shell('kill -15 1234'), '')):
862 self.assertEquals( 863 self.assertEquals(
863 1, self.device.KillAll('some.process', signum=device_signal.SIGTERM)) 864 1, self.device.KillAll('some.process', signum=device_signal.SIGTERM))
864 865
866 def testKillAll_multipleInstances(self):
867 with self.assertCalls(
868 (self.call.device.GetPids('some.process'),
869 {'some.process': ['1234', '4567']}),
870 (self.call.adb.Shell('kill -15 1234 4567'), '')):
871 self.assertEquals(
872 2, self.device.KillAll('some.process', signum=device_signal.SIGTERM))
873
865 874
866 class DeviceUtilsStartActivityTest(DeviceUtilsTest): 875 class DeviceUtilsStartActivityTest(DeviceUtilsTest):
867 876
868 def testStartActivity_actionOnly(self): 877 def testStartActivity_actionOnly(self):
869 test_intent = intent.Intent(action='android.intent.action.VIEW') 878 test_intent = intent.Intent(action='android.intent.action.VIEW')
870 with self.assertCall( 879 with self.assertCall(
871 self.call.adb.Shell('am start ' 880 self.call.adb.Shell('am start '
872 '-a android.intent.action.VIEW'), 881 '-a android.intent.action.VIEW'),
873 'Starting: Intent { act=android.intent.action.VIEW }'): 882 'Starting: Intent { act=android.intent.action.VIEW }'):
874 self.device.StartActivity(test_intent) 883 self.device.StartActivity(test_intent)
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after
1658 def testGetPids_noMatches(self): 1667 def testGetPids_noMatches(self):
1659 with self.assertCall( 1668 with self.assertCall(
1660 self.call.device._RunPipedShellCommand('ps | grep -F does.not.match'), 1669 self.call.device._RunPipedShellCommand('ps | grep -F does.not.match'),
1661 []): 1670 []):
1662 self.assertEqual({}, self.device.GetPids('does.not.match')) 1671 self.assertEqual({}, self.device.GetPids('does.not.match'))
1663 1672
1664 def testGetPids_oneMatch(self): 1673 def testGetPids_oneMatch(self):
1665 with self.assertCall( 1674 with self.assertCall(
1666 self.call.device._RunPipedShellCommand('ps | grep -F one.match'), 1675 self.call.device._RunPipedShellCommand('ps | grep -F one.match'),
1667 ['user 1001 100 1024 1024 ffffffff 00000000 one.match']): 1676 ['user 1001 100 1024 1024 ffffffff 00000000 one.match']):
1668 self.assertEqual({'one.match': '1001'}, self.device.GetPids('one.match')) 1677 self.assertEqual(
1678 {'one.match': ['1001']},
1679 self.device.GetPids('one.match'))
1669 1680
1670 def testGetPids_mutlipleMatches(self): 1681 def testGetPids_multipleMatches(self):
1671 with self.assertCall( 1682 with self.assertCall(
1672 self.call.device._RunPipedShellCommand('ps | grep -F match'), 1683 self.call.device._RunPipedShellCommand('ps | grep -F match'),
1673 ['user 1001 100 1024 1024 ffffffff 00000000 one.match', 1684 ['user 1001 100 1024 1024 ffffffff 00000000 one.match',
1674 'user 1002 100 1024 1024 ffffffff 00000000 two.match', 1685 'user 1002 100 1024 1024 ffffffff 00000000 two.match',
1675 'user 1003 100 1024 1024 ffffffff 00000000 three.match']): 1686 'user 1003 100 1024 1024 ffffffff 00000000 three.match']):
1676 self.assertEqual( 1687 self.assertEqual(
1677 {'one.match': '1001', 'two.match': '1002', 'three.match': '1003'}, 1688 {'one.match': ['1001'],
1689 'two.match': ['1002'],
1690 'three.match': ['1003']},
1678 self.device.GetPids('match')) 1691 self.device.GetPids('match'))
1679 1692
1680 def testGetPids_exactMatch(self): 1693 def testGetPids_exactMatch(self):
1681 with self.assertCall( 1694 with self.assertCall(
1682 self.call.device._RunPipedShellCommand('ps | grep -F exact.match'), 1695 self.call.device._RunPipedShellCommand('ps | grep -F exact.match'),
1683 ['user 1000 100 1024 1024 ffffffff 00000000 not.exact.match', 1696 ['user 1000 100 1024 1024 ffffffff 00000000 not.exact.match',
1684 'user 1234 100 1024 1024 ffffffff 00000000 exact.match']): 1697 'user 1234 100 1024 1024 ffffffff 00000000 exact.match']):
1685 self.assertEqual( 1698 self.assertEqual(
1686 {'not.exact.match': '1000', 'exact.match': '1234'}, 1699 {'not.exact.match': ['1000'], 'exact.match': ['1234']},
1687 self.device.GetPids('exact.match')) 1700 self.device.GetPids('exact.match'))
1688 1701
1689 def testGetPids_quotable(self): 1702 def testGetPids_quotable(self):
1690 with self.assertCall( 1703 with self.assertCall(
1691 self.call.device._RunPipedShellCommand("ps | grep -F 'my$process'"), 1704 self.call.device._RunPipedShellCommand("ps | grep -F 'my$process'"),
1692 ['user 1234 100 1024 1024 ffffffff 00000000 my$process']): 1705 ['user 1234 100 1024 1024 ffffffff 00000000 my$process']):
1693 self.assertEqual( 1706 self.assertEqual(
1694 {'my$process': '1234'}, self.device.GetPids('my$process')) 1707 {'my$process': ['1234']}, self.device.GetPids('my$process'))
1708
1709 def testGetPids_multipleInstances(self):
1710 with self.assertCall(
1711 self.call.device._RunPipedShellCommand('ps | grep -F foo'),
1712 ['user 1000 100 1024 1024 ffffffff 00000000 foo',
1713 'user 1234 100 1024 1024 ffffffff 00000000 foo']):
1714 self.assertEqual(
1715 {'foo': ['1000', '1234']},
1716 self.device.GetPids('foo'))
1695 1717
1696 1718
1697 class DeviceUtilsTakeScreenshotTest(DeviceUtilsTest): 1719 class DeviceUtilsTakeScreenshotTest(DeviceUtilsTest):
1698 1720
1699 def testTakeScreenshot_fileNameProvided(self): 1721 def testTakeScreenshot_fileNameProvided(self):
1700 with self.assertCalls( 1722 with self.assertCalls(
1701 (mock.call.pylib.utils.device_temp_file.DeviceTempFile( 1723 (mock.call.pylib.utils.device_temp_file.DeviceTempFile(
1702 self.adb, suffix='.png'), 1724 self.adb, suffix='.png'),
1703 MockTempFile('/tmp/path/temp-123.png')), 1725 MockTempFile('/tmp/path/temp-123.png')),
1704 (self.call.adb.Shell('/system/bin/screencap -p /tmp/path/temp-123.png'), 1726 (self.call.adb.Shell('/system/bin/screencap -p /tmp/path/temp-123.png'),
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1836 devices = device_utils.DeviceUtils.HealthyDevices() 1858 devices = device_utils.DeviceUtils.HealthyDevices()
1837 self.assertEquals(1, len(devices)) 1859 self.assertEquals(1, len(devices))
1838 self.assertTrue(isinstance(devices[0], device_utils.DeviceUtils)) 1860 self.assertTrue(isinstance(devices[0], device_utils.DeviceUtils))
1839 self.assertEquals('0123456789abcdef', devices[0].adb.GetDeviceSerial()) 1861 self.assertEquals('0123456789abcdef', devices[0].adb.GetDeviceSerial())
1840 1862
1841 1863
1842 if __name__ == '__main__': 1864 if __name__ == '__main__':
1843 logging.getLogger().setLevel(logging.DEBUG) 1865 logging.getLogger().setLevel(logging.DEBUG)
1844 unittest.main(verbosity=2) 1866 unittest.main(verbosity=2)
1845 1867
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698