target/arm: Move debug routines to debug_helper.c
[qemu/ar7.git] / tests / acceptance / boot_linux_console.py
blob32159503e9f482842a14cfa03c682b3e992c016c
1 # Functional test that boots a Linux kernel and checks the console
3 # Copyright (c) 2018 Red Hat, Inc.
5 # Author:
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.
11 import os
12 import logging
13 import lzma
14 import gzip
15 import shutil
17 from avocado_qemu import Test
18 from avocado.utils import process
19 from avocado.utils import archive
22 class BootLinuxConsole(Test):
23 """
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
26 """
28 timeout = 90
30 KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
32 def wait_for_console_pattern(self, success_message,
33 failure_message='Kernel panic - not syncing'):
34 """
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
39 """
40 console = self.vm.console_socket.makefile()
41 console_logger = logging.getLogger('console')
42 while True:
43 msg = console.readline().strip()
44 if not msg:
45 continue
46 console_logger.debug(msg)
47 if success_message in msg:
48 break
49 if failure_message in msg:
50 fail = 'Failure message found in console: %s' % failure_message
51 self.fail(fail)
53 def exec_command_and_wait_for_pattern(self, command, success_message):
54 command += '\n'
55 self.vm.console_socket.sendall(command.encode())
56 self.wait_for_console_pattern(success_message)
58 def extract_from_deb(self, deb, path):
59 """
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
65 """
66 cwd = os.getcwd()
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)
71 os.chdir(cwd)
72 return self.workdir + path
74 def test_x86_64_pc(self):
75 """
76 :avocado: tags=arch:x86_64
77 :avocado: tags=machine:pc
78 """
79 kernel_url = ('https://download.fedoraproject.org/pub/fedora/linux/'
80 'releases/29/Everything/x86_64/os/images/pxeboot/vmlinuz')
81 kernel_hash = '23bebd2680757891cf7adedb033532163a792495'
82 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
84 self.vm.set_machine('pc')
85 self.vm.set_console()
86 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
87 self.vm.add_args('-kernel', kernel_path,
88 '-append', kernel_command_line)
89 self.vm.launch()
90 console_pattern = 'Kernel command line: %s' % kernel_command_line
91 self.wait_for_console_pattern(console_pattern)
93 def test_mips_malta(self):
94 """
95 :avocado: tags=arch:mips
96 :avocado: tags=machine:malta
97 :avocado: tags=endian:big
98 """
99 deb_url = ('http://snapshot.debian.org/archive/debian/'
100 '20130217T032700Z/pool/main/l/linux-2.6/'
101 'linux-image-2.6.32-5-4kc-malta_2.6.32-48_mips.deb')
102 deb_hash = 'a8cfc28ad8f45f54811fc6cf74fc43ffcfe0ba04'
103 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
104 kernel_path = self.extract_from_deb(deb_path,
105 '/boot/vmlinux-2.6.32-5-4kc-malta')
107 self.vm.set_machine('malta')
108 self.vm.set_console()
109 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
110 self.vm.add_args('-kernel', kernel_path,
111 '-append', kernel_command_line)
112 self.vm.launch()
113 console_pattern = 'Kernel command line: %s' % kernel_command_line
114 self.wait_for_console_pattern(console_pattern)
116 def test_mips64el_malta(self):
118 This test requires the ar tool to extract "data.tar.gz" from
119 the Debian package.
121 The kernel can be rebuilt using this Debian kernel source [1] and
122 following the instructions on [2].
124 [1] http://snapshot.debian.org/package/linux-2.6/2.6.32-48/
125 #linux-source-2.6.32_2.6.32-48
126 [2] https://kernel-team.pages.debian.net/kernel-handbook/
127 ch-common-tasks.html#s-common-official
129 :avocado: tags=arch:mips64el
130 :avocado: tags=machine:malta
132 deb_url = ('http://snapshot.debian.org/archive/debian/'
133 '20130217T032700Z/pool/main/l/linux-2.6/'
134 'linux-image-2.6.32-5-5kc-malta_2.6.32-48_mipsel.deb')
135 deb_hash = '1aaec92083bf22fda31e0d27fa8d9a388e5fc3d5'
136 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
137 kernel_path = self.extract_from_deb(deb_path,
138 '/boot/vmlinux-2.6.32-5-5kc-malta')
140 self.vm.set_machine('malta')
141 self.vm.set_console()
142 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
143 self.vm.add_args('-kernel', kernel_path,
144 '-append', kernel_command_line)
145 self.vm.launch()
146 console_pattern = 'Kernel command line: %s' % kernel_command_line
147 self.wait_for_console_pattern(console_pattern)
149 def test_mips_malta_cpio(self):
151 :avocado: tags=arch:mips
152 :avocado: tags=machine:malta
153 :avocado: tags=endian:big
155 deb_url = ('http://snapshot.debian.org/archive/debian/'
156 '20160601T041800Z/pool/main/l/linux/'
157 'linux-image-4.5.0-2-4kc-malta_4.5.5-1_mips.deb')
158 deb_hash = 'a3c84f3e88b54e06107d65a410d1d1e8e0f340f8'
159 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
160 kernel_path = self.extract_from_deb(deb_path,
161 '/boot/vmlinux-4.5.0-2-4kc-malta')
162 initrd_url = ('https://github.com/groeck/linux-build-test/raw/'
163 '8584a59ed9e5eb5ee7ca91f6d74bbb06619205b8/rootfs/'
164 'mips/rootfs.cpio.gz')
165 initrd_hash = 'bf806e17009360a866bf537f6de66590de349a99'
166 initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash)
167 initrd_path = self.workdir + "rootfs.cpio"
169 with gzip.open(initrd_path_gz, 'rb') as f_in:
170 with open(initrd_path, 'wb') as f_out:
171 shutil.copyfileobj(f_in, f_out)
173 self.vm.set_machine('malta')
174 self.vm.set_console()
175 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE
176 + 'console=ttyS0 console=tty '
177 + 'rdinit=/sbin/init noreboot')
178 self.vm.add_args('-kernel', kernel_path,
179 '-initrd', initrd_path,
180 '-append', kernel_command_line,
181 '-no-reboot')
182 self.vm.launch()
183 self.wait_for_console_pattern('Boot successful.')
185 self.exec_command_and_wait_for_pattern('cat /proc/cpuinfo',
186 'BogoMIPS')
187 self.exec_command_and_wait_for_pattern('uname -a',
188 'Debian')
189 self.exec_command_and_wait_for_pattern('reboot',
190 'reboot: Restarting system')
192 def do_test_mips_malta32el_nanomips(self, kernel_url, kernel_hash):
193 kernel_path_xz = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
194 kernel_path = self.workdir + "kernel"
195 with lzma.open(kernel_path_xz, 'rb') as f_in:
196 with open(kernel_path, 'wb') as f_out:
197 shutil.copyfileobj(f_in, f_out)
199 self.vm.set_machine('malta')
200 self.vm.set_console()
201 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE
202 + 'mem=256m@@0x0 '
203 + 'console=ttyS0')
204 self.vm.add_args('-no-reboot',
205 '-cpu', 'I7200',
206 '-kernel', kernel_path,
207 '-append', kernel_command_line)
208 self.vm.launch()
209 console_pattern = 'Kernel command line: %s' % kernel_command_line
210 self.wait_for_console_pattern(console_pattern)
212 def test_mips_malta32el_nanomips_4k(self):
214 :avocado: tags=arch:mipsel
215 :avocado: tags=machine:malta
216 :avocado: tags=endian:little
218 kernel_url = ('https://mipsdistros.mips.com/LinuxDistro/nanomips/'
219 'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/'
220 'generic_nano32r6el_page4k.xz')
221 kernel_hash = '477456aafd2a0f1ddc9482727f20fe9575565dd6'
222 self.do_test_mips_malta32el_nanomips(kernel_url, kernel_hash)
224 def test_mips_malta32el_nanomips_16k_up(self):
226 :avocado: tags=arch:mipsel
227 :avocado: tags=machine:malta
228 :avocado: tags=endian:little
230 kernel_url = ('https://mipsdistros.mips.com/LinuxDistro/nanomips/'
231 'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/'
232 'generic_nano32r6el_page16k_up.xz')
233 kernel_hash = 'e882868f944c71c816e832e2303b7874d044a7bc'
234 self.do_test_mips_malta32el_nanomips(kernel_url, kernel_hash)
236 def test_mips_malta32el_nanomips_64k_dbg(self):
238 :avocado: tags=arch:mipsel
239 :avocado: tags=machine:malta
240 :avocado: tags=endian:little
242 kernel_url = ('https://mipsdistros.mips.com/LinuxDistro/nanomips/'
243 'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/'
244 'generic_nano32r6el_page64k_dbg.xz')
245 kernel_hash = '18d1c68f2e23429e266ca39ba5349ccd0aeb7180'
246 self.do_test_mips_malta32el_nanomips(kernel_url, kernel_hash)
248 def test_aarch64_virt(self):
250 :avocado: tags=arch:aarch64
251 :avocado: tags=machine:virt
253 kernel_url = ('https://download.fedoraproject.org/pub/fedora/linux/'
254 'releases/29/Everything/aarch64/os/images/pxeboot/vmlinuz')
255 kernel_hash = '8c73e469fc6ea06a58dc83a628fc695b693b8493'
256 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
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('-cpu', 'cortex-a53',
263 '-kernel', kernel_path,
264 '-append', kernel_command_line)
265 self.vm.launch()
266 console_pattern = 'Kernel command line: %s' % kernel_command_line
267 self.wait_for_console_pattern(console_pattern)
269 def test_arm_virt(self):
271 :avocado: tags=arch:arm
272 :avocado: tags=machine:virt
274 kernel_url = ('https://download.fedoraproject.org/pub/fedora/linux/'
275 'releases/29/Everything/armhfp/os/images/pxeboot/vmlinuz')
276 kernel_hash = 'e9826d741b4fb04cadba8d4824d1ed3b7fb8b4d4'
277 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
279 self.vm.set_machine('virt')
280 self.vm.set_console()
281 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
282 'console=ttyAMA0')
283 self.vm.add_args('-kernel', kernel_path,
284 '-append', kernel_command_line)
285 self.vm.launch()
286 console_pattern = 'Kernel command line: %s' % kernel_command_line
287 self.wait_for_console_pattern(console_pattern)
289 def test_arm_emcraft_sf2(self):
291 :avocado: tags=arch:arm
292 :avocado: tags=machine:emcraft_sf2
293 :avocado: tags=endian:little
295 uboot_url = ('https://raw.githubusercontent.com/'
296 'Subbaraya-Sundeep/qemu-test-binaries/'
297 'fa030bd77a014a0b8e360d3b7011df89283a2f0b/u-boot')
298 uboot_hash = 'abba5d9c24cdd2d49cdc2a8aa92976cf20737eff'
299 uboot_path = self.fetch_asset(uboot_url, asset_hash=uboot_hash)
300 spi_url = ('https://raw.githubusercontent.com/'
301 'Subbaraya-Sundeep/qemu-test-binaries/'
302 'fa030bd77a014a0b8e360d3b7011df89283a2f0b/spi.bin')
303 spi_hash = '85f698329d38de63aea6e884a86fbde70890a78a'
304 spi_path = self.fetch_asset(spi_url, asset_hash=spi_hash)
306 self.vm.set_machine('emcraft-sf2')
307 self.vm.set_console()
308 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE
309 self.vm.add_args('-kernel', uboot_path,
310 '-append', kernel_command_line,
311 '-drive', 'file=' + spi_path + ',if=mtd,format=raw',
312 '-no-reboot')
313 self.vm.launch()
314 self.wait_for_console_pattern('init started: BusyBox')
316 def test_s390x_s390_ccw_virtio(self):
318 :avocado: tags=arch:s390x
319 :avocado: tags=machine:s390_ccw_virtio
321 kernel_url = ('https://download.fedoraproject.org/pub/fedora-secondary/'
322 'releases/29/Everything/s390x/os/images/kernel.img')
323 kernel_hash = 'e8e8439103ef8053418ef062644ffd46a7919313'
324 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
326 self.vm.set_machine('s390-ccw-virtio')
327 self.vm.set_console()
328 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=sclp0'
329 self.vm.add_args('-nodefaults',
330 '-kernel', kernel_path,
331 '-append', kernel_command_line)
332 self.vm.launch()
333 console_pattern = 'Kernel command line: %s' % kernel_command_line
334 self.wait_for_console_pattern(console_pattern)
336 def test_alpha_clipper(self):
338 :avocado: tags=arch:alpha
339 :avocado: tags=machine:clipper
341 kernel_url = ('http://archive.debian.org/debian/dists/lenny/main/'
342 'installer-alpha/current/images/cdrom/vmlinuz')
343 kernel_hash = '3a943149335529e2ed3e74d0d787b85fb5671ba3'
344 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
346 uncompressed_kernel = archive.uncompress(kernel_path, self.workdir)
348 self.vm.set_machine('clipper')
349 self.vm.set_console()
350 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
351 self.vm.add_args('-vga', 'std',
352 '-kernel', uncompressed_kernel,
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)