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 11import os 12import lzma 13import gzip 14import shutil 15 16from avocado import skip 17from avocado import skipUnless 18from avocado import skipIf 19from avocado_qemu import QemuSystemTest 20from avocado_qemu import exec_command 21from avocado_qemu import exec_command_and_wait_for_pattern 22from avocado_qemu import interrupt_interactive_console_until_pattern 23from avocado_qemu import wait_for_console_pattern 24from avocado.utils import process 25from avocado.utils import archive 26 27""" 28Round up to next power of 2 29""" 30def pow2ceil(x): 31 return 1 if x == 0 else 2**(x - 1).bit_length() 32 33def file_truncate(path, size): 34 if size != os.path.getsize(path): 35 with open(path, 'ab+') as fd: 36 fd.truncate(size) 37 38""" 39Expand file size to next power of 2 40""" 41def image_pow2ceil_expand(path): 42 size = os.path.getsize(path) 43 size_aligned = pow2ceil(size) 44 if size != size_aligned: 45 with open(path, 'ab+') as fd: 46 fd.truncate(size_aligned) 47 48class LinuxKernelTest(QemuSystemTest): 49 KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 ' 50 51 def wait_for_console_pattern(self, success_message, vm=None): 52 wait_for_console_pattern(self, success_message, 53 failure_message='Kernel panic - not syncing', 54 vm=vm) 55 56 def extract_from_deb(self, deb, path): 57 """ 58 Extracts a file from a deb package into the test workdir 59 60 :param deb: path to the deb archive 61 :param path: path within the deb archive of the file to be extracted 62 :returns: path of the extracted file 63 """ 64 cwd = os.getcwd() 65 os.chdir(self.workdir) 66 file_path = process.run("ar t %s" % deb).stdout_text.split()[2] 67 process.run("ar x %s %s" % (deb, file_path)) 68 archive.extract(file_path, self.workdir) 69 os.chdir(cwd) 70 # Return complete path to extracted file. Because callers to 71 # extract_from_deb() specify 'path' with a leading slash, it is 72 # necessary to use os.path.relpath() as otherwise os.path.join() 73 # interprets it as an absolute path and drops the self.workdir part. 74 return os.path.normpath(os.path.join(self.workdir, 75 os.path.relpath(path, '/'))) 76 77 def extract_from_rpm(self, rpm, path): 78 """ 79 Extracts a file from an RPM package into the test workdir. 80 81 :param rpm: path to the rpm archive 82 :param path: path within the rpm archive of the file to be extracted 83 needs to be a relative path (starting with './') because 84 cpio(1), which is used to extract the file, expects that. 85 :returns: path of the extracted file 86 """ 87 cwd = os.getcwd() 88 os.chdir(self.workdir) 89 process.run("rpm2cpio %s | cpio -id %s" % (rpm, path), shell=True) 90 os.chdir(cwd) 91 return os.path.normpath(os.path.join(self.workdir, path)) 92 93class BootLinuxConsole(LinuxKernelTest): 94 """ 95 Boots a Linux kernel and checks that the console is operational and the 96 kernel command line is properly passed from QEMU to the kernel 97 """ 98 timeout = 90 99 100 def test_x86_64_pc(self): 101 """ 102 :avocado: tags=arch:x86_64 103 :avocado: tags=machine:pc 104 """ 105 kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora' 106 '/linux/releases/29/Everything/x86_64/os/images/pxeboot' 107 '/vmlinuz') 108 kernel_hash = '23bebd2680757891cf7adedb033532163a792495' 109 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) 110 111 self.vm.set_console() 112 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0' 113 self.vm.add_args('-kernel', kernel_path, 114 '-append', kernel_command_line) 115 self.vm.launch() 116 console_pattern = 'Kernel command line: %s' % kernel_command_line 117 self.wait_for_console_pattern(console_pattern) 118 119 @skip('https://gitlab.com/qemu-project/qemu/-/issues/1884') 120 def test_mips_malta(self): 121 """ 122 :avocado: tags=arch:mips 123 :avocado: tags=machine:malta 124 :avocado: tags=endian:big 125 """ 126 deb_url = ('http://snapshot.debian.org/archive/debian/' 127 '20130217T032700Z/pool/main/l/linux-2.6/' 128 'linux-image-2.6.32-5-4kc-malta_2.6.32-48_mips.deb') 129 deb_hash = 'a8cfc28ad8f45f54811fc6cf74fc43ffcfe0ba04' 130 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 131 kernel_path = self.extract_from_deb(deb_path, 132 '/boot/vmlinux-2.6.32-5-4kc-malta') 133 134 self.vm.set_console() 135 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0' 136 self.vm.add_args('-kernel', kernel_path, 137 '-append', kernel_command_line) 138 self.vm.launch() 139 console_pattern = 'Kernel command line: %s' % kernel_command_line 140 self.wait_for_console_pattern(console_pattern) 141 142 @skip('https://gitlab.com/qemu-project/qemu/-/issues/1884') 143 def test_mips64el_malta(self): 144 """ 145 This test requires the ar tool to extract "data.tar.gz" from 146 the Debian package. 147 148 The kernel can be rebuilt using this Debian kernel source [1] and 149 following the instructions on [2]. 150 151 [1] http://snapshot.debian.org/package/linux-2.6/2.6.32-48/ 152 #linux-source-2.6.32_2.6.32-48 153 [2] https://kernel-team.pages.debian.net/kernel-handbook/ 154 ch-common-tasks.html#s-common-official 155 156 :avocado: tags=arch:mips64el 157 :avocado: tags=machine:malta 158 """ 159 deb_url = ('http://snapshot.debian.org/archive/debian/' 160 '20130217T032700Z/pool/main/l/linux-2.6/' 161 'linux-image-2.6.32-5-5kc-malta_2.6.32-48_mipsel.deb') 162 deb_hash = '1aaec92083bf22fda31e0d27fa8d9a388e5fc3d5' 163 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 164 kernel_path = self.extract_from_deb(deb_path, 165 '/boot/vmlinux-2.6.32-5-5kc-malta') 166 167 self.vm.set_console() 168 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0' 169 self.vm.add_args('-kernel', kernel_path, 170 '-append', kernel_command_line) 171 self.vm.launch() 172 console_pattern = 'Kernel command line: %s' % kernel_command_line 173 self.wait_for_console_pattern(console_pattern) 174 175 def test_mips64el_fuloong2e(self): 176 """ 177 :avocado: tags=arch:mips64el 178 :avocado: tags=machine:fuloong2e 179 :avocado: tags=endian:little 180 """ 181 deb_url = ('http://archive.debian.org/debian/pool/main/l/linux/' 182 'linux-image-3.16.0-6-loongson-2e_3.16.56-1+deb8u1_mipsel.deb') 183 deb_hash = 'd04d446045deecf7b755ef576551de0c4184dd44' 184 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 185 kernel_path = self.extract_from_deb(deb_path, 186 '/boot/vmlinux-3.16.0-6-loongson-2e') 187 188 self.vm.set_console() 189 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0' 190 self.vm.add_args('-kernel', kernel_path, 191 '-append', kernel_command_line) 192 self.vm.launch() 193 console_pattern = 'Kernel command line: %s' % kernel_command_line 194 self.wait_for_console_pattern(console_pattern) 195 196 @skip('https://gitlab.com/qemu-project/qemu/-/issues/1884') 197 def test_mips_malta_cpio(self): 198 """ 199 :avocado: tags=arch:mips 200 :avocado: tags=machine:malta 201 :avocado: tags=endian:big 202 """ 203 deb_url = ('http://snapshot.debian.org/archive/debian/' 204 '20160601T041800Z/pool/main/l/linux/' 205 'linux-image-4.5.0-2-4kc-malta_4.5.5-1_mips.deb') 206 deb_hash = 'a3c84f3e88b54e06107d65a410d1d1e8e0f340f8' 207 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 208 kernel_path = self.extract_from_deb(deb_path, 209 '/boot/vmlinux-4.5.0-2-4kc-malta') 210 initrd_url = ('https://github.com/groeck/linux-build-test/raw/' 211 '8584a59ed9e5eb5ee7ca91f6d74bbb06619205b8/rootfs/' 212 'mips/rootfs.cpio.gz') 213 initrd_hash = 'bf806e17009360a866bf537f6de66590de349a99' 214 initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash) 215 initrd_path = self.workdir + "rootfs.cpio" 216 archive.gzip_uncompress(initrd_path_gz, initrd_path) 217 218 self.vm.set_console() 219 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE 220 + 'console=ttyS0 console=tty ' 221 + 'rdinit=/sbin/init noreboot') 222 self.vm.add_args('-kernel', kernel_path, 223 '-initrd', initrd_path, 224 '-append', kernel_command_line, 225 '-no-reboot') 226 self.vm.launch() 227 self.wait_for_console_pattern('Boot successful.') 228 229 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 230 'BogoMIPS') 231 exec_command_and_wait_for_pattern(self, 'uname -a', 232 'Debian') 233 exec_command_and_wait_for_pattern(self, 'reboot', 234 'reboot: Restarting system') 235 # Wait for VM to shut down gracefully 236 self.vm.wait() 237 238 @skip('https://gitlab.com/qemu-project/qemu/-/issues/1884') 239 @skipUnless(os.getenv('AVOCADO_ALLOW_UNTRUSTED_CODE'), 'untrusted code') 240 def test_mips64el_malta_5KEc_cpio(self): 241 """ 242 :avocado: tags=arch:mips64el 243 :avocado: tags=machine:malta 244 :avocado: tags=endian:little 245 :avocado: tags=cpu:5KEc 246 """ 247 kernel_url = ('https://github.com/philmd/qemu-testing-blob/' 248 'raw/9ad2df38/mips/malta/mips64el/' 249 'vmlinux-3.19.3.mtoman.20150408') 250 kernel_hash = '00d1d268fb9f7d8beda1de6bebcc46e884d71754' 251 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) 252 initrd_url = ('https://github.com/groeck/linux-build-test/' 253 'raw/8584a59e/rootfs/' 254 'mipsel64/rootfs.mipsel64r1.cpio.gz') 255 initrd_hash = '1dbb8a396e916847325284dbe2151167' 256 initrd_path_gz = self.fetch_asset(initrd_url, algorithm='md5', 257 asset_hash=initrd_hash) 258 initrd_path = self.workdir + "rootfs.cpio" 259 archive.gzip_uncompress(initrd_path_gz, initrd_path) 260 261 self.vm.set_console() 262 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE 263 + 'console=ttyS0 console=tty ' 264 + 'rdinit=/sbin/init noreboot') 265 self.vm.add_args('-kernel', kernel_path, 266 '-initrd', initrd_path, 267 '-append', kernel_command_line, 268 '-no-reboot') 269 self.vm.launch() 270 wait_for_console_pattern(self, 'Boot successful.') 271 272 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 273 'MIPS 5KE') 274 exec_command_and_wait_for_pattern(self, 'uname -a', 275 '3.19.3.mtoman.20150408') 276 exec_command_and_wait_for_pattern(self, 'reboot', 277 'reboot: Restarting system') 278 # Wait for VM to shut down gracefully 279 self.vm.wait() 280 281 def do_test_mips_malta32el_nanomips(self, kernel_url, kernel_hash): 282 kernel_path_xz = self.fetch_asset(kernel_url, asset_hash=kernel_hash) 283 kernel_path = self.workdir + "kernel" 284 with lzma.open(kernel_path_xz, 'rb') as f_in: 285 with open(kernel_path, 'wb') as f_out: 286 shutil.copyfileobj(f_in, f_out) 287 288 self.vm.set_console() 289 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE 290 + 'mem=256m@@0x0 ' 291 + 'console=ttyS0') 292 self.vm.add_args('-no-reboot', 293 '-kernel', kernel_path, 294 '-append', kernel_command_line) 295 self.vm.launch() 296 console_pattern = 'Kernel command line: %s' % kernel_command_line 297 self.wait_for_console_pattern(console_pattern) 298 299 @skip('https://gitlab.com/qemu-project/qemu/-/issues/1884') 300 def test_mips_malta32el_nanomips_4k(self): 301 """ 302 :avocado: tags=arch:mipsel 303 :avocado: tags=machine:malta 304 :avocado: tags=endian:little 305 :avocado: tags=cpu:I7200 306 """ 307 kernel_url = ('https://mipsdistros.mips.com/LinuxDistro/nanomips/' 308 'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/' 309 'generic_nano32r6el_page4k.xz') 310 kernel_hash = '477456aafd2a0f1ddc9482727f20fe9575565dd6' 311 self.do_test_mips_malta32el_nanomips(kernel_url, kernel_hash) 312 313 @skip('https://gitlab.com/qemu-project/qemu/-/issues/1884') 314 def test_mips_malta32el_nanomips_16k_up(self): 315 """ 316 :avocado: tags=arch:mipsel 317 :avocado: tags=machine:malta 318 :avocado: tags=endian:little 319 :avocado: tags=cpu:I7200 320 """ 321 kernel_url = ('https://mipsdistros.mips.com/LinuxDistro/nanomips/' 322 'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/' 323 'generic_nano32r6el_page16k_up.xz') 324 kernel_hash = 'e882868f944c71c816e832e2303b7874d044a7bc' 325 self.do_test_mips_malta32el_nanomips(kernel_url, kernel_hash) 326 327 @skip('https://gitlab.com/qemu-project/qemu/-/issues/1884') 328 def test_mips_malta32el_nanomips_64k_dbg(self): 329 """ 330 :avocado: tags=arch:mipsel 331 :avocado: tags=machine:malta 332 :avocado: tags=endian:little 333 :avocado: tags=cpu:I7200 334 """ 335 kernel_url = ('https://mipsdistros.mips.com/LinuxDistro/nanomips/' 336 'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/' 337 'generic_nano32r6el_page64k_dbg.xz') 338 kernel_hash = '18d1c68f2e23429e266ca39ba5349ccd0aeb7180' 339 self.do_test_mips_malta32el_nanomips(kernel_url, kernel_hash) 340 341 def test_aarch64_xlnx_versal_virt(self): 342 """ 343 :avocado: tags=arch:aarch64 344 :avocado: tags=machine:xlnx-versal-virt 345 :avocado: tags=device:pl011 346 :avocado: tags=device:arm_gicv3 347 :avocado: tags=accel:tcg 348 """ 349 images_url = ('http://ports.ubuntu.com/ubuntu-ports/dists/' 350 'bionic-updates/main/installer-arm64/' 351 '20101020ubuntu543.19/images/') 352 kernel_url = images_url + 'netboot/ubuntu-installer/arm64/linux' 353 kernel_hash = 'e167757620640eb26de0972f578741924abb3a82' 354 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) 355 356 initrd_url = images_url + 'netboot/ubuntu-installer/arm64/initrd.gz' 357 initrd_hash = 'cab5cb3fcefca8408aa5aae57f24574bfce8bdb9' 358 initrd_path = self.fetch_asset(initrd_url, asset_hash=initrd_hash) 359 360 self.vm.set_console() 361 self.vm.add_args('-m', '2G', 362 '-accel', 'tcg', 363 '-kernel', kernel_path, 364 '-initrd', initrd_path) 365 self.vm.launch() 366 self.wait_for_console_pattern('Checked W+X mappings: passed') 367 368 def test_arm_virt(self): 369 """ 370 :avocado: tags=arch:arm 371 :avocado: tags=machine:virt 372 :avocado: tags=accel:tcg 373 """ 374 kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora' 375 '/linux/releases/29/Everything/armhfp/os/images/pxeboot' 376 '/vmlinuz') 377 kernel_hash = 'e9826d741b4fb04cadba8d4824d1ed3b7fb8b4d4' 378 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) 379 380 self.vm.set_console() 381 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 382 'console=ttyAMA0') 383 self.vm.add_args('-kernel', kernel_path, 384 '-append', kernel_command_line) 385 self.vm.launch() 386 console_pattern = 'Kernel command line: %s' % kernel_command_line 387 self.wait_for_console_pattern(console_pattern) 388 389 def test_arm_emcraft_sf2(self): 390 """ 391 :avocado: tags=arch:arm 392 :avocado: tags=machine:emcraft-sf2 393 :avocado: tags=endian:little 394 :avocado: tags=u-boot 395 :avocado: tags=accel:tcg 396 """ 397 self.require_netdev('user') 398 399 uboot_url = ('https://raw.githubusercontent.com/' 400 'Subbaraya-Sundeep/qemu-test-binaries/' 401 'fe371d32e50ca682391e1e70ab98c2942aeffb01/u-boot') 402 uboot_hash = 'cbb8cbab970f594bf6523b9855be209c08374ae2' 403 uboot_path = self.fetch_asset(uboot_url, asset_hash=uboot_hash) 404 spi_url = ('https://raw.githubusercontent.com/' 405 'Subbaraya-Sundeep/qemu-test-binaries/' 406 'fe371d32e50ca682391e1e70ab98c2942aeffb01/spi.bin') 407 spi_hash = '65523a1835949b6f4553be96dec1b6a38fb05501' 408 spi_path = self.fetch_asset(spi_url, asset_hash=spi_hash) 409 410 file_truncate(spi_path, 16 << 20) # Spansion S25FL128SDPBHICO is 16 MiB 411 412 self.vm.set_console() 413 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE 414 self.vm.add_args('-kernel', uboot_path, 415 '-append', kernel_command_line, 416 '-drive', 'file=' + spi_path + ',if=mtd,format=raw', 417 '-no-reboot') 418 self.vm.launch() 419 self.wait_for_console_pattern('Enter \'help\' for a list') 420 421 exec_command_and_wait_for_pattern(self, 'ifconfig eth0 10.0.2.15', 422 'eth0: link becomes ready') 423 exec_command_and_wait_for_pattern(self, 'ping -c 3 10.0.2.2', 424 '3 packets transmitted, 3 packets received, 0% packet loss') 425 426 def do_test_arm_raspi2(self, uart_id): 427 """ 428 :avocado: tags=accel:tcg 429 430 The kernel can be rebuilt using the kernel source referenced 431 and following the instructions on the on: 432 https://www.raspberrypi.org/documentation/linux/kernel/building.md 433 """ 434 serial_kernel_cmdline = { 435 0: 'earlycon=pl011,0x3f201000 console=ttyAMA0', 436 } 437 deb_url = ('http://archive.raspberrypi.org/debian/' 438 'pool/main/r/raspberrypi-firmware/' 439 'raspberrypi-kernel_1.20190215-1_armhf.deb') 440 deb_hash = 'cd284220b32128c5084037553db3c482426f3972' 441 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 442 kernel_path = self.extract_from_deb(deb_path, '/boot/kernel7.img') 443 dtb_path = self.extract_from_deb(deb_path, '/boot/bcm2709-rpi-2-b.dtb') 444 445 self.vm.set_console() 446 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 447 serial_kernel_cmdline[uart_id] + 448 ' root=/dev/mmcblk0p2 rootwait ' + 449 'dwc_otg.fiq_fsm_enable=0') 450 self.vm.add_args('-kernel', kernel_path, 451 '-dtb', dtb_path, 452 '-append', kernel_command_line, 453 '-device', 'usb-kbd') 454 self.vm.launch() 455 console_pattern = 'Kernel command line: %s' % kernel_command_line 456 self.wait_for_console_pattern(console_pattern) 457 console_pattern = 'Product: QEMU USB Keyboard' 458 self.wait_for_console_pattern(console_pattern) 459 460 def test_arm_raspi2_uart0(self): 461 """ 462 :avocado: tags=arch:arm 463 :avocado: tags=machine:raspi2b 464 :avocado: tags=device:pl011 465 :avocado: tags=accel:tcg 466 """ 467 self.do_test_arm_raspi2(0) 468 469 def test_arm_raspi2_initrd(self): 470 """ 471 :avocado: tags=arch:arm 472 :avocado: tags=machine:raspi2b 473 """ 474 deb_url = ('http://archive.raspberrypi.org/debian/' 475 'pool/main/r/raspberrypi-firmware/' 476 'raspberrypi-kernel_1.20190215-1_armhf.deb') 477 deb_hash = 'cd284220b32128c5084037553db3c482426f3972' 478 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 479 kernel_path = self.extract_from_deb(deb_path, '/boot/kernel7.img') 480 dtb_path = self.extract_from_deb(deb_path, '/boot/bcm2709-rpi-2-b.dtb') 481 482 initrd_url = ('https://github.com/groeck/linux-build-test/raw/' 483 '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/' 484 'arm/rootfs-armv7a.cpio.gz') 485 initrd_hash = '604b2e45cdf35045846b8bbfbf2129b1891bdc9c' 486 initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash) 487 initrd_path = os.path.join(self.workdir, 'rootfs.cpio') 488 archive.gzip_uncompress(initrd_path_gz, initrd_path) 489 490 self.vm.set_console() 491 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 492 'earlycon=pl011,0x3f201000 console=ttyAMA0 ' 493 'panic=-1 noreboot ' + 494 'dwc_otg.fiq_fsm_enable=0') 495 self.vm.add_args('-kernel', kernel_path, 496 '-dtb', dtb_path, 497 '-initrd', initrd_path, 498 '-append', kernel_command_line, 499 '-no-reboot') 500 self.vm.launch() 501 self.wait_for_console_pattern('Boot successful.') 502 503 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 504 'BCM2835') 505 exec_command_and_wait_for_pattern(self, 'cat /proc/iomem', 506 '/soc/cprman@7e101000') 507 exec_command_and_wait_for_pattern(self, 'halt', 'reboot: System halted') 508 # Wait for VM to shut down gracefully 509 self.vm.wait() 510 511 def test_arm_exynos4210_initrd(self): 512 """ 513 :avocado: tags=arch:arm 514 :avocado: tags=machine:smdkc210 515 :avocado: tags=accel:tcg 516 """ 517 deb_url = ('https://snapshot.debian.org/archive/debian/' 518 '20190928T224601Z/pool/main/l/linux/' 519 'linux-image-4.19.0-6-armmp_4.19.67-2+deb10u1_armhf.deb') 520 deb_hash = 'fa9df4a0d38936cb50084838f2cb933f570d7d82' 521 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 522 kernel_path = self.extract_from_deb(deb_path, 523 '/boot/vmlinuz-4.19.0-6-armmp') 524 dtb_path = '/usr/lib/linux-image-4.19.0-6-armmp/exynos4210-smdkv310.dtb' 525 dtb_path = self.extract_from_deb(deb_path, dtb_path) 526 527 initrd_url = ('https://github.com/groeck/linux-build-test/raw/' 528 '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/' 529 'arm/rootfs-armv5.cpio.gz') 530 initrd_hash = '2b50f1873e113523967806f4da2afe385462ff9b' 531 initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash) 532 initrd_path = os.path.join(self.workdir, 'rootfs.cpio') 533 archive.gzip_uncompress(initrd_path_gz, initrd_path) 534 535 self.vm.set_console() 536 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 537 'earlycon=exynos4210,0x13800000 earlyprintk ' + 538 'console=ttySAC0,115200n8 ' + 539 'random.trust_cpu=off cryptomgr.notests ' + 540 'cpuidle.off=1 panic=-1 noreboot') 541 542 self.vm.add_args('-kernel', kernel_path, 543 '-dtb', dtb_path, 544 '-initrd', initrd_path, 545 '-append', kernel_command_line, 546 '-no-reboot') 547 self.vm.launch() 548 549 self.wait_for_console_pattern('Boot successful.') 550 # TODO user command, for now the uart is stuck 551 552 def test_arm_cubieboard_initrd(self): 553 """ 554 :avocado: tags=arch:arm 555 :avocado: tags=machine:cubieboard 556 :avocado: tags=accel:tcg 557 """ 558 deb_url = ('https://apt.armbian.com/pool/main/l/' 559 'linux-5.10.16-sunxi/linux-image-current-sunxi_21.02.2_armhf.deb') 560 deb_hash = '9fa84beda245cabf0b4fa84cf6eaa7738ead1da0' 561 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 562 kernel_path = self.extract_from_deb(deb_path, 563 '/boot/vmlinuz-5.10.16-sunxi') 564 dtb_path = '/usr/lib/linux-image-current-sunxi/sun4i-a10-cubieboard.dtb' 565 dtb_path = self.extract_from_deb(deb_path, dtb_path) 566 initrd_url = ('https://github.com/groeck/linux-build-test/raw/' 567 '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/' 568 'arm/rootfs-armv5.cpio.gz') 569 initrd_hash = '2b50f1873e113523967806f4da2afe385462ff9b' 570 initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash) 571 initrd_path = os.path.join(self.workdir, 'rootfs.cpio') 572 archive.gzip_uncompress(initrd_path_gz, initrd_path) 573 574 self.vm.set_console() 575 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 576 'console=ttyS0,115200 ' 577 'usbcore.nousb ' 578 'panic=-1 noreboot') 579 self.vm.add_args('-kernel', kernel_path, 580 '-dtb', dtb_path, 581 '-initrd', initrd_path, 582 '-append', kernel_command_line, 583 '-no-reboot') 584 self.vm.launch() 585 self.wait_for_console_pattern('Boot successful.') 586 587 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 588 'Allwinner sun4i/sun5i') 589 exec_command_and_wait_for_pattern(self, 'cat /proc/iomem', 590 'system-control@1c00000') 591 exec_command_and_wait_for_pattern(self, 'reboot', 592 'reboot: Restarting system') 593 # Wait for VM to shut down gracefully 594 self.vm.wait() 595 596 def test_arm_cubieboard_sata(self): 597 """ 598 :avocado: tags=arch:arm 599 :avocado: tags=machine:cubieboard 600 :avocado: tags=accel:tcg 601 """ 602 deb_url = ('https://apt.armbian.com/pool/main/l/' 603 'linux-5.10.16-sunxi/linux-image-current-sunxi_21.02.2_armhf.deb') 604 deb_hash = '9fa84beda245cabf0b4fa84cf6eaa7738ead1da0' 605 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 606 kernel_path = self.extract_from_deb(deb_path, 607 '/boot/vmlinuz-5.10.16-sunxi') 608 dtb_path = '/usr/lib/linux-image-current-sunxi/sun4i-a10-cubieboard.dtb' 609 dtb_path = self.extract_from_deb(deb_path, dtb_path) 610 rootfs_url = ('https://github.com/groeck/linux-build-test/raw/' 611 '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/' 612 'arm/rootfs-armv5.ext2.gz') 613 rootfs_hash = '093e89d2b4d982234bf528bc9fb2f2f17a9d1f93' 614 rootfs_path_gz = self.fetch_asset(rootfs_url, asset_hash=rootfs_hash) 615 rootfs_path = os.path.join(self.workdir, 'rootfs.cpio') 616 archive.gzip_uncompress(rootfs_path_gz, rootfs_path) 617 618 self.vm.set_console() 619 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 620 'console=ttyS0,115200 ' 621 'usbcore.nousb ' 622 'root=/dev/sda ro ' 623 'panic=-1 noreboot') 624 self.vm.add_args('-kernel', kernel_path, 625 '-dtb', dtb_path, 626 '-drive', 'if=none,format=raw,id=disk0,file=' 627 + rootfs_path, 628 '-device', 'ide-hd,bus=ide.0,drive=disk0', 629 '-append', kernel_command_line, 630 '-no-reboot') 631 self.vm.launch() 632 self.wait_for_console_pattern('Boot successful.') 633 634 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 635 'Allwinner sun4i/sun5i') 636 exec_command_and_wait_for_pattern(self, 'cat /proc/partitions', 637 'sda') 638 exec_command_and_wait_for_pattern(self, 'reboot', 639 'reboot: Restarting system') 640 # Wait for VM to shut down gracefully 641 self.vm.wait() 642 643 @skipUnless(os.getenv('AVOCADO_ALLOW_LARGE_STORAGE'), 'storage limited') 644 def test_arm_cubieboard_openwrt_22_03_2(self): 645 """ 646 :avocado: tags=arch:arm 647 :avocado: tags=machine:cubieboard 648 :avocado: tags=device:sd 649 """ 650 651 # This test download a 7.5 MiB compressed image and expand it 652 # to 126 MiB. 653 image_url = ('https://downloads.openwrt.org/releases/22.03.2/targets/' 654 'sunxi/cortexa8/openwrt-22.03.2-sunxi-cortexa8-' 655 'cubietech_a10-cubieboard-ext4-sdcard.img.gz') 656 image_hash = ('94b5ecbfbc0b3b56276e5146b899eafa' 657 '2ac5dc2d08733d6705af9f144f39f554') 658 image_path_gz = self.fetch_asset(image_url, asset_hash=image_hash, 659 algorithm='sha256') 660 image_path = archive.extract(image_path_gz, self.workdir) 661 image_pow2ceil_expand(image_path) 662 663 self.vm.set_console() 664 self.vm.add_args('-drive', 'file=' + image_path + ',if=sd,format=raw', 665 '-nic', 'user', 666 '-no-reboot') 667 self.vm.launch() 668 669 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 670 'usbcore.nousb ' 671 'noreboot') 672 673 self.wait_for_console_pattern('U-Boot SPL') 674 675 interrupt_interactive_console_until_pattern( 676 self, 'Hit any key to stop autoboot:', '=>') 677 exec_command_and_wait_for_pattern(self, "setenv extraargs '" + 678 kernel_command_line + "'", '=>') 679 exec_command_and_wait_for_pattern(self, 'boot', 'Starting kernel ...'); 680 681 self.wait_for_console_pattern( 682 'Please press Enter to activate this console.') 683 684 exec_command_and_wait_for_pattern(self, ' ', 'root@') 685 686 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 687 'Allwinner sun4i/sun5i') 688 exec_command_and_wait_for_pattern(self, 'reboot', 689 'reboot: Restarting system') 690 # Wait for VM to shut down gracefully 691 self.vm.wait() 692 693 @skipUnless(os.getenv('AVOCADO_TIMEOUT_EXPECTED'), 'Test might timeout') 694 def test_arm_quanta_gsj(self): 695 """ 696 :avocado: tags=arch:arm 697 :avocado: tags=machine:quanta-gsj 698 :avocado: tags=accel:tcg 699 """ 700 # 25 MiB compressed, 32 MiB uncompressed. 701 image_url = ( 702 'https://github.com/hskinnemoen/openbmc/releases/download/' 703 '20200711-gsj-qemu-0/obmc-phosphor-image-gsj.static.mtd.gz') 704 image_hash = '14895e634923345cb5c8776037ff7876df96f6b1' 705 image_path_gz = self.fetch_asset(image_url, asset_hash=image_hash) 706 image_name = 'obmc.mtd' 707 image_path = os.path.join(self.workdir, image_name) 708 archive.gzip_uncompress(image_path_gz, image_path) 709 710 self.vm.set_console() 711 drive_args = 'file=' + image_path + ',if=mtd,bus=0,unit=0' 712 self.vm.add_args('-drive', drive_args) 713 self.vm.launch() 714 715 # Disable drivers and services that stall for a long time during boot, 716 # to avoid running past the 90-second timeout. These may be removed 717 # as the corresponding device support is added. 718 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + ( 719 'console=${console} ' 720 'mem=${mem} ' 721 'initcall_blacklist=npcm_i2c_bus_driver_init ' 722 'systemd.mask=systemd-random-seed.service ' 723 'systemd.mask=dropbearkey.service ' 724 ) 725 726 self.wait_for_console_pattern('> BootBlock by Nuvoton') 727 self.wait_for_console_pattern('>Device: Poleg BMC NPCM730') 728 self.wait_for_console_pattern('>Skip DDR init.') 729 self.wait_for_console_pattern('U-Boot ') 730 interrupt_interactive_console_until_pattern( 731 self, 'Hit any key to stop autoboot:', 'U-Boot>') 732 exec_command_and_wait_for_pattern( 733 self, "setenv bootargs ${bootargs} " + kernel_command_line, 734 'U-Boot>') 735 exec_command_and_wait_for_pattern( 736 self, 'run romboot', 'Booting Kernel from flash') 737 self.wait_for_console_pattern('Booting Linux on physical CPU 0x0') 738 self.wait_for_console_pattern('CPU1: thread -1, cpu 1, socket 0') 739 self.wait_for_console_pattern('OpenBMC Project Reference Distro') 740 self.wait_for_console_pattern('gsj login:') 741 742 def test_arm_quanta_gsj_initrd(self): 743 """ 744 :avocado: tags=arch:arm 745 :avocado: tags=machine:quanta-gsj 746 :avocado: tags=accel:tcg 747 """ 748 initrd_url = ( 749 'https://github.com/hskinnemoen/openbmc/releases/download/' 750 '20200711-gsj-qemu-0/obmc-phosphor-initramfs-gsj.cpio.xz') 751 initrd_hash = '98fefe5d7e56727b1eb17d5c00311b1b5c945300' 752 initrd_path = self.fetch_asset(initrd_url, asset_hash=initrd_hash) 753 kernel_url = ( 754 'https://github.com/hskinnemoen/openbmc/releases/download/' 755 '20200711-gsj-qemu-0/uImage-gsj.bin') 756 kernel_hash = 'fa67b2f141d56d39b3c54305c0e8a899c99eb2c7' 757 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) 758 dtb_url = ( 759 'https://github.com/hskinnemoen/openbmc/releases/download/' 760 '20200711-gsj-qemu-0/nuvoton-npcm730-gsj.dtb') 761 dtb_hash = '18315f7006d7b688d8312d5c727eecd819aa36a4' 762 dtb_path = self.fetch_asset(dtb_url, asset_hash=dtb_hash) 763 764 self.vm.set_console() 765 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 766 'console=ttyS0,115200n8 ' 767 'earlycon=uart8250,mmio32,0xf0001000') 768 self.vm.add_args('-kernel', kernel_path, 769 '-initrd', initrd_path, 770 '-dtb', dtb_path, 771 '-append', kernel_command_line) 772 self.vm.launch() 773 774 self.wait_for_console_pattern('Booting Linux on physical CPU 0x0') 775 self.wait_for_console_pattern('CPU1: thread -1, cpu 1, socket 0') 776 self.wait_for_console_pattern( 777 'Give root password for system maintenance') 778 779 def test_arm_bpim2u(self): 780 """ 781 :avocado: tags=arch:arm 782 :avocado: tags=machine:bpim2u 783 :avocado: tags=accel:tcg 784 """ 785 deb_url = ('https://apt.armbian.com/pool/main/l/linux-5.10.16-sunxi/' 786 'linux-image-current-sunxi_21.02.2_armhf.deb') 787 deb_hash = '9fa84beda245cabf0b4fa84cf6eaa7738ead1da0' 788 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 789 kernel_path = self.extract_from_deb(deb_path, 790 '/boot/vmlinuz-5.10.16-sunxi') 791 dtb_path = ('/usr/lib/linux-image-current-sunxi/' 792 'sun8i-r40-bananapi-m2-ultra.dtb') 793 dtb_path = self.extract_from_deb(deb_path, dtb_path) 794 795 self.vm.set_console() 796 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 797 'console=ttyS0,115200n8 ' 798 'earlycon=uart,mmio32,0x1c28000') 799 self.vm.add_args('-kernel', kernel_path, 800 '-dtb', dtb_path, 801 '-append', kernel_command_line) 802 self.vm.launch() 803 console_pattern = 'Kernel command line: %s' % kernel_command_line 804 self.wait_for_console_pattern(console_pattern) 805 806 def test_arm_bpim2u_initrd(self): 807 """ 808 :avocado: tags=arch:arm 809 :avocado: tags=accel:tcg 810 :avocado: tags=machine:bpim2u 811 """ 812 deb_url = ('https://apt.armbian.com/pool/main/l/linux-5.10.16-sunxi/' 813 'linux-image-current-sunxi_21.02.2_armhf.deb') 814 deb_hash = '9fa84beda245cabf0b4fa84cf6eaa7738ead1da0' 815 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 816 kernel_path = self.extract_from_deb(deb_path, 817 '/boot/vmlinuz-5.10.16-sunxi') 818 dtb_path = ('/usr/lib/linux-image-current-sunxi/' 819 'sun8i-r40-bananapi-m2-ultra.dtb') 820 dtb_path = self.extract_from_deb(deb_path, dtb_path) 821 initrd_url = ('https://github.com/groeck/linux-build-test/raw/' 822 '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/' 823 'arm/rootfs-armv7a.cpio.gz') 824 initrd_hash = '604b2e45cdf35045846b8bbfbf2129b1891bdc9c' 825 initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash) 826 initrd_path = os.path.join(self.workdir, 'rootfs.cpio') 827 archive.gzip_uncompress(initrd_path_gz, initrd_path) 828 829 self.vm.set_console() 830 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 831 'console=ttyS0,115200 ' 832 'panic=-1 noreboot') 833 self.vm.add_args('-kernel', kernel_path, 834 '-dtb', dtb_path, 835 '-initrd', initrd_path, 836 '-append', kernel_command_line, 837 '-no-reboot') 838 self.vm.launch() 839 self.wait_for_console_pattern('Boot successful.') 840 841 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 842 'Allwinner sun8i Family') 843 exec_command_and_wait_for_pattern(self, 'cat /proc/iomem', 844 'system-control@1c00000') 845 exec_command_and_wait_for_pattern(self, 'reboot', 846 'reboot: Restarting system') 847 # Wait for VM to shut down gracefully 848 self.vm.wait() 849 850 def test_arm_bpim2u_gmac(self): 851 """ 852 :avocado: tags=arch:arm 853 :avocado: tags=accel:tcg 854 :avocado: tags=machine:bpim2u 855 :avocado: tags=device:sd 856 """ 857 self.require_netdev('user') 858 859 deb_url = ('https://apt.armbian.com/pool/main/l/linux-5.10.16-sunxi/' 860 'linux-image-current-sunxi_21.02.2_armhf.deb') 861 deb_hash = '9fa84beda245cabf0b4fa84cf6eaa7738ead1da0' 862 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 863 kernel_path = self.extract_from_deb(deb_path, 864 '/boot/vmlinuz-5.10.16-sunxi') 865 dtb_path = ('/usr/lib/linux-image-current-sunxi/' 866 'sun8i-r40-bananapi-m2-ultra.dtb') 867 dtb_path = self.extract_from_deb(deb_path, dtb_path) 868 rootfs_url = ('http://storage.kernelci.org/images/rootfs/buildroot/' 869 'buildroot-baseline/20221116.0/armel/rootfs.ext2.xz') 870 rootfs_hash = 'fae32f337c7b87547b10f42599acf109da8b6d9a' 871 rootfs_path_xz = self.fetch_asset(rootfs_url, asset_hash=rootfs_hash) 872 rootfs_path = os.path.join(self.workdir, 'rootfs.cpio') 873 archive.lzma_uncompress(rootfs_path_xz, rootfs_path) 874 image_pow2ceil_expand(rootfs_path) 875 876 self.vm.set_console() 877 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 878 'console=ttyS0,115200 ' 879 'root=b300 rootwait rw ' 880 'panic=-1 noreboot') 881 self.vm.add_args('-kernel', kernel_path, 882 '-dtb', dtb_path, 883 '-drive', 'file=' + rootfs_path + ',if=sd,format=raw', 884 '-net', 'nic,model=gmac,netdev=host_gmac', 885 '-netdev', 'user,id=host_gmac', 886 '-append', kernel_command_line, 887 '-no-reboot') 888 self.vm.launch() 889 shell_ready = "/bin/sh: can't access tty; job control turned off" 890 self.wait_for_console_pattern(shell_ready) 891 892 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 893 'Allwinner sun8i Family') 894 exec_command_and_wait_for_pattern(self, 'cat /proc/partitions', 895 'mmcblk') 896 exec_command_and_wait_for_pattern(self, 'ifconfig eth0 up', 897 'eth0: Link is Up') 898 exec_command_and_wait_for_pattern(self, 'udhcpc eth0', 899 'udhcpc: lease of 10.0.2.15 obtained') 900 exec_command_and_wait_for_pattern(self, 'ping -c 3 10.0.2.2', 901 '3 packets transmitted, 3 packets received, 0% packet loss') 902 exec_command_and_wait_for_pattern(self, 'reboot', 903 'reboot: Restarting system') 904 # Wait for VM to shut down gracefully 905 self.vm.wait() 906 907 @skipUnless(os.getenv('AVOCADO_ALLOW_LARGE_STORAGE'), 'storage limited') 908 def test_arm_bpim2u_openwrt_22_03_3(self): 909 """ 910 :avocado: tags=arch:arm 911 :avocado: tags=machine:bpim2u 912 :avocado: tags=device:sd 913 """ 914 915 # This test download a 8.9 MiB compressed image and expand it 916 # to 127 MiB. 917 image_url = ('https://downloads.openwrt.org/releases/22.03.3/targets/' 918 'sunxi/cortexa7/openwrt-22.03.3-sunxi-cortexa7-' 919 'sinovoip_bananapi-m2-ultra-ext4-sdcard.img.gz') 920 image_hash = ('5b41b4e11423e562c6011640f9a7cd3b' 921 'dd0a3d42b83430f7caa70a432e6cd82c') 922 image_path_gz = self.fetch_asset(image_url, asset_hash=image_hash, 923 algorithm='sha256') 924 image_path = archive.extract(image_path_gz, self.workdir) 925 image_pow2ceil_expand(image_path) 926 927 self.vm.set_console() 928 self.vm.add_args('-drive', 'file=' + image_path + ',if=sd,format=raw', 929 '-nic', 'user', 930 '-no-reboot') 931 self.vm.launch() 932 933 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 934 'usbcore.nousb ' 935 'noreboot') 936 937 self.wait_for_console_pattern('U-Boot SPL') 938 939 interrupt_interactive_console_until_pattern( 940 self, 'Hit any key to stop autoboot:', '=>') 941 exec_command_and_wait_for_pattern(self, "setenv extraargs '" + 942 kernel_command_line + "'", '=>') 943 exec_command_and_wait_for_pattern(self, 'boot', 'Starting kernel ...'); 944 945 self.wait_for_console_pattern( 946 'Please press Enter to activate this console.') 947 948 exec_command_and_wait_for_pattern(self, ' ', 'root@') 949 950 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 951 'Allwinner sun8i Family') 952 exec_command_and_wait_for_pattern(self, 'cat /proc/iomem', 953 'system-control@1c00000') 954 955 def test_arm_orangepi(self): 956 """ 957 :avocado: tags=arch:arm 958 :avocado: tags=machine:orangepi-pc 959 :avocado: tags=accel:tcg 960 """ 961 deb_url = ('https://apt.armbian.com/pool/main/l/' 962 'linux-5.10.16-sunxi/linux-image-current-sunxi_21.02.2_armhf.deb') 963 deb_hash = '9fa84beda245cabf0b4fa84cf6eaa7738ead1da0' 964 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 965 kernel_path = self.extract_from_deb(deb_path, 966 '/boot/vmlinuz-5.10.16-sunxi') 967 dtb_path = '/usr/lib/linux-image-current-sunxi/sun8i-h3-orangepi-pc.dtb' 968 dtb_path = self.extract_from_deb(deb_path, dtb_path) 969 970 self.vm.set_console() 971 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 972 'console=ttyS0,115200n8 ' 973 'earlycon=uart,mmio32,0x1c28000') 974 self.vm.add_args('-kernel', kernel_path, 975 '-dtb', dtb_path, 976 '-append', kernel_command_line) 977 self.vm.launch() 978 console_pattern = 'Kernel command line: %s' % kernel_command_line 979 self.wait_for_console_pattern(console_pattern) 980 981 def test_arm_orangepi_initrd(self): 982 """ 983 :avocado: tags=arch:arm 984 :avocado: tags=accel:tcg 985 :avocado: tags=machine:orangepi-pc 986 """ 987 deb_url = ('https://apt.armbian.com/pool/main/l/' 988 'linux-5.10.16-sunxi/linux-image-current-sunxi_21.02.2_armhf.deb') 989 deb_hash = '9fa84beda245cabf0b4fa84cf6eaa7738ead1da0' 990 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 991 kernel_path = self.extract_from_deb(deb_path, 992 '/boot/vmlinuz-5.10.16-sunxi') 993 dtb_path = '/usr/lib/linux-image-current-sunxi/sun8i-h3-orangepi-pc.dtb' 994 dtb_path = self.extract_from_deb(deb_path, dtb_path) 995 initrd_url = ('https://github.com/groeck/linux-build-test/raw/' 996 '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/' 997 'arm/rootfs-armv7a.cpio.gz') 998 initrd_hash = '604b2e45cdf35045846b8bbfbf2129b1891bdc9c' 999 initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash) 1000 initrd_path = os.path.join(self.workdir, 'rootfs.cpio') 1001 archive.gzip_uncompress(initrd_path_gz, initrd_path) 1002 1003 self.vm.set_console() 1004 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 1005 'console=ttyS0,115200 ' 1006 'panic=-1 noreboot') 1007 self.vm.add_args('-kernel', kernel_path, 1008 '-dtb', dtb_path, 1009 '-initrd', initrd_path, 1010 '-append', kernel_command_line, 1011 '-no-reboot') 1012 self.vm.launch() 1013 self.wait_for_console_pattern('Boot successful.') 1014 1015 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 1016 'Allwinner sun8i Family') 1017 exec_command_and_wait_for_pattern(self, 'cat /proc/iomem', 1018 'system-control@1c00000') 1019 exec_command_and_wait_for_pattern(self, 'reboot', 1020 'reboot: Restarting system') 1021 # Wait for VM to shut down gracefully 1022 self.vm.wait() 1023 1024 def test_arm_orangepi_sd(self): 1025 """ 1026 :avocado: tags=arch:arm 1027 :avocado: tags=accel:tcg 1028 :avocado: tags=machine:orangepi-pc 1029 :avocado: tags=device:sd 1030 """ 1031 self.require_netdev('user') 1032 1033 deb_url = ('https://apt.armbian.com/pool/main/l/' 1034 'linux-5.10.16-sunxi/linux-image-current-sunxi_21.02.2_armhf.deb') 1035 deb_hash = '9fa84beda245cabf0b4fa84cf6eaa7738ead1da0' 1036 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 1037 kernel_path = self.extract_from_deb(deb_path, 1038 '/boot/vmlinuz-5.10.16-sunxi') 1039 dtb_path = '/usr/lib/linux-image-current-sunxi/sun8i-h3-orangepi-pc.dtb' 1040 dtb_path = self.extract_from_deb(deb_path, dtb_path) 1041 rootfs_url = ('http://storage.kernelci.org/images/rootfs/buildroot/' 1042 'buildroot-baseline/20221116.0/armel/rootfs.ext2.xz') 1043 rootfs_hash = 'fae32f337c7b87547b10f42599acf109da8b6d9a' 1044 rootfs_path_xz = self.fetch_asset(rootfs_url, asset_hash=rootfs_hash) 1045 rootfs_path = os.path.join(self.workdir, 'rootfs.cpio') 1046 archive.lzma_uncompress(rootfs_path_xz, rootfs_path) 1047 image_pow2ceil_expand(rootfs_path) 1048 1049 self.vm.set_console() 1050 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 1051 'console=ttyS0,115200 ' 1052 'root=/dev/mmcblk0 rootwait rw ' 1053 'panic=-1 noreboot') 1054 self.vm.add_args('-kernel', kernel_path, 1055 '-dtb', dtb_path, 1056 '-drive', 'file=' + rootfs_path + ',if=sd,format=raw', 1057 '-append', kernel_command_line, 1058 '-no-reboot') 1059 self.vm.launch() 1060 shell_ready = "/bin/sh: can't access tty; job control turned off" 1061 self.wait_for_console_pattern(shell_ready) 1062 1063 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 1064 'Allwinner sun8i Family') 1065 exec_command_and_wait_for_pattern(self, 'cat /proc/partitions', 1066 'mmcblk0') 1067 exec_command_and_wait_for_pattern(self, 'ifconfig eth0 up', 1068 'eth0: Link is Up') 1069 exec_command_and_wait_for_pattern(self, 'udhcpc eth0', 1070 'udhcpc: lease of 10.0.2.15 obtained') 1071 exec_command_and_wait_for_pattern(self, 'ping -c 3 10.0.2.2', 1072 '3 packets transmitted, 3 packets received, 0% packet loss') 1073 exec_command_and_wait_for_pattern(self, 'reboot', 1074 'reboot: Restarting system') 1075 # Wait for VM to shut down gracefully 1076 self.vm.wait() 1077 1078 @skipUnless(os.getenv('AVOCADO_ALLOW_LARGE_STORAGE'), 'storage limited') 1079 def test_arm_orangepi_bionic_20_08(self): 1080 """ 1081 :avocado: tags=arch:arm 1082 :avocado: tags=machine:orangepi-pc 1083 :avocado: tags=device:sd 1084 """ 1085 1086 # This test download a 275 MiB compressed image and expand it 1087 # to 1036 MiB, but the underlying filesystem is 1552 MiB... 1088 # As we expand it to 2 GiB we are safe. 1089 1090 image_url = ('https://archive.armbian.com/orangepipc/archive/' 1091 'Armbian_20.08.1_Orangepipc_bionic_current_5.8.5.img.xz') 1092 image_hash = ('b4d6775f5673486329e45a0586bf06b6' 1093 'dbe792199fd182ac6b9c7bb6c7d3e6dd') 1094 image_path_xz = self.fetch_asset(image_url, asset_hash=image_hash, 1095 algorithm='sha256') 1096 image_path = archive.extract(image_path_xz, self.workdir) 1097 image_pow2ceil_expand(image_path) 1098 1099 self.vm.set_console() 1100 self.vm.add_args('-drive', 'file=' + image_path + ',if=sd,format=raw', 1101 '-nic', 'user', 1102 '-no-reboot') 1103 self.vm.launch() 1104 1105 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 1106 'console=ttyS0,115200 ' 1107 'loglevel=7 ' 1108 'nosmp ' 1109 'systemd.default_timeout_start_sec=9000 ' 1110 'systemd.mask=armbian-zram-config.service ' 1111 'systemd.mask=armbian-ramlog.service') 1112 1113 self.wait_for_console_pattern('U-Boot SPL') 1114 self.wait_for_console_pattern('Autoboot in ') 1115 exec_command_and_wait_for_pattern(self, ' ', '=>') 1116 exec_command_and_wait_for_pattern(self, "setenv extraargs '" + 1117 kernel_command_line + "'", '=>') 1118 exec_command_and_wait_for_pattern(self, 'boot', 'Starting kernel ...'); 1119 1120 self.wait_for_console_pattern('systemd[1]: Set hostname ' + 1121 'to <orangepipc>') 1122 self.wait_for_console_pattern('Starting Load Kernel Modules...') 1123 1124 @skipUnless(os.getenv('AVOCADO_ALLOW_LARGE_STORAGE'), 'storage limited') 1125 def test_arm_orangepi_uboot_netbsd9(self): 1126 """ 1127 :avocado: tags=arch:arm 1128 :avocado: tags=machine:orangepi-pc 1129 :avocado: tags=device:sd 1130 :avocado: tags=os:netbsd 1131 """ 1132 # This test download a 304MB compressed image and expand it to 2GB 1133 deb_url = ('http://snapshot.debian.org/archive/debian/' 1134 '20200108T145233Z/pool/main/u/u-boot/' 1135 'u-boot-sunxi_2020.01%2Bdfsg-1_armhf.deb') 1136 deb_hash = 'f67f404a80753ca3d1258f13e38f2b060e13db99' 1137 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 1138 # We use the common OrangePi PC 'plus' build of U-Boot for our secondary 1139 # program loader (SPL). We will then set the path to the more specific 1140 # OrangePi "PC" device tree blob with 'setenv fdtfile' in U-Boot prompt, 1141 # before to boot NetBSD. 1142 uboot_path = '/usr/lib/u-boot/orangepi_plus/u-boot-sunxi-with-spl.bin' 1143 uboot_path = self.extract_from_deb(deb_path, uboot_path) 1144 image_url = ('https://cdn.netbsd.org/pub/NetBSD/NetBSD-9.0/' 1145 'evbarm-earmv7hf/binary/gzimg/armv7.img.gz') 1146 image_hash = '2babb29d36d8360adcb39c09e31060945259917a' 1147 image_path_gz = self.fetch_asset(image_url, asset_hash=image_hash) 1148 image_path = os.path.join(self.workdir, 'armv7.img') 1149 archive.gzip_uncompress(image_path_gz, image_path) 1150 image_pow2ceil_expand(image_path) 1151 image_drive_args = 'if=sd,format=raw,snapshot=on,file=' + image_path 1152 1153 # dd if=u-boot-sunxi-with-spl.bin of=armv7.img bs=1K seek=8 conv=notrunc 1154 with open(uboot_path, 'rb') as f_in: 1155 with open(image_path, 'r+b') as f_out: 1156 f_out.seek(8 * 1024) 1157 shutil.copyfileobj(f_in, f_out) 1158 1159 self.vm.set_console() 1160 self.vm.add_args('-nic', 'user', 1161 '-drive', image_drive_args, 1162 '-global', 'allwinner-rtc.base-year=2000', 1163 '-no-reboot') 1164 self.vm.launch() 1165 wait_for_console_pattern(self, 'U-Boot 2020.01+dfsg-1') 1166 interrupt_interactive_console_until_pattern(self, 1167 'Hit any key to stop autoboot:', 1168 'switch to partitions #0, OK') 1169 1170 exec_command_and_wait_for_pattern(self, '', '=>') 1171 cmd = 'setenv bootargs root=ld0a' 1172 exec_command_and_wait_for_pattern(self, cmd, '=>') 1173 cmd = 'setenv kernel netbsd-GENERIC.ub' 1174 exec_command_and_wait_for_pattern(self, cmd, '=>') 1175 cmd = 'setenv fdtfile dtb/sun8i-h3-orangepi-pc.dtb' 1176 exec_command_and_wait_for_pattern(self, cmd, '=>') 1177 cmd = ("setenv bootcmd 'fatload mmc 0:1 ${kernel_addr_r} ${kernel}; " 1178 "fatload mmc 0:1 ${fdt_addr_r} ${fdtfile}; " 1179 "fdt addr ${fdt_addr_r}; " 1180 "bootm ${kernel_addr_r} - ${fdt_addr_r}'") 1181 exec_command_and_wait_for_pattern(self, cmd, '=>') 1182 1183 exec_command_and_wait_for_pattern(self, 'boot', 1184 'Booting kernel from Legacy Image') 1185 wait_for_console_pattern(self, 'Starting kernel ...') 1186 wait_for_console_pattern(self, 'NetBSD 9.0 (GENERIC)') 1187 # Wait for user-space 1188 wait_for_console_pattern(self, 'Starting root file system check') 1189 1190 def test_aarch64_raspi3_atf(self): 1191 """ 1192 :avocado: tags=accel:tcg 1193 :avocado: tags=arch:aarch64 1194 :avocado: tags=machine:raspi3b 1195 :avocado: tags=cpu:cortex-a53 1196 :avocado: tags=device:pl011 1197 :avocado: tags=atf 1198 """ 1199 zip_url = ('https://github.com/pbatard/RPi3/releases/download/' 1200 'v1.15/RPi3_UEFI_Firmware_v1.15.zip') 1201 zip_hash = '74b3bd0de92683cadb14e008a7575e1d0c3cafb9' 1202 zip_path = self.fetch_asset(zip_url, asset_hash=zip_hash) 1203 1204 archive.extract(zip_path, self.workdir) 1205 efi_fd = os.path.join(self.workdir, 'RPI_EFI.fd') 1206 1207 self.vm.set_console(console_index=1) 1208 self.vm.add_args('-nodefaults', 1209 '-device', 'loader,file=%s,force-raw=true' % efi_fd) 1210 self.vm.launch() 1211 self.wait_for_console_pattern('version UEFI Firmware v1.15') 1212 1213 def test_s390x_s390_ccw_virtio(self): 1214 """ 1215 :avocado: tags=arch:s390x 1216 :avocado: tags=machine:s390-ccw-virtio 1217 """ 1218 kernel_url = ('https://archives.fedoraproject.org/pub/archive' 1219 '/fedora-secondary/releases/29/Everything/s390x/os/images' 1220 '/kernel.img') 1221 kernel_hash = 'e8e8439103ef8053418ef062644ffd46a7919313' 1222 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) 1223 1224 self.vm.set_console() 1225 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=sclp0' 1226 self.vm.add_args('-nodefaults', 1227 '-kernel', kernel_path, 1228 '-append', kernel_command_line) 1229 self.vm.launch() 1230 console_pattern = 'Kernel command line: %s' % kernel_command_line 1231 self.wait_for_console_pattern(console_pattern) 1232 1233 def test_alpha_clipper(self): 1234 """ 1235 :avocado: tags=arch:alpha 1236 :avocado: tags=machine:clipper 1237 """ 1238 kernel_url = ('http://archive.debian.org/debian/dists/lenny/main/' 1239 'installer-alpha/20090123lenny10/images/cdrom/vmlinuz') 1240 kernel_hash = '3a943149335529e2ed3e74d0d787b85fb5671ba3' 1241 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) 1242 1243 uncompressed_kernel = archive.uncompress(kernel_path, self.workdir) 1244 1245 self.vm.set_console() 1246 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0' 1247 self.vm.add_args('-nodefaults', 1248 '-kernel', uncompressed_kernel, 1249 '-append', kernel_command_line) 1250 self.vm.launch() 1251 console_pattern = 'Kernel command line: %s' % kernel_command_line 1252 self.wait_for_console_pattern(console_pattern) 1253 1254 def test_m68k_q800(self): 1255 """ 1256 :avocado: tags=arch:m68k 1257 :avocado: tags=machine:q800 1258 """ 1259 deb_url = ('https://snapshot.debian.org/archive/debian-ports' 1260 '/20191021T083923Z/pool-m68k/main' 1261 '/l/linux/kernel-image-5.3.0-1-m68k-di_5.3.7-1_m68k.udeb') 1262 deb_hash = '044954bb9be4160a3ce81f8bc1b5e856b75cccd1' 1263 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 1264 kernel_path = self.extract_from_deb(deb_path, 1265 '/boot/vmlinux-5.3.0-1-m68k') 1266 1267 self.vm.set_console() 1268 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 1269 'console=ttyS0 vga=off') 1270 self.vm.add_args('-kernel', kernel_path, 1271 '-append', kernel_command_line) 1272 self.vm.launch() 1273 console_pattern = 'Kernel command line: %s' % kernel_command_line 1274 self.wait_for_console_pattern(console_pattern) 1275 console_pattern = 'No filesystem could mount root' 1276 self.wait_for_console_pattern(console_pattern) 1277 1278 def do_test_advcal_2018(self, day, tar_hash, kernel_name, console=0): 1279 tar_url = ('https://qemu-advcal.gitlab.io' 1280 '/qac-best-of-multiarch/download/day' + day + '.tar.xz') 1281 file_path = self.fetch_asset(tar_url, asset_hash=tar_hash) 1282 archive.extract(file_path, self.workdir) 1283 self.vm.set_console(console_index=console) 1284 self.vm.add_args('-kernel', 1285 self.workdir + '/day' + day + '/' + kernel_name) 1286 self.vm.launch() 1287 self.wait_for_console_pattern('QEMU advent calendar') 1288 1289 def test_arm_vexpressa9(self): 1290 """ 1291 :avocado: tags=arch:arm 1292 :avocado: tags=machine:vexpress-a9 1293 """ 1294 tar_hash = '32b7677ce8b6f1471fb0059865f451169934245b' 1295 self.vm.add_args('-dtb', self.workdir + '/day16/vexpress-v2p-ca9.dtb') 1296 self.do_test_advcal_2018('16', tar_hash, 'winter.zImage') 1297 1298 def test_arm_ast2600_debian(self): 1299 """ 1300 :avocado: tags=arch:arm 1301 :avocado: tags=machine:rainier-bmc 1302 """ 1303 deb_url = ('http://snapshot.debian.org/archive/debian/' 1304 '20220606T211338Z/' 1305 'pool/main/l/linux/' 1306 'linux-image-5.17.0-2-armmp_5.17.6-1%2Bb1_armhf.deb') 1307 deb_hash = '8acb2b4439faedc2f3ed4bdb2847ad4f6e0491f73debaeb7f660c8abe4dcdc0e' 1308 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash, 1309 algorithm='sha256') 1310 kernel_path = self.extract_from_deb(deb_path, '/boot/vmlinuz-5.17.0-2-armmp') 1311 dtb_path = self.extract_from_deb(deb_path, 1312 '/usr/lib/linux-image-5.17.0-2-armmp/aspeed-bmc-ibm-rainier.dtb') 1313 1314 self.vm.set_console() 1315 self.vm.add_args('-kernel', kernel_path, 1316 '-dtb', dtb_path, 1317 '-net', 'nic') 1318 self.vm.launch() 1319 self.wait_for_console_pattern("Booting Linux on physical CPU 0xf00") 1320 self.wait_for_console_pattern("SMP: Total of 2 processors activated") 1321 self.wait_for_console_pattern("No filesystem could mount root") 1322 1323 def test_m68k_mcf5208evb(self): 1324 """ 1325 :avocado: tags=arch:m68k 1326 :avocado: tags=machine:mcf5208evb 1327 """ 1328 tar_hash = 'ac688fd00561a2b6ce1359f9ff6aa2b98c9a570c' 1329 self.do_test_advcal_2018('07', tar_hash, 'sanity-clause.elf') 1330 1331 def test_or1k_sim(self): 1332 """ 1333 :avocado: tags=arch:or1k 1334 :avocado: tags=machine:or1k-sim 1335 """ 1336 tar_hash = '20334cdaf386108c530ff0badaecc955693027dd' 1337 self.do_test_advcal_2018('20', tar_hash, 'vmlinux') 1338 1339 def test_nios2_10m50(self): 1340 """ 1341 :avocado: tags=arch:nios2 1342 :avocado: tags=machine:10m50-ghrd 1343 """ 1344 tar_hash = 'e4251141726c412ac0407c5a6bceefbbff018918' 1345 self.do_test_advcal_2018('14', tar_hash, 'vmlinux.elf') 1346 1347 def test_ppc64_e500(self): 1348 """ 1349 :avocado: tags=arch:ppc64 1350 :avocado: tags=machine:ppce500 1351 :avocado: tags=cpu:e5500 1352 :avocado: tags=accel:tcg 1353 """ 1354 self.require_accelerator("tcg") 1355 tar_hash = '6951d86d644b302898da2fd701739c9406527fe1' 1356 self.do_test_advcal_2018('19', tar_hash, 'uImage') 1357 1358 def do_test_ppc64_powernv(self, proc): 1359 self.require_accelerator("tcg") 1360 images_url = ('https://github.com/open-power/op-build/releases/download/v2.7/') 1361 1362 kernel_url = images_url + 'zImage.epapr' 1363 kernel_hash = '0ab237df661727e5392cee97460e8674057a883c5f74381a128fa772588d45cd' 1364 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash, 1365 algorithm='sha256') 1366 self.vm.set_console() 1367 self.vm.add_args('-kernel', kernel_path, 1368 '-append', 'console=tty0 console=hvc0', 1369 '-device', 'pcie-pci-bridge,id=bridge1,bus=pcie.1,addr=0x0', 1370 '-device', 'nvme,bus=pcie.2,addr=0x0,serial=1234', 1371 '-device', 'e1000e,bus=bridge1,addr=0x3', 1372 '-device', 'nec-usb-xhci,bus=bridge1,addr=0x2') 1373 self.vm.launch() 1374 1375 self.wait_for_console_pattern("CPU: " + proc + " generation processor") 1376 self.wait_for_console_pattern("zImage starting: loaded") 1377 self.wait_for_console_pattern("Run /init as init process") 1378 self.wait_for_console_pattern("Creating 1 MTD partitions") 1379 1380 def test_ppc_powernv8(self): 1381 """ 1382 :avocado: tags=arch:ppc64 1383 :avocado: tags=machine:powernv8 1384 :avocado: tags=accel:tcg 1385 """ 1386 self.do_test_ppc64_powernv('P8') 1387 1388 def test_ppc_powernv9(self): 1389 """ 1390 :avocado: tags=arch:ppc64 1391 :avocado: tags=machine:powernv9 1392 :avocado: tags=accel:tcg 1393 """ 1394 self.do_test_ppc64_powernv('P9') 1395 1396 def test_ppc_g3beige(self): 1397 """ 1398 :avocado: tags=arch:ppc 1399 :avocado: tags=machine:g3beige 1400 :avocado: tags=accel:tcg 1401 """ 1402 # TODO: g3beige works with kvm_pr but we don't have a 1403 # reliable way ATM (e.g. looking at /proc/modules) to detect 1404 # whether we're running kvm_hv or kvm_pr. For now let's 1405 # disable this test if we don't have TCG support. 1406 self.require_accelerator("tcg") 1407 tar_hash = 'e0b872a5eb8fdc5bed19bd43ffe863900ebcedfc' 1408 self.vm.add_args('-M', 'graphics=off') 1409 self.do_test_advcal_2018('15', tar_hash, 'invaders.elf') 1410 1411 def test_ppc_mac99(self): 1412 """ 1413 :avocado: tags=arch:ppc 1414 :avocado: tags=machine:mac99 1415 :avocado: tags=accel:tcg 1416 """ 1417 # TODO: mac99 works with kvm_pr but we don't have a 1418 # reliable way ATM (e.g. looking at /proc/modules) to detect 1419 # whether we're running kvm_hv or kvm_pr. For now let's 1420 # disable this test if we don't have TCG support. 1421 self.require_accelerator("tcg") 1422 tar_hash = 'e0b872a5eb8fdc5bed19bd43ffe863900ebcedfc' 1423 self.vm.add_args('-M', 'graphics=off') 1424 self.do_test_advcal_2018('15', tar_hash, 'invaders.elf') 1425 1426 # This test has a 6-10% failure rate on various hosts that look 1427 # like issues with a buggy kernel. As a result we don't want it 1428 # gating releases on Gitlab. 1429 @skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab') 1430 def test_sh4_r2d(self): 1431 """ 1432 :avocado: tags=arch:sh4 1433 :avocado: tags=machine:r2d 1434 """ 1435 tar_hash = 'fe06a4fd8ccbf2e27928d64472939d47829d4c7e' 1436 self.vm.add_args('-append', 'console=ttySC1') 1437 self.do_test_advcal_2018('09', tar_hash, 'zImage', console=1) 1438 1439 def test_sparc_ss20(self): 1440 """ 1441 :avocado: tags=arch:sparc 1442 :avocado: tags=machine:SS-20 1443 """ 1444 tar_hash = 'b18550d5d61c7615d989a06edace051017726a9f' 1445 self.do_test_advcal_2018('11', tar_hash, 'zImage.elf') 1446 1447 def test_xtensa_lx60(self): 1448 """ 1449 :avocado: tags=arch:xtensa 1450 :avocado: tags=machine:lx60 1451 :avocado: tags=cpu:dc233c 1452 """ 1453 tar_hash = '49e88d9933742f0164b60839886c9739cb7a0d34' 1454 self.do_test_advcal_2018('02', tar_hash, 'santas-sleigh-ride.elf') 1455