-#! /usr/bin/python
+#! /usr/bin/python2
#
# Copyright (c) 2006 by Aurelien Foret <orelien@chez.com>
-#
+# Copyright (c) 2006-2013 Pacman Development Team <pacman-dev@archlinux.org>
+#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
import os
-import os.path
+import shlex
import shutil
import stat
+import subprocess
import time
import pmrule
"root = %s" % (self.name, self.testname, self.root)
def addpkg2db(self, treename, pkg):
- """
- """
if not treename in self.db:
self.db[treename] = pmdb.pmdb(treename, self.root)
self.db[treename].pkgs.append(pkg)
def addpkg(self, pkg):
- """
- """
self.localpkgs.append(pkg)
def findpkg(self, name, version, allow_local=False):
either sync databases or the local package collection. The local database
is allowed to match if allow_local is True."""
for db in self.db.itervalues():
- if db.treename == "local" and not allow_local:
+ if db.is_local and not allow_local:
continue
pkg = db.getpkg(name)
if pkg and pkg.version == version:
return None
def addrule(self, rulename):
- """
- """
rule = pmrule.pmrule(rulename)
self.rules.append(rule)
def load(self):
- """
- """
-
# Reset test parameters
self.result = {
"success": 0,
self.rules = []
self.files = []
self.expectfailure = False
-
+
if os.path.isfile(self.name):
# all tests expect this to be available
from pmpkg import pmpkg
else:
raise IOError("file %s does not exist!" % self.name)
- def generate(self):
- """
- """
-
+ def generate(self, pacman):
print "==> Generating test environment"
# Cleanup leftover files from a previous test session
# Create directory structure
vprint(" Creating directory structure:")
- dbdir = os.path.join(self.root, util.PM_DBPATH)
+ dbdir = os.path.join(self.root, util.PM_SYNCDBPATH)
cachedir = os.path.join(self.root, util.PM_CACHEDIR)
syncdir = os.path.join(self.root, util.SYNCREPO)
tmpdir = os.path.join(self.root, util.TMPDIR)
logdir = os.path.join(self.root, os.path.dirname(util.LOGFILE))
etcdir = os.path.join(self.root, os.path.dirname(util.PACCONF))
bindir = os.path.join(self.root, "bin")
- sys_dirs = [dbdir, cachedir, syncdir, tmpdir, logdir, etcdir, bindir]
+ ldconfig = os.path.basename(pacman["ldconfig"])
+ ldconfigdir = os.path.join(self.root, os.path.dirname(pacman["ldconfig"][1:]))
+ shell = pacman["scriptlet-shell"][1:]
+ shelldir = os.path.join(self.root, os.path.dirname(shell))
+ sys_dirs = [dbdir, cachedir, syncdir, tmpdir, logdir, etcdir, bindir,
+ ldconfigdir, shelldir]
for sys_dir in sys_dirs:
if not os.path.isdir(sys_dir):
vprint("\t%s" % sys_dir[len(self.root)+1:])
os.makedirs(sys_dir, 0755)
# Only the dynamically linked binary is needed for fakechroot
shutil.copy("/bin/sh", bindir)
+ if shell != "bin/sh":
+ shutil.copy("/bin/sh", os.path.join(self.root, shell))
+ shutil.copy(os.path.join(util.SELFPATH, "ldconfig.stub"),
+ os.path.join(ldconfigdir, ldconfig))
+ ld_so_conf = open(os.path.join(etcdir, "ld.so.conf"), "w")
+ ld_so_conf.close()
# Configuration file
vprint(" Creating configuration file")
vprint(" Creating package archives")
for pkg in self.localpkgs:
vprint("\t%s" % os.path.join(util.TMPDIR, pkg.filename()))
+ pkg.finalize()
pkg.makepkg(tmpdir)
for key, value in self.db.iteritems():
+ for pkg in value.pkgs:
+ pkg.finalize()
if key == "local" and not self.createlocalpkgs:
continue
for pkg in value.pkgs:
pkg.md5sum = util.getmd5sum(pkg.path)
pkg.csize = os.stat(pkg.path)[stat.ST_SIZE]
- # Populating databases
- vprint(" Populating databases")
- for key, value in self.db.iteritems():
- for pkg in value.pkgs:
- vprint("\t%s/%s" % (key, pkg.fullname()))
- if key == "local":
- pkg.installdate = time.ctime()
- value.db_write(pkg)
-
# Creating sync database archives
- vprint(" Creating sync database archives")
+ vprint(" Creating databases")
for key, value in self.db.iteritems():
- if key == "local":
- continue
vprint("\t" + value.treename)
- value.gensync()
- serverpath = os.path.join(syncdir, value.treename)
- util.mkdir(serverpath)
- shutil.copy(value.dbfile, serverpath)
+ value.generate()
# Filesystem
vprint(" Populating file system")
- for pkg in self.db["local"].pkgs:
- vprint("\tinstalling %s" % pkg.fullname())
- for f in pkg.files:
- vprint("\t%s" % f)
- path = os.path.join(self.root, f)
- util.mkfile(path, f)
- if os.path.isfile(path):
- os.utime(path, (355, 355))
for f in self.filesystem:
vprint("\t%s" % f)
+ util.mkfile(self.root, f, f)
path = os.path.join(self.root, f)
- util.mkfile(path, f)
if os.path.isfile(path):
os.utime(path, (355, 355))
+ for pkg in self.db["local"].pkgs:
+ vprint("\tinstalling %s" % pkg.fullname())
+ pkg.install_package(self.root)
# Done.
vprint(" Taking a snapshot of the file system")
for roots, dirs, files in os.walk(self.root):
for i in files:
filename = os.path.join(roots, i)
- f = pmfile.pmfile(self.root, filename.replace(self.root + "/", ""))
+ f = pmfile.PacmanFile(self.root, filename.replace(self.root + "/", ""))
self.files.append(f)
vprint("\t%s" % f.name)
def run(self, pacman):
- """
- """
-
if os.path.isfile(util.PM_LOCK):
print "\tERROR: another pacman session is on-going -- skipping"
return
print "==> Running test"
vprint("\tpacman %s" % self.args)
- cmd = [""]
+ cmd = []
if os.geteuid() != 0:
fakeroot = util.which("fakeroot")
if not fakeroot:
cmd.append("fakeroot")
fakechroot = util.which("fakechroot")
- if fakechroot:
+ if not fakechroot:
+ print "WARNING: fakechroot not found!"
+ else:
cmd.append("fakechroot")
if pacman["gdb"]:
- cmd.append("libtool execute gdb --args")
+ cmd.extend(["libtool", "execute", "gdb", "--args"])
if pacman["valgrind"]:
- cmd.append("valgrind -q --tool=memcheck --leak-check=full --show-reachable=yes --suppressions=%s/valgrind.supp" % os.getcwd())
- cmd.append("\"%s\" --config=\"%s\" --root=\"%s\" --dbpath=\"%s\" --cachedir=\"%s\"" \
- % (pacman["bin"],
- os.path.join(self.root, util.PACCONF),
- self.root,
- os.path.join(self.root, util.PM_DBPATH),
- os.path.join(self.root, util.PM_CACHEDIR)))
+ suppfile = os.path.join(os.path.dirname(__file__),
+ '..', '..', 'valgrind.supp')
+ cmd.extend(["libtool", "execute", "valgrind", "-q",
+ "--tool=memcheck", "--leak-check=full",
+ "--show-reachable=yes",
+ "--suppressions=%s" % suppfile])
+ cmd.extend([pacman["bin"],
+ "--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["debug"]:
cmd.append("--debug=%s" % pacman["debug"])
- cmd.append("%s" % self.args)
- if not pacman["gdb"] and not pacman["valgrind"] and not pacman["nolog"]:
- cmd.append(">\"%s\" 2>&1" % os.path.join(self.root, util.LOGFILE))
+ cmd.extend(shlex.split(self.args))
+ if not (pacman["gdb"] or pacman["valgrind"] or pacman["nolog"]):
+ output = open(os.path.join(self.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.
- curdir = os.getcwd()
- tmpdir = os.path.join(self.root, util.TMPDIR)
- os.chdir(tmpdir)
-
time_start = time.time()
- self.retcode = os.system(" ".join(cmd))
+ self.retcode = subprocess.call(cmd, stdout=output, stderr=output,
+ cwd=os.path.join(self.root, util.TMPDIR), env={'LC_ALL': 'C'})
time_end = time.time()
- vprint("\ttime elapsed: %ds" % (time_end - time_start))
+ vprint("\ttime elapsed: %.2fs" % (time_end - time_start))
+
+ if output:
+ output.close()
- if self.retcode == None:
- self.retcode = 0
- else:
- self.retcode /= 256
vprint("\tretcode = %s" % self.retcode)
- os.chdir(curdir)
# Check if the lock is still there
if os.path.isfile(util.PM_LOCK):
print "\tERROR: pacman dumped a core file"
def check(self):
- """
- """
-
print "==> Checking rules"
for i in self.rules:
if success == 1:
msg = " OK "
self.result["success"] += 1
- elif success == 0:
+ else:
msg = "FAIL"
self.result["fail"] += 1
- else:
- msg = "SKIP"
print "\t[%s] %s" % (msg, i)
# vim: set ts=4 sw=4 et: