]> git.proxmox.com Git - mirror_qemu.git/blame - tests/acceptance/boot_linux_console.py
BootLinuxConsoleTest: Test the SmartFusion2 board
[mirror_qemu.git] / tests / acceptance / boot_linux_console.py
CommitLineData
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 11import os
c1cc73f4
CR
12import logging
13
14from avocado_qemu import Test
f8792047
PMD
15from avocado.utils import process
16from avocado.utils import archive
c1cc73f4
CR
17
18
19class BootLinuxConsole(Test):
20 """
78664ed8
CR
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
c1cc73f4
CR
23 """
24
61f74506 25 timeout = 90
c1cc73f4 26
b50fcd39
CR
27 KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
28
0d1d74e5
CR
29 def wait_for_console_pattern(self, success_message,
30 failure_message='Kernel panic - not syncing'):
31 """
32 Waits for messages to appear on the console, while logging the content
33
34 :param success_message: if this message appears, test succeeds
35 :param failure_message: if this message appears, test fails
36 """
37 console = self.vm.console_socket.makefile()
38 console_logger = logging.getLogger('console')
39 while True:
da77bc91
PMD
40 msg = console.readline().strip()
41 if not msg:
42 continue
43 console_logger.debug(msg)
0d1d74e5
CR
44 if success_message in msg:
45 break
46 if failure_message in msg:
47 fail = 'Failure message found in console: %s' % failure_message
48 self.fail(fail)
49
f8792047
PMD
50 def extract_from_deb(self, deb, path):
51 """
52 Extracts a file from a deb package into the test workdir
53
54 :param deb: path to the deb archive
55 :param file: path within the deb archive of the file to be extracted
56 :returns: path of the extracted file
57 """
58 cwd = os.getcwd()
59 os.chdir(self.workdir)
6c1c4c33
PMD
60 file_path = process.run("ar t %s" % deb).stdout_text.split()[2]
61 process.run("ar x %s %s" % (deb, file_path))
62 archive.extract(file_path, self.workdir)
f8792047
PMD
63 os.chdir(cwd)
64 return self.workdir + path
65
78664ed8
CR
66 def test_x86_64_pc(self):
67 """
68 :avocado: tags=arch:x86_64
69 :avocado: tags=machine:pc
70 """
7d7985b1
CR
71 kernel_url = ('https://download.fedoraproject.org/pub/fedora/linux/'
72 'releases/29/Everything/x86_64/os/images/pxeboot/vmlinuz')
73 kernel_hash = '23bebd2680757891cf7adedb033532163a792495'
c1cc73f4
CR
74 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
75
76 self.vm.set_machine('pc')
77 self.vm.set_console()
b50fcd39 78 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
c1cc73f4
CR
79 self.vm.add_args('-kernel', kernel_path,
80 '-append', kernel_command_line)
81 self.vm.launch()
0d1d74e5
CR
82 console_pattern = 'Kernel command line: %s' % kernel_command_line
83 self.wait_for_console_pattern(console_pattern)
f8792047
PMD
84
85 def test_mips_malta(self):
86 """
87 :avocado: tags=arch:mips
88 :avocado: tags=machine:malta
89 :avocado: tags=endian:big
90 """
91 deb_url = ('http://snapshot.debian.org/archive/debian/'
92 '20130217T032700Z/pool/main/l/linux-2.6/'
93 'linux-image-2.6.32-5-4kc-malta_2.6.32-48_mips.deb')
94 deb_hash = 'a8cfc28ad8f45f54811fc6cf74fc43ffcfe0ba04'
95 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
96 kernel_path = self.extract_from_deb(deb_path,
97 '/boot/vmlinux-2.6.32-5-4kc-malta')
98
99 self.vm.set_machine('malta')
100 self.vm.set_console()
101 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
102 self.vm.add_args('-kernel', kernel_path,
103 '-append', kernel_command_line)
104 self.vm.launch()
105 console_pattern = 'Kernel command line: %s' % kernel_command_line
106 self.wait_for_console_pattern(console_pattern)
02c2852b
CR
107
108 def test_mips64el_malta(self):
109 """
110 This test requires the ar tool to extract "data.tar.gz" from
111 the Debian package.
112
113 The kernel can be rebuilt using this Debian kernel source [1] and
114 following the instructions on [2].
115
116 [1] http://snapshot.debian.org/package/linux-2.6/2.6.32-48/
117 #linux-source-2.6.32_2.6.32-48
118 [2] https://kernel-team.pages.debian.net/kernel-handbook/
119 ch-common-tasks.html#s-common-official
120
121 :avocado: tags=arch:mips64el
122 :avocado: tags=machine:malta
123 """
124 deb_url = ('http://snapshot.debian.org/archive/debian/'
125 '20130217T032700Z/pool/main/l/linux-2.6/'
126 'linux-image-2.6.32-5-5kc-malta_2.6.32-48_mipsel.deb')
127 deb_hash = '1aaec92083bf22fda31e0d27fa8d9a388e5fc3d5'
128 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
129 kernel_path = self.extract_from_deb(deb_path,
130 '/boot/vmlinux-2.6.32-5-5kc-malta')
131
132 self.vm.set_machine('malta')
133 self.vm.set_console()
134 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
135 self.vm.add_args('-kernel', kernel_path,
136 '-append', kernel_command_line)
137 self.vm.launch()
138 console_pattern = 'Kernel command line: %s' % kernel_command_line
139 self.wait_for_console_pattern(console_pattern)
d4e12161
CR
140
141 def test_aarch64_virt(self):
142 """
143 :avocado: tags=arch:aarch64
144 :avocado: tags=machine:virt
145 """
146 kernel_url = ('https://download.fedoraproject.org/pub/fedora/linux/'
147 'releases/29/Everything/aarch64/os/images/pxeboot/vmlinuz')
148 kernel_hash = '8c73e469fc6ea06a58dc83a628fc695b693b8493'
149 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
150
151 self.vm.set_machine('virt')
152 self.vm.set_console()
153 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
154 'console=ttyAMA0')
155 self.vm.add_args('-cpu', 'cortex-a53',
156 '-kernel', kernel_path,
157 '-append', kernel_command_line)
158 self.vm.launch()
159 console_pattern = 'Kernel command line: %s' % kernel_command_line
160 self.wait_for_console_pattern(console_pattern)
1a30892e
CR
161
162 def test_arm_virt(self):
163 """
164 :avocado: tags=arch:arm
165 :avocado: tags=machine:virt
166 """
167 kernel_url = ('https://download.fedoraproject.org/pub/fedora/linux/'
168 'releases/29/Everything/armhfp/os/images/pxeboot/vmlinuz')
169 kernel_hash = 'e9826d741b4fb04cadba8d4824d1ed3b7fb8b4d4'
170 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
171
172 self.vm.set_machine('virt')
173 self.vm.set_console()
174 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
175 'console=ttyAMA0')
176 self.vm.add_args('-kernel', kernel_path,
177 '-append', kernel_command_line)
178 self.vm.launch()
179 console_pattern = 'Kernel command line: %s' % kernel_command_line
180 self.wait_for_console_pattern(console_pattern)
79182494 181
77ead6b8
PMD
182 def test_arm_emcraft_sf2(self):
183 """
184 :avocado: tags=arch:arm
185 :avocado: tags=machine:emcraft_sf2
186 :avocado: tags=endian:little
187 """
188 uboot_url = ('https://raw.githubusercontent.com/'
189 'Subbaraya-Sundeep/qemu-test-binaries/'
190 'fa030bd77a014a0b8e360d3b7011df89283a2f0b/u-boot')
191 uboot_hash = 'abba5d9c24cdd2d49cdc2a8aa92976cf20737eff'
192 uboot_path = self.fetch_asset(uboot_url, asset_hash=uboot_hash)
193 spi_url = ('https://raw.githubusercontent.com/'
194 'Subbaraya-Sundeep/qemu-test-binaries/'
195 'fa030bd77a014a0b8e360d3b7011df89283a2f0b/spi.bin')
196 spi_hash = '85f698329d38de63aea6e884a86fbde70890a78a'
197 spi_path = self.fetch_asset(spi_url, asset_hash=spi_hash)
198
199 self.vm.set_machine('emcraft-sf2')
200 self.vm.set_console()
201 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE
202 self.vm.add_args('-kernel', uboot_path,
203 '-append', kernel_command_line,
204 '-drive', 'file=' + spi_path + ',if=mtd,format=raw',
205 '-no-reboot')
206 self.vm.launch()
207 self.wait_for_console_pattern('init started: BusyBox')
208
79182494
CR
209 def test_s390x_s390_ccw_virtio(self):
210 """
211 :avocado: tags=arch:s390x
212 :avocado: tags=machine:s390_ccw_virtio
213 """
214 kernel_url = ('https://download.fedoraproject.org/pub/fedora-secondary/'
215 'releases/29/Everything/s390x/os/images/kernel.img')
216 kernel_hash = 'e8e8439103ef8053418ef062644ffd46a7919313'
217 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
218
219 self.vm.set_machine('s390-ccw-virtio')
220 self.vm.set_console()
221 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=sclp0'
222 self.vm.add_args('-nodefaults',
223 '-kernel', kernel_path,
224 '-append', kernel_command_line)
225 self.vm.launch()
226 console_pattern = 'Kernel command line: %s' % kernel_command_line
227 self.wait_for_console_pattern(console_pattern)
b36b5937
CR
228
229 def test_alpha_clipper(self):
230 """
231 :avocado: tags=arch:alpha
232 :avocado: tags=machine:clipper
233 """
234 kernel_url = ('http://archive.debian.org/debian/dists/lenny/main/'
235 'installer-alpha/current/images/cdrom/vmlinuz')
236 kernel_hash = '3a943149335529e2ed3e74d0d787b85fb5671ba3'
237 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
238
239 uncompressed_kernel = archive.uncompress(kernel_path, self.workdir)
240
241 self.vm.set_machine('clipper')
242 self.vm.set_console()
243 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
244 self.vm.add_args('-vga', 'std',
245 '-kernel', uncompressed_kernel,
246 '-append', kernel_command_line)
247 self.vm.launch()
248 console_pattern = 'Kernel command line: %s' % kernel_command_line
249 self.wait_for_console_pattern(console_pattern)