Пример #1
0
def socrates_ub_update_i(
    lab: typing.Optional[linux.LinuxShell] = None,
    uboot: typing.Optional[board.UBootShell] = None,
    interactive = True,
) -> None:
    with contextlib.ExitStack() as cx:
        lh = cx.enter_context(lab or tbot.acquire_lab())
        if uboot is not None:
            ub = uboot
        else:
            b = cx.enter_context(tbot.acquire_board(lh))
            ub = cx.enter_context(tbot.acquire_uboot(b))

        ret = ub.exec("ping", "192.168.1.1")
        while ret[0] != 0:
            ret = ub.exec("ping", "192.168.1.1")

        if "restore_old_ub" in tbot.flags:
            tbot.log.message("restore old U-Boot")
            ub.env("uboot_addr", "FFFA0000")
            ub.env("uboot_file", "socrates-abb/20190627/socrates-u-boot.bin-voncajus")
        else:
            ub.env("uboot_addr", "FFF60000")
            ub.env("uboot_file", f"socrates-abb/{b.date}/u-boot-socrates.bin")
            ub.env("update_uboot", "tftp 110000 ${uboot_file};protect off ${uboot_addr} ffffffff;era ${uboot_addr} ffffffff;cp.b 110000 ${uboot_addr} ${filesize}")

        ub.exec0("printenv")
        ub.exec0("run", "update_uboot")

        if interactive:
            ub.interactive()
Пример #2
0
def selftest_tc_git_checkout(lab: typing.Optional[linux.LabHost] = None,) -> None:
    with lab or tbot.acquire_lab() as lh:
        remote = git_prepare(lh)
        target = lh.workdir / "selftest-git-checkout"

        if target.exists():
            lh.exec0("rm", "-rf", target)

        tbot.log.message("Cloning repo ...")
        repo = git.GitRepository(target, remote)

        assert (repo / "README.md").is_file()
        assert not (repo / "file2.md").is_file()

        tbot.log.message("Make repo dirty ...")
        lh.exec0("echo", "Test 123", stdout=repo / "file.txt")

        repo = git.GitRepository(target, remote, clean=False)
        assert (repo / "file.txt").is_file()

        repo = git.GitRepository(target, remote, clean=True)
        assert not (repo / "file.txt").is_file()

        tbot.log.message("Add dirty commit ...")
        lh.exec0("echo", "Test 123", stdout=repo / "file.txt")
        repo.add(repo / "file.txt")
        repo.commit("Add file.txt", author="tbot Selftest <none@none>")

        repo = git.GitRepository(target, remote, clean=False)
        assert (repo / "file.txt").is_file()

        repo = git.GitRepository(target, remote, clean=True)
        assert not (repo / "file.txt").is_file()

        lh.exec0("rm", "-rf", target)
Пример #3
0
Файл: path.py Проект: zkrx/tbot
def selftest_path_integrity(
        lab: typing.Optional[selftest.SelftestHost] = None) -> None:
    """Test if using a path on the wrong host fails."""

    with lab or selftest.SelftestHost() as lh:
        p = lh.workdir / "folder" / "file.txt"

        with tbot.acquire_lab() as lh2:
            raised = False
            try:
                # mypy detects that this is wrong
                lh2.exec0("echo", p)  # type: ignore
            # TODO: Proper exception type
            except:  # noqa: E722
                raised = True
            assert raised

        # It is ok to clone a machine and reuse the path
        with lh.clone() as lh3:
            lh3.exec0("echo", p)

        lh.exec0("mkdir", "-p", p.parent)
        assert p.parent.is_dir()
        lh.exec0("uname", "-a", linux.RedirStdout(p))
        assert p.is_file()
        lh.exec0("rm", "-r", p.parent)
        assert not p.exists()
        assert not p.parent.exists()
Пример #4
0
def selftest_board_uboot_noab(
    lab: typing.Optional[tbot.selectable.LabHost] = None
) -> None:
    """Test if tbot intercepts U-Boot correctly without autoboot."""

    class TestBoardUBootNoAB(board.UBootMachine[TestBoard]):
        """Dummy Board UBoot."""

        autoboot_prompt = None
        prompt = "Test-U-Boot> "

    with contextlib.ExitStack() as cx:
        lh = cx.enter_context(lab or tbot.acquire_lab())
        b = cx.enter_context(TestBoard(lh, has_autoboot=False))
        ub = cx.enter_context(TestBoardUBootNoAB(b))

        ub.exec0("version")
        env = ub.exec0("printenv").strip().split("\n")

        for line in env[:-1]:
            if line != "" and line[0].isalnum():
                assert "=" in line, repr(line)

        out = ub.exec0("echo", board.F("0x{}", str(1234))).strip()
        assert out == "0x1234", repr(out)

        mach.selftest_machine_shell(ub)
Пример #5
0
def ari_ub_check_multi_dtb_select(
    lab: typing.Optional[linux.LinuxShell] = None,
    board: typing.Optional[board.Board] = None,
    ubx: typing.Optional[board.UBootShell] = None,
) -> None:
    with lab or tbot.acquire_lab() as lh:
        with contextlib.ExitStack() as bx:
            b = bx.enter_context(tbot.acquire_board(lh))
            with contextlib.ExitStack() as cx:
                ub = cx.enter_context(tbot.acquire_uboot(b))

                cur_panel = ge.ub_get_var(ub, "panel")
                old_panel = cur_panel
                check_panel(ub, cur_panel)
                cur_panel = switch_panel(ub, cur_panel)
                ub.ch.sendline("res")

            with contextlib.ExitStack() as cx:
                ub = cx.enter_context(tbot.acquire_uboot(b))
                cur_panel = ge.ub_get_var(ub, "panel")
                if old_panel == cur_panel:
                    raise RuntimeError(
                        f"{cur_panel} == {old_panel}, should change")
                old_panel = cur_panel
                check_panel(ub, cur_panel)
                cur_panel = switch_panel(ub, cur_panel)
                ub.ch.sendline("res")

            with contextlib.ExitStack() as cx:
                ub = cx.enter_context(tbot.acquire_uboot(b))
                cur_panel = ge.ub_get_var(ub, "panel")
                if old_panel == cur_panel:
                    raise RuntimeError(
                        f"{cur_panel} == {old_panel}, should change")
                check_panel(ub, cur_panel)
Пример #6
0
def socrates_ub_bdi_update(
    lab: typing.Optional[linux.LinuxShell] = None,
    board: typing.Optional[board.Board] = None,
    ubma: typing.Optional[board.UBootShell] = None,
) -> None:
    with contextlib.ExitStack() as cx:
        if lab is not None:
            lh = lab
        else:
            lh = cx.enter_context(tbot.acquire_lab())

        if board is not None:
            b = board
        else:
            b = cx.enter_context(tbot.acquire_board(lh))

        bd.bdi_connect(lh, b)

        bd.bdi_reset_board()

        bd.exec("era")
        if "restore_old_ub" in tbot.flags:
            bd.exec("prog", "0xfffa0000", f"socrates-abb/{b.date}/socrates-u-boot.bin-voncajus", "BIN")
        else:
            bd.exec("era", "0xfff60000")
            bd.exec("prog", "0xfff60000", f"socrates-abb/{b.date}/u-boot-socrates.bin", "BIN")

        bd.bdi_reset_board_run()
        if ubma is not None:
            ub = ubma
        else:
            ub = cx.enter_context(tbot.acquire_uboot(b))

        ub.interactive()
Пример #7
0
def ari_ub_check_version(
    lab: typing.Optional[linux.LinuxShell] = None,
    board: typing.Optional[board.Board] = None,
    ubx: typing.Optional[board.UBootShell] = None,
) -> None:
    """
    u-boot check if version on board is the same as in binary
    """
    with lab or tbot.acquire_lab() as lh:
        with contextlib.ExitStack() as cx:
            if board is not None:
                b = board
            else:
                b = cx.enter_context(tbot.acquire_board(lh))

            if ubx is not None:
                ub = ubx
            else:
                ub = cx.enter_context(tbot.acquire_uboot(b))

            t = lh.tftp_dir / "u-boot-dtb.imx.signed"

            #bin_vers = lh.exec0("strings", t, linux.Pipe, "grep", '"U-Boot 2"')
            bin_vers = lh.exec0(
                linux.Raw(
                    f"strings /tftpboot/aristainetos/tbot/u-boot-dtb.imx.signed | grep --color=never 'U-Boot 2'"
                ))
            ub_vers = ub.exec0("version")

            if bin_vers in ub_vers:
                tbot.log.message(
                    tbot.log.c("Info: U-Boot version is the same").green)
            else:
                raise RuntimeError(f"{bin_vers} != {ub_vers}")
