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