예제 #1
0
def Convert(pb_spec, py_value):
    """Converts Python native data structure to VTS VariableSecificationMessage.

    Args:
        pb_spec: VariableSpecificationMessage which captures the
                 specification of a target attribute.
        py_value: Python value provided by a test case.

    Returns:
        Converted VariableSpecificationMessage if found, None otherwise
    """
    if not pb_spec:
        logging.error("py2pb.Convert: ProtoBuf spec is None", pb_spec)
        return None

    message = CompSpecMsg.VariableSpecificationMessage()
    message.name = pb_spec.name

    if isinstance(py_value, CompSpecMsg.VariableSpecificationMessage):
        message.CopyFrom(py_value)
    elif pb_spec.type == CompSpecMsg.TYPE_STRUCT:
        PyDict2PbStruct(message, pb_spec, py_value)
    elif pb_spec.type == CompSpecMsg.TYPE_ENUM:
        PyValue2PbEnum(message, pb_spec, py_value)
    elif pb_spec.type == CompSpecMsg.TYPE_SCALAR:
        PyValue2PbScalar(message, pb_spec, py_value)
    elif pb_spec.type == CompSpecMsg.TYPE_STRING:
        PyString2PbString(message, pb_spec, py_value)
    elif pb_spec.type == CompSpecMsg.TYPE_VECTOR:
        PyList2PbVector(message, pb_spec, py_value)
    else:
        logging.error("py2pb.Convert: unsupported type %s", pb_spec.type)
        sys.exit(-1)

    return message
예제 #2
0
    def GetHidlCallbackInterface(self, interface_name, **kwargs):
        var_msg = CompSpecMsg.VariableSpecificationMessage()
        var_msg.name = interface_name
        var_msg.type = CompSpecMsg.TYPE_FUNCTION_POINTER
        var_msg.is_callback = True

        msg = self._if_spec_msg
        specification = self._client.ReadSpecification(
            interface_name, msg.component_class, msg.component_type,
            msg.component_type_version, msg.package)
        logging.info("specification: %s", specification)
        interface = getattr(specification, INTERFACE, None)
        apis = getattr(interface, API, [])
        for api in apis:
            function_pointer = None
            if api.name in kwargs:
                function_pointer = kwargs[api.name]
            else:

                def dummy(*args):
                    """Dummy implementation for any callback function."""
                    logging.info(
                        "Entering dummy implementation"
                        " for callback function: %s", api.name)
                    for arg_index in range(len(args)):
                        logging.info("arg%s: %s", arg_index, args[arg_index])

                function_pointer = dummy
            func_pt_msg = var_msg.function_pointer.add()
            func_pt_msg.function_name = api.name
            func_pt_msg.id = self.GetFunctionPointerID(function_pointer)

        return var_msg
예제 #3
0
    def GetHidlCallbackInterface(self, interface_name, **kwargs):
        """Gets the ProtoBuf message for a callback interface based on args.

        Args:
            interface_name: string, the callback interface name.
            **kwargs: a dict for the arg name and value pairs

        Returns:
            VariableSpecificationMessage that contains the callback interface
            description.
        """
        var_msg = CompSpecMsg.VariableSpecificationMessage()
        var_msg.name = interface_name
        var_msg.type = CompSpecMsg.TYPE_FUNCTION_POINTER
        var_msg.is_callback = True

        msg = self._if_spec_msg
        specification = self._client.ReadSpecification(
            interface_name, msg.component_class, msg.component_type,
            msg.component_type_version_major, msg.component_type_version_minor,
            msg.package)
        logging.debug("specification: %s", specification)
        interface = getattr(specification, INTERFACE, None)
        apis = getattr(interface, API, [])
        for api in apis:
            function_pointer = None
            if api.name in kwargs:
                function_pointer = kwargs[api.name]
            else:

                def dummy(*args):
                    """Dummy implementation for any callback function."""
                    logging.debug(
                        "Entering dummy implementation"
                        " for callback function: %s", api.name)
                    for arg_index in range(len(args)):
                        logging.debug("arg%s: %s", arg_index, args[arg_index])

                function_pointer = dummy
            func_pt_msg = var_msg.function_pointer.add()
            func_pt_msg.function_name = api.name
            func_pt_msg.id = self.GetCallbackFunctionID(function_pointer)

        return var_msg
예제 #4
0
    def testHidlHandleArgument(self):
        """Test calling APIs in dumpstate HAL server.

        Host side specifies a handle object in resource_manager, ans pass
        it to dumpstate HAL server to write debug message into it.
        Host side then reads part of the debug message.
        """
        # Prepare a VariableSpecificationMessage to specify the handle object
        # that will be passed into the HAL service.
        var_msg = CompSpecMsg.VariableSpecificationMessage()
        var_msg.type = CompSpecMsg.TYPE_HANDLE
        var_msg.handle_value.handle_id = self._writer.handleId

        self._dumpstate.dumpstateBoard(var_msg)
        # Read 1000 bytes to retrieve part of debug message.
        debug_msg = self._reader.readFile(1000)
        logging.info("Below are part of result from dumpstate: ")
        logging.info(debug_msg)
        asserts.assertNotEqual(debug_msg, "")
    def setUp(self):
        # Initialize a FMQ on the target-side driver.
        self._sync_client = self.dut.resource.InitFmq(
            data_type="uint16_t",
            sync=True,
            queue_size=self.MAX_NUM_MSG,
            blocking=True,
            client=self.dut.hal.GetTcpClient("tests_msgq"))
        asserts.assertNotEqual(self._sync_client.queueId, -1)

        # Prepare a VariableSpecificationMessage to specify the FMQ that will be
        # passed into the HAL service.
        var_msg = CompSpecMsg.VariableSpecificationMessage()
        var_msg.type = CompSpecMsg.TYPE_FMQ_SYNC
        fmq_val = var_msg.fmq_value.add()
        fmq_val.fmq_id = self._sync_client.queueId
        fmq_val.scalar_type = "uint16_t"
        fmq_val.type = CompSpecMsg.TYPE_SCALAR

        # Call API in the HAL server.
        sync_init_result = self._tests_msgq.configureFmqSyncReadWrite(var_msg)
        asserts.assertTrue(
            sync_init_result,
            "Hal should configure a synchronized queue without error.")

        # Initialize an unsynchronized queue on the server.
        [success,
         self._unsync_client1] = self._tests_msgq.getFmqUnsyncWrite(True)
        asserts.assertTrue(
            success,
            "Hal should configure an unsynchronized queue without error.")
        # An unsynchronized queue is registered successfully on the target driver.
        asserts.assertNotEqual(self._unsync_client1, None)
        asserts.assertNotEqual(self._unsync_client1.queueId, -1)
        # Register another reader.
        self._unsync_client2 = self.dut.resource.InitFmq(
            existing_queue=self._unsync_client1,
            client=self.dut.hal.GetTcpClient("tests_msgq"))
        asserts.assertNotEqual(self._unsync_client2.queueId, -1)