]>
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
, os
.path
.join(self
.root
, PM_DBPATH
))
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", os
.path
.join(self
.root
, PM_DBPATH
))
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 for dir in [dbdir
, cachedir
, syncdir
, tmpdir
, logdir
, etcdir
]:
114 if not os
.path
.isdir(dir):
115 vprint("\t%s" % dir[len(self
.root
)+1:])
116 os
.makedirs(dir, 0755)
119 vprint(" Creating configuration file")
120 vprint("\t%s" % PACCONF
)
121 mkcfgfile(PACCONF
, self
.root
, self
.option
, self
.db
)
124 vprint(" Creating package archives")
125 for pkg
in self
.localpkgs
:
126 vprint("\t%s" % os
.path
.join(TMPDIR
, pkg
.filename()))
128 for key
, value
in self
.db
.iteritems():
129 if key
== "local": continue
130 for pkg
in value
.pkgs
:
131 vprint("\t%s" % os
.path
.join(PM_CACHEDIR
, pkg
.filename()))
133 pkg
.makepkg(cachedir
)
135 pkg
.makepkg(os
.path
.join(syncdir
, value
.treename
))
136 pkg
.md5sum
= getmd5sum(pkg
.path
)
137 pkg
.csize
= os
.stat(pkg
.path
)[stat
.ST_SIZE
]
139 # Populating databases
140 vprint(" Populating databases")
141 for key
, value
in self
.db
.iteritems():
142 for pkg
in value
.pkgs
:
143 vprint("\t%s/%s" % (key
, pkg
.fullname()))
145 pkg
.installdate
= time
.ctime()
148 # Creating sync database archives
149 vprint(" Creating sync database archives")
150 for key
, value
in self
.db
.iteritems():
151 if key
== "local": continue
152 archive
= value
.treename
+ ".db"
153 vprint("\t" + os
.path
.join(SYNCREPO
, archive
))
154 value
.gensync(os
.path
.join(syncdir
, value
.treename
))
157 vprint(" Populating file system")
158 for pkg
in self
.db
["local"].pkgs
:
159 vprint("\tinstalling %s" % pkg
.fullname())
160 pkg
.install_files(self
.root
)
161 for f
in self
.filesystem
:
163 mkfile(os
.path
.join(self
.root
, f
), f
)
166 vprint(" Taking a snapshot of the file system")
167 for roots
, dirs
, files
in os
.walk(self
.root
):
169 filename
= os
.path
.join(roots
, i
)
170 f
= pmfile
.pmfile(self
.root
, filename
.replace(self
.root
+ "/", ""))
172 vprint("\t%s" % f
.name
)
174 def run(self
, pacman
):
178 if os
.path
.isfile(PM_LOCK
):
179 print "\tERROR: another pacman session is on-going -- skipping"
182 print "==> Running test"
183 vprint("\tpacman %s" % self
.args
)
186 if os
.geteuid() != 0:
187 fakeroot
= which("fakeroot")
189 print "WARNING: fakeroot not found!"
191 cmd
.append("fakeroot")
193 fakechroot
= which("fakechroot")
195 cmd
.append("fakechroot")
198 cmd
.append("libtool execute gdb --args")
199 if pacman
["valgrind"]:
200 cmd
.append("valgrind -q --tool=memcheck --leak-check=full --show-reachable=yes")
201 cmd
.append("\"%s\" --config=\"%s\" --root=\"%s\" --dbpath=\"%s\" --cachedir=\"%s\"" \
203 os
.path
.join(self
.root
, PACCONF
),
205 os
.path
.join(self
.root
, PM_DBPATH
),
206 os
.path
.join(self
.root
, PM_CACHEDIR
)))
207 if not pacman
["manual-confirm"]:
208 cmd
.append("--noconfirm")
210 cmd
.append("--debug=%s" % pacman
["debug"])
211 cmd
.append("%s" % self
.args
)
212 if not pacman
["gdb"] and not pacman
["valgrind"] and not pacman
["nolog"]:
213 cmd
.append(">\"%s\" 2>&1" % os
.path
.join(self
.root
, LOGFILE
))
214 vprint("\trunning: %s" % " ".join(cmd
))
216 # Change to the tmp dir before running pacman, so that local package
217 # archives are made available more easily.
219 tmpdir
= os
.path
.join(self
.root
, TMPDIR
)
223 self
.retcode
= os
.system(" ".join(cmd
))
225 vprint("\ttime elapsed: %ds" % (t1
-t0
))
227 if self
.retcode
== None:
231 vprint("\tretcode = %s" % self
.retcode
)
234 # Check if the lock is still there
235 if os
.path
.isfile(PM_LOCK
):
236 print "\tERROR: %s not removed" % PM_LOCK
238 # Look for a core file
239 if os
.path
.isfile(os
.path
.join(self
.root
, TMPDIR
, "core")):
240 print "\tERROR: pacman dumped a core file"
246 print "==> Checking rules"
249 success
= i
.check(self
.root
, self
.retcode
, self
.db
["local"], self
.files
)
252 self
.result
["success"] += 1
255 self
.result
["fail"] += 1
258 print "\t[%s] %s" % (msg
, i
.rule
)
262 if __name__
== "__main__":
265 # vim: set ts=4 sw=4 et: