1 # Functional test that boots a Linux kernel and checks the console
3 # Copyright (c) 2018 Red Hat, Inc.
6 # Cleber Rosa <crosa@redhat.com>
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.
17 from avocado_qemu
import Test
18 from avocado
.utils
import process
19 from avocado
.utils
import archive
22 class BootLinuxConsole(Test
):
24 Boots a Linux kernel and checks that the console is operational and the
25 kernel command line is properly passed from QEMU to the kernel
30 KERNEL_COMMON_COMMAND_LINE
= 'printk.time=0 '
32 def wait_for_console_pattern(self
, success_message
,
33 failure_message
='Kernel panic - not syncing'):
35 Waits for messages to appear on the console, while logging the content
37 :param success_message: if this message appears, test succeeds
38 :param failure_message: if this message appears, test fails
40 console
= self
.vm
.console_socket
.makefile()
41 console_logger
= logging
.getLogger('console')
43 msg
= console
.readline().strip()
46 console_logger
.debug(msg
)
47 if success_message
in msg
:
49 if failure_message
in msg
:
50 fail
= 'Failure message found in console: %s' % failure_message
53 def exec_command_and_wait_for_pattern(self
, command
, success_message
):
55 self
.vm
.console_socket
.sendall(command
.encode())
56 self
.wait_for_console_pattern(success_message
)
58 def extract_from_deb(self
, deb
, path
):
60 Extracts a file from a deb package into the test workdir
62 :param deb: path to the deb archive
63 :param file: path within the deb archive of the file to be extracted
64 :returns: path of the extracted file
67 os
.chdir(self
.workdir
)
68 file_path
= process
.run("ar t %s" % deb
).stdout_text
.split()[2]
69 process
.run("ar x %s %s" % (deb
, file_path
))
70 archive
.extract(file_path
, self
.workdir
)
72 return self
.workdir
+ path
74 def test_x86_64_pc(self
):
76 :avocado: tags=arch:x86_64
77 :avocado: tags=machine:pc
79 kernel_url
= ('https://archives.fedoraproject.org/pub/archive/fedora'
80 '/linux/releases/29/Everything/x86_64/os/images/pxeboot'
82 kernel_hash
= '23bebd2680757891cf7adedb033532163a792495'
83 kernel_path
= self
.fetch_asset(kernel_url
, asset_hash
=kernel_hash
)
85 self
.vm
.set_machine('pc')
87 kernel_command_line
= self
.KERNEL_COMMON_COMMAND_LINE
+ 'console=ttyS0'
88 self
.vm
.add_args('-kernel', kernel_path
,
89 '-append', kernel_command_line
)
91 console_pattern
= 'Kernel command line: %s' % kernel_command_line
92 self
.wait_for_console_pattern(console_pattern
)
94 def test_mips_malta(self
):
96 :avocado: tags=arch:mips
97 :avocado: tags=machine:malta
98 :avocado: tags=endian:big
100 deb_url
= ('http://snapshot.debian.org/archive/debian/'
101 '20130217T032700Z/pool/main/l/linux-2.6/'
102 'linux-image-2.6.32-5-4kc-malta_2.6.32-48_mips.deb')
103 deb_hash
= 'a8cfc28ad8f45f54811fc6cf74fc43ffcfe0ba04'
104 deb_path
= self
.fetch_asset(deb_url
, asset_hash
=deb_hash
)
105 kernel_path
= self
.extract_from_deb(deb_path
,
106 '/boot/vmlinux-2.6.32-5-4kc-malta')
108 self
.vm
.set_machine('malta')
109 self
.vm
.set_console()
110 kernel_command_line
= self
.KERNEL_COMMON_COMMAND_LINE
+ 'console=ttyS0'
111 self
.vm
.add_args('-kernel', kernel_path
,
112 '-append', kernel_command_line
)
114 console_pattern
= 'Kernel command line: %s' % kernel_command_line
115 self
.wait_for_console_pattern(console_pattern
)
117 def test_mips64el_malta(self
):
119 This test requires the ar tool to extract "data.tar.gz" from
122 The kernel can be rebuilt using this Debian kernel source [1] and
123 following the instructions on [2].
125 [1] http://snapshot.debian.org/package/linux-2.6/2.6.32-48/
126 #linux-source-2.6.32_2.6.32-48
127 [2] https://kernel-team.pages.debian.net/kernel-handbook/
128 ch-common-tasks.html#s-common-official
130 :avocado: tags=arch:mips64el
131 :avocado: tags=machine:malta
133 deb_url
= ('http://snapshot.debian.org/archive/debian/'
134 '20130217T032700Z/pool/main/l/linux-2.6/'
135 'linux-image-2.6.32-5-5kc-malta_2.6.32-48_mipsel.deb')
136 deb_hash
= '1aaec92083bf22fda31e0d27fa8d9a388e5fc3d5'
137 deb_path
= self
.fetch_asset(deb_url
, asset_hash
=deb_hash
)
138 kernel_path
= self
.extract_from_deb(deb_path
,
139 '/boot/vmlinux-2.6.32-5-5kc-malta')
141 self
.vm
.set_machine('malta')
142 self
.vm
.set_console()
143 kernel_command_line
= self
.KERNEL_COMMON_COMMAND_LINE
+ 'console=ttyS0'
144 self
.vm
.add_args('-kernel', kernel_path
,
145 '-append', kernel_command_line
)
147 console_pattern
= 'Kernel command line: %s' % kernel_command_line
148 self
.wait_for_console_pattern(console_pattern
)
150 def test_mips_malta_cpio(self
):
152 :avocado: tags=arch:mips
153 :avocado: tags=machine:malta
154 :avocado: tags=endian:big
156 deb_url
= ('http://snapshot.debian.org/archive/debian/'
157 '20160601T041800Z/pool/main/l/linux/'
158 'linux-image-4.5.0-2-4kc-malta_4.5.5-1_mips.deb')
159 deb_hash
= 'a3c84f3e88b54e06107d65a410d1d1e8e0f340f8'
160 deb_path
= self
.fetch_asset(deb_url
, asset_hash
=deb_hash
)
161 kernel_path
= self
.extract_from_deb(deb_path
,
162 '/boot/vmlinux-4.5.0-2-4kc-malta')
163 initrd_url
= ('https://github.com/groeck/linux-build-test/raw/'
164 '8584a59ed9e5eb5ee7ca91f6d74bbb06619205b8/rootfs/'
165 'mips/rootfs.cpio.gz')
166 initrd_hash
= 'bf806e17009360a866bf537f6de66590de349a99'
167 initrd_path_gz
= self
.fetch_asset(initrd_url
, asset_hash
=initrd_hash
)
168 initrd_path
= self
.workdir
+ "rootfs.cpio"
170 with gzip
.open(initrd_path_gz
, 'rb') as f_in
:
171 with
open(initrd_path
, 'wb') as f_out
:
172 shutil
.copyfileobj(f_in
, f_out
)
174 self
.vm
.set_machine('malta')
175 self
.vm
.set_console()
176 kernel_command_line
= (self
.KERNEL_COMMON_COMMAND_LINE
177 + 'console=ttyS0 console=tty '
178 + 'rdinit=/sbin/init noreboot')
179 self
.vm
.add_args('-kernel', kernel_path
,
180 '-initrd', initrd_path
,
181 '-append', kernel_command_line
,
184 self
.wait_for_console_pattern('Boot successful.')
186 self
.exec_command_and_wait_for_pattern('cat /proc/cpuinfo',
188 self
.exec_command_and_wait_for_pattern('uname -a',
190 self
.exec_command_and_wait_for_pattern('reboot',
191 'reboot: Restarting system')
193 def do_test_mips_malta32el_nanomips(self
, kernel_url
, kernel_hash
):
194 kernel_path_xz
= self
.fetch_asset(kernel_url
, asset_hash
=kernel_hash
)
195 kernel_path
= self
.workdir
+ "kernel"
196 with lzma
.open(kernel_path_xz
, 'rb') as f_in
:
197 with
open(kernel_path
, 'wb') as f_out
:
198 shutil
.copyfileobj(f_in
, f_out
)
200 self
.vm
.set_machine('malta')
201 self
.vm
.set_console()
202 kernel_command_line
= (self
.KERNEL_COMMON_COMMAND_LINE
205 self
.vm
.add_args('-no-reboot',
207 '-kernel', kernel_path
,
208 '-append', kernel_command_line
)
210 console_pattern
= 'Kernel command line: %s' % kernel_command_line
211 self
.wait_for_console_pattern(console_pattern
)
213 def test_mips_malta32el_nanomips_4k(self
):
215 :avocado: tags=arch:mipsel
216 :avocado: tags=machine:malta
217 :avocado: tags=endian:little
219 kernel_url
= ('https://mipsdistros.mips.com/LinuxDistro/nanomips/'
220 'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/'
221 'generic_nano32r6el_page4k.xz')
222 kernel_hash
= '477456aafd2a0f1ddc9482727f20fe9575565dd6'
223 self
.do_test_mips_malta32el_nanomips(kernel_url
, kernel_hash
)
225 def test_mips_malta32el_nanomips_16k_up(self
):
227 :avocado: tags=arch:mipsel
228 :avocado: tags=machine:malta
229 :avocado: tags=endian:little
231 kernel_url
= ('https://mipsdistros.mips.com/LinuxDistro/nanomips/'
232 'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/'
233 'generic_nano32r6el_page16k_up.xz')
234 kernel_hash
= 'e882868f944c71c816e832e2303b7874d044a7bc'
235 self
.do_test_mips_malta32el_nanomips(kernel_url
, kernel_hash
)
237 def test_mips_malta32el_nanomips_64k_dbg(self
):
239 :avocado: tags=arch:mipsel
240 :avocado: tags=machine:malta
241 :avocado: tags=endian:little
243 kernel_url
= ('https://mipsdistros.mips.com/LinuxDistro/nanomips/'
244 'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/'
245 'generic_nano32r6el_page64k_dbg.xz')
246 kernel_hash
= '18d1c68f2e23429e266ca39ba5349ccd0aeb7180'
247 self
.do_test_mips_malta32el_nanomips(kernel_url
, kernel_hash
)
249 def test_aarch64_virt(self
):
251 :avocado: tags=arch:aarch64
252 :avocado: tags=machine:virt
254 kernel_url
= ('https://archives.fedoraproject.org/pub/archive/fedora'
255 '/linux/releases/29/Everything/aarch64/os/images/pxeboot'
257 kernel_hash
= '8c73e469fc6ea06a58dc83a628fc695b693b8493'
258 kernel_path
= self
.fetch_asset(kernel_url
, asset_hash
=kernel_hash
)
260 self
.vm
.set_machine('virt')
261 self
.vm
.set_console()
262 kernel_command_line
= (self
.KERNEL_COMMON_COMMAND_LINE
+
264 self
.vm
.add_args('-cpu', 'cortex-a53',
265 '-kernel', kernel_path
,
266 '-append', kernel_command_line
)
268 console_pattern
= 'Kernel command line: %s' % kernel_command_line
269 self
.wait_for_console_pattern(console_pattern
)
271 def test_arm_virt(self
):
273 :avocado: tags=arch:arm
274 :avocado: tags=machine:virt
276 kernel_url
= ('https://archives.fedoraproject.org/pub/archive/fedora'
277 '/linux/releases/29/Everything/armhfp/os/images/pxeboot'
279 kernel_hash
= 'e9826d741b4fb04cadba8d4824d1ed3b7fb8b4d4'
280 kernel_path
= self
.fetch_asset(kernel_url
, asset_hash
=kernel_hash
)
282 self
.vm
.set_machine('virt')
283 self
.vm
.set_console()
284 kernel_command_line
= (self
.KERNEL_COMMON_COMMAND_LINE
+
286 self
.vm
.add_args('-kernel', kernel_path
,
287 '-append', kernel_command_line
)
289 console_pattern
= 'Kernel command line: %s' % kernel_command_line
290 self
.wait_for_console_pattern(console_pattern
)
292 def test_arm_emcraft_sf2(self
):
294 :avocado: tags=arch:arm
295 :avocado: tags=machine:emcraft_sf2
296 :avocado: tags=endian:little
298 uboot_url
= ('https://raw.githubusercontent.com/'
299 'Subbaraya-Sundeep/qemu-test-binaries/'
300 'fa030bd77a014a0b8e360d3b7011df89283a2f0b/u-boot')
301 uboot_hash
= 'abba5d9c24cdd2d49cdc2a8aa92976cf20737eff'
302 uboot_path
= self
.fetch_asset(uboot_url
, asset_hash
=uboot_hash
)
303 spi_url
= ('https://raw.githubusercontent.com/'
304 'Subbaraya-Sundeep/qemu-test-binaries/'
305 'fa030bd77a014a0b8e360d3b7011df89283a2f0b/spi.bin')
306 spi_hash
= '85f698329d38de63aea6e884a86fbde70890a78a'
307 spi_path
= self
.fetch_asset(spi_url
, asset_hash
=spi_hash
)
309 self
.vm
.set_machine('emcraft-sf2')
310 self
.vm
.set_console()
311 kernel_command_line
= self
.KERNEL_COMMON_COMMAND_LINE
312 self
.vm
.add_args('-kernel', uboot_path
,
313 '-append', kernel_command_line
,
314 '-drive', 'file=' + spi_path
+ ',if=mtd,format=raw',
317 self
.wait_for_console_pattern('init started: BusyBox')
319 def test_s390x_s390_ccw_virtio(self
):
321 :avocado: tags=arch:s390x
322 :avocado: tags=machine:s390_ccw_virtio
324 kernel_url
= ('https://archives.fedoraproject.org/pub/archive'
325 '/fedora-secondary/releases/29/Everything/s390x/os/images'
327 kernel_hash
= 'e8e8439103ef8053418ef062644ffd46a7919313'
328 kernel_path
= self
.fetch_asset(kernel_url
, asset_hash
=kernel_hash
)
330 self
.vm
.set_machine('s390-ccw-virtio')
331 self
.vm
.set_console()
332 kernel_command_line
= self
.KERNEL_COMMON_COMMAND_LINE
+ 'console=sclp0'
333 self
.vm
.add_args('-nodefaults',
334 '-kernel', kernel_path
,
335 '-append', kernel_command_line
)
337 console_pattern
= 'Kernel command line: %s' % kernel_command_line
338 self
.wait_for_console_pattern(console_pattern
)
340 def test_alpha_clipper(self
):
342 :avocado: tags=arch:alpha
343 :avocado: tags=machine:clipper
345 kernel_url
= ('http://archive.debian.org/debian/dists/lenny/main/'
346 'installer-alpha/current/images/cdrom/vmlinuz')
347 kernel_hash
= '3a943149335529e2ed3e74d0d787b85fb5671ba3'
348 kernel_path
= self
.fetch_asset(kernel_url
, asset_hash
=kernel_hash
)
350 uncompressed_kernel
= archive
.uncompress(kernel_path
, self
.workdir
)
352 self
.vm
.set_machine('clipper')
353 self
.vm
.set_console()
354 kernel_command_line
= self
.KERNEL_COMMON_COMMAND_LINE
+ 'console=ttyS0'
355 self
.vm
.add_args('-vga', 'std',
356 '-kernel', uncompressed_kernel
,
357 '-append', kernel_command_line
)
359 console_pattern
= 'Kernel command line: %s' % kernel_command_line
360 self
.wait_for_console_pattern(console_pattern
)
362 def test_ppc64_pseries(self
):
364 :avocado: tags=arch:ppc64
365 :avocado: tags=machine:pseries
367 kernel_url
= ('https://archives.fedoraproject.org/pub/archive'
368 '/fedora-secondary/releases/29/Everything/ppc64le/os'
369 '/ppc/ppc64/vmlinuz')
370 kernel_hash
= '3fe04abfc852b66653b8c3c897a59a689270bc77'
371 kernel_path
= self
.fetch_asset(kernel_url
, asset_hash
=kernel_hash
)
373 self
.vm
.set_machine('pseries')
374 self
.vm
.set_console()
375 kernel_command_line
= self
.KERNEL_COMMON_COMMAND_LINE
+ 'console=hvc0'
376 self
.vm
.add_args('-kernel', kernel_path
,
377 '-append', kernel_command_line
)
379 console_pattern
= 'Kernel command line: %s' % kernel_command_line
380 self
.wait_for_console_pattern(console_pattern
)