Пример #8
0
def selftest(lab: typing.Optional[linux.Lab] = None, ) -> None:
    """Run all selftests."""
    with lab or tbot.acquire_lab() as lh:
        tc.testsuite(
            selftest_failing,
            selftest_skipping,
            selftest_uname,
            selftest_user,
            machine.selftest_machine_reentrant,
            machine.selftest_machine_labhost_shell,
            machine.selftest_machine_ssh_shell,
            machine.selftest_machine_sshlab_shell,
            path.selftest_path_stat,
            path.selftest_path_integrity,
            board_machine.selftest_board_power,
            board_machine.selftest_board_uboot,
            board_machine.selftest_board_uboot_noab,
            board_machine.selftest_board_linux,
            board_machine.selftest_board_linux_uboot,
            board_machine.selftest_board_linux_standalone,
            board_machine.selftest_board_linux_nopw,
            board_machine.selftest_board_linux_bad_console,
            testcase.selftest_with_lab,
            testcase.selftest_with_uboot,
            testcase.selftest_with_linux,
            lab=lh,
        )
Пример #9
0
def selftest_tc_git_bisect(lab: typing.Optional[linux.Lab] = None, ) -> None:
    """Test the git-bisect testcase."""
    with lab or tbot.acquire_lab() as lh:
        remote = git_prepare(lh)
        target = lh.workdir / "selftest-git-bisect"

        if target.exists():
            lh.exec0("rm", "-rf", target)

        repo = git.GitRepository(target, remote)
        good = git_increment_commits(repo)

        @tbot.testcase
        def check_counter(repo: git.GitRepository) -> bool:
            result = repo.host.exec("cat", repo / "counter.txt")
            return result[0] == 0 and int(result[1].strip()) < 17

        head = repo.symbolic_head

        bad = repo.bisect(good=good, test=check_counter)
        tbot.log.message(f"Bad commit is {bad}!")

        repo.git0("show", bad, linux.Pipe, "cat")

        new_head = repo.symbolic_head
        assert (new_head == head
                ), f"Bisect didn't clean up ... ({new_head!r} != {head!r})"
        lh.exec0("rm", "-rf", target)
Пример #10
0
def board_power(
    lab: typing.Optional[tbot.selectable.LabHost] = None,
    board: typing.Optional[board.Board] = None,
    state='on',
) -> None:
    """
    power on or off the board without acquiring console.

    This is only hacky version, we should bring in this into
    tbot.
    """
    with contextlib.ExitStack() as cx:
        lh = cx.enter_context(lab or tbot.acquire_lab())

        fl = tbot.flags

        tbot.flags = {"no_console_check", "nopoweroff"}
        b = cx.enter_context(board or tbot.acquire_board(lh))

        tbot.flags = fl
        if state == 'on':
            b.poweron()
        else:
            b.poweroff()

        tbot.flags = {"no_console_check", "nopoweroff"}
Пример #11
0
def selftest_board_uboot(lab: typing.Optional[tbot.selectable.LabHost] = None) -> None:
    """Test if tbot intercepts U-Boot correctly."""

    with contextlib.ExitStack() as cx:
        lh = cx.enter_context(lab or tbot.acquire_lab())
        try:
            b: board.Board = cx.enter_context(tbot.acquire_board(lh))
            ub: board.UBootShell = cx.enter_context(
                tbot.acquire_uboot(b)  # type: ignore
            )
        except NotImplementedError:
            b = cx.enter_context(TestBoard(lh))
            ub = cx.enter_context(TestBoardUBoot(b))

        ub.exec0("version")
        env = ub.exec0("printenv").strip().split("\n")

        for line in env[:-1]:
            if line != "" and line[0].isalnum():
                assert "=" in line, repr(line)

        out = ub.exec0("echo", hex(0x1234)).strip()
        assert out == "0x1234", repr(out)

        mach.selftest_machine_shell(ub)
Пример #12
0
def selftest_board_linux_standalone(
    lab: typing.Optional[tbot.selectable.LabHost] = None
) -> None:
    """Test linux booting standalone."""

    class TestBoardLinuxStandalone(board.LinuxStandaloneMachine[TestBoard]):
        username = "******"
        password = None
        login_prompt = "Autoboot: "
        shell = linux.shell.Bash

    with lab or tbot.acquire_lab() as lh:
        tbot.log.message("Testing without UB ...")
        with TestBoard(lh) as b:
            with TestBoardLinuxStandalone(b) as lnx:
                lnx.exec0("uname", "-a")

        tbot.log.message("Testing with UB ...")
        with TestBoard(lh) as b:
            with TestBoardUBoot(b) as ub:
                raised = False
                try:
                    with TestBoardLinuxStandalone(ub) as lnx:
                        lnx.exec0("uname", "-a")
                except RuntimeError:
                    raised = True
                assert raised
Пример #13
0
def selftest_board_power(lab: typing.Optional[tbot.selectable.LabHost] = None) -> None:
    """Test if the board is powered on and off correctly."""
    with lab or tbot.acquire_lab() as lh:
        power_path = lh.workdir / "selftest_power"
        if power_path.exists():
            lh.exec0("rm", power_path)

        tbot.log.message("Emulating a normal run ...")
        assert not power_path.exists()
        with TestBoard(lh):
            assert power_path.exists()

        assert not power_path.exists()

        class TestException(Exception):
            pass

        tbot.log.message("Emulating a failing run ...")
        try:
            with TestBoard(lh):
                assert power_path.exists()
                tbot.log.message("raise TestException()")
                raise TestException()
        except TestException:
            pass

        assert not power_path.exists()
Пример #14
0
def selftest_user(lab: typing.Optional[linux.Lab] = None, ) -> None:
    """Test lab-host variable expansion."""
    with lab or tbot.acquire_lab() as lh:
        lh.exec0("echo", lh.env("USER"))

        user = lh.env("USER")
        assert "\n" not in user, "Malformed username?"
Пример #15
0
def ari_ub_sign(lab: typing.Optional[linux.LinuxShell] = None, ) -> None:
    """
    sign u-boot
    """
    with lab or tbot.acquire_lab() as lh:
        for f in result_files:
            if "u-boot" in f:
                # copy file to sign path
                s = lh.tftp_dir / f
                t = lh.sign_dir / f
                tbot.tc.shell.copy(s, t)
                lh.exec0("cd", lh.sign_dir)
                lh.exec0("pwd")
                lh.exec0("./cst", "--o", "u-boot-dtb_csf.bin", "--i",
                         "u-boot-dtb.csf")
                lh.exec0(
                    linux.Raw(
                        "cat u-boot-dtb.imx u-boot-dtb_csf.bin > u-boot-dtb.imx.signed"
                    ))
                s = lh.sign_dir / "u-boot-dtb.imx.signed"
                t = lh.tftp_dir / "u-boot-dtb.imx.signed"
                tbot.tc.shell.copy(s, t)
                # cleanup
                lh.exec0("rm", "u-boot-dtb_csf.bin")
                lh.exec0("rm", "u-boot-dtb.imx.signed")
Пример #16
0
def install():
    """ Flash the u-boot-image to the board """
    with contextlib.ExitStack() as cx:
        lab = cx.enter_context(tbot.acquire_lab())
        host = typing.cast(linux.Builder, cx.enter_context(lab.build()))
        builder = getattr(tbot.selectable.UBootMachine, "build")
        path = builder.do_repo_path(host)
        builder.install(host, path._local_str())
Пример #17
0
def selftest_with_lab(lab: typing.Optional[linux.Lab] = None) -> None:
    """Test the tbot.with_lab decorator."""
    with lab or tbot.acquire_lab() as lh:
        # Call without parameter
        selftest_decorated_lab()

        # Call with parameter
        selftest_decorated_lab(lh)
Пример #18
0
def selftest_machine_reentrant(lab: typing.Optional[linux.LabHost] = None,) -> None:
    """Test if a machine can be entered multiple times."""
    with lab or tbot.acquire_lab() as lh:
        with lh as h1:
            assert h1.exec0("echo", "FooBar") == "FooBar\n"

        with lh as h2:
            assert h2.exec0("echo", "FooBar2") == "FooBar2\n"
Пример #19
0
def selftest_machine_labhost_shell(
    lab: typing.Optional[linux.LabHost] = None, ) -> None:
    """Test the LabHost's shell."""
    with lab or tbot.acquire_lab() as lh:
        selftest_machine_shell(lh)

        selftest_machine_channel(lh.new_channel(), False)
        selftest_machine_channel(lh.new_channel(), True)
Пример #20
0
def ub_check_version(
    resfiles: list,
    lab: typing.Optional[linux.LinuxShell] = None,
    board: typing.Optional[board.Board] = None,
    ubx: typing.Optional[board.UBootShell] = None,
) -> None:
    """
    check if installed U-Boot version is the same as in
    tftp directory.
    """
    with lab or tbot.acquire_lab() as lh:
        r = get_path(lh.tftp_root_path) + "/" + get_path(lh.tftp_dir_board)
        spl_vers = None
        ub_vers = None
        splfiles = ["MLO", "SPL"]
        ubfiles = ["u-boot.img", "u-boot-socrates.bin", "u-boot.bin", "u-boot-dtb.imx", "u-boot-dtb.bin"]
        for f in resfiles:
            if spl_vers == None:
                if any(s in f for s in splfiles):
                    log_event.doc_begin("get_spl_vers")
                    spl_vers = lh.exec0(linux.Raw(f'strings {r}/{f} | grep --color=never "U-Boot SPL 2"'))
                    spl_vers = spl_vers.strip()
                    log_event.doc_tag("ub_spl_new_version", spl_vers)
                    log_event.doc_end("get_spl_vers")
                    tbot.log.message(tbot.log.c(f"found in image U-Boot SPL version {spl_vers}").green)
            if ub_vers == None:
                if any(s in f for s in ubfiles):
                    log_event.doc_begin("get_ub_vers")
                    ub_vers = lh.exec0(linux.Raw(f'strings {r}/{f} | grep --color=never "U-Boot 2"'))
                    for l in ub_vers.split('\n'):
                        if ":" in l:
                            ub_vers = l.strip()
                    if ub_vers[0] == 'V':
                        ub_vers = ub_vers[1:]
                    log_event.doc_tag("ub_ub_new_version", ub_vers)
                    log_event.doc_end("get_ub_vers")
                    tbot.log.message(tbot.log.c(f"found in image U-Boot version {ub_vers}").green)

        with contextlib.ExitStack() as cx:
            if board is not None:
                b = board
            else:
                b = cx.enter_context(tbot.acquire_board(lh))
            if ubx is not None:
                ub = ubx
            else:
                ub = cx.enter_context(tbot.acquire_uboot(b))
            if spl_vers != None:
                if spl_vers not in ub.bootlog:
                    raise RuntimeError(f"{spl_vers} not found.")
                tbot.log.message(tbot.log.c(f"found U-Boot SPL version {spl_vers} installed").green)
            if ub_vers == None:
                raise RuntimeError(f"No U-Boot version defined")
            else:
                if ub_vers not in ub.bootlog:
                    raise RuntimeError(f"{ub_vers} not found.")
                tbot.log.message(tbot.log.c(f"found U-Boot version {ub_vers} installed").green)
Пример #21
0
def selftest_tc(lab: typing.Optional[linux.LabHost] = None, ) -> None:
    """Test builtin testcases."""
    with lab or tbot.acquire_lab() as lh:
        tc.testsuite(
            selftest_tc_git_checkout,  # noqa: F405
            selftest_tc_git_am,  # noqa: F405
            selftest_tc_git_bisect,  # noqa: F405
            selftest_tc_shell_copy,  # noqa: F405
            lab=lh,
        )
Пример #22
0
def getcpu(mach: typing.Optional[linux.LinuxMachine] = None, ) -> None:
    with contextlib.ExitStack() as cx:
        if mach is None:
            lh = cx.enter_context(tbot.acquire_lab())
            b = cx.enter_context(tbot.acquire_board(lh))
            lnx = cx.enter_context(tbot.acquire_linux(b))
        else:
            lnx = mach

        lnx.exec0("cat", "/proc/cpuinfo")
Пример #23
0
def gettarget(mach: typing.Optional[linux.LinuxMachine] = None, ) -> None:
    with contextlib.ExitStack() as cx:
        if mach is None:
            lh = cx.enter_context(tbot.acquire_lab())
            b = cx.enter_context(tbot.acquire_board(lh))
            lnx = cx.enter_context(tbot.acquire_linux(b))
        else:
            lnx = mach

        tc.testsuite(getcpu, getlinuxversion, getyoctoversion, mach=lnx)
Пример #24
0
def selftest_tc_kconfig(lab: typing.Optional[linux.Lab] = None) -> None:
    """Test kconig setting."""
    with lab or tbot.acquire_lab() as lh:
        conf = lh.workdir / "selftest-kconfig"

        for i in range(4):
            lh.exec0(
                "echo",
                """\
# tbot-selftest kconfig file
# DO NOT EDIT! (Deleting is ok, though)

CONFIG_FOO=y
CONFIG_BAR=m
# CONFIG_BAZ is not set
CONFIG_STRING="a happy string"
CONFIG_HEX=0xC0FFEE""",
                linux.RedirStdout(conf),
            )

            if i == 0:
                tbot.log.message("Enabling all ...")
                kconfig.enable(conf, "CONFIG_FOO")
                kconfig.enable(conf, "CONFIG_BAR")
                kconfig.enable(conf, "CONFIG_BAZ")

                assert (lh.exec0("grep", "-c", "-E", "CONFIG_(FOO|BAR|BAZ)=y",
                                 conf).strip() == "3")
            elif i == 1:
                tbot.log.message("Disabling all ...")
                kconfig.disable(conf, "CONFIG_FOO")
                kconfig.disable(conf, "CONFIG_BAR")
                kconfig.disable(conf, "CONFIG_BAZ")

                assert (lh.exec0("grep", "-c", "-E", "# CONFIG_(FOO|BAR|BAZ)",
                                 conf).strip() == "3")
                assert (lh.exec("grep", "-c", "-E", "^CONFIG_(FOO|BAR|BAZ)",
                                conf)[1].strip() == "0")
            elif i == 2:
                tbot.log.message("Moduling all ...")
                kconfig.module(conf, "CONFIG_FOO")
                kconfig.module(conf, "CONFIG_BAR")
                kconfig.module(conf, "CONFIG_BAZ")

                assert (lh.exec0("grep", "-c", "-E", "CONFIG_(FOO|BAR|BAZ)=m",
                                 conf).strip() == "3")
            elif i == 3:
                tbot.log.message("Testing values ...")
                kconfig.set_string_value(conf, "CONFIG_STRING", "abcdef")
                kconfig.set_hex_value(conf, "CONFIG_HEX", 0xDEADBEEF)

                assert (lh.exec0("grep", "-c", 'CONFIG_STRING="abcdef"',
                                 conf).strip() == "1")
                assert (lh.exec0("grep", "-c", "CONFIG_HEX=0xdeadbeef",
                                 conf).strip() == "1")
Пример #25
0
def selftest_tc_shell_copy(
    lab: typing.Optional[linux.LabHost] = None, ) -> None:
    """Test ``shell.copy``."""
    def do_test(a: linux.Path, b: linux.Path, msg: str) -> None:
        if b.exists():
            b.host.exec0("rm", b)
        a.host.exec0("echo", msg, stdout=a)

        shell.copy(a, b)

        out = b.host.exec0("cat", b).strip()
        assert out == msg, repr(out) + " != " + repr(msg)

    with lab or tbot.acquire_lab() as lh:
        tbot.log.message("Test copying a file on the same host ...")
        do_test(
            lh.workdir / ".selftest-copy-local1",
            lh.workdir / ".selftest-copy-local2",
            "Copy locally",
        )

        if minisshd.check_minisshd(lh):
            with minisshd.minisshd(lh) as ssh:
                tbot.log.message(
                    "Test downloading a file from an ssh host ...")
                do_test(
                    ssh.workdir / ".selftest-copy-ssh1",
                    lh.workdir / ".selftest-copy-ssh2",
                    "Download via SCP",
                )

                tbot.log.message("Test uploading a file to an ssh host ...")
                do_test(
                    lh.workdir / ".selftest-copy-ssh1",
                    ssh.workdir / ".selftest-copy-ssh2",
                    "Upload via SCP",
                )

                with minisshd.MiniSSHLabHost(ssh.port) as sl:
                    tbot.log.message(
                        "Test downloading a file from an ssh lab ...")
                    do_test(
                        sl.workdir / ".selftest-copy-ssh4",
                        lh.workdir / ".selftest-copy-ssh3",
                        "Download via SCP Lab",
                    )

                    tbot.log.message("Test uploading a file to an ssh lab ...")
                    do_test(
                        lh.workdir / ".selftest-copy-ssh3",
                        sl.workdir / ".selftest-copy-ssh4",
                        "Upload via SCP Lab",
                    )
        else:
            tbot.log.message(tbot.log.c("Skip").yellow.bold + " ssh tests.")
Пример #26
0
def getyoctoversion(
    mach: typing.Optional[linux.LinuxMachine] = None, ) -> None:
    with contextlib.ExitStack() as cx:
        if mach is None:
            lh = cx.enter_context(tbot.acquire_lab())
            b = cx.enter_context(tbot.acquire_board(lh))
            lnx = cx.enter_context(tbot.acquire_linux(b))
        else:
            lnx = mach

        lnx.exec0("cat", "/etc/os_release")
Пример #27
0
 def yo_repo_sync(
         self,
         lab: typing.Optional[linux.LinuxShell] = None,
         build: typing.
     Optional[
         linux.LinuxShell] = None,  # besser check if it is a build machine!
 ) -> None:
     with lab or tbot.acquire_lab() as lh:
         with build or lh.build() as bh:
             self.cd_yocto_workdir(bh)
             self.repo_sync(bh)
Пример #28
0
def selftest_machine_labhost_shell(
    lab: typing.Optional[linux.Lab] = None, ) -> None:
    """Test the LabHost's shell."""
    with lab or tbot.acquire_lab() as lh:
        selftest_machine_shell(lh)

        with lh.clone() as l2:
            selftest_machine_channel(l2.ch, False)

        with lh.clone() as l2:
            selftest_machine_channel(l2.ch, True)
Пример #29
0
def selftest_path_integrity(lab: typing.Optional[linux.LabHost] = None,) -> None:
    with lab or tbot.acquire_lab() as lh:
        p = lh.workdir / "folder" / "file.txt"

        with tbot.acquire_lab() as lh2:
            raised = False
            try:
                # mypy detects that this is wrong
                lh2.exec0("echo", p)  # type: ignore
            except machine.WrongHostException:
                raised = True
            assert raised

        lh.exec0("mkdir", "-p", p.parent)
        assert p.parent.is_dir()
        lh.exec0("uname", "-a", stdout=p)
        assert p.is_file()
        lh.exec0("rm", "-r", p.parent)
        assert not p.exists()
        assert not p.parent.exists()
Пример #30
0
def selftest_machine_ssh_shell(lab: typing.Optional[linux.LabHost] = None,) -> None:
    """Test an SSH shell."""
    from tbot.tc.selftest import minisshd

    with lab or tbot.acquire_lab() as lh:
        if minisshd.check_minisshd(lh):
            with minisshd.minisshd(lh) as ssh:
                selftest_machine_shell(ssh)

                selftest_machine_channel(ssh._obtain_channel(), True)
        else:
            tbot.log.message(tbot.log.c("Skip").yellow.bold + " ssh tests.")