Пример #1
0
 def GetAttribute(self, attribute_name):
     """Returns the Message.
     """
     logging.debug("GetAttribute %s for %s", attribute_name,
                   self._if_spec_msg)
     if self._if_spec_msg.attribute:
         for attribute in self._if_spec_msg.attribute:
             if attribute.name == attribute_name:
                 func_msg = CompSpecMsg.FunctionSpecificationMessage()
                 func_msg.name = attribute.name
                 func_msg.return_type.type = attribute.type
                 if func_msg.return_type.type == CompSpecMsg.TYPE_SCALAR:
                     func_msg.return_type.scalar_type = attribute.scalar_type
                 else:
                     func_msg.return_type.predefined_type = attribute.predefined_type
                 logging.info("GetAttribute attribute: %s", attribute)
                 logging.info("GetAttribute request: %s", func_msg)
                 return copy.copy(func_msg)
     if (self._if_spec_msg.interface
             and self._if_spec_msg.interface.attribute):
         for attribute in self._if_spec_msg.interface.attribute:
             if attribute.name == attribute_name:
                 func_msg = CompSpecMsg.FunctionSpecificationMessage()
                 func_msg.name = attribute.name
                 func_msg.return_type.type = attribute.type
                 if func_msg.return_type.type == CompSpecMsg.TYPE_SCALAR:
                     func_msg.return_type.scalar_type = attribute.scalar_type
                 else:
                     func_msg.return_type.predefined_type = attribute.predefined_type
                 logging.info("GetAttribute attribute: %s", attribute)
                 logging.info("GetAttribute request: %s", func_msg)
                 return copy.copy(func_msg)
     return None
Пример #2
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))
Пример #3
0
    def GetApi(self, api_name):
        """Gets the ProtoBuf message for given api.

        Args:
            api_name: string, the name of the target function API.

        Returns:
            FunctionSpecificationMessage if found, None otherwise
        """
        logging.debug("GetAPI %s for %s", api_name, self._if_spec_msg)
        # handle reserved methods first.
        if api_name == "notifySyspropsChanged":
            func_msg = CompSpecMsg.FunctionSpecificationMessage()
            func_msg.name = api_name
            return func_msg
        if isinstance(self._if_spec_msg,
                      CompSpecMsg.ComponentSpecificationMessage):
            if len(self._if_spec_msg.interface.api) > 0:
                for api in self._if_spec_msg.interface.api:
                    if api.name == api_name:
                        return copy.copy(api)
        else:
            logging.error("unknown spec type %s", type(self._if_spec_msg))
            sys.exit(1)
        return None
Пример #4
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))
Пример #5
0
    def OpenConventionalHal(self, module_name=None):
        """Opens the target conventional HAL component.

        This is only needed for conventional HAL.

        Args:
            module_name: string, the name of a module to load.
        """
        func_msg = CompSpecMsg.FunctionSpecificationMessage()
        func_msg.name = "#Open"
        logging.debug("remote call %s", func_msg.name)
        if module_name:
            arg = func_msg.arg.add()
            arg.type = CompSpecMsg.TYPE_STRING
            arg.string_value.message = module_name

            func_msg.return_type.type == CompSpecMsg.TYPE_SCALAR
            func_msg.return_type.scalar_type = "int32_t"
        logging.debug("final msg %s", func_msg)

        result = self._client.CallApi(text_format.MessageToString(func_msg),
                                      self.__caller_uid)
        logging.debug(result)
        return result