How to use the labgrid.util.Timeout function in labgrid

To help you get started, we’ve selected a few labgrid examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github labgrid-project / labgrid / tests / test_timeout.py View on Github external
def test_create(self):
        t = Timeout()
        assert (isinstance(t, Timeout))
        t = Timeout(5.0)
        assert (isinstance(t, Timeout))
        with pytest.raises(TypeError):
            t = Timeout(10)
        with pytest.raises(ValueError):
            t = Timeout(-1.0)
github labgrid-project / labgrid / tests / test_timeout.py View on Github external
def test_create(self):
        t = Timeout()
        assert (isinstance(t, Timeout))
        t = Timeout(5.0)
        assert (isinstance(t, Timeout))
        with pytest.raises(TypeError):
            t = Timeout(10)
        with pytest.raises(ValueError):
            t = Timeout(-1.0)
github labgrid-project / labgrid / tests / test_timeout.py View on Github external
def test_create(self):
        t = Timeout()
        assert (isinstance(t, Timeout))
        t = Timeout(5.0)
        assert (isinstance(t, Timeout))
        with pytest.raises(TypeError):
            t = Timeout(10)
        with pytest.raises(ValueError):
            t = Timeout(-1.0)
github labgrid-project / labgrid / labgrid / driver / bareboxdriver.py View on Github external
def _await_prompt(self):
        """Awaits the prompt and enters the shell"""

        timeout = Timeout(float(self.login_timeout))

        # We call console.expect with a short timeout here to detect if the
        # console is idle, which would result in a timeout without any changes
        # to the before property. So we store the last before value we've seen.
        # Because pexpect keeps any read data in it's buffer when a timeout
        # occours, we can't lose any data this way.
        last_before = None
        password_entered = False

        expectations = [self.prompt, self.autoboot, "Password: ", TIMEOUT]
        while True:
            index, before, _, _ = self.console.expect(
                expectations,
                timeout=2
            )
github labgrid-project / labgrid / labgrid / driver / usbstoragedriver.py View on Github external
filename (str): optional, path to the image to write to bound USB storage
            mode (Mode): optional, Mode.DD or Mode.BMAPTOOL (defaults to Mode.DD)
            partition (int or None): optional, write to the specified partition or None for writing
                to root device (defaults to None)
            skip (int): optional, skip n 512-sized blocks at start of input file (defaults to 0)
            seek (int): optional, skip n 512-sized blocks at start of output (defaults to 0)
        """
        if filename is None and self.image is not None:
            filename = self.target.env.config.get_image_path(self.image)
        assert filename, "write_image requires a filename"
        mf = ManagedFile(filename, self.storage)
        mf.sync_to_resource()
        self.logger.info("pwd: %s", os.getcwd())

        # wait for medium
        timeout = Timeout(10.0)
        while not timeout.expired:
            try:
                if self.get_size() > 0:
                    break
                time.sleep(0.5)
            except ValueError:
                # when the medium gets ready the sysfs attribute is empty for a short time span
                continue
        else:
            raise ExecutionError("Timeout while waiting for medium")

        partition = "" if partition is None else partition

        if mode == Mode.DD:
            block_size = '512' if skip or seek else '4M'
            args = [
github labgrid-project / labgrid / labgrid / target.py View on Github external
timeout (float): optional timeout
            avail (bool): optionally wait until the resources are unavailable with avail=False
        """
        self.update_resources()

        waiting = set(r for r in resources if r.avail != avail)
        static = set(r for r in waiting if r.get_managed_parent() is None)
        if static:
            raise NoResourceFoundError("Static resources are not {}: {}".format(
                "available" if avail else "unavailable", static))

        if not waiting:
            return

        if timeout is None:
            timeout = Timeout(max(resource.get_managed_parent().timeout for resource in waiting))
        else:
            timeout = Timeout(timeout)

        while waiting and not timeout.expired:
            waiting = set(r for r in waiting if r.avail != avail)
            for r in waiting:
                r.poll()
            if not any(r for r in waiting if r.avail == avail):
                # sleep if no progress
                sleep(0.5)

        if waiting:
            raise NoResourceFoundError(
                "Not all resources are {}: {}".format(
                    "available" if avail else "unavailable", waiting),
                filter=waiting
github labgrid-project / labgrid / labgrid / target.py View on Github external
"""
        self.update_resources()

        waiting = set(r for r in resources if r.avail != avail)
        static = set(r for r in waiting if r.get_managed_parent() is None)
        if static:
            raise NoResourceFoundError("Static resources are not {}: {}".format(
                "available" if avail else "unavailable", static))

        if not waiting:
            return

        if timeout is None:
            timeout = Timeout(max(resource.get_managed_parent().timeout for resource in waiting))
        else:
            timeout = Timeout(timeout)

        while waiting and not timeout.expired:
            waiting = set(r for r in waiting if r.avail != avail)
            for r in waiting:
                r.poll()
            if not any(r for r in waiting if r.avail == avail):
                # sleep if no progress
                sleep(0.5)

        if waiting:
            raise NoResourceFoundError(
                "Not all resources are {}: {}".format(
                    "available" if avail else "unavailable", waiting),
                filter=waiting
            )