always run 'dpkg --configure -a' at the end of our dpkg callings
[ntk/apt.git] / test / integration / test-no-fds-leaked-to-maintainer-scripts
CommitLineData
9fc0b435
DK
1#!/bin/sh
2set -e
3
4TESTDIR=$(readlink -f $(dirname $0))
5. $TESTDIR/framework
6
7setupenvironment
e18f6133 8configarchitecture 'amd64' 'i386'
9fc0b435
DK
9configdpkgnoopchroot
10
299aea92 11setupsimplenativepackage "fdleaks" 'all' '1.0' 'unstable'
9fc0b435
DK
12BUILDDIR="incoming/fdleaks-1.0"
13for script in 'preinst' 'postinst' 'prerm' 'postrm'; do
14 echo '#!/bin/sh
15ls -l /proc/self/fd/' > ${BUILDDIR}/debian/$script
16done
17buildpackage "$BUILDDIR" 'unstable' 'main' 'native'
18rm -rf "$BUILDDIR"
19
e18f6133
DK
20PKGNAME='fdleaks:all'
21if ! dpkg-checkbuilddeps -d 'dpkg (>= 1.16.2)' /dev/null >/dev/null 2>&1; then
22 PKGNAME='fdleaks'
23fi
24
9fc0b435
DK
25setupaptarchive
26
299aea92
DK
27rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log
28testsuccess aptget install -y fdleaks -qq < /dev/null
9fc0b435 29
e18f6133
DK
30checkfdleak() {
31 msgtest 'Check if fds were not' 'leaked'
32 if [ "$(grep 'root root' rootdir/tmp/testsuccess.output | wc -l)" = "$1" ]; then
33 msgpass
34 else
35 echo
36 cat rootdir/tmp/testsuccess.output
37 msgfail
38 fi
39}
40checkinstall() {
41 checkfdleak 8
42
43 cp rootdir/tmp/testsuccess.output terminal.output
44 tail -n +3 rootdir/var/log/apt/term.log | head -n -1 > terminal.log
45 testfileequal 'terminal.log' "$(cat terminal.output)"
299aea92 46
e18f6133
DK
47 testequal "startup archives unpack
48install $PKGNAME <none> 1.0
49status half-installed $PKGNAME 1.0
50status unpacked $PKGNAME 1.0
51status unpacked $PKGNAME 1.0
299aea92 52startup packages configure
e18f6133
DK
53configure $PKGNAME 1.0 <none>
54status unpacked $PKGNAME 1.0
55status half-configured $PKGNAME 1.0
a2a75ff4
DK
56status installed $PKGNAME 1.0
57startup packages configure" cut -f 3- -d' ' rootdir/var/log/dpkg.log
e18f6133
DK
58}
59checkinstall
299aea92
DK
60
61rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log
62testsuccess aptget purge -y fdleaks -qq
e18f6133
DK
63checkpurge() {
64 checkfdleak 12
65
66 cp rootdir/tmp/testsuccess.output terminal.output
67 tail -n +3 rootdir/var/log/apt/term.log | head -n -1 > terminal.log
68 testfileequal 'terminal.log' "$(cat terminal.output)"
69
70 testequal "startup packages purge
71status installed $PKGNAME 1.0
72remove $PKGNAME 1.0 <none>
73status half-configured $PKGNAME 1.0
74status half-installed $PKGNAME 1.0
75status config-files $PKGNAME 1.0
76purge $PKGNAME 1.0 <none>
77status config-files $PKGNAME 1.0
78status config-files $PKGNAME 1.0
79status config-files $PKGNAME 1.0
80status config-files $PKGNAME 1.0
81status config-files $PKGNAME 1.0
a2a75ff4
DK
82status not-installed $PKGNAME <none>
83startup packages configure" cut -f 3- -d' ' rootdir/var/log/dpkg.log
e18f6133
DK
84}
85checkpurge
86
87msgtest 'setsid provided is new enough to support' '-w'
88if dpkg-checkbuilddeps -d 'util-linux (>= 2.24.2-1)' /dev/null >/dev/null 2>&1; then
9fc0b435
DK
89 msgpass
90else
e18f6133
DK
91 msgskip "$(command dpkg -l util-linux)"
92 exit
9fc0b435 93fi
299aea92 94
e18f6133
DK
95rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log
96testsuccess runapt command setsid -w "${BUILDDIRECTORY}/apt-get" install -y fdleaks -qq < /dev/null
97checkinstall
98
99rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log
100testsuccess runapt command setsid -w "${BUILDDIRECTORY}/apt-get" purge -y fdleaks -qq
101checkpurge