]> git.saurik.com Git - apt.git/blame - test/integration/test-no-fds-leaked-to-maintainer-scripts
correct cross & disappear progress detection
[apt.git] / test / integration / test-no-fds-leaked-to-maintainer-scripts
CommitLineData
9fc0b435
DK
1#!/bin/sh
2set -e
3
3abb6a6a
DK
4TESTDIR="$(readlink -f "$(dirname "$0")")"
5. "$TESTDIR/framework"
9fc0b435
DK
6
7setupenvironment
e18f6133 8configarchitecture 'amd64' 'i386'
9fc0b435
DK
9configdpkgnoopchroot
10
8683da61
JAK
11if [ ! -e /proc/self/fd ]; then
12 msgskip "needs /proc/self/fd"
13 exit 0
14fi
15
299aea92 16setupsimplenativepackage "fdleaks" 'all' '1.0' 'unstable'
9fc0b435
DK
17BUILDDIR="incoming/fdleaks-1.0"
18for script in 'preinst' 'postinst' 'prerm' 'postrm'; do
748a2177
DK
19 cat > ${BUILDDIR}/debian/$script << EOF
20#!/bin/sh
3abb6a6a 21if [ -e '$(pwd)/rootdir/tmp/read_stdin' ]; then
748a2177
DK
22 read line;
23 echo "STDIN: -\$line-"
24fi
25ls -l /proc/self/fd/
26EOF
9fc0b435
DK
27done
28buildpackage "$BUILDDIR" 'unstable' 'main' 'native'
29rm -rf "$BUILDDIR"
30
e18f6133 31PKGNAME='fdleaks:all'
03ae49ac 32if dpkg --compare-versions "$(dpkg_version)" 'lt' '1.16.2'; then
e18f6133
DK
33 PKGNAME='fdleaks'
34fi
35
9fc0b435
DK
36setupaptarchive
37
299aea92
DK
38rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log
39testsuccess aptget install -y fdleaks -qq < /dev/null
9fc0b435 40
e18f6133 41checkfdleak() {
7ec34330 42 msgtest 'Check if fds were not' "leaked: expect $1"
e18f6133
DK
43 if [ "$(grep 'root root' rootdir/tmp/testsuccess.output | wc -l)" = "$1" ]; then
44 msgpass
45 else
46 echo
47 cat rootdir/tmp/testsuccess.output
48 msgfail
49 fi
50}
51checkinstall() {
52 checkfdleak 8
53
54 cp rootdir/tmp/testsuccess.output terminal.output
55 tail -n +3 rootdir/var/log/apt/term.log | head -n -1 > terminal.log
56 testfileequal 'terminal.log' "$(cat terminal.output)"
299aea92 57
e18f6133
DK
58 testequal "startup archives unpack
59install $PKGNAME <none> 1.0
60status half-installed $PKGNAME 1.0
61status unpacked $PKGNAME 1.0
62status unpacked $PKGNAME 1.0
299aea92 63startup packages configure
e18f6133
DK
64configure $PKGNAME 1.0 <none>
65status unpacked $PKGNAME 1.0
66status half-configured $PKGNAME 1.0
b4450f1d 67status installed $PKGNAME 1.0" cut -f 3- -d' ' rootdir/var/log/dpkg.log
e18f6133
DK
68}
69checkinstall
299aea92
DK
70
71rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log
72testsuccess aptget purge -y fdleaks -qq
e18f6133
DK
73checkpurge() {
74 checkfdleak 12
75
76 cp rootdir/tmp/testsuccess.output terminal.output
77 tail -n +3 rootdir/var/log/apt/term.log | head -n -1 > terminal.log
78 testfileequal 'terminal.log' "$(cat terminal.output)"
79
9444da76
DK
80 if dpkg --compare-versions "$(dpkg_version)" 'ge' '1.18.11'; then
81 testequal "startup packages remove
82status installed $PKGNAME 1.0
83remove $PKGNAME 1.0 <none>
84status half-configured $PKGNAME 1.0
85status half-installed $PKGNAME 1.0
86status config-files $PKGNAME 1.0
87status config-files $PKGNAME 1.0
88startup packages configure
89startup packages purge
90purge $PKGNAME 1.0 <none>
91status config-files $PKGNAME 1.0
92status config-files $PKGNAME 1.0
93status config-files $PKGNAME 1.0
94status config-files $PKGNAME 1.0
95status config-files $PKGNAME 1.0
96status not-installed $PKGNAME <none>
97startup packages configure" cut -f 3- -d' ' rootdir/var/log/dpkg.log
98 else
99 testequal "startup packages remove
28557f94 100status installed $PKGNAME 1.0
e18f6133
DK
101remove $PKGNAME 1.0 <none>
102status half-configured $PKGNAME 1.0
103status half-installed $PKGNAME 1.0
104status config-files $PKGNAME 1.0
28557f94 105status config-files $PKGNAME 1.0
fb51ce32 106startup packages configure
28557f94
DK
107startup packages purge
108remove $PKGNAME 1.0 <none>
e18f6133
DK
109purge $PKGNAME 1.0 <none>
110status config-files $PKGNAME 1.0
111status config-files $PKGNAME 1.0
112status config-files $PKGNAME 1.0
113status config-files $PKGNAME 1.0
114status config-files $PKGNAME 1.0
a2a75ff4
DK
115status not-installed $PKGNAME <none>
116startup packages configure" cut -f 3- -d' ' rootdir/var/log/dpkg.log
9444da76 117 fi
7ec34330 118 testequalor2 "dpkg-query: no packages found matching ${PKGNAME}" "No packages found matching ${PKGNAME}." dpkg -l "$PKGNAME"
e18f6133
DK
119}
120checkpurge
121
122msgtest 'setsid provided is new enough to support' '-w'
123if dpkg-checkbuilddeps -d 'util-linux (>= 2.24.2-1)' /dev/null >/dev/null 2>&1; then
9fc0b435
DK
124 msgpass
125else
e18f6133
DK
126 msgskip "$(command dpkg -l util-linux)"
127 exit
9fc0b435 128fi
299aea92 129
e18f6133
DK
130rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log
131testsuccess runapt command setsid -w "${BUILDDIRECTORY}/apt-get" install -y fdleaks -qq < /dev/null
132checkinstall
133
134rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log
135testsuccess runapt command setsid -w "${BUILDDIRECTORY}/apt-get" purge -y fdleaks -qq
136checkpurge
748a2177
DK
137
138touch rootdir/tmp/read_stdin
139
140rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log
141for i in $(seq 1 10); do echo "$i"; done | testsuccess aptget install -y fdleaks -qq
142checkinstall
143testequal '2' grep -c '^STDIN: ' rootdir/var/log/apt/term.log
144
145rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log
146yes '' | testsuccess runapt command setsid -w "${BUILDDIRECTORY}/apt-get" purge -y fdleaks -qq
147checkpurge
148testequal '3' grep -c '^STDIN: ' rootdir/var/log/apt/term.log