summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/tests/fetch.py
diff options
context:
space:
mode:
authorPavel Zhukov <pavel@zhukoff.net>2023-10-10 11:47:01 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2023-10-23 11:46:36 +0100
commit695ba46528c5dd44226a6fd0ad0201b1c2982789 (patch)
tree8df07231774ac30181ef88525c58a795853a6221 /bitbake/lib/bb/tests/fetch.py
parentea09071364a45559d15bf39db8e2848c7ce7cd22 (diff)
downloadpoky-695ba46528c5dd44226a6fd0ad0201b1c2982789.tar.gz
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 <pavel@zhukoff.net> Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/tests/fetch.py')
-rw-r--r--bitbake/lib/bb/tests/fetch.py75
1 files changed, 69 insertions, 6 deletions
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):
3042 self.d.setVar("BB_FETCH_PREMIRRORONLY", "1") 3042 self.d.setVar("BB_FETCH_PREMIRRORONLY", "1")
3043 self.d.setVar("BB_NO_NETWORK", "1") 3043 self.d.setVar("BB_NO_NETWORK", "1")
3044 self.d.setVar("PREMIRRORS", self.recipe_url + " " + "file://{}".format(self.mirrordir) + " \n") 3044 self.d.setVar("PREMIRRORS", self.recipe_url + " " + "file://{}".format(self.mirrordir) + " \n")
3045 self.mirrorname = "git2_git.fake.repo.bitbake.tar.gz"
3046 self.mirrorfile = os.path.join(self.mirrordir, self.mirrorname)
3047 self.testfilename = "bitbake-fetch.test"
3045 3048
3046 def make_git_repo(self): 3049 def make_git_repo(self):
3047 self.mirrorname = "git2_git.fake.repo.bitbake.tar.gz"
3048 recipeurl = "git:/git.fake.repo/bitbake" 3050 recipeurl = "git:/git.fake.repo/bitbake"
3049 os.makedirs(self.gitdir) 3051 os.makedirs(self.gitdir)
3050 self.git_init(cwd=self.gitdir) 3052 self.git_init(cwd=self.gitdir)
@@ -3054,15 +3056,23 @@ class FetchPremirroronlyLocalTest(FetcherTest):
3054 3056
3055 def git_new_commit(self): 3057 def git_new_commit(self):
3056 import random 3058 import random
3057 testfilename = "bibake-fetch.test"
3058 os.unlink(os.path.join(self.mirrordir, self.mirrorname)) 3059 os.unlink(os.path.join(self.mirrordir, self.mirrorname))
3059 with open(os.path.join(self.gitdir, testfilename), "w") as testfile: 3060 branch = self.git("branch --show-current", self.gitdir).split()
3060 testfile.write("Useless random data {}".format(random.random())) 3061 with open(os.path.join(self.gitdir, self.testfilename), "w") as testfile:
3061 self.git("add {}".format(testfilename), self.gitdir) 3062 testfile.write("File {} from branch {}; Useless random data {}".format(self.testfilename, branch, random.random()))
3062 self.git("commit -a -m \"This random commit {}. I'm useless.\"".format(random.random()), self.gitdir) 3063 self.git("add {}".format(self.testfilename), self.gitdir)
3064 self.git("commit -a -m \"This random commit {} in branch {}. I'm useless.\"".format(random.random(), branch), self.gitdir)
3063 bb.process.run('tar -czvf {} .'.format(os.path.join(self.mirrordir, self.mirrorname)), cwd = self.gitdir) 3065 bb.process.run('tar -czvf {} .'.format(os.path.join(self.mirrordir, self.mirrorname)), cwd = self.gitdir)
3064 return self.git("rev-parse HEAD", self.gitdir).strip() 3066 return self.git("rev-parse HEAD", self.gitdir).strip()
3065 3067
3068 def git_new_branch(self, name):
3069 self.git_new_commit()
3070 head = self.git("rev-parse HEAD", self.gitdir).strip()
3071 self.git("checkout -b {}".format(name), self.gitdir)
3072 newrev = self.git_new_commit()
3073 self.git("checkout {}".format(head), self.gitdir)
3074 return newrev
3075
3066 def test_mirror_commit_nonexistent(self): 3076 def test_mirror_commit_nonexistent(self):
3067 self.make_git_repo() 3077 self.make_git_repo()
3068 self.d.setVar("SRCREV", "0"*40) 3078 self.d.setVar("SRCREV", "0"*40)
@@ -3083,6 +3093,59 @@ class FetchPremirroronlyLocalTest(FetcherTest):
3083 with self.assertRaises(bb.fetch2.NetworkAccess): 3093 with self.assertRaises(bb.fetch2.NetworkAccess):
3084 fetcher.download() 3094 fetcher.download()
3085 3095
3096 def test_mirror_tarball_multiple_branches(self):
3097 """
3098 test if PREMIRRORS can handle multiple name/branches correctly
3099 both branches have required revisions
3100 """
3101 self.make_git_repo()
3102 branch1rev = self.git_new_branch("testbranch1")
3103 branch2rev = self.git_new_branch("testbranch2")
3104 self.recipe_url = "git://git.fake.repo/bitbake;branch=testbranch1,testbranch2;protocol=https;name=branch1,branch2"
3105 self.d.setVar("SRCREV_branch1", branch1rev)
3106 self.d.setVar("SRCREV_branch2", branch2rev)
3107 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
3108 self.assertTrue(os.path.exists(self.mirrorfile), "Mirror file doesn't exist")
3109 fetcher.download()
3110 fetcher.unpack(os.path.join(self.tempdir, "unpacked"))
3111 unpacked = os.path.join(self.tempdir, "unpacked", "git", self.testfilename)
3112 self.assertTrue(os.path.exists(unpacked), "Repo has not been unpackaged properly!")
3113 with open(unpacked, 'r') as f:
3114 content = f.read()
3115 ## We expect to see testbranch1 in the file, not master, not testbranch2
3116 self.assertTrue(content.find("testbranch1") != -1, "Wrong branch has been checked out!")
3117
3118 def test_mirror_tarball_multiple_branches_nobranch(self):
3119 """
3120 test if PREMIRRORS can handle multiple name/branches correctly
3121 Unbalanced name/branches raises ParameterError
3122 """
3123 self.make_git_repo()
3124 branch1rev = self.git_new_branch("testbranch1")
3125 branch2rev = self.git_new_branch("testbranch2")
3126 self.recipe_url = "git://git.fake.repo/bitbake;branch=testbranch1;protocol=https;name=branch1,branch2"
3127 self.d.setVar("SRCREV_branch1", branch1rev)
3128 self.d.setVar("SRCREV_branch2", branch2rev)
3129 with self.assertRaises(bb.fetch2.ParameterError):
3130 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
3131
3132 def test_mirror_tarball_multiple_branches_norev(self):
3133 """
3134 test if PREMIRRORS can handle multiple name/branches correctly
3135 one of the branches specifies non existing SRCREV
3136 """
3137 self.make_git_repo()
3138 branch1rev = self.git_new_branch("testbranch1")
3139 branch2rev = self.git_new_branch("testbranch2")
3140 self.recipe_url = "git://git.fake.repo/bitbake;branch=testbranch1,testbranch2;protocol=https;name=branch1,branch2"
3141 self.d.setVar("SRCREV_branch1", branch1rev)
3142 self.d.setVar("SRCREV_branch2", "0"*40)
3143 fetcher = bb.fetch.Fetch([self.recipe_url], self.d)
3144 self.assertTrue(os.path.exists(self.mirrorfile), "Mirror file doesn't exist")
3145 with self.assertRaises(bb.fetch2.NetworkAccess):
3146 fetcher.download()
3147
3148
3086class FetchPremirroronlyNetworkTest(FetcherTest): 3149class FetchPremirroronlyNetworkTest(FetcherTest):
3087 3150
3088 def setUp(self): 3151 def setUp(self):