pmtest: allow tests to specify test binary
Adds a cmd property to tests (defaults to pacman) which is resolved using directories specified with --bindir (defaults to PATH). The ability to manually specify a particular binary is preserved in order to allow running individual tests with differently named binaries such as lt-pacman. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
parent
01beca5df7
commit
42c859e4cc
@ -45,7 +45,8 @@ PY_LOG_COMPILER = $(PYTHON) $(top_srcdir)/test/pacman/pactest.py
|
|||||||
AM_PY_LOG_FLAGS = \
|
AM_PY_LOG_FLAGS = \
|
||||||
--scriptlet-shell $(SCRIPTLET_SHELL) \
|
--scriptlet-shell $(SCRIPTLET_SHELL) \
|
||||||
--ldconfig $(LDCONFIG) \
|
--ldconfig $(LDCONFIG) \
|
||||||
-p $(top_builddir)/src/pacman/pacman
|
--bindir $(top_builddir)/src/pacman \
|
||||||
|
--bindir $(top_builddir)/scripts
|
||||||
|
|
||||||
# create the pacman DB and cache directories upon install
|
# create the pacman DB and cache directories upon install
|
||||||
install-data-local:
|
install-data-local:
|
||||||
|
@ -31,9 +31,6 @@
|
|||||||
__author__ = "Aurelien FORET"
|
__author__ = "Aurelien FORET"
|
||||||
__version__ = "0.4"
|
__version__ = "0.4"
|
||||||
|
|
||||||
def resolve_binary_path(option, opt_str, value, parser):
|
|
||||||
setattr(parser.values, option.dest, os.path.abspath(value))
|
|
||||||
|
|
||||||
def create_parser():
|
def create_parser():
|
||||||
usage = "usage: %prog [options] <path/to/testfile.py>..."
|
usage = "usage: %prog [options] <path/to/testfile.py>..."
|
||||||
description = "Runs automated tests on the pacman binary. Tests are " \
|
description = "Runs automated tests on the pacman binary. Tests are " \
|
||||||
@ -47,10 +44,12 @@ def create_parser():
|
|||||||
parser.add_option("-d", "--debug", type = "int",
|
parser.add_option("-d", "--debug", type = "int",
|
||||||
dest = "debug", default = 0,
|
dest = "debug", default = 0,
|
||||||
help = "set debug level for pacman")
|
help = "set debug level for pacman")
|
||||||
parser.add_option("-p", "--pacman", action = "callback",
|
parser.add_option("-p", "--pacman", type = "string",
|
||||||
callback = resolve_binary_path, type = "string",
|
dest = "bin", default = None,
|
||||||
dest = "bin", default = util.which("pacman"),
|
|
||||||
help = "specify location of the pacman binary")
|
help = "specify location of the pacman binary")
|
||||||
|
parser.add_option("--bindir", type = "string",
|
||||||
|
dest = "bindir", action = "append",
|
||||||
|
help = "specify location of binaries")
|
||||||
parser.add_option("--keep-root", action = "store_true",
|
parser.add_option("--keep-root", action = "store_true",
|
||||||
dest = "keeproot", default = False,
|
dest = "keeproot", default = False,
|
||||||
help = "don't remove the generated pacman root filesystem")
|
help = "don't remove the generated pacman root filesystem")
|
||||||
@ -86,10 +85,6 @@ def create_parser():
|
|||||||
opt_parser = create_parser()
|
opt_parser = create_parser()
|
||||||
(opts, args) = opt_parser.parse_args()
|
(opts, args) = opt_parser.parse_args()
|
||||||
|
|
||||||
if opts.bin is None or not os.access(opts.bin, os.X_OK):
|
|
||||||
tap.bail("cannot locate pacman binary")
|
|
||||||
sys.exit(2)
|
|
||||||
|
|
||||||
if args is None or len(args) == 0:
|
if args is None or len(args) == 0:
|
||||||
tap.bail("no tests defined, nothing to do")
|
tap.bail("no tests defined, nothing to do")
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
@ -102,6 +97,7 @@ def create_parser():
|
|||||||
util.verbose = opts.verbose
|
util.verbose = opts.verbose
|
||||||
env.pacman["debug"] = opts.debug
|
env.pacman["debug"] = opts.debug
|
||||||
env.pacman["bin"] = opts.bin
|
env.pacman["bin"] = opts.bin
|
||||||
|
env.pacman["bindir"] = opts.bindir
|
||||||
env.pacman["nolog"] = opts.nolog
|
env.pacman["nolog"] = opts.nolog
|
||||||
env.pacman["gdb"] = opts.gdb
|
env.pacman["gdb"] = opts.gdb
|
||||||
env.pacman["valgrind"] = opts.valgrind
|
env.pacman["valgrind"] = opts.valgrind
|
||||||
|
@ -34,7 +34,8 @@ class pmenv(object):
|
|||||||
def __init__(self, root = "root"):
|
def __init__(self, root = "root"):
|
||||||
self.root = os.path.abspath(root)
|
self.root = os.path.abspath(root)
|
||||||
self.pacman = {
|
self.pacman = {
|
||||||
"bin": "pacman",
|
"bin": None,
|
||||||
|
"bindir": ["/usr/bin/"],
|
||||||
"debug": 0,
|
"debug": 0,
|
||||||
"gdb": 0,
|
"gdb": 0,
|
||||||
"valgrind": 0,
|
"valgrind": 0,
|
||||||
|
@ -39,6 +39,11 @@ def __init__(self, name, root):
|
|||||||
self.root = root
|
self.root = root
|
||||||
self.dbver = 9
|
self.dbver = 9
|
||||||
self.cachepkgs = True
|
self.cachepkgs = True
|
||||||
|
self.cmd = ["pacman", "--noconfirm",
|
||||||
|
"--config", os.path.join(self.root, util.PACCONF),
|
||||||
|
"--root", self.root,
|
||||||
|
"--dbpath", os.path.join(self.root, util.PM_DBPATH),
|
||||||
|
"--cachedir", os.path.join(self.root, util.PM_CACHEDIR)]
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "name = %s\n" \
|
return "name = %s\n" \
|
||||||
@ -234,16 +239,24 @@ def run(self, pacman):
|
|||||||
"--log-file=%s" % os.path.join(self.root, "var/log/valgrind"),
|
"--log-file=%s" % os.path.join(self.root, "var/log/valgrind"),
|
||||||
"--suppressions=%s" % suppfile])
|
"--suppressions=%s" % suppfile])
|
||||||
self.addrule("FILE_EMPTY=var/log/valgrind")
|
self.addrule("FILE_EMPTY=var/log/valgrind")
|
||||||
cmd.extend([pacman["bin"], "--noconfirm",
|
|
||||||
"--config", os.path.join(self.root, util.PACCONF),
|
# replace program name with absolute path
|
||||||
"--root", self.root,
|
prog = pacman["bin"]
|
||||||
"--dbpath", os.path.join(self.root, util.PM_DBPATH),
|
if not prog:
|
||||||
"--cachedir", os.path.join(self.root, util.PM_CACHEDIR)])
|
prog = util.which(self.cmd[0], pacman["bindir"])
|
||||||
|
if not prog or not os.access(prog, os.X_OK):
|
||||||
|
if not prog:
|
||||||
|
tap.bail("could not locate '%s' binary" % (self.cmd[0]))
|
||||||
|
return
|
||||||
|
|
||||||
|
cmd.append(os.path.abspath(prog))
|
||||||
|
cmd.extend(self.cmd[1:])
|
||||||
if pacman["manual-confirm"]:
|
if pacman["manual-confirm"]:
|
||||||
cmd.append("--confirm")
|
cmd.append("--confirm")
|
||||||
if pacman["debug"]:
|
if pacman["debug"]:
|
||||||
cmd.append("--debug=%s" % pacman["debug"])
|
cmd.append("--debug=%s" % pacman["debug"])
|
||||||
cmd.extend(shlex.split(self.args))
|
cmd.extend(shlex.split(self.args))
|
||||||
|
|
||||||
if not (pacman["gdb"] or pacman["nolog"]):
|
if not (pacman["gdb"] or pacman["nolog"]):
|
||||||
output = open(os.path.join(self.root, util.LOGFILE), 'w')
|
output = open(os.path.join(self.root, util.LOGFILE), 'w')
|
||||||
else:
|
else:
|
||||||
|
@ -157,8 +157,9 @@ def mkmd5sum(data):
|
|||||||
# Miscellaneous
|
# Miscellaneous
|
||||||
#
|
#
|
||||||
|
|
||||||
def which(filename):
|
def which(filename, path=None):
|
||||||
path = os.environ["PATH"].split(':')
|
if not path:
|
||||||
|
path = os.environ["PATH"].split(os.pathsep)
|
||||||
for p in path:
|
for p in path:
|
||||||
f = os.path.join(p, filename)
|
f = os.path.join(p, filename)
|
||||||
if os.access(f, os.F_OK):
|
if os.access(f, os.F_OK):
|
||||||
|
Loading…
Reference in New Issue
Block a user