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 1425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1436 self.assertEqual( | 1436 self.assertEqual( |
1437 { | 1437 { |
1438 'num_reads': 1, | 1438 'num_reads': 1, |
1439 'num_writes': 5, | 1439 'num_writes': 5, |
1440 'read_ms': 4, | 1440 'read_ms': 4, |
1441 'write_ms': 8, | 1441 'write_ms': 8, |
1442 }, | 1442 }, |
1443 self.device.GetIOStats()) | 1443 self.device.GetIOStats()) |
1444 | 1444 |
1445 | 1445 |
| 1446 class DeviceUtilsGetMemoryUsageForPidTest(DeviceUtilsOldImplTest): |
| 1447 |
| 1448 def setUp(self): |
| 1449 super(DeviceUtilsGetMemoryUsageForPidTest, self).setUp() |
| 1450 self.device.old_interface._privileged_command_runner = ( |
| 1451 self.device.old_interface.RunShellCommand) |
| 1452 self.device.old_interface._protected_file_access_method_initialized = True |
| 1453 |
| 1454 def testGetMemoryUsageForPid_validPid(self): |
| 1455 with self.assertCallsSequence([ |
| 1456 ("adb -s 0123456789abcdef shell 'showmap 1234'", |
| 1457 '100 101 102 103 104 105 106 107 TOTAL\r\n'), |
| 1458 ("adb -s 0123456789abcdef shell " |
| 1459 "'cat \"/proc/1234/status\" 2> /dev/null'", |
| 1460 'VmHWM: 1024 kB') |
| 1461 ]): |
| 1462 self.assertEqual( |
| 1463 { |
| 1464 'Size': 100, |
| 1465 'Rss': 101, |
| 1466 'Pss': 102, |
| 1467 'Shared_Clean': 103, |
| 1468 'Shared_Dirty': 104, |
| 1469 'Private_Clean': 105, |
| 1470 'Private_Dirty': 106, |
| 1471 'VmHWM': 1024 |
| 1472 }, |
| 1473 self.device.GetMemoryUsageForPid(1234)) |
| 1474 |
| 1475 def testGetMemoryUsageForPid_invalidPid(self): |
| 1476 with self.assertCalls( |
| 1477 "adb -s 0123456789abcdef shell 'showmap 4321'", |
| 1478 'cannot open /proc/4321/smaps: No such file or directory\r\n'): |
| 1479 self.assertEqual({}, self.device.GetMemoryUsageForPid(4321)) |
| 1480 |
| 1481 |
| 1482 class DeviceUtilsStrTest(DeviceUtilsOldImplTest): |
| 1483 def testStr_noAdbCalls(self): |
| 1484 with self.assertNoAdbCalls(): |
| 1485 self.assertEqual('0123456789abcdef', str(self.device)) |
| 1486 |
| 1487 |
1446 if __name__ == '__main__': | 1488 if __name__ == '__main__': |
1447 logging.getLogger().setLevel(logging.DEBUG) | 1489 logging.getLogger().setLevel(logging.DEBUG) |
1448 unittest.main(verbosity=2) | 1490 unittest.main(verbosity=2) |
1449 | 1491 |
OLD | NEW |