| OLD | NEW |
| 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 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n'): | 550 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n'): |
| 551 with self.assertRaises(device_errors.CommandFailedError): | 551 with self.assertRaises(device_errors.CommandFailedError): |
| 552 self.device.KillAll('test_process') | 552 self.device.KillAll('test_process') |
| 553 | 553 |
| 554 def testKillAll_nonblocking(self): | 554 def testKillAll_nonblocking(self): |
| 555 with self.assertCallsSequence([ | 555 with self.assertCallsSequence([ |
| 556 ("adb -s 0123456789abcdef shell 'ps'", | 556 ("adb -s 0123456789abcdef shell 'ps'", |
| 557 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n' | 557 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n' |
| 558 'u0_a1 1234 174 123456 54321 ffffffff 456789ab ' | 558 'u0_a1 1234 174 123456 54321 ffffffff 456789ab ' |
| 559 'this.is.a.test.process\r\n'), | 559 'this.is.a.test.process\r\n'), |
| 560 ("adb -s 0123456789abcdef shell 'ps'", | |
| 561 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n' | |
| 562 'u0_a1 1234 174 123456 54321 ffffffff 456789ab ' | |
| 563 'this.is.a.test.process\r\n'), | |
| 564 ("adb -s 0123456789abcdef shell 'kill -9 1234'", '')]): | 560 ("adb -s 0123456789abcdef shell 'kill -9 1234'", '')]): |
| 565 self.device.KillAll('this.is.a.test.process', blocking=False) | 561 self.assertEquals(1, |
| 562 self.device.KillAll('this.is.a.test.process', blocking=False)) |
| 566 | 563 |
| 567 def testKillAll_blocking(self): | 564 def testKillAll_blocking(self): |
| 568 with mock.patch('time.sleep'): | 565 with mock.patch('time.sleep'): |
| 569 with self.assertCallsSequence([ | 566 with self.assertCallsSequence([ |
| 570 ("adb -s 0123456789abcdef shell 'ps'", | 567 ("adb -s 0123456789abcdef shell 'ps'", |
| 571 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n' | 568 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n' |
| 572 'u0_a1 1234 174 123456 54321 ffffffff 456789ab ' | 569 'u0_a1 1234 174 123456 54321 ffffffff 456789ab ' |
| 573 'this.is.a.test.process\r\n'), | 570 'this.is.a.test.process\r\n'), |
| 574 ("adb -s 0123456789abcdef shell 'ps'", | |
| 575 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n' | |
| 576 'u0_a1 1234 174 123456 54321 ffffffff 456789ab ' | |
| 577 'this.is.a.test.process\r\n'), | |
| 578 ("adb -s 0123456789abcdef shell 'kill -9 1234'", ''), | 571 ("adb -s 0123456789abcdef shell 'kill -9 1234'", ''), |
| 579 ("adb -s 0123456789abcdef shell 'ps'", | 572 ("adb -s 0123456789abcdef shell 'ps'", |
| 580 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n' | 573 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n' |
| 581 'u0_a1 1234 174 123456 54321 ffffffff 456789ab ' | 574 'u0_a1 1234 174 123456 54321 ffffffff 456789ab ' |
| 582 'this.is.a.test.process\r\n'), | 575 'this.is.a.test.process\r\n'), |
| 583 ("adb -s 0123456789abcdef shell 'ps'", | 576 ("adb -s 0123456789abcdef shell 'ps'", |
| 584 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n')]): | 577 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n')]): |
| 585 self.device.KillAll('this.is.a.test.process', blocking=True) | 578 self.assertEquals(1, |
| 579 self.device.KillAll('this.is.a.test.process', blocking=True)) |
| 586 | 580 |
| 587 def testKillAll_root(self): | 581 def testKillAll_root(self): |
| 588 with self.assertCallsSequence([ | 582 with self.assertCallsSequence([ |
| 589 ("adb -s 0123456789abcdef shell 'ps'", | 583 ("adb -s 0123456789abcdef shell 'ps'", |
| 590 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n' | 584 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n' |
| 591 'u0_a1 1234 174 123456 54321 ffffffff 456789ab ' | 585 'u0_a1 1234 174 123456 54321 ffffffff 456789ab ' |
| 592 'this.is.a.test.process\r\n'), | 586 'this.is.a.test.process\r\n'), |
| 593 ("adb -s 0123456789abcdef shell 'ps'", | 587 ("adb -s 0123456789abcdef shell 'ls /root'", 'Permission denied\r\n'), |
| 594 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n' | |
| 595 'u0_a1 1234 174 123456 54321 ffffffff 456789ab ' | |
| 596 'this.is.a.test.process\r\n'), | |
| 597 ("adb -s 0123456789abcdef shell 'su -c kill -9 1234'", '')]): | 588 ("adb -s 0123456789abcdef shell 'su -c kill -9 1234'", '')]): |
| 598 self.device.KillAll('this.is.a.test.process', as_root=True) | 589 self.assertEquals(1, |
| 590 self.device.KillAll('this.is.a.test.process', as_root=True)) |
| 599 | 591 |
| 600 def testKillAll_sigterm(self): | 592 def testKillAll_sigterm(self): |
| 601 with self.assertCallsSequence([ | 593 with self.assertCallsSequence([ |
| 602 ("adb -s 0123456789abcdef shell 'ps'", | 594 ("adb -s 0123456789abcdef shell 'ps'", |
| 603 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n' | 595 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n' |
| 604 'u0_a1 1234 174 123456 54321 ffffffff 456789ab ' | 596 'u0_a1 1234 174 123456 54321 ffffffff 456789ab ' |
| 605 'this.is.a.test.process\r\n'), | 597 'this.is.a.test.process\r\n'), |
| 606 ("adb -s 0123456789abcdef shell 'ps'", | |
| 607 'USER PID PPID VSIZE RSS WCHAN PC NAME\r\n' | |
| 608 'u0_a1 1234 174 123456 54321 ffffffff 456789ab ' | |
| 609 'this.is.a.test.process\r\n'), | |
| 610 ("adb -s 0123456789abcdef shell 'kill -15 1234'", '')]): | 598 ("adb -s 0123456789abcdef shell 'kill -15 1234'", '')]): |
| 611 self.device.KillAll('this.is.a.test.process', signum=signal.SIGTERM) | 599 self.assertEquals(1, |
| 600 self.device.KillAll('this.is.a.test.process', signum=signal.SIGTERM)) |
| 612 | 601 |
| 613 | 602 |
| 614 class DeviceUtilsStartActivityTest(DeviceUtilsOldImplTest): | 603 class DeviceUtilsStartActivityTest(DeviceUtilsOldImplTest): |
| 615 | 604 |
| 616 def testStartActivity_actionOnly(self): | 605 def testStartActivity_actionOnly(self): |
| 617 test_intent = intent.Intent(action='android.intent.action.VIEW') | 606 test_intent = intent.Intent(action='android.intent.action.VIEW') |
| 618 with self.assertCalls( | 607 with self.assertCalls( |
| 619 "adb -s 0123456789abcdef shell 'am start " | 608 "adb -s 0123456789abcdef shell 'am start " |
| 620 "-a android.intent.action.VIEW'", | 609 "-a android.intent.action.VIEW'", |
| 621 'Starting: Intent { act=android.intent.action.VIEW }'): | 610 'Starting: Intent { act=android.intent.action.VIEW }'): |
| (...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1493 self.device = device_utils.DeviceUtils(None) | 1482 self.device = device_utils.DeviceUtils(None) |
| 1494 with self.assertCalls('adb get-serialno', 'unknown'), ( | 1483 with self.assertCalls('adb get-serialno', 'unknown'), ( |
| 1495 self.assertRaises(device_errors.NoDevicesError)): | 1484 self.assertRaises(device_errors.NoDevicesError)): |
| 1496 str(self.device) | 1485 str(self.device) |
| 1497 | 1486 |
| 1498 | 1487 |
| 1499 if __name__ == '__main__': | 1488 if __name__ == '__main__': |
| 1500 logging.getLogger().setLevel(logging.DEBUG) | 1489 logging.getLogger().setLevel(logging.DEBUG) |
| 1501 unittest.main(verbosity=2) | 1490 unittest.main(verbosity=2) |
| 1502 | 1491 |
| OLD | NEW |