1#!/usr/bin/env python 2# 3# Copyright (C) 2024 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 os 19import unittest 20 21import proc_utils as utils 22 23 24class VtsKernelProcSysrqTriggerTest(unittest.TestCase): 25 def setUp(self): 26 """Initializes tests. 27 28 Data file path, device, remote shell instance and temporary directory 29 are initialized. 30 """ 31 serial_number = os.environ.get("ANDROID_SERIAL") 32 self.assertTrue(serial_number, "$ANDROID_SERIAL is empty.") 33 self.dut = utils.AndroidDevice(serial_number) 34 35 def testProcSysrqTrigger(self): 36 filepath = "/proc/sysrq-trigger" 37 38 # This command only performs a best effort attempt to remount all 39 # filesystems. Check that it doesn't throw an error. 40 self.dut.shell.Execute("echo u > %s" % filepath) 41 42 # Reboot the device. 43 self.dut.shell.Execute("echo b > %s" % filepath) 44 self.assertTrue(self.dut.IsShutdown(10), "Device is still alive.") 45 self.assertTrue(self.dut.WaitForBootCompletion(600)) 46 self.assertTrue(self.dut.Root()) 47 48if __name__ == "__main__": 49 try: 50 suite = unittest.TestLoader().loadTestsFromTestCase( 51 VtsKernelProcSysrqTriggerTest) 52 results = unittest.TextTestRunner(verbosity=2).run(suite) 53 finally: 54 if results.failures: 55 sys.exit(1) 56