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

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

Issue 1079113002: [Android] Add a "quiet" flag so KillAll doesn't complain if no processes killed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update pylib/screenshot.py Created 5 years, 8 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 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 constants.ANDROID_SDK_VERSION_CODES.ICE_CREAM_SANDWICH), 634 constants.ANDROID_SDK_VERSION_CODES.ICE_CREAM_SANDWICH),
635 (mock.call.pylib.constants.GetOutDirectory(), '/foo/bar'), 635 (mock.call.pylib.constants.GetOutDirectory(), '/foo/bar'),
636 (mock.call.os.path.exists(mock.ANY), True), 636 (mock.call.os.path.exists(mock.ANY), True),
637 (self.call.adb.Push(mock.ANY, mock.ANY), '')): 637 (self.call.adb.Push(mock.ANY, mock.ANY), '')):
638 self.assertNotEqual('', self.device.GetDevicePieWrapper()) 638 self.assertNotEqual('', self.device.GetDevicePieWrapper())
639 639
640 640
641 @mock.patch('time.sleep', mock.Mock()) 641 @mock.patch('time.sleep', mock.Mock())
642 class DeviceUtilsKillAllTest(DeviceUtilsTest): 642 class DeviceUtilsKillAllTest(DeviceUtilsTest):
643 643
644 def testKillAll_noMatchingProcesses(self): 644 def testKillAll_noMatchingProcessesFailure(self):
645 with self.assertCall(self.call.adb.Shell('ps'), 645 with self.assertCall(self.call.device.GetPids('test_process'), {}):
646 'USER PID PPID VSIZE RSS WCHAN PC NAME\n'):
647 with self.assertRaises(device_errors.CommandFailedError): 646 with self.assertRaises(device_errors.CommandFailedError):
648 self.device.KillAll('test_process') 647 self.device.KillAll('test_process')
649 648
649 def testKillAll_noMatchingProcessesQuiet(self):
650 with self.assertCall(self.call.device.GetPids('test_process'), {}):
651 self.assertEqual(0, self.device.KillAll('test_process', quiet=True))
652
650 def testKillAll_nonblocking(self): 653 def testKillAll_nonblocking(self):
651 with self.assertCalls( 654 with self.assertCalls(
652 (self.call.adb.Shell('ps'), 655 (self.call.device.GetPids('some.process'), {'some.process': '1234'}),
653 'USER PID PPID VSIZE RSS WCHAN PC NAME\n'
654 'u0_a1 1234 174 123456 54321 ffffffff 456789ab some.process\n'),
655 (self.call.adb.Shell('kill -9 1234'), '')): 656 (self.call.adb.Shell('kill -9 1234'), '')):
656 self.assertEquals(1, 657 self.assertEquals(1,
657 self.device.KillAll('some.process', blocking=False)) 658 self.device.KillAll('some.process', blocking=False))
658 659
659 def testKillAll_blocking(self): 660 def testKillAll_blocking(self):
660 with self.assertCalls( 661 with self.assertCalls(
661 (self.call.adb.Shell('ps'), 662 (self.call.device.GetPids('some.process'), {'some.process': '1234'}),
662 'USER PID PPID VSIZE RSS WCHAN PC NAME\n'
663 'u0_a1 1234 174 123456 54321 ffffffff 456789ab some.process\n'),
664 (self.call.adb.Shell('kill -9 1234'), ''), 663 (self.call.adb.Shell('kill -9 1234'), ''),
665 (self.call.adb.Shell('ps'), 664 (self.call.device.GetPids('some.process'), {'some.process': '1234'}),
666 'USER PID PPID VSIZE RSS WCHAN PC NAME\n' 665 (self.call.device.GetPids('some.process'), {})):
667 'u0_a1 1234 174 123456 54321 ffffffff 456789ab some.process\n'),
668 (self.call.adb.Shell('ps'),
669 'USER PID PPID VSIZE RSS WCHAN PC NAME\n')):
670 self.assertEquals(1, 666 self.assertEquals(1,
671 self.device.KillAll('some.process', blocking=True)) 667 self.device.KillAll('some.process', blocking=True))
672 668
673 def testKillAll_root(self): 669 def testKillAll_root(self):
674 with self.assertCalls( 670 with self.assertCalls(
675 (self.call.adb.Shell('ps'), 671 (self.call.device.GetPids('some.process'), {'some.process': '1234'}),
676 'USER PID PPID VSIZE RSS WCHAN PC NAME\n'
677 'u0_a1 1234 174 123456 54321 ffffffff 456789ab some.process\n'),
678 (self.call.device.NeedsSU(), True), 672 (self.call.device.NeedsSU(), True),
679 (self.call.adb.Shell("su -c sh -c 'kill -9 1234'"), '')): 673 (self.call.adb.Shell("su -c sh -c 'kill -9 1234'"), '')):
680 self.assertEquals(1, 674 self.assertEquals(1,
681 self.device.KillAll('some.process', as_root=True)) 675 self.device.KillAll('some.process', as_root=True))
682 676
683 def testKillAll_sigterm(self): 677 def testKillAll_sigterm(self):
684 with self.assertCalls( 678 with self.assertCalls(
685 (self.call.adb.Shell('ps'), 679 (self.call.device.GetPids('some.process'), {'some.process': '1234'}),
686 'USER PID PPID VSIZE RSS WCHAN PC NAME\n'
687 'u0_a1 1234 174 123456 54321 ffffffff 456789ab some.process\n'),
688 (self.call.adb.Shell('kill -15 1234'), '')): 680 (self.call.adb.Shell('kill -15 1234'), '')):
689 self.assertEquals(1, 681 self.assertEquals(1,
690 self.device.KillAll('some.process', signum=signal.SIGTERM)) 682 self.device.KillAll('some.process', signum=signal.SIGTERM))
691 683
692 684
693 class DeviceUtilsStartActivityTest(DeviceUtilsTest): 685 class DeviceUtilsStartActivityTest(DeviceUtilsTest):
694 686
695 def testStartActivity_actionOnly(self): 687 def testStartActivity_actionOnly(self):
696 test_intent = intent.Intent(action='android.intent.action.VIEW') 688 test_intent = intent.Intent(action='android.intent.action.VIEW')
697 with self.assertCall( 689 with self.assertCall(
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after
1540 self.assertEqual(client_cache_one, {'test': 1}) 1532 self.assertEqual(client_cache_one, {'test': 1})
1541 self.assertEqual(client_cache_two, {'test': 1}) 1533 self.assertEqual(client_cache_two, {'test': 1})
1542 self.device._ClearCache() 1534 self.device._ClearCache()
1543 self.assertEqual(client_cache_one, {}) 1535 self.assertEqual(client_cache_one, {})
1544 self.assertEqual(client_cache_two, {}) 1536 self.assertEqual(client_cache_two, {})
1545 1537
1546 if __name__ == '__main__': 1538 if __name__ == '__main__':
1547 logging.getLogger().setLevel(logging.DEBUG) 1539 logging.getLogger().setLevel(logging.DEBUG)
1548 unittest.main(verbosity=2) 1540 unittest.main(verbosity=2)
1549 1541
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698