1 #!/usr/bin/env python 2 # 3 # Copyright (C) 2017 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 18 import logging 19 20 from vts.runners.host import asserts 21 from vts.runners.host import base_test 22 from vts.runners.host import const 23 from vts.runners.host import test_runner 24 from vts.utils.python.controllers import android_device 25 from vts.utils.python.file import target_file_utils 26 27 HWBINDER_PATH = "/dev/hwbinder" 28 29 30 class VtsKernelHwBinderTest(base_test.BaseTestClass): 31 """Test case to validate existence of hwbinder node. 32 """ 33 34 def setUpClass(self): 35 self.dut = self.registerController(android_device)[0] 36 self.dut.shell.InvokeTerminal( 37 "VtsKernelHwBinderTest") # creates a remote shell instance. 38 self.shell = self.dut.shell.VtsKernelHwBinderTest 39 40 def testHwbinderExistence(self): 41 """Checks that hwbinder node exists. 42 """ 43 logging.info("Testing existence of %s", HWBINDER_PATH) 44 asserts.assertTrue( 45 target_file_utils.Exists(HWBINDER_PATH, self.shell), 46 "%s: File does not exist." % HWBINDER_PATH) 47 48 try: 49 permissions = target_file_utils.GetPermission( 50 HWBINDER_PATH, self.shell) 51 asserts.assertTrue( 52 target_file_utils.IsReadWrite(permissions), 53 "%s: File has invalid permissions (%s)" % (HWBINDER_PATH, 54 permissions)) 55 except (ValueError, IOError) as e: 56 asserts.fail("Failed to assert permissions: %s" % str(e)) 57 58 59 if __name__ == "__main__": 60 test_runner.main() 61