From 695ba46528c5dd44226a6fd0ad0201b1c2982789 Mon Sep 17 00:00:00 2001 From: Pavel Zhukov Date: Tue, 10 Oct 2023 11:47:01 +0200 Subject: bitbake: tests/fetch.py: Add tests to cover multiple branch/name parameters Create repository with few branches and test if fetcher can work with such repository as PREMIRROR (Bitbake rev: a1737610e5d5b61e126ec3632d7f27b337a87818) Signed-off-by: Pavel Zhukov Signed-off-by: Luca Ceresoli Signed-off-by: Richard Purdie --- bitbake/lib/bb/tests/fetch.py | 75 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 69 insertions(+), 6 deletions(-) (limited to 'bitbake/lib/bb/tests/fetch.py') diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py index eeb7a31471..0e806c0ff7 100644 --- a/bitbake/lib/bb/tests/fetch.py +++ b/bitbake/lib/bb/tests/fetch.py @@ -3042,9 +3042,11 @@ class FetchPremirroronlyLocalTest(FetcherTest): self.d.setVar("BB_FETCH_PREMIRRORONLY", "1") self.d.setVar("BB_NO_NETWORK", "1") self.d.setVar("PREMIRRORS", self.recipe_url + " " + "file://{}".format(self.mirrordir) + " \n") + self.mirrorname = "git2_git.fake.repo.bitbake.tar.gz" + self.mirrorfile = os.path.join(self.mirrordir, self.mirrorname) + self.testfilename = "bitbake-fetch.test" def make_git_repo(self): - self.mirrorname = "git2_git.fake.repo.bitbake.tar.gz" recipeurl = "git:/git.fake.repo/bitbake" os.makedirs(self.gitdir) self.git_init(cwd=self.gitdir) @@ -3054,15 +3056,23 @@ class FetchPremirroronlyLocalTest(FetcherTest): def git_new_commit(self): import random - testfilename = "bibake-fetch.test" os.unlink(os.path.join(self.mirrordir, self.mirrorname)) - with open(os.path.join(self.gitdir, testfilename), "w") as testfile: - testfile.write("Useless random data {}".format(random.random())) - self.git("add {}".format(testfilename), self.gitdir) - self.git("commit -a -m \"This random commit {}. I'm useless.\"".format(random.random()), self.gitdir) + branch = self.git("branch --show-current", self.gitdir).split() + with open(os.path.join(self.gitdir, self.testfilename), "w") as testfile: + testfile.write("File {} from branch {}; Useless random data {}".format(self.testfilename, branch, random.random())) + self.git("add {}".format(self.testfilename), self.gitdir) + self.git("commit -a -m \"This random commit {} in branch {}. I'm useless.\"".format(random.random(), branch), self.gitdir) bb.process.run('tar -czvf {} .'.format(os.path.join(self.mirrordir, self.mirrorname)), cwd = self.gitdir) return self.git("rev-parse HEAD", self.gitdir).strip() + def git_new_branch(self, name): + self.git_new_commit() + head = self.git("rev-parse HEAD", self.gitdir).strip() + self.git("checkout -b {}".format(name), self.gitdir) + newrev = self.git_new_commit() + self.git("checkout {}".format(head), self.gitdir) + return newrev + def test_mirror_commit_nonexistent(self): self.make_git_repo() self.d.setVar("SRCREV", "0"*40) @@ -3083,6 +3093,59 @@ class FetchPremirroronlyLocalTest(FetcherTest): with self.assertRaises(bb.fetch2.NetworkAccess): fetcher.download() + def test_mirror_tarball_multiple_branches(self): + """ + test if PREMIRRORS can handle multiple name/branches correctly + both branches have required revisions + """ + self.make_git_repo() + branch1rev = self.git_new_branch("testbranch1") + branch2rev = self.git_new_branch("testbranch2") + self.recipe_url = "git://git.fake.repo/bitbake;branch=testbranch1,testbranch2;protocol=https;name=branch1,branch2" + self.d.setVar("SRCREV_branch1", branch1rev) + self.d.setVar("SRCREV_branch2", branch2rev) + fetcher = bb.fetch.Fetch([self.recipe_url], self.d) + self.assertTrue(os.path.exists(self.mirrorfile), "Mirror file doesn't exist") + fetcher.download() + fetcher.unpack(os.path.join(self.tempdir, "unpacked")) + unpacked = os.path.join(self.tempdir, "unpacked", "git", self.testfilename) + self.assertTrue(os.path.exists(unpacked), "Repo has not been unpackaged properly!") + with open(unpacked, 'r') as f: + content = f.read() + ## We expect to see testbranch1 in the file, not master, not testbranch2 + self.assertTrue(content.find("testbranch1") != -1, "Wrong branch has been checked out!") + + def test_mirror_tarball_multiple_branches_nobranch(self): + """ + test if PREMIRRORS can handle multiple name/branches correctly + Unbalanced name/branches raises ParameterError + """ + self.make_git_repo() + branch1rev = self.git_new_branch("testbranch1") + branch2rev = self.git_new_branch("testbranch2") + self.recipe_url = "git://git.fake.repo/bitbake;branch=testbranch1;protocol=https;name=branch1,branch2" + self.d.setVar("SRCREV_branch1", branch1rev) + self.d.setVar("SRCREV_branch2", branch2rev) + with self.assertRaises(bb.fetch2.ParameterError): + fetcher = bb.fetch.Fetch([self.recipe_url], self.d) + + def test_mirror_tarball_multiple_branches_norev(self): + """ + test if PREMIRRORS can handle multiple name/branches correctly + one of the branches specifies non existing SRCREV + """ + self.make_git_repo() + branch1rev = self.git_new_branch("testbranch1") + branch2rev = self.git_new_branch("testbranch2") + self.recipe_url = "git://git.fake.repo/bitbake;branch=testbranch1,testbranch2;protocol=https;name=branch1,branch2" + self.d.setVar("SRCREV_branch1", branch1rev) + self.d.setVar("SRCREV_branch2", "0"*40) + fetcher = bb.fetch.Fetch([self.recipe_url], self.d) + self.assertTrue(os.path.exists(self.mirrorfile), "Mirror file doesn't exist") + with self.assertRaises(bb.fetch2.NetworkAccess): + fetcher.download() + + class FetchPremirroronlyNetworkTest(FetcherTest): def setUp(self): -- cgit v1.2.3-54-g00ecf