diff options
author | Dan Albert <danalbert@google.com> | 2015-03-03 11:47:28 -0800 |
---|---|---|
committer | Dan Albert <danalbert@google.com> | 2015-03-09 10:45:50 -0700 |
commit | 857d7db69d2aac03ea624a0401e7231a3cef4597 (patch) | |
tree | 74bd2a45261e9e8908c868a93b40ce58f2391425 | |
parent | fbb3f8ca499b04c82437155f87c8666cad607c6b (diff) | |
download | system_core-857d7db69d2aac03ea624a0401e7231a3cef4597.zip system_core-857d7db69d2aac03ea624a0401e7231a3cef4597.tar.gz system_core-857d7db69d2aac03ea624a0401e7231a3cef4597.tar.bz2 |
Make the root/unroot test more robust.
* Check the current adb user to choose the order of root/unroot.
* Re-root the device when finished.
Change-Id: I47a14b89e2c405bd63722e4d2043fcc629fb5e58
-rwxr-xr-x | adb/tests/test_adb.py | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/adb/tests/test_adb.py b/adb/tests/test_adb.py index 49ead73..f111b04 100755 --- a/adb/tests/test_adb.py +++ b/adb/tests/test_adb.py @@ -237,16 +237,36 @@ class AdbBasic(unittest.TestCase): version_num = True self.assertTrue(version_num) - def test_root_unroot(self): - """Make sure that adb root and adb unroot work, using id(1).""" + def _test_root(self): adb = AdbWrapper() adb.root() adb.wait() self.assertEqual("root", adb.shell("id -un").strip()) + + def _test_unroot(self): + adb = AdbWrapper() adb.unroot() adb.wait() self.assertEqual("shell", adb.shell("id -un").strip()) + def test_root_unroot(self): + """Make sure that adb root and adb unroot work, using id(1).""" + adb = AdbWrapper() + original_user = adb.shell("id -un").strip() + try: + if original_user == "root": + self._test_unroot() + self._test_root() + elif original_user == "shell": + self._test_root() + self._test_unroot() + finally: + if original_user == "root": + adb.root() + else: + adb.unroot() + adb.wait() + class AdbFile(unittest.TestCase): SCRATCH_DIR = "/data/local/tmp" |