[pacman-dev] [PATCH 1/6] pmdb: include directories in package file lists
Needed for checking directories with PKG_FILES. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- test/pacman/pmdb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/pacman/pmdb.py b/test/pacman/pmdb.py index 60e0e9c..aa14dff 100644 --- a/test/pacman/pmdb.py +++ b/test/pacman/pmdb.py @@ -172,7 +172,7 @@ def db_read(self, name): if line == "%FILES%": while line: line = fd.readline().strip("\n") - if line and line[-1] != "/": + if line: pkg.files.append(line) if line == "%BACKUP%": pkg.backup = _getsection(fd) -- 2.1.2
This prevents an exception in the event backup entries are not in the correct format and brings the test in line with alpm's backup parsing which splits on the last tab rather than the first. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- test/pacman/pmrule.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/test/pacman/pmrule.py b/test/pacman/pmrule.py index 0eec8ea..c2336c5 100644 --- a/test/pacman/pmrule.py +++ b/test/pacman/pmrule.py @@ -103,13 +103,11 @@ def check(self, test): if not value in newpkg.files: success = 0 elif case == "BACKUP": - found = 0 + success = 0 for f in newpkg.backup: - name, md5sum = f.split("\t") - if value == name: - found = 1 - if not found: - success = 0 + if f.startswith(value + "\t"): + success = 1 + break; else: tap.diag("PKG rule '%s' not found" % case) success = -1 -- 2.1.2
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- test/pacman/pmtest.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/pacman/pmtest.py b/test/pacman/pmtest.py index 09baac7..7ed30eb 100644 --- a/test/pacman/pmtest.py +++ b/test/pacman/pmtest.py @@ -37,6 +37,7 @@ def __init__(self, name, root): self.name = name self.testname = os.path.basename(name).replace('.py', '') self.root = root + self.dbver = 9 self.cachepkgs = True def __str__(self): @@ -180,9 +181,9 @@ def generate(self, pacman): for pkg in self.db["local"].pkgs: vprint("\tinstalling %s" % pkg.fullname()) pkg.install_package(self.root) - if self.db["local"].pkgs: + if self.db["local"].pkgs and self.dbver >= 9: path = os.path.join(self.root, util.PM_DBPATH, "local") - util.mkfile(path, "ALPM_DB_VERSION", "9") + util.mkfile(path, "ALPM_DB_VERSION", str(self.dbver)) # Done. vprint(" Taking a snapshot of the file system") -- 2.1.2
--confirm cancels the effect of a previous --noconfirm. This makes it easier for scripts to default to --noconfirm but allow users to override it. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- doc/pacman.8.txt | 3 +++ src/pacman/conf.h | 1 + src/pacman/pacman.c | 5 +++++ test/pacman/pmtest.py | 6 +++--- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/doc/pacman.8.txt b/doc/pacman.8.txt index 45741b4..4041a06 100644 --- a/doc/pacman.8.txt +++ b/doc/pacman.8.txt @@ -177,6 +177,9 @@ Options Bypass any and all ``Are you sure?'' messages. It's not a good idea to do this unless you want to run pacman from a script. +*\--confirm*:: + Cancels the effects of a previous '\--noconfirm'. + Transaction Options (apply to '-S', '-R' and '-U') -------------------------------------------------- diff --git a/src/pacman/conf.h b/src/pacman/conf.h index 8aed6d6..3141e2c 100644 --- a/src/pacman/conf.h +++ b/src/pacman/conf.h @@ -131,6 +131,7 @@ enum { enum { OP_LONG_FLAG_MIN = 1000, OP_NOCONFIRM, + OP_CONFIRM, OP_CONFIG, OP_IGNORE, OP_DEBUG, diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 5cac37c..3d1406b 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -205,6 +205,7 @@ static void usage(int op, const char * const myname) addlist(_(" --gpgdir <path> set an alternate home directory for GnuPG\n")); addlist(_(" --logfile <path> set an alternate log file\n")); addlist(_(" --noconfirm do not ask for any confirmation\n")); + addlist(_(" --confirm always ask for confirmation\n")); } list = alpm_list_msort(list, alpm_list_count(list), options_cmp); for(i = list; i; i = alpm_list_next(i)) { @@ -456,6 +457,9 @@ static int parsearg_global(int opt) case OP_NOCONFIRM: config->noconfirm = 1; break; + case OP_CONFIRM: + config->noconfirm = 0; + break; case OP_DBPATH: case 'b': free(config->dbpath); @@ -858,6 +862,7 @@ static int parseargs(int argc, char *argv[]) {"downloadonly", no_argument, 0, OP_DOWNLOADONLY}, {"refresh", no_argument, 0, OP_REFRESH}, {"noconfirm", no_argument, 0, OP_NOCONFIRM}, + {"confirm", no_argument, 0, OP_CONFIRM}, {"config", required_argument, 0, OP_CONFIG}, {"ignore", required_argument, 0, OP_IGNORE}, {"assume-installed", required_argument, 0, OP_ASSUMEINSTALLED}, diff --git a/test/pacman/pmtest.py b/test/pacman/pmtest.py index 7ed30eb..3682963 100644 --- a/test/pacman/pmtest.py +++ b/test/pacman/pmtest.py @@ -234,13 +234,13 @@ def run(self, pacman): "--log-file=%s" % os.path.join(self.root, "var/log/valgrind"), "--suppressions=%s" % suppfile]) self.addrule("FILE_EMPTY=var/log/valgrind") - cmd.extend([pacman["bin"], + cmd.extend([pacman["bin"], "--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)]) - if not pacman["manual-confirm"]: - cmd.append("--noconfirm") + if pacman["manual-confirm"]: + cmd.append("--confirm") if pacman["debug"]: cmd.append("--debug=%s" % pacman["debug"]) cmd.extend(shlex.split(self.args)) -- 2.1.2
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> --- Makefile.am | 3 ++- test/pacman/pactest.py | 16 ++++++---------- test/pacman/pmenv.py | 3 ++- test/pacman/pmtest.py | 23 ++++++++++++++++++----- test/pacman/util.py | 5 +++-- 5 files changed, 31 insertions(+), 19 deletions(-) diff --git a/Makefile.am b/Makefile.am index 4c6f656..44a2341 100644 --- a/Makefile.am +++ b/Makefile.am @@ -45,7 +45,8 @@ PY_LOG_COMPILER = $(PYTHON) $(top_srcdir)/test/pacman/pactest.py AM_PY_LOG_FLAGS = \ --scriptlet-shell $(SCRIPTLET_SHELL) \ --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 install-data-local: diff --git a/test/pacman/pactest.py b/test/pacman/pactest.py index 58c14f6..8e87c28 100755 --- a/test/pacman/pactest.py +++ b/test/pacman/pactest.py @@ -31,9 +31,6 @@ __author__ = "Aurelien FORET" __version__ = "0.4" -def resolve_binary_path(option, opt_str, value, parser): - setattr(parser.values, option.dest, os.path.abspath(value)) - def create_parser(): usage = "usage: %prog [options] <path/to/testfile.py>..." description = "Runs automated tests on the pacman binary. Tests are " \ @@ -47,10 +44,12 @@ def create_parser(): parser.add_option("-d", "--debug", type = "int", dest = "debug", default = 0, help = "set debug level for pacman") - parser.add_option("-p", "--pacman", action = "callback", - callback = resolve_binary_path, type = "string", - dest = "bin", default = util.which("pacman"), + parser.add_option("-p", "--pacman", type = "string", + dest = "bin", default = None, 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", dest = "keeproot", default = False, help = "don't remove the generated pacman root filesystem") @@ -86,10 +85,6 @@ def create_parser(): opt_parser = create_parser() (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: tap.bail("no tests defined, nothing to do") sys.exit(2) @@ -102,6 +97,7 @@ def create_parser(): util.verbose = opts.verbose env.pacman["debug"] = opts.debug env.pacman["bin"] = opts.bin + env.pacman["bindir"] = opts.bindir env.pacman["nolog"] = opts.nolog env.pacman["gdb"] = opts.gdb env.pacman["valgrind"] = opts.valgrind diff --git a/test/pacman/pmenv.py b/test/pacman/pmenv.py index 2d887b0..27f44c9 100644 --- a/test/pacman/pmenv.py +++ b/test/pacman/pmenv.py @@ -34,7 +34,8 @@ class pmenv(object): def __init__(self, root = "root"): self.root = os.path.abspath(root) self.pacman = { - "bin": "pacman", + "bin": None, + "bindir": ["/usr/bin/"], "debug": 0, "gdb": 0, "valgrind": 0, diff --git a/test/pacman/pmtest.py b/test/pacman/pmtest.py index 3682963..5a79919 100644 --- a/test/pacman/pmtest.py +++ b/test/pacman/pmtest.py @@ -39,6 +39,11 @@ def __init__(self, name, root): self.root = root self.dbver = 9 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): return "name = %s\n" \ @@ -234,16 +239,24 @@ def run(self, pacman): "--log-file=%s" % os.path.join(self.root, "var/log/valgrind"), "--suppressions=%s" % suppfile]) self.addrule("FILE_EMPTY=var/log/valgrind") - cmd.extend([pacman["bin"], "--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)]) + + # replace program name with absolute path + prog = pacman["bin"] + if not prog: + 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"]: cmd.append("--confirm") if pacman["debug"]: cmd.append("--debug=%s" % pacman["debug"]) cmd.extend(shlex.split(self.args)) + if not (pacman["gdb"] or pacman["nolog"]): output = open(os.path.join(self.root, util.LOGFILE), 'w') else: diff --git a/test/pacman/util.py b/test/pacman/util.py index 57471fe..ae96a3b 100644 --- a/test/pacman/util.py +++ b/test/pacman/util.py @@ -157,8 +157,9 @@ def mkmd5sum(data): # Miscellaneous # -def which(filename): - path = os.environ["PATH"].split(':') +def which(filename, path=None): + if not path: + path = os.environ["PATH"].split(os.pathsep) for p in path: f = os.path.join(p, filename) if os.access(f, os.F_OK): -- 2.1.2
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- Makefile.am | 1 + test/scripts/pacman-db-upgrade-v9.py | 21 +++++++++++++++++++++ valgrind.supp | 7 +++++++ 3 files changed, 29 insertions(+) create mode 100644 test/scripts/pacman-db-upgrade-v9.py diff --git a/Makefile.am b/Makefile.am index 44a2341..e9b3dfa 100644 --- a/Makefile.am +++ b/Makefile.am @@ -28,6 +28,7 @@ $(top_srcdir)/test/pacman/tests/TESTS: $(wildcard test/pacman/tests/*.py*) TESTS = test/scripts/parseopts_test.sh \ test/scripts/human_to_size_test.sh \ + test/scripts/pacman-db-upgrade-v9.py \ test/util/pacsorttest.sh \ test/util/vercmptest.sh include $(top_srcdir)/test/pacman/tests/TESTS diff --git a/test/scripts/pacman-db-upgrade-v9.py b/test/scripts/pacman-db-upgrade-v9.py new file mode 100644 index 0000000..dc6f97d --- /dev/null +++ b/test/scripts/pacman-db-upgrade-v9.py @@ -0,0 +1,21 @@ +self.description = "pacman-db-upgrade DB version 9 (symlink support removal)" + +self.filesystem = [ "mnt_real/subdir/", "mnt -> mnt_real/subdir/", "bar -> ./" ] + +fpkg = pmpkg("filesystem") +fpkg.files = ["mnt_real/", "mnt/", "mnt/foo", "bar/", "bar/baz"] +fpkg.backup = ["mnt/foo"] + +self.addpkg2db("local", fpkg) +self.dbver = 8 + +self.cmd = ["pacman-db-upgrade", "--root", self.root + "/"] + +self.addrule("PACMAN_RETCODE=0") +self.addrule("PKG_BACKUP=filesystem|mnt_real/subdir/foo") +self.addrule("PKG_FILES=filesystem|mnt_real/") +self.addrule("PKG_FILES=filesystem|mnt_real/subdir/") +self.addrule("PKG_FILES=filesystem|mnt_real/subdir/foo") +self.addrule("PKG_FILES=filesystem|baz") +self.addrule("!PKG_FILES=filesystem|mnt/") +self.addrule("!PKG_FILES=filesystem|bar/") diff --git a/valgrind.supp b/valgrind.supp index ac54b74..806c9b6 100644 --- a/valgrind.supp +++ b/valgrind.supp @@ -149,3 +149,10 @@ Memcheck:Cond fun:__lxstat } +{ + bash-is-a-sieve + Memcheck:Leak + match-leak-kinds: reachable,definite,indirect + ... + obj:*/bash +} -- 2.1.2
On 08/10/14 16:39, Andrew Gregory wrote:
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
make PY_LOG_FLAGS=--valgrind check not ok 9 - FILE_EMPTY=var/log/valgrind How do I run this individually to get the contents?
On 10/13/14 at 01:32pm, Allan McRae wrote:
On 08/10/14 16:39, Andrew Gregory wrote:
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
make PY_LOG_FLAGS=--valgrind check
not ok 9 - FILE_EMPTY=var/log/valgrind
How do I run this individually to get the contents?
test/pacman/pactest.py -p scripts/pacman-db-upgrade --valgrind --keep-root test/scripts/pacman-db-upgrade-v9.py apg
On 08/10/14 16:39, Andrew Gregory wrote:
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Hi Andrew, "make distcheck" fails with this patch: make[5]: Nothing to be done for 'test/scripts/pacman-db-upgrade-v9.log'. fatal: making test/test-suite.log: failed to create test/scripts/pacman-db-upgrade-v9.trs fatal: making test/test-suite.log: failed to create test/scripts/pacman-db-upgrade-v9.log Makefile:1046: recipe for target 'test/test-suite.log' failed make[4]: *** [test/test-suite.log] Error 1 Makefile:1152: recipe for target 'check-TESTS' failed make[3]: *** [check-TESTS] Error 2 Makefile:1404: recipe for target 'check-am' failed make[2]: *** [check-am] Error 2 Makefile:932: recipe for target 'check-recursive' failed make[1]: *** [check-recursive] Error 1 Makefile:1322: recipe for target 'distcheck' failed make: *** [distcheck] Error 1
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- scripts/pacman-db-upgrade.sh.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pacman-db-upgrade.sh.in b/scripts/pacman-db-upgrade.sh.in index f9bd101..2fced9b 100644 --- a/scripts/pacman-db-upgrade.sh.in +++ b/scripts/pacman-db-upgrade.sh.in @@ -94,7 +94,7 @@ fi USE_COLOR='y' OPT_SHORT="d:hr:V" -OPT_LONG=('confg' 'dbpath:' 'help' 'nocolor' 'root:' 'version') +OPT_LONG=('config:' 'dbpath:' 'help' 'nocolor' 'root:' 'version') if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then exit 1 # E_INVALID_OPTION fi -- 2.1.2
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- test/pacman/pmtest.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/test/pacman/pmtest.py b/test/pacman/pmtest.py index 5a79919..4991971 100644 --- a/test/pacman/pmtest.py +++ b/test/pacman/pmtest.py @@ -40,10 +40,10 @@ def __init__(self, name, root): self.dbver = 9 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)] + "--config", self.configfile(), + "--root", self.rootdir(), + "--dbpath", self.dbdir(), + "--cachedir", self.cachedir()] def __str__(self): return "name = %s\n" \ @@ -294,4 +294,16 @@ def check(self): self.result["fail"] += 1 tap.ok(success, i) + def configfile(self): + return os.path.join(self.root, util.PACCONF) + + def dbdir(self): + return os.path.join(self.root, util.PM_DBPATH) + + def rootdir(self): + return self.root + '/' + + def cachedir(self): + return os.path.join(self.root, util.PM_CACHEDIR) + # vim: set ts=4 sw=4 et: -- 2.1.2
--config does not respect root, causing pacman-db-upgrade to read the local pacman.conf rather than the one in the test root. Also add a rule to ensure the ALPM_DB_VERSION file is actually being created. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- test/scripts/pacman-db-upgrade-v9.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/scripts/pacman-db-upgrade-v9.py b/test/scripts/pacman-db-upgrade-v9.py index dc6f97d..a54319f 100644 --- a/test/scripts/pacman-db-upgrade-v9.py +++ b/test/scripts/pacman-db-upgrade-v9.py @@ -9,9 +9,13 @@ self.addpkg2db("local", fpkg) self.dbver = 8 -self.cmd = ["pacman-db-upgrade", "--root", self.root + "/"] +self.cmd = ["pacman-db-upgrade", + "--root", self.rootdir(), + "--dbpath", self.dbdir(), + "--config", self.configfile() ] self.addrule("PACMAN_RETCODE=0") +self.addrule("FILE_EXIST=var/lib/pacman/local/ALPM_DB_VERSION") self.addrule("PKG_BACKUP=filesystem|mnt_real/subdir/foo") self.addrule("PKG_FILES=filesystem|mnt_real/") self.addrule("PKG_FILES=filesystem|mnt_real/subdir/") -- 2.1.2
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- test/scripts/Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/test/scripts/Makefile.am b/test/scripts/Makefile.am index 5dca9a4..8d6bc84 100644 --- a/test/scripts/Makefile.am +++ b/test/scripts/Makefile.am @@ -1,5 +1,6 @@ check_SCRIPTS = \ parseopts_test.sh \ + pacman-db-upgrade-v9.py \ human_to_size_test.sh noinst_SCRIPTS = $(check_SCRIPTS) -- 2.1.2
participants (2)
-
Allan McRae
-
Andrew Gregory