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