Two new "hooks" were made available in pmtest: genhook is called after
everything is generated just before the snapshot is taken, and
snaphook is called just after. A hook is a list of strings. Calling a
hook is "exec"ing each string in the list.
Several helper functions were added to pmtest: pacmanrun, unlink,
rmtree and warnmissing. These can be used in a hook to install a
package and then intentionally mess it up, which then allows the
pmtest to verify the results of "-Qk".
An mtree attribute was added to pmtest, and a parameter added to
pmpkg.makepkg, in anticipation of testing "-Qkk". TODO: figure out how
to create an mtree in makepkg.
Signed-off-by: Jeremy Heiner <ScalaProtractor at gmail>
---
test/pacman/pmpkg.py | 2 +-
test/pacman/pmtest.py | 75 ++++++++++++++++++++++++++++----------
test/pacman/tests/querycheck001.py | 18 +++++++++
test/pacman/tests/querycheck002.py | 24 ++++++++++++
test/pacman/tests/querycheck003.py | 24 ++++++++++++
test/pacman/tests/querycheck004.py | 25 +++++++++++++
test/pacman/tests/querycheck005.py | 31 ++++++++++++++++
test/pacman/tests/querycheck006.py | 19 ++++++++++
test/pacman/util.py | 1 +
9 files changed, 199 insertions(+), 20 deletions(-)
create mode 100644 test/pacman/tests/querycheck001.py
create mode 100644 test/pacman/tests/querycheck002.py
create mode 100644 test/pacman/tests/querycheck003.py
create mode 100644 test/pacman/tests/querycheck004.py
create mode 100644 test/pacman/tests/querycheck005.py
create mode 100644 test/pacman/tests/querycheck006.py
diff --git a/test/pacman/pmpkg.py b/test/pacman/pmpkg.py
index 9b3147a..1397229 100644
--- a/test/pacman/pmpkg.py
+++ b/test/pacman/pmpkg.py
@@ -104,7 +104,7 @@ def parse_filename(name):
filename, extra = filename.split("|")
return filename
- def makepkg(self, path):
+ def makepkg(self, mtree, path):
"""Creates an Arch Linux package archive.
A package archive is generated in the location 'path', based
on the data
diff --git a/test/pacman/pmtest.py b/test/pacman/pmtest.py
index 63d25e8..739c445 100644
--- a/test/pacman/pmtest.py
+++ b/test/pacman/pmtest.py
@@ -18,6 +18,7 @@
import os
+import re
import shlex
import shutil
import stat
@@ -92,6 +93,10 @@ def load(self):
self.description = ""
self.option = {}
+ self.mtree = False
+ self.genhook = []
+ self.snaphook = []
+
# Test rules
self.rules = []
self.files = []
@@ -152,7 +157,7 @@ def generate(self):
for pkg in self.localpkgs:
vprint("\t%s" % os.path.join(util.TMPDIR, pkg.filename()))
pkg.finalize()
- pkg.makepkg(tmpdir)
+ pkg.makepkg(self.mtree, tmpdir)
for key, value in self.db.iteritems():
for pkg in value.pkgs:
pkg.finalize()
@@ -161,9 +166,9 @@ def generate(self):
for pkg in value.pkgs:
vprint("\t%s" % os.path.join(util.PM_CACHEDIR, pkg.filename()))
if self.cachepkgs:
- pkg.makepkg(cachedir)
+ pkg.makepkg(self.mtree, cachedir)
else:
- pkg.makepkg(os.path.join(syncdir, value.treename))
+ pkg.makepkg(self.mtree, os.path.join(syncdir,
value.treename))
pkg.md5sum = util.getmd5sum(pkg.path)
pkg.csize = os.stat(pkg.path)[stat.ST_SIZE]
@@ -187,12 +192,58 @@ def generate(self):
# Done.
vprint(" Taking a snapshot of the file system")
+ for cmd in self.genhook:
+ exec cmd
for roots, dirs, files in os.walk(root):
for i in files:
filename = os.path.join(roots, i)
f = pmfile.PacmanFile(root, filename.replace(root + "/", ""))
self.files.append(f)
vprint("\t%s" % f.name)
+ for cmd in self.snaphook:
+ exec cmd
+
+ def pacmanbin(self):
+ root = self.env.root
+ return([self.env.pacman["bin"],
+ "--config", os.path.join(root, util.PACCONF),
+ "--root", root,
+ "--dbpath", os.path.join(root, util.PM_DBPATH),
+ "--cachedir", os.path.join(root, util.PM_CACHEDIR)])
+
+ def pacmansub(self, cmd, output):
+ vprint("\trunning: %s" % " ".join(cmd))
+ # Change to the tmp dir before running pacman, so that local package
+ # archives are made available more easily.
+ time_start = time.time()
+ retcode = subprocess.call(cmd, stdout=output, stderr=output,
+ cwd=os.path.join(self.env.root, util.TMPDIR),
+ env={'LC_ALL': 'C'})
+ time_end = time.time()
+ vprint("\ttime elapsed: %.2fs" % (time_end - time_start))
+ vprint("\tretcode = %s" % retcode)
+ return retcode
+
+ def pacmanrun(self, args):
+ cmd = self.env.cmdroot()
+ cmd.extend(self.pacmanbin())
+ cmd.append("--noconfirm")
+ cmd.extend(shlex.split(args))
+ output = open(os.path.join(self.env.root, util.GENFILE), 'a')
+ self.pacmansub(cmd, output)
+ output.close()
+
+ def unlink(self, path):
+ path = os.path.join(self.env.root, path)
+ os.unlink(path)
+ def rmtree(self, path):
+ path = os.path.join(self.env.root, path)
+ shutil.rmtree(path)
+ def warnmissing(self, pkg, path):
+ return "PACMAN_OUTPUT=^" + re.escape(
+ "warning: %s: %s (No such file or directory)"
+ % (pkg.name, os.path.join(self.env.root, path))
+ ) + "$"
def run(self):
if os.path.isfile(util.PM_LOCK):
@@ -215,11 +266,7 @@ def run(self):
"--tool=memcheck", "--leak-check=full",
"--show-reachable=yes",
"--suppressions=%s" % suppfile])
- cmd.extend([pacman["bin"],
- "--config", os.path.join(root, util.PACCONF),
- "--root", root,
- "--dbpath", os.path.join(root, util.PM_DBPATH),
- "--cachedir", os.path.join(root, util.PM_CACHEDIR)])
+ cmd.extend(self.pacmanbin())
if not pacman["manual-confirm"]:
cmd.append("--noconfirm")
if pacman["debug"]:
@@ -229,21 +276,11 @@ def run(self):
output = open(os.path.join(root, util.LOGFILE), 'w')
else:
output = None
- vprint("\trunning: %s" % " ".join(cmd))
-
- # Change to the tmp dir before running pacman, so that local package
- # archives are made available more easily.
- time_start = time.time()
- self.retcode = subprocess.call(cmd, stdout=output, stderr=output,
- cwd=os.path.join(root, util.TMPDIR), env={'LC_ALL': 'C'})
- time_end = time.time()
- vprint("\ttime elapsed: %.2fs" % (time_end - time_start))
+ self.retcode = self.pacmansub(cmd, output)
if output:
output.close()
- vprint("\tretcode = %s" % self.retcode)
-
# Check if the lock is still there
if os.path.isfile(util.PM_LOCK):
tap.diag("\tERROR: %s not removed" % util.PM_LOCK)
diff --git a/test/pacman/tests/querycheck001.py
b/test/pacman/tests/querycheck001.py
new file mode 100644
index 0000000..8587b50
--- /dev/null
+++ b/test/pacman/tests/querycheck001.py
@@ -0,0 +1,18 @@
+self.description = "Query--check files, all there"
+
+pkg = pmpkg("dummy")
+pkg.files = [
+ "etc/dummy.conf",
+ "lib/libdummy.so.0",
+ "lib/libdummy.so -> ./libdummy.so.0",
+ "lib/dummy/",
+ "lib/dummy/stuff",
+ "bin/dummy"]
+
+self.addpkg(pkg)
+self.genhook.extend([
+ "self.pacmanrun('-U %s')" % pkg.filename()])
+
+self.args = "-Qk"
+
+self.addrule("PACMAN_RETCODE=0")
diff --git a/test/pacman/tests/querycheck002.py
b/test/pacman/tests/querycheck002.py
new file mode 100644
index 0000000..0bc3ff4
--- /dev/null
+++ b/test/pacman/tests/querycheck002.py
@@ -0,0 +1,24 @@
+self.description = "Query--check files, missing a file"
+
+pkg = pmpkg("dummy")
+pkg.files = [
+ "etc/dummy.conf",
+ "lib/libdummy.so.0",
+ "lib/libdummy.so -> ./libdummy.so.0",
+ "lib/dummy/",
+ "lib/dummy/stuff",
+ "bin/dummy"]
+
+self.addpkg(pkg)
+
+zap = pkg.files[1]
+
+self.genhook.extend([
+ "self.pacmanrun('-U %s')" % pkg.filename(),
+ "self.unlink('%s')" % zap])
+
+self.args = "-Qk"
+
+self.addrule("PACMAN_RETCODE=1")
+self.addrule(self.warnmissing(pkg, zap))
+self.addrule("PACMAN_OUTPUT= 1 missing file$")
diff --git a/test/pacman/tests/querycheck003.py
b/test/pacman/tests/querycheck003.py
new file mode 100644
index 0000000..bda095d
--- /dev/null
+++ b/test/pacman/tests/querycheck003.py
@@ -0,0 +1,24 @@
+self.description = "Query--check files, missing a link"
+
+pkg = pmpkg("dummy")
+pkg.files = [
+ "etc/dummy.conf",
+ "lib/libdummy.so.0",
+ "lib/libdummy.so -> ./libdummy.so.0",
+ "lib/dummy/",
+ "lib/dummy/stuff",
+ "bin/dummy"]
+
+self.addpkg(pkg)
+
+zap = pkg.files[2].split(' -> ')[0]
+
+self.genhook.extend([
+ "self.pacmanrun('-U %s')" % pkg.filename(),
+ "self.unlink('%s')" % zap])
+
+self.args = "-Qk"
+
+self.addrule("PACMAN_RETCODE=1")
+self.addrule(self.warnmissing(pkg, zap))
+self.addrule("PACMAN_OUTPUT= 1 missing file$")
diff --git a/test/pacman/tests/querycheck004.py
b/test/pacman/tests/querycheck004.py
new file mode 100644
index 0000000..be9c381
--- /dev/null
+++ b/test/pacman/tests/querycheck004.py
@@ -0,0 +1,25 @@
+self.description = "Query--check files, missing a dir"
+
+pkg = pmpkg("dummy")
+pkg.files = [
+ "etc/dummy.conf",
+ "lib/libdummy.so.0",
+ "lib/libdummy.so -> ./libdummy.so.0",
+ "lib/dummy/",
+ "lib/dummy/stuff",
+ "bin/dummy"]
+
+self.addpkg(pkg)
+
+zap = pkg.files[3]
+
+self.genhook.extend([
+ "self.pacmanrun('-U %s')" % pkg.filename(),
+ "self.rmtree('%s')" % zap])
+
+self.args = "-Qk"
+
+self.addrule("PACMAN_RETCODE=1")
+self.addrule(self.warnmissing(pkg, zap))
+self.addrule(self.warnmissing(pkg, pkg.files[4]))
+self.addrule("PACMAN_OUTPUT= 2 missing files$")
diff --git a/test/pacman/tests/querycheck005.py
b/test/pacman/tests/querycheck005.py
new file mode 100644
index 0000000..416e17f
--- /dev/null
+++ b/test/pacman/tests/querycheck005.py
@@ -0,0 +1,31 @@
+self.description = "Query--check files, missing several"
+
+pkg = pmpkg("dummy")
+pkg.files = [
+ "etc/dummy.conf",
+ "lib/libdummy.so.0",
+ "lib/libdummy.so -> ./libdummy.so.0",
+ "lib/dummy/",
+ "lib/dummy/stuff",
+ "bin/dummy"]
+
+self.addpkg(pkg)
+
+zap1 = pkg.files[1]
+zap2 = pkg.files[2].split(' -> ')[0]
+zap3 = pkg.files[3]
+
+self.genhook.extend([
+ "self.pacmanrun('-U %s')" % pkg.filename(),
+ "self.unlink('%s')" % zap1,
+ "self.unlink('%s')" % zap2,
+ "self.rmtree('%s')" % zap3])
+
+self.args = "-Qk"
+
+self.addrule("PACMAN_RETCODE=1")
+self.addrule(self.warnmissing(pkg, zap1))
+self.addrule(self.warnmissing(pkg, zap2))
+self.addrule(self.warnmissing(pkg, zap3))
+self.addrule(self.warnmissing(pkg, pkg.files[4]))
+self.addrule("PACMAN_OUTPUT= 4 missing files$")
diff --git a/test/pacman/tests/querycheck006.py
b/test/pacman/tests/querycheck006.py
new file mode 100644
index 0000000..d710a5b
--- /dev/null
+++ b/test/pacman/tests/querycheck006.py
@@ -0,0 +1,19 @@
+self.description = "Query--check mtree, no mtree"
+
+pkg = pmpkg("dummy")
+pkg.files = [
+ "etc/dummy.conf",
+ "lib/libdummy.so.0",
+ "lib/libdummy.so -> ./libdummy.so.0",
+ "lib/dummy/",
+ "lib/dummy/stuff",
+ "bin/dummy"]
+
+self.addpkg(pkg)
+self.genhook.extend([
+ "self.pacmanrun('-U %s')" % pkg.filename()])
+
+self.args = "-Qkk"
+
+self.addrule("PACMAN_RETCODE=0")
+self.addrule("PACMAN_OUTPUT=dummy: no mtree file")
diff --git a/test/pacman/util.py b/test/pacman/util.py
index 14035d7..db8fef3 100644
--- a/test/pacman/util.py
+++ b/test/pacman/util.py
@@ -40,6 +40,7 @@
TMPDIR = "tmp"
SYNCREPO = "var/pub"
LOGFILE = "var/log/pactest.log"
+GENFILE = "var/log/pacgen.log"
verbose = 0
--
1.8.4