Beispiel #1
0
 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))
Beispiel #2
0
    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))
Beispiel #3
0
    def ReadSpecification(self,
                          interface_name,
                          target_class,
                          target_type,
                          target_version,
                          target_package,
                          recursive=False):
        """RPC to VTS_AGENT_COMMAND_READ_SPECIFICATION.

        Args:
            other args: see SendCommand
            recursive: boolean, set to recursively read the imported
                       specification(s) and return the merged one.
        """
        self.SendCommand(SysMsg_pb2.VTS_AGENT_COMMAND_READ_SPECIFICATION,
                         service_name=interface_name,
                         target_class=target_class,
                         target_type=target_type,
                         target_version=target_version,
                         target_package=target_package)
        resp = self.RecvResponse(retries=2)
        logging.info("resp for VTS_AGENT_COMMAND_EXECUTE_READ_INTERFACE: %s",
                     resp)
        logging.info("proto: %s", resp.result)
        result = CompSpecMsg_pb2.ComponentSpecificationMessage()
        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 recursive and hasattr(result, "import"):
            for imported_interface in getattr(result, "import"):
                if imported_interface == "[email protected]::types":
                    logging.warn("import [email protected]::types skipped")
                    continue
                imported_result = self.ReadSpecification(
                    imported_interface.split("::")[1],
                    # TODO(yim): derive target_class and
                    # target_type from package path or remove them
                    msg.component_class
                    if target_class is None else target_class,
                    msg.component_type if target_type is None else target_type,
                    float(imported_interface.split("@")[1].split("::")[0]),
                    imported_interface.split("@")[0])
                # Merge the attributes from imported interface.
                for attribute in imported_result.attribute:
                    imported_attribute = result.attribute.add()
                    imported_attribute.CopyFrom(attribute)

        return result
Beispiel #4
0
    def SendCommand(self,
                    command_type,
                    paths=None,
                    file_path=None,
                    bits=None,
                    target_class=None,
                    target_type=None,
                    target_version_major=None,
                    target_version_minor=None,
                    target_package=None,
                    target_component_name=None,
                    hw_binder_service_name=None,
                    is_test_hal=None,
                    module_name=None,
                    service_name=None,
                    callback_port=None,
                    driver_type=None,
                    shell_command=None,
                    caller_uid=None,
                    arg=None,
                    fmq_request=None,
                    hidl_memory_request=None,
                    hidl_handle_request=None):
        """Sends a command.

        Args:
            command_type: integer, the command type.
            each of the other args are to fill in a field in
            AndroidSystemControlCommandMessage.
        """
        if not self.channel:
            raise errors.VtsTcpCommunicationError(
                "channel is None, unable to send command.")

        command_msg = SysMsg_pb2.AndroidSystemControlCommandMessage()
        command_msg.command_type = command_type
        logging.debug("sending a command (type %s)",
                      COMMAND_TYPE_NAME[command_type])
        if command_type == 202:
            logging.debug("target API: %s", arg)

        if target_class is not None:
            command_msg.target_class = target_class

        if target_type is not None:
            command_msg.target_type = target_type

        if target_version_major is not None:
            command_msg.target_version_major = target_version_major

        if target_version_minor is not None:
            command_msg.target_version_minor = target_version_minor

        if target_package is not None:
            command_msg.target_package = target_package

        if target_component_name is not None:
            command_msg.target_component_name = target_component_name

        if hw_binder_service_name is not None:
            command_msg.hw_binder_service_name = hw_binder_service_name

        if is_test_hal is not None:
            command_msg.is_test_hal = is_test_hal

        if module_name is not None:
            command_msg.module_name = module_name

        if service_name is not None:
            command_msg.service_name = service_name

        if driver_type is not None:
            command_msg.driver_type = driver_type

        if paths is not None:
            command_msg.paths.extend(paths)

        if file_path is not None:
            command_msg.file_path = file_path

        if bits is not None:
            command_msg.bits = bits

        if callback_port is not None:
            command_msg.callback_port = callback_port

        if caller_uid is not None:
            command_msg.driver_caller_uid = caller_uid

        if arg is not None:
            command_msg.arg = arg

        if shell_command is not None:
            if isinstance(shell_command, (list, tuple)):
                command_msg.shell_command.extend(shell_command)
            else:
                command_msg.shell_command.append(shell_command)

        if fmq_request is not None:
            command_msg.fmq_request.CopyFrom(fmq_request)

        if hidl_memory_request is not None:
            command_msg.hidl_memory_request.CopyFrom(hidl_memory_request)

        if hidl_handle_request is not None:
            command_msg.hidl_handle_request.CopyFrom(hidl_handle_request)

        logging.debug("command %s" % command_msg)
        message = command_msg.SerializeToString()
        message_len = len(message)
        logging.debug("sending %d bytes", message_len)
        self.channel.write(str(message_len) + b'\n')
        self.channel.write(message)
        self.channel.flush()