Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 857d7db6 authored by Dan Albert's avatar Dan Albert
Browse files

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
parent fbb3f8ca
Loading
Loading
Loading
Loading
+22 −2
Original line number Original line Diff line number Diff line
@@ -237,16 +237,36 @@ class AdbBasic(unittest.TestCase):
                version_num = True
                version_num = True
        self.assertTrue(version_num)
        self.assertTrue(version_num)


    def test_root_unroot(self):
    def _test_root(self):
        """Make sure that adb root and adb unroot work, using id(1)."""
        adb = AdbWrapper()
        adb = AdbWrapper()
        adb.root()
        adb.root()
        adb.wait()
        adb.wait()
        self.assertEqual("root", adb.shell("id -un").strip())
        self.assertEqual("root", adb.shell("id -un").strip())

    def _test_unroot(self):
        adb = AdbWrapper()
        adb.unroot()
        adb.unroot()
        adb.wait()
        adb.wait()
        self.assertEqual("shell", adb.shell("id -un").strip())
        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):
class AdbFile(unittest.TestCase):
    SCRATCH_DIR = "/data/local/tmp"
    SCRATCH_DIR = "/data/local/tmp"