• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2# Copyright (C) 2017 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17import logging
18
19from vts.runners.host import const
20from vts.runners.host import keys
21from vts.utils.python.common import vintf_utils
22
23
24def CanRunHidlHalTest(test_instance, dut, shell=None):
25    """Checks HAL precondition of a test instance.
26
27    Args:
28        test_instance: the test instance which inherits BaseTestClass.
29        dut: the AndroidDevice under test.
30        shell: the ShellMirrorObject to execute command on the device.
31               If not specified, the function creates one from dut.
32
33    Returns:
34        True if the precondition is satisfied; False otherwise.
35    """
36    if shell is None:
37        dut.shell.InvokeTerminal("check_hal_preconditions")
38        shell = dut.shell.check_hal_preconditions
39
40    opt_params = [
41        keys.ConfigKeys.IKEY_ABI_BITNESS,
42        keys.ConfigKeys.IKEY_PRECONDITION_HWBINDER_SERVICE,
43        keys.ConfigKeys.IKEY_PRECONDITION_FEATURE,
44        keys.ConfigKeys.IKEY_PRECONDITION_FILE_PATH_PREFIX,
45        keys.ConfigKeys.IKEY_PRECONDITION_LSHAL,
46    ]
47    test_instance.getUserParams(opt_param_names=opt_params)
48
49    hwbinder_service_name = str(getattr(test_instance,
50        keys.ConfigKeys.IKEY_PRECONDITION_HWBINDER_SERVICE, ""))
51    if hwbinder_service_name:
52        if not hwbinder_service_name.startswith("android.hardware."):
53            logging.error("The given hwbinder service name %s is invalid.",
54                          hwbinder_service_name)
55        else:
56            cmd_results = shell.Execute("ps -A")
57            hwbinder_service_name += "@"
58            if (any(cmd_results[const.EXIT_CODE]) or
59                hwbinder_service_name not in cmd_results[const.STDOUT][0]):
60                logging.warn("The required hwbinder service %s not found.",
61                             hwbinder_service_name)
62                return False
63
64    feature = str(getattr(test_instance,
65        keys.ConfigKeys.IKEY_PRECONDITION_FEATURE, ""))
66    if feature:
67        if not feature.startswith("android.hardware."):
68            logging.error(
69                "The given feature name %s is invalid for HIDL HAL.",
70                feature)
71        else:
72            cmd_results = shell.Execute("pm list features")
73            if (any(cmd_results[const.EXIT_CODE]) or
74                feature not in cmd_results[const.STDOUT][0]):
75                logging.warn("The required feature %s not found.",
76                             feature)
77                return False
78
79    file_path_prefix = str(getattr(test_instance,
80        keys.ConfigKeys.IKEY_PRECONDITION_FILE_PATH_PREFIX, ""))
81    if file_path_prefix:
82        cmd_results = shell.Execute("ls %s*" % file_path_prefix)
83        if any(cmd_results[const.EXIT_CODE]):
84            logging.warn("The required file (prefix: %s) not found.",
85                         file_path_prefix)
86            return False
87
88    hal = str(getattr(test_instance,
89        keys.ConfigKeys.IKEY_PRECONDITION_LSHAL, ""))
90    if hal:
91        vintf_xml = dut.getVintfXml()
92        if vintf_xml:
93            hwbinder_hals, passthrough_hals = vintf_utils.GetHalDescriptions(
94                vintf_xml)
95            if not hwbinder_hals or not passthrough_hals:
96                logging.error("can't check precondition due to a "
97                          "lshal output format error.")
98            elif (hal not in hwbinder_hals and
99                  hal not in passthrough_hals):
100                logging.warn(
101                    "The required hal %s not found by lshal.",
102                    hal)
103                return False
104            elif (hal not in hwbinder_hals and
105                  hal in passthrough_hals):
106                if hasattr(test_instance, keys.ConfigKeys.IKEY_ABI_BITNESS):
107                    bitness = getattr(test_instance,
108                                      keys.ConfigKeys.IKEY_ABI_BITNESS)
109                    if (bitness not in
110                        passthrough_hals[hal].hal_archs):
111                        logging.warn(
112                            "The required feature %s found as a "
113                            "passthrough hal but the client bitness %s "
114                            "not supported",
115                            hal, bitness)
116                        return False
117            else:
118                logging.info(
119                    "The feature %s found in lshal-emitted vintf xml", hal)
120
121    return True
122