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