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.
14 from avocado_qemu
import Test
15 from avocado
.utils
import process
16 from avocado
.utils
import archive
19 class BootLinuxConsole(Test
):
21 Boots a Linux kernel and checks that the console is operational and the
22 kernel command line is properly passed from QEMU to the kernel
27 KERNEL_COMMON_COMMAND_LINE
= 'printk.time=0 '
29 def wait_for_console_pattern(self
, success_message
,
30 failure_message
='Kernel panic - not syncing'):
32 Waits for messages to appear on the console, while logging the content
34 :param success_message: if this message appears, test succeeds
35 :param failure_message: if this message appears, test fails
37 console
= self
.vm
.console_socket
.makefile()
38 console_logger
= logging
.getLogger('console')
40 msg
= console
.readline()
41 console_logger
.debug(msg
.strip())
42 if success_message
in msg
:
44 if failure_message
in msg
:
45 fail
= 'Failure message found in console: %s' % failure_message
48 def extract_from_deb(self
, deb
, path
):
50 Extracts a file from a deb package into the test workdir
52 :param deb: path to the deb archive
53 :param file: path within the deb archive of the file to be extracted
54 :returns: path of the extracted file
57 os
.chdir(self
.workdir
)
58 process
.run("ar x %s data.tar.gz" % deb
)
59 archive
.extract("data.tar.gz", self
.workdir
)
61 return self
.workdir
+ path
63 def test_x86_64_pc(self
):
65 :avocado: tags=arch:x86_64
66 :avocado: tags=machine:pc
68 kernel_url
= ('https://download.fedoraproject.org/pub/fedora/linux/'
69 'releases/29/Everything/x86_64/os/images/pxeboot/vmlinuz')
70 kernel_hash
= '23bebd2680757891cf7adedb033532163a792495'
71 kernel_path
= self
.fetch_asset(kernel_url
, asset_hash
=kernel_hash
)
73 self
.vm
.set_machine('pc')
75 kernel_command_line
= self
.KERNEL_COMMON_COMMAND_LINE
+ 'console=ttyS0'
76 self
.vm
.add_args('-kernel', kernel_path
,
77 '-append', kernel_command_line
)
79 console_pattern
= 'Kernel command line: %s' % kernel_command_line
80 self
.wait_for_console_pattern(console_pattern
)
82 def test_mips_malta(self
):
84 :avocado: tags=arch:mips
85 :avocado: tags=machine:malta
86 :avocado: tags=endian:big
88 deb_url
= ('http://snapshot.debian.org/archive/debian/'
89 '20130217T032700Z/pool/main/l/linux-2.6/'
90 'linux-image-2.6.32-5-4kc-malta_2.6.32-48_mips.deb')
91 deb_hash
= 'a8cfc28ad8f45f54811fc6cf74fc43ffcfe0ba04'
92 deb_path
= self
.fetch_asset(deb_url
, asset_hash
=deb_hash
)
93 kernel_path
= self
.extract_from_deb(deb_path
,
94 '/boot/vmlinux-2.6.32-5-4kc-malta')
96 self
.vm
.set_machine('malta')
98 kernel_command_line
= self
.KERNEL_COMMON_COMMAND_LINE
+ 'console=ttyS0'
99 self
.vm
.add_args('-kernel', kernel_path
,
100 '-append', kernel_command_line
)
102 console_pattern
= 'Kernel command line: %s' % kernel_command_line
103 self
.wait_for_console_pattern(console_pattern
)
105 def test_mips64el_malta(self
):
107 This test requires the ar tool to extract "data.tar.gz" from
110 The kernel can be rebuilt using this Debian kernel source [1] and
111 following the instructions on [2].
113 [1] http://snapshot.debian.org/package/linux-2.6/2.6.32-48/
114 #linux-source-2.6.32_2.6.32-48
115 [2] https://kernel-team.pages.debian.net/kernel-handbook/
116 ch-common-tasks.html#s-common-official
118 :avocado: tags=arch:mips64el
119 :avocado: tags=machine:malta
121 deb_url
= ('http://snapshot.debian.org/archive/debian/'
122 '20130217T032700Z/pool/main/l/linux-2.6/'
123 'linux-image-2.6.32-5-5kc-malta_2.6.32-48_mipsel.deb')
124 deb_hash
= '1aaec92083bf22fda31e0d27fa8d9a388e5fc3d5'
125 deb_path
= self
.fetch_asset(deb_url
, asset_hash
=deb_hash
)
126 kernel_path
= self
.extract_from_deb(deb_path
,
127 '/boot/vmlinux-2.6.32-5-5kc-malta')
129 self
.vm
.set_machine('malta')
130 self
.vm
.set_console()
131 kernel_command_line
= self
.KERNEL_COMMON_COMMAND_LINE
+ 'console=ttyS0'
132 self
.vm
.add_args('-kernel', kernel_path
,
133 '-append', kernel_command_line
)
135 console_pattern
= 'Kernel command line: %s' % kernel_command_line
136 self
.wait_for_console_pattern(console_pattern
)
138 def test_aarch64_virt(self
):
140 :avocado: tags=arch:aarch64
141 :avocado: tags=machine:virt
143 kernel_url
= ('https://download.fedoraproject.org/pub/fedora/linux/'
144 'releases/29/Everything/aarch64/os/images/pxeboot/vmlinuz')
145 kernel_hash
= '8c73e469fc6ea06a58dc83a628fc695b693b8493'
146 kernel_path
= self
.fetch_asset(kernel_url
, asset_hash
=kernel_hash
)
148 self
.vm
.set_machine('virt')
149 self
.vm
.set_console()
150 kernel_command_line
= (self
.KERNEL_COMMON_COMMAND_LINE
+
152 self
.vm
.add_args('-cpu', 'cortex-a53',
153 '-kernel', kernel_path
,
154 '-append', kernel_command_line
)
156 console_pattern
= 'Kernel command line: %s' % kernel_command_line
157 self
.wait_for_console_pattern(console_pattern
)
159 def test_arm_virt(self
):
161 :avocado: tags=arch:arm
162 :avocado: tags=machine:virt
164 kernel_url
= ('https://download.fedoraproject.org/pub/fedora/linux/'
165 'releases/29/Everything/armhfp/os/images/pxeboot/vmlinuz')
166 kernel_hash
= 'e9826d741b4fb04cadba8d4824d1ed3b7fb8b4d4'
167 kernel_path
= self
.fetch_asset(kernel_url
, asset_hash
=kernel_hash
)
169 self
.vm
.set_machine('virt')
170 self
.vm
.set_console()
171 kernel_command_line
= (self
.KERNEL_COMMON_COMMAND_LINE
+
173 self
.vm
.add_args('-kernel', kernel_path
,
174 '-append', kernel_command_line
)
176 console_pattern
= 'Kernel command line: %s' % kernel_command_line
177 self
.wait_for_console_pattern(console_pattern
)