def GetAttribute(self, arg): """RPC to VTS_AGENT_COMMAND_GET_ATTRIBUTE.""" self.SendCommand(SysMsg_pb2.VTS_AGENT_COMMAND_GET_ATTRIBUTE, arg=arg) resp = self.RecvResponse() resp_code = resp.response_code if (resp_code == SysMsg_pb2.SUCCESS): result = CompSpecMsg_pb2.FunctionSpecificationMessage() if resp.result == "error": raise errors.VtsTcpCommunicationError( "Get attribute request failed on target.") try: text_format.Merge(resp.result, result) except text_format.ParseError as e: logging.exception(e) logging.error("Paring error\n%s", resp.result) if result.return_type.type == CompSpecMsg_pb2.TYPE_SUBMODULE: logging.debug("returned a submodule spec") logging.debug("spec: %s", result.return_type_submodule_spec) return mirror_object.MirrorObject( self, result.return_type_submodule_spec, None) elif result.return_type.type == CompSpecMsg_pb2.TYPE_SCALAR: return getattr(result.return_type.scalar_value, result.return_type.scalar_type) return result logging.error("NOTICE - Likely a crash discovery!") logging.error("SysMsg_pb2.SUCCESS is %s", SysMsg_pb2.SUCCESS) raise errors.VtsTcpCommunicationError( "RPC Error, response code for %s is %s" % (arg, resp_code))
def CallApi(self, arg, caller_uid=None): """RPC to CALL_API.""" self.SendCommand(SysMsg_pb2.CALL_API, arg=arg, caller_uid=caller_uid) resp = self.RecvResponse() resp_code = resp.response_code if (resp_code == SysMsg_pb2.SUCCESS): result = CompSpecMsg_pb2.FunctionSpecificationMessage() if resp.result == "error": raise errors.VtsTcpCommunicationError( "API call error by the VTS driver.") try: text_format.Merge(resp.result, result) except text_format.ParseError as e: logging.exception(e) logging.error("Paring error\n%s", resp.result) if result.return_type.type == CompSpecMsg_pb2.TYPE_SUBMODULE: logging.info("returned a submodule spec") logging.info("spec: %s", result.return_type_submodule_spec) return mirror_object.MirrorObject( self, result.return_type_submodule_spec, None) logging.info("result: %s", result.return_type_hidl) if len(result.return_type_hidl) == 1: result_value = self.GetPythonDataOfVariableSpecMsg( result.return_type_hidl[0]) elif len(result.return_type_hidl) > 1: result_value = [] for return_type_hidl in result.return_type_hidl: result_value.append( self.GetPythonDataOfVariableSpecMsg(return_type_hidl)) else: # For non-HIDL return value if hasattr(result, "return_type"): result_value = result else: result_value = None if hasattr(result, "raw_coverage_data"): return result_value, {"coverage": result.raw_coverage_data} else: return result_value logging.error("NOTICE - Likely a crash discovery!") logging.error("SysMsg_pb2.SUCCESS is %s", SysMsg_pb2.SUCCESS) raise errors.VtsTcpCommunicationError( "RPC Error, response code for %s is %s" % (arg, resp_code))
def _CreateMirrorObject(self, target_class, target_type, target_version, target_package=None, target_component_name=None, target_basepaths=_DEFAULT_TARGET_BASE_PATHS, handler_name=None, hw_binder_service_name=None, bits=64): """Initiates the driver for a HAL on the target device and creates a top level MirroObject for it. Also starts the callback server to listen for callback invocations. Args: target_class: string, the target class name (e.g., hal). target_type: string, the target type name (e.g., light, camera). target_version: float, the target component version (e.g., 1.0). target_package: string, the package name of a HIDL HAL. target_component_name: string, the name of a target component. target_basepaths: list of strings, the paths to look for target files in. Default is _DEFAULT_TARGET_BASE_PATHS. handler_name: string, the name of the handler. target_type is used by default. hw_binder_service_name: string, the name of a HW binder service. bits: integer, processor architecture indicator: 32 or 64. Raises: errors.ComponentLoadingError is raised when error occurs trying to create a MirrorObject. """ if bits not in [32, 64]: raise error.ComponentLoadingError("Invalid value for bits: %s" % bits) self._StartCallbackServer() self._client = vts_tcp_client.VtsTcpClient() self._client.Connect(command_port=self._host_command_port, callback_port=self._host_callback_port) if not handler_name: handler_name = target_type service_name = "vts_driver_%s" % handler_name target_filename = None if target_class == "hal_conventional" or target_class == "hal_legacy": # Get all the HALs available on the target. hal_list = self._client.ListHals(target_basepaths) if not hal_list: raise errors.ComponentLoadingError( "Could not find any HAL under path %s" % target_basepaths) logging.debug(hal_list) # Find the corresponding filename for HAL target type. for name in hal_list: if target_type in name: # TODO: check more exactly (e.g., multiple hits). target_filename = name if not target_filename: raise errors.ComponentLoadingError( "No file found for HAL target type %s." % target_type) # Check whether the requested binder service is already running. # if client.CheckDriverService(service_name=service_name): # raise errors.ComponentLoadingError("A driver for %s already exists" % # service_name) elif target_class == "hal_hidl": # TODO: either user the default hw-binder service or start a new # service (e.g., if an instrumented binary is used). pass # Launch the corresponding driver of the requested HAL on the target. logging.info("Init the driver service for %s", target_type) target_class_id = COMPONENT_CLASS_DICT[target_class.lower()] target_type_id = COMPONENT_TYPE_DICT[target_type.lower()] driver_type = { "hal_conventional": ASysCtrlMsg.VTS_DRIVER_TYPE_HAL_CONVENTIONAL, "hal_legacy": ASysCtrlMsg.VTS_DRIVER_TYPE_HAL_LEGACY, "hal_hidl": ASysCtrlMsg.VTS_DRIVER_TYPE_HAL_HIDL }.get(target_class) launched = self._client.LaunchDriverService( driver_type=driver_type, service_name=service_name, bits=bits, file_path=target_filename, target_class=target_class_id, target_type=target_type_id, target_version=target_version, target_package=target_package, target_component_name=target_component_name, hw_binder_service_name=hw_binder_service_name) if not launched: raise errors.ComponentLoadingError( "Failed to launch driver service %s from file path %s" % (target_type, target_filename)) # Create API spec message. found_api_spec = self._client.ListApis() if not found_api_spec: raise errors.ComponentLoadingError("No API found for %s" % service_name) logging.debug("Found %d APIs for %s:\n%s", len(found_api_spec), service_name, found_api_spec) if_spec_msg = CompSpecMsg.ComponentSpecificationMessage() text_format.Merge(found_api_spec, if_spec_msg) # Instantiate a MirrorObject and return it. hal_mirror = mirror_object.MirrorObject(self._client, if_spec_msg, self._callback_server) self._hal_level_mirrors[handler_name] = hal_mirror
def _CreateMirrorObject(self, target_class, target_type, target_version, target_basepaths=_DEFAULT_TARGET_BASE_PATHS, target_package="", target_filename=None, handler_name=None, bits=64): """Initiates the driver for a lib on the target device and creates a top level MirroObject for it. Args: target_class: string, the target class name (e.g., lib). target_type: string, the target type name (e.g., light, camera). target_version: float, the target component version (e.g., 1.0). target_basepaths: list of strings, the paths to look for target files in. Default is _DEFAULT_TARGET_BASE_PATHS. target_package: . separated string (e.g., a.b.c) to denote the package name of target component. target_filename: string, the target file name (e.g., libm.so). handler_name: string, the name of the handler. target_type is used by default. bits: integer, processor architecture indicator: 32 or 64. Raises: errors.ComponentLoadingError is raised when error occurs trying to create a MirrorObject. """ if bits not in [32, 64]: raise error.ComponentLoadingError("Invalid value for bits: %s" % bits) client = vts_tcp_client.VtsTcpClient() client.Connect(command_port=self._host_command_port) if not handler_name: handler_name = target_type service_name = "vts_driver_%s" % handler_name # Get all the libs available on the target. lib_list = client.ListHals(target_basepaths) if not lib_list: raise errors.ComponentLoadingError( "Could not find any lib under path %s" % target_basepaths) logging.debug(lib_list) # Find the corresponding filename for Lib target type. if target_filename is not None: for name in lib_list: if name.endswith(target_filename): target_filename = name break else: for name in lib_list: if target_type in name: # TODO: check more exactly (e.g., multiple hits). target_filename = name if not target_filename: raise errors.ComponentLoadingError( "No file found for target type %s." % target_type) # Check whether the requested binder service is already running. # if client.CheckDriverService(service_name=service_name): # raise errors.ComponentLoadingError("A driver for %s already exists" % # service_name) # Launch the corresponding driver of the requested Lib on the target. logging.info("Init the driver service for %s", target_type) target_class_id = hal_mirror.COMPONENT_CLASS_DICT[target_class.lower()] target_type_id = hal_mirror.COMPONENT_TYPE_DICT[target_type.lower()] launched = client.LaunchDriverService( driver_type=ASysCtrlMsg.VTS_DRIVER_TYPE_HAL_CONVENTIONAL, service_name=service_name, bits=bits, file_path=target_filename, target_class=target_class_id, target_type=target_type_id, target_version=target_version, target_package=target_package) if not launched: raise errors.ComponentLoadingError( "Failed to launch driver service %s from file path %s" % (target_type, target_filename)) # Create API spec message. found_api_spec = client.ListApis() if not found_api_spec: raise errors.ComponentLoadingError("No API found for %s" % service_name) logging.debug("Found %d APIs for %s:\n%s", len(found_api_spec), service_name, found_api_spec) if_spec_msg = CompSpecMsg.ComponentSpecificationMessage() text_format.Merge(found_api_spec, if_spec_msg) # Instantiate a MirrorObject and return it. lib_mirror = mirror_object.MirrorObject(client, if_spec_msg, None) self._lib_level_mirrors[handler_name] = lib_mirror