]>
Commit | Line | Data |
---|---|---|
9fc0b435 DK |
1 | #!/bin/sh |
2 | set -e | |
3 | ||
3abb6a6a DK |
4 | TESTDIR="$(readlink -f "$(dirname "$0")")" |
5 | . "$TESTDIR/framework" | |
9fc0b435 DK |
6 | |
7 | setupenvironment | |
e18f6133 | 8 | configarchitecture 'amd64' 'i386' |
9fc0b435 DK |
9 | configdpkgnoopchroot |
10 | ||
8683da61 JAK |
11 | if [ ! -e /proc/self/fd ]; then |
12 | msgskip "needs /proc/self/fd" | |
13 | exit 0 | |
14 | fi | |
15 | ||
299aea92 | 16 | setupsimplenativepackage "fdleaks" 'all' '1.0' 'unstable' |
9fc0b435 DK |
17 | BUILDDIR="incoming/fdleaks-1.0" |
18 | for script in 'preinst' 'postinst' 'prerm' 'postrm'; do | |
748a2177 DK |
19 | cat > ${BUILDDIR}/debian/$script << EOF |
20 | #!/bin/sh | |
3abb6a6a | 21 | if [ -e '$(pwd)/rootdir/tmp/read_stdin' ]; then |
748a2177 DK |
22 | read line; |
23 | echo "STDIN: -\$line-" | |
24 | fi | |
25 | ls -l /proc/self/fd/ | |
26 | EOF | |
9fc0b435 DK |
27 | done |
28 | buildpackage "$BUILDDIR" 'unstable' 'main' 'native' | |
29 | rm -rf "$BUILDDIR" | |
30 | ||
e18f6133 | 31 | PKGNAME='fdleaks:all' |
03ae49ac | 32 | if dpkg --compare-versions "$(dpkg_version)" 'lt' '1.16.2'; then |
e18f6133 DK |
33 | PKGNAME='fdleaks' |
34 | fi | |
35 | ||
9fc0b435 DK |
36 | setupaptarchive |
37 | ||
299aea92 DK |
38 | rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log |
39 | testsuccess aptget install -y fdleaks -qq < /dev/null | |
9fc0b435 | 40 | |
e18f6133 | 41 | checkfdleak() { |
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 | } | |
51 | checkinstall() { | |
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 |
59 | install $PKGNAME <none> 1.0 | |
60 | status half-installed $PKGNAME 1.0 | |
61 | status unpacked $PKGNAME 1.0 | |
62 | status unpacked $PKGNAME 1.0 | |
299aea92 | 63 | startup packages configure |
e18f6133 DK |
64 | configure $PKGNAME 1.0 <none> |
65 | status unpacked $PKGNAME 1.0 | |
66 | status half-configured $PKGNAME 1.0 | |
b4450f1d | 67 | status installed $PKGNAME 1.0" cut -f 3- -d' ' rootdir/var/log/dpkg.log |
e18f6133 DK |
68 | } |
69 | checkinstall | |
299aea92 DK |
70 | |
71 | rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log | |
72 | testsuccess aptget purge -y fdleaks -qq | |
e18f6133 DK |
73 | checkpurge() { |
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 | ||
28557f94 DK |
80 | testequal "startup packages remove |
81 | status installed $PKGNAME 1.0 | |
e18f6133 DK |
82 | remove $PKGNAME 1.0 <none> |
83 | status half-configured $PKGNAME 1.0 | |
84 | status half-installed $PKGNAME 1.0 | |
85 | status config-files $PKGNAME 1.0 | |
28557f94 | 86 | status config-files $PKGNAME 1.0 |
fb51ce32 | 87 | startup packages configure |
28557f94 DK |
88 | startup packages purge |
89 | remove $PKGNAME 1.0 <none> | |
e18f6133 DK |
90 | purge $PKGNAME 1.0 <none> |
91 | status config-files $PKGNAME 1.0 | |
92 | status config-files $PKGNAME 1.0 | |
93 | status config-files $PKGNAME 1.0 | |
94 | status config-files $PKGNAME 1.0 | |
95 | status config-files $PKGNAME 1.0 | |
a2a75ff4 DK |
96 | status not-installed $PKGNAME <none> |
97 | startup packages configure" cut -f 3- -d' ' rootdir/var/log/dpkg.log | |
7ec34330 | 98 | testequalor2 "dpkg-query: no packages found matching ${PKGNAME}" "No packages found matching ${PKGNAME}." dpkg -l "$PKGNAME" |
e18f6133 DK |
99 | } |
100 | checkpurge | |
101 | ||
102 | msgtest 'setsid provided is new enough to support' '-w' | |
103 | if dpkg-checkbuilddeps -d 'util-linux (>= 2.24.2-1)' /dev/null >/dev/null 2>&1; then | |
9fc0b435 DK |
104 | msgpass |
105 | else | |
e18f6133 DK |
106 | msgskip "$(command dpkg -l util-linux)" |
107 | exit | |
9fc0b435 | 108 | fi |
299aea92 | 109 | |
e18f6133 DK |
110 | rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log |
111 | testsuccess runapt command setsid -w "${BUILDDIRECTORY}/apt-get" install -y fdleaks -qq < /dev/null | |
112 | checkinstall | |
113 | ||
114 | rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log | |
115 | testsuccess runapt command setsid -w "${BUILDDIRECTORY}/apt-get" purge -y fdleaks -qq | |
116 | checkpurge | |
748a2177 DK |
117 | |
118 | touch rootdir/tmp/read_stdin | |
119 | ||
120 | rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log | |
121 | for i in $(seq 1 10); do echo "$i"; done | testsuccess aptget install -y fdleaks -qq | |
122 | checkinstall | |
123 | testequal '2' grep -c '^STDIN: ' rootdir/var/log/apt/term.log | |
124 | ||
125 | rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log | |
126 | yes '' | testsuccess runapt command setsid -w "${BUILDDIRECTORY}/apt-get" purge -y fdleaks -qq | |
127 | checkpurge | |
128 | testequal '3' grep -c '^STDIN: ' rootdir/var/log/apt/term.log |