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

47 lines
1.8 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
# subprocess does not kill the child daemon when a test case fails by raising
# an exception. So use pexpect instead.
import infra
import pexpect
GIT_REMOTE_PORT_INITIAL = 9418
GIT_REMOTE_PORT_LAST = GIT_REMOTE_PORT_INITIAL + 99
class GitRemote(object):
def __init__(self, builddir, serveddir, logtofile):
"""
Start a local git server.
In order to support test cases in parallel, select the port the
server will listen to in runtime. Since there is no reliable way
to allocate the port prior to starting the server (another
process in the host machine can use the port between it is
selected from a list and it is really allocated to the server)
try to start the server in a port and in the case it is already
in use, try the next one in the allowed range.
"""
self.daemon = None
self.port = None
self.logfile = infra.open_log_file(builddir, "gitremote", logtofile)
daemon_cmd = ["git", "daemon", "--reuseaddr", "--verbose",
"--listen=localhost", "--export-all",
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
"--base-path={}".format(serveddir)]
for port in range(GIT_REMOTE_PORT_INITIAL, GIT_REMOTE_PORT_LAST + 1):
cmd = daemon_cmd + ["--port={port}".format(port=port)]
self.logfile.write("> starting git remote with '{}'\n".format(" ".join(cmd)))
self.daemon = pexpect.spawn(cmd[0], cmd[1:], logfile=self.logfile)
ret = self.daemon.expect(["Ready to rumble",
"Address already in use"])
if ret == 0:
self.port = port
return
raise SystemError("Could not find a free port to run git remote")
def stop(self):
if self.daemon is None:
return
self.daemon.terminate(force=True)