]>
Commit | Line | Data |
---|---|---|
c1cc73f4 CR |
1 | # Functional test that boots a Linux kernel and checks the console |
2 | # | |
3 | # Copyright (c) 2018 Red Hat, Inc. | |
4 | # | |
5 | # Author: | |
6 | # Cleber Rosa <crosa@redhat.com> | |
7 | # | |
8 | # This work is licensed under the terms of the GNU GPL, version 2 or | |
9 | # later. See the COPYING file in the top-level directory. | |
10 | ||
f8792047 | 11 | import os |
f375ad6a | 12 | import lzma |
89368673 | 13 | import gzip |
f375ad6a | 14 | import shutil |
c1cc73f4 CR |
15 | |
16 | from avocado_qemu import Test | |
2b17d81f | 17 | from avocado_qemu import exec_command_and_wait_for_pattern |
77bcd248 | 18 | from avocado_qemu import wait_for_console_pattern |
f8792047 PMD |
19 | from avocado.utils import process |
20 | from avocado.utils import archive | |
c1cc73f4 CR |
21 | |
22 | ||
23 | class BootLinuxConsole(Test): | |
24 | """ | |
78664ed8 CR |
25 | Boots a Linux kernel and checks that the console is operational and the |
26 | kernel command line is properly passed from QEMU to the kernel | |
c1cc73f4 CR |
27 | """ |
28 | ||
61f74506 | 29 | timeout = 90 |
c1cc73f4 | 30 | |
b50fcd39 CR |
31 | KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 ' |
32 | ||
77bcd248 CR |
33 | def wait_for_console_pattern(self, success_message): |
34 | wait_for_console_pattern(self, success_message, | |
35 | failure_message='Kernel panic - not syncing') | |
0d1d74e5 | 36 | |
f8792047 PMD |
37 | def extract_from_deb(self, deb, path): |
38 | """ | |
39 | Extracts a file from a deb package into the test workdir | |
40 | ||
41 | :param deb: path to the deb archive | |
42 | :param file: path within the deb archive of the file to be extracted | |
43 | :returns: path of the extracted file | |
44 | """ | |
45 | cwd = os.getcwd() | |
46 | os.chdir(self.workdir) | |
6c1c4c33 PMD |
47 | file_path = process.run("ar t %s" % deb).stdout_text.split()[2] |
48 | process.run("ar x %s %s" % (deb, file_path)) | |
49 | archive.extract(file_path, self.workdir) | |
f8792047 PMD |
50 | os.chdir(cwd) |
51 | return self.workdir + path | |
52 | ||
78664ed8 CR |
53 | def test_x86_64_pc(self): |
54 | """ | |
55 | :avocado: tags=arch:x86_64 | |
56 | :avocado: tags=machine:pc | |
57 | """ | |
93bbbdf6 CR |
58 | kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora' |
59 | '/linux/releases/29/Everything/x86_64/os/images/pxeboot' | |
60 | '/vmlinuz') | |
7d7985b1 | 61 | kernel_hash = '23bebd2680757891cf7adedb033532163a792495' |
c1cc73f4 CR |
62 | kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) |
63 | ||
64 | self.vm.set_machine('pc') | |
65 | self.vm.set_console() | |
b50fcd39 | 66 | kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0' |
c1cc73f4 CR |
67 | self.vm.add_args('-kernel', kernel_path, |
68 | '-append', kernel_command_line) | |
69 | self.vm.launch() | |
0d1d74e5 CR |
70 | console_pattern = 'Kernel command line: %s' % kernel_command_line |
71 | self.wait_for_console_pattern(console_pattern) | |
f8792047 PMD |
72 | |
73 | def test_mips_malta(self): | |
74 | """ | |
75 | :avocado: tags=arch:mips | |
76 | :avocado: tags=machine:malta | |
77 | :avocado: tags=endian:big | |
78 | """ | |
79 | deb_url = ('http://snapshot.debian.org/archive/debian/' | |
80 | '20130217T032700Z/pool/main/l/linux-2.6/' | |
81 | 'linux-image-2.6.32-5-4kc-malta_2.6.32-48_mips.deb') | |
82 | deb_hash = 'a8cfc28ad8f45f54811fc6cf74fc43ffcfe0ba04' | |
83 | deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) | |
84 | kernel_path = self.extract_from_deb(deb_path, | |
85 | '/boot/vmlinux-2.6.32-5-4kc-malta') | |
86 | ||
87 | self.vm.set_machine('malta') | |
88 | self.vm.set_console() | |
89 | kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0' | |
90 | self.vm.add_args('-kernel', kernel_path, | |
91 | '-append', kernel_command_line) | |
92 | self.vm.launch() | |
93 | console_pattern = 'Kernel command line: %s' % kernel_command_line | |
94 | self.wait_for_console_pattern(console_pattern) | |
02c2852b CR |
95 | |
96 | def test_mips64el_malta(self): | |
97 | """ | |
98 | This test requires the ar tool to extract "data.tar.gz" from | |
99 | the Debian package. | |
100 | ||
101 | The kernel can be rebuilt using this Debian kernel source [1] and | |
102 | following the instructions on [2]. | |
103 | ||
104 | [1] http://snapshot.debian.org/package/linux-2.6/2.6.32-48/ | |
105 | #linux-source-2.6.32_2.6.32-48 | |
106 | [2] https://kernel-team.pages.debian.net/kernel-handbook/ | |
107 | ch-common-tasks.html#s-common-official | |
108 | ||
109 | :avocado: tags=arch:mips64el | |
110 | :avocado: tags=machine:malta | |
111 | """ | |
112 | deb_url = ('http://snapshot.debian.org/archive/debian/' | |
113 | '20130217T032700Z/pool/main/l/linux-2.6/' | |
114 | 'linux-image-2.6.32-5-5kc-malta_2.6.32-48_mipsel.deb') | |
115 | deb_hash = '1aaec92083bf22fda31e0d27fa8d9a388e5fc3d5' | |
116 | deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) | |
117 | kernel_path = self.extract_from_deb(deb_path, | |
118 | '/boot/vmlinux-2.6.32-5-5kc-malta') | |
119 | ||
120 | self.vm.set_machine('malta') | |
121 | self.vm.set_console() | |
122 | kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0' | |
123 | self.vm.add_args('-kernel', kernel_path, | |
124 | '-append', kernel_command_line) | |
125 | self.vm.launch() | |
126 | console_pattern = 'Kernel command line: %s' % kernel_command_line | |
127 | self.wait_for_console_pattern(console_pattern) | |
d4e12161 | 128 | |
89368673 PMD |
129 | def test_mips_malta_cpio(self): |
130 | """ | |
131 | :avocado: tags=arch:mips | |
132 | :avocado: tags=machine:malta | |
133 | :avocado: tags=endian:big | |
134 | """ | |
135 | deb_url = ('http://snapshot.debian.org/archive/debian/' | |
136 | '20160601T041800Z/pool/main/l/linux/' | |
137 | 'linux-image-4.5.0-2-4kc-malta_4.5.5-1_mips.deb') | |
138 | deb_hash = 'a3c84f3e88b54e06107d65a410d1d1e8e0f340f8' | |
139 | deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) | |
140 | kernel_path = self.extract_from_deb(deb_path, | |
141 | '/boot/vmlinux-4.5.0-2-4kc-malta') | |
142 | initrd_url = ('https://github.com/groeck/linux-build-test/raw/' | |
143 | '8584a59ed9e5eb5ee7ca91f6d74bbb06619205b8/rootfs/' | |
144 | 'mips/rootfs.cpio.gz') | |
145 | initrd_hash = 'bf806e17009360a866bf537f6de66590de349a99' | |
146 | initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash) | |
147 | initrd_path = self.workdir + "rootfs.cpio" | |
f2cd6cf6 | 148 | archive.gzip_uncompress(initrd_path_gz, initrd_path) |
89368673 PMD |
149 | |
150 | self.vm.set_machine('malta') | |
151 | self.vm.set_console() | |
152 | kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE | |
153 | + 'console=ttyS0 console=tty ' | |
154 | + 'rdinit=/sbin/init noreboot') | |
155 | self.vm.add_args('-kernel', kernel_path, | |
156 | '-initrd', initrd_path, | |
157 | '-append', kernel_command_line, | |
158 | '-no-reboot') | |
159 | self.vm.launch() | |
160 | self.wait_for_console_pattern('Boot successful.') | |
161 | ||
2b17d81f PMD |
162 | exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', |
163 | 'BogoMIPS') | |
164 | exec_command_and_wait_for_pattern(self, 'uname -a', | |
165 | 'Debian') | |
166 | exec_command_and_wait_for_pattern(self, 'reboot', | |
167 | 'reboot: Restarting system') | |
89368673 | 168 | |
f375ad6a PMD |
169 | def do_test_mips_malta32el_nanomips(self, kernel_url, kernel_hash): |
170 | kernel_path_xz = self.fetch_asset(kernel_url, asset_hash=kernel_hash) | |
171 | kernel_path = self.workdir + "kernel" | |
172 | with lzma.open(kernel_path_xz, 'rb') as f_in: | |
173 | with open(kernel_path, 'wb') as f_out: | |
174 | shutil.copyfileobj(f_in, f_out) | |
175 | ||
176 | self.vm.set_machine('malta') | |
177 | self.vm.set_console() | |
178 | kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE | |
179 | + 'mem=256m@@0x0 ' | |
180 | + 'console=ttyS0') | |
181 | self.vm.add_args('-no-reboot', | |
182 | '-cpu', 'I7200', | |
183 | '-kernel', kernel_path, | |
184 | '-append', kernel_command_line) | |
185 | self.vm.launch() | |
186 | console_pattern = 'Kernel command line: %s' % kernel_command_line | |
187 | self.wait_for_console_pattern(console_pattern) | |
188 | ||
189 | def test_mips_malta32el_nanomips_4k(self): | |
190 | """ | |
191 | :avocado: tags=arch:mipsel | |
192 | :avocado: tags=machine:malta | |
193 | :avocado: tags=endian:little | |
194 | """ | |
195 | kernel_url = ('https://mipsdistros.mips.com/LinuxDistro/nanomips/' | |
196 | 'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/' | |
197 | 'generic_nano32r6el_page4k.xz') | |
198 | kernel_hash = '477456aafd2a0f1ddc9482727f20fe9575565dd6' | |
199 | self.do_test_mips_malta32el_nanomips(kernel_url, kernel_hash) | |
200 | ||
201 | def test_mips_malta32el_nanomips_16k_up(self): | |
202 | """ | |
203 | :avocado: tags=arch:mipsel | |
204 | :avocado: tags=machine:malta | |
205 | :avocado: tags=endian:little | |
206 | """ | |
207 | kernel_url = ('https://mipsdistros.mips.com/LinuxDistro/nanomips/' | |
208 | 'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/' | |
209 | 'generic_nano32r6el_page16k_up.xz') | |
210 | kernel_hash = 'e882868f944c71c816e832e2303b7874d044a7bc' | |
211 | self.do_test_mips_malta32el_nanomips(kernel_url, kernel_hash) | |
212 | ||
213 | def test_mips_malta32el_nanomips_64k_dbg(self): | |
214 | """ | |
215 | :avocado: tags=arch:mipsel | |
216 | :avocado: tags=machine:malta | |
217 | :avocado: tags=endian:little | |
218 | """ | |
219 | kernel_url = ('https://mipsdistros.mips.com/LinuxDistro/nanomips/' | |
220 | 'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/' | |
221 | 'generic_nano32r6el_page64k_dbg.xz') | |
222 | kernel_hash = '18d1c68f2e23429e266ca39ba5349ccd0aeb7180' | |
223 | self.do_test_mips_malta32el_nanomips(kernel_url, kernel_hash) | |
224 | ||
d4e12161 CR |
225 | def test_aarch64_virt(self): |
226 | """ | |
227 | :avocado: tags=arch:aarch64 | |
228 | :avocado: tags=machine:virt | |
229 | """ | |
93bbbdf6 CR |
230 | kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora' |
231 | '/linux/releases/29/Everything/aarch64/os/images/pxeboot' | |
232 | '/vmlinuz') | |
d4e12161 CR |
233 | kernel_hash = '8c73e469fc6ea06a58dc83a628fc695b693b8493' |
234 | kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) | |
235 | ||
236 | self.vm.set_machine('virt') | |
237 | self.vm.set_console() | |
238 | kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + | |
239 | 'console=ttyAMA0') | |
240 | self.vm.add_args('-cpu', 'cortex-a53', | |
241 | '-kernel', kernel_path, | |
242 | '-append', kernel_command_line) | |
243 | self.vm.launch() | |
244 | console_pattern = 'Kernel command line: %s' % kernel_command_line | |
245 | self.wait_for_console_pattern(console_pattern) | |
1a30892e CR |
246 | |
247 | def test_arm_virt(self): | |
248 | """ | |
249 | :avocado: tags=arch:arm | |
250 | :avocado: tags=machine:virt | |
251 | """ | |
93bbbdf6 CR |
252 | kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora' |
253 | '/linux/releases/29/Everything/armhfp/os/images/pxeboot' | |
254 | '/vmlinuz') | |
1a30892e CR |
255 | kernel_hash = 'e9826d741b4fb04cadba8d4824d1ed3b7fb8b4d4' |
256 | kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) | |
257 | ||
258 | self.vm.set_machine('virt') | |
259 | self.vm.set_console() | |
260 | kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + | |
261 | 'console=ttyAMA0') | |
262 | self.vm.add_args('-kernel', kernel_path, | |
263 | '-append', kernel_command_line) | |
264 | self.vm.launch() | |
265 | console_pattern = 'Kernel command line: %s' % kernel_command_line | |
266 | self.wait_for_console_pattern(console_pattern) | |
79182494 | 267 | |
77ead6b8 PMD |
268 | def test_arm_emcraft_sf2(self): |
269 | """ | |
270 | :avocado: tags=arch:arm | |
271 | :avocado: tags=machine:emcraft_sf2 | |
272 | :avocado: tags=endian:little | |
273 | """ | |
274 | uboot_url = ('https://raw.githubusercontent.com/' | |
275 | 'Subbaraya-Sundeep/qemu-test-binaries/' | |
276 | 'fa030bd77a014a0b8e360d3b7011df89283a2f0b/u-boot') | |
277 | uboot_hash = 'abba5d9c24cdd2d49cdc2a8aa92976cf20737eff' | |
278 | uboot_path = self.fetch_asset(uboot_url, asset_hash=uboot_hash) | |
279 | spi_url = ('https://raw.githubusercontent.com/' | |
280 | 'Subbaraya-Sundeep/qemu-test-binaries/' | |
281 | 'fa030bd77a014a0b8e360d3b7011df89283a2f0b/spi.bin') | |
282 | spi_hash = '85f698329d38de63aea6e884a86fbde70890a78a' | |
283 | spi_path = self.fetch_asset(spi_url, asset_hash=spi_hash) | |
284 | ||
285 | self.vm.set_machine('emcraft-sf2') | |
286 | self.vm.set_console() | |
287 | kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE | |
288 | self.vm.add_args('-kernel', uboot_path, | |
289 | '-append', kernel_command_line, | |
290 | '-drive', 'file=' + spi_path + ',if=mtd,format=raw', | |
291 | '-no-reboot') | |
292 | self.vm.launch() | |
293 | self.wait_for_console_pattern('init started: BusyBox') | |
294 | ||
79182494 CR |
295 | def test_s390x_s390_ccw_virtio(self): |
296 | """ | |
297 | :avocado: tags=arch:s390x | |
298 | :avocado: tags=machine:s390_ccw_virtio | |
299 | """ | |
93bbbdf6 CR |
300 | kernel_url = ('https://archives.fedoraproject.org/pub/archive' |
301 | '/fedora-secondary/releases/29/Everything/s390x/os/images' | |
302 | '/kernel.img') | |
79182494 CR |
303 | kernel_hash = 'e8e8439103ef8053418ef062644ffd46a7919313' |
304 | kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) | |
305 | ||
306 | self.vm.set_machine('s390-ccw-virtio') | |
307 | self.vm.set_console() | |
308 | kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=sclp0' | |
309 | self.vm.add_args('-nodefaults', | |
310 | '-kernel', kernel_path, | |
311 | '-append', kernel_command_line) | |
312 | self.vm.launch() | |
313 | console_pattern = 'Kernel command line: %s' % kernel_command_line | |
314 | self.wait_for_console_pattern(console_pattern) | |
b36b5937 CR |
315 | |
316 | def test_alpha_clipper(self): | |
317 | """ | |
318 | :avocado: tags=arch:alpha | |
319 | :avocado: tags=machine:clipper | |
320 | """ | |
321 | kernel_url = ('http://archive.debian.org/debian/dists/lenny/main/' | |
322 | 'installer-alpha/current/images/cdrom/vmlinuz') | |
323 | kernel_hash = '3a943149335529e2ed3e74d0d787b85fb5671ba3' | |
324 | kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) | |
325 | ||
326 | uncompressed_kernel = archive.uncompress(kernel_path, self.workdir) | |
327 | ||
328 | self.vm.set_machine('clipper') | |
329 | self.vm.set_console() | |
330 | kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0' | |
331 | self.vm.add_args('-vga', 'std', | |
332 | '-kernel', uncompressed_kernel, | |
333 | '-append', kernel_command_line) | |
334 | self.vm.launch() | |
335 | console_pattern = 'Kernel command line: %s' % kernel_command_line | |
336 | self.wait_for_console_pattern(console_pattern) | |
83fa3bc3 CR |
337 | |
338 | def test_ppc64_pseries(self): | |
339 | """ | |
340 | :avocado: tags=arch:ppc64 | |
341 | :avocado: tags=machine:pseries | |
342 | """ | |
93bbbdf6 CR |
343 | kernel_url = ('https://archives.fedoraproject.org/pub/archive' |
344 | '/fedora-secondary/releases/29/Everything/ppc64le/os' | |
345 | '/ppc/ppc64/vmlinuz') | |
83fa3bc3 CR |
346 | kernel_hash = '3fe04abfc852b66653b8c3c897a59a689270bc77' |
347 | kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) | |
348 | ||
349 | self.vm.set_machine('pseries') | |
350 | self.vm.set_console() | |
351 | kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=hvc0' | |
352 | self.vm.add_args('-kernel', kernel_path, | |
353 | '-append', kernel_command_line) | |
354 | self.vm.launch() | |
355 | console_pattern = 'Kernel command line: %s' % kernel_command_line | |
356 | self.wait_for_console_pattern(console_pattern) |