4 pactest is a test suite for the ArchLinux package manager: pacman.
6 It has a rather high level view of operations performed by pacman: it
7 automatically creates a test environment based on a test case file
8 description, the run pacman, and finally check the results of test according
9 to a set of rules defined in the test case.
11 It is written in Python and makes available most of what can be found in
12 pacman's code to create ArchLinux packages or read and write databases entries.
14 Each test case is defined in a separate file that is sourced in order to set
17 pactest creates the environment in the subdirectory "root" created in the
19 The following directory structure is used:
20 - var/lib/pacman: databases path (local and sync ones)
21 - etc/pacman.conf for pacman configuration file
22 - var/cache/pkg: sync packages cache
23 - var/log/pactest.log: log file
24 - var/pub: location for pseudo sync repositories
25 - tmp: hold all local package archives (to be used with pacman -A or -U)
27 Note: the logfile is used to capture all pacman outputs.
30 self.description = "Install a package"
32 p = pmpkg("dummy", "1.0-3")
33 p.files = ["bin/dummy",
34 "usr/man/man1/dummy.1"]
37 self.args = "-A dummy-1.0-1.pkg.tar.gz"
39 self.addrule("PACMAN_RETCODE=0")
40 self.addrule("PKG_EXIST=dummy")
42 self.addrule("FILE_EXIST=%s" % f)
44 Basically, the above test case will try to install a package (dummy-1.0-3),
45 including two files, from a local archive, by calling "pacman -A"
46 Upon completion, it checks that:
47 - pacman returned no error code,
48 - a "dummy" entry exists in the "local" database
49 - all files from the package exist in the filesystem.
55 Simply extract the pactest tarball, jump into the newly created directory and
56 run pactest.py. See the usage section below.
58 Remark: pacman 3.x restrictions regarding fakeroot must be disabled.
59 It can be done by configuring pacman with the --disable-fakeroot flag:
60 ./configure --disable-fakeroot
62 For pacman 2.9.x releases, apply the patch found in the patches directory,
63 then export CFLAGS as following before rebuilding pacman:
64 export CFLAGS=-DNOFAKEROOT
70 pactest will run the suite of tests defined by the "--test" parameter.
73 ./pactest.py --test=test/*
75 This example will run tests from the "test" directory.
76 Note: several "--test" options can be passed to pactest.
78 Use the ""help" option to get the full list of parameters:
85 The test environment is described by the following basic parameters:
90 A short string describing the aim of the test case. It is displayed on the
91 standard output during test execution.
96 A string of arguments that are passed to the pacman binary when the test is
100 self.args = "-S dummy"
105 A dictionary that holds the data used in the pacman configuration file.
106 It has 3 keys, each one of them pointing at a list of strings:
112 self.option["noupgrade"] = ["etc/X11/xorg.conf",
114 self.option["noextract"] = ["etc/lilo.conf"]
119 A list of strings describing a set of files supposed to exist in the filesystem
120 when the test case is run.
121 Upon test startup, pactest will automatically populate the test environment
122 filesystem with this list of files.
125 self.filesystem = ["bin/dummy",
126 "etc/X11/xorg.conf.pacsave"]
128 Note that all paths are relative ones, and thus file names should not start
135 The test case file description shall define a number of packages that can be
136 used to either populate a database, or to feed pacman with data needed during
139 This can be achieved by creating pmpkg objects, with the following constructor:
142 Both "name" and "version" are strings. Also, note that if not provided, the
143 version defaults to "1.0-1".
146 pkg1 = pmpkg("dummy", "2.1-1")
147 pkg2 = pmpkg("foobar")
149 All fields from a ArchLinux package can be set and modified directly with no
150 methods to access them.
151 Note: some fields are automatically set by pactest and should preferably not
152 be modified by hand (i.e. "md5sum", "size", or "csize").
155 pkg.depends = ["pkg2", "pkg3>=2.0"]
156 pkg.files = ["bin/dummy", "etc/dummy.conf", "usr/man/man1/dummy.1"]
162 The test environment provides a way to create and fill databases (local or
165 The following methods shall be used:
167 * addpkg2db(database, package)
169 Notes: "database" is a string, and "package" shall be a previously created
173 self.addpkg2db("local", lpkg)
174 self.addpkg2db("sync1", spkg11)
175 self.addpkg2db("sync1", spkg12)
176 self.addpkg2db("sync2", spkg21)
178 Note: there is no need to explicitly create a database. The "local" one
179 already exists (even if empty), and sync databases are created on the fly when
180 a new database new is given.
184 package is an existing pmpkg object.
185 It creates a package archive based on the given object. The resulting archive
186 is located in the temporary directory of the test environment, ready to be
187 supplied to pacman for test purposes.
193 All files created by pactest are filled with a content defaulting to the file
194 name, with an additional line feed.
195 For instance, the content of a file "bin/dummy" created in the test environment
196 file system is: "bin/dummy\n".
198 It is possible to create directories by appending a slash "/" to the name and
199 to create symlinks by appending an arrow followed by a filename " -> target".
201 Note: only relative symlinks are supported.
205 pkg.files = ["bin/dummy",
208 "lib/libfoo.so -> ./libfoo.so.0"]
210 In this example, "usr/local/" is a directory, and "libfoo.so" will be a
211 symlink pointing at "libfoo.so.0". It is usually a good idea to also define
212 the target of the symlink!
214 It can be interesting for some tests to create altered files. This can be
215 done by appending one or more asterisks "*" to the file name.
218 lpkg = pmpkg("dummy")
219 lpkg.files = ["bin/dummy"]
220 self.addpkg2db("local", lpkg)
222 newpkg = pmpkg("dummy", "1.0-2")
223 newpkg.files = ["bin/dummy*"]
226 self.args = "-U dummy-1.0-2.pkg.tar.gz"
228 In this case, package "lpkg" will install a file "bin/dummy" with "bin/dummy\n"
229 as its content. Upon package upgrade, newpkg will provide a file named
230 "bin/dummy" with "bin/dummy*\n" as its content.
231 This is useful to simulate that a file has been modified between two different
232 releases of a same package.
234 The same also applies to files from the "filesystem" parameter of the test
235 environment, and to the "backup" attribute of a package object.
241 Finally, to check test success or failure, one shall define a set of rules.
246 A rule is a string composed by a key and an item, joined with a "=" symbol.
249 self.addrule("PACMAN_RETCODE=0")
250 self.addrule("PKG_EXIST=dummy")
251 self.addrule("FILE_MODIFIED=bin/dummy")
252 self.addrule("PKG_DEPENDS=xorg|fontconfig")
254 Note: an item can be divided into two arguments, as shown in the latter
257 All rules can be prepended with a bang "!" in order to tell pactest to expect
258 the exact opposite result.
261 self.addrule("!FILE_MODIFIED=bin/dummy")
263 Finally, the following rules are supported:
272 For RETCODE, pactest will ensure the pacman return code is the value given.
273 For OUTPUT, pactest will grep pacman outputs for the given value.
275 Note: PACMAN_OUTPUT should not be used. Pacman outputs are likely to change
276 from one release to another, so that it's reliability is quite low.
280 For each rule, pactest will read the entry "name" from the local database and
281 challenge the requested data with it.
287 PKG_VERSION=name|version
288 PKG_GROUPS=name|group
289 PKG_PROVIDES=name|providename
290 PKG_DEPENDS=name|depname
291 PKG_OPTDEPENDS=name|depname
292 PKG_REASON=name|intvalue
293 PKG_FILES=name|filename
294 PKG_BACKUP=name|backupname
297 PKG_DEPENDS=ncurses|glibc
299 pactest will test to ensure the local database entry "ncurses" has "glibc" in
304 FILE_EXIST=path/to/file
305 FILE_MODIFIED=path/to/file
306 FILE_MODE=path/to/file|octal
307 FILE_TYPE=path/to/file|type (possible types: dir, file, link)
308 FILE_PACNEW=path/to/file
309 FILE_PACSAVE=path/to/file
310 FILE_PACORIG=path/to/file
313 FILE_EXIST=etc/test.conf
315 pactest will ensure the file /etc/test.conf exists in the filesystem.