Home | History | Annotate | Download | only in hidl_shim
      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 test_runner
     23 from vts.utils.python.common import vintf_utils
     24 from vts.utils.python.controllers import android_device
     25 from vts.utils.python.file import target_file_utils
     26 from vts.utils.python.os import path_utils
     27 
     28 
     29 class VtsTrebleHidlShimTest(base_test.BaseTestClass):
     30     """Ensures existence of at least one HIDL shim library (32 or 64-bit)."""
     31 
     32     VENDOR_MANIFEST_FILE_PATH = '/vendor/manifest.xml'
     33     SHIM_DIRS = [
     34         '/system/lib/', '/system/lib64/', '/vendor/lib/', '/vendor/lib64/'
     35     ]
     36 
     37     def setUpClass(self):
     38         self.dut = self.registerController(android_device)[0]
     39         self.dut.shell.InvokeTerminal(
     40             'VtsTrebleHidlShim')  # creates a remote shell instance.
     41         self.shell = self.dut.shell.VtsTrebleHidlShim
     42 
     43     def missingHidlShims(self, hal_dictionary):
     44         """Finds HALs listed in hal_dictionary that are missing shims on device.
     45 
     46         Args:
     47             hal_dictionary:
     48                 {key: hal_name@version, value: vintf_utils.HalDescription object}
     49         Returns:
     50             a list of the hal_keys (hal_name@version) for which no HIDL shim was
     51             found on device
     52         """
     53         missing_hidl_shims = []
     54         for hal_key, hal_info in hal_dictionary.iteritems():
     55             for shim_dir in self.SHIM_DIRS:
     56                 hidl_shim_path = path_utils.JoinTargetPath(
     57                     shim_dir, hal_key + '.so')
     58                 found = target_file_utils.Exists(hidl_shim_path, self.shell)
     59                 if found:
     60                     break
     61             if not found:
     62                 missing_hidl_shims.append(hal_key)
     63         return missing_hidl_shims
     64 
     65     def testHidlShimExists(self):
     66         """Checks that at least one HIDL shim (32 or 64-bit) exists on device.
     67 
     68         For all HALs registered in /vendor/manifest.xml, at least one HIDL shim
     69         must exist on device under one of the dirs listed in self.SHIM_DIRS.
     70         """
     71         vendor_manifest_xml = target_file_utils.ReadFileContent(
     72             self.VENDOR_MANIFEST_FILE_PATH, self.shell)
     73         manifest_hwbinder_hals, manifest_passthrough_hals = vintf_utils.GetHalDescriptions(
     74             vendor_manifest_xml)
     75 
     76         missing_hidl_shims_hwbinder = self.missingHidlShims(
     77             manifest_hwbinder_hals)
     78         missing_hidl_shims_passthrough = self.missingHidlShims(
     79             manifest_passthrough_hals)
     80 
     81         asserts.assertTrue(
     82             len(missing_hidl_shims_hwbinder) == 0 and
     83             len(missing_hidl_shims_passthrough) == 0,
     84             ('No HIDL shim library (neither 32 or 64-bit) was found on device for the following HALs: %s, %s'
     85              ) % (missing_hidl_shims_hwbinder, missing_hidl_shims_passthrough))
     86 
     87 
     88 if __name__ == "__main__":
     89     test_runner.main()
     90