1#!/usr/bin/env python 2# 3# Copyright (C) 2016 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16# 17 18import logging 19 20from vts.runners.host import asserts 21from vts.runners.host import base_test 22from vts.runners.host import test_runner 23from vts.runners.host import utils 24from vts.utils.python.controllers import adb 25 26 27class RebootRootRemountTest(base_test.BaseTestClass): 28 """Tests if device can root and remount /system partition after reboot. 29 30 Attributes: 31 dut: AndroidDevice, the device under test as config. 32 verity: boolean, True if verity was enabled before test, 33 False otherwise. 34 """ 35 36 def setUpClass(self): 37 self.dut = self.android_devices[0] 38 self.verity = self.dut.verityEnabled 39 40 def testRebootRootRemount(self): 41 """Tests if /system partition can be remounted as r/w after reboot.""" 42 # Disable verity if it's enabled. 43 if self.verity: 44 logging.info("Disable verity.") 45 self.dut.adb.disable_verity() 46 47 try: 48 self.dut.reboot() 49 self.dut.waitForBootCompletion() 50 except utils.TimeoutError: 51 asserts.fail("Reboot failed.") 52 53 try: 54 self.dut.adb.root() 55 self.dut.adb.wait_for_device() 56 # Remount /system partition as r/w. 57 self.dut.adb.remount() 58 self.dut.adb.wait_for_device() 59 except adb.AdbError(): 60 asserts.fail("Root/remount failed.") 61 62 # Restore verity to its original state. 63 if self.verity: 64 logging.info("Enable verity.") 65 self.dut.adb.enable_verity() 66 try: 67 self.dut.reboot() 68 self.dut.waitForBootCompletion() 69 except utils.TimeoutError: 70 asserts.fail("Reboot failed after re-enabling verity.") 71 72 asserts.assertEqual(self.verity, self.dut.verityEnabled, 73 "Verity state was successfully restored.") 74 75 76if __name__ == "__main__": 77 test_runner.main() 78