]> git.saurik.com Git - apt.git/blame - test/integration/test-kernel-helper-autoremove
CMake: Add coverage build type
[apt.git] / test / integration / test-kernel-helper-autoremove
CommitLineData
e5bdcc87 1#!/bin/sh
e5bdcc87
MV
2set -e
3
3abb6a6a
DK
4TESTDIR="$(readlink -f "$(dirname "$0")")"
5. "$TESTDIR/framework"
b9b0f622 6setupenvironment
33677a0c 7configarchitecture 'amd64'
e5bdcc87 8
15134a8e 9CURRENTKERNEL="linux-image-$(uname -r | tr '[A-Z]' '[a-z]')"
3196dae8
DK
10insertinstalledpackage "$CURRENTKERNEL" 'amd64' '5-1'
11# debug packages do not need our protection
12insertinstalledpackage "${CURRENTKERNEL}-dbg" 'amd64' '5-1'
13# but other kernel flavours should be protected
14insertinstalledpackage "${CURRENTKERNEL}-686-pae" 'i386' '5-1'
15insertinstalledpackage "${CURRENTKERNEL}-rt" 'amd64' '5-1'
16# some more versions
33677a0c
DK
17insertinstalledpackage 'linux-image-1.0.0-2-generic' 'amd64' '1.0.0-2'
18insertinstalledpackage 'linux-image-100.0.0-1-generic' 'amd64' '100.0.0-1'
3196dae8
DK
19# kernel metapackages should be ignored
20insertinstalledpackage 'linux-image-amd64' 'amd64' '200-1'
21insertinstalledpackage 'linux-image-686-pae' 'i386' '300-1'
7ce1ac85
DK
22# ensure that the '.' is really a dot and not a wildcard
23insertinstalledpackage 'linux-headers-1000000-1-generic' 'amd64' '100.0.0-1'
130176bc
AP
24# ensure that the '+' is really a plus and not a regexp quantifier
25insertinstalledpackage "${CURRENTKERNEL}+variant" 'amd64' '5-1'
33677a0c 26
3196dae8 27testsuccess aptmark auto "$CURRENTKERNEL" "${CURRENTKERNEL}-dbg" "${CURRENTKERNEL}-686-pae:i386" "${CURRENTKERNEL}-rt" \
130176bc 28 'linux-image-1.0.0-2-generic' 'linux-image-100.0.0-1-generic' 'linux-headers-1000000-1-generic' "${CURRENTKERNEL}+variant"
3196dae8 29testsuccess aptmark hold "${CURRENTKERNEL}-rt"
e5bdcc87 30
b9b0f622
DK
31testprotected() {
32 rm -f rootdir/etc/apt/apt.conf.d/01autoremove-kernels protected.list
e5bdcc87 33
63c71412 34 testsuccess runapt sh "${TESTDIR}/../../debian/apt.auto-removal.sh" "$@"
3196dae8 35 testfailure test -s rootdir/tmp/testsuccess.output
c6918c16 36
b9b0f622 37 msgtest 'Check kernel autoremoval protection list' 'is created'
3196dae8
DK
38 testsuccess --nomsg test -e rootdir/etc/apt/apt.conf.d/01autoremove-kernels
39 testfilestats 'rootdir/etc/apt/apt.conf.d/01autoremove-kernels' '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:444"
c6918c16 40
b9b0f622 41 msgtest 'Check kernel autoremoval protection list' 'can be dumped'
3196dae8
DK
42 testsuccess --nomsg aptconfig dump --no-empty --format '%v%n' 'APT::NeverAutoRemove'
43 cp rootdir/tmp/testsuccess.output protected.list
e5bdcc87 44
b9b0f622 45 msgtest 'Check kernel autoremoval protection list' 'can be parsed'
3196dae8 46 testfailure --nomsg grep '^[A-Z]: ' protected.list
d269b88d 47
b9b0f622 48 msgtest 'Check kernel autoremoval protection list includes' 'most recent kernel'
3196dae8 49 testsuccess --nomsg grep '^\^linux-image-100\\\.0\\\.0-1-generic\$$' protected.list
b9b0f622
DK
50
51 msgtest 'Check kernel autoremoval protection list includes' 'running kernel'
15134a8e 52 testsuccess --nomsg grep "^\\^linux-image-$(uname -r | tr '[A-Z]' '[a-z]' | sed -e 's#\.#\\\\.#g')\\\$\$" protected.list
3196dae8
DK
53
54 msgtest 'Check kernel autoremoval protection list does not include' 'metapackages'
55 testfailure --nomsg grep -e '^\^linux-image-amd64\$$' -e '^\^linux-image-686-pae\$$' -e ':i386' protected.list
b9b0f622
DK
56}
57
73fe49f9
DK
58AUTOREMOVE='apt autoremove'
59if [ -n "$SUDO_USER" ]; then
60 AUTOREMOVE="sudo $AUTOREMOVE"
61fi
25b86db1 62testsuccessequal "Reading package lists...
33677a0c
DK
63Building dependency tree...
64Reading state information...
a0c19a21
DK
65The following packages were automatically installed and are no longer required:
66 linux-headers-1000000-1-generic (100.0.0-1)
67 linux-image-1.0.0-2-generic (1.0.0-2)
68 linux-image-100.0.0-1-generic (100.0.0-1)
3196dae8 69 $CURRENTKERNEL (5-1)
130176bc 70 ${CURRENTKERNEL}+variant (5-1)
3196dae8
DK
71 ${CURRENTKERNEL}-686-pae:i386 (5-1)
72 ${CURRENTKERNEL}-dbg (5-1)
73fe49f9 73Use '$AUTOREMOVE' to remove them.
a0c19a21 740 upgraded, 0 newly installed, 0 to remove and 0 not upgraded." aptget install -sV
3196dae8
DK
75testsuccessequal "Reading package lists...
76Building dependency tree...
77Reading state information...
78The following packages were automatically installed and are no longer required:
79 linux-headers-1000000-1-generic (100.0.0-1)
80 linux-image-1.0.0-2-generic (1.0.0-2)
81 linux-image-100.0.0-1-generic (100.0.0-1)
82 $CURRENTKERNEL (5-1)
130176bc 83 ${CURRENTKERNEL}+variant (5-1)
3196dae8
DK
84 ${CURRENTKERNEL}-686-pae:i386 (5-1)
85 ${CURRENTKERNEL}-dbg (5-1)
86 ${CURRENTKERNEL}-rt (5-1)
73fe49f9 87Use '$AUTOREMOVE' to remove them.
3196dae8 880 upgraded, 0 newly installed, 0 to remove and 0 not upgraded." aptget install -sV --ignore-hold
a0c19a21
DK
89testequal "Reading package lists...
90Building dependency tree...
91Reading state information...
130176bc 927 packages were automatically installed and are no longer required.
73fe49f9 93Use '$AUTOREMOVE' to remove them.
a0c19a21
DK
940 upgraded, 0 newly installed, 0 to remove and 0 not upgraded." aptget install -s -o APT::Get::HideAutoRemove=small
95testequal "Reading package lists...
96Building dependency tree...
97Reading state information...
33677a0c 98The following packages will be REMOVED:
7ce1ac85 99 linux-headers-1000000-1-generic (100.0.0-1)
33677a0c
DK
100 linux-image-1.0.0-2-generic (1.0.0-2)
101 linux-image-100.0.0-1-generic (100.0.0-1)
3196dae8 102 $CURRENTKERNEL (5-1)
130176bc 103 ${CURRENTKERNEL}+variant (5-1)
3196dae8
DK
104 ${CURRENTKERNEL}-686-pae:i386 (5-1)
105 ${CURRENTKERNEL}-dbg (5-1)
130176bc 1060 upgraded, 0 newly installed, 7 to remove and 0 not upgraded.
7ce1ac85 107Remv linux-headers-1000000-1-generic [100.0.0-1]
33677a0c
DK
108Remv linux-image-1.0.0-2-generic [1.0.0-2]
109Remv linux-image-100.0.0-1-generic [100.0.0-1]
3196dae8 110Remv $CURRENTKERNEL [5-1]
130176bc 111Remv ${CURRENTKERNEL}+variant [5-1]
3196dae8
DK
112Remv ${CURRENTKERNEL}-686-pae:i386 [5-1]
113Remv ${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -sV
33677a0c 114
3196dae8 115msgmsg "run without parameter"
b9b0f622
DK
116testprotected
117msgtest 'Check kernel autoremoval protection list does not include' 'old kernel'
3196dae8
DK
118testfailure --nomsg grep '^\^linux-image-1\\\.0\\\.0-2-generic\$$' protected.list
119testsuccessequal "Reading package lists...
120Building dependency tree...
121Reading state information...
122The following packages will be REMOVED:
123 linux-headers-1000000-1-generic linux-image-1.0.0-2-generic
124 ${CURRENTKERNEL}-dbg
1250 upgraded, 0 newly installed, 3 to remove and 0 not upgraded.
126Remv linux-headers-1000000-1-generic [100.0.0-1]
127Remv linux-image-1.0.0-2-generic [1.0.0-2]
128Remv ${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -s
d269b88d 129
3196dae8
DK
130msgmsg "install unknown kernel"
131# even if installed/uname reports a kernel which we can't find via dpkg,
132# ensure that we still protect it just in case as these are kernels we
133# know for sure without complicated detection mechanisms
134testprotected 1.0.0-2-ungeneric
135msgtest 'Check kernel autoremoval protection list does not include' 'old kernel'
136testfailure --nomsg grep '^\^linux-image-1\\\.0\\\.0-2-generic\$$' protected.list
137msgtest 'Check kernel autoremoval protection list does include' 'unknown installed kernel'
138testsuccess --nomsg grep '^\^linux-image-1\\\.0\\\.0-2-ungeneric\$$' protected.list
139testsuccessequal "Reading package lists...
33677a0c
DK
140Building dependency tree...
141Reading state information...
142The following packages will be REMOVED:
7ce1ac85 143 linux-headers-1000000-1-generic linux-image-1.0.0-2-generic
3196dae8
DK
144 ${CURRENTKERNEL}-dbg
1450 upgraded, 0 newly installed, 3 to remove and 0 not upgraded.
7ce1ac85 146Remv linux-headers-1000000-1-generic [100.0.0-1]
3196dae8
DK
147Remv linux-image-1.0.0-2-generic [1.0.0-2]
148Remv ${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -s
33677a0c 149
3196dae8 150msgmsg "install an old kernel"
b9b0f622
DK
151testprotected 1.0.0-2-generic
152msgtest 'Check kernel autoremoval protection list includes' 'installed kernel'
3196dae8
DK
153testsuccess --nomsg grep '^\^linux-image-1\\\.0\\\.0-2-generic\$$' protected.list
154testsuccessequal "Reading package lists...
155Building dependency tree...
156Reading state information...
157The following packages will be REMOVED:
158 linux-headers-1000000-1-generic ${CURRENTKERNEL}-dbg
1590 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
160Remv linux-headers-1000000-1-generic [100.0.0-1]
161Remv ${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -s
162
163# rt kernel was put on hold while the protected list was generated
164testsuccess aptmark unhold "${CURRENTKERNEL}-rt"
165testsuccessequal "Reading package lists...
33677a0c
DK
166Building dependency tree...
167Reading state information...
7ce1ac85 168The following packages will be REMOVED:
3196dae8
DK
169 linux-headers-1000000-1-generic ${CURRENTKERNEL}-dbg
1700 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
171Remv linux-headers-1000000-1-generic [100.0.0-1]
172Remv ${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -s