Пример #1
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)
Пример #2
0
    def do_checkout(
        self, target: linux.Path[H], clean: bool, rev: typing.Optional[str]
    ) -> git.GitRepository[H]:
        """
        Build step that defines how to checkout OpenSBI.

        Overwrite this step if you have a custom checkout procedure::

            def do_checkout(self, target: linux.Path, clean: bool) -> git.GitRepository:
                return git.GitRepository(
                    target=target,
                    url=self.remote,
                    clean=clean,
                    rev="v0.8",
                )

        :param linux.Path target:  Where to checkout OpenSBI to. This build-step
            must be able to deal with an already checked out OpenSBI source.
        :param bool clean: Whether this build-step should clean the source-dir
            (like ``git clean -fdx``).
        :param str rev: Revision to check out, or None to use the current
            revision.
        :rtype: tbot.tc.git.GitRepository
        :returns: A git repo of the checked out OpenSBI sources
        """
        return git.GitRepository(target=target, url=self.remote, clean=clean, rev=rev)
Пример #3
0
Файл: git.py Проект: Lusus/tbot
def selftest_tc_git_bisect(lab: typing.Optional[selftest.SelftestHost] = None) -> None:
    """Test the git-bisect testcase."""
    with lab or selftest.SelftestHost() 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)
Пример #4
0
 def do_checkout(self, target: linux.Path, clean: bool,
                 rev: typing.Optional[str]) -> git.GitRepository:
     branch = "master"
     return git.GitRepository(target=target,
                              url=self.remote,
                              clean=clean,
                              rev=branch)
Пример #5
0
Файл: git.py Проект: Lusus/tbot
def git_prepare(lab: linux.Lab) -> str:
    """Prepare a test git repo."""
    global _GIT

    if _GIT is None:
        # Git committer and author information in case the user's git
        # environment is not set up yet
        lab.env("GIT_AUTHOR_NAME", "tbot selftest")
        lab.env("GIT_AUTHOR_EMAIL", "*****@*****.**")
        lab.env("GIT_COMMITTER_NAME", "tbot selftest")
        lab.env("GIT_COMMITTER_EMAIL", "*****@*****.**")

        p = lab.workdir / "selftest-git-remote"

        if p.exists():
            lab.exec0("rm", "-rf", p)

        tbot.log.message("Setting up test repo ...")

        lab.exec0("mkdir", "-p", p)
        lab.exec0("git", "-C", p, "init")
        repo = git.GitRepository(p, clean=False)

        lab.exec0(
            "echo",
            """\
# tbot Selftest
This repo exists to test tbot's git testcase.

You can safely remove it, but please **do not** modify it as that might
break the tests.""",
            linux.RedirStdout(repo / "README.md"),
        )

        repo.add(repo / "README.md")
        repo.commit("Initial", author="tbot Selftest <none@none>")

        tbot.log.message("Creating test patch ...")
        lab.exec0(
            "echo",
            """\
# File 2
A second file that will have been added by patching.""",
            linux.RedirStdout(repo / "file2.md"),
        )

        repo.add(repo / "file2.md")
        repo.commit("Add file2", author="tbot Selftest <none@none>")
        patch_name = repo.git0("format-patch", "HEAD~1").strip()
        lab.exec0("mv", repo / patch_name, lab.workdir / "selftest-git.patch")

        tbot.log.message("Resetting repo ...")
        repo.reset("HEAD~1", git.ResetMode.HARD)

        _GIT = p._local_str()
        return _GIT
    else:
        return _GIT
Пример #6
0
Файл: git.py Проект: zkrx/tbot
def selftest_tc_git_apply(
        lab: typing.Optional[selftest.SelftestHost] = None) -> None:
    """Test applying patches."""
    with lab or selftest.SelftestHost() as lh:
        remote = git_prepare(lh)
        target = lh.workdir / "selftest-git-apply"

        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("Apply patch ...")
        repo.apply(lh.workdir / "selftest-git.patch")

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

        repo.add(repo / "file2.md")
        repo.commit("Add file2 from patch", author="tbot Selftest <none@none>")

        lh.exec0(
            "echo",
            """\
# File 2
A second file that will have been added by patching.

## 2.2
This section was added by a second patch""",
            linux.RedirStdout(repo / "file2.md"),
        )

        repo.add(repo / "file2.md")
        repo.commit("Update file2", author="tbot Selftest <none@none>")

        patch_dir = lh.workdir / "selftest-git-patches"
        lh.exec0("mkdir", "-p", patch_dir)
        repo.git0("format-patch", "-o", patch_dir, "HEAD~2")
        repo.reset("HEAD~2", git.ResetMode.HARD)

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

        tbot.log.message("Apply multiple patches ...")
        repo.apply(patch_dir)

        assert lh.test("grep", "2.2", repo / "file2.md")

        lh.exec0("rm", "-rf", target)
        lh.exec0("rm", "-rf", patch_dir)
Пример #7
0
def git_prepare(lab: linux.LabHost) -> str:
    global _GIT

    if _GIT is None:
        p = lab.workdir / "selftest-git-remote"

        if p.exists():
            lab.exec0("rm", "-rf", p)

        tbot.log.message("Setting up test repo ...")

        lab.exec0("mkdir", "-p", p)
        lab.exec0("git", "-C", p, "init")
        repo = git.GitRepository(p, clean=False)

        lab.exec0(
            "echo",
            """\
# TBot Selftest
This repo exists to test TBot's git testcase.

You can safely remove it, but please **do not** modify it as that might
break the tests.""",
            stdout=repo / "README.md",
        )

        repo.add(repo / "README.md")
        repo.commit("Initial", author="TBot Selftest <none@none>")

        tbot.log.message("Creating test patch ...")
        lab.exec0(
            "echo",
            """\
# File 2
A second file that will have been added by patching.""",
            stdout=repo / "file2.md",
        )

        repo.add(repo / "file2.md")
        repo.commit("Add file2", author="TBot Selftest <none@none>")
        patch_name = repo.git0("format-patch", "HEAD~1").strip()
        lab.exec0("mv", repo / patch_name, lab.workdir / "selftest-git.patch")

        tbot.log.message("Resetting repo ...")
        repo.reset("HEAD~1", git.ResetMode.HARD)

        _GIT = p._local_str()
        return _GIT
    else:
        return _GIT
Пример #8
0
    def checkout(self, clean: bool = True) -> git.GitRepository[BH]:
        """
        Checkout U-Boot for this config.

        Defaults to checking out ``self.uboot_remote`` (=``git://git.denx.de/u-boot.git``).

        Overwrite this method to specify a custom checkout procedure (eg.
        patching the repo afterwards)
        """

        return git.GitRepository(
            target=self.h.workdir / f"uboot-{self.name}",
            url=self.uboot_remote,
            clean=clean,
            rev="master",
        )
Пример #9
0
def selftest_tc_git_am(lab: typing.Optional[linux.LabHost] = None,) -> None:
    with lab or tbot.acquire_lab() as lh:
        remote = git_prepare(lh)
        target = lh.workdir / "selftest-git-am"

        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("Apply patch ...")
        repo.am(lh.workdir / "selftest-git.patch")

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

        lh.exec0(
            "echo",
            """\
# File 2
A second file that will have been added by patching.

## 2.2
This section was added by a second patch""",
            stdout=repo / "file2.md",
        )

        repo.add(repo / "file2.md")
        repo.commit("Update file2", author="TBot Selftest <none@none>")

        patch_dir = lh.workdir / "selftest-git-patches"
        lh.exec0("mkdir", "-p", patch_dir)
        lh.exec0("git", "-C", repo, "format-patch", "-o", patch_dir, "HEAD~2")
        repo.reset("HEAD~2", git.ResetMode.HARD)

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

        tbot.log.message("Apply multiple patches ...")
        repo.am(patch_dir)

        assert lh.test("grep", "2.2", repo / "file2.md")

        lh.exec0("rm", "-rf", target)
        lh.exec0("rm", "-rf", patch_dir)
Пример #10
0
def selftest_tc_git_bisect(
    lab: typing.Optional[linux.LabHost] = None, ) -> None:
    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)
        counter = repo / "counter.txt"

        for i in range(0, 24):
            tbot.log.message(f"Create commit ({i+1:2}/24) ...")

            lh.exec0("echo", str(i), stdout=counter)
            repo.add(counter)
            repo.commit(f"Set counter to {i}",
                        author="tbot Selftest <none@none>")

            if i == 0:
                # Take the first commit with counter as good
                rev = repo.head

        @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=rev, 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)
Пример #11
0
    def do_checkout(self, target: linux.Path[H], clean: bool) -> git.GitRepository[H]:
        """
        Build-Step that defines how to checkout U-Boot.

        Overwrite this step if you have a custom checkout procedure::

            def do_checkout(self, target: linux.Path, clean: bool) -> git.GitRepository:
                return git.GitRepository(
                    target=target,
                    url=self.remote,
                    clean=clean,
                    rev="v2018.09",
                )

        :param linux.Path target:  Where to checkout U-Boot to.  This build-step
            must be able to deal with an already checked out U-Boot source.
        :param bool clean: Whether this build-step should clean the source-dir
            (like ``git clean -fdx``).
        :rtype: tbot.tc.git.GitRepository
        :returns: A git repo of the checked out U-Boot sources
        """
        return git.GitRepository(target=target, url=self.remote, clean=clean)
Пример #12
0
def _uboot_prepare(h: linux.LinuxShell) -> uboot.UBootBuilder:
    remote = h.workdir / "selftest-ub-remote"

    if remote.exists():
        h.exec0("rm", "-rf", remote)

    h.exec0("mkdir", remote)
    h.exec0("git", "-C", remote, "init")
    repo = git.GitRepository(target=remote, clean=False)

    makefile = """\
all:
\t@echo "Making all ..."
\ttest ${CC} = "dummy-none-gcc"
\texit 1

defconfig:
\t@echo "Configuring ..."
\ttouch .config

mrproper:
\t@echo "Cleaning ..."
\trm -f .config
\ttouch .cleaned

.PHONY: all defconfig mrproper
"""

    h.exec0("echo", makefile, linux.RedirStdout(repo / "Makefile"))

    repo.add(repo / "Makefile")
    repo.commit("U-Boot Dummy", author="tbot selftest <tbot@tbot>")

    # Create Patch
    patch = """\
From 1d78601502661ae531b00540bf86e145a317f23f Mon Sep 17 00:00:00 2001
From: tbot Selftest <none@none>
Date: Wed, 30 Jan 2019 13:31:12 +0100
Subject: [PATCH] Fix Makefile

---
 Makefile | 1 -
 1 file changed, 1 deletion(-)

diff --git a/Makefile b/Makefile
index b5319d7..0f01838 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,6 @@
 all:
 \t@echo "Making all ..."
 \ttest ${CC} = "dummy-none-gcc"
-\texit 1
 \n defconfig:
 \t@echo "Configuring ..."
-- \n2.20.1
"""

    patchfile = h.workdir / "uboot-selftest.patch"
    h.exec0("echo", patch, linux.RedirStdout(patchfile))

    class UBootBuilder(uboot.UBootBuilder):
        name = "tbot-selftest"
        remote = repo._local_str()
        defconfig = "defconfig"
        toolchain = "selftest-toolchain"

        def do_patch(self, repo: git.GitRepository) -> None:
            patch = repo.host.workdir / "uboot-selftest.patch"
            repo.am(patch)

    return UBootBuilder()
Пример #13
0
def _uboot_prepare(h: linux.LinuxShell) -> uboot.UBootBuilder:
    remote = h.workdir / "selftest-ub-remote"

    # Git committer and author information in case the user's git
    # environment is not set up yet
    h.env("GIT_AUTHOR_NAME", "tbot selftest")
    h.env("GIT_AUTHOR_EMAIL", "*****@*****.**")
    h.env("GIT_COMMITTER_NAME", "tbot selftest")
    h.env("GIT_COMMITTER_EMAIL", "*****@*****.**")

    if remote.exists():
        h.exec0("rm", "-rf", remote)

    h.exec0("mkdir", remote)
    h.exec0("git", "-C", remote, "init")
    repo = git.GitRepository(target=remote, clean=False)

    makefile = """\
all:
\t@echo "Making all ..."
\ttest ${CC} = "dummy-none-gcc"
\texit 1

defconfig:
\t@echo "Configuring ..."
\ttouch .config

mrproper:
\t@echo "Cleaning ..."
\trm -f .config
\ttouch .cleaned

olddefconfig:

.PHONY: all defconfig mrproper olddefconfig
"""

    (repo / "Makefile").write_text(makefile)

    repo.add(repo / "Makefile")
    repo.commit("U-Boot Dummy", author="tbot selftest <tbot@tbot>")

    # Create Patch
    patch = """\
From 1d78601502661ae531b00540bf86e145a317f23f Mon Sep 17 00:00:00 2001
From: tbot Selftest <none@none>
Date: Wed, 30 Jan 2019 13:31:12 +0100
Subject: [PATCH] Fix Makefile

---
 Makefile | 1 -
 1 file changed, 1 deletion(-)

diff --git a/Makefile b/Makefile
index e76351696ad0..fe143c6d4054 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,6 @@
 all:
 \t@echo "Making all ..."
 \ttest ${CC} = "dummy-none-gcc"
-\texit 1
 \n defconfig:
 \t@echo "Configuring ..."
-- \n2.20.1
"""

    patchfile = h.workdir / "uboot-selftest.patch"
    patchfile.write_text(patch)

    class UBootBuilder(uboot.UBootBuilder):
        name = "tbot-selftest"
        remote = repo.at_host(h)
        defconfig = "defconfig"
        toolchain = "selftest-toolchain"

        def do_patch(self, repo: git.GitRepository) -> None:
            patch = repo.host.workdir / "uboot-selftest.patch"

            # Git committer and author information in case the user's git
            # environment is not set up yet
            repo.host.env("GIT_AUTHOR_NAME", "tbot selftest")
            repo.host.env("GIT_AUTHOR_EMAIL", "*****@*****.**")
            repo.host.env("GIT_COMMITTER_NAME", "tbot selftest")
            repo.host.env("GIT_COMMITTER_EMAIL", "*****@*****.**")

            repo.am(patch)

    return UBootBuilder()
Пример #14
0
 def do_checkout(self, target, clean, rev) -> git.GitRepository:
     branch = "master"
     return git.GitRepository(target=target,
                              url=self.remote,
                              clean=clean,
                              rev=branch)