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

Unified Diff: build/android/pylib/device/device_utils_test.py

Issue 285143002: [Android] Convert to DeviceUtils versions of IsOnline, HasRoot, and EnableRoot. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/pylib/device/device_utils.py ('k') | build/android/pylib/gtest/test_runner.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/pylib/device/device_utils_test.py
diff --git a/build/android/pylib/device/device_utils_test.py b/build/android/pylib/device/device_utils_test.py
index 0aff7ec9358d84707a554abc0dc3ae29d29003d1..4c00e4941a8275a29afb78de6d1cfa17e58e4253 100644
--- a/build/android/pylib/device/device_utils_test.py
+++ b/build/android/pylib/device/device_utils_test.py
@@ -9,10 +9,13 @@ Unit tests for the contents of device_utils.py (mostly DeviceUtils).
# pylint: disable=W0212
# pylint: disable=W0613
+import random
import unittest
+
from pylib import android_commands
from pylib import cmd_helper
from pylib.device import adb_wrapper
+from pylib.device import device_errors
from pylib.device import device_utils
@@ -21,9 +24,10 @@ class DeviceUtilsTest(unittest.TestCase):
pass
def testRestartServerNotRunning(self):
- # TODO(jbudorick) If these fail, it's not DeviceUtils's fault.
- self.assertEqual(0, cmd_helper.RunCmd(['pkill', 'adb']))
- self.assertNotEqual(0, cmd_helper.RunCmd(['pgrep', 'adb']))
+ self.assertEqual(0, cmd_helper.RunCmd(['pkill', 'adb']),
+ msg='Unable to kill adb during setup.')
+ self.assertNotEqual(0, cmd_helper.RunCmd(['pgrep', 'adb']),
+ msg='Unexpectedly found adb during setup.')
device_utils.RestartServer()
self.assertEqual(0, cmd_helper.RunCmd(['pgrep', 'adb']))
@@ -63,7 +67,83 @@ class DeviceUtilsTest(unittest.TestCase):
d = device_utils.DeviceUtils(None)
self.assertIsNone(d.old_interface.GetDevice())
+ @staticmethod
+ def _getTestAdbWrapper():
+ devices = adb_wrapper.AdbWrapper.GetDevices()
+ if devices:
+ return random.choice(devices)
+ return None
+
+ @staticmethod
+ def _getUnusedSerial():
+ used_devices = [str(d) for d in adb_wrapper.AdbWrapper.GetDevices()]
+ while True:
+ serial = ''
+ for _ in xrange(0, 16):
+ serial += random.choice('0123456789abcdef')
+ if serial not in used_devices:
+ return serial
+
+ def testIsOnline(self):
+ d = device_utils.DeviceUtils(self._getTestAdbWrapper())
+ self.assertTrue(d is None or d.IsOnline())
+ d = device_utils.DeviceUtils(self._getUnusedSerial())
+ self.assertFalse(d.IsOnline())
+
+ def testHasRoot(self):
+ a = self._getTestAdbWrapper()
+ d = device_utils.DeviceUtils(a)
+ secure_prop = a.Shell('getprop ro.secure').strip()
+ if secure_prop == '1':
+ build_type_prop = a.Shell('getprop ro.build.type').strip()
+ if build_type_prop == 'userdebug':
+ adb_root_prop = a.Shell('getprop service.adb.root').strip()
+ if adb_root_prop is None or adb_root_prop == '0':
+ self.assertFalse(d.HasRoot())
+ else:
+ self.assertTrue(d.HasRoot())
+ else:
+ self.assertFalse(d.HasRoot())
+ else:
+ self.assertTrue(d.HasRoot())
+
+ def testEnableRoot(self):
+ a = self._getTestAdbWrapper()
+ d = device_utils.DeviceUtils(a)
+
+ secure_prop = a.Shell('getprop ro.secure').strip()
+ if secure_prop == '1':
+ build_type_prop = a.Shell('getprop ro.build.type').strip()
+ if build_type_prop == 'userdebug':
+ # Turn off the adb root property
+ adb_root_prop = a.Shell('getprop service.adb.root').strip()
+ if adb_root_prop == '1':
+ a.Shell('setprop service.adb.root 0')
+
+ # Make sure that adbd is running without root by restarting it
+ ps_out = a.Shell('ps')
+ adbd_pids = []
+ for line in ps_out.splitlines():
+ if 'adbd' in line:
+ pid = line.split()[1]
+ adbd_pids.append(pid)
+ for pid in adbd_pids:
+ a.Shell('kill %s' % str(pid))
+ a.WaitForDevice()
+
+ self.assertFalse(d.HasRoot())
+ d.EnableRoot()
+ self.assertTrue(d.HasRoot())
+ else:
+ self.assertFalse(d.HasRoot())
+ with self.assertRaises(device_errors.CommandFailedError):
+ d.EnableRoot()
+ else:
+ self.assertTrue(d.HasRoot())
+ d.EnableRoot()
+ self.assertTrue(d.HasRoot())
+
if __name__ == '__main__':
- unittest.main()
+ unittest.main(verbosity=2, buffer=True)
« no previous file with comments | « build/android/pylib/device/device_utils.py ('k') | build/android/pylib/gtest/test_runner.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698