kumquat-buildroot/support/testing/tests/download/test_git.py

82 lines
2.9 KiB
Python
Raw Normal View History

testing/tests/download: add git hash test Add one test case to ensure the hash is checked for git packages: - correct hash; - wrong hash; - no hash file. Add required infra: - a GitRemote class, that can start a git server in the host machine to emulate a remote git server under the control of the test; - a new base class, called GitTestBase, that inherits from BRTest and must be subclassed by all git test cases. Its setUp() method takes care of configuring the build with a br2-external, avoiding to hit http://sources.buildroot.net by using an empty BR2_BACKUP_SITE. It also avoids downloading not pre-installed dependencies (i.e. lzip) every time by calling 'make dependencies' using the common dl directory, and it instantiates the GitRemote object. Besides the Python scripts, add some fixtures used during the tests: - a br2-external (git-hash) with one package for each part of the test case; - a static git bare repo (repo.git) to be served using GitRemote class. Neither the br2-external nor the check hash functionalities are the subject of these tests per se, so for simplicity limit the check to the error codes and don't look for the messages in the log. Thanks to Arnout for the hint about how to add a bare repo to test. Signed-off-by: Ricardo Martincoski <ricardo.martincoski@datacom.ind.br> Cc: Arnout Vandecappelle <arnout@mind.be> Tested-by: Matthew Weber <matthew.weber@rockwellcollins.com> [Arnout: split long line; reorder imports to satisfy flake8] Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
2018-05-12 04:58:27 +02:00
import os
import shutil
testing/tests/download: add git hash test Add one test case to ensure the hash is checked for git packages: - correct hash; - wrong hash; - no hash file. Add required infra: - a GitRemote class, that can start a git server in the host machine to emulate a remote git server under the control of the test; - a new base class, called GitTestBase, that inherits from BRTest and must be subclassed by all git test cases. Its setUp() method takes care of configuring the build with a br2-external, avoiding to hit http://sources.buildroot.net by using an empty BR2_BACKUP_SITE. It also avoids downloading not pre-installed dependencies (i.e. lzip) every time by calling 'make dependencies' using the common dl directory, and it instantiates the GitRemote object. Besides the Python scripts, add some fixtures used during the tests: - a br2-external (git-hash) with one package for each part of the test case; - a static git bare repo (repo.git) to be served using GitRemote class. Neither the br2-external nor the check hash functionalities are the subject of these tests per se, so for simplicity limit the check to the error codes and don't look for the messages in the log. Thanks to Arnout for the hint about how to add a bare repo to test. Signed-off-by: Ricardo Martincoski <ricardo.martincoski@datacom.ind.br> Cc: Arnout Vandecappelle <arnout@mind.be> Tested-by: Matthew Weber <matthew.weber@rockwellcollins.com> [Arnout: split long line; reorder imports to satisfy flake8] Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
2018-05-12 04:58:27 +02:00
support/testing: switch to Python 3 only Python 2.7 will not be maintained past 2020. Many scripts on the tree are used during the build and should keep Python 2 compatibility for a while. This is not the case for the runtime test infra. It's meant to be run in modern distros only, so it can safely switch to support Python 3 only. An advantage of this approach is to have less scenarios to test in. Otherwise every change to the test infra or runtime tests would need to be tested against both versions of the interpreter, increasing the effort of the developers, to ensure the compatibility to Python 2 was not broken. In order to accomplish the change to Python 3: - change the shebang for run-tests; - use Python 3 urllib as a drop-in replacement for Python 2 urllib2; - when writing the downloaded binary files, explicitly open the output file as binary; - when subprocess is used to retrieve the text output from commands, explicitly ask for text output. For this, use 'universal_newlines' because 'text' was added only on Python 3.7; - when pexpect is used to retrieve the text output from qemu or git, explicitly ask for text output using 'encoding'; - the code using csv currently follows the example in the documentation for the Python 2 module, change it to follow the example in the documentation for the Python 3 module; - fix the relative import for test_git.py to be Python 3 compliant. Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com> Cc: Arnout Vandecappelle <arnout@mind.be> Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com> Cc: Yann E. MORIN <yann.morin.1998@free.fr> Tested-by: Romain Naour <romain.naour@smile.fr> Tested-by: Nicolas Carrier <nicolas.carrier@orolia.com> Signed-off-by: Nicolas Carrier <nicolas.carrier@orolia.com> Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
2019-10-27 14:37:00 +01:00
from tests.download.gitremote import GitRemote
testing/tests/download: add git hash test Add one test case to ensure the hash is checked for git packages: - correct hash; - wrong hash; - no hash file. Add required infra: - a GitRemote class, that can start a git server in the host machine to emulate a remote git server under the control of the test; - a new base class, called GitTestBase, that inherits from BRTest and must be subclassed by all git test cases. Its setUp() method takes care of configuring the build with a br2-external, avoiding to hit http://sources.buildroot.net by using an empty BR2_BACKUP_SITE. It also avoids downloading not pre-installed dependencies (i.e. lzip) every time by calling 'make dependencies' using the common dl directory, and it instantiates the GitRemote object. Besides the Python scripts, add some fixtures used during the tests: - a br2-external (git-hash) with one package for each part of the test case; - a static git bare repo (repo.git) to be served using GitRemote class. Neither the br2-external nor the check hash functionalities are the subject of these tests per se, so for simplicity limit the check to the error codes and don't look for the messages in the log. Thanks to Arnout for the hint about how to add a bare repo to test. Signed-off-by: Ricardo Martincoski <ricardo.martincoski@datacom.ind.br> Cc: Arnout Vandecappelle <arnout@mind.be> Tested-by: Matthew Weber <matthew.weber@rockwellcollins.com> [Arnout: split long line; reorder imports to satisfy flake8] Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
2018-05-12 04:58:27 +02:00
import infra
class GitTestBase(infra.basetest.BRConfigTest):
testing/tests/download: add git hash test Add one test case to ensure the hash is checked for git packages: - correct hash; - wrong hash; - no hash file. Add required infra: - a GitRemote class, that can start a git server in the host machine to emulate a remote git server under the control of the test; - a new base class, called GitTestBase, that inherits from BRTest and must be subclassed by all git test cases. Its setUp() method takes care of configuring the build with a br2-external, avoiding to hit http://sources.buildroot.net by using an empty BR2_BACKUP_SITE. It also avoids downloading not pre-installed dependencies (i.e. lzip) every time by calling 'make dependencies' using the common dl directory, and it instantiates the GitRemote object. Besides the Python scripts, add some fixtures used during the tests: - a br2-external (git-hash) with one package for each part of the test case; - a static git bare repo (repo.git) to be served using GitRemote class. Neither the br2-external nor the check hash functionalities are the subject of these tests per se, so for simplicity limit the check to the error codes and don't look for the messages in the log. Thanks to Arnout for the hint about how to add a bare repo to test. Signed-off-by: Ricardo Martincoski <ricardo.martincoski@datacom.ind.br> Cc: Arnout Vandecappelle <arnout@mind.be> Tested-by: Matthew Weber <matthew.weber@rockwellcollins.com> [Arnout: split long line; reorder imports to satisfy flake8] Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
2018-05-12 04:58:27 +02:00
config = \
"""
BR2_BACKUP_SITE=""
"""
gitremotedir = infra.filepath("tests/download/git-remote")
gitremote = None
def setUp(self):
super(GitTestBase, self).setUp()
self.gitremote = GitRemote(self.builddir, self.gitremotedir, self.logtofile)
def tearDown(self):
self.show_msg("Cleaning up")
if self.gitremote:
self.gitremote.stop()
if self.b and not self.keepbuilds:
self.b.delete()
def check_hash(self, package):
# store downloaded tarball inside the output dir so the test infra
# cleans it up at the end
env = {"BR2_DL_DIR": os.path.join(self.builddir, "dl"),
"GITREMOTE_PORT_NUMBER": str(self.gitremote.port)}
self.b.build(["{}-dirclean".format(package),
"{}-source".format(package)],
env)
def check_download(self, package):
# store downloaded tarball inside the output dir so the test infra
# cleans it up at the end
dl_dir = os.path.join(self.builddir, "dl")
# enforce we test the download
if os.path.exists(dl_dir):
shutil.rmtree(dl_dir)
env = {"BR2_DL_DIR": dl_dir,
"GITREMOTE_PORT_NUMBER": str(self.gitremote.port)}
self.b.build(["{}-dirclean".format(package),
"{}-legal-info".format(package)],
env)
testing/tests/download: add git hash test Add one test case to ensure the hash is checked for git packages: - correct hash; - wrong hash; - no hash file. Add required infra: - a GitRemote class, that can start a git server in the host machine to emulate a remote git server under the control of the test; - a new base class, called GitTestBase, that inherits from BRTest and must be subclassed by all git test cases. Its setUp() method takes care of configuring the build with a br2-external, avoiding to hit http://sources.buildroot.net by using an empty BR2_BACKUP_SITE. It also avoids downloading not pre-installed dependencies (i.e. lzip) every time by calling 'make dependencies' using the common dl directory, and it instantiates the GitRemote object. Besides the Python scripts, add some fixtures used during the tests: - a br2-external (git-hash) with one package for each part of the test case; - a static git bare repo (repo.git) to be served using GitRemote class. Neither the br2-external nor the check hash functionalities are the subject of these tests per se, so for simplicity limit the check to the error codes and don't look for the messages in the log. Thanks to Arnout for the hint about how to add a bare repo to test. Signed-off-by: Ricardo Martincoski <ricardo.martincoski@datacom.ind.br> Cc: Arnout Vandecappelle <arnout@mind.be> Tested-by: Matthew Weber <matthew.weber@rockwellcollins.com> [Arnout: split long line; reorder imports to satisfy flake8] Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
2018-05-12 04:58:27 +02:00
class TestGitHash(GitTestBase):
br2_external = [infra.filepath("tests/download/br2-external/git-hash")]
def test_run(self):
with self.assertRaises(SystemError):
self.check_hash("bad")
self.check_hash("good")
self.check_hash("nohash")
class TestGitRefs(GitTestBase):
br2_external = [infra.filepath("tests/download/br2-external/git-refs")]
def test_run(self):
with self.assertRaises(SystemError):
self.check_download("git-wrong-content")
with self.assertRaises(SystemError):
self.check_download("git-wrong-sha1")
self.check_download("git-partial-sha1-branch-head")
self.check_download("git-partial-sha1-reachable-by-branch")
self.check_download("git-partial-sha1-reachable-by-tag")
self.check_download("git-partial-sha1-tag-itself")
self.check_download("git-partial-sha1-tag-points-to")
self.check_download("git-sha1-branch-head")
self.check_download("git-sha1-reachable-by-branch")
self.check_download("git-sha1-reachable-by-tag")
self.check_download("git-sha1-tag-itself")
self.check_download("git-sha1-tag-points-to")
self.check_download("git-submodule-disabled")
self.check_download("git-submodule-enabled")
self.check_download("git-tag")