]>
wolfpit.net Git - tool/Arch-pacman/.git/blob - test/pacman/pmtest.py
3 # Copyright (c) 2006 by Aurelien Foret <orelien@chez.com>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
29 from util
import vprint
35 def __init__(self
, name
, root
):
37 self
.testname
= os
.path
.basename(name
).replace('.py', '')
42 return "name = %s\n" \
44 "root = %s" % (self
.name
, self
.testname
, self
.root
)
46 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
):
56 self
.localpkgs
.append(pkg
)
58 def addrule(self
, rulename
):
61 rule
= pmrule
.pmrule(rulename
)
62 self
.rules
.append(rule
)
68 # Reset test parameters
76 "local": pmdb
.pmdb("local", self
.root
)
87 self
.expectfailure
= False
89 if os
.path
.isfile(self
.name
):
90 # all tests expect this to be available
91 from pmpkg
import pmpkg
94 raise IOError("file %s does not exist!" % self
.name
)
100 print "==> Generating test environment"
102 # Cleanup leftover files from a previous test session
103 if os
.path
.isdir(self
.root
):
104 shutil
.rmtree(self
.root
)
105 vprint("\t%s" % self
.root
)
107 # Create directory structure
108 vprint(" Creating directory structure:")
109 dbdir
= os
.path
.join(self
.root
, util
.PM_DBPATH
)
110 cachedir
= os
.path
.join(self
.root
, util
.PM_CACHEDIR
)
111 syncdir
= os
.path
.join(self
.root
, util
.SYNCREPO
)
112 tmpdir
= os
.path
.join(self
.root
, util
.TMPDIR
)
113 logdir
= os
.path
.join(self
.root
, os
.path
.dirname(util
.LOGFILE
))
114 etcdir
= os
.path
.join(self
.root
, os
.path
.dirname(util
.PACCONF
))
115 bindir
= os
.path
.join(self
.root
, "bin")
116 sys_dirs
= [dbdir
, cachedir
, syncdir
, tmpdir
, logdir
, etcdir
, bindir
]
117 for sys_dir
in sys_dirs
:
118 if not os
.path
.isdir(sys_dir
):
119 vprint("\t%s" % sys_dir
[len(self
.root
)+1:])
120 os
.makedirs(sys_dir
, 0755)
121 # Only the dynamically linked binary is needed for fakechroot
122 shutil
.copy("/bin/sh", bindir
)
125 vprint(" Creating configuration file")
126 util
.mkcfgfile(util
.PACCONF
, self
.root
, self
.option
, self
.db
)
129 vprint(" Creating package archives")
130 for pkg
in self
.localpkgs
:
131 vprint("\t%s" % os
.path
.join(util
.TMPDIR
, pkg
.filename()))
133 for key
, value
in self
.db
.iteritems():
136 for pkg
in value
.pkgs
:
137 vprint("\t%s" % os
.path
.join(util
.PM_CACHEDIR
, pkg
.filename()))
139 pkg
.makepkg(cachedir
)
141 pkg
.makepkg(os
.path
.join(syncdir
, value
.treename
))
142 pkg
.md5sum
= util
.getmd5sum(pkg
.path
)
143 pkg
.csize
= os
.stat(pkg
.path
)[stat
.ST_SIZE
]
145 # Populating databases
146 vprint(" Populating databases")
147 for key
, value
in self
.db
.iteritems():
148 for pkg
in value
.pkgs
:
149 vprint("\t%s/%s" % (key
, pkg
.fullname()))
151 pkg
.installdate
= time
.ctime()
154 # Creating sync database archives
155 vprint(" Creating sync database archives")
156 for key
, value
in self
.db
.iteritems():
159 vprint("\t" + value
.treename
)
161 serverpath
= os
.path
.join(syncdir
, value
.treename
)
162 util
.mkdir(serverpath
)
163 shutil
.copy(value
.dbfile
, serverpath
)
166 vprint(" Populating file system")
167 for pkg
in self
.db
["local"].pkgs
:
168 vprint("\tinstalling %s" % pkg
.fullname())
169 pkg
.install_files(self
.root
)
170 for f
in self
.filesystem
:
172 util
.mkfile(os
.path
.join(self
.root
, f
), f
)
175 vprint(" Taking a snapshot of the file system")
176 for roots
, dirs
, files
in os
.walk(self
.root
):
178 filename
= os
.path
.join(roots
, i
)
179 f
= pmfile
.pmfile(self
.root
, filename
.replace(self
.root
+ "/", ""))
181 vprint("\t%s" % f
.name
)
183 def run(self
, pacman
):
187 if os
.path
.isfile(util
.PM_LOCK
):
188 print "\tERROR: another pacman session is on-going -- skipping"
191 print "==> Running test"
192 vprint("\tpacman %s" % self
.args
)
195 if os
.geteuid() != 0:
196 fakeroot
= util
.which("fakeroot")
198 print "WARNING: fakeroot not found!"
200 cmd
.append("fakeroot")
202 fakechroot
= util
.which("fakechroot")
204 cmd
.append("fakechroot")
207 cmd
.append("libtool execute gdb --args")
208 if pacman
["valgrind"]:
209 cmd
.append("valgrind -q --tool=memcheck --leak-check=full --show-reachable=yes --suppressions=%s/valgrind.supp" % os
.getcwd())
210 cmd
.append("\"%s\" --config=\"%s\" --root=\"%s\" --dbpath=\"%s\" --cachedir=\"%s\"" \
212 os
.path
.join(self
.root
, util
.PACCONF
),
214 os
.path
.join(self
.root
, util
.PM_DBPATH
),
215 os
.path
.join(self
.root
, util
.PM_CACHEDIR
)))
216 if not pacman
["manual-confirm"]:
217 cmd
.append("--noconfirm")
219 cmd
.append("--debug=%s" % pacman
["debug"])
220 cmd
.append("%s" % self
.args
)
221 if not pacman
["gdb"] and not pacman
["valgrind"] and not pacman
["nolog"]:
222 cmd
.append(">\"%s\" 2>&1" % os
.path
.join(self
.root
, util
.LOGFILE
))
223 vprint("\trunning: %s" % " ".join(cmd
))
225 # Change to the tmp dir before running pacman, so that local package
226 # archives are made available more easily.
228 tmpdir
= os
.path
.join(self
.root
, util
.TMPDIR
)
231 time_start
= time
.time()
232 self
.retcode
= os
.system(" ".join(cmd
))
233 time_end
= time
.time()
234 vprint("\ttime elapsed: %ds" % (time_end
- time_start
))
236 if self
.retcode
== None:
240 vprint("\tretcode = %s" % self
.retcode
)
243 # Check if the lock is still there
244 if os
.path
.isfile(util
.PM_LOCK
):
245 print "\tERROR: %s not removed" % util
.PM_LOCK
246 os
.unlink(util
.PM_LOCK
)
247 # Look for a core file
248 if os
.path
.isfile(os
.path
.join(self
.root
, util
.TMPDIR
, "core")):
249 print "\tERROR: pacman dumped a core file"
255 print "==> Checking rules"
258 success
= i
.check(self
.root
, self
.retcode
, self
.db
["local"], self
.files
)
261 self
.result
["success"] += 1
264 self
.result
["fail"] += 1
267 print "\t[%s] %s" % (msg
, i
)
269 # vim: set ts=4 sw=4 et: