]> git.saurik.com Git - apt.git/blame_incremental - test/integration/framework
extend the magic which creates the test archive by using FileLists to
[apt.git] / test / integration / framework
... / ...
CommitLineData
1#!/bin/sh -- # no runable script, just for vi
2
3# we all like colorful messages
4CERROR="\e[1;31m" # red
5CWARNING="\e[1;33m" # yellow
6CMSG="\e[1;32m" # green
7CINFO="\e[1;96m" # light blue
8CDEBUG="\e[1;94m" # blue
9CNORMAL="\e[0;39m" # default system console color
10CDONE="\e[1;32m" # green
11CPASS="\e[1;32m" # green
12CFAIL="\e[1;31m" # red
13CCMD="\e[1;35m" # pink
14
15msgdie() { echo "${CERROR}E: $1${CNORMAL}" >&2; exit 1; }
16msgwarn() { echo "${CWARNING}W: $1${CNORMAL}" >&2; }
17msgmsg() { echo "${CMSG}$1${CNORMAL}" >&2; }
18msginfo() { echo "${CINFO}I: $1${CNORMAL}" >&2; }
19msgdebug() { echo "${CDEBUG}D: $1${CNORMAL}" >&2; }
20msgdone() { echo "${CDONE}DONE${CNORMAL}" >&2; }
21msgnwarn() { echo -n "${CWARNING}W: $1${CNORMAL}" >&2; }
22msgnmsg() { echo -n "${CMSG}$1${CNORMAL}" >&2; }
23msgninfo() { echo -n "${CINFO}I: $1${CNORMAL}" >&2; }
24msgndebug() { echo -n "${CDEBUG}D: $1${CNORMAL}" >&2; }
25msgtest() { echo -n "${CINFO}$1 ${CCMD}$(echo "$2" | sed -e 's/^aptc/apt-c/' -e 's/^aptg/apt-g/' -e 's/^aptf/apt-f/')${CINFO} …${CNORMAL} " >&2; }
26msgpass() { echo "${CPASS}PASS${CNORMAL}" >&2; }
27msgskip() { echo "${CWARNING}SKIP${CNORMAL}" >&2; }
28msgfail() { echo "${CFAIL}FAIL${CNORMAL}" >&2; }
29
30# enable / disable Debugging
31MSGLEVEL=${MSGLEVEL:-3}
32if [ $MSGLEVEL -le 0 ]; then
33 msgdie() { true; }
34fi
35if [ $MSGLEVEL -le 1 ]; then
36 msgwarn() { true; }
37 msgnwarn() { true; }
38fi
39if [ $MSGLEVEL -le 2 ]; then
40 msgmsg() { true; }
41 msgnmsg() { true; }
42fi
43if [ $MSGLEVEL -le 3 ]; then
44 msginfo() { true; }
45 msgninfo() { true; }
46fi
47if [ $MSGLEVEL -le 4 ]; then
48 msgdebug() { true; }
49 msgndebug() { true; }
50fi
51msgdone() {
52 if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] ||
53 [ "$1" = "info" -a $MSGLEVEL -le 3 ] ||
54 [ "$1" = "msg" -a $MSGLEVEL -le 2 ] ||
55 [ "$1" = "warn" -a $MSGLEVEL -le 1 ] ||
56 [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then
57 true;
58 else
59 echo "${CDONE}DONE${CNORMAL}" >&2;
60 fi
61}
62
63runapt() {
64 msgdebug "Executing: ${CCMD}$*${CDEBUG} "
65 if [ -f ./aptconfig.conf ]; then
66 APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$*
67 else
68 LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$*
69 fi
70}
71aptconfig() { runapt apt-config $*; }
72aptcache() { runapt apt-cache $*; }
73aptget() { runapt apt-get $*; }
74aptftparchive() { runapt apt-ftparchive $*; }
75
76setupenvironment() {
77 local TMPWORKINGDIRECTORY=$(mktemp -d)
78 local TESTDIR=$(readlink -f $(dirname $0))
79 msgninfo "Preparing environment for ${CCMD}$0${CINFO} in ${TMPWORKINGDIRECTORY}… "
80 BUILDDIRECTORY="${TESTDIR}/../../build/bin"
81 test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first"
82 local OLDWORKINGDIRECTORY=$(pwd)
83 trap "cd /; rm -rf $TMPWORKINGDIRECTORY; cd $OLDWORKINGDIRECTORY" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
84 cd $TMPWORKINGDIRECTORY
85 mkdir rootdir aptarchive
86 cd rootdir
87 mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d var/cache var/lib/dpkg
88 mkdir -p var/cache/apt/archives/partial var/lib/apt/lists/partial
89 local STATUSFILE=$(echo "$(basename $0)" | sed 's/^test-/status-/')
90 if [ -f "${TESTDIR}/${STATUSFILE}" ]; then
91 cp "${TESTDIR}/${STATUSFILE}" var/lib/dpkg/status
92 else
93 touch var/lib/dpkg/status
94 fi
95 mkdir -p usr/lib/apt
96 ln -s ${BUILDDIRECTORY}/methods usr/lib/apt/methods
97 cd ..
98 local PACKAGESFILE=$(echo "$(basename $0)" | sed 's/^test-/Packages-/')
99 if [ -f "${TESTDIR}/${PACKAGESFILE}" ]; then
100 cp "${TESTDIR}/${PACKAGESFILE}" aptarchive/Packages
101 else
102 touch aptarchive/Packages
103 fi
104 echo "RootDir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
105 echo "Debug::NoLocking \"true\";" >> aptconfig.conf
106 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
107 export LC_ALL=C
108 msgdone "info"
109}
110
111configarchitecture() {
112 local CONFFILE=rootdir/etc/apt/apt.conf.d/01multiarch.conf
113 echo "APT::Architecture \"$1\";" > $CONFFILE
114 shift
115 while [ -n "$1" ]; do
116 echo "APT::Architectures:: \"$1\";" >> $CONFFILE
117 shift
118 done
119}
120
121buildsimplenativepackage() {
122 local NAME="$1"
123 local ARCH="$2"
124 local VERSION="$3"
125 local RELEASE="${4:-unstable}"
126 local DEPENDENCIES="$5"
127 local DESCRIPTION="$6"
128 local SECTION="${7:-others}"
129 local DISTSECTION
130 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
131 DISTSECTION="main"
132 else
133 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
134 fi
135 msgndebug "Build package ${CCMD}${NAME}=${VERSION}/${RELEASE}${CDEBUG}… "
136 local BUILDDIR=incoming/${NAME}-${VERSION}
137 mkdir -p ${BUILDDIR}/debian/source
138 cd ${BUILDDIR}
139 echo "* most suckless software product ever" > FEATURES
140 test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright
141 test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low
142
143 * Initial release
144
145 -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog
146 test -e debian/control || echo "Source: $NAME
147Section: $SECTION
148Priority: optional
149Maintainer: Joe Sixpack <joe@example.org>
150Build-Depends: debhelper (>= 7)
151Standards-Version: 3.9.1
152
153Package: $NAME
154Architecture: $ARCH" > debian/control
155 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
156 if [ -z "$DESCRIPTION" ]; then
157 echo "Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
158 If you find such a package installed on your system,
159 YOU did something horribly wrong! They are autogenerated
160 und used only by testcases for APT and surf no other propose…" >> debian/control
161 else
162 echo "Description: $DESCRIPTION" >> debian/control
163 fi
164 test -e debian/compat || echo "7" > debian/compat
165 test -e debian/source/format || echo "3.0 (native)" > debian/source/format
166 test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
167 local BUILT="$(dpkg-buildpackage -uc -us -a$ARCH 2> /dev/null)"
168 local PKGS="$( echo "$BUILT" | grep '^dpkg-deb: building package' | cut -d'/' -f 2 | sed -e "s#'\.##")"
169 local SRCS="$( echo "$BUILT" | grep '^dpkg-source: info: building' | grep -o '[a-z0-9._-]*$')"
170 cd - > /dev/null
171 for PKG in $PKGS; do
172 echo "pool/${PKG}" >> ./incoming/${RELEASE}.${DISTSECTION}.pkglist
173 done
174 for SRC in $SRCS; do
175 echo "pool/${SRC}" >> ./incoming/${RELEASE}.${DISTSECTION}.srclist
176 done
177 rm -rf $BUILDDIR
178 msgdone "debug"
179}
180
181buildaptarchive() {
182 if [ -d incoming ]; then
183 buildaptarchivefromincoming $*
184 else
185 buildaptarchivefromfiles $*
186 fi
187}
188
189createaptftparchiveconfig() {
190 local ARCHS="$(find pool/ -name '*.deb' | grep -oE '_[a-z0-9-]+\.deb$' | sort | uniq | sed -e '/^_all.deb$/ d' -e 's#^_\([a-z0-9-]*\)\.deb$#\1#' | tr '\n' ' ')"
191 echo -n 'Dir {
192 ArchiveDir "' >> ftparchive.conf
193 echo -n $(readlink -f .) >> ftparchive.conf
194 echo -n '";
195 CacheDir "' >> ftparchive.conf
196 echo -n $(readlink -f ..) >> ftparchive.conf
197 echo -n '";
198 FileListDir "' >> ftparchive.conf
199 echo -n $(readlink -f pool/) >> ftparchive.conf
200 echo -n '";
201};
202Default {
203 Packages::Compress ". gzip bzip2 lzma";
204 Sources::Compress ". gzip bzip2 lzma";
205 Contents::Compress ". gzip bzip2 lzma";
206};
207TreeDefault {
208 Directory "pool/";
209 SrcDirectory "pool/";
210};
211APT {
212 FTPArchive {
213 Release {
214 Origin "joesixpack";
215 Label "apttestcases";
216 Suite "unstable";
217 Description "repository with dummy packages";
218 Architectures "' >> ftparchive.conf
219 echo -n "$ARCHS" >> ftparchive.conf
220 echo 'source";
221 };
222 };
223};' >> ftparchive.conf
224 for DIST in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
225 echo -n 'tree "dists/' >> ftparchive.conf
226 echo -n "$DIST" >> ftparchive.conf
227 echo -n '" {
228 Architectures "' >> ftparchive.conf
229 echo -n "$ARCHS" >> ftparchive.conf
230 echo -n 'source";
231 FileList "' >> ftparchive.conf
232 echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
233 echo -n '";
234 SourceFileList "' >> ftparchive.conf
235 echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
236 echo -n '";
237 Sections "' >> ftparchive.conf
238 echo -n "$(find ./pool/ -maxdepth 1 -name "${DIST}.*.pkglist" -type f | cut -d'/' -f 3 | cut -d'.' -f 2 | sort | uniq | tr '\n' ' ')" >> ftparchive.conf
239 echo '";
240};' >> ftparchive.conf
241 done
242 less ftparchive.conf
243}
244
245buildaptftparchivedirectorystructure() {
246 local DISTS="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
247 for DIST in $DISTS; do
248 local SECTIONS="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
249 for SECTION in $SECTIONS; do
250 local ARCHS="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
251 for ARCH in $ARCHS; do
252 mkdir -p dists/${DIST}/${SECTION}/binary-${ARCH}
253 done
254 mkdir -p dists/${DIST}/${SECTION}/source
255 mkdir -p dists/${DIST}/${SECTION}/i18n
256 done
257 done
258}
259
260buildaptarchivefromincoming() {
261 msginfo "Build APT archive for ${CCMD}$0${CINFO} based on incoming packages…"
262 cd aptarchive
263 [ -e pool ] || ln -s ../incoming pool
264 [ -e ftparchive.conf ] || createaptftparchiveconfig
265 [ -e dists ] || buildaptftparchivedirectorystructure
266 msgninfo "\tGenerate Packages, Sources and Contents files… "
267 aptftparchive -qq generate ftparchive.conf
268 msgdone "info"
269 msgninfo "\tGenerate Release files… "
270 for dir in $(find ./dists -mindepth 1 -maxdepth 1 -type d); do
271 aptftparchive -qq release $dir | sed -e '/0 Release$/ d' > $dir/Release # remove the self reference
272 done
273 cd - > /dev/null
274 msgdone "info"
275}
276
277buildaptarchivefromfiles() {
278 msginfo "Build APT archive for ${CCMD}$0${CINFO} based on prebuild files…"
279 cd aptarchive
280 if [ -f Packages ]; then
281 msgninfo "\tPackages file… "
282 cat Packages | gzip > Packages.gz
283 cat Packages | bzip2 > Packages.bz2
284 cat Packages | lzma > Packages.lzma
285 msgdone "info"
286 fi
287 if [ -f Sources ]; then
288 msgninfo "\tSources file… "
289 cat Sources | gzip > Sources.gz
290 cat Sources | bzip2 > Sources.bz2
291 cat Sources | lzma > Sources.lzma
292 msgdone "info"
293 fi
294 msgninfo "\tRelease file… "
295 aptftparchive -qq release . | sed -e '/0 Release$/ d' > Release # remove the self reference
296 msgdone "info"
297 cd ..
298}
299
300setupdistsaptarchive() {
301 local APTARCHIVE=$(readlink -f ./aptarchive)
302 rm -f root/etc/apt/sources.list.d/apt-test-*-deb.list
303 rm -f root/etc/apt/sources.list.d/apt-test-*-deb-src.list
304 for DISTS in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
305 SECTIONS=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
306 msgninfo "\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
307 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list
308 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list
309 msgdone "info"
310 done
311}
312
313setupflataptarchive() {
314 local APTARCHIVE=$(readlink -f ./aptarchive)
315 if [ -f ${APTARCHIVE}/Packages ]; then
316 msgninfo "\tadd deb sources.list line… "
317 echo "deb file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
318 msgdone "info"
319 else
320 rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
321 fi
322 if [ -f ${APTARCHIVE}/Sources ]; then
323 msgninfo "\tadd deb-src sources.list line… "
324 echo "deb-src file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
325 msgdone "info"
326 else
327 rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
328 fi
329}
330
331setupaptarchive() {
332 buildaptarchive
333 if [ -e aptarchive/dists ]; then
334 setupdistsaptarchive
335 else
336 setupflataptarchive
337 fi
338 aptget update -qq
339}
340
341diff() {
342 local DIFFTEXT="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
343 if [ -n "$DIFFTEXT" ]; then
344 echo
345 echo "$DIFFTEXT"
346 return 1
347 else
348 return 0
349 fi
350}
351
352testequal() {
353 local COMPAREFILE=$(mktemp)
354 echo "$1" > $COMPAREFILE
355 shift
356 msgtest "Test for equality of" "$*"
357 $* 2>&1 | diff $COMPAREFILE - && msgpass || msgfail
358 rm $COMPAREFILE
359}
360
361testequalor2() {
362 local COMPAREFILE1=$(mktemp)
363 local COMPAREFILE2=$(mktemp)
364 local COMPAREAGAINST=$(mktemp)
365 echo "$1" > $COMPAREFILE1
366 echo "$2" > $COMPAREFILE2
367 shift 2
368 msgtest "Test for equality OR of" "$*"
369 $* 2>&1 1> $COMPAREAGAINST
370 (diff $COMPAREFILE1 $COMPAREAGAINST 1> /dev/null ||
371 diff $COMPAREFILE2 $COMPAREAGAINST 1> /dev/null) && msgpass ||
372 ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(diff $COMPAREFILE1 $COMPAREAGAINST)" \
373 "\n${CINFO}Diff against OR 2${CNORMAL}" "$(diff $COMPAREFILE2 $COMPAREAGAINST)" &&
374 msgfail )
375 rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST
376}
377
378testshowvirtual() {
379 local VIRTUAL="N: Can't select versions from package '$1' as it purely virtual"
380 local PACKAGE="$1"
381 shift
382 while [ -n "$1" ]; do
383 VIRTUAL="${VIRTUAL}
384N: Can't select versions from package '$1' as it purely virtual"
385 PACKAGE="${PACKAGE} $1"
386 shift
387 done
388 msgtest "Test for virtual packages" "apt-cache show $PACKAGE"
389 VIRTUAL="${VIRTUAL}
390N: No packages found"
391 local COMPAREFILE=$(mktemp)
392 local ARCH=$(dpkg-architecture -qDEB_HOST_ARCH_CPU)
393 eval `apt-config shell ARCH APT::Architecture`
394 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
395 aptcache show $PACKAGE 2>&1 | diff $COMPAREFILE - && msgpass || msgfail
396 rm $COMPAREFILE
397}
398
399testnopackage() {
400 msgtest "Test for non-existent packages" "apt-cache show $*"
401 local SHOWPKG="$(aptcache show $* 2>&1 | grep '^Package: ')"
402 if [ -n "$SHOWPKG" ]; then
403 echo
404 echo "$SHOWPKG"
405 msgfail
406 return 1
407 fi
408 msgpass
409}