]>
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/>.
27 from pmpkg
import pmpkg
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
):
92 raise IOerror("file %s does not exist!" % self
.name
)
98 print "==> Generating test environment"
100 # Cleanup leftover files from a previous test session
101 if os
.path
.isdir(self
.root
):
102 shutil
.rmtree(self
.root
)
103 vprint("\t%s" % self
.root
)
105 # Create directory structure
106 vprint(" Creating directory structure:")
107 dbdir
= os
.path
.join(self
.root
, PM_DBPATH
)
108 cachedir
= os
.path
.join(self
.root
, PM_CACHEDIR
)
109 syncdir
= os
.path
.join(self
.root
, SYNCREPO
)
110 tmpdir
= os
.path
.join(self
.root
, TMPDIR
)
111 logdir
= os
.path
.join(self
.root
, os
.path
.dirname(LOGFILE
))
112 etcdir
= os
.path
.join(self
.root
, os
.path
.dirname(PACCONF
))
113 bindir
= os
.path
.join(self
.root
, "bin")
114 for dir in [dbdir
, cachedir
, syncdir
, tmpdir
, logdir
, etcdir
, bindir
]:
115 if not os
.path
.isdir(dir):
116 vprint("\t%s" % dir[len(self
.root
)+1:])
117 os
.makedirs(dir, 0755)
118 # Only the dynamically linked binary is needed for fakechroot
119 shutil
.copy("/bin/sh", bindir
)
122 vprint(" Creating configuration file")
123 vprint("\t%s" % PACCONF
)
124 mkcfgfile(PACCONF
, self
.root
, self
.option
, self
.db
)
127 vprint(" Creating package archives")
128 for pkg
in self
.localpkgs
:
129 vprint("\t%s" % os
.path
.join(TMPDIR
, pkg
.filename()))
131 for key
, value
in self
.db
.iteritems():
132 if key
== "local": continue
133 for pkg
in value
.pkgs
:
134 vprint("\t%s" % os
.path
.join(PM_CACHEDIR
, pkg
.filename()))
136 pkg
.makepkg(cachedir
)
138 pkg
.makepkg(os
.path
.join(syncdir
, value
.treename
))
139 pkg
.md5sum
= getmd5sum(pkg
.path
)
140 pkg
.csize
= os
.stat(pkg
.path
)[stat
.ST_SIZE
]
142 # Populating databases
143 vprint(" Populating databases")
144 for key
, value
in self
.db
.iteritems():
145 for pkg
in value
.pkgs
:
146 vprint("\t%s/%s" % (key
, pkg
.fullname()))
148 pkg
.installdate
= time
.ctime()
151 # Creating sync database archives
152 vprint(" Creating sync database archives")
153 for key
, value
in self
.db
.iteritems():
154 if key
== "local": continue
155 vprint("\t" + value
.treename
)
157 serverpath
= os
.path
.join(syncdir
, value
.treename
)
159 shutil
.copy(value
.dbfile
, serverpath
)
162 vprint(" Populating file system")
163 for pkg
in self
.db
["local"].pkgs
:
164 vprint("\tinstalling %s" % pkg
.fullname())
165 pkg
.install_files(self
.root
)
166 for f
in self
.filesystem
:
168 mkfile(os
.path
.join(self
.root
, f
), f
)
171 vprint(" Taking a snapshot of the file system")
172 for roots
, dirs
, files
in os
.walk(self
.root
):
174 filename
= os
.path
.join(roots
, i
)
175 f
= pmfile
.pmfile(self
.root
, filename
.replace(self
.root
+ "/", ""))
177 vprint("\t%s" % f
.name
)
179 def run(self
, pacman
):
183 if os
.path
.isfile(PM_LOCK
):
184 print "\tERROR: another pacman session is on-going -- skipping"
187 print "==> Running test"
188 vprint("\tpacman %s" % self
.args
)
191 if os
.geteuid() != 0:
192 fakeroot
= which("fakeroot")
194 print "WARNING: fakeroot not found!"
196 cmd
.append("fakeroot")
198 fakechroot
= which("fakechroot")
200 cmd
.append("fakechroot")
203 cmd
.append("libtool execute gdb --args")
204 if pacman
["valgrind"]:
205 cmd
.append("valgrind -q --tool=memcheck --leak-check=full --show-reachable=yes --suppressions=%s/valgrind.supp" % os
.getcwd())
206 cmd
.append("\"%s\" --config=\"%s\" --root=\"%s\" --dbpath=\"%s\" --cachedir=\"%s\"" \
208 os
.path
.join(self
.root
, PACCONF
),
210 os
.path
.join(self
.root
, PM_DBPATH
),
211 os
.path
.join(self
.root
, PM_CACHEDIR
)))
212 if not pacman
["manual-confirm"]:
213 cmd
.append("--noconfirm")
215 cmd
.append("--debug=%s" % pacman
["debug"])
216 cmd
.append("%s" % self
.args
)
217 if not pacman
["gdb"] and not pacman
["valgrind"] and not pacman
["nolog"]:
218 cmd
.append(">\"%s\" 2>&1" % os
.path
.join(self
.root
, LOGFILE
))
219 vprint("\trunning: %s" % " ".join(cmd
))
221 # Change to the tmp dir before running pacman, so that local package
222 # archives are made available more easily.
224 tmpdir
= os
.path
.join(self
.root
, TMPDIR
)
228 self
.retcode
= os
.system(" ".join(cmd
))
230 vprint("\ttime elapsed: %ds" % (t1
-t0
))
232 if self
.retcode
== None:
236 vprint("\tretcode = %s" % self
.retcode
)
239 # Check if the lock is still there
240 if os
.path
.isfile(PM_LOCK
):
241 print "\tERROR: %s not removed" % PM_LOCK
243 # Look for a core file
244 if os
.path
.isfile(os
.path
.join(self
.root
, TMPDIR
, "core")):
245 print "\tERROR: pacman dumped a core file"
251 print "==> Checking rules"
254 success
= i
.check(self
.root
, self
.retcode
, self
.db
["local"], self
.files
)
257 self
.result
["success"] += 1
260 self
.result
["fail"] += 1
263 print "\t[%s] %s" % (msg
, i
)
265 # vim: set ts=4 sw=4 et: