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

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

Issue 924003003: [Android] Migrate DeviceUtils.GetMemoryUsageForPid to adb_wrapper. (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 1381 matching lines...) Expand 10 before | Expand all | Expand 10 after
1392 self.assertEqual( 1392 self.assertEqual(
1393 { 1393 {
1394 'num_reads': 1, 1394 'num_reads': 1,
1395 'num_writes': 5, 1395 'num_writes': 5,
1396 'read_ms': 4, 1396 'read_ms': 4,
1397 'write_ms': 8, 1397 'write_ms': 8,
1398 }, 1398 },
1399 self.device.GetIOStats()) 1399 self.device.GetIOStats())
1400 1400
1401 1401
1402 class DeviceUtilsGetMemoryUsageForPidTest(DeviceUtilsOldImplTest): 1402 class DeviceUtilsGetMemoryUsageForPidTest(DeviceUtilsNewImplTest):
1403 1403
1404 def setUp(self): 1404 def setUp(self):
1405 super(DeviceUtilsGetMemoryUsageForPidTest, self).setUp() 1405 super(DeviceUtilsGetMemoryUsageForPidTest, self).setUp()
1406 self.device.old_interface._privileged_command_runner = (
1407 self.device.old_interface.RunShellCommand)
1408 self.device.old_interface._protected_file_access_method_initialized = True
1409 1406
1410 def testGetMemoryUsageForPid_validPid(self): 1407 def testGetMemoryUsageForPid_validPid(self):
1411 with self.assertCallsSequence([ 1408 with self.assertCalls(
1412 ("adb -s 0123456789abcdef shell 'showmap 1234'", 1409 (self.call.device.RunShellCommand(
1413 '100 101 102 103 104 105 106 107 TOTAL\r\n'), 1410 ['showmap', '1234'], as_root=True, check_return=True),
1414 ("adb -s 0123456789abcdef shell " 1411 ['100 101 102 103 104 105 106 107 TOTAL']),
1415 "'cat \"/proc/1234/status\" 2> /dev/null'", 1412 (self.call.device.ReadFile('/proc/1234/status', as_root=True),
1416 'VmHWM: 1024 kB') 1413 'VmHWM: 1024 kB\n')):
1417 ]):
1418 self.assertEqual( 1414 self.assertEqual(
1419 { 1415 {
1420 'Size': 100, 1416 'Size': 100,
1421 'Rss': 101, 1417 'Rss': 101,
1422 'Pss': 102, 1418 'Pss': 102,
1423 'Shared_Clean': 103, 1419 'Shared_Clean': 103,
1424 'Shared_Dirty': 104, 1420 'Shared_Dirty': 104,
1425 'Private_Clean': 105, 1421 'Private_Clean': 105,
1426 'Private_Dirty': 106, 1422 'Private_Dirty': 106,
1427 'VmHWM': 1024 1423 'VmHWM': 1024
1428 }, 1424 },
1429 self.device.GetMemoryUsageForPid(1234)) 1425 self.device.GetMemoryUsageForPid(1234))
1430 1426
1431 def testGetMemoryUsageForPid_invalidPid(self): 1427 def testGetMemoryUsageForPid_noSmaps(self):
1432 with self.assertCalls( 1428 with self.assertCalls(
1433 "adb -s 0123456789abcdef shell 'showmap 4321'", 1429 (self.call.device.RunShellCommand(
1434 'cannot open /proc/4321/smaps: No such file or directory\r\n'): 1430 ['showmap', '4321'], as_root=True, check_return=True),
1435 self.assertEqual({}, self.device.GetMemoryUsageForPid(4321)) 1431 ['cannot open /proc/4321/smaps: No such file or directory']),
1432 (self.call.device.ReadFile('/proc/4321/status', as_root=True),
1433 'VmHWM: 1024 kb\n')):
1434 self.assertEquals({'VmHWM': 1024}, self.device.GetMemoryUsageForPid(4321))
1435
1436 def testGetMemoryUsageForPid_noStatus(self):
1437 with self.assertCalls(
1438 (self.call.device.RunShellCommand(
1439 ['showmap', '4321'], as_root=True, check_return=True),
1440 ['100 101 102 103 104 105 106 107 TOTAL']),
1441 (self.call.device.ReadFile('/proc/4321/status', as_root=True),
1442 self.CommandError())):
1443 self.assertEquals(
1444 {
1445 'Size': 100,
1446 'Rss': 101,
1447 'Pss': 102,
1448 'Shared_Clean': 103,
1449 'Shared_Dirty': 104,
1450 'Private_Clean': 105,
1451 'Private_Dirty': 106,
1452 },
1453 self.device.GetMemoryUsageForPid(4321))
1436 1454
1437 1455
1438 class DeviceUtilsStrTest(DeviceUtilsNewImplTest): 1456 class DeviceUtilsStrTest(DeviceUtilsNewImplTest):
1439 1457
1440 def testStr_returnsSerial(self): 1458 def testStr_returnsSerial(self):
1441 with self.assertCalls( 1459 with self.assertCalls(
1442 (self.call.adb.GetDeviceSerial(), '0123456789abcdef')): 1460 (self.call.adb.GetDeviceSerial(), '0123456789abcdef')):
1443 self.assertEqual('0123456789abcdef', str(self.device)) 1461 self.assertEqual('0123456789abcdef', str(self.device))
1444 1462
1445 1463
1446 class DeviceUtilsParallelTest(mock_calls.TestCase): 1464 class DeviceUtilsParallelTest(mock_calls.TestCase):
1447 1465
1448 def testParallel_default(self): 1466 def testParallel_default(self):
1449 test_serials = ['0123456789abcdef', 'fedcba9876543210'] 1467 test_serials = ['0123456789abcdef', 'fedcba9876543210']
1450 with self.assertCall( 1468 with self.assertCall(
1451 mock.call.pylib.device.adb_wrapper.AdbWrapper.GetDevices(), 1469 mock.call.pylib.device.adb_wrapper.AdbWrapper.GetDevices(),
1452 [_AdbWrapperMock(serial) for serial in test_serials]): 1470 [_AdbWrapperMock(serial) for serial in test_serials]):
1453 parallel_devices = device_utils.DeviceUtils.parallel() 1471 parallel_devices = device_utils.DeviceUtils.parallel()
1454 for serial, device in zip(test_serials, parallel_devices.pGet(None)): 1472 for serial, device in zip(test_serials, parallel_devices.pGet(None)):
1455 self.assertTrue( 1473 self.assertTrue(
1456 isinstance(device, device_utils.DeviceUtils) 1474 isinstance(device, device_utils.DeviceUtils)
1457 and serial == str(device), 1475 and serial == str(device),
1458 'Expected a DeviceUtils object with serial %s' % serial) 1476 'Expected a DeviceUtils object with serial %s' % serial)
1459 1477
1460 1478
1461 if __name__ == '__main__': 1479 if __name__ == '__main__':
1462 logging.getLogger().setLevel(logging.DEBUG) 1480 logging.getLogger().setLevel(logging.DEBUG)
1463 unittest.main(verbosity=2) 1481 unittest.main(verbosity=2)
1464 1482
OLDNEW
« build/android/pylib/device/device_utils.py ('K') | « build/android/pylib/device/device_utils.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698