コード例 #1
0
ファイル: mirror_tracker.py プロジェクト: SATYAM86400/VTS
    def InvokeTerminal(self, instance_name, bits=32):
        """Initiates a handler for a particular shell terminal.

        This will initiate a driver service for a shell on the target side,
        create a mirror object for the shell, and register it in the tracker.

        Args:
            instance_name: string, the shell terminal instance name.
            bits: integer, processor architecture indicator: 32 or 64.
        """
        if not instance_name:
            raise error.ComponentLoadingError("instance_name is None")
        if bits not in [32, 64]:
            raise error.ComponentLoadingError(
                "Invalid value for bits: %s" % bits)

        if instance_name in self._registered_mirrors:
            logging.warning("shell driver %s already exists", instance_name)
            return

        client = vts_tcp_client.VtsTcpClient()
        client.Connect(command_port=self._host_command_port)

        logging.debug("Init the driver service for shell, %s", instance_name)
        launched = client.LaunchDriverService(
            driver_type=ASysCtrlMsg.VTS_DRIVER_TYPE_SHELL,
            service_name="shell_" + instance_name,
            bits=bits)

        if not launched:
            raise errors.ComponentLoadingError(
                "Failed to launch shell driver service %s" % instance_name)

        mirror = shell_mirror.ShellMirror(client, self._adb)
        self._registered_mirrors[instance_name] = mirror
コード例 #2
0
ファイル: mirror_tracker.py プロジェクト: SATYAM86400/VTS
    def _StartCallbackServer(self):
        """Starts the callback server.

        Raises:
            errors.ComponentLoadingError is raised if the callback server fails
            to start.
        """
        self._callback_server = callback_server.CallbackServer()
        _, port = self._callback_server.Start(self._host_callback_port)
        if port != self._host_callback_port:
            raise errors.ComponentLoadingError(
                "Failed to start a callback TcpServer at port %s" %
                self._host_callback_port)
コード例 #3
0
    def LaunchMirrorDriver(self,
                           driver_type,
                           target_class,
                           target_type,
                           target_version,
                           target_package="",
                           target_filename=None,
                           target_component_name=None,
                           handler_name=None,
                           service_name=None,
                           hw_binder_service_name=_DEFAULT_HWBINDER_SERVICE,
                           bits=64):
        """Initiates the driver for a lib on the target device and creates a top
        level MirroObject for it.

        Args:
            driver_type: type of
            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)
        if not handler_name:
            handler_name = target_type
        if not service_name:
            service_name = "vts_driver_%s" % handler_name

        # 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_id = 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 driver_id == -1:
            raise errors.ComponentLoadingError(
                "Failed to launch driver service %s from file path %s" %
                (target_type, target_filename))

        return driver_id
コード例 #4
0
ファイル: lib_mirror.py プロジェクト: MIPS/test-vts
    def InitLibDriver(self, target_type, target_version, target_package,
                      target_filename, target_basepaths, handler_name, bits):
        """Initiates the driver for a lib on the target device and loads
        the interface specification message.

        Args:
            target_type: string, the target type name (e.g., light, camera).
            target_version: float, the target component version (e.g., 1.0).
            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).
            target_basepaths: list of strings, the paths to look for target
                             files in.
            handler_name: string, the name of the handler. target_type is used
                          by default.
            bits: integer, processor architecture indicator: 32 or 64.
        """
        # Get all the libs available on the target.
        lib_list = self._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)

        driver_id = self.LaunchMirrorDriver(
            ASysCtrlMsg.VTS_DRIVER_TYPE_HAL_CONVENTIONAL,
            "lib_shared",
            target_type,
            target_version,
            target_package=target_package,
            target_filename=target_filename,
            handler_name=handler_name,
            bits=bits)

        self._driver_id = driver_id

        #TODO: ListApis assumes only one lib is loaded at a time, need to
        #      figure out a way to get the api_spec when we want to test
        #      multiple libs together.
        found_api_spec = self._client.ListApis()
        if not found_api_spec:
            raise errors.ComponentLoadingError("No API found for %s" %
                                               target_type)
        if_spec_msg = CompSpecMsg.ComponentSpecificationMessage()
        text_format.Merge(found_api_spec, if_spec_msg)

        self._if_spec_msg = if_spec_msg
コード例 #5
0
    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
コード例 #6
0
    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