]>
wolfpit.net Git - tool/Arch-pacman/.git/blob - test/pacman/pmtest.py
f5a9680574e230f18174bf89d03f14801a95b1be
3 # Copyright (c) 2006 by Aurelien Foret <orelien@chez.com>
4 # Copyright (c) 2006-2013 Pacman Development Team <pacman-dev@archlinux.org>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
31 from util
import vprint
37 def __init__(self
, name
, root
):
39 self
.testname
= os
.path
.basename(name
).replace('.py', '')
44 return "name = %s\n" \
46 "root = %s" % (self
.name
, self
.testname
, self
.root
)
48 def addpkg2db(self
, treename
, pkg
):
49 if not treename
in self
.db
:
50 self
.db
[treename
] = pmdb
.pmdb(treename
, self
.root
)
51 self
.db
[treename
].pkgs
.append(pkg
)
53 def addpkg(self
, pkg
):
54 self
.localpkgs
.append(pkg
)
56 def findpkg(self
, name
, version
, allow_local
=False):
57 """Find a package object matching the name and version specified in
58 either sync databases or the local package collection. The local database
59 is allowed to match if allow_local is True."""
60 for db
in self
.db
.itervalues():
61 if db
.is_local
and not allow_local
:
64 if pkg
and pkg
.version
== version
:
66 for pkg
in self
.localpkgs
:
67 if pkg
.name
== name
and pkg
.version
== version
:
72 def addrule(self
, rulename
):
73 rule
= pmrule
.pmrule(rulename
)
74 self
.rules
.append(rule
)
77 # Reset test parameters
85 "local": pmdb
.pmdb("local", self
.root
)
88 self
.createlocalpkgs
= False
97 self
.expectfailure
= False
99 if os
.path
.isfile(self
.name
):
100 # all tests expect this to be available
101 from pmpkg
import pmpkg
104 raise IOError("file %s does not exist!" % self
.name
)
106 def generate(self
, pacman
):
107 print "==> Generating test environment"
109 # Cleanup leftover files from a previous test session
110 if os
.path
.isdir(self
.root
):
111 shutil
.rmtree(self
.root
)
112 vprint("\t%s" % self
.root
)
114 # Create directory structure
115 vprint(" Creating directory structure:")
116 dbdir
= os
.path
.join(self
.root
, util
.PM_SYNCDBPATH
)
117 cachedir
= os
.path
.join(self
.root
, util
.PM_CACHEDIR
)
118 syncdir
= os
.path
.join(self
.root
, util
.SYNCREPO
)
119 tmpdir
= os
.path
.join(self
.root
, util
.TMPDIR
)
120 logdir
= os
.path
.join(self
.root
, os
.path
.dirname(util
.LOGFILE
))
121 etcdir
= os
.path
.join(self
.root
, os
.path
.dirname(util
.PACCONF
))
122 bindir
= os
.path
.join(self
.root
, "bin")
123 ldconfig
= os
.path
.basename(pacman
["ldconfig"])
124 ldconfigdir
= os
.path
.join(self
.root
, os
.path
.dirname(pacman
["ldconfig"][1:]))
125 shell
= pacman
["scriptlet-shell"][1:]
126 shelldir
= os
.path
.join(self
.root
, os
.path
.dirname(shell
))
127 sys_dirs
= [dbdir
, cachedir
, syncdir
, tmpdir
, logdir
, etcdir
, bindir
,
128 ldconfigdir
, shelldir
]
129 for sys_dir
in sys_dirs
:
130 if not os
.path
.isdir(sys_dir
):
131 vprint("\t%s" % sys_dir
[len(self
.root
)+1:])
132 os
.makedirs(sys_dir
, 0755)
133 # Only the dynamically linked binary is needed for fakechroot
134 shutil
.copy("/bin/sh", bindir
)
135 if shell
!= "bin/sh":
136 shutil
.copy("/bin/sh", os
.path
.join(self
.root
, shell
))
137 shutil
.copy(os
.path
.join(util
.SELFPATH
, "ldconfig.stub"),
138 os
.path
.join(ldconfigdir
, ldconfig
))
139 ld_so_conf
= open(os
.path
.join(etcdir
, "ld.so.conf"), "w")
143 vprint(" Creating configuration file")
144 util
.mkcfgfile(util
.PACCONF
, self
.root
, self
.option
, self
.db
)
147 vprint(" Creating package archives")
148 for pkg
in self
.localpkgs
:
149 vprint("\t%s" % os
.path
.join(util
.TMPDIR
, pkg
.filename()))
152 for key
, value
in self
.db
.iteritems():
153 for pkg
in value
.pkgs
:
155 if key
== "local" and not self
.createlocalpkgs
:
157 for pkg
in value
.pkgs
:
158 vprint("\t%s" % os
.path
.join(util
.PM_CACHEDIR
, pkg
.filename()))
160 pkg
.makepkg(cachedir
)
162 pkg
.makepkg(os
.path
.join(syncdir
, value
.treename
))
163 pkg
.md5sum
= util
.getmd5sum(pkg
.path
)
164 pkg
.csize
= os
.stat(pkg
.path
)[stat
.ST_SIZE
]
166 # Creating sync database archives
167 vprint(" Creating databases")
168 for key
, value
in self
.db
.iteritems():
169 vprint("\t" + value
.treename
)
173 vprint(" Populating file system")
174 for f
in self
.filesystem
:
176 util
.mkfile(self
.root
, f
, f
)
177 path
= os
.path
.join(self
.root
, f
)
178 if os
.path
.isfile(path
):
179 os
.utime(path
, (355, 355))
180 for pkg
in self
.db
["local"].pkgs
:
181 vprint("\tinstalling %s" % pkg
.fullname())
182 pkg
.install_package(self
.root
)
185 vprint(" Taking a snapshot of the file system")
186 for roots
, dirs
, files
in os
.walk(self
.root
):
188 filename
= os
.path
.join(roots
, i
)
189 f
= pmfile
.PacmanFile(self
.root
, filename
.replace(self
.root
+ "/", ""))
191 vprint("\t%s" % f
.name
)
193 def run(self
, pacman
):
194 if os
.path
.isfile(util
.PM_LOCK
):
195 print "\tERROR: another pacman session is on-going -- skipping"
198 print "==> Running test"
199 vprint("\tpacman %s" % self
.args
)
202 if os
.geteuid() != 0:
203 fakeroot
= util
.which("fakeroot")
205 print "WARNING: fakeroot not found!"
207 cmd
.append("fakeroot")
209 fakechroot
= util
.which("fakechroot")
211 print "WARNING: fakechroot not found!"
213 cmd
.append("fakechroot")
216 cmd
.extend(["libtool", "execute", "gdb", "--args"])
217 if pacman
["valgrind"]:
218 suppfile
= os
.path
.join(os
.path
.dirname(__file__
),
219 '..', '..', 'valgrind.supp')
220 cmd
.extend(["libtool", "execute", "valgrind", "-q",
221 "--tool=memcheck", "--leak-check=full",
222 "--show-reachable=yes",
223 "--suppressions=%s" % suppfile
])
224 cmd
.extend([pacman
["bin"],
225 "--config", os
.path
.join(self
.root
, util
.PACCONF
),
227 "--dbpath", os
.path
.join(self
.root
, util
.PM_DBPATH
),
228 "--cachedir", os
.path
.join(self
.root
, util
.PM_CACHEDIR
)])
229 if not pacman
["manual-confirm"]:
230 cmd
.append("--noconfirm")
232 cmd
.append("--debug=%s" % pacman
["debug"])
233 cmd
.extend(shlex
.split(self
.args
))
234 if not (pacman
["gdb"] or pacman
["valgrind"] or pacman
["nolog"]):
235 output
= open(os
.path
.join(self
.root
, util
.LOGFILE
), 'w')
238 vprint("\trunning: %s" % " ".join(cmd
))
240 # Change to the tmp dir before running pacman, so that local package
241 # archives are made available more easily.
242 time_start
= time
.time()
243 self
.retcode
= subprocess
.call(cmd
, stdout
=output
, stderr
=output
,
244 cwd
=os
.path
.join(self
.root
, util
.TMPDIR
), env
={'LC_ALL': 'C'}
)
245 time_end
= time
.time()
246 vprint("\ttime elapsed: %.2fs" % (time_end
- time_start
))
251 vprint("\tretcode = %s" % self
.retcode
)
253 # Check if the lock is still there
254 if os
.path
.isfile(util
.PM_LOCK
):
255 print "\tERROR: %s not removed" % util
.PM_LOCK
256 os
.unlink(util
.PM_LOCK
)
257 # Look for a core file
258 if os
.path
.isfile(os
.path
.join(self
.root
, util
.TMPDIR
, "core")):
259 print "\tERROR: pacman dumped a core file"
262 print "==> Checking rules"
265 success
= i
.check(self
)
268 self
.result
["success"] += 1
271 self
.result
["fail"] += 1
274 print "\t[%s] %s" % (msg
, i
)
276 # vim: set ts=4 sw=4 et: