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

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

Issue 929603002: [Android] Add PIE support for ICS devices. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.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
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 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 self.assertEquals( 590 self.assertEquals(
591 [payload], 591 [payload],
592 self.device.RunShellCommand(['echo', payload], as_root=True)) 592 self.device.RunShellCommand(['echo', payload], as_root=True))
593 593
594 def testRunShellCommand_withSu(self): 594 def testRunShellCommand_withSu(self):
595 with self.assertCalls( 595 with self.assertCalls(
596 (self.call.device.NeedsSU(), True), 596 (self.call.device.NeedsSU(), True),
597 (self.call.adb.Shell("su -c sh -c 'setprop service.adb.root 0'"), '')): 597 (self.call.adb.Shell("su -c sh -c 'setprop service.adb.root 0'"), '')):
598 self.device.RunShellCommand('setprop service.adb.root 0', as_root=True) 598 self.device.RunShellCommand('setprop service.adb.root 0', as_root=True)
599 599
600 def testRunShellCommand_withPie_ics(self):
601 with self.assertCalls(
602 (self.call.device.build_version_sdk(),
jbudorick 2015/02/17 15:15:10 These calls to build_version_sdk() are why we need
perezju 2015/02/17 16:04:26 Acknowledged.
603 constants.ANDROID_SDK_VERSION_CODES.ICE_CREAM_SANDWICH),
604 (self.call.device.GetDevicePieWrapper(), '/path/to/run_pie'),
605 (self.call.adb.Shell('/path/to/run_pie md5sum /foo/bar'),
606 '0123456789abcdef0123456789abcdef')):
607 self.device.RunShellCommand('md5sum /foo/bar', with_pie=True)
608
609 def testRunShellCommand_withPie_jb(self):
610 with self.assertCalls(
611 (self.call.device.build_version_sdk(),
612 constants.ANDROID_SDK_VERSION_CODES.JELLY_BEAN),
613 (self.call.adb.Shell('md5sum /foo/bar'),
614 '0123456789abcdef0123456789abcdef')):
615 self.device.RunShellCommand('md5sum /foo/bar', with_pie=True)
616
600 def testRunShellCommand_manyLines(self): 617 def testRunShellCommand_manyLines(self):
601 cmd = 'ls /some/path' 618 cmd = 'ls /some/path'
602 with self.assertCall(self.call.adb.Shell(cmd), 'file1\nfile2\nfile3\n'): 619 with self.assertCall(self.call.adb.Shell(cmd), 'file1\nfile2\nfile3\n'):
603 self.assertEquals(['file1', 'file2', 'file3'], 620 self.assertEquals(['file1', 'file2', 'file3'],
604 self.device.RunShellCommand(cmd)) 621 self.device.RunShellCommand(cmd))
605 622
606 def testRunShellCommand_singleLine_success(self): 623 def testRunShellCommand_singleLine_success(self):
607 cmd = 'echo $VALUE' 624 cmd = 'echo $VALUE'
608 with self.assertCall(self.call.adb.Shell(cmd), 'some value\n'): 625 with self.assertCall(self.call.adb.Shell(cmd), 'some value\n'):
609 self.assertEquals('some value', 626 self.assertEquals('some value',
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 self.device.RunShellCommand(cmd, check_return=True) 666 self.device.RunShellCommand(cmd, check_return=True)
650 667
651 def testRunShellCommand_checkReturn_disabled(self): 668 def testRunShellCommand_checkReturn_disabled(self):
652 cmd = 'ls /root' 669 cmd = 'ls /root'
653 output = 'opendir failed, Permission denied\n' 670 output = 'opendir failed, Permission denied\n'
654 with self.assertCall(self.call.adb.Shell(cmd), self.ShellError(output)): 671 with self.assertCall(self.call.adb.Shell(cmd), self.ShellError(output)):
655 self.assertEquals([output.rstrip()], 672 self.assertEquals([output.rstrip()],
656 self.device.RunShellCommand(cmd, check_return=False)) 673 self.device.RunShellCommand(cmd, check_return=False))
657 674
658 675
676 class DeviceUtilsGetDevicePieWrapper(DeviceUtilsNewImplTest):
677
678 def testGetDevicePieWrapper_jb(self):
679 with self.assertCall(
680 self.call.device.build_version_sdk(),
681 constants.ANDROID_SDK_VERSION_CODES.JELLY_BEAN):
682 self.assertEqual('', self.device.GetDevicePieWrapper())
683
684 def testGetDevicePieWrapper_ics(self):
685 with mock.patch('pylib.constants.GetOutDirectory',
686 mock.Mock(return_value='/foo/bar')), (
687 mock.patch('os.path.exists', return_value=True)):
perezju 2015/02/16 10:25:23 you could also place these in the list of assertCa
jbudorick 2015/02/17 15:15:10 Oh, nice. I like that better.
688 with self.assertCalls(
689 (self.call.device.build_version_sdk(),
690 constants.ANDROID_SDK_VERSION_CODES.ICE_CREAM_SANDWICH),
691 (self.call.adb.Push(mock.ANY, mock.ANY),
692 '')):
693 self.assertNotEqual('', self.device.GetDevicePieWrapper())
694
695
659 @mock.patch('time.sleep', mock.Mock()) 696 @mock.patch('time.sleep', mock.Mock())
660 class DeviceUtilsKillAllTest(DeviceUtilsNewImplTest): 697 class DeviceUtilsKillAllTest(DeviceUtilsNewImplTest):
661 698
662 def testKillAll_noMatchingProcesses(self): 699 def testKillAll_noMatchingProcesses(self):
663 with self.assertCall(self.call.adb.Shell('ps'), 700 with self.assertCall(self.call.adb.Shell('ps'),
664 'USER PID PPID VSIZE RSS WCHAN PC NAME\n'): 701 'USER PID PPID VSIZE RSS WCHAN PC NAME\n'):
665 with self.assertRaises(device_errors.CommandFailedError): 702 with self.assertRaises(device_errors.CommandFailedError):
666 self.device.KillAll('test_process') 703 self.device.KillAll('test_process')
667 704
668 def testKillAll_nonblocking(self): 705 def testKillAll_nonblocking(self):
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after
1455 self.assertTrue( 1492 self.assertTrue(
1456 isinstance(device, device_utils.DeviceUtils) 1493 isinstance(device, device_utils.DeviceUtils)
1457 and serial == str(device), 1494 and serial == str(device),
1458 'Expected a DeviceUtils object with serial %s' % serial) 1495 'Expected a DeviceUtils object with serial %s' % serial)
1459 1496
1460 1497
1461 if __name__ == '__main__': 1498 if __name__ == '__main__':
1462 logging.getLogger().setLevel(logging.DEBUG) 1499 logging.getLogger().setLevel(logging.DEBUG)
1463 unittest.main(verbosity=2) 1500 unittest.main(verbosity=2)
1464 1501
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698